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/sched.h>
32 #include <linux/slab.h>
33 #include <net/mac80211.h>
35 #include "iwl-eeprom.h"
36 #include "iwl-debug.h"
39 #include "iwl-power.h"
40 #include "iwl-shared.h"
42 #include "iwl-trans.h"
44 const u8 iwl_bcast_addr
[ETH_ALEN
] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
46 static bool iwl_is_channel_extension(struct iwl_priv
*priv
,
47 enum ieee80211_band band
,
48 u16 channel
, u8 extension_chan_offset
)
50 const struct iwl_channel_info
*ch_info
;
52 ch_info
= iwl_get_channel_info(priv
, band
, channel
);
53 if (!is_channel_valid(ch_info
))
56 if (extension_chan_offset
== IEEE80211_HT_PARAM_CHA_SEC_ABOVE
)
57 return !(ch_info
->ht40_extension_channel
&
58 IEEE80211_CHAN_NO_HT40PLUS
);
59 else if (extension_chan_offset
== IEEE80211_HT_PARAM_CHA_SEC_BELOW
)
60 return !(ch_info
->ht40_extension_channel
&
61 IEEE80211_CHAN_NO_HT40MINUS
);
66 bool iwl_is_ht40_tx_allowed(struct iwl_priv
*priv
,
67 struct iwl_rxon_context
*ctx
,
68 struct ieee80211_sta_ht_cap
*ht_cap
)
70 if (!ctx
->ht
.enabled
|| !ctx
->ht
.is_40mhz
)
74 * We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
75 * the bit will not set if it is pure 40MHz case
77 if (ht_cap
&& !ht_cap
->ht_supported
)
80 #ifdef CONFIG_IWLWIFI_DEBUGFS
81 if (priv
->disable_ht40
)
85 return iwl_is_channel_extension(priv
, priv
->band
,
86 le16_to_cpu(ctx
->staging
.channel
),
87 ctx
->ht
.extension_chan_offset
);
90 static void _iwl_set_rxon_ht(struct iwl_priv
*priv
,
91 struct iwl_ht_config
*ht_conf
,
92 struct iwl_rxon_context
*ctx
)
94 struct iwl_rxon_cmd
*rxon
= &ctx
->staging
;
96 if (!ctx
->ht
.enabled
) {
97 rxon
->flags
&= ~(RXON_FLG_CHANNEL_MODE_MSK
|
98 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
|
99 RXON_FLG_HT40_PROT_MSK
|
100 RXON_FLG_HT_PROT_MSK
);
104 /* FIXME: if the definition of ht.protection changed, the "translation"
105 * will be needed for rxon->flags
107 rxon
->flags
|= cpu_to_le32(ctx
->ht
.protection
<< RXON_FLG_HT_OPERATING_MODE_POS
);
109 /* Set up channel bandwidth:
110 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
111 /* clear the HT channel mode before set the mode */
112 rxon
->flags
&= ~(RXON_FLG_CHANNEL_MODE_MSK
|
113 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
);
114 if (iwl_is_ht40_tx_allowed(priv
, ctx
, NULL
)) {
116 if (ctx
->ht
.protection
== IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
) {
117 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_PURE_40
;
118 /* Note: control channel is opposite of extension channel */
119 switch (ctx
->ht
.extension_chan_offset
) {
120 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE
:
121 rxon
->flags
&= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
;
123 case IEEE80211_HT_PARAM_CHA_SEC_BELOW
:
124 rxon
->flags
|= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
;
128 /* Note: control channel is opposite of extension channel */
129 switch (ctx
->ht
.extension_chan_offset
) {
130 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE
:
131 rxon
->flags
&= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
);
132 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_MIXED
;
134 case IEEE80211_HT_PARAM_CHA_SEC_BELOW
:
135 rxon
->flags
|= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
;
136 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_MIXED
;
138 case IEEE80211_HT_PARAM_CHA_SEC_NONE
:
140 /* channel location only valid if in Mixed mode */
141 IWL_ERR(priv
, "invalid extension channel offset\n");
146 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_LEGACY
;
149 iwlagn_set_rxon_chain(priv
, ctx
);
151 IWL_DEBUG_ASSOC(priv
, "rxon flags 0x%X operation mode :0x%X "
152 "extension channel offset 0x%x\n",
153 le32_to_cpu(rxon
->flags
), ctx
->ht
.protection
,
154 ctx
->ht
.extension_chan_offset
);
157 void iwl_set_rxon_ht(struct iwl_priv
*priv
, struct iwl_ht_config
*ht_conf
)
159 struct iwl_rxon_context
*ctx
;
161 for_each_context(priv
, ctx
)
162 _iwl_set_rxon_ht(priv
, ht_conf
, ctx
);
166 * iwl_set_rxon_channel - Set the band and channel values in staging RXON
167 * @ch: requested channel as a pointer to struct ieee80211_channel
169 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
170 * in the staging RXON flag structure based on the ch->band
172 void iwl_set_rxon_channel(struct iwl_priv
*priv
, struct ieee80211_channel
*ch
,
173 struct iwl_rxon_context
*ctx
)
175 enum ieee80211_band band
= ch
->band
;
176 u16 channel
= ch
->hw_value
;
178 if ((le16_to_cpu(ctx
->staging
.channel
) == channel
) &&
179 (priv
->band
== band
))
182 ctx
->staging
.channel
= cpu_to_le16(channel
);
183 if (band
== IEEE80211_BAND_5GHZ
)
184 ctx
->staging
.flags
&= ~RXON_FLG_BAND_24G_MSK
;
186 ctx
->staging
.flags
|= RXON_FLG_BAND_24G_MSK
;
190 IWL_DEBUG_INFO(priv
, "Staging channel set to %d [%d]\n", channel
, band
);
194 void iwl_set_flags_for_band(struct iwl_priv
*priv
,
195 struct iwl_rxon_context
*ctx
,
196 enum ieee80211_band band
,
197 struct ieee80211_vif
*vif
)
199 if (band
== IEEE80211_BAND_5GHZ
) {
200 ctx
->staging
.flags
&=
201 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
203 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
205 /* Copied from iwl_post_associate() */
206 if (vif
&& vif
->bss_conf
.use_short_slot
)
207 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
209 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
211 ctx
->staging
.flags
|= RXON_FLG_BAND_24G_MSK
;
212 ctx
->staging
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
213 ctx
->staging
.flags
&= ~RXON_FLG_CCK_MSK
;
218 * initialize rxon structure with default values from eeprom
220 void iwl_connection_init_rx_config(struct iwl_priv
*priv
,
221 struct iwl_rxon_context
*ctx
)
223 const struct iwl_channel_info
*ch_info
;
225 memset(&ctx
->staging
, 0, sizeof(ctx
->staging
));
228 ctx
->staging
.dev_type
= ctx
->unused_devtype
;
229 } else switch (ctx
->vif
->type
) {
230 case NL80211_IFTYPE_AP
:
231 ctx
->staging
.dev_type
= ctx
->ap_devtype
;
234 case NL80211_IFTYPE_STATION
:
235 ctx
->staging
.dev_type
= ctx
->station_devtype
;
236 ctx
->staging
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
239 case NL80211_IFTYPE_ADHOC
:
240 ctx
->staging
.dev_type
= ctx
->ibss_devtype
;
241 ctx
->staging
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
242 ctx
->staging
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
243 RXON_FILTER_ACCEPT_GRP_MSK
;
247 IWL_ERR(priv
, "Unsupported interface type %d\n",
253 /* TODO: Figure out when short_preamble would be set and cache from
255 if (!hw_to_local(priv
->hw
)->short_preamble
)
256 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
258 ctx
->staging
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
261 ch_info
= iwl_get_channel_info(priv
, priv
->band
,
262 le16_to_cpu(ctx
->active
.channel
));
265 ch_info
= &priv
->channel_info
[0];
267 ctx
->staging
.channel
= cpu_to_le16(ch_info
->channel
);
268 priv
->band
= ch_info
->band
;
270 iwl_set_flags_for_band(priv
, ctx
, priv
->band
, ctx
->vif
);
272 ctx
->staging
.ofdm_basic_rates
=
273 (IWL_OFDM_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
274 ctx
->staging
.cck_basic_rates
=
275 (IWL_CCK_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
277 /* clear both MIX and PURE40 mode flag */
278 ctx
->staging
.flags
&= ~(RXON_FLG_CHANNEL_MODE_MIXED
|
279 RXON_FLG_CHANNEL_MODE_PURE_40
);
281 memcpy(ctx
->staging
.node_addr
, ctx
->vif
->addr
, ETH_ALEN
);
283 ctx
->staging
.ofdm_ht_single_stream_basic_rates
= 0xff;
284 ctx
->staging
.ofdm_ht_dual_stream_basic_rates
= 0xff;
285 ctx
->staging
.ofdm_ht_triple_stream_basic_rates
= 0xff;
288 void iwl_set_rate(struct iwl_priv
*priv
)
290 const struct ieee80211_supported_band
*hw
= NULL
;
291 struct ieee80211_rate
*rate
;
292 struct iwl_rxon_context
*ctx
;
295 hw
= iwl_get_hw_mode(priv
, priv
->band
);
297 IWL_ERR(priv
, "Failed to set rate: unable to get hw mode\n");
301 priv
->active_rate
= 0;
303 for (i
= 0; i
< hw
->n_bitrates
; i
++) {
304 rate
= &(hw
->bitrates
[i
]);
305 if (rate
->hw_value
< IWL_RATE_COUNT_LEGACY
)
306 priv
->active_rate
|= (1 << rate
->hw_value
);
309 IWL_DEBUG_RATE(priv
, "Set active_rate = %0x\n", priv
->active_rate
);
311 for_each_context(priv
, ctx
) {
312 ctx
->staging
.cck_basic_rates
=
313 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
315 ctx
->staging
.ofdm_basic_rates
=
316 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
320 void iwl_chswitch_done(struct iwl_priv
*priv
, bool is_success
)
324 * See iwlagn_mac_channel_switch.
326 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
328 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
331 if (test_and_clear_bit(STATUS_CHANNEL_SWITCH_PENDING
, &priv
->status
))
332 ieee80211_chswitch_done(ctx
->vif
, is_success
);
335 #ifdef CONFIG_IWLWIFI_DEBUG
336 void iwl_print_rx_config_cmd(struct iwl_priv
*priv
,
337 enum iwl_rxon_context_id ctxid
)
339 struct iwl_rxon_context
*ctx
= &priv
->contexts
[ctxid
];
340 struct iwl_rxon_cmd
*rxon
= &ctx
->staging
;
342 IWL_DEBUG_RADIO(priv
, "RX CONFIG:\n");
343 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
344 IWL_DEBUG_RADIO(priv
, "u16 channel: 0x%x\n", le16_to_cpu(rxon
->channel
));
345 IWL_DEBUG_RADIO(priv
, "u32 flags: 0x%08X\n", le32_to_cpu(rxon
->flags
));
346 IWL_DEBUG_RADIO(priv
, "u32 filter_flags: 0x%08x\n",
347 le32_to_cpu(rxon
->filter_flags
));
348 IWL_DEBUG_RADIO(priv
, "u8 dev_type: 0x%x\n", rxon
->dev_type
);
349 IWL_DEBUG_RADIO(priv
, "u8 ofdm_basic_rates: 0x%02x\n",
350 rxon
->ofdm_basic_rates
);
351 IWL_DEBUG_RADIO(priv
, "u8 cck_basic_rates: 0x%02x\n", rxon
->cck_basic_rates
);
352 IWL_DEBUG_RADIO(priv
, "u8[6] node_addr: %pM\n", rxon
->node_addr
);
353 IWL_DEBUG_RADIO(priv
, "u8[6] bssid_addr: %pM\n", rxon
->bssid_addr
);
354 IWL_DEBUG_RADIO(priv
, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon
->assoc_id
));
358 void iwlagn_fw_error(struct iwl_priv
*priv
, bool ondemand
)
360 unsigned int reload_msec
;
361 unsigned long reload_jiffies
;
363 #ifdef CONFIG_IWLWIFI_DEBUG
364 if (iwl_have_debug_level(IWL_DL_FW_ERRORS
))
365 iwl_print_rx_config_cmd(priv
, IWL_RXON_CTX_BSS
);
368 /* uCode is no longer loaded. */
369 priv
->ucode_loaded
= false;
371 /* Set the FW error flag -- cleared on iwl_down */
372 set_bit(STATUS_FW_ERROR
, &priv
->status
);
374 /* Cancel currently queued command. */
375 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->shrd
->status
);
377 iwl_abort_notification_waits(&priv
->notif_wait
);
379 /* Keep the restart process from trying to send host
380 * commands by clearing the ready bit */
381 clear_bit(STATUS_READY
, &priv
->status
);
383 wake_up(&trans(priv
)->wait_command_queue
);
387 * If firmware keep reloading, then it indicate something
388 * serious wrong and firmware having problem to recover
389 * from it. Instead of keep trying which will fill the syslog
390 * and hang the system, let's just stop it
392 reload_jiffies
= jiffies
;
393 reload_msec
= jiffies_to_msecs((long) reload_jiffies
-
394 (long) priv
->reload_jiffies
);
395 priv
->reload_jiffies
= reload_jiffies
;
396 if (reload_msec
<= IWL_MIN_RELOAD_DURATION
) {
397 priv
->reload_count
++;
398 if (priv
->reload_count
>= IWL_MAX_CONTINUE_RELOAD_CNT
) {
399 IWL_ERR(priv
, "BUG_ON, Stop restarting\n");
403 priv
->reload_count
= 0;
406 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
407 if (iwlagn_mod_params
.restart_fw
) {
408 IWL_DEBUG_FW_ERRORS(priv
,
409 "Restarting adapter due to uCode error.\n");
410 queue_work(priv
->workqueue
, &priv
->restart
);
412 IWL_DEBUG_FW_ERRORS(priv
,
413 "Detected FW error, but not restarting\n");
417 int iwl_set_tx_power(struct iwl_priv
*priv
, s8 tx_power
, bool force
)
422 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
424 lockdep_assert_held(&priv
->mutex
);
426 if (priv
->tx_power_user_lmt
== tx_power
&& !force
)
429 if (tx_power
< IWLAGN_TX_POWER_TARGET_POWER_MIN
) {
431 "Requested user TXPOWER %d below lower limit %d.\n",
433 IWLAGN_TX_POWER_TARGET_POWER_MIN
);
437 if (tx_power
> priv
->tx_power_device_lmt
) {
439 "Requested user TXPOWER %d above upper limit %d.\n",
440 tx_power
, priv
->tx_power_device_lmt
);
444 if (!iwl_is_ready_rf(priv
))
447 /* scan complete and commit_rxon use tx_power_next value,
448 * it always need to be updated for newest request */
449 priv
->tx_power_next
= tx_power
;
451 /* do not set tx power when scanning or channel changing */
452 defer
= test_bit(STATUS_SCANNING
, &priv
->status
) ||
453 memcmp(&ctx
->active
, &ctx
->staging
, sizeof(ctx
->staging
));
454 if (defer
&& !force
) {
455 IWL_DEBUG_INFO(priv
, "Deferring tx power set\n");
459 prev_tx_power
= priv
->tx_power_user_lmt
;
460 priv
->tx_power_user_lmt
= tx_power
;
462 ret
= iwlagn_send_tx_power(priv
);
464 /* if fail to set tx_power, restore the orig. tx power */
466 priv
->tx_power_user_lmt
= prev_tx_power
;
467 priv
->tx_power_next
= prev_tx_power
;
472 void iwl_send_bt_config(struct iwl_priv
*priv
)
474 struct iwl_bt_cmd bt_cmd
= {
475 .lead_time
= BT_LEAD_TIME_DEF
,
476 .max_kill
= BT_MAX_KILL_DEF
,
481 if (!iwlagn_mod_params
.bt_coex_active
)
482 bt_cmd
.flags
= BT_COEX_DISABLE
;
484 bt_cmd
.flags
= BT_COEX_ENABLE
;
486 priv
->bt_enable_flag
= bt_cmd
.flags
;
487 IWL_DEBUG_INFO(priv
, "BT coex %s\n",
488 (bt_cmd
.flags
== BT_COEX_DISABLE
) ? "disable" : "active");
490 if (iwl_dvm_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
491 CMD_SYNC
, sizeof(struct iwl_bt_cmd
), &bt_cmd
))
492 IWL_ERR(priv
, "failed to send BT Coex Config\n");
495 int iwl_send_statistics_request(struct iwl_priv
*priv
, u8 flags
, bool clear
)
497 struct iwl_statistics_cmd statistics_cmd
= {
498 .configuration_flags
=
499 clear
? IWL_STATS_CONF_CLEAR_STATS
: 0,
502 if (flags
& CMD_ASYNC
)
503 return iwl_dvm_send_cmd_pdu(priv
, REPLY_STATISTICS_CMD
,
505 sizeof(struct iwl_statistics_cmd
),
508 return iwl_dvm_send_cmd_pdu(priv
, REPLY_STATISTICS_CMD
,
510 sizeof(struct iwl_statistics_cmd
),
517 #ifdef CONFIG_IWLWIFI_DEBUGFS
519 #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
521 void iwl_reset_traffic_log(struct iwl_priv
*priv
)
523 priv
->tx_traffic_idx
= 0;
524 priv
->rx_traffic_idx
= 0;
525 if (priv
->tx_traffic
)
526 memset(priv
->tx_traffic
, 0, IWL_TRAFFIC_DUMP_SIZE
);
527 if (priv
->rx_traffic
)
528 memset(priv
->rx_traffic
, 0, IWL_TRAFFIC_DUMP_SIZE
);
531 int iwl_alloc_traffic_mem(struct iwl_priv
*priv
)
533 u32 traffic_size
= IWL_TRAFFIC_DUMP_SIZE
;
535 if (iwl_have_debug_level(IWL_DL_TX
)) {
536 if (!priv
->tx_traffic
) {
538 kzalloc(traffic_size
, GFP_KERNEL
);
539 if (!priv
->tx_traffic
)
543 if (iwl_have_debug_level(IWL_DL_RX
)) {
544 if (!priv
->rx_traffic
) {
546 kzalloc(traffic_size
, GFP_KERNEL
);
547 if (!priv
->rx_traffic
)
551 iwl_reset_traffic_log(priv
);
555 void iwl_free_traffic_mem(struct iwl_priv
*priv
)
557 kfree(priv
->tx_traffic
);
558 priv
->tx_traffic
= NULL
;
560 kfree(priv
->rx_traffic
);
561 priv
->rx_traffic
= NULL
;
564 void iwl_dbg_log_tx_data_frame(struct iwl_priv
*priv
,
565 u16 length
, struct ieee80211_hdr
*header
)
570 if (likely(!iwl_have_debug_level(IWL_DL_TX
)))
573 if (!priv
->tx_traffic
)
576 fc
= header
->frame_control
;
577 if (ieee80211_is_data(fc
)) {
578 len
= (length
> IWL_TRAFFIC_ENTRY_SIZE
)
579 ? IWL_TRAFFIC_ENTRY_SIZE
: length
;
580 memcpy((priv
->tx_traffic
+
581 (priv
->tx_traffic_idx
* IWL_TRAFFIC_ENTRY_SIZE
)),
583 priv
->tx_traffic_idx
=
584 (priv
->tx_traffic_idx
+ 1) % IWL_TRAFFIC_ENTRIES
;
588 void iwl_dbg_log_rx_data_frame(struct iwl_priv
*priv
,
589 u16 length
, struct ieee80211_hdr
*header
)
594 if (likely(!iwl_have_debug_level(IWL_DL_RX
)))
597 if (!priv
->rx_traffic
)
600 fc
= header
->frame_control
;
601 if (ieee80211_is_data(fc
)) {
602 len
= (length
> IWL_TRAFFIC_ENTRY_SIZE
)
603 ? IWL_TRAFFIC_ENTRY_SIZE
: length
;
604 memcpy((priv
->rx_traffic
+
605 (priv
->rx_traffic_idx
* IWL_TRAFFIC_ENTRY_SIZE
)),
607 priv
->rx_traffic_idx
=
608 (priv
->rx_traffic_idx
+ 1) % IWL_TRAFFIC_ENTRIES
;
612 const char *get_mgmt_string(int cmd
)
615 IWL_CMD(MANAGEMENT_ASSOC_REQ
);
616 IWL_CMD(MANAGEMENT_ASSOC_RESP
);
617 IWL_CMD(MANAGEMENT_REASSOC_REQ
);
618 IWL_CMD(MANAGEMENT_REASSOC_RESP
);
619 IWL_CMD(MANAGEMENT_PROBE_REQ
);
620 IWL_CMD(MANAGEMENT_PROBE_RESP
);
621 IWL_CMD(MANAGEMENT_BEACON
);
622 IWL_CMD(MANAGEMENT_ATIM
);
623 IWL_CMD(MANAGEMENT_DISASSOC
);
624 IWL_CMD(MANAGEMENT_AUTH
);
625 IWL_CMD(MANAGEMENT_DEAUTH
);
626 IWL_CMD(MANAGEMENT_ACTION
);
633 const char *get_ctrl_string(int cmd
)
636 IWL_CMD(CONTROL_BACK_REQ
);
637 IWL_CMD(CONTROL_BACK
);
638 IWL_CMD(CONTROL_PSPOLL
);
639 IWL_CMD(CONTROL_RTS
);
640 IWL_CMD(CONTROL_CTS
);
641 IWL_CMD(CONTROL_ACK
);
642 IWL_CMD(CONTROL_CFEND
);
643 IWL_CMD(CONTROL_CFENDACK
);
650 void iwl_clear_traffic_stats(struct iwl_priv
*priv
)
652 memset(&priv
->tx_stats
, 0, sizeof(struct traffic_stats
));
653 memset(&priv
->rx_stats
, 0, sizeof(struct traffic_stats
));
657 * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will
658 * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass.
659 * Use debugFs to display the rx/rx_statistics
660 * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL
661 * information will be recorded, but DATA pkt still will be recorded
662 * for the reason of iwl_led.c need to control the led blinking based on
663 * number of tx and rx data.
666 void iwl_update_stats(struct iwl_priv
*priv
, bool is_tx
, __le16 fc
, u16 len
)
668 struct traffic_stats
*stats
;
671 stats
= &priv
->tx_stats
;
673 stats
= &priv
->rx_stats
;
675 if (ieee80211_is_mgmt(fc
)) {
676 switch (fc
& cpu_to_le16(IEEE80211_FCTL_STYPE
)) {
677 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ
):
678 stats
->mgmt
[MANAGEMENT_ASSOC_REQ
]++;
680 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP
):
681 stats
->mgmt
[MANAGEMENT_ASSOC_RESP
]++;
683 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ
):
684 stats
->mgmt
[MANAGEMENT_REASSOC_REQ
]++;
686 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP
):
687 stats
->mgmt
[MANAGEMENT_REASSOC_RESP
]++;
689 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
):
690 stats
->mgmt
[MANAGEMENT_PROBE_REQ
]++;
692 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP
):
693 stats
->mgmt
[MANAGEMENT_PROBE_RESP
]++;
695 case cpu_to_le16(IEEE80211_STYPE_BEACON
):
696 stats
->mgmt
[MANAGEMENT_BEACON
]++;
698 case cpu_to_le16(IEEE80211_STYPE_ATIM
):
699 stats
->mgmt
[MANAGEMENT_ATIM
]++;
701 case cpu_to_le16(IEEE80211_STYPE_DISASSOC
):
702 stats
->mgmt
[MANAGEMENT_DISASSOC
]++;
704 case cpu_to_le16(IEEE80211_STYPE_AUTH
):
705 stats
->mgmt
[MANAGEMENT_AUTH
]++;
707 case cpu_to_le16(IEEE80211_STYPE_DEAUTH
):
708 stats
->mgmt
[MANAGEMENT_DEAUTH
]++;
710 case cpu_to_le16(IEEE80211_STYPE_ACTION
):
711 stats
->mgmt
[MANAGEMENT_ACTION
]++;
714 } else if (ieee80211_is_ctl(fc
)) {
715 switch (fc
& cpu_to_le16(IEEE80211_FCTL_STYPE
)) {
716 case cpu_to_le16(IEEE80211_STYPE_BACK_REQ
):
717 stats
->ctrl
[CONTROL_BACK_REQ
]++;
719 case cpu_to_le16(IEEE80211_STYPE_BACK
):
720 stats
->ctrl
[CONTROL_BACK
]++;
722 case cpu_to_le16(IEEE80211_STYPE_PSPOLL
):
723 stats
->ctrl
[CONTROL_PSPOLL
]++;
725 case cpu_to_le16(IEEE80211_STYPE_RTS
):
726 stats
->ctrl
[CONTROL_RTS
]++;
728 case cpu_to_le16(IEEE80211_STYPE_CTS
):
729 stats
->ctrl
[CONTROL_CTS
]++;
731 case cpu_to_le16(IEEE80211_STYPE_ACK
):
732 stats
->ctrl
[CONTROL_ACK
]++;
734 case cpu_to_le16(IEEE80211_STYPE_CFEND
):
735 stats
->ctrl
[CONTROL_CFEND
]++;
737 case cpu_to_le16(IEEE80211_STYPE_CFENDACK
):
738 stats
->ctrl
[CONTROL_CFENDACK
]++;
744 stats
->data_bytes
+= len
;
749 static void iwl_force_rf_reset(struct iwl_priv
*priv
)
751 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
754 if (!iwl_is_any_associated(priv
)) {
755 IWL_DEBUG_SCAN(priv
, "force reset rejected: not associated\n");
759 * There is no easy and better way to force reset the radio,
760 * the only known method is switching channel which will force to
761 * reset and tune the radio.
762 * Use internal short scan (single channel) operation to should
763 * achieve this objective.
764 * Driver should reset the radio when number of consecutive missed
765 * beacon, or any other uCode error condition detected.
767 IWL_DEBUG_INFO(priv
, "perform radio reset.\n");
768 iwl_internal_short_hw_scan(priv
);
772 int iwl_force_reset(struct iwl_priv
*priv
, int mode
, bool external
)
774 struct iwl_force_reset
*force_reset
;
776 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
779 if (mode
>= IWL_MAX_FORCE_RESET
) {
780 IWL_DEBUG_INFO(priv
, "invalid reset request.\n");
783 force_reset
= &priv
->force_reset
[mode
];
784 force_reset
->reset_request_count
++;
786 if (force_reset
->last_force_reset_jiffies
&&
787 time_after(force_reset
->last_force_reset_jiffies
+
788 force_reset
->reset_duration
, jiffies
)) {
789 IWL_DEBUG_INFO(priv
, "force reset rejected\n");
790 force_reset
->reset_reject_count
++;
794 force_reset
->reset_success_count
++;
795 force_reset
->last_force_reset_jiffies
= jiffies
;
796 IWL_DEBUG_INFO(priv
, "perform force reset (%d)\n", mode
);
799 iwl_force_rf_reset(priv
);
803 * if the request is from external(ex: debugfs),
804 * then always perform the request in regardless the module
806 * if the request is from internal (uCode error or driver
807 * detect failure), then fw_restart module parameter
808 * need to be check before performing firmware reload
810 if (!external
&& !iwlagn_mod_params
.restart_fw
) {
811 IWL_DEBUG_INFO(priv
, "Cancel firmware reload based on "
812 "module parameter setting\n");
815 IWL_ERR(priv
, "On demand firmware reload\n");
816 iwlagn_fw_error(priv
, true);
823 int iwl_cmd_echo_test(struct iwl_priv
*priv
)
826 struct iwl_host_cmd cmd
= {
832 ret
= iwl_dvm_send_cmd(priv
, &cmd
);
834 IWL_ERR(priv
, "echo testing fail: 0X%x\n", ret
);
836 IWL_DEBUG_INFO(priv
, "echo testing pass\n");
840 static inline int iwl_check_stuck_queue(struct iwl_priv
*priv
, int txq
)
842 if (iwl_trans_check_stuck_queue(trans(priv
), txq
)) {
844 ret
= iwl_force_reset(priv
, IWL_FW_RESET
, false);
845 return (ret
== -EAGAIN
) ? 0 : 1;
851 * Making watchdog tick be a quarter of timeout assure we will
852 * discover the queue hung between timeout and 1.25*timeout
854 #define IWL_WD_TICK(timeout) ((timeout) / 4)
857 * Watchdog timer callback, we check each tx queue for stuck, if if hung
858 * we reset the firmware. If everything is fine just rearm the timer.
860 void iwl_bg_watchdog(unsigned long data
)
862 struct iwl_priv
*priv
= (struct iwl_priv
*)data
;
864 unsigned long timeout
;
866 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
869 if (iwl_is_rfkill(priv
))
872 timeout
= hw_params(priv
).wd_timeout
;
876 /* monitor and check for stuck queues */
877 for (cnt
= 0; cnt
< cfg(priv
)->base_params
->num_of_queues
; cnt
++)
878 if (iwl_check_stuck_queue(priv
, cnt
))
881 mod_timer(&priv
->watchdog
, jiffies
+
882 msecs_to_jiffies(IWL_WD_TICK(timeout
)));
885 void iwl_setup_watchdog(struct iwl_priv
*priv
)
887 unsigned int timeout
= hw_params(priv
).wd_timeout
;
889 if (!iwlagn_mod_params
.wd_disable
) {
890 /* use system default */
891 if (timeout
&& !cfg(priv
)->base_params
->wd_disable
)
892 mod_timer(&priv
->watchdog
,
894 msecs_to_jiffies(IWL_WD_TICK(timeout
)));
896 del_timer(&priv
->watchdog
);
898 /* module parameter overwrite default configuration */
899 if (timeout
&& iwlagn_mod_params
.wd_disable
== 2)
900 mod_timer(&priv
->watchdog
,
902 msecs_to_jiffies(IWL_WD_TICK(timeout
)));
904 del_timer(&priv
->watchdog
);
909 * iwl_beacon_time_mask_low - mask of lower 32 bit of beacon time
910 * @priv -- pointer to iwl_priv data structure
911 * @tsf_bits -- number of bits need to shift for masking)
913 static inline u32
iwl_beacon_time_mask_low(struct iwl_priv
*priv
,
916 return (1 << tsf_bits
) - 1;
920 * iwl_beacon_time_mask_high - mask of higher 32 bit of beacon time
921 * @priv -- pointer to iwl_priv data structure
922 * @tsf_bits -- number of bits need to shift for masking)
924 static inline u32
iwl_beacon_time_mask_high(struct iwl_priv
*priv
,
927 return ((1 << (32 - tsf_bits
)) - 1) << tsf_bits
;
931 * extended beacon time format
932 * time in usec will be changed into a 32-bit value in extended:internal format
933 * the extended part is the beacon counts
934 * the internal part is the time in usec within one beacon interval
936 u32
iwl_usecs_to_beacons(struct iwl_priv
*priv
, u32 usec
, u32 beacon_interval
)
940 u32 interval
= beacon_interval
* TIME_UNIT
;
942 if (!interval
|| !usec
)
945 quot
= (usec
/ interval
) &
946 (iwl_beacon_time_mask_high(priv
, IWLAGN_EXT_BEACON_TIME_POS
) >>
947 IWLAGN_EXT_BEACON_TIME_POS
);
948 rem
= (usec
% interval
) & iwl_beacon_time_mask_low(priv
,
949 IWLAGN_EXT_BEACON_TIME_POS
);
951 return (quot
<< IWLAGN_EXT_BEACON_TIME_POS
) + rem
;
954 /* base is usually what we get from ucode with each received frame,
955 * the same as HW timer counter counting down
957 __le32
iwl_add_beacon_time(struct iwl_priv
*priv
, u32 base
,
958 u32 addon
, u32 beacon_interval
)
960 u32 base_low
= base
& iwl_beacon_time_mask_low(priv
,
961 IWLAGN_EXT_BEACON_TIME_POS
);
962 u32 addon_low
= addon
& iwl_beacon_time_mask_low(priv
,
963 IWLAGN_EXT_BEACON_TIME_POS
);
964 u32 interval
= beacon_interval
* TIME_UNIT
;
965 u32 res
= (base
& iwl_beacon_time_mask_high(priv
,
966 IWLAGN_EXT_BEACON_TIME_POS
)) +
967 (addon
& iwl_beacon_time_mask_high(priv
,
968 IWLAGN_EXT_BEACON_TIME_POS
));
970 if (base_low
> addon_low
)
971 res
+= base_low
- addon_low
;
972 else if (base_low
< addon_low
) {
973 res
+= interval
+ base_low
- addon_low
;
974 res
+= (1 << IWLAGN_EXT_BEACON_TIME_POS
);
976 res
+= (1 << IWLAGN_EXT_BEACON_TIME_POS
);
978 return cpu_to_le32(res
);
981 void iwl_set_hw_rfkill_state(struct iwl_op_mode
*op_mode
, bool state
)
983 struct iwl_priv
*priv
= IWL_OP_MODE_GET_DVM(op_mode
);
986 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
988 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
990 wiphy_rfkill_set_hw_state(priv
->hw
->wiphy
, state
);
993 void iwl_free_skb(struct iwl_op_mode
*op_mode
, struct sk_buff
*skb
)
995 struct ieee80211_tx_info
*info
;
997 info
= IEEE80211_SKB_CB(skb
);
998 kmem_cache_free(iwl_tx_cmd_pool
, (info
->driver_data
[1]));
999 dev_kfree_skb_any(skb
);