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"
48 /* module parameters */
49 static struct iwl_mod_params iwl4965_mod_params = {
50 .num_of_queues = IWL49_NUM_QUEUES,
54 /* the rest are 0 by default */
57 #ifdef CONFIG_IWL4965_HT
59 static const u16 default_tid_to_tx_fifo[] = {
79 #endif /*CONFIG_IWL4965_HT */
81 /* check contents of special bootstrap uCode SRAM */
82 static int iwl4965_verify_bsm(struct iwl_priv *priv)
84 __le32 *image = priv->ucode_boot.v_addr;
85 u32 len = priv->ucode_boot.len;
89 IWL_DEBUG_INFO("Begin verify bsm\n");
91 /* verify BSM SRAM contents */
92 val = iwl_read_prph(priv, BSM_WR_DWCOUNT_REG);
93 for (reg = BSM_SRAM_LOWER_BOUND;
94 reg < BSM_SRAM_LOWER_BOUND + len;
95 reg += sizeof(u32), image++) {
96 val = iwl_read_prph(priv, reg);
97 if (val != le32_to_cpu(*image)) {
98 IWL_ERROR("BSM uCode verification failed at "
99 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
100 BSM_SRAM_LOWER_BOUND,
101 reg - BSM_SRAM_LOWER_BOUND, len,
102 val, le32_to_cpu(*image));
107 IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
113 * iwl4965_load_bsm - Load bootstrap instructions
117 * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
118 * in special SRAM that does not power down during RFKILL. When powering back
119 * up after power-saving sleeps (or during initial uCode load), the BSM loads
120 * the bootstrap program into the on-board processor, and starts it.
122 * The bootstrap program loads (via DMA) instructions and data for a new
123 * program from host DRAM locations indicated by the host driver in the
124 * BSM_DRAM_* registers. Once the new program is loaded, it starts
127 * When initializing the NIC, the host driver points the BSM to the
128 * "initialize" uCode image. This uCode sets up some internal data, then
129 * notifies host via "initialize alive" that it is complete.
131 * The host then replaces the BSM_DRAM_* pointer values to point to the
132 * normal runtime uCode instructions and a backup uCode data cache buffer
133 * (filled initially with starting data values for the on-board processor),
134 * then triggers the "initialize" uCode to load and launch the runtime uCode,
135 * which begins normal operation.
137 * When doing a power-save shutdown, runtime uCode saves data SRAM into
138 * the backup data cache in DRAM before SRAM is powered down.
140 * When powering back up, the BSM loads the bootstrap program. This reloads
141 * the runtime uCode instructions and the backup data cache into SRAM,
142 * and re-launches the runtime uCode from where it left off.
144 static int iwl4965_load_bsm(struct iwl_priv *priv)
146 __le32 *image = priv->ucode_boot.v_addr;
147 u32 len = priv->ucode_boot.len;
157 IWL_DEBUG_INFO("Begin load bsm\n");
159 /* make sure bootstrap program is no larger than BSM's SRAM size */
160 if (len > IWL_MAX_BSM_SIZE)
163 /* Tell bootstrap uCode where to find the "Initialize" uCode
164 * in host DRAM ... host DRAM physical address bits 35:4 for 4965.
165 * NOTE: iwl4965_initialize_alive_start() will replace these values,
166 * after the "initialize" uCode has run, to point to
167 * runtime/protocol instructions and backup data cache. */
168 pinst = priv->ucode_init.p_addr >> 4;
169 pdata = priv->ucode_init_data.p_addr >> 4;
170 inst_len = priv->ucode_init.len;
171 data_len = priv->ucode_init_data.len;
173 ret = iwl_grab_nic_access(priv);
177 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
178 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
179 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
180 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
182 /* Fill BSM memory with bootstrap instructions */
183 for (reg_offset = BSM_SRAM_LOWER_BOUND;
184 reg_offset < BSM_SRAM_LOWER_BOUND + len;
185 reg_offset += sizeof(u32), image++)
186 _iwl_write_prph(priv, reg_offset, le32_to_cpu(*image));
188 ret = iwl4965_verify_bsm(priv);
190 iwl_release_nic_access(priv);
194 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
195 iwl_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
196 iwl_write_prph(priv, BSM_WR_MEM_DST_REG, RTC_INST_LOWER_BOUND);
197 iwl_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
199 /* Load bootstrap code into instruction SRAM now,
200 * to prepare to load "initialize" uCode */
201 iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START);
203 /* Wait for load of bootstrap uCode to finish */
204 for (i = 0; i < 100; i++) {
205 done = iwl_read_prph(priv, BSM_WR_CTRL_REG);
206 if (!(done & BSM_WR_CTRL_REG_BIT_START))
211 IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i);
213 IWL_ERROR("BSM write did not complete!\n");
217 /* Enable future boot loads whenever power management unit triggers it
218 * (e.g. when powering back up after power-save shutdown) */
219 iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN);
221 iwl_release_nic_access(priv);
227 * iwl4965_set_ucode_ptrs - Set uCode address location
229 * Tell initialization uCode where to find runtime uCode.
231 * BSM registers initially contain pointers to initialization uCode.
232 * We need to replace them to load runtime uCode inst and data,
233 * and to save runtime data when powering down.
235 static int iwl4965_set_ucode_ptrs(struct iwl_priv *priv)
242 /* bits 35:4 for 4965 */
243 pinst = priv->ucode_code.p_addr >> 4;
244 pdata = priv->ucode_data_backup.p_addr >> 4;
246 spin_lock_irqsave(&priv->lock, flags);
247 ret = iwl_grab_nic_access(priv);
249 spin_unlock_irqrestore(&priv->lock, flags);
253 /* Tell bootstrap uCode where to find image to load */
254 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
255 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
256 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
257 priv->ucode_data.len);
259 /* Inst bytecount must be last to set up, bit 31 signals uCode
260 * that all new ptr/size info is in place */
261 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
262 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
263 iwl_release_nic_access(priv);
265 spin_unlock_irqrestore(&priv->lock, flags);
267 IWL_DEBUG_INFO("Runtime uCode pointers are set.\n");
273 * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
275 * Called after REPLY_ALIVE notification received from "initialize" uCode.
277 * The 4965 "initialize" ALIVE reply contains calibration data for:
278 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
279 * (3945 does not contain this data).
281 * Tell "initialize" uCode to go ahead and load the runtime uCode.
283 static void iwl4965_init_alive_start(struct iwl_priv *priv)
285 /* Check alive response for "valid" sign from uCode */
286 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
287 /* We had an error bringing up the hardware, so take it
288 * all the way back down so we can try again */
289 IWL_DEBUG_INFO("Initialize Alive failed.\n");
293 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
294 * This is a paranoid check, because we would not have gotten the
295 * "initialize" alive if code weren't properly loaded. */
296 if (iwl_verify_ucode(priv)) {
297 /* Runtime instruction load was bad;
298 * take it all the way back down so we can try again */
299 IWL_DEBUG_INFO("Bad \"initialize\" uCode load.\n");
303 /* Calculate temperature */
304 priv->temperature = iwl4965_get_temperature(priv);
306 /* Send pointers to protocol/runtime uCode image ... init code will
307 * load and launch runtime uCode, which will send us another "Alive"
309 IWL_DEBUG_INFO("Initialization Alive received.\n");
310 if (iwl4965_set_ucode_ptrs(priv)) {
311 /* Runtime instruction load won't happen;
312 * take it all the way back down so we can try again */
313 IWL_DEBUG_INFO("Couldn't set up uCode pointers.\n");
319 queue_work(priv->workqueue, &priv->restart);
322 static int is_fat_channel(__le32 rxon_flags)
324 return (rxon_flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK) ||
325 (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK);
328 int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags)
332 /* 4965 HT rate format */
333 if (rate_n_flags & RATE_MCS_HT_MSK) {
334 idx = (rate_n_flags & 0xff);
336 if (idx >= IWL_RATE_MIMO2_6M_PLCP)
337 idx = idx - IWL_RATE_MIMO2_6M_PLCP;
339 idx += IWL_FIRST_OFDM_RATE;
340 /* skip 9M not supported in ht*/
341 if (idx >= IWL_RATE_9M_INDEX)
343 if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE))
346 /* 4965 legacy rate format, search for match in table */
348 for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++)
349 if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
357 * translate ucode response to mac80211 tx status control values
359 void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
360 struct ieee80211_tx_control *control)
364 control->antenna_sel_tx =
365 ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
366 if (rate_n_flags & RATE_MCS_HT_MSK)
367 control->flags |= IEEE80211_TXCTL_OFDM_HT;
368 if (rate_n_flags & RATE_MCS_GF_MSK)
369 control->flags |= IEEE80211_TXCTL_GREEN_FIELD;
370 if (rate_n_flags & RATE_MCS_FAT_MSK)
371 control->flags |= IEEE80211_TXCTL_40_MHZ_WIDTH;
372 if (rate_n_flags & RATE_MCS_DUP_MSK)
373 control->flags |= IEEE80211_TXCTL_DUP_DATA;
374 if (rate_n_flags & RATE_MCS_SGI_MSK)
375 control->flags |= IEEE80211_TXCTL_SHORT_GI;
376 /* since iwl4965_hwrate_to_plcp_idx is band indifferent, we always use
377 * IEEE80211_BAND_2GHZ band as it contains all the rates */
378 rate_index = iwl4965_hwrate_to_plcp_idx(rate_n_flags);
379 if (rate_index == -1)
380 control->tx_rate = NULL;
383 &priv->bands[IEEE80211_BAND_2GHZ].bitrates[rate_index];
386 int iwl4965_hw_rxq_stop(struct iwl_priv *priv)
391 spin_lock_irqsave(&priv->lock, flags);
392 rc = iwl_grab_nic_access(priv);
394 spin_unlock_irqrestore(&priv->lock, flags);
399 iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
400 rc = iwl_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG,
403 IWL_ERROR("Can't stop Rx DMA.\n");
405 iwl_release_nic_access(priv);
406 spin_unlock_irqrestore(&priv->lock, flags);
415 static int iwl4965_eeprom_check_version(struct iwl_priv *priv)
420 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
422 calib_ver = iwl_eeprom_query16(priv, EEPROM_4965_CALIB_VERSION_OFFSET);
424 if (eeprom_ver < EEPROM_4965_EEPROM_VERSION ||
425 calib_ver < EEPROM_4965_TX_POWER_VERSION)
430 IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
431 eeprom_ver, EEPROM_4965_EEPROM_VERSION,
432 calib_ver, EEPROM_4965_TX_POWER_VERSION);
436 int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
441 spin_lock_irqsave(&priv->lock, flags);
442 ret = iwl_grab_nic_access(priv);
444 spin_unlock_irqrestore(&priv->lock, flags);
448 if (src == IWL_PWR_SRC_VAUX) {
450 ret = pci_read_config_dword(priv->pci_dev, PCI_POWER_SOURCE,
453 if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT) {
454 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
455 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
456 ~APMG_PS_CTRL_MSK_PWR_SRC);
459 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
460 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
461 ~APMG_PS_CTRL_MSK_PWR_SRC);
464 iwl_release_nic_access(priv);
465 spin_unlock_irqrestore(&priv->lock, flags);
470 static int iwl4965_disable_tx_fifo(struct iwl_priv *priv)
475 spin_lock_irqsave(&priv->lock, flags);
477 ret = iwl_grab_nic_access(priv);
479 IWL_ERROR("Tx fifo reset failed");
480 spin_unlock_irqrestore(&priv->lock, flags);
484 iwl_write_prph(priv, IWL49_SCD_TXFACT, 0);
485 iwl_release_nic_access(priv);
486 spin_unlock_irqrestore(&priv->lock, flags);
491 static int iwl4965_apm_init(struct iwl_priv *priv)
495 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
496 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
498 /* set "initialization complete" bit to move adapter
499 * D0U* --> D0A* state */
500 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
502 /* wait for clock stabilization */
503 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
504 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
505 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
507 IWL_DEBUG_INFO("Failed to init the card\n");
511 ret = iwl_grab_nic_access(priv);
516 iwl_write_prph(priv, APMG_CLK_CTRL_REG,
517 APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT);
521 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
522 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
524 iwl_release_nic_access(priv);
530 static void iwl4965_nic_config(struct iwl_priv *priv)
537 spin_lock_irqsave(&priv->lock, flags);
539 if ((priv->rev_id & 0x80) == 0x80 && (priv->rev_id & 0x7f) < 8) {
540 pci_read_config_dword(priv->pci_dev, PCI_REG_WUM8, &val);
541 /* Enable No Snoop field */
542 pci_write_config_dword(priv->pci_dev, PCI_REG_WUM8,
546 pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link);
548 /* disable L1 entry -- workaround for pre-B1 */
549 pci_write_config_byte(priv->pci_dev, PCI_LINK_CTRL, val_link & ~0x02);
551 radio_cfg = iwl_eeprom_query16(priv, EEPROM_RADIO_CONFIG);
553 /* write radio config values to register */
554 if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg) == EEPROM_4965_RF_CFG_TYPE_MAX)
555 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
556 EEPROM_RF_CFG_TYPE_MSK(radio_cfg) |
557 EEPROM_RF_CFG_STEP_MSK(radio_cfg) |
558 EEPROM_RF_CFG_DASH_MSK(radio_cfg));
560 /* set CSR_HW_CONFIG_REG for uCode use */
561 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
562 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI |
563 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI);
565 priv->calib_info = (struct iwl_eeprom_calib_info *)
566 iwl_eeprom_query_addr(priv, EEPROM_4965_CALIB_TXPOWER_OFFSET);
568 spin_unlock_irqrestore(&priv->lock, flags);
571 int iwl4965_hw_nic_stop_master(struct iwl_priv *priv)
577 spin_lock_irqsave(&priv->lock, flags);
579 /* set stop master bit */
580 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
582 reg_val = iwl_read32(priv, CSR_GP_CNTRL);
584 if (CSR_GP_CNTRL_REG_FLAG_MAC_POWER_SAVE ==
585 (reg_val & CSR_GP_CNTRL_REG_MSK_POWER_SAVE_TYPE))
586 IWL_DEBUG_INFO("Card in power save, master is already "
589 rc = iwl_poll_bit(priv, CSR_RESET,
590 CSR_RESET_REG_FLAG_MASTER_DISABLED,
591 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
593 spin_unlock_irqrestore(&priv->lock, flags);
598 spin_unlock_irqrestore(&priv->lock, flags);
599 IWL_DEBUG_INFO("stop master\n");
605 * iwl4965_hw_txq_ctx_stop - Stop all Tx DMA channels, free Tx queue memory
607 void iwl4965_hw_txq_ctx_stop(struct iwl_priv *priv)
613 /* Stop each Tx DMA channel, and wait for it to be idle */
614 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
615 spin_lock_irqsave(&priv->lock, flags);
616 if (iwl_grab_nic_access(priv)) {
617 spin_unlock_irqrestore(&priv->lock, flags);
621 iwl_write_direct32(priv,
622 FH_TCSR_CHNL_TX_CONFIG_REG(txq_id), 0x0);
623 iwl_poll_direct_bit(priv, FH_TSSR_TX_STATUS_REG,
624 FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE
626 iwl_release_nic_access(priv);
627 spin_unlock_irqrestore(&priv->lock, flags);
630 /* Deallocate memory for all Tx queues */
631 iwl_hw_txq_ctx_free(priv);
634 int iwl4965_hw_nic_reset(struct iwl_priv *priv)
639 iwl4965_hw_nic_stop_master(priv);
641 spin_lock_irqsave(&priv->lock, flags);
643 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
647 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
648 rc = iwl_poll_bit(priv, CSR_RESET,
649 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
650 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25);
654 rc = iwl_grab_nic_access(priv);
656 iwl_write_prph(priv, APMG_CLK_EN_REG,
657 APMG_CLK_VAL_DMA_CLK_RQT |
658 APMG_CLK_VAL_BSM_CLK_RQT);
662 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
663 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
665 iwl_release_nic_access(priv);
668 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
669 wake_up_interruptible(&priv->wait_command_queue);
671 spin_unlock_irqrestore(&priv->lock, flags);
677 #define REG_RECALIB_PERIOD (60)
680 * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
682 * This callback is provided in order to send a statistics request.
684 * This timer function is continually reset to execute within
685 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
686 * was received. We need to ensure we receive the statistics in order
687 * to update the temperature used for calibrating the TXPOWER.
689 static void iwl4965_bg_statistics_periodic(unsigned long data)
691 struct iwl_priv *priv = (struct iwl_priv *)data;
693 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
696 iwl_send_statistics_request(priv, CMD_ASYNC);
699 void iwl4965_rf_kill_ct_config(struct iwl_priv *priv)
701 struct iwl4965_ct_kill_config cmd;
705 spin_lock_irqsave(&priv->lock, flags);
706 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
707 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
708 spin_unlock_irqrestore(&priv->lock, flags);
710 cmd.critical_temperature_R =
711 cpu_to_le32(priv->hw_params.ct_kill_threshold);
713 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
716 IWL_ERROR("REPLY_CT_KILL_CONFIG_CMD failed\n");
718 IWL_DEBUG_INFO("REPLY_CT_KILL_CONFIG_CMD succeeded, "
719 "critical temperature is %d\n",
720 cmd.critical_temperature_R);
723 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
725 /* Reset differential Rx gains in NIC to prepare for chain noise calibration.
726 * Called after every association, but this runs only once!
727 * ... once chain noise is calibrated the first time, it's good forever. */
728 static void iwl4965_chain_noise_reset(struct iwl_priv *priv)
730 struct iwl_chain_noise_data *data = &(priv->chain_noise_data);
732 if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
733 struct iwl4965_calibration_cmd cmd;
735 memset(&cmd, 0, sizeof(cmd));
736 cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
740 if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
742 IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
743 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
744 IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
748 static void iwl4965_gain_computation(struct iwl_priv *priv,
750 u16 min_average_noise_antenna_i,
751 u32 min_average_noise)
754 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
756 data->delta_gain_code[min_average_noise_antenna_i] = 0;
758 for (i = 0; i < NUM_RX_CHAINS; i++) {
761 if (!(data->disconn_array[i]) &&
762 (data->delta_gain_code[i] ==
763 CHAIN_NOISE_DELTA_GAIN_INIT_VAL)) {
764 delta_g = average_noise[i] - min_average_noise;
765 data->delta_gain_code[i] = (u8)((delta_g * 10) / 15);
766 data->delta_gain_code[i] =
767 min(data->delta_gain_code[i],
768 (u8) CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
770 data->delta_gain_code[i] =
771 (data->delta_gain_code[i] | (1 << 2));
773 data->delta_gain_code[i] = 0;
776 IWL_DEBUG_CALIB("delta_gain_codes: a %d b %d c %d\n",
777 data->delta_gain_code[0],
778 data->delta_gain_code[1],
779 data->delta_gain_code[2]);
781 /* Differential gain gets sent to uCode only once */
782 if (!data->radio_write) {
783 struct iwl4965_calibration_cmd cmd;
784 data->radio_write = 1;
786 memset(&cmd, 0, sizeof(cmd));
787 cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
788 cmd.diff_gain_a = data->delta_gain_code[0];
789 cmd.diff_gain_b = data->delta_gain_code[1];
790 cmd.diff_gain_c = data->delta_gain_code[2];
791 ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
794 IWL_DEBUG_CALIB("fail sending cmd "
795 "REPLY_PHY_CALIBRATION_CMD \n");
797 /* TODO we might want recalculate
798 * rx_chain in rxon cmd */
800 /* Mark so we run this algo only once! */
801 data->state = IWL_CHAIN_NOISE_CALIBRATED;
803 data->chain_noise_a = 0;
804 data->chain_noise_b = 0;
805 data->chain_noise_c = 0;
806 data->chain_signal_a = 0;
807 data->chain_signal_b = 0;
808 data->chain_signal_c = 0;
809 data->beacon_count = 0;
812 static void iwl4965_bg_sensitivity_work(struct work_struct *work)
814 struct iwl_priv *priv = container_of(work, struct iwl_priv,
817 mutex_lock(&priv->mutex);
819 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
820 test_bit(STATUS_SCANNING, &priv->status)) {
821 mutex_unlock(&priv->mutex);
825 if (priv->start_calib) {
826 iwl_chain_noise_calibration(priv, &priv->statistics);
828 iwl_sensitivity_calibration(priv, &priv->statistics);
831 mutex_unlock(&priv->mutex);
834 #endif /*CONFIG_IWL4965_RUN_TIME_CALIB*/
836 static void iwl4965_bg_txpower_work(struct work_struct *work)
838 struct iwl_priv *priv = container_of(work, struct iwl_priv,
841 /* If a scan happened to start before we got here
842 * then just return; the statistics notification will
843 * kick off another scheduled work to compensate for
844 * any temperature delta we missed here. */
845 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
846 test_bit(STATUS_SCANNING, &priv->status))
849 mutex_lock(&priv->mutex);
851 /* Regardless of if we are assocaited, we must reconfigure the
852 * TX power since frames can be sent on non-radar channels while
854 iwl4965_hw_reg_send_txpower(priv);
856 /* Update last_temperature to keep is_calib_needed from running
857 * when it isn't needed... */
858 priv->last_temperature = priv->temperature;
860 mutex_unlock(&priv->mutex);
864 * Acquire priv->lock before calling this function !
866 static void iwl4965_set_wr_ptrs(struct iwl_priv *priv, int txq_id, u32 index)
868 iwl_write_direct32(priv, HBUS_TARG_WRPTR,
869 (index & 0xff) | (txq_id << 8));
870 iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(txq_id), index);
874 * iwl4965_tx_queue_set_status - (optionally) start Tx/Cmd queue
875 * @tx_fifo_id: Tx DMA/FIFO channel (range 0-7) that the queue will feed
876 * @scd_retry: (1) Indicates queue will be used in aggregation mode
878 * NOTE: Acquire priv->lock before calling this function !
880 static void iwl4965_tx_queue_set_status(struct iwl_priv *priv,
881 struct iwl_tx_queue *txq,
882 int tx_fifo_id, int scd_retry)
884 int txq_id = txq->q.id;
886 /* Find out whether to activate Tx queue */
887 int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0;
889 /* Set up and activate */
890 iwl_write_prph(priv, IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
891 (active << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE) |
892 (tx_fifo_id << IWL49_SCD_QUEUE_STTS_REG_POS_TXF) |
893 (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_WSL) |
894 (scd_retry << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACK) |
895 IWL49_SCD_QUEUE_STTS_REG_MSK);
897 txq->sched_retry = scd_retry;
899 IWL_DEBUG_INFO("%s %s Queue %d on AC %d\n",
900 active ? "Activate" : "Deactivate",
901 scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
904 static const u16 default_queue_to_tx_fifo[] = {
914 int iwl4965_alive_notify(struct iwl_priv *priv)
921 spin_lock_irqsave(&priv->lock, flags);
923 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
924 memset(&(priv->sensitivity_data), 0,
925 sizeof(struct iwl_sensitivity_data));
926 memset(&(priv->chain_noise_data), 0,
927 sizeof(struct iwl_chain_noise_data));
928 for (i = 0; i < NUM_RX_CHAINS; i++)
929 priv->chain_noise_data.delta_gain_code[i] =
930 CHAIN_NOISE_DELTA_GAIN_INIT_VAL;
931 #endif /* CONFIG_IWL4965_RUN_TIME_CALIB*/
932 ret = iwl_grab_nic_access(priv);
934 spin_unlock_irqrestore(&priv->lock, flags);
938 /* Clear 4965's internal Tx Scheduler data base */
939 priv->scd_base_addr = iwl_read_prph(priv, IWL49_SCD_SRAM_BASE_ADDR);
940 a = priv->scd_base_addr + IWL49_SCD_CONTEXT_DATA_OFFSET;
941 for (; a < priv->scd_base_addr + IWL49_SCD_TX_STTS_BITMAP_OFFSET; a += 4)
942 iwl_write_targ_mem(priv, a, 0);
943 for (; a < priv->scd_base_addr + IWL49_SCD_TRANSLATE_TBL_OFFSET; a += 4)
944 iwl_write_targ_mem(priv, a, 0);
945 for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
946 iwl_write_targ_mem(priv, a, 0);
948 /* Tel 4965 where to find Tx byte count tables */
949 iwl_write_prph(priv, IWL49_SCD_DRAM_BASE_ADDR,
951 offsetof(struct iwl4965_shared, queues_byte_cnt_tbls)) >> 10);
953 /* Disable chain mode for all queues */
954 iwl_write_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, 0);
956 /* Initialize each Tx queue (including the command queue) */
957 for (i = 0; i < priv->hw_params.max_txq_num; i++) {
959 /* TFD circular buffer read/write indexes */
960 iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(i), 0);
961 iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
963 /* Max Tx Window size for Scheduler-ACK mode */
964 iwl_write_targ_mem(priv, priv->scd_base_addr +
965 IWL49_SCD_CONTEXT_QUEUE_OFFSET(i),
967 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
968 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
971 iwl_write_targ_mem(priv, priv->scd_base_addr +
972 IWL49_SCD_CONTEXT_QUEUE_OFFSET(i) +
975 IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
976 IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
979 iwl_write_prph(priv, IWL49_SCD_INTERRUPT_MASK,
980 (1 << priv->hw_params.max_txq_num) - 1);
982 /* Activate all Tx DMA/FIFO channels */
983 iwl_write_prph(priv, IWL49_SCD_TXFACT,
984 SCD_TXFACT_REG_TXFIFO_MASK(0, 7));
986 iwl4965_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
988 /* Map each Tx/cmd queue to its corresponding fifo */
989 for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) {
990 int ac = default_queue_to_tx_fifo[i];
991 iwl_txq_ctx_activate(priv, i);
992 iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
995 iwl_release_nic_access(priv);
996 spin_unlock_irqrestore(&priv->lock, flags);
998 /* Ask for statistics now, the uCode will send statistics notification
999 * periodically after association */
1000 iwl_send_statistics_request(priv, CMD_ASYNC);
1004 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
1005 static struct iwl_sensitivity_ranges iwl4965_sensitivity = {
1009 .auto_corr_min_ofdm = 85,
1010 .auto_corr_min_ofdm_mrc = 170,
1011 .auto_corr_min_ofdm_x1 = 105,
1012 .auto_corr_min_ofdm_mrc_x1 = 220,
1014 .auto_corr_max_ofdm = 120,
1015 .auto_corr_max_ofdm_mrc = 210,
1016 .auto_corr_max_ofdm_x1 = 140,
1017 .auto_corr_max_ofdm_mrc_x1 = 270,
1019 .auto_corr_min_cck = 125,
1020 .auto_corr_max_cck = 200,
1021 .auto_corr_min_cck_mrc = 200,
1022 .auto_corr_max_cck_mrc = 400,
1030 * iwl4965_hw_set_hw_params
1032 * Called when initializing driver
1034 int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
1037 if ((priv->cfg->mod_params->num_of_queues > IWL49_NUM_QUEUES) ||
1038 (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
1039 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
1040 IWL_MIN_NUM_QUEUES, IWL49_NUM_QUEUES);
1044 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
1045 priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
1046 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
1047 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
1048 if (priv->cfg->mod_params->amsdu_size_8K)
1049 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
1051 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
1052 priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
1053 priv->hw_params.max_stations = IWL4965_STATION_COUNT;
1054 priv->hw_params.bcast_sta_id = IWL4965_BROADCAST_ID;
1056 priv->hw_params.max_data_size = IWL49_RTC_DATA_SIZE;
1057 priv->hw_params.max_inst_size = IWL49_RTC_INST_SIZE;
1058 priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
1059 priv->hw_params.fat_channel = BIT(IEEE80211_BAND_5GHZ);
1061 priv->hw_params.tx_chains_num = 2;
1062 priv->hw_params.rx_chains_num = 2;
1063 priv->hw_params.valid_tx_ant = ANT_A | ANT_B;
1064 priv->hw_params.valid_rx_ant = ANT_A | ANT_B;
1065 priv->hw_params.ct_kill_threshold = CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
1067 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
1068 priv->hw_params.sens = &iwl4965_sensitivity;
1074 /* set card power command */
1075 static int iwl4965_set_power(struct iwl_priv *priv,
1080 ret = iwl_send_cmd_pdu_async(priv, POWER_TABLE_CMD,
1081 sizeof(struct iwl4965_powertable_cmd),
1085 int iwl4965_hw_reg_set_txpower(struct iwl_priv *priv, s8 power)
1087 IWL_ERROR("TODO: Implement iwl4965_hw_reg_set_txpower!\n");
1091 static s32 iwl4965_math_div_round(s32 num, s32 denom, s32 *res)
1104 *res = ((num * 2 + denom) / (denom * 2)) * sign;
1110 * iwl4965_get_voltage_compensation - Power supply voltage comp for txpower
1112 * Determines power supply voltage compensation for txpower calculations.
1113 * Returns number of 1/2-dB steps to subtract from gain table index,
1114 * to compensate for difference between power supply voltage during
1115 * factory measurements, vs. current power supply voltage.
1117 * Voltage indication is higher for lower voltage.
1118 * Lower voltage requires more gain (lower gain table index).
1120 static s32 iwl4965_get_voltage_compensation(s32 eeprom_voltage,
1121 s32 current_voltage)
1125 if ((TX_POWER_IWL_ILLEGAL_VOLTAGE == eeprom_voltage) ||
1126 (TX_POWER_IWL_ILLEGAL_VOLTAGE == current_voltage))
1129 iwl4965_math_div_round(current_voltage - eeprom_voltage,
1130 TX_POWER_IWL_VOLTAGE_CODES_PER_03V, &comp);
1132 if (current_voltage > eeprom_voltage)
1134 if ((comp < -2) || (comp > 2))
1140 static const struct iwl_channel_info *
1141 iwl4965_get_channel_txpower_info(struct iwl_priv *priv,
1142 enum ieee80211_band band, u16 channel)
1144 const struct iwl_channel_info *ch_info;
1146 ch_info = iwl_get_channel_info(priv, band, channel);
1148 if (!is_channel_valid(ch_info))
1154 static s32 iwl4965_get_tx_atten_grp(u16 channel)
1156 if (channel >= CALIB_IWL_TX_ATTEN_GR5_FCH &&
1157 channel <= CALIB_IWL_TX_ATTEN_GR5_LCH)
1158 return CALIB_CH_GROUP_5;
1160 if (channel >= CALIB_IWL_TX_ATTEN_GR1_FCH &&
1161 channel <= CALIB_IWL_TX_ATTEN_GR1_LCH)
1162 return CALIB_CH_GROUP_1;
1164 if (channel >= CALIB_IWL_TX_ATTEN_GR2_FCH &&
1165 channel <= CALIB_IWL_TX_ATTEN_GR2_LCH)
1166 return CALIB_CH_GROUP_2;
1168 if (channel >= CALIB_IWL_TX_ATTEN_GR3_FCH &&
1169 channel <= CALIB_IWL_TX_ATTEN_GR3_LCH)
1170 return CALIB_CH_GROUP_3;
1172 if (channel >= CALIB_IWL_TX_ATTEN_GR4_FCH &&
1173 channel <= CALIB_IWL_TX_ATTEN_GR4_LCH)
1174 return CALIB_CH_GROUP_4;
1176 IWL_ERROR("Can't find txatten group for channel %d.\n", channel);
1180 static u32 iwl4965_get_sub_band(const struct iwl_priv *priv, u32 channel)
1184 for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) {
1185 if (priv->calib_info->band_info[b].ch_from == 0)
1188 if ((channel >= priv->calib_info->band_info[b].ch_from)
1189 && (channel <= priv->calib_info->band_info[b].ch_to))
1196 static s32 iwl4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
1203 iwl4965_math_div_round((x2 - x) * (y1 - y2), (x2 - x1), &val);
1209 * iwl4965_interpolate_chan - Interpolate factory measurements for one channel
1211 * Interpolates factory measurements from the two sample channels within a
1212 * sub-band, to apply to channel of interest. Interpolation is proportional to
1213 * differences in channel frequencies, which is proportional to differences
1214 * in channel number.
1216 static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
1217 struct iwl_eeprom_calib_ch_info *chan_info)
1222 const struct iwl_eeprom_calib_measure *m1;
1223 const struct iwl_eeprom_calib_measure *m2;
1224 struct iwl_eeprom_calib_measure *omeas;
1228 s = iwl4965_get_sub_band(priv, channel);
1229 if (s >= EEPROM_TX_POWER_BANDS) {
1230 IWL_ERROR("Tx Power can not find channel %d ", channel);
1234 ch_i1 = priv->calib_info->band_info[s].ch1.ch_num;
1235 ch_i2 = priv->calib_info->band_info[s].ch2.ch_num;
1236 chan_info->ch_num = (u8) channel;
1238 IWL_DEBUG_TXPOWER("channel %d subband %d factory cal ch %d & %d\n",
1239 channel, s, ch_i1, ch_i2);
1241 for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) {
1242 for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) {
1243 m1 = &(priv->calib_info->band_info[s].ch1.
1244 measurements[c][m]);
1245 m2 = &(priv->calib_info->band_info[s].ch2.
1246 measurements[c][m]);
1247 omeas = &(chan_info->measurements[c][m]);
1250 (u8) iwl4965_interpolate_value(channel, ch_i1,
1255 (u8) iwl4965_interpolate_value(channel, ch_i1,
1256 m1->gain_idx, ch_i2,
1258 omeas->temperature =
1259 (u8) iwl4965_interpolate_value(channel, ch_i1,
1264 (s8) iwl4965_interpolate_value(channel, ch_i1,
1269 ("chain %d meas %d AP1=%d AP2=%d AP=%d\n", c, m,
1270 m1->actual_pow, m2->actual_pow, omeas->actual_pow);
1272 ("chain %d meas %d NI1=%d NI2=%d NI=%d\n", c, m,
1273 m1->gain_idx, m2->gain_idx, omeas->gain_idx);
1275 ("chain %d meas %d PA1=%d PA2=%d PA=%d\n", c, m,
1276 m1->pa_det, m2->pa_det, omeas->pa_det);
1278 ("chain %d meas %d T1=%d T2=%d T=%d\n", c, m,
1279 m1->temperature, m2->temperature,
1280 omeas->temperature);
1287 /* bit-rate-dependent table to prevent Tx distortion, in half-dB units,
1288 * for OFDM 6, 12, 18, 24, 36, 48, 54, 60 MBit, and CCK all rates. */
1289 static s32 back_off_table[] = {
1290 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 20 MHz */
1291 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 20 MHz */
1292 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 40 MHz */
1293 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 40 MHz */
1297 /* Thermal compensation values for txpower for various frequency ranges ...
1298 * ratios from 3:1 to 4.5:1 of degrees (Celsius) per half-dB gain adjust */
1299 static struct iwl4965_txpower_comp_entry {
1300 s32 degrees_per_05db_a;
1301 s32 degrees_per_05db_a_denom;
1302 } tx_power_cmp_tble[CALIB_CH_GROUP_MAX] = {
1303 {9, 2}, /* group 0 5.2, ch 34-43 */
1304 {4, 1}, /* group 1 5.2, ch 44-70 */
1305 {4, 1}, /* group 2 5.2, ch 71-124 */
1306 {4, 1}, /* group 3 5.2, ch 125-200 */
1307 {3, 1} /* group 4 2.4, ch all */
1310 static s32 get_min_power_index(s32 rate_power_index, u32 band)
1313 if ((rate_power_index & 7) <= 4)
1314 return MIN_TX_GAIN_INDEX_52GHZ_EXT;
1316 return MIN_TX_GAIN_INDEX;
1324 static const struct gain_entry gain_table[2][108] = {
1325 /* 5.2GHz power gain index table */
1327 {123, 0x3F}, /* highest txpower */
1436 /* 2.4GHz power gain index table */
1438 {110, 0x3f}, /* highest txpower */
1549 static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
1550 u8 is_fat, u8 ctrl_chan_high,
1551 struct iwl4965_tx_power_db *tx_power_tbl)
1553 u8 saturation_power;
1555 s32 user_target_power;
1559 s32 current_regulatory;
1560 s32 txatten_grp = CALIB_CH_GROUP_MAX;
1563 const struct iwl_channel_info *ch_info = NULL;
1564 struct iwl_eeprom_calib_ch_info ch_eeprom_info;
1565 const struct iwl_eeprom_calib_measure *measurement;
1568 s32 voltage_compensation;
1569 s32 degrees_per_05db_num;
1570 s32 degrees_per_05db_denom;
1572 s32 temperature_comp[2];
1573 s32 factory_gain_index[2];
1574 s32 factory_actual_pwr[2];
1577 /* Sanity check requested level (dBm) */
1578 if (priv->user_txpower_limit < IWL_TX_POWER_TARGET_POWER_MIN) {
1579 IWL_WARNING("Requested user TXPOWER %d below limit.\n",
1580 priv->user_txpower_limit);
1583 if (priv->user_txpower_limit > IWL_TX_POWER_TARGET_POWER_MAX) {
1584 IWL_WARNING("Requested user TXPOWER %d above limit.\n",
1585 priv->user_txpower_limit);
1589 /* user_txpower_limit is in dBm, convert to half-dBm (half-dB units
1590 * are used for indexing into txpower table) */
1591 user_target_power = 2 * priv->user_txpower_limit;
1593 /* Get current (RXON) channel, band, width */
1595 iwl4965_get_channel_txpower_info(priv, priv->band, channel);
1597 IWL_DEBUG_TXPOWER("chan %d band %d is_fat %d\n", channel, band,
1603 /* get txatten group, used to select 1) thermal txpower adjustment
1604 * and 2) mimo txpower balance between Tx chains. */
1605 txatten_grp = iwl4965_get_tx_atten_grp(channel);
1606 if (txatten_grp < 0)
1609 IWL_DEBUG_TXPOWER("channel %d belongs to txatten group %d\n",
1610 channel, txatten_grp);
1619 /* hardware txpower limits ...
1620 * saturation (clipping distortion) txpowers are in half-dBm */
1622 saturation_power = priv->calib_info->saturation_power24;
1624 saturation_power = priv->calib_info->saturation_power52;
1626 if (saturation_power < IWL_TX_POWER_SATURATION_MIN ||
1627 saturation_power > IWL_TX_POWER_SATURATION_MAX) {
1629 saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_24;
1631 saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_52;
1634 /* regulatory txpower limits ... reg_limit values are in half-dBm,
1635 * max_power_avg values are in dBm, convert * 2 */
1637 reg_limit = ch_info->fat_max_power_avg * 2;
1639 reg_limit = ch_info->max_power_avg * 2;
1641 if ((reg_limit < IWL_TX_POWER_REGULATORY_MIN) ||
1642 (reg_limit > IWL_TX_POWER_REGULATORY_MAX)) {
1644 reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_24;
1646 reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_52;
1649 /* Interpolate txpower calibration values for this channel,
1650 * based on factory calibration tests on spaced channels. */
1651 iwl4965_interpolate_chan(priv, channel, &ch_eeprom_info);
1653 /* calculate tx gain adjustment based on power supply voltage */
1654 voltage = priv->calib_info->voltage;
1655 init_voltage = (s32)le32_to_cpu(priv->card_alive_init.voltage);
1656 voltage_compensation =
1657 iwl4965_get_voltage_compensation(voltage, init_voltage);
1659 IWL_DEBUG_TXPOWER("curr volt %d eeprom volt %d volt comp %d\n",
1661 voltage, voltage_compensation);
1663 /* get current temperature (Celsius) */
1664 current_temp = max(priv->temperature, IWL_TX_POWER_TEMPERATURE_MIN);
1665 current_temp = min(priv->temperature, IWL_TX_POWER_TEMPERATURE_MAX);
1666 current_temp = KELVIN_TO_CELSIUS(current_temp);
1668 /* select thermal txpower adjustment params, based on channel group
1669 * (same frequency group used for mimo txatten adjustment) */
1670 degrees_per_05db_num =
1671 tx_power_cmp_tble[txatten_grp].degrees_per_05db_a;
1672 degrees_per_05db_denom =
1673 tx_power_cmp_tble[txatten_grp].degrees_per_05db_a_denom;
1675 /* get per-chain txpower values from factory measurements */
1676 for (c = 0; c < 2; c++) {
1677 measurement = &ch_eeprom_info.measurements[c][1];
1679 /* txgain adjustment (in half-dB steps) based on difference
1680 * between factory and current temperature */
1681 factory_temp = measurement->temperature;
1682 iwl4965_math_div_round((current_temp - factory_temp) *
1683 degrees_per_05db_denom,
1684 degrees_per_05db_num,
1685 &temperature_comp[c]);
1687 factory_gain_index[c] = measurement->gain_idx;
1688 factory_actual_pwr[c] = measurement->actual_pow;
1690 IWL_DEBUG_TXPOWER("chain = %d\n", c);
1691 IWL_DEBUG_TXPOWER("fctry tmp %d, "
1692 "curr tmp %d, comp %d steps\n",
1693 factory_temp, current_temp,
1694 temperature_comp[c]);
1696 IWL_DEBUG_TXPOWER("fctry idx %d, fctry pwr %d\n",
1697 factory_gain_index[c],
1698 factory_actual_pwr[c]);
1701 /* for each of 33 bit-rates (including 1 for CCK) */
1702 for (i = 0; i < POWER_TABLE_NUM_ENTRIES; i++) {
1704 union iwl4965_tx_power_dual_stream tx_power;
1706 /* for mimo, reduce each chain's txpower by half
1707 * (3dB, 6 steps), so total output power is regulatory
1710 current_regulatory = reg_limit -
1711 IWL_TX_POWER_MIMO_REGULATORY_COMPENSATION;
1714 current_regulatory = reg_limit;
1718 /* find txpower limit, either hardware or regulatory */
1719 power_limit = saturation_power - back_off_table[i];
1720 if (power_limit > current_regulatory)
1721 power_limit = current_regulatory;
1723 /* reduce user's txpower request if necessary
1724 * for this rate on this channel */
1725 target_power = user_target_power;
1726 if (target_power > power_limit)
1727 target_power = power_limit;
1729 IWL_DEBUG_TXPOWER("rate %d sat %d reg %d usr %d tgt %d\n",
1730 i, saturation_power - back_off_table[i],
1731 current_regulatory, user_target_power,
1734 /* for each of 2 Tx chains (radio transmitters) */
1735 for (c = 0; c < 2; c++) {
1740 (s32)le32_to_cpu(priv->card_alive_init.
1741 tx_atten[txatten_grp][c]);
1745 /* calculate index; higher index means lower txpower */
1746 power_index = (u8) (factory_gain_index[c] -
1748 factory_actual_pwr[c]) -
1749 temperature_comp[c] -
1750 voltage_compensation +
1753 /* IWL_DEBUG_TXPOWER("calculated txpower index %d\n",
1756 if (power_index < get_min_power_index(i, band))
1757 power_index = get_min_power_index(i, band);
1759 /* adjust 5 GHz index to support negative indexes */
1763 /* CCK, rate 32, reduce txpower for CCK */
1764 if (i == POWER_TABLE_CCK_ENTRY)
1766 IWL_TX_POWER_CCK_COMPENSATION_C_STEP;
1768 /* stay within the table! */
1769 if (power_index > 107) {
1770 IWL_WARNING("txpower index %d > 107\n",
1774 if (power_index < 0) {
1775 IWL_WARNING("txpower index %d < 0\n",
1780 /* fill txpower command for this rate/chain */
1781 tx_power.s.radio_tx_gain[c] =
1782 gain_table[band][power_index].radio;
1783 tx_power.s.dsp_predis_atten[c] =
1784 gain_table[band][power_index].dsp;
1786 IWL_DEBUG_TXPOWER("chain %d mimo %d index %d "
1787 "gain 0x%02x dsp %d\n",
1788 c, atten_value, power_index,
1789 tx_power.s.radio_tx_gain[c],
1790 tx_power.s.dsp_predis_atten[c]);
1791 }/* for each chain */
1793 tx_power_tbl->power_tbl[i].dw = cpu_to_le32(tx_power.dw);
1795 }/* for each rate */
1801 * iwl4965_hw_reg_send_txpower - Configure the TXPOWER level user limit
1803 * Uses the active RXON for channel, band, and characteristics (fat, high)
1804 * The power limit is taken from priv->user_txpower_limit.
1806 int iwl4965_hw_reg_send_txpower(struct iwl_priv *priv)
1808 struct iwl4965_txpowertable_cmd cmd = { 0 };
1812 u8 ctrl_chan_high = 0;
1814 if (test_bit(STATUS_SCANNING, &priv->status)) {
1815 /* If this gets hit a lot, switch it to a BUG() and catch
1816 * the stack trace to find out who is calling this during
1818 IWL_WARNING("TX Power requested while scanning!\n");
1822 band = priv->band == IEEE80211_BAND_2GHZ;
1824 is_fat = is_fat_channel(priv->active_rxon.flags);
1827 (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
1831 cmd.channel = priv->active_rxon.channel;
1833 ret = iwl4965_fill_txpower_tbl(priv, band,
1834 le16_to_cpu(priv->active_rxon.channel),
1835 is_fat, ctrl_chan_high, &cmd.tx_power);
1839 ret = iwl_send_cmd_pdu(priv, REPLY_TX_PWR_TABLE_CMD, sizeof(cmd), &cmd);
1845 static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
1848 struct iwl4965_rxon_assoc_cmd rxon_assoc;
1849 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
1850 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
1852 if ((rxon1->flags == rxon2->flags) &&
1853 (rxon1->filter_flags == rxon2->filter_flags) &&
1854 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
1855 (rxon1->ofdm_ht_single_stream_basic_rates ==
1856 rxon2->ofdm_ht_single_stream_basic_rates) &&
1857 (rxon1->ofdm_ht_dual_stream_basic_rates ==
1858 rxon2->ofdm_ht_dual_stream_basic_rates) &&
1859 (rxon1->rx_chain == rxon2->rx_chain) &&
1860 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
1861 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
1865 rxon_assoc.flags = priv->staging_rxon.flags;
1866 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
1867 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
1868 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
1869 rxon_assoc.reserved = 0;
1870 rxon_assoc.ofdm_ht_single_stream_basic_rates =
1871 priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
1872 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
1873 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
1874 rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
1876 ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
1877 sizeof(rxon_assoc), &rxon_assoc, NULL);
1885 int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel)
1890 u8 ctrl_chan_high = 0;
1891 struct iwl4965_channel_switch_cmd cmd = { 0 };
1892 const struct iwl_channel_info *ch_info;
1894 band = priv->band == IEEE80211_BAND_2GHZ;
1896 ch_info = iwl_get_channel_info(priv, priv->band, channel);
1898 is_fat = is_fat_channel(priv->staging_rxon.flags);
1901 (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
1905 cmd.expect_beacon = 0;
1906 cmd.channel = cpu_to_le16(channel);
1907 cmd.rxon_flags = priv->active_rxon.flags;
1908 cmd.rxon_filter_flags = priv->active_rxon.filter_flags;
1909 cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
1911 cmd.expect_beacon = is_channel_radar(ch_info);
1913 cmd.expect_beacon = 1;
1915 rc = iwl4965_fill_txpower_tbl(priv, band, channel, is_fat,
1916 ctrl_chan_high, &cmd.tx_power);
1918 IWL_DEBUG_11H("error:%d fill txpower_tbl\n", rc);
1922 rc = iwl_send_cmd_pdu(priv, REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd);
1926 static int iwl4965_shared_mem_rx_idx(struct iwl_priv *priv)
1928 struct iwl4965_shared *s = priv->shared_virt;
1929 return le32_to_cpu(s->rb_closed) & 0xFFF;
1932 int iwl4965_hw_get_temperature(struct iwl_priv *priv)
1934 return priv->temperature;
1937 unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
1938 struct iwl_frame *frame, u8 rate)
1940 struct iwl4965_tx_beacon_cmd *tx_beacon_cmd;
1941 unsigned int frame_size;
1943 tx_beacon_cmd = &frame->u.beacon;
1944 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
1946 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
1947 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
1949 frame_size = iwl4965_fill_beacon_frame(priv,
1950 tx_beacon_cmd->frame,
1952 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
1954 BUG_ON(frame_size > MAX_MPDU_SIZE);
1955 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
1957 if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
1958 tx_beacon_cmd->tx.rate_n_flags =
1959 iwl4965_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
1961 tx_beacon_cmd->tx.rate_n_flags =
1962 iwl4965_hw_set_rate_n_flags(rate, 0);
1964 tx_beacon_cmd->tx.tx_flags = (TX_CMD_FLG_SEQ_CTL_MSK |
1965 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK);
1966 return (sizeof(*tx_beacon_cmd) + frame_size);
1969 static int iwl4965_alloc_shared_mem(struct iwl_priv *priv)
1971 priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
1972 sizeof(struct iwl4965_shared),
1973 &priv->shared_phys);
1974 if (!priv->shared_virt)
1977 memset(priv->shared_virt, 0, sizeof(struct iwl4965_shared));
1979 priv->rb_closed_offset = offsetof(struct iwl4965_shared, rb_closed);
1984 static void iwl4965_free_shared_mem(struct iwl_priv *priv)
1986 if (priv->shared_virt)
1987 pci_free_consistent(priv->pci_dev,
1988 sizeof(struct iwl4965_shared),
1994 * iwl4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
1996 static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
1997 struct iwl_tx_queue *txq,
2001 int txq_id = txq->q.id;
2002 struct iwl4965_shared *shared_data = priv->shared_virt;
2004 len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
2006 /* Set up byte count within first 256 entries */
2007 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
2008 tfd_offset[txq->q.write_ptr], byte_cnt, len);
2010 /* If within first 64 entries, duplicate at end */
2011 if (txq->q.write_ptr < IWL49_MAX_WIN_SIZE)
2012 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
2013 tfd_offset[IWL49_QUEUE_SIZE + txq->q.write_ptr],
2018 * sign_extend - Sign extend a value using specified bit as sign-bit
2020 * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1
2021 * and bit0..2 is 001b which when sign extended to 1111111111111001b is -7.
2023 * @param oper value to sign extend
2024 * @param index 0 based bit index (0<=index<32) to sign bit
2026 static s32 sign_extend(u32 oper, int index)
2028 u8 shift = 31 - index;
2030 return (s32)(oper << shift) >> shift;
2034 * iwl4965_get_temperature - return the calibrated temperature (in Kelvin)
2035 * @statistics: Provides the temperature reading from the uCode
2037 * A return of <0 indicates bogus data in the statistics
2039 int iwl4965_get_temperature(const struct iwl_priv *priv)
2046 if (test_bit(STATUS_TEMPERATURE, &priv->status) &&
2047 (priv->statistics.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)) {
2048 IWL_DEBUG_TEMP("Running FAT temperature calibration\n");
2049 R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[1]);
2050 R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[1]);
2051 R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[1]);
2052 R4 = le32_to_cpu(priv->card_alive_init.therm_r4[1]);
2054 IWL_DEBUG_TEMP("Running temperature calibration\n");
2055 R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[0]);
2056 R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[0]);
2057 R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[0]);
2058 R4 = le32_to_cpu(priv->card_alive_init.therm_r4[0]);
2062 * Temperature is only 23 bits, so sign extend out to 32.
2064 * NOTE If we haven't received a statistics notification yet
2065 * with an updated temperature, use R4 provided to us in the
2066 * "initialize" ALIVE response.
2068 if (!test_bit(STATUS_TEMPERATURE, &priv->status))
2069 vt = sign_extend(R4, 23);
2072 le32_to_cpu(priv->statistics.general.temperature), 23);
2074 IWL_DEBUG_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n",
2078 IWL_ERROR("Calibration conflict R1 == R3\n");
2082 /* Calculate temperature in degrees Kelvin, adjust by 97%.
2083 * Add offset to center the adjustment around 0 degrees Centigrade. */
2084 temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2);
2085 temperature /= (R3 - R1);
2086 temperature = (temperature * 97) / 100 +
2087 TEMPERATURE_CALIB_KELVIN_OFFSET;
2089 IWL_DEBUG_TEMP("Calibrated temperature: %dK, %dC\n", temperature,
2090 KELVIN_TO_CELSIUS(temperature));
2095 /* Adjust Txpower only if temperature variance is greater than threshold. */
2096 #define IWL_TEMPERATURE_THRESHOLD 3
2099 * iwl4965_is_temp_calib_needed - determines if new calibration is needed
2101 * If the temperature changed has changed sufficiently, then a recalibration
2104 * Assumes caller will replace priv->last_temperature once calibration
2107 static int iwl4965_is_temp_calib_needed(struct iwl_priv *priv)
2111 if (!test_bit(STATUS_STATISTICS, &priv->status)) {
2112 IWL_DEBUG_TEMP("Temperature not updated -- no statistics.\n");
2116 temp_diff = priv->temperature - priv->last_temperature;
2118 /* get absolute value */
2119 if (temp_diff < 0) {
2120 IWL_DEBUG_POWER("Getting cooler, delta %d, \n", temp_diff);
2121 temp_diff = -temp_diff;
2122 } else if (temp_diff == 0)
2123 IWL_DEBUG_POWER("Same temp, \n");
2125 IWL_DEBUG_POWER("Getting warmer, delta %d, \n", temp_diff);
2127 if (temp_diff < IWL_TEMPERATURE_THRESHOLD) {
2128 IWL_DEBUG_POWER("Thermal txpower calib not needed\n");
2132 IWL_DEBUG_POWER("Thermal txpower calib needed\n");
2137 /* Calculate noise level, based on measurements during network silence just
2138 * before arriving beacon. This measurement can be done only if we know
2139 * exactly when to expect beacons, therefore only when we're associated. */
2140 static void iwl4965_rx_calc_noise(struct iwl_priv *priv)
2142 struct statistics_rx_non_phy *rx_info
2143 = &(priv->statistics.rx.general);
2144 int num_active_rx = 0;
2145 int total_silence = 0;
2147 le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
2149 le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
2151 le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
2153 if (bcn_silence_a) {
2154 total_silence += bcn_silence_a;
2157 if (bcn_silence_b) {
2158 total_silence += bcn_silence_b;
2161 if (bcn_silence_c) {
2162 total_silence += bcn_silence_c;
2166 /* Average among active antennas */
2168 priv->last_rx_noise = (total_silence / num_active_rx) - 107;
2170 priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
2172 IWL_DEBUG_CALIB("inband silence a %u, b %u, c %u, dBm %d\n",
2173 bcn_silence_a, bcn_silence_b, bcn_silence_c,
2174 priv->last_rx_noise);
2177 void iwl4965_hw_rx_statistics(struct iwl_priv *priv,
2178 struct iwl_rx_mem_buffer *rxb)
2180 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2184 IWL_DEBUG_RX("Statistics notification received (%d vs %d).\n",
2185 (int)sizeof(priv->statistics), pkt->len);
2187 change = ((priv->statistics.general.temperature !=
2188 pkt->u.stats.general.temperature) ||
2189 ((priv->statistics.flag &
2190 STATISTICS_REPLY_FLG_FAT_MODE_MSK) !=
2191 (pkt->u.stats.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)));
2193 memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics));
2195 set_bit(STATUS_STATISTICS, &priv->status);
2197 /* Reschedule the statistics timer to occur in
2198 * REG_RECALIB_PERIOD seconds to ensure we get a
2199 * thermal update even if the uCode doesn't give
2201 mod_timer(&priv->statistics_periodic, jiffies +
2202 msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
2204 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
2205 (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
2206 iwl4965_rx_calc_noise(priv);
2207 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
2208 queue_work(priv->workqueue, &priv->sensitivity_work);
2212 iwl_leds_background(priv);
2214 /* If the hardware hasn't reported a change in
2215 * temperature then don't bother computing a
2216 * calibrated temperature value */
2220 temp = iwl4965_get_temperature(priv);
2224 if (priv->temperature != temp) {
2225 if (priv->temperature)
2226 IWL_DEBUG_TEMP("Temperature changed "
2227 "from %dC to %dC\n",
2228 KELVIN_TO_CELSIUS(priv->temperature),
2229 KELVIN_TO_CELSIUS(temp));
2231 IWL_DEBUG_TEMP("Temperature "
2232 "initialized to %dC\n",
2233 KELVIN_TO_CELSIUS(temp));
2236 priv->temperature = temp;
2237 set_bit(STATUS_TEMPERATURE, &priv->status);
2239 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
2240 iwl4965_is_temp_calib_needed(priv))
2241 queue_work(priv->workqueue, &priv->txpower_work);
2244 static void iwl4965_add_radiotap(struct iwl_priv *priv,
2245 struct sk_buff *skb,
2246 struct iwl4965_rx_phy_res *rx_start,
2247 struct ieee80211_rx_status *stats,
2250 s8 signal = stats->signal;
2252 int rate = stats->rate_idx;
2253 u64 tsf = stats->mactime;
2255 __le16 phy_flags_hw = rx_start->phy_flags;
2256 struct iwl4965_rt_rx_hdr {
2257 struct ieee80211_radiotap_header rt_hdr;
2258 __le64 rt_tsf; /* TSF */
2259 u8 rt_flags; /* radiotap packet flags */
2260 u8 rt_rate; /* rate in 500kb/s */
2261 __le16 rt_channelMHz; /* channel in MHz */
2262 __le16 rt_chbitmask; /* channel bitfield */
2263 s8 rt_dbmsignal; /* signal in dBm, kluged to signed */
2265 u8 rt_antenna; /* antenna number */
2266 } __attribute__ ((packed)) *iwl4965_rt;
2268 /* TODO: We won't have enough headroom for HT frames. Fix it later. */
2269 if (skb_headroom(skb) < sizeof(*iwl4965_rt)) {
2270 if (net_ratelimit())
2271 printk(KERN_ERR "not enough headroom [%d] for "
2272 "radiotap head [%zd]\n",
2273 skb_headroom(skb), sizeof(*iwl4965_rt));
2277 /* put radiotap header in front of 802.11 header and data */
2278 iwl4965_rt = (void *)skb_push(skb, sizeof(*iwl4965_rt));
2280 /* initialise radiotap header */
2281 iwl4965_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
2282 iwl4965_rt->rt_hdr.it_pad = 0;
2284 /* total header + data */
2285 put_unaligned(cpu_to_le16(sizeof(*iwl4965_rt)),
2286 &iwl4965_rt->rt_hdr.it_len);
2288 /* Indicate all the fields we add to the radiotap header */
2289 put_unaligned(cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) |
2290 (1 << IEEE80211_RADIOTAP_FLAGS) |
2291 (1 << IEEE80211_RADIOTAP_RATE) |
2292 (1 << IEEE80211_RADIOTAP_CHANNEL) |
2293 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
2294 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
2295 (1 << IEEE80211_RADIOTAP_ANTENNA)),
2296 &iwl4965_rt->rt_hdr.it_present);
2298 /* Zero the flags, we'll add to them as we go */
2299 iwl4965_rt->rt_flags = 0;
2301 put_unaligned(cpu_to_le64(tsf), &iwl4965_rt->rt_tsf);
2303 iwl4965_rt->rt_dbmsignal = signal;
2304 iwl4965_rt->rt_dbmnoise = noise;
2306 /* Convert the channel frequency and set the flags */
2307 put_unaligned(cpu_to_le16(stats->freq), &iwl4965_rt->rt_channelMHz);
2308 if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK))
2309 put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM |
2310 IEEE80211_CHAN_5GHZ),
2311 &iwl4965_rt->rt_chbitmask);
2312 else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK)
2313 put_unaligned(cpu_to_le16(IEEE80211_CHAN_CCK |
2314 IEEE80211_CHAN_2GHZ),
2315 &iwl4965_rt->rt_chbitmask);
2317 put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM |
2318 IEEE80211_CHAN_2GHZ),
2319 &iwl4965_rt->rt_chbitmask);
2322 iwl4965_rt->rt_rate = 0;
2324 iwl4965_rt->rt_rate = iwl_rates[rate].ieee;
2329 * It seems that the antenna field in the phy flags value
2330 * is actually a bitfield. This is undefined by radiotap,
2331 * it wants an actual antenna number but I always get "7"
2332 * for most legacy frames I receive indicating that the
2333 * same frame was received on all three RX chains.
2335 * I think this field should be removed in favour of a
2336 * new 802.11n radiotap field "RX chains" that is defined
2339 antenna = phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK;
2340 iwl4965_rt->rt_antenna = le16_to_cpu(antenna) >> 4;
2342 /* set the preamble flag if appropriate */
2343 if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
2344 iwl4965_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
2346 stats->flag |= RX_FLAG_RADIOTAP;
2349 static void iwl_update_rx_stats(struct iwl_priv *priv, u16 fc, u16 len)
2351 /* 0 - mgmt, 1 - cnt, 2 - data */
2352 int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
2353 priv->rx_stats[idx].cnt++;
2354 priv->rx_stats[idx].bytes += len;
2358 * returns non-zero if packet should be dropped
2360 static int iwl4965_set_decrypted_flag(struct iwl_priv *priv,
2361 struct ieee80211_hdr *hdr,
2363 struct ieee80211_rx_status *stats)
2365 u16 fc = le16_to_cpu(hdr->frame_control);
2367 if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
2370 if (!(fc & IEEE80211_FCTL_PROTECTED))
2373 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
2374 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
2375 case RX_RES_STATUS_SEC_TYPE_TKIP:
2376 /* The uCode has got a bad phase 1 Key, pushes the packet.
2377 * Decryption will be done in SW. */
2378 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2379 RX_RES_STATUS_BAD_KEY_TTAK)
2382 case RX_RES_STATUS_SEC_TYPE_WEP:
2383 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2384 RX_RES_STATUS_BAD_ICV_MIC) {
2385 /* bad ICV, the packet is destroyed since the
2386 * decryption is inplace, drop it */
2387 IWL_DEBUG_RX("Packet destroyed\n");
2390 case RX_RES_STATUS_SEC_TYPE_CCMP:
2391 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2392 RX_RES_STATUS_DECRYPT_OK) {
2393 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2394 stats->flag |= RX_FLAG_DECRYPTED;
2404 static u32 iwl4965_translate_rx_status(struct iwl_priv *priv, u32 decrypt_in)
2406 u32 decrypt_out = 0;
2408 if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
2409 RX_RES_STATUS_STATION_FOUND)
2410 decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
2411 RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
2413 decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
2415 /* packet was not encrypted */
2416 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
2417 RX_RES_STATUS_SEC_TYPE_NONE)
2420 /* packet was encrypted with unknown alg */
2421 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
2422 RX_RES_STATUS_SEC_TYPE_ERR)
2425 /* decryption was not done in HW */
2426 if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
2427 RX_MPDU_RES_STATUS_DEC_DONE_MSK)
2430 switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
2432 case RX_RES_STATUS_SEC_TYPE_CCMP:
2433 /* alg is CCM: check MIC only */
2434 if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
2436 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
2438 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
2442 case RX_RES_STATUS_SEC_TYPE_TKIP:
2443 if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
2445 decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
2448 /* fall through if TTAK OK */
2450 if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
2451 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
2453 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
2457 IWL_DEBUG_RX("decrypt_in:0x%x decrypt_out = 0x%x\n",
2458 decrypt_in, decrypt_out);
2463 static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data,
2465 struct iwl_rx_mem_buffer *rxb,
2466 struct ieee80211_rx_status *stats)
2468 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2469 struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
2470 (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) : NULL;
2471 struct ieee80211_hdr *hdr;
2474 unsigned int skblen;
2476 u32 ampdu_status_legacy;
2478 if (!include_phy && priv->last_phy_res[0])
2479 rx_start = (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
2482 IWL_ERROR("MPDU frame without a PHY data\n");
2486 hdr = (struct ieee80211_hdr *)((u8 *) & rx_start[1] +
2487 rx_start->cfg_phy_cnt);
2489 len = le16_to_cpu(rx_start->byte_count);
2491 rx_end = (__le32 *) ((u8 *) & pkt->u.raw[0] +
2492 sizeof(struct iwl4965_rx_phy_res) +
2493 rx_start->cfg_phy_cnt + len);
2496 struct iwl4965_rx_mpdu_res_start *amsdu =
2497 (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
2499 hdr = (struct ieee80211_hdr *)(pkt->u.raw +
2500 sizeof(struct iwl4965_rx_mpdu_res_start));
2501 len = le16_to_cpu(amsdu->byte_count);
2502 rx_start->byte_count = amsdu->byte_count;
2503 rx_end = (__le32 *) (((u8 *) hdr) + len);
2505 /* In monitor mode allow 802.11 ACk frames (10 bytes) */
2506 if (len > priv->hw_params.max_pkt_size ||
2507 len < ((priv->iw_mode == IEEE80211_IF_TYPE_MNTR) ? 10 : 16)) {
2508 IWL_WARNING("byte count out of range [16,4K] : %d\n", len);
2512 ampdu_status = le32_to_cpu(*rx_end);
2513 skblen = ((u8 *) rx_end - (u8 *) & pkt->u.raw[0]) + sizeof(u32);
2516 /* New status scheme, need to translate */
2517 ampdu_status_legacy = ampdu_status;
2518 ampdu_status = iwl4965_translate_rx_status(priv, ampdu_status);
2521 /* start from MAC */
2522 skb_reserve(rxb->skb, (void *)hdr - (void *)pkt);
2523 skb_put(rxb->skb, len); /* end where data ends */
2525 /* We only process data packets if the interface is open */
2526 if (unlikely(!priv->is_open)) {
2527 IWL_DEBUG_DROP_LIMIT
2528 ("Dropping packet while interface is not open.\n");
2533 hdr = (struct ieee80211_hdr *)rxb->skb->data;
2535 /* in case of HW accelerated crypto and bad decryption, drop */
2536 if (!priv->hw_params.sw_crypto &&
2537 iwl4965_set_decrypted_flag(priv, hdr, ampdu_status, stats))
2540 if (priv->add_radiotap)
2541 iwl4965_add_radiotap(priv, rxb->skb, rx_start, stats, ampdu_status);
2543 iwl_update_rx_stats(priv, le16_to_cpu(hdr->frame_control), len);
2544 ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
2545 priv->alloc_rxb_skb--;
2549 /* Calc max signal level (dBm) among 3 possible receivers */
2550 static int iwl4965_calc_rssi(struct iwl_priv *priv,
2551 struct iwl4965_rx_phy_res *rx_resp)
2553 /* data from PHY/DSP regarding signal strength, etc.,
2554 * contents are always there, not configurable by host. */
2555 struct iwl4965_rx_non_cfg_phy *ncphy =
2556 (struct iwl4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy;
2557 u32 agc = (le16_to_cpu(ncphy->agc_info) & IWL_AGC_DB_MASK)
2560 u32 valid_antennae =
2561 (le16_to_cpu(rx_resp->phy_flags) & RX_PHY_FLAGS_ANTENNAE_MASK)
2562 >> RX_PHY_FLAGS_ANTENNAE_OFFSET;
2566 /* Find max rssi among 3 possible receivers.
2567 * These values are measured by the digital signal processor (DSP).
2568 * They should stay fairly constant even as the signal strength varies,
2569 * if the radio's automatic gain control (AGC) is working right.
2570 * AGC value (see below) will provide the "interesting" info. */
2571 for (i = 0; i < 3; i++)
2572 if (valid_antennae & (1 << i))
2573 max_rssi = max(ncphy->rssi_info[i << 1], max_rssi);
2575 IWL_DEBUG_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
2576 ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4],
2579 /* dBm = max_rssi dB - agc dB - constant.
2580 * Higher AGC (higher radio gain) means lower signal. */
2581 return (max_rssi - agc - IWL_RSSI_OFFSET);
2584 static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
2586 unsigned long flags;
2588 spin_lock_irqsave(&priv->sta_lock, flags);
2589 priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
2590 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
2591 priv->stations[sta_id].sta.sta.modify_mask = 0;
2592 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
2593 spin_unlock_irqrestore(&priv->sta_lock, flags);
2595 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
2598 static void iwl4965_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
2600 /* FIXME: need locking over ps_status ??? */
2601 u8 sta_id = iwl_find_station(priv, addr);
2603 if (sta_id != IWL_INVALID_STATION) {
2604 u8 sta_awake = priv->stations[sta_id].
2605 ps_status == STA_PS_STATUS_WAKE;
2607 if (sta_awake && ps_bit)
2608 priv->stations[sta_id].ps_status = STA_PS_STATUS_SLEEP;
2609 else if (!sta_awake && !ps_bit) {
2610 iwl4965_sta_modify_ps_wake(priv, sta_id);
2611 priv->stations[sta_id].ps_status = STA_PS_STATUS_WAKE;
2615 #ifdef CONFIG_IWLWIFI_DEBUG
2618 * iwl4965_dbg_report_frame - dump frame to syslog during debug sessions
2620 * You may hack this function to show different aspects of received frames,
2621 * including selective frame dumps.
2622 * group100 parameter selects whether to show 1 out of 100 good frames.
2624 * TODO: This was originally written for 3945, need to audit for
2625 * proper operation with 4965.
2627 static void iwl4965_dbg_report_frame(struct iwl_priv *priv,
2628 struct iwl_rx_packet *pkt,
2629 struct ieee80211_hdr *header, int group100)
2632 u32 print_summary = 0;
2633 u32 print_dump = 0; /* set to 1 to dump all frames' contents */
2650 struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
2651 struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
2652 struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt);
2653 u8 *data = IWL_RX_DATA(pkt);
2655 if (likely(!(priv->debug_level & IWL_DL_RX)))
2659 fc = le16_to_cpu(header->frame_control);
2660 seq_ctl = le16_to_cpu(header->seq_ctrl);
2663 channel = le16_to_cpu(rx_hdr->channel);
2664 phy_flags = le16_to_cpu(rx_hdr->phy_flags);
2665 rate_sym = rx_hdr->rate;
2666 length = le16_to_cpu(rx_hdr->len);
2668 /* end-of-frame status and timestamp */
2669 status = le32_to_cpu(rx_end->status);
2670 bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
2671 tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
2672 tsf = le64_to_cpu(rx_end->timestamp);
2674 /* signal statistics */
2675 rssi = rx_stats->rssi;
2676 agc = rx_stats->agc;
2677 sig_avg = le16_to_cpu(rx_stats->sig_avg);
2678 noise_diff = le16_to_cpu(rx_stats->noise_diff);
2680 to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
2682 /* if data frame is to us and all is good,
2683 * (optionally) print summary for only 1 out of every 100 */
2684 if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) ==
2685 (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
2688 print_summary = 1; /* print each frame */
2689 else if (priv->framecnt_to_us < 100) {
2690 priv->framecnt_to_us++;
2693 priv->framecnt_to_us = 0;
2698 /* print summary for all other frames */
2702 if (print_summary) {
2708 title = "100Frames";
2709 else if (fc & IEEE80211_FCTL_RETRY)
2711 else if (ieee80211_is_assoc_response(fc))
2713 else if (ieee80211_is_reassoc_response(fc))
2715 else if (ieee80211_is_probe_response(fc)) {
2717 print_dump = 1; /* dump frame contents */
2718 } else if (ieee80211_is_beacon(fc)) {
2720 print_dump = 1; /* dump frame contents */
2721 } else if (ieee80211_is_atim(fc))
2723 else if (ieee80211_is_auth(fc))
2725 else if (ieee80211_is_deauth(fc))
2727 else if (ieee80211_is_disassoc(fc))
2732 rate_idx = iwl4965_hwrate_to_plcp_idx(rate_sym);
2733 if (unlikely(rate_idx == -1))
2736 bitrate = iwl_rates[rate_idx].ieee / 2;
2738 /* print frame summary.
2739 * MAC addresses show just the last byte (for brevity),
2740 * but you can hack it to show more, if you'd like to. */
2742 IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
2743 "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
2744 title, fc, header->addr1[5],
2745 length, rssi, channel, bitrate);
2747 /* src/dst addresses assume managed mode */
2748 IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
2749 "src=0x%02x, rssi=%u, tim=%lu usec, "
2750 "phy=0x%02x, chnl=%d\n",
2751 title, fc, header->addr1[5],
2752 header->addr3[5], rssi,
2753 tsf_low - priv->scan_start_tsf,
2754 phy_flags, channel);
2758 iwl_print_hex_dump(priv, IWL_DL_RX, data, length);
2761 static inline void iwl4965_dbg_report_frame(struct iwl_priv *priv,
2762 struct iwl_rx_packet *pkt,
2763 struct ieee80211_hdr *header,
2771 /* Called for REPLY_RX (legacy ABG frames), or
2772 * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
2773 static void iwl4965_rx_reply_rx(struct iwl_priv *priv,
2774 struct iwl_rx_mem_buffer *rxb)
2776 struct ieee80211_hdr *header;
2777 struct ieee80211_rx_status rx_status;
2778 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2779 /* Use phy data (Rx signal strength, etc.) contained within
2780 * this rx packet for legacy frames,
2781 * or phy data cached from REPLY_RX_PHY_CMD for HT frames. */
2782 int include_phy = (pkt->hdr.cmd == REPLY_RX);
2783 struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
2784 (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) :
2785 (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
2787 unsigned int len = 0;
2791 rx_status.mactime = le64_to_cpu(rx_start->timestamp);
2793 ieee80211_channel_to_frequency(le16_to_cpu(rx_start->channel));
2794 rx_status.band = (rx_start->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
2795 IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
2796 rx_status.rate_idx =
2797 iwl4965_hwrate_to_plcp_idx(le32_to_cpu(rx_start->rate_n_flags));
2798 if (rx_status.band == IEEE80211_BAND_5GHZ)
2799 rx_status.rate_idx -= IWL_FIRST_OFDM_RATE;
2801 rx_status.antenna = 0;
2804 if ((unlikely(rx_start->cfg_phy_cnt > 20))) {
2805 IWL_DEBUG_DROP("dsp size out of range [0,20]: %d/n",
2806 rx_start->cfg_phy_cnt);
2811 if (priv->last_phy_res[0])
2812 rx_start = (struct iwl4965_rx_phy_res *)
2813 &priv->last_phy_res[1];
2819 IWL_ERROR("MPDU frame without a PHY data\n");
2824 header = (struct ieee80211_hdr *)((u8 *) & rx_start[1]
2825 + rx_start->cfg_phy_cnt);
2827 len = le16_to_cpu(rx_start->byte_count);
2828 rx_end = (__le32 *)(pkt->u.raw + rx_start->cfg_phy_cnt +
2829 sizeof(struct iwl4965_rx_phy_res) + len);
2831 struct iwl4965_rx_mpdu_res_start *amsdu =
2832 (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
2834 header = (void *)(pkt->u.raw +
2835 sizeof(struct iwl4965_rx_mpdu_res_start));
2836 len = le16_to_cpu(amsdu->byte_count);
2837 rx_end = (__le32 *) (pkt->u.raw +
2838 sizeof(struct iwl4965_rx_mpdu_res_start) + len);
2841 if (!(*rx_end & RX_RES_STATUS_NO_CRC32_ERROR) ||
2842 !(*rx_end & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
2843 IWL_DEBUG_RX("Bad CRC or FIFO: 0x%08X.\n",
2844 le32_to_cpu(*rx_end));
2848 priv->ucode_beacon_time = le32_to_cpu(rx_start->beacon_time_stamp);
2850 /* Find max signal strength (dBm) among 3 antenna/receiver chains */
2851 rx_status.signal = iwl4965_calc_rssi(priv, rx_start);
2853 /* Meaningful noise values are available only from beacon statistics,
2854 * which are gathered only when associated, and indicate noise
2855 * only for the associated network channel ...
2856 * Ignore these noise values while scanning (other channels) */
2857 if (iwl_is_associated(priv) &&
2858 !test_bit(STATUS_SCANNING, &priv->status)) {
2859 rx_status.noise = priv->last_rx_noise;
2860 rx_status.qual = iwl4965_calc_sig_qual(rx_status.signal,
2863 rx_status.noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
2864 rx_status.qual = iwl4965_calc_sig_qual(rx_status.signal, 0);
2867 /* Reset beacon noise level if not associated. */
2868 if (!iwl_is_associated(priv))
2869 priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
2871 /* Set "1" to report good data frames in groups of 100 */
2872 /* FIXME: need to optimze the call: */
2873 iwl4965_dbg_report_frame(priv, pkt, header, 1);
2875 IWL_DEBUG_STATS_LIMIT("Rssi %d, noise %d, qual %d, TSF %llu\n",
2876 rx_status.signal, rx_status.noise, rx_status.signal,
2877 (unsigned long long)rx_status.mactime);
2880 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
2881 iwl4965_handle_data_packet(priv, 1, include_phy,
2886 network_packet = iwl4965_is_network_packet(priv, header);
2887 if (network_packet) {
2888 priv->last_rx_rssi = rx_status.signal;
2889 priv->last_beacon_time = priv->ucode_beacon_time;
2890 priv->last_tsf = le64_to_cpu(rx_start->timestamp);
2893 fc = le16_to_cpu(header->frame_control);
2894 switch (fc & IEEE80211_FCTL_FTYPE) {
2895 case IEEE80211_FTYPE_MGMT:
2896 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
2897 iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
2899 iwl4965_handle_data_packet(priv, 0, include_phy, rxb, &rx_status);
2902 case IEEE80211_FTYPE_CTL:
2903 #ifdef CONFIG_IWL4965_HT
2904 switch (fc & IEEE80211_FCTL_STYPE) {
2905 case IEEE80211_STYPE_BACK_REQ:
2906 IWL_DEBUG_HT("IEEE80211_STYPE_BACK_REQ arrived\n");
2907 iwl4965_handle_data_packet(priv, 0, include_phy,
2916 case IEEE80211_FTYPE_DATA: {
2917 DECLARE_MAC_BUF(mac1);
2918 DECLARE_MAC_BUF(mac2);
2919 DECLARE_MAC_BUF(mac3);
2921 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
2922 iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
2925 if (unlikely(!network_packet))
2926 IWL_DEBUG_DROP("Dropping (non network): "
2928 print_mac(mac1, header->addr1),
2929 print_mac(mac2, header->addr2),
2930 print_mac(mac3, header->addr3));
2931 else if (unlikely(iwl4965_is_duplicate_packet(priv, header)))
2932 IWL_DEBUG_DROP("Dropping (dup): %s, %s, %s\n",
2933 print_mac(mac1, header->addr1),
2934 print_mac(mac2, header->addr2),
2935 print_mac(mac3, header->addr3));
2937 iwl4965_handle_data_packet(priv, 1, include_phy, rxb,
2947 /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
2948 * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
2949 static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv,
2950 struct iwl_rx_mem_buffer *rxb)
2952 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2953 priv->last_phy_res[0] = 1;
2954 memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]),
2955 sizeof(struct iwl4965_rx_phy_res));
2957 static void iwl4965_rx_missed_beacon_notif(struct iwl_priv *priv,
2958 struct iwl_rx_mem_buffer *rxb)
2961 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
2962 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
2963 struct iwl4965_missed_beacon_notif *missed_beacon;
2965 missed_beacon = &pkt->u.missed_beacon;
2966 if (le32_to_cpu(missed_beacon->consequtive_missed_beacons) > 5) {
2967 IWL_DEBUG_CALIB("missed bcn cnsq %d totl %d rcd %d expctd %d\n",
2968 le32_to_cpu(missed_beacon->consequtive_missed_beacons),
2969 le32_to_cpu(missed_beacon->total_missed_becons),
2970 le32_to_cpu(missed_beacon->num_recvd_beacons),
2971 le32_to_cpu(missed_beacon->num_expected_beacons));
2972 if (!test_bit(STATUS_SCANNING, &priv->status))
2973 iwl_init_sensitivity(priv);
2975 #endif /*CONFIG_IWL4965_RUN_TIME_CALIB*/
2977 #ifdef CONFIG_IWL4965_HT
2980 * iwl4965_sta_modify_enable_tid_tx - Enable Tx for this TID in station table
2982 static void iwl4965_sta_modify_enable_tid_tx(struct iwl_priv *priv,
2983 int sta_id, int tid)
2985 unsigned long flags;
2987 /* Remove "disable" flag, to enable Tx for this TID */
2988 spin_lock_irqsave(&priv->sta_lock, flags);
2989 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
2990 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
2991 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
2992 spin_unlock_irqrestore(&priv->sta_lock, flags);
2994 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
2998 * iwl4965_tx_status_reply_compressed_ba - Update tx status from block-ack
3000 * Go through block-ack's bitmap of ACK'd frames, update driver's record of
3001 * ACK vs. not. This gets sent to mac80211, then to rate scaling algo.
3003 static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv,
3004 struct iwl_ht_agg *agg,
3005 struct iwl4965_compressed_ba_resp*
3010 u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl);
3011 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
3014 struct ieee80211_tx_status *tx_status;
3016 if (unlikely(!agg->wait_for_ba)) {
3017 IWL_ERROR("Received BA when not expected\n");
3021 /* Mark that the expected block-ack response arrived */
3022 agg->wait_for_ba = 0;
3023 IWL_DEBUG_TX_REPLY("BA %d %d\n", agg->start_idx, ba_resp->seq_ctl);
3025 /* Calculate shift to align block-ack bits with our Tx window bits */
3026 sh = agg->start_idx - SEQ_TO_INDEX(seq_ctl>>4);
3027 if (sh < 0) /* tbw something is wrong with indices */
3030 /* don't use 64-bit values for now */
3031 bitmap = le64_to_cpu(ba_resp->bitmap) >> sh;
3033 if (agg->frame_count > (64 - sh)) {
3034 IWL_DEBUG_TX_REPLY("more frames than bitmap size");
3038 /* check for success or failure according to the
3039 * transmitted bitmap and block-ack bitmap */
3040 bitmap &= agg->bitmap;
3042 /* For each frame attempted in aggregation,
3043 * update driver's record of tx frame's status. */
3044 for (i = 0; i < agg->frame_count ; i++) {
3045 ack = bitmap & (1 << i);
3047 IWL_DEBUG_TX_REPLY("%s ON i=%d idx=%d raw=%d\n",
3048 ack? "ACK":"NACK", i, (agg->start_idx + i) & 0xff,
3049 agg->start_idx + i);
3052 tx_status = &priv->txq[scd_flow].txb[agg->start_idx].status;
3053 tx_status->flags = IEEE80211_TX_STATUS_ACK;
3054 tx_status->flags |= IEEE80211_TX_STATUS_AMPDU;
3055 tx_status->ampdu_ack_map = successes;
3056 tx_status->ampdu_ack_len = agg->frame_count;
3057 iwl4965_hwrate_to_tx_control(priv, agg->rate_n_flags,
3058 &tx_status->control);
3060 IWL_DEBUG_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap);
3066 * iwl4965_tx_queue_stop_scheduler - Stop queue, but keep configuration
3068 static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv,
3071 /* Simply stop the queue, but don't change any configuration;
3072 * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
3073 iwl_write_prph(priv,
3074 IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
3075 (0 << IWL49_SCD_QUEUE_STTS_REG_POS_ACTIVE)|
3076 (1 << IWL49_SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
3080 * txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID
3081 * priv->lock must be held by the caller
3083 static int iwl4965_tx_queue_agg_disable(struct iwl_priv *priv, u16 txq_id,
3084 u16 ssn_idx, u8 tx_fifo)
3088 if (IWL_BACK_QUEUE_FIRST_ID > txq_id) {
3089 IWL_WARNING("queue number too small: %d, must be > %d\n",
3090 txq_id, IWL_BACK_QUEUE_FIRST_ID);
3094 ret = iwl_grab_nic_access(priv);
3098 iwl4965_tx_queue_stop_scheduler(priv, txq_id);
3100 iwl_clear_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
3102 priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
3103 priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
3104 /* supposes that ssn_idx is valid (!= 0xFFF) */
3105 iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
3107 iwl_clear_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
3108 iwl_txq_ctx_deactivate(priv, txq_id);
3109 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
3111 iwl_release_nic_access(priv);
3116 int iwl4965_check_empty_hw_queue(struct iwl_priv *priv, int sta_id,
3119 struct iwl_queue *q = &priv->txq[txq_id].q;
3120 u8 *addr = priv->stations[sta_id].sta.sta.addr;
3121 struct iwl_tid_data *tid_data = &priv->stations[sta_id].tid[tid];
3123 switch (priv->stations[sta_id].tid[tid].agg.state) {
3124 case IWL_EMPTYING_HW_QUEUE_DELBA:
3125 /* We are reclaiming the last packet of the */
3126 /* aggregated HW queue */
3127 if (txq_id == tid_data->agg.txq_id &&
3128 q->read_ptr == q->write_ptr) {
3129 u16 ssn = SEQ_TO_SN(tid_data->seq_number);
3130 int tx_fifo = default_tid_to_tx_fifo[tid];
3131 IWL_DEBUG_HT("HW queue empty: continue DELBA flow\n");
3132 iwl4965_tx_queue_agg_disable(priv, txq_id,
3134 tid_data->agg.state = IWL_AGG_OFF;
3135 ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, addr, tid);
3138 case IWL_EMPTYING_HW_QUEUE_ADDBA:
3139 /* We are reclaiming the last packet of the queue */
3140 if (tid_data->tfds_in_queue == 0) {
3141 IWL_DEBUG_HT("HW queue empty: continue ADDBA flow\n");
3142 tid_data->agg.state = IWL_AGG_ON;
3143 ieee80211_start_tx_ba_cb_irqsafe(priv->hw, addr, tid);
3151 * iwl4965_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
3153 * Handles block-acknowledge notification from device, which reports success
3154 * of frames sent via aggregation.
3156 static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv,
3157 struct iwl_rx_mem_buffer *rxb)
3159 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
3160 struct iwl4965_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
3162 struct iwl_tx_queue *txq = NULL;
3163 struct iwl_ht_agg *agg;
3164 DECLARE_MAC_BUF(mac);
3166 /* "flow" corresponds to Tx queue */
3167 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
3169 /* "ssn" is start of block-ack Tx window, corresponds to index
3170 * (in Tx queue's circular buffer) of first TFD/frame in window */
3171 u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
3173 if (scd_flow >= priv->hw_params.max_txq_num) {
3174 IWL_ERROR("BUG_ON scd_flow is bigger than number of queues");
3178 txq = &priv->txq[scd_flow];
3179 agg = &priv->stations[ba_resp->sta_id].tid[ba_resp->tid].agg;
3181 /* Find index just before block-ack window */
3182 index = iwl_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd);
3184 /* TODO: Need to get this copy more safely - now good for debug */
3186 IWL_DEBUG_TX_REPLY("REPLY_COMPRESSED_BA [%d]Received from %s, "
3189 print_mac(mac, (u8*) &ba_resp->sta_addr_lo32),
3191 IWL_DEBUG_TX_REPLY("TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = "
3192 "%d, scd_ssn = %d\n",
3195 (unsigned long long)le64_to_cpu(ba_resp->bitmap),
3198 IWL_DEBUG_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx \n",
3200 (unsigned long long)agg->bitmap);
3202 /* Update driver's record of ACK vs. not for each frame in window */
3203 iwl4965_tx_status_reply_compressed_ba(priv, agg, ba_resp);
3205 /* Release all TFDs before the SSN, i.e. all TFDs in front of
3206 * block-ack window (we assume that they've been successfully
3207 * transmitted ... if not, it's too late anyway). */
3208 if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) {
3209 /* calculate mac80211 ampdu sw queue to wake */
3211 scd_flow - IWL_BACK_QUEUE_FIRST_ID + priv->hw->queues;
3212 int freed = iwl4965_tx_queue_reclaim(priv, scd_flow, index);
3213 priv->stations[ba_resp->sta_id].
3214 tid[ba_resp->tid].tfds_in_queue -= freed;
3215 if (iwl_queue_space(&txq->q) > txq->q.low_mark &&
3216 priv->mac80211_registered &&
3217 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)
3218 ieee80211_wake_queue(priv->hw, ampdu_q);
3219 iwl4965_check_empty_hw_queue(priv, ba_resp->sta_id,
3220 ba_resp->tid, scd_flow);
3225 * iwl4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue
3227 static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
3234 scd_q2ratid = ra_tid & IWL49_SCD_QUEUE_RA_TID_MAP_RATID_MSK;
3236 tbl_dw_addr = priv->scd_base_addr +
3237 IWL49_SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
3239 tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
3242 tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
3244 tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
3246 iwl_write_targ_mem(priv, tbl_dw_addr, tbl_dw);
3253 * iwl4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue
3255 * NOTE: txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID,
3256 * i.e. it must be one of the higher queues used for aggregation
3258 static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id,
3259 int tx_fifo, int sta_id, int tid,
3262 unsigned long flags;
3266 if (IWL_BACK_QUEUE_FIRST_ID > txq_id)
3267 IWL_WARNING("queue number too small: %d, must be > %d\n",
3268 txq_id, IWL_BACK_QUEUE_FIRST_ID);
3270 ra_tid = BUILD_RAxTID(sta_id, tid);
3272 /* Modify device's station table to Tx this TID */
3273 iwl4965_sta_modify_enable_tid_tx(priv, sta_id, tid);
3275 spin_lock_irqsave(&priv->lock, flags);
3276 rc = iwl_grab_nic_access(priv);
3278 spin_unlock_irqrestore(&priv->lock, flags);
3282 /* Stop this Tx queue before configuring it */
3283 iwl4965_tx_queue_stop_scheduler(priv, txq_id);
3285 /* Map receiver-address / traffic-ID to this queue */
3286 iwl4965_tx_queue_set_q2ratid(priv, ra_tid, txq_id);
3288 /* Set this queue as a chain-building queue */
3289 iwl_set_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
3291 /* Place first TFD at index corresponding to start sequence number.
3292 * Assumes that ssn_idx is valid (!= 0xFFF) */
3293 priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
3294 priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
3295 iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
3297 /* Set up Tx window size and frame limit for this queue */
3298 iwl_write_targ_mem(priv,
3299 priv->scd_base_addr + IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id),
3300 (SCD_WIN_SIZE << IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
3301 IWL49_SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
3303 iwl_write_targ_mem(priv, priv->scd_base_addr +
3304 IWL49_SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32),
3305 (SCD_FRAME_LIMIT << IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS)
3306 & IWL49_SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
3308 iwl_set_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
3310 /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
3311 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1);
3313 iwl_release_nic_access(priv);
3314 spin_unlock_irqrestore(&priv->lock, flags);
3319 #endif /* CONFIG_IWL4965_HT */
3322 #ifdef CONFIG_IWL4965_HT
3323 static int iwl4965_rx_agg_start(struct iwl_priv *priv,
3324 const u8 *addr, int tid, u16 ssn)
3326 unsigned long flags;
3329 sta_id = iwl_find_station(priv, addr);
3330 if (sta_id == IWL_INVALID_STATION)
3333 spin_lock_irqsave(&priv->sta_lock, flags);
3334 priv->stations[sta_id].sta.station_flags_msk = 0;
3335 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
3336 priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
3337 priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
3338 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3339 spin_unlock_irqrestore(&priv->sta_lock, flags);
3341 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
3345 static int iwl4965_rx_agg_stop(struct iwl_priv *priv,
3346 const u8 *addr, int tid)
3348 unsigned long flags;
3351 sta_id = iwl_find_station(priv, addr);
3352 if (sta_id == IWL_INVALID_STATION)
3355 spin_lock_irqsave(&priv->sta_lock, flags);
3356 priv->stations[sta_id].sta.station_flags_msk = 0;
3357 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
3358 priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
3359 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3360 spin_unlock_irqrestore(&priv->sta_lock, flags);
3362 return iwl_send_add_sta(priv, &priv->stations[sta_id].sta,
3367 * Find first available (lowest unused) Tx Queue, mark it "active".
3368 * Called only when finding queue for aggregation.
3369 * Should never return anything < 7, because they should already
3370 * be in use as EDCA AC (0-3), Command (4), HCCA (5, 6).
3372 static int iwl4965_txq_ctx_activate_free(struct iwl_priv *priv)
3376 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++)
3377 if (!test_and_set_bit(txq_id, &priv->txq_ctx_active_msk))
3382 static int iwl4965_tx_agg_start(struct ieee80211_hw *hw, const u8 *ra,
3383 u16 tid, u16 *start_seq_num)
3385 struct iwl_priv *priv = hw->priv;
3391 unsigned long flags;
3392 struct iwl_tid_data *tid_data;
3393 DECLARE_MAC_BUF(mac);
3395 if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
3396 tx_fifo = default_tid_to_tx_fifo[tid];
3400 IWL_WARNING("%s on ra = %s tid = %d\n",
3401 __func__, print_mac(mac, ra), tid);
3403 sta_id = iwl_find_station(priv, ra);
3404 if (sta_id == IWL_INVALID_STATION)
3407 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_OFF) {
3408 IWL_ERROR("Start AGG when state is not IWL_AGG_OFF !\n");
3412 txq_id = iwl4965_txq_ctx_activate_free(priv);
3416 spin_lock_irqsave(&priv->sta_lock, flags);
3417 tid_data = &priv->stations[sta_id].tid[tid];
3418 ssn = SEQ_TO_SN(tid_data->seq_number);
3419 tid_data->agg.txq_id = txq_id;
3420 spin_unlock_irqrestore(&priv->sta_lock, flags);
3422 *start_seq_num = ssn;
3423 ret = iwl4965_tx_queue_agg_enable(priv, txq_id, tx_fifo,
3429 if (tid_data->tfds_in_queue == 0) {
3430 printk(KERN_ERR "HW queue is empty\n");
3431 tid_data->agg.state = IWL_AGG_ON;
3432 ieee80211_start_tx_ba_cb_irqsafe(hw, ra, tid);
3434 IWL_DEBUG_HT("HW queue is NOT empty: %d packets in HW queue\n",
3435 tid_data->tfds_in_queue);
3436 tid_data->agg.state = IWL_EMPTYING_HW_QUEUE_ADDBA;
3441 static int iwl4965_tx_agg_stop(struct ieee80211_hw *hw, const u8 *ra, u16 tid)
3443 struct iwl_priv *priv = hw->priv;
3444 int tx_fifo_id, txq_id, sta_id, ssn = -1;
3445 struct iwl_tid_data *tid_data;
3446 int ret, write_ptr, read_ptr;
3447 unsigned long flags;
3448 DECLARE_MAC_BUF(mac);
3451 IWL_ERROR("ra = NULL\n");
3455 if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
3456 tx_fifo_id = default_tid_to_tx_fifo[tid];
3460 sta_id = iwl_find_station(priv, ra);
3462 if (sta_id == IWL_INVALID_STATION)
3465 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_ON)
3466 IWL_WARNING("Stopping AGG while state not IWL_AGG_ON\n");
3468 tid_data = &priv->stations[sta_id].tid[tid];
3469 ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4;
3470 txq_id = tid_data->agg.txq_id;
3471 write_ptr = priv->txq[txq_id].q.write_ptr;
3472 read_ptr = priv->txq[txq_id].q.read_ptr;
3474 /* The queue is not empty */
3475 if (write_ptr != read_ptr) {
3476 IWL_DEBUG_HT("Stopping a non empty AGG HW QUEUE\n");
3477 priv->stations[sta_id].tid[tid].agg.state =
3478 IWL_EMPTYING_HW_QUEUE_DELBA;
3482 IWL_DEBUG_HT("HW queue is empty\n");
3483 priv->stations[sta_id].tid[tid].agg.state = IWL_AGG_OFF;
3485 spin_lock_irqsave(&priv->lock, flags);
3486 ret = iwl4965_tx_queue_agg_disable(priv, txq_id, ssn, tx_fifo_id);
3487 spin_unlock_irqrestore(&priv->lock, flags);
3492 ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, ra, tid);
3497 int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
3498 enum ieee80211_ampdu_mlme_action action,
3499 const u8 *addr, u16 tid, u16 *ssn)
3501 struct iwl_priv *priv = hw->priv;
3502 DECLARE_MAC_BUF(mac);
3504 IWL_DEBUG_HT("A-MPDU action on addr %s tid %d\n",
3505 print_mac(mac, addr), tid);
3508 case IEEE80211_AMPDU_RX_START:
3509 IWL_DEBUG_HT("start Rx\n");
3510 return iwl4965_rx_agg_start(priv, addr, tid, *ssn);
3511 case IEEE80211_AMPDU_RX_STOP:
3512 IWL_DEBUG_HT("stop Rx\n");
3513 return iwl4965_rx_agg_stop(priv, addr, tid);
3514 case IEEE80211_AMPDU_TX_START:
3515 IWL_DEBUG_HT("start Tx\n");
3516 return iwl4965_tx_agg_start(hw, addr, tid, ssn);
3517 case IEEE80211_AMPDU_TX_STOP:
3518 IWL_DEBUG_HT("stop Tx\n");
3519 return iwl4965_tx_agg_stop(hw, addr, tid);
3521 IWL_DEBUG_HT("unknown\n");
3527 #endif /* CONFIG_IWL4965_HT */
3530 static u16 iwl4965_get_hcmd_size(u8 cmd_id, u16 len)
3534 return (u16) sizeof(struct iwl4965_rxon_cmd);
3540 static u16 iwl4965_build_addsta_hcmd(const struct iwl_addsta_cmd *cmd, u8 *data)
3542 struct iwl4965_addsta_cmd *addsta = (struct iwl4965_addsta_cmd *)data;
3543 addsta->mode = cmd->mode;
3544 memcpy(&addsta->sta, &cmd->sta, sizeof(struct sta_id_modify));
3545 memcpy(&addsta->key, &cmd->key, sizeof(struct iwl4965_keyinfo));
3546 addsta->station_flags = cmd->station_flags;
3547 addsta->station_flags_msk = cmd->station_flags_msk;
3548 addsta->tid_disable_tx = cmd->tid_disable_tx;
3549 addsta->add_immediate_ba_tid = cmd->add_immediate_ba_tid;
3550 addsta->remove_immediate_ba_tid = cmd->remove_immediate_ba_tid;
3551 addsta->add_immediate_ba_ssn = cmd->add_immediate_ba_ssn;
3552 addsta->reserved1 = __constant_cpu_to_le16(0);
3553 addsta->reserved2 = __constant_cpu_to_le32(0);
3555 return (u16)sizeof(struct iwl4965_addsta_cmd);
3557 /* Set up 4965-specific Rx frame reply handlers */
3558 static void iwl4965_rx_handler_setup(struct iwl_priv *priv)
3560 /* Legacy Rx frames */
3561 priv->rx_handlers[REPLY_RX] = iwl4965_rx_reply_rx;
3563 /* High-throughput (HT) Rx frames */
3564 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl4965_rx_reply_rx_phy;
3565 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl4965_rx_reply_rx;
3567 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
3568 iwl4965_rx_missed_beacon_notif;
3570 #ifdef CONFIG_IWL4965_HT
3571 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl4965_rx_reply_compressed_ba;
3572 #endif /* CONFIG_IWL4965_HT */
3575 void iwl4965_hw_setup_deferred_work(struct iwl_priv *priv)
3577 INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work);
3578 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
3579 INIT_WORK(&priv->sensitivity_work, iwl4965_bg_sensitivity_work);
3581 init_timer(&priv->statistics_periodic);
3582 priv->statistics_periodic.data = (unsigned long)priv;
3583 priv->statistics_periodic.function = iwl4965_bg_statistics_periodic;
3586 void iwl4965_hw_cancel_deferred_work(struct iwl_priv *priv)
3588 del_timer_sync(&priv->statistics_periodic);
3590 cancel_delayed_work(&priv->init_alive_start);
3594 static struct iwl_hcmd_ops iwl4965_hcmd = {
3595 .rxon_assoc = iwl4965_send_rxon_assoc,
3598 static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
3599 .get_hcmd_size = iwl4965_get_hcmd_size,
3600 .build_addsta_hcmd = iwl4965_build_addsta_hcmd,
3601 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
3602 .chain_noise_reset = iwl4965_chain_noise_reset,
3603 .gain_computation = iwl4965_gain_computation,
3607 static struct iwl_lib_ops iwl4965_lib = {
3608 .set_hw_params = iwl4965_hw_set_hw_params,
3609 .alloc_shared_mem = iwl4965_alloc_shared_mem,
3610 .free_shared_mem = iwl4965_free_shared_mem,
3611 .shared_mem_rx_idx = iwl4965_shared_mem_rx_idx,
3612 .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl,
3613 .disable_tx_fifo = iwl4965_disable_tx_fifo,
3614 .rx_handler_setup = iwl4965_rx_handler_setup,
3615 .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr,
3616 .alive_notify = iwl4965_alive_notify,
3617 .init_alive_start = iwl4965_init_alive_start,
3618 .load_ucode = iwl4965_load_bsm,
3620 .init = iwl4965_apm_init,
3621 .config = iwl4965_nic_config,
3622 .set_pwr_src = iwl4965_set_pwr_src,
3625 .regulatory_bands = {
3626 EEPROM_REGULATORY_BAND_1_CHANNELS,
3627 EEPROM_REGULATORY_BAND_2_CHANNELS,
3628 EEPROM_REGULATORY_BAND_3_CHANNELS,
3629 EEPROM_REGULATORY_BAND_4_CHANNELS,
3630 EEPROM_REGULATORY_BAND_5_CHANNELS,
3631 EEPROM_4965_REGULATORY_BAND_24_FAT_CHANNELS,
3632 EEPROM_4965_REGULATORY_BAND_52_FAT_CHANNELS
3634 .verify_signature = iwlcore_eeprom_verify_signature,
3635 .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
3636 .release_semaphore = iwlcore_eeprom_release_semaphore,
3637 .check_version = iwl4965_eeprom_check_version,
3638 .query_addr = iwlcore_eeprom_query_addr,
3640 .radio_kill_sw = iwl4965_radio_kill_sw,
3641 .set_power = iwl4965_set_power,
3642 .update_chain_flags = iwl4965_update_chain_flags,
3645 static struct iwl_ops iwl4965_ops = {
3646 .lib = &iwl4965_lib,
3647 .hcmd = &iwl4965_hcmd,
3648 .utils = &iwl4965_hcmd_utils,
3651 struct iwl_cfg iwl4965_agn_cfg = {
3653 .fw_name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode",
3654 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
3655 .eeprom_size = IWL4965_EEPROM_IMG_SIZE,
3656 .ops = &iwl4965_ops,
3657 .mod_params = &iwl4965_mod_params,
3660 module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444);
3661 MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
3662 module_param_named(disable, iwl4965_mod_params.disable, int, 0444);
3663 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
3664 module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, 0444);
3665 MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])\n");
3666 module_param_named(debug, iwl4965_mod_params.debug, int, 0444);
3667 MODULE_PARM_DESC(debug, "debug output mask");
3669 disable_hw_scan, iwl4965_mod_params.disable_hw_scan, int, 0444);
3670 MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
3672 module_param_named(queues_num, iwl4965_mod_params.num_of_queues, int, 0444);
3673 MODULE_PARM_DESC(queues_num, "number of hw queues.");
3676 module_param_named(qos_enable, iwl4965_mod_params.enable_qos, int, 0444);
3677 MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
3678 module_param_named(amsdu_size_8K, iwl4965_mod_params.amsdu_size_8K, int, 0444);
3679 MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");
3680 module_param_named(fw_restart4965, iwl4965_mod_params.restart_fw, int, 0444);
3681 MODULE_PARM_DESC(fw_restart4965, "restart firmware in case of error");