1 /******************************************************************************
5 * Copyright(c) 2008 - 2012 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-debug.h"
40 #include "iwl-power.h"
41 #include "iwl-shared.h"
43 #include "iwl-trans.h"
45 const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
47 static bool iwl_is_channel_extension(struct iwl_priv *priv,
48 enum ieee80211_band band,
49 u16 channel, u8 extension_chan_offset)
51 const struct iwl_channel_info *ch_info;
53 ch_info = iwl_get_channel_info(priv, band, channel);
54 if (!is_channel_valid(ch_info))
57 if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_ABOVE)
58 return !(ch_info->ht40_extension_channel &
59 IEEE80211_CHAN_NO_HT40PLUS);
60 else if (extension_chan_offset == IEEE80211_HT_PARAM_CHA_SEC_BELOW)
61 return !(ch_info->ht40_extension_channel &
62 IEEE80211_CHAN_NO_HT40MINUS);
67 bool iwl_is_ht40_tx_allowed(struct iwl_priv *priv,
68 struct iwl_rxon_context *ctx,
69 struct ieee80211_sta_ht_cap *ht_cap)
71 if (!ctx->ht.enabled || !ctx->ht.is_40mhz)
75 * We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
76 * the bit will not set if it is pure 40MHz case
78 if (ht_cap && !ht_cap->ht_supported)
81 #ifdef CONFIG_IWLWIFI_DEBUGFS
82 if (priv->disable_ht40)
86 return iwl_is_channel_extension(priv, priv->band,
87 le16_to_cpu(ctx->staging.channel),
88 ctx->ht.extension_chan_offset);
92 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
93 * @priv: staging_rxon is compared to active_rxon
95 * If the RXON structure is changing enough to require a new tune,
96 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
97 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
99 int iwl_full_rxon_required(struct iwl_priv *priv,
100 struct iwl_rxon_context *ctx)
102 const struct iwl_rxon_cmd *staging = &ctx->staging;
103 const struct iwl_rxon_cmd *active = &ctx->active;
107 IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
111 #define CHK_NEQ(c1, c2) \
112 if ((c1) != (c2)) { \
113 IWL_DEBUG_INFO(priv, "need full RXON - " \
114 #c1 " != " #c2 " - %d != %d\n", \
119 /* These items are only settable from the full RXON command */
120 CHK(!iwl_is_associated_ctx(ctx));
121 CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr));
122 CHK(compare_ether_addr(staging->node_addr, active->node_addr));
123 CHK(compare_ether_addr(staging->wlap_bssid_addr,
124 active->wlap_bssid_addr));
125 CHK_NEQ(staging->dev_type, active->dev_type);
126 CHK_NEQ(staging->channel, active->channel);
127 CHK_NEQ(staging->air_propagation, active->air_propagation);
128 CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
129 active->ofdm_ht_single_stream_basic_rates);
130 CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
131 active->ofdm_ht_dual_stream_basic_rates);
132 CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates,
133 active->ofdm_ht_triple_stream_basic_rates);
134 CHK_NEQ(staging->assoc_id, active->assoc_id);
136 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
137 * be updated with the RXON_ASSOC command -- however only some
138 * flag transitions are allowed using RXON_ASSOC */
140 /* Check if we are not switching bands */
141 CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
142 active->flags & RXON_FLG_BAND_24G_MSK);
144 /* Check if we are switching association toggle */
145 CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
146 active->filter_flags & RXON_FILTER_ASSOC_MSK);
154 static void _iwl_set_rxon_ht(struct iwl_priv *priv,
155 struct iwl_ht_config *ht_conf,
156 struct iwl_rxon_context *ctx)
158 struct iwl_rxon_cmd *rxon = &ctx->staging;
160 if (!ctx->ht.enabled) {
161 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
162 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
163 RXON_FLG_HT40_PROT_MSK |
164 RXON_FLG_HT_PROT_MSK);
168 /* FIXME: if the definition of ht.protection changed, the "translation"
169 * will be needed for rxon->flags
171 rxon->flags |= cpu_to_le32(ctx->ht.protection << RXON_FLG_HT_OPERATING_MODE_POS);
173 /* Set up channel bandwidth:
174 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
175 /* clear the HT channel mode before set the mode */
176 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
177 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
178 if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
180 if (ctx->ht.protection == IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
181 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
182 /* Note: control channel is opposite of extension channel */
183 switch (ctx->ht.extension_chan_offset) {
184 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
185 rxon->flags &= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
187 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
188 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
192 /* Note: control channel is opposite of extension channel */
193 switch (ctx->ht.extension_chan_offset) {
194 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
195 rxon->flags &= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
196 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
198 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
199 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
200 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
202 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
204 /* channel location only valid if in Mixed mode */
205 IWL_ERR(priv, "invalid extension channel offset\n");
210 rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
213 iwlagn_set_rxon_chain(priv, ctx);
215 IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
216 "extension channel offset 0x%x\n",
217 le32_to_cpu(rxon->flags), ctx->ht.protection,
218 ctx->ht.extension_chan_offset);
221 void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
223 struct iwl_rxon_context *ctx;
225 for_each_context(priv, ctx)
226 _iwl_set_rxon_ht(priv, ht_conf, ctx);
229 /* Return valid, unused, channel for a passive scan to reset the RF */
230 u8 iwl_get_single_channel_number(struct iwl_priv *priv,
231 enum ieee80211_band band)
233 const struct iwl_channel_info *ch_info;
237 struct iwl_rxon_context *ctx;
239 if (band == IEEE80211_BAND_5GHZ) {
241 max = priv->channel_count;
247 for (i = min; i < max; i++) {
250 for_each_context(priv, ctx) {
251 busy = priv->channel_info[i].channel ==
252 le16_to_cpu(ctx->staging.channel);
260 channel = priv->channel_info[i].channel;
261 ch_info = iwl_get_channel_info(priv, band, channel);
262 if (is_channel_valid(ch_info))
270 * iwl_set_rxon_channel - Set the band and channel values in staging RXON
271 * @ch: requested channel as a pointer to struct ieee80211_channel
273 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
274 * in the staging RXON flag structure based on the ch->band
276 void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
277 struct iwl_rxon_context *ctx)
279 enum ieee80211_band band = ch->band;
280 u16 channel = ch->hw_value;
282 if ((le16_to_cpu(ctx->staging.channel) == channel) &&
283 (priv->band == band))
286 ctx->staging.channel = cpu_to_le16(channel);
287 if (band == IEEE80211_BAND_5GHZ)
288 ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
290 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
294 IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
298 void iwl_set_flags_for_band(struct iwl_priv *priv,
299 struct iwl_rxon_context *ctx,
300 enum ieee80211_band band,
301 struct ieee80211_vif *vif)
303 if (band == IEEE80211_BAND_5GHZ) {
304 ctx->staging.flags &=
305 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
307 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
309 /* Copied from iwl_post_associate() */
310 if (vif && vif->bss_conf.use_short_slot)
311 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
313 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
315 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
316 ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
317 ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
322 * initialize rxon structure with default values from eeprom
324 void iwl_connection_init_rx_config(struct iwl_priv *priv,
325 struct iwl_rxon_context *ctx)
327 const struct iwl_channel_info *ch_info;
329 memset(&ctx->staging, 0, sizeof(ctx->staging));
332 ctx->staging.dev_type = ctx->unused_devtype;
333 } else switch (ctx->vif->type) {
334 case NL80211_IFTYPE_AP:
335 ctx->staging.dev_type = ctx->ap_devtype;
338 case NL80211_IFTYPE_STATION:
339 ctx->staging.dev_type = ctx->station_devtype;
340 ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
343 case NL80211_IFTYPE_ADHOC:
344 ctx->staging.dev_type = ctx->ibss_devtype;
345 ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
346 ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
347 RXON_FILTER_ACCEPT_GRP_MSK;
351 IWL_ERR(priv, "Unsupported interface type %d\n",
357 /* TODO: Figure out when short_preamble would be set and cache from
359 if (!hw_to_local(priv->hw)->short_preamble)
360 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
362 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
365 ch_info = iwl_get_channel_info(priv, priv->band,
366 le16_to_cpu(ctx->active.channel));
369 ch_info = &priv->channel_info[0];
371 ctx->staging.channel = cpu_to_le16(ch_info->channel);
372 priv->band = ch_info->band;
374 iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
376 ctx->staging.ofdm_basic_rates =
377 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
378 ctx->staging.cck_basic_rates =
379 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
381 /* clear both MIX and PURE40 mode flag */
382 ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
383 RXON_FLG_CHANNEL_MODE_PURE_40);
385 memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
387 ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
388 ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
389 ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
392 void iwl_set_rate(struct iwl_priv *priv)
394 const struct ieee80211_supported_band *hw = NULL;
395 struct ieee80211_rate *rate;
396 struct iwl_rxon_context *ctx;
399 hw = iwl_get_hw_mode(priv, priv->band);
401 IWL_ERR(priv, "Failed to set rate: unable to get hw mode\n");
405 priv->active_rate = 0;
407 for (i = 0; i < hw->n_bitrates; i++) {
408 rate = &(hw->bitrates[i]);
409 if (rate->hw_value < IWL_RATE_COUNT_LEGACY)
410 priv->active_rate |= (1 << rate->hw_value);
413 IWL_DEBUG_RATE(priv, "Set active_rate = %0x\n", priv->active_rate);
415 for_each_context(priv, ctx) {
416 ctx->staging.cck_basic_rates =
417 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
419 ctx->staging.ofdm_basic_rates =
420 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
424 void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
428 * See iwlagn_mac_channel_switch.
430 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
432 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
435 if (test_and_clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
436 ieee80211_chswitch_done(ctx->vif, is_success);
439 #ifdef CONFIG_IWLWIFI_DEBUG
440 void iwl_print_rx_config_cmd(struct iwl_priv *priv,
441 enum iwl_rxon_context_id ctxid)
443 struct iwl_rxon_context *ctx = &priv->contexts[ctxid];
444 struct iwl_rxon_cmd *rxon = &ctx->staging;
446 IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
447 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
448 IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
449 IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
450 IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
451 le32_to_cpu(rxon->filter_flags));
452 IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
453 IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
454 rxon->ofdm_basic_rates);
455 IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
456 IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
457 IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
458 IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
462 void iwlagn_fw_error(struct iwl_priv *priv, bool ondemand)
464 unsigned int reload_msec;
465 unsigned long reload_jiffies;
467 #ifdef CONFIG_IWLWIFI_DEBUG
468 if (iwl_have_debug_level(IWL_DL_FW_ERRORS))
469 iwl_print_rx_config_cmd(priv, IWL_RXON_CTX_BSS);
472 /* uCode is no longer loaded. */
473 priv->ucode_loaded = false;
475 /* Set the FW error flag -- cleared on iwl_down */
476 set_bit(STATUS_FW_ERROR, &priv->shrd->status);
478 /* Cancel currently queued command. */
479 clear_bit(STATUS_HCMD_ACTIVE, &priv->shrd->status);
481 iwl_abort_notification_waits(&priv->notif_wait);
483 /* Keep the restart process from trying to send host
484 * commands by clearing the ready bit */
485 clear_bit(STATUS_READY, &priv->status);
487 wake_up(&trans(priv)->wait_command_queue);
491 * If firmware keep reloading, then it indicate something
492 * serious wrong and firmware having problem to recover
493 * from it. Instead of keep trying which will fill the syslog
494 * and hang the system, let's just stop it
496 reload_jiffies = jiffies;
497 reload_msec = jiffies_to_msecs((long) reload_jiffies -
498 (long) priv->reload_jiffies);
499 priv->reload_jiffies = reload_jiffies;
500 if (reload_msec <= IWL_MIN_RELOAD_DURATION) {
501 priv->reload_count++;
502 if (priv->reload_count >= IWL_MAX_CONTINUE_RELOAD_CNT) {
503 IWL_ERR(priv, "BUG_ON, Stop restarting\n");
507 priv->reload_count = 0;
510 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
511 if (iwlagn_mod_params.restart_fw) {
512 IWL_DEBUG_FW_ERRORS(priv,
513 "Restarting adapter due to uCode error.\n");
514 queue_work(priv->workqueue, &priv->restart);
516 IWL_DEBUG_FW_ERRORS(priv,
517 "Detected FW error, but not restarting\n");
521 int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
526 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
528 lockdep_assert_held(&priv->mutex);
530 if (priv->tx_power_user_lmt == tx_power && !force)
533 if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
535 "Requested user TXPOWER %d below lower limit %d.\n",
537 IWLAGN_TX_POWER_TARGET_POWER_MIN);
541 if (tx_power > priv->tx_power_device_lmt) {
543 "Requested user TXPOWER %d above upper limit %d.\n",
544 tx_power, priv->tx_power_device_lmt);
548 if (!iwl_is_ready_rf(priv))
551 /* scan complete and commit_rxon use tx_power_next value,
552 * it always need to be updated for newest request */
553 priv->tx_power_next = tx_power;
555 /* do not set tx power when scanning or channel changing */
556 defer = test_bit(STATUS_SCANNING, &priv->status) ||
557 memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging));
558 if (defer && !force) {
559 IWL_DEBUG_INFO(priv, "Deferring tx power set\n");
563 prev_tx_power = priv->tx_power_user_lmt;
564 priv->tx_power_user_lmt = tx_power;
566 ret = iwlagn_send_tx_power(priv);
568 /* if fail to set tx_power, restore the orig. tx power */
570 priv->tx_power_user_lmt = prev_tx_power;
571 priv->tx_power_next = prev_tx_power;
576 void iwl_send_bt_config(struct iwl_priv *priv)
578 struct iwl_bt_cmd bt_cmd = {
579 .lead_time = BT_LEAD_TIME_DEF,
580 .max_kill = BT_MAX_KILL_DEF,
585 if (!iwlagn_mod_params.bt_coex_active)
586 bt_cmd.flags = BT_COEX_DISABLE;
588 bt_cmd.flags = BT_COEX_ENABLE;
590 priv->bt_enable_flag = bt_cmd.flags;
591 IWL_DEBUG_INFO(priv, "BT coex %s\n",
592 (bt_cmd.flags == BT_COEX_DISABLE) ? "disable" : "active");
594 if (iwl_dvm_send_cmd_pdu(priv, REPLY_BT_CONFIG,
595 CMD_SYNC, sizeof(struct iwl_bt_cmd), &bt_cmd))
596 IWL_ERR(priv, "failed to send BT Coex Config\n");
599 int iwl_send_statistics_request(struct iwl_priv *priv, u8 flags, bool clear)
601 struct iwl_statistics_cmd statistics_cmd = {
602 .configuration_flags =
603 clear ? IWL_STATS_CONF_CLEAR_STATS : 0,
606 if (flags & CMD_ASYNC)
607 return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
609 sizeof(struct iwl_statistics_cmd),
612 return iwl_dvm_send_cmd_pdu(priv, REPLY_STATISTICS_CMD,
614 sizeof(struct iwl_statistics_cmd),
621 #ifdef CONFIG_IWLWIFI_DEBUGFS
623 #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
625 void iwl_reset_traffic_log(struct iwl_priv *priv)
627 priv->tx_traffic_idx = 0;
628 priv->rx_traffic_idx = 0;
629 if (priv->tx_traffic)
630 memset(priv->tx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
631 if (priv->rx_traffic)
632 memset(priv->rx_traffic, 0, IWL_TRAFFIC_DUMP_SIZE);
635 int iwl_alloc_traffic_mem(struct iwl_priv *priv)
637 u32 traffic_size = IWL_TRAFFIC_DUMP_SIZE;
639 if (iwl_have_debug_level(IWL_DL_TX)) {
640 if (!priv->tx_traffic) {
642 kzalloc(traffic_size, GFP_KERNEL);
643 if (!priv->tx_traffic)
647 if (iwl_have_debug_level(IWL_DL_RX)) {
648 if (!priv->rx_traffic) {
650 kzalloc(traffic_size, GFP_KERNEL);
651 if (!priv->rx_traffic)
655 iwl_reset_traffic_log(priv);
659 void iwl_free_traffic_mem(struct iwl_priv *priv)
661 kfree(priv->tx_traffic);
662 priv->tx_traffic = NULL;
664 kfree(priv->rx_traffic);
665 priv->rx_traffic = NULL;
668 void iwl_dbg_log_tx_data_frame(struct iwl_priv *priv,
669 u16 length, struct ieee80211_hdr *header)
674 if (likely(!iwl_have_debug_level(IWL_DL_TX)))
677 if (!priv->tx_traffic)
680 fc = header->frame_control;
681 if (ieee80211_is_data(fc)) {
682 len = (length > IWL_TRAFFIC_ENTRY_SIZE)
683 ? IWL_TRAFFIC_ENTRY_SIZE : length;
684 memcpy((priv->tx_traffic +
685 (priv->tx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
687 priv->tx_traffic_idx =
688 (priv->tx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
692 void iwl_dbg_log_rx_data_frame(struct iwl_priv *priv,
693 u16 length, struct ieee80211_hdr *header)
698 if (likely(!iwl_have_debug_level(IWL_DL_RX)))
701 if (!priv->rx_traffic)
704 fc = header->frame_control;
705 if (ieee80211_is_data(fc)) {
706 len = (length > IWL_TRAFFIC_ENTRY_SIZE)
707 ? IWL_TRAFFIC_ENTRY_SIZE : length;
708 memcpy((priv->rx_traffic +
709 (priv->rx_traffic_idx * IWL_TRAFFIC_ENTRY_SIZE)),
711 priv->rx_traffic_idx =
712 (priv->rx_traffic_idx + 1) % IWL_TRAFFIC_ENTRIES;
716 const char *get_mgmt_string(int cmd)
719 IWL_CMD(MANAGEMENT_ASSOC_REQ);
720 IWL_CMD(MANAGEMENT_ASSOC_RESP);
721 IWL_CMD(MANAGEMENT_REASSOC_REQ);
722 IWL_CMD(MANAGEMENT_REASSOC_RESP);
723 IWL_CMD(MANAGEMENT_PROBE_REQ);
724 IWL_CMD(MANAGEMENT_PROBE_RESP);
725 IWL_CMD(MANAGEMENT_BEACON);
726 IWL_CMD(MANAGEMENT_ATIM);
727 IWL_CMD(MANAGEMENT_DISASSOC);
728 IWL_CMD(MANAGEMENT_AUTH);
729 IWL_CMD(MANAGEMENT_DEAUTH);
730 IWL_CMD(MANAGEMENT_ACTION);
737 const char *get_ctrl_string(int cmd)
740 IWL_CMD(CONTROL_BACK_REQ);
741 IWL_CMD(CONTROL_BACK);
742 IWL_CMD(CONTROL_PSPOLL);
743 IWL_CMD(CONTROL_RTS);
744 IWL_CMD(CONTROL_CTS);
745 IWL_CMD(CONTROL_ACK);
746 IWL_CMD(CONTROL_CFEND);
747 IWL_CMD(CONTROL_CFENDACK);
754 void iwl_clear_traffic_stats(struct iwl_priv *priv)
756 memset(&priv->tx_stats, 0, sizeof(struct traffic_stats));
757 memset(&priv->rx_stats, 0, sizeof(struct traffic_stats));
761 * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will
762 * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass.
763 * Use debugFs to display the rx/rx_statistics
764 * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL
765 * information will be recorded, but DATA pkt still will be recorded
766 * for the reason of iwl_led.c need to control the led blinking based on
767 * number of tx and rx data.
770 void iwl_update_stats(struct iwl_priv *priv, bool is_tx, __le16 fc, u16 len)
772 struct traffic_stats *stats;
775 stats = &priv->tx_stats;
777 stats = &priv->rx_stats;
779 if (ieee80211_is_mgmt(fc)) {
780 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
781 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ):
782 stats->mgmt[MANAGEMENT_ASSOC_REQ]++;
784 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
785 stats->mgmt[MANAGEMENT_ASSOC_RESP]++;
787 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ):
788 stats->mgmt[MANAGEMENT_REASSOC_REQ]++;
790 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
791 stats->mgmt[MANAGEMENT_REASSOC_RESP]++;
793 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
794 stats->mgmt[MANAGEMENT_PROBE_REQ]++;
796 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
797 stats->mgmt[MANAGEMENT_PROBE_RESP]++;
799 case cpu_to_le16(IEEE80211_STYPE_BEACON):
800 stats->mgmt[MANAGEMENT_BEACON]++;
802 case cpu_to_le16(IEEE80211_STYPE_ATIM):
803 stats->mgmt[MANAGEMENT_ATIM]++;
805 case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
806 stats->mgmt[MANAGEMENT_DISASSOC]++;
808 case cpu_to_le16(IEEE80211_STYPE_AUTH):
809 stats->mgmt[MANAGEMENT_AUTH]++;
811 case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
812 stats->mgmt[MANAGEMENT_DEAUTH]++;
814 case cpu_to_le16(IEEE80211_STYPE_ACTION):
815 stats->mgmt[MANAGEMENT_ACTION]++;
818 } else if (ieee80211_is_ctl(fc)) {
819 switch (fc & cpu_to_le16(IEEE80211_FCTL_STYPE)) {
820 case cpu_to_le16(IEEE80211_STYPE_BACK_REQ):
821 stats->ctrl[CONTROL_BACK_REQ]++;
823 case cpu_to_le16(IEEE80211_STYPE_BACK):
824 stats->ctrl[CONTROL_BACK]++;
826 case cpu_to_le16(IEEE80211_STYPE_PSPOLL):
827 stats->ctrl[CONTROL_PSPOLL]++;
829 case cpu_to_le16(IEEE80211_STYPE_RTS):
830 stats->ctrl[CONTROL_RTS]++;
832 case cpu_to_le16(IEEE80211_STYPE_CTS):
833 stats->ctrl[CONTROL_CTS]++;
835 case cpu_to_le16(IEEE80211_STYPE_ACK):
836 stats->ctrl[CONTROL_ACK]++;
838 case cpu_to_le16(IEEE80211_STYPE_CFEND):
839 stats->ctrl[CONTROL_CFEND]++;
841 case cpu_to_le16(IEEE80211_STYPE_CFENDACK):
842 stats->ctrl[CONTROL_CFENDACK]++;
848 stats->data_bytes += len;
853 static void iwl_force_rf_reset(struct iwl_priv *priv)
855 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
858 if (!iwl_is_any_associated(priv)) {
859 IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n");
863 * There is no easy and better way to force reset the radio,
864 * the only known method is switching channel which will force to
865 * reset and tune the radio.
866 * Use internal short scan (single channel) operation to should
867 * achieve this objective.
868 * Driver should reset the radio when number of consecutive missed
869 * beacon, or any other uCode error condition detected.
871 IWL_DEBUG_INFO(priv, "perform radio reset.\n");
872 iwl_internal_short_hw_scan(priv);
876 int iwl_force_reset(struct iwl_priv *priv, int mode, bool external)
878 struct iwl_force_reset *force_reset;
880 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
883 if (mode >= IWL_MAX_FORCE_RESET) {
884 IWL_DEBUG_INFO(priv, "invalid reset request.\n");
887 force_reset = &priv->force_reset[mode];
888 force_reset->reset_request_count++;
890 if (force_reset->last_force_reset_jiffies &&
891 time_after(force_reset->last_force_reset_jiffies +
892 force_reset->reset_duration, jiffies)) {
893 IWL_DEBUG_INFO(priv, "force reset rejected\n");
894 force_reset->reset_reject_count++;
898 force_reset->reset_success_count++;
899 force_reset->last_force_reset_jiffies = jiffies;
900 IWL_DEBUG_INFO(priv, "perform force reset (%d)\n", mode);
903 iwl_force_rf_reset(priv);
907 * if the request is from external(ex: debugfs),
908 * then always perform the request in regardless the module
910 * if the request is from internal (uCode error or driver
911 * detect failure), then fw_restart module parameter
912 * need to be check before performing firmware reload
914 if (!external && !iwlagn_mod_params.restart_fw) {
915 IWL_DEBUG_INFO(priv, "Cancel firmware reload based on "
916 "module parameter setting\n");
919 IWL_ERR(priv, "On demand firmware reload\n");
920 iwlagn_fw_error(priv, true);
927 int iwl_cmd_echo_test(struct iwl_priv *priv)
930 struct iwl_host_cmd cmd = {
936 ret = iwl_dvm_send_cmd(priv, &cmd);
938 IWL_ERR(priv, "echo testing fail: 0X%x\n", ret);
940 IWL_DEBUG_INFO(priv, "echo testing pass\n");
944 static inline int iwl_check_stuck_queue(struct iwl_priv *priv, int txq)
946 if (iwl_trans_check_stuck_queue(trans(priv), txq)) {
948 ret = iwl_force_reset(priv, IWL_FW_RESET, false);
949 return (ret == -EAGAIN) ? 0 : 1;
955 * Making watchdog tick be a quarter of timeout assure we will
956 * discover the queue hung between timeout and 1.25*timeout
958 #define IWL_WD_TICK(timeout) ((timeout) / 4)
961 * Watchdog timer callback, we check each tx queue for stuck, if if hung
962 * we reset the firmware. If everything is fine just rearm the timer.
964 void iwl_bg_watchdog(unsigned long data)
966 struct iwl_priv *priv = (struct iwl_priv *)data;
968 unsigned long timeout;
970 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
973 if (iwl_is_rfkill(priv))
976 timeout = hw_params(priv).wd_timeout;
980 /* monitor and check for stuck queues */
981 for (cnt = 0; cnt < cfg(priv)->base_params->num_of_queues; cnt++)
982 if (iwl_check_stuck_queue(priv, cnt))
985 mod_timer(&priv->watchdog, jiffies +
986 msecs_to_jiffies(IWL_WD_TICK(timeout)));
989 void iwl_setup_watchdog(struct iwl_priv *priv)
991 unsigned int timeout = hw_params(priv).wd_timeout;
993 if (!iwlagn_mod_params.wd_disable) {
994 /* use system default */
995 if (timeout && !cfg(priv)->base_params->wd_disable)
996 mod_timer(&priv->watchdog,
998 msecs_to_jiffies(IWL_WD_TICK(timeout)));
1000 del_timer(&priv->watchdog);
1002 /* module parameter overwrite default configuration */
1003 if (timeout && iwlagn_mod_params.wd_disable == 2)
1004 mod_timer(&priv->watchdog,
1006 msecs_to_jiffies(IWL_WD_TICK(timeout)));
1008 del_timer(&priv->watchdog);
1013 * iwl_beacon_time_mask_low - mask of lower 32 bit of beacon time
1014 * @priv -- pointer to iwl_priv data structure
1015 * @tsf_bits -- number of bits need to shift for masking)
1017 static inline u32 iwl_beacon_time_mask_low(struct iwl_priv *priv,
1020 return (1 << tsf_bits) - 1;
1024 * iwl_beacon_time_mask_high - mask of higher 32 bit of beacon time
1025 * @priv -- pointer to iwl_priv data structure
1026 * @tsf_bits -- number of bits need to shift for masking)
1028 static inline u32 iwl_beacon_time_mask_high(struct iwl_priv *priv,
1031 return ((1 << (32 - tsf_bits)) - 1) << tsf_bits;
1035 * extended beacon time format
1036 * time in usec will be changed into a 32-bit value in extended:internal format
1037 * the extended part is the beacon counts
1038 * the internal part is the time in usec within one beacon interval
1040 u32 iwl_usecs_to_beacons(struct iwl_priv *priv, u32 usec, u32 beacon_interval)
1044 u32 interval = beacon_interval * TIME_UNIT;
1046 if (!interval || !usec)
1049 quot = (usec / interval) &
1050 (iwl_beacon_time_mask_high(priv, IWLAGN_EXT_BEACON_TIME_POS) >>
1051 IWLAGN_EXT_BEACON_TIME_POS);
1052 rem = (usec % interval) & iwl_beacon_time_mask_low(priv,
1053 IWLAGN_EXT_BEACON_TIME_POS);
1055 return (quot << IWLAGN_EXT_BEACON_TIME_POS) + rem;
1058 /* base is usually what we get from ucode with each received frame,
1059 * the same as HW timer counter counting down
1061 __le32 iwl_add_beacon_time(struct iwl_priv *priv, u32 base,
1062 u32 addon, u32 beacon_interval)
1064 u32 base_low = base & iwl_beacon_time_mask_low(priv,
1065 IWLAGN_EXT_BEACON_TIME_POS);
1066 u32 addon_low = addon & iwl_beacon_time_mask_low(priv,
1067 IWLAGN_EXT_BEACON_TIME_POS);
1068 u32 interval = beacon_interval * TIME_UNIT;
1069 u32 res = (base & iwl_beacon_time_mask_high(priv,
1070 IWLAGN_EXT_BEACON_TIME_POS)) +
1071 (addon & iwl_beacon_time_mask_high(priv,
1072 IWLAGN_EXT_BEACON_TIME_POS));
1074 if (base_low > addon_low)
1075 res += base_low - addon_low;
1076 else if (base_low < addon_low) {
1077 res += interval + base_low - addon_low;
1078 res += (1 << IWLAGN_EXT_BEACON_TIME_POS);
1080 res += (1 << IWLAGN_EXT_BEACON_TIME_POS);
1082 return cpu_to_le32(res);
1085 void iwl_set_hw_rfkill_state(struct iwl_op_mode *op_mode, bool state)
1087 struct iwl_priv *priv = IWL_OP_MODE_GET_DVM(op_mode);
1090 set_bit(STATUS_RF_KILL_HW, &priv->status);
1092 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1094 wiphy_rfkill_set_hw_state(priv->hw->wiphy, state);
1097 void iwl_free_skb(struct iwl_op_mode *op_mode, struct sk_buff *skb)
1099 struct ieee80211_tx_info *info;
1101 info = IEEE80211_SKB_CB(skb);
1102 kmem_cache_free(iwl_tx_cmd_pool, (info->driver_data[1]));
1103 dev_kfree_skb_any(skb);