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 const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
76 EXPORT_SYMBOL(iwl_bcast_addr);
79 /* This function both allocates and initializes hw and priv. */
80 struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg)
82 struct iwl_priv *priv;
83 /* mac80211 allocates memory for this device instance, including
84 * space for this driver's private structure */
85 struct ieee80211_hw *hw;
87 hw = ieee80211_alloc_hw(sizeof(struct iwl_priv),
88 cfg->ops->ieee80211_ops);
90 pr_err("%s: Can not allocate network device\n",
101 EXPORT_SYMBOL(iwl_alloc_all);
103 #define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
104 #define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
105 static void iwlcore_init_ht_hw_capab(const struct iwl_priv *priv,
106 struct ieee80211_sta_ht_cap *ht_info,
107 enum ieee80211_band band)
109 u16 max_bit_rate = 0;
110 u8 rx_chains_num = priv->hw_params.rx_chains_num;
111 u8 tx_chains_num = priv->hw_params.tx_chains_num;
114 memset(&ht_info->mcs, 0, sizeof(ht_info->mcs));
116 ht_info->ht_supported = true;
118 if (priv->cfg->ht_params &&
119 priv->cfg->ht_params->ht_greenfield_support)
120 ht_info->cap |= IEEE80211_HT_CAP_GRN_FLD;
121 ht_info->cap |= IEEE80211_HT_CAP_SGI_20;
122 max_bit_rate = MAX_BIT_RATE_20_MHZ;
123 if (priv->hw_params.ht40_channel & BIT(band)) {
124 ht_info->cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
125 ht_info->cap |= IEEE80211_HT_CAP_SGI_40;
126 ht_info->mcs.rx_mask[4] = 0x01;
127 max_bit_rate = MAX_BIT_RATE_40_MHZ;
130 if (priv->cfg->mod_params->amsdu_size_8K)
131 ht_info->cap |= IEEE80211_HT_CAP_MAX_AMSDU;
133 ht_info->ampdu_factor = CFG_HT_RX_AMPDU_FACTOR_DEF;
134 if (priv->cfg->bt_params && priv->cfg->bt_params->ampdu_factor)
135 ht_info->ampdu_factor = priv->cfg->bt_params->ampdu_factor;
136 ht_info->ampdu_density = CFG_HT_MPDU_DENSITY_DEF;
137 if (priv->cfg->bt_params && priv->cfg->bt_params->ampdu_density)
138 ht_info->ampdu_density = priv->cfg->bt_params->ampdu_density;
140 ht_info->mcs.rx_mask[0] = 0xFF;
141 if (rx_chains_num >= 2)
142 ht_info->mcs.rx_mask[1] = 0xFF;
143 if (rx_chains_num >= 3)
144 ht_info->mcs.rx_mask[2] = 0xFF;
146 /* Highest supported Rx data rate */
147 max_bit_rate *= rx_chains_num;
148 WARN_ON(max_bit_rate & ~IEEE80211_HT_MCS_RX_HIGHEST_MASK);
149 ht_info->mcs.rx_highest = cpu_to_le16(max_bit_rate);
151 /* Tx MCS capabilities */
152 ht_info->mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
153 if (tx_chains_num != rx_chains_num) {
154 ht_info->mcs.tx_params |= IEEE80211_HT_MCS_TX_RX_DIFF;
155 ht_info->mcs.tx_params |= ((tx_chains_num - 1) <<
156 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT);
161 * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom
163 int iwlcore_init_geos(struct iwl_priv *priv)
165 struct iwl_channel_info *ch;
166 struct ieee80211_supported_band *sband;
167 struct ieee80211_channel *channels;
168 struct ieee80211_channel *geo_ch;
169 struct ieee80211_rate *rates;
172 if (priv->bands[IEEE80211_BAND_2GHZ].n_bitrates ||
173 priv->bands[IEEE80211_BAND_5GHZ].n_bitrates) {
174 IWL_DEBUG_INFO(priv, "Geography modes already initialized.\n");
175 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
179 channels = kzalloc(sizeof(struct ieee80211_channel) *
180 priv->channel_count, GFP_KERNEL);
184 rates = kzalloc((sizeof(struct ieee80211_rate) * IWL_RATE_COUNT_LEGACY),
191 /* 5.2GHz channels start after the 2.4GHz channels */
192 sband = &priv->bands[IEEE80211_BAND_5GHZ];
193 sband->channels = &channels[ARRAY_SIZE(iwl_eeprom_band_1)];
195 sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
196 sband->n_bitrates = IWL_RATE_COUNT_LEGACY - IWL_FIRST_OFDM_RATE;
198 if (priv->cfg->sku & IWL_SKU_N)
199 iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
200 IEEE80211_BAND_5GHZ);
202 sband = &priv->bands[IEEE80211_BAND_2GHZ];
203 sband->channels = channels;
205 sband->bitrates = rates;
206 sband->n_bitrates = IWL_RATE_COUNT_LEGACY;
208 if (priv->cfg->sku & IWL_SKU_N)
209 iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
210 IEEE80211_BAND_2GHZ);
212 priv->ieee_channels = channels;
213 priv->ieee_rates = rates;
215 for (i = 0; i < priv->channel_count; i++) {
216 ch = &priv->channel_info[i];
218 /* FIXME: might be removed if scan is OK */
219 if (!is_channel_valid(ch))
222 if (is_channel_a_band(ch))
223 sband = &priv->bands[IEEE80211_BAND_5GHZ];
225 sband = &priv->bands[IEEE80211_BAND_2GHZ];
227 geo_ch = &sband->channels[sband->n_channels++];
229 geo_ch->center_freq =
230 ieee80211_channel_to_frequency(ch->channel,
232 geo_ch->max_power = ch->max_power_avg;
233 geo_ch->max_antenna_gain = 0xff;
234 geo_ch->hw_value = ch->channel;
236 if (is_channel_valid(ch)) {
237 if (!(ch->flags & EEPROM_CHANNEL_IBSS))
238 geo_ch->flags |= IEEE80211_CHAN_NO_IBSS;
240 if (!(ch->flags & EEPROM_CHANNEL_ACTIVE))
241 geo_ch->flags |= IEEE80211_CHAN_PASSIVE_SCAN;
243 if (ch->flags & EEPROM_CHANNEL_RADAR)
244 geo_ch->flags |= IEEE80211_CHAN_RADAR;
246 geo_ch->flags |= ch->ht40_extension_channel;
248 if (ch->max_power_avg > priv->tx_power_device_lmt)
249 priv->tx_power_device_lmt = ch->max_power_avg;
251 geo_ch->flags |= IEEE80211_CHAN_DISABLED;
254 IWL_DEBUG_INFO(priv, "Channel %d Freq=%d[%sGHz] %s flag=0x%X\n",
255 ch->channel, geo_ch->center_freq,
256 is_channel_a_band(ch) ? "5.2" : "2.4",
257 geo_ch->flags & IEEE80211_CHAN_DISABLED ?
258 "restricted" : "valid",
262 if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
263 priv->cfg->sku & IWL_SKU_A) {
264 IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
265 "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
266 priv->pci_dev->device,
267 priv->pci_dev->subsystem_device);
268 priv->cfg->sku &= ~IWL_SKU_A;
271 IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
272 priv->bands[IEEE80211_BAND_2GHZ].n_channels,
273 priv->bands[IEEE80211_BAND_5GHZ].n_channels);
275 set_bit(STATUS_GEO_CONFIGURED, &priv->status);
279 EXPORT_SYMBOL(iwlcore_init_geos);
282 * iwlcore_free_geos - undo allocations in iwlcore_init_geos
284 void iwlcore_free_geos(struct iwl_priv *priv)
286 kfree(priv->ieee_channels);
287 kfree(priv->ieee_rates);
288 clear_bit(STATUS_GEO_CONFIGURED, &priv->status);
290 EXPORT_SYMBOL(iwlcore_free_geos);
292 static bool iwl_is_channel_extension(struct iwl_priv *priv,
293 enum ieee80211_band band,
294 u16 channel, u8 extension_chan_offset)
296 const struct iwl_channel_info *ch_info;
298 ch_info = iwl_get_channel_info(priv, band, channel);
299 if (!is_channel_valid(ch_info))
302 if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
303 return !(ch_info->ht40_extension_channel &
304 IEEE80211_CHAN_NO_HT40PLUS);
305 else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW)
306 return !(ch_info->ht40_extension_channel &
307 IEEE80211_CHAN_NO_HT40MINUS);
312 bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
313 struct iwl_rxon_context *ctx,
314 struct ieee80211_sta_ht_cap *ht_cap)
316 if (!ctx->ht.enabled || !ctx->ht.is_40mhz)
320 * We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
321 * the bit will not set if it is pure 40MHz case
323 if (ht_cap && !ht_cap->ht_supported)
326 #ifdef CONFIG_IWLWIFI_DEBUGFS
327 if (priv->disable_ht40)
331 return iwl_is_channel_extension(priv, priv->band,
332 le16_to_cpu(ctx->staging.channel),
333 ctx->ht.extension_chan_offset);
335 EXPORT_SYMBOL(iwl_is_ht40_tx_allowed);
337 static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
343 * If mac80211 hasn't given us a beacon interval, program
344 * the default into the device (not checking this here
345 * would cause the adjustment below to return the maximum
346 * value, which may break PAN.)
349 return DEFAULT_BEACON_INTERVAL;
352 * If the beacon interval we obtained from the peer
353 * is too large, we'll have to wake up more often
354 * (and in IBSS case, we'll beacon too much)
356 * For example, if max_beacon_val is 4096, and the
357 * requested beacon interval is 7000, we'll have to
358 * use 3500 to be able to wake up on the beacons.
360 * This could badly influence beacon detection stats.
363 beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
364 new_val = beacon_val / beacon_factor;
367 new_val = max_beacon_val;
372 int iwl_send_rxon_timing(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
375 s32 interval_tm, rem;
376 struct ieee80211_conf *conf = NULL;
378 struct ieee80211_vif *vif = ctx->vif;
380 conf = ieee80211_get_hw_conf(priv->hw);
382 lockdep_assert_held(&priv->mutex);
384 memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd));
386 ctx->timing.timestamp = cpu_to_le64(priv->timestamp);
387 ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
389 beacon_int = vif ? vif->bss_conf.beacon_int : 0;
392 * TODO: For IBSS we need to get atim_window from mac80211,
393 * for now just always use 0
395 ctx->timing.atim_window = 0;
397 if (ctx->ctxid == IWL_RXON_CTX_PAN &&
398 (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) &&
399 iwl_is_associated(priv, IWL_RXON_CTX_BSS) &&
400 priv->contexts[IWL_RXON_CTX_BSS].vif &&
401 priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) {
402 ctx->timing.beacon_interval =
403 priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval;
404 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
405 } else if (ctx->ctxid == IWL_RXON_CTX_BSS &&
406 iwl_is_associated(priv, IWL_RXON_CTX_PAN) &&
407 priv->contexts[IWL_RXON_CTX_PAN].vif &&
408 priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int &&
409 (!iwl_is_associated_ctx(ctx) || !ctx->vif ||
410 !ctx->vif->bss_conf.beacon_int)) {
411 ctx->timing.beacon_interval =
412 priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval;
413 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
415 beacon_int = iwl_adjust_beacon_interval(beacon_int,
416 priv->hw_params.max_beacon_itrvl * TIME_UNIT);
417 ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
420 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
421 interval_tm = beacon_int * TIME_UNIT;
422 rem = do_div(tsf, interval_tm);
423 ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
425 ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
427 IWL_DEBUG_ASSOC(priv,
428 "beacon interval %d beacon timer %d beacon tim %d\n",
429 le16_to_cpu(ctx->timing.beacon_interval),
430 le32_to_cpu(ctx->timing.beacon_init_val),
431 le16_to_cpu(ctx->timing.atim_window));
433 return iwl_send_cmd_pdu(priv, ctx->rxon_timing_cmd,
434 sizeof(ctx->timing), &ctx->timing);
436 EXPORT_SYMBOL(iwl_send_rxon_timing);
438 void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, struct iwl_rxon_context *ctx,
441 struct iwl_rxon_cmd *rxon = &ctx->staging;
444 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
446 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
449 EXPORT_SYMBOL(iwl_set_rxon_hwcrypto);
451 /* validate RXON structure is valid */
452 int iwl_check_rxon_cmd(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
454 struct iwl_rxon_cmd *rxon = &ctx->staging;
457 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
458 if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) {
459 IWL_WARN(priv, "check 2.4G: wrong narrow\n");
462 if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) {
463 IWL_WARN(priv, "check 2.4G: wrong radar\n");
467 if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) {
468 IWL_WARN(priv, "check 5.2G: not short slot!\n");
471 if (rxon->flags & RXON_FLG_CCK_MSK) {
472 IWL_WARN(priv, "check 5.2G: CCK!\n");
476 if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) {
477 IWL_WARN(priv, "mac/bssid mcast!\n");
481 /* make sure basic rates 6Mbps and 1Mbps are supported */
482 if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 &&
483 (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) {
484 IWL_WARN(priv, "neither 1 nor 6 are basic\n");
488 if (le16_to_cpu(rxon->assoc_id) > 2007) {
489 IWL_WARN(priv, "aid > 2007\n");
493 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
494 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) {
495 IWL_WARN(priv, "CCK and short slot\n");
499 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
500 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) {
501 IWL_WARN(priv, "CCK and auto detect");
505 if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
506 RXON_FLG_TGG_PROTECT_MSK)) ==
507 RXON_FLG_TGG_PROTECT_MSK) {
508 IWL_WARN(priv, "TGg but no auto-detect\n");
513 IWL_WARN(priv, "Tuning to channel %d\n",
514 le16_to_cpu(rxon->channel));
517 IWL_ERR(priv, "Invalid RXON\n");
522 EXPORT_SYMBOL(iwl_check_rxon_cmd);
525 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
526 * @priv: staging_rxon is compared to active_rxon
528 * If the RXON structure is changing enough to require a new tune,
529 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
530 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
532 int iwl_full_rxon_required(struct iwl_priv *priv,
533 struct iwl_rxon_context *ctx)
535 const struct iwl_rxon_cmd *staging = &ctx->staging;
536 const struct iwl_rxon_cmd *active = &ctx->active;
540 IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
544 #define CHK_NEQ(c1, c2) \
545 if ((c1) != (c2)) { \
546 IWL_DEBUG_INFO(priv, "need full RXON - " \
547 #c1 " != " #c2 " - %d != %d\n", \
552 /* These items are only settable from the full RXON command */
553 CHK(!iwl_is_associated_ctx(ctx));
554 CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr));
555 CHK(compare_ether_addr(staging->node_addr, active->node_addr));
556 CHK(compare_ether_addr(staging->wlap_bssid_addr,
557 active->wlap_bssid_addr));
558 CHK_NEQ(staging->dev_type, active->dev_type);
559 CHK_NEQ(staging->channel, active->channel);
560 CHK_NEQ(staging->air_propagation, active->air_propagation);
561 CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
562 active->ofdm_ht_single_stream_basic_rates);
563 CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
564 active->ofdm_ht_dual_stream_basic_rates);
565 CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates,
566 active->ofdm_ht_triple_stream_basic_rates);
567 CHK_NEQ(staging->assoc_id, active->assoc_id);
569 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
570 * be updated with the RXON_ASSOC command -- however only some
571 * flag transitions are allowed using RXON_ASSOC */
573 /* Check if we are not switching bands */
574 CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
575 active->flags & RXON_FLG_BAND_24G_MSK);
577 /* Check if we are switching association toggle */
578 CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
579 active->filter_flags & RXON_FILTER_ASSOC_MSK);
586 EXPORT_SYMBOL(iwl_full_rxon_required);
588 u8 iwl_rate_get_lowest_plcp(struct iwl_priv *priv,
589 struct iwl_rxon_context *ctx)
592 * Assign the lowest rate -- should really get this from
593 * the beacon skb from mac80211.
595 if (ctx->staging.flags & RXON_FLG_BAND_24G_MSK)
596 return IWL_RATE_1M_PLCP;
598 return IWL_RATE_6M_PLCP;
600 EXPORT_SYMBOL(iwl_rate_get_lowest_plcp);
602 static void _iwl_set_rxon_ht(struct iwl_priv *priv,
603 struct iwl_ht_config *ht_conf,
604 struct iwl_rxon_context *ctx)
606 struct iwl_rxon_cmd *rxon = &ctx->staging;
608 if (!ctx->ht.enabled) {
609 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
610 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
611 RXON_FLG_HT40_PROT_MSK |
612 RXON_FLG_HT_PROT_MSK);
616 /* FIXME: if the definition of ht.protection changed, the "translation"
617 * will be needed for rxon->flags
619 rxon->flags |= cpu_to_le32(ctx->ht.protection << RXON_FLG_HT_OPERATING_MODE_POS);
621 /* Set up channel bandwidth:
622 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
623 /* clear the HT channel mode before set the mode */
624 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
625 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
626 if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
628 if (ctx->ht.protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
629 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
630 /* Note: control channel is opposite of extension channel */
631 switch (ctx->ht.extension_chan_offset) {
632 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
633 rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
635 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
636 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
640 /* Note: control channel is opposite of extension channel */
641 switch (ctx->ht.extension_chan_offset) {
642 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
643 rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
644 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
646 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
647 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
648 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
650 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
652 /* channel location only valid if in Mixed mode */
653 IWL_ERR(priv, "invalid extension channel offset\n");
658 rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
661 if (priv->cfg->ops->hcmd->set_rxon_chain)
662 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
664 IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
665 "extension channel offset 0x%x\n",
666 le32_to_cpu(rxon->flags), ctx->ht.protection,
667 ctx->ht.extension_chan_offset);
670 void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
672 struct iwl_rxon_context *ctx;
674 for_each_context(priv, ctx)
675 _iwl_set_rxon_ht(priv, ht_conf, ctx);
677 EXPORT_SYMBOL(iwl_set_rxon_ht);
679 /* Return valid, unused, channel for a passive scan to reset the RF */
680 u8 iwl_get_single_channel_number(struct iwl_priv *priv,
681 enum ieee80211_band band)
683 const struct iwl_channel_info *ch_info;
687 struct iwl_rxon_context *ctx;
689 if (band == IEEE80211_BAND_5GHZ) {
691 max = priv->channel_count;
697 for (i = min; i < max; i++) {
700 for_each_context(priv, ctx) {
701 busy = priv->channel_info[i].channel ==
702 le16_to_cpu(ctx->staging.channel);
710 channel = priv->channel_info[i].channel;
711 ch_info = iwl_get_channel_info(priv, band, channel);
712 if (is_channel_valid(ch_info))
718 EXPORT_SYMBOL(iwl_get_single_channel_number);
721 * iwl_set_rxon_channel - Set the band and channel values in staging RXON
722 * @ch: requested channel as a pointer to struct ieee80211_channel
724 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
725 * in the staging RXON flag structure based on the ch->band
727 int iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
728 struct iwl_rxon_context *ctx)
730 enum ieee80211_band band = ch->band;
731 u16 channel = ch->hw_value;
733 if ((le16_to_cpu(ctx->staging.channel) == channel) &&
734 (priv->band == band))
737 ctx->staging.channel = cpu_to_le16(channel);
738 if (band == IEEE80211_BAND_5GHZ)
739 ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
741 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
745 IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
749 EXPORT_SYMBOL(iwl_set_rxon_channel);
751 void iwl_set_flags_for_band(struct iwl_priv *priv,
752 struct iwl_rxon_context *ctx,
753 enum ieee80211_band band,
754 struct ieee80211_vif *vif)
756 if (band == IEEE80211_BAND_5GHZ) {
757 ctx->staging.flags &=
758 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
760 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
762 /* Copied from iwl_post_associate() */
763 if (vif && vif->bss_conf.use_short_slot)
764 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
766 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
768 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
769 ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
770 ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
773 EXPORT_SYMBOL(iwl_set_flags_for_band);
776 * initialize rxon structure with default values from eeprom
778 void iwl_connection_init_rx_config(struct iwl_priv *priv,
779 struct iwl_rxon_context *ctx)
781 const struct iwl_channel_info *ch_info;
783 memset(&ctx->staging, 0, sizeof(ctx->staging));
786 ctx->staging.dev_type = ctx->unused_devtype;
787 } else switch (ctx->vif->type) {
788 case NL80211_IFTYPE_AP:
789 ctx->staging.dev_type = ctx->ap_devtype;
792 case NL80211_IFTYPE_STATION:
793 ctx->staging.dev_type = ctx->station_devtype;
794 ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
797 case NL80211_IFTYPE_ADHOC:
798 ctx->staging.dev_type = ctx->ibss_devtype;
799 ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
800 ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
801 RXON_FILTER_ACCEPT_GRP_MSK;
805 IWL_ERR(priv, "Unsupported interface type %d\n",
811 /* TODO: Figure out when short_preamble would be set and cache from
813 if (!hw_to_local(priv->hw)->short_preamble)
814 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
816 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
819 ch_info = iwl_get_channel_info(priv, priv->band,
820 le16_to_cpu(ctx->active.channel));
823 ch_info = &priv->channel_info[0];
825 ctx->staging.channel = cpu_to_le16(ch_info->channel);
826 priv->band = ch_info->band;
828 iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
830 ctx->staging.ofdm_basic_rates =
831 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
832 ctx->staging.cck_basic_rates =
833 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
835 /* clear both MIX and PURE40 mode flag */
836 ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
837 RXON_FLG_CHANNEL_MODE_PURE_40);
839 memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
841 ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
842 ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
843 ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
845 EXPORT_SYMBOL(iwl_connection_init_rx_config);
847 void iwl_set_rate(struct iwl_priv *priv)
849 const struct ieee80211_supported_band *hw = NULL;
850 struct ieee80211_rate *rate;
851 struct iwl_rxon_context *ctx;
854 hw = iwl_get_hw_mode(priv, priv->band);
856 IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
860 priv->active_rate = 0;
862 for (i = 0; i < hw->n_bitrates; i++) {
863 rate = &(hw->bitrates[i]);
864 if (rate->hw_value < IWL_RATE_COUNT_LEGACY)
865 priv->active_rate |= (1 << rate->hw_value);
868 IWL_DEBUG_RATE(priv, "Set active_rate = %0x\n", priv->active_rate);
870 for_each_context(priv, ctx) {
871 ctx->staging.cck_basic_rates =
872 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
874 ctx->staging.ofdm_basic_rates =
875 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
878 EXPORT_SYMBOL(iwl_set_rate);
880 void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
884 * See iwl_mac_channel_switch.
886 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
888 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
891 if (priv->switch_rxon.switch_in_progress) {
892 ieee80211_chswitch_done(ctx->vif, is_success);
893 mutex_lock(&priv->mutex);
894 priv->switch_rxon.switch_in_progress = false;
895 mutex_unlock(&priv->mutex);
898 EXPORT_SYMBOL(iwl_chswitch_done);
900 void iwl_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
902 struct iwl_rx_packet *pkt = rxb_addr(rxb);
903 struct iwl_csa_notification *csa = &(pkt->u.csa_notif);
906 * See iwl_mac_channel_switch.
908 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
909 struct iwl_rxon_cmd *rxon = (void *)&ctx->active;
911 if (priv->switch_rxon.switch_in_progress) {
912 if (!le32_to_cpu(csa->status) &&
913 (csa->channel == priv->switch_rxon.channel)) {
914 rxon->channel = csa->channel;
915 ctx->staging.channel = csa->channel;
916 IWL_DEBUG_11H(priv, "CSA notif: channel %d\n",
917 le16_to_cpu(csa->channel));
918 iwl_chswitch_done(priv, true);
920 IWL_ERR(priv, "CSA notif (fail) : channel %d\n",
921 le16_to_cpu(csa->channel));
922 iwl_chswitch_done(priv, false);
926 EXPORT_SYMBOL(iwl_rx_csa);
928 #ifdef CONFIG_IWLWIFI_DEBUG
929 void iwl_print_rx_config_cmd(struct iwl_priv *priv,
930 struct iwl_rxon_context *ctx)
932 struct iwl_rxon_cmd *rxon = &ctx->staging;
934 IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
935 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
936 IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
937 IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
938 IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
939 le32_to_cpu(rxon->filter_flags));
940 IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
941 IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
942 rxon->ofdm_basic_rates);
943 IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
944 IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
945 IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
946 IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
948 EXPORT_SYMBOL(iwl_print_rx_config_cmd);
951 * iwl_irq_handle_error - called for HW or SW error interrupt from card
953 void iwl_irq_handle_error(struct iwl_priv *priv)
955 /* Set the FW error flag -- cleared on iwl_down */
956 set_bit(STATUS_FW_ERROR, &priv->status);
958 /* Cancel currently queued command. */
959 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
961 /* W/A for WiFi/WiMAX coex and WiMAX own the RF */
962 if (priv->cfg->internal_wimax_coex &&
963 (!(iwl_read_prph(priv, APMG_CLK_CTRL_REG) &
964 APMS_CLK_VAL_MRB_FUNC_MODE) ||
965 (iwl_read_prph(priv, APMG_PS_CTRL_REG) &
966 APMG_PS_CTRL_VAL_RESET_REQ))) {
967 wake_up_interruptible(&priv->wait_command_queue);
969 *Keep the restart process from trying to send host
970 * commands by clearing the INIT status bit
972 clear_bit(STATUS_READY, &priv->status);
973 IWL_ERR(priv, "RF is used by WiMAX\n");
977 IWL_ERR(priv, "Loaded firmware version: %s\n",
978 priv->hw->wiphy->fw_version);
980 priv->cfg->ops->lib->dump_nic_error_log(priv);
981 if (priv->cfg->ops->lib->dump_csr)
982 priv->cfg->ops->lib->dump_csr(priv);
983 if (priv->cfg->ops->lib->dump_fh)
984 priv->cfg->ops->lib->dump_fh(priv, NULL, false);
985 priv->cfg->ops->lib->dump_nic_event_log(priv, false, NULL, false);
986 #ifdef CONFIG_IWLWIFI_DEBUG
987 if (iwl_get_debug_level(priv) & IWL_DL_FW_ERRORS)
988 iwl_print_rx_config_cmd(priv,
989 &priv->contexts[IWL_RXON_CTX_BSS]);
992 wake_up_interruptible(&priv->wait_command_queue);
994 /* Keep the restart process from trying to send host
995 * commands by clearing the INIT status bit */
996 clear_bit(STATUS_READY, &priv->status);
998 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
999 IWL_DEBUG(priv, IWL_DL_FW_ERRORS,
1000 "Restarting adapter due to uCode error.\n");
1002 if (priv->cfg->mod_params->restart_fw)
1003 queue_work(priv->workqueue, &priv->restart);
1006 EXPORT_SYMBOL(iwl_irq_handle_error);
1008 static int iwl_apm_stop_master(struct iwl_priv *priv)
1012 /* stop device's busmaster DMA activity */
1013 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_STOP_MASTER);
1015 ret = iwl_poll_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_MASTER_DISABLED,
1016 CSR_RESET_REG_FLAG_MASTER_DISABLED, 100);
1018 IWL_WARN(priv, "Master Disable Timed Out, 100 usec\n");
1020 IWL_DEBUG_INFO(priv, "stop master\n");
1025 void iwl_apm_stop(struct iwl_priv *priv)
1027 IWL_DEBUG_INFO(priv, "Stop card, put in low power state\n");
1029 /* Stop device's DMA activity */
1030 iwl_apm_stop_master(priv);
1032 /* Reset the entire device */
1033 iwl_set_bit(priv, CSR_RESET, CSR_RESET_REG_FLAG_SW_RESET);
1038 * Clear "initialization complete" bit to move adapter from
1039 * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
1041 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
1043 EXPORT_SYMBOL(iwl_apm_stop);
1047 * Start up NIC's basic functionality after it has been reset
1048 * (e.g. after platform boot, or shutdown via iwl_apm_stop())
1049 * NOTE: This does not load uCode nor start the embedded processor
1051 int iwl_apm_init(struct iwl_priv *priv)
1056 IWL_DEBUG_INFO(priv, "Init card's basic functions\n");
1059 * Use "set_bit" below rather than "write", to preserve any hardware
1060 * bits already set by default after reset.
1063 /* Disable L0S exit timer (platform NMI Work/Around) */
1064 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
1065 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER);
1068 * Disable L0s without affecting L1;
1069 * don't wait for ICH L0s (ICH bug W/A)
1071 iwl_set_bit(priv, CSR_GIO_CHICKEN_BITS,
1072 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX);
1074 /* Set FH wait threshold to maximum (HW error during stress W/A) */
1075 iwl_set_bit(priv, CSR_DBG_HPET_MEM_REG, CSR_DBG_HPET_MEM_REG_VAL);
1078 * Enable HAP INTA (interrupt from management bus) to
1079 * wake device's PCI Express link L1a -> L0s
1080 * NOTE: This is no-op for 3945 (non-existant bit)
1082 iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
1083 CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
1086 * HW bug W/A for instability in PCIe bus L0->L0S->L1 transition.
1087 * Check if BIOS (or OS) enabled L1-ASPM on this device.
1088 * If so (likely), disable L0S, so device moves directly L0->L1;
1089 * costs negligible amount of power savings.
1090 * If not (unlikely), enable L0S, so there is at least some
1091 * power savings, even without L1.
1093 if (priv->cfg->base_params->set_l0s) {
1094 lctl = iwl_pcie_link_ctl(priv);
1095 if ((lctl & PCI_CFG_LINK_CTRL_VAL_L1_EN) ==
1096 PCI_CFG_LINK_CTRL_VAL_L1_EN) {
1097 /* L1-ASPM enabled; disable(!) L0S */
1098 iwl_set_bit(priv, CSR_GIO_REG,
1099 CSR_GIO_REG_VAL_L0S_ENABLED);
1100 IWL_DEBUG_POWER(priv, "L1 Enabled; Disabling L0S\n");
1102 /* L1-ASPM disabled; enable(!) L0S */
1103 iwl_clear_bit(priv, CSR_GIO_REG,
1104 CSR_GIO_REG_VAL_L0S_ENABLED);
1105 IWL_DEBUG_POWER(priv, "L1 Disabled; Enabling L0S\n");
1109 /* Configure analog phase-lock-loop before activating to D0A */
1110 if (priv->cfg->base_params->pll_cfg_val)
1111 iwl_set_bit(priv, CSR_ANA_PLL_CFG,
1112 priv->cfg->base_params->pll_cfg_val);
1115 * Set "initialization complete" bit to move adapter from
1116 * D0U* --> D0A* (powered-up active) state.
1118 iwl_set_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_INIT_DONE);
1121 * Wait for clock stabilization; once stabilized, access to
1122 * device-internal resources is supported, e.g. iwl_write_prph()
1123 * and accesses to uCode SRAM.
1125 ret = iwl_poll_bit(priv, CSR_GP_CNTRL,
1126 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY,
1127 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY, 25000);
1129 IWL_DEBUG_INFO(priv, "Failed to init the card\n");
1134 * Enable DMA and BSM (if used) clocks, wait for them to stabilize.
1135 * BSM (Boostrap State Machine) is only in 3945 and 4965;
1136 * later devices (i.e. 5000 and later) have non-volatile SRAM,
1137 * and don't need BSM to restore data after power-saving sleep.
1139 * Write to "CLK_EN_REG"; "1" bits enable clocks, while "0" bits
1140 * do not disable clocks. This preserves any hardware bits already
1141 * set by default in "CLK_CTRL_REG" after reset.
1143 if (priv->cfg->base_params->use_bsm)
1144 iwl_write_prph(priv, APMG_CLK_EN_REG,
1145 APMG_CLK_VAL_DMA_CLK_RQT | APMG_CLK_VAL_BSM_CLK_RQT);
1147 iwl_write_prph(priv, APMG_CLK_EN_REG,
1148 APMG_CLK_VAL_DMA_CLK_RQT);
1151 /* Disable L1-Active */
1152 iwl_set_bits_prph(priv, APMG_PCIDEV_STT_REG,
1153 APMG_PCIDEV_STT_VAL_L1_ACT_DIS);
1158 EXPORT_SYMBOL(iwl_apm_init);
1161 int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
1166 lockdep_assert_held(&priv->mutex);
1168 if (priv->tx_power_user_lmt == tx_power && !force)
1171 if (!priv->cfg->ops->lib->send_tx_power)
1174 if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
1176 "Requested user TXPOWER %d below lower limit %d.\n",
1178 IWLAGN_TX_POWER_TARGET_POWER_MIN);
1182 if (tx_power > priv->tx_power_device_lmt) {
1184 "Requested user TXPOWER %d above upper limit %d.\n",
1185 tx_power, priv->tx_power_device_lmt);
1189 if (!iwl_is_ready_rf(priv))
1192 /* scan complete use tx_power_next, need to be updated */
1193 priv->tx_power_next = tx_power;
1194 if (test_bit(STATUS_SCANNING, &priv->status) && !force) {
1195 IWL_DEBUG_INFO(priv, "Deferring tx power set while scanning\n");
1199 prev_tx_power = priv->tx_power_user_lmt;
1200 priv->tx_power_user_lmt = tx_power;
1202 ret = priv->cfg->ops->lib->send_tx_power(priv);
1204 /* if fail to set tx_power, restore the orig. tx power */
1206 priv->tx_power_user_lmt = prev_tx_power;
1207 priv->tx_power_next = prev_tx_power;
1211 EXPORT_SYMBOL(iwl_set_tx_power);
1213 void iwl_send_bt_config(struct iwl_priv *priv)
1215 struct iwl_bt_cmd bt_cmd = {
1216 .lead_time = BT_LEAD_TIME_DEF,
1217 .max_kill = BT_MAX_KILL_DEF,
1222 if (!bt_coex_active)
1223 bt_cmd.flags = BT_COEX_DISABLE;
1225 bt_cmd.flags = BT_COEX_ENABLE;
1227 priv->bt_enable_flag = bt_cmd.flags;
1228 IWL_DEBUG_INFO(priv, "BT coex %s\n",
1229 (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
1231 if (iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
1232 sizeof(struct iwl_bt_cmd), &bt_cmd))
1233 IWL_ERR(priv, "failed to send BT Coex Config\n");
1235 EXPORT_SYMBOL(iwl_send_bt_config);
1237 int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
1239 struct iwl_statistics_cmd statistics_cmd = {
1240 .configuration_flags =
1241 clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
1244 if (flags & CMD_ASYNC)
1245 return iwl_send_cmd_pdu_async(priv, REPLY_STATISTICS_CMD,
1246 sizeof(struct iwl_statistics_cmd),
1247 &statistics_cmd, NULL);
1249 return iwl_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
1250 sizeof(struct iwl_statistics_cmd),
1253 EXPORT_SYMBOL(iwl_send_statistics_request);
1255 void iwl_rx_pm_sleep_notif(struct iwl_priv *priv,
1256 struct iwl_rx_mem_buffer *rxb)
1258 #ifdef CONFIG_IWLWIFI_DEBUG
1259 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1260 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
1261 IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
1262 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1265 EXPORT_SYMBOL(iwl_rx_pm_sleep_notif);
1267 void iwl_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
1268 struct iwl_rx_mem_buffer *rxb)
1270 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1271 u32 len = le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK;
1272 IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
1273 "notification for %s:\n", len,
1274 get_cmd_string(pkt->hdr.cmd));
1275 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, len);
1277 EXPORT_SYMBOL(iwl_rx_pm_debug_statistics_notif);
1279 void iwl_rx_reply_error(struct iwl_priv *priv,
1280 struct iwl_rx_mem_buffer *rxb)
1282 struct iwl_rx_packet *pkt = rxb_addr(rxb);
1284 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
1285 "seq 0x%04X ser 0x%08X\n",
1286 le32_to_cpu(pkt->u.err_resp.error_type),
1287 get_cmd_string(pkt->u.err_resp.cmd_id),
1288 pkt->u.err_resp.cmd_id,
1289 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
1290 le32_to_cpu(pkt->u.err_resp.error_info));
1292 EXPORT_SYMBOL(iwl_rx_reply_error);
1294 void iwl_clear_isr_stats(struct iwl_priv *priv)
1296 memset(&priv->isr_stats, 0, sizeof(priv->isr_stats));
1299 int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
1300 const struct ieee80211_tx_queue_params *params)
1302 struct iwl_priv *priv = hw->priv;
1303 struct iwl_rxon_context *ctx;
1304 unsigned long flags;
1307 IWL_DEBUG_MAC80211(priv, "enter\n");
1309 if (!iwl_is_ready_rf(priv)) {
1310 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
1314 if (queue >= AC_NUM) {
1315 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
1319 q = AC_NUM - 1 - queue;
1321 spin_lock_irqsave(&priv->lock, flags);
1325 * This may need to be done per interface in nl80211/cfg80211/mac80211.
1327 for_each_context(priv, ctx) {
1328 ctx->qos_data.def_qos_parm.ac[q].cw_min =
1329 cpu_to_le16(params->cw_min);
1330 ctx->qos_data.def_qos_parm.ac[q].cw_max =
1331 cpu_to_le16(params->cw_max);
1332 ctx->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
1333 ctx->qos_data.def_qos_parm.ac[q].edca_txop =
1334 cpu_to_le16((params->txop * 32));
1336 ctx->qos_data.def_qos_parm.ac[q].reserved1 = 0;
1339 spin_unlock_irqrestore(&priv->lock, flags);
1341 IWL_DEBUG_MAC80211(priv, "leave\n");
1344 EXPORT_SYMBOL(iwl_mac_conf_tx);
1346 int iwl_mac_tx_last_beacon(struct ieee80211_hw *hw)
1348 struct iwl_priv *priv = hw->priv;
1350 return priv->ibss_manager == IWL_IBSS_MANAGER;
1352 EXPORT_SYMBOL_GPL(iwl_mac_tx_last_beacon);
1354 static int iwl_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
1356 iwl_connection_init_rx_config(priv, ctx);
1358 if (priv->cfg->ops->hcmd->set_rxon_chain)
1359 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
1361 return iwlcore_commit_rxon(priv, ctx);
1364 static int iwl_setup_interface(struct iwl_priv *priv,
1365 struct iwl_rxon_context *ctx)
1367 struct ieee80211_vif *vif = ctx->vif;
1370 lockdep_assert_held(&priv->mutex);
1373 * This variable will be correct only when there's just
1374 * a single context, but all code using it is for hardware
1375 * that supports only one context.
1377 priv->iw_mode = vif->type;
1379 ctx->is_active = true;
1381 err = iwl_set_mode(priv, ctx);
1383 if (!ctx->always_active)
1384 ctx->is_active = false;
1388 if (priv->cfg->bt_params && priv->cfg->bt_params->advanced_bt_coexist &&
1389 vif->type == NL80211_IFTYPE_ADHOC) {
1391 * pretend to have high BT traffic as long as we
1392 * are operating in IBSS mode, as this will cause
1393 * the rate scaling etc. to behave as intended.
1395 priv->bt_traffic_load = IWL_BT_COEX_TRAFFIC_LOAD_HIGH;
1401 int iwl_mac_add_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
1403 struct iwl_priv *priv = hw->priv;
1404 struct iwl_vif_priv *vif_priv = (void *)vif->drv_priv;
1405 struct iwl_rxon_context *tmp, *ctx = NULL;
1407 enum nl80211_iftype viftype = ieee80211_vif_type_p2p(vif);
1409 IWL_DEBUG_MAC80211(priv, "enter: type %d, addr %pM\n",
1410 viftype, vif->addr);
1412 mutex_lock(&priv->mutex);
1414 if (!iwl_is_ready_rf(priv)) {
1415 IWL_WARN(priv, "Try to add interface when device not ready\n");
1420 for_each_context(priv, tmp) {
1421 u32 possible_modes =
1422 tmp->interface_modes | tmp->exclusive_interface_modes;
1425 /* check if this busy context is exclusive */
1426 if (tmp->exclusive_interface_modes &
1427 BIT(tmp->vif->type)) {
1434 if (!(possible_modes & BIT(viftype)))
1437 /* have maybe usable context w/o interface */
1447 vif_priv->ctx = ctx;
1450 err = iwl_setup_interface(priv, ctx);
1455 priv->iw_mode = NL80211_IFTYPE_STATION;
1457 mutex_unlock(&priv->mutex);
1459 IWL_DEBUG_MAC80211(priv, "leave\n");
1462 EXPORT_SYMBOL(iwl_mac_add_interface);
1464 static void iwl_teardown_interface(struct iwl_priv *priv,
1465 struct ieee80211_vif *vif,
1468 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1470 lockdep_assert_held(&priv->mutex);
1472 if (priv->scan_vif == vif) {
1473 iwl_scan_cancel_timeout(priv, 200);
1474 iwl_force_scan_end(priv);
1478 iwl_set_mode(priv, ctx);
1479 if (!ctx->always_active)
1480 ctx->is_active = false;
1484 * When removing the IBSS interface, overwrite the
1485 * BT traffic load with the stored one from the last
1486 * notification, if any. If this is a device that
1487 * doesn't implement this, this has no effect since
1488 * both values are the same and zero.
1490 if (vif->type == NL80211_IFTYPE_ADHOC)
1491 priv->bt_traffic_load = priv->last_bt_traffic_load;
1494 void iwl_mac_remove_interface(struct ieee80211_hw *hw,
1495 struct ieee80211_vif *vif)
1497 struct iwl_priv *priv = hw->priv;
1498 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1500 IWL_DEBUG_MAC80211(priv, "enter\n");
1502 mutex_lock(&priv->mutex);
1504 WARN_ON(ctx->vif != vif);
1507 iwl_teardown_interface(priv, vif, false);
1509 memset(priv->bssid, 0, ETH_ALEN);
1510 mutex_unlock(&priv->mutex);
1512 IWL_DEBUG_MAC80211(priv, "leave\n");
1515 EXPORT_SYMBOL(iwl_mac_remove_interface);
1517 int iwl_alloc_txq_mem(struct iwl_priv *priv)
1520 priv->txq = kzalloc(
1521 sizeof(struct iwl_tx_queue) *
1522 priv->cfg->base_params->num_of_queues,
1525 IWL_ERR(priv, "Not enough memory for txq\n");
1530 EXPORT_SYMBOL(iwl_alloc_txq_mem);
1532 void iwl_free_txq_mem(struct iwl_priv *priv)
1537 EXPORT_SYMBOL(iwl_free_txq_mem);
1539 #ifdef CONFIG_IWLWIFI_DEBUGFS
1541 #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
1543 void iwl_reset_traffic_log(struct iwl_priv *priv)
1545 priv->tx_traffic_idx = 0;
1546 priv->rx_traffic_idx = 0;
1547 if (priv->tx_traffic)
1548 memset(priv->tx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
1549 if (priv->rx_traffic)
1550 memset(priv->rx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
1553 int iwl_alloc_traffic_mem(struct iwl_priv *priv)
1555 u32 traffic_size = IWL_TRAFFIC_DUMP_SIZE;
1557 if (iwl_debug_level & IWL_DL_TX) {
1558 if (!priv->tx_traffic) {
1560 kzalloc(traffic_size, GFP_KERNEL);
1561 if (!priv->tx_traffic)
1565 if (iwl_debug_level & IWL_DL_RX) {
1566 if (!priv->rx_traffic) {
1568 kzalloc(traffic_size, GFP_KERNEL);
1569 if (!priv->rx_traffic)
1573 iwl_reset_traffic_log(priv);
1576 EXPORT_SYMBOL(iwl_alloc_traffic_mem);
1578 void iwl_free_traffic_mem(struct iwl_priv *priv)
1580 kfree(priv->tx_traffic);
1581 priv->tx_traffic = NULL;
1583 kfree(priv->rx_traffic);
1584 priv->rx_traffic = NULL;
1586 EXPORT_SYMBOL(iwl_free_traffic_mem);
1588 void iwl_dbg_log_tx_data_frame(struct iwl_priv *priv,
1589 u16 length, struct ieee80211_hdr *header)
1594 if (likely(!(iwl_debug_level & IWL_DL_TX)))
1597 if (!priv->tx_traffic)
1600 fc = header->frame_control;
1601 if (ieee80211_is_data(fc)) {
1602 len = (length > IWL_TRAFFIC_ENTRY_SIZE)
1603 ? IWL_TRAFFIC_ENTRY_SIZE : length;
1604 memcpy((priv->tx_traffic +
1605 (priv->tx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
1607 priv->tx_traffic_idx =
1608 (priv->tx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
1611 EXPORT_SYMBOL(iwl_dbg_log_tx_data_frame);
1613 void iwl_dbg_log_rx_data_frame(struct iwl_priv *priv,
1614 u16 length, struct ieee80211_hdr *header)
1619 if (likely(!(iwl_debug_level & IWL_DL_RX)))
1622 if (!priv->rx_traffic)
1625 fc = header->frame_control;
1626 if (ieee80211_is_data(fc)) {
1627 len = (length > IWL_TRAFFIC_ENTRY_SIZE)
1628 ? IWL_TRAFFIC_ENTRY_SIZE : length;
1629 memcpy((priv->rx_traffic +
1630 (priv->rx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
1632 priv->rx_traffic_idx =
1633 (priv->rx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
1636 EXPORT_SYMBOL(iwl_dbg_log_rx_data_frame);
1638 const char *get_mgmt_string(int cmd)
1641 IWL_CMD(MANAGEMENT_ASSOC_REQ);
1642 IWL_CMD(MANAGEMENT_ASSOC_RESP);
1643 IWL_CMD(MANAGEMENT_REASSOC_REQ);
1644 IWL_CMD(MANAGEMENT_REASSOC_RESP);
1645 IWL_CMD(MANAGEMENT_PROBE_REQ);
1646 IWL_CMD(MANAGEMENT_PROBE_RESP);
1647 IWL_CMD(MANAGEMENT_BEACON);
1648 IWL_CMD(MANAGEMENT_ATIM);
1649 IWL_CMD(MANAGEMENT_DISASSOC);
1650 IWL_CMD(MANAGEMENT_AUTH);
1651 IWL_CMD(MANAGEMENT_DEAUTH);
1652 IWL_CMD(MANAGEMENT_ACTION);
1659 const char *get_ctrl_string(int cmd)
1662 IWL_CMD(CONTROL_BACK_REQ);
1663 IWL_CMD(CONTROL_BACK);
1664 IWL_CMD(CONTROL_PSPOLL);
1665 IWL_CMD(CONTROL_RTS);
1666 IWL_CMD(CONTROL_CTS);
1667 IWL_CMD(CONTROL_ACK);
1668 IWL_CMD(CONTROL_CFEND);
1669 IWL_CMD(CONTROL_CFENDACK);
1676 void iwl_clear_traffic_stats(struct iwl_priv *priv)
1678 memset(&priv->tx_stats, 0, sizeof(struct traffic_stats));
1679 memset(&priv->rx_stats, 0, sizeof(struct traffic_stats));
1683 * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will
1684 * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass.
1685 * Use debugFs to display the rx/rx_statistics
1686 * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL
1687 * information will be recorded, but DATA pkt still will be recorded
1688 * for the reason of iwl_led.c need to control the led blinking based on
1689 * number of tx and rx data.
1692 void iwl_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len)
1694 struct traffic_stats *stats;
1697 stats = &priv->tx_stats;
1699 stats = &priv->rx_stats;
1701 if (ieee80211_is_mgmt(fc)) {
1702 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
1703 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
1704 stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
1706 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
1707 stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
1709 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
1710 stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
1712 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
1713 stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
1715 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
1716 stats->mgmt[MANAGEMENT_PROBE_REQ]++;
1718 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
1719 stats->mgmt[MANAGEMENT_PROBE_RESP]++;
1721 case cpu_to_le16(IEEE80211_STYPE_BEACON):
1722 stats->mgmt[MANAGEMENT_BEACON]++;
1724 case cpu_to_le16(IEEE80211_STYPE_ATIM):
1725 stats->mgmt[MANAGEMENT_ATIM]++;
1727 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
1728 stats->mgmt[MANAGEMENT_DISASSOC]++;
1730 case cpu_to_le16(IEEE80211_STYPE_AUTH):
1731 stats->mgmt[MANAGEMENT_AUTH]++;
1733 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
1734 stats->mgmt[MANAGEMENT_DEAUTH]++;
1736 case cpu_to_le16(IEEE80211_STYPE_ACTION):
1737 stats->mgmt[MANAGEMENT_ACTION]++;
1740 } else if (ieee80211_is_ctl(fc)) {
1741 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
1742 case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
1743 stats->ctrl[CONTROL_BACK_REQ]++;
1745 case cpu_to_le16(IEEE80211_STYPE_BACK):
1746 stats->ctrl[CONTROL_BACK]++;
1748 case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
1749 stats->ctrl[CONTROL_PSPOLL]++;
1751 case cpu_to_le16(IEEE80211_STYPE_RTS):
1752 stats->ctrl[CONTROL_RTS]++;
1754 case cpu_to_le16(IEEE80211_STYPE_CTS):
1755 stats->ctrl[CONTROL_CTS]++;
1757 case cpu_to_le16(IEEE80211_STYPE_ACK):
1758 stats->ctrl[CONTROL_ACK]++;
1760 case cpu_to_le16(IEEE80211_STYPE_CFEND):
1761 stats->ctrl[CONTROL_CFEND]++;
1763 case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
1764 stats->ctrl[CONTROL_CFENDACK]++;
1770 stats->data_bytes += len;
1773 EXPORT_SYMBOL(iwl_update_stats);
1776 static void iwl_force_rf_reset(struct iwl_priv *priv)
1778 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1781 if (!iwl_is_any_associated(priv)) {
1782 IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
1786 * There is no easy and better way to force reset the radio,
1787 * the only known method is switching channel which will force to
1788 * reset and tune the radio.
1789 * Use internal short scan (single channel) operation to should
1790 * achieve this objective.
1791 * Driver should reset the radio when number of consecutive missed
1792 * beacon, or any other uCode error condition detected.
1794 IWL_DEBUG_INFO(priv, "perform radio reset.\n");
1795 iwl_internal_short_hw_scan(priv);
1799 int iwl_force_reset(struct iwl_priv *priv, int mode, bool external)
1801 struct iwl_force_reset *force_reset;
1803 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1806 if (mode >= IWL_MAX_FORCE_RESET) {
1807 IWL_DEBUG_INFO(priv, "invalid reset request.\n");
1810 force_reset = &priv->force_reset[mode];
1811 force_reset->reset_request_count++;
1813 if (force_reset->last_force_reset_jiffies &&
1814 time_after(force_reset->last_force_reset_jiffies +
1815 force_reset->reset_duration, jiffies)) {
1816 IWL_DEBUG_INFO(priv, "force reset rejected\n");
1817 force_reset->reset_reject_count++;
1821 force_reset->reset_success_count++;
1822 force_reset->last_force_reset_jiffies = jiffies;
1823 IWL_DEBUG_INFO(priv, "perform force reset (%d)\n", mode);
1826 iwl_force_rf_reset(priv);
1830 * if the request is from external(ex: debugfs),
1831 * then always perform the request in regardless the module
1833 * if the request is from internal (uCode error or driver
1834 * detect failure), then fw_restart module parameter
1835 * need to be check before performing firmware reload
1837 if (!external && !priv->cfg->mod_params->restart_fw) {
1838 IWL_DEBUG_INFO(priv, "Cancel firmware reload based on "
1839 "module parameter setting\n");
1842 IWL_ERR(priv, "On demand firmware reload\n");
1843 /* Set the FW error flag -- cleared on iwl_down */
1844 set_bit(STATUS_FW_ERROR, &priv->status);
1845 wake_up_interruptible(&priv->wait_command_queue);
1847 * Keep the restart process from trying to send host
1848 * commands by clearing the INIT status bit
1850 clear_bit(STATUS_READY, &priv->status);
1851 queue_work(priv->workqueue, &priv->restart);
1857 int iwl_mac_change_interface(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
1858 enum nl80211_iftype newtype, bool newp2p)
1860 struct iwl_priv *priv = hw->priv;
1861 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1862 struct iwl_rxon_context *tmp;
1863 u32 interface_modes;
1866 newtype = ieee80211_iftype_p2p(newtype, newp2p);
1868 mutex_lock(&priv->mutex);
1870 interface_modes = ctx->interface_modes | ctx->exclusive_interface_modes;
1872 if (!(interface_modes & BIT(newtype))) {
1877 if (ctx->exclusive_interface_modes & BIT(newtype)) {
1878 for_each_context(priv, tmp) {
1886 * The current mode switch would be exclusive, but
1887 * another context is active ... refuse the switch.
1895 iwl_teardown_interface(priv, vif, true);
1896 vif->type = newtype;
1897 err = iwl_setup_interface(priv, ctx);
1900 * We've switched internally, but submitting to the
1901 * device may have failed for some reason. Mask this
1902 * error, because otherwise mac80211 will not switch
1903 * (and set the interface type back) and we'll be
1904 * out of sync with it.
1909 mutex_unlock(&priv->mutex);
1912 EXPORT_SYMBOL(iwl_mac_change_interface);
1915 * On every watchdog tick we check (latest) time stamp. If it does not
1916 * change during timeout period and queue is not empty we reset firmware.
1918 static int iwl_check_stuck_queue(struct iwl_priv *priv, int cnt)
1920 struct iwl_tx_queue *txq = &priv->txq[cnt];
1921 struct iwl_queue *q = &txq->q;
1922 unsigned long timeout;
1925 if (q->read_ptr == q->write_ptr) {
1926 txq->time_stamp = jiffies;
1930 timeout = txq->time_stamp +
1931 msecs_to_jiffies(priv->cfg->base_params->wd_timeout);
1933 if (time_after(jiffies, timeout)) {
1934 IWL_ERR(priv, "Queue %d stuck for %u ms.\n",
1935 q->id, priv->cfg->base_params->wd_timeout);
1936 ret = iwl_force_reset(priv, IWL_FW_RESET, false);
1937 return (ret == -EAGAIN) ? 0 : 1;
1944 * Making watchdog tick be a quarter of timeout assure we will
1945 * discover the queue hung between timeout and 1.25*timeout
1947 #define IWL_WD_TICK(timeout) ((timeout) / 4)
1950 * Watchdog timer callback, we check each tx queue for stuck, if if hung
1951 * we reset the firmware. If everything is fine just rearm the timer.
1953 void iwl_bg_watchdog(unsigned long data)
1955 struct iwl_priv *priv = (struct iwl_priv *)data;
1957 unsigned long timeout;
1959 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1962 timeout = priv->cfg->base_params->wd_timeout;
1966 /* monitor and check for stuck cmd queue */
1967 if (iwl_check_stuck_queue(priv, priv->cmd_queue))
1970 /* monitor and check for other stuck queues */
1971 if (iwl_is_any_associated(priv)) {
1972 for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) {
1973 /* skip as we already checked the command queue */
1974 if (cnt == priv->cmd_queue)
1976 if (iwl_check_stuck_queue(priv, cnt))
1981 mod_timer(&priv->watchdog, jiffies +
1982 msecs_to_jiffies(IWL_WD_TICK(timeout)));
1984 EXPORT_SYMBOL(iwl_bg_watchdog);
1986 void iwl_setup_watchdog(struct iwl_priv *priv)
1988 unsigned int timeout = priv->cfg->base_params->wd_timeout;
1991 mod_timer(&priv->watchdog,
1992 jiffies + msecs_to_jiffies(IWL_WD_TICK(timeout)));
1994 del_timer(&priv->watchdog);
1996 EXPORT_SYMBOL(iwl_setup_watchdog);
1999 * extended beacon time format
2000 * time in usec will be changed into a 32-bit value in extended:internal format
2001 * the extended part is the beacon counts
2002 * the internal part is the time in usec within one beacon interval
2004 u32 iwl_usecs_to_beacons(struct iwl_priv *priv, u32 usec, u32 beacon_interval)
2008 u32 interval = beacon_interval * TIME_UNIT;
2010 if (!interval || !usec)
2013 quot = (usec / interval) &
2014 (iwl_beacon_time_mask_high(priv,
2015 priv->hw_params.beacon_time_tsf_bits) >>
2016 priv->hw_params.beacon_time_tsf_bits);
2017 rem = (usec % interval) & iwl_beacon_time_mask_low(priv,
2018 priv->hw_params.beacon_time_tsf_bits);
2020 return (quot << priv->hw_params.beacon_time_tsf_bits) + rem;
2022 EXPORT_SYMBOL(iwl_usecs_to_beacons);
2024 /* base is usually what we get from ucode with each received frame,
2025 * the same as HW timer counter counting down
2027 __le32 iwl_add_beacon_time(struct iwl_priv *priv, u32 base,
2028 u32 addon, u32 beacon_interval)
2030 u32 base_low = base & iwl_beacon_time_mask_low(priv,
2031 priv->hw_params.beacon_time_tsf_bits);
2032 u32 addon_low = addon & iwl_beacon_time_mask_low(priv,
2033 priv->hw_params.beacon_time_tsf_bits);
2034 u32 interval = beacon_interval * TIME_UNIT;
2035 u32 res = (base & iwl_beacon_time_mask_high(priv,
2036 priv->hw_params.beacon_time_tsf_bits)) +
2037 (addon & iwl_beacon_time_mask_high(priv,
2038 priv->hw_params.beacon_time_tsf_bits));
2040 if (base_low > addon_low)
2041 res += base_low - addon_low;
2042 else if (base_low < addon_low) {
2043 res += interval + base_low - addon_low;
2044 res += (1 << priv->hw_params.beacon_time_tsf_bits);
2046 res += (1 << priv->hw_params.beacon_time_tsf_bits);
2048 return cpu_to_le32(res);
2050 EXPORT_SYMBOL(iwl_add_beacon_time);
2054 int iwl_pci_suspend(struct device *device)
2056 struct pci_dev *pdev = to_pci_dev(device);
2057 struct iwl_priv *priv = pci_get_drvdata(pdev);
2060 * This function is called when system goes into suspend state
2061 * mac80211 will call iwl_mac_stop() from the mac80211 suspend function
2062 * first but since iwl_mac_stop() has no knowledge of who the caller is,
2063 * it will not call apm_ops.stop() to stop the DMA operation.
2064 * Calling apm_ops.stop here to make sure we stop the DMA.
2070 EXPORT_SYMBOL(iwl_pci_suspend);
2072 int iwl_pci_resume(struct device *device)
2074 struct pci_dev *pdev = to_pci_dev(device);
2075 struct iwl_priv *priv = pci_get_drvdata(pdev);
2076 bool hw_rfkill = false;
2079 * We disable the RETRY_TIMEOUT register (0x41) to keep
2080 * PCI Tx retries from interfering with C3 CPU state.
2082 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
2084 iwl_enable_interrupts(priv);
2086 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
2087 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
2091 set_bit(STATUS_RF_KILL_HW, &priv->status);
2093 clear_bit(STATUS_RF_KILL_HW, &priv->status);
2095 wiphy_rfkill_set_hw_state(priv->hw->wiphy, hw_rfkill);
2099 EXPORT_SYMBOL(iwl_pci_resume);
2101 const struct dev_pm_ops iwl_pm_ops = {
2102 .suspend = iwl_pci_suspend,
2103 .resume = iwl_pci_resume,
2104 .freeze = iwl_pci_suspend,
2105 .thaw = iwl_pci_resume,
2106 .poweroff = iwl_pci_suspend,
2107 .restore = iwl_pci_resume,
2109 EXPORT_SYMBOL(iwl_pm_ops);
2111 #endif /* CONFIG_PM */