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 = IWL4965_MAX_NUM_QUEUES,
53 /* the rest are 0 by default */
56 static void iwl4965_hw_card_show_info(struct iwl_priv *priv);
58 #define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
59 [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
60 IWL_RATE_SISO_##s##M_PLCP, \
61 IWL_RATE_MIMO2_##s##M_PLCP,\
62 IWL_RATE_MIMO3_##s##M_PLCP,\
63 IWL_RATE_##r##M_IEEE, \
64 IWL_RATE_##ip##M_INDEX, \
65 IWL_RATE_##in##M_INDEX, \
66 IWL_RATE_##rp##M_INDEX, \
67 IWL_RATE_##rn##M_INDEX, \
68 IWL_RATE_##pp##M_INDEX, \
69 IWL_RATE_##np##M_INDEX }
73 * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
75 * If there isn't a valid next or previous rate then INV is used which
76 * maps to IWL_RATE_INVALID
79 const struct iwl4965_rate_info iwl4965_rates[IWL_RATE_COUNT] = {
80 IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
81 IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
82 IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
83 IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
84 IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
85 IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
86 IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
87 IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
88 IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
89 IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
90 IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
91 IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
92 IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
93 /* FIXME:RS: ^^ should be INV (legacy) */
96 #ifdef CONFIG_IWL4965_HT
98 static const u16 default_tid_to_tx_fifo[] = {
118 #endif /*CONFIG_IWL4965_HT */
120 /* check contents of special bootstrap uCode SRAM */
121 static int iwl4965_verify_bsm(struct iwl_priv *priv)
123 __le32 *image = priv->ucode_boot.v_addr;
124 u32 len = priv->ucode_boot.len;
128 IWL_DEBUG_INFO("Begin verify bsm\n");
130 /* verify BSM SRAM contents */
131 val = iwl_read_prph(priv, BSM_WR_DWCOUNT_REG);
132 for (reg = BSM_SRAM_LOWER_BOUND;
133 reg < BSM_SRAM_LOWER_BOUND + len;
134 reg += sizeof(u32), image++) {
135 val = iwl_read_prph(priv, reg);
136 if (val != le32_to_cpu(*image)) {
137 IWL_ERROR("BSM uCode verification failed at "
138 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
139 BSM_SRAM_LOWER_BOUND,
140 reg - BSM_SRAM_LOWER_BOUND, len,
141 val, le32_to_cpu(*image));
146 IWL_DEBUG_INFO("BSM bootstrap uCode image OK\n");
152 * iwl4965_load_bsm - Load bootstrap instructions
156 * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
157 * in special SRAM that does not power down during RFKILL. When powering back
158 * up after power-saving sleeps (or during initial uCode load), the BSM loads
159 * the bootstrap program into the on-board processor, and starts it.
161 * The bootstrap program loads (via DMA) instructions and data for a new
162 * program from host DRAM locations indicated by the host driver in the
163 * BSM_DRAM_* registers. Once the new program is loaded, it starts
166 * When initializing the NIC, the host driver points the BSM to the
167 * "initialize" uCode image. This uCode sets up some internal data, then
168 * notifies host via "initialize alive" that it is complete.
170 * The host then replaces the BSM_DRAM_* pointer values to point to the
171 * normal runtime uCode instructions and a backup uCode data cache buffer
172 * (filled initially with starting data values for the on-board processor),
173 * then triggers the "initialize" uCode to load and launch the runtime uCode,
174 * which begins normal operation.
176 * When doing a power-save shutdown, runtime uCode saves data SRAM into
177 * the backup data cache in DRAM before SRAM is powered down.
179 * When powering back up, the BSM loads the bootstrap program. This reloads
180 * the runtime uCode instructions and the backup data cache into SRAM,
181 * and re-launches the runtime uCode from where it left off.
183 static int iwl4965_load_bsm(struct iwl_priv *priv)
185 __le32 *image = priv->ucode_boot.v_addr;
186 u32 len = priv->ucode_boot.len;
196 IWL_DEBUG_INFO("Begin load bsm\n");
198 /* make sure bootstrap program is no larger than BSM's SRAM size */
199 if (len > IWL_MAX_BSM_SIZE)
202 /* Tell bootstrap uCode where to find the "Initialize" uCode
203 * in host DRAM ... host DRAM physical address bits 35:4 for 4965.
204 * NOTE: iwl4965_initialize_alive_start() will replace these values,
205 * after the "initialize" uCode has run, to point to
206 * runtime/protocol instructions and backup data cache. */
207 pinst = priv->ucode_init.p_addr >> 4;
208 pdata = priv->ucode_init_data.p_addr >> 4;
209 inst_len = priv->ucode_init.len;
210 data_len = priv->ucode_init_data.len;
212 ret = iwl_grab_nic_access(priv);
216 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
217 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
218 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG, inst_len);
219 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG, data_len);
221 /* Fill BSM memory with bootstrap instructions */
222 for (reg_offset = BSM_SRAM_LOWER_BOUND;
223 reg_offset < BSM_SRAM_LOWER_BOUND + len;
224 reg_offset += sizeof(u32), image++)
225 _iwl_write_prph(priv, reg_offset, le32_to_cpu(*image));
227 ret = iwl4965_verify_bsm(priv);
229 iwl_release_nic_access(priv);
233 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
234 iwl_write_prph(priv, BSM_WR_MEM_SRC_REG, 0x0);
235 iwl_write_prph(priv, BSM_WR_MEM_DST_REG, RTC_INST_LOWER_BOUND);
236 iwl_write_prph(priv, BSM_WR_DWCOUNT_REG, len / sizeof(u32));
238 /* Load bootstrap code into instruction SRAM now,
239 * to prepare to load "initialize" uCode */
240 iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START);
242 /* Wait for load of bootstrap uCode to finish */
243 for (i = 0; i < 100; i++) {
244 done = iwl_read_prph(priv, BSM_WR_CTRL_REG);
245 if (!(done & BSM_WR_CTRL_REG_BIT_START))
250 IWL_DEBUG_INFO("BSM write complete, poll %d iterations\n", i);
252 IWL_ERROR("BSM write did not complete!\n");
256 /* Enable future boot loads whenever power management unit triggers it
257 * (e.g. when powering back up after power-save shutdown) */
258 iwl_write_prph(priv, BSM_WR_CTRL_REG, BSM_WR_CTRL_REG_BIT_START_EN);
260 iwl_release_nic_access(priv);
265 static int iwl4965_init_drv(struct iwl_priv *priv)
270 priv->retry_rate = 1;
271 priv->ibss_beacon = NULL;
273 spin_lock_init(&priv->lock);
274 spin_lock_init(&priv->power_data.lock);
275 spin_lock_init(&priv->sta_lock);
276 spin_lock_init(&priv->hcmd_lock);
277 spin_lock_init(&priv->lq_mngr.lock);
279 for (i = 0; i < IWL_IBSS_MAC_HASH_SIZE; i++)
280 INIT_LIST_HEAD(&priv->ibss_mac_hash[i]);
282 INIT_LIST_HEAD(&priv->free_frames);
284 mutex_init(&priv->mutex);
286 /* Clear the driver's (not device's) station table */
287 iwlcore_clear_stations_table(priv);
289 priv->data_retry_limit = -1;
290 priv->ieee_channels = NULL;
291 priv->ieee_rates = NULL;
292 priv->band = IEEE80211_BAND_2GHZ;
294 priv->iw_mode = IEEE80211_IF_TYPE_STA;
296 priv->use_ant_b_for_management_frame = 1; /* start with ant B */
297 priv->ps_mode = IWL_MIMO_PS_NONE;
299 /* Choose which receivers/antennas to use */
300 iwl4965_set_rxon_chain(priv);
302 iwlcore_reset_qos(priv);
304 priv->qos_data.qos_active = 0;
305 priv->qos_data.qos_cap.val = 0;
307 iwlcore_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
309 priv->rates_mask = IWL_RATES_MASK;
310 /* If power management is turned on, default to AC mode */
311 priv->power_mode = IWL_POWER_AC;
312 priv->user_txpower_limit = IWL_DEFAULT_TX_POWER;
314 ret = iwl_init_channel_map(priv);
316 IWL_ERROR("initializing regulatory failed: %d\n", ret);
320 ret = iwl4965_init_geos(priv);
322 IWL_ERROR("initializing geos failed: %d\n", ret);
323 goto err_free_channel_map;
326 ret = ieee80211_register_hw(priv->hw);
328 IWL_ERROR("Failed to register network device (error %d)\n",
333 priv->hw->conf.beacon_int = 100;
334 priv->mac80211_registered = 1;
339 iwl4965_free_geos(priv);
340 err_free_channel_map:
341 iwl_free_channel_map(priv);
346 static int is_fat_channel(__le32 rxon_flags)
348 return (rxon_flags & RXON_FLG_CHANNEL_MODE_PURE_40_MSK) ||
349 (rxon_flags & RXON_FLG_CHANNEL_MODE_MIXED_MSK);
352 #ifdef CONFIG_IWL4965_HT
353 static u8 is_single_rx_stream(struct iwl_priv *priv)
355 return !priv->current_ht_config.is_ht ||
356 ((priv->current_ht_config.supp_mcs_set[1] == 0) &&
357 (priv->current_ht_config.supp_mcs_set[2] == 0)) ||
358 priv->ps_mode == IWL_MIMO_PS_STATIC;
361 static inline u8 is_single_rx_stream(struct iwl_priv *priv)
365 #endif /*CONFIG_IWL4965_HT */
367 int iwl4965_hwrate_to_plcp_idx(u32 rate_n_flags)
371 /* 4965 HT rate format */
372 if (rate_n_flags & RATE_MCS_HT_MSK) {
373 idx = (rate_n_flags & 0xff);
375 if (idx >= IWL_RATE_MIMO2_6M_PLCP)
376 idx = idx - IWL_RATE_MIMO2_6M_PLCP;
378 idx += IWL_FIRST_OFDM_RATE;
379 /* skip 9M not supported in ht*/
380 if (idx >= IWL_RATE_9M_INDEX)
382 if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE))
385 /* 4965 legacy rate format, search for match in table */
387 for (idx = 0; idx < ARRAY_SIZE(iwl4965_rates); idx++)
388 if (iwl4965_rates[idx].plcp == (rate_n_flags & 0xFF))
396 * translate ucode response to mac80211 tx status control values
398 void iwl4965_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags,
399 struct ieee80211_tx_control *control)
403 control->antenna_sel_tx =
404 ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS);
405 if (rate_n_flags & RATE_MCS_HT_MSK)
406 control->flags |= IEEE80211_TXCTL_OFDM_HT;
407 if (rate_n_flags & RATE_MCS_GF_MSK)
408 control->flags |= IEEE80211_TXCTL_GREEN_FIELD;
409 if (rate_n_flags & RATE_MCS_FAT_MSK)
410 control->flags |= IEEE80211_TXCTL_40_MHZ_WIDTH;
411 if (rate_n_flags & RATE_MCS_DUP_MSK)
412 control->flags |= IEEE80211_TXCTL_DUP_DATA;
413 if (rate_n_flags & RATE_MCS_SGI_MSK)
414 control->flags |= IEEE80211_TXCTL_SHORT_GI;
415 /* since iwl4965_hwrate_to_plcp_idx is band indifferent, we always use
416 * IEEE80211_BAND_2GHZ band as it contains all the rates */
417 rate_index = iwl4965_hwrate_to_plcp_idx(rate_n_flags);
418 if (rate_index == -1)
419 control->tx_rate = NULL;
422 &priv->bands[IEEE80211_BAND_2GHZ].bitrates[rate_index];
426 * Determine how many receiver/antenna chains to use.
427 * More provides better reception via diversity. Fewer saves power.
428 * MIMO (dual stream) requires at least 2, but works better with 3.
429 * This does not determine *which* chains to use, just how many.
431 static int iwl4965_get_rx_chain_counter(struct iwl_priv *priv,
432 u8 *idle_state, u8 *rx_state)
434 u8 is_single = is_single_rx_stream(priv);
435 u8 is_cam = test_bit(STATUS_POWER_PMI, &priv->status) ? 0 : 1;
437 /* # of Rx chains to use when expecting MIMO. */
438 if (is_single || (!is_cam && (priv->ps_mode == IWL_MIMO_PS_STATIC)))
443 /* # Rx chains when idling and maybe trying to save power */
444 switch (priv->ps_mode) {
445 case IWL_MIMO_PS_STATIC:
446 case IWL_MIMO_PS_DYNAMIC:
447 *idle_state = (is_cam) ? 2 : 1;
449 case IWL_MIMO_PS_NONE:
450 *idle_state = (is_cam) ? *rx_state : 1;
460 int iwl4965_hw_rxq_stop(struct iwl_priv *priv)
465 spin_lock_irqsave(&priv->lock, flags);
466 rc = iwl_grab_nic_access(priv);
468 spin_unlock_irqrestore(&priv->lock, flags);
473 iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
474 rc = iwl_poll_direct_bit(priv, FH_MEM_RSSR_RX_STATUS_REG,
477 IWL_ERROR("Can't stop Rx DMA.\n");
479 iwl_release_nic_access(priv);
480 spin_unlock_irqrestore(&priv->lock, flags);
489 static int iwl4965_eeprom_check_version(struct iwl_priv *priv)
494 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
496 calib_ver = iwl_eeprom_query16(priv, EEPROM_4965_CALIB_VERSION_OFFSET);
498 if (eeprom_ver < EEPROM_4965_EEPROM_VERSION ||
499 calib_ver < EEPROM_4965_TX_POWER_VERSION)
504 IWL_ERROR("Unsuported EEPROM VER=0x%x < 0x%x CALIB=0x%x < 0x%x\n",
505 eeprom_ver, EEPROM_4965_EEPROM_VERSION,
506 calib_ver, EEPROM_4965_TX_POWER_VERSION);
510 int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
515 spin_lock_irqsave(&priv->lock, flags);
516 ret = iwl_grab_nic_access(priv);
518 spin_unlock_irqrestore(&priv->lock, flags);
522 if (src == IWL_PWR_SRC_VAUX) {
524 ret = pci_read_config_dword(priv->pci_dev, PCI_POWER_SOURCE,
527 if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT) {
528 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
529 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
530 ~APMG_PS_CTRL_MSK_PWR_SRC);
533 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
534 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
535 ~APMG_PS_CTRL_MSK_PWR_SRC);
538 iwl_release_nic_access(priv);
539 spin_unlock_irqrestore(&priv->lock, flags);
544 static int iwl4965_rx_init(struct iwl_priv *priv, struct iwl4965_rx_queue *rxq)
548 unsigned int rb_size;
550 spin_lock_irqsave(&priv->lock, flags);
551 ret = iwl_grab_nic_access(priv);
553 spin_unlock_irqrestore(&priv->lock, flags);
557 if (priv->cfg->mod_params->amsdu_size_8K)
558 rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_8K;
560 rb_size = FH_RCSR_RX_CONFIG_REG_VAL_RB_SIZE_4K;
563 iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG, 0);
565 /* Reset driver's Rx queue write index */
566 iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_WPTR_REG, 0);
568 /* Tell device where to find RBD circular buffer in DRAM */
569 iwl_write_direct32(priv, FH_RSCSR_CHNL0_RBDCB_BASE_REG,
572 /* Tell device where in DRAM to update its Rx status */
573 iwl_write_direct32(priv, FH_RSCSR_CHNL0_STTS_WPTR_REG,
575 offsetof(struct iwl4965_shared, rb_closed)) >> 4);
577 /* Enable Rx DMA, enable host interrupt, Rx buffer size 4k, 256 RBDs */
578 iwl_write_direct32(priv, FH_MEM_RCSR_CHNL0_CONFIG_REG,
579 FH_RCSR_RX_CONFIG_CHNL_EN_ENABLE_VAL |
580 FH_RCSR_CHNL0_RX_CONFIG_IRQ_DEST_INT_HOST_VAL |
583 (RX_QUEUE_SIZE_LOG <<
584 FH_RCSR_RX_CONFIG_RBDCB_SIZE_BITSHIFT));
587 * iwl_write32(priv,CSR_INT_COAL_REG,0);
590 iwl_release_nic_access(priv);
591 spin_unlock_irqrestore(&priv->lock, flags);
596 /* Tell 4965 where to find the "keep warm" buffer */
597 static int iwl4965_kw_init(struct iwl_priv *priv)
602 spin_lock_irqsave(&priv->lock, flags);
603 rc = iwl_grab_nic_access(priv);
607 iwl_write_direct32(priv, IWL_FH_KW_MEM_ADDR_REG,
608 priv->kw.dma_addr >> 4);
609 iwl_release_nic_access(priv);
611 spin_unlock_irqrestore(&priv->lock, flags);
615 static int iwl4965_kw_alloc(struct iwl_priv *priv)
617 struct pci_dev *dev = priv->pci_dev;
618 struct iwl4965_kw *kw = &priv->kw;
620 kw->size = IWL4965_KW_SIZE; /* TBW need set somewhere else */
621 kw->v_addr = pci_alloc_consistent(dev, kw->size, &kw->dma_addr);
629 * iwl4965_kw_free - Free the "keep warm" buffer
631 static void iwl4965_kw_free(struct iwl_priv *priv)
633 struct pci_dev *dev = priv->pci_dev;
634 struct iwl4965_kw *kw = &priv->kw;
637 pci_free_consistent(dev, kw->size, kw->v_addr, kw->dma_addr);
638 memset(kw, 0, sizeof(*kw));
643 * iwl4965_txq_ctx_reset - Reset TX queue context
644 * Destroys all DMA structures and initialise them again
649 static int iwl4965_txq_ctx_reset(struct iwl_priv *priv)
652 int txq_id, slots_num;
655 iwl4965_kw_free(priv);
657 /* Free all tx/cmd queues and keep-warm buffer */
658 iwl4965_hw_txq_ctx_free(priv);
660 /* Alloc keep-warm buffer */
661 rc = iwl4965_kw_alloc(priv);
663 IWL_ERROR("Keep Warm allocation failed");
667 spin_lock_irqsave(&priv->lock, flags);
669 rc = iwl_grab_nic_access(priv);
671 IWL_ERROR("TX reset failed");
672 spin_unlock_irqrestore(&priv->lock, flags);
676 /* Turn off all Tx DMA channels */
677 iwl_write_prph(priv, IWL49_SCD_TXFACT, 0);
678 iwl_release_nic_access(priv);
679 spin_unlock_irqrestore(&priv->lock, flags);
681 /* Tell 4965 where to find the keep-warm buffer */
682 rc = iwl4965_kw_init(priv);
684 IWL_ERROR("kw_init failed\n");
688 /* Alloc and init all (default 16) Tx queues,
689 * including the command queue (#4) */
690 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
691 slots_num = (txq_id == IWL_CMD_QUEUE_NUM) ?
692 TFD_CMD_SLOTS : TFD_TX_CMD_SLOTS;
693 rc = iwl4965_tx_queue_init(priv, &priv->txq[txq_id], slots_num,
696 IWL_ERROR("Tx %d queue init failed\n", txq_id);
704 iwl4965_hw_txq_ctx_free(priv);
706 iwl4965_kw_free(priv);
710 static int iwl4965_apm_init(struct iwl_priv *priv)
715 spin_lock_irqsave(&priv->lock, flags);
716 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
717 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
719 /* set "initialization complete" bit to move adapter
720 * D0U* --> D0A* state */
721 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
723 /* wait for clock stabilization */
724 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
725 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
726 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
728 IWL_DEBUG_INFO("Failed to init the card\n");
732 ret = iwl_grab_nic_access(priv);
737 iwl_write_prph(priv, APMG_CLK_CTRL_REG,
738 APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT);
742 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
743 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
745 iwl_release_nic_access(priv);
747 spin_unlock_irqrestore(&priv->lock, flags);
751 int iwl4965_hw_nic_init(struct iwl_priv *priv)
754 struct iwl4965_rx_queue *rxq = &priv->rxq;
760 priv->cfg->ops->lib->apm_ops.init(priv);
762 spin_lock_irqsave(&priv->lock, flags);
763 iwl_write32(priv, CSR_INT_COALESCING, 512 / 32);
764 spin_unlock_irqrestore(&priv->lock, flags);
766 ret = priv->cfg->ops->lib->apm_ops.set_pwr_src(priv, IWL_PWR_SRC_VMAIN);
768 spin_lock_irqsave(&priv->lock, flags);
770 if ((priv->rev_id & 0x80) == 0x80 && (priv->rev_id & 0x7f) < 8) {
771 pci_read_config_dword(priv->pci_dev, PCI_REG_WUM8, &val);
772 /* Enable No Snoop field */
773 pci_write_config_dword(priv->pci_dev, PCI_REG_WUM8,
777 spin_unlock_irqrestore(&priv->lock, flags);
779 pci_read_config_byte(priv->pci_dev, PCI_LINK_CTRL, &val_link);
781 /* disable L1 entry -- workaround for pre-B1 */
782 pci_write_config_byte(priv->pci_dev, PCI_LINK_CTRL, val_link & ~0x02);
784 spin_lock_irqsave(&priv->lock, flags);
786 /* set CSR_HW_CONFIG_REG for uCode use */
788 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
789 CSR49_HW_IF_CONFIG_REG_BIT_4965_R |
790 CSR49_HW_IF_CONFIG_REG_BIT_RADIO_SI |
791 CSR49_HW_IF_CONFIG_REG_BIT_MAC_SI);
793 ret = iwl_grab_nic_access(priv);
795 spin_unlock_irqrestore(&priv->lock, flags);
796 IWL_DEBUG_INFO("Failed to init the card\n");
800 iwl_read_prph(priv, APMG_PS_CTRL_REG);
801 iwl_set_bits_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ);
803 iwl_clear_bits_prph(priv, APMG_PS_CTRL_REG, APMG_PS_CTRL_VAL_RESET_REQ);
805 iwl_release_nic_access(priv);
806 spin_unlock_irqrestore(&priv->lock, flags);
808 iwl4965_hw_card_show_info(priv);
812 /* Allocate the RX queue, or reset if it is already allocated */
814 ret = iwl4965_rx_queue_alloc(priv);
816 IWL_ERROR("Unable to initialize Rx queue\n");
820 iwl4965_rx_queue_reset(priv, rxq);
822 iwl4965_rx_replenish(priv);
824 iwl4965_rx_init(priv, rxq);
826 spin_lock_irqsave(&priv->lock, flags);
828 rxq->need_update = 1;
829 iwl4965_rx_queue_update_write_ptr(priv, rxq);
831 /* init the txpower calibration pointer */
832 priv->calib_info = (struct iwl_eeprom_calib_info *)
833 iwl_eeprom_query_addr(priv, EEPROM_4965_CALIB_TXPOWER_OFFSET);
835 spin_unlock_irqrestore(&priv->lock, flags);
837 /* Allocate and init all Tx and Command queues */
838 ret = iwl4965_txq_ctx_reset(priv);
842 set_bit(STATUS_INIT, &priv->status);
847 int iwl4965_hw_nic_stop_master(struct iwl_priv *priv)
853 spin_lock_irqsave(&priv->lock, flags);
855 /* set stop master bit */
856 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
858 reg_val = iwl_read32(priv, CSR_GP_CNTRL);
860 if (CSR_GP_CNTRL_REG_FLAG_MAC_POWER_SAVE ==
861 (reg_val & CSR_GP_CNTRL_REG_MSK_POWER_SAVE_TYPE))
862 IWL_DEBUG_INFO("Card in power save, master is already "
865 rc = iwl_poll_bit(priv, CSR_RESET,
866 CSR_RESET_REG_FLAG_MASTER_DISABLED,
867 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
869 spin_unlock_irqrestore(&priv->lock, flags);
874 spin_unlock_irqrestore(&priv->lock, flags);
875 IWL_DEBUG_INFO("stop master\n");
881 * iwl4965_hw_txq_ctx_stop - Stop all Tx DMA channels, free Tx queue memory
883 void iwl4965_hw_txq_ctx_stop(struct iwl_priv *priv)
889 /* Stop each Tx DMA channel, and wait for it to be idle */
890 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++) {
891 spin_lock_irqsave(&priv->lock, flags);
892 if (iwl_grab_nic_access(priv)) {
893 spin_unlock_irqrestore(&priv->lock, flags);
897 iwl_write_direct32(priv,
898 IWL_FH_TCSR_CHNL_TX_CONFIG_REG(txq_id), 0x0);
899 iwl_poll_direct_bit(priv, IWL_FH_TSSR_TX_STATUS_REG,
900 IWL_FH_TSSR_TX_STATUS_REG_MSK_CHNL_IDLE
902 iwl_release_nic_access(priv);
903 spin_unlock_irqrestore(&priv->lock, flags);
906 /* Deallocate memory for all Tx queues */
907 iwl4965_hw_txq_ctx_free(priv);
910 int iwl4965_hw_nic_reset(struct iwl_priv *priv)
915 iwl4965_hw_nic_stop_master(priv);
917 spin_lock_irqsave(&priv->lock, flags);
919 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
923 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
924 rc = iwl_poll_bit(priv, CSR_RESET,
925 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
926 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25);
930 rc = iwl_grab_nic_access(priv);
932 iwl_write_prph(priv, APMG_CLK_EN_REG,
933 APMG_CLK_VAL_DMA_CLK_RQT |
934 APMG_CLK_VAL_BSM_CLK_RQT);
938 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
939 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
941 iwl_release_nic_access(priv);
944 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
945 wake_up_interruptible(&priv->wait_command_queue);
947 spin_unlock_irqrestore(&priv->lock, flags);
953 #define REG_RECALIB_PERIOD (60)
956 * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
958 * This callback is provided in order to send a statistics request.
960 * This timer function is continually reset to execute within
961 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
962 * was received. We need to ensure we receive the statistics in order
963 * to update the temperature used for calibrating the TXPOWER.
965 static void iwl4965_bg_statistics_periodic(unsigned long data)
967 struct iwl_priv *priv = (struct iwl_priv *)data;
969 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
972 iwl_send_statistics_request(priv, CMD_ASYNC);
975 void iwl4965_rf_kill_ct_config(struct iwl_priv *priv)
977 struct iwl4965_ct_kill_config cmd;
981 spin_lock_irqsave(&priv->lock, flags);
982 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
983 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
984 spin_unlock_irqrestore(&priv->lock, flags);
986 cmd.critical_temperature_R =
987 cpu_to_le32(priv->hw_params.ct_kill_threshold);
989 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
992 IWL_ERROR("REPLY_CT_KILL_CONFIG_CMD failed\n");
994 IWL_DEBUG_INFO("REPLY_CT_KILL_CONFIG_CMD succeeded, "
995 "critical temperature is %d\n",
996 cmd.critical_temperature_R);
999 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
1001 /* Reset differential Rx gains in NIC to prepare for chain noise calibration.
1002 * Called after every association, but this runs only once!
1003 * ... once chain noise is calibrated the first time, it's good forever. */
1004 static void iwl4965_chain_noise_reset(struct iwl_priv *priv)
1006 struct iwl_chain_noise_data *data = &(priv->chain_noise_data);
1008 if ((data->state == IWL_CHAIN_NOISE_ALIVE) && iwl_is_associated(priv)) {
1009 struct iwl4965_calibration_cmd cmd;
1011 memset(&cmd, 0, sizeof(cmd));
1012 cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
1013 cmd.diff_gain_a = 0;
1014 cmd.diff_gain_b = 0;
1015 cmd.diff_gain_c = 0;
1016 if (iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
1018 IWL_ERROR("Could not send REPLY_PHY_CALIBRATION_CMD\n");
1019 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
1020 IWL_DEBUG_CALIB("Run chain_noise_calibrate\n");
1024 static void iwl4965_gain_computation(struct iwl_priv *priv,
1026 u16 min_average_noise_antenna_i,
1027 u32 min_average_noise)
1030 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
1032 data->delta_gain_code[min_average_noise_antenna_i] = 0;
1034 for (i = 0; i < NUM_RX_CHAINS; i++) {
1037 if (!(data->disconn_array[i]) &&
1038 (data->delta_gain_code[i] ==
1039 CHAIN_NOISE_DELTA_GAIN_INIT_VAL)) {
1040 delta_g = average_noise[i] - min_average_noise;
1041 data->delta_gain_code[i] = (u8)((delta_g * 10) / 15);
1042 data->delta_gain_code[i] =
1043 min(data->delta_gain_code[i],
1044 (u8) CHAIN_NOISE_MAX_DELTA_GAIN_CODE);
1046 data->delta_gain_code[i] =
1047 (data->delta_gain_code[i] | (1 << 2));
1049 data->delta_gain_code[i] = 0;
1052 IWL_DEBUG_CALIB("delta_gain_codes: a %d b %d c %d\n",
1053 data->delta_gain_code[0],
1054 data->delta_gain_code[1],
1055 data->delta_gain_code[2]);
1057 /* Differential gain gets sent to uCode only once */
1058 if (!data->radio_write) {
1059 struct iwl4965_calibration_cmd cmd;
1060 data->radio_write = 1;
1062 memset(&cmd, 0, sizeof(cmd));
1063 cmd.opCode = PHY_CALIBRATE_DIFF_GAIN_CMD;
1064 cmd.diff_gain_a = data->delta_gain_code[0];
1065 cmd.diff_gain_b = data->delta_gain_code[1];
1066 cmd.diff_gain_c = data->delta_gain_code[2];
1067 ret = iwl_send_cmd_pdu(priv, REPLY_PHY_CALIBRATION_CMD,
1070 IWL_DEBUG_CALIB("fail sending cmd "
1071 "REPLY_PHY_CALIBRATION_CMD \n");
1073 /* TODO we might want recalculate
1074 * rx_chain in rxon cmd */
1076 /* Mark so we run this algo only once! */
1077 data->state = IWL_CHAIN_NOISE_CALIBRATED;
1079 data->chain_noise_a = 0;
1080 data->chain_noise_b = 0;
1081 data->chain_noise_c = 0;
1082 data->chain_signal_a = 0;
1083 data->chain_signal_b = 0;
1084 data->chain_signal_c = 0;
1085 data->beacon_count = 0;
1088 static void iwl4965_bg_sensitivity_work(struct work_struct *work)
1090 struct iwl_priv *priv = container_of(work, struct iwl_priv,
1093 mutex_lock(&priv->mutex);
1095 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
1096 test_bit(STATUS_SCANNING, &priv->status)) {
1097 mutex_unlock(&priv->mutex);
1101 if (priv->start_calib) {
1102 iwl_chain_noise_calibration(priv, &priv->statistics);
1104 iwl_sensitivity_calibration(priv, &priv->statistics);
1107 mutex_unlock(&priv->mutex);
1110 #endif /*CONFIG_IWL4965_RUN_TIME_CALIB*/
1112 static void iwl4965_bg_txpower_work(struct work_struct *work)
1114 struct iwl_priv *priv = container_of(work, struct iwl_priv,
1117 /* If a scan happened to start before we got here
1118 * then just return; the statistics notification will
1119 * kick off another scheduled work to compensate for
1120 * any temperature delta we missed here. */
1121 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
1122 test_bit(STATUS_SCANNING, &priv->status))
1125 mutex_lock(&priv->mutex);
1127 /* Regardless of if we are assocaited, we must reconfigure the
1128 * TX power since frames can be sent on non-radar channels while
1130 iwl4965_hw_reg_send_txpower(priv);
1132 /* Update last_temperature to keep is_calib_needed from running
1133 * when it isn't needed... */
1134 priv->last_temperature = priv->temperature;
1136 mutex_unlock(&priv->mutex);
1140 * Acquire priv->lock before calling this function !
1142 static void iwl4965_set_wr_ptrs(struct iwl_priv *priv, int txq_id, u32 index)
1144 iwl_write_direct32(priv, HBUS_TARG_WRPTR,
1145 (index & 0xff) | (txq_id << 8));
1146 iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(txq_id), index);
1150 * iwl4965_tx_queue_set_status - (optionally) start Tx/Cmd queue
1151 * @tx_fifo_id: Tx DMA/FIFO channel (range 0-7) that the queue will feed
1152 * @scd_retry: (1) Indicates queue will be used in aggregation mode
1154 * NOTE: Acquire priv->lock before calling this function !
1156 static void iwl4965_tx_queue_set_status(struct iwl_priv *priv,
1157 struct iwl4965_tx_queue *txq,
1158 int tx_fifo_id, int scd_retry)
1160 int txq_id = txq->q.id;
1162 /* Find out whether to activate Tx queue */
1163 int active = test_bit(txq_id, &priv->txq_ctx_active_msk)?1:0;
1165 /* Set up and activate */
1166 iwl_write_prph(priv, IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
1167 (active << SCD_QUEUE_STTS_REG_POS_ACTIVE) |
1168 (tx_fifo_id << SCD_QUEUE_STTS_REG_POS_TXF) |
1169 (scd_retry << SCD_QUEUE_STTS_REG_POS_WSL) |
1170 (scd_retry << SCD_QUEUE_STTS_REG_POS_SCD_ACK) |
1171 SCD_QUEUE_STTS_REG_MSK);
1173 txq->sched_retry = scd_retry;
1175 IWL_DEBUG_INFO("%s %s Queue %d on AC %d\n",
1176 active ? "Activate" : "Deactivate",
1177 scd_retry ? "BA" : "AC", txq_id, tx_fifo_id);
1180 static const u16 default_queue_to_tx_fifo[] = {
1190 static inline void iwl4965_txq_ctx_activate(struct iwl_priv *priv, int txq_id)
1192 set_bit(txq_id, &priv->txq_ctx_active_msk);
1195 static inline void iwl4965_txq_ctx_deactivate(struct iwl_priv *priv, int txq_id)
1197 clear_bit(txq_id, &priv->txq_ctx_active_msk);
1200 int iwl4965_alive_notify(struct iwl_priv *priv)
1204 unsigned long flags;
1207 spin_lock_irqsave(&priv->lock, flags);
1209 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
1210 memset(&(priv->sensitivity_data), 0,
1211 sizeof(struct iwl_sensitivity_data));
1212 memset(&(priv->chain_noise_data), 0,
1213 sizeof(struct iwl_chain_noise_data));
1214 for (i = 0; i < NUM_RX_CHAINS; i++)
1215 priv->chain_noise_data.delta_gain_code[i] =
1216 CHAIN_NOISE_DELTA_GAIN_INIT_VAL;
1217 #endif /* CONFIG_IWL4965_RUN_TIME_CALIB*/
1218 ret = iwl_grab_nic_access(priv);
1220 spin_unlock_irqrestore(&priv->lock, flags);
1224 /* Clear 4965's internal Tx Scheduler data base */
1225 priv->scd_base_addr = iwl_read_prph(priv, IWL49_SCD_SRAM_BASE_ADDR);
1226 a = priv->scd_base_addr + SCD_CONTEXT_DATA_OFFSET;
1227 for (; a < priv->scd_base_addr + SCD_TX_STTS_BITMAP_OFFSET; a += 4)
1228 iwl_write_targ_mem(priv, a, 0);
1229 for (; a < priv->scd_base_addr + SCD_TRANSLATE_TBL_OFFSET; a += 4)
1230 iwl_write_targ_mem(priv, a, 0);
1231 for (; a < sizeof(u16) * priv->hw_params.max_txq_num; a += 4)
1232 iwl_write_targ_mem(priv, a, 0);
1234 /* Tel 4965 where to find Tx byte count tables */
1235 iwl_write_prph(priv, IWL49_SCD_DRAM_BASE_ADDR,
1236 (priv->shared_phys +
1237 offsetof(struct iwl4965_shared, queues_byte_cnt_tbls)) >> 10);
1239 /* Disable chain mode for all queues */
1240 iwl_write_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, 0);
1242 /* Initialize each Tx queue (including the command queue) */
1243 for (i = 0; i < priv->hw_params.max_txq_num; i++) {
1245 /* TFD circular buffer read/write indexes */
1246 iwl_write_prph(priv, IWL49_SCD_QUEUE_RDPTR(i), 0);
1247 iwl_write_direct32(priv, HBUS_TARG_WRPTR, 0 | (i << 8));
1249 /* Max Tx Window size for Scheduler-ACK mode */
1250 iwl_write_targ_mem(priv, priv->scd_base_addr +
1251 SCD_CONTEXT_QUEUE_OFFSET(i),
1253 SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
1254 SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
1257 iwl_write_targ_mem(priv, priv->scd_base_addr +
1258 SCD_CONTEXT_QUEUE_OFFSET(i) +
1261 SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS) &
1262 SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
1265 iwl_write_prph(priv, IWL49_SCD_INTERRUPT_MASK,
1266 (1 << priv->hw_params.max_txq_num) - 1);
1268 /* Activate all Tx DMA/FIFO channels */
1269 iwl_write_prph(priv, IWL49_SCD_TXFACT,
1270 SCD_TXFACT_REG_TXFIFO_MASK(0, 7));
1272 iwl4965_set_wr_ptrs(priv, IWL_CMD_QUEUE_NUM, 0);
1274 /* Map each Tx/cmd queue to its corresponding fifo */
1275 for (i = 0; i < ARRAY_SIZE(default_queue_to_tx_fifo); i++) {
1276 int ac = default_queue_to_tx_fifo[i];
1277 iwl4965_txq_ctx_activate(priv, i);
1278 iwl4965_tx_queue_set_status(priv, &priv->txq[i], ac, 0);
1281 iwl_release_nic_access(priv);
1282 spin_unlock_irqrestore(&priv->lock, flags);
1284 /* Ask for statistics now, the uCode will send statistics notification
1285 * periodically after association */
1286 iwl_send_statistics_request(priv, CMD_ASYNC);
1290 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
1291 static struct iwl_sensitivity_ranges iwl4965_sensitivity = {
1295 .auto_corr_min_ofdm = 85,
1296 .auto_corr_min_ofdm_mrc = 170,
1297 .auto_corr_min_ofdm_x1 = 105,
1298 .auto_corr_min_ofdm_mrc_x1 = 220,
1300 .auto_corr_max_ofdm = 120,
1301 .auto_corr_max_ofdm_mrc = 210,
1302 .auto_corr_max_ofdm_x1 = 140,
1303 .auto_corr_max_ofdm_mrc_x1 = 270,
1305 .auto_corr_min_cck = 125,
1306 .auto_corr_max_cck = 200,
1307 .auto_corr_min_cck_mrc = 200,
1308 .auto_corr_max_cck_mrc = 400,
1316 * iwl4965_hw_set_hw_params
1318 * Called when initializing driver
1320 int iwl4965_hw_set_hw_params(struct iwl_priv *priv)
1323 if ((priv->cfg->mod_params->num_of_queues > IWL4965_MAX_NUM_QUEUES) ||
1324 (priv->cfg->mod_params->num_of_queues < IWL_MIN_NUM_QUEUES)) {
1325 IWL_ERROR("invalid queues_num, should be between %d and %d\n",
1326 IWL_MIN_NUM_QUEUES, IWL4965_MAX_NUM_QUEUES);
1330 priv->hw_params.max_txq_num = priv->cfg->mod_params->num_of_queues;
1331 priv->hw_params.sw_crypto = priv->cfg->mod_params->sw_crypto;
1332 priv->hw_params.tx_cmd_len = sizeof(struct iwl4965_tx_cmd);
1333 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
1334 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
1335 if (priv->cfg->mod_params->amsdu_size_8K)
1336 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_8K;
1338 priv->hw_params.rx_buf_size = IWL_RX_BUF_SIZE_4K;
1339 priv->hw_params.max_pkt_size = priv->hw_params.rx_buf_size - 256;
1340 priv->hw_params.max_stations = IWL4965_STATION_COUNT;
1341 priv->hw_params.bcast_sta_id = IWL4965_BROADCAST_ID;
1343 priv->hw_params.max_data_size = IWL49_RTC_DATA_SIZE;
1344 priv->hw_params.max_inst_size = IWL49_RTC_INST_SIZE;
1345 priv->hw_params.max_bsm_size = BSM_SRAM_SIZE;
1346 priv->hw_params.fat_channel = BIT(IEEE80211_BAND_5GHZ);
1348 priv->hw_params.tx_chains_num = 2;
1349 priv->hw_params.rx_chains_num = 2;
1350 priv->hw_params.valid_tx_ant = ANT_A | ANT_B;
1351 priv->hw_params.valid_rx_ant = ANT_A | ANT_B;
1352 priv->hw_params.ct_kill_threshold = CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD);
1354 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
1355 priv->hw_params.sens = &iwl4965_sensitivity;
1362 * iwl4965_hw_txq_ctx_free - Free TXQ Context
1364 * Destroy all TX DMA queues and structures
1366 void iwl4965_hw_txq_ctx_free(struct iwl_priv *priv)
1371 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++)
1372 iwl4965_tx_queue_free(priv, &priv->txq[txq_id]);
1374 /* Keep-warm buffer */
1375 iwl4965_kw_free(priv);
1379 * iwl4965_hw_txq_free_tfd - Free all chunks referenced by TFD [txq->q.read_ptr]
1381 * Does NOT advance any TFD circular buffer read/write indexes
1382 * Does NOT free the TFD itself (which is within circular buffer)
1384 int iwl4965_hw_txq_free_tfd(struct iwl_priv *priv, struct iwl4965_tx_queue *txq)
1386 struct iwl4965_tfd_frame *bd_tmp = (struct iwl4965_tfd_frame *)&txq->bd[0];
1387 struct iwl4965_tfd_frame *bd = &bd_tmp[txq->q.read_ptr];
1388 struct pci_dev *dev = priv->pci_dev;
1393 /* Host command buffers stay mapped in memory, nothing to clean */
1394 if (txq->q.id == IWL_CMD_QUEUE_NUM)
1397 /* Sanity check on number of chunks */
1398 counter = IWL_GET_BITS(*bd, num_tbs);
1399 if (counter > MAX_NUM_OF_TBS) {
1400 IWL_ERROR("Too many chunks: %i\n", counter);
1401 /* @todo issue fatal error, it is quite serious situation */
1405 /* Unmap chunks, if any.
1406 * TFD info for odd chunks is different format than for even chunks. */
1407 for (i = 0; i < counter; i++) {
1414 IWL_GET_BITS(bd->pa[index], tb2_addr_lo16) |
1415 (IWL_GET_BITS(bd->pa[index],
1416 tb2_addr_hi20) << 16),
1417 IWL_GET_BITS(bd->pa[index], tb2_len),
1421 pci_unmap_single(dev,
1422 le32_to_cpu(bd->pa[index].tb1_addr),
1423 IWL_GET_BITS(bd->pa[index], tb1_len),
1426 /* Free SKB, if any, for this chunk */
1427 if (txq->txb[txq->q.read_ptr].skb[i]) {
1428 struct sk_buff *skb = txq->txb[txq->q.read_ptr].skb[i];
1431 txq->txb[txq->q.read_ptr].skb[i] = NULL;
1437 /* set card power command */
1438 static int iwl4965_set_power(struct iwl_priv *priv,
1443 ret = iwl_send_cmd_pdu_async(priv, POWER_TABLE_CMD,
1444 sizeof(struct iwl4965_powertable_cmd),
1448 int iwl4965_hw_reg_set_txpower(struct iwl_priv *priv, s8 power)
1450 IWL_ERROR("TODO: Implement iwl4965_hw_reg_set_txpower!\n");
1454 static s32 iwl4965_math_div_round(s32 num, s32 denom, s32 *res)
1467 *res = ((num * 2 + denom) / (denom * 2)) * sign;
1473 * iwl4965_get_voltage_compensation - Power supply voltage comp for txpower
1475 * Determines power supply voltage compensation for txpower calculations.
1476 * Returns number of 1/2-dB steps to subtract from gain table index,
1477 * to compensate for difference between power supply voltage during
1478 * factory measurements, vs. current power supply voltage.
1480 * Voltage indication is higher for lower voltage.
1481 * Lower voltage requires more gain (lower gain table index).
1483 static s32 iwl4965_get_voltage_compensation(s32 eeprom_voltage,
1484 s32 current_voltage)
1488 if ((TX_POWER_IWL_ILLEGAL_VOLTAGE == eeprom_voltage) ||
1489 (TX_POWER_IWL_ILLEGAL_VOLTAGE == current_voltage))
1492 iwl4965_math_div_round(current_voltage - eeprom_voltage,
1493 TX_POWER_IWL_VOLTAGE_CODES_PER_03V, &comp);
1495 if (current_voltage > eeprom_voltage)
1497 if ((comp < -2) || (comp > 2))
1503 static const struct iwl_channel_info *
1504 iwl4965_get_channel_txpower_info(struct iwl_priv *priv,
1505 enum ieee80211_band band, u16 channel)
1507 const struct iwl_channel_info *ch_info;
1509 ch_info = iwl_get_channel_info(priv, band, channel);
1511 if (!is_channel_valid(ch_info))
1517 static s32 iwl4965_get_tx_atten_grp(u16 channel)
1519 if (channel >= CALIB_IWL_TX_ATTEN_GR5_FCH &&
1520 channel <= CALIB_IWL_TX_ATTEN_GR5_LCH)
1521 return CALIB_CH_GROUP_5;
1523 if (channel >= CALIB_IWL_TX_ATTEN_GR1_FCH &&
1524 channel <= CALIB_IWL_TX_ATTEN_GR1_LCH)
1525 return CALIB_CH_GROUP_1;
1527 if (channel >= CALIB_IWL_TX_ATTEN_GR2_FCH &&
1528 channel <= CALIB_IWL_TX_ATTEN_GR2_LCH)
1529 return CALIB_CH_GROUP_2;
1531 if (channel >= CALIB_IWL_TX_ATTEN_GR3_FCH &&
1532 channel <= CALIB_IWL_TX_ATTEN_GR3_LCH)
1533 return CALIB_CH_GROUP_3;
1535 if (channel >= CALIB_IWL_TX_ATTEN_GR4_FCH &&
1536 channel <= CALIB_IWL_TX_ATTEN_GR4_LCH)
1537 return CALIB_CH_GROUP_4;
1539 IWL_ERROR("Can't find txatten group for channel %d.\n", channel);
1543 static u32 iwl4965_get_sub_band(const struct iwl_priv *priv, u32 channel)
1547 for (b = 0; b < EEPROM_TX_POWER_BANDS; b++) {
1548 if (priv->calib_info->band_info[b].ch_from == 0)
1551 if ((channel >= priv->calib_info->band_info[b].ch_from)
1552 && (channel <= priv->calib_info->band_info[b].ch_to))
1559 static s32 iwl4965_interpolate_value(s32 x, s32 x1, s32 y1, s32 x2, s32 y2)
1566 iwl4965_math_div_round((x2 - x) * (y1 - y2), (x2 - x1), &val);
1572 * iwl4965_interpolate_chan - Interpolate factory measurements for one channel
1574 * Interpolates factory measurements from the two sample channels within a
1575 * sub-band, to apply to channel of interest. Interpolation is proportional to
1576 * differences in channel frequencies, which is proportional to differences
1577 * in channel number.
1579 static int iwl4965_interpolate_chan(struct iwl_priv *priv, u32 channel,
1580 struct iwl_eeprom_calib_ch_info *chan_info)
1585 const struct iwl_eeprom_calib_measure *m1;
1586 const struct iwl_eeprom_calib_measure *m2;
1587 struct iwl_eeprom_calib_measure *omeas;
1591 s = iwl4965_get_sub_band(priv, channel);
1592 if (s >= EEPROM_TX_POWER_BANDS) {
1593 IWL_ERROR("Tx Power can not find channel %d ", channel);
1597 ch_i1 = priv->calib_info->band_info[s].ch1.ch_num;
1598 ch_i2 = priv->calib_info->band_info[s].ch2.ch_num;
1599 chan_info->ch_num = (u8) channel;
1601 IWL_DEBUG_TXPOWER("channel %d subband %d factory cal ch %d & %d\n",
1602 channel, s, ch_i1, ch_i2);
1604 for (c = 0; c < EEPROM_TX_POWER_TX_CHAINS; c++) {
1605 for (m = 0; m < EEPROM_TX_POWER_MEASUREMENTS; m++) {
1606 m1 = &(priv->calib_info->band_info[s].ch1.
1607 measurements[c][m]);
1608 m2 = &(priv->calib_info->band_info[s].ch2.
1609 measurements[c][m]);
1610 omeas = &(chan_info->measurements[c][m]);
1613 (u8) iwl4965_interpolate_value(channel, ch_i1,
1618 (u8) iwl4965_interpolate_value(channel, ch_i1,
1619 m1->gain_idx, ch_i2,
1621 omeas->temperature =
1622 (u8) iwl4965_interpolate_value(channel, ch_i1,
1627 (s8) iwl4965_interpolate_value(channel, ch_i1,
1632 ("chain %d meas %d AP1=%d AP2=%d AP=%d\n", c, m,
1633 m1->actual_pow, m2->actual_pow, omeas->actual_pow);
1635 ("chain %d meas %d NI1=%d NI2=%d NI=%d\n", c, m,
1636 m1->gain_idx, m2->gain_idx, omeas->gain_idx);
1638 ("chain %d meas %d PA1=%d PA2=%d PA=%d\n", c, m,
1639 m1->pa_det, m2->pa_det, omeas->pa_det);
1641 ("chain %d meas %d T1=%d T2=%d T=%d\n", c, m,
1642 m1->temperature, m2->temperature,
1643 omeas->temperature);
1650 /* bit-rate-dependent table to prevent Tx distortion, in half-dB units,
1651 * for OFDM 6, 12, 18, 24, 36, 48, 54, 60 MBit, and CCK all rates. */
1652 static s32 back_off_table[] = {
1653 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 20 MHz */
1654 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 20 MHz */
1655 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 40 MHz */
1656 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 40 MHz */
1660 /* Thermal compensation values for txpower for various frequency ranges ...
1661 * ratios from 3:1 to 4.5:1 of degrees (Celsius) per half-dB gain adjust */
1662 static struct iwl4965_txpower_comp_entry {
1663 s32 degrees_per_05db_a;
1664 s32 degrees_per_05db_a_denom;
1665 } tx_power_cmp_tble[CALIB_CH_GROUP_MAX] = {
1666 {9, 2}, /* group 0 5.2, ch 34-43 */
1667 {4, 1}, /* group 1 5.2, ch 44-70 */
1668 {4, 1}, /* group 2 5.2, ch 71-124 */
1669 {4, 1}, /* group 3 5.2, ch 125-200 */
1670 {3, 1} /* group 4 2.4, ch all */
1673 static s32 get_min_power_index(s32 rate_power_index, u32 band)
1676 if ((rate_power_index & 7) <= 4)
1677 return MIN_TX_GAIN_INDEX_52GHZ_EXT;
1679 return MIN_TX_GAIN_INDEX;
1687 static const struct gain_entry gain_table[2][108] = {
1688 /* 5.2GHz power gain index table */
1690 {123, 0x3F}, /* highest txpower */
1799 /* 2.4GHz power gain index table */
1801 {110, 0x3f}, /* highest txpower */
1912 static int iwl4965_fill_txpower_tbl(struct iwl_priv *priv, u8 band, u16 channel,
1913 u8 is_fat, u8 ctrl_chan_high,
1914 struct iwl4965_tx_power_db *tx_power_tbl)
1916 u8 saturation_power;
1918 s32 user_target_power;
1922 s32 current_regulatory;
1923 s32 txatten_grp = CALIB_CH_GROUP_MAX;
1926 const struct iwl_channel_info *ch_info = NULL;
1927 struct iwl_eeprom_calib_ch_info ch_eeprom_info;
1928 const struct iwl_eeprom_calib_measure *measurement;
1931 s32 voltage_compensation;
1932 s32 degrees_per_05db_num;
1933 s32 degrees_per_05db_denom;
1935 s32 temperature_comp[2];
1936 s32 factory_gain_index[2];
1937 s32 factory_actual_pwr[2];
1940 /* Sanity check requested level (dBm) */
1941 if (priv->user_txpower_limit < IWL_TX_POWER_TARGET_POWER_MIN) {
1942 IWL_WARNING("Requested user TXPOWER %d below limit.\n",
1943 priv->user_txpower_limit);
1946 if (priv->user_txpower_limit > IWL_TX_POWER_TARGET_POWER_MAX) {
1947 IWL_WARNING("Requested user TXPOWER %d above limit.\n",
1948 priv->user_txpower_limit);
1952 /* user_txpower_limit is in dBm, convert to half-dBm (half-dB units
1953 * are used for indexing into txpower table) */
1954 user_target_power = 2 * priv->user_txpower_limit;
1956 /* Get current (RXON) channel, band, width */
1958 iwl4965_get_channel_txpower_info(priv, priv->band, channel);
1960 IWL_DEBUG_TXPOWER("chan %d band %d is_fat %d\n", channel, band,
1966 /* get txatten group, used to select 1) thermal txpower adjustment
1967 * and 2) mimo txpower balance between Tx chains. */
1968 txatten_grp = iwl4965_get_tx_atten_grp(channel);
1969 if (txatten_grp < 0)
1972 IWL_DEBUG_TXPOWER("channel %d belongs to txatten group %d\n",
1973 channel, txatten_grp);
1982 /* hardware txpower limits ...
1983 * saturation (clipping distortion) txpowers are in half-dBm */
1985 saturation_power = priv->calib_info->saturation_power24;
1987 saturation_power = priv->calib_info->saturation_power52;
1989 if (saturation_power < IWL_TX_POWER_SATURATION_MIN ||
1990 saturation_power > IWL_TX_POWER_SATURATION_MAX) {
1992 saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_24;
1994 saturation_power = IWL_TX_POWER_DEFAULT_SATURATION_52;
1997 /* regulatory txpower limits ... reg_limit values are in half-dBm,
1998 * max_power_avg values are in dBm, convert * 2 */
2000 reg_limit = ch_info->fat_max_power_avg * 2;
2002 reg_limit = ch_info->max_power_avg * 2;
2004 if ((reg_limit < IWL_TX_POWER_REGULATORY_MIN) ||
2005 (reg_limit > IWL_TX_POWER_REGULATORY_MAX)) {
2007 reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_24;
2009 reg_limit = IWL_TX_POWER_DEFAULT_REGULATORY_52;
2012 /* Interpolate txpower calibration values for this channel,
2013 * based on factory calibration tests on spaced channels. */
2014 iwl4965_interpolate_chan(priv, channel, &ch_eeprom_info);
2016 /* calculate tx gain adjustment based on power supply voltage */
2017 voltage = priv->calib_info->voltage;
2018 init_voltage = (s32)le32_to_cpu(priv->card_alive_init.voltage);
2019 voltage_compensation =
2020 iwl4965_get_voltage_compensation(voltage, init_voltage);
2022 IWL_DEBUG_TXPOWER("curr volt %d eeprom volt %d volt comp %d\n",
2024 voltage, voltage_compensation);
2026 /* get current temperature (Celsius) */
2027 current_temp = max(priv->temperature, IWL_TX_POWER_TEMPERATURE_MIN);
2028 current_temp = min(priv->temperature, IWL_TX_POWER_TEMPERATURE_MAX);
2029 current_temp = KELVIN_TO_CELSIUS(current_temp);
2031 /* select thermal txpower adjustment params, based on channel group
2032 * (same frequency group used for mimo txatten adjustment) */
2033 degrees_per_05db_num =
2034 tx_power_cmp_tble[txatten_grp].degrees_per_05db_a;
2035 degrees_per_05db_denom =
2036 tx_power_cmp_tble[txatten_grp].degrees_per_05db_a_denom;
2038 /* get per-chain txpower values from factory measurements */
2039 for (c = 0; c < 2; c++) {
2040 measurement = &ch_eeprom_info.measurements[c][1];
2042 /* txgain adjustment (in half-dB steps) based on difference
2043 * between factory and current temperature */
2044 factory_temp = measurement->temperature;
2045 iwl4965_math_div_round((current_temp - factory_temp) *
2046 degrees_per_05db_denom,
2047 degrees_per_05db_num,
2048 &temperature_comp[c]);
2050 factory_gain_index[c] = measurement->gain_idx;
2051 factory_actual_pwr[c] = measurement->actual_pow;
2053 IWL_DEBUG_TXPOWER("chain = %d\n", c);
2054 IWL_DEBUG_TXPOWER("fctry tmp %d, "
2055 "curr tmp %d, comp %d steps\n",
2056 factory_temp, current_temp,
2057 temperature_comp[c]);
2059 IWL_DEBUG_TXPOWER("fctry idx %d, fctry pwr %d\n",
2060 factory_gain_index[c],
2061 factory_actual_pwr[c]);
2064 /* for each of 33 bit-rates (including 1 for CCK) */
2065 for (i = 0; i < POWER_TABLE_NUM_ENTRIES; i++) {
2067 union iwl4965_tx_power_dual_stream tx_power;
2069 /* for mimo, reduce each chain's txpower by half
2070 * (3dB, 6 steps), so total output power is regulatory
2073 current_regulatory = reg_limit -
2074 IWL_TX_POWER_MIMO_REGULATORY_COMPENSATION;
2077 current_regulatory = reg_limit;
2081 /* find txpower limit, either hardware or regulatory */
2082 power_limit = saturation_power - back_off_table[i];
2083 if (power_limit > current_regulatory)
2084 power_limit = current_regulatory;
2086 /* reduce user's txpower request if necessary
2087 * for this rate on this channel */
2088 target_power = user_target_power;
2089 if (target_power > power_limit)
2090 target_power = power_limit;
2092 IWL_DEBUG_TXPOWER("rate %d sat %d reg %d usr %d tgt %d\n",
2093 i, saturation_power - back_off_table[i],
2094 current_regulatory, user_target_power,
2097 /* for each of 2 Tx chains (radio transmitters) */
2098 for (c = 0; c < 2; c++) {
2103 (s32)le32_to_cpu(priv->card_alive_init.
2104 tx_atten[txatten_grp][c]);
2108 /* calculate index; higher index means lower txpower */
2109 power_index = (u8) (factory_gain_index[c] -
2111 factory_actual_pwr[c]) -
2112 temperature_comp[c] -
2113 voltage_compensation +
2116 /* IWL_DEBUG_TXPOWER("calculated txpower index %d\n",
2119 if (power_index < get_min_power_index(i, band))
2120 power_index = get_min_power_index(i, band);
2122 /* adjust 5 GHz index to support negative indexes */
2126 /* CCK, rate 32, reduce txpower for CCK */
2127 if (i == POWER_TABLE_CCK_ENTRY)
2129 IWL_TX_POWER_CCK_COMPENSATION_C_STEP;
2131 /* stay within the table! */
2132 if (power_index > 107) {
2133 IWL_WARNING("txpower index %d > 107\n",
2137 if (power_index < 0) {
2138 IWL_WARNING("txpower index %d < 0\n",
2143 /* fill txpower command for this rate/chain */
2144 tx_power.s.radio_tx_gain[c] =
2145 gain_table[band][power_index].radio;
2146 tx_power.s.dsp_predis_atten[c] =
2147 gain_table[band][power_index].dsp;
2149 IWL_DEBUG_TXPOWER("chain %d mimo %d index %d "
2150 "gain 0x%02x dsp %d\n",
2151 c, atten_value, power_index,
2152 tx_power.s.radio_tx_gain[c],
2153 tx_power.s.dsp_predis_atten[c]);
2154 }/* for each chain */
2156 tx_power_tbl->power_tbl[i].dw = cpu_to_le32(tx_power.dw);
2158 }/* for each rate */
2164 * iwl4965_hw_reg_send_txpower - Configure the TXPOWER level user limit
2166 * Uses the active RXON for channel, band, and characteristics (fat, high)
2167 * The power limit is taken from priv->user_txpower_limit.
2169 int iwl4965_hw_reg_send_txpower(struct iwl_priv *priv)
2171 struct iwl4965_txpowertable_cmd cmd = { 0 };
2175 u8 ctrl_chan_high = 0;
2177 if (test_bit(STATUS_SCANNING, &priv->status)) {
2178 /* If this gets hit a lot, switch it to a BUG() and catch
2179 * the stack trace to find out who is calling this during
2181 IWL_WARNING("TX Power requested while scanning!\n");
2185 band = priv->band == IEEE80211_BAND_2GHZ;
2187 is_fat = is_fat_channel(priv->active_rxon.flags);
2190 (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
2194 cmd.channel = priv->active_rxon.channel;
2196 ret = iwl4965_fill_txpower_tbl(priv, band,
2197 le16_to_cpu(priv->active_rxon.channel),
2198 is_fat, ctrl_chan_high, &cmd.tx_power);
2202 ret = iwl_send_cmd_pdu(priv, REPLY_TX_PWR_TABLE_CMD, sizeof(cmd), &cmd);
2208 static int iwl4965_send_rxon_assoc(struct iwl_priv *priv)
2211 struct iwl4965_rxon_assoc_cmd rxon_assoc;
2212 const struct iwl4965_rxon_cmd *rxon1 = &priv->staging_rxon;
2213 const struct iwl4965_rxon_cmd *rxon2 = &priv->active_rxon;
2215 if ((rxon1->flags == rxon2->flags) &&
2216 (rxon1->filter_flags == rxon2->filter_flags) &&
2217 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
2218 (rxon1->ofdm_ht_single_stream_basic_rates ==
2219 rxon2->ofdm_ht_single_stream_basic_rates) &&
2220 (rxon1->ofdm_ht_dual_stream_basic_rates ==
2221 rxon2->ofdm_ht_dual_stream_basic_rates) &&
2222 (rxon1->rx_chain == rxon2->rx_chain) &&
2223 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
2224 IWL_DEBUG_INFO("Using current RXON_ASSOC. Not resending.\n");
2228 rxon_assoc.flags = priv->staging_rxon.flags;
2229 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
2230 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
2231 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
2232 rxon_assoc.reserved = 0;
2233 rxon_assoc.ofdm_ht_single_stream_basic_rates =
2234 priv->staging_rxon.ofdm_ht_single_stream_basic_rates;
2235 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
2236 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates;
2237 rxon_assoc.rx_chain_select_flags = priv->staging_rxon.rx_chain;
2239 ret = iwl_send_cmd_pdu_async(priv, REPLY_RXON_ASSOC,
2240 sizeof(rxon_assoc), &rxon_assoc, NULL);
2248 int iwl4965_hw_channel_switch(struct iwl_priv *priv, u16 channel)
2253 u8 ctrl_chan_high = 0;
2254 struct iwl4965_channel_switch_cmd cmd = { 0 };
2255 const struct iwl_channel_info *ch_info;
2257 band = priv->band == IEEE80211_BAND_2GHZ;
2259 ch_info = iwl_get_channel_info(priv, priv->band, channel);
2261 is_fat = is_fat_channel(priv->staging_rxon.flags);
2264 (priv->active_rxon.flags & RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK))
2268 cmd.expect_beacon = 0;
2269 cmd.channel = cpu_to_le16(channel);
2270 cmd.rxon_flags = priv->active_rxon.flags;
2271 cmd.rxon_filter_flags = priv->active_rxon.filter_flags;
2272 cmd.switch_time = cpu_to_le32(priv->ucode_beacon_time);
2274 cmd.expect_beacon = is_channel_radar(ch_info);
2276 cmd.expect_beacon = 1;
2278 rc = iwl4965_fill_txpower_tbl(priv, band, channel, is_fat,
2279 ctrl_chan_high, &cmd.tx_power);
2281 IWL_DEBUG_11H("error:%d fill txpower_tbl\n", rc);
2285 rc = iwl_send_cmd_pdu(priv, REPLY_CHANNEL_SWITCH, sizeof(cmd), &cmd);
2289 #define RTS_HCCA_RETRY_LIMIT 3
2290 #define RTS_DFAULT_RETRY_LIMIT 60
2292 void iwl4965_hw_build_tx_cmd_rate(struct iwl_priv *priv,
2293 struct iwl_cmd *cmd,
2294 struct ieee80211_tx_control *ctrl,
2295 struct ieee80211_hdr *hdr, int sta_id,
2298 struct iwl4965_tx_cmd *tx = &cmd->cmd.tx;
2299 u8 rts_retry_limit = 0;
2300 u8 data_retry_limit = 0;
2301 u16 fc = le16_to_cpu(hdr->frame_control);
2304 int rate_idx = min(ctrl->tx_rate->hw_value & 0xffff, IWL_RATE_COUNT - 1);
2306 rate_plcp = iwl4965_rates[rate_idx].plcp;
2308 rts_retry_limit = (is_hcca) ?
2309 RTS_HCCA_RETRY_LIMIT : RTS_DFAULT_RETRY_LIMIT;
2311 if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE))
2312 rate_flags |= RATE_MCS_CCK_MSK;
2315 if (ieee80211_is_probe_response(fc)) {
2316 data_retry_limit = 3;
2317 if (data_retry_limit < rts_retry_limit)
2318 rts_retry_limit = data_retry_limit;
2320 data_retry_limit = IWL_DEFAULT_TX_RETRY;
2322 if (priv->data_retry_limit != -1)
2323 data_retry_limit = priv->data_retry_limit;
2326 if (ieee80211_is_data(fc)) {
2327 tx->initial_rate_index = 0;
2328 tx->tx_flags |= TX_CMD_FLG_STA_RATE_MSK;
2330 switch (fc & IEEE80211_FCTL_STYPE) {
2331 case IEEE80211_STYPE_AUTH:
2332 case IEEE80211_STYPE_DEAUTH:
2333 case IEEE80211_STYPE_ASSOC_REQ:
2334 case IEEE80211_STYPE_REASSOC_REQ:
2335 if (tx->tx_flags & TX_CMD_FLG_RTS_MSK) {
2336 tx->tx_flags &= ~TX_CMD_FLG_RTS_MSK;
2337 tx->tx_flags |= TX_CMD_FLG_CTS_MSK;
2344 /* Alternate between antenna A and B for successive frames */
2345 if (priv->use_ant_b_for_management_frame) {
2346 priv->use_ant_b_for_management_frame = 0;
2347 rate_flags |= RATE_MCS_ANT_B_MSK;
2349 priv->use_ant_b_for_management_frame = 1;
2350 rate_flags |= RATE_MCS_ANT_A_MSK;
2354 tx->rts_retry_limit = rts_retry_limit;
2355 tx->data_retry_limit = data_retry_limit;
2356 tx->rate_n_flags = iwl4965_hw_set_rate_n_flags(rate_plcp, rate_flags);
2359 int iwl4965_hw_get_rx_read(struct iwl_priv *priv)
2361 struct iwl4965_shared *s = priv->shared_virt;
2362 return le32_to_cpu(s->rb_closed) & 0xFFF;
2365 int iwl4965_hw_get_temperature(struct iwl_priv *priv)
2367 return priv->temperature;
2370 unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
2371 struct iwl4965_frame *frame, u8 rate)
2373 struct iwl4965_tx_beacon_cmd *tx_beacon_cmd;
2374 unsigned int frame_size;
2376 tx_beacon_cmd = &frame->u.beacon;
2377 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
2379 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
2380 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
2382 frame_size = iwl4965_fill_beacon_frame(priv,
2383 tx_beacon_cmd->frame,
2384 iwl4965_broadcast_addr,
2385 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
2387 BUG_ON(frame_size > MAX_MPDU_SIZE);
2388 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
2390 if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
2391 tx_beacon_cmd->tx.rate_n_flags =
2392 iwl4965_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
2394 tx_beacon_cmd->tx.rate_n_flags =
2395 iwl4965_hw_set_rate_n_flags(rate, 0);
2397 tx_beacon_cmd->tx.tx_flags = (TX_CMD_FLG_SEQ_CTL_MSK |
2398 TX_CMD_FLG_TSF_MSK | TX_CMD_FLG_STA_RATE_MSK);
2399 return (sizeof(*tx_beacon_cmd) + frame_size);
2403 * Tell 4965 where to find circular buffer of Tx Frame Descriptors for
2404 * given Tx queue, and enable the DMA channel used for that queue.
2406 * 4965 supports up to 16 Tx queues in DRAM, mapped to up to 8 Tx DMA
2407 * channels supported in hardware.
2409 int iwl4965_hw_tx_queue_init(struct iwl_priv *priv, struct iwl4965_tx_queue *txq)
2412 unsigned long flags;
2413 int txq_id = txq->q.id;
2415 spin_lock_irqsave(&priv->lock, flags);
2416 rc = iwl_grab_nic_access(priv);
2418 spin_unlock_irqrestore(&priv->lock, flags);
2422 /* Circular buffer (TFD queue in DRAM) physical base address */
2423 iwl_write_direct32(priv, FH_MEM_CBBC_QUEUE(txq_id),
2424 txq->q.dma_addr >> 8);
2426 /* Enable DMA channel, using same id as for TFD queue */
2428 priv, IWL_FH_TCSR_CHNL_TX_CONFIG_REG(txq_id),
2429 IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CHNL_ENABLE |
2430 IWL_FH_TCSR_TX_CONFIG_REG_VAL_DMA_CREDIT_ENABLE_VAL);
2431 iwl_release_nic_access(priv);
2432 spin_unlock_irqrestore(&priv->lock, flags);
2437 int iwl4965_hw_txq_attach_buf_to_tfd(struct iwl_priv *priv, void *ptr,
2438 dma_addr_t addr, u16 len)
2441 struct iwl4965_tfd_frame *tfd = ptr;
2442 u32 num_tbs = IWL_GET_BITS(*tfd, num_tbs);
2444 /* Each TFD can point to a maximum 20 Tx buffers */
2445 if ((num_tbs >= MAX_NUM_OF_TBS) || (num_tbs < 0)) {
2446 IWL_ERROR("Error can not send more than %d chunks\n",
2451 index = num_tbs / 2;
2452 is_odd = num_tbs & 0x1;
2455 tfd->pa[index].tb1_addr = cpu_to_le32(addr);
2456 IWL_SET_BITS(tfd->pa[index], tb1_addr_hi,
2457 iwl_get_dma_hi_address(addr));
2458 IWL_SET_BITS(tfd->pa[index], tb1_len, len);
2460 IWL_SET_BITS(tfd->pa[index], tb2_addr_lo16,
2461 (u32) (addr & 0xffff));
2462 IWL_SET_BITS(tfd->pa[index], tb2_addr_hi20, addr >> 16);
2463 IWL_SET_BITS(tfd->pa[index], tb2_len, len);
2466 IWL_SET_BITS(*tfd, num_tbs, num_tbs + 1);
2471 static void iwl4965_hw_card_show_info(struct iwl_priv *priv)
2473 u16 hw_version = iwl_eeprom_query16(priv, EEPROM_4965_BOARD_REVISION);
2475 IWL_DEBUG_INFO("4965ABGN HW Version %u.%u.%u\n",
2476 ((hw_version >> 8) & 0x0F),
2477 ((hw_version >> 8) >> 4), (hw_version & 0x00FF));
2479 IWL_DEBUG_INFO("4965ABGN PBA Number %.16s\n",
2480 &priv->eeprom[EEPROM_4965_BOARD_PBA]);
2483 static int iwl4965_alloc_shared_mem(struct iwl_priv *priv)
2485 priv->shared_virt = pci_alloc_consistent(priv->pci_dev,
2486 sizeof(struct iwl4965_shared),
2487 &priv->shared_phys);
2488 if (!priv->shared_virt)
2491 memset(priv->shared_virt, 0, sizeof(struct iwl4965_shared));
2496 static void iwl4965_free_shared_mem(struct iwl_priv *priv)
2498 if (priv->shared_virt)
2499 pci_free_consistent(priv->pci_dev,
2500 sizeof(struct iwl4965_shared),
2505 #define IWL_TX_CRC_SIZE 4
2506 #define IWL_TX_DELIMITER_SIZE 4
2509 * iwl4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
2511 static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv *priv,
2512 struct iwl4965_tx_queue *txq,
2516 int txq_id = txq->q.id;
2517 struct iwl4965_shared *shared_data = priv->shared_virt;
2519 len = byte_cnt + IWL_TX_CRC_SIZE + IWL_TX_DELIMITER_SIZE;
2521 /* Set up byte count within first 256 entries */
2522 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
2523 tfd_offset[txq->q.write_ptr], byte_cnt, len);
2525 /* If within first 64 entries, duplicate at end */
2526 if (txq->q.write_ptr < IWL4965_MAX_WIN_SIZE)
2527 IWL_SET_BITS16(shared_data->queues_byte_cnt_tbls[txq_id].
2528 tfd_offset[IWL4965_QUEUE_SIZE + txq->q.write_ptr],
2533 * iwl4965_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
2535 * Selects how many and which Rx receivers/antennas/chains to use.
2536 * This should not be used for scan command ... it puts data in wrong place.
2538 void iwl4965_set_rxon_chain(struct iwl_priv *priv)
2540 u8 is_single = is_single_rx_stream(priv);
2541 u8 idle_state, rx_state;
2543 priv->staging_rxon.rx_chain = 0;
2544 rx_state = idle_state = 3;
2546 /* Tell uCode which antennas are actually connected.
2547 * Before first association, we assume all antennas are connected.
2548 * Just after first association, iwl_chain_noise_calibration()
2549 * checks which antennas actually *are* connected. */
2550 priv->staging_rxon.rx_chain |=
2551 cpu_to_le16(priv->hw_params.valid_rx_ant <<
2552 RXON_RX_CHAIN_VALID_POS);
2554 /* How many receivers should we use? */
2555 iwl4965_get_rx_chain_counter(priv, &idle_state, &rx_state);
2556 priv->staging_rxon.rx_chain |=
2557 cpu_to_le16(rx_state << RXON_RX_CHAIN_MIMO_CNT_POS);
2558 priv->staging_rxon.rx_chain |=
2559 cpu_to_le16(idle_state << RXON_RX_CHAIN_CNT_POS);
2561 if (!is_single && (rx_state >= 2) &&
2562 !test_bit(STATUS_POWER_PMI, &priv->status))
2563 priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
2565 priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
2567 IWL_DEBUG_ASSOC("rx chain %X\n", priv->staging_rxon.rx_chain);
2571 * sign_extend - Sign extend a value using specified bit as sign-bit
2573 * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1
2574 * and bit0..2 is 001b which when sign extended to 1111111111111001b is -7.
2576 * @param oper value to sign extend
2577 * @param index 0 based bit index (0<=index<32) to sign bit
2579 static s32 sign_extend(u32 oper, int index)
2581 u8 shift = 31 - index;
2583 return (s32)(oper << shift) >> shift;
2587 * iwl4965_get_temperature - return the calibrated temperature (in Kelvin)
2588 * @statistics: Provides the temperature reading from the uCode
2590 * A return of <0 indicates bogus data in the statistics
2592 int iwl4965_get_temperature(const struct iwl_priv *priv)
2599 if (test_bit(STATUS_TEMPERATURE, &priv->status) &&
2600 (priv->statistics.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)) {
2601 IWL_DEBUG_TEMP("Running FAT temperature calibration\n");
2602 R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[1]);
2603 R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[1]);
2604 R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[1]);
2605 R4 = le32_to_cpu(priv->card_alive_init.therm_r4[1]);
2607 IWL_DEBUG_TEMP("Running temperature calibration\n");
2608 R1 = (s32)le32_to_cpu(priv->card_alive_init.therm_r1[0]);
2609 R2 = (s32)le32_to_cpu(priv->card_alive_init.therm_r2[0]);
2610 R3 = (s32)le32_to_cpu(priv->card_alive_init.therm_r3[0]);
2611 R4 = le32_to_cpu(priv->card_alive_init.therm_r4[0]);
2615 * Temperature is only 23 bits, so sign extend out to 32.
2617 * NOTE If we haven't received a statistics notification yet
2618 * with an updated temperature, use R4 provided to us in the
2619 * "initialize" ALIVE response.
2621 if (!test_bit(STATUS_TEMPERATURE, &priv->status))
2622 vt = sign_extend(R4, 23);
2625 le32_to_cpu(priv->statistics.general.temperature), 23);
2627 IWL_DEBUG_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n",
2631 IWL_ERROR("Calibration conflict R1 == R3\n");
2635 /* Calculate temperature in degrees Kelvin, adjust by 97%.
2636 * Add offset to center the adjustment around 0 degrees Centigrade. */
2637 temperature = TEMPERATURE_CALIB_A_VAL * (vt - R2);
2638 temperature /= (R3 - R1);
2639 temperature = (temperature * 97) / 100 +
2640 TEMPERATURE_CALIB_KELVIN_OFFSET;
2642 IWL_DEBUG_TEMP("Calibrated temperature: %dK, %dC\n", temperature,
2643 KELVIN_TO_CELSIUS(temperature));
2648 /* Adjust Txpower only if temperature variance is greater than threshold. */
2649 #define IWL_TEMPERATURE_THRESHOLD 3
2652 * iwl4965_is_temp_calib_needed - determines if new calibration is needed
2654 * If the temperature changed has changed sufficiently, then a recalibration
2657 * Assumes caller will replace priv->last_temperature once calibration
2660 static int iwl4965_is_temp_calib_needed(struct iwl_priv *priv)
2664 if (!test_bit(STATUS_STATISTICS, &priv->status)) {
2665 IWL_DEBUG_TEMP("Temperature not updated -- no statistics.\n");
2669 temp_diff = priv->temperature - priv->last_temperature;
2671 /* get absolute value */
2672 if (temp_diff < 0) {
2673 IWL_DEBUG_POWER("Getting cooler, delta %d, \n", temp_diff);
2674 temp_diff = -temp_diff;
2675 } else if (temp_diff == 0)
2676 IWL_DEBUG_POWER("Same temp, \n");
2678 IWL_DEBUG_POWER("Getting warmer, delta %d, \n", temp_diff);
2680 if (temp_diff < IWL_TEMPERATURE_THRESHOLD) {
2681 IWL_DEBUG_POWER("Thermal txpower calib not needed\n");
2685 IWL_DEBUG_POWER("Thermal txpower calib needed\n");
2690 /* Calculate noise level, based on measurements during network silence just
2691 * before arriving beacon. This measurement can be done only if we know
2692 * exactly when to expect beacons, therefore only when we're associated. */
2693 static void iwl4965_rx_calc_noise(struct iwl_priv *priv)
2695 struct statistics_rx_non_phy *rx_info
2696 = &(priv->statistics.rx.general);
2697 int num_active_rx = 0;
2698 int total_silence = 0;
2700 le32_to_cpu(rx_info->beacon_silence_rssi_a) & IN_BAND_FILTER;
2702 le32_to_cpu(rx_info->beacon_silence_rssi_b) & IN_BAND_FILTER;
2704 le32_to_cpu(rx_info->beacon_silence_rssi_c) & IN_BAND_FILTER;
2706 if (bcn_silence_a) {
2707 total_silence += bcn_silence_a;
2710 if (bcn_silence_b) {
2711 total_silence += bcn_silence_b;
2714 if (bcn_silence_c) {
2715 total_silence += bcn_silence_c;
2719 /* Average among active antennas */
2721 priv->last_rx_noise = (total_silence / num_active_rx) - 107;
2723 priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
2725 IWL_DEBUG_CALIB("inband silence a %u, b %u, c %u, dBm %d\n",
2726 bcn_silence_a, bcn_silence_b, bcn_silence_c,
2727 priv->last_rx_noise);
2730 void iwl4965_hw_rx_statistics(struct iwl_priv *priv, struct iwl4965_rx_mem_buffer *rxb)
2732 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
2736 IWL_DEBUG_RX("Statistics notification received (%d vs %d).\n",
2737 (int)sizeof(priv->statistics), pkt->len);
2739 change = ((priv->statistics.general.temperature !=
2740 pkt->u.stats.general.temperature) ||
2741 ((priv->statistics.flag &
2742 STATISTICS_REPLY_FLG_FAT_MODE_MSK) !=
2743 (pkt->u.stats.flag & STATISTICS_REPLY_FLG_FAT_MODE_MSK)));
2745 memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics));
2747 set_bit(STATUS_STATISTICS, &priv->status);
2749 /* Reschedule the statistics timer to occur in
2750 * REG_RECALIB_PERIOD seconds to ensure we get a
2751 * thermal update even if the uCode doesn't give
2753 mod_timer(&priv->statistics_periodic, jiffies +
2754 msecs_to_jiffies(REG_RECALIB_PERIOD * 1000));
2756 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
2757 (pkt->hdr.cmd == STATISTICS_NOTIFICATION)) {
2758 iwl4965_rx_calc_noise(priv);
2759 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
2760 queue_work(priv->workqueue, &priv->sensitivity_work);
2764 iwl_leds_background(priv);
2766 /* If the hardware hasn't reported a change in
2767 * temperature then don't bother computing a
2768 * calibrated temperature value */
2772 temp = iwl4965_get_temperature(priv);
2776 if (priv->temperature != temp) {
2777 if (priv->temperature)
2778 IWL_DEBUG_TEMP("Temperature changed "
2779 "from %dC to %dC\n",
2780 KELVIN_TO_CELSIUS(priv->temperature),
2781 KELVIN_TO_CELSIUS(temp));
2783 IWL_DEBUG_TEMP("Temperature "
2784 "initialized to %dC\n",
2785 KELVIN_TO_CELSIUS(temp));
2788 priv->temperature = temp;
2789 set_bit(STATUS_TEMPERATURE, &priv->status);
2791 if (unlikely(!test_bit(STATUS_SCANNING, &priv->status)) &&
2792 iwl4965_is_temp_calib_needed(priv))
2793 queue_work(priv->workqueue, &priv->txpower_work);
2796 static void iwl4965_add_radiotap(struct iwl_priv *priv,
2797 struct sk_buff *skb,
2798 struct iwl4965_rx_phy_res *rx_start,
2799 struct ieee80211_rx_status *stats,
2802 s8 signal = stats->ssi;
2804 int rate = stats->rate_idx;
2805 u64 tsf = stats->mactime;
2807 __le16 phy_flags_hw = rx_start->phy_flags;
2808 struct iwl4965_rt_rx_hdr {
2809 struct ieee80211_radiotap_header rt_hdr;
2810 __le64 rt_tsf; /* TSF */
2811 u8 rt_flags; /* radiotap packet flags */
2812 u8 rt_rate; /* rate in 500kb/s */
2813 __le16 rt_channelMHz; /* channel in MHz */
2814 __le16 rt_chbitmask; /* channel bitfield */
2815 s8 rt_dbmsignal; /* signal in dBm, kluged to signed */
2817 u8 rt_antenna; /* antenna number */
2818 } __attribute__ ((packed)) *iwl4965_rt;
2820 /* TODO: We won't have enough headroom for HT frames. Fix it later. */
2821 if (skb_headroom(skb) < sizeof(*iwl4965_rt)) {
2822 if (net_ratelimit())
2823 printk(KERN_ERR "not enough headroom [%d] for "
2824 "radiotap head [%zd]\n",
2825 skb_headroom(skb), sizeof(*iwl4965_rt));
2829 /* put radiotap header in front of 802.11 header and data */
2830 iwl4965_rt = (void *)skb_push(skb, sizeof(*iwl4965_rt));
2832 /* initialise radiotap header */
2833 iwl4965_rt->rt_hdr.it_version = PKTHDR_RADIOTAP_VERSION;
2834 iwl4965_rt->rt_hdr.it_pad = 0;
2836 /* total header + data */
2837 put_unaligned(cpu_to_le16(sizeof(*iwl4965_rt)),
2838 &iwl4965_rt->rt_hdr.it_len);
2840 /* Indicate all the fields we add to the radiotap header */
2841 put_unaligned(cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT) |
2842 (1 << IEEE80211_RADIOTAP_FLAGS) |
2843 (1 << IEEE80211_RADIOTAP_RATE) |
2844 (1 << IEEE80211_RADIOTAP_CHANNEL) |
2845 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL) |
2846 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE) |
2847 (1 << IEEE80211_RADIOTAP_ANTENNA)),
2848 &iwl4965_rt->rt_hdr.it_present);
2850 /* Zero the flags, we'll add to them as we go */
2851 iwl4965_rt->rt_flags = 0;
2853 put_unaligned(cpu_to_le64(tsf), &iwl4965_rt->rt_tsf);
2855 iwl4965_rt->rt_dbmsignal = signal;
2856 iwl4965_rt->rt_dbmnoise = noise;
2858 /* Convert the channel frequency and set the flags */
2859 put_unaligned(cpu_to_le16(stats->freq), &iwl4965_rt->rt_channelMHz);
2860 if (!(phy_flags_hw & RX_RES_PHY_FLAGS_BAND_24_MSK))
2861 put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM |
2862 IEEE80211_CHAN_5GHZ),
2863 &iwl4965_rt->rt_chbitmask);
2864 else if (phy_flags_hw & RX_RES_PHY_FLAGS_MOD_CCK_MSK)
2865 put_unaligned(cpu_to_le16(IEEE80211_CHAN_CCK |
2866 IEEE80211_CHAN_2GHZ),
2867 &iwl4965_rt->rt_chbitmask);
2869 put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM |
2870 IEEE80211_CHAN_2GHZ),
2871 &iwl4965_rt->rt_chbitmask);
2874 iwl4965_rt->rt_rate = 0;
2876 iwl4965_rt->rt_rate = iwl4965_rates[rate].ieee;
2881 * It seems that the antenna field in the phy flags value
2882 * is actually a bitfield. This is undefined by radiotap,
2883 * it wants an actual antenna number but I always get "7"
2884 * for most legacy frames I receive indicating that the
2885 * same frame was received on all three RX chains.
2887 * I think this field should be removed in favour of a
2888 * new 802.11n radiotap field "RX chains" that is defined
2891 antenna = phy_flags_hw & RX_RES_PHY_FLAGS_ANTENNA_MSK;
2892 iwl4965_rt->rt_antenna = le16_to_cpu(antenna) >> 4;
2894 /* set the preamble flag if appropriate */
2895 if (phy_flags_hw & RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK)
2896 iwl4965_rt->rt_flags |= IEEE80211_RADIOTAP_F_SHORTPRE;
2898 stats->flag |= RX_FLAG_RADIOTAP;
2901 static void iwl_update_rx_stats(struct iwl_priv *priv, u16 fc, u16 len)
2903 /* 0 - mgmt, 1 - cnt, 2 - data */
2904 int idx = (fc & IEEE80211_FCTL_FTYPE) >> 2;
2905 priv->rx_stats[idx].cnt++;
2906 priv->rx_stats[idx].bytes += len;
2910 * returns non-zero if packet should be dropped
2912 static int iwl4965_set_decrypted_flag(struct iwl_priv *priv,
2913 struct ieee80211_hdr *hdr,
2915 struct ieee80211_rx_status *stats)
2917 u16 fc = le16_to_cpu(hdr->frame_control);
2919 if (priv->active_rxon.filter_flags & RXON_FILTER_DIS_DECRYPT_MSK)
2922 if (!(fc & IEEE80211_FCTL_PROTECTED))
2925 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res);
2926 switch (decrypt_res & RX_RES_STATUS_SEC_TYPE_MSK) {
2927 case RX_RES_STATUS_SEC_TYPE_TKIP:
2928 /* The uCode has got a bad phase 1 Key, pushes the packet.
2929 * Decryption will be done in SW. */
2930 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2931 RX_RES_STATUS_BAD_KEY_TTAK)
2934 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2935 RX_RES_STATUS_BAD_ICV_MIC) {
2936 /* bad ICV, the packet is destroyed since the
2937 * decryption is inplace, drop it */
2938 IWL_DEBUG_RX("Packet destroyed\n");
2941 case RX_RES_STATUS_SEC_TYPE_WEP:
2942 case RX_RES_STATUS_SEC_TYPE_CCMP:
2943 if ((decrypt_res & RX_RES_STATUS_DECRYPT_TYPE_MSK) ==
2944 RX_RES_STATUS_DECRYPT_OK) {
2945 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2946 stats->flag |= RX_FLAG_DECRYPTED;
2956 static u32 iwl4965_translate_rx_status(u32 decrypt_in)
2958 u32 decrypt_out = 0;
2960 if ((decrypt_in & RX_RES_STATUS_STATION_FOUND) ==
2961 RX_RES_STATUS_STATION_FOUND)
2962 decrypt_out |= (RX_RES_STATUS_STATION_FOUND |
2963 RX_RES_STATUS_NO_STATION_INFO_MISMATCH);
2965 decrypt_out |= (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK);
2967 /* packet was not encrypted */
2968 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
2969 RX_RES_STATUS_SEC_TYPE_NONE)
2972 /* packet was encrypted with unknown alg */
2973 if ((decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) ==
2974 RX_RES_STATUS_SEC_TYPE_ERR)
2977 /* decryption was not done in HW */
2978 if ((decrypt_in & RX_MPDU_RES_STATUS_DEC_DONE_MSK) !=
2979 RX_MPDU_RES_STATUS_DEC_DONE_MSK)
2982 switch (decrypt_in & RX_RES_STATUS_SEC_TYPE_MSK) {
2984 case RX_RES_STATUS_SEC_TYPE_CCMP:
2985 /* alg is CCM: check MIC only */
2986 if (!(decrypt_in & RX_MPDU_RES_STATUS_MIC_OK))
2988 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
2990 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
2994 case RX_RES_STATUS_SEC_TYPE_TKIP:
2995 if (!(decrypt_in & RX_MPDU_RES_STATUS_TTAK_OK)) {
2997 decrypt_out |= RX_RES_STATUS_BAD_KEY_TTAK;
3000 /* fall through if TTAK OK */
3002 if (!(decrypt_in & RX_MPDU_RES_STATUS_ICV_OK))
3003 decrypt_out |= RX_RES_STATUS_BAD_ICV_MIC;
3005 decrypt_out |= RX_RES_STATUS_DECRYPT_OK;
3009 IWL_DEBUG_RX("decrypt_in:0x%x decrypt_out = 0x%x\n",
3010 decrypt_in, decrypt_out);
3015 static void iwl4965_handle_data_packet(struct iwl_priv *priv, int is_data,
3017 struct iwl4965_rx_mem_buffer *rxb,
3018 struct ieee80211_rx_status *stats)
3020 struct iwl4965_rx_packet *pkt = (struct iwl4965_rx_packet *)rxb->skb->data;
3021 struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
3022 (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) : NULL;
3023 struct ieee80211_hdr *hdr;
3026 unsigned int skblen;
3028 u32 ampdu_status_legacy;
3030 if (!include_phy && priv->last_phy_res[0])
3031 rx_start = (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
3034 IWL_ERROR("MPDU frame without a PHY data\n");
3038 hdr = (struct ieee80211_hdr *)((u8 *) & rx_start[1] +
3039 rx_start->cfg_phy_cnt);
3041 len = le16_to_cpu(rx_start->byte_count);
3043 rx_end = (__le32 *) ((u8 *) & pkt->u.raw[0] +
3044 sizeof(struct iwl4965_rx_phy_res) +
3045 rx_start->cfg_phy_cnt + len);
3048 struct iwl4965_rx_mpdu_res_start *amsdu =
3049 (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
3051 hdr = (struct ieee80211_hdr *)(pkt->u.raw +
3052 sizeof(struct iwl4965_rx_mpdu_res_start));
3053 len = le16_to_cpu(amsdu->byte_count);
3054 rx_start->byte_count = amsdu->byte_count;
3055 rx_end = (__le32 *) (((u8 *) hdr) + len);
3057 if (len > priv->hw_params.max_pkt_size || len < 16) {
3058 IWL_WARNING("byte count out of range [16,4K] : %d\n", len);
3062 ampdu_status = le32_to_cpu(*rx_end);
3063 skblen = ((u8 *) rx_end - (u8 *) & pkt->u.raw[0]) + sizeof(u32);
3066 /* New status scheme, need to translate */
3067 ampdu_status_legacy = ampdu_status;
3068 ampdu_status = iwl4965_translate_rx_status(ampdu_status);
3071 /* start from MAC */
3072 skb_reserve(rxb->skb, (void *)hdr - (void *)pkt);
3073 skb_put(rxb->skb, len); /* end where data ends */
3075 /* We only process data packets if the interface is open */
3076 if (unlikely(!priv->is_open)) {
3077 IWL_DEBUG_DROP_LIMIT
3078 ("Dropping packet while interface is not open.\n");
3083 hdr = (struct ieee80211_hdr *)rxb->skb->data;
3085 /* in case of HW accelerated crypto and bad decryption, drop */
3086 if (!priv->hw_params.sw_crypto &&
3087 iwl4965_set_decrypted_flag(priv, hdr, ampdu_status, stats))
3090 if (priv->add_radiotap)
3091 iwl4965_add_radiotap(priv, rxb->skb, rx_start, stats, ampdu_status);
3093 iwl_update_rx_stats(priv, le16_to_cpu(hdr->frame_control), len);
3094 ieee80211_rx_irqsafe(priv->hw, rxb->skb, stats);
3095 priv->alloc_rxb_skb--;
3099 /* Calc max signal level (dBm) among 3 possible receivers */
3100 static int iwl4965_calc_rssi(struct iwl4965_rx_phy_res *rx_resp)
3102 /* data from PHY/DSP regarding signal strength, etc.,
3103 * contents are always there, not configurable by host. */
3104 struct iwl4965_rx_non_cfg_phy *ncphy =
3105 (struct iwl4965_rx_non_cfg_phy *)rx_resp->non_cfg_phy;
3106 u32 agc = (le16_to_cpu(ncphy->agc_info) & IWL_AGC_DB_MASK)
3109 u32 valid_antennae =
3110 (le16_to_cpu(rx_resp->phy_flags) & RX_PHY_FLAGS_ANTENNAE_MASK)
3111 >> RX_PHY_FLAGS_ANTENNAE_OFFSET;
3115 /* Find max rssi among 3 possible receivers.
3116 * These values are measured by the digital signal processor (DSP).
3117 * They should stay fairly constant even as the signal strength varies,
3118 * if the radio's automatic gain control (AGC) is working right.
3119 * AGC value (see below) will provide the "interesting" info. */
3120 for (i = 0; i < 3; i++)
3121 if (valid_antennae & (1 << i))
3122 max_rssi = max(ncphy->rssi_info[i << 1], max_rssi);
3124 IWL_DEBUG_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
3125 ncphy->rssi_info[0], ncphy->rssi_info[2], ncphy->rssi_info[4],
3128 /* dBm = max_rssi dB - agc dB - constant.
3129 * Higher AGC (higher radio gain) means lower signal. */
3130 return (max_rssi - agc - IWL_RSSI_OFFSET);
3133 #ifdef CONFIG_IWL4965_HT
3135 void iwl4965_init_ht_hw_capab(const struct iwl_priv *priv,
3136 struct ieee80211_ht_info *ht_info,
3137 enum ieee80211_band band)
3140 memset(ht_info->supp_mcs_set, 0, 16);
3142 ht_info->ht_supported = 1;
3144 if (priv->hw_params.fat_channel & BIT(band)) {
3145 ht_info->cap |= (u16)IEEE80211_HT_CAP_SUP_WIDTH;
3146 ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_40;
3147 ht_info->supp_mcs_set[4] = 0x01;
3149 ht_info->cap |= (u16)IEEE80211_HT_CAP_GRN_FLD;
3150 ht_info->cap |= (u16)IEEE80211_HT_CAP_SGI_20;
3151 ht_info->cap |= (u16)(IEEE80211_HT_CAP_MIMO_PS &
3152 (IWL_MIMO_PS_NONE << 2));
3154 if (priv->cfg->mod_params->amsdu_size_8K)
3155 ht_info->cap |= (u16)IEEE80211_HT_CAP_MAX_AMSDU;
3157 ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
3158 ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
3160 ht_info->supp_mcs_set[0] = 0xFF;
3161 if (priv->hw_params.tx_chains_num >= 2)
3162 ht_info->supp_mcs_set[1] = 0xFF;
3163 if (priv->hw_params.tx_chains_num >= 3)
3164 ht_info->supp_mcs_set[2] = 0xFF;
3166 #endif /* CONFIG_IWL4965_HT */
3168 static void iwl4965_sta_modify_ps_wake(struct iwl_priv *priv, int sta_id)
3170 unsigned long flags;
3172 spin_lock_irqsave(&priv->sta_lock, flags);
3173 priv->stations[sta_id].sta.station_flags &= ~STA_FLG_PWR_SAVE_MSK;
3174 priv->stations[sta_id].sta.station_flags_msk = STA_FLG_PWR_SAVE_MSK;
3175 priv->stations[sta_id].sta.sta.modify_mask = 0;
3176 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3177 spin_unlock_irqrestore(&priv->sta_lock, flags);
3179 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
3182 static void iwl4965_update_ps_mode(struct iwl_priv *priv, u16 ps_bit, u8 *addr)
3184 /* FIXME: need locking over ps_status ??? */
3185 u8 sta_id = iwl_find_station(priv, addr);
3187 if (sta_id != IWL_INVALID_STATION) {
3188 u8 sta_awake = priv->stations[sta_id].
3189 ps_status == STA_PS_STATUS_WAKE;
3191 if (sta_awake && ps_bit)
3192 priv->stations[sta_id].ps_status = STA_PS_STATUS_SLEEP;
3193 else if (!sta_awake && !ps_bit) {
3194 iwl4965_sta_modify_ps_wake(priv, sta_id);
3195 priv->stations[sta_id].ps_status = STA_PS_STATUS_WAKE;
3199 #ifdef CONFIG_IWLWIFI_DEBUG
3202 * iwl4965_dbg_report_frame - dump frame to syslog during debug sessions
3204 * You may hack this function to show different aspects of received frames,
3205 * including selective frame dumps.
3206 * group100 parameter selects whether to show 1 out of 100 good frames.
3208 * TODO: This was originally written for 3945, need to audit for
3209 * proper operation with 4965.
3211 static void iwl4965_dbg_report_frame(struct iwl_priv *priv,
3212 struct iwl4965_rx_packet *pkt,
3213 struct ieee80211_hdr *header, int group100)
3216 u32 print_summary = 0;
3217 u32 print_dump = 0; /* set to 1 to dump all frames' contents */
3234 struct iwl4965_rx_frame_stats *rx_stats = IWL_RX_STATS(pkt);
3235 struct iwl4965_rx_frame_hdr *rx_hdr = IWL_RX_HDR(pkt);
3236 struct iwl4965_rx_frame_end *rx_end = IWL_RX_END(pkt);
3237 u8 *data = IWL_RX_DATA(pkt);
3239 if (likely(!(iwl_debug_level & IWL_DL_RX)))
3243 fc = le16_to_cpu(header->frame_control);
3244 seq_ctl = le16_to_cpu(header->seq_ctrl);
3247 channel = le16_to_cpu(rx_hdr->channel);
3248 phy_flags = le16_to_cpu(rx_hdr->phy_flags);
3249 rate_sym = rx_hdr->rate;
3250 length = le16_to_cpu(rx_hdr->len);
3252 /* end-of-frame status and timestamp */
3253 status = le32_to_cpu(rx_end->status);
3254 bcn_tmr = le32_to_cpu(rx_end->beacon_timestamp);
3255 tsf_low = le64_to_cpu(rx_end->timestamp) & 0x0ffffffff;
3256 tsf = le64_to_cpu(rx_end->timestamp);
3258 /* signal statistics */
3259 rssi = rx_stats->rssi;
3260 agc = rx_stats->agc;
3261 sig_avg = le16_to_cpu(rx_stats->sig_avg);
3262 noise_diff = le16_to_cpu(rx_stats->noise_diff);
3264 to_us = !compare_ether_addr(header->addr1, priv->mac_addr);
3266 /* if data frame is to us and all is good,
3267 * (optionally) print summary for only 1 out of every 100 */
3268 if (to_us && (fc & ~IEEE80211_FCTL_PROTECTED) ==
3269 (IEEE80211_FCTL_FROMDS | IEEE80211_FTYPE_DATA)) {
3272 print_summary = 1; /* print each frame */
3273 else if (priv->framecnt_to_us < 100) {
3274 priv->framecnt_to_us++;
3277 priv->framecnt_to_us = 0;
3282 /* print summary for all other frames */
3286 if (print_summary) {
3292 title = "100Frames";
3293 else if (fc & IEEE80211_FCTL_RETRY)
3295 else if (ieee80211_is_assoc_response(fc))
3297 else if (ieee80211_is_reassoc_response(fc))
3299 else if (ieee80211_is_probe_response(fc)) {
3301 print_dump = 1; /* dump frame contents */
3302 } else if (ieee80211_is_beacon(fc)) {
3304 print_dump = 1; /* dump frame contents */
3305 } else if (ieee80211_is_atim(fc))
3307 else if (ieee80211_is_auth(fc))
3309 else if (ieee80211_is_deauth(fc))
3311 else if (ieee80211_is_disassoc(fc))
3316 rate_idx = iwl4965_hwrate_to_plcp_idx(rate_sym);
3317 if (unlikely(rate_idx == -1))
3320 bitrate = iwl4965_rates[rate_idx].ieee / 2;
3322 /* print frame summary.
3323 * MAC addresses show just the last byte (for brevity),
3324 * but you can hack it to show more, if you'd like to. */
3326 IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
3327 "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
3328 title, fc, header->addr1[5],
3329 length, rssi, channel, bitrate);
3331 /* src/dst addresses assume managed mode */
3332 IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
3333 "src=0x%02x, rssi=%u, tim=%lu usec, "
3334 "phy=0x%02x, chnl=%d\n",
3335 title, fc, header->addr1[5],
3336 header->addr3[5], rssi,
3337 tsf_low - priv->scan_start_tsf,
3338 phy_flags, channel);
3342 iwl_print_hex_dump(IWL_DL_RX, data, length);
3345 static inline void iwl4965_dbg_report_frame(struct iwl_priv *priv,
3346 struct iwl4965_rx_packet *pkt,
3347 struct ieee80211_hdr *header,
3355 /* Called for REPLY_RX (legacy ABG frames), or
3356 * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
3357 static void iwl4965_rx_reply_rx(struct iwl_priv *priv,
3358 struct iwl4965_rx_mem_buffer *rxb)
3360 struct ieee80211_hdr *header;
3361 struct ieee80211_rx_status rx_status;
3362 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3363 /* Use phy data (Rx signal strength, etc.) contained within
3364 * this rx packet for legacy frames,
3365 * or phy data cached from REPLY_RX_PHY_CMD for HT frames. */
3366 int include_phy = (pkt->hdr.cmd == REPLY_RX);
3367 struct iwl4965_rx_phy_res *rx_start = (include_phy) ?
3368 (struct iwl4965_rx_phy_res *)&(pkt->u.raw[0]) :
3369 (struct iwl4965_rx_phy_res *)&priv->last_phy_res[1];
3371 unsigned int len = 0;
3375 rx_status.mactime = le64_to_cpu(rx_start->timestamp);
3377 ieee80211_frequency_to_channel(le16_to_cpu(rx_start->channel));
3378 rx_status.band = (rx_start->phy_flags & RX_RES_PHY_FLAGS_BAND_24_MSK) ?
3379 IEEE80211_BAND_2GHZ : IEEE80211_BAND_5GHZ;
3380 rx_status.rate_idx =
3381 iwl4965_hwrate_to_plcp_idx(le32_to_cpu(rx_start->rate_n_flags));
3382 if (rx_status.band == IEEE80211_BAND_5GHZ)
3383 rx_status.rate_idx -= IWL_FIRST_OFDM_RATE;
3385 rx_status.antenna = 0;
3388 if ((unlikely(rx_start->cfg_phy_cnt > 20))) {
3389 IWL_DEBUG_DROP("dsp size out of range [0,20]: %d/n",
3390 rx_start->cfg_phy_cnt);
3395 if (priv->last_phy_res[0])
3396 rx_start = (struct iwl4965_rx_phy_res *)
3397 &priv->last_phy_res[1];
3403 IWL_ERROR("MPDU frame without a PHY data\n");
3408 header = (struct ieee80211_hdr *)((u8 *) & rx_start[1]
3409 + rx_start->cfg_phy_cnt);
3411 len = le16_to_cpu(rx_start->byte_count);
3412 rx_end = (__le32 *)(pkt->u.raw + rx_start->cfg_phy_cnt +
3413 sizeof(struct iwl4965_rx_phy_res) + len);
3415 struct iwl4965_rx_mpdu_res_start *amsdu =
3416 (struct iwl4965_rx_mpdu_res_start *)pkt->u.raw;
3418 header = (void *)(pkt->u.raw +
3419 sizeof(struct iwl4965_rx_mpdu_res_start));
3420 len = le16_to_cpu(amsdu->byte_count);
3421 rx_end = (__le32 *) (pkt->u.raw +
3422 sizeof(struct iwl4965_rx_mpdu_res_start) + len);
3425 if (!(*rx_end & RX_RES_STATUS_NO_CRC32_ERROR) ||
3426 !(*rx_end & RX_RES_STATUS_NO_RXE_OVERFLOW)) {
3427 IWL_DEBUG_RX("Bad CRC or FIFO: 0x%08X.\n",
3428 le32_to_cpu(*rx_end));
3432 priv->ucode_beacon_time = le32_to_cpu(rx_start->beacon_time_stamp);
3434 /* Find max signal strength (dBm) among 3 antenna/receiver chains */
3435 rx_status.ssi = iwl4965_calc_rssi(rx_start);
3437 /* Meaningful noise values are available only from beacon statistics,
3438 * which are gathered only when associated, and indicate noise
3439 * only for the associated network channel ...
3440 * Ignore these noise values while scanning (other channels) */
3441 if (iwl_is_associated(priv) &&
3442 !test_bit(STATUS_SCANNING, &priv->status)) {
3443 rx_status.noise = priv->last_rx_noise;
3444 rx_status.signal = iwl4965_calc_sig_qual(rx_status.ssi,
3447 rx_status.noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
3448 rx_status.signal = iwl4965_calc_sig_qual(rx_status.ssi, 0);
3451 /* Reset beacon noise level if not associated. */
3452 if (!iwl_is_associated(priv))
3453 priv->last_rx_noise = IWL_NOISE_MEAS_NOT_AVAILABLE;
3455 /* Set "1" to report good data frames in groups of 100 */
3456 /* FIXME: need to optimze the call: */
3457 iwl4965_dbg_report_frame(priv, pkt, header, 1);
3459 IWL_DEBUG_STATS_LIMIT("Rssi %d, noise %d, qual %d, TSF %llu\n",
3460 rx_status.ssi, rx_status.noise, rx_status.signal,
3461 (unsigned long long)rx_status.mactime);
3463 network_packet = iwl4965_is_network_packet(priv, header);
3464 if (network_packet) {
3465 priv->last_rx_rssi = rx_status.ssi;
3466 priv->last_beacon_time = priv->ucode_beacon_time;
3467 priv->last_tsf = le64_to_cpu(rx_start->timestamp);
3470 fc = le16_to_cpu(header->frame_control);
3471 switch (fc & IEEE80211_FCTL_FTYPE) {
3472 case IEEE80211_FTYPE_MGMT:
3473 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
3474 iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
3476 iwl4965_handle_data_packet(priv, 0, include_phy, rxb, &rx_status);
3479 case IEEE80211_FTYPE_CTL:
3480 #ifdef CONFIG_IWL4965_HT
3481 switch (fc & IEEE80211_FCTL_STYPE) {
3482 case IEEE80211_STYPE_BACK_REQ:
3483 IWL_DEBUG_HT("IEEE80211_STYPE_BACK_REQ arrived\n");
3484 iwl4965_handle_data_packet(priv, 0, include_phy,
3493 case IEEE80211_FTYPE_DATA: {
3494 DECLARE_MAC_BUF(mac1);
3495 DECLARE_MAC_BUF(mac2);
3496 DECLARE_MAC_BUF(mac3);
3498 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
3499 iwl4965_update_ps_mode(priv, fc & IEEE80211_FCTL_PM,
3502 if (unlikely(!network_packet))
3503 IWL_DEBUG_DROP("Dropping (non network): "
3505 print_mac(mac1, header->addr1),
3506 print_mac(mac2, header->addr2),
3507 print_mac(mac3, header->addr3));
3508 else if (unlikely(iwl4965_is_duplicate_packet(priv, header)))
3509 IWL_DEBUG_DROP("Dropping (dup): %s, %s, %s\n",
3510 print_mac(mac1, header->addr1),
3511 print_mac(mac2, header->addr2),
3512 print_mac(mac3, header->addr3));
3514 iwl4965_handle_data_packet(priv, 1, include_phy, rxb,
3524 /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
3525 * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
3526 static void iwl4965_rx_reply_rx_phy(struct iwl_priv *priv,
3527 struct iwl4965_rx_mem_buffer *rxb)
3529 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3530 priv->last_phy_res[0] = 1;
3531 memcpy(&priv->last_phy_res[1], &(pkt->u.raw[0]),
3532 sizeof(struct iwl4965_rx_phy_res));
3534 static void iwl4965_rx_missed_beacon_notif(struct iwl_priv *priv,
3535 struct iwl4965_rx_mem_buffer *rxb)
3538 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
3539 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3540 struct iwl4965_missed_beacon_notif *missed_beacon;
3542 missed_beacon = &pkt->u.missed_beacon;
3543 if (le32_to_cpu(missed_beacon->consequtive_missed_beacons) > 5) {
3544 IWL_DEBUG_CALIB("missed bcn cnsq %d totl %d rcd %d expctd %d\n",
3545 le32_to_cpu(missed_beacon->consequtive_missed_beacons),
3546 le32_to_cpu(missed_beacon->total_missed_becons),
3547 le32_to_cpu(missed_beacon->num_recvd_beacons),
3548 le32_to_cpu(missed_beacon->num_expected_beacons));
3549 if (!test_bit(STATUS_SCANNING, &priv->status))
3550 iwl_init_sensitivity(priv);
3552 #endif /*CONFIG_IWL4965_RUN_TIME_CALIB*/
3554 #ifdef CONFIG_IWL4965_HT
3557 * iwl4965_sta_modify_enable_tid_tx - Enable Tx for this TID in station table
3559 static void iwl4965_sta_modify_enable_tid_tx(struct iwl_priv *priv,
3560 int sta_id, int tid)
3562 unsigned long flags;
3564 /* Remove "disable" flag, to enable Tx for this TID */
3565 spin_lock_irqsave(&priv->sta_lock, flags);
3566 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_TID_DISABLE_TX;
3567 priv->stations[sta_id].sta.tid_disable_tx &= cpu_to_le16(~(1 << tid));
3568 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3569 spin_unlock_irqrestore(&priv->sta_lock, flags);
3571 iwl4965_send_add_station(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
3575 * iwl4965_tx_status_reply_compressed_ba - Update tx status from block-ack
3577 * Go through block-ack's bitmap of ACK'd frames, update driver's record of
3578 * ACK vs. not. This gets sent to mac80211, then to rate scaling algo.
3580 static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv *priv,
3581 struct iwl4965_ht_agg *agg,
3582 struct iwl4965_compressed_ba_resp*
3587 u16 seq_ctl = le16_to_cpu(ba_resp->seq_ctl);
3588 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
3591 struct ieee80211_tx_status *tx_status;
3593 if (unlikely(!agg->wait_for_ba)) {
3594 IWL_ERROR("Received BA when not expected\n");
3598 /* Mark that the expected block-ack response arrived */
3599 agg->wait_for_ba = 0;
3600 IWL_DEBUG_TX_REPLY("BA %d %d\n", agg->start_idx, ba_resp->seq_ctl);
3602 /* Calculate shift to align block-ack bits with our Tx window bits */
3603 sh = agg->start_idx - SEQ_TO_INDEX(seq_ctl>>4);
3604 if (sh < 0) /* tbw something is wrong with indices */
3607 /* don't use 64-bit values for now */
3608 bitmap = le64_to_cpu(ba_resp->bitmap) >> sh;
3610 if (agg->frame_count > (64 - sh)) {
3611 IWL_DEBUG_TX_REPLY("more frames than bitmap size");
3615 /* check for success or failure according to the
3616 * transmitted bitmap and block-ack bitmap */
3617 bitmap &= agg->bitmap;
3619 /* For each frame attempted in aggregation,
3620 * update driver's record of tx frame's status. */
3621 for (i = 0; i < agg->frame_count ; i++) {
3622 ack = bitmap & (1 << i);
3624 IWL_DEBUG_TX_REPLY("%s ON i=%d idx=%d raw=%d\n",
3625 ack? "ACK":"NACK", i, (agg->start_idx + i) & 0xff,
3626 agg->start_idx + i);
3629 tx_status = &priv->txq[scd_flow].txb[agg->start_idx].status;
3630 tx_status->flags = IEEE80211_TX_STATUS_ACK;
3631 tx_status->flags |= IEEE80211_TX_STATUS_AMPDU;
3632 tx_status->ampdu_ack_map = successes;
3633 tx_status->ampdu_ack_len = agg->frame_count;
3634 iwl4965_hwrate_to_tx_control(priv, agg->rate_n_flags,
3635 &tx_status->control);
3637 IWL_DEBUG_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap);
3643 * iwl4965_tx_queue_stop_scheduler - Stop queue, but keep configuration
3645 static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv *priv,
3648 /* Simply stop the queue, but don't change any configuration;
3649 * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
3650 iwl_write_prph(priv,
3651 IWL49_SCD_QUEUE_STATUS_BITS(txq_id),
3652 (0 << SCD_QUEUE_STTS_REG_POS_ACTIVE)|
3653 (1 << SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN));
3657 * txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID
3658 * priv->lock must be held by the caller
3660 static int iwl4965_tx_queue_agg_disable(struct iwl_priv *priv, u16 txq_id,
3661 u16 ssn_idx, u8 tx_fifo)
3665 if (IWL_BACK_QUEUE_FIRST_ID > txq_id) {
3666 IWL_WARNING("queue number too small: %d, must be > %d\n",
3667 txq_id, IWL_BACK_QUEUE_FIRST_ID);
3671 ret = iwl_grab_nic_access(priv);
3675 iwl4965_tx_queue_stop_scheduler(priv, txq_id);
3677 iwl_clear_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
3679 priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
3680 priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
3681 /* supposes that ssn_idx is valid (!= 0xFFF) */
3682 iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
3684 iwl_clear_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
3685 iwl4965_txq_ctx_deactivate(priv, txq_id);
3686 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 0);
3688 iwl_release_nic_access(priv);
3693 int iwl4965_check_empty_hw_queue(struct iwl_priv *priv, int sta_id,
3696 struct iwl4965_queue *q = &priv->txq[txq_id].q;
3697 u8 *addr = priv->stations[sta_id].sta.sta.addr;
3698 struct iwl4965_tid_data *tid_data = &priv->stations[sta_id].tid[tid];
3700 switch (priv->stations[sta_id].tid[tid].agg.state) {
3701 case IWL_EMPTYING_HW_QUEUE_DELBA:
3702 /* We are reclaiming the last packet of the */
3703 /* aggregated HW queue */
3704 if (txq_id == tid_data->agg.txq_id &&
3705 q->read_ptr == q->write_ptr) {
3706 u16 ssn = SEQ_TO_SN(tid_data->seq_number);
3707 int tx_fifo = default_tid_to_tx_fifo[tid];
3708 IWL_DEBUG_HT("HW queue empty: continue DELBA flow\n");
3709 iwl4965_tx_queue_agg_disable(priv, txq_id,
3711 tid_data->agg.state = IWL_AGG_OFF;
3712 ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, addr, tid);
3715 case IWL_EMPTYING_HW_QUEUE_ADDBA:
3716 /* We are reclaiming the last packet of the queue */
3717 if (tid_data->tfds_in_queue == 0) {
3718 IWL_DEBUG_HT("HW queue empty: continue ADDBA flow\n");
3719 tid_data->agg.state = IWL_AGG_ON;
3720 ieee80211_start_tx_ba_cb_irqsafe(priv->hw, addr, tid);
3728 * iwl4965_queue_dec_wrap - Decrement queue index, wrap back to end if needed
3729 * @index -- current index
3730 * @n_bd -- total number of entries in queue (s/b power of 2)
3732 static inline int iwl4965_queue_dec_wrap(int index, int n_bd)
3734 return (index == 0) ? n_bd - 1 : index - 1;
3738 * iwl4965_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
3740 * Handles block-acknowledge notification from device, which reports success
3741 * of frames sent via aggregation.
3743 static void iwl4965_rx_reply_compressed_ba(struct iwl_priv *priv,
3744 struct iwl4965_rx_mem_buffer *rxb)
3746 struct iwl4965_rx_packet *pkt = (void *)rxb->skb->data;
3747 struct iwl4965_compressed_ba_resp *ba_resp = &pkt->u.compressed_ba;
3749 struct iwl4965_tx_queue *txq = NULL;
3750 struct iwl4965_ht_agg *agg;
3751 DECLARE_MAC_BUF(mac);
3753 /* "flow" corresponds to Tx queue */
3754 u16 scd_flow = le16_to_cpu(ba_resp->scd_flow);
3756 /* "ssn" is start of block-ack Tx window, corresponds to index
3757 * (in Tx queue's circular buffer) of first TFD/frame in window */
3758 u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn);
3760 if (scd_flow >= priv->hw_params.max_txq_num) {
3761 IWL_ERROR("BUG_ON scd_flow is bigger than number of queues");
3765 txq = &priv->txq[scd_flow];
3766 agg = &priv->stations[ba_resp->sta_id].tid[ba_resp->tid].agg;
3768 /* Find index just before block-ack window */
3769 index = iwl4965_queue_dec_wrap(ba_resp_scd_ssn & 0xff, txq->q.n_bd);
3771 /* TODO: Need to get this copy more safely - now good for debug */
3773 IWL_DEBUG_TX_REPLY("REPLY_COMPRESSED_BA [%d]Received from %s, "
3776 print_mac(mac, (u8*) &ba_resp->sta_addr_lo32),
3778 IWL_DEBUG_TX_REPLY("TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = "
3779 "%d, scd_ssn = %d\n",
3782 (unsigned long long)le64_to_cpu(ba_resp->bitmap),
3785 IWL_DEBUG_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx \n",
3787 (unsigned long long)agg->bitmap);
3789 /* Update driver's record of ACK vs. not for each frame in window */
3790 iwl4965_tx_status_reply_compressed_ba(priv, agg, ba_resp);
3792 /* Release all TFDs before the SSN, i.e. all TFDs in front of
3793 * block-ack window (we assume that they've been successfully
3794 * transmitted ... if not, it's too late anyway). */
3795 if (txq->q.read_ptr != (ba_resp_scd_ssn & 0xff)) {
3796 int freed = iwl4965_tx_queue_reclaim(priv, scd_flow, index);
3797 priv->stations[ba_resp->sta_id].
3798 tid[ba_resp->tid].tfds_in_queue -= freed;
3799 if (iwl4965_queue_space(&txq->q) > txq->q.low_mark &&
3800 priv->mac80211_registered &&
3801 agg->state != IWL_EMPTYING_HW_QUEUE_DELBA)
3802 ieee80211_wake_queue(priv->hw, scd_flow);
3803 iwl4965_check_empty_hw_queue(priv, ba_resp->sta_id,
3804 ba_resp->tid, scd_flow);
3809 * iwl4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue
3811 static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv *priv, u16 ra_tid,
3818 scd_q2ratid = ra_tid & SCD_QUEUE_RA_TID_MAP_RATID_MSK;
3820 tbl_dw_addr = priv->scd_base_addr +
3821 SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id);
3823 tbl_dw = iwl_read_targ_mem(priv, tbl_dw_addr);
3826 tbl_dw = (scd_q2ratid << 16) | (tbl_dw & 0x0000FFFF);
3828 tbl_dw = scd_q2ratid | (tbl_dw & 0xFFFF0000);
3830 iwl_write_targ_mem(priv, tbl_dw_addr, tbl_dw);
3837 * iwl4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue
3839 * NOTE: txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID,
3840 * i.e. it must be one of the higher queues used for aggregation
3842 static int iwl4965_tx_queue_agg_enable(struct iwl_priv *priv, int txq_id,
3843 int tx_fifo, int sta_id, int tid,
3846 unsigned long flags;
3850 if (IWL_BACK_QUEUE_FIRST_ID > txq_id)
3851 IWL_WARNING("queue number too small: %d, must be > %d\n",
3852 txq_id, IWL_BACK_QUEUE_FIRST_ID);
3854 ra_tid = BUILD_RAxTID(sta_id, tid);
3856 /* Modify device's station table to Tx this TID */
3857 iwl4965_sta_modify_enable_tid_tx(priv, sta_id, tid);
3859 spin_lock_irqsave(&priv->lock, flags);
3860 rc = iwl_grab_nic_access(priv);
3862 spin_unlock_irqrestore(&priv->lock, flags);
3866 /* Stop this Tx queue before configuring it */
3867 iwl4965_tx_queue_stop_scheduler(priv, txq_id);
3869 /* Map receiver-address / traffic-ID to this queue */
3870 iwl4965_tx_queue_set_q2ratid(priv, ra_tid, txq_id);
3872 /* Set this queue as a chain-building queue */
3873 iwl_set_bits_prph(priv, IWL49_SCD_QUEUECHAIN_SEL, (1 << txq_id));
3875 /* Place first TFD at index corresponding to start sequence number.
3876 * Assumes that ssn_idx is valid (!= 0xFFF) */
3877 priv->txq[txq_id].q.read_ptr = (ssn_idx & 0xff);
3878 priv->txq[txq_id].q.write_ptr = (ssn_idx & 0xff);
3879 iwl4965_set_wr_ptrs(priv, txq_id, ssn_idx);
3881 /* Set up Tx window size and frame limit for this queue */
3882 iwl_write_targ_mem(priv,
3883 priv->scd_base_addr + SCD_CONTEXT_QUEUE_OFFSET(txq_id),
3884 (SCD_WIN_SIZE << SCD_QUEUE_CTX_REG1_WIN_SIZE_POS) &
3885 SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK);
3887 iwl_write_targ_mem(priv, priv->scd_base_addr +
3888 SCD_CONTEXT_QUEUE_OFFSET(txq_id) + sizeof(u32),
3889 (SCD_FRAME_LIMIT << SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS)
3890 & SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK);
3892 iwl_set_bits_prph(priv, IWL49_SCD_INTERRUPT_MASK, (1 << txq_id));
3894 /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
3895 iwl4965_tx_queue_set_status(priv, &priv->txq[txq_id], tx_fifo, 1);
3897 iwl_release_nic_access(priv);
3898 spin_unlock_irqrestore(&priv->lock, flags);
3903 #endif /* CONFIG_IWL4965_HT */
3906 * iwl4965_add_station - Initialize a station's hardware rate table
3908 * The uCode's station table contains a table of fallback rates
3909 * for automatic fallback during transmission.
3911 * NOTE: This sets up a default set of values. These will be replaced later
3912 * if the driver's iwl-4965-rs rate scaling algorithm is used, instead of
3915 * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
3916 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
3917 * which requires station table entry to exist).
3919 void iwl4965_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
3922 struct iwl_link_quality_cmd link_cmd = {
3927 /* Set up the rate scaling to start at selected rate, fall back
3928 * all the way down to 1M in IEEE order, and then spin on 1M */
3930 r = IWL_RATE_54M_INDEX;
3931 else if (priv->band == IEEE80211_BAND_5GHZ)
3932 r = IWL_RATE_6M_INDEX;
3934 r = IWL_RATE_1M_INDEX;
3936 for (i = 0; i < LINK_QUAL_MAX_RETRY_NUM; i++) {
3938 if (r >= IWL_FIRST_CCK_RATE && r <= IWL_LAST_CCK_RATE)
3939 rate_flags |= RATE_MCS_CCK_MSK;
3941 /* Use Tx antenna B only */
3942 rate_flags |= RATE_MCS_ANT_B_MSK; /*FIXME:RS*/
3944 link_cmd.rs_table[i].rate_n_flags =
3945 iwl4965_hw_set_rate_n_flags(iwl4965_rates[r].plcp, rate_flags);
3946 r = iwl4965_get_prev_ieee_rate(r);
3949 link_cmd.general_params.single_stream_ant_msk = 2;
3950 link_cmd.general_params.dual_stream_ant_msk = 3;
3951 link_cmd.agg_params.agg_dis_start_th = 3;
3952 link_cmd.agg_params.agg_time_limit = cpu_to_le16(4000);
3954 /* Update the rate scaling for control frame Tx to AP */
3955 link_cmd.sta_id = is_ap ? IWL_AP_ID : priv->hw_params.bcast_sta_id;
3957 iwl_send_cmd_pdu_async(priv, REPLY_TX_LINK_QUALITY_CMD,
3958 sizeof(link_cmd), &link_cmd, NULL);
3961 #ifdef CONFIG_IWL4965_HT
3963 static u8 iwl4965_is_channel_extension(struct iwl_priv *priv,
3964 enum ieee80211_band band,
3965 u16 channel, u8 extension_chan_offset)
3967 const struct iwl_channel_info *ch_info;
3969 ch_info = iwl_get_channel_info(priv, band, channel);
3970 if (!is_channel_valid(ch_info))
3973 if (extension_chan_offset == IWL_EXT_CHANNEL_OFFSET_NONE)
3976 if ((ch_info->fat_extension_channel == extension_chan_offset) ||
3977 (ch_info->fat_extension_channel == HT_IE_EXT_CHANNEL_MAX))
3983 static u8 iwl4965_is_fat_tx_allowed(struct iwl_priv *priv,
3984 struct ieee80211_ht_info *sta_ht_inf)
3986 struct iwl_ht_info *iwl_ht_conf = &priv->current_ht_config;
3988 if ((!iwl_ht_conf->is_ht) ||
3989 (iwl_ht_conf->supported_chan_width != IWL_CHANNEL_WIDTH_40MHZ) ||
3990 (iwl_ht_conf->extension_chan_offset == IWL_EXT_CHANNEL_OFFSET_NONE))
3994 if ((!sta_ht_inf->ht_supported) ||
3995 (!(sta_ht_inf->cap & IEEE80211_HT_CAP_SUP_WIDTH)))
3999 return (iwl4965_is_channel_extension(priv, priv->band,
4000 iwl_ht_conf->control_channel,
4001 iwl_ht_conf->extension_chan_offset));
4004 void iwl4965_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_info *ht_info)
4006 struct iwl4965_rxon_cmd *rxon = &priv->staging_rxon;
4009 if (!ht_info->is_ht)
4012 /* Set up channel bandwidth: 20 MHz only, or 20/40 mixed if fat ok */
4013 if (iwl4965_is_fat_tx_allowed(priv, NULL))
4014 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED_MSK;
4016 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
4017 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
4019 if (le16_to_cpu(rxon->channel) != ht_info->control_channel) {
4020 IWL_DEBUG_ASSOC("control diff than current %d %d\n",
4021 le16_to_cpu(rxon->channel),
4022 ht_info->control_channel);
4023 rxon->channel = cpu_to_le16(ht_info->control_channel);
4027 /* Note: control channel is opposite of extension channel */
4028 switch (ht_info->extension_chan_offset) {
4029 case IWL_EXT_CHANNEL_OFFSET_ABOVE:
4030 rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
4032 case IWL_EXT_CHANNEL_OFFSET_BELOW:
4033 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
4035 case IWL_EXT_CHANNEL_OFFSET_NONE:
4037 rxon->flags &= ~RXON_FLG_CHANNEL_MODE_MIXED_MSK;
4041 val = ht_info->ht_protection;
4043 rxon->flags |= cpu_to_le32(val << RXON_FLG_HT_OPERATING_MODE_POS);
4045 iwl4965_set_rxon_chain(priv);
4047 IWL_DEBUG_ASSOC("supported HT rate 0x%X 0x%X 0x%X "
4048 "rxon flags 0x%X operation mode :0x%X "
4049 "extension channel offset 0x%x "
4050 "control chan %d\n",
4051 ht_info->supp_mcs_set[0],
4052 ht_info->supp_mcs_set[1],
4053 ht_info->supp_mcs_set[2],
4054 le32_to_cpu(rxon->flags), ht_info->ht_protection,
4055 ht_info->extension_chan_offset,
4056 ht_info->control_channel);
4060 void iwl4965_set_ht_add_station(struct iwl_priv *priv, u8 index,
4061 struct ieee80211_ht_info *sta_ht_inf)
4066 if (!sta_ht_inf || !sta_ht_inf->ht_supported)
4069 mimo_ps_mode = (sta_ht_inf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2;
4071 sta_flags = priv->stations[index].sta.station_flags;
4073 sta_flags &= ~(STA_FLG_RTS_MIMO_PROT_MSK | STA_FLG_MIMO_DIS_MSK);
4075 switch (mimo_ps_mode) {
4076 case WLAN_HT_CAP_MIMO_PS_STATIC:
4077 sta_flags |= STA_FLG_MIMO_DIS_MSK;
4079 case WLAN_HT_CAP_MIMO_PS_DYNAMIC:
4080 sta_flags |= STA_FLG_RTS_MIMO_PROT_MSK;
4082 case WLAN_HT_CAP_MIMO_PS_DISABLED:
4085 IWL_WARNING("Invalid MIMO PS mode %d", mimo_ps_mode);
4089 sta_flags |= cpu_to_le32(
4090 (u32)sta_ht_inf->ampdu_factor << STA_FLG_MAX_AGG_SIZE_POS);
4092 sta_flags |= cpu_to_le32(
4093 (u32)sta_ht_inf->ampdu_density << STA_FLG_AGG_MPDU_DENSITY_POS);
4095 if (iwl4965_is_fat_tx_allowed(priv, sta_ht_inf))
4096 sta_flags |= STA_FLG_FAT_EN_MSK;
4098 sta_flags &= ~STA_FLG_FAT_EN_MSK;
4100 priv->stations[index].sta.station_flags = sta_flags;
4105 static int iwl4965_rx_agg_start(struct iwl_priv *priv,
4106 const u8 *addr, int tid, u16 ssn)
4108 unsigned long flags;
4111 sta_id = iwl_find_station(priv, addr);
4112 if (sta_id == IWL_INVALID_STATION)
4115 spin_lock_irqsave(&priv->sta_lock, flags);
4116 priv->stations[sta_id].sta.station_flags_msk = 0;
4117 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_ADDBA_TID_MSK;
4118 priv->stations[sta_id].sta.add_immediate_ba_tid = (u8)tid;
4119 priv->stations[sta_id].sta.add_immediate_ba_ssn = cpu_to_le16(ssn);
4120 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
4121 spin_unlock_irqrestore(&priv->sta_lock, flags);
4123 return iwl4965_send_add_station(priv, &priv->stations[sta_id].sta,
4127 static int iwl4965_rx_agg_stop(struct iwl_priv *priv,
4128 const u8 *addr, int tid)
4130 unsigned long flags;
4133 sta_id = iwl_find_station(priv, addr);
4134 if (sta_id == IWL_INVALID_STATION)
4137 spin_lock_irqsave(&priv->sta_lock, flags);
4138 priv->stations[sta_id].sta.station_flags_msk = 0;
4139 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_DELBA_TID_MSK;
4140 priv->stations[sta_id].sta.remove_immediate_ba_tid = (u8)tid;
4141 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
4142 spin_unlock_irqrestore(&priv->sta_lock, flags);
4144 return iwl4965_send_add_station(priv, &priv->stations[sta_id].sta,
4149 * Find first available (lowest unused) Tx Queue, mark it "active".
4150 * Called only when finding queue for aggregation.
4151 * Should never return anything < 7, because they should already
4152 * be in use as EDCA AC (0-3), Command (4), HCCA (5, 6).
4154 static int iwl4965_txq_ctx_activate_free(struct iwl_priv *priv)
4158 for (txq_id = 0; txq_id < priv->hw_params.max_txq_num; txq_id++)
4159 if (!test_and_set_bit(txq_id, &priv->txq_ctx_active_msk))
4164 static int iwl4965_tx_agg_start(struct ieee80211_hw *hw, const u8 *ra,
4165 u16 tid, u16 *start_seq_num)
4167 struct iwl_priv *priv = hw->priv;
4173 unsigned long flags;
4174 struct iwl4965_tid_data *tid_data;
4175 DECLARE_MAC_BUF(mac);
4177 if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
4178 tx_fifo = default_tid_to_tx_fifo[tid];
4182 IWL_WARNING("%s on ra = %s tid = %d\n",
4183 __func__, print_mac(mac, ra), tid);
4185 sta_id = iwl_find_station(priv, ra);
4186 if (sta_id == IWL_INVALID_STATION)
4189 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_OFF) {
4190 IWL_ERROR("Start AGG when state is not IWL_AGG_OFF !\n");
4194 txq_id = iwl4965_txq_ctx_activate_free(priv);
4198 spin_lock_irqsave(&priv->sta_lock, flags);
4199 tid_data = &priv->stations[sta_id].tid[tid];
4200 ssn = SEQ_TO_SN(tid_data->seq_number);
4201 tid_data->agg.txq_id = txq_id;
4202 spin_unlock_irqrestore(&priv->sta_lock, flags);
4204 *start_seq_num = ssn;
4205 ret = iwl4965_tx_queue_agg_enable(priv, txq_id, tx_fifo,
4211 if (tid_data->tfds_in_queue == 0) {
4212 printk(KERN_ERR "HW queue is empty\n");
4213 tid_data->agg.state = IWL_AGG_ON;
4214 ieee80211_start_tx_ba_cb_irqsafe(hw, ra, tid);
4216 IWL_DEBUG_HT("HW queue is NOT empty: %d packets in HW queue\n",
4217 tid_data->tfds_in_queue);
4218 tid_data->agg.state = IWL_EMPTYING_HW_QUEUE_ADDBA;
4223 static int iwl4965_tx_agg_stop(struct ieee80211_hw *hw, const u8 *ra, u16 tid)
4225 struct iwl_priv *priv = hw->priv;
4226 int tx_fifo_id, txq_id, sta_id, ssn = -1;
4227 struct iwl4965_tid_data *tid_data;
4228 int ret, write_ptr, read_ptr;
4229 unsigned long flags;
4230 DECLARE_MAC_BUF(mac);
4233 IWL_ERROR("ra = NULL\n");
4237 if (likely(tid < ARRAY_SIZE(default_tid_to_tx_fifo)))
4238 tx_fifo_id = default_tid_to_tx_fifo[tid];
4242 sta_id = iwl_find_station(priv, ra);
4244 if (sta_id == IWL_INVALID_STATION)
4247 if (priv->stations[sta_id].tid[tid].agg.state != IWL_AGG_ON)
4248 IWL_WARNING("Stopping AGG while state not IWL_AGG_ON\n");
4250 tid_data = &priv->stations[sta_id].tid[tid];
4251 ssn = (tid_data->seq_number & IEEE80211_SCTL_SEQ) >> 4;
4252 txq_id = tid_data->agg.txq_id;
4253 write_ptr = priv->txq[txq_id].q.write_ptr;
4254 read_ptr = priv->txq[txq_id].q.read_ptr;
4256 /* The queue is not empty */
4257 if (write_ptr != read_ptr) {
4258 IWL_DEBUG_HT("Stopping a non empty AGG HW QUEUE\n");
4259 priv->stations[sta_id].tid[tid].agg.state =
4260 IWL_EMPTYING_HW_QUEUE_DELBA;
4264 IWL_DEBUG_HT("HW queue is empty\n");
4265 priv->stations[sta_id].tid[tid].agg.state = IWL_AGG_OFF;
4267 spin_lock_irqsave(&priv->lock, flags);
4268 ret = iwl4965_tx_queue_agg_disable(priv, txq_id, ssn, tx_fifo_id);
4269 spin_unlock_irqrestore(&priv->lock, flags);
4274 ieee80211_stop_tx_ba_cb_irqsafe(priv->hw, ra, tid);
4279 int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
4280 enum ieee80211_ampdu_mlme_action action,
4281 const u8 *addr, u16 tid, u16 *ssn)
4283 struct iwl_priv *priv = hw->priv;
4284 DECLARE_MAC_BUF(mac);
4286 IWL_DEBUG_HT("A-MPDU action on addr %s tid %d\n",
4287 print_mac(mac, addr), tid);
4290 case IEEE80211_AMPDU_RX_START:
4291 IWL_DEBUG_HT("start Rx\n");
4292 return iwl4965_rx_agg_start(priv, addr, tid, *ssn);
4293 case IEEE80211_AMPDU_RX_STOP:
4294 IWL_DEBUG_HT("stop Rx\n");
4295 return iwl4965_rx_agg_stop(priv, addr, tid);
4296 case IEEE80211_AMPDU_TX_START:
4297 IWL_DEBUG_HT("start Tx\n");
4298 return iwl4965_tx_agg_start(hw, addr, tid, ssn);
4299 case IEEE80211_AMPDU_TX_STOP:
4300 IWL_DEBUG_HT("stop Tx\n");
4301 return iwl4965_tx_agg_stop(hw, addr, tid);
4303 IWL_DEBUG_HT("unknown\n");
4310 #endif /* CONFIG_IWL4965_HT */
4312 /* Set up 4965-specific Rx frame reply handlers */
4313 void iwl4965_hw_rx_handler_setup(struct iwl_priv *priv)
4315 /* Legacy Rx frames */
4316 priv->rx_handlers[REPLY_RX] = iwl4965_rx_reply_rx;
4318 /* High-throughput (HT) Rx frames */
4319 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl4965_rx_reply_rx_phy;
4320 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl4965_rx_reply_rx;
4322 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
4323 iwl4965_rx_missed_beacon_notif;
4325 #ifdef CONFIG_IWL4965_HT
4326 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl4965_rx_reply_compressed_ba;
4327 #endif /* CONFIG_IWL4965_HT */
4330 void iwl4965_hw_setup_deferred_work(struct iwl_priv *priv)
4332 INIT_WORK(&priv->txpower_work, iwl4965_bg_txpower_work);
4333 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
4334 INIT_WORK(&priv->sensitivity_work, iwl4965_bg_sensitivity_work);
4336 init_timer(&priv->statistics_periodic);
4337 priv->statistics_periodic.data = (unsigned long)priv;
4338 priv->statistics_periodic.function = iwl4965_bg_statistics_periodic;
4341 void iwl4965_hw_cancel_deferred_work(struct iwl_priv *priv)
4343 del_timer_sync(&priv->statistics_periodic);
4345 cancel_delayed_work(&priv->init_alive_start);
4349 static struct iwl_hcmd_ops iwl4965_hcmd = {
4350 .rxon_assoc = iwl4965_send_rxon_assoc,
4353 static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils = {
4354 .enqueue_hcmd = iwl4965_enqueue_hcmd,
4355 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
4356 .chain_noise_reset = iwl4965_chain_noise_reset,
4357 .gain_computation = iwl4965_gain_computation,
4361 static struct iwl_lib_ops iwl4965_lib = {
4362 .init_drv = iwl4965_init_drv,
4363 .set_hw_params = iwl4965_hw_set_hw_params,
4364 .alloc_shared_mem = iwl4965_alloc_shared_mem,
4365 .free_shared_mem = iwl4965_free_shared_mem,
4366 .txq_update_byte_cnt_tbl = iwl4965_txq_update_byte_cnt_tbl,
4367 .hw_nic_init = iwl4965_hw_nic_init,
4368 .is_valid_rtc_data_addr = iwl4965_hw_valid_rtc_data_addr,
4369 .alive_notify = iwl4965_alive_notify,
4370 .load_ucode = iwl4965_load_bsm,
4372 .init = iwl4965_apm_init,
4373 .set_pwr_src = iwl4965_set_pwr_src,
4376 .regulatory_bands = {
4377 EEPROM_REGULATORY_BAND_1_CHANNELS,
4378 EEPROM_REGULATORY_BAND_2_CHANNELS,
4379 EEPROM_REGULATORY_BAND_3_CHANNELS,
4380 EEPROM_REGULATORY_BAND_4_CHANNELS,
4381 EEPROM_REGULATORY_BAND_5_CHANNELS,
4382 EEPROM_4965_REGULATORY_BAND_24_FAT_CHANNELS,
4383 EEPROM_4965_REGULATORY_BAND_52_FAT_CHANNELS
4385 .verify_signature = iwlcore_eeprom_verify_signature,
4386 .acquire_semaphore = iwlcore_eeprom_acquire_semaphore,
4387 .release_semaphore = iwlcore_eeprom_release_semaphore,
4388 .check_version = iwl4965_eeprom_check_version,
4389 .query_addr = iwlcore_eeprom_query_addr,
4391 .radio_kill_sw = iwl4965_radio_kill_sw,
4392 .set_power = iwl4965_set_power,
4393 .update_chain_flags = iwl4965_update_chain_flags,
4396 static struct iwl_ops iwl4965_ops = {
4397 .lib = &iwl4965_lib,
4398 .hcmd = &iwl4965_hcmd,
4399 .utils = &iwl4965_hcmd_utils,
4402 struct iwl_cfg iwl4965_agn_cfg = {
4404 .fw_name = "iwlwifi-4965" IWL4965_UCODE_API ".ucode",
4405 .sku = IWL_SKU_A|IWL_SKU_G|IWL_SKU_N,
4406 .eeprom_size = IWL4965_EEPROM_IMG_SIZE,
4407 .ops = &iwl4965_ops,
4408 .mod_params = &iwl4965_mod_params,
4411 module_param_named(antenna, iwl4965_mod_params.antenna, int, 0444);
4412 MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
4413 module_param_named(disable, iwl4965_mod_params.disable, int, 0444);
4414 MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
4415 module_param_named(swcrypto, iwl4965_mod_params.sw_crypto, int, 0444);
4416 MODULE_PARM_DESC(swcrypto, "using crypto in software (default 0 [hardware])\n");
4417 module_param_named(debug, iwl4965_mod_params.debug, int, 0444);
4418 MODULE_PARM_DESC(debug, "debug output mask");
4420 disable_hw_scan, iwl4965_mod_params.disable_hw_scan, int, 0444);
4421 MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
4423 module_param_named(queues_num, iwl4965_mod_params.num_of_queues, int, 0444);
4424 MODULE_PARM_DESC(queues_num, "number of hw queues.");
4427 module_param_named(qos_enable, iwl4965_mod_params.enable_qos, int, 0444);
4428 MODULE_PARM_DESC(qos_enable, "enable all QoS functionality");
4429 module_param_named(amsdu_size_8K, iwl4965_mod_params.amsdu_size_8K, int, 0444);
4430 MODULE_PARM_DESC(amsdu_size_8K, "enable 8K amsdu size");