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 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 * The full GNU General Public License is included in this distribution in the
20 * file called LICENSE.
22 * Contact Information:
23 * Intel Linux Wireless <ilw@linux.intel.com>
24 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
26 *****************************************************************************/
28 #include <linux/etherdevice.h>
29 #include "iwl-trans.h"
30 #include "iwl-modparams.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 memset(&ctx
->staging
, 0, sizeof(ctx
->staging
));
44 ctx
->staging
.dev_type
= ctx
->unused_devtype
;
46 switch (ctx
->vif
->type
) {
47 case NL80211_IFTYPE_AP
:
48 ctx
->staging
.dev_type
= ctx
->ap_devtype
;
51 case NL80211_IFTYPE_STATION
:
52 ctx
->staging
.dev_type
= ctx
->station_devtype
;
53 ctx
->staging
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
56 case NL80211_IFTYPE_ADHOC
:
57 ctx
->staging
.dev_type
= ctx
->ibss_devtype
;
58 ctx
->staging
.flags
= RXON_FLG_SHORT_PREAMBLE_MSK
;
59 ctx
->staging
.filter_flags
= RXON_FILTER_BCON_AWARE_MSK
|
60 RXON_FILTER_ACCEPT_GRP_MSK
;
63 case NL80211_IFTYPE_MONITOR
:
64 ctx
->staging
.dev_type
= RXON_DEV_TYPE_SNIFFER
;
68 IWL_ERR(priv
, "Unsupported interface type %d\n",
74 /* TODO: Figure out when short_preamble would be set and cache from
76 if (!hw_to_local(priv
->hw
)->short_preamble
)
77 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
79 ctx
->staging
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
82 ctx
->staging
.channel
=
83 cpu_to_le16(priv
->hw
->conf
.chandef
.chan
->hw_value
);
84 priv
->band
= priv
->hw
->conf
.chandef
.chan
->band
;
86 iwl_set_flags_for_band(priv
, ctx
, priv
->band
, ctx
->vif
);
88 /* clear both MIX and PURE40 mode flag */
89 ctx
->staging
.flags
&= ~(RXON_FLG_CHANNEL_MODE_MIXED
|
90 RXON_FLG_CHANNEL_MODE_PURE_40
);
92 memcpy(ctx
->staging
.node_addr
, ctx
->vif
->addr
, ETH_ALEN
);
94 ctx
->staging
.ofdm_ht_single_stream_basic_rates
= 0xff;
95 ctx
->staging
.ofdm_ht_dual_stream_basic_rates
= 0xff;
96 ctx
->staging
.ofdm_ht_triple_stream_basic_rates
= 0xff;
99 static int iwlagn_disable_bss(struct iwl_priv
*priv
,
100 struct iwl_rxon_context
*ctx
,
101 struct iwl_rxon_cmd
*send
)
103 __le32 old_filter
= send
->filter_flags
;
106 send
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
107 ret
= iwl_dvm_send_cmd_pdu(priv
, ctx
->rxon_cmd
,
108 0, sizeof(*send
), send
);
110 send
->filter_flags
= old_filter
;
113 IWL_DEBUG_QUIET_RFKILL(priv
,
114 "Error clearing ASSOC_MSK on BSS (%d)\n", ret
);
119 static int iwlagn_disable_pan(struct iwl_priv
*priv
,
120 struct iwl_rxon_context
*ctx
,
121 struct iwl_rxon_cmd
*send
)
123 struct iwl_notification_wait disable_wait
;
124 __le32 old_filter
= send
->filter_flags
;
125 u8 old_dev_type
= send
->dev_type
;
127 static const u16 deactivate_cmd
[] = {
128 REPLY_WIPAN_DEACTIVATION_COMPLETE
131 iwl_init_notification_wait(&priv
->notif_wait
, &disable_wait
,
132 deactivate_cmd
, ARRAY_SIZE(deactivate_cmd
),
135 send
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
136 send
->dev_type
= RXON_DEV_TYPE_P2P
;
137 ret
= iwl_dvm_send_cmd_pdu(priv
, ctx
->rxon_cmd
,
138 0, sizeof(*send
), send
);
140 send
->filter_flags
= old_filter
;
141 send
->dev_type
= old_dev_type
;
144 IWL_ERR(priv
, "Error disabling PAN (%d)\n", ret
);
145 iwl_remove_notification(&priv
->notif_wait
, &disable_wait
);
147 ret
= iwl_wait_notification(&priv
->notif_wait
,
150 IWL_ERR(priv
, "Timed out waiting for PAN disable\n");
156 static int iwlagn_disconn_pan(struct iwl_priv
*priv
,
157 struct iwl_rxon_context
*ctx
,
158 struct iwl_rxon_cmd
*send
)
160 __le32 old_filter
= send
->filter_flags
;
163 send
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
164 ret
= iwl_dvm_send_cmd_pdu(priv
, ctx
->rxon_cmd
, 0,
165 sizeof(*send
), send
);
167 send
->filter_flags
= old_filter
;
172 static void iwlagn_update_qos(struct iwl_priv
*priv
,
173 struct iwl_rxon_context
*ctx
)
180 ctx
->qos_data
.def_qos_parm
.qos_flags
= 0;
182 if (ctx
->qos_data
.qos_active
)
183 ctx
->qos_data
.def_qos_parm
.qos_flags
|=
184 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
187 ctx
->qos_data
.def_qos_parm
.qos_flags
|= QOS_PARAM_FLG_TGN_MSK
;
189 IWL_DEBUG_INFO(priv
, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
190 ctx
->qos_data
.qos_active
,
191 ctx
->qos_data
.def_qos_parm
.qos_flags
);
193 ret
= iwl_dvm_send_cmd_pdu(priv
, ctx
->qos_cmd
, 0,
194 sizeof(struct iwl_qosparam_cmd
),
195 &ctx
->qos_data
.def_qos_parm
);
197 IWL_DEBUG_QUIET_RFKILL(priv
, "Failed to update QoS\n");
200 static int iwlagn_update_beacon(struct iwl_priv
*priv
,
201 struct ieee80211_vif
*vif
)
203 lockdep_assert_held(&priv
->mutex
);
205 dev_kfree_skb(priv
->beacon_skb
);
206 priv
->beacon_skb
= ieee80211_beacon_get(priv
->hw
, vif
);
207 if (!priv
->beacon_skb
)
209 return iwlagn_send_beacon_cmd(priv
);
212 static int iwlagn_send_rxon_assoc(struct iwl_priv
*priv
,
213 struct iwl_rxon_context
*ctx
)
216 struct iwl_rxon_assoc_cmd rxon_assoc
;
217 const struct iwl_rxon_cmd
*rxon1
= &ctx
->staging
;
218 const struct iwl_rxon_cmd
*rxon2
= &ctx
->active
;
220 if ((rxon1
->flags
== rxon2
->flags
) &&
221 (rxon1
->filter_flags
== rxon2
->filter_flags
) &&
222 (rxon1
->cck_basic_rates
== rxon2
->cck_basic_rates
) &&
223 (rxon1
->ofdm_ht_single_stream_basic_rates
==
224 rxon2
->ofdm_ht_single_stream_basic_rates
) &&
225 (rxon1
->ofdm_ht_dual_stream_basic_rates
==
226 rxon2
->ofdm_ht_dual_stream_basic_rates
) &&
227 (rxon1
->ofdm_ht_triple_stream_basic_rates
==
228 rxon2
->ofdm_ht_triple_stream_basic_rates
) &&
229 (rxon1
->acquisition_data
== rxon2
->acquisition_data
) &&
230 (rxon1
->rx_chain
== rxon2
->rx_chain
) &&
231 (rxon1
->ofdm_basic_rates
== rxon2
->ofdm_basic_rates
)) {
232 IWL_DEBUG_INFO(priv
, "Using current RXON_ASSOC. Not resending.\n");
236 rxon_assoc
.flags
= ctx
->staging
.flags
;
237 rxon_assoc
.filter_flags
= ctx
->staging
.filter_flags
;
238 rxon_assoc
.ofdm_basic_rates
= ctx
->staging
.ofdm_basic_rates
;
239 rxon_assoc
.cck_basic_rates
= ctx
->staging
.cck_basic_rates
;
240 rxon_assoc
.reserved1
= 0;
241 rxon_assoc
.reserved2
= 0;
242 rxon_assoc
.reserved3
= 0;
243 rxon_assoc
.ofdm_ht_single_stream_basic_rates
=
244 ctx
->staging
.ofdm_ht_single_stream_basic_rates
;
245 rxon_assoc
.ofdm_ht_dual_stream_basic_rates
=
246 ctx
->staging
.ofdm_ht_dual_stream_basic_rates
;
247 rxon_assoc
.rx_chain_select_flags
= ctx
->staging
.rx_chain
;
248 rxon_assoc
.ofdm_ht_triple_stream_basic_rates
=
249 ctx
->staging
.ofdm_ht_triple_stream_basic_rates
;
250 rxon_assoc
.acquisition_data
= ctx
->staging
.acquisition_data
;
252 ret
= iwl_dvm_send_cmd_pdu(priv
, ctx
->rxon_assoc_cmd
,
253 CMD_ASYNC
, sizeof(rxon_assoc
), &rxon_assoc
);
257 static u16
iwl_adjust_beacon_interval(u16 beacon_val
, u16 max_beacon_val
)
263 * If mac80211 hasn't given us a beacon interval, program
264 * the default into the device (not checking this here
265 * would cause the adjustment below to return the maximum
266 * value, which may break PAN.)
269 return DEFAULT_BEACON_INTERVAL
;
272 * If the beacon interval we obtained from the peer
273 * is too large, we'll have to wake up more often
274 * (and in IBSS case, we'll beacon too much)
276 * For example, if max_beacon_val is 4096, and the
277 * requested beacon interval is 7000, we'll have to
278 * use 3500 to be able to wake up on the beacons.
280 * This could badly influence beacon detection stats.
283 beacon_factor
= (beacon_val
+ max_beacon_val
) / max_beacon_val
;
284 new_val
= beacon_val
/ beacon_factor
;
287 new_val
= max_beacon_val
;
292 static int iwl_send_rxon_timing(struct iwl_priv
*priv
,
293 struct iwl_rxon_context
*ctx
)
296 s32 interval_tm
, rem
;
297 struct ieee80211_conf
*conf
= NULL
;
299 struct ieee80211_vif
*vif
= ctx
->vif
;
301 conf
= &priv
->hw
->conf
;
303 lockdep_assert_held(&priv
->mutex
);
305 memset(&ctx
->timing
, 0, sizeof(struct iwl_rxon_time_cmd
));
307 ctx
->timing
.timestamp
= cpu_to_le64(priv
->timestamp
);
308 ctx
->timing
.listen_interval
= cpu_to_le16(conf
->listen_interval
);
310 beacon_int
= vif
? vif
->bss_conf
.beacon_int
: 0;
313 * TODO: For IBSS we need to get atim_window from mac80211,
314 * for now just always use 0
316 ctx
->timing
.atim_window
= 0;
318 if (ctx
->ctxid
== IWL_RXON_CTX_PAN
&&
319 (!ctx
->vif
|| ctx
->vif
->type
!= NL80211_IFTYPE_STATION
) &&
320 iwl_is_associated(priv
, IWL_RXON_CTX_BSS
) &&
321 priv
->contexts
[IWL_RXON_CTX_BSS
].vif
&&
322 priv
->contexts
[IWL_RXON_CTX_BSS
].vif
->bss_conf
.beacon_int
) {
323 ctx
->timing
.beacon_interval
=
324 priv
->contexts
[IWL_RXON_CTX_BSS
].timing
.beacon_interval
;
325 beacon_int
= le16_to_cpu(ctx
->timing
.beacon_interval
);
326 } else if (ctx
->ctxid
== IWL_RXON_CTX_BSS
&&
327 iwl_is_associated(priv
, IWL_RXON_CTX_PAN
) &&
328 priv
->contexts
[IWL_RXON_CTX_PAN
].vif
&&
329 priv
->contexts
[IWL_RXON_CTX_PAN
].vif
->bss_conf
.beacon_int
&&
330 (!iwl_is_associated_ctx(ctx
) || !ctx
->vif
||
331 !ctx
->vif
->bss_conf
.beacon_int
)) {
332 ctx
->timing
.beacon_interval
=
333 priv
->contexts
[IWL_RXON_CTX_PAN
].timing
.beacon_interval
;
334 beacon_int
= le16_to_cpu(ctx
->timing
.beacon_interval
);
336 beacon_int
= iwl_adjust_beacon_interval(beacon_int
,
337 IWL_MAX_UCODE_BEACON_INTERVAL
* TIME_UNIT
);
338 ctx
->timing
.beacon_interval
= cpu_to_le16(beacon_int
);
341 ctx
->beacon_int
= beacon_int
;
343 tsf
= priv
->timestamp
; /* tsf is modifed by do_div: copy it */
344 interval_tm
= beacon_int
* TIME_UNIT
;
345 rem
= do_div(tsf
, interval_tm
);
346 ctx
->timing
.beacon_init_val
= cpu_to_le32(interval_tm
- rem
);
348 ctx
->timing
.dtim_period
= vif
? (vif
->bss_conf
.dtim_period
?: 1) : 1;
350 IWL_DEBUG_ASSOC(priv
,
351 "beacon interval %d beacon timer %d beacon tim %d\n",
352 le16_to_cpu(ctx
->timing
.beacon_interval
),
353 le32_to_cpu(ctx
->timing
.beacon_init_val
),
354 le16_to_cpu(ctx
->timing
.atim_window
));
356 return iwl_dvm_send_cmd_pdu(priv
, ctx
->rxon_timing_cmd
,
357 0, sizeof(ctx
->timing
), &ctx
->timing
);
360 static int iwlagn_rxon_disconn(struct iwl_priv
*priv
,
361 struct iwl_rxon_context
*ctx
)
364 struct iwl_rxon_cmd
*active
= (void *)&ctx
->active
;
366 if (ctx
->ctxid
== IWL_RXON_CTX_BSS
) {
367 ret
= iwlagn_disable_bss(priv
, ctx
, &ctx
->staging
);
369 ret
= iwlagn_disable_pan(priv
, ctx
, &ctx
->staging
);
373 ret
= iwl_send_rxon_timing(priv
, ctx
);
375 IWL_ERR(priv
, "Failed to send timing (%d)!\n", ret
);
378 ret
= iwlagn_disconn_pan(priv
, ctx
, &ctx
->staging
);
385 * Un-assoc RXON clears the station table and WEP
386 * keys, so we have to restore those afterwards.
388 iwl_clear_ucode_stations(priv
, ctx
);
389 /* update -- might need P2P now */
390 iwl_update_bcast_station(priv
, ctx
);
391 iwl_restore_stations(priv
, ctx
);
392 ret
= iwl_restore_default_wep_keys(priv
, ctx
);
394 IWL_ERR(priv
, "Failed to restore WEP keys (%d)\n", ret
);
398 memcpy(active
, &ctx
->staging
, sizeof(*active
));
402 static int iwl_set_tx_power(struct iwl_priv
*priv
, s8 tx_power
, bool force
)
407 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
409 if (priv
->calib_disabled
& IWL_TX_POWER_CALIB_DISABLED
)
412 lockdep_assert_held(&priv
->mutex
);
414 if (priv
->tx_power_user_lmt
== tx_power
&& !force
)
417 if (tx_power
< IWLAGN_TX_POWER_TARGET_POWER_MIN
) {
419 "Requested user TXPOWER %d below lower limit %d.\n",
421 IWLAGN_TX_POWER_TARGET_POWER_MIN
);
425 if (tx_power
> DIV_ROUND_UP(priv
->nvm_data
->max_tx_pwr_half_dbm
, 2)) {
427 "Requested user TXPOWER %d above upper limit %d.\n",
428 tx_power
, priv
->nvm_data
->max_tx_pwr_half_dbm
);
432 if (!iwl_is_ready_rf(priv
))
435 /* scan complete and commit_rxon use tx_power_next value,
436 * it always need to be updated for newest request */
437 priv
->tx_power_next
= tx_power
;
439 /* do not set tx power when scanning or channel changing */
440 defer
= test_bit(STATUS_SCANNING
, &priv
->status
) ||
441 memcmp(&ctx
->active
, &ctx
->staging
, sizeof(ctx
->staging
));
442 if (defer
&& !force
) {
443 IWL_DEBUG_INFO(priv
, "Deferring tx power set\n");
447 prev_tx_power
= priv
->tx_power_user_lmt
;
448 priv
->tx_power_user_lmt
= tx_power
;
450 ret
= iwlagn_send_tx_power(priv
);
452 /* if fail to set tx_power, restore the orig. tx power */
454 priv
->tx_power_user_lmt
= prev_tx_power
;
455 priv
->tx_power_next
= prev_tx_power
;
460 static int iwlagn_rxon_connect(struct iwl_priv
*priv
,
461 struct iwl_rxon_context
*ctx
)
464 struct iwl_rxon_cmd
*active
= (void *)&ctx
->active
;
466 /* RXON timing must be before associated RXON */
467 if (ctx
->ctxid
== IWL_RXON_CTX_BSS
) {
468 ret
= iwl_send_rxon_timing(priv
, ctx
);
470 IWL_ERR(priv
, "Failed to send timing (%d)!\n", ret
);
474 /* QoS info may be cleared by previous un-assoc RXON */
475 iwlagn_update_qos(priv
, ctx
);
478 * We'll run into this code path when beaconing is
479 * enabled, but then we also need to send the beacon
482 if (ctx
->vif
&& (ctx
->vif
->type
== NL80211_IFTYPE_AP
)) {
483 ret
= iwlagn_update_beacon(priv
, ctx
->vif
);
486 "Error sending required beacon (%d)!\n",
492 priv
->start_calib
= 0;
494 * Apply the new configuration.
496 * Associated RXON doesn't clear the station table in uCode,
497 * so we don't need to restore stations etc. after this.
499 ret
= iwl_dvm_send_cmd_pdu(priv
, ctx
->rxon_cmd
, 0,
500 sizeof(struct iwl_rxon_cmd
), &ctx
->staging
);
502 IWL_ERR(priv
, "Error setting new RXON (%d)\n", ret
);
505 memcpy(active
, &ctx
->staging
, sizeof(*active
));
507 /* IBSS beacon needs to be sent after setting assoc */
508 if (ctx
->vif
&& (ctx
->vif
->type
== NL80211_IFTYPE_ADHOC
))
509 if (iwlagn_update_beacon(priv
, ctx
->vif
))
510 IWL_ERR(priv
, "Error sending IBSS beacon\n");
511 iwl_init_sensitivity(priv
);
514 * If we issue a new RXON command which required a tune then
515 * we must send a new TXPOWER command or we won't be able to
518 * It's expected we set power here if channel is changing.
520 ret
= iwl_set_tx_power(priv
, priv
->tx_power_next
, true);
522 IWL_ERR(priv
, "Error sending TX power (%d)\n", ret
);
526 if (ctx
->vif
&& ctx
->vif
->type
== NL80211_IFTYPE_STATION
&&
527 priv
->cfg
->ht_params
&& priv
->cfg
->ht_params
->smps_mode
)
528 ieee80211_request_smps(ctx
->vif
,
529 priv
->cfg
->ht_params
->smps_mode
);
534 int iwlagn_set_pan_params(struct iwl_priv
*priv
)
536 struct iwl_wipan_params_cmd cmd
;
537 struct iwl_rxon_context
*ctx_bss
, *ctx_pan
;
538 int slot0
= 300, slot1
= 0;
541 if (priv
->valid_contexts
== BIT(IWL_RXON_CTX_BSS
))
544 BUILD_BUG_ON(NUM_IWL_RXON_CTX
!= 2);
546 lockdep_assert_held(&priv
->mutex
);
548 ctx_bss
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
549 ctx_pan
= &priv
->contexts
[IWL_RXON_CTX_PAN
];
552 * If the PAN context is inactive, then we don't need
553 * to update the PAN parameters, the last thing we'll
554 * have done before it goes inactive is making the PAN
555 * parameters be WLAN-only.
557 if (!ctx_pan
->is_active
)
560 memset(&cmd
, 0, sizeof(cmd
));
562 /* only 2 slots are currently allowed */
565 cmd
.slots
[0].type
= 0; /* BSS */
566 cmd
.slots
[1].type
= 1; /* PAN */
568 if (ctx_bss
->vif
&& ctx_pan
->vif
) {
569 int bcnint
= ctx_pan
->beacon_int
;
570 int dtim
= ctx_pan
->vif
->bss_conf
.dtim_period
?: 1;
572 /* should be set, but seems unused?? */
573 cmd
.flags
|= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE
);
575 if (ctx_pan
->vif
->type
== NL80211_IFTYPE_AP
&&
577 bcnint
!= ctx_bss
->beacon_int
) {
579 "beacon intervals don't match (%d, %d)\n",
580 ctx_bss
->beacon_int
, ctx_pan
->beacon_int
);
582 bcnint
= max_t(int, bcnint
,
583 ctx_bss
->beacon_int
);
585 bcnint
= DEFAULT_BEACON_INTERVAL
;
587 slot1
= bcnint
- slot0
;
589 if (test_bit(STATUS_SCAN_HW
, &priv
->status
) ||
590 (!ctx_bss
->vif
->bss_conf
.idle
&&
591 !ctx_bss
->vif
->bss_conf
.assoc
)) {
592 slot0
= dtim
* bcnint
* 3 - IWL_MIN_SLOT_TIME
;
593 slot1
= IWL_MIN_SLOT_TIME
;
594 } else if (!ctx_pan
->vif
->bss_conf
.idle
&&
595 !ctx_pan
->vif
->bss_conf
.assoc
) {
596 slot1
= dtim
* bcnint
* 3 - IWL_MIN_SLOT_TIME
;
597 slot0
= IWL_MIN_SLOT_TIME
;
599 } else if (ctx_pan
->vif
) {
601 slot1
= max_t(int, 1, ctx_pan
->vif
->bss_conf
.dtim_period
) *
603 slot1
= max_t(int, DEFAULT_BEACON_INTERVAL
, slot1
);
605 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
606 slot0
= slot1
* 3 - IWL_MIN_SLOT_TIME
;
607 slot1
= IWL_MIN_SLOT_TIME
;
611 cmd
.slots
[0].width
= cpu_to_le16(slot0
);
612 cmd
.slots
[1].width
= cpu_to_le16(slot1
);
614 ret
= iwl_dvm_send_cmd_pdu(priv
, REPLY_WIPAN_PARAMS
, 0,
617 IWL_ERR(priv
, "Error setting PAN parameters (%d)\n", ret
);
622 static void _iwl_set_rxon_ht(struct iwl_priv
*priv
,
623 struct iwl_ht_config
*ht_conf
,
624 struct iwl_rxon_context
*ctx
)
626 struct iwl_rxon_cmd
*rxon
= &ctx
->staging
;
628 if (!ctx
->ht
.enabled
) {
629 rxon
->flags
&= ~(RXON_FLG_CHANNEL_MODE_MSK
|
630 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
|
631 RXON_FLG_HT40_PROT_MSK
|
632 RXON_FLG_HT_PROT_MSK
);
636 /* FIXME: if the definition of ht.protection changed, the "translation"
637 * will be needed for rxon->flags
639 rxon
->flags
|= cpu_to_le32(ctx
->ht
.protection
<<
640 RXON_FLG_HT_OPERATING_MODE_POS
);
642 /* Set up channel bandwidth:
643 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
644 /* clear the HT channel mode before set the mode */
645 rxon
->flags
&= ~(RXON_FLG_CHANNEL_MODE_MSK
|
646 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
);
647 if (iwl_is_ht40_tx_allowed(priv
, ctx
, NULL
)) {
649 if (ctx
->ht
.protection
==
650 IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
) {
651 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_PURE_40
;
653 * Note: control channel is opposite of extension
656 switch (ctx
->ht
.extension_chan_offset
) {
657 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE
:
659 ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
;
661 case IEEE80211_HT_PARAM_CHA_SEC_BELOW
:
663 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
;
668 * Note: control channel is opposite of extension
671 switch (ctx
->ht
.extension_chan_offset
) {
672 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE
:
674 ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
);
675 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_MIXED
;
677 case IEEE80211_HT_PARAM_CHA_SEC_BELOW
:
678 rxon
->flags
|= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
;
679 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_MIXED
;
681 case IEEE80211_HT_PARAM_CHA_SEC_NONE
:
684 * channel location only valid if in Mixed
688 "invalid extension channel offset\n");
693 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_LEGACY
;
696 iwlagn_set_rxon_chain(priv
, ctx
);
698 IWL_DEBUG_ASSOC(priv
, "rxon flags 0x%X operation mode :0x%X "
699 "extension channel offset 0x%x\n",
700 le32_to_cpu(rxon
->flags
), ctx
->ht
.protection
,
701 ctx
->ht
.extension_chan_offset
);
704 void iwl_set_rxon_ht(struct iwl_priv
*priv
, struct iwl_ht_config
*ht_conf
)
706 struct iwl_rxon_context
*ctx
;
708 for_each_context(priv
, ctx
)
709 _iwl_set_rxon_ht(priv
, ht_conf
, ctx
);
713 * iwl_set_rxon_channel - Set the band and channel values in staging RXON
714 * @ch: requested channel as a pointer to struct ieee80211_channel
716 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
717 * in the staging RXON flag structure based on the ch->band
719 void iwl_set_rxon_channel(struct iwl_priv
*priv
, struct ieee80211_channel
*ch
,
720 struct iwl_rxon_context
*ctx
)
722 enum ieee80211_band band
= ch
->band
;
723 u16 channel
= ch
->hw_value
;
725 if ((le16_to_cpu(ctx
->staging
.channel
) == channel
) &&
726 (priv
->band
== band
))
729 ctx
->staging
.channel
= cpu_to_le16(channel
);
730 if (band
== IEEE80211_BAND_5GHZ
)
731 ctx
->staging
.flags
&= ~RXON_FLG_BAND_24G_MSK
;
733 ctx
->staging
.flags
|= RXON_FLG_BAND_24G_MSK
;
737 IWL_DEBUG_INFO(priv
, "Staging channel set to %d [%d]\n", channel
, band
);
741 void iwl_set_flags_for_band(struct iwl_priv
*priv
,
742 struct iwl_rxon_context
*ctx
,
743 enum ieee80211_band band
,
744 struct ieee80211_vif
*vif
)
746 if (band
== IEEE80211_BAND_5GHZ
) {
747 ctx
->staging
.flags
&=
748 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
750 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
752 /* Copied from iwl_post_associate() */
753 if (vif
&& vif
->bss_conf
.use_short_slot
)
754 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
756 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
758 ctx
->staging
.flags
|= RXON_FLG_BAND_24G_MSK
;
759 ctx
->staging
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
760 ctx
->staging
.flags
&= ~RXON_FLG_CCK_MSK
;
764 static void iwl_set_rxon_hwcrypto(struct iwl_priv
*priv
,
765 struct iwl_rxon_context
*ctx
, int hw_decrypt
)
767 struct iwl_rxon_cmd
*rxon
= &ctx
->staging
;
770 rxon
->filter_flags
&= ~RXON_FILTER_DIS_DECRYPT_MSK
;
772 rxon
->filter_flags
|= RXON_FILTER_DIS_DECRYPT_MSK
;
776 /* validate RXON structure is valid */
777 static int iwl_check_rxon_cmd(struct iwl_priv
*priv
,
778 struct iwl_rxon_context
*ctx
)
780 struct iwl_rxon_cmd
*rxon
= &ctx
->staging
;
783 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
784 if (rxon
->flags
& RXON_FLG_TGJ_NARROW_BAND_MSK
) {
785 IWL_WARN(priv
, "check 2.4G: wrong narrow\n");
788 if (rxon
->flags
& RXON_FLG_RADAR_DETECT_MSK
) {
789 IWL_WARN(priv
, "check 2.4G: wrong radar\n");
793 if (!(rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
)) {
794 IWL_WARN(priv
, "check 5.2G: not short slot!\n");
797 if (rxon
->flags
& RXON_FLG_CCK_MSK
) {
798 IWL_WARN(priv
, "check 5.2G: CCK!\n");
802 if ((rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1) {
803 IWL_WARN(priv
, "mac/bssid mcast!\n");
807 /* make sure basic rates 6Mbps and 1Mbps are supported */
808 if ((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0 &&
809 (rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0) {
810 IWL_WARN(priv
, "neither 1 nor 6 are basic\n");
814 if (le16_to_cpu(rxon
->assoc_id
) > 2007) {
815 IWL_WARN(priv
, "aid > 2007\n");
819 if ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
820 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
)) {
821 IWL_WARN(priv
, "CCK and short slot\n");
825 if ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
826 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
)) {
827 IWL_WARN(priv
, "CCK and auto detect\n");
831 if ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
832 RXON_FLG_TGG_PROTECT_MSK
)) ==
833 RXON_FLG_TGG_PROTECT_MSK
) {
834 IWL_WARN(priv
, "TGg but no auto-detect\n");
838 if (rxon
->channel
== 0) {
839 IWL_WARN(priv
, "zero channel is invalid\n");
843 WARN(errors
, "Invalid RXON (%#x), channel %d",
844 errors
, le16_to_cpu(rxon
->channel
));
846 return errors
? -EINVAL
: 0;
850 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
851 * @priv: staging_rxon is compared to active_rxon
853 * If the RXON structure is changing enough to require a new tune,
854 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
855 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
857 static int iwl_full_rxon_required(struct iwl_priv
*priv
,
858 struct iwl_rxon_context
*ctx
)
860 const struct iwl_rxon_cmd
*staging
= &ctx
->staging
;
861 const struct iwl_rxon_cmd
*active
= &ctx
->active
;
865 IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
869 #define CHK_NEQ(c1, c2) \
870 if ((c1) != (c2)) { \
871 IWL_DEBUG_INFO(priv, "need full RXON - " \
872 #c1 " != " #c2 " - %d != %d\n", \
877 /* These items are only settable from the full RXON command */
878 CHK(!iwl_is_associated_ctx(ctx
));
879 CHK(!ether_addr_equal(staging
->bssid_addr
, active
->bssid_addr
));
880 CHK(!ether_addr_equal(staging
->node_addr
, active
->node_addr
));
881 CHK(!ether_addr_equal(staging
->wlap_bssid_addr
,
882 active
->wlap_bssid_addr
));
883 CHK_NEQ(staging
->dev_type
, active
->dev_type
);
884 CHK_NEQ(staging
->channel
, active
->channel
);
885 CHK_NEQ(staging
->air_propagation
, active
->air_propagation
);
886 CHK_NEQ(staging
->ofdm_ht_single_stream_basic_rates
,
887 active
->ofdm_ht_single_stream_basic_rates
);
888 CHK_NEQ(staging
->ofdm_ht_dual_stream_basic_rates
,
889 active
->ofdm_ht_dual_stream_basic_rates
);
890 CHK_NEQ(staging
->ofdm_ht_triple_stream_basic_rates
,
891 active
->ofdm_ht_triple_stream_basic_rates
);
892 CHK_NEQ(staging
->assoc_id
, active
->assoc_id
);
894 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
895 * be updated with the RXON_ASSOC command -- however only some
896 * flag transitions are allowed using RXON_ASSOC */
898 /* Check if we are not switching bands */
899 CHK_NEQ(staging
->flags
& RXON_FLG_BAND_24G_MSK
,
900 active
->flags
& RXON_FLG_BAND_24G_MSK
);
902 /* Check if we are switching association toggle */
903 CHK_NEQ(staging
->filter_flags
& RXON_FILTER_ASSOC_MSK
,
904 active
->filter_flags
& RXON_FILTER_ASSOC_MSK
);
912 #ifdef CONFIG_IWLWIFI_DEBUG
913 void iwl_print_rx_config_cmd(struct iwl_priv
*priv
,
914 enum iwl_rxon_context_id ctxid
)
916 struct iwl_rxon_context
*ctx
= &priv
->contexts
[ctxid
];
917 struct iwl_rxon_cmd
*rxon
= &ctx
->staging
;
919 IWL_DEBUG_RADIO(priv
, "RX CONFIG:\n");
920 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
921 IWL_DEBUG_RADIO(priv
, "u16 channel: 0x%x\n",
922 le16_to_cpu(rxon
->channel
));
923 IWL_DEBUG_RADIO(priv
, "u32 flags: 0x%08X\n",
924 le32_to_cpu(rxon
->flags
));
925 IWL_DEBUG_RADIO(priv
, "u32 filter_flags: 0x%08x\n",
926 le32_to_cpu(rxon
->filter_flags
));
927 IWL_DEBUG_RADIO(priv
, "u8 dev_type: 0x%x\n", rxon
->dev_type
);
928 IWL_DEBUG_RADIO(priv
, "u8 ofdm_basic_rates: 0x%02x\n",
929 rxon
->ofdm_basic_rates
);
930 IWL_DEBUG_RADIO(priv
, "u8 cck_basic_rates: 0x%02x\n",
931 rxon
->cck_basic_rates
);
932 IWL_DEBUG_RADIO(priv
, "u8[6] node_addr: %pM\n", rxon
->node_addr
);
933 IWL_DEBUG_RADIO(priv
, "u8[6] bssid_addr: %pM\n", rxon
->bssid_addr
);
934 IWL_DEBUG_RADIO(priv
, "u16 assoc_id: 0x%x\n",
935 le16_to_cpu(rxon
->assoc_id
));
939 static void iwl_calc_basic_rates(struct iwl_priv
*priv
,
940 struct iwl_rxon_context
*ctx
)
942 int lowest_present_ofdm
= 100;
943 int lowest_present_cck
= 100;
948 struct ieee80211_supported_band
*sband
;
949 unsigned long basic
= ctx
->vif
->bss_conf
.basic_rates
;
952 sband
= priv
->hw
->wiphy
->bands
[priv
->hw
->conf
.chandef
.chan
->band
];
954 for_each_set_bit(i
, &basic
, BITS_PER_LONG
) {
955 int hw
= sband
->bitrates
[i
].hw_value
;
956 if (hw
>= IWL_FIRST_OFDM_RATE
) {
957 ofdm
|= BIT(hw
- IWL_FIRST_OFDM_RATE
);
958 if (lowest_present_ofdm
> hw
)
959 lowest_present_ofdm
= hw
;
961 BUILD_BUG_ON(IWL_FIRST_CCK_RATE
!= 0);
964 if (lowest_present_cck
> hw
)
965 lowest_present_cck
= hw
;
971 * Now we've got the basic rates as bitmaps in the ofdm and cck
972 * variables. This isn't sufficient though, as there might not
973 * be all the right rates in the bitmap. E.g. if the only basic
974 * rates are 5.5 Mbps and 11 Mbps, we still need to add 1 Mbps
975 * and 6 Mbps because the 802.11-2007 standard says in 9.6:
977 * [...] a STA responding to a received frame shall transmit
978 * its Control Response frame [...] at the highest rate in the
979 * BSSBasicRateSet parameter that is less than or equal to the
980 * rate of the immediately previous frame in the frame exchange
981 * sequence ([...]) and that is of the same modulation class
982 * ([...]) as the received frame. If no rate contained in the
983 * BSSBasicRateSet parameter meets these conditions, then the
984 * control frame sent in response to a received frame shall be
985 * transmitted at the highest mandatory rate of the PHY that is
986 * less than or equal to the rate of the received frame, and
987 * that is of the same modulation class as the received frame.
989 * As a consequence, we need to add all mandatory rates that are
990 * lower than all of the basic rates to these bitmaps.
993 if (IWL_RATE_24M_INDEX
< lowest_present_ofdm
)
994 ofdm
|= IWL_RATE_24M_MASK
>> IWL_FIRST_OFDM_RATE
;
995 if (IWL_RATE_12M_INDEX
< lowest_present_ofdm
)
996 ofdm
|= IWL_RATE_12M_MASK
>> IWL_FIRST_OFDM_RATE
;
997 /* 6M already there or needed so always add */
998 ofdm
|= IWL_RATE_6M_MASK
>> IWL_FIRST_OFDM_RATE
;
1001 * CCK is a bit more complex with DSSS vs. HR/DSSS vs. ERP.
1003 * - if no CCK rates are basic, it must be ERP since there must
1004 * be some basic rates at all, so they're OFDM => ERP PHY
1005 * (or we're in 5 GHz, and the cck bitmap will never be used)
1006 * - if 11M is a basic rate, it must be ERP as well, so add 5.5M
1007 * - if 5.5M is basic, 1M and 2M are mandatory
1008 * - if 2M is basic, 1M is mandatory
1009 * - if 1M is basic, that's the only valid ACK rate.
1010 * As a consequence, it's not as complicated as it sounds, just add
1011 * any lower rates to the ACK rate bitmap.
1013 if (IWL_RATE_11M_INDEX
< lowest_present_cck
)
1014 cck
|= IWL_RATE_11M_MASK
>> IWL_FIRST_CCK_RATE
;
1015 if (IWL_RATE_5M_INDEX
< lowest_present_cck
)
1016 cck
|= IWL_RATE_5M_MASK
>> IWL_FIRST_CCK_RATE
;
1017 if (IWL_RATE_2M_INDEX
< lowest_present_cck
)
1018 cck
|= IWL_RATE_2M_MASK
>> IWL_FIRST_CCK_RATE
;
1019 /* 1M already there or needed so always add */
1020 cck
|= IWL_RATE_1M_MASK
>> IWL_FIRST_CCK_RATE
;
1022 IWL_DEBUG_RATE(priv
, "Set basic rates cck:0x%.2x ofdm:0x%.2x\n",
1025 /* "basic_rates" is a misnomer here -- should be called ACK rates */
1026 ctx
->staging
.cck_basic_rates
= cck
;
1027 ctx
->staging
.ofdm_basic_rates
= ofdm
;
1031 * iwlagn_commit_rxon - commit staging_rxon to hardware
1033 * The RXON command in staging_rxon is committed to the hardware and
1034 * the active_rxon structure is updated with the new data. This
1035 * function correctly transitions out of the RXON_ASSOC_MSK state if
1036 * a HW tune is required based on the RXON structure changes.
1038 * The connect/disconnect flow should be as the following:
1040 * 1. make sure send RXON command with association bit unset if not connect
1041 * this should include the channel and the band for the candidate
1042 * to be connected to
1043 * 2. Add Station before RXON association with the AP
1044 * 3. RXON_timing has to send before RXON for connection
1045 * 4. full RXON command - associated bit set
1046 * 5. use RXON_ASSOC command to update any flags changes
1048 int iwlagn_commit_rxon(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
1050 /* cast away the const for active_rxon in this function */
1051 struct iwl_rxon_cmd
*active
= (void *)&ctx
->active
;
1052 bool new_assoc
= !!(ctx
->staging
.filter_flags
& RXON_FILTER_ASSOC_MSK
);
1055 lockdep_assert_held(&priv
->mutex
);
1057 if (!iwl_is_alive(priv
))
1060 /* This function hardcodes a bunch of dual-mode assumptions */
1061 BUILD_BUG_ON(NUM_IWL_RXON_CTX
!= 2);
1063 if (!ctx
->is_active
)
1066 /* always get timestamp with Rx frame */
1067 ctx
->staging
.flags
|= RXON_FLG_TSF2HOST_MSK
;
1069 /* recalculate basic rates */
1070 iwl_calc_basic_rates(priv
, ctx
);
1073 * force CTS-to-self frames protection if RTS-CTS is not preferred
1074 * one aggregation protection method
1076 if (!priv
->hw_params
.use_rts_for_aggregation
)
1077 ctx
->staging
.flags
|= RXON_FLG_SELF_CTS_EN
;
1079 if ((ctx
->vif
&& ctx
->vif
->bss_conf
.use_short_slot
) ||
1080 !(ctx
->staging
.flags
& RXON_FLG_BAND_24G_MSK
))
1081 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
1083 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
1085 iwl_print_rx_config_cmd(priv
, ctx
->ctxid
);
1086 ret
= iwl_check_rxon_cmd(priv
, ctx
);
1088 IWL_ERR(priv
, "Invalid RXON configuration. Not committing.\n");
1093 * receive commit_rxon request
1094 * abort any previous channel switch if still in process
1096 if (test_bit(STATUS_CHANNEL_SWITCH_PENDING
, &priv
->status
) &&
1097 (priv
->switch_channel
!= ctx
->staging
.channel
)) {
1098 IWL_DEBUG_11H(priv
, "abort channel switch on %d\n",
1099 le16_to_cpu(priv
->switch_channel
));
1100 iwl_chswitch_done(priv
, false);
1104 * If we don't need to send a full RXON, we can use
1105 * iwl_rxon_assoc_cmd which is used to reconfigure filter
1106 * and other flags for the current radio configuration.
1108 if (!iwl_full_rxon_required(priv
, ctx
)) {
1109 ret
= iwlagn_send_rxon_assoc(priv
, ctx
);
1111 IWL_ERR(priv
, "Error setting RXON_ASSOC (%d)\n", ret
);
1115 memcpy(active
, &ctx
->staging
, sizeof(*active
));
1117 * We do not commit tx power settings while channel changing,
1118 * do it now if after settings changed.
1120 iwl_set_tx_power(priv
, priv
->tx_power_next
, false);
1122 /* make sure we are in the right PS state */
1123 iwl_power_update_mode(priv
, true);
1128 iwl_set_rxon_hwcrypto(priv
, ctx
, !iwlwifi_mod_params
.sw_crypto
);
1130 IWL_DEBUG_INFO(priv
,
1131 "Going to commit RXON\n"
1132 " * with%s RXON_FILTER_ASSOC_MSK\n"
1135 (new_assoc
? "" : "out"),
1136 le16_to_cpu(ctx
->staging
.channel
),
1137 ctx
->staging
.bssid_addr
);
1140 * Always clear associated first, but with the correct config.
1141 * This is required as for example station addition for the
1142 * AP station must be done after the BSSID is set to correctly
1143 * set up filters in the device.
1145 ret
= iwlagn_rxon_disconn(priv
, ctx
);
1149 ret
= iwlagn_set_pan_params(priv
);
1154 return iwlagn_rxon_connect(priv
, ctx
);
1159 void iwlagn_config_ht40(struct ieee80211_conf
*conf
,
1160 struct iwl_rxon_context
*ctx
)
1162 if (conf_is_ht40_minus(conf
)) {
1163 ctx
->ht
.extension_chan_offset
=
1164 IEEE80211_HT_PARAM_CHA_SEC_BELOW
;
1165 ctx
->ht
.is_40mhz
= true;
1166 } else if (conf_is_ht40_plus(conf
)) {
1167 ctx
->ht
.extension_chan_offset
=
1168 IEEE80211_HT_PARAM_CHA_SEC_ABOVE
;
1169 ctx
->ht
.is_40mhz
= true;
1171 ctx
->ht
.extension_chan_offset
=
1172 IEEE80211_HT_PARAM_CHA_SEC_NONE
;
1173 ctx
->ht
.is_40mhz
= false;
1177 int iwlagn_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
1179 struct iwl_priv
*priv
= IWL_MAC80211_GET_DVM(hw
);
1180 struct iwl_rxon_context
*ctx
;
1181 struct ieee80211_conf
*conf
= &hw
->conf
;
1182 struct ieee80211_channel
*channel
= conf
->chandef
.chan
;
1185 IWL_DEBUG_MAC80211(priv
, "enter: changed %#x\n", changed
);
1187 mutex_lock(&priv
->mutex
);
1189 if (unlikely(test_bit(STATUS_SCANNING
, &priv
->status
))) {
1190 IWL_DEBUG_MAC80211(priv
, "leave - scanning\n");
1194 if (!iwl_is_ready(priv
)) {
1195 IWL_DEBUG_MAC80211(priv
, "leave - not ready\n");
1199 if (changed
& (IEEE80211_CONF_CHANGE_SMPS
|
1200 IEEE80211_CONF_CHANGE_CHANNEL
)) {
1201 /* mac80211 uses static for non-HT which is what we want */
1202 priv
->current_ht_config
.smps
= conf
->smps_mode
;
1205 * Recalculate chain counts.
1207 * If monitor mode is enabled then mac80211 will
1208 * set up the SM PS mode to OFF if an HT channel is
1211 for_each_context(priv
, ctx
)
1212 iwlagn_set_rxon_chain(priv
, ctx
);
1215 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
1216 for_each_context(priv
, ctx
) {
1217 /* Configure HT40 channels */
1218 if (ctx
->ht
.enabled
!= conf_is_ht(conf
))
1219 ctx
->ht
.enabled
= conf_is_ht(conf
);
1221 if (ctx
->ht
.enabled
) {
1222 /* if HT40 is used, it should not change
1223 * after associated except channel switch */
1224 if (!ctx
->ht
.is_40mhz
||
1225 !iwl_is_associated_ctx(ctx
))
1226 iwlagn_config_ht40(conf
, ctx
);
1228 ctx
->ht
.is_40mhz
= false;
1231 * Default to no protection. Protection mode will
1232 * later be set from BSS config in iwl_ht_conf
1234 ctx
->ht
.protection
= IEEE80211_HT_OP_MODE_PROTECTION_NONE
;
1236 /* if we are switching from ht to 2.4 clear flags
1237 * from any ht related info since 2.4 does not
1239 if (le16_to_cpu(ctx
->staging
.channel
) !=
1241 ctx
->staging
.flags
= 0;
1243 iwl_set_rxon_channel(priv
, channel
, ctx
);
1244 iwl_set_rxon_ht(priv
, &priv
->current_ht_config
);
1246 iwl_set_flags_for_band(priv
, ctx
, channel
->band
,
1250 iwl_update_bcast_stations(priv
);
1253 if (changed
& (IEEE80211_CONF_CHANGE_PS
|
1254 IEEE80211_CONF_CHANGE_IDLE
)) {
1255 ret
= iwl_power_update_mode(priv
, false);
1257 IWL_DEBUG_MAC80211(priv
, "Error setting sleep level\n");
1260 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
1261 IWL_DEBUG_MAC80211(priv
, "TX Power old=%d new=%d\n",
1262 priv
->tx_power_user_lmt
, conf
->power_level
);
1264 iwl_set_tx_power(priv
, conf
->power_level
, false);
1267 for_each_context(priv
, ctx
) {
1268 if (!memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
1270 iwlagn_commit_rxon(priv
, ctx
);
1273 mutex_unlock(&priv
->mutex
);
1274 IWL_DEBUG_MAC80211(priv
, "leave\n");
1279 static void iwlagn_check_needed_chains(struct iwl_priv
*priv
,
1280 struct iwl_rxon_context
*ctx
,
1281 struct ieee80211_bss_conf
*bss_conf
)
1283 struct ieee80211_vif
*vif
= ctx
->vif
;
1284 struct iwl_rxon_context
*tmp
;
1285 struct ieee80211_sta
*sta
;
1286 struct iwl_ht_config
*ht_conf
= &priv
->current_ht_config
;
1287 struct ieee80211_sta_ht_cap
*ht_cap
;
1290 lockdep_assert_held(&priv
->mutex
);
1292 switch (vif
->type
) {
1293 case NL80211_IFTYPE_STATION
:
1295 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
1298 * If at all, this can only happen through a race
1299 * when the AP disconnects us while we're still
1300 * setting up the connection, in that case mac80211
1301 * will soon tell us about that.
1303 need_multiple
= false;
1308 ht_cap
= &sta
->ht_cap
;
1310 need_multiple
= true;
1313 * If the peer advertises no support for receiving 2 and 3
1314 * stream MCS rates, it can't be transmitting them either.
1316 if (ht_cap
->mcs
.rx_mask
[1] == 0 &&
1317 ht_cap
->mcs
.rx_mask
[2] == 0) {
1318 need_multiple
= false;
1319 } else if (!(ht_cap
->mcs
.tx_params
&
1320 IEEE80211_HT_MCS_TX_DEFINED
)) {
1321 /* If it can't TX MCS at all ... */
1322 need_multiple
= false;
1323 } else if (ht_cap
->mcs
.tx_params
&
1324 IEEE80211_HT_MCS_TX_RX_DIFF
) {
1328 * But if it can receive them, it might still not
1329 * be able to transmit them, which is what we need
1330 * to check here -- so check the number of streams
1331 * it advertises for TX (if different from RX).
1334 maxstreams
= (ht_cap
->mcs
.tx_params
&
1335 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK
);
1337 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT
;
1340 if (maxstreams
<= 1)
1341 need_multiple
= false;
1346 case NL80211_IFTYPE_ADHOC
:
1348 need_multiple
= false;
1351 /* only AP really */
1352 need_multiple
= true;
1356 ctx
->ht_need_multiple_chains
= need_multiple
;
1358 if (!need_multiple
) {
1359 /* check all contexts */
1360 for_each_context(priv
, tmp
) {
1363 if (tmp
->ht_need_multiple_chains
) {
1364 need_multiple
= true;
1370 ht_conf
->single_chain_sufficient
= !need_multiple
;
1373 static void iwlagn_chain_noise_reset(struct iwl_priv
*priv
)
1375 struct iwl_chain_noise_data
*data
= &priv
->chain_noise_data
;
1378 if (priv
->calib_disabled
& IWL_CHAIN_NOISE_CALIB_DISABLED
)
1381 if ((data
->state
== IWL_CHAIN_NOISE_ALIVE
) &&
1382 iwl_is_any_associated(priv
)) {
1383 struct iwl_calib_chain_noise_reset_cmd cmd
;
1385 /* clear data for chain noise calibration algorithm */
1386 data
->chain_noise_a
= 0;
1387 data
->chain_noise_b
= 0;
1388 data
->chain_noise_c
= 0;
1389 data
->chain_signal_a
= 0;
1390 data
->chain_signal_b
= 0;
1391 data
->chain_signal_c
= 0;
1392 data
->beacon_count
= 0;
1394 memset(&cmd
, 0, sizeof(cmd
));
1395 iwl_set_calib_hdr(&cmd
.hdr
,
1396 priv
->phy_calib_chain_noise_reset_cmd
);
1397 ret
= iwl_dvm_send_cmd_pdu(priv
,
1398 REPLY_PHY_CALIBRATION_CMD
,
1399 0, sizeof(cmd
), &cmd
);
1402 "Could not send REPLY_PHY_CALIBRATION_CMD\n");
1403 data
->state
= IWL_CHAIN_NOISE_ACCUMULATE
;
1404 IWL_DEBUG_CALIB(priv
, "Run chain_noise_calibrate\n");
1408 void iwlagn_bss_info_changed(struct ieee80211_hw
*hw
,
1409 struct ieee80211_vif
*vif
,
1410 struct ieee80211_bss_conf
*bss_conf
,
1413 struct iwl_priv
*priv
= IWL_MAC80211_GET_DVM(hw
);
1414 struct iwl_rxon_context
*ctx
= iwl_rxon_ctx_from_vif(vif
);
1418 mutex_lock(&priv
->mutex
);
1420 if (changes
& BSS_CHANGED_IDLE
&& bss_conf
->idle
) {
1422 * If we go idle, then clearly no "passive-no-rx"
1423 * workaround is needed any more, this is a reset.
1425 iwlagn_lift_passive_no_rx(priv
);
1428 if (unlikely(!iwl_is_ready(priv
))) {
1429 IWL_DEBUG_MAC80211(priv
, "leave - not ready\n");
1430 mutex_unlock(&priv
->mutex
);
1434 if (unlikely(!ctx
->vif
)) {
1435 IWL_DEBUG_MAC80211(priv
, "leave - vif is NULL\n");
1436 mutex_unlock(&priv
->mutex
);
1440 if (changes
& BSS_CHANGED_BEACON_INT
)
1443 if (changes
& BSS_CHANGED_QOS
) {
1444 ctx
->qos_data
.qos_active
= bss_conf
->qos
;
1445 iwlagn_update_qos(priv
, ctx
);
1448 ctx
->staging
.assoc_id
= cpu_to_le16(vif
->bss_conf
.aid
);
1449 if (vif
->bss_conf
.use_short_preamble
)
1450 ctx
->staging
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
1452 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
1454 if (changes
& BSS_CHANGED_ASSOC
) {
1455 if (bss_conf
->assoc
) {
1456 priv
->timestamp
= bss_conf
->sync_tsf
;
1457 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
1459 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
1461 if (ctx
->ctxid
== IWL_RXON_CTX_BSS
)
1462 priv
->have_rekey_data
= false;
1465 iwlagn_bt_coex_rssi_monitor(priv
);
1468 if (ctx
->ht
.enabled
) {
1469 ctx
->ht
.protection
= bss_conf
->ht_operation_mode
&
1470 IEEE80211_HT_OP_MODE_PROTECTION
;
1471 ctx
->ht
.non_gf_sta_present
= !!(bss_conf
->ht_operation_mode
&
1472 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
);
1473 iwlagn_check_needed_chains(priv
, ctx
, bss_conf
);
1474 iwl_set_rxon_ht(priv
, &priv
->current_ht_config
);
1477 iwlagn_set_rxon_chain(priv
, ctx
);
1479 if (bss_conf
->use_cts_prot
&& (priv
->band
!= IEEE80211_BAND_5GHZ
))
1480 ctx
->staging
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
1482 ctx
->staging
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
1484 if (bss_conf
->use_cts_prot
)
1485 ctx
->staging
.flags
|= RXON_FLG_SELF_CTS_EN
;
1487 ctx
->staging
.flags
&= ~RXON_FLG_SELF_CTS_EN
;
1489 memcpy(ctx
->staging
.bssid_addr
, bss_conf
->bssid
, ETH_ALEN
);
1491 if (vif
->type
== NL80211_IFTYPE_AP
||
1492 vif
->type
== NL80211_IFTYPE_ADHOC
) {
1493 if (vif
->bss_conf
.enable_beacon
) {
1494 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
1495 priv
->beacon_ctx
= ctx
;
1497 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
1498 priv
->beacon_ctx
= NULL
;
1503 * If the ucode decides to do beacon filtering before
1504 * association, it will lose beacons that are needed
1505 * before sending frames out on passive channels. This
1506 * causes association failures on those channels. Enable
1507 * receiving beacons in such cases.
1510 if (vif
->type
== NL80211_IFTYPE_STATION
) {
1511 if (!bss_conf
->assoc
)
1512 ctx
->staging
.filter_flags
|= RXON_FILTER_BCON_AWARE_MSK
;
1514 ctx
->staging
.filter_flags
&=
1515 ~RXON_FILTER_BCON_AWARE_MSK
;
1518 if (force
|| memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
1519 iwlagn_commit_rxon(priv
, ctx
);
1521 if (changes
& BSS_CHANGED_ASSOC
&& bss_conf
->assoc
) {
1523 * The chain noise calibration will enable PM upon
1524 * completion. If calibration has already been run
1525 * then we need to enable power management here.
1527 if (priv
->chain_noise_data
.state
== IWL_CHAIN_NOISE_DONE
)
1528 iwl_power_update_mode(priv
, false);
1530 /* Enable RX differential gain and sensitivity calibrations */
1531 iwlagn_chain_noise_reset(priv
);
1532 priv
->start_calib
= 1;
1535 if (changes
& BSS_CHANGED_IBSS
) {
1536 ret
= iwlagn_manage_ibss_station(priv
, vif
,
1537 bss_conf
->ibss_joined
);
1539 IWL_ERR(priv
, "failed to %s IBSS station %pM\n",
1540 bss_conf
->ibss_joined
? "add" : "remove",
1544 if (changes
& BSS_CHANGED_BEACON
&& priv
->beacon_ctx
== ctx
) {
1545 if (iwlagn_update_beacon(priv
, vif
))
1546 IWL_ERR(priv
, "Error updating beacon\n");
1549 mutex_unlock(&priv
->mutex
);
1552 void iwlagn_post_scan(struct iwl_priv
*priv
)
1554 struct iwl_rxon_context
*ctx
;
1557 * We do not commit power settings while scan is pending,
1558 * do it now if the settings changed.
1560 iwl_power_set_mode(priv
, &priv
->power_data
.sleep_cmd_next
, false);
1561 iwl_set_tx_power(priv
, priv
->tx_power_next
, false);
1564 * Since setting the RXON may have been deferred while
1565 * performing the scan, fire one off if needed
1567 for_each_context(priv
, ctx
)
1568 if (memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
1569 iwlagn_commit_rxon(priv
, ctx
);
1571 iwlagn_set_pan_params(priv
);