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
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>
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
));
46 ctx
->staging
.dev_type
= ctx
->unused_devtype
;
48 switch (ctx
->vif
->type
) {
49 case NL80211_IFTYPE_AP
:
50 ctx
->staging
.dev_type
= ctx
->ap_devtype
;
53 case NL80211_IFTYPE_STATION
:
54 ctx
->staging
.dev_type
= ctx
->station_devtype
;
55 ctx
->staging
.filter_flags
= RXON_FILTER_ACCEPT_GRP_MSK
;
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
;
66 IWL_ERR(priv
, "Unsupported interface type %d\n",
72 /* TODO: Figure out when short_preamble would be set and cache from
74 if (!hw_to_local(priv
->hw
)->short_preamble
)
75 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
77 ctx
->staging
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
80 ch_info
= iwl_get_channel_info(priv
, priv
->band
,
81 le16_to_cpu(ctx
->active
.channel
));
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
);
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
;
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
;
121 IWL_DEBUG_QUIET_RFKILL(priv
,
122 "Error clearing ASSOC_MSK on BSS (%d)\n", 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
;
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
),
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
;
152 IWL_ERR(priv
, "Error disabling PAN (%d)\n", ret
);
153 iwl_remove_notification(&priv
->notif_wait
, &disable_wait
);
155 ret
= iwl_wait_notification(&priv
->notif_wait
,
158 IWL_ERR(priv
, "Timed out waiting for PAN disable\n");
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
;
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
;
180 void iwlagn_update_qos(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
187 ctx
->qos_data
.def_qos_parm
.qos_flags
= 0;
189 if (ctx
->qos_data
.qos_active
)
190 ctx
->qos_data
.def_qos_parm
.qos_flags
|=
191 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
194 ctx
->qos_data
.def_qos_parm
.qos_flags
|= QOS_PARAM_FLG_TGN_MSK
;
196 IWL_DEBUG_INFO(priv
, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
197 ctx
->qos_data
.qos_active
,
198 ctx
->qos_data
.def_qos_parm
.qos_flags
);
200 ret
= iwl_dvm_send_cmd_pdu(priv
, ctx
->qos_cmd
, CMD_SYNC
,
201 sizeof(struct iwl_qosparam_cmd
),
202 &ctx
->qos_data
.def_qos_parm
);
204 IWL_DEBUG_QUIET_RFKILL(priv
, "Failed to update QoS\n");
207 int iwlagn_update_beacon(struct iwl_priv
*priv
,
208 struct ieee80211_vif
*vif
)
210 lockdep_assert_held(&priv
->mutex
);
212 dev_kfree_skb(priv
->beacon_skb
);
213 priv
->beacon_skb
= ieee80211_beacon_get(priv
->hw
, vif
);
214 if (!priv
->beacon_skb
)
216 return iwlagn_send_beacon_cmd(priv
);
219 static int iwlagn_send_rxon_assoc(struct iwl_priv
*priv
,
220 struct iwl_rxon_context
*ctx
)
223 struct iwl_rxon_assoc_cmd rxon_assoc
;
224 const struct iwl_rxon_cmd
*rxon1
= &ctx
->staging
;
225 const struct iwl_rxon_cmd
*rxon2
= &ctx
->active
;
227 if ((rxon1
->flags
== rxon2
->flags
) &&
228 (rxon1
->filter_flags
== rxon2
->filter_flags
) &&
229 (rxon1
->cck_basic_rates
== rxon2
->cck_basic_rates
) &&
230 (rxon1
->ofdm_ht_single_stream_basic_rates
==
231 rxon2
->ofdm_ht_single_stream_basic_rates
) &&
232 (rxon1
->ofdm_ht_dual_stream_basic_rates
==
233 rxon2
->ofdm_ht_dual_stream_basic_rates
) &&
234 (rxon1
->ofdm_ht_triple_stream_basic_rates
==
235 rxon2
->ofdm_ht_triple_stream_basic_rates
) &&
236 (rxon1
->acquisition_data
== rxon2
->acquisition_data
) &&
237 (rxon1
->rx_chain
== rxon2
->rx_chain
) &&
238 (rxon1
->ofdm_basic_rates
== rxon2
->ofdm_basic_rates
)) {
239 IWL_DEBUG_INFO(priv
, "Using current RXON_ASSOC. Not resending.\n");
243 rxon_assoc
.flags
= ctx
->staging
.flags
;
244 rxon_assoc
.filter_flags
= ctx
->staging
.filter_flags
;
245 rxon_assoc
.ofdm_basic_rates
= ctx
->staging
.ofdm_basic_rates
;
246 rxon_assoc
.cck_basic_rates
= ctx
->staging
.cck_basic_rates
;
247 rxon_assoc
.reserved1
= 0;
248 rxon_assoc
.reserved2
= 0;
249 rxon_assoc
.reserved3
= 0;
250 rxon_assoc
.ofdm_ht_single_stream_basic_rates
=
251 ctx
->staging
.ofdm_ht_single_stream_basic_rates
;
252 rxon_assoc
.ofdm_ht_dual_stream_basic_rates
=
253 ctx
->staging
.ofdm_ht_dual_stream_basic_rates
;
254 rxon_assoc
.rx_chain_select_flags
= ctx
->staging
.rx_chain
;
255 rxon_assoc
.ofdm_ht_triple_stream_basic_rates
=
256 ctx
->staging
.ofdm_ht_triple_stream_basic_rates
;
257 rxon_assoc
.acquisition_data
= ctx
->staging
.acquisition_data
;
259 ret
= iwl_dvm_send_cmd_pdu(priv
, ctx
->rxon_assoc_cmd
,
260 CMD_ASYNC
, sizeof(rxon_assoc
), &rxon_assoc
);
264 static u16
iwl_adjust_beacon_interval(u16 beacon_val
, u16 max_beacon_val
)
270 * If mac80211 hasn't given us a beacon interval, program
271 * the default into the device (not checking this here
272 * would cause the adjustment below to return the maximum
273 * value, which may break PAN.)
276 return DEFAULT_BEACON_INTERVAL
;
279 * If the beacon interval we obtained from the peer
280 * is too large, we'll have to wake up more often
281 * (and in IBSS case, we'll beacon too much)
283 * For example, if max_beacon_val is 4096, and the
284 * requested beacon interval is 7000, we'll have to
285 * use 3500 to be able to wake up on the beacons.
287 * This could badly influence beacon detection stats.
290 beacon_factor
= (beacon_val
+ max_beacon_val
) / max_beacon_val
;
291 new_val
= beacon_val
/ beacon_factor
;
294 new_val
= max_beacon_val
;
299 static int iwl_send_rxon_timing(struct iwl_priv
*priv
,
300 struct iwl_rxon_context
*ctx
)
303 s32 interval_tm
, rem
;
304 struct ieee80211_conf
*conf
= NULL
;
306 struct ieee80211_vif
*vif
= ctx
->vif
;
308 conf
= &priv
->hw
->conf
;
310 lockdep_assert_held(&priv
->mutex
);
312 memset(&ctx
->timing
, 0, sizeof(struct iwl_rxon_time_cmd
));
314 ctx
->timing
.timestamp
= cpu_to_le64(priv
->timestamp
);
315 ctx
->timing
.listen_interval
= cpu_to_le16(conf
->listen_interval
);
317 beacon_int
= vif
? vif
->bss_conf
.beacon_int
: 0;
320 * TODO: For IBSS we need to get atim_window from mac80211,
321 * for now just always use 0
323 ctx
->timing
.atim_window
= 0;
325 if (ctx
->ctxid
== IWL_RXON_CTX_PAN
&&
326 (!ctx
->vif
|| ctx
->vif
->type
!= NL80211_IFTYPE_STATION
) &&
327 iwl_is_associated(priv
, IWL_RXON_CTX_BSS
) &&
328 priv
->contexts
[IWL_RXON_CTX_BSS
].vif
&&
329 priv
->contexts
[IWL_RXON_CTX_BSS
].vif
->bss_conf
.beacon_int
) {
330 ctx
->timing
.beacon_interval
=
331 priv
->contexts
[IWL_RXON_CTX_BSS
].timing
.beacon_interval
;
332 beacon_int
= le16_to_cpu(ctx
->timing
.beacon_interval
);
333 } else if (ctx
->ctxid
== IWL_RXON_CTX_BSS
&&
334 iwl_is_associated(priv
, IWL_RXON_CTX_PAN
) &&
335 priv
->contexts
[IWL_RXON_CTX_PAN
].vif
&&
336 priv
->contexts
[IWL_RXON_CTX_PAN
].vif
->bss_conf
.beacon_int
&&
337 (!iwl_is_associated_ctx(ctx
) || !ctx
->vif
||
338 !ctx
->vif
->bss_conf
.beacon_int
)) {
339 ctx
->timing
.beacon_interval
=
340 priv
->contexts
[IWL_RXON_CTX_PAN
].timing
.beacon_interval
;
341 beacon_int
= le16_to_cpu(ctx
->timing
.beacon_interval
);
343 beacon_int
= iwl_adjust_beacon_interval(beacon_int
,
344 IWL_MAX_UCODE_BEACON_INTERVAL
* TIME_UNIT
);
345 ctx
->timing
.beacon_interval
= cpu_to_le16(beacon_int
);
348 ctx
->beacon_int
= beacon_int
;
350 tsf
= priv
->timestamp
; /* tsf is modifed by do_div: copy it */
351 interval_tm
= beacon_int
* TIME_UNIT
;
352 rem
= do_div(tsf
, interval_tm
);
353 ctx
->timing
.beacon_init_val
= cpu_to_le32(interval_tm
- rem
);
355 ctx
->timing
.dtim_period
= vif
? (vif
->bss_conf
.dtim_period
?: 1) : 1;
357 IWL_DEBUG_ASSOC(priv
,
358 "beacon interval %d beacon timer %d beacon tim %d\n",
359 le16_to_cpu(ctx
->timing
.beacon_interval
),
360 le32_to_cpu(ctx
->timing
.beacon_init_val
),
361 le16_to_cpu(ctx
->timing
.atim_window
));
363 return iwl_dvm_send_cmd_pdu(priv
, ctx
->rxon_timing_cmd
,
364 CMD_SYNC
, sizeof(ctx
->timing
), &ctx
->timing
);
367 static int iwlagn_rxon_disconn(struct iwl_priv
*priv
,
368 struct iwl_rxon_context
*ctx
)
371 struct iwl_rxon_cmd
*active
= (void *)&ctx
->active
;
373 if (ctx
->ctxid
== IWL_RXON_CTX_BSS
) {
374 ret
= iwlagn_disable_bss(priv
, ctx
, &ctx
->staging
);
376 ret
= iwlagn_disable_pan(priv
, ctx
, &ctx
->staging
);
380 ret
= iwl_send_rxon_timing(priv
, ctx
);
382 IWL_ERR(priv
, "Failed to send timing (%d)!\n", ret
);
385 ret
= iwlagn_disconn_pan(priv
, ctx
, &ctx
->staging
);
392 * Un-assoc RXON clears the station table and WEP
393 * keys, so we have to restore those afterwards.
395 iwl_clear_ucode_stations(priv
, ctx
);
396 /* update -- might need P2P now */
397 iwl_update_bcast_station(priv
, ctx
);
398 iwl_restore_stations(priv
, ctx
);
399 ret
= iwl_restore_default_wep_keys(priv
, ctx
);
401 IWL_ERR(priv
, "Failed to restore WEP keys (%d)\n", ret
);
405 memcpy(active
, &ctx
->staging
, sizeof(*active
));
409 static int iwl_set_tx_power(struct iwl_priv
*priv
, s8 tx_power
, bool force
)
414 struct iwl_rxon_context
*ctx
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
416 if (priv
->calib_disabled
& IWL_TX_POWER_CALIB_DISABLED
)
419 lockdep_assert_held(&priv
->mutex
);
421 if (priv
->tx_power_user_lmt
== tx_power
&& !force
)
424 if (tx_power
< IWLAGN_TX_POWER_TARGET_POWER_MIN
) {
426 "Requested user TXPOWER %d below lower limit %d.\n",
428 IWLAGN_TX_POWER_TARGET_POWER_MIN
);
432 if (tx_power
> priv
->tx_power_device_lmt
) {
434 "Requested user TXPOWER %d above upper limit %d.\n",
435 tx_power
, priv
->tx_power_device_lmt
);
439 if (!iwl_is_ready_rf(priv
))
442 /* scan complete and commit_rxon use tx_power_next value,
443 * it always need to be updated for newest request */
444 priv
->tx_power_next
= tx_power
;
446 /* do not set tx power when scanning or channel changing */
447 defer
= test_bit(STATUS_SCANNING
, &priv
->status
) ||
448 memcmp(&ctx
->active
, &ctx
->staging
, sizeof(ctx
->staging
));
449 if (defer
&& !force
) {
450 IWL_DEBUG_INFO(priv
, "Deferring tx power set\n");
454 prev_tx_power
= priv
->tx_power_user_lmt
;
455 priv
->tx_power_user_lmt
= tx_power
;
457 ret
= iwlagn_send_tx_power(priv
);
459 /* if fail to set tx_power, restore the orig. tx power */
461 priv
->tx_power_user_lmt
= prev_tx_power
;
462 priv
->tx_power_next
= prev_tx_power
;
467 static int iwlagn_rxon_connect(struct iwl_priv
*priv
,
468 struct iwl_rxon_context
*ctx
)
471 struct iwl_rxon_cmd
*active
= (void *)&ctx
->active
;
473 /* RXON timing must be before associated RXON */
474 if (ctx
->ctxid
== IWL_RXON_CTX_BSS
) {
475 ret
= iwl_send_rxon_timing(priv
, ctx
);
477 IWL_ERR(priv
, "Failed to send timing (%d)!\n", ret
);
481 /* QoS info may be cleared by previous un-assoc RXON */
482 iwlagn_update_qos(priv
, ctx
);
485 * We'll run into this code path when beaconing is
486 * enabled, but then we also need to send the beacon
489 if (ctx
->vif
&& (ctx
->vif
->type
== NL80211_IFTYPE_AP
)) {
490 ret
= iwlagn_update_beacon(priv
, ctx
->vif
);
493 "Error sending required beacon (%d)!\n",
499 priv
->start_calib
= 0;
501 * Apply the new configuration.
503 * Associated RXON doesn't clear the station table in uCode,
504 * so we don't need to restore stations etc. after this.
506 ret
= iwl_dvm_send_cmd_pdu(priv
, ctx
->rxon_cmd
, CMD_SYNC
,
507 sizeof(struct iwl_rxon_cmd
), &ctx
->staging
);
509 IWL_ERR(priv
, "Error setting new RXON (%d)\n", ret
);
512 memcpy(active
, &ctx
->staging
, sizeof(*active
));
514 /* IBSS beacon needs to be sent after setting assoc */
515 if (ctx
->vif
&& (ctx
->vif
->type
== NL80211_IFTYPE_ADHOC
))
516 if (iwlagn_update_beacon(priv
, ctx
->vif
))
517 IWL_ERR(priv
, "Error sending IBSS beacon\n");
518 iwl_init_sensitivity(priv
);
521 * If we issue a new RXON command which required a tune then
522 * we must send a new TXPOWER command or we won't be able to
525 * It's expected we set power here if channel is changing.
527 ret
= iwl_set_tx_power(priv
, priv
->tx_power_next
, true);
529 IWL_ERR(priv
, "Error sending TX power (%d)\n", ret
);
533 if (ctx
->vif
&& ctx
->vif
->type
== NL80211_IFTYPE_STATION
&&
534 cfg(priv
)->ht_params
&& cfg(priv
)->ht_params
->smps_mode
)
535 ieee80211_request_smps(ctx
->vif
,
536 cfg(priv
)->ht_params
->smps_mode
);
541 int iwlagn_set_pan_params(struct iwl_priv
*priv
)
543 struct iwl_wipan_params_cmd cmd
;
544 struct iwl_rxon_context
*ctx_bss
, *ctx_pan
;
545 int slot0
= 300, slot1
= 0;
548 if (priv
->valid_contexts
== BIT(IWL_RXON_CTX_BSS
))
551 BUILD_BUG_ON(NUM_IWL_RXON_CTX
!= 2);
553 lockdep_assert_held(&priv
->mutex
);
555 ctx_bss
= &priv
->contexts
[IWL_RXON_CTX_BSS
];
556 ctx_pan
= &priv
->contexts
[IWL_RXON_CTX_PAN
];
559 * If the PAN context is inactive, then we don't need
560 * to update the PAN parameters, the last thing we'll
561 * have done before it goes inactive is making the PAN
562 * parameters be WLAN-only.
564 if (!ctx_pan
->is_active
)
567 memset(&cmd
, 0, sizeof(cmd
));
569 /* only 2 slots are currently allowed */
572 cmd
.slots
[0].type
= 0; /* BSS */
573 cmd
.slots
[1].type
= 1; /* PAN */
575 if (priv
->hw_roc_setup
) {
576 /* both contexts must be used for this to happen */
577 slot1
= IWL_MIN_SLOT_TIME
;
579 } else if (ctx_bss
->vif
&& ctx_pan
->vif
) {
580 int bcnint
= ctx_pan
->beacon_int
;
581 int dtim
= ctx_pan
->vif
->bss_conf
.dtim_period
?: 1;
583 /* should be set, but seems unused?? */
584 cmd
.flags
|= cpu_to_le16(IWL_WIPAN_PARAMS_FLG_SLOTTED_MODE
);
586 if (ctx_pan
->vif
->type
== NL80211_IFTYPE_AP
&&
588 bcnint
!= ctx_bss
->beacon_int
) {
590 "beacon intervals don't match (%d, %d)\n",
591 ctx_bss
->beacon_int
, ctx_pan
->beacon_int
);
593 bcnint
= max_t(int, bcnint
,
594 ctx_bss
->beacon_int
);
596 bcnint
= DEFAULT_BEACON_INTERVAL
;
598 slot1
= bcnint
- slot0
;
600 if (test_bit(STATUS_SCAN_HW
, &priv
->status
) ||
601 (!ctx_bss
->vif
->bss_conf
.idle
&&
602 !ctx_bss
->vif
->bss_conf
.assoc
)) {
603 slot0
= dtim
* bcnint
* 3 - IWL_MIN_SLOT_TIME
;
604 slot1
= IWL_MIN_SLOT_TIME
;
605 } else if (!ctx_pan
->vif
->bss_conf
.idle
&&
606 !ctx_pan
->vif
->bss_conf
.assoc
) {
607 slot1
= dtim
* bcnint
* 3 - IWL_MIN_SLOT_TIME
;
608 slot0
= IWL_MIN_SLOT_TIME
;
610 } else if (ctx_pan
->vif
) {
612 slot1
= max_t(int, 1, ctx_pan
->vif
->bss_conf
.dtim_period
) *
614 slot1
= max_t(int, DEFAULT_BEACON_INTERVAL
, slot1
);
616 if (test_bit(STATUS_SCAN_HW
, &priv
->status
)) {
617 slot0
= slot1
* 3 - IWL_MIN_SLOT_TIME
;
618 slot1
= IWL_MIN_SLOT_TIME
;
622 cmd
.slots
[0].width
= cpu_to_le16(slot0
);
623 cmd
.slots
[1].width
= cpu_to_le16(slot1
);
625 ret
= iwl_dvm_send_cmd_pdu(priv
, REPLY_WIPAN_PARAMS
, CMD_SYNC
,
628 IWL_ERR(priv
, "Error setting PAN parameters (%d)\n", ret
);
633 static void _iwl_set_rxon_ht(struct iwl_priv
*priv
,
634 struct iwl_ht_config
*ht_conf
,
635 struct iwl_rxon_context
*ctx
)
637 struct iwl_rxon_cmd
*rxon
= &ctx
->staging
;
639 if (!ctx
->ht
.enabled
) {
640 rxon
->flags
&= ~(RXON_FLG_CHANNEL_MODE_MSK
|
641 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
|
642 RXON_FLG_HT40_PROT_MSK
|
643 RXON_FLG_HT_PROT_MSK
);
647 /* FIXME: if the definition of ht.protection changed, the "translation"
648 * will be needed for rxon->flags
650 rxon
->flags
|= cpu_to_le32(ctx
->ht
.protection
<<
651 RXON_FLG_HT_OPERATING_MODE_POS
);
653 /* Set up channel bandwidth:
654 * 20 MHz only, 20/40 mixed or pure 40 if ht40 ok */
655 /* clear the HT channel mode before set the mode */
656 rxon
->flags
&= ~(RXON_FLG_CHANNEL_MODE_MSK
|
657 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
);
658 if (iwl_is_ht40_tx_allowed(priv
, ctx
, NULL
)) {
660 if (ctx
->ht
.protection
==
661 IEEE80211_HT_OP_MODE_PROTECTION_20MHZ
) {
662 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_PURE_40
;
664 * Note: control channel is opposite of extension
667 switch (ctx
->ht
.extension_chan_offset
) {
668 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE
:
670 ~RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
;
672 case IEEE80211_HT_PARAM_CHA_SEC_BELOW
:
674 RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
;
679 * Note: control channel is opposite of extension
682 switch (ctx
->ht
.extension_chan_offset
) {
683 case IEEE80211_HT_PARAM_CHA_SEC_ABOVE
:
685 ~(RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
);
686 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_MIXED
;
688 case IEEE80211_HT_PARAM_CHA_SEC_BELOW
:
689 rxon
->flags
|= RXON_FLG_CTRL_CHANNEL_LOC_HI_MSK
;
690 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_MIXED
;
692 case IEEE80211_HT_PARAM_CHA_SEC_NONE
:
695 * channel location only valid if in Mixed
699 "invalid extension channel offset\n");
704 rxon
->flags
|= RXON_FLG_CHANNEL_MODE_LEGACY
;
707 iwlagn_set_rxon_chain(priv
, ctx
);
709 IWL_DEBUG_ASSOC(priv
, "rxon flags 0x%X operation mode :0x%X "
710 "extension channel offset 0x%x\n",
711 le32_to_cpu(rxon
->flags
), ctx
->ht
.protection
,
712 ctx
->ht
.extension_chan_offset
);
715 void iwl_set_rxon_ht(struct iwl_priv
*priv
, struct iwl_ht_config
*ht_conf
)
717 struct iwl_rxon_context
*ctx
;
719 for_each_context(priv
, ctx
)
720 _iwl_set_rxon_ht(priv
, ht_conf
, ctx
);
724 * iwl_set_rxon_channel - Set the band and channel values in staging RXON
725 * @ch: requested channel as a pointer to struct ieee80211_channel
727 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
728 * in the staging RXON flag structure based on the ch->band
730 void iwl_set_rxon_channel(struct iwl_priv
*priv
, struct ieee80211_channel
*ch
,
731 struct iwl_rxon_context
*ctx
)
733 enum ieee80211_band band
= ch
->band
;
734 u16 channel
= ch
->hw_value
;
736 if ((le16_to_cpu(ctx
->staging
.channel
) == channel
) &&
737 (priv
->band
== band
))
740 ctx
->staging
.channel
= cpu_to_le16(channel
);
741 if (band
== IEEE80211_BAND_5GHZ
)
742 ctx
->staging
.flags
&= ~RXON_FLG_BAND_24G_MSK
;
744 ctx
->staging
.flags
|= RXON_FLG_BAND_24G_MSK
;
748 IWL_DEBUG_INFO(priv
, "Staging channel set to %d [%d]\n", channel
, band
);
752 void iwl_set_flags_for_band(struct iwl_priv
*priv
,
753 struct iwl_rxon_context
*ctx
,
754 enum ieee80211_band band
,
755 struct ieee80211_vif
*vif
)
757 if (band
== IEEE80211_BAND_5GHZ
) {
758 ctx
->staging
.flags
&=
759 ~(RXON_FLG_BAND_24G_MSK
| RXON_FLG_AUTO_DETECT_MSK
761 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
763 /* Copied from iwl_post_associate() */
764 if (vif
&& vif
->bss_conf
.use_short_slot
)
765 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
767 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
769 ctx
->staging
.flags
|= RXON_FLG_BAND_24G_MSK
;
770 ctx
->staging
.flags
|= RXON_FLG_AUTO_DETECT_MSK
;
771 ctx
->staging
.flags
&= ~RXON_FLG_CCK_MSK
;
775 void iwl_set_rate(struct iwl_priv
*priv
)
777 struct iwl_rxon_context
*ctx
;
779 for_each_context(priv
, ctx
) {
780 ctx
->staging
.cck_basic_rates
=
781 (IWL_CCK_BASIC_RATES_MASK
>> IWL_FIRST_CCK_RATE
) & 0xF;
783 ctx
->staging
.ofdm_basic_rates
=
784 (IWL_OFDM_BASIC_RATES_MASK
>> IWL_FIRST_OFDM_RATE
) & 0xFF;
788 static void iwl_set_rxon_hwcrypto(struct iwl_priv
*priv
,
789 struct iwl_rxon_context
*ctx
, int hw_decrypt
)
791 struct iwl_rxon_cmd
*rxon
= &ctx
->staging
;
794 rxon
->filter_flags
&= ~RXON_FILTER_DIS_DECRYPT_MSK
;
796 rxon
->filter_flags
|= RXON_FILTER_DIS_DECRYPT_MSK
;
800 /* validate RXON structure is valid */
801 static int iwl_check_rxon_cmd(struct iwl_priv
*priv
,
802 struct iwl_rxon_context
*ctx
)
804 struct iwl_rxon_cmd
*rxon
= &ctx
->staging
;
807 if (rxon
->flags
& RXON_FLG_BAND_24G_MSK
) {
808 if (rxon
->flags
& RXON_FLG_TGJ_NARROW_BAND_MSK
) {
809 IWL_WARN(priv
, "check 2.4G: wrong narrow\n");
812 if (rxon
->flags
& RXON_FLG_RADAR_DETECT_MSK
) {
813 IWL_WARN(priv
, "check 2.4G: wrong radar\n");
817 if (!(rxon
->flags
& RXON_FLG_SHORT_SLOT_MSK
)) {
818 IWL_WARN(priv
, "check 5.2G: not short slot!\n");
821 if (rxon
->flags
& RXON_FLG_CCK_MSK
) {
822 IWL_WARN(priv
, "check 5.2G: CCK!\n");
826 if ((rxon
->node_addr
[0] | rxon
->bssid_addr
[0]) & 0x1) {
827 IWL_WARN(priv
, "mac/bssid mcast!\n");
831 /* make sure basic rates 6Mbps and 1Mbps are supported */
832 if ((rxon
->ofdm_basic_rates
& IWL_RATE_6M_MASK
) == 0 &&
833 (rxon
->cck_basic_rates
& IWL_RATE_1M_MASK
) == 0) {
834 IWL_WARN(priv
, "neither 1 nor 6 are basic\n");
838 if (le16_to_cpu(rxon
->assoc_id
) > 2007) {
839 IWL_WARN(priv
, "aid > 2007\n");
843 if ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
))
844 == (RXON_FLG_CCK_MSK
| RXON_FLG_SHORT_SLOT_MSK
)) {
845 IWL_WARN(priv
, "CCK and short slot\n");
849 if ((rxon
->flags
& (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
))
850 == (RXON_FLG_CCK_MSK
| RXON_FLG_AUTO_DETECT_MSK
)) {
851 IWL_WARN(priv
, "CCK and auto detect");
855 if ((rxon
->flags
& (RXON_FLG_AUTO_DETECT_MSK
|
856 RXON_FLG_TGG_PROTECT_MSK
)) ==
857 RXON_FLG_TGG_PROTECT_MSK
) {
858 IWL_WARN(priv
, "TGg but no auto-detect\n");
862 if (rxon
->channel
== 0) {
863 IWL_WARN(priv
, "zero channel is invalid\n");
867 WARN(errors
, "Invalid RXON (%#x), channel %d",
868 errors
, le16_to_cpu(rxon
->channel
));
870 return errors
? -EINVAL
: 0;
874 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
875 * @priv: staging_rxon is compared to active_rxon
877 * If the RXON structure is changing enough to require a new tune,
878 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
879 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
881 int iwl_full_rxon_required(struct iwl_priv
*priv
,
882 struct iwl_rxon_context
*ctx
)
884 const struct iwl_rxon_cmd
*staging
= &ctx
->staging
;
885 const struct iwl_rxon_cmd
*active
= &ctx
->active
;
889 IWL_DEBUG_INFO(priv, "need full RXON - " #cond "\n"); \
893 #define CHK_NEQ(c1, c2) \
894 if ((c1) != (c2)) { \
895 IWL_DEBUG_INFO(priv, "need full RXON - " \
896 #c1 " != " #c2 " - %d != %d\n", \
901 /* These items are only settable from the full RXON command */
902 CHK(!iwl_is_associated_ctx(ctx
));
903 CHK(compare_ether_addr(staging
->bssid_addr
, active
->bssid_addr
));
904 CHK(compare_ether_addr(staging
->node_addr
, active
->node_addr
));
905 CHK(compare_ether_addr(staging
->wlap_bssid_addr
,
906 active
->wlap_bssid_addr
));
907 CHK_NEQ(staging
->dev_type
, active
->dev_type
);
908 CHK_NEQ(staging
->channel
, active
->channel
);
909 CHK_NEQ(staging
->air_propagation
, active
->air_propagation
);
910 CHK_NEQ(staging
->ofdm_ht_single_stream_basic_rates
,
911 active
->ofdm_ht_single_stream_basic_rates
);
912 CHK_NEQ(staging
->ofdm_ht_dual_stream_basic_rates
,
913 active
->ofdm_ht_dual_stream_basic_rates
);
914 CHK_NEQ(staging
->ofdm_ht_triple_stream_basic_rates
,
915 active
->ofdm_ht_triple_stream_basic_rates
);
916 CHK_NEQ(staging
->assoc_id
, active
->assoc_id
);
918 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
919 * be updated with the RXON_ASSOC command -- however only some
920 * flag transitions are allowed using RXON_ASSOC */
922 /* Check if we are not switching bands */
923 CHK_NEQ(staging
->flags
& RXON_FLG_BAND_24G_MSK
,
924 active
->flags
& RXON_FLG_BAND_24G_MSK
);
926 /* Check if we are switching association toggle */
927 CHK_NEQ(staging
->filter_flags
& RXON_FILTER_ASSOC_MSK
,
928 active
->filter_flags
& RXON_FILTER_ASSOC_MSK
);
936 #ifdef CONFIG_IWLWIFI_DEBUG
937 void iwl_print_rx_config_cmd(struct iwl_priv
*priv
,
938 enum iwl_rxon_context_id ctxid
)
940 struct iwl_rxon_context
*ctx
= &priv
->contexts
[ctxid
];
941 struct iwl_rxon_cmd
*rxon
= &ctx
->staging
;
943 IWL_DEBUG_RADIO(priv
, "RX CONFIG:\n");
944 iwl_print_hex_dump(priv
, IWL_DL_RADIO
, (u8
*) rxon
, sizeof(*rxon
));
945 IWL_DEBUG_RADIO(priv
, "u16 channel: 0x%x\n",
946 le16_to_cpu(rxon
->channel
));
947 IWL_DEBUG_RADIO(priv
, "u32 flags: 0x%08X\n",
948 le32_to_cpu(rxon
->flags
));
949 IWL_DEBUG_RADIO(priv
, "u32 filter_flags: 0x%08x\n",
950 le32_to_cpu(rxon
->filter_flags
));
951 IWL_DEBUG_RADIO(priv
, "u8 dev_type: 0x%x\n", rxon
->dev_type
);
952 IWL_DEBUG_RADIO(priv
, "u8 ofdm_basic_rates: 0x%02x\n",
953 rxon
->ofdm_basic_rates
);
954 IWL_DEBUG_RADIO(priv
, "u8 cck_basic_rates: 0x%02x\n",
955 rxon
->cck_basic_rates
);
956 IWL_DEBUG_RADIO(priv
, "u8[6] node_addr: %pM\n", rxon
->node_addr
);
957 IWL_DEBUG_RADIO(priv
, "u8[6] bssid_addr: %pM\n", rxon
->bssid_addr
);
958 IWL_DEBUG_RADIO(priv
, "u16 assoc_id: 0x%x\n",
959 le16_to_cpu(rxon
->assoc_id
));
964 * iwlagn_commit_rxon - commit staging_rxon to hardware
966 * The RXON command in staging_rxon is committed to the hardware and
967 * the active_rxon structure is updated with the new data. This
968 * function correctly transitions out of the RXON_ASSOC_MSK state if
969 * a HW tune is required based on the RXON structure changes.
971 * The connect/disconnect flow should be as the following:
973 * 1. make sure send RXON command with association bit unset if not connect
974 * this should include the channel and the band for the candidate
976 * 2. Add Station before RXON association with the AP
977 * 3. RXON_timing has to send before RXON for connection
978 * 4. full RXON command - associated bit set
979 * 5. use RXON_ASSOC command to update any flags changes
981 int iwlagn_commit_rxon(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
983 /* cast away the const for active_rxon in this function */
984 struct iwl_rxon_cmd
*active
= (void *)&ctx
->active
;
985 bool new_assoc
= !!(ctx
->staging
.filter_flags
& RXON_FILTER_ASSOC_MSK
);
988 lockdep_assert_held(&priv
->mutex
);
990 if (!iwl_is_alive(priv
))
993 /* This function hardcodes a bunch of dual-mode assumptions */
994 BUILD_BUG_ON(NUM_IWL_RXON_CTX
!= 2);
999 /* always get timestamp with Rx frame */
1000 ctx
->staging
.flags
|= RXON_FLG_TSF2HOST_MSK
;
1003 * force CTS-to-self frames protection if RTS-CTS is not preferred
1004 * one aggregation protection method
1006 if (!priv
->hw_params
.use_rts_for_aggregation
)
1007 ctx
->staging
.flags
|= RXON_FLG_SELF_CTS_EN
;
1009 if ((ctx
->vif
&& ctx
->vif
->bss_conf
.use_short_slot
) ||
1010 !(ctx
->staging
.flags
& RXON_FLG_BAND_24G_MSK
))
1011 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
1013 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
1015 iwl_print_rx_config_cmd(priv
, ctx
->ctxid
);
1016 ret
= iwl_check_rxon_cmd(priv
, ctx
);
1018 IWL_ERR(priv
, "Invalid RXON configuration. Not committing.\n");
1023 * receive commit_rxon request
1024 * abort any previous channel switch if still in process
1026 if (test_bit(STATUS_CHANNEL_SWITCH_PENDING
, &priv
->status
) &&
1027 (priv
->switch_channel
!= ctx
->staging
.channel
)) {
1028 IWL_DEBUG_11H(priv
, "abort channel switch on %d\n",
1029 le16_to_cpu(priv
->switch_channel
));
1030 iwl_chswitch_done(priv
, false);
1034 * If we don't need to send a full RXON, we can use
1035 * iwl_rxon_assoc_cmd which is used to reconfigure filter
1036 * and other flags for the current radio configuration.
1038 if (!iwl_full_rxon_required(priv
, ctx
)) {
1039 ret
= iwlagn_send_rxon_assoc(priv
, ctx
);
1041 IWL_ERR(priv
, "Error setting RXON_ASSOC (%d)\n", ret
);
1045 memcpy(active
, &ctx
->staging
, sizeof(*active
));
1047 * We do not commit tx power settings while channel changing,
1048 * do it now if after settings changed.
1050 iwl_set_tx_power(priv
, priv
->tx_power_next
, false);
1052 /* make sure we are in the right PS state */
1053 iwl_power_update_mode(priv
, true);
1058 iwl_set_rxon_hwcrypto(priv
, ctx
, !iwlagn_mod_params
.sw_crypto
);
1060 IWL_DEBUG_INFO(priv
,
1061 "Going to commit RXON\n"
1062 " * with%s RXON_FILTER_ASSOC_MSK\n"
1065 (new_assoc
? "" : "out"),
1066 le16_to_cpu(ctx
->staging
.channel
),
1067 ctx
->staging
.bssid_addr
);
1070 * Always clear associated first, but with the correct config.
1071 * This is required as for example station addition for the
1072 * AP station must be done after the BSSID is set to correctly
1073 * set up filters in the device.
1075 ret
= iwlagn_rxon_disconn(priv
, ctx
);
1079 ret
= iwlagn_set_pan_params(priv
);
1084 return iwlagn_rxon_connect(priv
, ctx
);
1089 void iwlagn_config_ht40(struct ieee80211_conf
*conf
,
1090 struct iwl_rxon_context
*ctx
)
1092 if (conf_is_ht40_minus(conf
)) {
1093 ctx
->ht
.extension_chan_offset
=
1094 IEEE80211_HT_PARAM_CHA_SEC_BELOW
;
1095 ctx
->ht
.is_40mhz
= true;
1096 } else if (conf_is_ht40_plus(conf
)) {
1097 ctx
->ht
.extension_chan_offset
=
1098 IEEE80211_HT_PARAM_CHA_SEC_ABOVE
;
1099 ctx
->ht
.is_40mhz
= true;
1101 ctx
->ht
.extension_chan_offset
=
1102 IEEE80211_HT_PARAM_CHA_SEC_NONE
;
1103 ctx
->ht
.is_40mhz
= false;
1107 int iwlagn_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
1109 struct iwl_priv
*priv
= IWL_MAC80211_GET_DVM(hw
);
1110 struct iwl_rxon_context
*ctx
;
1111 struct ieee80211_conf
*conf
= &hw
->conf
;
1112 struct ieee80211_channel
*channel
= conf
->channel
;
1113 const struct iwl_channel_info
*ch_info
;
1116 IWL_DEBUG_MAC80211(priv
, "enter: changed %#x\n", changed
);
1118 mutex_lock(&priv
->mutex
);
1120 if (unlikely(test_bit(STATUS_SCANNING
, &priv
->status
))) {
1121 IWL_DEBUG_MAC80211(priv
, "leave - scanning\n");
1125 if (!iwl_is_ready(priv
)) {
1126 IWL_DEBUG_MAC80211(priv
, "leave - not ready\n");
1130 if (changed
& (IEEE80211_CONF_CHANGE_SMPS
|
1131 IEEE80211_CONF_CHANGE_CHANNEL
)) {
1132 /* mac80211 uses static for non-HT which is what we want */
1133 priv
->current_ht_config
.smps
= conf
->smps_mode
;
1136 * Recalculate chain counts.
1138 * If monitor mode is enabled then mac80211 will
1139 * set up the SM PS mode to OFF if an HT channel is
1142 for_each_context(priv
, ctx
)
1143 iwlagn_set_rxon_chain(priv
, ctx
);
1146 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
1147 ch_info
= iwl_get_channel_info(priv
, channel
->band
,
1149 if (!is_channel_valid(ch_info
)) {
1150 IWL_DEBUG_MAC80211(priv
, "leave - invalid channel\n");
1155 for_each_context(priv
, ctx
) {
1156 /* Configure HT40 channels */
1157 if (ctx
->ht
.enabled
!= conf_is_ht(conf
))
1158 ctx
->ht
.enabled
= conf_is_ht(conf
);
1160 if (ctx
->ht
.enabled
) {
1161 /* if HT40 is used, it should not change
1162 * after associated except channel switch */
1163 if (!ctx
->ht
.is_40mhz
||
1164 !iwl_is_associated_ctx(ctx
))
1165 iwlagn_config_ht40(conf
, ctx
);
1167 ctx
->ht
.is_40mhz
= false;
1170 * Default to no protection. Protection mode will
1171 * later be set from BSS config in iwl_ht_conf
1173 ctx
->ht
.protection
= IEEE80211_HT_OP_MODE_PROTECTION_NONE
;
1175 /* if we are switching from ht to 2.4 clear flags
1176 * from any ht related info since 2.4 does not
1178 if (le16_to_cpu(ctx
->staging
.channel
) !=
1180 ctx
->staging
.flags
= 0;
1182 iwl_set_rxon_channel(priv
, channel
, ctx
);
1183 iwl_set_rxon_ht(priv
, &priv
->current_ht_config
);
1185 iwl_set_flags_for_band(priv
, ctx
, channel
->band
,
1189 iwl_update_bcast_stations(priv
);
1192 * The list of supported rates and rate mask can be different
1193 * for each band; since the band may have changed, reset
1194 * the rate mask to what mac80211 lists.
1199 if (changed
& (IEEE80211_CONF_CHANGE_PS
|
1200 IEEE80211_CONF_CHANGE_IDLE
)) {
1201 ret
= iwl_power_update_mode(priv
, false);
1203 IWL_DEBUG_MAC80211(priv
, "Error setting sleep level\n");
1206 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
1207 IWL_DEBUG_MAC80211(priv
, "TX Power old=%d new=%d\n",
1208 priv
->tx_power_user_lmt
, conf
->power_level
);
1210 iwl_set_tx_power(priv
, conf
->power_level
, false);
1213 for_each_context(priv
, ctx
) {
1214 if (!memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
1216 iwlagn_commit_rxon(priv
, ctx
);
1219 mutex_unlock(&priv
->mutex
);
1220 IWL_DEBUG_MAC80211(priv
, "leave\n");
1225 void iwlagn_check_needed_chains(struct iwl_priv
*priv
,
1226 struct iwl_rxon_context
*ctx
,
1227 struct ieee80211_bss_conf
*bss_conf
)
1229 struct ieee80211_vif
*vif
= ctx
->vif
;
1230 struct iwl_rxon_context
*tmp
;
1231 struct ieee80211_sta
*sta
;
1232 struct iwl_ht_config
*ht_conf
= &priv
->current_ht_config
;
1233 struct ieee80211_sta_ht_cap
*ht_cap
;
1236 lockdep_assert_held(&priv
->mutex
);
1238 switch (vif
->type
) {
1239 case NL80211_IFTYPE_STATION
:
1241 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
1244 * If at all, this can only happen through a race
1245 * when the AP disconnects us while we're still
1246 * setting up the connection, in that case mac80211
1247 * will soon tell us about that.
1249 need_multiple
= false;
1254 ht_cap
= &sta
->ht_cap
;
1256 need_multiple
= true;
1259 * If the peer advertises no support for receiving 2 and 3
1260 * stream MCS rates, it can't be transmitting them either.
1262 if (ht_cap
->mcs
.rx_mask
[1] == 0 &&
1263 ht_cap
->mcs
.rx_mask
[2] == 0) {
1264 need_multiple
= false;
1265 } else if (!(ht_cap
->mcs
.tx_params
&
1266 IEEE80211_HT_MCS_TX_DEFINED
)) {
1267 /* If it can't TX MCS at all ... */
1268 need_multiple
= false;
1269 } else if (ht_cap
->mcs
.tx_params
&
1270 IEEE80211_HT_MCS_TX_RX_DIFF
) {
1274 * But if it can receive them, it might still not
1275 * be able to transmit them, which is what we need
1276 * to check here -- so check the number of streams
1277 * it advertises for TX (if different from RX).
1280 maxstreams
= (ht_cap
->mcs
.tx_params
&
1281 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK
);
1283 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT
;
1286 if (maxstreams
<= 1)
1287 need_multiple
= false;
1292 case NL80211_IFTYPE_ADHOC
:
1294 need_multiple
= false;
1297 /* only AP really */
1298 need_multiple
= true;
1302 ctx
->ht_need_multiple_chains
= need_multiple
;
1304 if (!need_multiple
) {
1305 /* check all contexts */
1306 for_each_context(priv
, tmp
) {
1309 if (tmp
->ht_need_multiple_chains
) {
1310 need_multiple
= true;
1316 ht_conf
->single_chain_sufficient
= !need_multiple
;
1319 void iwlagn_chain_noise_reset(struct iwl_priv
*priv
)
1321 struct iwl_chain_noise_data
*data
= &priv
->chain_noise_data
;
1324 if (!(priv
->calib_disabled
& IWL_CHAIN_NOISE_CALIB_DISABLED
))
1327 if ((data
->state
== IWL_CHAIN_NOISE_ALIVE
) &&
1328 iwl_is_any_associated(priv
)) {
1329 struct iwl_calib_chain_noise_reset_cmd cmd
;
1331 /* clear data for chain noise calibration algorithm */
1332 data
->chain_noise_a
= 0;
1333 data
->chain_noise_b
= 0;
1334 data
->chain_noise_c
= 0;
1335 data
->chain_signal_a
= 0;
1336 data
->chain_signal_b
= 0;
1337 data
->chain_signal_c
= 0;
1338 data
->beacon_count
= 0;
1340 memset(&cmd
, 0, sizeof(cmd
));
1341 iwl_set_calib_hdr(&cmd
.hdr
,
1342 priv
->phy_calib_chain_noise_reset_cmd
);
1343 ret
= iwl_dvm_send_cmd_pdu(priv
,
1344 REPLY_PHY_CALIBRATION_CMD
,
1345 CMD_SYNC
, sizeof(cmd
), &cmd
);
1348 "Could not send REPLY_PHY_CALIBRATION_CMD\n");
1349 data
->state
= IWL_CHAIN_NOISE_ACCUMULATE
;
1350 IWL_DEBUG_CALIB(priv
, "Run chain_noise_calibrate\n");
1354 void iwlagn_bss_info_changed(struct ieee80211_hw
*hw
,
1355 struct ieee80211_vif
*vif
,
1356 struct ieee80211_bss_conf
*bss_conf
,
1359 struct iwl_priv
*priv
= IWL_MAC80211_GET_DVM(hw
);
1360 struct iwl_rxon_context
*ctx
= iwl_rxon_ctx_from_vif(vif
);
1364 mutex_lock(&priv
->mutex
);
1366 if (unlikely(!iwl_is_ready(priv
))) {
1367 IWL_DEBUG_MAC80211(priv
, "leave - not ready\n");
1368 mutex_unlock(&priv
->mutex
);
1372 if (unlikely(!ctx
->vif
)) {
1373 IWL_DEBUG_MAC80211(priv
, "leave - vif is NULL\n");
1374 mutex_unlock(&priv
->mutex
);
1378 if (changes
& BSS_CHANGED_BEACON_INT
)
1381 if (changes
& BSS_CHANGED_QOS
) {
1382 ctx
->qos_data
.qos_active
= bss_conf
->qos
;
1383 iwlagn_update_qos(priv
, ctx
);
1386 ctx
->staging
.assoc_id
= cpu_to_le16(vif
->bss_conf
.aid
);
1387 if (vif
->bss_conf
.use_short_preamble
)
1388 ctx
->staging
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
1390 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
1392 if (changes
& BSS_CHANGED_ASSOC
) {
1393 if (bss_conf
->assoc
) {
1394 priv
->timestamp
= bss_conf
->last_tsf
;
1395 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
1398 * If we disassociate while there are pending
1399 * frames, just wake up the queues and let the
1400 * frames "escape" ... This shouldn't really
1401 * be happening to start with, but we should
1402 * not get stuck in this case either since it
1403 * can happen if userspace gets confused.
1405 iwlagn_lift_passive_no_rx(priv
);
1407 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
1409 if (ctx
->ctxid
== IWL_RXON_CTX_BSS
)
1410 priv
->have_rekey_data
= false;
1413 iwlagn_bt_coex_rssi_monitor(priv
);
1416 if (ctx
->ht
.enabled
) {
1417 ctx
->ht
.protection
= bss_conf
->ht_operation_mode
&
1418 IEEE80211_HT_OP_MODE_PROTECTION
;
1419 ctx
->ht
.non_gf_sta_present
= !!(bss_conf
->ht_operation_mode
&
1420 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
);
1421 iwlagn_check_needed_chains(priv
, ctx
, bss_conf
);
1422 iwl_set_rxon_ht(priv
, &priv
->current_ht_config
);
1425 iwlagn_set_rxon_chain(priv
, ctx
);
1427 if (bss_conf
->use_cts_prot
&& (priv
->band
!= IEEE80211_BAND_5GHZ
))
1428 ctx
->staging
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
1430 ctx
->staging
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
1432 if (bss_conf
->use_cts_prot
)
1433 ctx
->staging
.flags
|= RXON_FLG_SELF_CTS_EN
;
1435 ctx
->staging
.flags
&= ~RXON_FLG_SELF_CTS_EN
;
1437 memcpy(ctx
->staging
.bssid_addr
, bss_conf
->bssid
, ETH_ALEN
);
1439 if (vif
->type
== NL80211_IFTYPE_AP
||
1440 vif
->type
== NL80211_IFTYPE_ADHOC
) {
1441 if (vif
->bss_conf
.enable_beacon
) {
1442 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
1443 priv
->beacon_ctx
= ctx
;
1445 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
1446 priv
->beacon_ctx
= NULL
;
1451 * If the ucode decides to do beacon filtering before
1452 * association, it will lose beacons that are needed
1453 * before sending frames out on passive channels. This
1454 * causes association failures on those channels. Enable
1455 * receiving beacons in such cases.
1458 if (vif
->type
== NL80211_IFTYPE_STATION
) {
1459 if (!bss_conf
->assoc
)
1460 ctx
->staging
.filter_flags
|= RXON_FILTER_BCON_AWARE_MSK
;
1462 ctx
->staging
.filter_flags
&=
1463 ~RXON_FILTER_BCON_AWARE_MSK
;
1466 if (force
|| memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
1467 iwlagn_commit_rxon(priv
, ctx
);
1469 if (changes
& BSS_CHANGED_ASSOC
&& bss_conf
->assoc
) {
1471 * The chain noise calibration will enable PM upon
1472 * completion. If calibration has already been run
1473 * then we need to enable power management here.
1475 if (priv
->chain_noise_data
.state
== IWL_CHAIN_NOISE_DONE
)
1476 iwl_power_update_mode(priv
, false);
1478 /* Enable RX differential gain and sensitivity calibrations */
1479 iwlagn_chain_noise_reset(priv
);
1480 priv
->start_calib
= 1;
1483 if (changes
& BSS_CHANGED_IBSS
) {
1484 ret
= iwlagn_manage_ibss_station(priv
, vif
,
1485 bss_conf
->ibss_joined
);
1487 IWL_ERR(priv
, "failed to %s IBSS station %pM\n",
1488 bss_conf
->ibss_joined
? "add" : "remove",
1492 if (changes
& BSS_CHANGED_BEACON
&& vif
->type
== NL80211_IFTYPE_ADHOC
&&
1494 if (iwlagn_update_beacon(priv
, vif
))
1495 IWL_ERR(priv
, "Error sending IBSS beacon\n");
1498 mutex_unlock(&priv
->mutex
);
1501 void iwlagn_post_scan(struct iwl_priv
*priv
)
1503 struct iwl_rxon_context
*ctx
;
1506 * We do not commit power settings while scan is pending,
1507 * do it now if the settings changed.
1509 iwl_power_set_mode(priv
, &priv
->power_data
.sleep_cmd_next
, false);
1510 iwl_set_tx_power(priv
, priv
->tx_power_next
, false);
1513 * Since setting the RXON may have been deferred while
1514 * performing the scan, fire one off if needed
1516 for_each_context(priv
, ctx
)
1517 if (memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
1518 iwlagn_commit_rxon(priv
, ctx
);
1520 iwlagn_set_pan_params(priv
);