1 /******************************************************************************
5 * Copyright(c) 2008 - 2010 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/etherdevice.h>
32 #include <linux/sched.h>
33 #include <linux/slab.h>
34 #include <net/mac80211.h>
36 #include "iwl-eeprom.h"
37 #include "iwl-dev.h" /* FIXME: remove */
38 #include "iwl-debug.h"
41 #include "iwl-power.h"
43 #include "iwl-helpers.h"
46 MODULE_DESCRIPTION("iwl core");
47 MODULE_VERSION(IWLWIFI_VERSION);
48 MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
49 MODULE_LICENSE("GPL");
52 * set bt_coex_active to true, uCode will do kill/defer
53 * every time the priority line is asserted (BT is sending signals on the
54 * priority line in the PCIx).
55 * set bt_coex_active to false, uCode will ignore the BT activity and
56 * perform the normal operation
58 * User might experience transmit issue on some platform due to WiFi/BT
59 * co-exist problem. The possible behaviors are:
60 * Able to scan and finding all the available AP
61 * Not able to associate with any AP
62 * On those platforms, WiFi communication can be restored by set
63 * "bt_coex_active" module parameter to "false"
65 * default: bt_coex_active = true (BT_COEX_ENABLE)
67 static bool bt_coex_active = true;
68 module_param(bt_coex_active, bool, S_IRUGO);
69 MODULE_PARM_DESC(bt_coex_active, "enable wifi/bluetooth co-exist");
71 static struct iwl_wimax_coex_event_entry cu_priorities[COEX_NUM_OF_EVENTS] = {
72 {COEX_CU_UNASSOC_IDLE_RP, COEX_CU_UNASSOC_IDLE_WP,
73 0, COEX_UNASSOC_IDLE_FLAGS},
74 {COEX_CU_UNASSOC_MANUAL_SCAN_RP, COEX_CU_UNASSOC_MANUAL_SCAN_WP,
75 0, COEX_UNASSOC_MANUAL_SCAN_FLAGS},
76 {COEX_CU_UNASSOC_AUTO_SCAN_RP, COEX_CU_UNASSOC_AUTO_SCAN_WP,
77 0, COEX_UNASSOC_AUTO_SCAN_FLAGS},
78 {COEX_CU_CALIBRATION_RP, COEX_CU_CALIBRATION_WP,
79 0, COEX_CALIBRATION_FLAGS},
80 {COEX_CU_PERIODIC_CALIBRATION_RP, COEX_CU_PERIODIC_CALIBRATION_WP,
81 0, COEX_PERIODIC_CALIBRATION_FLAGS},
82 {COEX_CU_CONNECTION_ESTAB_RP, COEX_CU_CONNECTION_ESTAB_WP,
83 0, COEX_CONNECTION_ESTAB_FLAGS},
84 {COEX_CU_ASSOCIATED_IDLE_RP, COEX_CU_ASSOCIATED_IDLE_WP,
85 0, COEX_ASSOCIATED_IDLE_FLAGS},
86 {COEX_CU_ASSOC_MANUAL_SCAN_RP, COEX_CU_ASSOC_MANUAL_SCAN_WP,
87 0, COEX_ASSOC_MANUAL_SCAN_FLAGS},
88 {COEX_CU_ASSOC_AUTO_SCAN_RP, COEX_CU_ASSOC_AUTO_SCAN_WP,
89 0, COEX_ASSOC_AUTO_SCAN_FLAGS},
90 {COEX_CU_ASSOC_ACTIVE_LEVEL_RP, COEX_CU_ASSOC_ACTIVE_LEVEL_WP,
91 0, COEX_ASSOC_ACTIVE_LEVEL_FLAGS},
92 {COEX_CU_RF_ON_RP, COEX_CU_RF_ON_WP, 0, COEX_CU_RF_ON_FLAGS},
93 {COEX_CU_RF_OFF_RP, COEX_CU_RF_OFF_WP, 0, COEX_RF_OFF_FLAGS},
94 {COEX_CU_STAND_ALONE_DEBUG_RP, COEX_CU_STAND_ALONE_DEBUG_WP,
95 0, COEX_STAND_ALONE_DEBUG_FLAGS},
96 {COEX_CU_IPAN_ASSOC_LEVEL_RP, COEX_CU_IPAN_ASSOC_LEVEL_WP,
97 0, COEX_IPAN_ASSOC_LEVEL_FLAGS},
98 {COEX_CU_RSRVD1_RP, COEX_CU_RSRVD1_WP, 0, COEX_RSRVD1_FLAGS},
99 {COEX_CU_RSRVD2_RP, COEX_CU_RSRVD2_WP, 0, COEX_RSRVD2_FLAGS}
102 #define IWL_DECLARE_RATE_INFO(r, s, ip, in, rp, rn, pp, np) \
103 [IWL_RATE_##r##M_INDEX] = { IWL_RATE_##r##M_PLCP, \
104 IWL_RATE_SISO_##s##M_PLCP, \
105 IWL_RATE_MIMO2_##s##M_PLCP,\
106 IWL_RATE_MIMO3_##s##M_PLCP,\
107 IWL_RATE_##r##M_IEEE, \
108 IWL_RATE_##ip##M_INDEX, \
109 IWL_RATE_##in##M_INDEX, \
110 IWL_RATE_##rp##M_INDEX, \
111 IWL_RATE_##rn##M_INDEX, \
112 IWL_RATE_##pp##M_INDEX, \
113 IWL_RATE_##np##M_INDEX }
116 EXPORT_SYMBOL(iwl_debug_level);
120 * rate, ht rate, prev rate, next rate, prev tgg rate, next tgg rate
122 * If there isn't a valid next or previous rate then INV is used which
123 * maps to IWL_RATE_INVALID
126 const struct iwl_rate_info iwl_rates[IWL_RATE_COUNT] = {
127 IWL_DECLARE_RATE_INFO(1, INV, INV, 2, INV, 2, INV, 2), /* 1mbps */
128 IWL_DECLARE_RATE_INFO(2, INV, 1, 5, 1, 5, 1, 5), /* 2mbps */
129 IWL_DECLARE_RATE_INFO(5, INV, 2, 6, 2, 11, 2, 11), /*5.5mbps */
130 IWL_DECLARE_RATE_INFO(11, INV, 9, 12, 9, 12, 5, 18), /* 11mbps */
131 IWL_DECLARE_RATE_INFO(6, 6, 5, 9, 5, 11, 5, 11), /* 6mbps */
132 IWL_DECLARE_RATE_INFO(9, 6, 6, 11, 6, 11, 5, 11), /* 9mbps */
133 IWL_DECLARE_RATE_INFO(12, 12, 11, 18, 11, 18, 11, 18), /* 12mbps */
134 IWL_DECLARE_RATE_INFO(18, 18, 12, 24, 12, 24, 11, 24), /* 18mbps */
135 IWL_DECLARE_RATE_INFO(24, 24, 18, 36, 18, 36, 18, 36), /* 24mbps */
136 IWL_DECLARE_RATE_INFO(36, 36, 24, 48, 24, 48, 24, 48), /* 36mbps */
137 IWL_DECLARE_RATE_INFO(48, 48, 36, 54, 36, 54, 36, 54), /* 48mbps */
138 IWL_DECLARE_RATE_INFO(54, 54, 48, INV, 48, INV, 48, INV),/* 54mbps */
139 IWL_DECLARE_RATE_INFO(60, 60, 48, INV, 48, INV, 48, INV),/* 60mbps */
140 /* FIXME:RS: ^^ should be INV (legacy) */
142 EXPORT_SYMBOL(iwl_rates);
144 int iwl_hwrate_to_plcp_idx(u32 rate_n_flags)
149 if (rate_n_flags & RATE_MCS_HT_MSK) {
150 idx = (rate_n_flags & 0xff);
152 if (idx >= IWL_RATE_MIMO3_6M_PLCP)
153 idx = idx - IWL_RATE_MIMO3_6M_PLCP;
154 else if (idx >= IWL_RATE_MIMO2_6M_PLCP)
155 idx = idx - IWL_RATE_MIMO2_6M_PLCP;
157 idx += IWL_FIRST_OFDM_RATE;
158 /* skip 9M not supported in ht*/
159 if (idx >= IWL_RATE_9M_INDEX)
161 if ((idx >= IWL_FIRST_OFDM_RATE) && (idx <= IWL_LAST_OFDM_RATE))
164 /* legacy rate format, search for match in table */
166 for (idx = 0; idx < ARRAY_SIZE(iwl_rates); idx++)
167 if (iwl_rates[idx].plcp == (rate_n_flags & 0xFF))
173 EXPORT_SYMBOL(iwl_hwrate_to_plcp_idx);
175 u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant)
179 for (i = 0; i < RATE_ANT_NUM - 1; i++) {
180 ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
181 if (priv->hw_params.valid_tx_ant & BIT(ind))
186 EXPORT_SYMBOL(iwl_toggle_tx_ant);
188 const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
189 EXPORT_SYMBOL(iwl_bcast_addr);
192 /* This function both allocates and initializes hw and priv. */
193 struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
194 struct ieee80211_ops *hw_ops)
196 struct iwl_priv *priv;
198 /* mac80211 allocates memory for this device instance, including
199 * space for this driver's private structure */
200 struct ieee80211_hw *hw =
201 ieee80211_alloc_hw(sizeof(struct iwl_priv), hw_ops);
203 printk(KERN_ERR "%s: Can not allocate network device\n",
214 EXPORT_SYMBOL(iwl_alloc_all);
216 void iwl_hw_detect(struct iwl_priv *priv)
218 priv->hw_rev = _iwl_read32(priv, CSR_HW_REV);
219 priv->hw_wa_rev = _iwl_read32(priv, CSR_HW_REV_WA_REG);
220 pci_read_config_byte(priv->pci_dev, PCI_REVISION_ID, &priv->rev_id);
222 EXPORT_SYMBOL(iwl_hw_detect);
227 static void iwl_update_qos(struct iwl_priv *priv)
229 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
232 priv->qos_data.def_qos_parm.qos_flags = 0;
234 if (priv->qos_data.qos_active)
235 priv->qos_data.def_qos_parm.qos_flags |=
236 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
238 if (priv->current_ht_config.is_ht)
239 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
241 IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
242 priv->qos_data.qos_active,
243 priv->qos_data.def_qos_parm.qos_flags);
245 iwl_send_cmd_pdu_async(priv, REPLY_QOS_PARAM,
246 sizeof(struct iwl_qosparam_cmd),
247 &priv->qos_data.def_qos_parm, NULL);
250 #define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
251 #define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
252 static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
253 struct ieee80211_sta_ht_cap *ht_info,
254 enum ieee80211_band band)
256 u16 max_bit_rate = 0;
257 u8 rx_chains_num = priv->hw_params.rx_chains_num;
258 u8 tx_chains_num = priv->hw_params.tx_chains_num;
261 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
263 ht_info->ht_supported = true;
265 if (priv->cfg->ht_greenfield_support)
266 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
267 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
268 max_bit_rate = MAX_BIT_RATE_20_MHZ;
269 if (priv->hw_params.ht40_channel & BIT(band)) {
270 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
271 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
272 ht_info->mcs.rx_mask[4] = 0x01;
273 max_bit_rate = MAX_BIT_RATE_40_MHZ;
276 if (priv->cfg->mod_params->amsdu_size_8K)
277 ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU;
279 ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
280 ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
282 ht_info->mcs.rx_mask[0] = 0xFF;
283 if (rx_chains_num >= 2)
284 ht_info->mcs.rx_mask[1] = 0xFF;
285 if (rx_chains_num >= 3)
286 ht_info->mcs.rx_mask[2] = 0xFF;
288 /* Highest supported Rx data rate */
289 max_bit_rate *= rx_chains_num;
290 WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK);
291 ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate);
293 /* Tx MCS capabilities */
294 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
295 if (tx_chains_num != rx_chains_num) {
296 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
297 ht_info->mcs.tx_params |= ((tx_chains_num - 1) <<
298 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
303 * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom
305 int iwlcore_init_geos(struct iwl_priv *priv)
307 struct iwl_channel_info *ch;
308 struct ieee80211_supported_band *sband;
309 struct ieee80211_channel *channels;
310 struct ieee80211_channel *geo_ch;
311 struct ieee80211_rate *rates;
314 if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
315 priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
316 IWL_DEBUG_INFO(priv, "Geography modes already initialized.\n");
317 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
321 channels = kzalloc(sizeof(struct ieee80211_channel) *
322 priv->channel_count, GFP_KERNEL);
326 rates = kzalloc((sizeof(struct ieee80211_rate) * IWL_RATE_COUNT_LEGACY),
333 /* 5.2GHz channels start after the 2.4GHz channels */
334 sband = &priv->bands[IEEE80211_BAND_5GHZ];
335 sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
337 sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
338 sband->n_bitrates = IWL_RATE_COUNT_LEGACY - IWL_FIRST_OFDM_RATE;
340 if (priv->cfg->sku & IWL_SKU_N)
341 iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
342 IEEE80211_BAND_5GHZ);
344 sband = &priv->bands[IEEE80211_BAND_2GHZ];
345 sband->channels = channels;
347 sband->bitrates = rates;
348 sband->n_bitrates = IWL_RATE_COUNT_LEGACY;
350 if (priv->cfg->sku & IWL_SKU_N)
351 iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
352 IEEE80211_BAND_2GHZ);
354 priv->ieee_channels = channels;
355 priv->ieee_rates = rates;
357 for (i = 0; i < priv->channel_count; i++) {
358 ch = &priv->channel_info[i];
360 /* FIXME: might be removed if scan is OK */
361 if (!is_channel_valid(ch))
364 if (is_channel_a_band(ch))
365 sband = &priv->bands[IEEE80211_BAND_5GHZ];
367 sband = &priv->bands[IEEE80211_BAND_2GHZ];
369 geo_ch = &sband->channels[sband->n_channels++];
371 geo_ch->center_freq =
372 ieee80211_channel_to_frequency(ch->channel);
373 geo_ch->max_power = ch->max_power_avg;
374 geo_ch->max_antenna_gain = 0xff;
375 geo_ch->hw_value = ch->channel;
377 if (is_channel_valid(ch)) {
378 if (!(ch->flags & EEPROM_CHANNEL_IBSS))
379 geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
381 if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
382 geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
384 if (ch->flags & EEPROM_CHANNEL_RADAR)
385 geo_ch->flags |= IEEE80211_CHAN_RADAR;
387 geo_ch->flags |= ch->ht40_extension_channel;
389 if (ch->max_power_avg > priv->tx_power_device_lmt)
390 priv->tx_power_device_lmt = ch->max_power_avg;
392 geo_ch->flags |= IEEE80211_CHAN_DISABLED;
395 IWL_DEBUG_INFO(priv, "Channel %d Freq=%d[%sGHz] %s flag=0x%X\n",
396 ch->channel, geo_ch->center_freq,
397 is_channel_a_band(ch) ? "5.2" : "2.4",
398 geo_ch->flags & IEEE80211_CHAN_DISABLED ?
399 "restricted" : "valid",
403 if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
404 priv->cfg->sku & IWL_SKU_A) {
405 IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
406 "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
407 priv->pci_dev->device,
408 priv->pci_dev->subsystem_device);
409 priv->cfg->sku &= ~IWL_SKU_A;
412 IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
413 priv->bands[IEEE80211_BAND_2GHZ].n_channels,
414 priv->bands[IEEE80211_BAND_5GHZ].n_channels);
416 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
420 EXPORT_SYMBOL(iwlcore_init_geos);
423 * iwlcore_free_geos - undo allocations in iwlcore_init_geos
425 void iwlcore_free_geos(struct iwl_priv *priv)
427 kfree(priv->ieee_channels);
428 kfree(priv->ieee_rates);
429 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
431 EXPORT_SYMBOL(iwlcore_free_geos);
434 * iwlcore_rts_tx_cmd_flag: Set rts/cts. 3945 and 4965 only share this
437 void iwlcore_rts_tx_cmd_flag(struct ieee80211_tx_info *info,
440 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) {
441 *tx_flags |= TX_CMD_FLG_RTS_MSK;
442 *tx_flags &= ~TX_CMD_FLG_CTS_MSK;
443 } else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
444 *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
445 *tx_flags |= TX_CMD_FLG_CTS_MSK;
448 EXPORT_SYMBOL(iwlcore_rts_tx_cmd_flag);
450 static bool is_single_rx_stream(struct iwl_priv *priv)
452 return priv->current_ht_config.smps == IEEE80211_SMPS_STATIC ||
453 priv->current_ht_config.single_chain_sufficient;
456 static u8 iwl_is_channel_extension(struct iwl_priv *priv,
457 enum ieee80211_band band,
458 u16 channel, u8 extension_chan_offset)
460 const struct iwl_channel_info *ch_info;
462 ch_info = iwl_get_channel_info(priv, band, channel);
463 if (!is_channel_valid(ch_info))
466 if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
467 return !(ch_info->ht40_extension_channel &
468 IEEE80211_CHAN_NO_HT40PLUS);
469 else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW)
470 return !(ch_info->ht40_extension_channel &
471 IEEE80211_CHAN_NO_HT40MINUS);
476 u8 iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
477 struct ieee80211_sta_ht_cap *sta_ht_inf)
479 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
481 if (!ht_conf->is_ht || !ht_conf->is_40mhz)
484 /* We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
485 * the bit will not set if it is pure 40MHz case
488 if (!sta_ht_inf->ht_supported)
491 #ifdef CONFIG_IWLWIFI_DEBUG
492 if (priv->disable_ht40)
495 return iwl_is_channel_extension(priv, priv->band,
496 le16_to_cpu(priv->staging_rxon.channel),
497 ht_conf->extension_chan_offset);
499 EXPORT_SYMBOL(iwl_is_ht40_tx_allowed);
501 static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
504 u16 beacon_factor = 0;
506 beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
507 new_val = beacon_val / beacon_factor;
510 new_val = max_beacon_val;
515 void iwl_setup_rxon_timing(struct iwl_priv *priv)
518 s32 interval_tm, rem;
520 struct ieee80211_conf *conf = NULL;
523 conf = ieee80211_get_hw_conf(priv->hw);
525 spin_lock_irqsave(&priv->lock, flags);
526 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
527 priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval);
529 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
530 beacon_int = priv->beacon_int;
531 priv->rxon_timing.atim_window = 0;
533 beacon_int = priv->vif->bss_conf.beacon_int;
535 /* TODO: we need to get atim_window from upper stack
536 * for now we set to 0 */
537 priv->rxon_timing.atim_window = 0;
540 beacon_int = iwl_adjust_beacon_interval(beacon_int,
541 priv->hw_params.max_beacon_itrvl * 1024);
542 priv->rxon_timing.beacon_interval = cpu_to_le16(beacon_int);
544 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
545 interval_tm = beacon_int * 1024;
546 rem = do_div(tsf, interval_tm);
547 priv->rxon_timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
549 spin_unlock_irqrestore(&priv->lock, flags);
550 IWL_DEBUG_ASSOC(priv,
551 "beacon interval %d beacon timer %d beacon tim %d\n",
552 le16_to_cpu(priv->rxon_timing.beacon_interval),
553 le32_to_cpu(priv->rxon_timing.beacon_init_val),
554 le16_to_cpu(priv->rxon_timing.atim_window));
556 EXPORT_SYMBOL(iwl_setup_rxon_timing);
558 void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
560 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
563 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
565 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
568 EXPORT_SYMBOL(iwl_set_rxon_hwcrypto);
571 * iwl_check_rxon_cmd - validate RXON structure is valid
573 * NOTE: This is really only useful during development and can eventually
574 * be #ifdef'd out once the driver is stable and folks aren't actively
577 int iwl_check_rxon_cmd(struct iwl_priv *priv)
581 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
583 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
584 error |= le32_to_cpu(rxon->flags &
585 (RXON_FLG_TGJ_NARROW_BAND_MSK |
586 RXON_FLG_RADAR_DETECT_MSK));
588 IWL_WARN(priv, "check 24G fields %d | %d\n",
591 error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
592 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
594 IWL_WARN(priv, "check 52 fields %d | %d\n",
596 error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
598 IWL_WARN(priv, "check 52 CCK %d | %d\n",
601 error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
603 IWL_WARN(priv, "check mac addr %d | %d\n", counter++, error);
605 /* make sure basic rates 6Mbps and 1Mbps are supported */
606 error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
607 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
609 IWL_WARN(priv, "check basic rate %d | %d\n", counter++, error);
611 error |= (le16_to_cpu(rxon->assoc_id) > 2007);
613 IWL_WARN(priv, "check assoc id %d | %d\n", counter++, error);
615 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
616 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
618 IWL_WARN(priv, "check CCK and short slot %d | %d\n",
621 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
622 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
624 IWL_WARN(priv, "check CCK & auto detect %d | %d\n",
627 error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
628 RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
630 IWL_WARN(priv, "check TGG and auto detect %d | %d\n",
634 IWL_WARN(priv, "Tuning to channel %d\n",
635 le16_to_cpu(rxon->channel));
638 IWL_ERR(priv, "Not a valid iwl_rxon_assoc_cmd field values\n");
643 EXPORT_SYMBOL(iwl_check_rxon_cmd);
646 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
647 * @priv: staging_rxon is compared to active_rxon
649 * If the RXON structure is changing enough to require a new tune,
650 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
651 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
653 int iwl_full_rxon_required(struct iwl_priv *priv)
656 /* These items are only settable from the full RXON command */
657 if (!(iwl_is_associated(priv)) ||
658 compare_ether_addr(priv->staging_rxon.bssid_addr,
659 priv->active_rxon.bssid_addr) ||
660 compare_ether_addr(priv->staging_rxon.node_addr,
661 priv->active_rxon.node_addr) ||
662 compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
663 priv->active_rxon.wlap_bssid_addr) ||
664 (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
665 (priv->staging_rxon.channel != priv->active_rxon.channel) ||
666 (priv->staging_rxon.air_propagation !=
667 priv->active_rxon.air_propagation) ||
668 (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
669 priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
670 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
671 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
672 (priv->staging_rxon.ofdm_ht_triple_stream_basic_rates !=
673 priv->active_rxon.ofdm_ht_triple_stream_basic_rates) ||
674 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
677 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
678 * be updated with the RXON_ASSOC command -- however only some
679 * flag transitions are allowed using RXON_ASSOC */
681 /* Check if we are not switching bands */
682 if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
683 (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
686 /* Check if we are switching association toggle */
687 if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
688 (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
693 EXPORT_SYMBOL(iwl_full_rxon_required);
695 u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv)
698 * Assign the lowest rate -- should really get this from
699 * the beacon skb from mac80211.
701 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
702 return IWL_RATE_1M_PLCP;
704 return IWL_RATE_6M_PLCP;
706 EXPORT_SYMBOL(iwl_rate_get_lowest_plcp);
708 void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
710 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
712 if (!ht_conf->is_ht) {
713 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
714 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
715 RXON_FLG_HT40_PROT_MSK |
716 RXON_FLG_HT_PROT_MSK);
720 /* FIXME: if the definition of ht_protection changed, the "translation"
721 * will be needed for rxon->flags
723 rxon->flags |= cpu_to_le32(ht_conf->ht_protection << RXON_FLG_HT_OPERATING_MODE_POS);
725 /* Set up channel bandwidth:
726 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
727 /* clear the HT channel mode before set the mode */
728 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
729 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
730 if (iwl_is_ht40_tx_allowed(priv, NULL)) {
732 if (ht_conf->ht_protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
733 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
734 /* Note: control channel is opposite of extension channel */
735 switch (ht_conf->extension_chan_offset) {
736 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
737 rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
739 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
740 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
744 /* Note: control channel is opposite of extension channel */
745 switch (ht_conf->extension_chan_offset) {
746 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
747 rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
748 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
750 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
751 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
752 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
754 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
756 /* channel location only valid if in Mixed mode */
757 IWL_ERR(priv, "invalid extension channel offset\n");
762 rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
765 if (priv->cfg->ops->hcmd->set_rxon_chain)
766 priv->cfg->ops->hcmd->set_rxon_chain(priv);
768 IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
769 "extension channel offset 0x%x\n",
770 le32_to_cpu(rxon->flags), ht_conf->ht_protection,
771 ht_conf->extension_chan_offset);
774 EXPORT_SYMBOL(iwl_set_rxon_ht);
776 #define IWL_NUM_RX_CHAINS_MULTIPLE 3
777 #define IWL_NUM_RX_CHAINS_SINGLE 2
778 #define IWL_NUM_IDLE_CHAINS_DUAL 2
779 #define IWL_NUM_IDLE_CHAINS_SINGLE 1
782 * Determine how many receiver/antenna chains to use.
784 * More provides better reception via diversity. Fewer saves power
785 * at the expense of throughput, but only when not in powersave to
788 * MIMO (dual stream) requires at least 2, but works better with 3.
789 * This does not determine *which* chains to use, just how many.
791 static int iwl_get_active_rx_chain_count(struct iwl_priv *priv)
793 /* # of Rx chains to use when expecting MIMO. */
794 if (is_single_rx_stream(priv))
795 return IWL_NUM_RX_CHAINS_SINGLE;
797 return IWL_NUM_RX_CHAINS_MULTIPLE;
801 * When we are in power saving mode, unless device support spatial
802 * multiplexing power save, use the active count for rx chain count.
804 static int iwl_get_idle_rx_chain_count(struct iwl_priv *priv, int active_cnt)
806 /* # Rx chains when idling, depending on SMPS mode */
807 switch (priv->current_ht_config.smps) {
808 case IEEE80211_SMPS_STATIC:
809 case IEEE80211_SMPS_DYNAMIC:
810 return IWL_NUM_IDLE_CHAINS_SINGLE;
811 case IEEE80211_SMPS_OFF:
814 WARN(1, "invalid SMPS mode %d",
815 priv->current_ht_config.smps);
821 static u8 iwl_count_chain_bitmap(u32 chain_bitmap)
824 res = (chain_bitmap & BIT(0)) >> 0;
825 res += (chain_bitmap & BIT(1)) >> 1;
826 res += (chain_bitmap & BIT(2)) >> 2;
827 res += (chain_bitmap & BIT(3)) >> 3;
832 * iwl_set_rxon_chain - Set up Rx chain usage in "staging" RXON image
834 * Selects how many and which Rx receivers/antennas/chains to use.
835 * This should not be used for scan command ... it puts data in wrong place.
837 void iwl_set_rxon_chain(struct iwl_priv *priv)
839 bool is_single = is_single_rx_stream(priv);
840 bool is_cam = !test_bit(STATUS_POWER_PMI, &priv->status);
841 u8 idle_rx_cnt, active_rx_cnt, valid_rx_cnt;
845 /* Tell uCode which antennas are actually connected.
846 * Before first association, we assume all antennas are connected.
847 * Just after first association, iwl_chain_noise_calibration()
848 * checks which antennas actually *are* connected. */
849 if (priv->chain_noise_data.active_chains)
850 active_chains = priv->chain_noise_data.active_chains;
852 active_chains = priv->hw_params.valid_rx_ant;
854 rx_chain = active_chains << RXON_RX_CHAIN_VALID_POS;
856 /* How many receivers should we use? */
857 active_rx_cnt = iwl_get_active_rx_chain_count(priv);
858 idle_rx_cnt = iwl_get_idle_rx_chain_count(priv, active_rx_cnt);
861 /* correct rx chain count according hw settings
862 * and chain noise calibration
864 valid_rx_cnt = iwl_count_chain_bitmap(active_chains);
865 if (valid_rx_cnt < active_rx_cnt)
866 active_rx_cnt = valid_rx_cnt;
868 if (valid_rx_cnt < idle_rx_cnt)
869 idle_rx_cnt = valid_rx_cnt;
871 rx_chain |= active_rx_cnt << RXON_RX_CHAIN_MIMO_CNT_POS;
872 rx_chain |= idle_rx_cnt << RXON_RX_CHAIN_CNT_POS;
874 priv->staging_rxon.rx_chain = cpu_to_le16(rx_chain);
876 if (!is_single && (active_rx_cnt >= IWL_NUM_RX_CHAINS_SINGLE) && is_cam)
877 priv->staging_rxon.rx_chain |= RXON_RX_CHAIN_MIMO_FORCE_MSK;
879 priv->staging_rxon.rx_chain &= ~RXON_RX_CHAIN_MIMO_FORCE_MSK;
881 IWL_DEBUG_ASSOC(priv, "rx_chain=0x%X active=%d idle=%d\n",
882 priv->staging_rxon.rx_chain,
883 active_rx_cnt, idle_rx_cnt);
885 WARN_ON(active_rx_cnt == 0 || idle_rx_cnt == 0 ||
886 active_rx_cnt < idle_rx_cnt);
888 EXPORT_SYMBOL(iwl_set_rxon_chain);
891 * iwl_set_rxon_channel - Set the phymode and channel values in staging RXON
892 * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
893 * @channel: Any channel valid for the requested phymode
895 * In addition to setting the staging RXON, priv->phymode is also set.
897 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
898 * in the staging RXON flag structure based on the phymode
900 int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch)
902 enum ieee80211_band band = ch->band;
903 u16 channel = ieee80211_frequency_to_channel(ch->center_freq);
905 if (!iwl_get_channel_info(priv, band, channel)) {
906 IWL_DEBUG_INFO(priv, "Could not set channel to %d [%d]\n",
911 if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
912 (priv->band == band))
915 priv->staging_rxon.channel = cpu_to_le16(channel);
916 if (band == IEEE80211_BAND_5GHZ)
917 priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
919 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
923 IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
927 EXPORT_SYMBOL(iwl_set_rxon_channel);
929 void iwl_set_flags_for_band(struct iwl_priv *priv,
930 enum ieee80211_band band)
932 if (band == IEEE80211_BAND_5GHZ) {
933 priv->staging_rxon.flags &=
934 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
936 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
938 /* Copied from iwl_post_associate() */
939 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
940 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
942 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
944 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
945 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
947 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
948 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
949 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
954 * initialize rxon structure with default values from eeprom
956 void iwl_connection_init_rx_config(struct iwl_priv *priv, int mode)
958 const struct iwl_channel_info *ch_info;
960 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
963 case NL80211_IFTYPE_AP:
964 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
967 case NL80211_IFTYPE_STATION:
968 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
969 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
972 case NL80211_IFTYPE_ADHOC:
973 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
974 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
975 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
976 RXON_FILTER_ACCEPT_GRP_MSK;
980 IWL_ERR(priv, "Unsupported interface type %d\n", mode);
985 /* TODO: Figure out when short_preamble would be set and cache from
987 if (!hw_to_local(priv->hw)->short_preamble)
988 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
990 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
993 ch_info = iwl_get_channel_info(priv, priv->band,
994 le16_to_cpu(priv->active_rxon.channel));
997 ch_info = &priv->channel_info[0];
999 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
1000 priv->band = ch_info->band;
1002 iwl_set_flags_for_band(priv, priv->band);
1004 priv->staging_rxon.ofdm_basic_rates =
1005 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
1006 priv->staging_rxon.cck_basic_rates =
1007 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
1009 /* clear both MIX and PURE40 mode flag */
1010 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
1011 RXON_FLG_CHANNEL_MODE_PURE_40);
1012 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
1013 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
1014 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
1015 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
1016 priv->staging_rxon.ofdm_ht_triple_stream_basic_rates = 0xff;
1018 EXPORT_SYMBOL(iwl_connection_init_rx_config);
1020 static void iwl_set_rate(struct iwl_priv *priv)
1022 const struct ieee80211_supported_band *hw = NULL;
1023 struct ieee80211_rate *rate;
1026 hw = iwl_get_hw_mode(priv, priv->band);
1028 IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
1032 priv->active_rate = 0;
1034 for (i = 0; i < hw->n_bitrates; i++) {
1035 rate = &(hw->bitrates[i]);
1036 if (rate->hw_value < IWL_RATE_COUNT_LEGACY)
1037 priv->active_rate |= (1 << rate->hw_value);
1040 IWL_DEBUG_RATE(priv, "Set active_rate = %0x\n", priv->active_rate);
1042 priv->staging_rxon.cck_basic_rates =
1043 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
1045 priv->staging_rxon.ofdm_basic_rates =
1046 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
1049 void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
1051 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1052 struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
1053 struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
1055 if (priv->switch_rxon.switch_in_progress) {
1056 if (!le32_to_cpu(csa->status) &&
1057 (csa->channel == priv->switch_rxon.channel)) {
1058 rxon->channel = csa->channel;
1059 priv->staging_rxon.channel = csa->channel;
1060 IWL_DEBUG_11H(priv, "CSA notif: channel %d\n",
1061 le16_to_cpu(csa->channel));
1063 IWL_ERR(priv, "CSA notif (fail) : channel %d\n",
1064 le16_to_cpu(csa->channel));
1066 priv->switch_rxon.switch_in_progress = false;
1069 EXPORT_SYMBOL(iwl_rx_csa);
1071 #ifdef CONFIG_IWLWIFI_DEBUG
1072 void iwl_print_rx_config_cmd(struct iwl_priv *priv)
1074 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
1076 IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
1077 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
1078 IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
1079 IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
1080 IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
1081 le32_to_cpu(rxon->filter_flags));
1082 IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
1083 IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
1084 rxon->ofdm_basic_rates);
1085 IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
1086 IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
1087 IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
1088 IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
1090 EXPORT_SYMBOL(iwl_print_rx_config_cmd);
1093 * iwl_irq_handle_error - called for HW or SW error interrupt from card
1095 void iwl_irq_handle_error(struct iwl_priv *priv)
1097 /* Set the FW error flag -- cleared on iwl_down */
1098 set_bit(STATUS_FW_ERROR, &priv->status);
1100 /* Cancel currently queued command. */
1101 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1103 priv->cfg->ops->lib->dump_nic_error_log(priv);
1104 if (priv->cfg->ops->lib->dump_csr)
1105 priv->cfg->ops->lib->dump_csr(priv);
1106 if (priv->cfg->ops->lib->dump_fh)
1107 priv->cfg->ops->lib->dump_fh(priv, NULL, false);
1108 priv->cfg->ops->lib->dump_nic_event_log(priv, false, NULL, false);
1109 #ifdef CONFIG_IWLWIFI_DEBUG
1110 if (iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS)
1111 iwl_print_rx_config_cmd(priv);
1114 wake_up_interruptible(&priv->wait_command_queue);
1116 /* Keep the restart process from trying to send host
1117 * commands by clearing the INIT status bit */
1118 clear_bit(STATUS_READY, &priv->status);
1120 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
1121 IWL_DEBUG(priv, IWL_DL_FW_ERRORS,
1122 "Restarting adapter due to uCode error.\n");
1124 if (priv->cfg->mod_params->restart_fw)
1125 queue_work(priv->workqueue, &priv->restart);
1128 EXPORT_SYMBOL(iwl_irq_handle_error);
1130 static int iwl_apm_stop_master(struct iwl_priv *priv)
1134 /* stop device's busmaster DMA activity */
1135 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
1137 ret = iwl_poll_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_MASTER_DISABLED,
1138 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
1140 IWL_WARN(priv, "Master Disable Timed Out, 100 usec\n");
1142 IWL_DEBUG_INFO(priv, "stop master\n");
1147 void iwl_apm_stop(struct iwl_priv *priv)
1149 IWL_DEBUG_INFO(priv, "Stop card, put in low power state\n");
1151 /* Stop device's DMA activity */
1152 iwl_apm_stop_master(priv);
1154 /* Reset the entire device */
1155 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
1160 * Clear "initialization complete" bit to move adapter from
1161 * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
1163 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
1165 EXPORT_SYMBOL(iwl_apm_stop);
1169 * Start up NIC's basic functionality after it has been reset
1170 * (e.g. after platform boot, or shutdown via iwl_apm_stop())
1171 * NOTE: This does not load uCode nor start the embedded processor
1173 int iwl_apm_init(struct iwl_priv *priv)
1178 IWL_DEBUG_INFO(priv, "Init card's basic functions\n");
1181 * Use "set_bit" below rather than "write", to preserve any hardware
1182 * bits already set by default after reset.
1185 /* Disable L0S exit timer (platform NMI Work/Around) */
1186 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
1187 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
1190 * Disable L0s without affecting L1;
1191 * don't wait for ICH L0s (ICH bug W/A)
1193 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
1194 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
1196 /* Set FH wait threshold to maximum (HW error during stress W/A) */
1197 iwl_set_bit(priv, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL);
1200 * Enable HAP INTA (interrupt from management bus) to
1201 * wake device's PCI Express link L1a -> L0s
1202 * NOTE: This is no-op for 3945 (non-existant bit)
1204 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
1205 CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
1208 * HW bug W/A for instability in PCIe bus L0->L0S->L1 transition.
1209 * Check if BIOS (or OS) enabled L1-ASPM on this device.
1210 * If so (likely), disable L0S, so device moves directly L0->L1;
1211 * costs negligible amount of power savings.
1212 * If not (unlikely), enable L0S, so there is at least some
1213 * power savings, even without L1.
1215 if (priv->cfg->set_l0s) {
1216 lctl = iwl_pcie_link_ctl(priv);
1217 if ((lctl & PCI_CFG_LINK_CTRL_VAL_L1_EN) ==
1218 PCI_CFG_LINK_CTRL_VAL_L1_EN) {
1219 /* L1-ASPM enabled; disable(!) L0S */
1220 iwl_set_bit(priv, CSR_GIO_REG,
1221 CSR_GIO_REG_VAL_L0S_ENABLED);
1222 IWL_DEBUG_POWER(priv, "L1 Enabled; Disabling L0S\n");
1224 /* L1-ASPM disabled; enable(!) L0S */
1225 iwl_clear_bit(priv, CSR_GIO_REG,
1226 CSR_GIO_REG_VAL_L0S_ENABLED);
1227 IWL_DEBUG_POWER(priv, "L1 Disabled; Enabling L0S\n");
1231 /* Configure analog phase-lock-loop before activating to D0A */
1232 if (priv->cfg->pll_cfg_val)
1233 iwl_set_bit(priv, CSR_ANA_PLL_CFG, priv->cfg->pll_cfg_val);
1236 * Set "initialization complete" bit to move adapter from
1237 * D0U* --> D0A* (powered-up active) state.
1239 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
1242 * Wait for clock stabilization; once stabilized, access to
1243 * device-internal resources is supported, e.g. iwl_write_prph()
1244 * and accesses to uCode SRAM.
1246 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
1247 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
1248 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
1250 IWL_DEBUG_INFO(priv, "Failed to init the card\n");
1255 * Enable DMA and BSM (if used) clocks, wait for them to stabilize.
1256 * BSM (Boostrap State Machine) is only in 3945 and 4965;
1257 * later devices (i.e. 5000 and later) have non-volatile SRAM,
1258 * and don't need BSM to restore data after power-saving sleep.
1260 * Write to "CLK_EN_REG"; "1" bits enable clocks, while "0" bits
1261 * do not disable clocks. This preserves any hardware bits already
1262 * set by default in "CLK_CTRL_REG" after reset.
1264 if (priv->cfg->use_bsm)
1265 iwl_write_prph(priv, APMG_CLK_EN_REG,
1266 APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT);
1268 iwl_write_prph(priv, APMG_CLK_EN_REG,
1269 APMG_CLK_VAL_DMA_CLK_RQT);
1272 /* Disable L1-Active */
1273 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
1274 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
1279 EXPORT_SYMBOL(iwl_apm_init);
1283 void iwl_configure_filter(struct ieee80211_hw *hw,
1284 unsigned int changed_flags,
1285 unsigned int *total_flags,
1288 struct iwl_priv *priv = hw->priv;
1289 __le32 *filter_flags = &priv->staging_rxon.filter_flags;
1291 IWL_DEBUG_MAC80211(priv, "Enter: changed: 0x%x, total: 0x%x\n",
1292 changed_flags, *total_flags);
1294 if (changed_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS)) {
1295 if (*total_flags & (FIF_OTHER_BSS | FIF_PROMISC_IN_BSS))
1296 *filter_flags |= RXON_FILTER_PROMISC_MSK;
1298 *filter_flags &= ~RXON_FILTER_PROMISC_MSK;
1300 if (changed_flags & FIF_ALLMULTI) {
1301 if (*total_flags & FIF_ALLMULTI)
1302 *filter_flags |= RXON_FILTER_ACCEPT_GRP_MSK;
1304 *filter_flags &= ~RXON_FILTER_ACCEPT_GRP_MSK;
1306 if (changed_flags & FIF_CONTROL) {
1307 if (*total_flags & FIF_CONTROL)
1308 *filter_flags |= RXON_FILTER_CTL2HOST_MSK;
1310 *filter_flags &= ~RXON_FILTER_CTL2HOST_MSK;
1312 if (changed_flags & FIF_BCN_PRBRESP_PROMISC) {
1313 if (*total_flags & FIF_BCN_PRBRESP_PROMISC)
1314 *filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
1316 *filter_flags &= ~RXON_FILTER_BCON_AWARE_MSK;
1319 /* We avoid iwl_commit_rxon here to commit the new filter flags
1320 * since mac80211 will call ieee80211_hw_config immediately.
1321 * (mc_list is not supported at this time). Otherwise, we need to
1322 * queue a background iwl_commit_rxon work.
1325 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI | FIF_PROMISC_IN_BSS |
1326 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
1328 EXPORT_SYMBOL(iwl_configure_filter);
1330 int iwl_set_hw_params(struct iwl_priv *priv)
1332 priv->hw_params.max_rxq_size = RX_QUEUE_SIZE;
1333 priv->hw_params.max_rxq_log = RX_QUEUE_SIZE_LOG;
1334 if (priv->cfg->mod_params->amsdu_size_8K)
1335 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_8K);
1337 priv->hw_params.rx_page_order = get_order(IWL_RX_BUF_SIZE_4K);
1339 priv->hw_params.max_beacon_itrvl = IWL_MAX_UCODE_BEACON_INTERVAL;
1341 if (priv->cfg->mod_params->disable_11n)
1342 priv->cfg->sku &= ~IWL_SKU_N;
1344 /* Device-specific setup */
1345 return priv->cfg->ops->lib->set_hw_params(priv);
1347 EXPORT_SYMBOL(iwl_set_hw_params);
1349 int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
1352 s8 prev_tx_power = priv->tx_power_user_lmt;
1354 if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
1356 "Requested user TXPOWER %d below lower limit %d.\n",
1358 IWLAGN_TX_POWER_TARGET_POWER_MIN);
1362 if (tx_power > priv->tx_power_device_lmt) {
1364 "Requested user TXPOWER %d above upper limit %d.\n",
1365 tx_power, priv->tx_power_device_lmt);
1369 if (priv->tx_power_user_lmt != tx_power)
1372 /* if nic is not up don't send command */
1373 if (iwl_is_ready_rf(priv)) {
1374 priv->tx_power_user_lmt = tx_power;
1375 if (force && priv->cfg->ops->lib->send_tx_power)
1376 ret = priv->cfg->ops->lib->send_tx_power(priv);
1377 else if (!priv->cfg->ops->lib->send_tx_power)
1380 * if fail to set tx_power, restore the orig. tx power
1383 priv->tx_power_user_lmt = prev_tx_power;
1387 * Even this is an async host command, the command
1388 * will always report success from uCode
1389 * So once driver can placing the command into the queue
1390 * successfully, driver can use priv->tx_power_user_lmt
1391 * to reflect the current tx power
1395 EXPORT_SYMBOL(iwl_set_tx_power);
1397 irqreturn_t iwl_isr_legacy(int irq, void *data)
1399 struct iwl_priv *priv = data;
1400 u32 inta, inta_mask;
1402 unsigned long flags;
1406 spin_lock_irqsave(&priv->lock, flags);
1408 /* Disable (but don't clear!) interrupts here to avoid
1409 * back-to-back ISRs and sporadic interrupts from our NIC.
1410 * If we have something to service, the tasklet will re-enable ints.
1411 * If we *don't* have something, we'll re-enable before leaving here. */
1412 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1413 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
1415 /* Discover which interrupts are active/pending */
1416 inta = iwl_read32(priv, CSR_INT);
1417 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1419 /* Ignore interrupt if there's nothing in NIC to service.
1420 * This may be due to IRQ shared with another device,
1421 * or due to sporadic interrupts thrown from our NIC. */
1422 if (!inta && !inta_fh) {
1423 IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0, inta_fh == 0\n");
1427 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
1428 /* Hardware disappeared. It might have already raised
1430 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
1434 IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1435 inta, inta_mask, inta_fh);
1437 inta &= ~CSR_INT_BIT_SCD;
1439 /* iwl_irq_tasklet() will service interrupts and re-enable them */
1440 if (likely(inta || inta_fh))
1441 tasklet_schedule(&priv->irq_tasklet);
1444 spin_unlock_irqrestore(&priv->lock, flags);
1448 /* re-enable interrupts here since we don't have anything to service. */
1449 /* only Re-enable if diabled by irq */
1450 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1451 iwl_enable_interrupts(priv);
1452 spin_unlock_irqrestore(&priv->lock, flags);
1455 EXPORT_SYMBOL(iwl_isr_legacy);
1457 void iwl_send_bt_config(struct iwl_priv *priv)
1459 struct iwl_bt_cmd bt_cmd = {
1460 .lead_time = BT_LEAD_TIME_DEF,
1461 .max_kill = BT_MAX_KILL_DEF,
1466 if (!bt_coex_active)
1467 bt_cmd.flags = BT_COEX_DISABLE;
1469 bt_cmd.flags = BT_COEX_ENABLE;
1471 IWL_DEBUG_INFO(priv, "BT coex %s\n",
1472 (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
1474 if (iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
1475 sizeof(struct iwl_bt_cmd), &bt_cmd))
1476 IWL_ERR(priv, "failed to send BT Coex Config\n");
1478 EXPORT_SYMBOL(iwl_send_bt_config);
1480 int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
1482 struct iwl_statistics_cmd statistics_cmd = {
1483 .configuration_flags =
1484 clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
1487 if (flags & CMD_ASYNC)
1488 return iwl_send_cmd_pdu_async(priv, REPLY_STATISTICS_CMD,
1489 sizeof(struct iwl_statistics_cmd),
1490 &statistics_cmd, NULL);
1492 return iwl_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
1493 sizeof(struct iwl_statistics_cmd),
1496 EXPORT_SYMBOL(iwl_send_statistics_request);
1499 * iwl_verify_inst_sparse - verify runtime uCode image in card vs. host,
1500 * using sample data 100 bytes apart. If these sample points are good,
1501 * it's a pretty good bet that everything between them is good, too.
1503 static int iwlcore_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
1510 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
1512 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
1513 /* read data comes through single port, auto-incr addr */
1514 /* NOTE: Use the debugless read so we don't flood kernel log
1515 * if IWL_DL_IO is set */
1516 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
1517 i + IWL49_RTC_INST_LOWER_BOUND);
1518 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
1519 if (val != le32_to_cpu(*image)) {
1531 * iwlcore_verify_inst_full - verify runtime uCode image in card vs. host,
1532 * looking at all data.
1534 static int iwl_verify_inst_full(struct iwl_priv *priv, __le32 *image,
1542 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
1544 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
1545 IWL49_RTC_INST_LOWER_BOUND);
1548 for (; len > 0; len -= sizeof(u32), image++) {
1549 /* read data comes through single port, auto-incr addr */
1550 /* NOTE: Use the debugless read so we don't flood kernel log
1551 * if IWL_DL_IO is set */
1552 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
1553 if (val != le32_to_cpu(*image)) {
1554 IWL_ERR(priv, "uCode INST section is invalid at "
1555 "offset 0x%x, is 0x%x, s/b 0x%x\n",
1556 save_len - len, val, le32_to_cpu(*image));
1565 IWL_DEBUG_INFO(priv,
1566 "ucode image in INSTRUCTION memory is good\n");
1572 * iwl_verify_ucode - determine which instruction image is in SRAM,
1573 * and verify its contents
1575 int iwl_verify_ucode(struct iwl_priv *priv)
1582 image = (__le32 *)priv->ucode_boot.v_addr;
1583 len = priv->ucode_boot.len;
1584 ret = iwlcore_verify_inst_sparse(priv, image, len);
1586 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
1590 /* Try initialize */
1591 image = (__le32 *)priv->ucode_init.v_addr;
1592 len = priv->ucode_init.len;
1593 ret = iwlcore_verify_inst_sparse(priv, image, len);
1595 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
1599 /* Try runtime/protocol */
1600 image = (__le32 *)priv->ucode_code.v_addr;
1601 len = priv->ucode_code.len;
1602 ret = iwlcore_verify_inst_sparse(priv, image, len);
1604 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
1608 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
1610 /* Since nothing seems to match, show first several data entries in
1611 * instruction SRAM, so maybe visual inspection will give a clue.
1612 * Selection of bootstrap image (vs. other images) is arbitrary. */
1613 image = (__le32 *)priv->ucode_boot.v_addr;
1614 len = priv->ucode_boot.len;
1615 ret = iwl_verify_inst_full(priv, image, len);
1619 EXPORT_SYMBOL(iwl_verify_ucode);
1622 void iwl_rf_kill_ct_config(struct iwl_priv *priv)
1624 struct iwl_ct_kill_config cmd;
1625 struct iwl_ct_kill_throttling_config adv_cmd;
1626 unsigned long flags;
1629 spin_lock_irqsave(&priv->lock, flags);
1630 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
1631 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
1632 spin_unlock_irqrestore(&priv->lock, flags);
1633 priv->thermal_throttle.ct_kill_toggle = false;
1635 if (priv->cfg->support_ct_kill_exit) {
1636 adv_cmd.critical_temperature_enter =
1637 cpu_to_le32(priv->hw_params.ct_kill_threshold);
1638 adv_cmd.critical_temperature_exit =
1639 cpu_to_le32(priv->hw_params.ct_kill_exit_threshold);
1641 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
1642 sizeof(adv_cmd), &adv_cmd);
1644 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
1646 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
1648 "critical temperature enter is %d,"
1650 priv->hw_params.ct_kill_threshold,
1651 priv->hw_params.ct_kill_exit_threshold);
1653 cmd.critical_temperature_R =
1654 cpu_to_le32(priv->hw_params.ct_kill_threshold);
1656 ret = iwl_send_cmd_pdu(priv, REPLY_CT_KILL_CONFIG_CMD,
1659 IWL_ERR(priv, "REPLY_CT_KILL_CONFIG_CMD failed\n");
1661 IWL_DEBUG_INFO(priv, "REPLY_CT_KILL_CONFIG_CMD "
1663 "critical temperature is %d\n",
1664 priv->hw_params.ct_kill_threshold);
1667 EXPORT_SYMBOL(iwl_rf_kill_ct_config);
1673 * Use: Sets the device's internal card state to enable, disable, or halt
1675 * When in the 'enable' state the card operates as normal.
1676 * When in the 'disable' state, the card enters into a low power mode.
1677 * When in the 'halt' state, the card is shut down and must be fully
1678 * restarted to come back on.
1680 int iwl_send_card_state(struct iwl_priv *priv, u32 flags, u8 meta_flag)
1682 struct iwl_host_cmd cmd = {
1683 .id = REPLY_CARD_STATE_CMD,
1689 return iwl_send_cmd(priv, &cmd);
1692 void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
1693 struct iwl_rx_mem_buffer *rxb)
1695 #ifdef CONFIG_IWLWIFI_DEBUG
1696 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1697 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
1698 IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
1699 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1702 EXPORT_SYMBOL(iwl_rx_pm_sleep_notif);
1704 void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
1705 struct iwl_rx_mem_buffer *rxb)
1707 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1708 u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
1709 IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
1710 "notification for %s:\n", len,
1711 get_cmd_string(pkt->hdr.cmd));
1712 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, len);
1714 EXPORT_SYMBOL(iwl_rx_pm_debug_statistics_notif);
1716 void iwl_rx_reply_error(struct iwl_priv *priv,
1717 struct iwl_rx_mem_buffer *rxb)
1719 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1721 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
1722 "seq 0x%04X ser 0x%08X\n",
1723 le32_to_cpu(pkt->u.err_resp.error_type),
1724 get_cmd_string(pkt->u.err_resp.cmd_id),
1725 pkt->u.err_resp.cmd_id,
1726 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
1727 le32_to_cpu(pkt->u.err_resp.error_info));
1729 EXPORT_SYMBOL(iwl_rx_reply_error);
1731 void iwl_clear_isr_stats(struct iwl_priv *priv)
1733 memset(&priv->isr_stats, 0, sizeof(priv->isr_stats));
1736 int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
1737 const struct ieee80211_tx_queue_params *params)
1739 struct iwl_priv *priv = hw->priv;
1740 unsigned long flags;
1743 IWL_DEBUG_MAC80211(priv, "enter\n");
1745 if (!iwl_is_ready_rf(priv)) {
1746 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
1750 if (queue >= AC_NUM) {
1751 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
1755 q = AC_NUM - 1 - queue;
1757 spin_lock_irqsave(&priv->lock, flags);
1759 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
1760 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
1761 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
1762 priv->qos_data.def_qos_parm.ac[q].edca_txop =
1763 cpu_to_le16((params->txop * 32));
1765 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
1767 spin_unlock_irqrestore(&priv->lock, flags);
1769 IWL_DEBUG_MAC80211(priv, "leave\n");
1772 EXPORT_SYMBOL(iwl_mac_conf_tx);
1774 static void iwl_ht_conf(struct iwl_priv *priv,
1775 struct ieee80211_bss_conf *bss_conf)
1777 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
1778 struct ieee80211_sta *sta;
1780 IWL_DEBUG_MAC80211(priv, "enter:\n");
1782 if (!ht_conf->is_ht)
1785 ht_conf->ht_protection =
1786 bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
1787 ht_conf->non_GF_STA_present =
1788 !!(bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1790 ht_conf->single_chain_sufficient = false;
1792 switch (priv->iw_mode) {
1793 case NL80211_IFTYPE_STATION:
1795 sta = ieee80211_find_sta(priv->vif, priv->bssid);
1797 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1800 maxstreams = (ht_cap->mcs.tx_params &
1801 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
1802 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1805 if ((ht_cap->mcs.rx_mask[1] == 0) &&
1806 (ht_cap->mcs.rx_mask[2] == 0))
1807 ht_conf->single_chain_sufficient = true;
1808 if (maxstreams <= 1)
1809 ht_conf->single_chain_sufficient = true;
1812 * If at all, this can only happen through a race
1813 * when the AP disconnects us while we're still
1814 * setting up the connection, in that case mac80211
1815 * will soon tell us about that.
1817 ht_conf->single_chain_sufficient = true;
1821 case NL80211_IFTYPE_ADHOC:
1822 ht_conf->single_chain_sufficient = true;
1828 IWL_DEBUG_MAC80211(priv, "leave\n");
1831 static inline void iwl_set_no_assoc(struct iwl_priv *priv)
1834 iwl_led_disassociate(priv);
1836 * inform the ucode that there is no longer an
1837 * association and that no more packets should be
1840 priv->staging_rxon.filter_flags &=
1841 ~RXON_FILTER_ASSOC_MSK;
1842 priv->staging_rxon.assoc_id = 0;
1843 iwlcore_commit_rxon(priv);
1846 void iwl_bss_info_changed(struct ieee80211_hw *hw,
1847 struct ieee80211_vif *vif,
1848 struct ieee80211_bss_conf *bss_conf,
1851 struct iwl_priv *priv = hw->priv;
1854 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
1856 if (!iwl_is_alive(priv))
1859 mutex_lock(&priv->mutex);
1861 if (changes & BSS_CHANGED_BEACON &&
1862 priv->iw_mode == NL80211_IFTYPE_AP) {
1863 dev_kfree_skb(priv->ibss_beacon);
1864 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
1867 if (changes & BSS_CHANGED_BEACON_INT) {
1868 priv->beacon_int = bss_conf->beacon_int;
1869 /* TODO: in AP mode, do something to make this take effect */
1872 if (changes & BSS_CHANGED_BSSID) {
1873 IWL_DEBUG_MAC80211(priv, "BSSID %pM\n", bss_conf->bssid);
1876 * If there is currently a HW scan going on in the
1877 * background then we need to cancel it else the RXON
1878 * below/in post_associate will fail.
1880 if (iwl_scan_cancel_timeout(priv, 100)) {
1881 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
1882 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
1883 mutex_unlock(&priv->mutex);
1887 /* mac80211 only sets assoc when in STATION mode */
1888 if (priv->iw_mode == NL80211_IFTYPE_ADHOC ||
1890 memcpy(priv->staging_rxon.bssid_addr,
1891 bss_conf->bssid, ETH_ALEN);
1893 /* currently needed in a few places */
1894 memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
1896 priv->staging_rxon.filter_flags &=
1897 ~RXON_FILTER_ASSOC_MSK;
1903 * This needs to be after setting the BSSID in case
1904 * mac80211 decides to do both changes at once because
1905 * it will invoke post_associate.
1907 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
1908 changes & BSS_CHANGED_BEACON) {
1909 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
1912 iwl_mac_beacon_update(hw, beacon);
1915 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
1916 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
1917 bss_conf->use_short_preamble);
1918 if (bss_conf->use_short_preamble)
1919 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1921 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1924 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
1925 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n", bss_conf->use_cts_prot);
1926 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
1927 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
1929 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
1932 if (changes & BSS_CHANGED_BASIC_RATES) {
1933 /* XXX use this information
1935 * To do that, remove code from iwl_set_rate() and put something
1939 priv->staging_rxon.ofdm_basic_rates =
1940 bss_conf->basic_rates;
1942 priv->staging_rxon.ofdm_basic_rates =
1943 bss_conf->basic_rates >> 4;
1944 priv->staging_rxon.cck_basic_rates =
1945 bss_conf->basic_rates & 0xF;
1949 if (changes & BSS_CHANGED_HT) {
1950 iwl_ht_conf(priv, bss_conf);
1952 if (priv->cfg->ops->hcmd->set_rxon_chain)
1953 priv->cfg->ops->hcmd->set_rxon_chain(priv);
1956 if (changes & BSS_CHANGED_ASSOC) {
1957 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
1958 if (bss_conf->assoc) {
1959 priv->assoc_id = bss_conf->aid;
1960 priv->beacon_int = bss_conf->beacon_int;
1961 priv->timestamp = bss_conf->timestamp;
1962 priv->assoc_capability = bss_conf->assoc_capability;
1964 iwl_led_associate(priv);
1966 if (!iwl_is_rfkill(priv))
1967 priv->cfg->ops->lib->post_associate(priv);
1969 iwl_set_no_assoc(priv);
1972 if (changes && iwl_is_associated(priv) && priv->assoc_id) {
1973 IWL_DEBUG_MAC80211(priv, "Changes (%#x) while associated\n",
1975 ret = iwl_send_rxon_assoc(priv);
1977 /* Sync active_rxon with latest change. */
1978 memcpy((void *)&priv->active_rxon,
1979 &priv->staging_rxon,
1980 sizeof(struct iwl_rxon_cmd));
1984 if (changes & BSS_CHANGED_BEACON_ENABLED) {
1985 if (vif->bss_conf.enable_beacon) {
1986 memcpy(priv->staging_rxon.bssid_addr,
1987 bss_conf->bssid, ETH_ALEN);
1988 memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
1989 iwlcore_config_ap(priv);
1991 iwl_set_no_assoc(priv);
1994 mutex_unlock(&priv->mutex);
1996 IWL_DEBUG_MAC80211(priv, "leave\n");
1998 EXPORT_SYMBOL(iwl_bss_info_changed);
2000 int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
2002 struct iwl_priv *priv = hw->priv;
2003 unsigned long flags;
2006 IWL_DEBUG_MAC80211(priv, "enter\n");
2008 if (!iwl_is_ready_rf(priv)) {
2009 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
2013 spin_lock_irqsave(&priv->lock, flags);
2015 if (priv->ibss_beacon)
2016 dev_kfree_skb(priv->ibss_beacon);
2018 priv->ibss_beacon = skb;
2021 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
2022 priv->timestamp = le64_to_cpu(timestamp);
2024 IWL_DEBUG_MAC80211(priv, "leave\n");
2025 spin_unlock_irqrestore(&priv->lock, flags);
2027 priv->cfg->ops->lib->post_associate(priv);
2031 EXPORT_SYMBOL(iwl_mac_beacon_update);
2033 static int iwl_set_mode(struct iwl_priv *priv, struct ieee80211_vif *vif)
2035 iwl_connection_init_rx_config(priv, vif->type);
2037 if (priv->cfg->ops->hcmd->set_rxon_chain)
2038 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2040 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2042 return iwlcore_commit_rxon(priv);
2045 int iwl_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
2047 struct iwl_priv *priv = hw->priv;
2050 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", vif->type);
2052 mutex_lock(&priv->mutex);
2054 if (WARN_ON(!iwl_is_ready_rf(priv))) {
2060 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
2066 priv->iw_mode = vif->type;
2068 IWL_DEBUG_MAC80211(priv, "Set %pM\n", vif->addr);
2069 memcpy(priv->mac_addr, vif->addr, ETH_ALEN);
2071 err = iwl_set_mode(priv, vif);
2075 /* Add the broadcast address so we can send broadcast frames */
2076 priv->cfg->ops->lib->add_bcast_station(priv);
2082 priv->iw_mode = NL80211_IFTYPE_STATION;
2084 mutex_unlock(&priv->mutex);
2086 IWL_DEBUG_MAC80211(priv, "leave\n");
2089 EXPORT_SYMBOL(iwl_mac_add_interface);
2091 void iwl_mac_remove_interface(struct ieee80211_hw *hw,
2092 struct ieee80211_vif *vif)
2094 struct iwl_priv *priv = hw->priv;
2096 IWL_DEBUG_MAC80211(priv, "enter\n");
2098 mutex_lock(&priv->mutex);
2100 iwl_clear_ucode_stations(priv, true);
2102 if (iwl_is_ready_rf(priv)) {
2103 iwl_scan_cancel_timeout(priv, 100);
2104 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2105 iwlcore_commit_rxon(priv);
2107 if (priv->vif == vif) {
2109 memset(priv->bssid, 0, ETH_ALEN);
2111 mutex_unlock(&priv->mutex);
2113 IWL_DEBUG_MAC80211(priv, "leave\n");
2116 EXPORT_SYMBOL(iwl_mac_remove_interface);
2119 * iwl_mac_config - mac80211 config callback
2121 int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
2123 struct iwl_priv *priv = hw->priv;
2124 const struct iwl_channel_info *ch_info;
2125 struct ieee80211_conf *conf = &hw->conf;
2126 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
2127 unsigned long flags = 0;
2130 int scan_active = 0;
2132 mutex_lock(&priv->mutex);
2134 IWL_DEBUG_MAC80211(priv, "enter to channel %d changed 0x%X\n",
2135 conf->channel->hw_value, changed);
2137 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
2138 test_bit(STATUS_SCANNING, &priv->status))) {
2140 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
2143 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
2144 IEEE80211_CONF_CHANGE_CHANNEL)) {
2145 /* mac80211 uses static for non-HT which is what we want */
2146 priv->current_ht_config.smps = conf->smps_mode;
2149 * Recalculate chain counts.
2151 * If monitor mode is enabled then mac80211 will
2152 * set up the SM PS mode to OFF if an HT channel is
2155 if (priv->cfg->ops->hcmd->set_rxon_chain)
2156 priv->cfg->ops->hcmd->set_rxon_chain(priv);
2159 /* during scanning mac80211 will delay channel setting until
2160 * scan finish with changed = 0
2162 if (!changed || (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
2166 ch = ieee80211_frequency_to_channel(conf->channel->center_freq);
2167 ch_info = iwl_get_channel_info(priv, conf->channel->band, ch);
2168 if (!is_channel_valid(ch_info)) {
2169 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
2174 spin_lock_irqsave(&priv->lock, flags);
2176 /* Configure HT40 channels */
2177 ht_conf->is_ht = conf_is_ht(conf);
2178 if (ht_conf->is_ht) {
2179 if (conf_is_ht40_minus(conf)) {
2180 ht_conf->extension_chan_offset =
2181 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
2182 ht_conf->is_40mhz = true;
2183 } else if (conf_is_ht40_plus(conf)) {
2184 ht_conf->extension_chan_offset =
2185 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
2186 ht_conf->is_40mhz = true;
2188 ht_conf->extension_chan_offset =
2189 IEEE80211_HT_PARAM_CHA_SEC_NONE;
2190 ht_conf->is_40mhz = false;
2193 ht_conf->is_40mhz = false;
2194 /* Default to no protection. Protection mode will later be set
2195 * from BSS config in iwl_ht_conf */
2196 ht_conf->ht_protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
2198 /* if we are switching from ht to 2.4 clear flags
2199 * from any ht related info since 2.4 does not
2201 if ((le16_to_cpu(priv->staging_rxon.channel) != ch))
2202 priv->staging_rxon.flags = 0;
2204 iwl_set_rxon_channel(priv, conf->channel);
2205 iwl_set_rxon_ht(priv, ht_conf);
2207 iwl_set_flags_for_band(priv, conf->channel->band);
2208 spin_unlock_irqrestore(&priv->lock, flags);
2209 if (iwl_is_associated(priv) &&
2210 (le16_to_cpu(priv->active_rxon.channel) != ch) &&
2211 priv->cfg->ops->lib->set_channel_switch) {
2214 * at this point, staging_rxon has the
2215 * configuration for channel switch
2217 ret = priv->cfg->ops->lib->set_channel_switch(priv,
2220 iwl_print_rx_config_cmd(priv);
2223 priv->switch_rxon.switch_in_progress = false;
2226 /* The list of supported rates and rate mask can be different
2227 * for each band; since the band may have changed, reset
2228 * the rate mask to what mac80211 lists */
2232 if (changed & (IEEE80211_CONF_CHANGE_PS |
2233 IEEE80211_CONF_CHANGE_IDLE)) {
2234 ret = iwl_power_update_mode(priv, false);
2236 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
2239 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2240 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
2241 priv->tx_power_user_lmt, conf->power_level);
2243 iwl_set_tx_power(priv, conf->power_level, false);
2246 if (changed & IEEE80211_CONF_CHANGE_QOS) {
2247 bool qos_active = !!(conf->flags & IEEE80211_CONF_QOS);
2249 spin_lock_irqsave(&priv->lock, flags);
2250 priv->qos_data.qos_active = qos_active;
2251 iwl_update_qos(priv);
2252 spin_unlock_irqrestore(&priv->lock, flags);
2255 if (!iwl_is_ready(priv)) {
2256 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
2263 if (memcmp(&priv->active_rxon,
2264 &priv->staging_rxon, sizeof(priv->staging_rxon)))
2265 iwlcore_commit_rxon(priv);
2267 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration.\n");
2271 IWL_DEBUG_MAC80211(priv, "leave\n");
2272 mutex_unlock(&priv->mutex);
2275 EXPORT_SYMBOL(iwl_mac_config);
2277 void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
2279 struct iwl_priv *priv = hw->priv;
2280 unsigned long flags;
2282 mutex_lock(&priv->mutex);
2283 IWL_DEBUG_MAC80211(priv, "enter\n");
2285 spin_lock_irqsave(&priv->lock, flags);
2286 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_config));
2287 spin_unlock_irqrestore(&priv->lock, flags);
2289 spin_lock_irqsave(&priv->lock, flags);
2291 priv->assoc_capability = 0;
2293 /* new association get rid of ibss beacon skb */
2294 if (priv->ibss_beacon)
2295 dev_kfree_skb(priv->ibss_beacon);
2297 priv->ibss_beacon = NULL;
2299 priv->beacon_int = priv->vif->bss_conf.beacon_int;
2300 priv->timestamp = 0;
2302 spin_unlock_irqrestore(&priv->lock, flags);
2304 if (!iwl_is_ready_rf(priv)) {
2305 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
2306 mutex_unlock(&priv->mutex);
2310 /* we are restarting association process
2311 * clear RXON_FILTER_ASSOC_MSK bit
2313 iwl_scan_cancel_timeout(priv, 100);
2314 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2315 iwlcore_commit_rxon(priv);
2319 mutex_unlock(&priv->mutex);
2321 IWL_DEBUG_MAC80211(priv, "leave\n");
2323 EXPORT_SYMBOL(iwl_mac_reset_tsf);
2325 int iwl_alloc_txq_mem(struct iwl_priv *priv)
2328 priv->txq = kzalloc(
2329 sizeof(struct iwl_tx_queue) * priv->cfg->num_of_queues,
2332 IWL_ERR(priv, "Not enough memory for txq\n");
2337 EXPORT_SYMBOL(iwl_alloc_txq_mem);
2339 void iwl_free_txq_mem(struct iwl_priv *priv)
2344 EXPORT_SYMBOL(iwl_free_txq_mem);
2346 int iwl_send_wimax_coex(struct iwl_priv *priv)
2348 struct iwl_wimax_coex_cmd coex_cmd;
2350 if (priv->cfg->support_wimax_coexist) {
2351 /* UnMask wake up src at associated sleep */
2352 coex_cmd.flags = COEX_FLAGS_ASSOC_WA_UNMASK_MSK;
2354 /* UnMask wake up src at unassociated sleep */
2355 coex_cmd.flags |= COEX_FLAGS_UNASSOC_WA_UNMASK_MSK;
2356 memcpy(coex_cmd.sta_prio, cu_priorities,
2357 sizeof(struct iwl_wimax_coex_event_entry) *
2358 COEX_NUM_OF_EVENTS);
2360 /* enabling the coexistence feature */
2361 coex_cmd.flags |= COEX_FLAGS_COEX_ENABLE_MSK;
2363 /* enabling the priorities tables */
2364 coex_cmd.flags |= COEX_FLAGS_STA_TABLE_VALID_MSK;
2366 /* coexistence is disabled */
2367 memset(&coex_cmd, 0, sizeof(coex_cmd));
2369 return iwl_send_cmd_pdu(priv, COEX_PRIORITY_TABLE_CMD,
2370 sizeof(coex_cmd), &coex_cmd);
2372 EXPORT_SYMBOL(iwl_send_wimax_coex);
2374 #ifdef CONFIG_IWLWIFI_DEBUGFS
2376 #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
2378 void iwl_reset_traffic_log(struct iwl_priv *priv)
2380 priv->tx_traffic_idx = 0;
2381 priv->rx_traffic_idx = 0;
2382 if (priv->tx_traffic)
2383 memset(priv->tx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
2384 if (priv->rx_traffic)
2385 memset(priv->rx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
2388 int iwl_alloc_traffic_mem(struct iwl_priv *priv)
2390 u32 traffic_size = IWL_TRAFFIC_DUMP_SIZE;
2392 if (iwl_debug_level & IWL_DL_TX) {
2393 if (!priv->tx_traffic) {
2395 kzalloc(traffic_size, GFP_KERNEL);
2396 if (!priv->tx_traffic)
2400 if (iwl_debug_level & IWL_DL_RX) {
2401 if (!priv->rx_traffic) {
2403 kzalloc(traffic_size, GFP_KERNEL);
2404 if (!priv->rx_traffic)
2408 iwl_reset_traffic_log(priv);
2411 EXPORT_SYMBOL(iwl_alloc_traffic_mem);
2413 void iwl_free_traffic_mem(struct iwl_priv *priv)
2415 kfree(priv->tx_traffic);
2416 priv->tx_traffic = NULL;
2418 kfree(priv->rx_traffic);
2419 priv->rx_traffic = NULL;
2421 EXPORT_SYMBOL(iwl_free_traffic_mem);
2423 void iwl_dbg_log_tx_data_frame(struct iwl_priv *priv,
2424 u16 length, struct ieee80211_hdr *header)
2429 if (likely(!(iwl_debug_level & IWL_DL_TX)))
2432 if (!priv->tx_traffic)
2435 fc = header->frame_control;
2436 if (ieee80211_is_data(fc)) {
2437 len = (length > IWL_TRAFFIC_ENTRY_SIZE)
2438 ? IWL_TRAFFIC_ENTRY_SIZE : length;
2439 memcpy((priv->tx_traffic +
2440 (priv->tx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
2442 priv->tx_traffic_idx =
2443 (priv->tx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
2446 EXPORT_SYMBOL(iwl_dbg_log_tx_data_frame);
2448 void iwl_dbg_log_rx_data_frame(struct iwl_priv *priv,
2449 u16 length, struct ieee80211_hdr *header)
2454 if (likely(!(iwl_debug_level & IWL_DL_RX)))
2457 if (!priv->rx_traffic)
2460 fc = header->frame_control;
2461 if (ieee80211_is_data(fc)) {
2462 len = (length > IWL_TRAFFIC_ENTRY_SIZE)
2463 ? IWL_TRAFFIC_ENTRY_SIZE : length;
2464 memcpy((priv->rx_traffic +
2465 (priv->rx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
2467 priv->rx_traffic_idx =
2468 (priv->rx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
2471 EXPORT_SYMBOL(iwl_dbg_log_rx_data_frame);
2473 const char *get_mgmt_string(int cmd)
2476 IWL_CMD(MANAGEMENT_ASSOC_REQ);
2477 IWL_CMD(MANAGEMENT_ASSOC_RESP);
2478 IWL_CMD(MANAGEMENT_REASSOC_REQ);
2479 IWL_CMD(MANAGEMENT_REASSOC_RESP);
2480 IWL_CMD(MANAGEMENT_PROBE_REQ);
2481 IWL_CMD(MANAGEMENT_PROBE_RESP);
2482 IWL_CMD(MANAGEMENT_BEACON);
2483 IWL_CMD(MANAGEMENT_ATIM);
2484 IWL_CMD(MANAGEMENT_DISASSOC);
2485 IWL_CMD(MANAGEMENT_AUTH);
2486 IWL_CMD(MANAGEMENT_DEAUTH);
2487 IWL_CMD(MANAGEMENT_ACTION);
2494 const char *get_ctrl_string(int cmd)
2497 IWL_CMD(CONTROL_BACK_REQ);
2498 IWL_CMD(CONTROL_BACK);
2499 IWL_CMD(CONTROL_PSPOLL);
2500 IWL_CMD(CONTROL_RTS);
2501 IWL_CMD(CONTROL_CTS);
2502 IWL_CMD(CONTROL_ACK);
2503 IWL_CMD(CONTROL_CFEND);
2504 IWL_CMD(CONTROL_CFENDACK);
2511 void iwl_clear_traffic_stats(struct iwl_priv *priv)
2513 memset(&priv->tx_stats, 0, sizeof(struct traffic_stats));
2514 memset(&priv->rx_stats, 0, sizeof(struct traffic_stats));
2519 * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will
2520 * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass.
2521 * Use debugFs to display the rx/rx_statistics
2522 * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL
2523 * information will be recorded, but DATA pkt still will be recorded
2524 * for the reason of iwl_led.c need to control the led blinking based on
2525 * number of tx and rx data.
2528 void iwl_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len)
2530 struct traffic_stats *stats;
2533 stats = &priv->tx_stats;
2535 stats = &priv->rx_stats;
2537 if (ieee80211_is_mgmt(fc)) {
2538 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
2539 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
2540 stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
2542 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
2543 stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
2545 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
2546 stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
2548 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
2549 stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
2551 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
2552 stats->mgmt[MANAGEMENT_PROBE_REQ]++;
2554 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
2555 stats->mgmt[MANAGEMENT_PROBE_RESP]++;
2557 case cpu_to_le16(IEEE80211_STYPE_BEACON):
2558 stats->mgmt[MANAGEMENT_BEACON]++;
2560 case cpu_to_le16(IEEE80211_STYPE_ATIM):
2561 stats->mgmt[MANAGEMENT_ATIM]++;
2563 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
2564 stats->mgmt[MANAGEMENT_DISASSOC]++;
2566 case cpu_to_le16(IEEE80211_STYPE_AUTH):
2567 stats->mgmt[MANAGEMENT_AUTH]++;
2569 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
2570 stats->mgmt[MANAGEMENT_DEAUTH]++;
2572 case cpu_to_le16(IEEE80211_STYPE_ACTION):
2573 stats->mgmt[MANAGEMENT_ACTION]++;
2576 } else if (ieee80211_is_ctl(fc)) {
2577 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
2578 case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
2579 stats->ctrl[CONTROL_BACK_REQ]++;
2581 case cpu_to_le16(IEEE80211_STYPE_BACK):
2582 stats->ctrl[CONTROL_BACK]++;
2584 case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
2585 stats->ctrl[CONTROL_PSPOLL]++;
2587 case cpu_to_le16(IEEE80211_STYPE_RTS):
2588 stats->ctrl[CONTROL_RTS]++;
2590 case cpu_to_le16(IEEE80211_STYPE_CTS):
2591 stats->ctrl[CONTROL_CTS]++;
2593 case cpu_to_le16(IEEE80211_STYPE_ACK):
2594 stats->ctrl[CONTROL_ACK]++;
2596 case cpu_to_le16(IEEE80211_STYPE_CFEND):
2597 stats->ctrl[CONTROL_CFEND]++;
2599 case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
2600 stats->ctrl[CONTROL_CFENDACK]++;
2606 stats->data_bytes += len;
2608 iwl_leds_background(priv);
2610 EXPORT_SYMBOL(iwl_update_stats);
2613 const static char *get_csr_string(int cmd)
2616 IWL_CMD(CSR_HW_IF_CONFIG_REG);
2617 IWL_CMD(CSR_INT_COALESCING);
2619 IWL_CMD(CSR_INT_MASK);
2620 IWL_CMD(CSR_FH_INT_STATUS);
2621 IWL_CMD(CSR_GPIO_IN);
2623 IWL_CMD(CSR_GP_CNTRL);
2624 IWL_CMD(CSR_HW_REV);
2625 IWL_CMD(CSR_EEPROM_REG);
2626 IWL_CMD(CSR_EEPROM_GP);
2627 IWL_CMD(CSR_OTP_GP_REG);
2628 IWL_CMD(CSR_GIO_REG);
2629 IWL_CMD(CSR_GP_UCODE_REG);
2630 IWL_CMD(CSR_GP_DRIVER_REG);
2631 IWL_CMD(CSR_UCODE_DRV_GP1);
2632 IWL_CMD(CSR_UCODE_DRV_GP2);
2633 IWL_CMD(CSR_LED_REG);
2634 IWL_CMD(CSR_DRAM_INT_TBL_REG);
2635 IWL_CMD(CSR_GIO_CHICKEN_BITS);
2636 IWL_CMD(CSR_ANA_PLL_CFG);
2637 IWL_CMD(CSR_HW_REV_WA_REG);
2638 IWL_CMD(CSR_DBG_HPET_MEM_REG);
2645 void iwl_dump_csr(struct iwl_priv *priv)
2649 CSR_HW_IF_CONFIG_REG,
2667 CSR_DRAM_INT_TBL_REG,
2668 CSR_GIO_CHICKEN_BITS,
2671 CSR_DBG_HPET_MEM_REG
2673 IWL_ERR(priv, "CSR values:\n");
2674 IWL_ERR(priv, "(2nd byte of CSR_INT_COALESCING is "
2675 "CSR_INT_PERIODIC_REG)\n");
2676 for (i = 0; i < ARRAY_SIZE(csr_tbl); i++) {
2677 IWL_ERR(priv, " %25s: 0X%08x\n",
2678 get_csr_string(csr_tbl[i]),
2679 iwl_read32(priv, csr_tbl[i]));
2682 EXPORT_SYMBOL(iwl_dump_csr);
2684 const static char *get_fh_string(int cmd)
2687 IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
2688 IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
2689 IWL_CMD(FH_RSCSR_CHNL0_WPTR);
2690 IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
2691 IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
2692 IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
2693 IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
2694 IWL_CMD(FH_TSSR_TX_STATUS_REG);
2695 IWL_CMD(FH_TSSR_TX_ERROR_REG);
2702 int iwl_dump_fh(struct iwl_priv *priv, char **buf, bool display)
2705 #ifdef CONFIG_IWLWIFI_DEBUG
2710 FH_RSCSR_CHNL0_STTS_WPTR_REG,
2711 FH_RSCSR_CHNL0_RBDCB_BASE_REG,
2712 FH_RSCSR_CHNL0_WPTR,
2713 FH_MEM_RCSR_CHNL0_CONFIG_REG,
2714 FH_MEM_RSSR_SHARED_CTRL_REG,
2715 FH_MEM_RSSR_RX_STATUS_REG,
2716 FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
2717 FH_TSSR_TX_STATUS_REG,
2718 FH_TSSR_TX_ERROR_REG
2720 #ifdef CONFIG_IWLWIFI_DEBUG
2722 bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
2723 *buf = kmalloc(bufsz, GFP_KERNEL);
2726 pos += scnprintf(*buf + pos, bufsz - pos,
2727 "FH register values:\n");
2728 for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
2729 pos += scnprintf(*buf + pos, bufsz - pos,
2731 get_fh_string(fh_tbl[i]),
2732 iwl_read_direct32(priv, fh_tbl[i]));
2737 IWL_ERR(priv, "FH register values:\n");
2738 for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
2739 IWL_ERR(priv, " %34s: 0X%08x\n",
2740 get_fh_string(fh_tbl[i]),
2741 iwl_read_direct32(priv, fh_tbl[i]));
2745 EXPORT_SYMBOL(iwl_dump_fh);
2747 static void iwl_force_rf_reset(struct iwl_priv *priv)
2749 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2752 if (!iwl_is_associated(priv)) {
2753 IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
2757 * There is no easy and better way to force reset the radio,
2758 * the only known method is switching channel which will force to
2759 * reset and tune the radio.
2760 * Use internal short scan (single channel) operation to should
2761 * achieve this objective.
2762 * Driver should reset the radio when number of consecutive missed
2763 * beacon, or any other uCode error condition detected.
2765 IWL_DEBUG_INFO(priv, "perform radio reset.\n");
2766 iwl_internal_short_hw_scan(priv);
2770 int iwl_force_reset(struct iwl_priv *priv, int mode)
2772 struct iwl_force_reset *force_reset;
2774 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2777 if (mode >= IWL_MAX_FORCE_RESET) {
2778 IWL_DEBUG_INFO(priv, "invalid reset request.\n");
2781 force_reset = &priv->force_reset[mode];
2782 force_reset->reset_request_count++;
2783 if (force_reset->last_force_reset_jiffies &&
2784 time_after(force_reset->last_force_reset_jiffies +
2785 force_reset->reset_duration, jiffies)) {
2786 IWL_DEBUG_INFO(priv, "force reset rejected\n");
2787 force_reset->reset_reject_count++;
2790 force_reset->reset_success_count++;
2791 force_reset->last_force_reset_jiffies = jiffies;
2792 IWL_DEBUG_INFO(priv, "perform force reset (%d)\n", mode);
2795 iwl_force_rf_reset(priv);
2798 IWL_ERR(priv, "On demand firmware reload\n");
2799 /* Set the FW error flag -- cleared on iwl_down */
2800 set_bit(STATUS_FW_ERROR, &priv->status);
2801 wake_up_interruptible(&priv->wait_command_queue);
2803 * Keep the restart process from trying to send host
2804 * commands by clearing the INIT status bit
2806 clear_bit(STATUS_READY, &priv->status);
2807 queue_work(priv->workqueue, &priv->restart);
2812 EXPORT_SYMBOL(iwl_force_reset);
2815 * iwl_bg_monitor_recover - Timer callback to check for stuck queue and recover
2817 * During normal condition (no queue is stuck), the timer is continually set to
2818 * execute every monitor_recover_period milliseconds after the last timer
2819 * expired. When the queue read_ptr is at the same place, the timer is
2820 * shorten to 100mSecs. This is
2821 * 1) to reduce the chance that the read_ptr may wrap around (not stuck)
2822 * 2) to detect the stuck queues quicker before the station and AP can
2823 * disassociate each other.
2825 * This function monitors all the tx queues and recover from it if any
2826 * of the queues are stuck.
2827 * 1. It first check the cmd queue for stuck conditions. If it is stuck,
2828 * it will recover by resetting the firmware and return.
2829 * 2. Then, it checks for station association. If it associates it will check
2830 * other queues. If any queue is stuck, it will recover by resetting
2832 * Note: It the number of times the queue read_ptr to be at the same place to
2833 * be MAX_REPEAT+1 in order to consider to be stuck.
2836 * The maximum number of times the read pointer of the tx queue at the
2837 * same place without considering to be stuck.
2839 #define MAX_REPEAT (2)
2840 static int iwl_check_stuck_queue(struct iwl_priv *priv, int cnt)
2842 struct iwl_tx_queue *txq;
2843 struct iwl_queue *q;
2845 txq = &priv->txq[cnt];
2847 /* queue is empty, skip */
2848 if (q->read_ptr != q->write_ptr) {
2849 if (q->read_ptr == q->last_read_ptr) {
2850 /* a queue has not been read from last time */
2851 if (q->repeat_same_read_ptr > MAX_REPEAT) {
2853 "queue %d stuck %d time. Fw reload.\n",
2854 q->id, q->repeat_same_read_ptr);
2855 q->repeat_same_read_ptr = 0;
2856 iwl_force_reset(priv, IWL_FW_RESET);
2858 q->repeat_same_read_ptr++;
2859 IWL_DEBUG_RADIO(priv,
2860 "queue %d, not read %d time\n",
2862 q->repeat_same_read_ptr);
2863 mod_timer(&priv->monitor_recover, jiffies +
2864 msecs_to_jiffies(IWL_ONE_HUNDRED_MSECS));
2868 q->last_read_ptr = q->read_ptr;
2869 q->repeat_same_read_ptr = 0;
2875 void iwl_bg_monitor_recover(unsigned long data)
2877 struct iwl_priv *priv = (struct iwl_priv *)data;
2880 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2883 /* monitor and check for stuck cmd queue */
2884 if (iwl_check_stuck_queue(priv, IWL_CMD_QUEUE_NUM))
2887 /* monitor and check for other stuck queues */
2888 if (iwl_is_associated(priv)) {
2889 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
2890 /* skip as we already checked the command queue */
2891 if (cnt == IWL_CMD_QUEUE_NUM)
2893 if (iwl_check_stuck_queue(priv, cnt))
2898 * Reschedule the timer to occur in
2899 * priv->cfg->monitor_recover_period
2901 mod_timer(&priv->monitor_recover,
2902 jiffies + msecs_to_jiffies(priv->cfg->monitor_recover_period));
2904 EXPORT_SYMBOL(iwl_bg_monitor_recover);
2908 int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2910 struct iwl_priv *priv = pci_get_drvdata(pdev);
2913 * This function is called when system goes into suspend state
2914 * mac80211 will call iwl_mac_stop() from the mac80211 suspend function
2915 * first but since iwl_mac_stop() has no knowledge of who the caller is,
2916 * it will not call apm_ops.stop() to stop the DMA operation.
2917 * Calling apm_ops.stop here to make sure we stop the DMA.
2919 priv->cfg->ops->lib->apm_ops.stop(priv);
2921 pci_save_state(pdev);
2922 pci_disable_device(pdev);
2923 pci_set_power_state(pdev, PCI_D3hot);
2927 EXPORT_SYMBOL(iwl_pci_suspend);
2929 int iwl_pci_resume(struct pci_dev *pdev)
2931 struct iwl_priv *priv = pci_get_drvdata(pdev);
2935 * We disable the RETRY_TIMEOUT register (0x41) to keep
2936 * PCI Tx retries from interfering with C3 CPU state.
2938 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
2940 pci_set_power_state(pdev, PCI_D0);
2941 ret = pci_enable_device(pdev);
2944 pci_restore_state(pdev);
2945 iwl_enable_interrupts(priv);
2949 EXPORT_SYMBOL(iwl_pci_resume);
2951 #endif /* CONFIG_PM */