iwlwifi: Disabling calibrations variable
[linux-2.6.git] / drivers / net / wireless / iwlwifi / iwl-agn-rxon.c
blob88a7f3a1056c99997637f089f19547f1e716ebef
1 /******************************************************************************
3 * Copyright(c) 2003 - 2012 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
12 * more details.
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 *****************************************************************************/
27 #include <linux/etherdevice.h>
28 #include "iwl-dev.h"
29 #include "iwl-agn.h"
30 #include "iwl-core.h"
31 #include "iwl-agn-calib.h"
32 #include "iwl-trans.h"
33 #include "iwl-shared.h"
36 * initialize rxon structure with default values from eeprom
38 void iwl_connection_init_rx_config(struct iwl_priv *priv,
39 struct iwl_rxon_context *ctx)
41 const struct iwl_channel_info *ch_info;
43 memset(&ctx->staging, 0, sizeof(ctx->staging));
45 if (!ctx->vif) {
46 ctx->staging.dev_type = ctx->unused_devtype;
47 } else
48 switch (ctx->vif->type) {
49 case NL80211_IFTYPE_AP:
50 ctx->staging.dev_type = ctx->ap_devtype;
51 break;
53 case NL80211_IFTYPE_STATION:
54 ctx->staging.dev_type = ctx->station_devtype;
55 ctx->staging.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
56 break;
58 case NL80211_IFTYPE_ADHOC:
59 ctx->staging.dev_type = ctx->ibss_devtype;
60 ctx->staging.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
61 ctx->staging.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
62 RXON_FILTER_ACCEPT_GRP_MSK;
63 break;
65 default:
66 IWL_ERR(priv, "Unsupported interface type %d\n",
67 ctx->vif->type);
68 break;
71 #if 0
72 /* TODO: Figure out when short_preamble would be set and cache from
73 * that */
74 if (!hw_to_local(priv->hw)->short_preamble)
75 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
76 else
77 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
78 #endif
80 ch_info = iwl_get_channel_info(priv, priv->band,
81 le16_to_cpu(ctx->active.channel));
83 if (!ch_info)
84 ch_info = &priv->channel_info[0];
86 ctx->staging.channel = cpu_to_le16(ch_info->channel);
87 priv->band = ch_info->band;
89 iwl_set_flags_for_band(priv, ctx, priv->band, ctx->vif);
91 ctx->staging.ofdm_basic_rates =
92 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
93 ctx->staging.cck_basic_rates =
94 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
96 /* clear both MIX and PURE40 mode flag */
97 ctx->staging.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED |
98 RXON_FLG_CHANNEL_MODE_PURE_40);
99 if (ctx->vif)
100 memcpy(ctx->staging.node_addr, ctx->vif->addr, ETH_ALEN);
102 ctx->staging.ofdm_ht_single_stream_basic_rates = 0xff;
103 ctx->staging.ofdm_ht_dual_stream_basic_rates = 0xff;
104 ctx->staging.ofdm_ht_triple_stream_basic_rates = 0xff;
107 static int iwlagn_disable_bss(struct iwl_priv *priv,
108 struct iwl_rxon_context *ctx,
109 struct iwl_rxon_cmd *send)
111 __le32 old_filter = send->filter_flags;
112 int ret;
114 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
115 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
116 CMD_SYNC, sizeof(*send), send);
118 send->filter_flags = old_filter;
120 if (ret)
121 IWL_DEBUG_QUIET_RFKILL(priv,
122 "Error clearing ASSOC_MSK on BSS (%d)\n", ret);
124 return ret;
127 static int iwlagn_disable_pan(struct iwl_priv *priv,
128 struct iwl_rxon_context *ctx,
129 struct iwl_rxon_cmd *send)
131 struct iwl_notification_wait disable_wait;
132 __le32 old_filter = send->filter_flags;
133 u8 old_dev_type = send->dev_type;
134 int ret;
135 static const u8 deactivate_cmd[] = {
136 REPLY_WIPAN_DEACTIVATION_COMPLETE
139 iwl_init_notification_wait(&priv->notif_wait, &disable_wait,
140 deactivate_cmd, ARRAY_SIZE(deactivate_cmd),
141 NULL, NULL);
143 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
144 send->dev_type = RXON_DEV_TYPE_P2P;
145 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd,
146 CMD_SYNC, sizeof(*send), send);
148 send->filter_flags = old_filter;
149 send->dev_type = old_dev_type;
151 if (ret) {
152 IWL_ERR(priv, "Error disabling PAN (%d)\n", ret);
153 iwl_remove_notification(&priv->notif_wait, &disable_wait);
154 } else {
155 ret = iwl_wait_notification(&priv->notif_wait,
156 &disable_wait, HZ);
157 if (ret)
158 IWL_ERR(priv, "Timed out waiting for PAN disable\n");
161 return ret;
164 static int iwlagn_disconn_pan(struct iwl_priv *priv,
165 struct iwl_rxon_context *ctx,
166 struct iwl_rxon_cmd *send)
168 __le32 old_filter = send->filter_flags;
169 int ret;
171 send->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
172 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
173 sizeof(*send), send);
175 send->filter_flags = old_filter;
177 return ret;
180 static void iwlagn_update_qos(struct iwl_priv *priv,
181 struct iwl_rxon_context *ctx)
183 int ret;
185 if (!ctx->is_active)
186 return;
188 ctx->qos_data.def_qos_parm.qos_flags = 0;
190 if (ctx->qos_data.qos_active)
191 ctx->qos_data.def_qos_parm.qos_flags |=
192 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
194 if (ctx->ht.enabled)
195 ctx->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
197 IWL_DEBUG_INFO(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
198 ctx->qos_data.qos_active,
199 ctx->qos_data.def_qos_parm.qos_flags);
201 ret = iwl_dvm_send_cmd_pdu(priv, ctx->qos_cmd, CMD_SYNC,
202 sizeof(struct iwl_qosparam_cmd),
203 &ctx->qos_data.def_qos_parm);
204 if (ret)
205 IWL_DEBUG_QUIET_RFKILL(priv, "Failed to update QoS\n");
208 static int iwlagn_update_beacon(struct iwl_priv *priv,
209 struct ieee80211_vif *vif)
211 lockdep_assert_held(&priv->mutex);
213 dev_kfree_skb(priv->beacon_skb);
214 priv->beacon_skb = ieee80211_beacon_get(priv->hw, vif);
215 if (!priv->beacon_skb)
216 return -ENOMEM;
217 return iwlagn_send_beacon_cmd(priv);
220 static int iwlagn_send_rxon_assoc(struct iwl_priv *priv,
221 struct iwl_rxon_context *ctx)
223 int ret = 0;
224 struct iwl_rxon_assoc_cmd rxon_assoc;
225 const struct iwl_rxon_cmd *rxon1 = &ctx->staging;
226 const struct iwl_rxon_cmd *rxon2 = &ctx->active;
228 if ((rxon1->flags == rxon2->flags) &&
229 (rxon1->filter_flags == rxon2->filter_flags) &&
230 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
231 (rxon1->ofdm_ht_single_stream_basic_rates ==
232 rxon2->ofdm_ht_single_stream_basic_rates) &&
233 (rxon1->ofdm_ht_dual_stream_basic_rates ==
234 rxon2->ofdm_ht_dual_stream_basic_rates) &&
235 (rxon1->ofdm_ht_triple_stream_basic_rates ==
236 rxon2->ofdm_ht_triple_stream_basic_rates) &&
237 (rxon1->acquisition_data == rxon2->acquisition_data) &&
238 (rxon1->rx_chain == rxon2->rx_chain) &&
239 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
240 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
241 return 0;
244 rxon_assoc.flags = ctx->staging.flags;
245 rxon_assoc.filter_flags = ctx->staging.filter_flags;
246 rxon_assoc.ofdm_basic_rates = ctx->staging.ofdm_basic_rates;
247 rxon_assoc.cck_basic_rates = ctx->staging.cck_basic_rates;
248 rxon_assoc.reserved1 = 0;
249 rxon_assoc.reserved2 = 0;
250 rxon_assoc.reserved3 = 0;
251 rxon_assoc.ofdm_ht_single_stream_basic_rates =
252 ctx->staging.ofdm_ht_single_stream_basic_rates;
253 rxon_assoc.ofdm_ht_dual_stream_basic_rates =
254 ctx->staging.ofdm_ht_dual_stream_basic_rates;
255 rxon_assoc.rx_chain_select_flags = ctx->staging.rx_chain;
256 rxon_assoc.ofdm_ht_triple_stream_basic_rates =
257 ctx->staging.ofdm_ht_triple_stream_basic_rates;
258 rxon_assoc.acquisition_data = ctx->staging.acquisition_data;
260 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_assoc_cmd,
261 CMD_ASYNC, sizeof(rxon_assoc), &rxon_assoc);
262 return ret;
265 static u16 iwl_adjust_beacon_interval(u16 beacon_val, u16 max_beacon_val)
267 u16 new_val;
268 u16 beacon_factor;
271 * If mac80211 hasn't given us a beacon interval, program
272 * the default into the device (not checking this here
273 * would cause the adjustment below to return the maximum
274 * value, which may break PAN.)
276 if (!beacon_val)
277 return DEFAULT_BEACON_INTERVAL;
280 * If the beacon interval we obtained from the peer
281 * is too large, we'll have to wake up more often
282 * (and in IBSS case, we'll beacon too much)
284 * For example, if max_beacon_val is 4096, and the
285 * requested beacon interval is 7000, we'll have to
286 * use 3500 to be able to wake up on the beacons.
288 * This could badly influence beacon detection stats.
291 beacon_factor = (beacon_val + max_beacon_val) / max_beacon_val;
292 new_val = beacon_val / beacon_factor;
294 if (!new_val)
295 new_val = max_beacon_val;
297 return new_val;
300 static int iwl_send_rxon_timing(struct iwl_priv *priv,
301 struct iwl_rxon_context *ctx)
303 u64 tsf;
304 s32 interval_tm, rem;
305 struct ieee80211_conf *conf = NULL;
306 u16 beacon_int;
307 struct ieee80211_vif *vif = ctx->vif;
309 conf = &priv->hw->conf;
311 lockdep_assert_held(&priv->mutex);
313 memset(&ctx->timing, 0, sizeof(struct iwl_rxon_time_cmd));
315 ctx->timing.timestamp = cpu_to_le64(priv->timestamp);
316 ctx->timing.listen_interval = cpu_to_le16(conf->listen_interval);
318 beacon_int = vif ? vif->bss_conf.beacon_int : 0;
321 * TODO: For IBSS we need to get atim_window from mac80211,
322 * for now just always use 0
324 ctx->timing.atim_window = 0;
326 if (ctx->ctxid == IWL_RXON_CTX_PAN &&
327 (!ctx->vif || ctx->vif->type != NL80211_IFTYPE_STATION) &&
328 iwl_is_associated(priv, IWL_RXON_CTX_BSS) &&
329 priv->contexts[IWL_RXON_CTX_BSS].vif &&
330 priv->contexts[IWL_RXON_CTX_BSS].vif->bss_conf.beacon_int) {
331 ctx->timing.beacon_interval =
332 priv->contexts[IWL_RXON_CTX_BSS].timing.beacon_interval;
333 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
334 } else if (ctx->ctxid == IWL_RXON_CTX_BSS &&
335 iwl_is_associated(priv, IWL_RXON_CTX_PAN) &&
336 priv->contexts[IWL_RXON_CTX_PAN].vif &&
337 priv->contexts[IWL_RXON_CTX_PAN].vif->bss_conf.beacon_int &&
338 (!iwl_is_associated_ctx(ctx) || !ctx->vif ||
339 !ctx->vif->bss_conf.beacon_int)) {
340 ctx->timing.beacon_interval =
341 priv->contexts[IWL_RXON_CTX_PAN].timing.beacon_interval;
342 beacon_int = le16_to_cpu(ctx->timing.beacon_interval);
343 } else {
344 beacon_int = iwl_adjust_beacon_interval(beacon_int,
345 IWL_MAX_UCODE_BEACON_INTERVAL * TIME_UNIT);
346 ctx->timing.beacon_interval = cpu_to_le16(beacon_int);
349 ctx->beacon_int = beacon_int;
351 tsf = priv->timestamp; /* tsf is modifed by do_div: copy it */
352 interval_tm = beacon_int * TIME_UNIT;
353 rem = do_div(tsf, interval_tm);
354 ctx->timing.beacon_init_val = cpu_to_le32(interval_tm - rem);
356 ctx->timing.dtim_period = vif ? (vif->bss_conf.dtim_period ?: 1) : 1;
358 IWL_DEBUG_ASSOC(priv,
359 "beacon interval %d beacon timer %d beacon tim %d\n",
360 le16_to_cpu(ctx->timing.beacon_interval),
361 le32_to_cpu(ctx->timing.beacon_init_val),
362 le16_to_cpu(ctx->timing.atim_window));
364 return iwl_dvm_send_cmd_pdu(priv, ctx->rxon_timing_cmd,
365 CMD_SYNC, sizeof(ctx->timing), &ctx->timing);
368 static int iwlagn_rxon_disconn(struct iwl_priv *priv,
369 struct iwl_rxon_context *ctx)
371 int ret;
372 struct iwl_rxon_cmd *active = (void *)&ctx->active;
374 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
375 ret = iwlagn_disable_bss(priv, ctx, &ctx->staging);
376 } else {
377 ret = iwlagn_disable_pan(priv, ctx, &ctx->staging);
378 if (ret)
379 return ret;
380 if (ctx->vif) {
381 ret = iwl_send_rxon_timing(priv, ctx);
382 if (ret) {
383 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
384 return ret;
386 ret = iwlagn_disconn_pan(priv, ctx, &ctx->staging);
389 if (ret)
390 return ret;
393 * Un-assoc RXON clears the station table and WEP
394 * keys, so we have to restore those afterwards.
396 iwl_clear_ucode_stations(priv, ctx);
397 /* update -- might need P2P now */
398 iwl_update_bcast_station(priv, ctx);
399 iwl_restore_stations(priv, ctx);
400 ret = iwl_restore_default_wep_keys(priv, ctx);
401 if (ret) {
402 IWL_ERR(priv, "Failed to restore WEP keys (%d)\n", ret);
403 return ret;
406 memcpy(active, &ctx->staging, sizeof(*active));
407 return 0;
410 static int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
412 int ret;
413 s8 prev_tx_power;
414 bool defer;
415 struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS];
417 if (priv->calib_disabled & IWL_TX_POWER_CALIB_DISABLED)
418 return 0;
420 lockdep_assert_held(&priv->mutex);
422 if (priv->tx_power_user_lmt == tx_power && !force)
423 return 0;
425 if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
426 IWL_WARN(priv,
427 "Requested user TXPOWER %d below lower limit %d.\n",
428 tx_power,
429 IWLAGN_TX_POWER_TARGET_POWER_MIN);
430 return -EINVAL;
433 if (tx_power > priv->tx_power_device_lmt) {
434 IWL_WARN(priv,
435 "Requested user TXPOWER %d above upper limit %d.\n",
436 tx_power, priv->tx_power_device_lmt);
437 return -EINVAL;
440 if (!iwl_is_ready_rf(priv))
441 return -EIO;
443 /* scan complete and commit_rxon use tx_power_next value,
444 * it always need to be updated for newest request */
445 priv->tx_power_next = tx_power;
447 /* do not set tx power when scanning or channel changing */
448 defer = test_bit(STATUS_SCANNING, &priv->status) ||
449 memcmp(&ctx->active, &ctx->staging, sizeof(ctx->staging));
450 if (defer && !force) {
451 IWL_DEBUG_INFO(priv, "Deferring tx power set\n");
452 return 0;
455 prev_tx_power = priv->tx_power_user_lmt;
456 priv->tx_power_user_lmt = tx_power;
458 ret = iwlagn_send_tx_power(priv);
460 /* if fail to set tx_power, restore the orig. tx power */
461 if (ret) {
462 priv->tx_power_user_lmt = prev_tx_power;
463 priv->tx_power_next = prev_tx_power;
465 return ret;
468 static int iwlagn_rxon_connect(struct iwl_priv *priv,
469 struct iwl_rxon_context *ctx)
471 int ret;
472 struct iwl_rxon_cmd *active = (void *)&ctx->active;
474 /* RXON timing must be before associated RXON */
475 if (ctx->ctxid == IWL_RXON_CTX_BSS) {
476 ret = iwl_send_rxon_timing(priv, ctx);
477 if (ret) {
478 IWL_ERR(priv, "Failed to send timing (%d)!\n", ret);
479 return ret;
482 /* QoS info may be cleared by previous un-assoc RXON */
483 iwlagn_update_qos(priv, ctx);
486 * We'll run into this code path when beaconing is
487 * enabled, but then we also need to send the beacon
488 * to the device.
490 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_AP)) {
491 ret = iwlagn_update_beacon(priv, ctx->vif);
492 if (ret) {
493 IWL_ERR(priv,
494 "Error sending required beacon (%d)!\n",
495 ret);
496 return ret;
500 priv->start_calib = 0;
502 * Apply the new configuration.
504 * Associated RXON doesn't clear the station table in uCode,
505 * so we don't need to restore stations etc. after this.
507 ret = iwl_dvm_send_cmd_pdu(priv, ctx->rxon_cmd, CMD_SYNC,
508 sizeof(struct iwl_rxon_cmd), &ctx->staging);
509 if (ret) {
510 IWL_ERR(priv, "Error setting new RXON (%d)\n", ret);
511 return ret;
513 memcpy(active, &ctx->staging, sizeof(*active));
515 /* IBSS beacon needs to be sent after setting assoc */
516 if (ctx->vif && (ctx->vif->type == NL80211_IFTYPE_ADHOC))
517 if (iwlagn_update_beacon(priv, ctx->vif))
518 IWL_ERR(priv, "Error sending IBSS beacon\n");
519 iwl_init_sensitivity(priv);
522 * If we issue a new RXON command which required a tune then
523 * we must send a new TXPOWER command or we won't be able to
524 * Tx any frames.
526 * It's expected we set power here if channel is changing.
528 ret = iwl_set_tx_power(priv, priv->tx_power_next, true);
529 if (ret) {
530 IWL_ERR(priv, "Error sending TX power (%d)\n", ret);
531 return ret;
534 if (ctx->vif && ctx->vif->type == NL80211_IFTYPE_STATION &&
535 cfg(priv)->ht_params && cfg(priv)->ht_params->smps_mode)
536 ieee80211_request_smps(ctx->vif,
537 cfg(priv)->ht_params->smps_mode);
539 return 0;
542 int iwlagn_set_pan_params(struct iwl_priv *priv)
544 struct iwl_wipan_params_cmd cmd;
545 struct iwl_rxon_context *ctx_bss, *ctx_pan;
546 int slot0 = 300, slot1 = 0;
547 int ret;
549 if (priv->valid_contexts == BIT(IWL_RXON_CTX_BSS))
550 return 0;
552 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
554 lockdep_assert_held(&priv->mutex);
556 ctx_bss = &priv->contexts[IWL_RXON_CTX_BSS];
557 ctx_pan = &priv->contexts[IWL_RXON_CTX_PAN];
560 * If the PAN context is inactive, then we don't need
561 * to update the PAN parameters, the last thing we'll
562 * have done before it goes inactive is making the PAN
563 * parameters be WLAN-only.
565 if (!ctx_pan->is_active)
566 return 0;
568 memset(&cmd, 0, sizeof(cmd));
570 /* only 2 slots are currently allowed */
571 cmd.num_slots = 2;
573 cmd.slots[0].type = 0; /* BSS */
574 cmd.slots[1].type = 1; /* PAN */
576 if (priv->hw_roc_setup) {
577 /* both contexts must be used for this to happen */
578 slot1 = IWL_MIN_SLOT_TIME;
579 slot0 = 3000;
580 } else if (ctx_bss->vif && ctx_pan->vif) {
581 int bcnint = ctx_pan->beacon_int;
582 int dtim = ctx_pan->vif->bss_conf.dtim_period ?: 1;
584 /* should be set, but seems unused?? */
585 cmd.flags |= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE);
587 if (ctx_pan->vif->type == NL80211_IFTYPE_AP &&
588 bcnint &&
589 bcnint != ctx_bss->beacon_int) {
590 IWL_ERR(priv,
591 "beacon intervals don't match (%d, %d)\n",
592 ctx_bss->beacon_int, ctx_pan->beacon_int);
593 } else
594 bcnint = max_t(int, bcnint,
595 ctx_bss->beacon_int);
596 if (!bcnint)
597 bcnint = DEFAULT_BEACON_INTERVAL;
598 slot0 = bcnint / 2;
599 slot1 = bcnint - slot0;
601 if (test_bit(STATUS_SCAN_HW, &priv->status) ||
602 (!ctx_bss->vif->bss_conf.idle &&
603 !ctx_bss->vif->bss_conf.assoc)) {
604 slot0 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
605 slot1 = IWL_MIN_SLOT_TIME;
606 } else if (!ctx_pan->vif->bss_conf.idle &&
607 !ctx_pan->vif->bss_conf.assoc) {
608 slot1 = dtim * bcnint * 3 - IWL_MIN_SLOT_TIME;
609 slot0 = IWL_MIN_SLOT_TIME;
611 } else if (ctx_pan->vif) {
612 slot0 = 0;
613 slot1 = max_t(int, 1, ctx_pan->vif->bss_conf.dtim_period) *
614 ctx_pan->beacon_int;
615 slot1 = max_t(int, DEFAULT_BEACON_INTERVAL, slot1);
617 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
618 slot0 = slot1 * 3 - IWL_MIN_SLOT_TIME;
619 slot1 = IWL_MIN_SLOT_TIME;
623 cmd.slots[0].width = cpu_to_le16(slot0);
624 cmd.slots[1].width = cpu_to_le16(slot1);
626 ret = iwl_dvm_send_cmd_pdu(priv, REPLY_WIPAN_PARAMS, CMD_SYNC,
627 sizeof(cmd), &cmd);
628 if (ret)
629 IWL_ERR(priv, "Error setting PAN parameters (%d)\n", ret);
631 return ret;
634 static void _iwl_set_rxon_ht(struct iwl_priv *priv,
635 struct iwl_ht_config *ht_conf,
636 struct iwl_rxon_context *ctx)
638 struct iwl_rxon_cmd *rxon = &ctx->staging;
640 if (!ctx->ht.enabled) {
641 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
642 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK |
643 RXON_FLG_HT40_PROT_MSK |
644 RXON_FLG_HT_PROT_MSK);
645 return;
648 /* FIXME: if the definition of ht.protection changed, the "translation"
649 * will be needed for rxon->flags
651 rxon->flags |= cpu_to_le32(ctx->ht.protection <<
652 RXON_FLG_HT_OPERATING_MODE_POS);
654 /* Set up channel bandwidth:
655 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
656 /* clear the HT channel mode before set the mode */
657 rxon->flags &= ~(RXON_FLG_CHANNEL_MODE_MSK |
658 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
659 if (iwl_is_ht40_tx_allowed(priv, ctx, NULL)) {
660 /* pure ht40 */
661 if (ctx->ht.protection ==
662 IEEE80211_HT_OP_MODE_PROTECTION_20MHZ) {
663 rxon->flags |= RXON_FLG_CHANNEL_MODE_PURE_40;
665 * Note: control channel is opposite of extension
666 * channel
668 switch (ctx->ht.extension_chan_offset) {
669 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
670 rxon->flags &=
671 ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
672 break;
673 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
674 rxon->flags |=
675 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
676 break;
678 } else {
680 * Note: control channel is opposite of extension
681 * channel
683 switch (ctx->ht.extension_chan_offset) {
684 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
685 rxon->flags &=
686 ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK);
687 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
688 break;
689 case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
690 rxon->flags |= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK;
691 rxon->flags |= RXON_FLG_CHANNEL_MODE_MIXED;
692 break;
693 case IEEE80211_HT_PARAM_CHA_SEC_NONE:
694 default:
696 * channel location only valid if in Mixed
697 * mode
699 IWL_ERR(priv,
700 "invalid extension channel offset\n");
701 break;
704 } else {
705 rxon->flags |= RXON_FLG_CHANNEL_MODE_LEGACY;
708 iwlagn_set_rxon_chain(priv, ctx);
710 IWL_DEBUG_ASSOC(priv, "rxon flags 0x%X operation mode :0x%X "
711 "extension channel offset 0x%x\n",
712 le32_to_cpu(rxon->flags), ctx->ht.protection,
713 ctx->ht.extension_chan_offset);
716 void iwl_set_rxon_ht(struct iwl_priv *priv, struct iwl_ht_config *ht_conf)
718 struct iwl_rxon_context *ctx;
720 for_each_context(priv, ctx)
721 _iwl_set_rxon_ht(priv, ht_conf, ctx);
725 * iwl_set_rxon_channel - Set the band and channel values in staging RXON
726 * @ch: requested channel as a pointer to struct ieee80211_channel
728 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
729 * in the staging RXON flag structure based on the ch->band
731 void iwl_set_rxon_channel(struct iwl_priv *priv, struct ieee80211_channel *ch,
732 struct iwl_rxon_context *ctx)
734 enum ieee80211_band band = ch->band;
735 u16 channel = ch->hw_value;
737 if ((le16_to_cpu(ctx->staging.channel) == channel) &&
738 (priv->band == band))
739 return;
741 ctx->staging.channel = cpu_to_le16(channel);
742 if (band == IEEE80211_BAND_5GHZ)
743 ctx->staging.flags &= ~RXON_FLG_BAND_24G_MSK;
744 else
745 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
747 priv->band = band;
749 IWL_DEBUG_INFO(priv, "Staging channel set to %d [%d]\n", channel, band);
753 void iwl_set_flags_for_band(struct iwl_priv *priv,
754 struct iwl_rxon_context *ctx,
755 enum ieee80211_band band,
756 struct ieee80211_vif *vif)
758 if (band == IEEE80211_BAND_5GHZ) {
759 ctx->staging.flags &=
760 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
761 | RXON_FLG_CCK_MSK);
762 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
763 } else {
764 /* Copied from iwl_post_associate() */
765 if (vif && vif->bss_conf.use_short_slot)
766 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
767 else
768 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
770 ctx->staging.flags |= RXON_FLG_BAND_24G_MSK;
771 ctx->staging.flags |= RXON_FLG_AUTO_DETECT_MSK;
772 ctx->staging.flags &= ~RXON_FLG_CCK_MSK;
776 void iwl_set_rate(struct iwl_priv *priv)
778 struct iwl_rxon_context *ctx;
780 for_each_context(priv, ctx) {
781 ctx->staging.cck_basic_rates =
782 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
784 ctx->staging.ofdm_basic_rates =
785 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
789 static void iwl_set_rxon_hwcrypto(struct iwl_priv *priv,
790 struct iwl_rxon_context *ctx, int hw_decrypt)
792 struct iwl_rxon_cmd *rxon = &ctx->staging;
794 if (hw_decrypt)
795 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
796 else
797 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
801 /* validate RXON structure is valid */
802 static int iwl_check_rxon_cmd(struct iwl_priv *priv,
803 struct iwl_rxon_context *ctx)
805 struct iwl_rxon_cmd *rxon = &ctx->staging;
806 u32 errors = 0;
808 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
809 if (rxon->flags & RXON_FLG_TGJ_NARROW_BAND_MSK) {
810 IWL_WARN(priv, "check 2.4G: wrong narrow\n");
811 errors |= BIT(0);
813 if (rxon->flags & RXON_FLG_RADAR_DETECT_MSK) {
814 IWL_WARN(priv, "check 2.4G: wrong radar\n");
815 errors |= BIT(1);
817 } else {
818 if (!(rxon->flags & RXON_FLG_SHORT_SLOT_MSK)) {
819 IWL_WARN(priv, "check 5.2G: not short slot!\n");
820 errors |= BIT(2);
822 if (rxon->flags & RXON_FLG_CCK_MSK) {
823 IWL_WARN(priv, "check 5.2G: CCK!\n");
824 errors |= BIT(3);
827 if ((rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1) {
828 IWL_WARN(priv, "mac/bssid mcast!\n");
829 errors |= BIT(4);
832 /* make sure basic rates 6Mbps and 1Mbps are supported */
833 if ((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0 &&
834 (rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0) {
835 IWL_WARN(priv, "neither 1 nor 6 are basic\n");
836 errors |= BIT(5);
839 if (le16_to_cpu(rxon->assoc_id) > 2007) {
840 IWL_WARN(priv, "aid > 2007\n");
841 errors |= BIT(6);
844 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
845 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK)) {
846 IWL_WARN(priv, "CCK and short slot\n");
847 errors |= BIT(7);
850 if ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
851 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK)) {
852 IWL_WARN(priv, "CCK and auto detect");
853 errors |= BIT(8);
856 if ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
857 RXON_FLG_TGG_PROTECT_MSK)) ==
858 RXON_FLG_TGG_PROTECT_MSK) {
859 IWL_WARN(priv, "TGg but no auto-detect\n");
860 errors |= BIT(9);
863 if (rxon->channel == 0) {
864 IWL_WARN(priv, "zero channel is invalid\n");
865 errors |= BIT(10);
868 WARN(errors, "Invalid RXON (%#x), channel %d",
869 errors, le16_to_cpu(rxon->channel));
871 return errors ? -EINVAL : 0;
875 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
876 * @priv: staging_rxon is compared to active_rxon
878 * If the RXON structure is changing enough to require a new tune,
879 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
880 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
882 static int iwl_full_rxon_required(struct iwl_priv *priv,
883 struct iwl_rxon_context *ctx)
885 const struct iwl_rxon_cmd *staging = &ctx->staging;
886 const struct iwl_rxon_cmd *active = &ctx->active;
888 #define CHK(cond) \
889 if ((cond)) { \
890 IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
891 return 1; \
894 #define CHK_NEQ(c1, c2) \
895 if ((c1) != (c2)) { \
896 IWL_DEBUG_INFO(priv, "need full RXON - " \
897 #c1 " != " #c2 " - %d != %d\n", \
898 (c1), (c2)); \
899 return 1; \
902 /* These items are only settable from the full RXON command */
903 CHK(!iwl_is_associated_ctx(ctx));
904 CHK(compare_ether_addr(staging->bssid_addr, active->bssid_addr));
905 CHK(compare_ether_addr(staging->node_addr, active->node_addr));
906 CHK(compare_ether_addr(staging->wlap_bssid_addr,
907 active->wlap_bssid_addr));
908 CHK_NEQ(staging->dev_type, active->dev_type);
909 CHK_NEQ(staging->channel, active->channel);
910 CHK_NEQ(staging->air_propagation, active->air_propagation);
911 CHK_NEQ(staging->ofdm_ht_single_stream_basic_rates,
912 active->ofdm_ht_single_stream_basic_rates);
913 CHK_NEQ(staging->ofdm_ht_dual_stream_basic_rates,
914 active->ofdm_ht_dual_stream_basic_rates);
915 CHK_NEQ(staging->ofdm_ht_triple_stream_basic_rates,
916 active->ofdm_ht_triple_stream_basic_rates);
917 CHK_NEQ(staging->assoc_id, active->assoc_id);
919 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
920 * be updated with the RXON_ASSOC command -- however only some
921 * flag transitions are allowed using RXON_ASSOC */
923 /* Check if we are not switching bands */
924 CHK_NEQ(staging->flags & RXON_FLG_BAND_24G_MSK,
925 active->flags & RXON_FLG_BAND_24G_MSK);
927 /* Check if we are switching association toggle */
928 CHK_NEQ(staging->filter_flags & RXON_FILTER_ASSOC_MSK,
929 active->filter_flags & RXON_FILTER_ASSOC_MSK);
931 #undef CHK
932 #undef CHK_NEQ
934 return 0;
937 #ifdef CONFIG_IWLWIFI_DEBUG
938 void iwl_print_rx_config_cmd(struct iwl_priv *priv,
939 enum iwl_rxon_context_id ctxid)
941 struct iwl_rxon_context *ctx = &priv->contexts[ctxid];
942 struct iwl_rxon_cmd *rxon = &ctx->staging;
944 IWL_DEBUG_RADIO(priv, "RX CONFIG:\n");
945 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
946 IWL_DEBUG_RADIO(priv, "u16 channel: 0x%x\n",
947 le16_to_cpu(rxon->channel));
948 IWL_DEBUG_RADIO(priv, "u32 flags: 0x%08X\n",
949 le32_to_cpu(rxon->flags));
950 IWL_DEBUG_RADIO(priv, "u32 filter_flags: 0x%08x\n",
951 le32_to_cpu(rxon->filter_flags));
952 IWL_DEBUG_RADIO(priv, "u8 dev_type: 0x%x\n", rxon->dev_type);
953 IWL_DEBUG_RADIO(priv, "u8 ofdm_basic_rates: 0x%02x\n",
954 rxon->ofdm_basic_rates);
955 IWL_DEBUG_RADIO(priv, "u8 cck_basic_rates: 0x%02x\n",
956 rxon->cck_basic_rates);
957 IWL_DEBUG_RADIO(priv, "u8[6] node_addr: %pM\n", rxon->node_addr);
958 IWL_DEBUG_RADIO(priv, "u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
959 IWL_DEBUG_RADIO(priv, "u16 assoc_id: 0x%x\n",
960 le16_to_cpu(rxon->assoc_id));
962 #endif
965 * iwlagn_commit_rxon - commit staging_rxon to hardware
967 * The RXON command in staging_rxon is committed to the hardware and
968 * the active_rxon structure is updated with the new data. This
969 * function correctly transitions out of the RXON_ASSOC_MSK state if
970 * a HW tune is required based on the RXON structure changes.
972 * The connect/disconnect flow should be as the following:
974 * 1. make sure send RXON command with association bit unset if not connect
975 * this should include the channel and the band for the candidate
976 * to be connected to
977 * 2. Add Station before RXON association with the AP
978 * 3. RXON_timing has to send before RXON for connection
979 * 4. full RXON command - associated bit set
980 * 5. use RXON_ASSOC command to update any flags changes
982 int iwlagn_commit_rxon(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
984 /* cast away the const for active_rxon in this function */
985 struct iwl_rxon_cmd *active = (void *)&ctx->active;
986 bool new_assoc = !!(ctx->staging.filter_flags & RXON_FILTER_ASSOC_MSK);
987 int ret;
989 lockdep_assert_held(&priv->mutex);
991 if (!iwl_is_alive(priv))
992 return -EBUSY;
994 /* This function hardcodes a bunch of dual-mode assumptions */
995 BUILD_BUG_ON(NUM_IWL_RXON_CTX != 2);
997 if (!ctx->is_active)
998 return 0;
1000 /* always get timestamp with Rx frame */
1001 ctx->staging.flags |= RXON_FLG_TSF2HOST_MSK;
1004 * force CTS-to-self frames protection if RTS-CTS is not preferred
1005 * one aggregation protection method
1007 if (!priv->hw_params.use_rts_for_aggregation)
1008 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
1010 if ((ctx->vif && ctx->vif->bss_conf.use_short_slot) ||
1011 !(ctx->staging.flags & RXON_FLG_BAND_24G_MSK))
1012 ctx->staging.flags |= RXON_FLG_SHORT_SLOT_MSK;
1013 else
1014 ctx->staging.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
1016 iwl_print_rx_config_cmd(priv, ctx->ctxid);
1017 ret = iwl_check_rxon_cmd(priv, ctx);
1018 if (ret) {
1019 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
1020 return -EINVAL;
1024 * receive commit_rxon request
1025 * abort any previous channel switch if still in process
1027 if (test_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status) &&
1028 (priv->switch_channel != ctx->staging.channel)) {
1029 IWL_DEBUG_11H(priv, "abort channel switch on %d\n",
1030 le16_to_cpu(priv->switch_channel));
1031 iwl_chswitch_done(priv, false);
1035 * If we don't need to send a full RXON, we can use
1036 * iwl_rxon_assoc_cmd which is used to reconfigure filter
1037 * and other flags for the current radio configuration.
1039 if (!iwl_full_rxon_required(priv, ctx)) {
1040 ret = iwlagn_send_rxon_assoc(priv, ctx);
1041 if (ret) {
1042 IWL_ERR(priv, "Error setting RXON_ASSOC (%d)\n", ret);
1043 return ret;
1046 memcpy(active, &ctx->staging, sizeof(*active));
1048 * We do not commit tx power settings while channel changing,
1049 * do it now if after settings changed.
1051 iwl_set_tx_power(priv, priv->tx_power_next, false);
1053 /* make sure we are in the right PS state */
1054 iwl_power_update_mode(priv, true);
1056 return 0;
1059 iwl_set_rxon_hwcrypto(priv, ctx, !iwlagn_mod_params.sw_crypto);
1061 IWL_DEBUG_INFO(priv,
1062 "Going to commit RXON\n"
1063 " * with%s RXON_FILTER_ASSOC_MSK\n"
1064 " * channel = %d\n"
1065 " * bssid = %pM\n",
1066 (new_assoc ? "" : "out"),
1067 le16_to_cpu(ctx->staging.channel),
1068 ctx->staging.bssid_addr);
1071 * Always clear associated first, but with the correct config.
1072 * This is required as for example station addition for the
1073 * AP station must be done after the BSSID is set to correctly
1074 * set up filters in the device.
1076 ret = iwlagn_rxon_disconn(priv, ctx);
1077 if (ret)
1078 return ret;
1080 ret = iwlagn_set_pan_params(priv);
1081 if (ret)
1082 return ret;
1084 if (new_assoc)
1085 return iwlagn_rxon_connect(priv, ctx);
1087 return 0;
1090 void iwlagn_config_ht40(struct ieee80211_conf *conf,
1091 struct iwl_rxon_context *ctx)
1093 if (conf_is_ht40_minus(conf)) {
1094 ctx->ht.extension_chan_offset =
1095 IEEE80211_HT_PARAM_CHA_SEC_BELOW;
1096 ctx->ht.is_40mhz = true;
1097 } else if (conf_is_ht40_plus(conf)) {
1098 ctx->ht.extension_chan_offset =
1099 IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
1100 ctx->ht.is_40mhz = true;
1101 } else {
1102 ctx->ht.extension_chan_offset =
1103 IEEE80211_HT_PARAM_CHA_SEC_NONE;
1104 ctx->ht.is_40mhz = false;
1108 int iwlagn_mac_config(struct ieee80211_hw *hw, u32 changed)
1110 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1111 struct iwl_rxon_context *ctx;
1112 struct ieee80211_conf *conf = &hw->conf;
1113 struct ieee80211_channel *channel = conf->channel;
1114 const struct iwl_channel_info *ch_info;
1115 int ret = 0;
1117 IWL_DEBUG_MAC80211(priv, "enter: changed %#x\n", changed);
1119 mutex_lock(&priv->mutex);
1121 if (unlikely(test_bit(STATUS_SCANNING, &priv->status))) {
1122 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
1123 goto out;
1126 if (!iwl_is_ready(priv)) {
1127 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
1128 goto out;
1131 if (changed & (IEEE80211_CONF_CHANGE_SMPS |
1132 IEEE80211_CONF_CHANGE_CHANNEL)) {
1133 /* mac80211 uses static for non-HT which is what we want */
1134 priv->current_ht_config.smps = conf->smps_mode;
1137 * Recalculate chain counts.
1139 * If monitor mode is enabled then mac80211 will
1140 * set up the SM PS mode to OFF if an HT channel is
1141 * configured.
1143 for_each_context(priv, ctx)
1144 iwlagn_set_rxon_chain(priv, ctx);
1147 if (changed & IEEE80211_CONF_CHANGE_CHANNEL) {
1148 ch_info = iwl_get_channel_info(priv, channel->band,
1149 channel->hw_value);
1150 if (!is_channel_valid(ch_info)) {
1151 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
1152 ret = -EINVAL;
1153 goto out;
1156 for_each_context(priv, ctx) {
1157 /* Configure HT40 channels */
1158 if (ctx->ht.enabled != conf_is_ht(conf))
1159 ctx->ht.enabled = conf_is_ht(conf);
1161 if (ctx->ht.enabled) {
1162 /* if HT40 is used, it should not change
1163 * after associated except channel switch */
1164 if (!ctx->ht.is_40mhz ||
1165 !iwl_is_associated_ctx(ctx))
1166 iwlagn_config_ht40(conf, ctx);
1167 } else
1168 ctx->ht.is_40mhz = false;
1171 * Default to no protection. Protection mode will
1172 * later be set from BSS config in iwl_ht_conf
1174 ctx->ht.protection = IEEE80211_HT_OP_MODE_PROTECTION_NONE;
1176 /* if we are switching from ht to 2.4 clear flags
1177 * from any ht related info since 2.4 does not
1178 * support ht */
1179 if (le16_to_cpu(ctx->staging.channel) !=
1180 channel->hw_value)
1181 ctx->staging.flags = 0;
1183 iwl_set_rxon_channel(priv, channel, ctx);
1184 iwl_set_rxon_ht(priv, &priv->current_ht_config);
1186 iwl_set_flags_for_band(priv, ctx, channel->band,
1187 ctx->vif);
1190 iwl_update_bcast_stations(priv);
1193 * The list of supported rates and rate mask can be different
1194 * for each band; since the band may have changed, reset
1195 * the rate mask to what mac80211 lists.
1197 iwl_set_rate(priv);
1200 if (changed & (IEEE80211_CONF_CHANGE_PS |
1201 IEEE80211_CONF_CHANGE_IDLE)) {
1202 ret = iwl_power_update_mode(priv, false);
1203 if (ret)
1204 IWL_DEBUG_MAC80211(priv, "Error setting sleep level\n");
1207 if (changed & IEEE80211_CONF_CHANGE_POWER) {
1208 IWL_DEBUG_MAC80211(priv, "TX Power old=%d new=%d\n",
1209 priv->tx_power_user_lmt, conf->power_level);
1211 iwl_set_tx_power(priv, conf->power_level, false);
1214 for_each_context(priv, ctx) {
1215 if (!memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1216 continue;
1217 iwlagn_commit_rxon(priv, ctx);
1219 out:
1220 mutex_unlock(&priv->mutex);
1221 IWL_DEBUG_MAC80211(priv, "leave\n");
1223 return ret;
1226 static void iwlagn_check_needed_chains(struct iwl_priv *priv,
1227 struct iwl_rxon_context *ctx,
1228 struct ieee80211_bss_conf *bss_conf)
1230 struct ieee80211_vif *vif = ctx->vif;
1231 struct iwl_rxon_context *tmp;
1232 struct ieee80211_sta *sta;
1233 struct iwl_ht_config *ht_conf = &priv->current_ht_config;
1234 struct ieee80211_sta_ht_cap *ht_cap;
1235 bool need_multiple;
1237 lockdep_assert_held(&priv->mutex);
1239 switch (vif->type) {
1240 case NL80211_IFTYPE_STATION:
1241 rcu_read_lock();
1242 sta = ieee80211_find_sta(vif, bss_conf->bssid);
1243 if (!sta) {
1245 * If at all, this can only happen through a race
1246 * when the AP disconnects us while we're still
1247 * setting up the connection, in that case mac80211
1248 * will soon tell us about that.
1250 need_multiple = false;
1251 rcu_read_unlock();
1252 break;
1255 ht_cap = &sta->ht_cap;
1257 need_multiple = true;
1260 * If the peer advertises no support for receiving 2 and 3
1261 * stream MCS rates, it can't be transmitting them either.
1263 if (ht_cap->mcs.rx_mask[1] == 0 &&
1264 ht_cap->mcs.rx_mask[2] == 0) {
1265 need_multiple = false;
1266 } else if (!(ht_cap->mcs.tx_params &
1267 IEEE80211_HT_MCS_TX_DEFINED)) {
1268 /* If it can't TX MCS at all ... */
1269 need_multiple = false;
1270 } else if (ht_cap->mcs.tx_params &
1271 IEEE80211_HT_MCS_TX_RX_DIFF) {
1272 int maxstreams;
1275 * But if it can receive them, it might still not
1276 * be able to transmit them, which is what we need
1277 * to check here -- so check the number of streams
1278 * it advertises for TX (if different from RX).
1281 maxstreams = (ht_cap->mcs.tx_params &
1282 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK);
1283 maxstreams >>=
1284 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT;
1285 maxstreams += 1;
1287 if (maxstreams <= 1)
1288 need_multiple = false;
1291 rcu_read_unlock();
1292 break;
1293 case NL80211_IFTYPE_ADHOC:
1294 /* currently */
1295 need_multiple = false;
1296 break;
1297 default:
1298 /* only AP really */
1299 need_multiple = true;
1300 break;
1303 ctx->ht_need_multiple_chains = need_multiple;
1305 if (!need_multiple) {
1306 /* check all contexts */
1307 for_each_context(priv, tmp) {
1308 if (!tmp->vif)
1309 continue;
1310 if (tmp->ht_need_multiple_chains) {
1311 need_multiple = true;
1312 break;
1317 ht_conf->single_chain_sufficient = !need_multiple;
1320 static void iwlagn_chain_noise_reset(struct iwl_priv *priv)
1322 struct iwl_chain_noise_data *data = &priv->chain_noise_data;
1323 int ret;
1325 if (!(priv->calib_disabled & IWL_CHAIN_NOISE_CALIB_DISABLED))
1326 return;
1328 if ((data->state == IWL_CHAIN_NOISE_ALIVE) &&
1329 iwl_is_any_associated(priv)) {
1330 struct iwl_calib_chain_noise_reset_cmd cmd;
1332 /* clear data for chain noise calibration algorithm */
1333 data->chain_noise_a = 0;
1334 data->chain_noise_b = 0;
1335 data->chain_noise_c = 0;
1336 data->chain_signal_a = 0;
1337 data->chain_signal_b = 0;
1338 data->chain_signal_c = 0;
1339 data->beacon_count = 0;
1341 memset(&cmd, 0, sizeof(cmd));
1342 iwl_set_calib_hdr(&cmd.hdr,
1343 priv->phy_calib_chain_noise_reset_cmd);
1344 ret = iwl_dvm_send_cmd_pdu(priv,
1345 REPLY_PHY_CALIBRATION_CMD,
1346 CMD_SYNC, sizeof(cmd), &cmd);
1347 if (ret)
1348 IWL_ERR(priv,
1349 "Could not send REPLY_PHY_CALIBRATION_CMD\n");
1350 data->state = IWL_CHAIN_NOISE_ACCUMULATE;
1351 IWL_DEBUG_CALIB(priv, "Run chain_noise_calibrate\n");
1355 void iwlagn_bss_info_changed(struct ieee80211_hw *hw,
1356 struct ieee80211_vif *vif,
1357 struct ieee80211_bss_conf *bss_conf,
1358 u32 changes)
1360 struct iwl_priv *priv = IWL_MAC80211_GET_DVM(hw);
1361 struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif);
1362 int ret;
1363 bool force = false;
1365 mutex_lock(&priv->mutex);
1367 if (unlikely(!iwl_is_ready(priv))) {
1368 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
1369 mutex_unlock(&priv->mutex);
1370 return;
1373 if (unlikely(!ctx->vif)) {
1374 IWL_DEBUG_MAC80211(priv, "leave - vif is NULL\n");
1375 mutex_unlock(&priv->mutex);
1376 return;
1379 if (changes & BSS_CHANGED_BEACON_INT)
1380 force = true;
1382 if (changes & BSS_CHANGED_QOS) {
1383 ctx->qos_data.qos_active = bss_conf->qos;
1384 iwlagn_update_qos(priv, ctx);
1387 ctx->staging.assoc_id = cpu_to_le16(vif->bss_conf.aid);
1388 if (vif->bss_conf.use_short_preamble)
1389 ctx->staging.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
1390 else
1391 ctx->staging.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
1393 if (changes & BSS_CHANGED_ASSOC) {
1394 if (bss_conf->assoc) {
1395 priv->timestamp = bss_conf->last_tsf;
1396 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
1397 } else {
1399 * If we disassociate while there are pending
1400 * frames, just wake up the queues and let the
1401 * frames "escape" ... This shouldn't really
1402 * be happening to start with, but we should
1403 * not get stuck in this case either since it
1404 * can happen if userspace gets confused.
1406 iwlagn_lift_passive_no_rx(priv);
1408 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1410 if (ctx->ctxid == IWL_RXON_CTX_BSS)
1411 priv->have_rekey_data = false;
1414 iwlagn_bt_coex_rssi_monitor(priv);
1417 if (ctx->ht.enabled) {
1418 ctx->ht.protection = bss_conf->ht_operation_mode &
1419 IEEE80211_HT_OP_MODE_PROTECTION;
1420 ctx->ht.non_gf_sta_present = !!(bss_conf->ht_operation_mode &
1421 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT);
1422 iwlagn_check_needed_chains(priv, ctx, bss_conf);
1423 iwl_set_rxon_ht(priv, &priv->current_ht_config);
1426 iwlagn_set_rxon_chain(priv, ctx);
1428 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
1429 ctx->staging.flags |= RXON_FLG_TGG_PROTECT_MSK;
1430 else
1431 ctx->staging.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
1433 if (bss_conf->use_cts_prot)
1434 ctx->staging.flags |= RXON_FLG_SELF_CTS_EN;
1435 else
1436 ctx->staging.flags &= ~RXON_FLG_SELF_CTS_EN;
1438 memcpy(ctx->staging.bssid_addr, bss_conf->bssid, ETH_ALEN);
1440 if (vif->type == NL80211_IFTYPE_AP ||
1441 vif->type == NL80211_IFTYPE_ADHOC) {
1442 if (vif->bss_conf.enable_beacon) {
1443 ctx->staging.filter_flags |= RXON_FILTER_ASSOC_MSK;
1444 priv->beacon_ctx = ctx;
1445 } else {
1446 ctx->staging.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
1447 priv->beacon_ctx = NULL;
1452 * If the ucode decides to do beacon filtering before
1453 * association, it will lose beacons that are needed
1454 * before sending frames out on passive channels. This
1455 * causes association failures on those channels. Enable
1456 * receiving beacons in such cases.
1459 if (vif->type == NL80211_IFTYPE_STATION) {
1460 if (!bss_conf->assoc)
1461 ctx->staging.filter_flags |= RXON_FILTER_BCON_AWARE_MSK;
1462 else
1463 ctx->staging.filter_flags &=
1464 ~RXON_FILTER_BCON_AWARE_MSK;
1467 if (force || memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1468 iwlagn_commit_rxon(priv, ctx);
1470 if (changes & BSS_CHANGED_ASSOC && bss_conf->assoc) {
1472 * The chain noise calibration will enable PM upon
1473 * completion. If calibration has already been run
1474 * then we need to enable power management here.
1476 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
1477 iwl_power_update_mode(priv, false);
1479 /* Enable RX differential gain and sensitivity calibrations */
1480 iwlagn_chain_noise_reset(priv);
1481 priv->start_calib = 1;
1484 if (changes & BSS_CHANGED_IBSS) {
1485 ret = iwlagn_manage_ibss_station(priv, vif,
1486 bss_conf->ibss_joined);
1487 if (ret)
1488 IWL_ERR(priv, "failed to %s IBSS station %pM\n",
1489 bss_conf->ibss_joined ? "add" : "remove",
1490 bss_conf->bssid);
1493 if (changes & BSS_CHANGED_BEACON && vif->type == NL80211_IFTYPE_ADHOC &&
1494 priv->beacon_ctx) {
1495 if (iwlagn_update_beacon(priv, vif))
1496 IWL_ERR(priv, "Error sending IBSS beacon\n");
1499 mutex_unlock(&priv->mutex);
1502 void iwlagn_post_scan(struct iwl_priv *priv)
1504 struct iwl_rxon_context *ctx;
1507 * We do not commit power settings while scan is pending,
1508 * do it now if the settings changed.
1510 iwl_power_set_mode(priv, &priv->power_data.sleep_cmd_next, false);
1511 iwl_set_tx_power(priv, priv->tx_power_next, false);
1514 * Since setting the RXON may have been deferred while
1515 * performing the scan, fire one off if needed
1517 for_each_context(priv, ctx)
1518 if (memcmp(&ctx->staging, &ctx->active, sizeof(ctx->staging)))
1519 iwlagn_commit_rxon(priv, ctx);
1521 iwlagn_set_pan_params(priv);