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 /* module parameters */
50 static struct iwl_mod_params iwl4965_mod_params = {
51 .num_of_queues = IWL49_NUM_QUEUES,
55 /* the rest are 0 by default */
58 /* check contents of special bootstrap uCode SRAM */
59 static int iwl4965_verify_bsm(struct iwl_priv *priv)
61 __le32 *image = priv->ucode_boot.v_addr;
62 u32 len = priv->ucode_boot.len;
66 IWL_DEBUG_INFO("Begin verify bsm\n");
68 /* verify BSM SRAM contents */
69 val = iwl_read_prph(priv, BSM_WR_DWCOUNT_REG);
70 for (reg = BSM_SRAM_LOWER_BOUND;
71 reg < BSM_SRAM_LOWER_BOUND + len;
72 reg += sizeof(u32), image++) {
73 val = iwl_read_prph(priv, reg);
74 if (val != le32_to_cpu(*image)) {
75 IWL_ERROR("BSM uCode verification failed at "
76 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
78 reg - BSM_SRAM_LOWER_BOUND, len,
79 val, le32_to_cpu(*image));
84 IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
90 * iwl4965_load_bsm - Load bootstrap instructions
94 * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
95 * in special SRAM that does not power down during RFKILL. When powering back
96 * up after power-saving sleeps (or during initial uCode load), the BSM loads
97 * the bootstrap program into the on-board processor, and starts it.
99 * The bootstrap program loads (via DMA) instructions and data for a new
100 * program from host DRAM locations indicated by the host driver in the
101 * BSM_DRAM_* registers. Once the new program is loaded, it starts
104 * When initializing the NIC, the host driver points the BSM to the
105 * "initialize" uCode image. This uCode sets up some internal data, then
106 * notifies host via "initialize alive" that it is complete.
108 * The host then replaces the BSM_DRAM_* pointer values to point to the
109 * normal runtime uCode instructions and a backup uCode data cache buffer
110 * (filled initially with starting data values for the on-board processor),
111 * then triggers the "initialize" uCode to load and launch the runtime uCode,
112 * which begins normal operation.
114 * When doing a power-save shutdown, runtime uCode saves data SRAM into
115 * the backup data cache in DRAM before SRAM is powered down.
117 * When powering back up, the BSM loads the bootstrap program. This reloads
118 * the runtime uCode instructions and the backup data cache into SRAM,
119 * and re-launches the runtime uCode from where it left off.
121 static int iwl4965_load_bsm(struct iwl_priv *priv)
123 __le32 *image = priv->ucode_boot.v_addr;
124 u32 len = priv->ucode_boot.len;
134 IWL_DEBUG_INFO("Begin load bsm\n");
136 priv->ucode_type = UCODE_RT;
138 /* make sure bootstrap program is no larger than BSM's SRAM size */
139 if (len > IWL_MAX_BSM_SIZE)
142 /* Tell bootstrap uCode where to find the "Initialize" uCode
143 * in host DRAM ... host DRAM physical address bits 35:4 for 4965.
144 * NOTE: iwl_init_alive_start() will replace these values,
145 * after the "initialize" uCode has run, to point to
146 * runtime/protocol instructions and backup data cache.
148 pinst = priv->ucode_init.p_addr >> 4;
149 pdata = priv->ucode_init_data.p_addr >> 4;
150 inst_len = priv->ucode_init.len;
151 data_len = priv->ucode_init_data.len;
153 ret = iwl_grab_nic_access(priv);
157 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
158 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
159 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
160 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
162 /* Fill BSM memory with bootstrap instructions */
163 for (reg_offset = BSM_SRAM_LOWER_BOUND;
164 reg_offset < BSM_SRAM_LOWER_BOUND + len;
165 reg_offset += sizeof(u32), image++)
166 _iwl_write_prph(priv, reg_offset, le32_to_cpu(*image));
168 ret = iwl4965_verify_bsm(priv);
170 iwl_release_nic_access(priv);
174 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
175 iwl_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
176 iwl_write_prph(priv, BSM_WR_MEM_DST_REG, RTC_INST_LOWER_BOUND);
177 iwl_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
179 /* Load bootstrap code into instruction SRAM now,
180 * to prepare to load "initialize" uCode */
181 iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START);
183 /* Wait for load of bootstrap uCode to finish */
184 for (i = 0; i < 100; i++) {
185 done = iwl_read_prph(priv, BSM_WR_CTRL_REG);
186 if (!(done & BSM_WR_CTRL_REG_BIT_START))
191 IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i);
193 IWL_ERROR("BSM write did not complete!\n");
197 /* Enable future boot loads whenever power management unit triggers it
198 * (e.g. when powering back up after power-save shutdown) */
199 iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN);
201 iwl_release_nic_access(priv);
207 * iwl4965_set_ucode_ptrs - Set uCode address location
209 * Tell initialization uCode where to find runtime uCode.
211 * BSM registers initially contain pointers to initialization uCode.
212 * We need to replace them to load runtime uCode inst and data,
213 * and to save runtime data when powering down.
215 static int iwl4965_set_ucode_ptrs(struct iwl_priv *priv)
222 /* bits 35:4 for 4965 */
223 pinst = priv->ucode_code.p_addr >> 4;
224 pdata = priv->ucode_data_backup.p_addr >> 4;
226 spin_lock_irqsave(&priv->lock, flags);
227 ret = iwl_grab_nic_access(priv);
229 spin_unlock_irqrestore(&priv->lock, flags);
233 /* Tell bootstrap uCode where to find image to load */
234 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
235 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
236 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
237 priv->ucode_data.len);
239 /* Inst bytecount must be last to set up, bit 31 signals uCode
240 * that all new ptr/size info is in place */
241 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
242 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
243 iwl_release_nic_access(priv);
245 spin_unlock_irqrestore(&priv->lock, flags);
247 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
253 * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
255 * Called after REPLY_ALIVE notification received from "initialize" uCode.
257 * The 4965 "initialize" ALIVE reply contains calibration data for:
258 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
259 * (3945 does not contain this data).
261 * Tell "initialize" uCode to go ahead and load the runtime uCode.
263 static void iwl4965_init_alive_start(struct iwl_priv *priv)
265 /* Check alive response for "valid" sign from uCode */
266 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
267 /* We had an error bringing up the hardware, so take it
268 * all the way back down so we can try again */
269 IWL_DEBUG_INFO("Initialize Alive failed.\n");
273 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
274 * This is a paranoid check, because we would not have gotten the
275 * "initialize" alive if code weren't properly loaded. */
276 if (iwl_verify_ucode(priv)) {
277 /* Runtime instruction load was bad;
278 * take it all the way back down so we can try again */
279 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
283 /* Calculate temperature */
284 priv->temperature = iwl4965_get_temperature(priv);
286 /* Send pointers to protocol/runtime uCode image ... init code will
287 * load and launch runtime uCode, which will send us another "Alive"
289 IWL_DEBUG_INFO("Initialization Alive received.\n");
290 if (iwl4965_set_ucode_ptrs(priv)) {
291 /* Runtime instruction load won't happen;
292 * take it all the way back down so we can try again */
293 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
299 queue_work(priv->workqueue, &priv->restart);
302 static int is_fat_channel(__le32 rxon_flags)
304 return (rxon_flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK) ||
305 (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK);
308 int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags)
312 /* 4965 HT rate format */
313 if (rate_n_flags & RATE_MCS_HT_MSK) {
314 idx = (rate_n_flags & 0xff);
316 if (idx >= IWL_RATE_MIMO2_6M_PLCP)
317 idx = idx - IWL_RATE_MIMO2_6M_PLCP;
319 idx += IWL_FIRST_OFDM_RATE;
320 /* skip 9M not supported in ht*/
321 if (idx >= IWL_RATE_9M_INDEX)
323 if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE))
326 /* 4965 legacy rate format, search for match in table */
328 for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++)
329 if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
337 * translate ucode response to mac80211 tx status control values
339 void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
340 struct ieee80211_tx_info *control)
344 control->antenna_sel_tx =
345 ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
346 if (rate_n_flags & RATE_MCS_HT_MSK)
347 control->flags |= IEEE80211_TX_CTL_OFDM_HT;
348 if (rate_n_flags & RATE_MCS_GF_MSK)
349 control->flags |= IEEE80211_TX_CTL_GREEN_FIELD;
350 if (rate_n_flags & RATE_MCS_FAT_MSK)
351 control->flags |= IEEE80211_TX_CTL_40_MHZ_WIDTH;
352 if (rate_n_flags & RATE_MCS_DUP_MSK)
353 control->flags |= IEEE80211_TX_CTL_DUP_DATA;
354 if (rate_n_flags & RATE_MCS_SGI_MSK)
355 control->flags |= IEEE80211_TX_CTL_SHORT_GI;
356 rate_index = iwl4965_hwrate_to_plcp_idx(rate_n_flags);
357 if (control->band == IEEE80211_BAND_5GHZ)
358 rate_index -= IWL_FIRST_OFDM_RATE;
359 control->tx_rate_idx = rate_index;
366 static int iwl4965_eeprom_check_version(struct iwl_priv *priv)
371 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
373 calib_ver = iwl_eeprom_query16(priv, EEPROM_4965_CALIB_VERSION_OFFSET);
375 if (eeprom_ver < EEPROM_4965_EEPROM_VERSION ||
376 calib_ver < EEPROM_4965_TX_POWER_VERSION)
381 IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
382 eeprom_ver, EEPROM_4965_EEPROM_VERSION,
383 calib_ver, EEPROM_4965_TX_POWER_VERSION);
387 int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
392 spin_lock_irqsave(&priv->lock, flags);
393 ret = iwl_grab_nic_access(priv);
395 spin_unlock_irqrestore(&priv->lock, flags);
399 if (src == IWL_PWR_SRC_VAUX) {
401 ret = pci_read_config_dword(priv->pci_dev, PCI_POWER_SOURCE,
404 if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT) {
405 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
406 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
407 ~APMG_PS_CTRL_MSK_PWR_SRC);
410 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
411 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
412 ~APMG_PS_CTRL_MSK_PWR_SRC);
415 iwl_release_nic_access(priv);
416 spin_unlock_irqrestore(&priv->lock, flags);
422 * Activate/Deactivat Tx DMA/FIFO channels according tx fifos mask
423 * must be called under priv->lock and mac access
425 static void iwl4965_txq_set_sched(struct iwl_priv *priv, u32 mask)
427 iwl_write_prph(priv, IWL49_SCD_TXFACT, mask);
430 static int iwl4965_apm_init(struct iwl_priv *priv)
434 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
435 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
437 /* disable L0s without affecting L1 :don't wait for ICH L0s bug W/A) */
438 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
439 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
441 /* set "initialization complete" bit to move adapter
442 * D0U* --> D0A* state */
443 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
445 /* wait for clock stabilization */
446 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
447 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
448 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
450 IWL_DEBUG_INFO("Failed to init the card\n");
454 ret = iwl_grab_nic_access(priv);
459 iwl_write_prph(priv, APMG_CLK_CTRL_REG, APMG_CLK_VAL_DMA_CLK_RQT |
460 APMG_CLK_VAL_BSM_CLK_RQT);
464 /* disable L1-Active */
465 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
466 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
468 iwl_release_nic_access(priv);
474 static void iwl4965_nic_config(struct iwl_priv *priv)
481 spin_lock_irqsave(&priv->lock, flags);
483 if ((priv->rev_id & 0x80) == 0x80 && (priv->rev_id & 0x7f) < 8) {
484 pci_read_config_dword(priv->pci_dev, PCI_REG_WUM8, &val);
485 /* Enable No Snoop field */
486 pci_write_config_dword(priv->pci_dev, PCI_REG_WUM8,
490 pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link);
492 /* L1 is enabled by BIOS */
493 if ((val_link & PCI_LINK_VAL_L1_EN) == PCI_LINK_VAL_L1_EN)
494 /* diable L0S disabled L1A enabled */
495 iwl_set_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
497 /* L0S enabled L1A disabled */
498 iwl_clear_bit(priv, CSR_GIO_REG, CSR_GIO_REG_VAL_L0S_ENABLED);
500 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
502 /* write radio config values to register */
503 if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) == EEPROM_4965_RF_CFG_TYPE_MAX)
504 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
505 EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
506 EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
507 EEPROM_RF_CFG_DASH_MSK(radio_cfg));
509 /* set CSR_HW_CONFIG_REG for uCode use */
510 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
511 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
512 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
514 priv->calib_info = (struct iwl_eeprom_calib_info *)
515 iwl_eeprom_query_addr(priv, EEPROM_4965_CALIB_TXPOWER_OFFSET);
517 spin_unlock_irqrestore(&priv->lock, flags);
520 static int iwl4965_apm_stop_master(struct iwl_priv *priv)
525 spin_lock_irqsave(&priv->lock, flags);
527 /* set stop master bit */
528 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
530 ret = iwl_poll_bit(priv, CSR_RESET,
531 CSR_RESET_REG_FLAG_MASTER_DISABLED,
532 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
537 spin_unlock_irqrestore(&priv->lock, flags);
538 IWL_DEBUG_INFO("stop master\n");
543 static void iwl4965_apm_stop(struct iwl_priv *priv)
547 iwl4965_apm_stop_master(priv);
549 spin_lock_irqsave(&priv->lock, flags);
551 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
555 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
556 spin_unlock_irqrestore(&priv->lock, flags);
559 static int iwl4965_apm_reset(struct iwl_priv *priv)
564 iwl4965_apm_stop_master(priv);
566 spin_lock_irqsave(&priv->lock, flags);
568 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
572 /* FIXME: put here L1A -L0S w/a */
574 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
576 ret = iwl_poll_bit(priv, CSR_RESET,
577 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
578 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25);
585 ret = iwl_grab_nic_access(priv);
588 /* Enable DMA and BSM Clock */
589 iwl_write_prph(priv, APMG_CLK_EN_REG, APMG_CLK_VAL_DMA_CLK_RQT |
590 APMG_CLK_VAL_BSM_CLK_RQT);
595 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
596 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
598 iwl_release_nic_access(priv);
600 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
601 wake_up_interruptible(&priv->wait_command_queue);
604 spin_unlock_irqrestore(&priv->lock, flags);
609 #define REG_RECALIB_PERIOD (60)
611 void iwl4965_rf_kill_ct_config(struct iwl_priv *priv)
613 struct iwl4965_ct_kill_config cmd;
617 spin_lock_irqsave(&priv->lock, flags);
618 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
619 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
620 spin_unlock_irqrestore(&priv->lock, flags);
622 cmd.critical_temperature_R =
623 cpu_to_le32(priv->hw_params.ct_kill_threshold);
625 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
628 IWL_ERROR("REPLY_CT_KILL_CONFIG_CMD failed\n");
630 IWL_DEBUG_INFO("REPLY_CT_KILL_CONFIG_CMD succeeded, "
631 "critical temperature is %d\n",
632 cmd.critical_temperature_R);
635 /* Reset differential Rx gains in NIC to prepare for chain noise calibration.
636 * Called after every association, but this runs only once!
637 * ... once chain noise is calibrated the first time, it's good forever. */
638 static void iwl4965_chain_noise_reset(struct iwl_priv *priv)
640 struct iwl_chain_noise_data *data = &(priv->chain_noise_data);
642 if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
643 struct iwl4965_calibration_cmd cmd;
645 memset(&cmd, 0, sizeof(cmd));
646 cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
650 if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
652 IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
653 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
654 IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
658 static void iwl4965_gain_computation(struct iwl_priv *priv,
660 u16 min_average_noise_antenna_i,
661 u32 min_average_noise)
664 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
666 data->delta_gain_code[min_average_noise_antenna_i] = 0;
668 for (i = 0; i < NUM_RX_CHAINS; i++) {
671 if (!(data->disconn_array[i]) &&
672 (data->delta_gain_code[i] ==
673 CHAIN_NOISE_DELTA_GAIN_INIT_VAL)) {
674 delta_g = average_noise[i] - min_average_noise;
675 data->delta_gain_code[i] = (u8)((delta_g * 10) / 15);
676 data->delta_gain_code[i] =
677 min(data->delta_gain_code[i],
678 (u8) CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
680 data->delta_gain_code[i] =
681 (data->delta_gain_code[i] | (1 << 2));
683 data->delta_gain_code[i] = 0;
686 IWL_DEBUG_CALIB("delta_gain_codes: a %d b %d c %d\n",
687 data->delta_gain_code[0],
688 data->delta_gain_code[1],
689 data->delta_gain_code[2]);
691 /* Differential gain gets sent to uCode only once */
692 if (!data->radio_write) {
693 struct iwl4965_calibration_cmd cmd;
694 data->radio_write = 1;
696 memset(&cmd, 0, sizeof(cmd));
697 cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
698 cmd.diff_gain_a = data->delta_gain_code[0];
699 cmd.diff_gain_b = data->delta_gain_code[1];
700 cmd.diff_gain_c = data->delta_gain_code[2];
701 ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
704 IWL_DEBUG_CALIB("fail sending cmd "
705 "REPLY_PHY_CALIBRATION_CMD \n");
707 /* TODO we might want recalculate
708 * rx_chain in rxon cmd */
710 /* Mark so we run this algo only once! */
711 data->state = IWL_CHAIN_NOISE_CALIBRATED;
713 data->chain_noise_a = 0;
714 data->chain_noise_b = 0;
715 data->chain_noise_c = 0;
716 data->chain_signal_a = 0;
717 data->chain_signal_b = 0;
718 data->chain_signal_c = 0;
719 data->beacon_count = 0;
722 static void iwl4965_bg_txpower_work(struct work_struct *work)
724 struct iwl_priv *priv = container_of(work, struct iwl_priv,
727 /* If a scan happened to start before we got here
728 * then just return; the statistics notification will
729 * kick off another scheduled work to compensate for
730 * any temperature delta we missed here. */
731 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
732 test_bit(STATUS_SCANNING, &priv->status))
735 mutex_lock(&priv->mutex);
737 /* Regardless of if we are assocaited, we must reconfigure the
738 * TX power since frames can be sent on non-radar channels while
740 iwl4965_hw_reg_send_txpower(priv);
742 /* Update last_temperature to keep is_calib_needed from running
743 * when it isn't needed... */
744 priv->last_temperature = priv->temperature;
746 mutex_unlock(&priv->mutex);
750 * Acquire priv->lock before calling this function !
752 static void iwl4965_set_wr_ptrs(struct iwl_priv *priv, int txq_id, u32 index)
754 iwl_write_direct32(priv, HBUS_TARG_WRPTR,
755 (index & 0xff) | (txq_id << 8));
756 iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(txq_id), index);
760 * iwl4965_tx_queue_set_status - (optionally) start Tx/Cmd queue
761 * @tx_fifo_id: Tx DMA/FIFO channel (range 0-7) that the queue will feed
762 * @scd_retry: (1) Indicates queue will be used in aggregation mode
764 * NOTE: Acquire priv->lock before calling this function !
766 static void iwl4965_tx_queue_set_status(struct iwl_priv *priv,
767 struct iwl_tx_queue *txq,
768 int tx_fifo_id, int scd_retry)
770 int txq_id = txq->q.id;
772 /* Find out whether to activate Tx queue */
773 int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0;
775 /* Set up and activate */
776 iwl_write_prph(priv, IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
777 (active << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
778 (tx_fifo_id << IWL49_SCD_QUEUE_STTS_REG_POS_TXF) |
779 (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_WSL) |
780 (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK) |
781 IWL49_SCD_QUEUE_STTS_REG_MSK);
783 txq->sched_retry = scd_retry;
785 IWL_DEBUG_INFO("%s %s Queue %d on AC %d\n",
786 active ? "Activate" : "Deactivate",
787 scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
790 static const u16 default_queue_to_tx_fifo[] = {
800 int iwl4965_alive_notify(struct iwl_priv *priv)
807 spin_lock_irqsave(&priv->lock, flags);
809 ret = iwl_grab_nic_access(priv);
811 spin_unlock_irqrestore(&priv->lock, flags);
815 /* Clear 4965's internal Tx Scheduler data base */
816 priv->scd_base_addr = iwl_read_prph(priv, IWL49_SCD_SRAM_BASE_ADDR);
817 a = priv->scd_base_addr + IWL49_SCD_CONTEXT_DATA_OFFSET;
818 for (; a < priv->scd_base_addr + IWL49_SCD_TX_STTS_BITMAP_OFFSET; a += 4)
819 iwl_write_targ_mem(priv, a, 0);
820 for (; a < priv->scd_base_addr + IWL49_SCD_TRANSLATE_TBL_OFFSET; a += 4)
821 iwl_write_targ_mem(priv, a, 0);
822 for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
823 iwl_write_targ_mem(priv, a, 0);
825 /* Tel 4965 where to find Tx byte count tables */
826 iwl_write_prph(priv, IWL49_SCD_DRAM_BASE_ADDR,
828 offsetof(struct iwl4965_shared, queues_byte_cnt_tbls)) >> 10);
830 /* Disable chain mode for all queues */
831 iwl_write_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, 0);
833 /* Initialize each Tx queue (including the command queue) */
834 for (i = 0; i < priv->hw_params.max_txq_num; i++) {
836 /* TFD circular buffer read/write indexes */
837 iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(i), 0);
838 iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
840 /* Max Tx Window size for Scheduler-ACK mode */
841 iwl_write_targ_mem(priv, priv->scd_base_addr +
842 IWL49_SCD_CONTEXT_QUEUE_OFFSET(i),
844 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
845 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
848 iwl_write_targ_mem(priv, priv->scd_base_addr +
849 IWL49_SCD_CONTEXT_QUEUE_OFFSET(i) +
852 IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
853 IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
856 iwl_write_prph(priv, IWL49_SCD_INTERRUPT_MASK,
857 (1 << priv->hw_params.max_txq_num) - 1);
859 /* Activate all Tx DMA/FIFO channels */
860 priv->cfg->ops->lib->txq_set_sched(priv, IWL_MASK(0, 7));
862 iwl4965_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
864 /* Map each Tx/cmd queue to its corresponding fifo */
865 for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) {
866 int ac = default_queue_to_tx_fifo[i];
867 iwl_txq_ctx_activate(priv, i);
868 iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
871 iwl_release_nic_access(priv);
872 spin_unlock_irqrestore(&priv->lock, flags);
877 static struct iwl_sensitivity_ranges iwl4965_sensitivity = {
881 .auto_corr_min_ofdm = 85,
882 .auto_corr_min_ofdm_mrc = 170,
883 .auto_corr_min_ofdm_x1 = 105,
884 .auto_corr_min_ofdm_mrc_x1 = 220,
886 .auto_corr_max_ofdm = 120,
887 .auto_corr_max_ofdm_mrc = 210,
888 .auto_corr_max_ofdm_x1 = 140,
889 .auto_corr_max_ofdm_mrc_x1 = 270,
891 .auto_corr_min_cck = 125,
892 .auto_corr_max_cck = 200,
893 .auto_corr_min_cck_mrc = 200,
894 .auto_corr_max_cck_mrc = 400,
901 * iwl4965_hw_set_hw_params
903 * Called when initializing driver
905 int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
908 if ((priv->cfg->mod_params->num_of_queues > IWL49_NUM_QUEUES) ||
909 (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
910 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
911 IWL_MIN_NUM_QUEUES, IWL49_NUM_QUEUES);
915 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
916 priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
917 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
918 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
919 if (priv->cfg->mod_params->amsdu_size_8K)
920 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
922 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
923 priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
924 priv->hw_params.max_stations = IWL4965_STATION_COUNT;
925 priv->hw_params.bcast_sta_id = IWL4965_BROADCAST_ID;
927 priv->hw_params.max_data_size = IWL49_RTC_DATA_SIZE;
928 priv->hw_params.max_inst_size = IWL49_RTC_INST_SIZE;
929 priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
930 priv->hw_params.fat_channel = BIT(IEEE80211_BAND_5GHZ);
932 priv->hw_params.tx_chains_num = 2;
933 priv->hw_params.rx_chains_num = 2;
934 priv->hw_params.valid_tx_ant = ANT_A | ANT_B;
935 priv->hw_params.valid_rx_ant = ANT_A | ANT_B;
936 priv->hw_params.ct_kill_threshold = CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
938 priv->hw_params.sens = &iwl4965_sensitivity;
943 /* set card power command */
944 static int iwl4965_set_power(struct iwl_priv *priv,
949 ret = iwl_send_cmd_pdu_async(priv, POWER_TABLE_CMD,
950 sizeof(struct iwl4965_powertable_cmd),
954 int iwl4965_hw_reg_set_txpower(struct iwl_priv *priv, s8 power)
956 IWL_ERROR("TODO: Implement iwl4965_hw_reg_set_txpower!\n");
960 static s32 iwl4965_math_div_round(s32 num, s32 denom, s32 *res)
973 *res = ((num * 2 + denom) / (denom * 2)) * sign;
979 * iwl4965_get_voltage_compensation - Power supply voltage comp for txpower
981 * Determines power supply voltage compensation for txpower calculations.
982 * Returns number of 1/2-dB steps to subtract from gain table index,
983 * to compensate for difference between power supply voltage during
984 * factory measurements, vs. current power supply voltage.
986 * Voltage indication is higher for lower voltage.
987 * Lower voltage requires more gain (lower gain table index).
989 static s32 iwl4965_get_voltage_compensation(s32 eeprom_voltage,
994 if ((TX_POWER_IWL_ILLEGAL_VOLTAGE == eeprom_voltage) ||
995 (TX_POWER_IWL_ILLEGAL_VOLTAGE == current_voltage))
998 iwl4965_math_div_round(current_voltage - eeprom_voltage,
999 TX_POWER_IWL_VOLTAGE_CODES_PER_03V, &comp);
1001 if (current_voltage > eeprom_voltage)
1003 if ((comp < -2) || (comp > 2))
1009 static const struct iwl_channel_info *
1010 iwl4965_get_channel_txpower_info(struct iwl_priv *priv,
1011 enum ieee80211_band band, u16 channel)
1013 const struct iwl_channel_info *ch_info;
1015 ch_info = iwl_get_channel_info(priv, band, channel);
1017 if (!is_channel_valid(ch_info))
1023 static s32 iwl4965_get_tx_atten_grp(u16 channel)
1025 if (channel >= CALIB_IWL_TX_ATTEN_GR5_FCH &&
1026 channel <= CALIB_IWL_TX_ATTEN_GR5_LCH)
1027 return CALIB_CH_GROUP_5;
1029 if (channel >= CALIB_IWL_TX_ATTEN_GR1_FCH &&
1030 channel <= CALIB_IWL_TX_ATTEN_GR1_LCH)
1031 return CALIB_CH_GROUP_1;
1033 if (channel >= CALIB_IWL_TX_ATTEN_GR2_FCH &&
1034 channel <= CALIB_IWL_TX_ATTEN_GR2_LCH)
1035 return CALIB_CH_GROUP_2;
1037 if (channel >= CALIB_IWL_TX_ATTEN_GR3_FCH &&
1038 channel <= CALIB_IWL_TX_ATTEN_GR3_LCH)
1039 return CALIB_CH_GROUP_3;
1041 if (channel >= CALIB_IWL_TX_ATTEN_GR4_FCH &&
1042 channel <= CALIB_IWL_TX_ATTEN_GR4_LCH)
1043 return CALIB_CH_GROUP_4;
1045 IWL_ERROR("Can't find txatten group for channel %d.\n", channel);
1049 static u32 iwl4965_get_sub_band(const struct iwl_priv *priv, u32 channel)
1053 for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) {
1054 if (priv->calib_info->band_info[b].ch_from == 0)
1057 if ((channel >= priv->calib_info->band_info[b].ch_from)
1058 && (channel <= priv->calib_info->band_info[b].ch_to))
1065 static s32 iwl4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
1072 iwl4965_math_div_round((x2 - x) * (y1 - y2), (x2 - x1), &val);
1078 * iwl4965_interpolate_chan - Interpolate factory measurements for one channel
1080 * Interpolates factory measurements from the two sample channels within a
1081 * sub-band, to apply to channel of interest. Interpolation is proportional to
1082 * differences in channel frequencies, which is proportional to differences
1083 * in channel number.
1085 static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
1086 struct iwl_eeprom_calib_ch_info *chan_info)
1091 const struct iwl_eeprom_calib_measure *m1;
1092 const struct iwl_eeprom_calib_measure *m2;
1093 struct iwl_eeprom_calib_measure *omeas;
1097 s = iwl4965_get_sub_band(priv, channel);
1098 if (s >= EEPROM_TX_POWER_BANDS) {
1099 IWL_ERROR("Tx Power can not find channel %d ", channel);
1103 ch_i1 = priv->calib_info->band_info[s].ch1.ch_num;
1104 ch_i2 = priv->calib_info->band_info[s].ch2.ch_num;
1105 chan_info->ch_num = (u8) channel;
1107 IWL_DEBUG_TXPOWER("channel %d subband %d factory cal ch %d & %d\n",
1108 channel, s, ch_i1, ch_i2);
1110 for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) {
1111 for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) {
1112 m1 = &(priv->calib_info->band_info[s].ch1.
1113 measurements[c][m]);
1114 m2 = &(priv->calib_info->band_info[s].ch2.
1115 measurements[c][m]);
1116 omeas = &(chan_info->measurements[c][m]);
1119 (u8) iwl4965_interpolate_value(channel, ch_i1,
1124 (u8) iwl4965_interpolate_value(channel, ch_i1,
1125 m1->gain_idx, ch_i2,
1127 omeas->temperature =
1128 (u8) iwl4965_interpolate_value(channel, ch_i1,
1133 (s8) iwl4965_interpolate_value(channel, ch_i1,
1138 ("chain %d meas %d AP1=%d AP2=%d AP=%d\n", c, m,
1139 m1->actual_pow, m2->actual_pow, omeas->actual_pow);
1141 ("chain %d meas %d NI1=%d NI2=%d NI=%d\n", c, m,
1142 m1->gain_idx, m2->gain_idx, omeas->gain_idx);
1144 ("chain %d meas %d PA1=%d PA2=%d PA=%d\n", c, m,
1145 m1->pa_det, m2->pa_det, omeas->pa_det);
1147 ("chain %d meas %d T1=%d T2=%d T=%d\n", c, m,
1148 m1->temperature, m2->temperature,
1149 omeas->temperature);
1156 /* bit-rate-dependent table to prevent Tx distortion, in half-dB units,
1157 * for OFDM 6, 12, 18, 24, 36, 48, 54, 60 MBit, and CCK all rates. */
1158 static s32 back_off_table[] = {
1159 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 20 MHz */
1160 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 20 MHz */
1161 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 40 MHz */
1162 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 40 MHz */
1166 /* Thermal compensation values for txpower for various frequency ranges ...
1167 * ratios from 3:1 to 4.5:1 of degrees (Celsius) per half-dB gain adjust */
1168 static struct iwl4965_txpower_comp_entry {
1169 s32 degrees_per_05db_a;
1170 s32 degrees_per_05db_a_denom;
1171 } tx_power_cmp_tble[CALIB_CH_GROUP_MAX] = {
1172 {9, 2}, /* group 0 5.2, ch 34-43 */
1173 {4, 1}, /* group 1 5.2, ch 44-70 */
1174 {4, 1}, /* group 2 5.2, ch 71-124 */
1175 {4, 1}, /* group 3 5.2, ch 125-200 */
1176 {3, 1} /* group 4 2.4, ch all */
1179 static s32 get_min_power_index(s32 rate_power_index, u32 band)
1182 if ((rate_power_index & 7) <= 4)
1183 return MIN_TX_GAIN_INDEX_52GHZ_EXT;
1185 return MIN_TX_GAIN_INDEX;
1193 static const struct gain_entry gain_table[2][108] = {
1194 /* 5.2GHz power gain index table */
1196 {123, 0x3F}, /* highest txpower */
1305 /* 2.4GHz power gain index table */
1307 {110, 0x3f}, /* highest txpower */
1418 static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
1419 u8 is_fat, u8 ctrl_chan_high,
1420 struct iwl4965_tx_power_db *tx_power_tbl)
1422 u8 saturation_power;
1424 s32 user_target_power;
1428 s32 current_regulatory;
1429 s32 txatten_grp = CALIB_CH_GROUP_MAX;
1432 const struct iwl_channel_info *ch_info = NULL;
1433 struct iwl_eeprom_calib_ch_info ch_eeprom_info;
1434 const struct iwl_eeprom_calib_measure *measurement;
1437 s32 voltage_compensation;
1438 s32 degrees_per_05db_num;
1439 s32 degrees_per_05db_denom;
1441 s32 temperature_comp[2];
1442 s32 factory_gain_index[2];
1443 s32 factory_actual_pwr[2];
1446 /* Sanity check requested level (dBm) */
1447 if (priv->user_txpower_limit < IWL_TX_POWER_TARGET_POWER_MIN) {
1448 IWL_WARNING("Requested user TXPOWER %d below limit.\n",
1449 priv->user_txpower_limit);
1452 if (priv->user_txpower_limit > IWL_TX_POWER_TARGET_POWER_MAX) {
1453 IWL_WARNING("Requested user TXPOWER %d above limit.\n",
1454 priv->user_txpower_limit);
1458 /* user_txpower_limit is in dBm, convert to half-dBm (half-dB units
1459 * are used for indexing into txpower table) */
1460 user_target_power = 2 * priv->user_txpower_limit;
1462 /* Get current (RXON) channel, band, width */
1464 iwl4965_get_channel_txpower_info(priv, priv->band, channel);
1466 IWL_DEBUG_TXPOWER("chan %d band %d is_fat %d\n", channel, band,
1472 /* get txatten group, used to select 1) thermal txpower adjustment
1473 * and 2) mimo txpower balance between Tx chains. */
1474 txatten_grp = iwl4965_get_tx_atten_grp(channel);
1475 if (txatten_grp < 0)
1478 IWL_DEBUG_TXPOWER("channel %d belongs to txatten group %d\n",
1479 channel, txatten_grp);
1488 /* hardware txpower limits ...
1489 * saturation (clipping distortion) txpowers are in half-dBm */
1491 saturation_power = priv->calib_info->saturation_power24;
1493 saturation_power = priv->calib_info->saturation_power52;
1495 if (saturation_power < IWL_TX_POWER_SATURATION_MIN ||
1496 saturation_power > IWL_TX_POWER_SATURATION_MAX) {
1498 saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_24;
1500 saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_52;
1503 /* regulatory txpower limits ... reg_limit values are in half-dBm,
1504 * max_power_avg values are in dBm, convert * 2 */
1506 reg_limit = ch_info->fat_max_power_avg * 2;
1508 reg_limit = ch_info->max_power_avg * 2;
1510 if ((reg_limit < IWL_TX_POWER_REGULATORY_MIN) ||
1511 (reg_limit > IWL_TX_POWER_REGULATORY_MAX)) {
1513 reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_24;
1515 reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_52;
1518 /* Interpolate txpower calibration values for this channel,
1519 * based on factory calibration tests on spaced channels. */
1520 iwl4965_interpolate_chan(priv, channel, &ch_eeprom_info);
1522 /* calculate tx gain adjustment based on power supply voltage */
1523 voltage = priv->calib_info->voltage;
1524 init_voltage = (s32)le32_to_cpu(priv->card_alive_init.voltage);
1525 voltage_compensation =
1526 iwl4965_get_voltage_compensation(voltage, init_voltage);
1528 IWL_DEBUG_TXPOWER("curr volt %d eeprom volt %d volt comp %d\n",
1530 voltage, voltage_compensation);
1532 /* get current temperature (Celsius) */
1533 current_temp = max(priv->temperature, IWL_TX_POWER_TEMPERATURE_MIN);
1534 current_temp = min(priv->temperature, IWL_TX_POWER_TEMPERATURE_MAX);
1535 current_temp = KELVIN_TO_CELSIUS(current_temp);
1537 /* select thermal txpower adjustment params, based on channel group
1538 * (same frequency group used for mimo txatten adjustment) */
1539 degrees_per_05db_num =
1540 tx_power_cmp_tble[txatten_grp].degrees_per_05db_a;
1541 degrees_per_05db_denom =
1542 tx_power_cmp_tble[txatten_grp].degrees_per_05db_a_denom;
1544 /* get per-chain txpower values from factory measurements */
1545 for (c = 0; c < 2; c++) {
1546 measurement = &ch_eeprom_info.measurements[c][1];
1548 /* txgain adjustment (in half-dB steps) based on difference
1549 * between factory and current temperature */
1550 factory_temp = measurement->temperature;
1551 iwl4965_math_div_round((current_temp - factory_temp) *
1552 degrees_per_05db_denom,
1553 degrees_per_05db_num,
1554 &temperature_comp[c]);
1556 factory_gain_index[c] = measurement->gain_idx;
1557 factory_actual_pwr[c] = measurement->actual_pow;
1559 IWL_DEBUG_TXPOWER("chain = %d\n", c);
1560 IWL_DEBUG_TXPOWER("fctry tmp %d, "
1561 "curr tmp %d, comp %d steps\n",
1562 factory_temp, current_temp,
1563 temperature_comp[c]);
1565 IWL_DEBUG_TXPOWER("fctry idx %d, fctry pwr %d\n",
1566 factory_gain_index[c],
1567 factory_actual_pwr[c]);
1570 /* for each of 33 bit-rates (including 1 for CCK) */
1571 for (i = 0; i < POWER_TABLE_NUM_ENTRIES; i++) {
1573 union iwl4965_tx_power_dual_stream tx_power;
1575 /* for mimo, reduce each chain's txpower by half
1576 * (3dB, 6 steps), so total output power is regulatory
1579 current_regulatory = reg_limit -
1580 IWL_TX_POWER_MIMO_REGULATORY_COMPENSATION;
1583 current_regulatory = reg_limit;
1587 /* find txpower limit, either hardware or regulatory */
1588 power_limit = saturation_power - back_off_table[i];
1589 if (power_limit > current_regulatory)
1590 power_limit = current_regulatory;
1592 /* reduce user's txpower request if necessary
1593 * for this rate on this channel */
1594 target_power = user_target_power;
1595 if (target_power > power_limit)
1596 target_power = power_limit;
1598 IWL_DEBUG_TXPOWER("rate %d sat %d reg %d usr %d tgt %d\n",
1599 i, saturation_power - back_off_table[i],
1600 current_regulatory, user_target_power,
1603 /* for each of 2 Tx chains (radio transmitters) */
1604 for (c = 0; c < 2; c++) {
1609 (s32)le32_to_cpu(priv->card_alive_init.
1610 tx_atten[txatten_grp][c]);
1614 /* calculate index; higher index means lower txpower */
1615 power_index = (u8) (factory_gain_index[c] -
1617 factory_actual_pwr[c]) -
1618 temperature_comp[c] -
1619 voltage_compensation +
1622 /* IWL_DEBUG_TXPOWER("calculated txpower index %d\n",
1625 if (power_index < get_min_power_index(i, band))
1626 power_index = get_min_power_index(i, band);
1628 /* adjust 5 GHz index to support negative indexes */
1632 /* CCK, rate 32, reduce txpower for CCK */
1633 if (i == POWER_TABLE_CCK_ENTRY)
1635 IWL_TX_POWER_CCK_COMPENSATION_C_STEP;
1637 /* stay within the table! */
1638 if (power_index > 107) {
1639 IWL_WARNING("txpower index %d > 107\n",
1643 if (power_index < 0) {
1644 IWL_WARNING("txpower index %d < 0\n",
1649 /* fill txpower command for this rate/chain */
1650 tx_power.s.radio_tx_gain[c] =
1651 gain_table[band][power_index].radio;
1652 tx_power.s.dsp_predis_atten[c] =
1653 gain_table[band][power_index].dsp;
1655 IWL_DEBUG_TXPOWER("chain %d mimo %d index %d "
1656 "gain 0x%02x dsp %d\n",
1657 c, atten_value, power_index,
1658 tx_power.s.radio_tx_gain[c],
1659 tx_power.s.dsp_predis_atten[c]);
1660 }/* for each chain */
1662 tx_power_tbl->power_tbl[i].dw = cpu_to_le32(tx_power.dw);
1664 }/* for each rate */
1670 * iwl4965_hw_reg_send_txpower - Configure the TXPOWER level user limit
1672 * Uses the active RXON for channel, band, and characteristics (fat, high)
1673 * The power limit is taken from priv->user_txpower_limit.
1675 int iwl4965_hw_reg_send_txpower(struct iwl_priv *priv)
1677 struct iwl4965_txpowertable_cmd cmd = { 0 };
1681 u8 ctrl_chan_high = 0;
1683 if (test_bit(STATUS_SCANNING, &priv->status)) {
1684 /* If this gets hit a lot, switch it to a BUG() and catch
1685 * the stack trace to find out who is calling this during
1687 IWL_WARNING("TX Power requested while scanning!\n");
1691 band = priv->band == IEEE80211_BAND_2GHZ;
1693 is_fat = is_fat_channel(priv->active_rxon.flags);
1696 (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
1700 cmd.channel = priv->active_rxon.channel;
1702 ret = iwl4965_fill_txpower_tbl(priv, band,
1703 le16_to_cpu(priv->active_rxon.channel),
1704 is_fat, ctrl_chan_high, &cmd.tx_power);
1708 ret = iwl_send_cmd_pdu(priv, REPLY_TX_PWR_TABLE_CMD, sizeof(cmd), &cmd);
1714 static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
1717 struct iwl4965_rxon_assoc_cmd rxon_assoc;
1718 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
1719 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
1721 if ((rxon1->flags == rxon2->flags) &&
1722 (rxon1->filter_flags == rxon2->filter_flags) &&
1723 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
1724 (rxon1->ofdm_ht_single_stream_basic_rates ==
1725 rxon2->ofdm_ht_single_stream_basic_rates) &&
1726 (rxon1->ofdm_ht_dual_stream_basic_rates ==
1727 rxon2->ofdm_ht_dual_stream_basic_rates) &&
1728 (rxon1->rx_chain == rxon2->rx_chain) &&
1729 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
1730 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1734 rxon_assoc.flags = priv->staging_rxon.flags;
1735 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
1736 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
1737 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
1738 rxon_assoc.reserved = 0;
1739 rxon_assoc.ofdm_ht_single_stream_basic_rates =
1740 priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
1741 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
1742 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
1743 rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
1745 ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
1746 sizeof(rxon_assoc), &rxon_assoc, NULL);
1754 int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel)
1759 u8 ctrl_chan_high = 0;
1760 struct iwl4965_channel_switch_cmd cmd = { 0 };
1761 const struct iwl_channel_info *ch_info;
1763 band = priv->band == IEEE80211_BAND_2GHZ;
1765 ch_info = iwl_get_channel_info(priv, priv->band, channel);
1767 is_fat = is_fat_channel(priv->staging_rxon.flags);
1770 (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
1774 cmd.expect_beacon = 0;
1775 cmd.channel = cpu_to_le16(channel);
1776 cmd.rxon_flags = priv->active_rxon.flags;
1777 cmd.rxon_filter_flags = priv->active_rxon.filter_flags;
1778 cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
1780 cmd.expect_beacon = is_channel_radar(ch_info);
1782 cmd.expect_beacon = 1;
1784 rc = iwl4965_fill_txpower_tbl(priv, band, channel, is_fat,
1785 ctrl_chan_high, &cmd.tx_power);
1787 IWL_DEBUG_11H("error:%d fill txpower_tbl\n", rc);
1791 rc = iwl_send_cmd_pdu(priv, REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd);
1795 static int iwl4965_shared_mem_rx_idx(struct iwl_priv *priv)
1797 struct iwl4965_shared *s = priv->shared_virt;
1798 return le32_to_cpu(s->rb_closed) & 0xFFF;
1801 int iwl4965_hw_get_temperature(struct iwl_priv *priv)
1803 return priv->temperature;
1806 unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
1807 struct iwl_frame *frame, u8 rate)
1809 struct iwl4965_tx_beacon_cmd *tx_beacon_cmd;
1810 unsigned int frame_size;
1812 tx_beacon_cmd = &frame->u.beacon;
1813 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
1815 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
1816 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
1818 frame_size = iwl4965_fill_beacon_frame(priv,
1819 tx_beacon_cmd->frame,
1821 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
1823 BUG_ON(frame_size > MAX_MPDU_SIZE);
1824 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
1826 if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
1827 tx_beacon_cmd->tx.rate_n_flags =
1828 iwl4965_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
1830 tx_beacon_cmd->tx.rate_n_flags =
1831 iwl4965_hw_set_rate_n_flags(rate, 0);
1833 tx_beacon_cmd->tx.tx_flags = (TX_CMD_FLG_SEQ_CTL_MSK |
1834 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK);
1835 return (sizeof(*tx_beacon_cmd) + frame_size);
1838 static int iwl4965_alloc_shared_mem(struct iwl_priv *priv)
1840 priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
1841 sizeof(struct iwl4965_shared),
1842 &priv->shared_phys);
1843 if (!priv->shared_virt)
1846 memset(priv->shared_virt, 0, sizeof(struct iwl4965_shared));
1848 priv->rb_closed_offset = offsetof(struct iwl4965_shared, rb_closed);
1853 static void iwl4965_free_shared_mem(struct iwl_priv *priv)
1855 if (priv->shared_virt)
1856 pci_free_consistent(priv->pci_dev,
1857 sizeof(struct iwl4965_shared),
1863 * iwl4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
1865 static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
1866 struct iwl_tx_queue *txq,
1870 int txq_id = txq->q.id;
1871 struct iwl4965_shared *shared_data = priv->shared_virt;
1873 len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
1875 /* Set up byte count within first 256 entries */
1876 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
1877 tfd_offset[txq->q.write_ptr], byte_cnt, len);
1879 /* If within first 64 entries, duplicate at end */
1880 if (txq->q.write_ptr < IWL49_MAX_WIN_SIZE)
1881 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
1882 tfd_offset[IWL49_QUEUE_SIZE + txq->q.write_ptr],
1887 * sign_extend - Sign extend a value using specified bit as sign-bit
1889 * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1
1890 * and bit0..2 is 001b which when sign extended to 1111111111111001b is -7.
1892 * @param oper value to sign extend
1893 * @param index 0 based bit index (0<=index<32) to sign bit
1895 static s32 sign_extend(u32 oper, int index)
1897 u8 shift = 31 - index;
1899 return (s32)(oper << shift) >> shift;
1903 * iwl4965_get_temperature - return the calibrated temperature (in Kelvin)
1904 * @statistics: Provides the temperature reading from the uCode
1906 * A return of <0 indicates bogus data in the statistics
1908 int iwl4965_get_temperature(const struct iwl_priv *priv)
1915 if (test_bit(STATUS_TEMPERATURE, &priv->status) &&
1916 (priv->statistics.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)) {
1917 IWL_DEBUG_TEMP("Running FAT temperature calibration\n");
1918 R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[1]);
1919 R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[1]);
1920 R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[1]);
1921 R4 = le32_to_cpu(priv->card_alive_init.therm_r4[1]);
1923 IWL_DEBUG_TEMP("Running temperature calibration\n");
1924 R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[0]);
1925 R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[0]);
1926 R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[0]);
1927 R4 = le32_to_cpu(priv->card_alive_init.therm_r4[0]);
1931 * Temperature is only 23 bits, so sign extend out to 32.
1933 * NOTE If we haven't received a statistics notification yet
1934 * with an updated temperature, use R4 provided to us in the
1935 * "initialize" ALIVE response.
1937 if (!test_bit(STATUS_TEMPERATURE, &priv->status))
1938 vt = sign_extend(R4, 23);
1941 le32_to_cpu(priv->statistics.general.temperature), 23);
1943 IWL_DEBUG_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n",
1947 IWL_ERROR("Calibration conflict R1 == R3\n");
1951 /* Calculate temperature in degrees Kelvin, adjust by 97%.
1952 * Add offset to center the adjustment around 0 degrees Centigrade. */
1953 temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2);
1954 temperature /= (R3 - R1);
1955 temperature = (temperature * 97) / 100 +
1956 TEMPERATURE_CALIB_KELVIN_OFFSET;
1958 IWL_DEBUG_TEMP("Calibrated temperature: %dK, %dC\n", temperature,
1959 KELVIN_TO_CELSIUS(temperature));
1964 /* Adjust Txpower only if temperature variance is greater than threshold. */
1965 #define IWL_TEMPERATURE_THRESHOLD 3
1968 * iwl4965_is_temp_calib_needed - determines if new calibration is needed
1970 * If the temperature changed has changed sufficiently, then a recalibration
1973 * Assumes caller will replace priv->last_temperature once calibration
1976 static int iwl4965_is_temp_calib_needed(struct iwl_priv *priv)
1980 if (!test_bit(STATUS_STATISTICS, &priv->status)) {
1981 IWL_DEBUG_TEMP("Temperature not updated -- no statistics.\n");
1985 temp_diff = priv->temperature - priv->last_temperature;
1987 /* get absolute value */
1988 if (temp_diff < 0) {
1989 IWL_DEBUG_POWER("Getting cooler, delta %d, \n", temp_diff);
1990 temp_diff = -temp_diff;
1991 } else if (temp_diff == 0)
1992 IWL_DEBUG_POWER("Same temp, \n");
1994 IWL_DEBUG_POWER("Getting warmer, delta %d, \n", temp_diff);
1996 if (temp_diff < IWL_TEMPERATURE_THRESHOLD) {
1997 IWL_DEBUG_POWER("Thermal txpower calib not needed\n");
2001 IWL_DEBUG_POWER("Thermal txpower calib needed\n");
2006 /* Calculate noise level, based on measurements during network silence just
2007 * before arriving beacon. This measurement can be done only if we know
2008 * exactly when to expect beacons, therefore only when we're associated. */
2009 static void iwl4965_rx_calc_noise(struct iwl_priv *priv)
2011 struct statistics_rx_non_phy *rx_info
2012 = &(priv->statistics.rx.general);
2013 int num_active_rx = 0;
2014 int total_silence = 0;
2016 le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
2018 le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
2020 le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
2022 if (bcn_silence_a) {
2023 total_silence += bcn_silence_a;
2026 if (bcn_silence_b) {
2027 total_silence += bcn_silence_b;
2030 if (bcn_silence_c) {
2031 total_silence += bcn_silence_c;
2035 /* Average among active antennas */
2037 priv->last_rx_noise = (total_silence / num_active_rx) - 107;
2039 priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
2041 IWL_DEBUG_CALIB("inband silence a %u, b %u, c %u, dBm %d\n",
2042 bcn_silence_a, bcn_silence_b, bcn_silence_c,
2043 priv->last_rx_noise);
2046 void iwl4965_hw_rx_statistics(struct iwl_priv *priv,
2047 struct iwl_rx_mem_buffer *rxb)
2049 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2053 IWL_DEBUG_RX("Statistics notification received (%d vs %d).\n",
2054 (int)sizeof(priv->statistics), pkt->len);
2056 change = ((priv->statistics.general.temperature !=
2057 pkt->u.stats.general.temperature) ||
2058 ((priv->statistics.flag &
2059 STATISTICS_REPLY_FLG_FAT_MODE_MSK) !=
2060 (pkt->u.stats.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)));
2062 memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics));
2064 set_bit(STATUS_STATISTICS, &priv->status);
2066 /* Reschedule the statistics timer to occur in
2067 * REG_RECALIB_PERIOD seconds to ensure we get a
2068 * thermal update even if the uCode doesn't give
2070 mod_timer(&priv->statistics_periodic, jiffies +
2071 msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
2073 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
2074 (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
2075 iwl4965_rx_calc_noise(priv);
2076 queue_work(priv->workqueue, &priv->run_time_calib_work);
2079 iwl_leds_background(priv);
2081 /* If the hardware hasn't reported a change in
2082 * temperature then don't bother computing a
2083 * calibrated temperature value */
2087 temp = iwl4965_get_temperature(priv);
2091 if (priv->temperature != temp) {
2092 if (priv->temperature)
2093 IWL_DEBUG_TEMP("Temperature changed "
2094 "from %dC to %dC\n",
2095 KELVIN_TO_CELSIUS(priv->temperature),
2096 KELVIN_TO_CELSIUS(temp));
2098 IWL_DEBUG_TEMP("Temperature "
2099 "initialized to %dC\n",
2100 KELVIN_TO_CELSIUS(temp));
2103 priv->temperature = temp;
2104 set_bit(STATUS_TEMPERATURE, &priv->status);
2106 if (!priv->disable_tx_power_cal &&
2107 unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
2108 iwl4965_is_temp_calib_needed(priv))
2109 queue_work(priv->workqueue, &priv->txpower_work);
2112 static void iwl4965_add_radiotap(struct iwl_priv *priv,
2113 struct sk_buff *skb,
2114 struct iwl4965_rx_phy_res *rx_start,
2115 struct ieee80211_rx_status *stats,
2118 s8 signal = stats->signal;
2120 int rate = stats->rate_idx;
2121 u64 tsf = stats->mactime;
2123 __le16 phy_flags_hw = rx_start->phy_flags;
2124 struct iwl4965_rt_rx_hdr {
2125 struct ieee80211_radiotap_header rt_hdr;
2126 __le64 rt_tsf; /* TSF */
2127 u8 rt_flags; /* radiotap packet flags */
2128 u8 rt_rate; /* rate in 500kb/s */
2129 __le16 rt_channelMHz; /* channel in MHz */
2130 __le16 rt_chbitmask; /* channel bitfield */
2131 s8 rt_dbmsignal; /* signal in dBm, kluged to signed */
2133 u8 rt_antenna; /* antenna number */
2134 } __attribute__ ((packed)) *iwl4965_rt;
2136 /* TODO: We won't have enough headroom for HT frames. Fix it later. */
2137 if (skb_headroom(skb) < sizeof(*iwl4965_rt)) {
2138 if (net_ratelimit())
2139 printk(KERN_ERR "not enough headroom [%d] for "
2140 "radiotap head [%zd]\n",
2141 skb_headroom(skb), sizeof(*iwl4965_rt));
2145 /* put radiotap header in front of 802.11 header and data */
2146 iwl4965_rt = (void *)skb_push(skb, sizeof(*iwl4965_rt));
2148 /* initialise radiotap header */
2149 iwl4965_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
2150 iwl4965_rt->rt_hdr.it_pad = 0;
2152 /* total header + data */
2153 put_unaligned(cpu_to_le16(sizeof(*iwl4965_rt)),
2154 &iwl4965_rt->rt_hdr.it_len);
2156 /* Indicate all the fields we add to the radiotap header */
2157 put_unaligned(cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) |
2158 (1 << IEEE80211_RADIOTAP_FLAGS) |
2159 (1 << IEEE80211_RADIOTAP_RATE) |
2160 (1 << IEEE80211_RADIOTAP_CHANNEL) |
2161 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
2162 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
2163 (1 << IEEE80211_RADIOTAP_ANTENNA)),
2164 &iwl4965_rt->rt_hdr.it_present);
2166 /* Zero the flags, we'll add to them as we go */
2167 iwl4965_rt->rt_flags = 0;
2169 put_unaligned(cpu_to_le64(tsf), &iwl4965_rt->rt_tsf);
2171 iwl4965_rt->rt_dbmsignal = signal;
2172 iwl4965_rt->rt_dbmnoise = noise;
2174 /* Convert the channel frequency and set the flags */
2175 put_unaligned(cpu_to_le16(stats->freq), &iwl4965_rt->rt_channelMHz);
2176 if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK))
2177 put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM |
2178 IEEE80211_CHAN_5GHZ),
2179 &iwl4965_rt->rt_chbitmask);
2180 else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK)
2181 put_unaligned(cpu_to_le16(IEEE80211_CHAN_CCK |
2182 IEEE80211_CHAN_2GHZ),
2183 &iwl4965_rt->rt_chbitmask);
2185 put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM |
2186 IEEE80211_CHAN_2GHZ),
2187 &iwl4965_rt->rt_chbitmask);
2190 iwl4965_rt->rt_rate = 0;
2192 iwl4965_rt->rt_rate = iwl_rates[rate].ieee;
2197 * It seems that the antenna field in the phy flags value
2198 * is actually a bitfield. This is undefined by radiotap,
2199 * it wants an actual antenna number but I always get "7"
2200 * for most legacy frames I receive indicating that the
2201 * same frame was received on all three RX chains.
2203 * I think this field should be removed in favour of a
2204 * new 802.11n radiotap field "RX chains" that is defined
2207 antenna = phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK;
2208 iwl4965_rt->rt_antenna = le16_to_cpu(antenna) >> 4;
2210 /* set the preamble flag if appropriate */
2211 if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
2212 iwl4965_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
2214 stats->flag |= RX_FLAG_RADIOTAP;
2217 static void iwl_update_rx_stats(struct iwl_priv *priv, u16 fc, u16 len)
2219 /* 0 - mgmt, 1 - cnt, 2 - data */
2220 int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
2221 priv->rx_stats[idx].cnt++;
2222 priv->rx_stats[idx].bytes += len;
2226 * returns non-zero if packet should be dropped
2228 static int iwl4965_set_decrypted_flag(struct iwl_priv *priv,
2229 struct ieee80211_hdr *hdr,
2231 struct ieee80211_rx_status *stats)
2233 u16 fc = le16_to_cpu(hdr->frame_control);
2235 if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
2238 if (!(fc & IEEE80211_FCTL_PROTECTED))
2241 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
2242 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
2243 case RX_RES_STATUS_SEC_TYPE_TKIP:
2244 /* The uCode has got a bad phase 1 Key, pushes the packet.
2245 * Decryption will be done in SW. */
2246 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2247 RX_RES_STATUS_BAD_KEY_TTAK)
2250 case RX_RES_STATUS_SEC_TYPE_WEP:
2251 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2252 RX_RES_STATUS_BAD_ICV_MIC) {
2253 /* bad ICV, the packet is destroyed since the
2254 * decryption is inplace, drop it */
2255 IWL_DEBUG_RX("Packet destroyed\n");
2258 case RX_RES_STATUS_SEC_TYPE_CCMP:
2259 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2260 RX_RES_STATUS_DECRYPT_OK) {
2261 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2262 stats->flag |= RX_FLAG_DECRYPTED;
2272 static u32 iwl4965_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
2274 u32 decrypt_out = 0;
2276 if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
2277 RX_RES_STATUS_STATION_FOUND)
2278 decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
2279 RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
2281 decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
2283 /* packet was not encrypted */
2284 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
2285 RX_RES_STATUS_SEC_TYPE_NONE)
2288 /* packet was encrypted with unknown alg */
2289 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
2290 RX_RES_STATUS_SEC_TYPE_ERR)
2293 /* decryption was not done in HW */
2294 if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
2295 RX_MPDU_RES_STATUS_DEC_DONE_MSK)
2298 switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
2300 case RX_RES_STATUS_SEC_TYPE_CCMP:
2301 /* alg is CCM: check MIC only */
2302 if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
2304 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
2306 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
2310 case RX_RES_STATUS_SEC_TYPE_TKIP:
2311 if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
2313 decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
2316 /* fall through if TTAK OK */
2318 if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
2319 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
2321 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
2325 IWL_DEBUG_RX("decrypt_in:0x%x decrypt_out = 0x%x\n",
2326 decrypt_in, decrypt_out);
2331 static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data,
2333 struct iwl_rx_mem_buffer *rxb,
2334 struct ieee80211_rx_status *stats)
2336 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2337 struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
2338 (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) : NULL;
2339 struct ieee80211_hdr *hdr;
2342 unsigned int skblen;
2344 u32 ampdu_status_legacy;
2346 if (!include_phy && priv->last_phy_res[0])
2347 rx_start = (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
2350 IWL_ERROR("MPDU frame without a PHY data\n");
2354 hdr = (struct ieee80211_hdr *)((u8 *) & rx_start[1] +
2355 rx_start->cfg_phy_cnt);
2357 len = le16_to_cpu(rx_start->byte_count);
2359 rx_end = (__le32 *) ((u8 *) & pkt->u.raw[0] +
2360 sizeof(struct iwl4965_rx_phy_res) +
2361 rx_start->cfg_phy_cnt + len);
2364 struct iwl4965_rx_mpdu_res_start *amsdu =
2365 (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
2367 hdr = (struct ieee80211_hdr *)(pkt->u.raw +
2368 sizeof(struct iwl4965_rx_mpdu_res_start));
2369 len = le16_to_cpu(amsdu->byte_count);
2370 rx_start->byte_count = amsdu->byte_count;
2371 rx_end = (__le32 *) (((u8 *) hdr) + len);
2373 /* In monitor mode allow 802.11 ACk frames (10 bytes) */
2374 if (len > priv->hw_params.max_pkt_size ||
2375 len < ((priv->iw_mode == IEEE80211_IF_TYPE_MNTR) ? 10 : 16)) {
2376 IWL_WARNING("byte count out of range [16,4K] : %d\n", len);
2380 ampdu_status = le32_to_cpu(*rx_end);
2381 skblen = ((u8 *) rx_end - (u8 *) & pkt->u.raw[0]) + sizeof(u32);
2384 /* New status scheme, need to translate */
2385 ampdu_status_legacy = ampdu_status;
2386 ampdu_status = iwl4965_translate_rx_status(priv, ampdu_status);
2389 /* start from MAC */
2390 skb_reserve(rxb->skb, (void *)hdr - (void *)pkt);
2391 skb_put(rxb->skb, len); /* end where data ends */
2393 /* We only process data packets if the interface is open */
2394 if (unlikely(!priv->is_open)) {
2395 IWL_DEBUG_DROP_LIMIT
2396 ("Dropping packet while interface is not open.\n");
2401 hdr = (struct ieee80211_hdr *)rxb->skb->data;
2403 /* in case of HW accelerated crypto and bad decryption, drop */
2404 if (!priv->hw_params.sw_crypto &&
2405 iwl4965_set_decrypted_flag(priv, hdr, ampdu_status, stats))
2408 if (priv->add_radiotap)
2409 iwl4965_add_radiotap(priv, rxb->skb, rx_start, stats, ampdu_status);
2411 iwl_update_rx_stats(priv, le16_to_cpu(hdr->frame_control), len);
2412 ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
2413 priv->alloc_rxb_skb--;
2417 /* Calc max signal level (dBm) among 3 possible receivers */
2418 static int iwl4965_calc_rssi(struct iwl_priv *priv,
2419 struct iwl4965_rx_phy_res *rx_resp)
2421 /* data from PHY/DSP regarding signal strength, etc.,
2422 * contents are always there, not configurable by host. */
2423 struct iwl4965_rx_non_cfg_phy *ncphy =
2424 (struct iwl4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy;
2425 u32 agc = (le16_to_cpu(ncphy->agc_info) & IWL_AGC_DB_MASK)
2428 u32 valid_antennae =
2429 (le16_to_cpu(rx_resp->phy_flags) & RX_PHY_FLAGS_ANTENNAE_MASK)
2430 >> RX_PHY_FLAGS_ANTENNAE_OFFSET;
2434 /* Find max rssi among 3 possible receivers.
2435 * These values are measured by the digital signal processor (DSP).
2436 * They should stay fairly constant even as the signal strength varies,
2437 * if the radio's automatic gain control (AGC) is working right.
2438 * AGC value (see below) will provide the "interesting" info. */
2439 for (i = 0; i < 3; i++)
2440 if (valid_antennae & (1 << i))
2441 max_rssi = max(ncphy->rssi_info[i << 1], max_rssi);
2443 IWL_DEBUG_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
2444 ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4],
2447 /* dBm = max_rssi dB - agc dB - constant.
2448 * Higher AGC (higher radio gain) means lower signal. */
2449 return (max_rssi - agc - IWL_RSSI_OFFSET);
2452 static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
2454 unsigned long flags;
2456 spin_lock_irqsave(&priv->sta_lock, flags);
2457 priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
2458 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
2459 priv->stations[sta_id].sta.sta.modify_mask = 0;
2460 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
2461 spin_unlock_irqrestore(&priv->sta_lock, flags);
2463 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
2466 static void iwl4965_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
2468 /* FIXME: need locking over ps_status ??? */
2469 u8 sta_id = iwl_find_station(priv, addr);
2471 if (sta_id != IWL_INVALID_STATION) {
2472 u8 sta_awake = priv->stations[sta_id].
2473 ps_status == STA_PS_STATUS_WAKE;
2475 if (sta_awake && ps_bit)
2476 priv->stations[sta_id].ps_status = STA_PS_STATUS_SLEEP;
2477 else if (!sta_awake && !ps_bit) {
2478 iwl4965_sta_modify_ps_wake(priv, sta_id);
2479 priv->stations[sta_id].ps_status = STA_PS_STATUS_WAKE;
2483 #ifdef CONFIG_IWLWIFI_DEBUG
2486 * iwl4965_dbg_report_frame - dump frame to syslog during debug sessions
2488 * You may hack this function to show different aspects of received frames,
2489 * including selective frame dumps.
2490 * group100 parameter selects whether to show 1 out of 100 good frames.
2492 * TODO: This was originally written for 3945, need to audit for
2493 * proper operation with 4965.
2495 static void iwl4965_dbg_report_frame(struct iwl_priv *priv,
2496 struct iwl_rx_packet *pkt,
2497 struct ieee80211_hdr *header, int group100)
2500 u32 print_summary = 0;
2501 u32 print_dump = 0; /* set to 1 to dump all frames' contents */
2518 struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
2519 struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
2520 struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt);
2521 u8 *data = IWL_RX_DATA(pkt);
2523 if (likely(!(priv->debug_level & IWL_DL_RX)))
2527 fc = le16_to_cpu(header->frame_control);
2528 seq_ctl = le16_to_cpu(header->seq_ctrl);
2531 channel = le16_to_cpu(rx_hdr->channel);
2532 phy_flags = le16_to_cpu(rx_hdr->phy_flags);
2533 rate_sym = rx_hdr->rate;
2534 length = le16_to_cpu(rx_hdr->len);
2536 /* end-of-frame status and timestamp */
2537 status = le32_to_cpu(rx_end->status);
2538 bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
2539 tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
2540 tsf = le64_to_cpu(rx_end->timestamp);
2542 /* signal statistics */
2543 rssi = rx_stats->rssi;
2544 agc = rx_stats->agc;
2545 sig_avg = le16_to_cpu(rx_stats->sig_avg);
2546 noise_diff = le16_to_cpu(rx_stats->noise_diff);
2548 to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
2550 /* if data frame is to us and all is good,
2551 * (optionally) print summary for only 1 out of every 100 */
2552 if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) ==
2553 (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
2556 print_summary = 1; /* print each frame */
2557 else if (priv->framecnt_to_us < 100) {
2558 priv->framecnt_to_us++;
2561 priv->framecnt_to_us = 0;
2566 /* print summary for all other frames */
2570 if (print_summary) {
2576 title = "100Frames";
2577 else if (fc & IEEE80211_FCTL_RETRY)
2579 else if (ieee80211_is_assoc_response(fc))
2581 else if (ieee80211_is_reassoc_response(fc))
2583 else if (ieee80211_is_probe_response(fc)) {
2585 print_dump = 1; /* dump frame contents */
2586 } else if (ieee80211_is_beacon(fc)) {
2588 print_dump = 1; /* dump frame contents */
2589 } else if (ieee80211_is_atim(fc))
2591 else if (ieee80211_is_auth(fc))
2593 else if (ieee80211_is_deauth(fc))
2595 else if (ieee80211_is_disassoc(fc))
2600 rate_idx = iwl4965_hwrate_to_plcp_idx(rate_sym);
2601 if (unlikely(rate_idx == -1))
2604 bitrate = iwl_rates[rate_idx].ieee / 2;
2606 /* print frame summary.
2607 * MAC addresses show just the last byte (for brevity),
2608 * but you can hack it to show more, if you'd like to. */
2610 IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
2611 "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
2612 title, fc, header->addr1[5],
2613 length, rssi, channel, bitrate);
2615 /* src/dst addresses assume managed mode */
2616 IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
2617 "src=0x%02x, rssi=%u, tim=%lu usec, "
2618 "phy=0x%02x, chnl=%d\n",
2619 title, fc, header->addr1[5],
2620 header->addr3[5], rssi,
2621 tsf_low - priv->scan_start_tsf,
2622 phy_flags, channel);
2626 iwl_print_hex_dump(priv, IWL_DL_RX, data, length);
2629 static inline void iwl4965_dbg_report_frame(struct iwl_priv *priv,
2630 struct iwl_rx_packet *pkt,
2631 struct ieee80211_hdr *header,
2639 /* Called for REPLY_RX (legacy ABG frames), or
2640 * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
2641 void iwl4965_rx_reply_rx(struct iwl_priv *priv,
2642 struct iwl_rx_mem_buffer *rxb)
2644 struct ieee80211_hdr *header;
2645 struct ieee80211_rx_status rx_status;
2646 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2647 /* Use phy data (Rx signal strength, etc.) contained within
2648 * this rx packet for legacy frames,
2649 * or phy data cached from REPLY_RX_PHY_CMD for HT frames. */
2650 int include_phy = (pkt->hdr.cmd == REPLY_RX);
2651 struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
2652 (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) :
2653 (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
2655 unsigned int len = 0;
2659 rx_status.mactime = le64_to_cpu(rx_start->timestamp);
2661 ieee80211_channel_to_frequency(le16_to_cpu(rx_start->channel));
2662 rx_status.band = (rx_start->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
2663 IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
2664 rx_status.rate_idx =
2665 iwl4965_hwrate_to_plcp_idx(le32_to_cpu(rx_start->rate_n_flags));
2666 if (rx_status.band == IEEE80211_BAND_5GHZ)
2667 rx_status.rate_idx -= IWL_FIRST_OFDM_RATE;
2669 rx_status.antenna = 0;
2672 if ((unlikely(rx_start->cfg_phy_cnt > 20))) {
2673 IWL_DEBUG_DROP("dsp size out of range [0,20]: %d/n",
2674 rx_start->cfg_phy_cnt);
2679 if (priv->last_phy_res[0])
2680 rx_start = (struct iwl4965_rx_phy_res *)
2681 &priv->last_phy_res[1];
2687 IWL_ERROR("MPDU frame without a PHY data\n");
2692 header = (struct ieee80211_hdr *)((u8 *) & rx_start[1]
2693 + rx_start->cfg_phy_cnt);
2695 len = le16_to_cpu(rx_start->byte_count);
2696 rx_end = (__le32 *)(pkt->u.raw + rx_start->cfg_phy_cnt +
2697 sizeof(struct iwl4965_rx_phy_res) + len);
2699 struct iwl4965_rx_mpdu_res_start *amsdu =
2700 (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
2702 header = (void *)(pkt->u.raw +
2703 sizeof(struct iwl4965_rx_mpdu_res_start));
2704 len = le16_to_cpu(amsdu->byte_count);
2705 rx_end = (__le32 *) (pkt->u.raw +
2706 sizeof(struct iwl4965_rx_mpdu_res_start) + len);
2709 if (!(*rx_end & RX_RES_STATUS_NO_CRC32_ERROR) ||
2710 !(*rx_end & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
2711 IWL_DEBUG_RX("Bad CRC or FIFO: 0x%08X.\n",
2712 le32_to_cpu(*rx_end));
2716 priv->ucode_beacon_time = le32_to_cpu(rx_start->beacon_time_stamp);
2718 /* Find max signal strength (dBm) among 3 antenna/receiver chains */
2719 rx_status.signal = iwl4965_calc_rssi(priv, rx_start);
2721 /* Meaningful noise values are available only from beacon statistics,
2722 * which are gathered only when associated, and indicate noise
2723 * only for the associated network channel ...
2724 * Ignore these noise values while scanning (other channels) */
2725 if (iwl_is_associated(priv) &&
2726 !test_bit(STATUS_SCANNING, &priv->status)) {
2727 rx_status.noise = priv->last_rx_noise;
2728 rx_status.qual = iwl4965_calc_sig_qual(rx_status.signal,
2731 rx_status.noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
2732 rx_status.qual = iwl4965_calc_sig_qual(rx_status.signal, 0);
2735 /* Reset beacon noise level if not associated. */
2736 if (!iwl_is_associated(priv))
2737 priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
2739 /* Set "1" to report good data frames in groups of 100 */
2740 /* FIXME: need to optimze the call: */
2741 iwl4965_dbg_report_frame(priv, pkt, header, 1);
2743 IWL_DEBUG_STATS_LIMIT("Rssi %d, noise %d, qual %d, TSF %llu\n",
2744 rx_status.signal, rx_status.noise, rx_status.signal,
2745 (unsigned long long)rx_status.mactime);
2748 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
2749 iwl4965_handle_data_packet(priv, 1, include_phy,
2754 network_packet = iwl4965_is_network_packet(priv, header);
2755 if (network_packet) {
2756 priv->last_rx_rssi = rx_status.signal;
2757 priv->last_beacon_time = priv->ucode_beacon_time;
2758 priv->last_tsf = le64_to_cpu(rx_start->timestamp);
2761 fc = le16_to_cpu(header->frame_control);
2762 switch (fc & IEEE80211_FCTL_FTYPE) {
2763 case IEEE80211_FTYPE_MGMT:
2764 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
2765 iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
2767 iwl4965_handle_data_packet(priv, 0, include_phy, rxb, &rx_status);
2770 case IEEE80211_FTYPE_CTL:
2771 switch (fc & IEEE80211_FCTL_STYPE) {
2772 case IEEE80211_STYPE_BACK_REQ:
2773 IWL_DEBUG_HT("IEEE80211_STYPE_BACK_REQ arrived\n");
2774 iwl4965_handle_data_packet(priv, 0, include_phy,
2782 case IEEE80211_FTYPE_DATA: {
2783 DECLARE_MAC_BUF(mac1);
2784 DECLARE_MAC_BUF(mac2);
2785 DECLARE_MAC_BUF(mac3);
2787 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
2788 iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
2791 if (unlikely(!network_packet))
2792 IWL_DEBUG_DROP("Dropping (non network): "
2794 print_mac(mac1, header->addr1),
2795 print_mac(mac2, header->addr2),
2796 print_mac(mac3, header->addr3));
2797 else if (unlikely(iwl4965_is_duplicate_packet(priv, header)))
2798 IWL_DEBUG_DROP("Dropping (dup): %s, %s, %s\n",
2799 print_mac(mac1, header->addr1),
2800 print_mac(mac2, header->addr2),
2801 print_mac(mac3, header->addr3));
2803 iwl4965_handle_data_packet(priv, 1, include_phy, rxb,
2814 * iwl4965_tx_status_reply_compressed_ba - Update tx status from block-ack
2816 * Go through block-ack's bitmap of ACK'd frames, update driver's record of
2817 * ACK vs. not. This gets sent to mac80211, then to rate scaling algo.
2819 static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv,
2820 struct iwl_ht_agg *agg,
2821 struct iwl4965_compressed_ba_resp*
2826 u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl);
2827 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
2830 struct ieee80211_tx_info *info;
2832 if (unlikely(!agg->wait_for_ba)) {
2833 IWL_ERROR("Received BA when not expected\n");
2837 /* Mark that the expected block-ack response arrived */
2838 agg->wait_for_ba = 0;
2839 IWL_DEBUG_TX_REPLY("BA %d %d\n", agg->start_idx, ba_resp->seq_ctl);
2841 /* Calculate shift to align block-ack bits with our Tx window bits */
2842 sh = agg->start_idx - SEQ_TO_INDEX(seq_ctl>>4);
2843 if (sh < 0) /* tbw something is wrong with indices */
2846 /* don't use 64-bit values for now */
2847 bitmap = le64_to_cpu(ba_resp->bitmap) >> sh;
2849 if (agg->frame_count > (64 - sh)) {
2850 IWL_DEBUG_TX_REPLY("more frames than bitmap size");
2854 /* check for success or failure according to the
2855 * transmitted bitmap and block-ack bitmap */
2856 bitmap &= agg->bitmap;
2858 /* For each frame attempted in aggregation,
2859 * update driver's record of tx frame's status. */
2860 for (i = 0; i < agg->frame_count ; i++) {
2861 ack = bitmap & (1 << i);
2863 IWL_DEBUG_TX_REPLY("%s ON i=%d idx=%d raw=%d\n",
2864 ack? "ACK":"NACK", i, (agg->start_idx + i) & 0xff,
2865 agg->start_idx + i);
2868 info = IEEE80211_SKB_CB(priv->txq[scd_flow].txb[agg->start_idx].skb[0]);
2869 memset(&info->status, 0, sizeof(info->status));
2870 info->flags = IEEE80211_TX_STAT_ACK;
2871 info->flags |= IEEE80211_TX_STAT_AMPDU;
2872 info->status.ampdu_ack_map = successes;
2873 info->status.ampdu_ack_len = agg->frame_count;
2874 iwl4965_hwrate_to_tx_control(priv, agg->rate_n_flags, info);
2876 IWL_DEBUG_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap);
2882 * iwl4965_tx_queue_stop_scheduler - Stop queue, but keep configuration
2884 static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv,
2887 /* Simply stop the queue, but don't change any configuration;
2888 * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
2889 iwl_write_prph(priv,
2890 IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
2891 (0 << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE)|
2892 (1 << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
2896 * txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID
2897 * priv->lock must be held by the caller
2899 static int iwl4965_txq_agg_disable(struct iwl_priv *priv, u16 txq_id,
2900 u16 ssn_idx, u8 tx_fifo)
2904 if (IWL_BACK_QUEUE_FIRST_ID > txq_id) {
2905 IWL_WARNING("queue number too small: %d, must be > %d\n",
2906 txq_id, IWL_BACK_QUEUE_FIRST_ID);
2910 ret = iwl_grab_nic_access(priv);
2914 iwl4965_tx_queue_stop_scheduler(priv, txq_id);
2916 iwl_clear_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
2918 priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
2919 priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
2920 /* supposes that ssn_idx is valid (!= 0xFFF) */
2921 iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
2923 iwl_clear_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
2924 iwl_txq_ctx_deactivate(priv, txq_id);
2925 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
2927 iwl_release_nic_access(priv);
2934 * iwl4965_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
2936 * Handles block-acknowledge notification from device, which reports success
2937 * of frames sent via aggregation.
2939 static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv,
2940 struct iwl_rx_mem_buffer *rxb)
2942 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2943 struct iwl4965_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
2945 struct iwl_tx_queue *txq = NULL;
2946 struct iwl_ht_agg *agg;
2947 DECLARE_MAC_BUF(mac);
2949 /* "flow" corresponds to Tx queue */
2950 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
2952 /* "ssn" is start of block-ack Tx window, corresponds to index
2953 * (in Tx queue's circular buffer) of first TFD/frame in window */
2954 u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
2956 if (scd_flow >= priv->hw_params.max_txq_num) {
2957 IWL_ERROR("BUG_ON scd_flow is bigger than number of queues");
2961 txq = &priv->txq[scd_flow];
2962 agg = &priv->stations[ba_resp->sta_id].tid[ba_resp->tid].agg;
2964 /* Find index just before block-ack window */
2965 index = iwl_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd);
2967 /* TODO: Need to get this copy more safely - now good for debug */
2969 IWL_DEBUG_TX_REPLY("REPLY_COMPRESSED_BA [%d]Received from %s, "
2972 print_mac(mac, (u8*) &ba_resp->sta_addr_lo32),
2974 IWL_DEBUG_TX_REPLY("TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = "
2975 "%d, scd_ssn = %d\n",
2978 (unsigned long long)le64_to_cpu(ba_resp->bitmap),
2981 IWL_DEBUG_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx \n",
2983 (unsigned long long)agg->bitmap);
2985 /* Update driver's record of ACK vs. not for each frame in window */
2986 iwl4965_tx_status_reply_compressed_ba(priv, agg, ba_resp);
2988 /* Release all TFDs before the SSN, i.e. all TFDs in front of
2989 * block-ack window (we assume that they've been successfully
2990 * transmitted ... if not, it's too late anyway). */
2991 if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) {
2992 /* calculate mac80211 ampdu sw queue to wake */
2994 scd_flow - IWL_BACK_QUEUE_FIRST_ID + priv->hw->queues;
2995 int freed = iwl_tx_queue_reclaim(priv, scd_flow, index);
2996 priv->stations[ba_resp->sta_id].
2997 tid[ba_resp->tid].tfds_in_queue -= freed;
2998 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
2999 priv->mac80211_registered &&
3000 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)
3001 ieee80211_wake_queue(priv->hw, ampdu_q);
3003 iwl_txq_check_empty(priv, ba_resp->sta_id,
3004 ba_resp->tid, scd_flow);
3009 * iwl4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue
3011 static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
3018 scd_q2ratid = ra_tid & IWL_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
3020 tbl_dw_addr = priv->scd_base_addr +
3021 IWL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
3023 tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
3026 tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
3028 tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
3030 iwl_write_targ_mem(priv, tbl_dw_addr, tbl_dw);
3037 * iwl4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue
3039 * NOTE: txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID,
3040 * i.e. it must be one of the higher queues used for aggregation
3042 static int iwl4965_txq_agg_enable(struct iwl_priv *priv, int txq_id,
3043 int tx_fifo, int sta_id, int tid, u16 ssn_idx)
3045 unsigned long flags;
3049 if (IWL_BACK_QUEUE_FIRST_ID > txq_id)
3050 IWL_WARNING("queue number too small: %d, must be > %d\n",
3051 txq_id, IWL_BACK_QUEUE_FIRST_ID);
3053 ra_tid = BUILD_RAxTID(sta_id, tid);
3055 /* Modify device's station table to Tx this TID */
3056 iwl_sta_modify_enable_tid_tx(priv, sta_id, tid);
3058 spin_lock_irqsave(&priv->lock, flags);
3059 ret = iwl_grab_nic_access(priv);
3061 spin_unlock_irqrestore(&priv->lock, flags);
3065 /* Stop this Tx queue before configuring it */
3066 iwl4965_tx_queue_stop_scheduler(priv, txq_id);
3068 /* Map receiver-address / traffic-ID to this queue */
3069 iwl4965_tx_queue_set_q2ratid(priv, ra_tid, txq_id);
3071 /* Set this queue as a chain-building queue */
3072 iwl_set_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
3074 /* Place first TFD at index corresponding to start sequence number.
3075 * Assumes that ssn_idx is valid (!= 0xFFF) */
3076 priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
3077 priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
3078 iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
3080 /* Set up Tx window size and frame limit for this queue */
3081 iwl_write_targ_mem(priv,
3082 priv->scd_base_addr + IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id),
3083 (SCD_WIN_SIZE << IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
3084 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
3086 iwl_write_targ_mem(priv, priv->scd_base_addr +
3087 IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32),
3088 (SCD_FRAME_LIMIT << IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS)
3089 & IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
3091 iwl_set_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
3093 /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
3094 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1);
3096 iwl_release_nic_access(priv);
3097 spin_unlock_irqrestore(&priv->lock, flags);
3102 static int iwl4965_rx_agg_start(struct iwl_priv *priv,
3103 const u8 *addr, int tid, u16 ssn)
3105 unsigned long flags;
3108 sta_id = iwl_find_station(priv, addr);
3109 if (sta_id == IWL_INVALID_STATION)
3112 spin_lock_irqsave(&priv->sta_lock, flags);
3113 priv->stations[sta_id].sta.station_flags_msk = 0;
3114 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
3115 priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
3116 priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
3117 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3118 spin_unlock_irqrestore(&priv->sta_lock, flags);
3120 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
3124 static int iwl4965_rx_agg_stop(struct iwl_priv *priv,
3125 const u8 *addr, int tid)
3127 unsigned long flags;
3130 sta_id = iwl_find_station(priv, addr);
3131 if (sta_id == IWL_INVALID_STATION)
3134 spin_lock_irqsave(&priv->sta_lock, flags);
3135 priv->stations[sta_id].sta.station_flags_msk = 0;
3136 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
3137 priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
3138 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3139 spin_unlock_irqrestore(&priv->sta_lock, flags);
3141 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
3145 int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
3146 enum ieee80211_ampdu_mlme_action action,
3147 const u8 *addr, u16 tid, u16 *ssn)
3149 struct iwl_priv *priv = hw->priv;
3150 DECLARE_MAC_BUF(mac);
3152 IWL_DEBUG_HT("A-MPDU action on addr %s tid %d\n",
3153 print_mac(mac, addr), tid);
3156 case IEEE80211_AMPDU_RX_START:
3157 IWL_DEBUG_HT("start Rx\n");
3158 return iwl4965_rx_agg_start(priv, addr, tid, *ssn);
3159 case IEEE80211_AMPDU_RX_STOP:
3160 IWL_DEBUG_HT("stop Rx\n");
3161 return iwl4965_rx_agg_stop(priv, addr, tid);
3162 case IEEE80211_AMPDU_TX_START:
3163 IWL_DEBUG_HT("start Tx\n");
3164 return iwl_tx_agg_start(priv, addr, tid, ssn);
3165 case IEEE80211_AMPDU_TX_STOP:
3166 IWL_DEBUG_HT("stop Tx\n");
3167 return iwl_tx_agg_stop(priv, addr, tid);
3169 IWL_DEBUG_HT("unknown\n");
3176 static u16 iwl4965_get_hcmd_size(u8 cmd_id, u16 len)
3180 return (u16) sizeof(struct iwl4965_rxon_cmd);
3186 static u16 iwl4965_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
3188 struct iwl4965_addsta_cmd *addsta = (struct iwl4965_addsta_cmd *)data;
3189 addsta->mode = cmd->mode;
3190 memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify));
3191 memcpy(&addsta->key, &cmd->key, sizeof(struct iwl4965_keyinfo));
3192 addsta->station_flags = cmd->station_flags;
3193 addsta->station_flags_msk = cmd->station_flags_msk;
3194 addsta->tid_disable_tx = cmd->tid_disable_tx;
3195 addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid;
3196 addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid;
3197 addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn;
3198 addsta->reserved1 = __constant_cpu_to_le16(0);
3199 addsta->reserved2 = __constant_cpu_to_le32(0);
3201 return (u16)sizeof(struct iwl4965_addsta_cmd);
3204 static inline u32 iwl4965_get_scd_ssn(struct iwl4965_tx_resp *tx_resp)
3206 __le32 *scd_ssn = (__le32 *)((u32 *)&tx_resp->status +
3207 tx_resp->frame_count);
3208 return le32_to_cpu(*scd_ssn) & MAX_SN;
3213 * iwl4965_tx_status_reply_tx - Handle Tx rspnse for frames in aggregation queue
3215 static int iwl4965_tx_status_reply_tx(struct iwl_priv *priv,
3216 struct iwl_ht_agg *agg,
3217 struct iwl4965_tx_resp_agg *tx_resp,
3221 struct agg_tx_status *frame_status = &tx_resp->status;
3222 struct ieee80211_tx_info *info = NULL;
3223 struct ieee80211_hdr *hdr = NULL;
3228 if (agg->wait_for_ba)
3229 IWL_DEBUG_TX_REPLY("got tx response w/o block-ack\n");
3231 agg->frame_count = tx_resp->frame_count;
3232 agg->start_idx = start_idx;
3233 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
3236 /* # frames attempted by Tx command */
3237 if (agg->frame_count == 1) {
3238 /* Only one frame was attempted; no block-ack will arrive */
3239 status = le16_to_cpu(frame_status[0].status);
3240 seq = le16_to_cpu(frame_status[0].sequence);
3241 idx = SEQ_TO_INDEX(seq);
3242 txq_id = SEQ_TO_QUEUE(seq);
3244 /* FIXME: code repetition */
3245 IWL_DEBUG_TX_REPLY("FrameCnt = %d, StartIdx=%d idx=%d\n",
3246 agg->frame_count, agg->start_idx, idx);
3248 info = IEEE80211_SKB_CB(priv->txq[txq_id].txb[idx].skb[0]);
3249 info->status.retry_count = tx_resp->failure_frame;
3250 info->flags &= ~IEEE80211_TX_CTL_AMPDU;
3251 info->flags |= iwl_is_tx_success(status)?
3252 IEEE80211_TX_STAT_ACK : 0;
3253 iwl4965_hwrate_to_tx_control(priv,
3254 le32_to_cpu(tx_resp->rate_n_flags),
3256 /* FIXME: code repetition end */
3258 IWL_DEBUG_TX_REPLY("1 Frame 0x%x failure :%d\n",
3259 status & 0xff, tx_resp->failure_frame);
3260 IWL_DEBUG_TX_REPLY("Rate Info rate_n_flags=%x\n",
3261 iwl4965_hw_get_rate_n_flags(tx_resp->rate_n_flags));
3263 agg->wait_for_ba = 0;
3265 /* Two or more frames were attempted; expect block-ack */
3267 int start = agg->start_idx;
3269 /* Construct bit-map of pending frames within Tx window */
3270 for (i = 0; i < agg->frame_count; i++) {
3272 status = le16_to_cpu(frame_status[i].status);
3273 seq = le16_to_cpu(frame_status[i].sequence);
3274 idx = SEQ_TO_INDEX(seq);
3275 txq_id = SEQ_TO_QUEUE(seq);
3277 if (status & (AGG_TX_STATE_FEW_BYTES_MSK |
3278 AGG_TX_STATE_ABORT_MSK))
3281 IWL_DEBUG_TX_REPLY("FrameCnt = %d, txq_id=%d idx=%d\n",
3282 agg->frame_count, txq_id, idx);
3284 hdr = iwl_tx_queue_get_hdr(priv, txq_id, idx);
3286 sc = le16_to_cpu(hdr->seq_ctrl);
3287 if (idx != (SEQ_TO_SN(sc) & 0xff)) {
3288 IWL_ERROR("BUG_ON idx doesn't match seq control"
3289 " idx=%d, seq_idx=%d, seq=%d\n",
3295 IWL_DEBUG_TX_REPLY("AGG Frame i=%d idx %d seq=%d\n",
3296 i, idx, SEQ_TO_SN(sc));
3300 sh = (start - idx) + 0xff;
3301 bitmap = bitmap << sh;
3304 } else if (sh < -64)
3305 sh = 0xff - (start - idx);
3309 bitmap = bitmap << sh;
3312 bitmap |= (1 << sh);
3313 IWL_DEBUG_TX_REPLY("start=%d bitmap=0x%x\n",
3314 start, (u32)(bitmap & 0xFFFFFFFF));
3317 agg->bitmap = bitmap;
3318 agg->start_idx = start;
3319 agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags);
3320 IWL_DEBUG_TX_REPLY("Frames %d start_idx=%d bitmap=0x%llx\n",
3321 agg->frame_count, agg->start_idx,
3322 (unsigned long long)agg->bitmap);
3325 agg->wait_for_ba = 1;
3331 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
3333 static void iwl4965_rx_reply_tx(struct iwl_priv *priv,
3334 struct iwl_rx_mem_buffer *rxb)
3336 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
3337 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
3338 int txq_id = SEQ_TO_QUEUE(sequence);
3339 int index = SEQ_TO_INDEX(sequence);
3340 struct iwl_tx_queue *txq = &priv->txq[txq_id];
3341 struct ieee80211_tx_info *info;
3342 struct iwl4965_tx_resp *tx_resp = (void *)&pkt->u.raw[0];
3343 u32 status = le32_to_cpu(tx_resp->status);
3344 int tid = MAX_TID_COUNT, sta_id = IWL_INVALID_STATION;
3346 struct ieee80211_hdr *hdr;
3349 if ((index >= txq->q.n_bd) || (iwl_queue_used(&txq->q, index) == 0)) {
3350 IWL_ERROR("Read index for DMA queue txq_id (%d) index %d "
3351 "is out of range [0-%d] %d %d\n", txq_id,
3352 index, txq->q.n_bd, txq->q.write_ptr,
3357 info = IEEE80211_SKB_CB(txq->txb[txq->q.read_ptr].skb[0]);
3358 memset(&info->status, 0, sizeof(info->status));
3360 hdr = iwl_tx_queue_get_hdr(priv, txq_id, index);
3361 fc = le16_to_cpu(hdr->frame_control);
3362 if (ieee80211_is_qos_data(fc)) {
3363 qc = ieee80211_get_qos_ctrl(hdr, ieee80211_get_hdrlen(fc));
3367 sta_id = iwl_get_ra_sta_id(priv, hdr);
3368 if (txq->sched_retry && unlikely(sta_id == IWL_INVALID_STATION)) {
3369 IWL_ERROR("Station not known\n");
3373 if (txq->sched_retry) {
3374 const u32 scd_ssn = iwl4965_get_scd_ssn(tx_resp);
3375 struct iwl_ht_agg *agg = NULL;
3380 agg = &priv->stations[sta_id].tid[tid].agg;
3382 iwl4965_tx_status_reply_tx(priv, agg,
3383 (struct iwl4965_tx_resp_agg *)tx_resp, index);
3385 if ((tx_resp->frame_count == 1) && !iwl_is_tx_success(status)) {
3386 /* TODO: send BAR */
3389 if (txq->q.read_ptr != (scd_ssn & 0xff)) {
3391 index = iwl_queue_dec_wrap(scd_ssn & 0xff, txq->q.n_bd);
3392 IWL_DEBUG_TX_REPLY("Retry scheduler reclaim scd_ssn "
3393 "%d index %d\n", scd_ssn , index);
3394 freed = iwl_tx_queue_reclaim(priv, txq_id, index);
3395 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
3397 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
3398 txq_id >= 0 && priv->mac80211_registered &&
3399 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA) {
3400 /* calculate mac80211 ampdu sw queue to wake */
3401 ampdu_q = txq_id - IWL_BACK_QUEUE_FIRST_ID +
3403 if (agg->state == IWL_AGG_OFF)
3404 ieee80211_wake_queue(priv->hw, txq_id);
3406 ieee80211_wake_queue(priv->hw, ampdu_q);
3408 iwl_txq_check_empty(priv, sta_id, tid, txq_id);
3411 info->status.retry_count = tx_resp->failure_frame;
3413 iwl_is_tx_success(status) ? IEEE80211_TX_STAT_ACK : 0;
3414 iwl4965_hwrate_to_tx_control(priv,
3415 le32_to_cpu(tx_resp->rate_n_flags),
3418 IWL_DEBUG_TX("Tx queue %d Status %s (0x%08x) rate_n_flags "
3419 "0x%x retries %d\n", txq_id,
3420 iwl_get_tx_fail_reason(status),
3421 status, le32_to_cpu(tx_resp->rate_n_flags),
3422 tx_resp->failure_frame);
3424 IWL_DEBUG_TX_REPLY("Tx queue reclaim %d\n", index);
3426 int freed = iwl_tx_queue_reclaim(priv, txq_id, index);
3427 if (tid != MAX_TID_COUNT)
3428 priv->stations[sta_id].tid[tid].tfds_in_queue -= freed;
3429 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
3430 (txq_id >= 0) && priv->mac80211_registered)
3431 ieee80211_wake_queue(priv->hw, txq_id);
3432 if (tid != MAX_TID_COUNT)
3433 iwl_txq_check_empty(priv, sta_id, tid, txq_id);
3437 if (iwl_check_bits(status, TX_ABORT_REQUIRED_MSK))
3438 IWL_ERROR("TODO: Implement Tx ABORT REQUIRED!!!\n");
3442 /* Set up 4965-specific Rx frame reply handlers */
3443 static void iwl4965_rx_handler_setup(struct iwl_priv *priv)
3445 /* Legacy Rx frames */
3446 priv->rx_handlers[REPLY_RX] = iwl4965_rx_reply_rx;
3448 priv->rx_handlers[REPLY_TX] = iwl4965_rx_reply_tx;
3450 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl4965_rx_reply_compressed_ba;
3453 static void iwl4965_setup_deferred_work(struct iwl_priv *priv)
3455 INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work);
3458 static void iwl4965_cancel_deferred_work(struct iwl_priv *priv)
3460 cancel_work_sync(&priv->txpower_work);
3464 static struct iwl_hcmd_ops iwl4965_hcmd = {
3465 .rxon_assoc = iwl4965_send_rxon_assoc,
3468 static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
3469 .get_hcmd_size = iwl4965_get_hcmd_size,
3470 .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
3471 .chain_noise_reset = iwl4965_chain_noise_reset,
3472 .gain_computation = iwl4965_gain_computation,
3475 static struct iwl_lib_ops iwl4965_lib = {
3476 .set_hw_params = iwl4965_hw_set_hw_params,
3477 .alloc_shared_mem = iwl4965_alloc_shared_mem,
3478 .free_shared_mem = iwl4965_free_shared_mem,
3479 .shared_mem_rx_idx = iwl4965_shared_mem_rx_idx,
3480 .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl,
3481 .txq_set_sched = iwl4965_txq_set_sched,
3482 .txq_agg_enable = iwl4965_txq_agg_enable,
3483 .txq_agg_disable = iwl4965_txq_agg_disable,
3484 .rx_handler_setup = iwl4965_rx_handler_setup,
3485 .setup_deferred_work = iwl4965_setup_deferred_work,
3486 .cancel_deferred_work = iwl4965_cancel_deferred_work,
3487 .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr,
3488 .alive_notify = iwl4965_alive_notify,
3489 .init_alive_start = iwl4965_init_alive_start,
3490 .load_ucode = iwl4965_load_bsm,
3492 .init = iwl4965_apm_init,
3493 .reset = iwl4965_apm_reset,
3494 .stop = iwl4965_apm_stop,
3495 .config = iwl4965_nic_config,
3496 .set_pwr_src = iwl4965_set_pwr_src,
3499 .regulatory_bands = {
3500 EEPROM_REGULATORY_BAND_1_CHANNELS,
3501 EEPROM_REGULATORY_BAND_2_CHANNELS,
3502 EEPROM_REGULATORY_BAND_3_CHANNELS,
3503 EEPROM_REGULATORY_BAND_4_CHANNELS,
3504 EEPROM_REGULATORY_BAND_5_CHANNELS,
3505 EEPROM_4965_REGULATORY_BAND_24_FAT_CHANNELS,
3506 EEPROM_4965_REGULATORY_BAND_52_FAT_CHANNELS
3508 .verify_signature = iwlcore_eeprom_verify_signature,
3509 .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
3510 .release_semaphore = iwlcore_eeprom_release_semaphore,
3511 .check_version = iwl4965_eeprom_check_version,
3512 .query_addr = iwlcore_eeprom_query_addr,
3514 .radio_kill_sw = iwl4965_radio_kill_sw,
3515 .set_power = iwl4965_set_power,
3516 .update_chain_flags = iwl4965_update_chain_flags,
3519 static struct iwl_ops iwl4965_ops = {
3520 .lib = &iwl4965_lib,
3521 .hcmd = &iwl4965_hcmd,
3522 .utils = &iwl4965_hcmd_utils,
3525 struct iwl_cfg iwl4965_agn_cfg = {
3527 .fw_name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode",
3528 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
3529 .eeprom_size = IWL4965_EEPROM_IMG_SIZE,
3530 .ops = &iwl4965_ops,
3531 .mod_params = &iwl4965_mod_params,
3534 module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444);
3535 MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
3536 module_param_named(disable, iwl4965_mod_params.disable, int, 0444);
3537 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
3538 module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, 0444);
3539 MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])\n");
3540 module_param_named(debug, iwl4965_mod_params.debug, int, 0444);
3541 MODULE_PARM_DESC(debug, "debug output mask");
3543 disable_hw_scan, iwl4965_mod_params.disable_hw_scan, int, 0444);
3544 MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
3546 module_param_named(queues_num, iwl4965_mod_params.num_of_queues, int, 0444);
3547 MODULE_PARM_DESC(queues_num, "number of hw queues.");
3550 module_param_named(qos_enable, iwl4965_mod_params.enable_qos, int, 0444);
3551 MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
3552 module_param_named(amsdu_size_8K, iwl4965_mod_params.amsdu_size_8K, int, 0444);
3553 MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
3554 module_param_named(fw_restart4965, iwl4965_mod_params.restart_fw, int, 0444);
3555 MODULE_PARM_DESC(fw_restart4965, "restart firmware in case of error");