1 /******************************************************************************
5 * Copyright(c) 2008 - 2011 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"
48 * set bt_coex_active to true, uCode will do kill/defer
49 * every time the priority line is asserted (BT is sending signals on the
50 * priority line in the PCIx).
51 * set bt_coex_active to false, uCode will ignore the BT activity and
52 * perform the normal operation
54 * User might experience transmit issue on some platform due to WiFi/BT
55 * co-exist problem. The possible behaviors are:
56 * Able to scan and finding all the available AP
57 * Not able to associate with any AP
58 * On those platforms, WiFi communication can be restored by set
59 * "bt_coex_active" module parameter to "false"
61 * default: bt_coex_active = true (BT_COEX_ENABLE)
63 bool bt_coex_active
= true;
64 module_param(bt_coex_active
, bool, S_IRUGO
);
65 MODULE_PARM_DESC(bt_coex_active
, "enable wifi/bluetooth co-exist");
69 const u8 iwl_bcast_addr
[ETH_ALEN
] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
71 #define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
72 #define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
73 static void iwlcore_init_ht_hw_capab(const struct iwl_priv
*priv
,
74 struct ieee80211_sta_ht_cap
*ht_info
,
75 enum ieee80211_band band
)
78 u8 rx_chains_num
= priv
->hw_params
.rx_chains_num
;
79 u8 tx_chains_num
= priv
->hw_params
.tx_chains_num
;
82 memset(&ht_info
->mcs
, 0, sizeof(ht_info
->mcs
));
84 ht_info
->ht_supported
= true;
86 if (priv
->cfg
->ht_params
&&
87 priv
->cfg
->ht_params
->ht_greenfield_support
)
88 ht_info
->cap
|= IEEE80211_HT_CAP_GRN_FLD
;
89 ht_info
->cap
|= IEEE80211_HT_CAP_SGI_20
;
90 max_bit_rate
= MAX_BIT_RATE_20_MHZ
;
91 if (priv
->hw_params
.ht40_channel
& BIT(band
)) {
92 ht_info
->cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
93 ht_info
->cap
|= IEEE80211_HT_CAP_SGI_40
;
94 ht_info
->mcs
.rx_mask
[4] = 0x01;
95 max_bit_rate
= MAX_BIT_RATE_40_MHZ
;
98 if (iwlagn_mod_params
.amsdu_size_8K
)
99 ht_info
->cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
101 ht_info
->ampdu_factor
= CFG_HT_RX_AMPDU_FACTOR_DEF
;
102 if (priv
->cfg
->bt_params
&& priv
->cfg
->bt_params
->ampdu_factor
)
103 ht_info
->ampdu_factor
= priv
->cfg
->bt_params
->ampdu_factor
;
104 ht_info
->ampdu_density
= CFG_HT_MPDU_DENSITY_DEF
;
105 if (priv
->cfg
->bt_params
&& priv
->cfg
->bt_params
->ampdu_density
)
106 ht_info
->ampdu_density
= priv
->cfg
->bt_params
->ampdu_density
;
108 ht_info
->mcs
.rx_mask
[0] = 0xFF;
109 if (rx_chains_num
>= 2)
110 ht_info
->mcs
.rx_mask
[1] = 0xFF;
111 if (rx_chains_num
>= 3)
112 ht_info
->mcs
.rx_mask
[2] = 0xFF;
114 /* Highest supported Rx data rate */
115 max_bit_rate
*= rx_chains_num
;
116 WARN_ON(max_bit_rate
& ~IEEE80211_HT_MCS_RX_HIGHEST_MASK
);
117 ht_info
->mcs
.rx_highest
= cpu_to_le16(max_bit_rate
);
119 /* Tx MCS capabilities */
120 ht_info
->mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
121 if (tx_chains_num
!= rx_chains_num
) {
122 ht_info
->mcs
.tx_params
|= IEEE80211_HT_MCS_TX_RX_DIFF
;
123 ht_info
->mcs
.tx_params
|= ((tx_chains_num
- 1) <<
124 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT
);
129 * iwlcore_init_geos - Initialize mac80211's geo/channel info based from eeprom
131 int iwlcore_init_geos(struct iwl_priv
*priv
)
133 struct iwl_channel_info
*ch
;
134 struct ieee80211_supported_band
*sband
;
135 struct ieee80211_channel
*channels
;
136 struct ieee80211_channel
*geo_ch
;
137 struct ieee80211_rate
*rates
;
139 s8 max_tx_power
= IWLAGN_TX_POWER_TARGET_POWER_MIN
;
141 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_bitrates
||
142 priv
->bands
[IEEE80211_BAND_5GHZ
].n_bitrates
) {
143 IWL_DEBUG_INFO(priv
, "Geography modes already initialized.\n");
144 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
148 channels
= kzalloc(sizeof(struct ieee80211_channel
) *
149 priv
->channel_count
, GFP_KERNEL
);
153 rates
= kzalloc((sizeof(struct ieee80211_rate
) * IWL_RATE_COUNT_LEGACY
),
160 /* 5.2GHz channels start after the 2.4GHz channels */
161 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
162 sband
->channels
= &channels
[ARRAY_SIZE(iwl_eeprom_band_1
)];
164 sband
->bitrates
= &rates
[IWL_FIRST_OFDM_RATE
];
165 sband
->n_bitrates
= IWL_RATE_COUNT_LEGACY
- IWL_FIRST_OFDM_RATE
;
167 if (priv
->cfg
->sku
& IWL_SKU_N
)
168 iwlcore_init_ht_hw_capab(priv
, &sband
->ht_cap
,
169 IEEE80211_BAND_5GHZ
);
171 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
172 sband
->channels
= channels
;
174 sband
->bitrates
= rates
;
175 sband
->n_bitrates
= IWL_RATE_COUNT_LEGACY
;
177 if (priv
->cfg
->sku
& IWL_SKU_N
)
178 iwlcore_init_ht_hw_capab(priv
, &sband
->ht_cap
,
179 IEEE80211_BAND_2GHZ
);
181 priv
->ieee_channels
= channels
;
182 priv
->ieee_rates
= rates
;
184 for (i
= 0; i
< priv
->channel_count
; i
++) {
185 ch
= &priv
->channel_info
[i
];
187 /* FIXME: might be removed if scan is OK */
188 if (!is_channel_valid(ch
))
191 sband
= &priv
->bands
[ch
->band
];
193 geo_ch
= &sband
->channels
[sband
->n_channels
++];
195 geo_ch
->center_freq
=
196 ieee80211_channel_to_frequency(ch
->channel
, ch
->band
);
197 geo_ch
->max_power
= ch
->max_power_avg
;
198 geo_ch
->max_antenna_gain
= 0xff;
199 geo_ch
->hw_value
= ch
->channel
;
201 if (is_channel_valid(ch
)) {
202 if (!(ch
->flags
& EEPROM_CHANNEL_IBSS
))
203 geo_ch
->flags
|= IEEE80211_CHAN_NO_IBSS
;
205 if (!(ch
->flags
& EEPROM_CHANNEL_ACTIVE
))
206 geo_ch
->flags
|= IEEE80211_CHAN_PASSIVE_SCAN
;
208 if (ch
->flags
& EEPROM_CHANNEL_RADAR
)
209 geo_ch
->flags
|= IEEE80211_CHAN_RADAR
;
211 geo_ch
->flags
|= ch
->ht40_extension_channel
;
213 if (ch
->max_power_avg
> max_tx_power
)
214 max_tx_power
= ch
->max_power_avg
;
216 geo_ch
->flags
|= IEEE80211_CHAN_DISABLED
;
219 IWL_DEBUG_INFO(priv
, "Channel %d Freq=%d[%sGHz] %s flag=0x%X\n",
220 ch
->channel
, geo_ch
->center_freq
,
221 is_channel_a_band(ch
) ? "5.2" : "2.4",
222 geo_ch
->flags
& IEEE80211_CHAN_DISABLED
?
223 "restricted" : "valid",
227 priv
->tx_power_device_lmt
= max_tx_power
;
228 priv
->tx_power_user_lmt
= max_tx_power
;
229 priv
->tx_power_next
= max_tx_power
;
231 if ((priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
== 0) &&
232 priv
->cfg
->sku
& IWL_SKU_A
) {
233 IWL_INFO(priv
, "Incorrectly detected BG card as ABG. "
234 "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
235 priv
->pci_dev
->device
,
236 priv
->pci_dev
->subsystem_device
);
237 priv
->cfg
->sku
&= ~IWL_SKU_A
;
240 IWL_INFO(priv
, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
241 priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
,
242 priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
);
244 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
250 * iwlcore_free_geos - undo allocations in iwlcore_init_geos
252 void iwlcore_free_geos(struct iwl_priv
*priv
)
254 kfree(priv
->ieee_channels
);
255 kfree(priv
->ieee_rates
);
256 clear_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
259 static bool iwl_is_channel_extension(struct iwl_priv
*priv
,
260 enum ieee80211_band band
,
261 u16 channel
, u8 extension_chan_offset
)
263 const struct iwl_channel_info
*ch_info
;
265 ch_info
= iwl_get_channel_info(priv
, band
, channel
);
266 if (!is_channel_valid(ch_info
))
269 if (extension_chan_offset
== IEEE80211_HT_PARAM_CHA_SEC_ABOVE
)
270 return !(ch_info
->ht40_extension_channel
&
271 IEEE80211_CHAN_NO_HT40PLUS
);
272 else if (extension_chan_offset
== IEEE80211_HT_PARAM_CHA_SEC_BELOW
)
273 return !(ch_info
->ht40_extension_channel
&
274 IEEE80211_CHAN_NO_HT40MINUS
);
279 bool iwl_is_ht40_tx_allowed(struct iwl_priv
*priv
,
280 struct iwl_rxon_context
*ctx
,
281 struct ieee80211_sta_ht_cap
*ht_cap
)
283 if (!ctx
->ht
.enabled
|| !ctx
->ht
.is_40mhz
)
287 * We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
288 * the bit will not set if it is pure 40MHz case
290 if (ht_cap
&& !ht_cap
->ht_supported
)
293 #ifdef CONFIG_IWLWIFI_DEBUGFS
294 if (priv
->disable_ht40
)
298 return iwl_is_channel_extension(priv
, priv
->band
,
299 le16_to_cpu(ctx
->staging
.channel
),
300 ctx
->ht
.extension_chan_offset
);
303 static u16
iwl_adjust_beacon_interval(u16 beacon_val
, u16 max_beacon_val
)
309 * If mac80211 hasn't given us a beacon interval, program
310 * the default into the device (not checking this here
311 * would cause the adjustment below to return the maximum
312 * value, which may break PAN.)
315 return DEFAULT_BEACON_INTERVAL
;
318 * If the beacon interval we obtained from the peer
319 * is too large, we'll have to wake up more often
320 * (and in IBSS case, we'll beacon too much)
322 * For example, if max_beacon_val is 4096, and the
323 * requested beacon interval is 7000, we'll have to
324 * use 3500 to be able to wake up on the beacons.
326 * This could badly influence beacon detection stats.
329 beacon_factor
= (beacon_val
+ max_beacon_val
) / max_beacon_val
;
330 new_val
= beacon_val
/ beacon_factor
;
333 new_val
= max_beacon_val
;
338 int iwl_send_rxon_timing(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
341 s32 interval_tm
, rem
;
342 struct ieee80211_conf
*conf
= NULL
;
344 struct ieee80211_vif
*vif
= ctx
->vif
;
346 conf
= ieee80211_get_hw_conf(priv
->hw
);
348 lockdep_assert_held(&priv
->mutex
);
350 memset(&ctx
->timing
, 0, sizeof(struct iwl_rxon_time_cmd
));
352 ctx
->timing
.timestamp
= cpu_to_le64(priv
->timestamp
);
353 ctx
->timing
.listen_interval
= cpu_to_le16(conf
->listen_interval
);
355 beacon_int
= vif
? vif
->bss_conf
.beacon_int
: 0;
358 * TODO: For IBSS we need to get atim_window from mac80211,
359 * for now just always use 0
361 ctx
->timing
.atim_window
= 0;
363 if (ctx
->ctxid
== IWL_RXON_CTX_PAN
&&
364 (!ctx
->vif
|| ctx
->vif
->type
!= NL80211_IFTYPE_STATION
) &&
365 iwl_is_associated(priv
, IWL_RXON_CTX_BSS
) &&
366 priv
->contexts
[IWL_RXON_CTX_BSS
].vif
&&
367 priv
->contexts
[IWL_RXON_CTX_BSS
].vif
->bss_conf
.beacon_int
) {
368 ctx
->timing
.beacon_interval
=
369 priv
->contexts
[IWL_RXON_CTX_BSS
].timing
.beacon_interval
;
370 beacon_int
= le16_to_cpu(ctx
->timing
.beacon_interval
);
371 } else if (ctx
->ctxid
== IWL_RXON_CTX_BSS
&&
372 iwl_is_associated(priv
, IWL_RXON_CTX_PAN
) &&
373 priv
->contexts
[IWL_RXON_CTX_PAN
].vif
&&
374 priv
->contexts
[IWL_RXON_CTX_PAN
].vif
->bss_conf
.beacon_int
&&
375 (!iwl_is_associated_ctx(ctx
) || !ctx
->vif
||
376 !ctx
->vif
->bss_conf
.beacon_int
)) {
377 ctx
->timing
.beacon_interval
=
378 priv
->contexts
[IWL_RXON_CTX_PAN
].timing
.beacon_interval
;
379 beacon_int
= le16_to_cpu(ctx
->timing
.beacon_interval
);
381 beacon_int
= iwl_adjust_beacon_interval(beacon_int
,
382 priv
->hw_params
.max_beacon_itrvl
* TIME_UNIT
);
383 ctx
->timing
.beacon_interval
= cpu_to_le16(beacon_int
);
386 tsf
= priv
->timestamp
; /* tsf is modifed by do_div: copy it */
387 interval_tm
= beacon_int
* TIME_UNIT
;
388 rem
= do_div(tsf
, interval_tm
);
389 ctx
->timing
.beacon_init_val
= cpu_to_le32(interval_tm
- rem
);
391 ctx
->timing
.dtim_period
= vif
? (vif
->bss_conf
.dtim_period
?: 1) : 1;
393 IWL_DEBUG_ASSOC(priv
,
394 "beacon interval %d beacon timer %d beacon tim %d\n",
395 le16_to_cpu(ctx
->timing
.beacon_interval
),
396 le32_to_cpu(ctx
->timing
.beacon_init_val
),
397 le16_to_cpu(ctx
->timing
.atim_window
));
399 return iwl_send_cmd_pdu(priv
, ctx
->rxon_timing_cmd
,
400 sizeof(ctx
->timing
), &ctx
->timing
);
403 void iwl_set_rxon_hwcrypto(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
,
406 struct iwl_rxon_cmd
*rxon
= &ctx
->staging
;
409 rxon
->filter_flags
&= ~RXON_FILTER_DIS_DECRYPT_MSK
;
411 rxon
->filter_flags
|= RXON_FILTER_DIS_DECRYPT_MSK
;
415 /* validate RXON structure is valid */
416 int iwl_check_rxon_cmd(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
418 struct iwl_rxon_cmd
*rxon
= &ctx
->staging
;
421 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
422 if (rxon
->flags
& RXON_FLG_TGJ_NARROW_BAND_MSK
) {
423 IWL_WARN(priv
, "check 2.4G: wrong narrow\n");
426 if (rxon
->flags
& RXON_FLG_RADAR_DETECT_MSK
) {
427 IWL_WARN(priv
, "check 2.4G: wrong radar\n");
431 if (!(rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
)) {
432 IWL_WARN(priv
, "check 5.2G: not short slot!\n");
435 if (rxon
->flags
& RXON_FLG_CCK_MSK
) {
436 IWL_WARN(priv
, "check 5.2G: CCK!\n");
440 if ((rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1) {
441 IWL_WARN(priv
, "mac/bssid mcast!\n");
445 /* make sure basic rates 6Mbps and 1Mbps are supported */
446 if ((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0 &&
447 (rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0) {
448 IWL_WARN(priv
, "neither 1 nor 6 are basic\n");
452 if (le16_to_cpu(rxon
->assoc_id
) > 2007) {
453 IWL_WARN(priv
, "aid > 2007\n");
457 if ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
458 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
)) {
459 IWL_WARN(priv
, "CCK and short slot\n");
463 if ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
464 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
)) {
465 IWL_WARN(priv
, "CCK and auto detect");
469 if ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
470 RXON_FLG_TGG_PROTECT_MSK
)) ==
471 RXON_FLG_TGG_PROTECT_MSK
) {
472 IWL_WARN(priv
, "TGg but no auto-detect\n");
476 if (rxon
->channel
== 0) {
477 IWL_WARN(priv
, "zero channel is invalid\n");
481 WARN(errors
, "Invalid RXON (%#x), channel %d",
482 errors
, le16_to_cpu(rxon
->channel
));
484 return errors
? -EINVAL
: 0;
488 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
489 * @priv: staging_rxon is compared to active_rxon
491 * If the RXON structure is changing enough to require a new tune,
492 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
493 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
495 int iwl_full_rxon_required(struct iwl_priv
*priv
,
496 struct iwl_rxon_context
*ctx
)
498 const struct iwl_rxon_cmd
*staging
= &ctx
->staging
;
499 const struct iwl_rxon_cmd
*active
= &ctx
->active
;
503 IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
507 #define CHK_NEQ(c1, c2) \
508 if ((c1) != (c2)) { \
509 IWL_DEBUG_INFO(priv, "need full RXON - " \
510 #c1 " != " #c2 " - %d != %d\n", \
515 /* These items are only settable from the full RXON command */
516 CHK(!iwl_is_associated_ctx(ctx
));
517 CHK(compare_ether_addr(staging
->bssid_addr
, active
->bssid_addr
));
518 CHK(compare_ether_addr(staging
->node_addr
, active
->node_addr
));
519 CHK(compare_ether_addr(staging
->wlap_bssid_addr
,
520 active
->wlap_bssid_addr
));
521 CHK_NEQ(staging
->dev_type
, active
->dev_type
);
522 CHK_NEQ(staging
->channel
, active
->channel
);
523 CHK_NEQ(staging
->air_propagation
, active
->air_propagation
);
524 CHK_NEQ(staging
->ofdm_ht_single_stream_basic_rates
,
525 active
->ofdm_ht_single_stream_basic_rates
);
526 CHK_NEQ(staging
->ofdm_ht_dual_stream_basic_rates
,
527 active
->ofdm_ht_dual_stream_basic_rates
);
528 CHK_NEQ(staging
->ofdm_ht_triple_stream_basic_rates
,
529 active
->ofdm_ht_triple_stream_basic_rates
);
530 CHK_NEQ(staging
->assoc_id
, active
->assoc_id
);
532 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
533 * be updated with the RXON_ASSOC command -- however only some
534 * flag transitions are allowed using RXON_ASSOC */
536 /* Check if we are not switching bands */
537 CHK_NEQ(staging
->flags
& RXON_FLG_BAND_24G_MSK
,
538 active
->flags
& RXON_FLG_BAND_24G_MSK
);
540 /* Check if we are switching association toggle */
541 CHK_NEQ(staging
->filter_flags
& RXON_FILTER_ASSOC_MSK
,
542 active
->filter_flags
& RXON_FILTER_ASSOC_MSK
);
550 u8
iwl_rate_get_lowest_plcp(struct iwl_priv
*priv
,
551 struct iwl_rxon_context
*ctx
)
554 * Assign the lowest rate -- should really get this from
555 * the beacon skb from mac80211.
557 if (ctx
->staging
.flags
& RXON_FLG_BAND_24G_MSK
)
558 return IWL_RATE_1M_PLCP
;
560 return IWL_RATE_6M_PLCP
;
563 static void _iwl_set_rxon_ht(struct iwl_priv
*priv
,
564 struct iwl_ht_config
*ht_conf
,
565 struct iwl_rxon_context
*ctx
)
567 struct iwl_rxon_cmd
*rxon
= &ctx
->staging
;
569 if (!ctx
->ht
.enabled
) {
570 rxon
->flags
&= ~(RXON_FLG_CHANNEL_MODE_MSK
|
571 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
|
572 RXON_FLG_HT40_PROT_MSK
|
573 RXON_FLG_HT_PROT_MSK
);
577 /* FIXME: if the definition of ht.protection changed, the "translation"
578 * will be needed for rxon->flags
580 rxon
->flags
|= cpu_to_le32(ctx
->ht
.protection
<< RXON_FLG_HT_OPERATING_MODE_POS
);
582 /* Set up channel bandwidth:
583 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
584 /* clear the HT channel mode before set the mode */
585 rxon
->flags
&= ~(RXON_FLG_CHANNEL_MODE_MSK
|
586 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
);
587 if (iwl_is_ht40_tx_allowed(priv
, ctx
, NULL
)) {
589 if (ctx
->ht
.protection
== IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
) {
590 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_PURE_40
;
591 /* Note: control channel is opposite of extension channel */
592 switch (ctx
->ht
.extension_chan_offset
) {
593 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE
:
594 rxon
->flags
&= ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
;
596 case IEEE80211_HT_PARAM_CHA_SEC_BELOW
:
597 rxon
->flags
|= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
;
601 /* Note: control channel is opposite of extension channel */
602 switch (ctx
->ht
.extension_chan_offset
) {
603 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE
:
604 rxon
->flags
&= ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
);
605 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_MIXED
;
607 case IEEE80211_HT_PARAM_CHA_SEC_BELOW
:
608 rxon
->flags
|= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
;
609 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_MIXED
;
611 case IEEE80211_HT_PARAM_CHA_SEC_NONE
:
613 /* channel location only valid if in Mixed mode */
614 IWL_ERR(priv
, "invalid extension channel offset\n");
619 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_LEGACY
;
622 if (priv
->cfg
->ops
->hcmd
->set_rxon_chain
)
623 priv
->cfg
->ops
->hcmd
->set_rxon_chain(priv
, ctx
);
625 IWL_DEBUG_ASSOC(priv
, "rxon flags 0x%X operation mode :0x%X "
626 "extension channel offset 0x%x\n",
627 le32_to_cpu(rxon
->flags
), ctx
->ht
.protection
,
628 ctx
->ht
.extension_chan_offset
);
631 void iwl_set_rxon_ht(struct iwl_priv
*priv
, struct iwl_ht_config
*ht_conf
)
633 struct iwl_rxon_context
*ctx
;
635 for_each_context(priv
, ctx
)
636 _iwl_set_rxon_ht(priv
, ht_conf
, ctx
);
639 /* Return valid, unused, channel for a passive scan to reset the RF */
640 u8
iwl_get_single_channel_number(struct iwl_priv
*priv
,
641 enum ieee80211_band band
)
643 const struct iwl_channel_info
*ch_info
;
647 struct iwl_rxon_context
*ctx
;
649 if (band
== IEEE80211_BAND_5GHZ
) {
651 max
= priv
->channel_count
;
657 for (i
= min
; i
< max
; i
++) {
660 for_each_context(priv
, ctx
) {
661 busy
= priv
->channel_info
[i
].channel
==
662 le16_to_cpu(ctx
->staging
.channel
);
670 channel
= priv
->channel_info
[i
].channel
;
671 ch_info
= iwl_get_channel_info(priv
, band
, channel
);
672 if (is_channel_valid(ch_info
))
680 * iwl_set_rxon_channel - Set the band and channel values in staging RXON
681 * @ch: requested channel as a pointer to struct ieee80211_channel
683 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
684 * in the staging RXON flag structure based on the ch->band
686 int iwl_set_rxon_channel(struct iwl_priv
*priv
, struct ieee80211_channel
*ch
,
687 struct iwl_rxon_context
*ctx
)
689 enum ieee80211_band band
= ch
->band
;
690 u16 channel
= ch
->hw_value
;
692 if ((le16_to_cpu(ctx
->staging
.channel
) == channel
) &&
693 (priv
->band
== band
))
696 ctx
->staging
.channel
= cpu_to_le16(channel
);
697 if (band
== IEEE80211_BAND_5GHZ
)
698 ctx
->staging
.flags
&= ~RXON_FLG_BAND_24G_MSK
;
700 ctx
->staging
.flags
|= RXON_FLG_BAND_24G_MSK
;
704 IWL_DEBUG_INFO(priv
, "Staging channel set to %d [%d]\n", channel
, band
);
709 void iwl_set_flags_for_band(struct iwl_priv
*priv
,
710 struct iwl_rxon_context
*ctx
,
711 enum ieee80211_band band
,
712 struct ieee80211_vif
*vif
)
714 if (band
== IEEE80211_BAND_5GHZ
) {
715 ctx
->staging
.flags
&=
716 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
718 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
720 /* Copied from iwl_post_associate() */
721 if (vif
&& vif
->bss_conf
.use_short_slot
)
722 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
724 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
726 ctx
->staging
.flags
|= RXON_FLG_BAND_24G_MSK
;
727 ctx
->staging
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
728 ctx
->staging
.flags
&= ~RXON_FLG_CCK_MSK
;
733 * initialize rxon structure with default values from eeprom
735 void iwl_connection_init_rx_config(struct iwl_priv
*priv
,
736 struct iwl_rxon_context
*ctx
)
738 const struct iwl_channel_info
*ch_info
;
740 memset(&ctx
->staging
, 0, sizeof(ctx
->staging
));
743 ctx
->staging
.dev_type
= ctx
->unused_devtype
;
744 } else switch (ctx
->vif
->type
) {
745 case NL80211_IFTYPE_AP
:
746 ctx
->staging
.dev_type
= ctx
->ap_devtype
;
749 case NL80211_IFTYPE_STATION
:
750 ctx
->staging
.dev_type
= ctx
->station_devtype
;
751 ctx
->staging
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
754 case NL80211_IFTYPE_ADHOC
:
755 ctx
->staging
.dev_type
= ctx
->ibss_devtype
;
756 ctx
->staging
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
757 ctx
->staging
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
758 RXON_FILTER_ACCEPT_GRP_MSK
;
762 IWL_ERR(priv
, "Unsupported interface type %d\n",
768 /* TODO: Figure out when short_preamble would be set and cache from
770 if (!hw_to_local(priv
->hw
)->short_preamble
)
771 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
773 ctx
->staging
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
776 ch_info
= iwl_get_channel_info(priv
, priv
->band
,
777 le16_to_cpu(ctx
->active
.channel
));
780 ch_info
= &priv
->channel_info
[0];
782 ctx
->staging
.channel
= cpu_to_le16(ch_info
->channel
);
783 priv
->band
= ch_info
->band
;
785 iwl_set_flags_for_band(priv
, ctx
, priv
->band
, ctx
->vif
);
787 ctx
->staging
.ofdm_basic_rates
=
788 (IWL_OFDM_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
789 ctx
->staging
.cck_basic_rates
=
790 (IWL_CCK_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
792 /* clear both MIX and PURE40 mode flag */
793 ctx
->staging
.flags
&= ~(RXON_FLG_CHANNEL_MODE_MIXED
|
794 RXON_FLG_CHANNEL_MODE_PURE_40
);
796 memcpy(ctx
->staging
.node_addr
, ctx
->vif
->addr
, ETH_ALEN
);
798 ctx
->staging
.ofdm_ht_single_stream_basic_rates
= 0xff;
799 ctx
->staging
.ofdm_ht_dual_stream_basic_rates
= 0xff;
800 ctx
->staging
.ofdm_ht_triple_stream_basic_rates
= 0xff;
803 void iwl_set_rate(struct iwl_priv
*priv
)
805 const struct ieee80211_supported_band
*hw
= NULL
;
806 struct ieee80211_rate
*rate
;
807 struct iwl_rxon_context
*ctx
;
810 hw
= iwl_get_hw_mode(priv
, priv
->band
);
812 IWL_ERR(priv
, "Failed to set rate: unable to get hw mode\n");
816 priv
->active_rate
= 0;
818 for (i
= 0; i
< hw
->n_bitrates
; i
++) {
819 rate
= &(hw
->bitrates
[i
]);
820 if (rate
->hw_value
< IWL_RATE_COUNT_LEGACY
)
821 priv
->active_rate
|= (1 << rate
->hw_value
);
824 IWL_DEBUG_RATE(priv
, "Set active_rate = %0x\n", priv
->active_rate
);
826 for_each_context(priv
, ctx
) {
827 ctx
->staging
.cck_basic_rates
=
828 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
830 ctx
->staging
.ofdm_basic_rates
=
831 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
835 void iwl_chswitch_done(struct iwl_priv
*priv
, bool is_success
)
839 * See iwl_mac_channel_switch.
841 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
843 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
846 if (test_and_clear_bit(STATUS_CHANNEL_SWITCH_PENDING
, &priv
->status
))
847 ieee80211_chswitch_done(ctx
->vif
, is_success
);
850 #ifdef CONFIG_IWLWIFI_DEBUG
851 void iwl_print_rx_config_cmd(struct iwl_priv
*priv
,
852 struct iwl_rxon_context
*ctx
)
854 struct iwl_rxon_cmd
*rxon
= &ctx
->staging
;
856 IWL_DEBUG_RADIO(priv
, "RX CONFIG:\n");
857 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
858 IWL_DEBUG_RADIO(priv
, "u16 channel: 0x%x\n", le16_to_cpu(rxon
->channel
));
859 IWL_DEBUG_RADIO(priv
, "u32 flags: 0x%08X\n", le32_to_cpu(rxon
->flags
));
860 IWL_DEBUG_RADIO(priv
, "u32 filter_flags: 0x%08x\n",
861 le32_to_cpu(rxon
->filter_flags
));
862 IWL_DEBUG_RADIO(priv
, "u8 dev_type: 0x%x\n", rxon
->dev_type
);
863 IWL_DEBUG_RADIO(priv
, "u8 ofdm_basic_rates: 0x%02x\n",
864 rxon
->ofdm_basic_rates
);
865 IWL_DEBUG_RADIO(priv
, "u8 cck_basic_rates: 0x%02x\n", rxon
->cck_basic_rates
);
866 IWL_DEBUG_RADIO(priv
, "u8[6] node_addr: %pM\n", rxon
->node_addr
);
867 IWL_DEBUG_RADIO(priv
, "u8[6] bssid_addr: %pM\n", rxon
->bssid_addr
);
868 IWL_DEBUG_RADIO(priv
, "u16 assoc_id: 0x%x\n", le16_to_cpu(rxon
->assoc_id
));
872 static void iwlagn_abort_notification_waits(struct iwl_priv
*priv
)
875 struct iwl_notification_wait
*wait_entry
;
877 spin_lock_irqsave(&priv
->_agn
.notif_wait_lock
, flags
);
878 list_for_each_entry(wait_entry
, &priv
->_agn
.notif_waits
, list
)
879 wait_entry
->aborted
= true;
880 spin_unlock_irqrestore(&priv
->_agn
.notif_wait_lock
, flags
);
882 wake_up_all(&priv
->_agn
.notif_waitq
);
885 void iwlagn_fw_error(struct iwl_priv
*priv
, bool ondemand
)
887 unsigned int reload_msec
;
888 unsigned long reload_jiffies
;
890 /* Set the FW error flag -- cleared on iwl_down */
891 set_bit(STATUS_FW_ERROR
, &priv
->status
);
893 /* Cancel currently queued command. */
894 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
896 iwlagn_abort_notification_waits(priv
);
898 /* Keep the restart process from trying to send host
899 * commands by clearing the ready bit */
900 clear_bit(STATUS_READY
, &priv
->status
);
902 wake_up_interruptible(&priv
->wait_command_queue
);
906 * If firmware keep reloading, then it indicate something
907 * serious wrong and firmware having problem to recover
908 * from it. Instead of keep trying which will fill the syslog
909 * and hang the system, let's just stop it
911 reload_jiffies
= jiffies
;
912 reload_msec
= jiffies_to_msecs((long) reload_jiffies
-
913 (long) priv
->reload_jiffies
);
914 priv
->reload_jiffies
= reload_jiffies
;
915 if (reload_msec
<= IWL_MIN_RELOAD_DURATION
) {
916 priv
->reload_count
++;
917 if (priv
->reload_count
>= IWL_MAX_CONTINUE_RELOAD_CNT
) {
918 IWL_ERR(priv
, "BUG_ON, Stop restarting\n");
922 priv
->reload_count
= 0;
925 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
926 if (iwlagn_mod_params
.restart_fw
) {
927 IWL_DEBUG(priv
, IWL_DL_FW_ERRORS
,
928 "Restarting adapter due to uCode error.\n");
929 queue_work(priv
->workqueue
, &priv
->restart
);
931 IWL_DEBUG(priv
, IWL_DL_FW_ERRORS
,
932 "Detected FW error, but not restarting\n");
937 * iwl_irq_handle_error - called for HW or SW error interrupt from card
939 void iwl_irq_handle_error(struct iwl_priv
*priv
)
941 /* W/A for WiFi/WiMAX coex and WiMAX own the RF */
942 if (priv
->cfg
->internal_wimax_coex
&&
943 (!(iwl_read_prph(priv
, APMG_CLK_CTRL_REG
) &
944 APMS_CLK_VAL_MRB_FUNC_MODE
) ||
945 (iwl_read_prph(priv
, APMG_PS_CTRL_REG
) &
946 APMG_PS_CTRL_VAL_RESET_REQ
))) {
948 * Keep the restart process from trying to send host
949 * commands by clearing the ready bit.
951 clear_bit(STATUS_READY
, &priv
->status
);
952 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
953 wake_up_interruptible(&priv
->wait_command_queue
);
954 IWL_ERR(priv
, "RF is used by WiMAX\n");
958 IWL_ERR(priv
, "Loaded firmware version: %s\n",
959 priv
->hw
->wiphy
->fw_version
);
961 iwl_dump_nic_error_log(priv
);
963 iwl_dump_fh(priv
, NULL
, false);
964 iwl_dump_nic_event_log(priv
, false, NULL
, false);
965 #ifdef CONFIG_IWLWIFI_DEBUG
966 if (iwl_get_debug_level(priv
) & IWL_DL_FW_ERRORS
)
967 iwl_print_rx_config_cmd(priv
,
968 &priv
->contexts
[IWL_RXON_CTX_BSS
]);
971 iwlagn_fw_error(priv
, false);
974 static int iwl_apm_stop_master(struct iwl_priv
*priv
)
978 /* stop device's busmaster DMA activity */
979 iwl_set_bit(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_STOP_MASTER
);
981 ret
= iwl_poll_bit(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_MASTER_DISABLED
,
982 CSR_RESET_REG_FLAG_MASTER_DISABLED
, 100);
984 IWL_WARN(priv
, "Master Disable Timed Out, 100 usec\n");
986 IWL_DEBUG_INFO(priv
, "stop master\n");
991 void iwl_apm_stop(struct iwl_priv
*priv
)
993 IWL_DEBUG_INFO(priv
, "Stop card, put in low power state\n");
995 clear_bit(STATUS_DEVICE_ENABLED
, &priv
->status
);
997 /* Stop device's DMA activity */
998 iwl_apm_stop_master(priv
);
1000 /* Reset the entire device */
1001 iwl_set_bit(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_SW_RESET
);
1006 * Clear "initialization complete" bit to move adapter from
1007 * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
1009 iwl_clear_bit(priv
, CSR_GP_CNTRL
, CSR_GP_CNTRL_REG_FLAG_INIT_DONE
);
1014 * Start up NIC's basic functionality after it has been reset
1015 * (e.g. after platform boot, or shutdown via iwl_apm_stop())
1016 * NOTE: This does not load uCode nor start the embedded processor
1018 int iwl_apm_init(struct iwl_priv
*priv
)
1023 IWL_DEBUG_INFO(priv
, "Init card's basic functions\n");
1026 * Use "set_bit" below rather than "write", to preserve any hardware
1027 * bits already set by default after reset.
1030 /* Disable L0S exit timer (platform NMI Work/Around) */
1031 iwl_set_bit(priv
, CSR_GIO_CHICKEN_BITS
,
1032 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER
);
1035 * Disable L0s without affecting L1;
1036 * don't wait for ICH L0s (ICH bug W/A)
1038 iwl_set_bit(priv
, CSR_GIO_CHICKEN_BITS
,
1039 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX
);
1041 /* Set FH wait threshold to maximum (HW error during stress W/A) */
1042 iwl_set_bit(priv
, CSR_DBG_HPET_MEM_REG
, CSR_DBG_HPET_MEM_REG_VAL
);
1045 * Enable HAP INTA (interrupt from management bus) to
1046 * wake device's PCI Express link L1a -> L0s
1048 iwl_set_bit(priv
, CSR_HW_IF_CONFIG_REG
,
1049 CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A
);
1052 * HW bug W/A for instability in PCIe bus L0->L0S->L1 transition.
1053 * Check if BIOS (or OS) enabled L1-ASPM on this device.
1054 * If so (likely), disable L0S, so device moves directly L0->L1;
1055 * costs negligible amount of power savings.
1056 * If not (unlikely), enable L0S, so there is at least some
1057 * power savings, even without L1.
1059 lctl
= iwl_pcie_link_ctl(priv
);
1060 if ((lctl
& PCI_CFG_LINK_CTRL_VAL_L1_EN
) ==
1061 PCI_CFG_LINK_CTRL_VAL_L1_EN
) {
1062 /* L1-ASPM enabled; disable(!) L0S */
1063 iwl_set_bit(priv
, CSR_GIO_REG
,
1064 CSR_GIO_REG_VAL_L0S_ENABLED
);
1065 IWL_DEBUG_POWER(priv
, "L1 Enabled; Disabling L0S\n");
1067 /* L1-ASPM disabled; enable(!) L0S */
1068 iwl_clear_bit(priv
, CSR_GIO_REG
,
1069 CSR_GIO_REG_VAL_L0S_ENABLED
);
1070 IWL_DEBUG_POWER(priv
, "L1 Disabled; Enabling L0S\n");
1073 /* Configure analog phase-lock-loop before activating to D0A */
1074 if (priv
->cfg
->base_params
->pll_cfg_val
)
1075 iwl_set_bit(priv
, CSR_ANA_PLL_CFG
,
1076 priv
->cfg
->base_params
->pll_cfg_val
);
1079 * Set "initialization complete" bit to move adapter from
1080 * D0U* --> D0A* (powered-up active) state.
1082 iwl_set_bit(priv
, CSR_GP_CNTRL
, CSR_GP_CNTRL_REG_FLAG_INIT_DONE
);
1085 * Wait for clock stabilization; once stabilized, access to
1086 * device-internal resources is supported, e.g. iwl_write_prph()
1087 * and accesses to uCode SRAM.
1089 ret
= iwl_poll_bit(priv
, CSR_GP_CNTRL
,
1090 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
,
1091 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
, 25000);
1093 IWL_DEBUG_INFO(priv
, "Failed to init the card\n");
1098 * Enable DMA clock and wait for it to stabilize.
1100 * Write to "CLK_EN_REG"; "1" bits enable clocks, while "0" bits
1101 * do not disable clocks. This preserves any hardware bits already
1102 * set by default in "CLK_CTRL_REG" after reset.
1104 iwl_write_prph(priv
, APMG_CLK_EN_REG
, APMG_CLK_VAL_DMA_CLK_RQT
);
1107 /* Disable L1-Active */
1108 iwl_set_bits_prph(priv
, APMG_PCIDEV_STT_REG
,
1109 APMG_PCIDEV_STT_VAL_L1_ACT_DIS
);
1111 set_bit(STATUS_DEVICE_ENABLED
, &priv
->status
);
1118 int iwl_set_tx_power(struct iwl_priv
*priv
, s8 tx_power
, bool force
)
1123 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
1125 lockdep_assert_held(&priv
->mutex
);
1127 if (priv
->tx_power_user_lmt
== tx_power
&& !force
)
1130 if (!priv
->cfg
->ops
->lib
->send_tx_power
)
1133 if (tx_power
< IWLAGN_TX_POWER_TARGET_POWER_MIN
) {
1135 "Requested user TXPOWER %d below lower limit %d.\n",
1137 IWLAGN_TX_POWER_TARGET_POWER_MIN
);
1141 if (tx_power
> priv
->tx_power_device_lmt
) {
1143 "Requested user TXPOWER %d above upper limit %d.\n",
1144 tx_power
, priv
->tx_power_device_lmt
);
1148 if (!iwl_is_ready_rf(priv
))
1151 /* scan complete and commit_rxon use tx_power_next value,
1152 * it always need to be updated for newest request */
1153 priv
->tx_power_next
= tx_power
;
1155 /* do not set tx power when scanning or channel changing */
1156 defer
= test_bit(STATUS_SCANNING
, &priv
->status
) ||
1157 memcmp(&ctx
->active
, &ctx
->staging
, sizeof(ctx
->staging
));
1158 if (defer
&& !force
) {
1159 IWL_DEBUG_INFO(priv
, "Deferring tx power set\n");
1163 prev_tx_power
= priv
->tx_power_user_lmt
;
1164 priv
->tx_power_user_lmt
= tx_power
;
1166 ret
= priv
->cfg
->ops
->lib
->send_tx_power(priv
);
1168 /* if fail to set tx_power, restore the orig. tx power */
1170 priv
->tx_power_user_lmt
= prev_tx_power
;
1171 priv
->tx_power_next
= prev_tx_power
;
1176 void iwl_send_bt_config(struct iwl_priv
*priv
)
1178 struct iwl_bt_cmd bt_cmd
= {
1179 .lead_time
= BT_LEAD_TIME_DEF
,
1180 .max_kill
= BT_MAX_KILL_DEF
,
1185 if (!bt_coex_active
)
1186 bt_cmd
.flags
= BT_COEX_DISABLE
;
1188 bt_cmd
.flags
= BT_COEX_ENABLE
;
1190 priv
->bt_enable_flag
= bt_cmd
.flags
;
1191 IWL_DEBUG_INFO(priv
, "BT coex %s\n",
1192 (bt_cmd
.flags
== BT_COEX_DISABLE
) ? "disable" : "active");
1194 if (iwl_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
1195 sizeof(struct iwl_bt_cmd
), &bt_cmd
))
1196 IWL_ERR(priv
, "failed to send BT Coex Config\n");
1199 int iwl_send_statistics_request(struct iwl_priv
*priv
, u8 flags
, bool clear
)
1201 struct iwl_statistics_cmd statistics_cmd
= {
1202 .configuration_flags
=
1203 clear
? IWL_STATS_CONF_CLEAR_STATS
: 0,
1206 if (flags
& CMD_ASYNC
)
1207 return iwl_send_cmd_pdu_async(priv
, REPLY_STATISTICS_CMD
,
1208 sizeof(struct iwl_statistics_cmd
),
1209 &statistics_cmd
, NULL
);
1211 return iwl_send_cmd_pdu(priv
, REPLY_STATISTICS_CMD
,
1212 sizeof(struct iwl_statistics_cmd
),
1216 void iwl_clear_isr_stats(struct iwl_priv
*priv
)
1218 memset(&priv
->isr_stats
, 0, sizeof(priv
->isr_stats
));
1221 int iwl_mac_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
1222 const struct ieee80211_tx_queue_params
*params
)
1224 struct iwl_priv
*priv
= hw
->priv
;
1225 struct iwl_rxon_context
*ctx
;
1226 unsigned long flags
;
1229 IWL_DEBUG_MAC80211(priv
, "enter\n");
1231 if (!iwl_is_ready_rf(priv
)) {
1232 IWL_DEBUG_MAC80211(priv
, "leave - RF not ready\n");
1236 if (queue
>= AC_NUM
) {
1237 IWL_DEBUG_MAC80211(priv
, "leave - queue >= AC_NUM %d\n", queue
);
1241 q
= AC_NUM
- 1 - queue
;
1243 spin_lock_irqsave(&priv
->lock
, flags
);
1247 * This may need to be done per interface in nl80211/cfg80211/mac80211.
1249 for_each_context(priv
, ctx
) {
1250 ctx
->qos_data
.def_qos_parm
.ac
[q
].cw_min
=
1251 cpu_to_le16(params
->cw_min
);
1252 ctx
->qos_data
.def_qos_parm
.ac
[q
].cw_max
=
1253 cpu_to_le16(params
->cw_max
);
1254 ctx
->qos_data
.def_qos_parm
.ac
[q
].aifsn
= params
->aifs
;
1255 ctx
->qos_data
.def_qos_parm
.ac
[q
].edca_txop
=
1256 cpu_to_le16((params
->txop
* 32));
1258 ctx
->qos_data
.def_qos_parm
.ac
[q
].reserved1
= 0;
1261 spin_unlock_irqrestore(&priv
->lock
, flags
);
1263 IWL_DEBUG_MAC80211(priv
, "leave\n");
1267 int iwl_mac_tx_last_beacon(struct ieee80211_hw
*hw
)
1269 struct iwl_priv
*priv
= hw
->priv
;
1271 return priv
->ibss_manager
== IWL_IBSS_MANAGER
;
1274 static int iwl_set_mode(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
1276 iwl_connection_init_rx_config(priv
, ctx
);
1278 if (priv
->cfg
->ops
->hcmd
->set_rxon_chain
)
1279 priv
->cfg
->ops
->hcmd
->set_rxon_chain(priv
, ctx
);
1281 return iwlcore_commit_rxon(priv
, ctx
);
1284 static int iwl_setup_interface(struct iwl_priv
*priv
,
1285 struct iwl_rxon_context
*ctx
)
1287 struct ieee80211_vif
*vif
= ctx
->vif
;
1290 lockdep_assert_held(&priv
->mutex
);
1293 * This variable will be correct only when there's just
1294 * a single context, but all code using it is for hardware
1295 * that supports only one context.
1297 priv
->iw_mode
= vif
->type
;
1299 ctx
->is_active
= true;
1301 err
= iwl_set_mode(priv
, ctx
);
1303 if (!ctx
->always_active
)
1304 ctx
->is_active
= false;
1308 if (priv
->cfg
->bt_params
&& priv
->cfg
->bt_params
->advanced_bt_coexist
&&
1309 vif
->type
== NL80211_IFTYPE_ADHOC
) {
1311 * pretend to have high BT traffic as long as we
1312 * are operating in IBSS mode, as this will cause
1313 * the rate scaling etc. to behave as intended.
1315 priv
->bt_traffic_load
= IWL_BT_COEX_TRAFFIC_LOAD_HIGH
;
1321 int iwl_mac_add_interface(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1323 struct iwl_priv
*priv
= hw
->priv
;
1324 struct iwl_vif_priv
*vif_priv
= (void *)vif
->drv_priv
;
1325 struct iwl_rxon_context
*tmp
, *ctx
= NULL
;
1327 enum nl80211_iftype viftype
= ieee80211_vif_type_p2p(vif
);
1329 IWL_DEBUG_MAC80211(priv
, "enter: type %d, addr %pM\n",
1330 viftype
, vif
->addr
);
1332 mutex_lock(&priv
->mutex
);
1334 if (!iwl_is_ready_rf(priv
)) {
1335 IWL_WARN(priv
, "Try to add interface when device not ready\n");
1340 for_each_context(priv
, tmp
) {
1341 u32 possible_modes
=
1342 tmp
->interface_modes
| tmp
->exclusive_interface_modes
;
1345 /* check if this busy context is exclusive */
1346 if (tmp
->exclusive_interface_modes
&
1347 BIT(tmp
->vif
->type
)) {
1354 if (!(possible_modes
& BIT(viftype
)))
1357 /* have maybe usable context w/o interface */
1367 vif_priv
->ctx
= ctx
;
1370 err
= iwl_setup_interface(priv
, ctx
);
1375 priv
->iw_mode
= NL80211_IFTYPE_STATION
;
1377 mutex_unlock(&priv
->mutex
);
1379 IWL_DEBUG_MAC80211(priv
, "leave\n");
1383 static void iwl_teardown_interface(struct iwl_priv
*priv
,
1384 struct ieee80211_vif
*vif
,
1387 struct iwl_rxon_context
*ctx
= iwl_rxon_ctx_from_vif(vif
);
1389 lockdep_assert_held(&priv
->mutex
);
1391 if (priv
->scan_vif
== vif
) {
1392 iwl_scan_cancel_timeout(priv
, 200);
1393 iwl_force_scan_end(priv
);
1397 iwl_set_mode(priv
, ctx
);
1398 if (!ctx
->always_active
)
1399 ctx
->is_active
= false;
1403 * When removing the IBSS interface, overwrite the
1404 * BT traffic load with the stored one from the last
1405 * notification, if any. If this is a device that
1406 * doesn't implement this, this has no effect since
1407 * both values are the same and zero.
1409 if (vif
->type
== NL80211_IFTYPE_ADHOC
)
1410 priv
->bt_traffic_load
= priv
->last_bt_traffic_load
;
1413 void iwl_mac_remove_interface(struct ieee80211_hw
*hw
,
1414 struct ieee80211_vif
*vif
)
1416 struct iwl_priv
*priv
= hw
->priv
;
1417 struct iwl_rxon_context
*ctx
= iwl_rxon_ctx_from_vif(vif
);
1419 IWL_DEBUG_MAC80211(priv
, "enter\n");
1421 mutex_lock(&priv
->mutex
);
1423 WARN_ON(ctx
->vif
!= vif
);
1426 iwl_teardown_interface(priv
, vif
, false);
1428 mutex_unlock(&priv
->mutex
);
1430 IWL_DEBUG_MAC80211(priv
, "leave\n");
1434 int iwl_alloc_txq_mem(struct iwl_priv
*priv
)
1437 priv
->txq
= kzalloc(
1438 sizeof(struct iwl_tx_queue
) *
1439 priv
->cfg
->base_params
->num_of_queues
,
1442 IWL_ERR(priv
, "Not enough memory for txq\n");
1448 void iwl_free_txq_mem(struct iwl_priv
*priv
)
1454 #ifdef CONFIG_IWLWIFI_DEBUGFS
1456 #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
1458 void iwl_reset_traffic_log(struct iwl_priv
*priv
)
1460 priv
->tx_traffic_idx
= 0;
1461 priv
->rx_traffic_idx
= 0;
1462 if (priv
->tx_traffic
)
1463 memset(priv
->tx_traffic
, 0, IWL_TRAFFIC_DUMP_SIZE
);
1464 if (priv
->rx_traffic
)
1465 memset(priv
->rx_traffic
, 0, IWL_TRAFFIC_DUMP_SIZE
);
1468 int iwl_alloc_traffic_mem(struct iwl_priv
*priv
)
1470 u32 traffic_size
= IWL_TRAFFIC_DUMP_SIZE
;
1472 if (iwl_debug_level
& IWL_DL_TX
) {
1473 if (!priv
->tx_traffic
) {
1475 kzalloc(traffic_size
, GFP_KERNEL
);
1476 if (!priv
->tx_traffic
)
1480 if (iwl_debug_level
& IWL_DL_RX
) {
1481 if (!priv
->rx_traffic
) {
1483 kzalloc(traffic_size
, GFP_KERNEL
);
1484 if (!priv
->rx_traffic
)
1488 iwl_reset_traffic_log(priv
);
1492 void iwl_free_traffic_mem(struct iwl_priv
*priv
)
1494 kfree(priv
->tx_traffic
);
1495 priv
->tx_traffic
= NULL
;
1497 kfree(priv
->rx_traffic
);
1498 priv
->rx_traffic
= NULL
;
1501 void iwl_dbg_log_tx_data_frame(struct iwl_priv
*priv
,
1502 u16 length
, struct ieee80211_hdr
*header
)
1507 if (likely(!(iwl_debug_level
& IWL_DL_TX
)))
1510 if (!priv
->tx_traffic
)
1513 fc
= header
->frame_control
;
1514 if (ieee80211_is_data(fc
)) {
1515 len
= (length
> IWL_TRAFFIC_ENTRY_SIZE
)
1516 ? IWL_TRAFFIC_ENTRY_SIZE
: length
;
1517 memcpy((priv
->tx_traffic
+
1518 (priv
->tx_traffic_idx
* IWL_TRAFFIC_ENTRY_SIZE
)),
1520 priv
->tx_traffic_idx
=
1521 (priv
->tx_traffic_idx
+ 1) % IWL_TRAFFIC_ENTRIES
;
1525 void iwl_dbg_log_rx_data_frame(struct iwl_priv
*priv
,
1526 u16 length
, struct ieee80211_hdr
*header
)
1531 if (likely(!(iwl_debug_level
& IWL_DL_RX
)))
1534 if (!priv
->rx_traffic
)
1537 fc
= header
->frame_control
;
1538 if (ieee80211_is_data(fc
)) {
1539 len
= (length
> IWL_TRAFFIC_ENTRY_SIZE
)
1540 ? IWL_TRAFFIC_ENTRY_SIZE
: length
;
1541 memcpy((priv
->rx_traffic
+
1542 (priv
->rx_traffic_idx
* IWL_TRAFFIC_ENTRY_SIZE
)),
1544 priv
->rx_traffic_idx
=
1545 (priv
->rx_traffic_idx
+ 1) % IWL_TRAFFIC_ENTRIES
;
1549 const char *get_mgmt_string(int cmd
)
1552 IWL_CMD(MANAGEMENT_ASSOC_REQ
);
1553 IWL_CMD(MANAGEMENT_ASSOC_RESP
);
1554 IWL_CMD(MANAGEMENT_REASSOC_REQ
);
1555 IWL_CMD(MANAGEMENT_REASSOC_RESP
);
1556 IWL_CMD(MANAGEMENT_PROBE_REQ
);
1557 IWL_CMD(MANAGEMENT_PROBE_RESP
);
1558 IWL_CMD(MANAGEMENT_BEACON
);
1559 IWL_CMD(MANAGEMENT_ATIM
);
1560 IWL_CMD(MANAGEMENT_DISASSOC
);
1561 IWL_CMD(MANAGEMENT_AUTH
);
1562 IWL_CMD(MANAGEMENT_DEAUTH
);
1563 IWL_CMD(MANAGEMENT_ACTION
);
1570 const char *get_ctrl_string(int cmd
)
1573 IWL_CMD(CONTROL_BACK_REQ
);
1574 IWL_CMD(CONTROL_BACK
);
1575 IWL_CMD(CONTROL_PSPOLL
);
1576 IWL_CMD(CONTROL_RTS
);
1577 IWL_CMD(CONTROL_CTS
);
1578 IWL_CMD(CONTROL_ACK
);
1579 IWL_CMD(CONTROL_CFEND
);
1580 IWL_CMD(CONTROL_CFENDACK
);
1587 void iwl_clear_traffic_stats(struct iwl_priv
*priv
)
1589 memset(&priv
->tx_stats
, 0, sizeof(struct traffic_stats
));
1590 memset(&priv
->rx_stats
, 0, sizeof(struct traffic_stats
));
1594 * if CONFIG_IWLWIFI_DEBUGFS defined, iwl_update_stats function will
1595 * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass.
1596 * Use debugFs to display the rx/rx_statistics
1597 * if CONFIG_IWLWIFI_DEBUGFS not being defined, then no MGMT and CTRL
1598 * information will be recorded, but DATA pkt still will be recorded
1599 * for the reason of iwl_led.c need to control the led blinking based on
1600 * number of tx and rx data.
1603 void iwl_update_stats(struct iwl_priv
*priv
, bool is_tx
, __le16 fc
, u16 len
)
1605 struct traffic_stats
*stats
;
1608 stats
= &priv
->tx_stats
;
1610 stats
= &priv
->rx_stats
;
1612 if (ieee80211_is_mgmt(fc
)) {
1613 switch (fc
& cpu_to_le16(IEEE80211_FCTL_STYPE
)) {
1614 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ
):
1615 stats
->mgmt
[MANAGEMENT_ASSOC_REQ
]++;
1617 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP
):
1618 stats
->mgmt
[MANAGEMENT_ASSOC_RESP
]++;
1620 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ
):
1621 stats
->mgmt
[MANAGEMENT_REASSOC_REQ
]++;
1623 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP
):
1624 stats
->mgmt
[MANAGEMENT_REASSOC_RESP
]++;
1626 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
):
1627 stats
->mgmt
[MANAGEMENT_PROBE_REQ
]++;
1629 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP
):
1630 stats
->mgmt
[MANAGEMENT_PROBE_RESP
]++;
1632 case cpu_to_le16(IEEE80211_STYPE_BEACON
):
1633 stats
->mgmt
[MANAGEMENT_BEACON
]++;
1635 case cpu_to_le16(IEEE80211_STYPE_ATIM
):
1636 stats
->mgmt
[MANAGEMENT_ATIM
]++;
1638 case cpu_to_le16(IEEE80211_STYPE_DISASSOC
):
1639 stats
->mgmt
[MANAGEMENT_DISASSOC
]++;
1641 case cpu_to_le16(IEEE80211_STYPE_AUTH
):
1642 stats
->mgmt
[MANAGEMENT_AUTH
]++;
1644 case cpu_to_le16(IEEE80211_STYPE_DEAUTH
):
1645 stats
->mgmt
[MANAGEMENT_DEAUTH
]++;
1647 case cpu_to_le16(IEEE80211_STYPE_ACTION
):
1648 stats
->mgmt
[MANAGEMENT_ACTION
]++;
1651 } else if (ieee80211_is_ctl(fc
)) {
1652 switch (fc
& cpu_to_le16(IEEE80211_FCTL_STYPE
)) {
1653 case cpu_to_le16(IEEE80211_STYPE_BACK_REQ
):
1654 stats
->ctrl
[CONTROL_BACK_REQ
]++;
1656 case cpu_to_le16(IEEE80211_STYPE_BACK
):
1657 stats
->ctrl
[CONTROL_BACK
]++;
1659 case cpu_to_le16(IEEE80211_STYPE_PSPOLL
):
1660 stats
->ctrl
[CONTROL_PSPOLL
]++;
1662 case cpu_to_le16(IEEE80211_STYPE_RTS
):
1663 stats
->ctrl
[CONTROL_RTS
]++;
1665 case cpu_to_le16(IEEE80211_STYPE_CTS
):
1666 stats
->ctrl
[CONTROL_CTS
]++;
1668 case cpu_to_le16(IEEE80211_STYPE_ACK
):
1669 stats
->ctrl
[CONTROL_ACK
]++;
1671 case cpu_to_le16(IEEE80211_STYPE_CFEND
):
1672 stats
->ctrl
[CONTROL_CFEND
]++;
1674 case cpu_to_le16(IEEE80211_STYPE_CFENDACK
):
1675 stats
->ctrl
[CONTROL_CFENDACK
]++;
1681 stats
->data_bytes
+= len
;
1686 static void iwl_force_rf_reset(struct iwl_priv
*priv
)
1688 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1691 if (!iwl_is_any_associated(priv
)) {
1692 IWL_DEBUG_SCAN(priv
, "force reset rejected: not associated\n");
1696 * There is no easy and better way to force reset the radio,
1697 * the only known method is switching channel which will force to
1698 * reset and tune the radio.
1699 * Use internal short scan (single channel) operation to should
1700 * achieve this objective.
1701 * Driver should reset the radio when number of consecutive missed
1702 * beacon, or any other uCode error condition detected.
1704 IWL_DEBUG_INFO(priv
, "perform radio reset.\n");
1705 iwl_internal_short_hw_scan(priv
);
1709 int iwl_force_reset(struct iwl_priv
*priv
, int mode
, bool external
)
1711 struct iwl_force_reset
*force_reset
;
1713 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1716 if (mode
>= IWL_MAX_FORCE_RESET
) {
1717 IWL_DEBUG_INFO(priv
, "invalid reset request.\n");
1720 force_reset
= &priv
->force_reset
[mode
];
1721 force_reset
->reset_request_count
++;
1723 if (force_reset
->last_force_reset_jiffies
&&
1724 time_after(force_reset
->last_force_reset_jiffies
+
1725 force_reset
->reset_duration
, jiffies
)) {
1726 IWL_DEBUG_INFO(priv
, "force reset rejected\n");
1727 force_reset
->reset_reject_count
++;
1731 force_reset
->reset_success_count
++;
1732 force_reset
->last_force_reset_jiffies
= jiffies
;
1733 IWL_DEBUG_INFO(priv
, "perform force reset (%d)\n", mode
);
1736 iwl_force_rf_reset(priv
);
1740 * if the request is from external(ex: debugfs),
1741 * then always perform the request in regardless the module
1743 * if the request is from internal (uCode error or driver
1744 * detect failure), then fw_restart module parameter
1745 * need to be check before performing firmware reload
1747 if (!external
&& !iwlagn_mod_params
.restart_fw
) {
1748 IWL_DEBUG_INFO(priv
, "Cancel firmware reload based on "
1749 "module parameter setting\n");
1752 IWL_ERR(priv
, "On demand firmware reload\n");
1753 iwlagn_fw_error(priv
, true);
1759 int iwl_mac_change_interface(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
,
1760 enum nl80211_iftype newtype
, bool newp2p
)
1762 struct iwl_priv
*priv
= hw
->priv
;
1763 struct iwl_rxon_context
*ctx
= iwl_rxon_ctx_from_vif(vif
);
1764 struct iwl_rxon_context
*bss_ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
1765 struct iwl_rxon_context
*tmp
;
1766 u32 interface_modes
;
1769 newtype
= ieee80211_iftype_p2p(newtype
, newp2p
);
1771 mutex_lock(&priv
->mutex
);
1773 if (!ctx
->vif
|| !iwl_is_ready_rf(priv
)) {
1775 * Huh? But wait ... this can maybe happen when
1776 * we're in the middle of a firmware restart!
1782 interface_modes
= ctx
->interface_modes
| ctx
->exclusive_interface_modes
;
1784 if (!(interface_modes
& BIT(newtype
))) {
1790 * Refuse a change that should be done by moving from the PAN
1791 * context to the BSS context instead, if the BSS context is
1792 * available and can support the new interface type.
1794 if (ctx
->ctxid
== IWL_RXON_CTX_PAN
&& !bss_ctx
->vif
&&
1795 (bss_ctx
->interface_modes
& BIT(newtype
) ||
1796 bss_ctx
->exclusive_interface_modes
& BIT(newtype
))) {
1797 BUILD_BUG_ON(NUM_IWL_RXON_CTX
!= 2);
1802 if (ctx
->exclusive_interface_modes
& BIT(newtype
)) {
1803 for_each_context(priv
, tmp
) {
1811 * The current mode switch would be exclusive, but
1812 * another context is active ... refuse the switch.
1820 iwl_teardown_interface(priv
, vif
, true);
1821 vif
->type
= newtype
;
1823 err
= iwl_setup_interface(priv
, ctx
);
1826 * We've switched internally, but submitting to the
1827 * device may have failed for some reason. Mask this
1828 * error, because otherwise mac80211 will not switch
1829 * (and set the interface type back) and we'll be
1830 * out of sync with it.
1835 mutex_unlock(&priv
->mutex
);
1840 * On every watchdog tick we check (latest) time stamp. If it does not
1841 * change during timeout period and queue is not empty we reset firmware.
1843 static int iwl_check_stuck_queue(struct iwl_priv
*priv
, int cnt
)
1845 struct iwl_tx_queue
*txq
= &priv
->txq
[cnt
];
1846 struct iwl_queue
*q
= &txq
->q
;
1847 unsigned long timeout
;
1850 if (q
->read_ptr
== q
->write_ptr
) {
1851 txq
->time_stamp
= jiffies
;
1855 timeout
= txq
->time_stamp
+
1856 msecs_to_jiffies(priv
->cfg
->base_params
->wd_timeout
);
1858 if (time_after(jiffies
, timeout
)) {
1859 IWL_ERR(priv
, "Queue %d stuck for %u ms.\n",
1860 q
->id
, priv
->cfg
->base_params
->wd_timeout
);
1861 ret
= iwl_force_reset(priv
, IWL_FW_RESET
, false);
1862 return (ret
== -EAGAIN
) ? 0 : 1;
1869 * Making watchdog tick be a quarter of timeout assure we will
1870 * discover the queue hung between timeout and 1.25*timeout
1872 #define IWL_WD_TICK(timeout) ((timeout) / 4)
1875 * Watchdog timer callback, we check each tx queue for stuck, if if hung
1876 * we reset the firmware. If everything is fine just rearm the timer.
1878 void iwl_bg_watchdog(unsigned long data
)
1880 struct iwl_priv
*priv
= (struct iwl_priv
*)data
;
1882 unsigned long timeout
;
1884 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1887 timeout
= priv
->cfg
->base_params
->wd_timeout
;
1891 /* monitor and check for stuck cmd queue */
1892 if (iwl_check_stuck_queue(priv
, priv
->cmd_queue
))
1895 /* monitor and check for other stuck queues */
1896 if (iwl_is_any_associated(priv
)) {
1897 for (cnt
= 0; cnt
< priv
->hw_params
.max_txq_num
; cnt
++) {
1898 /* skip as we already checked the command queue */
1899 if (cnt
== priv
->cmd_queue
)
1901 if (iwl_check_stuck_queue(priv
, cnt
))
1906 mod_timer(&priv
->watchdog
, jiffies
+
1907 msecs_to_jiffies(IWL_WD_TICK(timeout
)));
1910 void iwl_setup_watchdog(struct iwl_priv
*priv
)
1912 unsigned int timeout
= priv
->cfg
->base_params
->wd_timeout
;
1915 mod_timer(&priv
->watchdog
,
1916 jiffies
+ msecs_to_jiffies(IWL_WD_TICK(timeout
)));
1918 del_timer(&priv
->watchdog
);
1922 * extended beacon time format
1923 * time in usec will be changed into a 32-bit value in extended:internal format
1924 * the extended part is the beacon counts
1925 * the internal part is the time in usec within one beacon interval
1927 u32
iwl_usecs_to_beacons(struct iwl_priv
*priv
, u32 usec
, u32 beacon_interval
)
1931 u32 interval
= beacon_interval
* TIME_UNIT
;
1933 if (!interval
|| !usec
)
1936 quot
= (usec
/ interval
) &
1937 (iwl_beacon_time_mask_high(priv
,
1938 priv
->hw_params
.beacon_time_tsf_bits
) >>
1939 priv
->hw_params
.beacon_time_tsf_bits
);
1940 rem
= (usec
% interval
) & iwl_beacon_time_mask_low(priv
,
1941 priv
->hw_params
.beacon_time_tsf_bits
);
1943 return (quot
<< priv
->hw_params
.beacon_time_tsf_bits
) + rem
;
1946 /* base is usually what we get from ucode with each received frame,
1947 * the same as HW timer counter counting down
1949 __le32
iwl_add_beacon_time(struct iwl_priv
*priv
, u32 base
,
1950 u32 addon
, u32 beacon_interval
)
1952 u32 base_low
= base
& iwl_beacon_time_mask_low(priv
,
1953 priv
->hw_params
.beacon_time_tsf_bits
);
1954 u32 addon_low
= addon
& iwl_beacon_time_mask_low(priv
,
1955 priv
->hw_params
.beacon_time_tsf_bits
);
1956 u32 interval
= beacon_interval
* TIME_UNIT
;
1957 u32 res
= (base
& iwl_beacon_time_mask_high(priv
,
1958 priv
->hw_params
.beacon_time_tsf_bits
)) +
1959 (addon
& iwl_beacon_time_mask_high(priv
,
1960 priv
->hw_params
.beacon_time_tsf_bits
));
1962 if (base_low
> addon_low
)
1963 res
+= base_low
- addon_low
;
1964 else if (base_low
< addon_low
) {
1965 res
+= interval
+ base_low
- addon_low
;
1966 res
+= (1 << priv
->hw_params
.beacon_time_tsf_bits
);
1968 res
+= (1 << priv
->hw_params
.beacon_time_tsf_bits
);
1970 return cpu_to_le32(res
);
1975 int iwl_pci_suspend(struct device
*device
)
1977 struct pci_dev
*pdev
= to_pci_dev(device
);
1978 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
1981 * This function is called when system goes into suspend state
1982 * mac80211 will call iwl_mac_stop() from the mac80211 suspend function
1983 * first but since iwl_mac_stop() has no knowledge of who the caller is,
1984 * it will not call apm_ops.stop() to stop the DMA operation.
1985 * Calling apm_ops.stop here to make sure we stop the DMA.
1992 int iwl_pci_resume(struct device
*device
)
1994 struct pci_dev
*pdev
= to_pci_dev(device
);
1995 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
1996 bool hw_rfkill
= false;
1999 * We disable the RETRY_TIMEOUT register (0x41) to keep
2000 * PCI Tx retries from interfering with C3 CPU state.
2002 pci_write_config_byte(pdev
, PCI_CFG_RETRY_TIMEOUT
, 0x00);
2004 iwl_enable_interrupts(priv
);
2006 if (!(iwl_read32(priv
, CSR_GP_CNTRL
) &
2007 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
))
2011 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2013 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2015 wiphy_rfkill_set_hw_state(priv
->hw
->wiphy
, hw_rfkill
);
2020 const struct dev_pm_ops iwl_pm_ops
= {
2021 .suspend
= iwl_pci_suspend
,
2022 .resume
= iwl_pci_resume
,
2023 .freeze
= iwl_pci_suspend
,
2024 .thaw
= iwl_pci_resume
,
2025 .poweroff
= iwl_pci_suspend
,
2026 .restore
= iwl_pci_resume
,
2029 #endif /* CONFIG_PM */