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 void iwlagn_update_qos(struct iwl_priv
*priv
,
76 struct iwl_rxon_context
*ctx
)
83 ctx
->qos_data
.def_qos_parm
.qos_flags
= 0;
85 if (ctx
->qos_data
.qos_active
)
86 ctx
->qos_data
.def_qos_parm
.qos_flags
|=
87 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
90 ctx
->qos_data
.def_qos_parm
.qos_flags
|= QOS_PARAM_FLG_TGN_MSK
;
92 IWL_DEBUG_QOS(priv
, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
93 ctx
->qos_data
.qos_active
,
94 ctx
->qos_data
.def_qos_parm
.qos_flags
);
96 ret
= iwl_send_cmd_pdu(priv
, ctx
->qos_cmd
,
97 sizeof(struct iwl_qosparam_cmd
),
98 &ctx
->qos_data
.def_qos_parm
);
100 IWL_ERR(priv
, "Failed to update QoS\n");
103 static int iwlagn_update_beacon(struct iwl_priv
*priv
,
104 struct ieee80211_vif
*vif
)
106 lockdep_assert_held(&priv
->mutex
);
108 dev_kfree_skb(priv
->beacon_skb
);
109 priv
->beacon_skb
= ieee80211_beacon_get(priv
->hw
, vif
);
110 if (!priv
->beacon_skb
)
112 return iwlagn_send_beacon_cmd(priv
);
116 * iwlagn_commit_rxon - commit staging_rxon to hardware
118 * The RXON command in staging_rxon is committed to the hardware and
119 * the active_rxon structure is updated with the new data. This
120 * function correctly transitions out of the RXON_ASSOC_MSK state if
121 * a HW tune is required based on the RXON structure changes.
123 int iwlagn_commit_rxon(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
125 /* cast away the const for active_rxon in this function */
126 struct iwl_rxon_cmd
*active
= (void *)&ctx
->active
;
127 bool new_assoc
= !!(ctx
->staging
.filter_flags
& RXON_FILTER_ASSOC_MSK
);
128 bool old_assoc
= !!(ctx
->active
.filter_flags
& RXON_FILTER_ASSOC_MSK
);
131 lockdep_assert_held(&priv
->mutex
);
133 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
136 if (!iwl_is_alive(priv
))
139 /* This function hardcodes a bunch of dual-mode assumptions */
140 BUILD_BUG_ON(NUM_IWL_RXON_CTX
!= 2);
145 /* always get timestamp with Rx frame */
146 ctx
->staging
.flags
|= RXON_FLG_TSF2HOST_MSK
;
148 if ((ctx
->vif
&& ctx
->vif
->bss_conf
.use_short_slot
) ||
149 !(ctx
->staging
.flags
& RXON_FLG_BAND_24G_MSK
))
150 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
152 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
154 ret
= iwl_check_rxon_cmd(priv
, ctx
);
156 IWL_ERR(priv
, "Invalid RXON configuration. Not committing.\n");
161 * receive commit_rxon request
162 * abort any previous channel switch if still in process
164 if (priv
->switch_rxon
.switch_in_progress
&&
165 (priv
->switch_rxon
.channel
!= ctx
->staging
.channel
)) {
166 IWL_DEBUG_11H(priv
, "abort channel switch on %d\n",
167 le16_to_cpu(priv
->switch_rxon
.channel
));
168 iwl_chswitch_done(priv
, false);
172 * If we don't need to send a full RXON, we can use
173 * iwl_rxon_assoc_cmd which is used to reconfigure filter
174 * and other flags for the current radio configuration.
176 if (!iwl_full_rxon_required(priv
, ctx
)) {
177 ret
= iwl_send_rxon_assoc(priv
, ctx
);
179 IWL_ERR(priv
, "Error setting RXON_ASSOC (%d)\n", ret
);
183 memcpy(active
, &ctx
->staging
, sizeof(*active
));
184 iwl_print_rx_config_cmd(priv
, ctx
);
188 if (priv
->cfg
->ops
->hcmd
->set_pan_params
) {
189 ret
= priv
->cfg
->ops
->hcmd
->set_pan_params(priv
);
194 iwl_set_rxon_hwcrypto(priv
, ctx
, !priv
->cfg
->mod_params
->sw_crypto
);
197 "Going to commit RXON\n"
198 " * with%s RXON_FILTER_ASSOC_MSK\n"
201 (new_assoc
? "" : "out"),
202 le16_to_cpu(ctx
->staging
.channel
),
203 ctx
->staging
.bssid_addr
);
206 * Always clear associated first, but with the correct config.
207 * This is required as for example station addition for the
208 * AP station must be done after the BSSID is set to correctly
209 * set up filters in the device.
211 if ((old_assoc
&& new_assoc
) || !new_assoc
) {
212 if (ctx
->ctxid
== IWL_RXON_CTX_BSS
)
213 ret
= iwlagn_disable_bss(priv
, ctx
, &ctx
->staging
);
215 ret
= iwlagn_disable_pan(priv
, ctx
, &ctx
->staging
);
219 memcpy(active
, &ctx
->staging
, sizeof(*active
));
222 * Un-assoc RXON clears the station table and WEP
223 * keys, so we have to restore those afterwards.
225 iwl_clear_ucode_stations(priv
, ctx
);
226 iwl_restore_stations(priv
, ctx
);
227 ret
= iwl_restore_default_wep_keys(priv
, ctx
);
229 IWL_ERR(priv
, "Failed to restore WEP keys (%d)\n", ret
);
234 /* RXON timing must be before associated RXON */
235 ret
= iwl_send_rxon_timing(priv
, ctx
);
237 IWL_ERR(priv
, "Failed to send timing (%d)!\n", ret
);
242 /* QoS info may be cleared by previous un-assoc RXON */
243 iwlagn_update_qos(priv
, ctx
);
246 * We'll run into this code path when beaconing is
247 * enabled, but then we also need to send the beacon
250 if (ctx
->vif
&& (ctx
->vif
->type
== NL80211_IFTYPE_AP
)) {
251 ret
= iwlagn_update_beacon(priv
, ctx
->vif
);
254 "Error sending required beacon (%d)!\n",
260 priv
->start_calib
= 0;
262 * Apply the new configuration.
264 * Associated RXON doesn't clear the station table in uCode,
265 * so we don't need to restore stations etc. after this.
267 ret
= iwl_send_cmd_pdu(priv
, ctx
->rxon_cmd
,
268 sizeof(struct iwl_rxon_cmd
), &ctx
->staging
);
270 IWL_ERR(priv
, "Error setting new RXON (%d)\n", ret
);
273 memcpy(active
, &ctx
->staging
, sizeof(*active
));
275 iwl_reprogram_ap_sta(priv
, ctx
);
277 /* IBSS beacon needs to be sent after setting assoc */
278 if (ctx
->vif
&& (ctx
->vif
->type
== NL80211_IFTYPE_ADHOC
))
279 if (iwlagn_update_beacon(priv
, ctx
->vif
))
280 IWL_ERR(priv
, "Error sending IBSS beacon\n");
283 iwl_print_rx_config_cmd(priv
, ctx
);
285 iwl_init_sensitivity(priv
);
288 * If we issue a new RXON command which required a tune then we must
289 * send a new TXPOWER command or we won't be able to Tx any frames.
291 * FIXME: which RXON requires a tune? Can we optimise this out in
294 ret
= iwl_set_tx_power(priv
, priv
->tx_power_user_lmt
, true);
296 IWL_ERR(priv
, "Error sending TX power (%d)\n", ret
);
303 int iwlagn_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
305 struct iwl_priv
*priv
= hw
->priv
;
306 struct iwl_rxon_context
*ctx
;
307 struct ieee80211_conf
*conf
= &hw
->conf
;
308 struct ieee80211_channel
*channel
= conf
->channel
;
309 const struct iwl_channel_info
*ch_info
;
311 bool ht_changed
[NUM_IWL_RXON_CTX
] = {};
313 IWL_DEBUG_MAC80211(priv
, "changed %#x", changed
);
315 mutex_lock(&priv
->mutex
);
317 if (unlikely(test_bit(STATUS_SCANNING
, &priv
->status
))) {
318 IWL_DEBUG_MAC80211(priv
, "leave - scanning\n");
322 if (!iwl_is_ready(priv
)) {
323 IWL_DEBUG_MAC80211(priv
, "leave - not ready\n");
327 if (changed
& (IEEE80211_CONF_CHANGE_SMPS
|
328 IEEE80211_CONF_CHANGE_CHANNEL
)) {
329 /* mac80211 uses static for non-HT which is what we want */
330 priv
->current_ht_config
.smps
= conf
->smps_mode
;
333 * Recalculate chain counts.
335 * If monitor mode is enabled then mac80211 will
336 * set up the SM PS mode to OFF if an HT channel is
339 if (priv
->cfg
->ops
->hcmd
->set_rxon_chain
)
340 for_each_context(priv
, ctx
)
341 priv
->cfg
->ops
->hcmd
->set_rxon_chain(priv
, ctx
);
344 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
347 ch_info
= iwl_get_channel_info(priv
, channel
->band
,
349 if (!is_channel_valid(ch_info
)) {
350 IWL_DEBUG_MAC80211(priv
, "leave - invalid channel\n");
355 spin_lock_irqsave(&priv
->lock
, flags
);
357 for_each_context(priv
, ctx
) {
358 /* Configure HT40 channels */
359 if (ctx
->ht
.enabled
!= conf_is_ht(conf
)) {
360 ctx
->ht
.enabled
= conf_is_ht(conf
);
361 ht_changed
[ctx
->ctxid
] = true;
364 if (ctx
->ht
.enabled
) {
365 if (conf_is_ht40_minus(conf
)) {
366 ctx
->ht
.extension_chan_offset
=
367 IEEE80211_HT_PARAM_CHA_SEC_BELOW
;
368 ctx
->ht
.is_40mhz
= true;
369 } else if (conf_is_ht40_plus(conf
)) {
370 ctx
->ht
.extension_chan_offset
=
371 IEEE80211_HT_PARAM_CHA_SEC_ABOVE
;
372 ctx
->ht
.is_40mhz
= true;
374 ctx
->ht
.extension_chan_offset
=
375 IEEE80211_HT_PARAM_CHA_SEC_NONE
;
376 ctx
->ht
.is_40mhz
= false;
379 ctx
->ht
.is_40mhz
= false;
382 * Default to no protection. Protection mode will
383 * later be set from BSS config in iwl_ht_conf
385 ctx
->ht
.protection
= IEEE80211_HT_OP_MODE_PROTECTION_NONE
;
387 /* if we are switching from ht to 2.4 clear flags
388 * from any ht related info since 2.4 does not
390 if (le16_to_cpu(ctx
->staging
.channel
) !=
392 ctx
->staging
.flags
= 0;
394 iwl_set_rxon_channel(priv
, channel
, ctx
);
395 iwl_set_rxon_ht(priv
, &priv
->current_ht_config
);
397 iwl_set_flags_for_band(priv
, ctx
, channel
->band
,
401 spin_unlock_irqrestore(&priv
->lock
, flags
);
403 iwl_update_bcast_stations(priv
);
406 * The list of supported rates and rate mask can be different
407 * for each band; since the band may have changed, reset
408 * the rate mask to what mac80211 lists.
413 if (changed
& (IEEE80211_CONF_CHANGE_PS
|
414 IEEE80211_CONF_CHANGE_IDLE
)) {
415 ret
= iwl_power_update_mode(priv
, false);
417 IWL_DEBUG_MAC80211(priv
, "Error setting sleep level\n");
420 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
421 IWL_DEBUG_MAC80211(priv
, "TX Power old=%d new=%d\n",
422 priv
->tx_power_user_lmt
, conf
->power_level
);
424 iwl_set_tx_power(priv
, conf
->power_level
, false);
427 for_each_context(priv
, ctx
) {
428 if (!memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
430 iwlagn_commit_rxon(priv
, ctx
);
431 if (ht_changed
[ctx
->ctxid
])
432 iwlagn_update_qos(priv
, ctx
);
435 mutex_unlock(&priv
->mutex
);
439 static void iwlagn_check_needed_chains(struct iwl_priv
*priv
,
440 struct iwl_rxon_context
*ctx
,
441 struct ieee80211_bss_conf
*bss_conf
)
443 struct ieee80211_vif
*vif
= ctx
->vif
;
444 struct iwl_rxon_context
*tmp
;
445 struct ieee80211_sta
*sta
;
446 struct iwl_ht_config
*ht_conf
= &priv
->current_ht_config
;
449 lockdep_assert_held(&priv
->mutex
);
452 case NL80211_IFTYPE_STATION
:
454 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
456 struct ieee80211_sta_ht_cap
*ht_cap
= &sta
->ht_cap
;
459 maxstreams
= (ht_cap
->mcs
.tx_params
&
460 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK
)
461 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT
;
464 need_multiple
= true;
466 if ((ht_cap
->mcs
.rx_mask
[1] == 0) &&
467 (ht_cap
->mcs
.rx_mask
[2] == 0))
468 need_multiple
= false;
470 need_multiple
= false;
473 * If at all, this can only happen through a race
474 * when the AP disconnects us while we're still
475 * setting up the connection, in that case mac80211
476 * will soon tell us about that.
478 need_multiple
= false;
482 case NL80211_IFTYPE_ADHOC
:
484 need_multiple
= false;
488 need_multiple
= true;
492 ctx
->ht_need_multiple_chains
= need_multiple
;
494 if (!need_multiple
) {
495 /* check all contexts */
496 for_each_context(priv
, tmp
) {
499 if (tmp
->ht_need_multiple_chains
) {
500 need_multiple
= true;
506 ht_conf
->single_chain_sufficient
= !need_multiple
;
509 void iwlagn_bss_info_changed(struct ieee80211_hw
*hw
,
510 struct ieee80211_vif
*vif
,
511 struct ieee80211_bss_conf
*bss_conf
,
514 struct iwl_priv
*priv
= hw
->priv
;
515 struct iwl_rxon_context
*ctx
= iwl_rxon_ctx_from_vif(vif
);
519 mutex_lock(&priv
->mutex
);
521 if (unlikely(!iwl_is_ready(priv
))) {
522 IWL_DEBUG_MAC80211(priv
, "leave - not ready\n");
523 mutex_unlock(&priv
->mutex
);
527 if (unlikely(!ctx
->vif
)) {
528 IWL_DEBUG_MAC80211(priv
, "leave - vif is NULL\n");
529 mutex_unlock(&priv
->mutex
);
533 if (changes
& BSS_CHANGED_BEACON_INT
)
536 if (changes
& BSS_CHANGED_QOS
) {
537 ctx
->qos_data
.qos_active
= bss_conf
->qos
;
538 iwlagn_update_qos(priv
, ctx
);
541 ctx
->staging
.assoc_id
= cpu_to_le16(vif
->bss_conf
.aid
);
542 if (vif
->bss_conf
.use_short_preamble
)
543 ctx
->staging
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
545 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
547 if (changes
& BSS_CHANGED_ASSOC
) {
548 if (bss_conf
->assoc
) {
549 iwl_led_associate(priv
);
550 priv
->timestamp
= bss_conf
->timestamp
;
551 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
553 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
554 iwl_led_disassociate(priv
);
558 if (ctx
->ht
.enabled
) {
559 ctx
->ht
.protection
= bss_conf
->ht_operation_mode
&
560 IEEE80211_HT_OP_MODE_PROTECTION
;
561 ctx
->ht
.non_gf_sta_present
= !!(bss_conf
->ht_operation_mode
&
562 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
);
563 iwlagn_check_needed_chains(priv
, ctx
, bss_conf
);
564 iwl_set_rxon_ht(priv
, &priv
->current_ht_config
);
567 if (priv
->cfg
->ops
->hcmd
->set_rxon_chain
)
568 priv
->cfg
->ops
->hcmd
->set_rxon_chain(priv
, ctx
);
570 if (bss_conf
->use_cts_prot
&& (priv
->band
!= IEEE80211_BAND_5GHZ
))
571 ctx
->staging
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
573 ctx
->staging
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
575 if (bss_conf
->use_cts_prot
)
576 ctx
->staging
.flags
|= RXON_FLG_SELF_CTS_EN
;
578 ctx
->staging
.flags
&= ~RXON_FLG_SELF_CTS_EN
;
580 memcpy(ctx
->staging
.bssid_addr
, bss_conf
->bssid
, ETH_ALEN
);
582 if (vif
->type
== NL80211_IFTYPE_AP
||
583 vif
->type
== NL80211_IFTYPE_ADHOC
) {
584 if (vif
->bss_conf
.enable_beacon
) {
585 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
586 priv
->beacon_ctx
= ctx
;
588 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
589 priv
->beacon_ctx
= NULL
;
593 if (force
|| memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
594 iwlagn_commit_rxon(priv
, ctx
);
596 if (changes
& BSS_CHANGED_ASSOC
&& bss_conf
->assoc
) {
598 * The chain noise calibration will enable PM upon
599 * completion. If calibration has already been run
600 * then we need to enable power management here.
602 if (priv
->chain_noise_data
.state
== IWL_CHAIN_NOISE_DONE
)
603 iwl_power_update_mode(priv
, false);
605 /* Enable RX differential gain and sensitivity calibrations */
606 iwl_chain_noise_reset(priv
);
607 priv
->start_calib
= 1;
610 if (changes
& BSS_CHANGED_IBSS
) {
611 ret
= iwlagn_manage_ibss_station(priv
, vif
,
612 bss_conf
->ibss_joined
);
614 IWL_ERR(priv
, "failed to %s IBSS station %pM\n",
615 bss_conf
->ibss_joined
? "add" : "remove",
619 if (changes
& BSS_CHANGED_BEACON
&& vif
->type
== NL80211_IFTYPE_ADHOC
&&
621 if (iwlagn_update_beacon(priv
, vif
))
622 IWL_ERR(priv
, "Error sending IBSS beacon\n");
625 mutex_unlock(&priv
->mutex
);
628 void iwlagn_post_scan(struct iwl_priv
*priv
)
630 struct iwl_rxon_context
*ctx
;
633 * Since setting the RXON may have been deferred while
634 * performing the scan, fire one off if needed
636 for_each_context(priv
, ctx
)
637 if (memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
638 iwlagn_commit_rxon(priv
, ctx
);
640 if (priv
->cfg
->ops
->hcmd
->set_pan_params
)
641 priv
->cfg
->ops
->hcmd
->set_pan_params(priv
);