1 /******************************************************************************
3 * Copyright(c) 2003 - 2010 Intel Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * Intel Linux Wireless <ilw@linux.intel.com>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 *****************************************************************************/
31 #include "iwl-agn-calib.h"
33 static int iwlagn_disable_bss(struct iwl_priv
*priv
,
34 struct iwl_rxon_context
*ctx
,
35 struct iwl_rxon_cmd
*send
)
37 __le32 old_filter
= send
->filter_flags
;
40 send
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
41 ret
= iwl_send_cmd_pdu(priv
, ctx
->rxon_cmd
, sizeof(*send
), send
);
43 send
->filter_flags
= old_filter
;
46 IWL_ERR(priv
, "Error clearing ASSOC_MSK on BSS (%d)\n", ret
);
51 static int iwlagn_disable_pan(struct iwl_priv
*priv
,
52 struct iwl_rxon_context
*ctx
,
53 struct iwl_rxon_cmd
*send
)
55 __le32 old_filter
= send
->filter_flags
;
56 u8 old_dev_type
= send
->dev_type
;
59 send
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
60 send
->dev_type
= RXON_DEV_TYPE_P2P
;
61 ret
= iwl_send_cmd_pdu(priv
, ctx
->rxon_cmd
, sizeof(*send
), send
);
63 send
->filter_flags
= old_filter
;
64 send
->dev_type
= old_dev_type
;
67 IWL_ERR(priv
, "Error disabling PAN (%d)\n", ret
);
69 /* FIXME: WAIT FOR PAN DISABLE */
75 static int iwlagn_update_beacon(struct iwl_priv
*priv
,
76 struct ieee80211_vif
*vif
)
78 lockdep_assert_held(&priv
->mutex
);
80 dev_kfree_skb(priv
->beacon_skb
);
81 priv
->beacon_skb
= ieee80211_beacon_get(priv
->hw
, vif
);
82 if (!priv
->beacon_skb
)
84 return iwlagn_send_beacon_cmd(priv
);
88 * iwlagn_commit_rxon - commit staging_rxon to hardware
90 * The RXON command in staging_rxon is committed to the hardware and
91 * the active_rxon structure is updated with the new data. This
92 * function correctly transitions out of the RXON_ASSOC_MSK state if
93 * a HW tune is required based on the RXON structure changes.
95 int iwlagn_commit_rxon(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
97 /* cast away the const for active_rxon in this function */
98 struct iwl_rxon_cmd
*active
= (void *)&ctx
->active
;
99 bool old_assoc
= !!(ctx
->active
.filter_flags
& RXON_FILTER_ASSOC_MSK
);
100 bool new_assoc
= !!(ctx
->staging
.filter_flags
& RXON_FILTER_ASSOC_MSK
);
103 lockdep_assert_held(&priv
->mutex
);
105 if (!iwl_is_alive(priv
))
108 /* This function hardcodes a bunch of dual-mode assumptions */
109 BUILD_BUG_ON(NUM_IWL_RXON_CTX
!= 2);
114 /* always get timestamp with Rx frame */
115 ctx
->staging
.flags
|= RXON_FLG_TSF2HOST_MSK
;
117 if ((ctx
->vif
&& ctx
->vif
->bss_conf
.use_short_slot
) ||
118 !(ctx
->staging
.flags
& RXON_FLG_BAND_24G_MSK
))
119 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
121 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
123 ret
= iwl_check_rxon_cmd(priv
, ctx
);
125 IWL_ERR(priv
, "Invalid RXON configuration. Not committing.\n");
130 * receive commit_rxon request
131 * abort any previous channel switch if still in process
133 if (priv
->switch_rxon
.switch_in_progress
&&
134 (priv
->switch_rxon
.channel
!= ctx
->staging
.channel
)) {
135 IWL_DEBUG_11H(priv
, "abort channel switch on %d\n",
136 le16_to_cpu(priv
->switch_rxon
.channel
));
137 iwl_chswitch_done(priv
, false);
141 * If we don't need to send a full RXON, we can use
142 * iwl_rxon_assoc_cmd which is used to reconfigure filter
143 * and other flags for the current radio configuration.
145 if (!iwl_full_rxon_required(priv
, ctx
)) {
146 ret
= iwl_send_rxon_assoc(priv
, ctx
);
148 IWL_ERR(priv
, "Error setting RXON_ASSOC (%d)\n", ret
);
152 memcpy(active
, &ctx
->staging
, sizeof(*active
));
153 iwl_print_rx_config_cmd(priv
, ctx
);
157 if (priv
->cfg
->ops
->hcmd
->set_pan_params
) {
158 ret
= priv
->cfg
->ops
->hcmd
->set_pan_params(priv
);
163 iwl_set_rxon_hwcrypto(priv
, ctx
, !priv
->cfg
->mod_params
->sw_crypto
);
166 "Going to commit RXON\n"
167 " * with%s RXON_FILTER_ASSOC_MSK\n"
170 (new_assoc
? "" : "out"),
171 le16_to_cpu(ctx
->staging
.channel
),
172 ctx
->staging
.bssid_addr
);
175 * If we are currently associated and the new config is also
176 * going to be associated, OR if the new config is simply not
177 * associated, clear associated.
179 if ((old_assoc
&& new_assoc
) || !new_assoc
) {
180 struct iwl_rxon_cmd
*send
= active
;
183 send
= &ctx
->staging
;
185 if (ctx
->ctxid
== IWL_RXON_CTX_BSS
)
186 ret
= iwlagn_disable_bss(priv
, ctx
, send
);
188 ret
= iwlagn_disable_pan(priv
, ctx
, send
);
193 memcpy(active
, send
, sizeof(*active
));
196 * Un-assoc RXON clears the station table and WEP
197 * keys, so we have to restore those afterwards.
199 iwl_clear_ucode_stations(priv
, ctx
);
200 iwl_restore_stations(priv
, ctx
);
201 ret
= iwl_restore_default_wep_keys(priv
, ctx
);
203 IWL_ERR(priv
, "Failed to restore WEP keys (%d)\n", ret
);
208 /* RXON timing must be before associated RXON */
209 ret
= iwl_send_rxon_timing(priv
, ctx
);
211 IWL_ERR(priv
, "Failed to send timing (%d)!\n", ret
);
217 * We'll run into this code path when beaconing is
218 * enabled, but then we also need to send the beacon
221 if (ctx
->vif
&& (ctx
->vif
->type
== NL80211_IFTYPE_AP
)) {
222 ret
= iwlagn_update_beacon(priv
, ctx
->vif
);
225 "Error sending required beacon (%d)!\n",
231 priv
->start_calib
= 0;
233 * Apply the new configuration.
235 * Associated RXON doesn't clear the station table in uCode,
236 * so we don't need to restore stations etc. after this.
238 ret
= iwl_send_cmd_pdu(priv
, ctx
->rxon_cmd
,
239 sizeof(struct iwl_rxon_cmd
), &ctx
->staging
);
241 IWL_ERR(priv
, "Error setting new RXON (%d)\n", ret
);
244 memcpy(active
, &ctx
->staging
, sizeof(*active
));
246 /* IBSS beacon needs to be sent after setting assoc */
247 if (ctx
->vif
&& (ctx
->vif
->type
== NL80211_IFTYPE_ADHOC
))
248 if (iwlagn_update_beacon(priv
, ctx
->vif
))
249 IWL_ERR(priv
, "Error sending IBSS beacon\n");
252 iwl_print_rx_config_cmd(priv
, ctx
);
254 iwl_init_sensitivity(priv
);
257 * If we issue a new RXON command which required a tune then we must
258 * send a new TXPOWER command or we won't be able to Tx any frames.
260 * FIXME: which RXON requires a tune? Can we optimise this out in
263 ret
= iwl_set_tx_power(priv
, priv
->tx_power_user_lmt
, true);
265 IWL_ERR(priv
, "Error sending TX power (%d)\n", ret
);
272 int iwlagn_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
274 struct iwl_priv
*priv
= hw
->priv
;
275 struct iwl_rxon_context
*ctx
;
276 struct ieee80211_conf
*conf
= &hw
->conf
;
277 struct ieee80211_channel
*channel
= conf
->channel
;
278 const struct iwl_channel_info
*ch_info
;
281 IWL_DEBUG_MAC80211(priv
, "changed %#x", changed
);
283 mutex_lock(&priv
->mutex
);
285 if (unlikely(test_bit(STATUS_SCANNING
, &priv
->status
))) {
286 IWL_DEBUG_MAC80211(priv
, "leave - scanning\n");
290 if (!iwl_is_ready(priv
)) {
291 IWL_DEBUG_MAC80211(priv
, "leave - not ready\n");
295 if (changed
& (IEEE80211_CONF_CHANGE_SMPS
|
296 IEEE80211_CONF_CHANGE_CHANNEL
)) {
297 /* mac80211 uses static for non-HT which is what we want */
298 priv
->current_ht_config
.smps
= conf
->smps_mode
;
301 * Recalculate chain counts.
303 * If monitor mode is enabled then mac80211 will
304 * set up the SM PS mode to OFF if an HT channel is
307 if (priv
->cfg
->ops
->hcmd
->set_rxon_chain
)
308 for_each_context(priv
, ctx
)
309 priv
->cfg
->ops
->hcmd
->set_rxon_chain(priv
, ctx
);
312 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
315 ch_info
= iwl_get_channel_info(priv
, channel
->band
,
317 if (!is_channel_valid(ch_info
)) {
318 IWL_DEBUG_MAC80211(priv
, "leave - invalid channel\n");
323 spin_lock_irqsave(&priv
->lock
, flags
);
325 for_each_context(priv
, ctx
) {
326 /* Configure HT40 channels */
327 ctx
->ht
.enabled
= conf_is_ht(conf
);
328 if (ctx
->ht
.enabled
) {
329 if (conf_is_ht40_minus(conf
)) {
330 ctx
->ht
.extension_chan_offset
=
331 IEEE80211_HT_PARAM_CHA_SEC_BELOW
;
332 ctx
->ht
.is_40mhz
= true;
333 } else if (conf_is_ht40_plus(conf
)) {
334 ctx
->ht
.extension_chan_offset
=
335 IEEE80211_HT_PARAM_CHA_SEC_ABOVE
;
336 ctx
->ht
.is_40mhz
= true;
338 ctx
->ht
.extension_chan_offset
=
339 IEEE80211_HT_PARAM_CHA_SEC_NONE
;
340 ctx
->ht
.is_40mhz
= false;
343 ctx
->ht
.is_40mhz
= false;
346 * Default to no protection. Protection mode will
347 * later be set from BSS config in iwl_ht_conf
349 ctx
->ht
.protection
= IEEE80211_HT_OP_MODE_PROTECTION_NONE
;
351 /* if we are switching from ht to 2.4 clear flags
352 * from any ht related info since 2.4 does not
354 if (le16_to_cpu(ctx
->staging
.channel
) !=
356 ctx
->staging
.flags
= 0;
358 iwl_set_rxon_channel(priv
, channel
, ctx
);
359 iwl_set_rxon_ht(priv
, &priv
->current_ht_config
);
361 iwl_set_flags_for_band(priv
, ctx
, channel
->band
,
365 spin_unlock_irqrestore(&priv
->lock
, flags
);
367 iwl_update_bcast_stations(priv
);
370 * The list of supported rates and rate mask can be different
371 * for each band; since the band may have changed, reset
372 * the rate mask to what mac80211 lists.
377 if (changed
& (IEEE80211_CONF_CHANGE_PS
|
378 IEEE80211_CONF_CHANGE_IDLE
)) {
379 ret
= iwl_power_update_mode(priv
, false);
381 IWL_DEBUG_MAC80211(priv
, "Error setting sleep level\n");
384 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
385 IWL_DEBUG_MAC80211(priv
, "TX Power old=%d new=%d\n",
386 priv
->tx_power_user_lmt
, conf
->power_level
);
388 iwl_set_tx_power(priv
, conf
->power_level
, false);
391 for_each_context(priv
, ctx
) {
392 if (!memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
394 iwlagn_commit_rxon(priv
, ctx
);
397 mutex_unlock(&priv
->mutex
);
401 static void iwlagn_update_qos(struct iwl_priv
*priv
,
402 struct iwl_rxon_context
*ctx
)
409 ctx
->qos_data
.def_qos_parm
.qos_flags
= 0;
411 if (ctx
->qos_data
.qos_active
)
412 ctx
->qos_data
.def_qos_parm
.qos_flags
|=
413 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
416 ctx
->qos_data
.def_qos_parm
.qos_flags
|= QOS_PARAM_FLG_TGN_MSK
;
418 IWL_DEBUG_QOS(priv
, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
419 ctx
->qos_data
.qos_active
,
420 ctx
->qos_data
.def_qos_parm
.qos_flags
);
422 ret
= iwl_send_cmd_pdu(priv
, ctx
->qos_cmd
,
423 sizeof(struct iwl_qosparam_cmd
),
424 &ctx
->qos_data
.def_qos_parm
);
426 IWL_ERR(priv
, "Failed to update QoS\n");
429 static void iwlagn_check_needed_chains(struct iwl_priv
*priv
,
430 struct iwl_rxon_context
*ctx
,
431 struct ieee80211_bss_conf
*bss_conf
)
433 struct ieee80211_vif
*vif
= ctx
->vif
;
434 struct iwl_rxon_context
*tmp
;
435 struct ieee80211_sta
*sta
;
436 struct iwl_ht_config
*ht_conf
= &priv
->current_ht_config
;
439 lockdep_assert_held(&priv
->mutex
);
442 case NL80211_IFTYPE_STATION
:
444 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
446 struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
449 maxstreams
= (ht_cap
->mcs
.tx_params
&
450 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK
)
451 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT
;
454 if ((ht_cap
->mcs
.rx_mask
[1] == 0) &&
455 (ht_cap
->mcs
.rx_mask
[2] == 0))
456 need_multiple
= false;
458 need_multiple
= true;
461 * If at all, this can only happen through a race
462 * when the AP disconnects us while we're still
463 * setting up the connection, in that case mac80211
464 * will soon tell us about that.
466 need_multiple
= false;
470 case NL80211_IFTYPE_ADHOC
:
472 need_multiple
= false;
476 need_multiple
= true;
480 ctx
->ht_need_multiple_chains
= need_multiple
;
482 if (!need_multiple
) {
483 /* check all contexts */
484 for_each_context(priv
, tmp
) {
487 if (tmp
->ht_need_multiple_chains
) {
488 need_multiple
= true;
494 ht_conf
->single_chain_sufficient
= !need_multiple
;
497 void iwlagn_bss_info_changed(struct ieee80211_hw
*hw
,
498 struct ieee80211_vif
*vif
,
499 struct ieee80211_bss_conf
*bss_conf
,
502 struct iwl_priv
*priv
= hw
->priv
;
503 struct iwl_rxon_context
*ctx
= iwl_rxon_ctx_from_vif(vif
);
507 mutex_lock(&priv
->mutex
);
509 if (changes
& BSS_CHANGED_BEACON_INT
)
512 if (changes
& BSS_CHANGED_QOS
) {
513 ctx
->qos_data
.qos_active
= bss_conf
->qos
;
514 iwlagn_update_qos(priv
, ctx
);
517 ctx
->staging
.assoc_id
= cpu_to_le16(vif
->bss_conf
.aid
);
518 if (vif
->bss_conf
.use_short_preamble
)
519 ctx
->staging
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
521 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
523 if (changes
& BSS_CHANGED_ASSOC
) {
524 if (bss_conf
->assoc
) {
525 iwl_led_associate(priv
);
526 priv
->timestamp
= bss_conf
->timestamp
;
527 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
529 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
530 iwl_led_disassociate(priv
);
534 if (ctx
->ht
.enabled
) {
535 ctx
->ht
.protection
= bss_conf
->ht_operation_mode
&
536 IEEE80211_HT_OP_MODE_PROTECTION
;
537 ctx
->ht
.non_gf_sta_present
= !!(bss_conf
->ht_operation_mode
&
538 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
);
539 iwlagn_check_needed_chains(priv
, ctx
, bss_conf
);
542 if (priv
->cfg
->ops
->hcmd
->set_rxon_chain
)
543 priv
->cfg
->ops
->hcmd
->set_rxon_chain(priv
, ctx
);
545 if (bss_conf
->use_cts_prot
&& (priv
->band
!= IEEE80211_BAND_5GHZ
))
546 ctx
->staging
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
548 ctx
->staging
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
550 if (bss_conf
->use_cts_prot
)
551 ctx
->staging
.flags
|= RXON_FLG_SELF_CTS_EN
;
553 ctx
->staging
.flags
&= ~RXON_FLG_SELF_CTS_EN
;
555 memcpy(ctx
->staging
.bssid_addr
, bss_conf
->bssid
, ETH_ALEN
);
557 if (vif
->type
== NL80211_IFTYPE_AP
||
558 vif
->type
== NL80211_IFTYPE_ADHOC
) {
559 if (vif
->bss_conf
.enable_beacon
) {
560 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
561 priv
->beacon_ctx
= ctx
;
563 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
564 priv
->beacon_ctx
= NULL
;
568 if (force
|| memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
569 iwlagn_commit_rxon(priv
, ctx
);
571 if (changes
& BSS_CHANGED_IBSS
) {
572 ret
= iwlagn_manage_ibss_station(priv
, vif
,
573 bss_conf
->ibss_joined
);
575 IWL_ERR(priv
, "failed to %s IBSS station %pM\n",
576 bss_conf
->ibss_joined
? "add" : "remove",
580 if (changes
& BSS_CHANGED_BEACON
&& vif
->type
== NL80211_IFTYPE_ADHOC
&&
582 if (iwlagn_update_beacon(priv
, vif
))
583 IWL_ERR(priv
, "Error sending IBSS beacon\n");
586 mutex_unlock(&priv
->mutex
);
589 void iwlagn_post_scan(struct iwl_priv
*priv
)
591 struct iwl_rxon_context
*ctx
;
594 * Since setting the RXON may have been deferred while
595 * performing the scan, fire one off if needed
597 for_each_context(priv
, ctx
)
598 if (memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
599 iwlagn_commit_rxon(priv
, ctx
);
601 if (priv
->cfg
->ops
->hcmd
->set_pan_params
)
602 priv
->cfg
->ops
->hcmd
->set_pan_params(priv
);