1 /******************************************************************************
3 * Copyright(c) 2003 - 2011 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 * Intel Linux Wireless <ilw@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/init.h>
30 #include <linux/pci.h>
31 #include <linux/dma-mapping.h>
32 #include <linux/delay.h>
33 #include <linux/sched.h>
34 #include <linux/skbuff.h>
35 #include <linux/netdevice.h>
36 #include <net/mac80211.h>
37 #include <linux/etherdevice.h>
38 #include <asm/unaligned.h>
40 #include "iwl-eeprom.h"
44 #include "iwl-helpers.h"
45 #include "iwl-4965-calib.h"
47 #include "iwl-4965-led.h"
49 #include "iwl-4965-debugfs.h"
51 static int iwl4965_send_tx_power(struct iwl_priv
*priv
);
52 static int iwl4965_hw_get_temperature(struct iwl_priv
*priv
);
54 /* Highest firmware API version supported */
55 #define IWL4965_UCODE_API_MAX 2
57 /* Lowest firmware API version supported */
58 #define IWL4965_UCODE_API_MIN 2
60 #define IWL4965_FW_PRE "iwlwifi-4965-"
61 #define _IWL4965_MODULE_FIRMWARE(api) IWL4965_FW_PRE #api ".ucode"
62 #define IWL4965_MODULE_FIRMWARE(api) _IWL4965_MODULE_FIRMWARE(api)
64 /* check contents of special bootstrap uCode SRAM */
65 static int iwl4965_verify_bsm(struct iwl_priv
*priv
)
67 __le32
*image
= priv
->ucode_boot
.v_addr
;
68 u32 len
= priv
->ucode_boot
.len
;
72 IWL_DEBUG_INFO(priv
, "Begin verify bsm\n");
74 /* verify BSM SRAM contents */
75 val
= iwl_legacy_read_prph(priv
, BSM_WR_DWCOUNT_REG
);
76 for (reg
= BSM_SRAM_LOWER_BOUND
;
77 reg
< BSM_SRAM_LOWER_BOUND
+ len
;
78 reg
+= sizeof(u32
), image
++) {
79 val
= iwl_legacy_read_prph(priv
, reg
);
80 if (val
!= le32_to_cpu(*image
)) {
81 IWL_ERR(priv
, "BSM uCode verification failed at "
82 "addr 0x%08X+%u (of %u), is 0x%x, s/b 0x%x\n",
84 reg
- BSM_SRAM_LOWER_BOUND
, len
,
85 val
, le32_to_cpu(*image
));
90 IWL_DEBUG_INFO(priv
, "BSM bootstrap uCode image OK\n");
96 * iwl4965_load_bsm - Load bootstrap instructions
100 * The Bootstrap State Machine (BSM) stores a short bootstrap uCode program
101 * in special SRAM that does not power down during RFKILL. When powering back
102 * up after power-saving sleeps (or during initial uCode load), the BSM loads
103 * the bootstrap program into the on-board processor, and starts it.
105 * The bootstrap program loads (via DMA) instructions and data for a new
106 * program from host DRAM locations indicated by the host driver in the
107 * BSM_DRAM_* registers. Once the new program is loaded, it starts
110 * When initializing the NIC, the host driver points the BSM to the
111 * "initialize" uCode image. This uCode sets up some internal data, then
112 * notifies host via "initialize alive" that it is complete.
114 * The host then replaces the BSM_DRAM_* pointer values to point to the
115 * normal runtime uCode instructions and a backup uCode data cache buffer
116 * (filled initially with starting data values for the on-board processor),
117 * then triggers the "initialize" uCode to load and launch the runtime uCode,
118 * which begins normal operation.
120 * When doing a power-save shutdown, runtime uCode saves data SRAM into
121 * the backup data cache in DRAM before SRAM is powered down.
123 * When powering back up, the BSM loads the bootstrap program. This reloads
124 * the runtime uCode instructions and the backup data cache into SRAM,
125 * and re-launches the runtime uCode from where it left off.
127 static int iwl4965_load_bsm(struct iwl_priv
*priv
)
129 __le32
*image
= priv
->ucode_boot
.v_addr
;
130 u32 len
= priv
->ucode_boot
.len
;
140 IWL_DEBUG_INFO(priv
, "Begin load bsm\n");
142 priv
->ucode_type
= UCODE_RT
;
144 /* make sure bootstrap program is no larger than BSM's SRAM size */
145 if (len
> IWL49_MAX_BSM_SIZE
)
148 /* Tell bootstrap uCode where to find the "Initialize" uCode
149 * in host DRAM ... host DRAM physical address bits 35:4 for 4965.
150 * NOTE: iwl_init_alive_start() will replace these values,
151 * after the "initialize" uCode has run, to point to
152 * runtime/protocol instructions and backup data cache.
154 pinst
= priv
->ucode_init
.p_addr
>> 4;
155 pdata
= priv
->ucode_init_data
.p_addr
>> 4;
156 inst_len
= priv
->ucode_init
.len
;
157 data_len
= priv
->ucode_init_data
.len
;
159 iwl_legacy_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
160 iwl_legacy_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
161 iwl_legacy_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
, inst_len
);
162 iwl_legacy_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
, data_len
);
164 /* Fill BSM memory with bootstrap instructions */
165 for (reg_offset
= BSM_SRAM_LOWER_BOUND
;
166 reg_offset
< BSM_SRAM_LOWER_BOUND
+ len
;
167 reg_offset
+= sizeof(u32
), image
++)
168 _iwl_legacy_write_prph(priv
, reg_offset
, le32_to_cpu(*image
));
170 ret
= iwl4965_verify_bsm(priv
);
174 /* Tell BSM to copy from BSM SRAM into instruction SRAM, when asked */
175 iwl_legacy_write_prph(priv
, BSM_WR_MEM_SRC_REG
, 0x0);
176 iwl_legacy_write_prph(priv
,
177 BSM_WR_MEM_DST_REG
, IWL49_RTC_INST_LOWER_BOUND
);
178 iwl_legacy_write_prph(priv
, BSM_WR_DWCOUNT_REG
, len
/ sizeof(u32
));
180 /* Load bootstrap code into instruction SRAM now,
181 * to prepare to load "initialize" uCode */
182 iwl_legacy_write_prph(priv
, BSM_WR_CTRL_REG
, BSM_WR_CTRL_REG_BIT_START
);
184 /* Wait for load of bootstrap uCode to finish */
185 for (i
= 0; i
< 100; i
++) {
186 done
= iwl_legacy_read_prph(priv
, BSM_WR_CTRL_REG
);
187 if (!(done
& BSM_WR_CTRL_REG_BIT_START
))
192 IWL_DEBUG_INFO(priv
, "BSM write complete, poll %d iterations\n", i
);
194 IWL_ERR(priv
, "BSM write did not complete!\n");
198 /* Enable future boot loads whenever power management unit triggers it
199 * (e.g. when powering back up after power-save shutdown) */
200 iwl_legacy_write_prph(priv
,
201 BSM_WR_CTRL_REG
, BSM_WR_CTRL_REG_BIT_START_EN
);
208 * iwl4965_set_ucode_ptrs - Set uCode address location
210 * Tell initialization uCode where to find runtime uCode.
212 * BSM registers initially contain pointers to initialization uCode.
213 * We need to replace them to load runtime uCode inst and data,
214 * and to save runtime data when powering down.
216 static int iwl4965_set_ucode_ptrs(struct iwl_priv
*priv
)
222 /* bits 35:4 for 4965 */
223 pinst
= priv
->ucode_code
.p_addr
>> 4;
224 pdata
= priv
->ucode_data_backup
.p_addr
>> 4;
226 /* Tell bootstrap uCode where to find image to load */
227 iwl_legacy_write_prph(priv
, BSM_DRAM_INST_PTR_REG
, pinst
);
228 iwl_legacy_write_prph(priv
, BSM_DRAM_DATA_PTR_REG
, pdata
);
229 iwl_legacy_write_prph(priv
, BSM_DRAM_DATA_BYTECOUNT_REG
,
230 priv
->ucode_data
.len
);
232 /* Inst byte count must be last to set up, bit 31 signals uCode
233 * that all new ptr/size info is in place */
234 iwl_legacy_write_prph(priv
, BSM_DRAM_INST_BYTECOUNT_REG
,
235 priv
->ucode_code
.len
| BSM_DRAM_INST_LOAD
);
236 IWL_DEBUG_INFO(priv
, "Runtime uCode pointers are set.\n");
242 * iwl4965_init_alive_start - Called after REPLY_ALIVE notification received
244 * Called after REPLY_ALIVE notification received from "initialize" uCode.
246 * The 4965 "initialize" ALIVE reply contains calibration data for:
247 * Voltage, temperature, and MIMO tx gain correction, now stored in priv
248 * (3945 does not contain this data).
250 * Tell "initialize" uCode to go ahead and load the runtime uCode.
252 static void iwl4965_init_alive_start(struct iwl_priv
*priv
)
254 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
255 * This is a paranoid check, because we would not have gotten the
256 * "initialize" alive if code weren't properly loaded. */
257 if (iwl4965_verify_ucode(priv
)) {
258 /* Runtime instruction load was bad;
259 * take it all the way back down so we can try again */
260 IWL_DEBUG_INFO(priv
, "Bad \"initialize\" uCode load.\n");
264 /* Calculate temperature */
265 priv
->temperature
= iwl4965_hw_get_temperature(priv
);
267 /* Send pointers to protocol/runtime uCode image ... init code will
268 * load and launch runtime uCode, which will send us another "Alive"
270 IWL_DEBUG_INFO(priv
, "Initialization Alive received.\n");
271 if (iwl4965_set_ucode_ptrs(priv
)) {
272 /* Runtime instruction load won't happen;
273 * take it all the way back down so we can try again */
274 IWL_DEBUG_INFO(priv
, "Couldn't set up uCode pointers.\n");
280 queue_work(priv
->workqueue
, &priv
->restart
);
283 static bool iw4965_is_ht40_channel(__le32 rxon_flags
)
285 int chan_mod
= le32_to_cpu(rxon_flags
& RXON_FLG_CHANNEL_MODE_MSK
)
286 >> RXON_FLG_CHANNEL_MODE_POS
;
287 return ((chan_mod
== CHANNEL_MODE_PURE_40
) ||
288 (chan_mod
== CHANNEL_MODE_MIXED
));
291 static void iwl4965_nic_config(struct iwl_priv
*priv
)
296 spin_lock_irqsave(&priv
->lock
, flags
);
298 radio_cfg
= iwl_legacy_eeprom_query16(priv
, EEPROM_RADIO_CONFIG
);
300 /* write radio config values to register */
301 if (EEPROM_RF_CFG_TYPE_MSK(radio_cfg
) == EEPROM_4965_RF_CFG_TYPE_MAX
)
302 iwl_legacy_set_bit(priv
, CSR_HW_IF_CONFIG_REG
,
303 EEPROM_RF_CFG_TYPE_MSK(radio_cfg
) |
304 EEPROM_RF_CFG_STEP_MSK(radio_cfg
) |
305 EEPROM_RF_CFG_DASH_MSK(radio_cfg
));
307 /* set CSR_HW_CONFIG_REG for uCode use */
308 iwl_legacy_set_bit(priv
, CSR_HW_IF_CONFIG_REG
,
309 CSR_HW_IF_CONFIG_REG_BIT_RADIO_SI
|
310 CSR_HW_IF_CONFIG_REG_BIT_MAC_SI
);
312 priv
->calib_info
= (struct iwl_eeprom_calib_info
*)
313 iwl_legacy_eeprom_query_addr(priv
,
314 EEPROM_4965_CALIB_TXPOWER_OFFSET
);
316 spin_unlock_irqrestore(&priv
->lock
, flags
);
319 /* Reset differential Rx gains in NIC to prepare for chain noise calibration.
320 * Called after every association, but this runs only once!
321 * ... once chain noise is calibrated the first time, it's good forever. */
322 static void iwl4965_chain_noise_reset(struct iwl_priv
*priv
)
324 struct iwl_chain_noise_data
*data
= &(priv
->chain_noise_data
);
326 if ((data
->state
== IWL_CHAIN_NOISE_ALIVE
) &&
327 iwl_legacy_is_any_associated(priv
)) {
328 struct iwl_calib_diff_gain_cmd cmd
;
330 /* clear data for chain noise calibration algorithm */
331 data
->chain_noise_a
= 0;
332 data
->chain_noise_b
= 0;
333 data
->chain_noise_c
= 0;
334 data
->chain_signal_a
= 0;
335 data
->chain_signal_b
= 0;
336 data
->chain_signal_c
= 0;
337 data
->beacon_count
= 0;
339 memset(&cmd
, 0, sizeof(cmd
));
340 cmd
.hdr
.op_code
= IWL_PHY_CALIBRATE_DIFF_GAIN_CMD
;
344 if (iwl_legacy_send_cmd_pdu(priv
, REPLY_PHY_CALIBRATION_CMD
,
347 "Could not send REPLY_PHY_CALIBRATION_CMD\n");
348 data
->state
= IWL_CHAIN_NOISE_ACCUMULATE
;
349 IWL_DEBUG_CALIB(priv
, "Run chain_noise_calibrate\n");
353 static struct iwl_sensitivity_ranges iwl4965_sensitivity
= {
355 .max_nrg_cck
= 0, /* not used, set to 0 */
357 .auto_corr_min_ofdm
= 85,
358 .auto_corr_min_ofdm_mrc
= 170,
359 .auto_corr_min_ofdm_x1
= 105,
360 .auto_corr_min_ofdm_mrc_x1
= 220,
362 .auto_corr_max_ofdm
= 120,
363 .auto_corr_max_ofdm_mrc
= 210,
364 .auto_corr_max_ofdm_x1
= 140,
365 .auto_corr_max_ofdm_mrc_x1
= 270,
367 .auto_corr_min_cck
= 125,
368 .auto_corr_max_cck
= 200,
369 .auto_corr_min_cck_mrc
= 200,
370 .auto_corr_max_cck_mrc
= 400,
375 .barker_corr_th_min
= 190,
376 .barker_corr_th_min_mrc
= 390,
380 static void iwl4965_set_ct_threshold(struct iwl_priv
*priv
)
383 priv
->hw_params
.ct_kill_threshold
=
384 CELSIUS_TO_KELVIN(CT_KILL_THRESHOLD_LEGACY
);
388 * iwl4965_hw_set_hw_params
390 * Called when initializing driver
392 static int iwl4965_hw_set_hw_params(struct iwl_priv
*priv
)
394 if (priv
->cfg
->mod_params
->num_of_queues
>= IWL_MIN_NUM_QUEUES
&&
395 priv
->cfg
->mod_params
->num_of_queues
<= IWL49_NUM_QUEUES
)
396 priv
->cfg
->base_params
->num_of_queues
=
397 priv
->cfg
->mod_params
->num_of_queues
;
399 priv
->hw_params
.max_txq_num
= priv
->cfg
->base_params
->num_of_queues
;
400 priv
->hw_params
.dma_chnl_num
= FH49_TCSR_CHNL_NUM
;
401 priv
->hw_params
.scd_bc_tbls_size
=
402 priv
->cfg
->base_params
->num_of_queues
*
403 sizeof(struct iwl4965_scd_bc_tbl
);
404 priv
->hw_params
.tfd_size
= sizeof(struct iwl_tfd
);
405 priv
->hw_params
.max_stations
= IWL4965_STATION_COUNT
;
406 priv
->contexts
[IWL_RXON_CTX_BSS
].bcast_sta_id
= IWL4965_BROADCAST_ID
;
407 priv
->hw_params
.max_data_size
= IWL49_RTC_DATA_SIZE
;
408 priv
->hw_params
.max_inst_size
= IWL49_RTC_INST_SIZE
;
409 priv
->hw_params
.max_bsm_size
= BSM_SRAM_SIZE
;
410 priv
->hw_params
.ht40_channel
= BIT(IEEE80211_BAND_5GHZ
);
412 priv
->hw_params
.rx_wrt_ptr_reg
= FH_RSCSR_CHNL0_WPTR
;
414 priv
->hw_params
.tx_chains_num
= iwl4965_num_of_ant(priv
->cfg
->valid_tx_ant
);
415 priv
->hw_params
.rx_chains_num
= iwl4965_num_of_ant(priv
->cfg
->valid_rx_ant
);
416 priv
->hw_params
.valid_tx_ant
= priv
->cfg
->valid_tx_ant
;
417 priv
->hw_params
.valid_rx_ant
= priv
->cfg
->valid_rx_ant
;
419 iwl4965_set_ct_threshold(priv
);
421 priv
->hw_params
.sens
= &iwl4965_sensitivity
;
422 priv
->hw_params
.beacon_time_tsf_bits
= IWL4965_EXT_BEACON_TIME_POS
;
427 static s32
iwl4965_math_div_round(s32 num
, s32 denom
, s32
*res
)
440 *res
= ((num
* 2 + denom
) / (denom
* 2)) * sign
;
446 * iwl4965_get_voltage_compensation - Power supply voltage comp for txpower
448 * Determines power supply voltage compensation for txpower calculations.
449 * Returns number of 1/2-dB steps to subtract from gain table index,
450 * to compensate for difference between power supply voltage during
451 * factory measurements, vs. current power supply voltage.
453 * Voltage indication is higher for lower voltage.
454 * Lower voltage requires more gain (lower gain table index).
456 static s32
iwl4965_get_voltage_compensation(s32 eeprom_voltage
,
461 if ((TX_POWER_IWL_ILLEGAL_VOLTAGE
== eeprom_voltage
) ||
462 (TX_POWER_IWL_ILLEGAL_VOLTAGE
== current_voltage
))
465 iwl4965_math_div_round(current_voltage
- eeprom_voltage
,
466 TX_POWER_IWL_VOLTAGE_CODES_PER_03V
, &comp
);
468 if (current_voltage
> eeprom_voltage
)
470 if ((comp
< -2) || (comp
> 2))
476 static s32
iwl4965_get_tx_atten_grp(u16 channel
)
478 if (channel
>= CALIB_IWL_TX_ATTEN_GR5_FCH
&&
479 channel
<= CALIB_IWL_TX_ATTEN_GR5_LCH
)
480 return CALIB_CH_GROUP_5
;
482 if (channel
>= CALIB_IWL_TX_ATTEN_GR1_FCH
&&
483 channel
<= CALIB_IWL_TX_ATTEN_GR1_LCH
)
484 return CALIB_CH_GROUP_1
;
486 if (channel
>= CALIB_IWL_TX_ATTEN_GR2_FCH
&&
487 channel
<= CALIB_IWL_TX_ATTEN_GR2_LCH
)
488 return CALIB_CH_GROUP_2
;
490 if (channel
>= CALIB_IWL_TX_ATTEN_GR3_FCH
&&
491 channel
<= CALIB_IWL_TX_ATTEN_GR3_LCH
)
492 return CALIB_CH_GROUP_3
;
494 if (channel
>= CALIB_IWL_TX_ATTEN_GR4_FCH
&&
495 channel
<= CALIB_IWL_TX_ATTEN_GR4_LCH
)
496 return CALIB_CH_GROUP_4
;
501 static u32
iwl4965_get_sub_band(const struct iwl_priv
*priv
, u32 channel
)
505 for (b
= 0; b
< EEPROM_TX_POWER_BANDS
; b
++) {
506 if (priv
->calib_info
->band_info
[b
].ch_from
== 0)
509 if ((channel
>= priv
->calib_info
->band_info
[b
].ch_from
)
510 && (channel
<= priv
->calib_info
->band_info
[b
].ch_to
))
517 static s32
iwl4965_interpolate_value(s32 x
, s32 x1
, s32 y1
, s32 x2
, s32 y2
)
524 iwl4965_math_div_round((x2
- x
) * (y1
- y2
), (x2
- x1
), &val
);
530 * iwl4965_interpolate_chan - Interpolate factory measurements for one channel
532 * Interpolates factory measurements from the two sample channels within a
533 * sub-band, to apply to channel of interest. Interpolation is proportional to
534 * differences in channel frequencies, which is proportional to differences
537 static int iwl4965_interpolate_chan(struct iwl_priv
*priv
, u32 channel
,
538 struct iwl_eeprom_calib_ch_info
*chan_info
)
543 const struct iwl_eeprom_calib_measure
*m1
;
544 const struct iwl_eeprom_calib_measure
*m2
;
545 struct iwl_eeprom_calib_measure
*omeas
;
549 s
= iwl4965_get_sub_band(priv
, channel
);
550 if (s
>= EEPROM_TX_POWER_BANDS
) {
551 IWL_ERR(priv
, "Tx Power can not find channel %d\n", channel
);
555 ch_i1
= priv
->calib_info
->band_info
[s
].ch1
.ch_num
;
556 ch_i2
= priv
->calib_info
->band_info
[s
].ch2
.ch_num
;
557 chan_info
->ch_num
= (u8
) channel
;
559 IWL_DEBUG_TXPOWER(priv
, "channel %d subband %d factory cal ch %d & %d\n",
560 channel
, s
, ch_i1
, ch_i2
);
562 for (c
= 0; c
< EEPROM_TX_POWER_TX_CHAINS
; c
++) {
563 for (m
= 0; m
< EEPROM_TX_POWER_MEASUREMENTS
; m
++) {
564 m1
= &(priv
->calib_info
->band_info
[s
].ch1
.
566 m2
= &(priv
->calib_info
->band_info
[s
].ch2
.
568 omeas
= &(chan_info
->measurements
[c
][m
]);
571 (u8
) iwl4965_interpolate_value(channel
, ch_i1
,
576 (u8
) iwl4965_interpolate_value(channel
, ch_i1
,
580 (u8
) iwl4965_interpolate_value(channel
, ch_i1
,
585 (s8
) iwl4965_interpolate_value(channel
, ch_i1
,
589 IWL_DEBUG_TXPOWER(priv
,
590 "chain %d meas %d AP1=%d AP2=%d AP=%d\n", c
, m
,
591 m1
->actual_pow
, m2
->actual_pow
, omeas
->actual_pow
);
592 IWL_DEBUG_TXPOWER(priv
,
593 "chain %d meas %d NI1=%d NI2=%d NI=%d\n", c
, m
,
594 m1
->gain_idx
, m2
->gain_idx
, omeas
->gain_idx
);
595 IWL_DEBUG_TXPOWER(priv
,
596 "chain %d meas %d PA1=%d PA2=%d PA=%d\n", c
, m
,
597 m1
->pa_det
, m2
->pa_det
, omeas
->pa_det
);
598 IWL_DEBUG_TXPOWER(priv
,
599 "chain %d meas %d T1=%d T2=%d T=%d\n", c
, m
,
600 m1
->temperature
, m2
->temperature
,
608 /* bit-rate-dependent table to prevent Tx distortion, in half-dB units,
609 * for OFDM 6, 12, 18, 24, 36, 48, 54, 60 MBit, and CCK all rates. */
610 static s32 back_off_table
[] = {
611 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 20 MHz */
612 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 20 MHz */
613 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM SISO 40 MHz */
614 10, 10, 10, 10, 10, 15, 17, 20, /* OFDM MIMO 40 MHz */
618 /* Thermal compensation values for txpower for various frequency ranges ...
619 * ratios from 3:1 to 4.5:1 of degrees (Celsius) per half-dB gain adjust */
620 static struct iwl4965_txpower_comp_entry
{
621 s32 degrees_per_05db_a
;
622 s32 degrees_per_05db_a_denom
;
623 } tx_power_cmp_tble
[CALIB_CH_GROUP_MAX
] = {
624 {9, 2}, /* group 0 5.2, ch 34-43 */
625 {4, 1}, /* group 1 5.2, ch 44-70 */
626 {4, 1}, /* group 2 5.2, ch 71-124 */
627 {4, 1}, /* group 3 5.2, ch 125-200 */
628 {3, 1} /* group 4 2.4, ch all */
631 static s32
get_min_power_index(s32 rate_power_index
, u32 band
)
634 if ((rate_power_index
& 7) <= 4)
635 return MIN_TX_GAIN_INDEX_52GHZ_EXT
;
637 return MIN_TX_GAIN_INDEX
;
645 static const struct gain_entry gain_table
[2][108] = {
646 /* 5.2GHz power gain index table */
648 {123, 0x3F}, /* highest txpower */
757 /* 2.4GHz power gain index table */
759 {110, 0x3f}, /* highest txpower */
870 static int iwl4965_fill_txpower_tbl(struct iwl_priv
*priv
, u8 band
, u16 channel
,
871 u8 is_ht40
, u8 ctrl_chan_high
,
872 struct iwl4965_tx_power_db
*tx_power_tbl
)
876 s32 user_target_power
;
880 s32 current_regulatory
;
881 s32 txatten_grp
= CALIB_CH_GROUP_MAX
;
884 const struct iwl_channel_info
*ch_info
= NULL
;
885 struct iwl_eeprom_calib_ch_info ch_eeprom_info
;
886 const struct iwl_eeprom_calib_measure
*measurement
;
889 s32 voltage_compensation
;
890 s32 degrees_per_05db_num
;
891 s32 degrees_per_05db_denom
;
893 s32 temperature_comp
[2];
894 s32 factory_gain_index
[2];
895 s32 factory_actual_pwr
[2];
898 /* tx_power_user_lmt is in dBm, convert to half-dBm (half-dB units
899 * are used for indexing into txpower table) */
900 user_target_power
= 2 * priv
->tx_power_user_lmt
;
902 /* Get current (RXON) channel, band, width */
903 IWL_DEBUG_TXPOWER(priv
, "chan %d band %d is_ht40 %d\n", channel
, band
,
906 ch_info
= iwl_legacy_get_channel_info(priv
, priv
->band
, channel
);
908 if (!iwl_legacy_is_channel_valid(ch_info
))
911 /* get txatten group, used to select 1) thermal txpower adjustment
912 * and 2) mimo txpower balance between Tx chains. */
913 txatten_grp
= iwl4965_get_tx_atten_grp(channel
);
914 if (txatten_grp
< 0) {
915 IWL_ERR(priv
, "Can't find txatten group for channel %d.\n",
920 IWL_DEBUG_TXPOWER(priv
, "channel %d belongs to txatten group %d\n",
921 channel
, txatten_grp
);
930 /* hardware txpower limits ...
931 * saturation (clipping distortion) txpowers are in half-dBm */
933 saturation_power
= priv
->calib_info
->saturation_power24
;
935 saturation_power
= priv
->calib_info
->saturation_power52
;
937 if (saturation_power
< IWL_TX_POWER_SATURATION_MIN
||
938 saturation_power
> IWL_TX_POWER_SATURATION_MAX
) {
940 saturation_power
= IWL_TX_POWER_DEFAULT_SATURATION_24
;
942 saturation_power
= IWL_TX_POWER_DEFAULT_SATURATION_52
;
945 /* regulatory txpower limits ... reg_limit values are in half-dBm,
946 * max_power_avg values are in dBm, convert * 2 */
948 reg_limit
= ch_info
->ht40_max_power_avg
* 2;
950 reg_limit
= ch_info
->max_power_avg
* 2;
952 if ((reg_limit
< IWL_TX_POWER_REGULATORY_MIN
) ||
953 (reg_limit
> IWL_TX_POWER_REGULATORY_MAX
)) {
955 reg_limit
= IWL_TX_POWER_DEFAULT_REGULATORY_24
;
957 reg_limit
= IWL_TX_POWER_DEFAULT_REGULATORY_52
;
960 /* Interpolate txpower calibration values for this channel,
961 * based on factory calibration tests on spaced channels. */
962 iwl4965_interpolate_chan(priv
, channel
, &ch_eeprom_info
);
964 /* calculate tx gain adjustment based on power supply voltage */
965 voltage
= le16_to_cpu(priv
->calib_info
->voltage
);
966 init_voltage
= (s32
)le32_to_cpu(priv
->card_alive_init
.voltage
);
967 voltage_compensation
=
968 iwl4965_get_voltage_compensation(voltage
, init_voltage
);
970 IWL_DEBUG_TXPOWER(priv
, "curr volt %d eeprom volt %d volt comp %d\n",
972 voltage
, voltage_compensation
);
974 /* get current temperature (Celsius) */
975 current_temp
= max(priv
->temperature
, IWL_TX_POWER_TEMPERATURE_MIN
);
976 current_temp
= min(priv
->temperature
, IWL_TX_POWER_TEMPERATURE_MAX
);
977 current_temp
= KELVIN_TO_CELSIUS(current_temp
);
979 /* select thermal txpower adjustment params, based on channel group
980 * (same frequency group used for mimo txatten adjustment) */
981 degrees_per_05db_num
=
982 tx_power_cmp_tble
[txatten_grp
].degrees_per_05db_a
;
983 degrees_per_05db_denom
=
984 tx_power_cmp_tble
[txatten_grp
].degrees_per_05db_a_denom
;
986 /* get per-chain txpower values from factory measurements */
987 for (c
= 0; c
< 2; c
++) {
988 measurement
= &ch_eeprom_info
.measurements
[c
][1];
990 /* txgain adjustment (in half-dB steps) based on difference
991 * between factory and current temperature */
992 factory_temp
= measurement
->temperature
;
993 iwl4965_math_div_round((current_temp
- factory_temp
) *
994 degrees_per_05db_denom
,
995 degrees_per_05db_num
,
996 &temperature_comp
[c
]);
998 factory_gain_index
[c
] = measurement
->gain_idx
;
999 factory_actual_pwr
[c
] = measurement
->actual_pow
;
1001 IWL_DEBUG_TXPOWER(priv
, "chain = %d\n", c
);
1002 IWL_DEBUG_TXPOWER(priv
, "fctry tmp %d, "
1003 "curr tmp %d, comp %d steps\n",
1004 factory_temp
, current_temp
,
1005 temperature_comp
[c
]);
1007 IWL_DEBUG_TXPOWER(priv
, "fctry idx %d, fctry pwr %d\n",
1008 factory_gain_index
[c
],
1009 factory_actual_pwr
[c
]);
1012 /* for each of 33 bit-rates (including 1 for CCK) */
1013 for (i
= 0; i
< POWER_TABLE_NUM_ENTRIES
; i
++) {
1015 union iwl4965_tx_power_dual_stream tx_power
;
1017 /* for mimo, reduce each chain's txpower by half
1018 * (3dB, 6 steps), so total output power is regulatory
1021 current_regulatory
= reg_limit
-
1022 IWL_TX_POWER_MIMO_REGULATORY_COMPENSATION
;
1025 current_regulatory
= reg_limit
;
1029 /* find txpower limit, either hardware or regulatory */
1030 power_limit
= saturation_power
- back_off_table
[i
];
1031 if (power_limit
> current_regulatory
)
1032 power_limit
= current_regulatory
;
1034 /* reduce user's txpower request if necessary
1035 * for this rate on this channel */
1036 target_power
= user_target_power
;
1037 if (target_power
> power_limit
)
1038 target_power
= power_limit
;
1040 IWL_DEBUG_TXPOWER(priv
, "rate %d sat %d reg %d usr %d tgt %d\n",
1041 i
, saturation_power
- back_off_table
[i
],
1042 current_regulatory
, user_target_power
,
1045 /* for each of 2 Tx chains (radio transmitters) */
1046 for (c
= 0; c
< 2; c
++) {
1051 (s32
)le32_to_cpu(priv
->card_alive_init
.
1052 tx_atten
[txatten_grp
][c
]);
1056 /* calculate index; higher index means lower txpower */
1057 power_index
= (u8
) (factory_gain_index
[c
] -
1059 factory_actual_pwr
[c
]) -
1060 temperature_comp
[c
] -
1061 voltage_compensation
+
1064 /* IWL_DEBUG_TXPOWER(priv, "calculated txpower index %d\n",
1067 if (power_index
< get_min_power_index(i
, band
))
1068 power_index
= get_min_power_index(i
, band
);
1070 /* adjust 5 GHz index to support negative indexes */
1074 /* CCK, rate 32, reduce txpower for CCK */
1075 if (i
== POWER_TABLE_CCK_ENTRY
)
1077 IWL_TX_POWER_CCK_COMPENSATION_C_STEP
;
1079 /* stay within the table! */
1080 if (power_index
> 107) {
1081 IWL_WARN(priv
, "txpower index %d > 107\n",
1085 if (power_index
< 0) {
1086 IWL_WARN(priv
, "txpower index %d < 0\n",
1091 /* fill txpower command for this rate/chain */
1092 tx_power
.s
.radio_tx_gain
[c
] =
1093 gain_table
[band
][power_index
].radio
;
1094 tx_power
.s
.dsp_predis_atten
[c
] =
1095 gain_table
[band
][power_index
].dsp
;
1097 IWL_DEBUG_TXPOWER(priv
, "chain %d mimo %d index %d "
1098 "gain 0x%02x dsp %d\n",
1099 c
, atten_value
, power_index
,
1100 tx_power
.s
.radio_tx_gain
[c
],
1101 tx_power
.s
.dsp_predis_atten
[c
]);
1102 } /* for each chain */
1104 tx_power_tbl
->power_tbl
[i
].dw
= cpu_to_le32(tx_power
.dw
);
1106 } /* for each rate */
1112 * iwl4965_send_tx_power - Configure the TXPOWER level user limit
1114 * Uses the active RXON for channel, band, and characteristics (ht40, high)
1115 * The power limit is taken from priv->tx_power_user_lmt.
1117 static int iwl4965_send_tx_power(struct iwl_priv
*priv
)
1119 struct iwl4965_txpowertable_cmd cmd
= { 0 };
1122 bool is_ht40
= false;
1123 u8 ctrl_chan_high
= 0;
1124 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
1126 if (WARN_ONCE(test_bit(STATUS_SCAN_HW
, &priv
->status
),
1127 "TX Power requested while scanning!\n"))
1130 band
= priv
->band
== IEEE80211_BAND_2GHZ
;
1132 is_ht40
= iw4965_is_ht40_channel(ctx
->active
.flags
);
1134 if (is_ht40
&& (ctx
->active
.flags
& RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
))
1138 cmd
.channel
= ctx
->active
.channel
;
1140 ret
= iwl4965_fill_txpower_tbl(priv
, band
,
1141 le16_to_cpu(ctx
->active
.channel
),
1142 is_ht40
, ctrl_chan_high
, &cmd
.tx_power
);
1146 ret
= iwl_legacy_send_cmd_pdu(priv
,
1147 REPLY_TX_PWR_TABLE_CMD
, sizeof(cmd
), &cmd
);
1153 static int iwl4965_send_rxon_assoc(struct iwl_priv
*priv
,
1154 struct iwl_rxon_context
*ctx
)
1157 struct iwl4965_rxon_assoc_cmd rxon_assoc
;
1158 const struct iwl_legacy_rxon_cmd
*rxon1
= &ctx
->staging
;
1159 const struct iwl_legacy_rxon_cmd
*rxon2
= &ctx
->active
;
1161 if ((rxon1
->flags
== rxon2
->flags
) &&
1162 (rxon1
->filter_flags
== rxon2
->filter_flags
) &&
1163 (rxon1
->cck_basic_rates
== rxon2
->cck_basic_rates
) &&
1164 (rxon1
->ofdm_ht_single_stream_basic_rates
==
1165 rxon2
->ofdm_ht_single_stream_basic_rates
) &&
1166 (rxon1
->ofdm_ht_dual_stream_basic_rates
==
1167 rxon2
->ofdm_ht_dual_stream_basic_rates
) &&
1168 (rxon1
->rx_chain
== rxon2
->rx_chain
) &&
1169 (rxon1
->ofdm_basic_rates
== rxon2
->ofdm_basic_rates
)) {
1170 IWL_DEBUG_INFO(priv
, "Using current RXON_ASSOC. Not resending.\n");
1174 rxon_assoc
.flags
= ctx
->staging
.flags
;
1175 rxon_assoc
.filter_flags
= ctx
->staging
.filter_flags
;
1176 rxon_assoc
.ofdm_basic_rates
= ctx
->staging
.ofdm_basic_rates
;
1177 rxon_assoc
.cck_basic_rates
= ctx
->staging
.cck_basic_rates
;
1178 rxon_assoc
.reserved
= 0;
1179 rxon_assoc
.ofdm_ht_single_stream_basic_rates
=
1180 ctx
->staging
.ofdm_ht_single_stream_basic_rates
;
1181 rxon_assoc
.ofdm_ht_dual_stream_basic_rates
=
1182 ctx
->staging
.ofdm_ht_dual_stream_basic_rates
;
1183 rxon_assoc
.rx_chain_select_flags
= ctx
->staging
.rx_chain
;
1185 ret
= iwl_legacy_send_cmd_pdu_async(priv
, REPLY_RXON_ASSOC
,
1186 sizeof(rxon_assoc
), &rxon_assoc
, NULL
);
1191 static int iwl4965_commit_rxon(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
1193 /* cast away the const for active_rxon in this function */
1194 struct iwl_legacy_rxon_cmd
*active_rxon
= (void *)&ctx
->active
;
1197 !!(ctx
->staging
.filter_flags
& RXON_FILTER_ASSOC_MSK
);
1199 if (!iwl_legacy_is_alive(priv
))
1202 if (!ctx
->is_active
)
1205 /* always get timestamp with Rx frame */
1206 ctx
->staging
.flags
|= RXON_FLG_TSF2HOST_MSK
;
1208 ret
= iwl_legacy_check_rxon_cmd(priv
, ctx
);
1210 IWL_ERR(priv
, "Invalid RXON configuration. Not committing.\n");
1215 * receive commit_rxon request
1216 * abort any previous channel switch if still in process
1218 if (test_bit(STATUS_CHANNEL_SWITCH_PENDING
, &priv
->status
) &&
1219 (priv
->switch_channel
!= ctx
->staging
.channel
)) {
1220 IWL_DEBUG_11H(priv
, "abort channel switch on %d\n",
1221 le16_to_cpu(priv
->switch_channel
));
1222 iwl_legacy_chswitch_done(priv
, false);
1225 /* If we don't need to send a full RXON, we can use
1226 * iwl_rxon_assoc_cmd which is used to reconfigure filter
1227 * and other flags for the current radio configuration. */
1228 if (!iwl_legacy_full_rxon_required(priv
, ctx
)) {
1229 ret
= iwl_legacy_send_rxon_assoc(priv
, ctx
);
1231 IWL_ERR(priv
, "Error setting RXON_ASSOC (%d)\n", ret
);
1235 memcpy(active_rxon
, &ctx
->staging
, sizeof(*active_rxon
));
1236 iwl_legacy_print_rx_config_cmd(priv
, ctx
);
1238 * We do not commit tx power settings while channel changing,
1239 * do it now if tx power changed.
1241 iwl_legacy_set_tx_power(priv
, priv
->tx_power_next
, false);
1245 /* If we are currently associated and the new config requires
1246 * an RXON_ASSOC and the new config wants the associated mask enabled,
1247 * we must clear the associated from the active configuration
1248 * before we apply the new config */
1249 if (iwl_legacy_is_associated_ctx(ctx
) && new_assoc
) {
1250 IWL_DEBUG_INFO(priv
, "Toggling associated bit on current RXON\n");
1251 active_rxon
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
1253 ret
= iwl_legacy_send_cmd_pdu(priv
, ctx
->rxon_cmd
,
1254 sizeof(struct iwl_legacy_rxon_cmd
),
1257 /* If the mask clearing failed then we set
1258 * active_rxon back to what it was previously */
1260 active_rxon
->filter_flags
|= RXON_FILTER_ASSOC_MSK
;
1261 IWL_ERR(priv
, "Error clearing ASSOC_MSK (%d)\n", ret
);
1264 iwl_legacy_clear_ucode_stations(priv
, ctx
);
1265 iwl_legacy_restore_stations(priv
, ctx
);
1266 ret
= iwl4965_restore_default_wep_keys(priv
, ctx
);
1268 IWL_ERR(priv
, "Failed to restore WEP keys (%d)\n", ret
);
1273 IWL_DEBUG_INFO(priv
, "Sending RXON\n"
1274 "* with%s RXON_FILTER_ASSOC_MSK\n"
1277 (new_assoc
? "" : "out"),
1278 le16_to_cpu(ctx
->staging
.channel
),
1279 ctx
->staging
.bssid_addr
);
1281 iwl_legacy_set_rxon_hwcrypto(priv
, ctx
,
1282 !priv
->cfg
->mod_params
->sw_crypto
);
1284 /* Apply the new configuration
1285 * RXON unassoc clears the station table in uCode so restoration of
1286 * stations is needed after it (the RXON command) completes
1289 ret
= iwl_legacy_send_cmd_pdu(priv
, ctx
->rxon_cmd
,
1290 sizeof(struct iwl_legacy_rxon_cmd
), &ctx
->staging
);
1292 IWL_ERR(priv
, "Error setting new RXON (%d)\n", ret
);
1295 IWL_DEBUG_INFO(priv
, "Return from !new_assoc RXON.\n");
1296 memcpy(active_rxon
, &ctx
->staging
, sizeof(*active_rxon
));
1297 iwl_legacy_clear_ucode_stations(priv
, ctx
);
1298 iwl_legacy_restore_stations(priv
, ctx
);
1299 ret
= iwl4965_restore_default_wep_keys(priv
, ctx
);
1301 IWL_ERR(priv
, "Failed to restore WEP keys (%d)\n", ret
);
1306 priv
->start_calib
= 0;
1307 /* Apply the new configuration
1308 * RXON assoc doesn't clear the station table in uCode,
1310 ret
= iwl_legacy_send_cmd_pdu(priv
, ctx
->rxon_cmd
,
1311 sizeof(struct iwl_legacy_rxon_cmd
), &ctx
->staging
);
1313 IWL_ERR(priv
, "Error setting new RXON (%d)\n", ret
);
1316 memcpy(active_rxon
, &ctx
->staging
, sizeof(*active_rxon
));
1318 iwl_legacy_print_rx_config_cmd(priv
, ctx
);
1320 iwl4965_init_sensitivity(priv
);
1322 /* If we issue a new RXON command which required a tune then we must
1323 * send a new TXPOWER command or we won't be able to Tx any frames */
1324 ret
= iwl_legacy_set_tx_power(priv
, priv
->tx_power_next
, true);
1326 IWL_ERR(priv
, "Error sending TX power (%d)\n", ret
);
1333 static int iwl4965_hw_channel_switch(struct iwl_priv
*priv
,
1334 struct ieee80211_channel_switch
*ch_switch
)
1336 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
1339 bool is_ht40
= false;
1340 u8 ctrl_chan_high
= 0;
1341 struct iwl4965_channel_switch_cmd cmd
;
1342 const struct iwl_channel_info
*ch_info
;
1343 u32 switch_time_in_usec
, ucode_switch_time
;
1347 u16 beacon_interval
= le16_to_cpu(ctx
->timing
.beacon_interval
);
1348 struct ieee80211_vif
*vif
= ctx
->vif
;
1349 band
= priv
->band
== IEEE80211_BAND_2GHZ
;
1351 is_ht40
= iw4965_is_ht40_channel(ctx
->staging
.flags
);
1354 (ctx
->staging
.flags
& RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
))
1358 cmd
.expect_beacon
= 0;
1359 ch
= ch_switch
->channel
->hw_value
;
1360 cmd
.channel
= cpu_to_le16(ch
);
1361 cmd
.rxon_flags
= ctx
->staging
.flags
;
1362 cmd
.rxon_filter_flags
= ctx
->staging
.filter_flags
;
1363 switch_count
= ch_switch
->count
;
1364 tsf_low
= ch_switch
->timestamp
& 0x0ffffffff;
1366 * calculate the ucode channel switch time
1367 * adding TSF as one of the factor for when to switch
1369 if ((priv
->ucode_beacon_time
> tsf_low
) && beacon_interval
) {
1370 if (switch_count
> ((priv
->ucode_beacon_time
- tsf_low
) /
1372 switch_count
-= (priv
->ucode_beacon_time
-
1373 tsf_low
) / beacon_interval
;
1377 if (switch_count
<= 1)
1378 cmd
.switch_time
= cpu_to_le32(priv
->ucode_beacon_time
);
1380 switch_time_in_usec
=
1381 vif
->bss_conf
.beacon_int
* switch_count
* TIME_UNIT
;
1382 ucode_switch_time
= iwl_legacy_usecs_to_beacons(priv
,
1383 switch_time_in_usec
,
1385 cmd
.switch_time
= iwl_legacy_add_beacon_time(priv
,
1386 priv
->ucode_beacon_time
,
1390 IWL_DEBUG_11H(priv
, "uCode time for the switch is 0x%x\n",
1392 ch_info
= iwl_legacy_get_channel_info(priv
, priv
->band
, ch
);
1394 cmd
.expect_beacon
= iwl_legacy_is_channel_radar(ch_info
);
1396 IWL_ERR(priv
, "invalid channel switch from %u to %u\n",
1397 ctx
->active
.channel
, ch
);
1401 rc
= iwl4965_fill_txpower_tbl(priv
, band
, ch
, is_ht40
,
1402 ctrl_chan_high
, &cmd
.tx_power
);
1404 IWL_DEBUG_11H(priv
, "error:%d fill txpower_tbl\n", rc
);
1408 return iwl_legacy_send_cmd_pdu(priv
,
1409 REPLY_CHANNEL_SWITCH
, sizeof(cmd
), &cmd
);
1413 * iwl4965_txq_update_byte_cnt_tbl - Set up entry in Tx byte-count array
1415 static void iwl4965_txq_update_byte_cnt_tbl(struct iwl_priv
*priv
,
1416 struct iwl_tx_queue
*txq
,
1419 struct iwl4965_scd_bc_tbl
*scd_bc_tbl
= priv
->scd_bc_tbls
.addr
;
1420 int txq_id
= txq
->q
.id
;
1421 int write_ptr
= txq
->q
.write_ptr
;
1422 int len
= byte_cnt
+ IWL_TX_CRC_SIZE
+ IWL_TX_DELIMITER_SIZE
;
1425 WARN_ON(len
> 0xFFF || write_ptr
>= TFD_QUEUE_SIZE_MAX
);
1427 bc_ent
= cpu_to_le16(len
& 0xFFF);
1428 /* Set up byte count within first 256 entries */
1429 scd_bc_tbl
[txq_id
].tfd_offset
[write_ptr
] = bc_ent
;
1431 /* If within first 64 entries, duplicate at end */
1432 if (write_ptr
< TFD_QUEUE_SIZE_BC_DUP
)
1434 tfd_offset
[TFD_QUEUE_SIZE_MAX
+ write_ptr
] = bc_ent
;
1438 * iwl4965_hw_get_temperature - return the calibrated temperature (in Kelvin)
1439 * @statistics: Provides the temperature reading from the uCode
1441 * A return of <0 indicates bogus data in the statistics
1443 static int iwl4965_hw_get_temperature(struct iwl_priv
*priv
)
1450 if (test_bit(STATUS_TEMPERATURE
, &priv
->status
) &&
1451 (priv
->_4965
.statistics
.flag
&
1452 STATISTICS_REPLY_FLG_HT40_MODE_MSK
)) {
1453 IWL_DEBUG_TEMP(priv
, "Running HT40 temperature calibration\n");
1454 R1
= (s32
)le32_to_cpu(priv
->card_alive_init
.therm_r1
[1]);
1455 R2
= (s32
)le32_to_cpu(priv
->card_alive_init
.therm_r2
[1]);
1456 R3
= (s32
)le32_to_cpu(priv
->card_alive_init
.therm_r3
[1]);
1457 R4
= le32_to_cpu(priv
->card_alive_init
.therm_r4
[1]);
1459 IWL_DEBUG_TEMP(priv
, "Running temperature calibration\n");
1460 R1
= (s32
)le32_to_cpu(priv
->card_alive_init
.therm_r1
[0]);
1461 R2
= (s32
)le32_to_cpu(priv
->card_alive_init
.therm_r2
[0]);
1462 R3
= (s32
)le32_to_cpu(priv
->card_alive_init
.therm_r3
[0]);
1463 R4
= le32_to_cpu(priv
->card_alive_init
.therm_r4
[0]);
1467 * Temperature is only 23 bits, so sign extend out to 32.
1469 * NOTE If we haven't received a statistics notification yet
1470 * with an updated temperature, use R4 provided to us in the
1471 * "initialize" ALIVE response.
1473 if (!test_bit(STATUS_TEMPERATURE
, &priv
->status
))
1474 vt
= sign_extend32(R4
, 23);
1476 vt
= sign_extend32(le32_to_cpu(priv
->_4965
.statistics
.
1477 general
.common
.temperature
), 23);
1479 IWL_DEBUG_TEMP(priv
, "Calib values R[1-3]: %d %d %d R4: %d\n", R1
, R2
, R3
, vt
);
1482 IWL_ERR(priv
, "Calibration conflict R1 == R3\n");
1486 /* Calculate temperature in degrees Kelvin, adjust by 97%.
1487 * Add offset to center the adjustment around 0 degrees Centigrade. */
1488 temperature
= TEMPERATURE_CALIB_A_VAL
* (vt
- R2
);
1489 temperature
/= (R3
- R1
);
1490 temperature
= (temperature
* 97) / 100 + TEMPERATURE_CALIB_KELVIN_OFFSET
;
1492 IWL_DEBUG_TEMP(priv
, "Calibrated temperature: %dK, %dC\n",
1493 temperature
, KELVIN_TO_CELSIUS(temperature
));
1498 /* Adjust Txpower only if temperature variance is greater than threshold. */
1499 #define IWL_TEMPERATURE_THRESHOLD 3
1502 * iwl4965_is_temp_calib_needed - determines if new calibration is needed
1504 * If the temperature changed has changed sufficiently, then a recalibration
1507 * Assumes caller will replace priv->last_temperature once calibration
1510 static int iwl4965_is_temp_calib_needed(struct iwl_priv
*priv
)
1514 if (!test_bit(STATUS_STATISTICS
, &priv
->status
)) {
1515 IWL_DEBUG_TEMP(priv
, "Temperature not updated -- no statistics.\n");
1519 temp_diff
= priv
->temperature
- priv
->last_temperature
;
1521 /* get absolute value */
1522 if (temp_diff
< 0) {
1523 IWL_DEBUG_POWER(priv
, "Getting cooler, delta %d\n", temp_diff
);
1524 temp_diff
= -temp_diff
;
1525 } else if (temp_diff
== 0)
1526 IWL_DEBUG_POWER(priv
, "Temperature unchanged\n");
1528 IWL_DEBUG_POWER(priv
, "Getting warmer, delta %d\n", temp_diff
);
1530 if (temp_diff
< IWL_TEMPERATURE_THRESHOLD
) {
1531 IWL_DEBUG_POWER(priv
, " => thermal txpower calib not needed\n");
1535 IWL_DEBUG_POWER(priv
, " => thermal txpower calib needed\n");
1540 static void iwl4965_temperature_calib(struct iwl_priv
*priv
)
1544 temp
= iwl4965_hw_get_temperature(priv
);
1545 if (IWL_TX_POWER_TEMPERATURE_OUT_OF_RANGE(temp
))
1548 if (priv
->temperature
!= temp
) {
1549 if (priv
->temperature
)
1550 IWL_DEBUG_TEMP(priv
, "Temperature changed "
1551 "from %dC to %dC\n",
1552 KELVIN_TO_CELSIUS(priv
->temperature
),
1553 KELVIN_TO_CELSIUS(temp
));
1555 IWL_DEBUG_TEMP(priv
, "Temperature "
1556 "initialized to %dC\n",
1557 KELVIN_TO_CELSIUS(temp
));
1560 priv
->temperature
= temp
;
1561 set_bit(STATUS_TEMPERATURE
, &priv
->status
);
1563 if (!priv
->disable_tx_power_cal
&&
1564 unlikely(!test_bit(STATUS_SCANNING
, &priv
->status
)) &&
1565 iwl4965_is_temp_calib_needed(priv
))
1566 queue_work(priv
->workqueue
, &priv
->txpower_work
);
1569 static u16
iwl4965_get_hcmd_size(u8 cmd_id
, u16 len
)
1573 return (u16
) sizeof(struct iwl4965_rxon_cmd
);
1579 static u16
iwl4965_build_addsta_hcmd(const struct iwl_legacy_addsta_cmd
*cmd
,
1582 struct iwl4965_addsta_cmd
*addsta
= (struct iwl4965_addsta_cmd
*)data
;
1583 addsta
->mode
= cmd
->mode
;
1584 memcpy(&addsta
->sta
, &cmd
->sta
, sizeof(struct sta_id_modify
));
1585 memcpy(&addsta
->key
, &cmd
->key
, sizeof(struct iwl4965_keyinfo
));
1586 addsta
->station_flags
= cmd
->station_flags
;
1587 addsta
->station_flags_msk
= cmd
->station_flags_msk
;
1588 addsta
->tid_disable_tx
= cmd
->tid_disable_tx
;
1589 addsta
->add_immediate_ba_tid
= cmd
->add_immediate_ba_tid
;
1590 addsta
->remove_immediate_ba_tid
= cmd
->remove_immediate_ba_tid
;
1591 addsta
->add_immediate_ba_ssn
= cmd
->add_immediate_ba_ssn
;
1592 addsta
->sleep_tx_count
= cmd
->sleep_tx_count
;
1593 addsta
->reserved1
= cpu_to_le16(0);
1594 addsta
->reserved2
= cpu_to_le16(0);
1596 return (u16
)sizeof(struct iwl4965_addsta_cmd
);
1599 static inline u32
iwl4965_get_scd_ssn(struct iwl4965_tx_resp
*tx_resp
)
1601 return le32_to_cpup(&tx_resp
->u
.status
+ tx_resp
->frame_count
) & MAX_SN
;
1605 * iwl4965_tx_status_reply_tx - Handle Tx response for frames in aggregation queue
1607 static int iwl4965_tx_status_reply_tx(struct iwl_priv
*priv
,
1608 struct iwl_ht_agg
*agg
,
1609 struct iwl4965_tx_resp
*tx_resp
,
1610 int txq_id
, u16 start_idx
)
1613 struct agg_tx_status
*frame_status
= tx_resp
->u
.agg_status
;
1614 struct ieee80211_tx_info
*info
= NULL
;
1615 struct ieee80211_hdr
*hdr
= NULL
;
1616 u32 rate_n_flags
= le32_to_cpu(tx_resp
->rate_n_flags
);
1619 if (agg
->wait_for_ba
)
1620 IWL_DEBUG_TX_REPLY(priv
, "got tx response w/o block-ack\n");
1622 agg
->frame_count
= tx_resp
->frame_count
;
1623 agg
->start_idx
= start_idx
;
1624 agg
->rate_n_flags
= rate_n_flags
;
1627 /* num frames attempted by Tx command */
1628 if (agg
->frame_count
== 1) {
1629 /* Only one frame was attempted; no block-ack will arrive */
1630 status
= le16_to_cpu(frame_status
[0].status
);
1633 IWL_DEBUG_TX_REPLY(priv
, "FrameCnt = %d, StartIdx=%d idx=%d\n",
1634 agg
->frame_count
, agg
->start_idx
, idx
);
1636 info
= IEEE80211_SKB_CB(priv
->txq
[txq_id
].txb
[idx
].skb
);
1637 info
->status
.rates
[0].count
= tx_resp
->failure_frame
+ 1;
1638 info
->flags
&= ~IEEE80211_TX_CTL_AMPDU
;
1639 info
->flags
|= iwl4965_tx_status_to_mac80211(status
);
1640 iwl4965_hwrate_to_tx_control(priv
, rate_n_flags
, info
);
1642 IWL_DEBUG_TX_REPLY(priv
, "1 Frame 0x%x failure :%d\n",
1643 status
& 0xff, tx_resp
->failure_frame
);
1644 IWL_DEBUG_TX_REPLY(priv
, "Rate Info rate_n_flags=%x\n", rate_n_flags
);
1646 agg
->wait_for_ba
= 0;
1648 /* Two or more frames were attempted; expect block-ack */
1650 int start
= agg
->start_idx
;
1652 /* Construct bit-map of pending frames within Tx window */
1653 for (i
= 0; i
< agg
->frame_count
; i
++) {
1655 status
= le16_to_cpu(frame_status
[i
].status
);
1656 seq
= le16_to_cpu(frame_status
[i
].sequence
);
1657 idx
= SEQ_TO_INDEX(seq
);
1658 txq_id
= SEQ_TO_QUEUE(seq
);
1660 if (status
& (AGG_TX_STATE_FEW_BYTES_MSK
|
1661 AGG_TX_STATE_ABORT_MSK
))
1664 IWL_DEBUG_TX_REPLY(priv
, "FrameCnt = %d, txq_id=%d idx=%d\n",
1665 agg
->frame_count
, txq_id
, idx
);
1667 hdr
= iwl_legacy_tx_queue_get_hdr(priv
, txq_id
, idx
);
1670 "BUG_ON idx doesn't point to valid skb"
1671 " idx=%d, txq_id=%d\n", idx
, txq_id
);
1675 sc
= le16_to_cpu(hdr
->seq_ctrl
);
1676 if (idx
!= (SEQ_TO_SN(sc
) & 0xff)) {
1678 "BUG_ON idx doesn't match seq control"
1679 " idx=%d, seq_idx=%d, seq=%d\n",
1680 idx
, SEQ_TO_SN(sc
), hdr
->seq_ctrl
);
1684 IWL_DEBUG_TX_REPLY(priv
, "AGG Frame i=%d idx %d seq=%d\n",
1685 i
, idx
, SEQ_TO_SN(sc
));
1689 sh
= (start
- idx
) + 0xff;
1690 bitmap
= bitmap
<< sh
;
1693 } else if (sh
< -64)
1694 sh
= 0xff - (start
- idx
);
1698 bitmap
= bitmap
<< sh
;
1701 bitmap
|= 1ULL << sh
;
1702 IWL_DEBUG_TX_REPLY(priv
, "start=%d bitmap=0x%llx\n",
1703 start
, (unsigned long long)bitmap
);
1706 agg
->bitmap
= bitmap
;
1707 agg
->start_idx
= start
;
1708 IWL_DEBUG_TX_REPLY(priv
, "Frames %d start_idx=%d bitmap=0x%llx\n",
1709 agg
->frame_count
, agg
->start_idx
,
1710 (unsigned long long)agg
->bitmap
);
1713 agg
->wait_for_ba
= 1;
1718 static u8
iwl4965_find_station(struct iwl_priv
*priv
, const u8
*addr
)
1722 int ret
= IWL_INVALID_STATION
;
1723 unsigned long flags
;
1725 if ((priv
->iw_mode
== NL80211_IFTYPE_ADHOC
))
1728 if (is_broadcast_ether_addr(addr
))
1729 return priv
->contexts
[IWL_RXON_CTX_BSS
].bcast_sta_id
;
1731 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1732 for (i
= start
; i
< priv
->hw_params
.max_stations
; i
++)
1733 if (priv
->stations
[i
].used
&&
1734 (!compare_ether_addr(priv
->stations
[i
].sta
.sta
.addr
,
1740 IWL_DEBUG_ASSOC_LIMIT(priv
, "can not find STA %pM total %d\n",
1741 addr
, priv
->num_stations
);
1745 * It may be possible that more commands interacting with stations
1746 * arrive before we completed processing the adding of
1749 if (ret
!= IWL_INVALID_STATION
&&
1750 (!(priv
->stations
[ret
].used
& IWL_STA_UCODE_ACTIVE
) ||
1751 ((priv
->stations
[ret
].used
& IWL_STA_UCODE_ACTIVE
) &&
1752 (priv
->stations
[ret
].used
& IWL_STA_UCODE_INPROGRESS
)))) {
1753 IWL_ERR(priv
, "Requested station info for sta %d before ready.\n",
1755 ret
= IWL_INVALID_STATION
;
1757 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1761 static int iwl4965_get_ra_sta_id(struct iwl_priv
*priv
, struct ieee80211_hdr
*hdr
)
1763 if (priv
->iw_mode
== NL80211_IFTYPE_STATION
) {
1766 u8
*da
= ieee80211_get_DA(hdr
);
1767 return iwl4965_find_station(priv
, da
);
1772 * iwl4965_rx_reply_tx - Handle standard (non-aggregation) Tx response
1774 static void iwl4965_rx_reply_tx(struct iwl_priv
*priv
,
1775 struct iwl_rx_mem_buffer
*rxb
)
1777 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1778 u16 sequence
= le16_to_cpu(pkt
->hdr
.sequence
);
1779 int txq_id
= SEQ_TO_QUEUE(sequence
);
1780 int index
= SEQ_TO_INDEX(sequence
);
1781 struct iwl_tx_queue
*txq
= &priv
->txq
[txq_id
];
1782 struct ieee80211_hdr
*hdr
;
1783 struct ieee80211_tx_info
*info
;
1784 struct iwl4965_tx_resp
*tx_resp
= (void *)&pkt
->u
.raw
[0];
1785 u32 status
= le32_to_cpu(tx_resp
->u
.status
);
1786 int uninitialized_var(tid
);
1790 unsigned long flags
;
1792 if ((index
>= txq
->q
.n_bd
) || (iwl_legacy_queue_used(&txq
->q
, index
) == 0)) {
1793 IWL_ERR(priv
, "Read index for DMA queue txq_id (%d) index %d "
1794 "is out of range [0-%d] %d %d\n", txq_id
,
1795 index
, txq
->q
.n_bd
, txq
->q
.write_ptr
,
1800 txq
->time_stamp
= jiffies
;
1801 info
= IEEE80211_SKB_CB(txq
->txb
[txq
->q
.read_ptr
].skb
);
1802 memset(&info
->status
, 0, sizeof(info
->status
));
1804 hdr
= iwl_legacy_tx_queue_get_hdr(priv
, txq_id
, index
);
1805 if (ieee80211_is_data_qos(hdr
->frame_control
)) {
1806 qc
= ieee80211_get_qos_ctl(hdr
);
1810 sta_id
= iwl4965_get_ra_sta_id(priv
, hdr
);
1811 if (txq
->sched_retry
&& unlikely(sta_id
== IWL_INVALID_STATION
)) {
1812 IWL_ERR(priv
, "Station not known\n");
1816 spin_lock_irqsave(&priv
->sta_lock
, flags
);
1817 if (txq
->sched_retry
) {
1818 const u32 scd_ssn
= iwl4965_get_scd_ssn(tx_resp
);
1819 struct iwl_ht_agg
*agg
= NULL
;
1822 agg
= &priv
->stations
[sta_id
].tid
[tid
].agg
;
1824 iwl4965_tx_status_reply_tx(priv
, agg
, tx_resp
, txq_id
, index
);
1826 /* check if BAR is needed */
1827 if ((tx_resp
->frame_count
== 1) && !iwl4965_is_tx_success(status
))
1828 info
->flags
|= IEEE80211_TX_STAT_AMPDU_NO_BACK
;
1830 if (txq
->q
.read_ptr
!= (scd_ssn
& 0xff)) {
1831 index
= iwl_legacy_queue_dec_wrap(scd_ssn
& 0xff,
1833 IWL_DEBUG_TX_REPLY(priv
, "Retry scheduler reclaim scd_ssn "
1834 "%d index %d\n", scd_ssn
, index
);
1835 freed
= iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
1837 iwl4965_free_tfds_in_queue(priv
, sta_id
,
1840 if (priv
->mac80211_registered
&&
1841 (iwl_legacy_queue_space(&txq
->q
) > txq
->q
.low_mark
)
1842 && (agg
->state
!= IWL_EMPTYING_HW_QUEUE_DELBA
))
1843 iwl_legacy_wake_queue(priv
, txq
);
1846 info
->status
.rates
[0].count
= tx_resp
->failure_frame
+ 1;
1847 info
->flags
|= iwl4965_tx_status_to_mac80211(status
);
1848 iwl4965_hwrate_to_tx_control(priv
,
1849 le32_to_cpu(tx_resp
->rate_n_flags
),
1852 IWL_DEBUG_TX_REPLY(priv
, "TXQ %d status %s (0x%08x) "
1853 "rate_n_flags 0x%x retries %d\n",
1855 iwl4965_get_tx_fail_reason(status
), status
,
1856 le32_to_cpu(tx_resp
->rate_n_flags
),
1857 tx_resp
->failure_frame
);
1859 freed
= iwl4965_tx_queue_reclaim(priv
, txq_id
, index
);
1860 if (qc
&& likely(sta_id
!= IWL_INVALID_STATION
))
1861 iwl4965_free_tfds_in_queue(priv
, sta_id
, tid
, freed
);
1862 else if (sta_id
== IWL_INVALID_STATION
)
1863 IWL_DEBUG_TX_REPLY(priv
, "Station not known\n");
1865 if (priv
->mac80211_registered
&&
1866 (iwl_legacy_queue_space(&txq
->q
) > txq
->q
.low_mark
))
1867 iwl_legacy_wake_queue(priv
, txq
);
1869 if (qc
&& likely(sta_id
!= IWL_INVALID_STATION
))
1870 iwl4965_txq_check_empty(priv
, sta_id
, tid
, txq_id
);
1872 iwl4965_check_abort_status(priv
, tx_resp
->frame_count
, status
);
1874 spin_unlock_irqrestore(&priv
->sta_lock
, flags
);
1877 static void iwl4965_rx_beacon_notif(struct iwl_priv
*priv
,
1878 struct iwl_rx_mem_buffer
*rxb
)
1880 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1881 struct iwl4965_beacon_notif
*beacon
= (void *)pkt
->u
.raw
;
1882 u8 rate __maybe_unused
=
1883 iwl4965_hw_get_rate(beacon
->beacon_notify_hdr
.rate_n_flags
);
1885 IWL_DEBUG_RX(priv
, "beacon status %#x, retries:%d ibssmgr:%d "
1886 "tsf:0x%.8x%.8x rate:%d\n",
1887 le32_to_cpu(beacon
->beacon_notify_hdr
.u
.status
) & TX_STATUS_MSK
,
1888 beacon
->beacon_notify_hdr
.failure_frame
,
1889 le32_to_cpu(beacon
->ibss_mgr_status
),
1890 le32_to_cpu(beacon
->high_tsf
),
1891 le32_to_cpu(beacon
->low_tsf
), rate
);
1893 priv
->ibss_manager
= le32_to_cpu(beacon
->ibss_mgr_status
);
1896 /* Set up 4965-specific Rx frame reply handlers */
1897 static void iwl4965_rx_handler_setup(struct iwl_priv
*priv
)
1899 /* Legacy Rx frames */
1900 priv
->rx_handlers
[REPLY_RX
] = iwl4965_rx_reply_rx
;
1902 priv
->rx_handlers
[REPLY_TX
] = iwl4965_rx_reply_tx
;
1903 priv
->rx_handlers
[BEACON_NOTIFICATION
] = iwl4965_rx_beacon_notif
;
1906 static struct iwl_hcmd_ops iwl4965_hcmd
= {
1907 .rxon_assoc
= iwl4965_send_rxon_assoc
,
1908 .commit_rxon
= iwl4965_commit_rxon
,
1909 .set_rxon_chain
= iwl4965_set_rxon_chain
,
1912 static void iwl4965_post_scan(struct iwl_priv
*priv
)
1914 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
1917 * Since setting the RXON may have been deferred while
1918 * performing the scan, fire one off if needed
1920 if (memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
1921 iwl_legacy_commit_rxon(priv
, ctx
);
1924 static void iwl4965_post_associate(struct iwl_priv
*priv
)
1926 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
1927 struct ieee80211_vif
*vif
= ctx
->vif
;
1928 struct ieee80211_conf
*conf
= NULL
;
1931 if (!vif
|| !priv
->is_open
)
1934 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1937 iwl_legacy_scan_cancel_timeout(priv
, 200);
1939 conf
= iwl_legacy_ieee80211_get_hw_conf(priv
->hw
);
1941 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
1942 iwl_legacy_commit_rxon(priv
, ctx
);
1944 ret
= iwl_legacy_send_rxon_timing(priv
, ctx
);
1946 IWL_WARN(priv
, "RXON timing - "
1947 "Attempting to continue.\n");
1949 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
1951 iwl_legacy_set_rxon_ht(priv
, &priv
->current_ht_config
);
1953 if (priv
->cfg
->ops
->hcmd
->set_rxon_chain
)
1954 priv
->cfg
->ops
->hcmd
->set_rxon_chain(priv
, ctx
);
1956 ctx
->staging
.assoc_id
= cpu_to_le16(vif
->bss_conf
.aid
);
1958 IWL_DEBUG_ASSOC(priv
, "assoc id %d beacon interval %d\n",
1959 vif
->bss_conf
.aid
, vif
->bss_conf
.beacon_int
);
1961 if (vif
->bss_conf
.use_short_preamble
)
1962 ctx
->staging
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
1964 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
1966 if (ctx
->staging
.flags
& RXON_FLG_BAND_24G_MSK
) {
1967 if (vif
->bss_conf
.use_short_slot
)
1968 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
1970 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
1973 iwl_legacy_commit_rxon(priv
, ctx
);
1975 IWL_DEBUG_ASSOC(priv
, "Associated as %d to: %pM\n",
1976 vif
->bss_conf
.aid
, ctx
->active
.bssid_addr
);
1978 switch (vif
->type
) {
1979 case NL80211_IFTYPE_STATION
:
1981 case NL80211_IFTYPE_ADHOC
:
1982 iwl4965_send_beacon_cmd(priv
);
1985 IWL_ERR(priv
, "%s Should not be called in %d mode\n",
1986 __func__
, vif
->type
);
1990 /* the chain noise calibration will enabled PM upon completion
1991 * If chain noise has already been run, then we need to enable
1992 * power management here */
1993 if (priv
->chain_noise_data
.state
== IWL_CHAIN_NOISE_DONE
)
1994 iwl_legacy_power_update_mode(priv
, false);
1996 /* Enable Rx differential gain and sensitivity calibrations */
1997 iwl4965_chain_noise_reset(priv
);
1998 priv
->start_calib
= 1;
2001 static void iwl4965_config_ap(struct iwl_priv
*priv
)
2003 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
2004 struct ieee80211_vif
*vif
= ctx
->vif
;
2007 lockdep_assert_held(&priv
->mutex
);
2009 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2012 /* The following should be done only at AP bring up */
2013 if (!iwl_legacy_is_associated_ctx(ctx
)) {
2015 /* RXON - unassoc (to set timing command) */
2016 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
2017 iwl_legacy_commit_rxon(priv
, ctx
);
2020 ret
= iwl_legacy_send_rxon_timing(priv
, ctx
);
2022 IWL_WARN(priv
, "RXON timing failed - "
2023 "Attempting to continue.\n");
2025 /* AP has all antennas */
2026 priv
->chain_noise_data
.active_chains
=
2027 priv
->hw_params
.valid_rx_ant
;
2028 iwl_legacy_set_rxon_ht(priv
, &priv
->current_ht_config
);
2029 if (priv
->cfg
->ops
->hcmd
->set_rxon_chain
)
2030 priv
->cfg
->ops
->hcmd
->set_rxon_chain(priv
, ctx
);
2032 ctx
->staging
.assoc_id
= 0;
2034 if (vif
->bss_conf
.use_short_preamble
)
2035 ctx
->staging
.flags
|=
2036 RXON_FLG_SHORT_PREAMBLE_MSK
;
2038 ctx
->staging
.flags
&=
2039 ~RXON_FLG_SHORT_PREAMBLE_MSK
;
2041 if (ctx
->staging
.flags
& RXON_FLG_BAND_24G_MSK
) {
2042 if (vif
->bss_conf
.use_short_slot
)
2043 ctx
->staging
.flags
|=
2044 RXON_FLG_SHORT_SLOT_MSK
;
2046 ctx
->staging
.flags
&=
2047 ~RXON_FLG_SHORT_SLOT_MSK
;
2049 /* need to send beacon cmd before committing assoc RXON! */
2050 iwl4965_send_beacon_cmd(priv
);
2051 /* restore RXON assoc */
2052 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
2053 iwl_legacy_commit_rxon(priv
, ctx
);
2055 iwl4965_send_beacon_cmd(priv
);
2058 static struct iwl_hcmd_utils_ops iwl4965_hcmd_utils
= {
2059 .get_hcmd_size
= iwl4965_get_hcmd_size
,
2060 .build_addsta_hcmd
= iwl4965_build_addsta_hcmd
,
2061 .request_scan
= iwl4965_request_scan
,
2062 .post_scan
= iwl4965_post_scan
,
2065 static struct iwl_lib_ops iwl4965_lib
= {
2066 .set_hw_params
= iwl4965_hw_set_hw_params
,
2067 .txq_update_byte_cnt_tbl
= iwl4965_txq_update_byte_cnt_tbl
,
2068 .txq_attach_buf_to_tfd
= iwl4965_hw_txq_attach_buf_to_tfd
,
2069 .txq_free_tfd
= iwl4965_hw_txq_free_tfd
,
2070 .txq_init
= iwl4965_hw_tx_queue_init
,
2071 .rx_handler_setup
= iwl4965_rx_handler_setup
,
2072 .is_valid_rtc_data_addr
= iwl4965_hw_valid_rtc_data_addr
,
2073 .init_alive_start
= iwl4965_init_alive_start
,
2074 .load_ucode
= iwl4965_load_bsm
,
2075 .dump_nic_error_log
= iwl4965_dump_nic_error_log
,
2076 .dump_fh
= iwl4965_dump_fh
,
2077 .set_channel_switch
= iwl4965_hw_channel_switch
,
2079 .init
= iwl_legacy_apm_init
,
2080 .config
= iwl4965_nic_config
,
2083 .regulatory_bands
= {
2084 EEPROM_REGULATORY_BAND_1_CHANNELS
,
2085 EEPROM_REGULATORY_BAND_2_CHANNELS
,
2086 EEPROM_REGULATORY_BAND_3_CHANNELS
,
2087 EEPROM_REGULATORY_BAND_4_CHANNELS
,
2088 EEPROM_REGULATORY_BAND_5_CHANNELS
,
2089 EEPROM_4965_REGULATORY_BAND_24_HT40_CHANNELS
,
2090 EEPROM_4965_REGULATORY_BAND_52_HT40_CHANNELS
2092 .acquire_semaphore
= iwl4965_eeprom_acquire_semaphore
,
2093 .release_semaphore
= iwl4965_eeprom_release_semaphore
,
2095 .send_tx_power
= iwl4965_send_tx_power
,
2096 .update_chain_flags
= iwl4965_update_chain_flags
,
2098 .temperature
= iwl4965_temperature_calib
,
2101 .rx_stats_read
= iwl4965_ucode_rx_stats_read
,
2102 .tx_stats_read
= iwl4965_ucode_tx_stats_read
,
2103 .general_stats_read
= iwl4965_ucode_general_stats_read
,
2107 static const struct iwl_legacy_ops iwl4965_legacy_ops
= {
2108 .post_associate
= iwl4965_post_associate
,
2109 .config_ap
= iwl4965_config_ap
,
2110 .manage_ibss_station
= iwl4965_manage_ibss_station
,
2111 .update_bcast_stations
= iwl4965_update_bcast_stations
,
2114 struct ieee80211_ops iwl4965_hw_ops
= {
2115 .tx
= iwl4965_mac_tx
,
2116 .start
= iwl4965_mac_start
,
2117 .stop
= iwl4965_mac_stop
,
2118 .add_interface
= iwl_legacy_mac_add_interface
,
2119 .remove_interface
= iwl_legacy_mac_remove_interface
,
2120 .change_interface
= iwl_legacy_mac_change_interface
,
2121 .config
= iwl_legacy_mac_config
,
2122 .configure_filter
= iwl4965_configure_filter
,
2123 .set_key
= iwl4965_mac_set_key
,
2124 .update_tkip_key
= iwl4965_mac_update_tkip_key
,
2125 .conf_tx
= iwl_legacy_mac_conf_tx
,
2126 .reset_tsf
= iwl_legacy_mac_reset_tsf
,
2127 .bss_info_changed
= iwl_legacy_mac_bss_info_changed
,
2128 .ampdu_action
= iwl4965_mac_ampdu_action
,
2129 .hw_scan
= iwl_legacy_mac_hw_scan
,
2130 .sta_add
= iwl4965_mac_sta_add
,
2131 .sta_remove
= iwl_legacy_mac_sta_remove
,
2132 .channel_switch
= iwl4965_mac_channel_switch
,
2133 .tx_last_beacon
= iwl_legacy_mac_tx_last_beacon
,
2136 static const struct iwl_ops iwl4965_ops
= {
2137 .lib
= &iwl4965_lib
,
2138 .hcmd
= &iwl4965_hcmd
,
2139 .utils
= &iwl4965_hcmd_utils
,
2140 .led
= &iwl4965_led_ops
,
2141 .legacy
= &iwl4965_legacy_ops
,
2142 .ieee80211_ops
= &iwl4965_hw_ops
,
2145 static struct iwl_base_params iwl4965_base_params
= {
2146 .eeprom_size
= IWL4965_EEPROM_IMG_SIZE
,
2147 .num_of_queues
= IWL49_NUM_QUEUES
,
2148 .num_of_ampdu_queues
= IWL49_NUM_AMPDU_QUEUES
,
2152 .led_compensation
= 61,
2153 .chain_noise_num_beacons
= IWL4965_CAL_NUM_BEACONS
,
2154 .wd_timeout
= IWL_DEF_WD_TIMEOUT
,
2155 .temperature_kelvin
= true,
2156 .ucode_tracing
= true,
2157 .sensitivity_calib_by_driver
= true,
2158 .chain_noise_calib_by_driver
= true,
2161 struct iwl_cfg iwl4965_cfg
= {
2162 .name
= "Intel(R) Wireless WiFi Link 4965AGN",
2163 .fw_name_pre
= IWL4965_FW_PRE
,
2164 .ucode_api_max
= IWL4965_UCODE_API_MAX
,
2165 .ucode_api_min
= IWL4965_UCODE_API_MIN
,
2166 .sku
= IWL_SKU_A
|IWL_SKU_G
|IWL_SKU_N
,
2167 .valid_tx_ant
= ANT_AB
,
2168 .valid_rx_ant
= ANT_ABC
,
2169 .eeprom_ver
= EEPROM_4965_EEPROM_VERSION
,
2170 .eeprom_calib_ver
= EEPROM_4965_TX_POWER_VERSION
,
2171 .ops
= &iwl4965_ops
,
2172 .mod_params
= &iwl4965_mod_params
,
2173 .base_params
= &iwl4965_base_params
,
2174 .led_mode
= IWL_LED_BLINK
,
2176 * Force use of chains B and C for scan RX on 5 GHz band
2177 * because the device has off-channel reception on chain A.
2179 .scan_rx_antennas
[IEEE80211_BAND_5GHZ
] = ANT_BC
,
2182 /* Module firmware */
2183 MODULE_FIRMWARE(IWL4965_MODULE_FIRMWARE(IWL4965_UCODE_API_MAX
));