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 bool bt_coex_active = true;
68 EXPORT_SYMBOL_GPL(bt_coex_active);
69 module_param(bt_coex_active, bool, S_IRUGO);
70 MODULE_PARM_DESC(bt_coex_active, "enable wifi/bluetooth co-exist");
73 EXPORT_SYMBOL(iwl_debug_level);
75 u8 iwl_toggle_tx_ant(struct iwl_priv *priv, u8 ant, u8 valid)
80 if (priv->band == IEEE80211_BAND_2GHZ &&
81 priv->bt_traffic_load >= IWL_BT_COEX_TRAFFIC_LOAD_HIGH)
84 for (i = 0; i < RATE_ANT_NUM - 1; i++) {
85 ind = (ind + 1) < RATE_ANT_NUM ? ind + 1 : 0;
91 EXPORT_SYMBOL(iwl_toggle_tx_ant);
93 const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
94 EXPORT_SYMBOL(iwl_bcast_addr);
97 /* This function both allocates and initializes hw and priv. */
98 struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
99 struct ieee80211_ops *hw_ops)
101 struct iwl_priv *priv;
103 /* mac80211 allocates memory for this device instance, including
104 * space for this driver's private structure */
105 struct ieee80211_hw *hw =
106 ieee80211_alloc_hw(sizeof(struct iwl_priv), hw_ops);
108 pr_err("%s: Can not allocate network device\n",
119 EXPORT_SYMBOL(iwl_alloc_all);
124 static void iwl_update_qos(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
126 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
132 ctx->qos_data.def_qos_parm.qos_flags = 0;
134 if (ctx->qos_data.qos_active)
135 ctx->qos_data.def_qos_parm.qos_flags |=
136 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
139 ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
141 IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
142 ctx->qos_data.qos_active,
143 ctx->qos_data.def_qos_parm.qos_flags);
145 iwl_send_cmd_pdu_async(priv, ctx->qos_cmd,
146 sizeof(struct iwl_qosparam_cmd),
147 &ctx->qos_data.def_qos_parm, NULL);
150 #define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
151 #define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
152 static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
153 struct ieee80211_sta_ht_cap *ht_info,
154 enum ieee80211_band band)
156 u16 max_bit_rate = 0;
157 u8 rx_chains_num = priv->hw_params.rx_chains_num;
158 u8 tx_chains_num = priv->hw_params.tx_chains_num;
161 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
163 ht_info->ht_supported = true;
165 if (priv->cfg->ht_params &&
166 priv->cfg->ht_params->ht_greenfield_support)
167 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
168 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
169 max_bit_rate = MAX_BIT_RATE_20_MHZ;
170 if (priv->hw_params.ht40_channel & BIT(band)) {
171 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
172 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
173 ht_info->mcs.rx_mask[4] = 0x01;
174 max_bit_rate = MAX_BIT_RATE_40_MHZ;
177 if (priv->cfg->mod_params->amsdu_size_8K)
178 ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU;
180 ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
181 if (priv->cfg->bt_params && priv->cfg->bt_params->ampdu_factor)
182 ht_info->ampdu_factor = priv->cfg->bt_params->ampdu_factor;
183 ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
184 if (priv->cfg->bt_params && priv->cfg->bt_params->ampdu_density)
185 ht_info->ampdu_density = priv->cfg->bt_params->ampdu_density;
187 ht_info->mcs.rx_mask[0] = 0xFF;
188 if (rx_chains_num >= 2)
189 ht_info->mcs.rx_mask[1] = 0xFF;
190 if (rx_chains_num >= 3)
191 ht_info->mcs.rx_mask[2] = 0xFF;
193 /* Highest supported Rx data rate */
194 max_bit_rate *= rx_chains_num;
195 WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK);
196 ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate);
198 /* Tx MCS capabilities */
199 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
200 if (tx_chains_num != rx_chains_num) {
201 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
202 ht_info->mcs.tx_params |= ((tx_chains_num - 1) <<
203 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
208 * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom
210 int iwlcore_init_geos(struct iwl_priv *priv)
212 struct iwl_channel_info *ch;
213 struct ieee80211_supported_band *sband;
214 struct ieee80211_channel *channels;
215 struct ieee80211_channel *geo_ch;
216 struct ieee80211_rate *rates;
219 if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
220 priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
221 IWL_DEBUG_INFO(priv, "Geography modes already initialized.\n");
222 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
226 channels = kzalloc(sizeof(struct ieee80211_channel) *
227 priv->channel_count, GFP_KERNEL);
231 rates = kzalloc((sizeof(struct ieee80211_rate) * IWL_RATE_COUNT_LEGACY),
238 /* 5.2GHz channels start after the 2.4GHz channels */
239 sband = &priv->bands[IEEE80211_BAND_5GHZ];
240 sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
242 sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
243 sband->n_bitrates = IWL_RATE_COUNT_LEGACY - IWL_FIRST_OFDM_RATE;
245 if (priv->cfg->sku & IWL_SKU_N)
246 iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
247 IEEE80211_BAND_5GHZ);
249 sband = &priv->bands[IEEE80211_BAND_2GHZ];
250 sband->channels = channels;
252 sband->bitrates = rates;
253 sband->n_bitrates = IWL_RATE_COUNT_LEGACY;
255 if (priv->cfg->sku & IWL_SKU_N)
256 iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
257 IEEE80211_BAND_2GHZ);
259 priv->ieee_channels = channels;
260 priv->ieee_rates = rates;
262 for (i = 0; i < priv->channel_count; i++) {
263 ch = &priv->channel_info[i];
265 /* FIXME: might be removed if scan is OK */
266 if (!is_channel_valid(ch))
269 if (is_channel_a_band(ch))
270 sband = &priv->bands[IEEE80211_BAND_5GHZ];
272 sband = &priv->bands[IEEE80211_BAND_2GHZ];
274 geo_ch = &sband->channels[sband->n_channels++];
276 geo_ch->center_freq =
277 ieee80211_channel_to_frequency(ch->channel);
278 geo_ch->max_power = ch->max_power_avg;
279 geo_ch->max_antenna_gain = 0xff;
280 geo_ch->hw_value = ch->channel;
282 if (is_channel_valid(ch)) {
283 if (!(ch->flags & EEPROM_CHANNEL_IBSS))
284 geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
286 if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
287 geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
289 if (ch->flags & EEPROM_CHANNEL_RADAR)
290 geo_ch->flags |= IEEE80211_CHAN_RADAR;
292 geo_ch->flags |= ch->ht40_extension_channel;
294 if (ch->max_power_avg > priv->tx_power_device_lmt)
295 priv->tx_power_device_lmt = ch->max_power_avg;
297 geo_ch->flags |= IEEE80211_CHAN_DISABLED;
300 IWL_DEBUG_INFO(priv, "Channel %d Freq=%d[%sGHz] %s flag=0x%X\n",
301 ch->channel, geo_ch->center_freq,
302 is_channel_a_band(ch) ? "5.2" : "2.4",
303 geo_ch->flags & IEEE80211_CHAN_DISABLED ?
304 "restricted" : "valid",
308 if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
309 priv->cfg->sku & IWL_SKU_A) {
310 IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
311 "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
312 priv->pci_dev->device,
313 priv->pci_dev->subsystem_device);
314 priv->cfg->sku &= ~IWL_SKU_A;
317 IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
318 priv->bands[IEEE80211_BAND_2GHZ].n_channels,
319 priv->bands[IEEE80211_BAND_5GHZ].n_channels);
321 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
325 EXPORT_SYMBOL(iwlcore_init_geos);
328 * iwlcore_free_geos - undo allocations in iwlcore_init_geos
330 void iwlcore_free_geos(struct iwl_priv *priv)
332 kfree(priv->ieee_channels);
333 kfree(priv->ieee_rates);
334 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
336 EXPORT_SYMBOL(iwlcore_free_geos);
339 * iwlcore_tx_cmd_protection: Set rts/cts. 3945 and 4965 only share this
342 void iwlcore_tx_cmd_protection(struct iwl_priv *priv,
343 struct ieee80211_tx_info *info,
344 __le16 fc, __le32 *tx_flags)
346 if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS) {
347 *tx_flags |= TX_CMD_FLG_RTS_MSK;
348 *tx_flags &= ~TX_CMD_FLG_CTS_MSK;
349 *tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
351 if (!ieee80211_is_mgmt(fc))
354 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
355 case cpu_to_le16(IEEE80211_STYPE_AUTH):
356 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
357 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
358 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
359 *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
360 *tx_flags |= TX_CMD_FLG_CTS_MSK;
363 } else if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
364 *tx_flags &= ~TX_CMD_FLG_RTS_MSK;
365 *tx_flags |= TX_CMD_FLG_CTS_MSK;
366 *tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
369 EXPORT_SYMBOL(iwlcore_tx_cmd_protection);
372 static bool iwl_is_channel_extension(struct iwl_priv *priv,
373 enum ieee80211_band band,
374 u16 channel, u8 extension_chan_offset)
376 const struct iwl_channel_info *ch_info;
378 ch_info = iwl_get_channel_info(priv, band, channel);
379 if (!is_channel_valid(ch_info))
382 if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
383 return !(ch_info->ht40_extension_channel &
384 IEEE80211_CHAN_NO_HT40PLUS);
385 else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW)
386 return !(ch_info->ht40_extension_channel &
387 IEEE80211_CHAN_NO_HT40MINUS);
392 bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
393 struct iwl_rxon_context *ctx,
394 struct ieee80211_sta_ht_cap *ht_cap)
396 if (!ctx->ht.enabled || !ctx->ht.is_40mhz)
400 * We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
401 * the bit will not set if it is pure 40MHz case
403 if (ht_cap && !ht_cap->ht_supported)
406 #ifdef CONFIG_IWLWIFI_DEBUGFS
407 if (priv->disable_ht40)
411 return iwl_is_channel_extension(priv, priv->band,
412 le16_to_cpu(ctx->staging.channel),
413 ctx->ht.extension_chan_offset);
415 EXPORT_SYMBOL(iwl_is_ht40_tx_allowed);
417 static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
423 * If mac80211 hasn't given us a beacon interval, program
424 * the default into the device (not checking this here
425 * would cause the adjustment below to return the maximum
426 * value, which may break PAN.)
429 return DEFAULT_BEACON_INTERVAL;
432 * If the beacon interval we obtained from the peer
433 * is too large, we'll have to wake up more often
434 * (and in IBSS case, we'll beacon too much)
436 * For example, if max_beacon_val is 4096, and the
437 * requested beacon interval is 7000, we'll have to
438 * use 3500 to be able to wake up on the beacons.
440 * This could badly influence beacon detection stats.
443 beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
444 new_val = beacon_val / beacon_factor;
447 new_val = max_beacon_val;
452 int iwl_send_rxon_timing(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
455 s32 interval_tm, rem;
456 struct ieee80211_conf *conf = NULL;
458 struct ieee80211_vif *vif = ctx->vif;
460 conf = ieee80211_get_hw_conf(priv->hw);
462 lockdep_assert_held(&priv->mutex);
464 memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd));
466 ctx->timing.timestamp = cpu_to_le64(priv->timestamp);
467 ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
469 beacon_int = vif ? vif->bss_conf.beacon_int : 0;
472 * TODO: For IBSS we need to get atim_window from mac80211,
473 * for now just always use 0
475 ctx->timing.atim_window = 0;
477 if (ctx->ctxid == IWL_RXON_CTX_PAN &&
478 (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) &&
479 iwl_is_associated(priv, IWL_RXON_CTX_BSS) &&
480 priv->contexts[IWL_RXON_CTX_BSS].vif &&
481 priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) {
482 ctx->timing.beacon_interval =
483 priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval;
484 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
485 } else if (ctx->ctxid == IWL_RXON_CTX_BSS &&
486 iwl_is_associated(priv, IWL_RXON_CTX_PAN) &&
487 priv->contexts[IWL_RXON_CTX_PAN].vif &&
488 priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int &&
489 (!iwl_is_associated_ctx(ctx) || !ctx->vif ||
490 !ctx->vif->bss_conf.beacon_int)) {
491 ctx->timing.beacon_interval =
492 priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval;
493 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
495 beacon_int = iwl_adjust_beacon_interval(beacon_int,
496 priv->hw_params.max_beacon_itrvl * TIME_UNIT);
497 ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
500 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
501 interval_tm = beacon_int * TIME_UNIT;
502 rem = do_div(tsf, interval_tm);
503 ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
505 ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
507 IWL_DEBUG_ASSOC(priv,
508 "beacon interval %d beacon timer %d beacon tim %d\n",
509 le16_to_cpu(ctx->timing.beacon_interval),
510 le32_to_cpu(ctx->timing.beacon_init_val),
511 le16_to_cpu(ctx->timing.atim_window));
513 return iwl_send_cmd_pdu(priv, ctx->rxon_timing_cmd,
514 sizeof(ctx->timing), &ctx->timing);
516 EXPORT_SYMBOL(iwl_send_rxon_timing);
518 void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
521 struct iwl_rxon_cmd *rxon = &ctx->staging;
524 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
526 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
529 EXPORT_SYMBOL(iwl_set_rxon_hwcrypto);
532 * iwl_check_rxon_cmd - validate RXON structure is valid
534 * NOTE: This is really only useful during development and can eventually
535 * be #ifdef'd out once the driver is stable and folks aren't actively
538 int iwl_check_rxon_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
542 struct iwl_rxon_cmd *rxon = &ctx->staging;
544 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
545 error |= le32_to_cpu(rxon->flags &
546 (RXON_FLG_TGJ_NARROW_BAND_MSK |
547 RXON_FLG_RADAR_DETECT_MSK));
549 IWL_WARN(priv, "check 24G fields %d | %d\n",
552 error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
553 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
555 IWL_WARN(priv, "check 52 fields %d | %d\n",
557 error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
559 IWL_WARN(priv, "check 52 CCK %d | %d\n",
562 error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
564 IWL_WARN(priv, "check mac addr %d | %d\n", counter++, error);
566 /* make sure basic rates 6Mbps and 1Mbps are supported */
567 error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
568 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
570 IWL_WARN(priv, "check basic rate %d | %d\n", counter++, error);
572 error |= (le16_to_cpu(rxon->assoc_id) > 2007);
574 IWL_WARN(priv, "check assoc id %d | %d\n", counter++, error);
576 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
577 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
579 IWL_WARN(priv, "check CCK and short slot %d | %d\n",
582 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
583 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
585 IWL_WARN(priv, "check CCK & auto detect %d | %d\n",
588 error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
589 RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
591 IWL_WARN(priv, "check TGG and auto detect %d | %d\n",
595 IWL_WARN(priv, "Tuning to channel %d\n",
596 le16_to_cpu(rxon->channel));
599 IWL_ERR(priv, "Not a valid iwl_rxon_assoc_cmd field values\n");
604 EXPORT_SYMBOL(iwl_check_rxon_cmd);
607 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
608 * @priv: staging_rxon is compared to active_rxon
610 * If the RXON structure is changing enough to require a new tune,
611 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
612 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
614 int iwl_full_rxon_required(struct iwl_priv *priv,
615 struct iwl_rxon_context *ctx)
617 const struct iwl_rxon_cmd *staging = &ctx->staging;
618 const struct iwl_rxon_cmd *active = &ctx->active;
622 IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
626 #define CHK_NEQ(c1, c2) \
627 if ((c1) != (c2)) { \
628 IWL_DEBUG_INFO(priv, "need full RXON - " \
629 #c1 " != " #c2 " - %d != %d\n", \
634 /* These items are only settable from the full RXON command */
635 CHK(!iwl_is_associated_ctx(ctx));
636 CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr));
637 CHK(compare_ether_addr(staging->node_addr, active->node_addr));
638 CHK(compare_ether_addr(staging->wlap_bssid_addr,
639 active->wlap_bssid_addr));
640 CHK_NEQ(staging->dev_type, active->dev_type);
641 CHK_NEQ(staging->channel, active->channel);
642 CHK_NEQ(staging->air_propagation, active->air_propagation);
643 CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
644 active->ofdm_ht_single_stream_basic_rates);
645 CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
646 active->ofdm_ht_dual_stream_basic_rates);
647 CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates,
648 active->ofdm_ht_triple_stream_basic_rates);
649 CHK_NEQ(staging->assoc_id, active->assoc_id);
651 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
652 * be updated with the RXON_ASSOC command -- however only some
653 * flag transitions are allowed using RXON_ASSOC */
655 /* Check if we are not switching bands */
656 CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
657 active->flags & RXON_FLG_BAND_24G_MSK);
659 /* Check if we are switching association toggle */
660 CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
661 active->filter_flags & RXON_FILTER_ASSOC_MSK);
668 EXPORT_SYMBOL(iwl_full_rxon_required);
670 u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv,
671 struct iwl_rxon_context *ctx)
674 * Assign the lowest rate -- should really get this from
675 * the beacon skb from mac80211.
677 if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK)
678 return IWL_RATE_1M_PLCP;
680 return IWL_RATE_6M_PLCP;
682 EXPORT_SYMBOL(iwl_rate_get_lowest_plcp);
684 static void _iwl_set_rxon_ht(struct iwl_priv *priv,
685 struct iwl_ht_config *ht_conf,
686 struct iwl_rxon_context *ctx)
688 struct iwl_rxon_cmd *rxon = &ctx->staging;
690 if (!ctx->ht.enabled) {
691 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
692 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
693 RXON_FLG_HT40_PROT_MSK |
694 RXON_FLG_HT_PROT_MSK);
698 /* FIXME: if the definition of ht.protection changed, the "translation"
699 * will be needed for rxon->flags
701 rxon->flags |= cpu_to_le32(ctx->ht.protection << RXON_FLG_HT_OPERATING_MODE_POS);
703 /* Set up channel bandwidth:
704 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
705 /* clear the HT channel mode before set the mode */
706 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
707 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
708 if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
710 if (ctx->ht.protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
711 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
712 /* Note: control channel is opposite of extension channel */
713 switch (ctx->ht.extension_chan_offset) {
714 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
715 rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
717 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
718 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
722 /* Note: control channel is opposite of extension channel */
723 switch (ctx->ht.extension_chan_offset) {
724 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
725 rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
726 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
728 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
729 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
730 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
732 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
734 /* channel location only valid if in Mixed mode */
735 IWL_ERR(priv, "invalid extension channel offset\n");
740 rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
743 if (priv->cfg->ops->hcmd->set_rxon_chain)
744 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
746 IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
747 "extension channel offset 0x%x\n",
748 le32_to_cpu(rxon->flags), ctx->ht.protection,
749 ctx->ht.extension_chan_offset);
752 void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
754 struct iwl_rxon_context *ctx;
756 for_each_context(priv, ctx)
757 _iwl_set_rxon_ht(priv, ht_conf, ctx);
759 EXPORT_SYMBOL(iwl_set_rxon_ht);
761 /* Return valid, unused, channel for a passive scan to reset the RF */
762 u8 iwl_get_single_channel_number(struct iwl_priv *priv,
763 enum ieee80211_band band)
765 const struct iwl_channel_info *ch_info;
769 struct iwl_rxon_context *ctx;
771 if (band == IEEE80211_BAND_5GHZ) {
773 max = priv->channel_count;
779 for (i = min; i < max; i++) {
782 for_each_context(priv, ctx) {
783 busy = priv->channel_info[i].channel ==
784 le16_to_cpu(ctx->staging.channel);
792 channel = priv->channel_info[i].channel;
793 ch_info = iwl_get_channel_info(priv, band, channel);
794 if (is_channel_valid(ch_info))
800 EXPORT_SYMBOL(iwl_get_single_channel_number);
803 * iwl_set_rxon_channel - Set the band and channel values in staging RXON
804 * @ch: requested channel as a pointer to struct ieee80211_channel
806 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
807 * in the staging RXON flag structure based on the ch->band
809 int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
810 struct iwl_rxon_context *ctx)
812 enum ieee80211_band band = ch->band;
813 u16 channel = ch->hw_value;
815 if ((le16_to_cpu(ctx->staging.channel) == channel) &&
816 (priv->band == band))
819 ctx->staging.channel = cpu_to_le16(channel);
820 if (band == IEEE80211_BAND_5GHZ)
821 ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
823 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
827 IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
831 EXPORT_SYMBOL(iwl_set_rxon_channel);
833 void iwl_set_flags_for_band(struct iwl_priv *priv,
834 struct iwl_rxon_context *ctx,
835 enum ieee80211_band band,
836 struct ieee80211_vif *vif)
838 if (band == IEEE80211_BAND_5GHZ) {
839 ctx->staging.flags &=
840 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
842 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
844 /* Copied from iwl_post_associate() */
845 if (vif && vif->bss_conf.use_short_slot)
846 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
848 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
850 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
851 ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
852 ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
855 EXPORT_SYMBOL(iwl_set_flags_for_band);
858 * initialize rxon structure with default values from eeprom
860 void iwl_connection_init_rx_config(struct iwl_priv *priv,
861 struct iwl_rxon_context *ctx)
863 const struct iwl_channel_info *ch_info;
865 memset(&ctx->staging, 0, sizeof(ctx->staging));
868 ctx->staging.dev_type = ctx->unused_devtype;
869 } else switch (ctx->vif->type) {
870 case NL80211_IFTYPE_AP:
871 ctx->staging.dev_type = ctx->ap_devtype;
874 case NL80211_IFTYPE_STATION:
875 ctx->staging.dev_type = ctx->station_devtype;
876 ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
879 case NL80211_IFTYPE_ADHOC:
880 ctx->staging.dev_type = ctx->ibss_devtype;
881 ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
882 ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
883 RXON_FILTER_ACCEPT_GRP_MSK;
887 IWL_ERR(priv, "Unsupported interface type %d\n",
893 /* TODO: Figure out when short_preamble would be set and cache from
895 if (!hw_to_local(priv->hw)->short_preamble)
896 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
898 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
901 ch_info = iwl_get_channel_info(priv, priv->band,
902 le16_to_cpu(ctx->active.channel));
905 ch_info = &priv->channel_info[0];
907 ctx->staging.channel = cpu_to_le16(ch_info->channel);
908 priv->band = ch_info->band;
910 iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
912 ctx->staging.ofdm_basic_rates =
913 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
914 ctx->staging.cck_basic_rates =
915 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
917 /* clear both MIX and PURE40 mode flag */
918 ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
919 RXON_FLG_CHANNEL_MODE_PURE_40);
921 memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
923 ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
924 ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
925 ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
927 EXPORT_SYMBOL(iwl_connection_init_rx_config);
929 void iwl_set_rate(struct iwl_priv *priv)
931 const struct ieee80211_supported_band *hw = NULL;
932 struct ieee80211_rate *rate;
933 struct iwl_rxon_context *ctx;
936 hw = iwl_get_hw_mode(priv, priv->band);
938 IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
942 priv->active_rate = 0;
944 for (i = 0; i < hw->n_bitrates; i++) {
945 rate = &(hw->bitrates[i]);
946 if (rate->hw_value < IWL_RATE_COUNT_LEGACY)
947 priv->active_rate |= (1 << rate->hw_value);
950 IWL_DEBUG_RATE(priv, "Set active_rate = %0x\n", priv->active_rate);
952 for_each_context(priv, ctx) {
953 ctx->staging.cck_basic_rates =
954 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
956 ctx->staging.ofdm_basic_rates =
957 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
960 EXPORT_SYMBOL(iwl_set_rate);
962 void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
966 * See iwl_mac_channel_switch.
968 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
970 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
973 if (priv->switch_rxon.switch_in_progress) {
974 ieee80211_chswitch_done(ctx->vif, is_success);
975 mutex_lock(&priv->mutex);
976 priv->switch_rxon.switch_in_progress = false;
977 mutex_unlock(&priv->mutex);
980 EXPORT_SYMBOL(iwl_chswitch_done);
982 void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
984 struct iwl_rx_packet *pkt = rxb_addr(rxb);
985 struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
988 * See iwl_mac_channel_switch.
990 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
991 struct iwl_rxon_cmd *rxon = (void *)&ctx->active;
993 if (priv->switch_rxon.switch_in_progress) {
994 if (!le32_to_cpu(csa->status) &&
995 (csa->channel == priv->switch_rxon.channel)) {
996 rxon->channel = csa->channel;
997 ctx->staging.channel = csa->channel;
998 IWL_DEBUG_11H(priv, "CSA notif: channel %d\n",
999 le16_to_cpu(csa->channel));
1000 iwl_chswitch_done(priv, true);
1002 IWL_ERR(priv, "CSA notif (fail) : channel %d\n",
1003 le16_to_cpu(csa->channel));
1004 iwl_chswitch_done(priv, false);
1008 EXPORT_SYMBOL(iwl_rx_csa);
1010 #ifdef CONFIG_IWLWIFI_DEBUG
1011 void iwl_print_rx_config_cmd(struct iwl_priv *priv,
1012 struct iwl_rxon_context *ctx)
1014 struct iwl_rxon_cmd *rxon = &ctx->staging;
1016 IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
1017 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
1018 IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
1019 IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
1020 IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
1021 le32_to_cpu(rxon->filter_flags));
1022 IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
1023 IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
1024 rxon->ofdm_basic_rates);
1025 IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
1026 IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
1027 IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
1028 IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
1030 EXPORT_SYMBOL(iwl_print_rx_config_cmd);
1033 * iwl_irq_handle_error - called for HW or SW error interrupt from card
1035 void iwl_irq_handle_error(struct iwl_priv *priv)
1037 /* Set the FW error flag -- cleared on iwl_down */
1038 set_bit(STATUS_FW_ERROR, &priv->status);
1040 /* Cancel currently queued command. */
1041 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1043 IWL_ERR(priv, "Loaded firmware version: %s\n",
1044 priv->hw->wiphy->fw_version);
1046 priv->cfg->ops->lib->dump_nic_error_log(priv);
1047 if (priv->cfg->ops->lib->dump_csr)
1048 priv->cfg->ops->lib->dump_csr(priv);
1049 if (priv->cfg->ops->lib->dump_fh)
1050 priv->cfg->ops->lib->dump_fh(priv, NULL, false);
1051 priv->cfg->ops->lib->dump_nic_event_log(priv, false, NULL, false);
1052 #ifdef CONFIG_IWLWIFI_DEBUG
1053 if (iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS)
1054 iwl_print_rx_config_cmd(priv,
1055 &priv->contexts[IWL_RXON_CTX_BSS]);
1058 wake_up_interruptible(&priv->wait_command_queue);
1060 /* Keep the restart process from trying to send host
1061 * commands by clearing the INIT status bit */
1062 clear_bit(STATUS_READY, &priv->status);
1064 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
1065 IWL_DEBUG(priv, IWL_DL_FW_ERRORS,
1066 "Restarting adapter due to uCode error.\n");
1068 if (priv->cfg->mod_params->restart_fw)
1069 queue_work(priv->workqueue, &priv->restart);
1072 EXPORT_SYMBOL(iwl_irq_handle_error);
1074 static int iwl_apm_stop_master(struct iwl_priv *priv)
1078 /* stop device's busmaster DMA activity */
1079 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
1081 ret = iwl_poll_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_MASTER_DISABLED,
1082 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
1084 IWL_WARN(priv, "Master Disable Timed Out, 100 usec\n");
1086 IWL_DEBUG_INFO(priv, "stop master\n");
1091 void iwl_apm_stop(struct iwl_priv *priv)
1093 IWL_DEBUG_INFO(priv, "Stop card, put in low power state\n");
1095 /* Stop device's DMA activity */
1096 iwl_apm_stop_master(priv);
1098 /* Reset the entire device */
1099 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
1104 * Clear "initialization complete" bit to move adapter from
1105 * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
1107 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
1109 EXPORT_SYMBOL(iwl_apm_stop);
1113 * Start up NIC's basic functionality after it has been reset
1114 * (e.g. after platform boot, or shutdown via iwl_apm_stop())
1115 * NOTE: This does not load uCode nor start the embedded processor
1117 int iwl_apm_init(struct iwl_priv *priv)
1122 IWL_DEBUG_INFO(priv, "Init card's basic functions\n");
1125 * Use "set_bit" below rather than "write", to preserve any hardware
1126 * bits already set by default after reset.
1129 /* Disable L0S exit timer (platform NMI Work/Around) */
1130 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
1131 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
1134 * Disable L0s without affecting L1;
1135 * don't wait for ICH L0s (ICH bug W/A)
1137 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
1138 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
1140 /* Set FH wait threshold to maximum (HW error during stress W/A) */
1141 iwl_set_bit(priv, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL);
1144 * Enable HAP INTA (interrupt from management bus) to
1145 * wake device's PCI Express link L1a -> L0s
1146 * NOTE: This is no-op for 3945 (non-existant bit)
1148 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
1149 CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
1152 * HW bug W/A for instability in PCIe bus L0->L0S->L1 transition.
1153 * Check if BIOS (or OS) enabled L1-ASPM on this device.
1154 * If so (likely), disable L0S, so device moves directly L0->L1;
1155 * costs negligible amount of power savings.
1156 * If not (unlikely), enable L0S, so there is at least some
1157 * power savings, even without L1.
1159 if (priv->cfg->base_params->set_l0s) {
1160 lctl = iwl_pcie_link_ctl(priv);
1161 if ((lctl & PCI_CFG_LINK_CTRL_VAL_L1_EN) ==
1162 PCI_CFG_LINK_CTRL_VAL_L1_EN) {
1163 /* L1-ASPM enabled; disable(!) L0S */
1164 iwl_set_bit(priv, CSR_GIO_REG,
1165 CSR_GIO_REG_VAL_L0S_ENABLED);
1166 IWL_DEBUG_POWER(priv, "L1 Enabled; Disabling L0S\n");
1168 /* L1-ASPM disabled; enable(!) L0S */
1169 iwl_clear_bit(priv, CSR_GIO_REG,
1170 CSR_GIO_REG_VAL_L0S_ENABLED);
1171 IWL_DEBUG_POWER(priv, "L1 Disabled; Enabling L0S\n");
1175 /* Configure analog phase-lock-loop before activating to D0A */
1176 if (priv->cfg->base_params->pll_cfg_val)
1177 iwl_set_bit(priv, CSR_ANA_PLL_CFG,
1178 priv->cfg->base_params->pll_cfg_val);
1181 * Set "initialization complete" bit to move adapter from
1182 * D0U* --> D0A* (powered-up active) state.
1184 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
1187 * Wait for clock stabilization; once stabilized, access to
1188 * device-internal resources is supported, e.g. iwl_write_prph()
1189 * and accesses to uCode SRAM.
1191 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
1192 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
1193 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
1195 IWL_DEBUG_INFO(priv, "Failed to init the card\n");
1200 * Enable DMA and BSM (if used) clocks, wait for them to stabilize.
1201 * BSM (Boostrap State Machine) is only in 3945 and 4965;
1202 * later devices (i.e. 5000 and later) have non-volatile SRAM,
1203 * and don't need BSM to restore data after power-saving sleep.
1205 * Write to "CLK_EN_REG"; "1" bits enable clocks, while "0" bits
1206 * do not disable clocks. This preserves any hardware bits already
1207 * set by default in "CLK_CTRL_REG" after reset.
1209 if (priv->cfg->base_params->use_bsm)
1210 iwl_write_prph(priv, APMG_CLK_EN_REG,
1211 APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT);
1213 iwl_write_prph(priv, APMG_CLK_EN_REG,
1214 APMG_CLK_VAL_DMA_CLK_RQT);
1217 /* Disable L1-Active */
1218 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
1219 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
1224 EXPORT_SYMBOL(iwl_apm_init);
1227 int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
1230 s8 prev_tx_power = priv->tx_power_user_lmt;
1232 if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
1234 "Requested user TXPOWER %d below lower limit %d.\n",
1236 IWLAGN_TX_POWER_TARGET_POWER_MIN);
1240 if (tx_power > priv->tx_power_device_lmt) {
1242 "Requested user TXPOWER %d above upper limit %d.\n",
1243 tx_power, priv->tx_power_device_lmt);
1247 if (priv->tx_power_user_lmt != tx_power)
1250 /* if nic is not up don't send command */
1251 if (iwl_is_ready_rf(priv)) {
1252 priv->tx_power_user_lmt = tx_power;
1253 if (force && priv->cfg->ops->lib->send_tx_power)
1254 ret = priv->cfg->ops->lib->send_tx_power(priv);
1255 else if (!priv->cfg->ops->lib->send_tx_power)
1258 * if fail to set tx_power, restore the orig. tx power
1261 priv->tx_power_user_lmt = prev_tx_power;
1265 * Even this is an async host command, the command
1266 * will always report success from uCode
1267 * So once driver can placing the command into the queue
1268 * successfully, driver can use priv->tx_power_user_lmt
1269 * to reflect the current tx power
1273 EXPORT_SYMBOL(iwl_set_tx_power);
1275 irqreturn_t iwl_isr_legacy(int irq, void *data)
1277 struct iwl_priv *priv = data;
1278 u32 inta, inta_mask;
1280 unsigned long flags;
1284 spin_lock_irqsave(&priv->lock, flags);
1286 /* Disable (but don't clear!) interrupts here to avoid
1287 * back-to-back ISRs and sporadic interrupts from our NIC.
1288 * If we have something to service, the tasklet will re-enable ints.
1289 * If we *don't* have something, we'll re-enable before leaving here. */
1290 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1291 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
1293 /* Discover which interrupts are active/pending */
1294 inta = iwl_read32(priv, CSR_INT);
1295 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1297 /* Ignore interrupt if there's nothing in NIC to service.
1298 * This may be due to IRQ shared with another device,
1299 * or due to sporadic interrupts thrown from our NIC. */
1300 if (!inta && !inta_fh) {
1301 IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0, inta_fh == 0\n");
1305 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
1306 /* Hardware disappeared. It might have already raised
1308 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
1312 IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1313 inta, inta_mask, inta_fh);
1315 inta &= ~CSR_INT_BIT_SCD;
1317 /* iwl_irq_tasklet() will service interrupts and re-enable them */
1318 if (likely(inta || inta_fh))
1319 tasklet_schedule(&priv->irq_tasklet);
1322 spin_unlock_irqrestore(&priv->lock, flags);
1326 /* re-enable interrupts here since we don't have anything to service. */
1327 /* only Re-enable if diabled by irq */
1328 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1329 iwl_enable_interrupts(priv);
1330 spin_unlock_irqrestore(&priv->lock, flags);
1333 EXPORT_SYMBOL(iwl_isr_legacy);
1335 void iwl_send_bt_config(struct iwl_priv *priv)
1337 struct iwl_bt_cmd bt_cmd = {
1338 .lead_time = BT_LEAD_TIME_DEF,
1339 .max_kill = BT_MAX_KILL_DEF,
1344 if (!bt_coex_active)
1345 bt_cmd.flags = BT_COEX_DISABLE;
1347 bt_cmd.flags = BT_COEX_ENABLE;
1349 IWL_DEBUG_INFO(priv, "BT coex %s\n",
1350 (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
1352 if (iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
1353 sizeof(struct iwl_bt_cmd), &bt_cmd))
1354 IWL_ERR(priv, "failed to send BT Coex Config\n");
1356 EXPORT_SYMBOL(iwl_send_bt_config);
1358 int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
1360 struct iwl_statistics_cmd statistics_cmd = {
1361 .configuration_flags =
1362 clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
1365 if (flags & CMD_ASYNC)
1366 return iwl_send_cmd_pdu_async(priv, REPLY_STATISTICS_CMD,
1367 sizeof(struct iwl_statistics_cmd),
1368 &statistics_cmd, NULL);
1370 return iwl_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
1371 sizeof(struct iwl_statistics_cmd),
1374 EXPORT_SYMBOL(iwl_send_statistics_request);
1376 void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
1377 struct iwl_rx_mem_buffer *rxb)
1379 #ifdef CONFIG_IWLWIFI_DEBUG
1380 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1381 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
1382 IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
1383 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1386 EXPORT_SYMBOL(iwl_rx_pm_sleep_notif);
1388 void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
1389 struct iwl_rx_mem_buffer *rxb)
1391 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1392 u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
1393 IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
1394 "notification for %s:\n", len,
1395 get_cmd_string(pkt->hdr.cmd));
1396 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, len);
1398 EXPORT_SYMBOL(iwl_rx_pm_debug_statistics_notif);
1400 void iwl_rx_reply_error(struct iwl_priv *priv,
1401 struct iwl_rx_mem_buffer *rxb)
1403 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1405 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
1406 "seq 0x%04X ser 0x%08X\n",
1407 le32_to_cpu(pkt->u.err_resp.error_type),
1408 get_cmd_string(pkt->u.err_resp.cmd_id),
1409 pkt->u.err_resp.cmd_id,
1410 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
1411 le32_to_cpu(pkt->u.err_resp.error_info));
1413 EXPORT_SYMBOL(iwl_rx_reply_error);
1415 void iwl_clear_isr_stats(struct iwl_priv *priv)
1417 memset(&priv->isr_stats, 0, sizeof(priv->isr_stats));
1420 int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
1421 const struct ieee80211_tx_queue_params *params)
1423 struct iwl_priv *priv = hw->priv;
1424 struct iwl_rxon_context *ctx;
1425 unsigned long flags;
1428 IWL_DEBUG_MAC80211(priv, "enter\n");
1430 if (!iwl_is_ready_rf(priv)) {
1431 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
1435 if (queue >= AC_NUM) {
1436 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
1440 q = AC_NUM - 1 - queue;
1442 spin_lock_irqsave(&priv->lock, flags);
1446 * This may need to be done per interface in nl80211/cfg80211/mac80211.
1448 for_each_context(priv, ctx) {
1449 ctx->qos_data.def_qos_parm.ac[q].cw_min =
1450 cpu_to_le16(params->cw_min);
1451 ctx->qos_data.def_qos_parm.ac[q].cw_max =
1452 cpu_to_le16(params->cw_max);
1453 ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
1454 ctx->qos_data.def_qos_parm.ac[q].edca_txop =
1455 cpu_to_le16((params->txop * 32));
1457 ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0;
1460 spin_unlock_irqrestore(&priv->lock, flags);
1462 IWL_DEBUG_MAC80211(priv, "leave\n");
1465 EXPORT_SYMBOL(iwl_mac_conf_tx);
1467 int iwl_mac_tx_last_beacon(struct ieee80211_hw *hw)
1469 struct iwl_priv *priv = hw->priv;
1471 return priv->ibss_manager == IWL_IBSS_MANAGER;
1473 EXPORT_SYMBOL_GPL(iwl_mac_tx_last_beacon);
1475 static void iwl_ht_conf(struct iwl_priv *priv,
1476 struct ieee80211_vif *vif)
1478 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
1479 struct ieee80211_sta *sta;
1480 struct ieee80211_bss_conf *bss_conf = &vif->bss_conf;
1481 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1483 IWL_DEBUG_MAC80211(priv, "enter:\n");
1485 if (!ctx->ht.enabled)
1488 ctx->ht.protection =
1489 bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_PROTECTION;
1490 ctx->ht.non_gf_sta_present =
1491 !!(bss_conf->ht_operation_mode & IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1493 ht_conf->single_chain_sufficient = false;
1495 switch (vif->type) {
1496 case NL80211_IFTYPE_STATION:
1498 sta = ieee80211_find_sta(vif, bss_conf->bssid);
1500 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
1503 maxstreams = (ht_cap->mcs.tx_params &
1504 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
1505 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1508 if ((ht_cap->mcs.rx_mask[1] == 0) &&
1509 (ht_cap->mcs.rx_mask[2] == 0))
1510 ht_conf->single_chain_sufficient = true;
1511 if (maxstreams <= 1)
1512 ht_conf->single_chain_sufficient = true;
1515 * If at all, this can only happen through a race
1516 * when the AP disconnects us while we're still
1517 * setting up the connection, in that case mac80211
1518 * will soon tell us about that.
1520 ht_conf->single_chain_sufficient = true;
1524 case NL80211_IFTYPE_ADHOC:
1525 ht_conf->single_chain_sufficient = true;
1531 IWL_DEBUG_MAC80211(priv, "leave\n");
1534 static inline void iwl_set_no_assoc(struct iwl_priv *priv,
1535 struct ieee80211_vif *vif)
1537 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1539 iwl_led_disassociate(priv);
1541 * inform the ucode that there is no longer an
1542 * association and that no more packets should be
1545 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1546 ctx->staging.assoc_id = 0;
1547 iwlcore_commit_rxon(priv, ctx);
1550 static void iwlcore_beacon_update(struct ieee80211_hw *hw,
1551 struct ieee80211_vif *vif)
1553 struct iwl_priv *priv = hw->priv;
1554 unsigned long flags;
1556 struct sk_buff *skb = ieee80211_beacon_get(hw, vif);
1561 IWL_DEBUG_ASSOC(priv, "enter\n");
1563 lockdep_assert_held(&priv->mutex);
1565 if (!priv->beacon_ctx) {
1566 IWL_ERR(priv, "update beacon but no beacon context!\n");
1571 spin_lock_irqsave(&priv->lock, flags);
1573 if (priv->ibss_beacon)
1574 dev_kfree_skb(priv->ibss_beacon);
1576 priv->ibss_beacon = skb;
1578 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
1579 priv->timestamp = le64_to_cpu(timestamp);
1581 IWL_DEBUG_ASSOC(priv, "leave\n");
1583 spin_unlock_irqrestore(&priv->lock, flags);
1585 if (!iwl_is_ready_rf(priv)) {
1586 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
1590 priv->cfg->ops->lib->post_associate(priv, priv->beacon_ctx->vif);
1593 void iwl_bss_info_changed(struct ieee80211_hw *hw,
1594 struct ieee80211_vif *vif,
1595 struct ieee80211_bss_conf *bss_conf,
1598 struct iwl_priv *priv = hw->priv;
1599 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1602 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
1604 if (!iwl_is_alive(priv))
1607 mutex_lock(&priv->mutex);
1609 if (changes & BSS_CHANGED_QOS) {
1610 unsigned long flags;
1612 spin_lock_irqsave(&priv->lock, flags);
1613 ctx->qos_data.qos_active = bss_conf->qos;
1614 iwl_update_qos(priv, ctx);
1615 spin_unlock_irqrestore(&priv->lock, flags);
1618 if (changes & BSS_CHANGED_BEACON_ENABLED) {
1620 * the add_interface code must make sure we only ever
1621 * have a single interface that could be beaconing at
1624 if (vif->bss_conf.enable_beacon)
1625 priv->beacon_ctx = ctx;
1627 priv->beacon_ctx = NULL;
1630 if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_AP) {
1631 dev_kfree_skb(priv->ibss_beacon);
1632 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
1635 if (changes & BSS_CHANGED_BEACON_INT && vif->type == NL80211_IFTYPE_AP)
1636 iwl_send_rxon_timing(priv, ctx);
1638 if (changes & BSS_CHANGED_BSSID) {
1639 IWL_DEBUG_MAC80211(priv, "BSSID %pM\n", bss_conf->bssid);
1642 * If there is currently a HW scan going on in the
1643 * background then we need to cancel it else the RXON
1644 * below/in post_associate will fail.
1646 if (iwl_scan_cancel_timeout(priv, 100)) {
1647 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
1648 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
1649 mutex_unlock(&priv->mutex);
1653 /* mac80211 only sets assoc when in STATION mode */
1654 if (vif->type == NL80211_IFTYPE_ADHOC || bss_conf->assoc) {
1655 memcpy(ctx->staging.bssid_addr,
1656 bss_conf->bssid, ETH_ALEN);
1658 /* currently needed in a few places */
1659 memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
1661 ctx->staging.filter_flags &=
1662 ~RXON_FILTER_ASSOC_MSK;
1668 * This needs to be after setting the BSSID in case
1669 * mac80211 decides to do both changes at once because
1670 * it will invoke post_associate.
1672 if (vif->type == NL80211_IFTYPE_ADHOC && changes & BSS_CHANGED_BEACON)
1673 iwlcore_beacon_update(hw, vif);
1675 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
1676 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
1677 bss_conf->use_short_preamble);
1678 if (bss_conf->use_short_preamble)
1679 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1681 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1684 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
1685 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n", bss_conf->use_cts_prot);
1686 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
1687 ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
1689 ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
1690 if (bss_conf->use_cts_prot)
1691 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
1693 ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
1696 if (changes & BSS_CHANGED_BASIC_RATES) {
1697 /* XXX use this information
1699 * To do that, remove code from iwl_set_rate() and put something
1703 ctx->staging.ofdm_basic_rates =
1704 bss_conf->basic_rates;
1706 ctx->staging.ofdm_basic_rates =
1707 bss_conf->basic_rates >> 4;
1708 ctx->staging.cck_basic_rates =
1709 bss_conf->basic_rates & 0xF;
1713 if (changes & BSS_CHANGED_HT) {
1714 iwl_ht_conf(priv, vif);
1716 if (priv->cfg->ops->hcmd->set_rxon_chain)
1717 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
1720 if (changes & BSS_CHANGED_ASSOC) {
1721 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
1722 if (bss_conf->assoc) {
1723 priv->timestamp = bss_conf->timestamp;
1725 iwl_led_associate(priv);
1727 if (!iwl_is_rfkill(priv))
1728 priv->cfg->ops->lib->post_associate(priv, vif);
1730 iwl_set_no_assoc(priv, vif);
1733 if (changes && iwl_is_associated_ctx(ctx) && bss_conf->aid) {
1734 IWL_DEBUG_MAC80211(priv, "Changes (%#x) while associated\n",
1736 ret = iwl_send_rxon_assoc(priv, ctx);
1738 /* Sync active_rxon with latest change. */
1739 memcpy((void *)&ctx->active,
1741 sizeof(struct iwl_rxon_cmd));
1745 if (changes & BSS_CHANGED_BEACON_ENABLED) {
1746 if (vif->bss_conf.enable_beacon) {
1747 memcpy(ctx->staging.bssid_addr,
1748 bss_conf->bssid, ETH_ALEN);
1749 memcpy(priv->bssid, bss_conf->bssid, ETH_ALEN);
1750 iwlcore_config_ap(priv, vif);
1752 iwl_set_no_assoc(priv, vif);
1755 if (changes & BSS_CHANGED_IBSS) {
1756 ret = priv->cfg->ops->lib->manage_ibss_station(priv, vif,
1757 bss_conf->ibss_joined);
1759 IWL_ERR(priv, "failed to %s IBSS station %pM\n",
1760 bss_conf->ibss_joined ? "add" : "remove",
1764 if (changes & BSS_CHANGED_IDLE &&
1765 priv->cfg->ops->hcmd->set_pan_params) {
1766 if (priv->cfg->ops->hcmd->set_pan_params(priv))
1767 IWL_ERR(priv, "failed to update PAN params\n");
1770 mutex_unlock(&priv->mutex);
1772 IWL_DEBUG_MAC80211(priv, "leave\n");
1774 EXPORT_SYMBOL(iwl_bss_info_changed);
1776 static int iwl_set_mode(struct iwl_priv *priv, struct ieee80211_vif *vif)
1778 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1780 iwl_connection_init_rx_config(priv, ctx);
1782 if (priv->cfg->ops->hcmd->set_rxon_chain)
1783 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
1785 return iwlcore_commit_rxon(priv, ctx);
1788 int iwl_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1790 struct iwl_priv *priv = hw->priv;
1791 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
1792 struct iwl_rxon_context *tmp, *ctx = NULL;
1795 IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n",
1796 vif->type, vif->addr);
1798 mutex_lock(&priv->mutex);
1800 if (!iwl_is_ready_rf(priv)) {
1801 IWL_WARN(priv, "Try to add interface when device not ready\n");
1806 for_each_context(priv, tmp) {
1807 u32 possible_modes =
1808 tmp->interface_modes | tmp->exclusive_interface_modes;
1811 /* check if this busy context is exclusive */
1812 if (tmp->exclusive_interface_modes &
1813 BIT(tmp->vif->type)) {
1820 if (!(possible_modes & BIT(vif->type)))
1823 /* have maybe usable context w/o interface */
1833 vif_priv->ctx = ctx;
1836 * This variable will be correct only when there's just
1837 * a single context, but all code using it is for hardware
1838 * that supports only one context.
1840 priv->iw_mode = vif->type;
1842 ctx->is_active = true;
1844 err = iwl_set_mode(priv, vif);
1846 if (!ctx->always_active)
1847 ctx->is_active = false;
1851 if (priv->cfg->bt_params &&
1852 priv->cfg->bt_params->advanced_bt_coexist &&
1853 vif->type == NL80211_IFTYPE_ADHOC) {
1855 * pretend to have high BT traffic as long as we
1856 * are operating in IBSS mode, as this will cause
1857 * the rate scaling etc. to behave as intended.
1859 priv->bt_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
1866 priv->iw_mode = NL80211_IFTYPE_STATION;
1868 mutex_unlock(&priv->mutex);
1870 IWL_DEBUG_MAC80211(priv, "leave\n");
1873 EXPORT_SYMBOL(iwl_mac_add_interface);
1875 void iwl_mac_remove_interface(struct ieee80211_hw *hw,
1876 struct ieee80211_vif *vif)
1878 struct iwl_priv *priv = hw->priv;
1879 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1881 IWL_DEBUG_MAC80211(priv, "enter\n");
1883 mutex_lock(&priv->mutex);
1885 WARN_ON(ctx->vif != vif);
1888 if (priv->scan_vif == vif) {
1889 iwl_scan_cancel_timeout(priv, 200);
1890 iwl_force_scan_end(priv);
1892 iwl_set_mode(priv, vif);
1894 if (!ctx->always_active)
1895 ctx->is_active = false;
1898 * When removing the IBSS interface, overwrite the
1899 * BT traffic load with the stored one from the last
1900 * notification, if any. If this is a device that
1901 * doesn't implement this, this has no effect since
1902 * both values are the same and zero.
1904 if (vif->type == NL80211_IFTYPE_ADHOC)
1905 priv->bt_traffic_load = priv->notif_bt_traffic_load;
1907 memset(priv->bssid, 0, ETH_ALEN);
1908 mutex_unlock(&priv->mutex);
1910 IWL_DEBUG_MAC80211(priv, "leave\n");
1913 EXPORT_SYMBOL(iwl_mac_remove_interface);
1916 * iwl_mac_config - mac80211 config callback
1918 int iwl_mac_config(struct ieee80211_hw *hw, u32 changed)
1920 struct iwl_priv *priv = hw->priv;
1921 const struct iwl_channel_info *ch_info;
1922 struct ieee80211_conf *conf = &hw->conf;
1923 struct ieee80211_channel *channel = conf->channel;
1924 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
1925 struct iwl_rxon_context *ctx;
1926 unsigned long flags = 0;
1929 int scan_active = 0;
1931 mutex_lock(&priv->mutex);
1933 IWL_DEBUG_MAC80211(priv, "enter to channel %d changed 0x%X\n",
1934 channel->hw_value, changed);
1936 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
1937 test_bit(STATUS_SCANNING, &priv->status))) {
1939 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
1942 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
1943 IEEE80211_CONF_CHANGE_CHANNEL)) {
1944 /* mac80211 uses static for non-HT which is what we want */
1945 priv->current_ht_config.smps = conf->smps_mode;
1948 * Recalculate chain counts.
1950 * If monitor mode is enabled then mac80211 will
1951 * set up the SM PS mode to OFF if an HT channel is
1954 if (priv->cfg->ops->hcmd->set_rxon_chain)
1955 for_each_context(priv, ctx)
1956 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
1959 /* during scanning mac80211 will delay channel setting until
1960 * scan finish with changed = 0
1962 if (!changed || (changed & IEEE80211_CONF_CHANGE_CHANNEL)) {
1966 ch = channel->hw_value;
1967 ch_info = iwl_get_channel_info(priv, channel->band, ch);
1968 if (!is_channel_valid(ch_info)) {
1969 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
1974 spin_lock_irqsave(&priv->lock, flags);
1976 for_each_context(priv, ctx) {
1977 /* Configure HT40 channels */
1978 ctx->ht.enabled = conf_is_ht(conf);
1979 if (ctx->ht.enabled) {
1980 if (conf_is_ht40_minus(conf)) {
1981 ctx->ht.extension_chan_offset =
1982 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
1983 ctx->ht.is_40mhz = true;
1984 } else if (conf_is_ht40_plus(conf)) {
1985 ctx->ht.extension_chan_offset =
1986 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
1987 ctx->ht.is_40mhz = true;
1989 ctx->ht.extension_chan_offset =
1990 IEEE80211_HT_PARAM_CHA_SEC_NONE;
1991 ctx->ht.is_40mhz = false;
1994 ctx->ht.is_40mhz = false;
1997 * Default to no protection. Protection mode will
1998 * later be set from BSS config in iwl_ht_conf
2000 ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
2002 /* if we are switching from ht to 2.4 clear flags
2003 * from any ht related info since 2.4 does not
2005 if ((le16_to_cpu(ctx->staging.channel) != ch))
2006 ctx->staging.flags = 0;
2008 iwl_set_rxon_channel(priv, channel, ctx);
2009 iwl_set_rxon_ht(priv, ht_conf);
2011 iwl_set_flags_for_band(priv, ctx, channel->band,
2015 spin_unlock_irqrestore(&priv->lock, flags);
2017 if (priv->cfg->ops->lib->update_bcast_stations)
2018 ret = priv->cfg->ops->lib->update_bcast_stations(priv);
2021 /* The list of supported rates and rate mask can be different
2022 * for each band; since the band may have changed, reset
2023 * the rate mask to what mac80211 lists */
2027 if (changed & (IEEE80211_CONF_CHANGE_PS |
2028 IEEE80211_CONF_CHANGE_IDLE)) {
2029 ret = iwl_power_update_mode(priv, false);
2031 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
2034 if (changed & IEEE80211_CONF_CHANGE_POWER) {
2035 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
2036 priv->tx_power_user_lmt, conf->power_level);
2038 iwl_set_tx_power(priv, conf->power_level, false);
2041 if (!iwl_is_ready(priv)) {
2042 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
2049 for_each_context(priv, ctx) {
2050 if (memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging)))
2051 iwlcore_commit_rxon(priv, ctx);
2053 IWL_DEBUG_INFO(priv,
2054 "Not re-sending same RXON configuration.\n");
2058 IWL_DEBUG_MAC80211(priv, "leave\n");
2059 mutex_unlock(&priv->mutex);
2062 EXPORT_SYMBOL(iwl_mac_config);
2064 void iwl_mac_reset_tsf(struct ieee80211_hw *hw)
2066 struct iwl_priv *priv = hw->priv;
2067 unsigned long flags;
2068 /* IBSS can only be the IWL_RXON_CTX_BSS context */
2069 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
2071 mutex_lock(&priv->mutex);
2072 IWL_DEBUG_MAC80211(priv, "enter\n");
2074 spin_lock_irqsave(&priv->lock, flags);
2075 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_config));
2076 spin_unlock_irqrestore(&priv->lock, flags);
2078 spin_lock_irqsave(&priv->lock, flags);
2080 /* new association get rid of ibss beacon skb */
2081 if (priv->ibss_beacon)
2082 dev_kfree_skb(priv->ibss_beacon);
2084 priv->ibss_beacon = NULL;
2086 priv->timestamp = 0;
2088 spin_unlock_irqrestore(&priv->lock, flags);
2090 iwl_scan_cancel_timeout(priv, 100);
2091 if (!iwl_is_ready_rf(priv)) {
2092 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
2093 mutex_unlock(&priv->mutex);
2097 /* we are restarting association process
2098 * clear RXON_FILTER_ASSOC_MSK bit
2100 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2101 iwlcore_commit_rxon(priv, ctx);
2105 mutex_unlock(&priv->mutex);
2107 IWL_DEBUG_MAC80211(priv, "leave\n");
2109 EXPORT_SYMBOL(iwl_mac_reset_tsf);
2111 int iwl_alloc_txq_mem(struct iwl_priv *priv)
2114 priv->txq = kzalloc(
2115 sizeof(struct iwl_tx_queue) *
2116 priv->cfg->base_params->num_of_queues,
2119 IWL_ERR(priv, "Not enough memory for txq\n");
2124 EXPORT_SYMBOL(iwl_alloc_txq_mem);
2126 void iwl_free_txq_mem(struct iwl_priv *priv)
2131 EXPORT_SYMBOL(iwl_free_txq_mem);
2133 #ifdef CONFIG_IWLWIFI_DEBUGFS
2135 #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
2137 void iwl_reset_traffic_log(struct iwl_priv *priv)
2139 priv->tx_traffic_idx = 0;
2140 priv->rx_traffic_idx = 0;
2141 if (priv->tx_traffic)
2142 memset(priv->tx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
2143 if (priv->rx_traffic)
2144 memset(priv->rx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
2147 int iwl_alloc_traffic_mem(struct iwl_priv *priv)
2149 u32 traffic_size = IWL_TRAFFIC_DUMP_SIZE;
2151 if (iwl_debug_level & IWL_DL_TX) {
2152 if (!priv->tx_traffic) {
2154 kzalloc(traffic_size, GFP_KERNEL);
2155 if (!priv->tx_traffic)
2159 if (iwl_debug_level & IWL_DL_RX) {
2160 if (!priv->rx_traffic) {
2162 kzalloc(traffic_size, GFP_KERNEL);
2163 if (!priv->rx_traffic)
2167 iwl_reset_traffic_log(priv);
2170 EXPORT_SYMBOL(iwl_alloc_traffic_mem);
2172 void iwl_free_traffic_mem(struct iwl_priv *priv)
2174 kfree(priv->tx_traffic);
2175 priv->tx_traffic = NULL;
2177 kfree(priv->rx_traffic);
2178 priv->rx_traffic = NULL;
2180 EXPORT_SYMBOL(iwl_free_traffic_mem);
2182 void iwl_dbg_log_tx_data_frame(struct iwl_priv *priv,
2183 u16 length, struct ieee80211_hdr *header)
2188 if (likely(!(iwl_debug_level & IWL_DL_TX)))
2191 if (!priv->tx_traffic)
2194 fc = header->frame_control;
2195 if (ieee80211_is_data(fc)) {
2196 len = (length > IWL_TRAFFIC_ENTRY_SIZE)
2197 ? IWL_TRAFFIC_ENTRY_SIZE : length;
2198 memcpy((priv->tx_traffic +
2199 (priv->tx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
2201 priv->tx_traffic_idx =
2202 (priv->tx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
2205 EXPORT_SYMBOL(iwl_dbg_log_tx_data_frame);
2207 void iwl_dbg_log_rx_data_frame(struct iwl_priv *priv,
2208 u16 length, struct ieee80211_hdr *header)
2213 if (likely(!(iwl_debug_level & IWL_DL_RX)))
2216 if (!priv->rx_traffic)
2219 fc = header->frame_control;
2220 if (ieee80211_is_data(fc)) {
2221 len = (length > IWL_TRAFFIC_ENTRY_SIZE)
2222 ? IWL_TRAFFIC_ENTRY_SIZE : length;
2223 memcpy((priv->rx_traffic +
2224 (priv->rx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
2226 priv->rx_traffic_idx =
2227 (priv->rx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
2230 EXPORT_SYMBOL(iwl_dbg_log_rx_data_frame);
2232 const char *get_mgmt_string(int cmd)
2235 IWL_CMD(MANAGEMENT_ASSOC_REQ);
2236 IWL_CMD(MANAGEMENT_ASSOC_RESP);
2237 IWL_CMD(MANAGEMENT_REASSOC_REQ);
2238 IWL_CMD(MANAGEMENT_REASSOC_RESP);
2239 IWL_CMD(MANAGEMENT_PROBE_REQ);
2240 IWL_CMD(MANAGEMENT_PROBE_RESP);
2241 IWL_CMD(MANAGEMENT_BEACON);
2242 IWL_CMD(MANAGEMENT_ATIM);
2243 IWL_CMD(MANAGEMENT_DISASSOC);
2244 IWL_CMD(MANAGEMENT_AUTH);
2245 IWL_CMD(MANAGEMENT_DEAUTH);
2246 IWL_CMD(MANAGEMENT_ACTION);
2253 const char *get_ctrl_string(int cmd)
2256 IWL_CMD(CONTROL_BACK_REQ);
2257 IWL_CMD(CONTROL_BACK);
2258 IWL_CMD(CONTROL_PSPOLL);
2259 IWL_CMD(CONTROL_RTS);
2260 IWL_CMD(CONTROL_CTS);
2261 IWL_CMD(CONTROL_ACK);
2262 IWL_CMD(CONTROL_CFEND);
2263 IWL_CMD(CONTROL_CFENDACK);
2270 void iwl_clear_traffic_stats(struct iwl_priv *priv)
2272 memset(&priv->tx_stats, 0, sizeof(struct traffic_stats));
2273 memset(&priv->rx_stats, 0, sizeof(struct traffic_stats));
2278 * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will
2279 * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass.
2280 * Use debugFs to display the rx/rx_statistics
2281 * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL
2282 * information will be recorded, but DATA pkt still will be recorded
2283 * for the reason of iwl_led.c need to control the led blinking based on
2284 * number of tx and rx data.
2287 void iwl_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len)
2289 struct traffic_stats *stats;
2292 stats = &priv->tx_stats;
2294 stats = &priv->rx_stats;
2296 if (ieee80211_is_mgmt(fc)) {
2297 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
2298 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
2299 stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
2301 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
2302 stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
2304 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
2305 stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
2307 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
2308 stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
2310 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
2311 stats->mgmt[MANAGEMENT_PROBE_REQ]++;
2313 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
2314 stats->mgmt[MANAGEMENT_PROBE_RESP]++;
2316 case cpu_to_le16(IEEE80211_STYPE_BEACON):
2317 stats->mgmt[MANAGEMENT_BEACON]++;
2319 case cpu_to_le16(IEEE80211_STYPE_ATIM):
2320 stats->mgmt[MANAGEMENT_ATIM]++;
2322 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
2323 stats->mgmt[MANAGEMENT_DISASSOC]++;
2325 case cpu_to_le16(IEEE80211_STYPE_AUTH):
2326 stats->mgmt[MANAGEMENT_AUTH]++;
2328 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
2329 stats->mgmt[MANAGEMENT_DEAUTH]++;
2331 case cpu_to_le16(IEEE80211_STYPE_ACTION):
2332 stats->mgmt[MANAGEMENT_ACTION]++;
2335 } else if (ieee80211_is_ctl(fc)) {
2336 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
2337 case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
2338 stats->ctrl[CONTROL_BACK_REQ]++;
2340 case cpu_to_le16(IEEE80211_STYPE_BACK):
2341 stats->ctrl[CONTROL_BACK]++;
2343 case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
2344 stats->ctrl[CONTROL_PSPOLL]++;
2346 case cpu_to_le16(IEEE80211_STYPE_RTS):
2347 stats->ctrl[CONTROL_RTS]++;
2349 case cpu_to_le16(IEEE80211_STYPE_CTS):
2350 stats->ctrl[CONTROL_CTS]++;
2352 case cpu_to_le16(IEEE80211_STYPE_ACK):
2353 stats->ctrl[CONTROL_ACK]++;
2355 case cpu_to_le16(IEEE80211_STYPE_CFEND):
2356 stats->ctrl[CONTROL_CFEND]++;
2358 case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
2359 stats->ctrl[CONTROL_CFENDACK]++;
2365 stats->data_bytes += len;
2367 iwl_leds_background(priv);
2369 EXPORT_SYMBOL(iwl_update_stats);
2372 static const char *get_csr_string(int cmd)
2375 IWL_CMD(CSR_HW_IF_CONFIG_REG);
2376 IWL_CMD(CSR_INT_COALESCING);
2378 IWL_CMD(CSR_INT_MASK);
2379 IWL_CMD(CSR_FH_INT_STATUS);
2380 IWL_CMD(CSR_GPIO_IN);
2382 IWL_CMD(CSR_GP_CNTRL);
2383 IWL_CMD(CSR_HW_REV);
2384 IWL_CMD(CSR_EEPROM_REG);
2385 IWL_CMD(CSR_EEPROM_GP);
2386 IWL_CMD(CSR_OTP_GP_REG);
2387 IWL_CMD(CSR_GIO_REG);
2388 IWL_CMD(CSR_GP_UCODE_REG);
2389 IWL_CMD(CSR_GP_DRIVER_REG);
2390 IWL_CMD(CSR_UCODE_DRV_GP1);
2391 IWL_CMD(CSR_UCODE_DRV_GP2);
2392 IWL_CMD(CSR_LED_REG);
2393 IWL_CMD(CSR_DRAM_INT_TBL_REG);
2394 IWL_CMD(CSR_GIO_CHICKEN_BITS);
2395 IWL_CMD(CSR_ANA_PLL_CFG);
2396 IWL_CMD(CSR_HW_REV_WA_REG);
2397 IWL_CMD(CSR_DBG_HPET_MEM_REG);
2404 void iwl_dump_csr(struct iwl_priv *priv)
2408 CSR_HW_IF_CONFIG_REG,
2426 CSR_DRAM_INT_TBL_REG,
2427 CSR_GIO_CHICKEN_BITS,
2430 CSR_DBG_HPET_MEM_REG
2432 IWL_ERR(priv, "CSR values:\n");
2433 IWL_ERR(priv, "(2nd byte of CSR_INT_COALESCING is "
2434 "CSR_INT_PERIODIC_REG)\n");
2435 for (i = 0; i < ARRAY_SIZE(csr_tbl); i++) {
2436 IWL_ERR(priv, " %25s: 0X%08x\n",
2437 get_csr_string(csr_tbl[i]),
2438 iwl_read32(priv, csr_tbl[i]));
2441 EXPORT_SYMBOL(iwl_dump_csr);
2443 static const char *get_fh_string(int cmd)
2446 IWL_CMD(FH_RSCSR_CHNL0_STTS_WPTR_REG);
2447 IWL_CMD(FH_RSCSR_CHNL0_RBDCB_BASE_REG);
2448 IWL_CMD(FH_RSCSR_CHNL0_WPTR);
2449 IWL_CMD(FH_MEM_RCSR_CHNL0_CONFIG_REG);
2450 IWL_CMD(FH_MEM_RSSR_SHARED_CTRL_REG);
2451 IWL_CMD(FH_MEM_RSSR_RX_STATUS_REG);
2452 IWL_CMD(FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV);
2453 IWL_CMD(FH_TSSR_TX_STATUS_REG);
2454 IWL_CMD(FH_TSSR_TX_ERROR_REG);
2461 int iwl_dump_fh(struct iwl_priv *priv, char **buf, bool display)
2464 #ifdef CONFIG_IWLWIFI_DEBUG
2469 FH_RSCSR_CHNL0_STTS_WPTR_REG,
2470 FH_RSCSR_CHNL0_RBDCB_BASE_REG,
2471 FH_RSCSR_CHNL0_WPTR,
2472 FH_MEM_RCSR_CHNL0_CONFIG_REG,
2473 FH_MEM_RSSR_SHARED_CTRL_REG,
2474 FH_MEM_RSSR_RX_STATUS_REG,
2475 FH_MEM_RSSR_RX_ENABLE_ERR_IRQ2DRV,
2476 FH_TSSR_TX_STATUS_REG,
2477 FH_TSSR_TX_ERROR_REG
2479 #ifdef CONFIG_IWLWIFI_DEBUG
2481 bufsz = ARRAY_SIZE(fh_tbl) * 48 + 40;
2482 *buf = kmalloc(bufsz, GFP_KERNEL);
2485 pos += scnprintf(*buf + pos, bufsz - pos,
2486 "FH register values:\n");
2487 for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
2488 pos += scnprintf(*buf + pos, bufsz - pos,
2490 get_fh_string(fh_tbl[i]),
2491 iwl_read_direct32(priv, fh_tbl[i]));
2496 IWL_ERR(priv, "FH register values:\n");
2497 for (i = 0; i < ARRAY_SIZE(fh_tbl); i++) {
2498 IWL_ERR(priv, " %34s: 0X%08x\n",
2499 get_fh_string(fh_tbl[i]),
2500 iwl_read_direct32(priv, fh_tbl[i]));
2504 EXPORT_SYMBOL(iwl_dump_fh);
2506 static void iwl_force_rf_reset(struct iwl_priv *priv)
2508 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2511 if (!iwl_is_any_associated(priv)) {
2512 IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
2516 * There is no easy and better way to force reset the radio,
2517 * the only known method is switching channel which will force to
2518 * reset and tune the radio.
2519 * Use internal short scan (single channel) operation to should
2520 * achieve this objective.
2521 * Driver should reset the radio when number of consecutive missed
2522 * beacon, or any other uCode error condition detected.
2524 IWL_DEBUG_INFO(priv, "perform radio reset.\n");
2525 iwl_internal_short_hw_scan(priv);
2529 int iwl_force_reset(struct iwl_priv *priv, int mode, bool external)
2531 struct iwl_force_reset *force_reset;
2533 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2536 if (mode >= IWL_MAX_FORCE_RESET) {
2537 IWL_DEBUG_INFO(priv, "invalid reset request.\n");
2540 force_reset = &priv->force_reset[mode];
2541 force_reset->reset_request_count++;
2543 if (force_reset->last_force_reset_jiffies &&
2544 time_after(force_reset->last_force_reset_jiffies +
2545 force_reset->reset_duration, jiffies)) {
2546 IWL_DEBUG_INFO(priv, "force reset rejected\n");
2547 force_reset->reset_reject_count++;
2551 force_reset->reset_success_count++;
2552 force_reset->last_force_reset_jiffies = jiffies;
2553 IWL_DEBUG_INFO(priv, "perform force reset (%d)\n", mode);
2556 iwl_force_rf_reset(priv);
2560 * if the request is from external(ex: debugfs),
2561 * then always perform the request in regardless the module
2563 * if the request is from internal (uCode error or driver
2564 * detect failure), then fw_restart module parameter
2565 * need to be check before performing firmware reload
2567 if (!external && !priv->cfg->mod_params->restart_fw) {
2568 IWL_DEBUG_INFO(priv, "Cancel firmware reload based on "
2569 "module parameter setting\n");
2572 IWL_ERR(priv, "On demand firmware reload\n");
2573 /* Set the FW error flag -- cleared on iwl_down */
2574 set_bit(STATUS_FW_ERROR, &priv->status);
2575 wake_up_interruptible(&priv->wait_command_queue);
2577 * Keep the restart process from trying to send host
2578 * commands by clearing the INIT status bit
2580 clear_bit(STATUS_READY, &priv->status);
2581 queue_work(priv->workqueue, &priv->restart);
2588 * iwl_bg_monitor_recover - Timer callback to check for stuck queue and recover
2590 * During normal condition (no queue is stuck), the timer is continually set to
2591 * execute every monitor_recover_period milliseconds after the last timer
2592 * expired. When the queue read_ptr is at the same place, the timer is
2593 * shorten to 100mSecs. This is
2594 * 1) to reduce the chance that the read_ptr may wrap around (not stuck)
2595 * 2) to detect the stuck queues quicker before the station and AP can
2596 * disassociate each other.
2598 * This function monitors all the tx queues and recover from it if any
2599 * of the queues are stuck.
2600 * 1. It first check the cmd queue for stuck conditions. If it is stuck,
2601 * it will recover by resetting the firmware and return.
2602 * 2. Then, it checks for station association. If it associates it will check
2603 * other queues. If any queue is stuck, it will recover by resetting
2605 * Note: It the number of times the queue read_ptr to be at the same place to
2606 * be MAX_REPEAT+1 in order to consider to be stuck.
2609 * The maximum number of times the read pointer of the tx queue at the
2610 * same place without considering to be stuck.
2612 #define MAX_REPEAT (2)
2613 static int iwl_check_stuck_queue(struct iwl_priv *priv, int cnt)
2615 struct iwl_tx_queue *txq;
2616 struct iwl_queue *q;
2618 txq = &priv->txq[cnt];
2620 /* queue is empty, skip */
2621 if (q->read_ptr == q->write_ptr)
2624 if (q->read_ptr == q->last_read_ptr) {
2625 /* a queue has not been read from last time */
2626 if (q->repeat_same_read_ptr > MAX_REPEAT) {
2628 "queue %d stuck %d time. Fw reload.\n",
2629 q->id, q->repeat_same_read_ptr);
2630 q->repeat_same_read_ptr = 0;
2631 iwl_force_reset(priv, IWL_FW_RESET, false);
2633 q->repeat_same_read_ptr++;
2634 IWL_DEBUG_RADIO(priv,
2635 "queue %d, not read %d time\n",
2637 q->repeat_same_read_ptr);
2638 if (priv->cfg->bt_params &&
2639 !priv->cfg->bt_params->advanced_bt_coexist) {
2640 mod_timer(&priv->monitor_recover,
2641 jiffies + msecs_to_jiffies(
2642 IWL_ONE_HUNDRED_MSECS));
2647 q->last_read_ptr = q->read_ptr;
2648 q->repeat_same_read_ptr = 0;
2653 void iwl_bg_monitor_recover(unsigned long data)
2655 struct iwl_priv *priv = (struct iwl_priv *)data;
2658 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2661 /* monitor and check for stuck cmd queue */
2662 if (iwl_check_stuck_queue(priv, priv->cmd_queue))
2665 /* monitor and check for other stuck queues */
2666 if (iwl_is_any_associated(priv)) {
2667 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
2668 /* skip as we already checked the command queue */
2669 if (cnt == priv->cmd_queue)
2671 if (iwl_check_stuck_queue(priv, cnt))
2675 if (priv->cfg->base_params->monitor_recover_period) {
2677 * Reschedule the timer to occur in
2678 * priv->cfg->base_params->monitor_recover_period
2680 mod_timer(&priv->monitor_recover, jiffies + msecs_to_jiffies(
2681 priv->cfg->base_params->monitor_recover_period));
2684 EXPORT_SYMBOL(iwl_bg_monitor_recover);
2688 * extended beacon time format
2689 * time in usec will be changed into a 32-bit value in extended:internal format
2690 * the extended part is the beacon counts
2691 * the internal part is the time in usec within one beacon interval
2693 u32 iwl_usecs_to_beacons(struct iwl_priv *priv, u32 usec, u32 beacon_interval)
2697 u32 interval = beacon_interval * TIME_UNIT;
2699 if (!interval || !usec)
2702 quot = (usec / interval) &
2703 (iwl_beacon_time_mask_high(priv,
2704 priv->hw_params.beacon_time_tsf_bits) >>
2705 priv->hw_params.beacon_time_tsf_bits);
2706 rem = (usec % interval) & iwl_beacon_time_mask_low(priv,
2707 priv->hw_params.beacon_time_tsf_bits);
2709 return (quot << priv->hw_params.beacon_time_tsf_bits) + rem;
2711 EXPORT_SYMBOL(iwl_usecs_to_beacons);
2713 /* base is usually what we get from ucode with each received frame,
2714 * the same as HW timer counter counting down
2716 __le32 iwl_add_beacon_time(struct iwl_priv *priv, u32 base,
2717 u32 addon, u32 beacon_interval)
2719 u32 base_low = base & iwl_beacon_time_mask_low(priv,
2720 priv->hw_params.beacon_time_tsf_bits);
2721 u32 addon_low = addon & iwl_beacon_time_mask_low(priv,
2722 priv->hw_params.beacon_time_tsf_bits);
2723 u32 interval = beacon_interval * TIME_UNIT;
2724 u32 res = (base & iwl_beacon_time_mask_high(priv,
2725 priv->hw_params.beacon_time_tsf_bits)) +
2726 (addon & iwl_beacon_time_mask_high(priv,
2727 priv->hw_params.beacon_time_tsf_bits));
2729 if (base_low > addon_low)
2730 res += base_low - addon_low;
2731 else if (base_low < addon_low) {
2732 res += interval + base_low - addon_low;
2733 res += (1 << priv->hw_params.beacon_time_tsf_bits);
2735 res += (1 << priv->hw_params.beacon_time_tsf_bits);
2737 return cpu_to_le32(res);
2739 EXPORT_SYMBOL(iwl_add_beacon_time);
2743 int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state)
2745 struct iwl_priv *priv = pci_get_drvdata(pdev);
2748 * This function is called when system goes into suspend state
2749 * mac80211 will call iwl_mac_stop() from the mac80211 suspend function
2750 * first but since iwl_mac_stop() has no knowledge of who the caller is,
2751 * it will not call apm_ops.stop() to stop the DMA operation.
2752 * Calling apm_ops.stop here to make sure we stop the DMA.
2754 priv->cfg->ops->lib->apm_ops.stop(priv);
2756 pci_save_state(pdev);
2757 pci_disable_device(pdev);
2758 pci_set_power_state(pdev, PCI_D3hot);
2762 EXPORT_SYMBOL(iwl_pci_suspend);
2764 int iwl_pci_resume(struct pci_dev *pdev)
2766 struct iwl_priv *priv = pci_get_drvdata(pdev);
2768 bool hw_rfkill = false;
2771 * We disable the RETRY_TIMEOUT register (0x41) to keep
2772 * PCI Tx retries from interfering with C3 CPU state.
2774 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
2776 pci_set_power_state(pdev, PCI_D0);
2777 ret = pci_enable_device(pdev);
2780 pci_restore_state(pdev);
2781 iwl_enable_interrupts(priv);
2783 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
2784 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
2788 set_bit(STATUS_RF_KILL_HW, &priv->status);
2790 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2792 wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rfkill);
2796 EXPORT_SYMBOL(iwl_pci_resume);
2798 #endif /* CONFIG_PM */