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 (!iwl_is_alive(priv))
136 /* This function hardcodes a bunch of dual-mode assumptions */
137 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
142 /* always get timestamp with Rx frame */
143 ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
145 if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
146 !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
147 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
149 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
151 ret = iwl_check_rxon_cmd(priv, ctx);
153 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
158 * receive commit_rxon request
159 * abort any previous channel switch if still in process
161 if (priv->switch_rxon.switch_in_progress &&
162 (priv->switch_rxon.channel != ctx->staging.channel)) {
163 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
164 le16_to_cpu(priv->switch_rxon.channel));
165 iwl_chswitch_done(priv, false);
169 * If we don't need to send a full RXON, we can use
170 * iwl_rxon_assoc_cmd which is used to reconfigure filter
171 * and other flags for the current radio configuration.
173 if (!iwl_full_rxon_required(priv, ctx)) {
174 ret = iwl_send_rxon_assoc(priv, ctx);
176 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
180 memcpy(active, &ctx->staging, sizeof(*active));
181 iwl_print_rx_config_cmd(priv, ctx);
185 if (priv->cfg->ops->hcmd->set_pan_params) {
186 ret = priv->cfg->ops->hcmd->set_pan_params(priv);
191 iwl_set_rxon_hwcrypto(priv, ctx, !priv->cfg->mod_params->sw_crypto);
194 "Going to commit RXON\n"
195 " * with%s RXON_FILTER_ASSOC_MSK\n"
198 (new_assoc ? "" : "out"),
199 le16_to_cpu(ctx->staging.channel),
200 ctx->staging.bssid_addr);
203 * Always clear associated first, but with the correct config.
204 * This is required as for example station addition for the
205 * AP station must be done after the BSSID is set to correctly
206 * set up filters in the device.
208 if ((old_assoc && new_assoc) || !new_assoc) {
209 if (ctx->ctxid == IWL_RXON_CTX_BSS)
210 ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
212 ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
216 memcpy(active, &ctx->staging, sizeof(*active));
219 * Un-assoc RXON clears the station table and WEP
220 * keys, so we have to restore those afterwards.
222 iwl_clear_ucode_stations(priv, ctx);
223 iwl_restore_stations(priv, ctx);
224 ret = iwl_restore_default_wep_keys(priv, ctx);
226 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
231 /* RXON timing must be before associated RXON */
232 ret = iwl_send_rxon_timing(priv, ctx);
234 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
239 /* QoS info may be cleared by previous un-assoc RXON */
240 iwlagn_update_qos(priv, ctx);
243 * We'll run into this code path when beaconing is
244 * enabled, but then we also need to send the beacon
247 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
248 ret = iwlagn_update_beacon(priv, ctx->vif);
251 "Error sending required beacon (%d)!\n",
257 priv->start_calib = 0;
259 * Apply the new configuration.
261 * Associated RXON doesn't clear the station table in uCode,
262 * so we don't need to restore stations etc. after this.
264 ret = iwl_send_cmd_pdu(priv, ctx->rxon_cmd,
265 sizeof(struct iwl_rxon_cmd), &ctx->staging);
267 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
270 memcpy(active, &ctx->staging, sizeof(*active));
272 iwl_reprogram_ap_sta(priv, ctx);
274 /* IBSS beacon needs to be sent after setting assoc */
275 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
276 if (iwlagn_update_beacon(priv, ctx->vif))
277 IWL_ERR(priv, "Error sending IBSS beacon\n");
280 iwl_print_rx_config_cmd(priv, ctx);
282 iwl_init_sensitivity(priv);
285 * If we issue a new RXON command which required a tune then we must
286 * send a new TXPOWER command or we won't be able to Tx any frames.
288 * FIXME: which RXON requires a tune? Can we optimise this out in
291 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
293 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
300 int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
302 struct iwl_priv *priv = hw->priv;
303 struct iwl_rxon_context *ctx;
304 struct ieee80211_conf *conf = &hw->conf;
305 struct ieee80211_channel *channel = conf->channel;
306 const struct iwl_channel_info *ch_info;
308 bool ht_changed[NUM_IWL_RXON_CTX] = {};
310 IWL_DEBUG_MAC80211(priv, "changed %#x", changed);
312 mutex_lock(&priv->mutex);
314 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
315 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
319 if (!iwl_is_ready(priv)) {
320 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
324 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
325 IEEE80211_CONF_CHANGE_CHANNEL)) {
326 /* mac80211 uses static for non-HT which is what we want */
327 priv->current_ht_config.smps = conf->smps_mode;
330 * Recalculate chain counts.
332 * If monitor mode is enabled then mac80211 will
333 * set up the SM PS mode to OFF if an HT channel is
336 if (priv->cfg->ops->hcmd->set_rxon_chain)
337 for_each_context(priv, ctx)
338 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
341 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
344 ch_info = iwl_get_channel_info(priv, channel->band,
346 if (!is_channel_valid(ch_info)) {
347 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
352 spin_lock_irqsave(&priv->lock, flags);
354 for_each_context(priv, ctx) {
355 /* Configure HT40 channels */
356 if (ctx->ht.enabled != conf_is_ht(conf)) {
357 ctx->ht.enabled = conf_is_ht(conf);
358 ht_changed[ctx->ctxid] = true;
361 if (ctx->ht.enabled) {
362 if (conf_is_ht40_minus(conf)) {
363 ctx->ht.extension_chan_offset =
364 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
365 ctx->ht.is_40mhz = true;
366 } else if (conf_is_ht40_plus(conf)) {
367 ctx->ht.extension_chan_offset =
368 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
369 ctx->ht.is_40mhz = true;
371 ctx->ht.extension_chan_offset =
372 IEEE80211_HT_PARAM_CHA_SEC_NONE;
373 ctx->ht.is_40mhz = false;
376 ctx->ht.is_40mhz = false;
379 * Default to no protection. Protection mode will
380 * later be set from BSS config in iwl_ht_conf
382 ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
384 /* if we are switching from ht to 2.4 clear flags
385 * from any ht related info since 2.4 does not
387 if (le16_to_cpu(ctx->staging.channel) !=
389 ctx->staging.flags = 0;
391 iwl_set_rxon_channel(priv, channel, ctx);
392 iwl_set_rxon_ht(priv, &priv->current_ht_config);
394 iwl_set_flags_for_band(priv, ctx, channel->band,
398 spin_unlock_irqrestore(&priv->lock, flags);
400 iwl_update_bcast_stations(priv);
403 * The list of supported rates and rate mask can be different
404 * for each band; since the band may have changed, reset
405 * the rate mask to what mac80211 lists.
410 if (changed & (IEEE80211_CONF_CHANGE_PS |
411 IEEE80211_CONF_CHANGE_IDLE)) {
412 ret = iwl_power_update_mode(priv, false);
414 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
417 if (changed & IEEE80211_CONF_CHANGE_POWER) {
418 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
419 priv->tx_power_user_lmt, conf->power_level);
421 iwl_set_tx_power(priv, conf->power_level, false);
424 for_each_context(priv, ctx) {
425 if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
427 iwlagn_commit_rxon(priv, ctx);
428 if (ht_changed[ctx->ctxid])
429 iwlagn_update_qos(priv, ctx);
432 mutex_unlock(&priv->mutex);
436 static void iwlagn_check_needed_chains(struct iwl_priv *priv,
437 struct iwl_rxon_context *ctx,
438 struct ieee80211_bss_conf *bss_conf)
440 struct ieee80211_vif *vif = ctx->vif;
441 struct iwl_rxon_context *tmp;
442 struct ieee80211_sta *sta;
443 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
446 lockdep_assert_held(&priv->mutex);
449 case NL80211_IFTYPE_STATION:
451 sta = ieee80211_find_sta(vif, bss_conf->bssid);
453 struct ieee80211_sta_ht_cap *ht_cap = &sta->ht_cap;
456 maxstreams = (ht_cap->mcs.tx_params &
457 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK)
458 >> IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
461 need_multiple = true;
463 if ((ht_cap->mcs.rx_mask[1] == 0) &&
464 (ht_cap->mcs.rx_mask[2] == 0))
465 need_multiple = false;
467 need_multiple = false;
470 * If at all, this can only happen through a race
471 * when the AP disconnects us while we're still
472 * setting up the connection, in that case mac80211
473 * will soon tell us about that.
475 need_multiple = false;
479 case NL80211_IFTYPE_ADHOC:
481 need_multiple = false;
485 need_multiple = true;
489 ctx->ht_need_multiple_chains = need_multiple;
491 if (!need_multiple) {
492 /* check all contexts */
493 for_each_context(priv, tmp) {
496 if (tmp->ht_need_multiple_chains) {
497 need_multiple = true;
503 ht_conf->single_chain_sufficient = !need_multiple;
506 void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
507 struct ieee80211_vif *vif,
508 struct ieee80211_bss_conf *bss_conf,
511 struct iwl_priv *priv = hw->priv;
512 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
516 mutex_lock(&priv->mutex);
518 if (WARN_ON(!ctx->vif)) {
519 mutex_unlock(&priv->mutex);
523 if (changes & BSS_CHANGED_BEACON_INT)
526 if (changes & BSS_CHANGED_QOS) {
527 ctx->qos_data.qos_active = bss_conf->qos;
528 iwlagn_update_qos(priv, ctx);
531 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
532 if (vif->bss_conf.use_short_preamble)
533 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
535 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
537 if (changes & BSS_CHANGED_ASSOC) {
538 if (bss_conf->assoc) {
539 iwl_led_associate(priv);
540 priv->timestamp = bss_conf->timestamp;
541 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
543 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
544 iwl_led_disassociate(priv);
548 if (ctx->ht.enabled) {
549 ctx->ht.protection = bss_conf->ht_operation_mode &
550 IEEE80211_HT_OP_MODE_PROTECTION;
551 ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
552 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
553 iwlagn_check_needed_chains(priv, ctx, bss_conf);
554 iwl_set_rxon_ht(priv, &priv->current_ht_config);
557 if (priv->cfg->ops->hcmd->set_rxon_chain)
558 priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
560 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
561 ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
563 ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
565 if (bss_conf->use_cts_prot)
566 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
568 ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
570 memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
572 if (vif->type == NL80211_IFTYPE_AP ||
573 vif->type == NL80211_IFTYPE_ADHOC) {
574 if (vif->bss_conf.enable_beacon) {
575 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
576 priv->beacon_ctx = ctx;
578 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
579 priv->beacon_ctx = NULL;
583 if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
584 iwlagn_commit_rxon(priv, ctx);
586 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
588 * The chain noise calibration will enable PM upon
589 * completion. If calibration has already been run
590 * then we need to enable power management here.
592 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
593 iwl_power_update_mode(priv, false);
595 /* Enable RX differential gain and sensitivity calibrations */
596 iwl_chain_noise_reset(priv);
597 priv->start_calib = 1;
600 if (changes & BSS_CHANGED_IBSS) {
601 ret = iwlagn_manage_ibss_station(priv, vif,
602 bss_conf->ibss_joined);
604 IWL_ERR(priv, "failed to %s IBSS station %pM\n",
605 bss_conf->ibss_joined ? "add" : "remove",
609 if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC &&
611 if (iwlagn_update_beacon(priv, vif))
612 IWL_ERR(priv, "Error sending IBSS beacon\n");
615 mutex_unlock(&priv->mutex);
618 void iwlagn_post_scan(struct iwl_priv *priv)
620 struct iwl_rxon_context *ctx;
623 * Since setting the RXON may have been deferred while
624 * performing the scan, fire one off if needed
626 for_each_context(priv, ctx)
627 if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
628 iwlagn_commit_rxon(priv, ctx);
630 if (priv->cfg->ops->hcmd->set_pan_params)
631 priv->cfg->ops->hcmd->set_pan_params(priv);