1 /******************************************************************************
3 * Copyright(c) 2003 - 2014 Intel Corporation. All rights reserved.
4 * Copyright(c) 2015 Intel Deutschland GmbH
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of version 2 of the GNU General Public License as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 * The full GNU General Public License is included in this distribution in the
16 * file called LICENSE.
18 * Contact Information:
19 * Intel Linux Wireless <linuxwifi@intel.com>
20 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
22 *****************************************************************************/
24 #include <linux/etherdevice.h>
25 #include "iwl-trans.h"
26 #include "iwl-modparams.h"
32 * initialize rxon structure with default values from eeprom
34 void iwl_connection_init_rx_config(struct iwl_priv *priv,
35 struct iwl_rxon_context *ctx)
37 memset(&ctx->staging, 0, sizeof(ctx->staging));
40 ctx->staging.dev_type = ctx->unused_devtype;
42 switch (ctx->vif->type) {
43 case NL80211_IFTYPE_AP:
44 ctx->staging.dev_type = ctx->ap_devtype;
47 case NL80211_IFTYPE_STATION:
48 ctx->staging.dev_type = ctx->station_devtype;
49 ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
52 case NL80211_IFTYPE_ADHOC:
53 ctx->staging.dev_type = ctx->ibss_devtype;
54 ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
55 ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
56 RXON_FILTER_ACCEPT_GRP_MSK;
59 case NL80211_IFTYPE_MONITOR:
60 ctx->staging.dev_type = RXON_DEV_TYPE_SNIFFER;
64 IWL_ERR(priv, "Unsupported interface type %d\n",
70 /* TODO: Figure out when short_preamble would be set and cache from
72 if (!hw_to_local(priv->hw)->short_preamble)
73 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
75 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
78 ctx->staging.channel =
79 cpu_to_le16(priv->hw->conf.chandef.chan->hw_value);
80 priv->band = priv->hw->conf.chandef.chan->band;
82 iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
84 /* clear both MIX and PURE40 mode flag */
85 ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
86 RXON_FLG_CHANNEL_MODE_PURE_40);
88 memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
90 ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
91 ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
92 ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
95 static int iwlagn_disable_bss(struct iwl_priv *priv,
96 struct iwl_rxon_context *ctx,
97 struct iwl_rxon_cmd *send)
99 __le32 old_filter = send->filter_flags;
102 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
103 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
104 0, sizeof(*send), send);
106 send->filter_flags = old_filter;
109 IWL_DEBUG_QUIET_RFKILL(priv,
110 "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
115 static int iwlagn_disable_pan(struct iwl_priv *priv,
116 struct iwl_rxon_context *ctx,
117 struct iwl_rxon_cmd *send)
119 struct iwl_notification_wait disable_wait;
120 __le32 old_filter = send->filter_flags;
121 u8 old_dev_type = send->dev_type;
123 static const u16 deactivate_cmd[] = {
124 REPLY_WIPAN_DEACTIVATION_COMPLETE
127 iwl_init_notification_wait(&priv->notif_wait, &disable_wait,
128 deactivate_cmd, ARRAY_SIZE(deactivate_cmd),
131 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
132 send->dev_type = RXON_DEV_TYPE_P2P;
133 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
134 0, sizeof(*send), send);
136 send->filter_flags = old_filter;
137 send->dev_type = old_dev_type;
140 IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
141 iwl_remove_notification(&priv->notif_wait, &disable_wait);
143 ret = iwl_wait_notification(&priv->notif_wait,
146 IWL_ERR(priv, "Timed out waiting for PAN disable\n");
152 static int iwlagn_disconn_pan(struct iwl_priv *priv,
153 struct iwl_rxon_context *ctx,
154 struct iwl_rxon_cmd *send)
156 __le32 old_filter = send->filter_flags;
159 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
160 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, 0,
161 sizeof(*send), send);
163 send->filter_flags = old_filter;
168 static void iwlagn_update_qos(struct iwl_priv *priv,
169 struct iwl_rxon_context *ctx)
176 ctx->qos_data.def_qos_parm.qos_flags = 0;
178 if (ctx->qos_data.qos_active)
179 ctx->qos_data.def_qos_parm.qos_flags |=
180 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
183 ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
185 IWL_DEBUG_INFO(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
186 ctx->qos_data.qos_active,
187 ctx->qos_data.def_qos_parm.qos_flags);
189 ret = iwl_dvm_send_cmd_pdu(priv, ctx->qos_cmd, 0,
190 sizeof(struct iwl_qosparam_cmd),
191 &ctx->qos_data.def_qos_parm);
193 IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n");
196 static int iwlagn_update_beacon(struct iwl_priv *priv,
197 struct ieee80211_vif *vif)
199 lockdep_assert_held(&priv->mutex);
201 dev_kfree_skb(priv->beacon_skb);
202 priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif);
203 if (!priv->beacon_skb)
205 return iwlagn_send_beacon_cmd(priv);
208 static int iwlagn_send_rxon_assoc(struct iwl_priv *priv,
209 struct iwl_rxon_context *ctx)
212 struct iwl_rxon_assoc_cmd rxon_assoc;
213 const struct iwl_rxon_cmd *rxon1 = &ctx->staging;
214 const struct iwl_rxon_cmd *rxon2 = &ctx->active;
216 if ((rxon1->flags == rxon2->flags) &&
217 (rxon1->filter_flags == rxon2->filter_flags) &&
218 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
219 (rxon1->ofdm_ht_single_stream_basic_rates ==
220 rxon2->ofdm_ht_single_stream_basic_rates) &&
221 (rxon1->ofdm_ht_dual_stream_basic_rates ==
222 rxon2->ofdm_ht_dual_stream_basic_rates) &&
223 (rxon1->ofdm_ht_triple_stream_basic_rates ==
224 rxon2->ofdm_ht_triple_stream_basic_rates) &&
225 (rxon1->acquisition_data == rxon2->acquisition_data) &&
226 (rxon1->rx_chain == rxon2->rx_chain) &&
227 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
228 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
232 rxon_assoc.flags = ctx->staging.flags;
233 rxon_assoc.filter_flags = ctx->staging.filter_flags;
234 rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
235 rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
236 rxon_assoc.reserved1 = 0;
237 rxon_assoc.reserved2 = 0;
238 rxon_assoc.reserved3 = 0;
239 rxon_assoc.ofdm_ht_single_stream_basic_rates =
240 ctx->staging.ofdm_ht_single_stream_basic_rates;
241 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
242 ctx->staging.ofdm_ht_dual_stream_basic_rates;
243 rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain;
244 rxon_assoc.ofdm_ht_triple_stream_basic_rates =
245 ctx->staging.ofdm_ht_triple_stream_basic_rates;
246 rxon_assoc.acquisition_data = ctx->staging.acquisition_data;
248 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_assoc_cmd,
249 CMD_ASYNC, sizeof(rxon_assoc), &rxon_assoc);
253 static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
259 * If mac80211 hasn't given us a beacon interval, program
260 * the default into the device (not checking this here
261 * would cause the adjustment below to return the maximum
262 * value, which may break PAN.)
265 return DEFAULT_BEACON_INTERVAL;
268 * If the beacon interval we obtained from the peer
269 * is too large, we'll have to wake up more often
270 * (and in IBSS case, we'll beacon too much)
272 * For example, if max_beacon_val is 4096, and the
273 * requested beacon interval is 7000, we'll have to
274 * use 3500 to be able to wake up on the beacons.
276 * This could badly influence beacon detection stats.
279 beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
280 new_val = beacon_val / beacon_factor;
283 new_val = max_beacon_val;
288 static int iwl_send_rxon_timing(struct iwl_priv *priv,
289 struct iwl_rxon_context *ctx)
292 s32 interval_tm, rem;
293 struct ieee80211_conf *conf = NULL;
295 struct ieee80211_vif *vif = ctx->vif;
297 conf = &priv->hw->conf;
299 lockdep_assert_held(&priv->mutex);
301 memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd));
303 ctx->timing.timestamp = cpu_to_le64(priv->timestamp);
304 ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
306 beacon_int = vif ? vif->bss_conf.beacon_int : 0;
309 * TODO: For IBSS we need to get atim_window from mac80211,
310 * for now just always use 0
312 ctx->timing.atim_window = 0;
314 if (ctx->ctxid == IWL_RXON_CTX_PAN &&
315 (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) &&
316 iwl_is_associated(priv, IWL_RXON_CTX_BSS) &&
317 priv->contexts[IWL_RXON_CTX_BSS].vif &&
318 priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) {
319 ctx->timing.beacon_interval =
320 priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval;
321 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
322 } else if (ctx->ctxid == IWL_RXON_CTX_BSS &&
323 iwl_is_associated(priv, IWL_RXON_CTX_PAN) &&
324 priv->contexts[IWL_RXON_CTX_PAN].vif &&
325 priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int &&
326 (!iwl_is_associated_ctx(ctx) || !ctx->vif ||
327 !ctx->vif->bss_conf.beacon_int)) {
328 ctx->timing.beacon_interval =
329 priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval;
330 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
332 beacon_int = iwl_adjust_beacon_interval(beacon_int,
333 IWL_MAX_UCODE_BEACON_INTERVAL * TIME_UNIT);
334 ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
337 ctx->beacon_int = beacon_int;
339 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
340 interval_tm = beacon_int * TIME_UNIT;
341 rem = do_div(tsf, interval_tm);
342 ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
344 ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
346 IWL_DEBUG_ASSOC(priv,
347 "beacon interval %d beacon timer %d beacon tim %d\n",
348 le16_to_cpu(ctx->timing.beacon_interval),
349 le32_to_cpu(ctx->timing.beacon_init_val),
350 le16_to_cpu(ctx->timing.atim_window));
352 return iwl_dvm_send_cmd_pdu(priv, ctx->rxon_timing_cmd,
353 0, sizeof(ctx->timing), &ctx->timing);
356 static int iwlagn_rxon_disconn(struct iwl_priv *priv,
357 struct iwl_rxon_context *ctx)
360 struct iwl_rxon_cmd *active = (void *)&ctx->active;
362 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
363 ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
365 ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
369 ret = iwl_send_rxon_timing(priv, ctx);
371 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
374 ret = iwlagn_disconn_pan(priv, ctx, &ctx->staging);
381 * Un-assoc RXON clears the station table and WEP
382 * keys, so we have to restore those afterwards.
384 iwl_clear_ucode_stations(priv, ctx);
385 /* update -- might need P2P now */
386 iwl_update_bcast_station(priv, ctx);
387 iwl_restore_stations(priv, ctx);
388 ret = iwl_restore_default_wep_keys(priv, ctx);
390 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
394 memcpy(active, &ctx->staging, sizeof(*active));
398 static int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
403 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
405 if (priv->calib_disabled & IWL_TX_POWER_CALIB_DISABLED)
408 lockdep_assert_held(&priv->mutex);
410 if (priv->tx_power_user_lmt == tx_power && !force)
413 if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
415 "Requested user TXPOWER %d below lower limit %d.\n",
417 IWLAGN_TX_POWER_TARGET_POWER_MIN);
421 if (tx_power > DIV_ROUND_UP(priv->nvm_data->max_tx_pwr_half_dbm, 2)) {
423 "Requested user TXPOWER %d above upper limit %d.\n",
424 tx_power, priv->nvm_data->max_tx_pwr_half_dbm);
428 if (!iwl_is_ready_rf(priv))
431 /* scan complete and commit_rxon use tx_power_next value,
432 * it always need to be updated for newest request */
433 priv->tx_power_next = tx_power;
435 /* do not set tx power when scanning or channel changing */
436 defer = test_bit(STATUS_SCANNING, &priv->status) ||
437 memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging));
438 if (defer && !force) {
439 IWL_DEBUG_INFO(priv, "Deferring tx power set\n");
443 prev_tx_power = priv->tx_power_user_lmt;
444 priv->tx_power_user_lmt = tx_power;
446 ret = iwlagn_send_tx_power(priv);
448 /* if fail to set tx_power, restore the orig. tx power */
450 priv->tx_power_user_lmt = prev_tx_power;
451 priv->tx_power_next = prev_tx_power;
456 static int iwlagn_rxon_connect(struct iwl_priv *priv,
457 struct iwl_rxon_context *ctx)
460 struct iwl_rxon_cmd *active = (void *)&ctx->active;
462 /* RXON timing must be before associated RXON */
463 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
464 ret = iwl_send_rxon_timing(priv, ctx);
466 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
470 /* QoS info may be cleared by previous un-assoc RXON */
471 iwlagn_update_qos(priv, ctx);
474 * We'll run into this code path when beaconing is
475 * enabled, but then we also need to send the beacon
478 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
479 ret = iwlagn_update_beacon(priv, ctx->vif);
482 "Error sending required beacon (%d)!\n",
488 priv->start_calib = 0;
490 * Apply the new configuration.
492 * Associated RXON doesn't clear the station table in uCode,
493 * so we don't need to restore stations etc. after this.
495 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, 0,
496 sizeof(struct iwl_rxon_cmd), &ctx->staging);
498 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
501 memcpy(active, &ctx->staging, sizeof(*active));
503 /* IBSS beacon needs to be sent after setting assoc */
504 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
505 if (iwlagn_update_beacon(priv, ctx->vif))
506 IWL_ERR(priv, "Error sending IBSS beacon\n");
507 iwl_init_sensitivity(priv);
510 * If we issue a new RXON command which required a tune then
511 * we must send a new TXPOWER command or we won't be able to
514 * It's expected we set power here if channel is changing.
516 ret = iwl_set_tx_power(priv, priv->tx_power_next, true);
518 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
525 int iwlagn_set_pan_params(struct iwl_priv *priv)
527 struct iwl_wipan_params_cmd cmd;
528 struct iwl_rxon_context *ctx_bss, *ctx_pan;
529 int slot0 = 300, slot1 = 0;
532 if (priv->valid_contexts == BIT(IWL_RXON_CTX_BSS))
535 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
537 lockdep_assert_held(&priv->mutex);
539 ctx_bss = &priv->contexts[IWL_RXON_CTX_BSS];
540 ctx_pan = &priv->contexts[IWL_RXON_CTX_PAN];
543 * If the PAN context is inactive, then we don't need
544 * to update the PAN parameters, the last thing we'll
545 * have done before it goes inactive is making the PAN
546 * parameters be WLAN-only.
548 if (!ctx_pan->is_active)
551 memset(&cmd, 0, sizeof(cmd));
553 /* only 2 slots are currently allowed */
556 cmd.slots[0].type = 0; /* BSS */
557 cmd.slots[1].type = 1; /* PAN */
559 if (ctx_bss->vif && ctx_pan->vif) {
560 int bcnint = ctx_pan->beacon_int;
561 int dtim = ctx_pan->vif->bss_conf.dtim_period ?: 1;
563 /* should be set, but seems unused?? */
564 cmd.flags |= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE);
566 if (ctx_pan->vif->type == NL80211_IFTYPE_AP &&
568 bcnint != ctx_bss->beacon_int) {
570 "beacon intervals don't match (%d, %d)\n",
571 ctx_bss->beacon_int, ctx_pan->beacon_int);
573 bcnint = max_t(int, bcnint,
574 ctx_bss->beacon_int);
576 bcnint = DEFAULT_BEACON_INTERVAL;
578 slot1 = bcnint - slot0;
580 if (test_bit(STATUS_SCAN_HW, &priv->status) ||
581 (!ctx_bss->vif->bss_conf.idle &&
582 !ctx_bss->vif->bss_conf.assoc)) {
583 slot0 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
584 slot1 = IWL_MIN_SLOT_TIME;
585 } else if (!ctx_pan->vif->bss_conf.idle &&
586 !ctx_pan->vif->bss_conf.assoc) {
587 slot1 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
588 slot0 = IWL_MIN_SLOT_TIME;
590 } else if (ctx_pan->vif) {
592 slot1 = max_t(int, 1, ctx_pan->vif->bss_conf.dtim_period) *
594 slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1);
596 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
597 slot0 = slot1 * 3 - IWL_MIN_SLOT_TIME;
598 slot1 = IWL_MIN_SLOT_TIME;
602 cmd.slots[0].width = cpu_to_le16(slot0);
603 cmd.slots[1].width = cpu_to_le16(slot1);
605 ret = iwl_dvm_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, 0,
608 IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret);
613 static void _iwl_set_rxon_ht(struct iwl_priv *priv,
614 struct iwl_ht_config *ht_conf,
615 struct iwl_rxon_context *ctx)
617 struct iwl_rxon_cmd *rxon = &ctx->staging;
619 if (!ctx->ht.enabled) {
620 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
621 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
622 RXON_FLG_HT40_PROT_MSK |
623 RXON_FLG_HT_PROT_MSK);
627 /* FIXME: if the definition of ht.protection changed, the "translation"
628 * will be needed for rxon->flags
630 rxon->flags |= cpu_to_le32(ctx->ht.protection <<
631 RXON_FLG_HT_OPERATING_MODE_POS);
633 /* Set up channel bandwidth:
634 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
635 /* clear the HT channel mode before set the mode */
636 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
637 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
638 if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
640 if (ctx->ht.protection ==
641 IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
642 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
644 * Note: control channel is opposite of extension
647 switch (ctx->ht.extension_chan_offset) {
648 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
650 ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
652 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
654 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
659 * Note: control channel is opposite of extension
662 switch (ctx->ht.extension_chan_offset) {
663 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
665 ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
666 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
668 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
669 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
670 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
672 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
675 * channel location only valid if in Mixed
679 "invalid extension channel offset\n");
684 rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
687 iwlagn_set_rxon_chain(priv, ctx);
689 IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
690 "extension channel offset 0x%x\n",
691 le32_to_cpu(rxon->flags), ctx->ht.protection,
692 ctx->ht.extension_chan_offset);
695 void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
697 struct iwl_rxon_context *ctx;
699 for_each_context(priv, ctx)
700 _iwl_set_rxon_ht(priv, ht_conf, ctx);
704 * iwl_set_rxon_channel - Set the band and channel values in staging RXON
705 * @ch: requested channel as a pointer to struct ieee80211_channel
707 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
708 * in the staging RXON flag structure based on the ch->band
710 void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
711 struct iwl_rxon_context *ctx)
713 enum nl80211_band band = ch->band;
714 u16 channel = ch->hw_value;
716 if ((le16_to_cpu(ctx->staging.channel) == channel) &&
717 (priv->band == band))
720 ctx->staging.channel = cpu_to_le16(channel);
721 if (band == NL80211_BAND_5GHZ)
722 ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
724 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
728 IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
732 void iwl_set_flags_for_band(struct iwl_priv *priv,
733 struct iwl_rxon_context *ctx,
734 enum nl80211_band band,
735 struct ieee80211_vif *vif)
737 if (band == NL80211_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;
755 static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv,
756 struct iwl_rxon_context *ctx, int hw_decrypt)
758 struct iwl_rxon_cmd *rxon = &ctx->staging;
761 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
763 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
767 /* validate RXON structure is valid */
768 static int iwl_check_rxon_cmd(struct iwl_priv *priv,
769 struct iwl_rxon_context *ctx)
771 struct iwl_rxon_cmd *rxon = &ctx->staging;
774 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
775 if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) {
776 IWL_WARN(priv, "check 2.4G: wrong narrow\n");
779 if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) {
780 IWL_WARN(priv, "check 2.4G: wrong radar\n");
784 if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) {
785 IWL_WARN(priv, "check 5.2G: not short slot!\n");
788 if (rxon->flags & RXON_FLG_CCK_MSK) {
789 IWL_WARN(priv, "check 5.2G: CCK!\n");
793 if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) {
794 IWL_WARN(priv, "mac/bssid mcast!\n");
798 /* make sure basic rates 6Mbps and 1Mbps are supported */
799 if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 &&
800 (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) {
801 IWL_WARN(priv, "neither 1 nor 6 are basic\n");
805 if (le16_to_cpu(rxon->assoc_id) > 2007) {
806 IWL_WARN(priv, "aid > 2007\n");
810 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
811 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) {
812 IWL_WARN(priv, "CCK and short slot\n");
816 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
817 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) {
818 IWL_WARN(priv, "CCK and auto detect\n");
822 if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
823 RXON_FLG_TGG_PROTECT_MSK)) ==
824 RXON_FLG_TGG_PROTECT_MSK) {
825 IWL_WARN(priv, "TGg but no auto-detect\n");
829 if (rxon->channel == 0) {
830 IWL_WARN(priv, "zero channel is invalid\n");
834 WARN(errors, "Invalid RXON (%#x), channel %d",
835 errors, le16_to_cpu(rxon->channel));
837 return errors ? -EINVAL : 0;
841 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
842 * @priv: staging_rxon is compared to active_rxon
844 * If the RXON structure is changing enough to require a new tune,
845 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
846 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
848 static int iwl_full_rxon_required(struct iwl_priv *priv,
849 struct iwl_rxon_context *ctx)
851 const struct iwl_rxon_cmd *staging = &ctx->staging;
852 const struct iwl_rxon_cmd *active = &ctx->active;
856 IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
860 #define CHK_NEQ(c1, c2) \
861 if ((c1) != (c2)) { \
862 IWL_DEBUG_INFO(priv, "need full RXON - " \
863 #c1 " != " #c2 " - %d != %d\n", \
868 /* These items are only settable from the full RXON command */
869 CHK(!iwl_is_associated_ctx(ctx));
870 CHK(!ether_addr_equal(staging->bssid_addr, active->bssid_addr));
871 CHK(!ether_addr_equal(staging->node_addr, active->node_addr));
872 CHK(!ether_addr_equal(staging->wlap_bssid_addr,
873 active->wlap_bssid_addr));
874 CHK_NEQ(staging->dev_type, active->dev_type);
875 CHK_NEQ(staging->channel, active->channel);
876 CHK_NEQ(staging->air_propagation, active->air_propagation);
877 CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
878 active->ofdm_ht_single_stream_basic_rates);
879 CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
880 active->ofdm_ht_dual_stream_basic_rates);
881 CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates,
882 active->ofdm_ht_triple_stream_basic_rates);
883 CHK_NEQ(staging->assoc_id, active->assoc_id);
885 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
886 * be updated with the RXON_ASSOC command -- however only some
887 * flag transitions are allowed using RXON_ASSOC */
889 /* Check if we are not switching bands */
890 CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
891 active->flags & RXON_FLG_BAND_24G_MSK);
893 /* Check if we are switching association toggle */
894 CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
895 active->filter_flags & RXON_FILTER_ASSOC_MSK);
903 #ifdef CONFIG_IWLWIFI_DEBUG
904 void iwl_print_rx_config_cmd(struct iwl_priv *priv,
905 enum iwl_rxon_context_id ctxid)
907 struct iwl_rxon_context *ctx = &priv->contexts[ctxid];
908 struct iwl_rxon_cmd *rxon = &ctx->staging;
910 IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
911 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
912 IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n",
913 le16_to_cpu(rxon->channel));
914 IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n",
915 le32_to_cpu(rxon->flags));
916 IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
917 le32_to_cpu(rxon->filter_flags));
918 IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
919 IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
920 rxon->ofdm_basic_rates);
921 IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n",
922 rxon->cck_basic_rates);
923 IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
924 IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
925 IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n",
926 le16_to_cpu(rxon->assoc_id));
930 static void iwl_calc_basic_rates(struct iwl_priv *priv,
931 struct iwl_rxon_context *ctx)
933 int lowest_present_ofdm = 100;
934 int lowest_present_cck = 100;
939 struct ieee80211_supported_band *sband;
940 unsigned long basic = ctx->vif->bss_conf.basic_rates;
943 sband = priv->hw->wiphy->bands[priv->hw->conf.chandef.chan->band];
945 for_each_set_bit(i, &basic, BITS_PER_LONG) {
946 int hw = sband->bitrates[i].hw_value;
947 if (hw >= IWL_FIRST_OFDM_RATE) {
948 ofdm |= BIT(hw - IWL_FIRST_OFDM_RATE);
949 if (lowest_present_ofdm > hw)
950 lowest_present_ofdm = hw;
952 BUILD_BUG_ON(IWL_FIRST_CCK_RATE != 0);
955 if (lowest_present_cck > hw)
956 lowest_present_cck = hw;
962 * Now we've got the basic rates as bitmaps in the ofdm and cck
963 * variables. This isn't sufficient though, as there might not
964 * be all the right rates in the bitmap. E.g. if the only basic
965 * rates are 5.5 Mbps and 11 Mbps, we still need to add 1 Mbps
966 * and 6 Mbps because the 802.11-2007 standard says in 9.6:
968 * [...] a STA responding to a received frame shall transmit
969 * its Control Response frame [...] at the highest rate in the
970 * BSSBasicRateSet parameter that is less than or equal to the
971 * rate of the immediately previous frame in the frame exchange
972 * sequence ([...]) and that is of the same modulation class
973 * ([...]) as the received frame. If no rate contained in the
974 * BSSBasicRateSet parameter meets these conditions, then the
975 * control frame sent in response to a received frame shall be
976 * transmitted at the highest mandatory rate of the PHY that is
977 * less than or equal to the rate of the received frame, and
978 * that is of the same modulation class as the received frame.
980 * As a consequence, we need to add all mandatory rates that are
981 * lower than all of the basic rates to these bitmaps.
984 if (IWL_RATE_24M_INDEX < lowest_present_ofdm)
985 ofdm |= IWL_RATE_24M_MASK >> IWL_FIRST_OFDM_RATE;
986 if (IWL_RATE_12M_INDEX < lowest_present_ofdm)
987 ofdm |= IWL_RATE_12M_MASK >> IWL_FIRST_OFDM_RATE;
988 /* 6M already there or needed so always add */
989 ofdm |= IWL_RATE_6M_MASK >> IWL_FIRST_OFDM_RATE;
992 * CCK is a bit more complex with DSSS vs. HR/DSSS vs. ERP.
994 * - if no CCK rates are basic, it must be ERP since there must
995 * be some basic rates at all, so they're OFDM => ERP PHY
996 * (or we're in 5 GHz, and the cck bitmap will never be used)
997 * - if 11M is a basic rate, it must be ERP as well, so add 5.5M
998 * - if 5.5M is basic, 1M and 2M are mandatory
999 * - if 2M is basic, 1M is mandatory
1000 * - if 1M is basic, that's the only valid ACK rate.
1001 * As a consequence, it's not as complicated as it sounds, just add
1002 * any lower rates to the ACK rate bitmap.
1004 if (IWL_RATE_11M_INDEX < lowest_present_cck)
1005 cck |= IWL_RATE_11M_MASK >> IWL_FIRST_CCK_RATE;
1006 if (IWL_RATE_5M_INDEX < lowest_present_cck)
1007 cck |= IWL_RATE_5M_MASK >> IWL_FIRST_CCK_RATE;
1008 if (IWL_RATE_2M_INDEX < lowest_present_cck)
1009 cck |= IWL_RATE_2M_MASK >> IWL_FIRST_CCK_RATE;
1010 /* 1M already there or needed so always add */
1011 cck |= IWL_RATE_1M_MASK >> IWL_FIRST_CCK_RATE;
1013 IWL_DEBUG_RATE(priv, "Set basic rates cck:0x%.2x ofdm:0x%.2x\n",
1016 /* "basic_rates" is a misnomer here -- should be called ACK rates */
1017 ctx->staging.cck_basic_rates = cck;
1018 ctx->staging.ofdm_basic_rates = ofdm;
1022 * iwlagn_commit_rxon - commit staging_rxon to hardware
1024 * The RXON command in staging_rxon is committed to the hardware and
1025 * the active_rxon structure is updated with the new data. This
1026 * function correctly transitions out of the RXON_ASSOC_MSK state if
1027 * a HW tune is required based on the RXON structure changes.
1029 * The connect/disconnect flow should be as the following:
1031 * 1. make sure send RXON command with association bit unset if not connect
1032 * this should include the channel and the band for the candidate
1033 * to be connected to
1034 * 2. Add Station before RXON association with the AP
1035 * 3. RXON_timing has to send before RXON for connection
1036 * 4. full RXON command - associated bit set
1037 * 5. use RXON_ASSOC command to update any flags changes
1039 int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
1041 /* cast away the const for active_rxon in this function */
1042 struct iwl_rxon_cmd *active = (void *)&ctx->active;
1043 bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
1046 lockdep_assert_held(&priv->mutex);
1048 if (!iwl_is_alive(priv))
1051 /* This function hardcodes a bunch of dual-mode assumptions */
1052 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
1054 if (!ctx->is_active)
1057 /* always get timestamp with Rx frame */
1058 ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
1060 /* recalculate basic rates */
1061 iwl_calc_basic_rates(priv, ctx);
1064 * force CTS-to-self frames protection if RTS-CTS is not preferred
1065 * one aggregation protection method
1067 if (!priv->hw_params.use_rts_for_aggregation)
1068 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
1070 if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
1071 !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
1072 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
1074 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1076 iwl_print_rx_config_cmd(priv, ctx->ctxid);
1077 ret = iwl_check_rxon_cmd(priv, ctx);
1079 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
1084 * receive commit_rxon request
1085 * abort any previous channel switch if still in process
1087 if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status) &&
1088 (priv->switch_channel != ctx->staging.channel)) {
1089 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
1090 le16_to_cpu(priv->switch_channel));
1091 iwl_chswitch_done(priv, false);
1095 * If we don't need to send a full RXON, we can use
1096 * iwl_rxon_assoc_cmd which is used to reconfigure filter
1097 * and other flags for the current radio configuration.
1099 if (!iwl_full_rxon_required(priv, ctx)) {
1100 ret = iwlagn_send_rxon_assoc(priv, ctx);
1102 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
1106 memcpy(active, &ctx->staging, sizeof(*active));
1108 * We do not commit tx power settings while channel changing,
1109 * do it now if after settings changed.
1111 iwl_set_tx_power(priv, priv->tx_power_next, false);
1113 /* make sure we are in the right PS state */
1114 iwl_power_update_mode(priv, true);
1119 iwl_set_rxon_hwcrypto(priv, ctx, !iwlwifi_mod_params.swcrypto);
1121 IWL_DEBUG_INFO(priv,
1122 "Going to commit RXON\n"
1123 " * with%s RXON_FILTER_ASSOC_MSK\n"
1126 (new_assoc ? "" : "out"),
1127 le16_to_cpu(ctx->staging.channel),
1128 ctx->staging.bssid_addr);
1131 * Always clear associated first, but with the correct config.
1132 * This is required as for example station addition for the
1133 * AP station must be done after the BSSID is set to correctly
1134 * set up filters in the device.
1136 ret = iwlagn_rxon_disconn(priv, ctx);
1140 ret = iwlagn_set_pan_params(priv);
1145 return iwlagn_rxon_connect(priv, ctx);
1150 void iwlagn_config_ht40(struct ieee80211_conf *conf,
1151 struct iwl_rxon_context *ctx)
1153 if (conf_is_ht40_minus(conf)) {
1154 ctx->ht.extension_chan_offset =
1155 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
1156 ctx->ht.is_40mhz = true;
1157 } else if (conf_is_ht40_plus(conf)) {
1158 ctx->ht.extension_chan_offset =
1159 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
1160 ctx->ht.is_40mhz = true;
1162 ctx->ht.extension_chan_offset =
1163 IEEE80211_HT_PARAM_CHA_SEC_NONE;
1164 ctx->ht.is_40mhz = false;
1168 int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
1170 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1171 struct iwl_rxon_context *ctx;
1172 struct ieee80211_conf *conf = &hw->conf;
1173 struct ieee80211_channel *channel = conf->chandef.chan;
1176 IWL_DEBUG_MAC80211(priv, "enter: changed %#x\n", changed);
1178 mutex_lock(&priv->mutex);
1180 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
1181 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
1185 if (!iwl_is_ready(priv)) {
1186 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
1190 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
1191 IEEE80211_CONF_CHANGE_CHANNEL)) {
1192 /* mac80211 uses static for non-HT which is what we want */
1193 priv->current_ht_config.smps = conf->smps_mode;
1196 * Recalculate chain counts.
1198 * If monitor mode is enabled then mac80211 will
1199 * set up the SM PS mode to OFF if an HT channel is
1202 for_each_context(priv, ctx)
1203 iwlagn_set_rxon_chain(priv, ctx);
1206 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1207 for_each_context(priv, ctx) {
1208 /* Configure HT40 channels */
1209 if (ctx->ht.enabled != conf_is_ht(conf))
1210 ctx->ht.enabled = conf_is_ht(conf);
1212 if (ctx->ht.enabled) {
1213 /* if HT40 is used, it should not change
1214 * after associated except channel switch */
1215 if (!ctx->ht.is_40mhz ||
1216 !iwl_is_associated_ctx(ctx))
1217 iwlagn_config_ht40(conf, ctx);
1219 ctx->ht.is_40mhz = false;
1222 * Default to no protection. Protection mode will
1223 * later be set from BSS config in iwl_ht_conf
1225 ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
1227 /* if we are switching from ht to 2.4 clear flags
1228 * from any ht related info since 2.4 does not
1230 if (le16_to_cpu(ctx->staging.channel) !=
1232 ctx->staging.flags = 0;
1234 iwl_set_rxon_channel(priv, channel, ctx);
1235 iwl_set_rxon_ht(priv, &priv->current_ht_config);
1237 iwl_set_flags_for_band(priv, ctx, channel->band,
1241 iwl_update_bcast_stations(priv);
1244 if (changed & (IEEE80211_CONF_CHANGE_PS |
1245 IEEE80211_CONF_CHANGE_IDLE)) {
1246 ret = iwl_power_update_mode(priv, false);
1248 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
1251 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1252 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
1253 priv->tx_power_user_lmt, conf->power_level);
1255 iwl_set_tx_power(priv, conf->power_level, false);
1258 for_each_context(priv, ctx) {
1259 if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1261 iwlagn_commit_rxon(priv, ctx);
1264 mutex_unlock(&priv->mutex);
1265 IWL_DEBUG_MAC80211(priv, "leave\n");
1270 static void iwlagn_check_needed_chains(struct iwl_priv *priv,
1271 struct iwl_rxon_context *ctx,
1272 struct ieee80211_bss_conf *bss_conf)
1274 struct ieee80211_vif *vif = ctx->vif;
1275 struct iwl_rxon_context *tmp;
1276 struct ieee80211_sta *sta;
1277 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
1278 struct ieee80211_sta_ht_cap *ht_cap;
1281 lockdep_assert_held(&priv->mutex);
1283 switch (vif->type) {
1284 case NL80211_IFTYPE_STATION:
1286 sta = ieee80211_find_sta(vif, bss_conf->bssid);
1289 * If at all, this can only happen through a race
1290 * when the AP disconnects us while we're still
1291 * setting up the connection, in that case mac80211
1292 * will soon tell us about that.
1294 need_multiple = false;
1299 ht_cap = &sta->ht_cap;
1301 need_multiple = true;
1304 * If the peer advertises no support for receiving 2 and 3
1305 * stream MCS rates, it can't be transmitting them either.
1307 if (ht_cap->mcs.rx_mask[1] == 0 &&
1308 ht_cap->mcs.rx_mask[2] == 0) {
1309 need_multiple = false;
1310 } else if (!(ht_cap->mcs.tx_params &
1311 IEEE80211_HT_MCS_TX_DEFINED)) {
1312 /* If it can't TX MCS at all ... */
1313 need_multiple = false;
1314 } else if (ht_cap->mcs.tx_params &
1315 IEEE80211_HT_MCS_TX_RX_DIFF) {
1319 * But if it can receive them, it might still not
1320 * be able to transmit them, which is what we need
1321 * to check here -- so check the number of streams
1322 * it advertises for TX (if different from RX).
1325 maxstreams = (ht_cap->mcs.tx_params &
1326 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK);
1328 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1331 if (maxstreams <= 1)
1332 need_multiple = false;
1337 case NL80211_IFTYPE_ADHOC:
1339 need_multiple = false;
1342 /* only AP really */
1343 need_multiple = true;
1347 ctx->ht_need_multiple_chains = need_multiple;
1349 if (!need_multiple) {
1350 /* check all contexts */
1351 for_each_context(priv, tmp) {
1354 if (tmp->ht_need_multiple_chains) {
1355 need_multiple = true;
1361 ht_conf->single_chain_sufficient = !need_multiple;
1364 static void iwlagn_chain_noise_reset(struct iwl_priv *priv)
1366 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
1369 if (priv->calib_disabled & IWL_CHAIN_NOISE_CALIB_DISABLED)
1372 if ((data->state == IWL_CHAIN_NOISE_ALIVE) &&
1373 iwl_is_any_associated(priv)) {
1374 struct iwl_calib_chain_noise_reset_cmd cmd;
1376 /* clear data for chain noise calibration algorithm */
1377 data->chain_noise_a = 0;
1378 data->chain_noise_b = 0;
1379 data->chain_noise_c = 0;
1380 data->chain_signal_a = 0;
1381 data->chain_signal_b = 0;
1382 data->chain_signal_c = 0;
1383 data->beacon_count = 0;
1385 memset(&cmd, 0, sizeof(cmd));
1386 iwl_set_calib_hdr(&cmd.hdr,
1387 priv->phy_calib_chain_noise_reset_cmd);
1388 ret = iwl_dvm_send_cmd_pdu(priv,
1389 REPLY_PHY_CALIBRATION_CMD,
1390 0, sizeof(cmd), &cmd);
1393 "Could not send REPLY_PHY_CALIBRATION_CMD\n");
1394 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
1395 IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n");
1399 void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
1400 struct ieee80211_vif *vif,
1401 struct ieee80211_bss_conf *bss_conf,
1404 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1405 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1409 mutex_lock(&priv->mutex);
1411 if (changes & BSS_CHANGED_IDLE && bss_conf->idle) {
1413 * If we go idle, then clearly no "passive-no-rx"
1414 * workaround is needed any more, this is a reset.
1416 iwlagn_lift_passive_no_rx(priv);
1419 if (unlikely(!iwl_is_ready(priv))) {
1420 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
1421 mutex_unlock(&priv->mutex);
1425 if (unlikely(!ctx->vif)) {
1426 IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n");
1427 mutex_unlock(&priv->mutex);
1431 if (changes & BSS_CHANGED_BEACON_INT)
1434 if (changes & BSS_CHANGED_QOS) {
1435 ctx->qos_data.qos_active = bss_conf->qos;
1436 iwlagn_update_qos(priv, ctx);
1439 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
1440 if (vif->bss_conf.use_short_preamble)
1441 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1443 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1445 if (changes & BSS_CHANGED_ASSOC) {
1446 if (bss_conf->assoc) {
1447 priv->timestamp = bss_conf->sync_tsf;
1448 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
1450 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1452 if (ctx->ctxid == IWL_RXON_CTX_BSS)
1453 priv->have_rekey_data = false;
1456 iwlagn_bt_coex_rssi_monitor(priv);
1459 if (ctx->ht.enabled) {
1460 ctx->ht.protection = bss_conf->ht_operation_mode &
1461 IEEE80211_HT_OP_MODE_PROTECTION;
1462 ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
1463 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1464 iwlagn_check_needed_chains(priv, ctx, bss_conf);
1465 iwl_set_rxon_ht(priv, &priv->current_ht_config);
1468 iwlagn_set_rxon_chain(priv, ctx);
1470 if (bss_conf->use_cts_prot && (priv->band != NL80211_BAND_5GHZ))
1471 ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
1473 ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
1475 if (bss_conf->use_cts_prot)
1476 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
1478 ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
1480 memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
1482 if (vif->type == NL80211_IFTYPE_AP ||
1483 vif->type == NL80211_IFTYPE_ADHOC) {
1484 if (vif->bss_conf.enable_beacon) {
1485 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
1486 priv->beacon_ctx = ctx;
1488 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1489 priv->beacon_ctx = NULL;
1494 * If the ucode decides to do beacon filtering before
1495 * association, it will lose beacons that are needed
1496 * before sending frames out on passive channels. This
1497 * causes association failures on those channels. Enable
1498 * receiving beacons in such cases.
1501 if (vif->type == NL80211_IFTYPE_STATION) {
1502 if (!bss_conf->assoc)
1503 ctx->staging.filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
1505 ctx->staging.filter_flags &=
1506 ~RXON_FILTER_BCON_AWARE_MSK;
1509 if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1510 iwlagn_commit_rxon(priv, ctx);
1512 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
1514 * The chain noise calibration will enable PM upon
1515 * completion. If calibration has already been run
1516 * then we need to enable power management here.
1518 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
1519 iwl_power_update_mode(priv, false);
1521 /* Enable RX differential gain and sensitivity calibrations */
1522 iwlagn_chain_noise_reset(priv);
1523 priv->start_calib = 1;
1526 if (changes & BSS_CHANGED_IBSS) {
1527 ret = iwlagn_manage_ibss_station(priv, vif,
1528 bss_conf->ibss_joined);
1530 IWL_ERR(priv, "failed to %s IBSS station %pM\n",
1531 bss_conf->ibss_joined ? "add" : "remove",
1535 if (changes & BSS_CHANGED_BEACON && priv->beacon_ctx == ctx) {
1536 if (iwlagn_update_beacon(priv, vif))
1537 IWL_ERR(priv, "Error updating beacon\n");
1540 mutex_unlock(&priv->mutex);
1543 void iwlagn_post_scan(struct iwl_priv *priv)
1545 struct iwl_rxon_context *ctx;
1548 * We do not commit power settings while scan is pending,
1549 * do it now if the settings changed.
1551 iwl_power_set_mode(priv, &priv->power_data.sleep_cmd_next, false);
1552 iwl_set_tx_power(priv, priv->tx_power_next, false);
1555 * Since setting the RXON may have been deferred while
1556 * performing the scan, fire one off if needed
1558 for_each_context(priv, ctx)
1559 if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1560 iwlagn_commit_rxon(priv, ctx);
1562 iwlagn_set_pan_params(priv);