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"
38 #include "iwl-debug.h"
41 #include "iwl-power.h"
43 #include "iwl-helpers.h"
46 MODULE_DESCRIPTION("iwl-legacy: common functions for 3945 and 4965");
47 MODULE_VERSION(IWLWIFI_VERSION
);
48 MODULE_AUTHOR(DRV_COPYRIGHT
" " DRV_AUTHOR
);
49 MODULE_LICENSE("GPL");
52 * set bt_coex_active to true, uCode will do kill/defer
53 * every time the priority line is asserted (BT is sending signals on the
54 * priority line in the PCIx).
55 * set bt_coex_active to false, uCode will ignore the BT activity and
56 * perform the normal operation
58 * User might experience transmit issue on some platform due to WiFi/BT
59 * co-exist problem. The possible behaviors are:
60 * Able to scan and finding all the available AP
61 * Not able to associate with any AP
62 * On those platforms, WiFi communication can be restored by set
63 * "bt_coex_active" module parameter to "false"
65 * default: bt_coex_active = true (BT_COEX_ENABLE)
67 static bool bt_coex_active
= true;
68 module_param(bt_coex_active
, bool, S_IRUGO
);
69 MODULE_PARM_DESC(bt_coex_active
, "enable wifi/bluetooth co-exist");
71 u32 iwlegacy_debug_level
;
72 EXPORT_SYMBOL(iwlegacy_debug_level
);
74 const u8 iwlegacy_bcast_addr
[ETH_ALEN
] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
75 EXPORT_SYMBOL(iwlegacy_bcast_addr
);
78 /* This function both allocates and initializes hw and priv. */
79 struct ieee80211_hw
*iwl_legacy_alloc_all(struct iwl_cfg
*cfg
)
81 struct iwl_priv
*priv
;
82 /* mac80211 allocates memory for this device instance, including
83 * space for this driver's private structure */
84 struct ieee80211_hw
*hw
;
86 hw
= ieee80211_alloc_hw(sizeof(struct iwl_priv
),
87 cfg
->ops
->ieee80211_ops
);
89 pr_err("%s: Can not allocate network device\n",
100 EXPORT_SYMBOL(iwl_legacy_alloc_all
);
102 #define MAX_BIT_RATE_40_MHZ 150 /* Mbps */
103 #define MAX_BIT_RATE_20_MHZ 72 /* Mbps */
104 static void iwl_legacy_init_ht_hw_capab(const struct iwl_priv
*priv
,
105 struct ieee80211_sta_ht_cap
*ht_info
,
106 enum ieee80211_band band
)
108 u16 max_bit_rate
= 0;
109 u8 rx_chains_num
= priv
->hw_params
.rx_chains_num
;
110 u8 tx_chains_num
= priv
->hw_params
.tx_chains_num
;
113 memset(&ht_info
->mcs
, 0, sizeof(ht_info
->mcs
));
115 ht_info
->ht_supported
= true;
117 ht_info
->cap
|= IEEE80211_HT_CAP_SGI_20
;
118 max_bit_rate
= MAX_BIT_RATE_20_MHZ
;
119 if (priv
->hw_params
.ht40_channel
& BIT(band
)) {
120 ht_info
->cap
|= IEEE80211_HT_CAP_SUP_WIDTH_20_40
;
121 ht_info
->cap
|= IEEE80211_HT_CAP_SGI_40
;
122 ht_info
->mcs
.rx_mask
[4] = 0x01;
123 max_bit_rate
= MAX_BIT_RATE_40_MHZ
;
126 if (priv
->cfg
->mod_params
->amsdu_size_8K
)
127 ht_info
->cap
|= IEEE80211_HT_CAP_MAX_AMSDU
;
129 ht_info
->ampdu_factor
= CFG_HT_RX_AMPDU_FACTOR_DEF
;
130 ht_info
->ampdu_density
= CFG_HT_MPDU_DENSITY_DEF
;
132 ht_info
->mcs
.rx_mask
[0] = 0xFF;
133 if (rx_chains_num
>= 2)
134 ht_info
->mcs
.rx_mask
[1] = 0xFF;
135 if (rx_chains_num
>= 3)
136 ht_info
->mcs
.rx_mask
[2] = 0xFF;
138 /* Highest supported Rx data rate */
139 max_bit_rate
*= rx_chains_num
;
140 WARN_ON(max_bit_rate
& ~IEEE80211_HT_MCS_RX_HIGHEST_MASK
);
141 ht_info
->mcs
.rx_highest
= cpu_to_le16(max_bit_rate
);
143 /* Tx MCS capabilities */
144 ht_info
->mcs
.tx_params
= IEEE80211_HT_MCS_TX_DEFINED
;
145 if (tx_chains_num
!= rx_chains_num
) {
146 ht_info
->mcs
.tx_params
|= IEEE80211_HT_MCS_TX_RX_DIFF
;
147 ht_info
->mcs
.tx_params
|= ((tx_chains_num
- 1) <<
148 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT
);
153 * iwl_legacy_init_geos - Initialize mac80211's geo/channel info based from eeprom
155 int iwl_legacy_init_geos(struct iwl_priv
*priv
)
157 struct iwl_channel_info
*ch
;
158 struct ieee80211_supported_band
*sband
;
159 struct ieee80211_channel
*channels
;
160 struct ieee80211_channel
*geo_ch
;
161 struct ieee80211_rate
*rates
;
165 if (priv
->bands
[IEEE80211_BAND_2GHZ
].n_bitrates
||
166 priv
->bands
[IEEE80211_BAND_5GHZ
].n_bitrates
) {
167 IWL_DEBUG_INFO(priv
, "Geography modes already initialized.\n");
168 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
172 channels
= kzalloc(sizeof(struct ieee80211_channel
) *
173 priv
->channel_count
, GFP_KERNEL
);
177 rates
= kzalloc((sizeof(struct ieee80211_rate
) * IWL_RATE_COUNT_LEGACY
),
184 /* 5.2GHz channels start after the 2.4GHz channels */
185 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
186 sband
->channels
= &channels
[ARRAY_SIZE(iwlegacy_eeprom_band_1
)];
188 sband
->bitrates
= &rates
[IWL_FIRST_OFDM_RATE
];
189 sband
->n_bitrates
= IWL_RATE_COUNT_LEGACY
- IWL_FIRST_OFDM_RATE
;
191 if (priv
->cfg
->sku
& IWL_SKU_N
)
192 iwl_legacy_init_ht_hw_capab(priv
, &sband
->ht_cap
,
193 IEEE80211_BAND_5GHZ
);
195 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
196 sband
->channels
= channels
;
198 sband
->bitrates
= rates
;
199 sband
->n_bitrates
= IWL_RATE_COUNT_LEGACY
;
201 if (priv
->cfg
->sku
& IWL_SKU_N
)
202 iwl_legacy_init_ht_hw_capab(priv
, &sband
->ht_cap
,
203 IEEE80211_BAND_2GHZ
);
205 priv
->ieee_channels
= channels
;
206 priv
->ieee_rates
= rates
;
208 for (i
= 0; i
< priv
->channel_count
; i
++) {
209 ch
= &priv
->channel_info
[i
];
211 if (!iwl_legacy_is_channel_valid(ch
))
214 if (iwl_legacy_is_channel_a_band(ch
))
215 sband
= &priv
->bands
[IEEE80211_BAND_5GHZ
];
217 sband
= &priv
->bands
[IEEE80211_BAND_2GHZ
];
219 geo_ch
= &sband
->channels
[sband
->n_channels
++];
221 geo_ch
->center_freq
=
222 ieee80211_channel_to_frequency(ch
->channel
, ch
->band
);
223 geo_ch
->max_power
= ch
->max_power_avg
;
224 geo_ch
->max_antenna_gain
= 0xff;
225 geo_ch
->hw_value
= ch
->channel
;
227 if (iwl_legacy_is_channel_valid(ch
)) {
228 if (!(ch
->flags
& EEPROM_CHANNEL_IBSS
))
229 geo_ch
->flags
|= IEEE80211_CHAN_NO_IBSS
;
231 if (!(ch
->flags
& EEPROM_CHANNEL_ACTIVE
))
232 geo_ch
->flags
|= IEEE80211_CHAN_PASSIVE_SCAN
;
234 if (ch
->flags
& EEPROM_CHANNEL_RADAR
)
235 geo_ch
->flags
|= IEEE80211_CHAN_RADAR
;
237 geo_ch
->flags
|= ch
->ht40_extension_channel
;
239 if (ch
->max_power_avg
> max_tx_power
)
240 max_tx_power
= ch
->max_power_avg
;
242 geo_ch
->flags
|= IEEE80211_CHAN_DISABLED
;
245 IWL_DEBUG_INFO(priv
, "Channel %d Freq=%d[%sGHz] %s flag=0x%X\n",
246 ch
->channel
, geo_ch
->center_freq
,
247 iwl_legacy_is_channel_a_band(ch
) ? "5.2" : "2.4",
248 geo_ch
->flags
& IEEE80211_CHAN_DISABLED
?
249 "restricted" : "valid",
253 priv
->tx_power_device_lmt
= max_tx_power
;
254 priv
->tx_power_user_lmt
= max_tx_power
;
255 priv
->tx_power_next
= max_tx_power
;
257 if ((priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
== 0) &&
258 priv
->cfg
->sku
& IWL_SKU_A
) {
259 IWL_INFO(priv
, "Incorrectly detected BG card as ABG. "
260 "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
261 priv
->pci_dev
->device
,
262 priv
->pci_dev
->subsystem_device
);
263 priv
->cfg
->sku
&= ~IWL_SKU_A
;
266 IWL_INFO(priv
, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
267 priv
->bands
[IEEE80211_BAND_2GHZ
].n_channels
,
268 priv
->bands
[IEEE80211_BAND_5GHZ
].n_channels
);
270 set_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
274 EXPORT_SYMBOL(iwl_legacy_init_geos
);
277 * iwl_legacy_free_geos - undo allocations in iwl_legacy_init_geos
279 void iwl_legacy_free_geos(struct iwl_priv
*priv
)
281 kfree(priv
->ieee_channels
);
282 kfree(priv
->ieee_rates
);
283 clear_bit(STATUS_GEO_CONFIGURED
, &priv
->status
);
285 EXPORT_SYMBOL(iwl_legacy_free_geos
);
287 static bool iwl_legacy_is_channel_extension(struct iwl_priv
*priv
,
288 enum ieee80211_band band
,
289 u16 channel
, u8 extension_chan_offset
)
291 const struct iwl_channel_info
*ch_info
;
293 ch_info
= iwl_legacy_get_channel_info(priv
, band
, channel
);
294 if (!iwl_legacy_is_channel_valid(ch_info
))
297 if (extension_chan_offset
== IEEE80211_HT_PARAM_CHA_SEC_ABOVE
)
298 return !(ch_info
->ht40_extension_channel
&
299 IEEE80211_CHAN_NO_HT40PLUS
);
300 else if (extension_chan_offset
== IEEE80211_HT_PARAM_CHA_SEC_BELOW
)
301 return !(ch_info
->ht40_extension_channel
&
302 IEEE80211_CHAN_NO_HT40MINUS
);
307 bool iwl_legacy_is_ht40_tx_allowed(struct iwl_priv
*priv
,
308 struct iwl_rxon_context
*ctx
,
309 struct ieee80211_sta_ht_cap
*ht_cap
)
311 if (!ctx
->ht
.enabled
|| !ctx
->ht
.is_40mhz
)
315 * We do not check for IEEE80211_HT_CAP_SUP_WIDTH_20_40
316 * the bit will not set if it is pure 40MHz case
318 if (ht_cap
&& !ht_cap
->ht_supported
)
321 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUGFS
322 if (priv
->disable_ht40
)
326 return iwl_legacy_is_channel_extension(priv
, priv
->band
,
327 le16_to_cpu(ctx
->staging
.channel
),
328 ctx
->ht
.extension_chan_offset
);
330 EXPORT_SYMBOL(iwl_legacy_is_ht40_tx_allowed
);
332 static u16
iwl_legacy_adjust_beacon_interval(u16 beacon_val
, u16 max_beacon_val
)
338 * If mac80211 hasn't given us a beacon interval, program
339 * the default into the device.
342 return DEFAULT_BEACON_INTERVAL
;
345 * If the beacon interval we obtained from the peer
346 * is too large, we'll have to wake up more often
347 * (and in IBSS case, we'll beacon too much)
349 * For example, if max_beacon_val is 4096, and the
350 * requested beacon interval is 7000, we'll have to
351 * use 3500 to be able to wake up on the beacons.
353 * This could badly influence beacon detection stats.
356 beacon_factor
= (beacon_val
+ max_beacon_val
) / max_beacon_val
;
357 new_val
= beacon_val
/ beacon_factor
;
360 new_val
= max_beacon_val
;
366 iwl_legacy_send_rxon_timing(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
369 s32 interval_tm
, rem
;
370 struct ieee80211_conf
*conf
= NULL
;
372 struct ieee80211_vif
*vif
= ctx
->vif
;
374 conf
= iwl_legacy_ieee80211_get_hw_conf(priv
->hw
);
376 lockdep_assert_held(&priv
->mutex
);
378 memset(&ctx
->timing
, 0, sizeof(struct iwl_rxon_time_cmd
));
380 ctx
->timing
.timestamp
= cpu_to_le64(priv
->timestamp
);
381 ctx
->timing
.listen_interval
= cpu_to_le16(conf
->listen_interval
);
383 beacon_int
= vif
? vif
->bss_conf
.beacon_int
: 0;
386 * TODO: For IBSS we need to get atim_window from mac80211,
387 * for now just always use 0
389 ctx
->timing
.atim_window
= 0;
391 beacon_int
= iwl_legacy_adjust_beacon_interval(beacon_int
,
392 priv
->hw_params
.max_beacon_itrvl
* TIME_UNIT
);
393 ctx
->timing
.beacon_interval
= cpu_to_le16(beacon_int
);
395 tsf
= priv
->timestamp
; /* tsf is modifed by do_div: copy it */
396 interval_tm
= beacon_int
* TIME_UNIT
;
397 rem
= do_div(tsf
, interval_tm
);
398 ctx
->timing
.beacon_init_val
= cpu_to_le32(interval_tm
- rem
);
400 ctx
->timing
.dtim_period
= vif
? (vif
->bss_conf
.dtim_period
?: 1) : 1;
402 IWL_DEBUG_ASSOC(priv
,
403 "beacon interval %d beacon timer %d beacon tim %d\n",
404 le16_to_cpu(ctx
->timing
.beacon_interval
),
405 le32_to_cpu(ctx
->timing
.beacon_init_val
),
406 le16_to_cpu(ctx
->timing
.atim_window
));
408 return iwl_legacy_send_cmd_pdu(priv
, ctx
->rxon_timing_cmd
,
409 sizeof(ctx
->timing
), &ctx
->timing
);
411 EXPORT_SYMBOL(iwl_legacy_send_rxon_timing
);
414 iwl_legacy_set_rxon_hwcrypto(struct iwl_priv
*priv
,
415 struct iwl_rxon_context
*ctx
,
418 struct iwl_legacy_rxon_cmd
*rxon
= &ctx
->staging
;
421 rxon
->filter_flags
&= ~RXON_FILTER_DIS_DECRYPT_MSK
;
423 rxon
->filter_flags
|= RXON_FILTER_DIS_DECRYPT_MSK
;
426 EXPORT_SYMBOL(iwl_legacy_set_rxon_hwcrypto
);
428 /* validate RXON structure is valid */
430 iwl_legacy_check_rxon_cmd(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
432 struct iwl_legacy_rxon_cmd
*rxon
= &ctx
->staging
;
435 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
436 if (rxon
->flags
& RXON_FLG_TGJ_NARROW_BAND_MSK
) {
437 IWL_WARN(priv
, "check 2.4G: wrong narrow\n");
440 if (rxon
->flags
& RXON_FLG_RADAR_DETECT_MSK
) {
441 IWL_WARN(priv
, "check 2.4G: wrong radar\n");
445 if (!(rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
)) {
446 IWL_WARN(priv
, "check 5.2G: not short slot!\n");
449 if (rxon
->flags
& RXON_FLG_CCK_MSK
) {
450 IWL_WARN(priv
, "check 5.2G: CCK!\n");
454 if ((rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1) {
455 IWL_WARN(priv
, "mac/bssid mcast!\n");
459 /* make sure basic rates 6Mbps and 1Mbps are supported */
460 if ((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0 &&
461 (rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0) {
462 IWL_WARN(priv
, "neither 1 nor 6 are basic\n");
466 if (le16_to_cpu(rxon
->assoc_id
) > 2007) {
467 IWL_WARN(priv
, "aid > 2007\n");
471 if ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
472 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
)) {
473 IWL_WARN(priv
, "CCK and short slot\n");
477 if ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
478 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
)) {
479 IWL_WARN(priv
, "CCK and auto detect");
483 if ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
484 RXON_FLG_TGG_PROTECT_MSK
)) ==
485 RXON_FLG_TGG_PROTECT_MSK
) {
486 IWL_WARN(priv
, "TGg but no auto-detect\n");
491 IWL_WARN(priv
, "Tuning to channel %d\n",
492 le16_to_cpu(rxon
->channel
));
495 IWL_ERR(priv
, "Invalid RXON\n");
500 EXPORT_SYMBOL(iwl_legacy_check_rxon_cmd
);
503 * iwl_legacy_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
504 * @priv: staging_rxon is compared to active_rxon
506 * If the RXON structure is changing enough to require a new tune,
507 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
508 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
510 int iwl_legacy_full_rxon_required(struct iwl_priv
*priv
,
511 struct iwl_rxon_context
*ctx
)
513 const struct iwl_legacy_rxon_cmd
*staging
= &ctx
->staging
;
514 const struct iwl_legacy_rxon_cmd
*active
= &ctx
->active
;
518 IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
522 #define CHK_NEQ(c1, c2) \
523 if ((c1) != (c2)) { \
524 IWL_DEBUG_INFO(priv, "need full RXON - " \
525 #c1 " != " #c2 " - %d != %d\n", \
530 /* These items are only settable from the full RXON command */
531 CHK(!iwl_legacy_is_associated_ctx(ctx
));
532 CHK(compare_ether_addr(staging
->bssid_addr
, active
->bssid_addr
));
533 CHK(compare_ether_addr(staging
->node_addr
, active
->node_addr
));
534 CHK(compare_ether_addr(staging
->wlap_bssid_addr
,
535 active
->wlap_bssid_addr
));
536 CHK_NEQ(staging
->dev_type
, active
->dev_type
);
537 CHK_NEQ(staging
->channel
, active
->channel
);
538 CHK_NEQ(staging
->air_propagation
, active
->air_propagation
);
539 CHK_NEQ(staging
->ofdm_ht_single_stream_basic_rates
,
540 active
->ofdm_ht_single_stream_basic_rates
);
541 CHK_NEQ(staging
->ofdm_ht_dual_stream_basic_rates
,
542 active
->ofdm_ht_dual_stream_basic_rates
);
543 CHK_NEQ(staging
->assoc_id
, active
->assoc_id
);
545 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
546 * be updated with the RXON_ASSOC command -- however only some
547 * flag transitions are allowed using RXON_ASSOC */
549 /* Check if we are not switching bands */
550 CHK_NEQ(staging
->flags
& RXON_FLG_BAND_24G_MSK
,
551 active
->flags
& RXON_FLG_BAND_24G_MSK
);
553 /* Check if we are switching association toggle */
554 CHK_NEQ(staging
->filter_flags
& RXON_FILTER_ASSOC_MSK
,
555 active
->filter_flags
& RXON_FILTER_ASSOC_MSK
);
562 EXPORT_SYMBOL(iwl_legacy_full_rxon_required
);
564 u8
iwl_legacy_get_lowest_plcp(struct iwl_priv
*priv
,
565 struct iwl_rxon_context
*ctx
)
568 * Assign the lowest rate -- should really get this from
569 * the beacon skb from mac80211.
571 if (ctx
->staging
.flags
& RXON_FLG_BAND_24G_MSK
)
572 return IWL_RATE_1M_PLCP
;
574 return IWL_RATE_6M_PLCP
;
576 EXPORT_SYMBOL(iwl_legacy_get_lowest_plcp
);
578 static void _iwl_legacy_set_rxon_ht(struct iwl_priv
*priv
,
579 struct iwl_ht_config
*ht_conf
,
580 struct iwl_rxon_context
*ctx
)
582 struct iwl_legacy_rxon_cmd
*rxon
= &ctx
->staging
;
584 if (!ctx
->ht
.enabled
) {
585 rxon
->flags
&= ~(RXON_FLG_CHANNEL_MODE_MSK
|
586 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
|
587 RXON_FLG_HT40_PROT_MSK
|
588 RXON_FLG_HT_PROT_MSK
);
592 rxon
->flags
|= cpu_to_le32(ctx
->ht
.protection
<<
593 RXON_FLG_HT_OPERATING_MODE_POS
);
595 /* Set up channel bandwidth:
596 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
597 /* clear the HT channel mode before set the mode */
598 rxon
->flags
&= ~(RXON_FLG_CHANNEL_MODE_MSK
|
599 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
);
600 if (iwl_legacy_is_ht40_tx_allowed(priv
, ctx
, NULL
)) {
602 if (ctx
->ht
.protection
==
603 IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
) {
604 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_PURE_40
;
605 /* Note: control channel is opposite of extension channel */
606 switch (ctx
->ht
.extension_chan_offset
) {
607 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE
:
609 ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
;
611 case IEEE80211_HT_PARAM_CHA_SEC_BELOW
:
613 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
;
617 /* Note: control channel is opposite of extension channel */
618 switch (ctx
->ht
.extension_chan_offset
) {
619 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE
:
621 ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
);
622 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_MIXED
;
624 case IEEE80211_HT_PARAM_CHA_SEC_BELOW
:
626 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
;
627 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_MIXED
;
629 case IEEE80211_HT_PARAM_CHA_SEC_NONE
:
631 /* channel location only valid if in Mixed mode */
633 "invalid extension channel offset\n");
638 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_LEGACY
;
641 if (priv
->cfg
->ops
->hcmd
->set_rxon_chain
)
642 priv
->cfg
->ops
->hcmd
->set_rxon_chain(priv
, ctx
);
644 IWL_DEBUG_ASSOC(priv
, "rxon flags 0x%X operation mode :0x%X "
645 "extension channel offset 0x%x\n",
646 le32_to_cpu(rxon
->flags
), ctx
->ht
.protection
,
647 ctx
->ht
.extension_chan_offset
);
650 void iwl_legacy_set_rxon_ht(struct iwl_priv
*priv
, struct iwl_ht_config
*ht_conf
)
652 struct iwl_rxon_context
*ctx
;
654 for_each_context(priv
, ctx
)
655 _iwl_legacy_set_rxon_ht(priv
, ht_conf
, ctx
);
657 EXPORT_SYMBOL(iwl_legacy_set_rxon_ht
);
659 /* Return valid, unused, channel for a passive scan to reset the RF */
660 u8
iwl_legacy_get_single_channel_number(struct iwl_priv
*priv
,
661 enum ieee80211_band band
)
663 const struct iwl_channel_info
*ch_info
;
667 struct iwl_rxon_context
*ctx
;
669 if (band
== IEEE80211_BAND_5GHZ
) {
671 max
= priv
->channel_count
;
677 for (i
= min
; i
< max
; i
++) {
680 for_each_context(priv
, ctx
) {
681 busy
= priv
->channel_info
[i
].channel
==
682 le16_to_cpu(ctx
->staging
.channel
);
690 channel
= priv
->channel_info
[i
].channel
;
691 ch_info
= iwl_legacy_get_channel_info(priv
, band
, channel
);
692 if (iwl_legacy_is_channel_valid(ch_info
))
698 EXPORT_SYMBOL(iwl_legacy_get_single_channel_number
);
701 * iwl_legacy_set_rxon_channel - Set the band and channel values in staging RXON
702 * @ch: requested channel as a pointer to struct ieee80211_channel
704 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
705 * in the staging RXON flag structure based on the ch->band
708 iwl_legacy_set_rxon_channel(struct iwl_priv
*priv
, struct ieee80211_channel
*ch
,
709 struct iwl_rxon_context
*ctx
)
711 enum ieee80211_band band
= ch
->band
;
712 u16 channel
= ch
->hw_value
;
714 if ((le16_to_cpu(ctx
->staging
.channel
) == channel
) &&
715 (priv
->band
== band
))
718 ctx
->staging
.channel
= cpu_to_le16(channel
);
719 if (band
== IEEE80211_BAND_5GHZ
)
720 ctx
->staging
.flags
&= ~RXON_FLG_BAND_24G_MSK
;
722 ctx
->staging
.flags
|= RXON_FLG_BAND_24G_MSK
;
726 IWL_DEBUG_INFO(priv
, "Staging channel set to %d [%d]\n", channel
, band
);
730 EXPORT_SYMBOL(iwl_legacy_set_rxon_channel
);
732 void iwl_legacy_set_flags_for_band(struct iwl_priv
*priv
,
733 struct iwl_rxon_context
*ctx
,
734 enum ieee80211_band band
,
735 struct ieee80211_vif
*vif
)
737 if (band
== IEEE80211_BAND_5GHZ
) {
738 ctx
->staging
.flags
&=
739 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
741 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
743 /* Copied from iwl_post_associate() */
744 if (vif
&& vif
->bss_conf
.use_short_slot
)
745 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
747 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
749 ctx
->staging
.flags
|= RXON_FLG_BAND_24G_MSK
;
750 ctx
->staging
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
751 ctx
->staging
.flags
&= ~RXON_FLG_CCK_MSK
;
754 EXPORT_SYMBOL(iwl_legacy_set_flags_for_band
);
757 * initialize rxon structure with default values from eeprom
759 void iwl_legacy_connection_init_rx_config(struct iwl_priv
*priv
,
760 struct iwl_rxon_context
*ctx
)
762 const struct iwl_channel_info
*ch_info
;
764 memset(&ctx
->staging
, 0, sizeof(ctx
->staging
));
767 ctx
->staging
.dev_type
= ctx
->unused_devtype
;
769 switch (ctx
->vif
->type
) {
771 case NL80211_IFTYPE_STATION
:
772 ctx
->staging
.dev_type
= ctx
->station_devtype
;
773 ctx
->staging
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
776 case NL80211_IFTYPE_ADHOC
:
777 ctx
->staging
.dev_type
= ctx
->ibss_devtype
;
778 ctx
->staging
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
779 ctx
->staging
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
780 RXON_FILTER_ACCEPT_GRP_MSK
;
784 IWL_ERR(priv
, "Unsupported interface type %d\n",
790 /* TODO: Figure out when short_preamble would be set and cache from
792 if (!hw_to_local(priv
->hw
)->short_preamble
)
793 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
795 ctx
->staging
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
798 ch_info
= iwl_legacy_get_channel_info(priv
, priv
->band
,
799 le16_to_cpu(ctx
->active
.channel
));
802 ch_info
= &priv
->channel_info
[0];
804 ctx
->staging
.channel
= cpu_to_le16(ch_info
->channel
);
805 priv
->band
= ch_info
->band
;
807 iwl_legacy_set_flags_for_band(priv
, ctx
, priv
->band
, ctx
->vif
);
809 ctx
->staging
.ofdm_basic_rates
=
810 (IWL_OFDM_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
811 ctx
->staging
.cck_basic_rates
=
812 (IWL_CCK_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
814 /* clear both MIX and PURE40 mode flag */
815 ctx
->staging
.flags
&= ~(RXON_FLG_CHANNEL_MODE_MIXED
|
816 RXON_FLG_CHANNEL_MODE_PURE_40
);
818 memcpy(ctx
->staging
.node_addr
, ctx
->vif
->addr
, ETH_ALEN
);
820 ctx
->staging
.ofdm_ht_single_stream_basic_rates
= 0xff;
821 ctx
->staging
.ofdm_ht_dual_stream_basic_rates
= 0xff;
823 EXPORT_SYMBOL(iwl_legacy_connection_init_rx_config
);
825 void iwl_legacy_set_rate(struct iwl_priv
*priv
)
827 const struct ieee80211_supported_band
*hw
= NULL
;
828 struct ieee80211_rate
*rate
;
829 struct iwl_rxon_context
*ctx
;
832 hw
= iwl_get_hw_mode(priv
, priv
->band
);
834 IWL_ERR(priv
, "Failed to set rate: unable to get hw mode\n");
838 priv
->active_rate
= 0;
840 for (i
= 0; i
< hw
->n_bitrates
; i
++) {
841 rate
= &(hw
->bitrates
[i
]);
842 if (rate
->hw_value
< IWL_RATE_COUNT_LEGACY
)
843 priv
->active_rate
|= (1 << rate
->hw_value
);
846 IWL_DEBUG_RATE(priv
, "Set active_rate = %0x\n", priv
->active_rate
);
848 for_each_context(priv
, ctx
) {
849 ctx
->staging
.cck_basic_rates
=
850 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
852 ctx
->staging
.ofdm_basic_rates
=
853 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
856 EXPORT_SYMBOL(iwl_legacy_set_rate
);
858 void iwl_legacy_chswitch_done(struct iwl_priv
*priv
, bool is_success
)
860 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
862 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
865 if (priv
->switch_rxon
.switch_in_progress
) {
866 ieee80211_chswitch_done(ctx
->vif
, is_success
);
867 mutex_lock(&priv
->mutex
);
868 priv
->switch_rxon
.switch_in_progress
= false;
869 mutex_unlock(&priv
->mutex
);
872 EXPORT_SYMBOL(iwl_legacy_chswitch_done
);
874 void iwl_legacy_rx_csa(struct iwl_priv
*priv
, struct iwl_rx_mem_buffer
*rxb
)
876 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
877 struct iwl_csa_notification
*csa
= &(pkt
->u
.csa_notif
);
879 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
880 struct iwl_legacy_rxon_cmd
*rxon
= (void *)&ctx
->active
;
882 if (priv
->switch_rxon
.switch_in_progress
) {
883 if (!le32_to_cpu(csa
->status
) &&
884 (csa
->channel
== priv
->switch_rxon
.channel
)) {
885 rxon
->channel
= csa
->channel
;
886 ctx
->staging
.channel
= csa
->channel
;
887 IWL_DEBUG_11H(priv
, "CSA notif: channel %d\n",
888 le16_to_cpu(csa
->channel
));
889 iwl_legacy_chswitch_done(priv
, true);
891 IWL_ERR(priv
, "CSA notif (fail) : channel %d\n",
892 le16_to_cpu(csa
->channel
));
893 iwl_legacy_chswitch_done(priv
, false);
897 EXPORT_SYMBOL(iwl_legacy_rx_csa
);
899 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
900 void iwl_legacy_print_rx_config_cmd(struct iwl_priv
*priv
,
901 struct iwl_rxon_context
*ctx
)
903 struct iwl_legacy_rxon_cmd
*rxon
= &ctx
->staging
;
905 IWL_DEBUG_RADIO(priv
, "RX CONFIG:\n");
906 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
907 IWL_DEBUG_RADIO(priv
, "u16 channel: 0x%x\n",
908 le16_to_cpu(rxon
->channel
));
909 IWL_DEBUG_RADIO(priv
, "u32 flags: 0x%08X\n", le32_to_cpu(rxon
->flags
));
910 IWL_DEBUG_RADIO(priv
, "u32 filter_flags: 0x%08x\n",
911 le32_to_cpu(rxon
->filter_flags
));
912 IWL_DEBUG_RADIO(priv
, "u8 dev_type: 0x%x\n", rxon
->dev_type
);
913 IWL_DEBUG_RADIO(priv
, "u8 ofdm_basic_rates: 0x%02x\n",
914 rxon
->ofdm_basic_rates
);
915 IWL_DEBUG_RADIO(priv
, "u8 cck_basic_rates: 0x%02x\n",
916 rxon
->cck_basic_rates
);
917 IWL_DEBUG_RADIO(priv
, "u8[6] node_addr: %pM\n", rxon
->node_addr
);
918 IWL_DEBUG_RADIO(priv
, "u8[6] bssid_addr: %pM\n", rxon
->bssid_addr
);
919 IWL_DEBUG_RADIO(priv
, "u16 assoc_id: 0x%x\n",
920 le16_to_cpu(rxon
->assoc_id
));
922 EXPORT_SYMBOL(iwl_legacy_print_rx_config_cmd
);
925 * iwl_legacy_irq_handle_error - called for HW or SW error interrupt from card
927 void iwl_legacy_irq_handle_error(struct iwl_priv
*priv
)
929 /* Set the FW error flag -- cleared on iwl_down */
930 set_bit(STATUS_FW_ERROR
, &priv
->status
);
932 /* Cancel currently queued command. */
933 clear_bit(STATUS_HCMD_ACTIVE
, &priv
->status
);
935 IWL_ERR(priv
, "Loaded firmware version: %s\n",
936 priv
->hw
->wiphy
->fw_version
);
938 priv
->cfg
->ops
->lib
->dump_nic_error_log(priv
);
939 if (priv
->cfg
->ops
->lib
->dump_fh
)
940 priv
->cfg
->ops
->lib
->dump_fh(priv
, NULL
, false);
941 priv
->cfg
->ops
->lib
->dump_nic_event_log(priv
, false, NULL
, false);
942 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
943 if (iwl_legacy_get_debug_level(priv
) & IWL_DL_FW_ERRORS
)
944 iwl_legacy_print_rx_config_cmd(priv
,
945 &priv
->contexts
[IWL_RXON_CTX_BSS
]);
948 wake_up_interruptible(&priv
->wait_command_queue
);
950 /* Keep the restart process from trying to send host
951 * commands by clearing the INIT status bit */
952 clear_bit(STATUS_READY
, &priv
->status
);
954 if (!test_bit(STATUS_EXIT_PENDING
, &priv
->status
)) {
955 IWL_DEBUG(priv
, IWL_DL_FW_ERRORS
,
956 "Restarting adapter due to uCode error.\n");
958 if (priv
->cfg
->mod_params
->restart_fw
)
959 queue_work(priv
->workqueue
, &priv
->restart
);
962 EXPORT_SYMBOL(iwl_legacy_irq_handle_error
);
964 static int iwl_legacy_apm_stop_master(struct iwl_priv
*priv
)
968 /* stop device's busmaster DMA activity */
969 iwl_legacy_set_bit(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_STOP_MASTER
);
971 ret
= iwl_poll_bit(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_MASTER_DISABLED
,
972 CSR_RESET_REG_FLAG_MASTER_DISABLED
, 100);
974 IWL_WARN(priv
, "Master Disable Timed Out, 100 usec\n");
976 IWL_DEBUG_INFO(priv
, "stop master\n");
981 void iwl_legacy_apm_stop(struct iwl_priv
*priv
)
983 IWL_DEBUG_INFO(priv
, "Stop card, put in low power state\n");
985 /* Stop device's DMA activity */
986 iwl_legacy_apm_stop_master(priv
);
988 /* Reset the entire device */
989 iwl_legacy_set_bit(priv
, CSR_RESET
, CSR_RESET_REG_FLAG_SW_RESET
);
994 * Clear "initialization complete" bit to move adapter from
995 * D0A* (powered-up Active) --> D0U* (Uninitialized) state.
997 iwl_legacy_clear_bit(priv
, CSR_GP_CNTRL
,
998 CSR_GP_CNTRL_REG_FLAG_INIT_DONE
);
1000 EXPORT_SYMBOL(iwl_legacy_apm_stop
);
1004 * Start up NIC's basic functionality after it has been reset
1005 * (e.g. after platform boot, or shutdown via iwl_legacy_apm_stop())
1006 * NOTE: This does not load uCode nor start the embedded processor
1008 int iwl_legacy_apm_init(struct iwl_priv
*priv
)
1013 IWL_DEBUG_INFO(priv
, "Init card's basic functions\n");
1016 * Use "set_bit" below rather than "write", to preserve any hardware
1017 * bits already set by default after reset.
1020 /* Disable L0S exit timer (platform NMI Work/Around) */
1021 iwl_legacy_set_bit(priv
, CSR_GIO_CHICKEN_BITS
,
1022 CSR_GIO_CHICKEN_BITS_REG_BIT_DIS_L0S_EXIT_TIMER
);
1025 * Disable L0s without affecting L1;
1026 * don't wait for ICH L0s (ICH bug W/A)
1028 iwl_legacy_set_bit(priv
, CSR_GIO_CHICKEN_BITS
,
1029 CSR_GIO_CHICKEN_BITS_REG_BIT_L1A_NO_L0S_RX
);
1031 /* Set FH wait threshold to maximum (HW error during stress W/A) */
1032 iwl_legacy_set_bit(priv
, CSR_DBG_HPET_MEM_REG
,
1033 CSR_DBG_HPET_MEM_REG_VAL
);
1036 * Enable HAP INTA (interrupt from management bus) to
1037 * wake device's PCI Express link L1a -> L0s
1038 * NOTE: This is no-op for 3945 (non-existent bit)
1040 iwl_legacy_set_bit(priv
, CSR_HW_IF_CONFIG_REG
,
1041 CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A
);
1044 * HW bug W/A for instability in PCIe bus L0->L0S->L1 transition.
1045 * Check if BIOS (or OS) enabled L1-ASPM on this device.
1046 * If so (likely), disable L0S, so device moves directly L0->L1;
1047 * costs negligible amount of power savings.
1048 * If not (unlikely), enable L0S, so there is at least some
1049 * power savings, even without L1.
1051 if (priv
->cfg
->base_params
->set_l0s
) {
1052 lctl
= iwl_legacy_pcie_link_ctl(priv
);
1053 if ((lctl
& PCI_CFG_LINK_CTRL_VAL_L1_EN
) ==
1054 PCI_CFG_LINK_CTRL_VAL_L1_EN
) {
1055 /* L1-ASPM enabled; disable(!) L0S */
1056 iwl_legacy_set_bit(priv
, CSR_GIO_REG
,
1057 CSR_GIO_REG_VAL_L0S_ENABLED
);
1058 IWL_DEBUG_POWER(priv
, "L1 Enabled; Disabling L0S\n");
1060 /* L1-ASPM disabled; enable(!) L0S */
1061 iwl_legacy_clear_bit(priv
, CSR_GIO_REG
,
1062 CSR_GIO_REG_VAL_L0S_ENABLED
);
1063 IWL_DEBUG_POWER(priv
, "L1 Disabled; Enabling L0S\n");
1067 /* Configure analog phase-lock-loop before activating to D0A */
1068 if (priv
->cfg
->base_params
->pll_cfg_val
)
1069 iwl_legacy_set_bit(priv
, CSR_ANA_PLL_CFG
,
1070 priv
->cfg
->base_params
->pll_cfg_val
);
1073 * Set "initialization complete" bit to move adapter from
1074 * D0U* --> D0A* (powered-up active) state.
1076 iwl_legacy_set_bit(priv
, CSR_GP_CNTRL
, CSR_GP_CNTRL_REG_FLAG_INIT_DONE
);
1079 * Wait for clock stabilization; once stabilized, access to
1080 * device-internal resources is supported, e.g. iwl_legacy_write_prph()
1081 * and accesses to uCode SRAM.
1083 ret
= iwl_poll_bit(priv
, CSR_GP_CNTRL
,
1084 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
,
1085 CSR_GP_CNTRL_REG_FLAG_MAC_CLOCK_READY
, 25000);
1087 IWL_DEBUG_INFO(priv
, "Failed to init the card\n");
1092 * Enable DMA and BSM (if used) clocks, wait for them to stabilize.
1093 * BSM (Boostrap State Machine) is only in 3945 and 4965.
1095 * Write to "CLK_EN_REG"; "1" bits enable clocks, while "0" bits
1096 * do not disable clocks. This preserves any hardware bits already
1097 * set by default in "CLK_CTRL_REG" after reset.
1099 if (priv
->cfg
->base_params
->use_bsm
)
1100 iwl_legacy_write_prph(priv
, APMG_CLK_EN_REG
,
1101 APMG_CLK_VAL_DMA_CLK_RQT
| APMG_CLK_VAL_BSM_CLK_RQT
);
1103 iwl_legacy_write_prph(priv
, APMG_CLK_EN_REG
,
1104 APMG_CLK_VAL_DMA_CLK_RQT
);
1107 /* Disable L1-Active */
1108 iwl_legacy_set_bits_prph(priv
, APMG_PCIDEV_STT_REG
,
1109 APMG_PCIDEV_STT_VAL_L1_ACT_DIS
);
1114 EXPORT_SYMBOL(iwl_legacy_apm_init
);
1117 int iwl_legacy_set_tx_power(struct iwl_priv
*priv
, s8 tx_power
, bool force
)
1122 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
1124 lockdep_assert_held(&priv
->mutex
);
1126 if (priv
->tx_power_user_lmt
== tx_power
&& !force
)
1129 if (!priv
->cfg
->ops
->lib
->send_tx_power
)
1132 /* 0 dBm mean 1 milliwatt */
1135 "Requested user TXPOWER %d below 1 mW.\n",
1140 if (tx_power
> priv
->tx_power_device_lmt
) {
1142 "Requested user TXPOWER %d above upper limit %d.\n",
1143 tx_power
, priv
->tx_power_device_lmt
);
1147 if (!iwl_legacy_is_ready_rf(priv
))
1150 /* scan complete and commit_rxon use tx_power_next value,
1151 * it always need to be updated for newest request */
1152 priv
->tx_power_next
= tx_power
;
1154 /* do not set tx power when scanning or channel changing */
1155 defer
= test_bit(STATUS_SCANNING
, &priv
->status
) ||
1156 memcmp(&ctx
->active
, &ctx
->staging
, sizeof(ctx
->staging
));
1157 if (defer
&& !force
) {
1158 IWL_DEBUG_INFO(priv
, "Deferring tx power set\n");
1162 prev_tx_power
= priv
->tx_power_user_lmt
;
1163 priv
->tx_power_user_lmt
= tx_power
;
1165 ret
= priv
->cfg
->ops
->lib
->send_tx_power(priv
);
1167 /* if fail to set tx_power, restore the orig. tx power */
1169 priv
->tx_power_user_lmt
= prev_tx_power
;
1170 priv
->tx_power_next
= prev_tx_power
;
1174 EXPORT_SYMBOL(iwl_legacy_set_tx_power
);
1176 void iwl_legacy_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 IWL_DEBUG_INFO(priv
, "BT coex %s\n",
1191 (bt_cmd
.flags
== BT_COEX_DISABLE
) ? "disable" : "active");
1193 if (iwl_legacy_send_cmd_pdu(priv
, REPLY_BT_CONFIG
,
1194 sizeof(struct iwl_bt_cmd
), &bt_cmd
))
1195 IWL_ERR(priv
, "failed to send BT Coex Config\n");
1197 EXPORT_SYMBOL(iwl_legacy_send_bt_config
);
1199 int iwl_legacy_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_legacy_send_cmd_pdu_async(priv
, REPLY_STATISTICS_CMD
,
1208 sizeof(struct iwl_statistics_cmd
),
1209 &statistics_cmd
, NULL
);
1211 return iwl_legacy_send_cmd_pdu(priv
, REPLY_STATISTICS_CMD
,
1212 sizeof(struct iwl_statistics_cmd
),
1215 EXPORT_SYMBOL(iwl_legacy_send_statistics_request
);
1217 void iwl_legacy_rx_pm_sleep_notif(struct iwl_priv
*priv
,
1218 struct iwl_rx_mem_buffer
*rxb
)
1220 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUG
1221 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1222 struct iwl_sleep_notification
*sleep
= &(pkt
->u
.sleep_notif
);
1223 IWL_DEBUG_RX(priv
, "sleep mode: %d, src: %d\n",
1224 sleep
->pm_sleep_mode
, sleep
->pm_wakeup_src
);
1227 EXPORT_SYMBOL(iwl_legacy_rx_pm_sleep_notif
);
1229 void iwl_legacy_rx_pm_debug_statistics_notif(struct iwl_priv
*priv
,
1230 struct iwl_rx_mem_buffer
*rxb
)
1232 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1233 u32 len
= le32_to_cpu(pkt
->len_n_flags
) & FH_RSCSR_FRAME_SIZE_MSK
;
1234 IWL_DEBUG_RADIO(priv
, "Dumping %d bytes of unhandled "
1235 "notification for %s:\n", len
,
1236 iwl_legacy_get_cmd_string(pkt
->hdr
.cmd
));
1237 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, pkt
->u
.raw
, len
);
1239 EXPORT_SYMBOL(iwl_legacy_rx_pm_debug_statistics_notif
);
1241 void iwl_legacy_rx_reply_error(struct iwl_priv
*priv
,
1242 struct iwl_rx_mem_buffer
*rxb
)
1244 struct iwl_rx_packet
*pkt
= rxb_addr(rxb
);
1246 IWL_ERR(priv
, "Error Reply type 0x%08X cmd %s (0x%02X) "
1247 "seq 0x%04X ser 0x%08X\n",
1248 le32_to_cpu(pkt
->u
.err_resp
.error_type
),
1249 iwl_legacy_get_cmd_string(pkt
->u
.err_resp
.cmd_id
),
1250 pkt
->u
.err_resp
.cmd_id
,
1251 le16_to_cpu(pkt
->u
.err_resp
.bad_cmd_seq_num
),
1252 le32_to_cpu(pkt
->u
.err_resp
.error_info
));
1254 EXPORT_SYMBOL(iwl_legacy_rx_reply_error
);
1256 void iwl_legacy_clear_isr_stats(struct iwl_priv
*priv
)
1258 memset(&priv
->isr_stats
, 0, sizeof(priv
->isr_stats
));
1261 int iwl_legacy_mac_conf_tx(struct ieee80211_hw
*hw
, u16 queue
,
1262 const struct ieee80211_tx_queue_params
*params
)
1264 struct iwl_priv
*priv
= hw
->priv
;
1265 struct iwl_rxon_context
*ctx
;
1266 unsigned long flags
;
1269 IWL_DEBUG_MAC80211(priv
, "enter\n");
1271 if (!iwl_legacy_is_ready_rf(priv
)) {
1272 IWL_DEBUG_MAC80211(priv
, "leave - RF not ready\n");
1276 if (queue
>= AC_NUM
) {
1277 IWL_DEBUG_MAC80211(priv
, "leave - queue >= AC_NUM %d\n", queue
);
1281 q
= AC_NUM
- 1 - queue
;
1283 spin_lock_irqsave(&priv
->lock
, flags
);
1285 for_each_context(priv
, ctx
) {
1286 ctx
->qos_data
.def_qos_parm
.ac
[q
].cw_min
=
1287 cpu_to_le16(params
->cw_min
);
1288 ctx
->qos_data
.def_qos_parm
.ac
[q
].cw_max
=
1289 cpu_to_le16(params
->cw_max
);
1290 ctx
->qos_data
.def_qos_parm
.ac
[q
].aifsn
= params
->aifs
;
1291 ctx
->qos_data
.def_qos_parm
.ac
[q
].edca_txop
=
1292 cpu_to_le16((params
->txop
* 32));
1294 ctx
->qos_data
.def_qos_parm
.ac
[q
].reserved1
= 0;
1297 spin_unlock_irqrestore(&priv
->lock
, flags
);
1299 IWL_DEBUG_MAC80211(priv
, "leave\n");
1302 EXPORT_SYMBOL(iwl_legacy_mac_conf_tx
);
1304 int iwl_legacy_mac_tx_last_beacon(struct ieee80211_hw
*hw
)
1306 struct iwl_priv
*priv
= hw
->priv
;
1308 return priv
->ibss_manager
== IWL_IBSS_MANAGER
;
1310 EXPORT_SYMBOL_GPL(iwl_legacy_mac_tx_last_beacon
);
1313 iwl_legacy_set_mode(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
1315 iwl_legacy_connection_init_rx_config(priv
, ctx
);
1317 if (priv
->cfg
->ops
->hcmd
->set_rxon_chain
)
1318 priv
->cfg
->ops
->hcmd
->set_rxon_chain(priv
, ctx
);
1320 return iwl_legacy_commit_rxon(priv
, ctx
);
1323 static int iwl_legacy_setup_interface(struct iwl_priv
*priv
,
1324 struct iwl_rxon_context
*ctx
)
1326 struct ieee80211_vif
*vif
= ctx
->vif
;
1329 lockdep_assert_held(&priv
->mutex
);
1332 * This variable will be correct only when there's just
1333 * a single context, but all code using it is for hardware
1334 * that supports only one context.
1336 priv
->iw_mode
= vif
->type
;
1338 ctx
->is_active
= true;
1340 err
= iwl_legacy_set_mode(priv
, ctx
);
1342 if (!ctx
->always_active
)
1343 ctx
->is_active
= false;
1351 iwl_legacy_mac_add_interface(struct ieee80211_hw
*hw
, struct ieee80211_vif
*vif
)
1353 struct iwl_priv
*priv
= hw
->priv
;
1354 struct iwl_vif_priv
*vif_priv
= (void *)vif
->drv_priv
;
1355 struct iwl_rxon_context
*tmp
, *ctx
= NULL
;
1358 IWL_DEBUG_MAC80211(priv
, "enter: type %d, addr %pM\n",
1359 vif
->type
, vif
->addr
);
1361 mutex_lock(&priv
->mutex
);
1363 if (!iwl_legacy_is_ready_rf(priv
)) {
1364 IWL_WARN(priv
, "Try to add interface when device not ready\n");
1369 for_each_context(priv
, tmp
) {
1370 u32 possible_modes
=
1371 tmp
->interface_modes
| tmp
->exclusive_interface_modes
;
1374 /* check if this busy context is exclusive */
1375 if (tmp
->exclusive_interface_modes
&
1376 BIT(tmp
->vif
->type
)) {
1383 if (!(possible_modes
& BIT(vif
->type
)))
1386 /* have maybe usable context w/o interface */
1396 vif_priv
->ctx
= ctx
;
1399 err
= iwl_legacy_setup_interface(priv
, ctx
);
1404 priv
->iw_mode
= NL80211_IFTYPE_STATION
;
1406 mutex_unlock(&priv
->mutex
);
1408 IWL_DEBUG_MAC80211(priv
, "leave\n");
1411 EXPORT_SYMBOL(iwl_legacy_mac_add_interface
);
1413 static void iwl_legacy_teardown_interface(struct iwl_priv
*priv
,
1414 struct ieee80211_vif
*vif
,
1417 struct iwl_rxon_context
*ctx
= iwl_legacy_rxon_ctx_from_vif(vif
);
1419 lockdep_assert_held(&priv
->mutex
);
1421 if (priv
->scan_vif
== vif
) {
1422 iwl_legacy_scan_cancel_timeout(priv
, 200);
1423 iwl_legacy_force_scan_end(priv
);
1427 iwl_legacy_set_mode(priv
, ctx
);
1428 if (!ctx
->always_active
)
1429 ctx
->is_active
= false;
1433 void iwl_legacy_mac_remove_interface(struct ieee80211_hw
*hw
,
1434 struct ieee80211_vif
*vif
)
1436 struct iwl_priv
*priv
= hw
->priv
;
1437 struct iwl_rxon_context
*ctx
= iwl_legacy_rxon_ctx_from_vif(vif
);
1439 IWL_DEBUG_MAC80211(priv
, "enter\n");
1441 mutex_lock(&priv
->mutex
);
1443 WARN_ON(ctx
->vif
!= vif
);
1446 iwl_legacy_teardown_interface(priv
, vif
, false);
1448 memset(priv
->bssid
, 0, ETH_ALEN
);
1449 mutex_unlock(&priv
->mutex
);
1451 IWL_DEBUG_MAC80211(priv
, "leave\n");
1454 EXPORT_SYMBOL(iwl_legacy_mac_remove_interface
);
1456 int iwl_legacy_alloc_txq_mem(struct iwl_priv
*priv
)
1459 priv
->txq
= kzalloc(
1460 sizeof(struct iwl_tx_queue
) *
1461 priv
->cfg
->base_params
->num_of_queues
,
1464 IWL_ERR(priv
, "Not enough memory for txq\n");
1469 EXPORT_SYMBOL(iwl_legacy_alloc_txq_mem
);
1471 void iwl_legacy_txq_mem(struct iwl_priv
*priv
)
1476 EXPORT_SYMBOL(iwl_legacy_txq_mem
);
1478 #ifdef CONFIG_IWLWIFI_LEGACY_DEBUGFS
1480 #define IWL_TRAFFIC_DUMP_SIZE (IWL_TRAFFIC_ENTRY_SIZE * IWL_TRAFFIC_ENTRIES)
1482 void iwl_legacy_reset_traffic_log(struct iwl_priv
*priv
)
1484 priv
->tx_traffic_idx
= 0;
1485 priv
->rx_traffic_idx
= 0;
1486 if (priv
->tx_traffic
)
1487 memset(priv
->tx_traffic
, 0, IWL_TRAFFIC_DUMP_SIZE
);
1488 if (priv
->rx_traffic
)
1489 memset(priv
->rx_traffic
, 0, IWL_TRAFFIC_DUMP_SIZE
);
1492 int iwl_legacy_alloc_traffic_mem(struct iwl_priv
*priv
)
1494 u32 traffic_size
= IWL_TRAFFIC_DUMP_SIZE
;
1496 if (iwlegacy_debug_level
& IWL_DL_TX
) {
1497 if (!priv
->tx_traffic
) {
1499 kzalloc(traffic_size
, GFP_KERNEL
);
1500 if (!priv
->tx_traffic
)
1504 if (iwlegacy_debug_level
& IWL_DL_RX
) {
1505 if (!priv
->rx_traffic
) {
1507 kzalloc(traffic_size
, GFP_KERNEL
);
1508 if (!priv
->rx_traffic
)
1512 iwl_legacy_reset_traffic_log(priv
);
1515 EXPORT_SYMBOL(iwl_legacy_alloc_traffic_mem
);
1517 void iwl_legacy_free_traffic_mem(struct iwl_priv
*priv
)
1519 kfree(priv
->tx_traffic
);
1520 priv
->tx_traffic
= NULL
;
1522 kfree(priv
->rx_traffic
);
1523 priv
->rx_traffic
= NULL
;
1525 EXPORT_SYMBOL(iwl_legacy_free_traffic_mem
);
1527 void iwl_legacy_dbg_log_tx_data_frame(struct iwl_priv
*priv
,
1528 u16 length
, struct ieee80211_hdr
*header
)
1533 if (likely(!(iwlegacy_debug_level
& IWL_DL_TX
)))
1536 if (!priv
->tx_traffic
)
1539 fc
= header
->frame_control
;
1540 if (ieee80211_is_data(fc
)) {
1541 len
= (length
> IWL_TRAFFIC_ENTRY_SIZE
)
1542 ? IWL_TRAFFIC_ENTRY_SIZE
: length
;
1543 memcpy((priv
->tx_traffic
+
1544 (priv
->tx_traffic_idx
* IWL_TRAFFIC_ENTRY_SIZE
)),
1546 priv
->tx_traffic_idx
=
1547 (priv
->tx_traffic_idx
+ 1) % IWL_TRAFFIC_ENTRIES
;
1550 EXPORT_SYMBOL(iwl_legacy_dbg_log_tx_data_frame
);
1552 void iwl_legacy_dbg_log_rx_data_frame(struct iwl_priv
*priv
,
1553 u16 length
, struct ieee80211_hdr
*header
)
1558 if (likely(!(iwlegacy_debug_level
& IWL_DL_RX
)))
1561 if (!priv
->rx_traffic
)
1564 fc
= header
->frame_control
;
1565 if (ieee80211_is_data(fc
)) {
1566 len
= (length
> IWL_TRAFFIC_ENTRY_SIZE
)
1567 ? IWL_TRAFFIC_ENTRY_SIZE
: length
;
1568 memcpy((priv
->rx_traffic
+
1569 (priv
->rx_traffic_idx
* IWL_TRAFFIC_ENTRY_SIZE
)),
1571 priv
->rx_traffic_idx
=
1572 (priv
->rx_traffic_idx
+ 1) % IWL_TRAFFIC_ENTRIES
;
1575 EXPORT_SYMBOL(iwl_legacy_dbg_log_rx_data_frame
);
1577 const char *iwl_legacy_get_mgmt_string(int cmd
)
1580 IWL_CMD(MANAGEMENT_ASSOC_REQ
);
1581 IWL_CMD(MANAGEMENT_ASSOC_RESP
);
1582 IWL_CMD(MANAGEMENT_REASSOC_REQ
);
1583 IWL_CMD(MANAGEMENT_REASSOC_RESP
);
1584 IWL_CMD(MANAGEMENT_PROBE_REQ
);
1585 IWL_CMD(MANAGEMENT_PROBE_RESP
);
1586 IWL_CMD(MANAGEMENT_BEACON
);
1587 IWL_CMD(MANAGEMENT_ATIM
);
1588 IWL_CMD(MANAGEMENT_DISASSOC
);
1589 IWL_CMD(MANAGEMENT_AUTH
);
1590 IWL_CMD(MANAGEMENT_DEAUTH
);
1591 IWL_CMD(MANAGEMENT_ACTION
);
1598 const char *iwl_legacy_get_ctrl_string(int cmd
)
1601 IWL_CMD(CONTROL_BACK_REQ
);
1602 IWL_CMD(CONTROL_BACK
);
1603 IWL_CMD(CONTROL_PSPOLL
);
1604 IWL_CMD(CONTROL_RTS
);
1605 IWL_CMD(CONTROL_CTS
);
1606 IWL_CMD(CONTROL_ACK
);
1607 IWL_CMD(CONTROL_CFEND
);
1608 IWL_CMD(CONTROL_CFENDACK
);
1615 void iwl_legacy_clear_traffic_stats(struct iwl_priv
*priv
)
1617 memset(&priv
->tx_stats
, 0, sizeof(struct traffic_stats
));
1618 memset(&priv
->rx_stats
, 0, sizeof(struct traffic_stats
));
1622 * if CONFIG_IWLWIFI_LEGACY_DEBUGFS defined,
1623 * iwl_legacy_update_stats function will
1624 * record all the MGMT, CTRL and DATA pkt for both TX and Rx pass
1625 * Use debugFs to display the rx/rx_statistics
1626 * if CONFIG_IWLWIFI_LEGACY_DEBUGFS not being defined, then no MGMT and CTRL
1627 * information will be recorded, but DATA pkt still will be recorded
1628 * for the reason of iwl_led.c need to control the led blinking based on
1629 * number of tx and rx data.
1633 iwl_legacy_update_stats(struct iwl_priv
*priv
, bool is_tx
, __le16 fc
, u16 len
)
1635 struct traffic_stats
*stats
;
1638 stats
= &priv
->tx_stats
;
1640 stats
= &priv
->rx_stats
;
1642 if (ieee80211_is_mgmt(fc
)) {
1643 switch (fc
& cpu_to_le16(IEEE80211_FCTL_STYPE
)) {
1644 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ
):
1645 stats
->mgmt
[MANAGEMENT_ASSOC_REQ
]++;
1647 case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP
):
1648 stats
->mgmt
[MANAGEMENT_ASSOC_RESP
]++;
1650 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ
):
1651 stats
->mgmt
[MANAGEMENT_REASSOC_REQ
]++;
1653 case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP
):
1654 stats
->mgmt
[MANAGEMENT_REASSOC_RESP
]++;
1656 case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ
):
1657 stats
->mgmt
[MANAGEMENT_PROBE_REQ
]++;
1659 case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP
):
1660 stats
->mgmt
[MANAGEMENT_PROBE_RESP
]++;
1662 case cpu_to_le16(IEEE80211_STYPE_BEACON
):
1663 stats
->mgmt
[MANAGEMENT_BEACON
]++;
1665 case cpu_to_le16(IEEE80211_STYPE_ATIM
):
1666 stats
->mgmt
[MANAGEMENT_ATIM
]++;
1668 case cpu_to_le16(IEEE80211_STYPE_DISASSOC
):
1669 stats
->mgmt
[MANAGEMENT_DISASSOC
]++;
1671 case cpu_to_le16(IEEE80211_STYPE_AUTH
):
1672 stats
->mgmt
[MANAGEMENT_AUTH
]++;
1674 case cpu_to_le16(IEEE80211_STYPE_DEAUTH
):
1675 stats
->mgmt
[MANAGEMENT_DEAUTH
]++;
1677 case cpu_to_le16(IEEE80211_STYPE_ACTION
):
1678 stats
->mgmt
[MANAGEMENT_ACTION
]++;
1681 } else if (ieee80211_is_ctl(fc
)) {
1682 switch (fc
& cpu_to_le16(IEEE80211_FCTL_STYPE
)) {
1683 case cpu_to_le16(IEEE80211_STYPE_BACK_REQ
):
1684 stats
->ctrl
[CONTROL_BACK_REQ
]++;
1686 case cpu_to_le16(IEEE80211_STYPE_BACK
):
1687 stats
->ctrl
[CONTROL_BACK
]++;
1689 case cpu_to_le16(IEEE80211_STYPE_PSPOLL
):
1690 stats
->ctrl
[CONTROL_PSPOLL
]++;
1692 case cpu_to_le16(IEEE80211_STYPE_RTS
):
1693 stats
->ctrl
[CONTROL_RTS
]++;
1695 case cpu_to_le16(IEEE80211_STYPE_CTS
):
1696 stats
->ctrl
[CONTROL_CTS
]++;
1698 case cpu_to_le16(IEEE80211_STYPE_ACK
):
1699 stats
->ctrl
[CONTROL_ACK
]++;
1701 case cpu_to_le16(IEEE80211_STYPE_CFEND
):
1702 stats
->ctrl
[CONTROL_CFEND
]++;
1704 case cpu_to_le16(IEEE80211_STYPE_CFENDACK
):
1705 stats
->ctrl
[CONTROL_CFENDACK
]++;
1711 stats
->data_bytes
+= len
;
1714 EXPORT_SYMBOL(iwl_legacy_update_stats
);
1717 static void _iwl_legacy_force_rf_reset(struct iwl_priv
*priv
)
1719 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1722 if (!iwl_legacy_is_any_associated(priv
)) {
1723 IWL_DEBUG_SCAN(priv
, "force reset rejected: not associated\n");
1727 * There is no easy and better way to force reset the radio,
1728 * the only known method is switching channel which will force to
1729 * reset and tune the radio.
1730 * Use internal short scan (single channel) operation to should
1731 * achieve this objective.
1732 * Driver should reset the radio when number of consecutive missed
1733 * beacon, or any other uCode error condition detected.
1735 IWL_DEBUG_INFO(priv
, "perform radio reset.\n");
1736 iwl_legacy_internal_short_hw_scan(priv
);
1740 int iwl_legacy_force_reset(struct iwl_priv
*priv
, int mode
, bool external
)
1742 struct iwl_force_reset
*force_reset
;
1744 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1747 if (mode
>= IWL_MAX_FORCE_RESET
) {
1748 IWL_DEBUG_INFO(priv
, "invalid reset request.\n");
1751 force_reset
= &priv
->force_reset
[mode
];
1752 force_reset
->reset_request_count
++;
1754 if (force_reset
->last_force_reset_jiffies
&&
1755 time_after(force_reset
->last_force_reset_jiffies
+
1756 force_reset
->reset_duration
, jiffies
)) {
1757 IWL_DEBUG_INFO(priv
, "force reset rejected\n");
1758 force_reset
->reset_reject_count
++;
1762 force_reset
->reset_success_count
++;
1763 force_reset
->last_force_reset_jiffies
= jiffies
;
1764 IWL_DEBUG_INFO(priv
, "perform force reset (%d)\n", mode
);
1767 _iwl_legacy_force_rf_reset(priv
);
1771 * if the request is from external(ex: debugfs),
1772 * then always perform the request in regardless the module
1774 * if the request is from internal (uCode error or driver
1775 * detect failure), then fw_restart module parameter
1776 * need to be check before performing firmware reload
1778 if (!external
&& !priv
->cfg
->mod_params
->restart_fw
) {
1779 IWL_DEBUG_INFO(priv
, "Cancel firmware reload based on "
1780 "module parameter setting\n");
1783 IWL_ERR(priv
, "On demand firmware reload\n");
1784 /* Set the FW error flag -- cleared on iwl_down */
1785 set_bit(STATUS_FW_ERROR
, &priv
->status
);
1786 wake_up_interruptible(&priv
->wait_command_queue
);
1788 * Keep the restart process from trying to send host
1789 * commands by clearing the INIT status bit
1791 clear_bit(STATUS_READY
, &priv
->status
);
1792 queue_work(priv
->workqueue
, &priv
->restart
);
1799 iwl_legacy_mac_change_interface(struct ieee80211_hw
*hw
,
1800 struct ieee80211_vif
*vif
,
1801 enum nl80211_iftype newtype
, bool newp2p
)
1803 struct iwl_priv
*priv
= hw
->priv
;
1804 struct iwl_rxon_context
*ctx
= iwl_legacy_rxon_ctx_from_vif(vif
);
1805 struct iwl_rxon_context
*tmp
;
1806 u32 interface_modes
;
1809 newtype
= ieee80211_iftype_p2p(newtype
, newp2p
);
1811 mutex_lock(&priv
->mutex
);
1813 if (!ctx
->vif
|| !iwl_legacy_is_ready_rf(priv
)) {
1815 * Huh? But wait ... this can maybe happen when
1816 * we're in the middle of a firmware restart!
1822 interface_modes
= ctx
->interface_modes
| ctx
->exclusive_interface_modes
;
1824 if (!(interface_modes
& BIT(newtype
))) {
1829 if (ctx
->exclusive_interface_modes
& BIT(newtype
)) {
1830 for_each_context(priv
, tmp
) {
1838 * The current mode switch would be exclusive, but
1839 * another context is active ... refuse the switch.
1847 iwl_legacy_teardown_interface(priv
, vif
, true);
1848 vif
->type
= newtype
;
1850 err
= iwl_legacy_setup_interface(priv
, ctx
);
1853 * We've switched internally, but submitting to the
1854 * device may have failed for some reason. Mask this
1855 * error, because otherwise mac80211 will not switch
1856 * (and set the interface type back) and we'll be
1857 * out of sync with it.
1862 mutex_unlock(&priv
->mutex
);
1865 EXPORT_SYMBOL(iwl_legacy_mac_change_interface
);
1868 * On every watchdog tick we check (latest) time stamp. If it does not
1869 * change during timeout period and queue is not empty we reset firmware.
1871 static int iwl_legacy_check_stuck_queue(struct iwl_priv
*priv
, int cnt
)
1873 struct iwl_tx_queue
*txq
= &priv
->txq
[cnt
];
1874 struct iwl_queue
*q
= &txq
->q
;
1875 unsigned long timeout
;
1878 if (q
->read_ptr
== q
->write_ptr
) {
1879 txq
->time_stamp
= jiffies
;
1883 timeout
= txq
->time_stamp
+
1884 msecs_to_jiffies(priv
->cfg
->base_params
->wd_timeout
);
1886 if (time_after(jiffies
, timeout
)) {
1887 IWL_ERR(priv
, "Queue %d stuck for %u ms.\n",
1888 q
->id
, priv
->cfg
->base_params
->wd_timeout
);
1889 ret
= iwl_legacy_force_reset(priv
, IWL_FW_RESET
, false);
1890 return (ret
== -EAGAIN
) ? 0 : 1;
1897 * Making watchdog tick be a quarter of timeout assure we will
1898 * discover the queue hung between timeout and 1.25*timeout
1900 #define IWL_WD_TICK(timeout) ((timeout) / 4)
1903 * Watchdog timer callback, we check each tx queue for stuck, if if hung
1904 * we reset the firmware. If everything is fine just rearm the timer.
1906 void iwl_legacy_bg_watchdog(unsigned long data
)
1908 struct iwl_priv
*priv
= (struct iwl_priv
*)data
;
1910 unsigned long timeout
;
1912 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
1915 timeout
= priv
->cfg
->base_params
->wd_timeout
;
1919 /* monitor and check for stuck cmd queue */
1920 if (iwl_legacy_check_stuck_queue(priv
, priv
->cmd_queue
))
1923 /* monitor and check for other stuck queues */
1924 if (iwl_legacy_is_any_associated(priv
)) {
1925 for (cnt
= 0; cnt
< priv
->hw_params
.max_txq_num
; cnt
++) {
1926 /* skip as we already checked the command queue */
1927 if (cnt
== priv
->cmd_queue
)
1929 if (iwl_legacy_check_stuck_queue(priv
, cnt
))
1934 mod_timer(&priv
->watchdog
, jiffies
+
1935 msecs_to_jiffies(IWL_WD_TICK(timeout
)));
1937 EXPORT_SYMBOL(iwl_legacy_bg_watchdog
);
1939 void iwl_legacy_setup_watchdog(struct iwl_priv
*priv
)
1941 unsigned int timeout
= priv
->cfg
->base_params
->wd_timeout
;
1944 mod_timer(&priv
->watchdog
,
1945 jiffies
+ msecs_to_jiffies(IWL_WD_TICK(timeout
)));
1947 del_timer(&priv
->watchdog
);
1949 EXPORT_SYMBOL(iwl_legacy_setup_watchdog
);
1952 * extended beacon time format
1953 * time in usec will be changed into a 32-bit value in extended:internal format
1954 * the extended part is the beacon counts
1955 * the internal part is the time in usec within one beacon interval
1958 iwl_legacy_usecs_to_beacons(struct iwl_priv
*priv
,
1959 u32 usec
, u32 beacon_interval
)
1963 u32 interval
= beacon_interval
* TIME_UNIT
;
1965 if (!interval
|| !usec
)
1968 quot
= (usec
/ interval
) &
1969 (iwl_legacy_beacon_time_mask_high(priv
,
1970 priv
->hw_params
.beacon_time_tsf_bits
) >>
1971 priv
->hw_params
.beacon_time_tsf_bits
);
1972 rem
= (usec
% interval
) & iwl_legacy_beacon_time_mask_low(priv
,
1973 priv
->hw_params
.beacon_time_tsf_bits
);
1975 return (quot
<< priv
->hw_params
.beacon_time_tsf_bits
) + rem
;
1977 EXPORT_SYMBOL(iwl_legacy_usecs_to_beacons
);
1979 /* base is usually what we get from ucode with each received frame,
1980 * the same as HW timer counter counting down
1982 __le32
iwl_legacy_add_beacon_time(struct iwl_priv
*priv
, u32 base
,
1983 u32 addon
, u32 beacon_interval
)
1985 u32 base_low
= base
& iwl_legacy_beacon_time_mask_low(priv
,
1986 priv
->hw_params
.beacon_time_tsf_bits
);
1987 u32 addon_low
= addon
& iwl_legacy_beacon_time_mask_low(priv
,
1988 priv
->hw_params
.beacon_time_tsf_bits
);
1989 u32 interval
= beacon_interval
* TIME_UNIT
;
1990 u32 res
= (base
& iwl_legacy_beacon_time_mask_high(priv
,
1991 priv
->hw_params
.beacon_time_tsf_bits
)) +
1992 (addon
& iwl_legacy_beacon_time_mask_high(priv
,
1993 priv
->hw_params
.beacon_time_tsf_bits
));
1995 if (base_low
> addon_low
)
1996 res
+= base_low
- addon_low
;
1997 else if (base_low
< addon_low
) {
1998 res
+= interval
+ base_low
- addon_low
;
1999 res
+= (1 << priv
->hw_params
.beacon_time_tsf_bits
);
2001 res
+= (1 << priv
->hw_params
.beacon_time_tsf_bits
);
2003 return cpu_to_le32(res
);
2005 EXPORT_SYMBOL(iwl_legacy_add_beacon_time
);
2009 int iwl_legacy_pci_suspend(struct device
*device
)
2011 struct pci_dev
*pdev
= to_pci_dev(device
);
2012 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
2015 * This function is called when system goes into suspend state
2016 * mac80211 will call iwl_mac_stop() from the mac80211 suspend function
2017 * first but since iwl_mac_stop() has no knowledge of who the caller is,
2018 * it will not call apm_ops.stop() to stop the DMA operation.
2019 * Calling apm_ops.stop here to make sure we stop the DMA.
2021 iwl_legacy_apm_stop(priv
);
2025 EXPORT_SYMBOL(iwl_legacy_pci_suspend
);
2027 int iwl_legacy_pci_resume(struct device
*device
)
2029 struct pci_dev
*pdev
= to_pci_dev(device
);
2030 struct iwl_priv
*priv
= pci_get_drvdata(pdev
);
2031 bool hw_rfkill
= false;
2034 * We disable the RETRY_TIMEOUT register (0x41) to keep
2035 * PCI Tx retries from interfering with C3 CPU state.
2037 pci_write_config_byte(pdev
, PCI_CFG_RETRY_TIMEOUT
, 0x00);
2039 iwl_legacy_enable_interrupts(priv
);
2041 if (!(iwl_read32(priv
, CSR_GP_CNTRL
) &
2042 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW
))
2046 set_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2048 clear_bit(STATUS_RF_KILL_HW
, &priv
->status
);
2050 wiphy_rfkill_set_hw_state(priv
->hw
->wiphy
, hw_rfkill
);
2054 EXPORT_SYMBOL(iwl_legacy_pci_resume
);
2056 const struct dev_pm_ops iwl_legacy_pm_ops
= {
2057 .suspend
= iwl_legacy_pci_suspend
,
2058 .resume
= iwl_legacy_pci_resume
,
2059 .freeze
= iwl_legacy_pci_suspend
,
2060 .thaw
= iwl_legacy_pci_resume
,
2061 .poweroff
= iwl_legacy_pci_suspend
,
2062 .restore
= iwl_legacy_pci_resume
,
2064 EXPORT_SYMBOL(iwl_legacy_pm_ops
);
2066 #endif /* CONFIG_PM */
2069 iwl_legacy_update_qos(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
2071 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
2074 if (!ctx
->is_active
)
2077 ctx
->qos_data
.def_qos_parm
.qos_flags
= 0;
2079 if (ctx
->qos_data
.qos_active
)
2080 ctx
->qos_data
.def_qos_parm
.qos_flags
|=
2081 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
2083 if (ctx
->ht
.enabled
)
2084 ctx
->qos_data
.def_qos_parm
.qos_flags
|= QOS_PARAM_FLG_TGN_MSK
;
2086 IWL_DEBUG_QOS(priv
, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
2087 ctx
->qos_data
.qos_active
,
2088 ctx
->qos_data
.def_qos_parm
.qos_flags
);
2090 iwl_legacy_send_cmd_pdu_async(priv
, ctx
->qos_cmd
,
2091 sizeof(struct iwl_qosparam_cmd
),
2092 &ctx
->qos_data
.def_qos_parm
, NULL
);
2096 * iwl_legacy_mac_config - mac80211 config callback
2098 int iwl_legacy_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
2100 struct iwl_priv
*priv
= hw
->priv
;
2101 const struct iwl_channel_info
*ch_info
;
2102 struct ieee80211_conf
*conf
= &hw
->conf
;
2103 struct ieee80211_channel
*channel
= conf
->channel
;
2104 struct iwl_ht_config
*ht_conf
= &priv
->current_ht_config
;
2105 struct iwl_rxon_context
*ctx
;
2106 unsigned long flags
= 0;
2109 int scan_active
= 0;
2110 bool ht_changed
[NUM_IWL_RXON_CTX
] = {};
2112 if (WARN_ON(!priv
->cfg
->ops
->legacy
))
2115 mutex_lock(&priv
->mutex
);
2117 IWL_DEBUG_MAC80211(priv
, "enter to channel %d changed 0x%X\n",
2118 channel
->hw_value
, changed
);
2120 if (unlikely(!priv
->cfg
->mod_params
->disable_hw_scan
&&
2121 test_bit(STATUS_SCANNING
, &priv
->status
))) {
2123 IWL_DEBUG_MAC80211(priv
, "leave - scanning\n");
2126 if (changed
& (IEEE80211_CONF_CHANGE_SMPS
|
2127 IEEE80211_CONF_CHANGE_CHANNEL
)) {
2128 /* mac80211 uses static for non-HT which is what we want */
2129 priv
->current_ht_config
.smps
= conf
->smps_mode
;
2132 * Recalculate chain counts.
2134 * If monitor mode is enabled then mac80211 will
2135 * set up the SM PS mode to OFF if an HT channel is
2138 if (priv
->cfg
->ops
->hcmd
->set_rxon_chain
)
2139 for_each_context(priv
, ctx
)
2140 priv
->cfg
->ops
->hcmd
->set_rxon_chain(priv
, ctx
);
2143 /* during scanning mac80211 will delay channel setting until
2144 * scan finish with changed = 0
2146 if (!changed
|| (changed
& IEEE80211_CONF_CHANGE_CHANNEL
)) {
2150 ch
= channel
->hw_value
;
2151 ch_info
= iwl_legacy_get_channel_info(priv
, channel
->band
, ch
);
2152 if (!iwl_legacy_is_channel_valid(ch_info
)) {
2153 IWL_DEBUG_MAC80211(priv
, "leave - invalid channel\n");
2158 if (priv
->iw_mode
== NL80211_IFTYPE_ADHOC
&&
2159 !iwl_legacy_is_channel_ibss(ch_info
)) {
2160 IWL_DEBUG_MAC80211(priv
, "leave - not IBSS channel\n");
2165 spin_lock_irqsave(&priv
->lock
, flags
);
2167 for_each_context(priv
, ctx
) {
2168 /* Configure HT40 channels */
2169 if (ctx
->ht
.enabled
!= conf_is_ht(conf
)) {
2170 ctx
->ht
.enabled
= conf_is_ht(conf
);
2171 ht_changed
[ctx
->ctxid
] = true;
2173 if (ctx
->ht
.enabled
) {
2174 if (conf_is_ht40_minus(conf
)) {
2175 ctx
->ht
.extension_chan_offset
=
2176 IEEE80211_HT_PARAM_CHA_SEC_BELOW
;
2177 ctx
->ht
.is_40mhz
= true;
2178 } else if (conf_is_ht40_plus(conf
)) {
2179 ctx
->ht
.extension_chan_offset
=
2180 IEEE80211_HT_PARAM_CHA_SEC_ABOVE
;
2181 ctx
->ht
.is_40mhz
= true;
2183 ctx
->ht
.extension_chan_offset
=
2184 IEEE80211_HT_PARAM_CHA_SEC_NONE
;
2185 ctx
->ht
.is_40mhz
= false;
2188 ctx
->ht
.is_40mhz
= false;
2191 * Default to no protection. Protection mode will
2192 * later be set from BSS config in iwl_ht_conf
2194 ctx
->ht
.protection
=
2195 IEEE80211_HT_OP_MODE_PROTECTION_NONE
;
2197 /* if we are switching from ht to 2.4 clear flags
2198 * from any ht related info since 2.4 does not
2200 if ((le16_to_cpu(ctx
->staging
.channel
) != ch
))
2201 ctx
->staging
.flags
= 0;
2203 iwl_legacy_set_rxon_channel(priv
, channel
, ctx
);
2204 iwl_legacy_set_rxon_ht(priv
, ht_conf
);
2206 iwl_legacy_set_flags_for_band(priv
, ctx
, channel
->band
,
2210 spin_unlock_irqrestore(&priv
->lock
, flags
);
2212 if (priv
->cfg
->ops
->legacy
->update_bcast_stations
)
2214 priv
->cfg
->ops
->legacy
->update_bcast_stations(priv
);
2217 /* The list of supported rates and rate mask can be different
2218 * for each band; since the band may have changed, reset
2219 * the rate mask to what mac80211 lists */
2220 iwl_legacy_set_rate(priv
);
2223 if (changed
& (IEEE80211_CONF_CHANGE_PS
|
2224 IEEE80211_CONF_CHANGE_IDLE
)) {
2225 ret
= iwl_legacy_power_update_mode(priv
, false);
2227 IWL_DEBUG_MAC80211(priv
, "Error setting sleep level\n");
2230 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
2231 IWL_DEBUG_MAC80211(priv
, "TX Power old=%d new=%d\n",
2232 priv
->tx_power_user_lmt
, conf
->power_level
);
2234 iwl_legacy_set_tx_power(priv
, conf
->power_level
, false);
2237 if (!iwl_legacy_is_ready(priv
)) {
2238 IWL_DEBUG_MAC80211(priv
, "leave - not ready\n");
2245 for_each_context(priv
, ctx
) {
2246 if (memcmp(&ctx
->active
, &ctx
->staging
, sizeof(ctx
->staging
)))
2247 iwl_legacy_commit_rxon(priv
, ctx
);
2249 IWL_DEBUG_INFO(priv
,
2250 "Not re-sending same RXON configuration.\n");
2251 if (ht_changed
[ctx
->ctxid
])
2252 iwl_legacy_update_qos(priv
, ctx
);
2256 IWL_DEBUG_MAC80211(priv
, "leave\n");
2257 mutex_unlock(&priv
->mutex
);
2260 EXPORT_SYMBOL(iwl_legacy_mac_config
);
2262 void iwl_legacy_mac_reset_tsf(struct ieee80211_hw
*hw
)
2264 struct iwl_priv
*priv
= hw
->priv
;
2265 unsigned long flags
;
2266 /* IBSS can only be the IWL_RXON_CTX_BSS context */
2267 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
2269 if (WARN_ON(!priv
->cfg
->ops
->legacy
))
2272 mutex_lock(&priv
->mutex
);
2273 IWL_DEBUG_MAC80211(priv
, "enter\n");
2275 spin_lock_irqsave(&priv
->lock
, flags
);
2276 memset(&priv
->current_ht_config
, 0, sizeof(struct iwl_ht_config
));
2277 spin_unlock_irqrestore(&priv
->lock
, flags
);
2279 spin_lock_irqsave(&priv
->lock
, flags
);
2281 /* new association get rid of ibss beacon skb */
2282 if (priv
->beacon_skb
)
2283 dev_kfree_skb(priv
->beacon_skb
);
2285 priv
->beacon_skb
= NULL
;
2287 priv
->timestamp
= 0;
2289 spin_unlock_irqrestore(&priv
->lock
, flags
);
2291 iwl_legacy_scan_cancel_timeout(priv
, 100);
2292 if (!iwl_legacy_is_ready_rf(priv
)) {
2293 IWL_DEBUG_MAC80211(priv
, "leave - not ready\n");
2294 mutex_unlock(&priv
->mutex
);
2298 /* we are restarting association process
2299 * clear RXON_FILTER_ASSOC_MSK bit
2301 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
2302 iwl_legacy_commit_rxon(priv
, ctx
);
2304 iwl_legacy_set_rate(priv
);
2306 mutex_unlock(&priv
->mutex
);
2308 IWL_DEBUG_MAC80211(priv
, "leave\n");
2310 EXPORT_SYMBOL(iwl_legacy_mac_reset_tsf
);
2312 static void iwl_legacy_ht_conf(struct iwl_priv
*priv
,
2313 struct ieee80211_vif
*vif
)
2315 struct iwl_ht_config
*ht_conf
= &priv
->current_ht_config
;
2316 struct ieee80211_sta
*sta
;
2317 struct ieee80211_bss_conf
*bss_conf
= &vif
->bss_conf
;
2318 struct iwl_rxon_context
*ctx
= iwl_legacy_rxon_ctx_from_vif(vif
);
2320 IWL_DEBUG_ASSOC(priv
, "enter:\n");
2322 if (!ctx
->ht
.enabled
)
2325 ctx
->ht
.protection
=
2326 bss_conf
->ht_operation_mode
& IEEE80211_HT_OP_MODE_PROTECTION
;
2327 ctx
->ht
.non_gf_sta_present
=
2328 !!(bss_conf
->ht_operation_mode
&
2329 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
);
2331 ht_conf
->single_chain_sufficient
= false;
2333 switch (vif
->type
) {
2334 case NL80211_IFTYPE_STATION
:
2336 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
2338 struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
2341 maxstreams
= (ht_cap
->mcs
.tx_params
&
2342 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK
)
2343 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT
;
2346 if ((ht_cap
->mcs
.rx_mask
[1] == 0) &&
2347 (ht_cap
->mcs
.rx_mask
[2] == 0))
2348 ht_conf
->single_chain_sufficient
= true;
2349 if (maxstreams
<= 1)
2350 ht_conf
->single_chain_sufficient
= true;
2353 * If at all, this can only happen through a race
2354 * when the AP disconnects us while we're still
2355 * setting up the connection, in that case mac80211
2356 * will soon tell us about that.
2358 ht_conf
->single_chain_sufficient
= true;
2362 case NL80211_IFTYPE_ADHOC
:
2363 ht_conf
->single_chain_sufficient
= true;
2369 IWL_DEBUG_ASSOC(priv
, "leave\n");
2372 static inline void iwl_legacy_set_no_assoc(struct iwl_priv
*priv
,
2373 struct ieee80211_vif
*vif
)
2375 struct iwl_rxon_context
*ctx
= iwl_legacy_rxon_ctx_from_vif(vif
);
2378 * inform the ucode that there is no longer an
2379 * association and that no more packets should be
2382 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
2383 ctx
->staging
.assoc_id
= 0;
2384 iwl_legacy_commit_rxon(priv
, ctx
);
2387 static void iwl_legacy_beacon_update(struct ieee80211_hw
*hw
,
2388 struct ieee80211_vif
*vif
)
2390 struct iwl_priv
*priv
= hw
->priv
;
2391 unsigned long flags
;
2393 struct sk_buff
*skb
= ieee80211_beacon_get(hw
, vif
);
2398 IWL_DEBUG_MAC80211(priv
, "enter\n");
2400 lockdep_assert_held(&priv
->mutex
);
2402 if (!priv
->beacon_ctx
) {
2403 IWL_ERR(priv
, "update beacon but no beacon context!\n");
2408 spin_lock_irqsave(&priv
->lock
, flags
);
2410 if (priv
->beacon_skb
)
2411 dev_kfree_skb(priv
->beacon_skb
);
2413 priv
->beacon_skb
= skb
;
2415 timestamp
= ((struct ieee80211_mgmt
*)skb
->data
)->u
.beacon
.timestamp
;
2416 priv
->timestamp
= le64_to_cpu(timestamp
);
2418 IWL_DEBUG_MAC80211(priv
, "leave\n");
2419 spin_unlock_irqrestore(&priv
->lock
, flags
);
2421 if (!iwl_legacy_is_ready_rf(priv
)) {
2422 IWL_DEBUG_MAC80211(priv
, "leave - RF not ready\n");
2426 priv
->cfg
->ops
->legacy
->post_associate(priv
);
2429 void iwl_legacy_mac_bss_info_changed(struct ieee80211_hw
*hw
,
2430 struct ieee80211_vif
*vif
,
2431 struct ieee80211_bss_conf
*bss_conf
,
2434 struct iwl_priv
*priv
= hw
->priv
;
2435 struct iwl_rxon_context
*ctx
= iwl_legacy_rxon_ctx_from_vif(vif
);
2438 if (WARN_ON(!priv
->cfg
->ops
->legacy
))
2441 IWL_DEBUG_MAC80211(priv
, "changes = 0x%X\n", changes
);
2443 if (!iwl_legacy_is_alive(priv
))
2446 mutex_lock(&priv
->mutex
);
2448 if (changes
& BSS_CHANGED_QOS
) {
2449 unsigned long flags
;
2451 spin_lock_irqsave(&priv
->lock
, flags
);
2452 ctx
->qos_data
.qos_active
= bss_conf
->qos
;
2453 iwl_legacy_update_qos(priv
, ctx
);
2454 spin_unlock_irqrestore(&priv
->lock
, flags
);
2457 if (changes
& BSS_CHANGED_BEACON_ENABLED
) {
2459 * the add_interface code must make sure we only ever
2460 * have a single interface that could be beaconing at
2463 if (vif
->bss_conf
.enable_beacon
)
2464 priv
->beacon_ctx
= ctx
;
2466 priv
->beacon_ctx
= NULL
;
2469 if (changes
& BSS_CHANGED_BSSID
) {
2470 IWL_DEBUG_MAC80211(priv
, "BSSID %pM\n", bss_conf
->bssid
);
2473 * If there is currently a HW scan going on in the
2474 * background then we need to cancel it else the RXON
2475 * below/in post_associate will fail.
2477 if (iwl_legacy_scan_cancel_timeout(priv
, 100)) {
2479 "Aborted scan still in progress after 100ms\n");
2480 IWL_DEBUG_MAC80211(priv
,
2481 "leaving - scan abort failed.\n");
2482 mutex_unlock(&priv
->mutex
);
2486 /* mac80211 only sets assoc when in STATION mode */
2487 if (vif
->type
== NL80211_IFTYPE_ADHOC
|| bss_conf
->assoc
) {
2488 memcpy(ctx
->staging
.bssid_addr
,
2489 bss_conf
->bssid
, ETH_ALEN
);
2491 /* currently needed in a few places */
2492 memcpy(priv
->bssid
, bss_conf
->bssid
, ETH_ALEN
);
2494 ctx
->staging
.filter_flags
&=
2495 ~RXON_FILTER_ASSOC_MSK
;
2501 * This needs to be after setting the BSSID in case
2502 * mac80211 decides to do both changes at once because
2503 * it will invoke post_associate.
2505 if (vif
->type
== NL80211_IFTYPE_ADHOC
&& changes
& BSS_CHANGED_BEACON
)
2506 iwl_legacy_beacon_update(hw
, vif
);
2508 if (changes
& BSS_CHANGED_ERP_PREAMBLE
) {
2509 IWL_DEBUG_MAC80211(priv
, "ERP_PREAMBLE %d\n",
2510 bss_conf
->use_short_preamble
);
2511 if (bss_conf
->use_short_preamble
)
2512 ctx
->staging
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
2514 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
2517 if (changes
& BSS_CHANGED_ERP_CTS_PROT
) {
2518 IWL_DEBUG_MAC80211(priv
,
2519 "ERP_CTS %d\n", bss_conf
->use_cts_prot
);
2520 if (bss_conf
->use_cts_prot
&&
2521 (priv
->band
!= IEEE80211_BAND_5GHZ
))
2522 ctx
->staging
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
2524 ctx
->staging
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
2525 if (bss_conf
->use_cts_prot
)
2526 ctx
->staging
.flags
|= RXON_FLG_SELF_CTS_EN
;
2528 ctx
->staging
.flags
&= ~RXON_FLG_SELF_CTS_EN
;
2531 if (changes
& BSS_CHANGED_BASIC_RATES
) {
2532 /* XXX use this information
2534 * To do that, remove code from iwl_legacy_set_rate() and put something
2538 ctx->staging.ofdm_basic_rates =
2539 bss_conf->basic_rates;
2541 ctx->staging.ofdm_basic_rates =
2542 bss_conf->basic_rates >> 4;
2543 ctx->staging.cck_basic_rates =
2544 bss_conf->basic_rates & 0xF;
2548 if (changes
& BSS_CHANGED_HT
) {
2549 iwl_legacy_ht_conf(priv
, vif
);
2551 if (priv
->cfg
->ops
->hcmd
->set_rxon_chain
)
2552 priv
->cfg
->ops
->hcmd
->set_rxon_chain(priv
, ctx
);
2555 if (changes
& BSS_CHANGED_ASSOC
) {
2556 IWL_DEBUG_MAC80211(priv
, "ASSOC %d\n", bss_conf
->assoc
);
2557 if (bss_conf
->assoc
) {
2558 priv
->timestamp
= bss_conf
->timestamp
;
2560 if (!iwl_legacy_is_rfkill(priv
))
2561 priv
->cfg
->ops
->legacy
->post_associate(priv
);
2563 iwl_legacy_set_no_assoc(priv
, vif
);
2566 if (changes
&& iwl_legacy_is_associated_ctx(ctx
) && bss_conf
->aid
) {
2567 IWL_DEBUG_MAC80211(priv
, "Changes (%#x) while associated\n",
2569 ret
= iwl_legacy_send_rxon_assoc(priv
, ctx
);
2571 /* Sync active_rxon with latest change. */
2572 memcpy((void *)&ctx
->active
,
2574 sizeof(struct iwl_legacy_rxon_cmd
));
2578 if (changes
& BSS_CHANGED_BEACON_ENABLED
) {
2579 if (vif
->bss_conf
.enable_beacon
) {
2580 memcpy(ctx
->staging
.bssid_addr
,
2581 bss_conf
->bssid
, ETH_ALEN
);
2582 memcpy(priv
->bssid
, bss_conf
->bssid
, ETH_ALEN
);
2583 priv
->cfg
->ops
->legacy
->config_ap(priv
);
2585 iwl_legacy_set_no_assoc(priv
, vif
);
2588 if (changes
& BSS_CHANGED_IBSS
) {
2589 ret
= priv
->cfg
->ops
->legacy
->manage_ibss_station(priv
, vif
,
2590 bss_conf
->ibss_joined
);
2592 IWL_ERR(priv
, "failed to %s IBSS station %pM\n",
2593 bss_conf
->ibss_joined
? "add" : "remove",
2597 mutex_unlock(&priv
->mutex
);
2599 IWL_DEBUG_MAC80211(priv
, "leave\n");
2601 EXPORT_SYMBOL(iwl_legacy_mac_bss_info_changed
);
2603 irqreturn_t
iwl_legacy_isr(int irq
, void *data
)
2605 struct iwl_priv
*priv
= data
;
2606 u32 inta
, inta_mask
;
2608 unsigned long flags
;
2612 spin_lock_irqsave(&priv
->lock
, flags
);
2614 /* Disable (but don't clear!) interrupts here to avoid
2615 * back-to-back ISRs and sporadic interrupts from our NIC.
2616 * If we have something to service, the tasklet will re-enable ints.
2617 * If we *don't* have something, we'll re-enable before leaving here. */
2618 inta_mask
= iwl_read32(priv
, CSR_INT_MASK
); /* just for debug */
2619 iwl_write32(priv
, CSR_INT_MASK
, 0x00000000);
2621 /* Discover which interrupts are active/pending */
2622 inta
= iwl_read32(priv
, CSR_INT
);
2623 inta_fh
= iwl_read32(priv
, CSR_FH_INT_STATUS
);
2625 /* Ignore interrupt if there's nothing in NIC to service.
2626 * This may be due to IRQ shared with another device,
2627 * or due to sporadic interrupts thrown from our NIC. */
2628 if (!inta
&& !inta_fh
) {
2630 "Ignore interrupt, inta == 0, inta_fh == 0\n");
2634 if ((inta
== 0xFFFFFFFF) || ((inta
& 0xFFFFFFF0) == 0xa5a5a5a0)) {
2635 /* Hardware disappeared. It might have already raised
2637 IWL_WARN(priv
, "HARDWARE GONE?? INTA == 0x%08x\n", inta
);
2641 IWL_DEBUG_ISR(priv
, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
2642 inta
, inta_mask
, inta_fh
);
2644 inta
&= ~CSR_INT_BIT_SCD
;
2646 /* iwl_irq_tasklet() will service interrupts and re-enable them */
2647 if (likely(inta
|| inta_fh
))
2648 tasklet_schedule(&priv
->irq_tasklet
);
2651 spin_unlock_irqrestore(&priv
->lock
, flags
);
2655 /* re-enable interrupts here since we don't have anything to service. */
2656 /* only Re-enable if diabled by irq */
2657 if (test_bit(STATUS_INT_ENABLED
, &priv
->status
))
2658 iwl_legacy_enable_interrupts(priv
);
2659 spin_unlock_irqrestore(&priv
->lock
, flags
);
2662 EXPORT_SYMBOL(iwl_legacy_isr
);
2665 * iwl_legacy_tx_cmd_protection: Set rts/cts. 3945 and 4965 only share this
2668 void iwl_legacy_tx_cmd_protection(struct iwl_priv
*priv
,
2669 struct ieee80211_tx_info
*info
,
2670 __le16 fc
, __le32
*tx_flags
)
2672 if (info
->control
.rates
[0].flags
& IEEE80211_TX_RC_USE_RTS_CTS
) {
2673 *tx_flags
|= TX_CMD_FLG_RTS_MSK
;
2674 *tx_flags
&= ~TX_CMD_FLG_CTS_MSK
;
2675 *tx_flags
|= TX_CMD_FLG_FULL_TXOP_PROT_MSK
;
2677 if (!ieee80211_is_mgmt(fc
))
2680 switch (fc
& cpu_to_le16(IEEE80211_FCTL_STYPE
)) {
2681 case cpu_to_le16(IEEE80211_STYPE_AUTH
):
2682 case cpu_to_le16(IEEE80211_STYPE_DEAUTH
):
2683 case cpu_to_le16(IEEE80211_STYPE_ASSOC_REQ
):
2684 case cpu_to_le16(IEEE80211_STYPE_REASSOC_REQ
):
2685 *tx_flags
&= ~TX_CMD_FLG_RTS_MSK
;
2686 *tx_flags
|= TX_CMD_FLG_CTS_MSK
;
2689 } else if (info
->control
.rates
[0].flags
&
2690 IEEE80211_TX_RC_USE_CTS_PROTECT
) {
2691 *tx_flags
&= ~TX_CMD_FLG_RTS_MSK
;
2692 *tx_flags
|= TX_CMD_FLG_CTS_MSK
;
2693 *tx_flags
|= TX_CMD_FLG_FULL_TXOP_PROT_MSK
;
2696 EXPORT_SYMBOL(iwl_legacy_tx_cmd_protection
);