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
),
2506 * iwl4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
2508 static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv
*priv
,
2509 struct iwl4965_tx_queue
*txq
,
2513 int txq_id
= txq
->q
.id
;
2514 struct iwl4965_shared
*shared_data
= priv
->shared_virt
;
2516 len
= byte_cnt
+ IWL_TX_CRC_SIZE
+ IWL_TX_DELIMITER_SIZE
;
2518 /* Set up byte count within first 256 entries */
2519 IWL_SET_BITS16(shared_data
->queues_byte_cnt_tbls
[txq_id
].
2520 tfd_offset
[txq
->q
.write_ptr
], byte_cnt
, len
);
2522 /* If within first 64 entries, duplicate at end */
2523 if (txq
->q
.write_ptr
< IWL4965_MAX_WIN_SIZE
)
2524 IWL_SET_BITS16(shared_data
->queues_byte_cnt_tbls
[txq_id
].
2525 tfd_offset
[IWL4965_QUEUE_SIZE
+ txq
->q
.write_ptr
],
2530 * iwl4965_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
2532 * Selects how many and which Rx receivers/antennas/chains to use.
2533 * This should not be used for scan command ... it puts data in wrong place.
2535 void iwl4965_set_rxon_chain(struct iwl_priv
*priv
)
2537 u8 is_single
= is_single_rx_stream(priv
);
2538 u8 idle_state
, rx_state
;
2540 priv
->staging_rxon
.rx_chain
= 0;
2541 rx_state
= idle_state
= 3;
2543 /* Tell uCode which antennas are actually connected.
2544 * Before first association, we assume all antennas are connected.
2545 * Just after first association, iwl_chain_noise_calibration()
2546 * checks which antennas actually *are* connected. */
2547 priv
->staging_rxon
.rx_chain
|=
2548 cpu_to_le16(priv
->hw_params
.valid_rx_ant
<<
2549 RXON_RX_CHAIN_VALID_POS
);
2551 /* How many receivers should we use? */
2552 iwl4965_get_rx_chain_counter(priv
, &idle_state
, &rx_state
);
2553 priv
->staging_rxon
.rx_chain
|=
2554 cpu_to_le16(rx_state
<< RXON_RX_CHAIN_MIMO_CNT_POS
);
2555 priv
->staging_rxon
.rx_chain
|=
2556 cpu_to_le16(idle_state
<< RXON_RX_CHAIN_CNT_POS
);
2558 if (!is_single
&& (rx_state
>= 2) &&
2559 !test_bit(STATUS_POWER_PMI
, &priv
->status
))
2560 priv
->staging_rxon
.rx_chain
|= RXON_RX_CHAIN_MIMO_FORCE_MSK
;
2562 priv
->staging_rxon
.rx_chain
&= ~RXON_RX_CHAIN_MIMO_FORCE_MSK
;
2564 IWL_DEBUG_ASSOC("rx chain %X\n", priv
->staging_rxon
.rx_chain
);
2568 * sign_extend - Sign extend a value using specified bit as sign-bit
2570 * Example: sign_extend(9, 3) would return -7 as bit3 of 1001b is 1
2571 * and bit0..2 is 001b which when sign extended to 1111111111111001b is -7.
2573 * @param oper value to sign extend
2574 * @param index 0 based bit index (0<=index<32) to sign bit
2576 static s32
sign_extend(u32 oper
, int index
)
2578 u8 shift
= 31 - index
;
2580 return (s32
)(oper
<< shift
) >> shift
;
2584 * iwl4965_get_temperature - return the calibrated temperature (in Kelvin)
2585 * @statistics: Provides the temperature reading from the uCode
2587 * A return of <0 indicates bogus data in the statistics
2589 int iwl4965_get_temperature(const struct iwl_priv
*priv
)
2596 if (test_bit(STATUS_TEMPERATURE
, &priv
->status
) &&
2597 (priv
->statistics
.flag
& STATISTICS_REPLY_FLG_FAT_MODE_MSK
)) {
2598 IWL_DEBUG_TEMP("Running FAT temperature calibration\n");
2599 R1
= (s32
)le32_to_cpu(priv
->card_alive_init
.therm_r1
[1]);
2600 R2
= (s32
)le32_to_cpu(priv
->card_alive_init
.therm_r2
[1]);
2601 R3
= (s32
)le32_to_cpu(priv
->card_alive_init
.therm_r3
[1]);
2602 R4
= le32_to_cpu(priv
->card_alive_init
.therm_r4
[1]);
2604 IWL_DEBUG_TEMP("Running temperature calibration\n");
2605 R1
= (s32
)le32_to_cpu(priv
->card_alive_init
.therm_r1
[0]);
2606 R2
= (s32
)le32_to_cpu(priv
->card_alive_init
.therm_r2
[0]);
2607 R3
= (s32
)le32_to_cpu(priv
->card_alive_init
.therm_r3
[0]);
2608 R4
= le32_to_cpu(priv
->card_alive_init
.therm_r4
[0]);
2612 * Temperature is only 23 bits, so sign extend out to 32.
2614 * NOTE If we haven't received a statistics notification yet
2615 * with an updated temperature, use R4 provided to us in the
2616 * "initialize" ALIVE response.
2618 if (!test_bit(STATUS_TEMPERATURE
, &priv
->status
))
2619 vt
= sign_extend(R4
, 23);
2622 le32_to_cpu(priv
->statistics
.general
.temperature
), 23);
2624 IWL_DEBUG_TEMP("Calib values R[1-3]: %d %d %d R4: %d\n",
2628 IWL_ERROR("Calibration conflict R1 == R3\n");
2632 /* Calculate temperature in degrees Kelvin, adjust by 97%.
2633 * Add offset to center the adjustment around 0 degrees Centigrade. */
2634 temperature
= TEMPERATURE_CALIB_A_VAL
* (vt
- R2
);
2635 temperature
/= (R3
- R1
);
2636 temperature
= (temperature
* 97) / 100 +
2637 TEMPERATURE_CALIB_KELVIN_OFFSET
;
2639 IWL_DEBUG_TEMP("Calibrated temperature: %dK, %dC\n", temperature
,
2640 KELVIN_TO_CELSIUS(temperature
));
2645 /* Adjust Txpower only if temperature variance is greater than threshold. */
2646 #define IWL_TEMPERATURE_THRESHOLD 3
2649 * iwl4965_is_temp_calib_needed - determines if new calibration is needed
2651 * If the temperature changed has changed sufficiently, then a recalibration
2654 * Assumes caller will replace priv->last_temperature once calibration
2657 static int iwl4965_is_temp_calib_needed(struct iwl_priv
*priv
)
2661 if (!test_bit(STATUS_STATISTICS
, &priv
->status
)) {
2662 IWL_DEBUG_TEMP("Temperature not updated -- no statistics.\n");
2666 temp_diff
= priv
->temperature
- priv
->last_temperature
;
2668 /* get absolute value */
2669 if (temp_diff
< 0) {
2670 IWL_DEBUG_POWER("Getting cooler, delta %d, \n", temp_diff
);
2671 temp_diff
= -temp_diff
;
2672 } else if (temp_diff
== 0)
2673 IWL_DEBUG_POWER("Same temp, \n");
2675 IWL_DEBUG_POWER("Getting warmer, delta %d, \n", temp_diff
);
2677 if (temp_diff
< IWL_TEMPERATURE_THRESHOLD
) {
2678 IWL_DEBUG_POWER("Thermal txpower calib not needed\n");
2682 IWL_DEBUG_POWER("Thermal txpower calib needed\n");
2687 /* Calculate noise level, based on measurements during network silence just
2688 * before arriving beacon. This measurement can be done only if we know
2689 * exactly when to expect beacons, therefore only when we're associated. */
2690 static void iwl4965_rx_calc_noise(struct iwl_priv
*priv
)
2692 struct statistics_rx_non_phy
*rx_info
2693 = &(priv
->statistics
.rx
.general
);
2694 int num_active_rx
= 0;
2695 int total_silence
= 0;
2697 le32_to_cpu(rx_info
->beacon_silence_rssi_a
) & IN_BAND_FILTER
;
2699 le32_to_cpu(rx_info
->beacon_silence_rssi_b
) & IN_BAND_FILTER
;
2701 le32_to_cpu(rx_info
->beacon_silence_rssi_c
) & IN_BAND_FILTER
;
2703 if (bcn_silence_a
) {
2704 total_silence
+= bcn_silence_a
;
2707 if (bcn_silence_b
) {
2708 total_silence
+= bcn_silence_b
;
2711 if (bcn_silence_c
) {
2712 total_silence
+= bcn_silence_c
;
2716 /* Average among active antennas */
2718 priv
->last_rx_noise
= (total_silence
/ num_active_rx
) - 107;
2720 priv
->last_rx_noise
= IWL_NOISE_MEAS_NOT_AVAILABLE
;
2722 IWL_DEBUG_CALIB("inband silence a %u, b %u, c %u, dBm %d\n",
2723 bcn_silence_a
, bcn_silence_b
, bcn_silence_c
,
2724 priv
->last_rx_noise
);
2727 void iwl4965_hw_rx_statistics(struct iwl_priv
*priv
, struct iwl4965_rx_mem_buffer
*rxb
)
2729 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
2733 IWL_DEBUG_RX("Statistics notification received (%d vs %d).\n",
2734 (int)sizeof(priv
->statistics
), pkt
->len
);
2736 change
= ((priv
->statistics
.general
.temperature
!=
2737 pkt
->u
.stats
.general
.temperature
) ||
2738 ((priv
->statistics
.flag
&
2739 STATISTICS_REPLY_FLG_FAT_MODE_MSK
) !=
2740 (pkt
->u
.stats
.flag
& STATISTICS_REPLY_FLG_FAT_MODE_MSK
)));
2742 memcpy(&priv
->statistics
, &pkt
->u
.stats
, sizeof(priv
->statistics
));
2744 set_bit(STATUS_STATISTICS
, &priv
->status
);
2746 /* Reschedule the statistics timer to occur in
2747 * REG_RECALIB_PERIOD seconds to ensure we get a
2748 * thermal update even if the uCode doesn't give
2750 mod_timer(&priv
->statistics_periodic
, jiffies
+
2751 msecs_to_jiffies(REG_RECALIB_PERIOD
* 1000));
2753 if (unlikely(!test_bit(STATUS_SCANNING
, &priv
->status
)) &&
2754 (pkt
->hdr
.cmd
== STATISTICS_NOTIFICATION
)) {
2755 iwl4965_rx_calc_noise(priv
);
2756 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
2757 queue_work(priv
->workqueue
, &priv
->sensitivity_work
);
2761 iwl_leds_background(priv
);
2763 /* If the hardware hasn't reported a change in
2764 * temperature then don't bother computing a
2765 * calibrated temperature value */
2769 temp
= iwl4965_get_temperature(priv
);
2773 if (priv
->temperature
!= temp
) {
2774 if (priv
->temperature
)
2775 IWL_DEBUG_TEMP("Temperature changed "
2776 "from %dC to %dC\n",
2777 KELVIN_TO_CELSIUS(priv
->temperature
),
2778 KELVIN_TO_CELSIUS(temp
));
2780 IWL_DEBUG_TEMP("Temperature "
2781 "initialized to %dC\n",
2782 KELVIN_TO_CELSIUS(temp
));
2785 priv
->temperature
= temp
;
2786 set_bit(STATUS_TEMPERATURE
, &priv
->status
);
2788 if (unlikely(!test_bit(STATUS_SCANNING
, &priv
->status
)) &&
2789 iwl4965_is_temp_calib_needed(priv
))
2790 queue_work(priv
->workqueue
, &priv
->txpower_work
);
2793 static void iwl4965_add_radiotap(struct iwl_priv
*priv
,
2794 struct sk_buff
*skb
,
2795 struct iwl4965_rx_phy_res
*rx_start
,
2796 struct ieee80211_rx_status
*stats
,
2799 s8 signal
= stats
->ssi
;
2801 int rate
= stats
->rate_idx
;
2802 u64 tsf
= stats
->mactime
;
2804 __le16 phy_flags_hw
= rx_start
->phy_flags
;
2805 struct iwl4965_rt_rx_hdr
{
2806 struct ieee80211_radiotap_header rt_hdr
;
2807 __le64 rt_tsf
; /* TSF */
2808 u8 rt_flags
; /* radiotap packet flags */
2809 u8 rt_rate
; /* rate in 500kb/s */
2810 __le16 rt_channelMHz
; /* channel in MHz */
2811 __le16 rt_chbitmask
; /* channel bitfield */
2812 s8 rt_dbmsignal
; /* signal in dBm, kluged to signed */
2814 u8 rt_antenna
; /* antenna number */
2815 } __attribute__ ((packed
)) *iwl4965_rt
;
2817 /* TODO: We won't have enough headroom for HT frames. Fix it later. */
2818 if (skb_headroom(skb
) < sizeof(*iwl4965_rt
)) {
2819 if (net_ratelimit())
2820 printk(KERN_ERR
"not enough headroom [%d] for "
2821 "radiotap head [%zd]\n",
2822 skb_headroom(skb
), sizeof(*iwl4965_rt
));
2826 /* put radiotap header in front of 802.11 header and data */
2827 iwl4965_rt
= (void *)skb_push(skb
, sizeof(*iwl4965_rt
));
2829 /* initialise radiotap header */
2830 iwl4965_rt
->rt_hdr
.it_version
= PKTHDR_RADIOTAP_VERSION
;
2831 iwl4965_rt
->rt_hdr
.it_pad
= 0;
2833 /* total header + data */
2834 put_unaligned(cpu_to_le16(sizeof(*iwl4965_rt
)),
2835 &iwl4965_rt
->rt_hdr
.it_len
);
2837 /* Indicate all the fields we add to the radiotap header */
2838 put_unaligned(cpu_to_le32((1 << IEEE80211_RADIOTAP_TSFT
) |
2839 (1 << IEEE80211_RADIOTAP_FLAGS
) |
2840 (1 << IEEE80211_RADIOTAP_RATE
) |
2841 (1 << IEEE80211_RADIOTAP_CHANNEL
) |
2842 (1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL
) |
2843 (1 << IEEE80211_RADIOTAP_DBM_ANTNOISE
) |
2844 (1 << IEEE80211_RADIOTAP_ANTENNA
)),
2845 &iwl4965_rt
->rt_hdr
.it_present
);
2847 /* Zero the flags, we'll add to them as we go */
2848 iwl4965_rt
->rt_flags
= 0;
2850 put_unaligned(cpu_to_le64(tsf
), &iwl4965_rt
->rt_tsf
);
2852 iwl4965_rt
->rt_dbmsignal
= signal
;
2853 iwl4965_rt
->rt_dbmnoise
= noise
;
2855 /* Convert the channel frequency and set the flags */
2856 put_unaligned(cpu_to_le16(stats
->freq
), &iwl4965_rt
->rt_channelMHz
);
2857 if (!(phy_flags_hw
& RX_RES_PHY_FLAGS_BAND_24_MSK
))
2858 put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM
|
2859 IEEE80211_CHAN_5GHZ
),
2860 &iwl4965_rt
->rt_chbitmask
);
2861 else if (phy_flags_hw
& RX_RES_PHY_FLAGS_MOD_CCK_MSK
)
2862 put_unaligned(cpu_to_le16(IEEE80211_CHAN_CCK
|
2863 IEEE80211_CHAN_2GHZ
),
2864 &iwl4965_rt
->rt_chbitmask
);
2866 put_unaligned(cpu_to_le16(IEEE80211_CHAN_OFDM
|
2867 IEEE80211_CHAN_2GHZ
),
2868 &iwl4965_rt
->rt_chbitmask
);
2871 iwl4965_rt
->rt_rate
= 0;
2873 iwl4965_rt
->rt_rate
= iwl4965_rates
[rate
].ieee
;
2878 * It seems that the antenna field in the phy flags value
2879 * is actually a bitfield. This is undefined by radiotap,
2880 * it wants an actual antenna number but I always get "7"
2881 * for most legacy frames I receive indicating that the
2882 * same frame was received on all three RX chains.
2884 * I think this field should be removed in favour of a
2885 * new 802.11n radiotap field "RX chains" that is defined
2888 antenna
= phy_flags_hw
& RX_RES_PHY_FLAGS_ANTENNA_MSK
;
2889 iwl4965_rt
->rt_antenna
= le16_to_cpu(antenna
) >> 4;
2891 /* set the preamble flag if appropriate */
2892 if (phy_flags_hw
& RX_RES_PHY_FLAGS_SHORT_PREAMBLE_MSK
)
2893 iwl4965_rt
->rt_flags
|= IEEE80211_RADIOTAP_F_SHORTPRE
;
2895 stats
->flag
|= RX_FLAG_RADIOTAP
;
2898 static void iwl_update_rx_stats(struct iwl_priv
*priv
, u16 fc
, u16 len
)
2900 /* 0 - mgmt, 1 - cnt, 2 - data */
2901 int idx
= (fc
& IEEE80211_FCTL_FTYPE
) >> 2;
2902 priv
->rx_stats
[idx
].cnt
++;
2903 priv
->rx_stats
[idx
].bytes
+= len
;
2907 * returns non-zero if packet should be dropped
2909 static int iwl4965_set_decrypted_flag(struct iwl_priv
*priv
,
2910 struct ieee80211_hdr
*hdr
,
2912 struct ieee80211_rx_status
*stats
)
2914 u16 fc
= le16_to_cpu(hdr
->frame_control
);
2916 if (priv
->active_rxon
.filter_flags
& RXON_FILTER_DIS_DECRYPT_MSK
)
2919 if (!(fc
& IEEE80211_FCTL_PROTECTED
))
2922 IWL_DEBUG_RX("decrypt_res:0x%x\n", decrypt_res
);
2923 switch (decrypt_res
& RX_RES_STATUS_SEC_TYPE_MSK
) {
2924 case RX_RES_STATUS_SEC_TYPE_TKIP
:
2925 /* The uCode has got a bad phase 1 Key, pushes the packet.
2926 * Decryption will be done in SW. */
2927 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2928 RX_RES_STATUS_BAD_KEY_TTAK
)
2931 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2932 RX_RES_STATUS_BAD_ICV_MIC
) {
2933 /* bad ICV, the packet is destroyed since the
2934 * decryption is inplace, drop it */
2935 IWL_DEBUG_RX("Packet destroyed\n");
2938 case RX_RES_STATUS_SEC_TYPE_WEP
:
2939 case RX_RES_STATUS_SEC_TYPE_CCMP
:
2940 if ((decrypt_res
& RX_RES_STATUS_DECRYPT_TYPE_MSK
) ==
2941 RX_RES_STATUS_DECRYPT_OK
) {
2942 IWL_DEBUG_RX("hw decrypt successfully!!!\n");
2943 stats
->flag
|= RX_FLAG_DECRYPTED
;
2953 static u32
iwl4965_translate_rx_status(u32 decrypt_in
)
2955 u32 decrypt_out
= 0;
2957 if ((decrypt_in
& RX_RES_STATUS_STATION_FOUND
) ==
2958 RX_RES_STATUS_STATION_FOUND
)
2959 decrypt_out
|= (RX_RES_STATUS_STATION_FOUND
|
2960 RX_RES_STATUS_NO_STATION_INFO_MISMATCH
);
2962 decrypt_out
|= (decrypt_in
& RX_RES_STATUS_SEC_TYPE_MSK
);
2964 /* packet was not encrypted */
2965 if ((decrypt_in
& RX_RES_STATUS_SEC_TYPE_MSK
) ==
2966 RX_RES_STATUS_SEC_TYPE_NONE
)
2969 /* packet was encrypted with unknown alg */
2970 if ((decrypt_in
& RX_RES_STATUS_SEC_TYPE_MSK
) ==
2971 RX_RES_STATUS_SEC_TYPE_ERR
)
2974 /* decryption was not done in HW */
2975 if ((decrypt_in
& RX_MPDU_RES_STATUS_DEC_DONE_MSK
) !=
2976 RX_MPDU_RES_STATUS_DEC_DONE_MSK
)
2979 switch (decrypt_in
& RX_RES_STATUS_SEC_TYPE_MSK
) {
2981 case RX_RES_STATUS_SEC_TYPE_CCMP
:
2982 /* alg is CCM: check MIC only */
2983 if (!(decrypt_in
& RX_MPDU_RES_STATUS_MIC_OK
))
2985 decrypt_out
|= RX_RES_STATUS_BAD_ICV_MIC
;
2987 decrypt_out
|= RX_RES_STATUS_DECRYPT_OK
;
2991 case RX_RES_STATUS_SEC_TYPE_TKIP
:
2992 if (!(decrypt_in
& RX_MPDU_RES_STATUS_TTAK_OK
)) {
2994 decrypt_out
|= RX_RES_STATUS_BAD_KEY_TTAK
;
2997 /* fall through if TTAK OK */
2999 if (!(decrypt_in
& RX_MPDU_RES_STATUS_ICV_OK
))
3000 decrypt_out
|= RX_RES_STATUS_BAD_ICV_MIC
;
3002 decrypt_out
|= RX_RES_STATUS_DECRYPT_OK
;
3006 IWL_DEBUG_RX("decrypt_in:0x%x decrypt_out = 0x%x\n",
3007 decrypt_in
, decrypt_out
);
3012 static void iwl4965_handle_data_packet(struct iwl_priv
*priv
, int is_data
,
3014 struct iwl4965_rx_mem_buffer
*rxb
,
3015 struct ieee80211_rx_status
*stats
)
3017 struct iwl4965_rx_packet
*pkt
= (struct iwl4965_rx_packet
*)rxb
->skb
->data
;
3018 struct iwl4965_rx_phy_res
*rx_start
= (include_phy
) ?
3019 (struct iwl4965_rx_phy_res
*)&(pkt
->u
.raw
[0]) : NULL
;
3020 struct ieee80211_hdr
*hdr
;
3023 unsigned int skblen
;
3025 u32 ampdu_status_legacy
;
3027 if (!include_phy
&& priv
->last_phy_res
[0])
3028 rx_start
= (struct iwl4965_rx_phy_res
*)&priv
->last_phy_res
[1];
3031 IWL_ERROR("MPDU frame without a PHY data\n");
3035 hdr
= (struct ieee80211_hdr
*)((u8
*) & rx_start
[1] +
3036 rx_start
->cfg_phy_cnt
);
3038 len
= le16_to_cpu(rx_start
->byte_count
);
3040 rx_end
= (__le32
*) ((u8
*) & pkt
->u
.raw
[0] +
3041 sizeof(struct iwl4965_rx_phy_res
) +
3042 rx_start
->cfg_phy_cnt
+ len
);
3045 struct iwl4965_rx_mpdu_res_start
*amsdu
=
3046 (struct iwl4965_rx_mpdu_res_start
*)pkt
->u
.raw
;
3048 hdr
= (struct ieee80211_hdr
*)(pkt
->u
.raw
+
3049 sizeof(struct iwl4965_rx_mpdu_res_start
));
3050 len
= le16_to_cpu(amsdu
->byte_count
);
3051 rx_start
->byte_count
= amsdu
->byte_count
;
3052 rx_end
= (__le32
*) (((u8
*) hdr
) + len
);
3054 if (len
> priv
->hw_params
.max_pkt_size
|| len
< 16) {
3055 IWL_WARNING("byte count out of range [16,4K] : %d\n", len
);
3059 ampdu_status
= le32_to_cpu(*rx_end
);
3060 skblen
= ((u8
*) rx_end
- (u8
*) & pkt
->u
.raw
[0]) + sizeof(u32
);
3063 /* New status scheme, need to translate */
3064 ampdu_status_legacy
= ampdu_status
;
3065 ampdu_status
= iwl4965_translate_rx_status(ampdu_status
);
3068 /* start from MAC */
3069 skb_reserve(rxb
->skb
, (void *)hdr
- (void *)pkt
);
3070 skb_put(rxb
->skb
, len
); /* end where data ends */
3072 /* We only process data packets if the interface is open */
3073 if (unlikely(!priv
->is_open
)) {
3074 IWL_DEBUG_DROP_LIMIT
3075 ("Dropping packet while interface is not open.\n");
3080 hdr
= (struct ieee80211_hdr
*)rxb
->skb
->data
;
3082 /* in case of HW accelerated crypto and bad decryption, drop */
3083 if (!priv
->hw_params
.sw_crypto
&&
3084 iwl4965_set_decrypted_flag(priv
, hdr
, ampdu_status
, stats
))
3087 if (priv
->add_radiotap
)
3088 iwl4965_add_radiotap(priv
, rxb
->skb
, rx_start
, stats
, ampdu_status
);
3090 iwl_update_rx_stats(priv
, le16_to_cpu(hdr
->frame_control
), len
);
3091 ieee80211_rx_irqsafe(priv
->hw
, rxb
->skb
, stats
);
3092 priv
->alloc_rxb_skb
--;
3096 /* Calc max signal level (dBm) among 3 possible receivers */
3097 static int iwl4965_calc_rssi(struct iwl4965_rx_phy_res
*rx_resp
)
3099 /* data from PHY/DSP regarding signal strength, etc.,
3100 * contents are always there, not configurable by host. */
3101 struct iwl4965_rx_non_cfg_phy
*ncphy
=
3102 (struct iwl4965_rx_non_cfg_phy
*)rx_resp
->non_cfg_phy
;
3103 u32 agc
= (le16_to_cpu(ncphy
->agc_info
) & IWL_AGC_DB_MASK
)
3106 u32 valid_antennae
=
3107 (le16_to_cpu(rx_resp
->phy_flags
) & RX_PHY_FLAGS_ANTENNAE_MASK
)
3108 >> RX_PHY_FLAGS_ANTENNAE_OFFSET
;
3112 /* Find max rssi among 3 possible receivers.
3113 * These values are measured by the digital signal processor (DSP).
3114 * They should stay fairly constant even as the signal strength varies,
3115 * if the radio's automatic gain control (AGC) is working right.
3116 * AGC value (see below) will provide the "interesting" info. */
3117 for (i
= 0; i
< 3; i
++)
3118 if (valid_antennae
& (1 << i
))
3119 max_rssi
= max(ncphy
->rssi_info
[i
<< 1], max_rssi
);
3121 IWL_DEBUG_STATS("Rssi In A %d B %d C %d Max %d AGC dB %d\n",
3122 ncphy
->rssi_info
[0], ncphy
->rssi_info
[2], ncphy
->rssi_info
[4],
3125 /* dBm = max_rssi dB - agc dB - constant.
3126 * Higher AGC (higher radio gain) means lower signal. */
3127 return (max_rssi
- agc
- IWL_RSSI_OFFSET
);
3130 #ifdef CONFIG_IWL4965_HT
3132 void iwl4965_init_ht_hw_capab(const struct iwl_priv
*priv
,
3133 struct ieee80211_ht_info
*ht_info
,
3134 enum ieee80211_band band
)
3137 memset(ht_info
->supp_mcs_set
, 0, 16);
3139 ht_info
->ht_supported
= 1;
3141 if (priv
->hw_params
.fat_channel
& BIT(band
)) {
3142 ht_info
->cap
|= (u16
)IEEE80211_HT_CAP_SUP_WIDTH
;
3143 ht_info
->cap
|= (u16
)IEEE80211_HT_CAP_SGI_40
;
3144 ht_info
->supp_mcs_set
[4] = 0x01;
3146 ht_info
->cap
|= (u16
)IEEE80211_HT_CAP_GRN_FLD
;
3147 ht_info
->cap
|= (u16
)IEEE80211_HT_CAP_SGI_20
;
3148 ht_info
->cap
|= (u16
)(IEEE80211_HT_CAP_MIMO_PS
&
3149 (IWL_MIMO_PS_NONE
<< 2));
3151 if (priv
->cfg
->mod_params
->amsdu_size_8K
)
3152 ht_info
->cap
|= (u16
)IEEE80211_HT_CAP_MAX_AMSDU
;
3154 ht_info
->ampdu_factor
= CFG_HT_RX_AMPDU_FACTOR_DEF
;
3155 ht_info
->ampdu_density
= CFG_HT_MPDU_DENSITY_DEF
;
3157 ht_info
->supp_mcs_set
[0] = 0xFF;
3158 if (priv
->hw_params
.tx_chains_num
>= 2)
3159 ht_info
->supp_mcs_set
[1] = 0xFF;
3160 if (priv
->hw_params
.tx_chains_num
>= 3)
3161 ht_info
->supp_mcs_set
[2] = 0xFF;
3163 #endif /* CONFIG_IWL4965_HT */
3165 static void iwl4965_sta_modify_ps_wake(struct iwl_priv
*priv
, int sta_id
)
3167 unsigned long flags
;
3169 spin_lock_irqsave(&priv
->sta_lock
, flags
);
3170 priv
->stations
[sta_id
].sta
.station_flags
&= ~STA_FLG_PWR_SAVE_MSK
;
3171 priv
->stations
[sta_id
].sta
.station_flags_msk
= STA_FLG_PWR_SAVE_MSK
;
3172 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= 0;
3173 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
3174 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
3176 iwl4965_send_add_station(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
3179 static void iwl4965_update_ps_mode(struct iwl_priv
*priv
, u16 ps_bit
, u8
*addr
)
3181 /* FIXME: need locking over ps_status ??? */
3182 u8 sta_id
= iwl_find_station(priv
, addr
);
3184 if (sta_id
!= IWL_INVALID_STATION
) {
3185 u8 sta_awake
= priv
->stations
[sta_id
].
3186 ps_status
== STA_PS_STATUS_WAKE
;
3188 if (sta_awake
&& ps_bit
)
3189 priv
->stations
[sta_id
].ps_status
= STA_PS_STATUS_SLEEP
;
3190 else if (!sta_awake
&& !ps_bit
) {
3191 iwl4965_sta_modify_ps_wake(priv
, sta_id
);
3192 priv
->stations
[sta_id
].ps_status
= STA_PS_STATUS_WAKE
;
3196 #ifdef CONFIG_IWLWIFI_DEBUG
3199 * iwl4965_dbg_report_frame - dump frame to syslog during debug sessions
3201 * You may hack this function to show different aspects of received frames,
3202 * including selective frame dumps.
3203 * group100 parameter selects whether to show 1 out of 100 good frames.
3205 * TODO: This was originally written for 3945, need to audit for
3206 * proper operation with 4965.
3208 static void iwl4965_dbg_report_frame(struct iwl_priv
*priv
,
3209 struct iwl4965_rx_packet
*pkt
,
3210 struct ieee80211_hdr
*header
, int group100
)
3213 u32 print_summary
= 0;
3214 u32 print_dump
= 0; /* set to 1 to dump all frames' contents */
3231 struct iwl4965_rx_frame_stats
*rx_stats
= IWL_RX_STATS(pkt
);
3232 struct iwl4965_rx_frame_hdr
*rx_hdr
= IWL_RX_HDR(pkt
);
3233 struct iwl4965_rx_frame_end
*rx_end
= IWL_RX_END(pkt
);
3234 u8
*data
= IWL_RX_DATA(pkt
);
3236 if (likely(!(iwl_debug_level
& IWL_DL_RX
)))
3240 fc
= le16_to_cpu(header
->frame_control
);
3241 seq_ctl
= le16_to_cpu(header
->seq_ctrl
);
3244 channel
= le16_to_cpu(rx_hdr
->channel
);
3245 phy_flags
= le16_to_cpu(rx_hdr
->phy_flags
);
3246 rate_sym
= rx_hdr
->rate
;
3247 length
= le16_to_cpu(rx_hdr
->len
);
3249 /* end-of-frame status and timestamp */
3250 status
= le32_to_cpu(rx_end
->status
);
3251 bcn_tmr
= le32_to_cpu(rx_end
->beacon_timestamp
);
3252 tsf_low
= le64_to_cpu(rx_end
->timestamp
) & 0x0ffffffff;
3253 tsf
= le64_to_cpu(rx_end
->timestamp
);
3255 /* signal statistics */
3256 rssi
= rx_stats
->rssi
;
3257 agc
= rx_stats
->agc
;
3258 sig_avg
= le16_to_cpu(rx_stats
->sig_avg
);
3259 noise_diff
= le16_to_cpu(rx_stats
->noise_diff
);
3261 to_us
= !compare_ether_addr(header
->addr1
, priv
->mac_addr
);
3263 /* if data frame is to us and all is good,
3264 * (optionally) print summary for only 1 out of every 100 */
3265 if (to_us
&& (fc
& ~IEEE80211_FCTL_PROTECTED
) ==
3266 (IEEE80211_FCTL_FROMDS
| IEEE80211_FTYPE_DATA
)) {
3269 print_summary
= 1; /* print each frame */
3270 else if (priv
->framecnt_to_us
< 100) {
3271 priv
->framecnt_to_us
++;
3274 priv
->framecnt_to_us
= 0;
3279 /* print summary for all other frames */
3283 if (print_summary
) {
3289 title
= "100Frames";
3290 else if (fc
& IEEE80211_FCTL_RETRY
)
3292 else if (ieee80211_is_assoc_response(fc
))
3294 else if (ieee80211_is_reassoc_response(fc
))
3296 else if (ieee80211_is_probe_response(fc
)) {
3298 print_dump
= 1; /* dump frame contents */
3299 } else if (ieee80211_is_beacon(fc
)) {
3301 print_dump
= 1; /* dump frame contents */
3302 } else if (ieee80211_is_atim(fc
))
3304 else if (ieee80211_is_auth(fc
))
3306 else if (ieee80211_is_deauth(fc
))
3308 else if (ieee80211_is_disassoc(fc
))
3313 rate_idx
= iwl4965_hwrate_to_plcp_idx(rate_sym
);
3314 if (unlikely(rate_idx
== -1))
3317 bitrate
= iwl4965_rates
[rate_idx
].ieee
/ 2;
3319 /* print frame summary.
3320 * MAC addresses show just the last byte (for brevity),
3321 * but you can hack it to show more, if you'd like to. */
3323 IWL_DEBUG_RX("%s: mhd=0x%04x, dst=0x%02x, "
3324 "len=%u, rssi=%d, chnl=%d, rate=%u, \n",
3325 title
, fc
, header
->addr1
[5],
3326 length
, rssi
, channel
, bitrate
);
3328 /* src/dst addresses assume managed mode */
3329 IWL_DEBUG_RX("%s: 0x%04x, dst=0x%02x, "
3330 "src=0x%02x, rssi=%u, tim=%lu usec, "
3331 "phy=0x%02x, chnl=%d\n",
3332 title
, fc
, header
->addr1
[5],
3333 header
->addr3
[5], rssi
,
3334 tsf_low
- priv
->scan_start_tsf
,
3335 phy_flags
, channel
);
3339 iwl_print_hex_dump(IWL_DL_RX
, data
, length
);
3342 static inline void iwl4965_dbg_report_frame(struct iwl_priv
*priv
,
3343 struct iwl4965_rx_packet
*pkt
,
3344 struct ieee80211_hdr
*header
,
3352 /* Called for REPLY_RX (legacy ABG frames), or
3353 * REPLY_RX_MPDU_CMD (HT high-throughput N frames). */
3354 static void iwl4965_rx_reply_rx(struct iwl_priv
*priv
,
3355 struct iwl4965_rx_mem_buffer
*rxb
)
3357 struct ieee80211_hdr
*header
;
3358 struct ieee80211_rx_status rx_status
;
3359 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3360 /* Use phy data (Rx signal strength, etc.) contained within
3361 * this rx packet for legacy frames,
3362 * or phy data cached from REPLY_RX_PHY_CMD for HT frames. */
3363 int include_phy
= (pkt
->hdr
.cmd
== REPLY_RX
);
3364 struct iwl4965_rx_phy_res
*rx_start
= (include_phy
) ?
3365 (struct iwl4965_rx_phy_res
*)&(pkt
->u
.raw
[0]) :
3366 (struct iwl4965_rx_phy_res
*)&priv
->last_phy_res
[1];
3368 unsigned int len
= 0;
3372 rx_status
.mactime
= le64_to_cpu(rx_start
->timestamp
);
3374 ieee80211_frequency_to_channel(le16_to_cpu(rx_start
->channel
));
3375 rx_status
.band
= (rx_start
->phy_flags
& RX_RES_PHY_FLAGS_BAND_24_MSK
) ?
3376 IEEE80211_BAND_2GHZ
: IEEE80211_BAND_5GHZ
;
3377 rx_status
.rate_idx
=
3378 iwl4965_hwrate_to_plcp_idx(le32_to_cpu(rx_start
->rate_n_flags
));
3379 if (rx_status
.band
== IEEE80211_BAND_5GHZ
)
3380 rx_status
.rate_idx
-= IWL_FIRST_OFDM_RATE
;
3382 rx_status
.antenna
= 0;
3385 if ((unlikely(rx_start
->cfg_phy_cnt
> 20))) {
3386 IWL_DEBUG_DROP("dsp size out of range [0,20]: %d/n",
3387 rx_start
->cfg_phy_cnt
);
3392 if (priv
->last_phy_res
[0])
3393 rx_start
= (struct iwl4965_rx_phy_res
*)
3394 &priv
->last_phy_res
[1];
3400 IWL_ERROR("MPDU frame without a PHY data\n");
3405 header
= (struct ieee80211_hdr
*)((u8
*) & rx_start
[1]
3406 + rx_start
->cfg_phy_cnt
);
3408 len
= le16_to_cpu(rx_start
->byte_count
);
3409 rx_end
= (__le32
*)(pkt
->u
.raw
+ rx_start
->cfg_phy_cnt
+
3410 sizeof(struct iwl4965_rx_phy_res
) + len
);
3412 struct iwl4965_rx_mpdu_res_start
*amsdu
=
3413 (struct iwl4965_rx_mpdu_res_start
*)pkt
->u
.raw
;
3415 header
= (void *)(pkt
->u
.raw
+
3416 sizeof(struct iwl4965_rx_mpdu_res_start
));
3417 len
= le16_to_cpu(amsdu
->byte_count
);
3418 rx_end
= (__le32
*) (pkt
->u
.raw
+
3419 sizeof(struct iwl4965_rx_mpdu_res_start
) + len
);
3422 if (!(*rx_end
& RX_RES_STATUS_NO_CRC32_ERROR
) ||
3423 !(*rx_end
& RX_RES_STATUS_NO_RXE_OVERFLOW
)) {
3424 IWL_DEBUG_RX("Bad CRC or FIFO: 0x%08X.\n",
3425 le32_to_cpu(*rx_end
));
3429 priv
->ucode_beacon_time
= le32_to_cpu(rx_start
->beacon_time_stamp
);
3431 /* Find max signal strength (dBm) among 3 antenna/receiver chains */
3432 rx_status
.ssi
= iwl4965_calc_rssi(rx_start
);
3434 /* Meaningful noise values are available only from beacon statistics,
3435 * which are gathered only when associated, and indicate noise
3436 * only for the associated network channel ...
3437 * Ignore these noise values while scanning (other channels) */
3438 if (iwl_is_associated(priv
) &&
3439 !test_bit(STATUS_SCANNING
, &priv
->status
)) {
3440 rx_status
.noise
= priv
->last_rx_noise
;
3441 rx_status
.signal
= iwl4965_calc_sig_qual(rx_status
.ssi
,
3444 rx_status
.noise
= IWL_NOISE_MEAS_NOT_AVAILABLE
;
3445 rx_status
.signal
= iwl4965_calc_sig_qual(rx_status
.ssi
, 0);
3448 /* Reset beacon noise level if not associated. */
3449 if (!iwl_is_associated(priv
))
3450 priv
->last_rx_noise
= IWL_NOISE_MEAS_NOT_AVAILABLE
;
3452 /* Set "1" to report good data frames in groups of 100 */
3453 /* FIXME: need to optimze the call: */
3454 iwl4965_dbg_report_frame(priv
, pkt
, header
, 1);
3456 IWL_DEBUG_STATS_LIMIT("Rssi %d, noise %d, qual %d, TSF %llu\n",
3457 rx_status
.ssi
, rx_status
.noise
, rx_status
.signal
,
3458 (unsigned long long)rx_status
.mactime
);
3460 network_packet
= iwl4965_is_network_packet(priv
, header
);
3461 if (network_packet
) {
3462 priv
->last_rx_rssi
= rx_status
.ssi
;
3463 priv
->last_beacon_time
= priv
->ucode_beacon_time
;
3464 priv
->last_tsf
= le64_to_cpu(rx_start
->timestamp
);
3467 fc
= le16_to_cpu(header
->frame_control
);
3468 switch (fc
& IEEE80211_FCTL_FTYPE
) {
3469 case IEEE80211_FTYPE_MGMT
:
3470 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
3471 iwl4965_update_ps_mode(priv
, fc
& IEEE80211_FCTL_PM
,
3473 iwl4965_handle_data_packet(priv
, 0, include_phy
, rxb
, &rx_status
);
3476 case IEEE80211_FTYPE_CTL
:
3477 #ifdef CONFIG_IWL4965_HT
3478 switch (fc
& IEEE80211_FCTL_STYPE
) {
3479 case IEEE80211_STYPE_BACK_REQ
:
3480 IWL_DEBUG_HT("IEEE80211_STYPE_BACK_REQ arrived\n");
3481 iwl4965_handle_data_packet(priv
, 0, include_phy
,
3490 case IEEE80211_FTYPE_DATA
: {
3491 DECLARE_MAC_BUF(mac1
);
3492 DECLARE_MAC_BUF(mac2
);
3493 DECLARE_MAC_BUF(mac3
);
3495 if (priv
->iw_mode
== IEEE80211_IF_TYPE_AP
)
3496 iwl4965_update_ps_mode(priv
, fc
& IEEE80211_FCTL_PM
,
3499 if (unlikely(!network_packet
))
3500 IWL_DEBUG_DROP("Dropping (non network): "
3502 print_mac(mac1
, header
->addr1
),
3503 print_mac(mac2
, header
->addr2
),
3504 print_mac(mac3
, header
->addr3
));
3505 else if (unlikely(iwl4965_is_duplicate_packet(priv
, header
)))
3506 IWL_DEBUG_DROP("Dropping (dup): %s, %s, %s\n",
3507 print_mac(mac1
, header
->addr1
),
3508 print_mac(mac2
, header
->addr2
),
3509 print_mac(mac3
, header
->addr3
));
3511 iwl4965_handle_data_packet(priv
, 1, include_phy
, rxb
,
3521 /* Cache phy data (Rx signal strength, etc) for HT frame (REPLY_RX_PHY_CMD).
3522 * This will be used later in iwl4965_rx_reply_rx() for REPLY_RX_MPDU_CMD. */
3523 static void iwl4965_rx_reply_rx_phy(struct iwl_priv
*priv
,
3524 struct iwl4965_rx_mem_buffer
*rxb
)
3526 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3527 priv
->last_phy_res
[0] = 1;
3528 memcpy(&priv
->last_phy_res
[1], &(pkt
->u
.raw
[0]),
3529 sizeof(struct iwl4965_rx_phy_res
));
3531 static void iwl4965_rx_missed_beacon_notif(struct iwl_priv
*priv
,
3532 struct iwl4965_rx_mem_buffer
*rxb
)
3535 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
3536 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3537 struct iwl4965_missed_beacon_notif
*missed_beacon
;
3539 missed_beacon
= &pkt
->u
.missed_beacon
;
3540 if (le32_to_cpu(missed_beacon
->consequtive_missed_beacons
) > 5) {
3541 IWL_DEBUG_CALIB("missed bcn cnsq %d totl %d rcd %d expctd %d\n",
3542 le32_to_cpu(missed_beacon
->consequtive_missed_beacons
),
3543 le32_to_cpu(missed_beacon
->total_missed_becons
),
3544 le32_to_cpu(missed_beacon
->num_recvd_beacons
),
3545 le32_to_cpu(missed_beacon
->num_expected_beacons
));
3546 if (!test_bit(STATUS_SCANNING
, &priv
->status
))
3547 iwl_init_sensitivity(priv
);
3549 #endif /*CONFIG_IWL4965_RUN_TIME_CALIB*/
3551 #ifdef CONFIG_IWL4965_HT
3554 * iwl4965_sta_modify_enable_tid_tx - Enable Tx for this TID in station table
3556 static void iwl4965_sta_modify_enable_tid_tx(struct iwl_priv
*priv
,
3557 int sta_id
, int tid
)
3559 unsigned long flags
;
3561 /* Remove "disable" flag, to enable Tx for this TID */
3562 spin_lock_irqsave(&priv
->sta_lock
, flags
);
3563 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_TID_DISABLE_TX
;
3564 priv
->stations
[sta_id
].sta
.tid_disable_tx
&= cpu_to_le16(~(1 << tid
));
3565 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
3566 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
3568 iwl4965_send_add_station(priv
, &priv
->stations
[sta_id
].sta
, CMD_ASYNC
);
3572 * iwl4965_tx_status_reply_compressed_ba - Update tx status from block-ack
3574 * Go through block-ack's bitmap of ACK'd frames, update driver's record of
3575 * ACK vs. not. This gets sent to mac80211, then to rate scaling algo.
3577 static int iwl4965_tx_status_reply_compressed_ba(struct iwl_priv
*priv
,
3578 struct iwl4965_ht_agg
*agg
,
3579 struct iwl4965_compressed_ba_resp
*
3584 u16 seq_ctl
= le16_to_cpu(ba_resp
->seq_ctl
);
3585 u16 scd_flow
= le16_to_cpu(ba_resp
->scd_flow
);
3588 struct ieee80211_tx_status
*tx_status
;
3590 if (unlikely(!agg
->wait_for_ba
)) {
3591 IWL_ERROR("Received BA when not expected\n");
3595 /* Mark that the expected block-ack response arrived */
3596 agg
->wait_for_ba
= 0;
3597 IWL_DEBUG_TX_REPLY("BA %d %d\n", agg
->start_idx
, ba_resp
->seq_ctl
);
3599 /* Calculate shift to align block-ack bits with our Tx window bits */
3600 sh
= agg
->start_idx
- SEQ_TO_INDEX(seq_ctl
>>4);
3601 if (sh
< 0) /* tbw something is wrong with indices */
3604 /* don't use 64-bit values for now */
3605 bitmap
= le64_to_cpu(ba_resp
->bitmap
) >> sh
;
3607 if (agg
->frame_count
> (64 - sh
)) {
3608 IWL_DEBUG_TX_REPLY("more frames than bitmap size");
3612 /* check for success or failure according to the
3613 * transmitted bitmap and block-ack bitmap */
3614 bitmap
&= agg
->bitmap
;
3616 /* For each frame attempted in aggregation,
3617 * update driver's record of tx frame's status. */
3618 for (i
= 0; i
< agg
->frame_count
; i
++) {
3619 ack
= bitmap
& (1 << i
);
3621 IWL_DEBUG_TX_REPLY("%s ON i=%d idx=%d raw=%d\n",
3622 ack
? "ACK":"NACK", i
, (agg
->start_idx
+ i
) & 0xff,
3623 agg
->start_idx
+ i
);
3626 tx_status
= &priv
->txq
[scd_flow
].txb
[agg
->start_idx
].status
;
3627 tx_status
->flags
= IEEE80211_TX_STATUS_ACK
;
3628 tx_status
->flags
|= IEEE80211_TX_STATUS_AMPDU
;
3629 tx_status
->ampdu_ack_map
= successes
;
3630 tx_status
->ampdu_ack_len
= agg
->frame_count
;
3631 iwl4965_hwrate_to_tx_control(priv
, agg
->rate_n_flags
,
3632 &tx_status
->control
);
3634 IWL_DEBUG_TX_REPLY("Bitmap %llx\n", (unsigned long long)bitmap
);
3640 * iwl4965_tx_queue_stop_scheduler - Stop queue, but keep configuration
3642 static void iwl4965_tx_queue_stop_scheduler(struct iwl_priv
*priv
,
3645 /* Simply stop the queue, but don't change any configuration;
3646 * the SCD_ACT_EN bit is the write-enable mask for the ACTIVE bit. */
3647 iwl_write_prph(priv
,
3648 IWL49_SCD_QUEUE_STATUS_BITS(txq_id
),
3649 (0 << SCD_QUEUE_STTS_REG_POS_ACTIVE
)|
3650 (1 << SCD_QUEUE_STTS_REG_POS_SCD_ACT_EN
));
3654 * txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID
3655 * priv->lock must be held by the caller
3657 static int iwl4965_tx_queue_agg_disable(struct iwl_priv
*priv
, u16 txq_id
,
3658 u16 ssn_idx
, u8 tx_fifo
)
3662 if (IWL_BACK_QUEUE_FIRST_ID
> txq_id
) {
3663 IWL_WARNING("queue number too small: %d, must be > %d\n",
3664 txq_id
, IWL_BACK_QUEUE_FIRST_ID
);
3668 ret
= iwl_grab_nic_access(priv
);
3672 iwl4965_tx_queue_stop_scheduler(priv
, txq_id
);
3674 iwl_clear_bits_prph(priv
, IWL49_SCD_QUEUECHAIN_SEL
, (1 << txq_id
));
3676 priv
->txq
[txq_id
].q
.read_ptr
= (ssn_idx
& 0xff);
3677 priv
->txq
[txq_id
].q
.write_ptr
= (ssn_idx
& 0xff);
3678 /* supposes that ssn_idx is valid (!= 0xFFF) */
3679 iwl4965_set_wr_ptrs(priv
, txq_id
, ssn_idx
);
3681 iwl_clear_bits_prph(priv
, IWL49_SCD_INTERRUPT_MASK
, (1 << txq_id
));
3682 iwl4965_txq_ctx_deactivate(priv
, txq_id
);
3683 iwl4965_tx_queue_set_status(priv
, &priv
->txq
[txq_id
], tx_fifo
, 0);
3685 iwl_release_nic_access(priv
);
3690 int iwl4965_check_empty_hw_queue(struct iwl_priv
*priv
, int sta_id
,
3693 struct iwl4965_queue
*q
= &priv
->txq
[txq_id
].q
;
3694 u8
*addr
= priv
->stations
[sta_id
].sta
.sta
.addr
;
3695 struct iwl4965_tid_data
*tid_data
= &priv
->stations
[sta_id
].tid
[tid
];
3697 switch (priv
->stations
[sta_id
].tid
[tid
].agg
.state
) {
3698 case IWL_EMPTYING_HW_QUEUE_DELBA
:
3699 /* We are reclaiming the last packet of the */
3700 /* aggregated HW queue */
3701 if (txq_id
== tid_data
->agg
.txq_id
&&
3702 q
->read_ptr
== q
->write_ptr
) {
3703 u16 ssn
= SEQ_TO_SN(tid_data
->seq_number
);
3704 int tx_fifo
= default_tid_to_tx_fifo
[tid
];
3705 IWL_DEBUG_HT("HW queue empty: continue DELBA flow\n");
3706 iwl4965_tx_queue_agg_disable(priv
, txq_id
,
3708 tid_data
->agg
.state
= IWL_AGG_OFF
;
3709 ieee80211_stop_tx_ba_cb_irqsafe(priv
->hw
, addr
, tid
);
3712 case IWL_EMPTYING_HW_QUEUE_ADDBA
:
3713 /* We are reclaiming the last packet of the queue */
3714 if (tid_data
->tfds_in_queue
== 0) {
3715 IWL_DEBUG_HT("HW queue empty: continue ADDBA flow\n");
3716 tid_data
->agg
.state
= IWL_AGG_ON
;
3717 ieee80211_start_tx_ba_cb_irqsafe(priv
->hw
, addr
, tid
);
3725 * iwl4965_queue_dec_wrap - Decrement queue index, wrap back to end if needed
3726 * @index -- current index
3727 * @n_bd -- total number of entries in queue (s/b power of 2)
3729 static inline int iwl4965_queue_dec_wrap(int index
, int n_bd
)
3731 return (index
== 0) ? n_bd
- 1 : index
- 1;
3735 * iwl4965_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA
3737 * Handles block-acknowledge notification from device, which reports success
3738 * of frames sent via aggregation.
3740 static void iwl4965_rx_reply_compressed_ba(struct iwl_priv
*priv
,
3741 struct iwl4965_rx_mem_buffer
*rxb
)
3743 struct iwl4965_rx_packet
*pkt
= (void *)rxb
->skb
->data
;
3744 struct iwl4965_compressed_ba_resp
*ba_resp
= &pkt
->u
.compressed_ba
;
3746 struct iwl4965_tx_queue
*txq
= NULL
;
3747 struct iwl4965_ht_agg
*agg
;
3748 DECLARE_MAC_BUF(mac
);
3750 /* "flow" corresponds to Tx queue */
3751 u16 scd_flow
= le16_to_cpu(ba_resp
->scd_flow
);
3753 /* "ssn" is start of block-ack Tx window, corresponds to index
3754 * (in Tx queue's circular buffer) of first TFD/frame in window */
3755 u16 ba_resp_scd_ssn
= le16_to_cpu(ba_resp
->scd_ssn
);
3757 if (scd_flow
>= priv
->hw_params
.max_txq_num
) {
3758 IWL_ERROR("BUG_ON scd_flow is bigger than number of queues");
3762 txq
= &priv
->txq
[scd_flow
];
3763 agg
= &priv
->stations
[ba_resp
->sta_id
].tid
[ba_resp
->tid
].agg
;
3765 /* Find index just before block-ack window */
3766 index
= iwl4965_queue_dec_wrap(ba_resp_scd_ssn
& 0xff, txq
->q
.n_bd
);
3768 /* TODO: Need to get this copy more safely - now good for debug */
3770 IWL_DEBUG_TX_REPLY("REPLY_COMPRESSED_BA [%d]Received from %s, "
3773 print_mac(mac
, (u8
*) &ba_resp
->sta_addr_lo32
),
3775 IWL_DEBUG_TX_REPLY("TID = %d, SeqCtl = %d, bitmap = 0x%llx, scd_flow = "
3776 "%d, scd_ssn = %d\n",
3779 (unsigned long long)le64_to_cpu(ba_resp
->bitmap
),
3782 IWL_DEBUG_TX_REPLY("DAT start_idx = %d, bitmap = 0x%llx \n",
3784 (unsigned long long)agg
->bitmap
);
3786 /* Update driver's record of ACK vs. not for each frame in window */
3787 iwl4965_tx_status_reply_compressed_ba(priv
, agg
, ba_resp
);
3789 /* Release all TFDs before the SSN, i.e. all TFDs in front of
3790 * block-ack window (we assume that they've been successfully
3791 * transmitted ... if not, it's too late anyway). */
3792 if (txq
->q
.read_ptr
!= (ba_resp_scd_ssn
& 0xff)) {
3793 int freed
= iwl4965_tx_queue_reclaim(priv
, scd_flow
, index
);
3794 priv
->stations
[ba_resp
->sta_id
].
3795 tid
[ba_resp
->tid
].tfds_in_queue
-= freed
;
3796 if (iwl4965_queue_space(&txq
->q
) > txq
->q
.low_mark
&&
3797 priv
->mac80211_registered
&&
3798 agg
->state
!= IWL_EMPTYING_HW_QUEUE_DELBA
)
3799 ieee80211_wake_queue(priv
->hw
, scd_flow
);
3800 iwl4965_check_empty_hw_queue(priv
, ba_resp
->sta_id
,
3801 ba_resp
->tid
, scd_flow
);
3806 * iwl4965_tx_queue_set_q2ratid - Map unique receiver/tid combination to a queue
3808 static int iwl4965_tx_queue_set_q2ratid(struct iwl_priv
*priv
, u16 ra_tid
,
3815 scd_q2ratid
= ra_tid
& SCD_QUEUE_RA_TID_MAP_RATID_MSK
;
3817 tbl_dw_addr
= priv
->scd_base_addr
+
3818 SCD_TRANSLATE_TBL_OFFSET_QUEUE(txq_id
);
3820 tbl_dw
= iwl_read_targ_mem(priv
, tbl_dw_addr
);
3823 tbl_dw
= (scd_q2ratid
<< 16) | (tbl_dw
& 0x0000FFFF);
3825 tbl_dw
= scd_q2ratid
| (tbl_dw
& 0xFFFF0000);
3827 iwl_write_targ_mem(priv
, tbl_dw_addr
, tbl_dw
);
3834 * iwl4965_tx_queue_agg_enable - Set up & enable aggregation for selected queue
3836 * NOTE: txq_id must be greater than IWL_BACK_QUEUE_FIRST_ID,
3837 * i.e. it must be one of the higher queues used for aggregation
3839 static int iwl4965_tx_queue_agg_enable(struct iwl_priv
*priv
, int txq_id
,
3840 int tx_fifo
, int sta_id
, int tid
,
3843 unsigned long flags
;
3847 if (IWL_BACK_QUEUE_FIRST_ID
> txq_id
)
3848 IWL_WARNING("queue number too small: %d, must be > %d\n",
3849 txq_id
, IWL_BACK_QUEUE_FIRST_ID
);
3851 ra_tid
= BUILD_RAxTID(sta_id
, tid
);
3853 /* Modify device's station table to Tx this TID */
3854 iwl4965_sta_modify_enable_tid_tx(priv
, sta_id
, tid
);
3856 spin_lock_irqsave(&priv
->lock
, flags
);
3857 rc
= iwl_grab_nic_access(priv
);
3859 spin_unlock_irqrestore(&priv
->lock
, flags
);
3863 /* Stop this Tx queue before configuring it */
3864 iwl4965_tx_queue_stop_scheduler(priv
, txq_id
);
3866 /* Map receiver-address / traffic-ID to this queue */
3867 iwl4965_tx_queue_set_q2ratid(priv
, ra_tid
, txq_id
);
3869 /* Set this queue as a chain-building queue */
3870 iwl_set_bits_prph(priv
, IWL49_SCD_QUEUECHAIN_SEL
, (1 << txq_id
));
3872 /* Place first TFD at index corresponding to start sequence number.
3873 * Assumes that ssn_idx is valid (!= 0xFFF) */
3874 priv
->txq
[txq_id
].q
.read_ptr
= (ssn_idx
& 0xff);
3875 priv
->txq
[txq_id
].q
.write_ptr
= (ssn_idx
& 0xff);
3876 iwl4965_set_wr_ptrs(priv
, txq_id
, ssn_idx
);
3878 /* Set up Tx window size and frame limit for this queue */
3879 iwl_write_targ_mem(priv
,
3880 priv
->scd_base_addr
+ SCD_CONTEXT_QUEUE_OFFSET(txq_id
),
3881 (SCD_WIN_SIZE
<< SCD_QUEUE_CTX_REG1_WIN_SIZE_POS
) &
3882 SCD_QUEUE_CTX_REG1_WIN_SIZE_MSK
);
3884 iwl_write_targ_mem(priv
, priv
->scd_base_addr
+
3885 SCD_CONTEXT_QUEUE_OFFSET(txq_id
) + sizeof(u32
),
3886 (SCD_FRAME_LIMIT
<< SCD_QUEUE_CTX_REG2_FRAME_LIMIT_POS
)
3887 & SCD_QUEUE_CTX_REG2_FRAME_LIMIT_MSK
);
3889 iwl_set_bits_prph(priv
, IWL49_SCD_INTERRUPT_MASK
, (1 << txq_id
));
3891 /* Set up Status area in SRAM, map to Tx DMA/FIFO, activate the queue */
3892 iwl4965_tx_queue_set_status(priv
, &priv
->txq
[txq_id
], tx_fifo
, 1);
3894 iwl_release_nic_access(priv
);
3895 spin_unlock_irqrestore(&priv
->lock
, flags
);
3900 #endif /* CONFIG_IWL4965_HT */
3903 * iwl4965_add_station - Initialize a station's hardware rate table
3905 * The uCode's station table contains a table of fallback rates
3906 * for automatic fallback during transmission.
3908 * NOTE: This sets up a default set of values. These will be replaced later
3909 * if the driver's iwl-4965-rs rate scaling algorithm is used, instead of
3912 * NOTE: Run REPLY_ADD_STA command to set up station table entry, before
3913 * calling this function (which runs REPLY_TX_LINK_QUALITY_CMD,
3914 * which requires station table entry to exist).
3916 void iwl4965_add_station(struct iwl_priv
*priv
, const u8
*addr
, int is_ap
)
3919 struct iwl_link_quality_cmd link_cmd
= {
3924 /* Set up the rate scaling to start at selected rate, fall back
3925 * all the way down to 1M in IEEE order, and then spin on 1M */
3927 r
= IWL_RATE_54M_INDEX
;
3928 else if (priv
->band
== IEEE80211_BAND_5GHZ
)
3929 r
= IWL_RATE_6M_INDEX
;
3931 r
= IWL_RATE_1M_INDEX
;
3933 for (i
= 0; i
< LINK_QUAL_MAX_RETRY_NUM
; i
++) {
3935 if (r
>= IWL_FIRST_CCK_RATE
&& r
<= IWL_LAST_CCK_RATE
)
3936 rate_flags
|= RATE_MCS_CCK_MSK
;
3938 /* Use Tx antenna B only */
3939 rate_flags
|= RATE_MCS_ANT_B_MSK
; /*FIXME:RS*/
3941 link_cmd
.rs_table
[i
].rate_n_flags
=
3942 iwl4965_hw_set_rate_n_flags(iwl4965_rates
[r
].plcp
, rate_flags
);
3943 r
= iwl4965_get_prev_ieee_rate(r
);
3946 link_cmd
.general_params
.single_stream_ant_msk
= 2;
3947 link_cmd
.general_params
.dual_stream_ant_msk
= 3;
3948 link_cmd
.agg_params
.agg_dis_start_th
= 3;
3949 link_cmd
.agg_params
.agg_time_limit
= cpu_to_le16(4000);
3951 /* Update the rate scaling for control frame Tx to AP */
3952 link_cmd
.sta_id
= is_ap
? IWL_AP_ID
: priv
->hw_params
.bcast_sta_id
;
3954 iwl_send_cmd_pdu_async(priv
, REPLY_TX_LINK_QUALITY_CMD
,
3955 sizeof(link_cmd
), &link_cmd
, NULL
);
3958 #ifdef CONFIG_IWL4965_HT
3960 static u8
iwl4965_is_channel_extension(struct iwl_priv
*priv
,
3961 enum ieee80211_band band
,
3962 u16 channel
, u8 extension_chan_offset
)
3964 const struct iwl_channel_info
*ch_info
;
3966 ch_info
= iwl_get_channel_info(priv
, band
, channel
);
3967 if (!is_channel_valid(ch_info
))
3970 if (extension_chan_offset
== IWL_EXT_CHANNEL_OFFSET_NONE
)
3973 if ((ch_info
->fat_extension_channel
== extension_chan_offset
) ||
3974 (ch_info
->fat_extension_channel
== HT_IE_EXT_CHANNEL_MAX
))
3980 static u8
iwl4965_is_fat_tx_allowed(struct iwl_priv
*priv
,
3981 struct ieee80211_ht_info
*sta_ht_inf
)
3983 struct iwl_ht_info
*iwl_ht_conf
= &priv
->current_ht_config
;
3985 if ((!iwl_ht_conf
->is_ht
) ||
3986 (iwl_ht_conf
->supported_chan_width
!= IWL_CHANNEL_WIDTH_40MHZ
) ||
3987 (iwl_ht_conf
->extension_chan_offset
== IWL_EXT_CHANNEL_OFFSET_NONE
))
3991 if ((!sta_ht_inf
->ht_supported
) ||
3992 (!(sta_ht_inf
->cap
& IEEE80211_HT_CAP_SUP_WIDTH
)))
3996 return (iwl4965_is_channel_extension(priv
, priv
->band
,
3997 iwl_ht_conf
->control_channel
,
3998 iwl_ht_conf
->extension_chan_offset
));
4001 void iwl4965_set_rxon_ht(struct iwl_priv
*priv
, struct iwl_ht_info
*ht_info
)
4003 struct iwl4965_rxon_cmd
*rxon
= &priv
->staging_rxon
;
4006 if (!ht_info
->is_ht
)
4009 /* Set up channel bandwidth: 20 MHz only, or 20/40 mixed if fat ok */
4010 if (iwl4965_is_fat_tx_allowed(priv
, NULL
))
4011 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_MIXED_MSK
;
4013 rxon
->flags
&= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK
|
4014 RXON_FLG_CHANNEL_MODE_PURE_40_MSK
);
4016 if (le16_to_cpu(rxon
->channel
) != ht_info
->control_channel
) {
4017 IWL_DEBUG_ASSOC("control diff than current %d %d\n",
4018 le16_to_cpu(rxon
->channel
),
4019 ht_info
->control_channel
);
4020 rxon
->channel
= cpu_to_le16(ht_info
->control_channel
);
4024 /* Note: control channel is opposite of extension channel */
4025 switch (ht_info
->extension_chan_offset
) {
4026 case IWL_EXT_CHANNEL_OFFSET_ABOVE
:
4027 rxon
->flags
&= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
);
4029 case IWL_EXT_CHANNEL_OFFSET_BELOW
:
4030 rxon
->flags
|= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
;
4032 case IWL_EXT_CHANNEL_OFFSET_NONE
:
4034 rxon
->flags
&= ~RXON_FLG_CHANNEL_MODE_MIXED_MSK
;
4038 val
= ht_info
->ht_protection
;
4040 rxon
->flags
|= cpu_to_le32(val
<< RXON_FLG_HT_OPERATING_MODE_POS
);
4042 iwl4965_set_rxon_chain(priv
);
4044 IWL_DEBUG_ASSOC("supported HT rate 0x%X 0x%X 0x%X "
4045 "rxon flags 0x%X operation mode :0x%X "
4046 "extension channel offset 0x%x "
4047 "control chan %d\n",
4048 ht_info
->supp_mcs_set
[0],
4049 ht_info
->supp_mcs_set
[1],
4050 ht_info
->supp_mcs_set
[2],
4051 le32_to_cpu(rxon
->flags
), ht_info
->ht_protection
,
4052 ht_info
->extension_chan_offset
,
4053 ht_info
->control_channel
);
4057 void iwl4965_set_ht_add_station(struct iwl_priv
*priv
, u8 index
,
4058 struct ieee80211_ht_info
*sta_ht_inf
)
4063 if (!sta_ht_inf
|| !sta_ht_inf
->ht_supported
)
4066 mimo_ps_mode
= (sta_ht_inf
->cap
& IEEE80211_HT_CAP_MIMO_PS
) >> 2;
4068 sta_flags
= priv
->stations
[index
].sta
.station_flags
;
4070 sta_flags
&= ~(STA_FLG_RTS_MIMO_PROT_MSK
| STA_FLG_MIMO_DIS_MSK
);
4072 switch (mimo_ps_mode
) {
4073 case WLAN_HT_CAP_MIMO_PS_STATIC
:
4074 sta_flags
|= STA_FLG_MIMO_DIS_MSK
;
4076 case WLAN_HT_CAP_MIMO_PS_DYNAMIC
:
4077 sta_flags
|= STA_FLG_RTS_MIMO_PROT_MSK
;
4079 case WLAN_HT_CAP_MIMO_PS_DISABLED
:
4082 IWL_WARNING("Invalid MIMO PS mode %d", mimo_ps_mode
);
4086 sta_flags
|= cpu_to_le32(
4087 (u32
)sta_ht_inf
->ampdu_factor
<< STA_FLG_MAX_AGG_SIZE_POS
);
4089 sta_flags
|= cpu_to_le32(
4090 (u32
)sta_ht_inf
->ampdu_density
<< STA_FLG_AGG_MPDU_DENSITY_POS
);
4092 if (iwl4965_is_fat_tx_allowed(priv
, sta_ht_inf
))
4093 sta_flags
|= STA_FLG_FAT_EN_MSK
;
4095 sta_flags
&= ~STA_FLG_FAT_EN_MSK
;
4097 priv
->stations
[index
].sta
.station_flags
= sta_flags
;
4102 static int iwl4965_rx_agg_start(struct iwl_priv
*priv
,
4103 const u8
*addr
, int tid
, u16 ssn
)
4105 unsigned long flags
;
4108 sta_id
= iwl_find_station(priv
, addr
);
4109 if (sta_id
== IWL_INVALID_STATION
)
4112 spin_lock_irqsave(&priv
->sta_lock
, flags
);
4113 priv
->stations
[sta_id
].sta
.station_flags_msk
= 0;
4114 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_ADDBA_TID_MSK
;
4115 priv
->stations
[sta_id
].sta
.add_immediate_ba_tid
= (u8
)tid
;
4116 priv
->stations
[sta_id
].sta
.add_immediate_ba_ssn
= cpu_to_le16(ssn
);
4117 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
4118 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
4120 return iwl4965_send_add_station(priv
, &priv
->stations
[sta_id
].sta
,
4124 static int iwl4965_rx_agg_stop(struct iwl_priv
*priv
,
4125 const u8
*addr
, int tid
)
4127 unsigned long flags
;
4130 sta_id
= iwl_find_station(priv
, addr
);
4131 if (sta_id
== IWL_INVALID_STATION
)
4134 spin_lock_irqsave(&priv
->sta_lock
, flags
);
4135 priv
->stations
[sta_id
].sta
.station_flags_msk
= 0;
4136 priv
->stations
[sta_id
].sta
.sta
.modify_mask
= STA_MODIFY_DELBA_TID_MSK
;
4137 priv
->stations
[sta_id
].sta
.remove_immediate_ba_tid
= (u8
)tid
;
4138 priv
->stations
[sta_id
].sta
.mode
= STA_CONTROL_MODIFY_MSK
;
4139 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
4141 return iwl4965_send_add_station(priv
, &priv
->stations
[sta_id
].sta
,
4146 * Find first available (lowest unused) Tx Queue, mark it "active".
4147 * Called only when finding queue for aggregation.
4148 * Should never return anything < 7, because they should already
4149 * be in use as EDCA AC (0-3), Command (4), HCCA (5, 6).
4151 static int iwl4965_txq_ctx_activate_free(struct iwl_priv
*priv
)
4155 for (txq_id
= 0; txq_id
< priv
->hw_params
.max_txq_num
; txq_id
++)
4156 if (!test_and_set_bit(txq_id
, &priv
->txq_ctx_active_msk
))
4161 static int iwl4965_tx_agg_start(struct ieee80211_hw
*hw
, const u8
*ra
,
4162 u16 tid
, u16
*start_seq_num
)
4164 struct iwl_priv
*priv
= hw
->priv
;
4170 unsigned long flags
;
4171 struct iwl4965_tid_data
*tid_data
;
4172 DECLARE_MAC_BUF(mac
);
4174 if (likely(tid
< ARRAY_SIZE(default_tid_to_tx_fifo
)))
4175 tx_fifo
= default_tid_to_tx_fifo
[tid
];
4179 IWL_WARNING("%s on ra = %s tid = %d\n",
4180 __func__
, print_mac(mac
, ra
), tid
);
4182 sta_id
= iwl_find_station(priv
, ra
);
4183 if (sta_id
== IWL_INVALID_STATION
)
4186 if (priv
->stations
[sta_id
].tid
[tid
].agg
.state
!= IWL_AGG_OFF
) {
4187 IWL_ERROR("Start AGG when state is not IWL_AGG_OFF !\n");
4191 txq_id
= iwl4965_txq_ctx_activate_free(priv
);
4195 spin_lock_irqsave(&priv
->sta_lock
, flags
);
4196 tid_data
= &priv
->stations
[sta_id
].tid
[tid
];
4197 ssn
= SEQ_TO_SN(tid_data
->seq_number
);
4198 tid_data
->agg
.txq_id
= txq_id
;
4199 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
4201 *start_seq_num
= ssn
;
4202 ret
= iwl4965_tx_queue_agg_enable(priv
, txq_id
, tx_fifo
,
4208 if (tid_data
->tfds_in_queue
== 0) {
4209 printk(KERN_ERR
"HW queue is empty\n");
4210 tid_data
->agg
.state
= IWL_AGG_ON
;
4211 ieee80211_start_tx_ba_cb_irqsafe(hw
, ra
, tid
);
4213 IWL_DEBUG_HT("HW queue is NOT empty: %d packets in HW queue\n",
4214 tid_data
->tfds_in_queue
);
4215 tid_data
->agg
.state
= IWL_EMPTYING_HW_QUEUE_ADDBA
;
4220 static int iwl4965_tx_agg_stop(struct ieee80211_hw
*hw
, const u8
*ra
, u16 tid
)
4222 struct iwl_priv
*priv
= hw
->priv
;
4223 int tx_fifo_id
, txq_id
, sta_id
, ssn
= -1;
4224 struct iwl4965_tid_data
*tid_data
;
4225 int ret
, write_ptr
, read_ptr
;
4226 unsigned long flags
;
4227 DECLARE_MAC_BUF(mac
);
4230 IWL_ERROR("ra = NULL\n");
4234 if (likely(tid
< ARRAY_SIZE(default_tid_to_tx_fifo
)))
4235 tx_fifo_id
= default_tid_to_tx_fifo
[tid
];
4239 sta_id
= iwl_find_station(priv
, ra
);
4241 if (sta_id
== IWL_INVALID_STATION
)
4244 if (priv
->stations
[sta_id
].tid
[tid
].agg
.state
!= IWL_AGG_ON
)
4245 IWL_WARNING("Stopping AGG while state not IWL_AGG_ON\n");
4247 tid_data
= &priv
->stations
[sta_id
].tid
[tid
];
4248 ssn
= (tid_data
->seq_number
& IEEE80211_SCTL_SEQ
) >> 4;
4249 txq_id
= tid_data
->agg
.txq_id
;
4250 write_ptr
= priv
->txq
[txq_id
].q
.write_ptr
;
4251 read_ptr
= priv
->txq
[txq_id
].q
.read_ptr
;
4253 /* The queue is not empty */
4254 if (write_ptr
!= read_ptr
) {
4255 IWL_DEBUG_HT("Stopping a non empty AGG HW QUEUE\n");
4256 priv
->stations
[sta_id
].tid
[tid
].agg
.state
=
4257 IWL_EMPTYING_HW_QUEUE_DELBA
;
4261 IWL_DEBUG_HT("HW queue is empty\n");
4262 priv
->stations
[sta_id
].tid
[tid
].agg
.state
= IWL_AGG_OFF
;
4264 spin_lock_irqsave(&priv
->lock
, flags
);
4265 ret
= iwl4965_tx_queue_agg_disable(priv
, txq_id
, ssn
, tx_fifo_id
);
4266 spin_unlock_irqrestore(&priv
->lock
, flags
);
4271 ieee80211_stop_tx_ba_cb_irqsafe(priv
->hw
, ra
, tid
);
4276 int iwl4965_mac_ampdu_action(struct ieee80211_hw
*hw
,
4277 enum ieee80211_ampdu_mlme_action action
,
4278 const u8
*addr
, u16 tid
, u16
*ssn
)
4280 struct iwl_priv
*priv
= hw
->priv
;
4281 DECLARE_MAC_BUF(mac
);
4283 IWL_DEBUG_HT("A-MPDU action on addr %s tid %d\n",
4284 print_mac(mac
, addr
), tid
);
4287 case IEEE80211_AMPDU_RX_START
:
4288 IWL_DEBUG_HT("start Rx\n");
4289 return iwl4965_rx_agg_start(priv
, addr
, tid
, *ssn
);
4290 case IEEE80211_AMPDU_RX_STOP
:
4291 IWL_DEBUG_HT("stop Rx\n");
4292 return iwl4965_rx_agg_stop(priv
, addr
, tid
);
4293 case IEEE80211_AMPDU_TX_START
:
4294 IWL_DEBUG_HT("start Tx\n");
4295 return iwl4965_tx_agg_start(hw
, addr
, tid
, ssn
);
4296 case IEEE80211_AMPDU_TX_STOP
:
4297 IWL_DEBUG_HT("stop Tx\n");
4298 return iwl4965_tx_agg_stop(hw
, addr
, tid
);
4300 IWL_DEBUG_HT("unknown\n");
4307 #endif /* CONFIG_IWL4965_HT */
4309 /* Set up 4965-specific Rx frame reply handlers */
4310 void iwl4965_hw_rx_handler_setup(struct iwl_priv
*priv
)
4312 /* Legacy Rx frames */
4313 priv
->rx_handlers
[REPLY_RX
] = iwl4965_rx_reply_rx
;
4315 /* High-throughput (HT) Rx frames */
4316 priv
->rx_handlers
[REPLY_RX_PHY_CMD
] = iwl4965_rx_reply_rx_phy
;
4317 priv
->rx_handlers
[REPLY_RX_MPDU_CMD
] = iwl4965_rx_reply_rx
;
4319 priv
->rx_handlers
[MISSED_BEACONS_NOTIFICATION
] =
4320 iwl4965_rx_missed_beacon_notif
;
4322 #ifdef CONFIG_IWL4965_HT
4323 priv
->rx_handlers
[REPLY_COMPRESSED_BA
] = iwl4965_rx_reply_compressed_ba
;
4324 #endif /* CONFIG_IWL4965_HT */
4327 void iwl4965_hw_setup_deferred_work(struct iwl_priv
*priv
)
4329 INIT_WORK(&priv
->txpower_work
, iwl4965_bg_txpower_work
);
4330 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
4331 INIT_WORK(&priv
->sensitivity_work
, iwl4965_bg_sensitivity_work
);
4333 init_timer(&priv
->statistics_periodic
);
4334 priv
->statistics_periodic
.data
= (unsigned long)priv
;
4335 priv
->statistics_periodic
.function
= iwl4965_bg_statistics_periodic
;
4338 void iwl4965_hw_cancel_deferred_work(struct iwl_priv
*priv
)
4340 del_timer_sync(&priv
->statistics_periodic
);
4342 cancel_delayed_work(&priv
->init_alive_start
);
4346 static struct iwl_hcmd_ops iwl4965_hcmd
= {
4347 .rxon_assoc
= iwl4965_send_rxon_assoc
,
4350 static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils
= {
4351 .enqueue_hcmd
= iwl4965_enqueue_hcmd
,
4352 #ifdef CONFIG_IWL4965_RUN_TIME_CALIB
4353 .chain_noise_reset
= iwl4965_chain_noise_reset
,
4354 .gain_computation
= iwl4965_gain_computation
,
4358 static struct iwl_lib_ops iwl4965_lib
= {
4359 .init_drv
= iwl4965_init_drv
,
4360 .set_hw_params
= iwl4965_hw_set_hw_params
,
4361 .alloc_shared_mem
= iwl4965_alloc_shared_mem
,
4362 .free_shared_mem
= iwl4965_free_shared_mem
,
4363 .txq_update_byte_cnt_tbl
= iwl4965_txq_update_byte_cnt_tbl
,
4364 .hw_nic_init
= iwl4965_hw_nic_init
,
4365 .is_valid_rtc_data_addr
= iwl4965_hw_valid_rtc_data_addr
,
4366 .alive_notify
= iwl4965_alive_notify
,
4367 .load_ucode
= iwl4965_load_bsm
,
4369 .init
= iwl4965_apm_init
,
4370 .set_pwr_src
= iwl4965_set_pwr_src
,
4373 .regulatory_bands
= {
4374 EEPROM_REGULATORY_BAND_1_CHANNELS
,
4375 EEPROM_REGULATORY_BAND_2_CHANNELS
,
4376 EEPROM_REGULATORY_BAND_3_CHANNELS
,
4377 EEPROM_REGULATORY_BAND_4_CHANNELS
,
4378 EEPROM_REGULATORY_BAND_5_CHANNELS
,
4379 EEPROM_4965_REGULATORY_BAND_24_FAT_CHANNELS
,
4380 EEPROM_4965_REGULATORY_BAND_52_FAT_CHANNELS
4382 .verify_signature
= iwlcore_eeprom_verify_signature
,
4383 .acquire_semaphore
= iwlcore_eeprom_acquire_semaphore
,
4384 .release_semaphore
= iwlcore_eeprom_release_semaphore
,
4385 .check_version
= iwl4965_eeprom_check_version
,
4386 .query_addr
= iwlcore_eeprom_query_addr
,
4388 .radio_kill_sw
= iwl4965_radio_kill_sw
,
4389 .set_power
= iwl4965_set_power
,
4390 .update_chain_flags
= iwl4965_update_chain_flags
,
4393 static struct iwl_ops iwl4965_ops
= {
4394 .lib
= &iwl4965_lib
,
4395 .hcmd
= &iwl4965_hcmd
,
4396 .utils
= &iwl4965_hcmd_utils
,
4399 struct iwl_cfg iwl4965_agn_cfg
= {
4401 .fw_name
= "iwlwifi-4965" IWL4965_UCODE_API
".ucode",
4402 .sku
= IWL_SKU_A
|IWL_SKU_G
|IWL_SKU_N
,
4403 .eeprom_size
= IWL4965_EEPROM_IMG_SIZE
,
4404 .ops
= &iwl4965_ops
,
4405 .mod_params
= &iwl4965_mod_params
,
4408 module_param_named(antenna
, iwl4965_mod_params
.antenna
, int, 0444);
4409 MODULE_PARM_DESC(antenna
, "select antenna (1=Main, 2=Aux, default 0 [both])");
4410 module_param_named(disable
, iwl4965_mod_params
.disable
, int, 0444);
4411 MODULE_PARM_DESC(disable
, "manually disable the radio (default 0 [radio on])");
4412 module_param_named(swcrypto
, iwl4965_mod_params
.sw_crypto
, int, 0444);
4413 MODULE_PARM_DESC(swcrypto
, "using crypto in software (default 0 [hardware])\n");
4414 module_param_named(debug
, iwl4965_mod_params
.debug
, int, 0444);
4415 MODULE_PARM_DESC(debug
, "debug output mask");
4417 disable_hw_scan
, iwl4965_mod_params
.disable_hw_scan
, int, 0444);
4418 MODULE_PARM_DESC(disable_hw_scan
, "disable hardware scanning (default 0)");
4420 module_param_named(queues_num
, iwl4965_mod_params
.num_of_queues
, int, 0444);
4421 MODULE_PARM_DESC(queues_num
, "number of hw queues.");
4424 module_param_named(qos_enable
, iwl4965_mod_params
.enable_qos
, int, 0444);
4425 MODULE_PARM_DESC(qos_enable
, "enable all QoS functionality");
4426 module_param_named(amsdu_size_8K
, iwl4965_mod_params
.amsdu_size_8K
, int, 0444);
4427 MODULE_PARM_DESC(amsdu_size_8K
, "enable 8K amsdu size");