1 /******************************************************************************
3 * Copyright(c) 2003 - 2011 Intel Corporation. All rights reserved.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of version 2 of the GNU General Public License as
7 * published by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
18 * The full GNU General Public License is included in this distribution in the
19 * file called LICENSE.
21 * Contact Information:
22 * Intel Linux Wireless <ilw@linux.intel.com>
23 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
25 *****************************************************************************/
31 #include "iwl-agn-calib.h"
32 #include "iwl-helpers.h"
34 static int iwlagn_disable_bss(struct iwl_priv
*priv
,
35 struct iwl_rxon_context
*ctx
,
36 struct iwl_rxon_cmd
*send
)
38 __le32 old_filter
= send
->filter_flags
;
41 send
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
42 ret
= iwl_send_cmd_pdu(priv
, ctx
->rxon_cmd
, sizeof(*send
), send
);
44 send
->filter_flags
= old_filter
;
47 IWL_ERR(priv
, "Error clearing ASSOC_MSK on BSS (%d)\n", ret
);
52 static int iwlagn_disable_pan(struct iwl_priv
*priv
,
53 struct iwl_rxon_context
*ctx
,
54 struct iwl_rxon_cmd
*send
)
56 struct iwl_notification_wait disable_wait
;
57 __le32 old_filter
= send
->filter_flags
;
58 u8 old_dev_type
= send
->dev_type
;
61 iwlagn_init_notification_wait(priv
, &disable_wait
,
62 REPLY_WIPAN_DEACTIVATION_COMPLETE
,
65 send
->filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
66 send
->dev_type
= RXON_DEV_TYPE_P2P
;
67 ret
= iwl_send_cmd_pdu(priv
, ctx
->rxon_cmd
, sizeof(*send
), send
);
69 send
->filter_flags
= old_filter
;
70 send
->dev_type
= old_dev_type
;
73 IWL_ERR(priv
, "Error disabling PAN (%d)\n", ret
);
74 iwlagn_remove_notification(priv
, &disable_wait
);
76 ret
= iwlagn_wait_notification(priv
, &disable_wait
, HZ
);
78 IWL_ERR(priv
, "Timed out waiting for PAN disable\n");
84 static void iwlagn_update_qos(struct iwl_priv
*priv
,
85 struct iwl_rxon_context
*ctx
)
92 ctx
->qos_data
.def_qos_parm
.qos_flags
= 0;
94 if (ctx
->qos_data
.qos_active
)
95 ctx
->qos_data
.def_qos_parm
.qos_flags
|=
96 QOS_PARAM_FLG_UPDATE_EDCA_MSK
;
99 ctx
->qos_data
.def_qos_parm
.qos_flags
|= QOS_PARAM_FLG_TGN_MSK
;
101 IWL_DEBUG_QOS(priv
, "send QoS cmd with Qos active=%d FLAGS=0x%X\n",
102 ctx
->qos_data
.qos_active
,
103 ctx
->qos_data
.def_qos_parm
.qos_flags
);
105 ret
= iwl_send_cmd_pdu(priv
, ctx
->qos_cmd
,
106 sizeof(struct iwl_qosparam_cmd
),
107 &ctx
->qos_data
.def_qos_parm
);
109 IWL_ERR(priv
, "Failed to update QoS\n");
112 static int iwlagn_update_beacon(struct iwl_priv
*priv
,
113 struct ieee80211_vif
*vif
)
115 lockdep_assert_held(&priv
->mutex
);
117 dev_kfree_skb(priv
->beacon_skb
);
118 priv
->beacon_skb
= ieee80211_beacon_get(priv
->hw
, vif
);
119 if (!priv
->beacon_skb
)
121 return iwlagn_send_beacon_cmd(priv
);
125 * iwlagn_commit_rxon - commit staging_rxon to hardware
127 * The RXON command in staging_rxon is committed to the hardware and
128 * the active_rxon structure is updated with the new data. This
129 * function correctly transitions out of the RXON_ASSOC_MSK state if
130 * a HW tune is required based on the RXON structure changes.
132 int iwlagn_commit_rxon(struct iwl_priv
*priv
, struct iwl_rxon_context
*ctx
)
134 /* cast away the const for active_rxon in this function */
135 struct iwl_rxon_cmd
*active
= (void *)&ctx
->active
;
136 bool new_assoc
= !!(ctx
->staging
.filter_flags
& RXON_FILTER_ASSOC_MSK
);
137 bool old_assoc
= !!(ctx
->active
.filter_flags
& RXON_FILTER_ASSOC_MSK
);
140 lockdep_assert_held(&priv
->mutex
);
142 if (test_bit(STATUS_EXIT_PENDING
, &priv
->status
))
145 if (!iwl_is_alive(priv
))
148 /* This function hardcodes a bunch of dual-mode assumptions */
149 BUILD_BUG_ON(NUM_IWL_RXON_CTX
!= 2);
154 /* always get timestamp with Rx frame */
155 ctx
->staging
.flags
|= RXON_FLG_TSF2HOST_MSK
;
157 if (ctx
->ctxid
== IWL_RXON_CTX_PAN
&& priv
->_agn
.hw_roc_channel
) {
158 struct ieee80211_channel
*chan
= priv
->_agn
.hw_roc_channel
;
160 iwl_set_rxon_channel(priv
, chan
, ctx
);
161 iwl_set_flags_for_band(priv
, ctx
, chan
->band
, NULL
);
162 ctx
->staging
.filter_flags
|=
163 RXON_FILTER_ASSOC_MSK
|
164 RXON_FILTER_PROMISC_MSK
|
165 RXON_FILTER_CTL2HOST_MSK
;
166 ctx
->staging
.dev_type
= RXON_DEV_TYPE_P2P
;
169 if (memcmp(&ctx
->staging
, &ctx
->active
,
170 sizeof(ctx
->staging
)) == 0)
174 if ((ctx
->vif
&& ctx
->vif
->bss_conf
.use_short_slot
) ||
175 !(ctx
->staging
.flags
& RXON_FLG_BAND_24G_MSK
))
176 ctx
->staging
.flags
|= RXON_FLG_SHORT_SLOT_MSK
;
178 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_SLOT_MSK
;
180 ret
= iwl_check_rxon_cmd(priv
, ctx
);
182 IWL_ERR(priv
, "Invalid RXON configuration. Not committing.\n");
187 * receive commit_rxon request
188 * abort any previous channel switch if still in process
190 if (priv
->switch_rxon
.switch_in_progress
&&
191 (priv
->switch_rxon
.channel
!= ctx
->staging
.channel
)) {
192 IWL_DEBUG_11H(priv
, "abort channel switch on %d\n",
193 le16_to_cpu(priv
->switch_rxon
.channel
));
194 iwl_chswitch_done(priv
, false);
198 * If we don't need to send a full RXON, we can use
199 * iwl_rxon_assoc_cmd which is used to reconfigure filter
200 * and other flags for the current radio configuration.
202 if (!iwl_full_rxon_required(priv
, ctx
)) {
203 ret
= iwl_send_rxon_assoc(priv
, ctx
);
205 IWL_ERR(priv
, "Error setting RXON_ASSOC (%d)\n", ret
);
209 memcpy(active
, &ctx
->staging
, sizeof(*active
));
210 iwl_print_rx_config_cmd(priv
, ctx
);
214 if (priv
->cfg
->ops
->hcmd
->set_pan_params
) {
215 ret
= priv
->cfg
->ops
->hcmd
->set_pan_params(priv
);
220 iwl_set_rxon_hwcrypto(priv
, ctx
, !priv
->cfg
->mod_params
->sw_crypto
);
223 "Going to commit RXON\n"
224 " * with%s RXON_FILTER_ASSOC_MSK\n"
227 (new_assoc
? "" : "out"),
228 le16_to_cpu(ctx
->staging
.channel
),
229 ctx
->staging
.bssid_addr
);
232 * Always clear associated first, but with the correct config.
233 * This is required as for example station addition for the
234 * AP station must be done after the BSSID is set to correctly
235 * set up filters in the device.
237 if ((old_assoc
&& new_assoc
) || !new_assoc
) {
238 if (ctx
->ctxid
== IWL_RXON_CTX_BSS
)
239 ret
= iwlagn_disable_bss(priv
, ctx
, &ctx
->staging
);
241 ret
= iwlagn_disable_pan(priv
, ctx
, &ctx
->staging
);
245 memcpy(active
, &ctx
->staging
, sizeof(*active
));
248 * Un-assoc RXON clears the station table and WEP
249 * keys, so we have to restore those afterwards.
251 iwl_clear_ucode_stations(priv
, ctx
);
252 iwl_restore_stations(priv
, ctx
);
253 ret
= iwl_restore_default_wep_keys(priv
, ctx
);
255 IWL_ERR(priv
, "Failed to restore WEP keys (%d)\n", ret
);
260 /* RXON timing must be before associated RXON */
261 ret
= iwl_send_rxon_timing(priv
, ctx
);
263 IWL_ERR(priv
, "Failed to send timing (%d)!\n", ret
);
268 /* QoS info may be cleared by previous un-assoc RXON */
269 iwlagn_update_qos(priv
, ctx
);
272 * We'll run into this code path when beaconing is
273 * enabled, but then we also need to send the beacon
276 if (ctx
->vif
&& (ctx
->vif
->type
== NL80211_IFTYPE_AP
)) {
277 ret
= iwlagn_update_beacon(priv
, ctx
->vif
);
280 "Error sending required beacon (%d)!\n",
286 priv
->start_calib
= 0;
288 * Apply the new configuration.
290 * Associated RXON doesn't clear the station table in uCode,
291 * so we don't need to restore stations etc. after this.
293 ret
= iwl_send_cmd_pdu(priv
, ctx
->rxon_cmd
,
294 sizeof(struct iwl_rxon_cmd
), &ctx
->staging
);
296 IWL_ERR(priv
, "Error setting new RXON (%d)\n", ret
);
299 memcpy(active
, &ctx
->staging
, sizeof(*active
));
301 iwl_reprogram_ap_sta(priv
, ctx
);
303 /* IBSS beacon needs to be sent after setting assoc */
304 if (ctx
->vif
&& (ctx
->vif
->type
== NL80211_IFTYPE_ADHOC
))
305 if (iwlagn_update_beacon(priv
, ctx
->vif
))
306 IWL_ERR(priv
, "Error sending IBSS beacon\n");
309 iwl_print_rx_config_cmd(priv
, ctx
);
311 iwl_init_sensitivity(priv
);
314 * If we issue a new RXON command which required a tune then we must
315 * send a new TXPOWER command or we won't be able to Tx any frames.
317 * It's expected we set power here if channel is changing.
319 ret
= iwl_set_tx_power(priv
, priv
->tx_power_next
, true);
321 IWL_ERR(priv
, "Error sending TX power (%d)\n", ret
);
328 int iwlagn_mac_config(struct ieee80211_hw
*hw
, u32 changed
)
330 struct iwl_priv
*priv
= hw
->priv
;
331 struct iwl_rxon_context
*ctx
;
332 struct ieee80211_conf
*conf
= &hw
->conf
;
333 struct ieee80211_channel
*channel
= conf
->channel
;
334 const struct iwl_channel_info
*ch_info
;
336 bool ht_changed
[NUM_IWL_RXON_CTX
] = {};
338 IWL_DEBUG_MAC80211(priv
, "changed %#x", changed
);
340 mutex_lock(&priv
->mutex
);
342 if (unlikely(test_bit(STATUS_SCANNING
, &priv
->status
))) {
343 IWL_DEBUG_MAC80211(priv
, "leave - scanning\n");
347 if (!iwl_is_ready(priv
)) {
348 IWL_DEBUG_MAC80211(priv
, "leave - not ready\n");
352 if (changed
& (IEEE80211_CONF_CHANGE_SMPS
|
353 IEEE80211_CONF_CHANGE_CHANNEL
)) {
354 /* mac80211 uses static for non-HT which is what we want */
355 priv
->current_ht_config
.smps
= conf
->smps_mode
;
358 * Recalculate chain counts.
360 * If monitor mode is enabled then mac80211 will
361 * set up the SM PS mode to OFF if an HT channel is
364 if (priv
->cfg
->ops
->hcmd
->set_rxon_chain
)
365 for_each_context(priv
, ctx
)
366 priv
->cfg
->ops
->hcmd
->set_rxon_chain(priv
, ctx
);
369 if (changed
& IEEE80211_CONF_CHANGE_CHANNEL
) {
372 ch_info
= iwl_get_channel_info(priv
, channel
->band
,
374 if (!is_channel_valid(ch_info
)) {
375 IWL_DEBUG_MAC80211(priv
, "leave - invalid channel\n");
380 spin_lock_irqsave(&priv
->lock
, flags
);
382 for_each_context(priv
, ctx
) {
383 /* Configure HT40 channels */
384 if (ctx
->ht
.enabled
!= conf_is_ht(conf
)) {
385 ctx
->ht
.enabled
= conf_is_ht(conf
);
386 ht_changed
[ctx
->ctxid
] = true;
389 if (ctx
->ht
.enabled
) {
390 if (conf_is_ht40_minus(conf
)) {
391 ctx
->ht
.extension_chan_offset
=
392 IEEE80211_HT_PARAM_CHA_SEC_BELOW
;
393 ctx
->ht
.is_40mhz
= true;
394 } else if (conf_is_ht40_plus(conf
)) {
395 ctx
->ht
.extension_chan_offset
=
396 IEEE80211_HT_PARAM_CHA_SEC_ABOVE
;
397 ctx
->ht
.is_40mhz
= true;
399 ctx
->ht
.extension_chan_offset
=
400 IEEE80211_HT_PARAM_CHA_SEC_NONE
;
401 ctx
->ht
.is_40mhz
= false;
404 ctx
->ht
.is_40mhz
= false;
407 * Default to no protection. Protection mode will
408 * later be set from BSS config in iwl_ht_conf
410 ctx
->ht
.protection
= IEEE80211_HT_OP_MODE_PROTECTION_NONE
;
412 /* if we are switching from ht to 2.4 clear flags
413 * from any ht related info since 2.4 does not
415 if (le16_to_cpu(ctx
->staging
.channel
) !=
417 ctx
->staging
.flags
= 0;
419 iwl_set_rxon_channel(priv
, channel
, ctx
);
420 iwl_set_rxon_ht(priv
, &priv
->current_ht_config
);
422 iwl_set_flags_for_band(priv
, ctx
, channel
->band
,
426 spin_unlock_irqrestore(&priv
->lock
, flags
);
428 iwl_update_bcast_stations(priv
);
431 * The list of supported rates and rate mask can be different
432 * for each band; since the band may have changed, reset
433 * the rate mask to what mac80211 lists.
438 if (changed
& (IEEE80211_CONF_CHANGE_PS
|
439 IEEE80211_CONF_CHANGE_IDLE
)) {
440 ret
= iwl_power_update_mode(priv
, false);
442 IWL_DEBUG_MAC80211(priv
, "Error setting sleep level\n");
445 if (changed
& IEEE80211_CONF_CHANGE_POWER
) {
446 IWL_DEBUG_MAC80211(priv
, "TX Power old=%d new=%d\n",
447 priv
->tx_power_user_lmt
, conf
->power_level
);
449 iwl_set_tx_power(priv
, conf
->power_level
, false);
452 for_each_context(priv
, ctx
) {
453 if (!memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
455 iwlagn_commit_rxon(priv
, ctx
);
456 if (ht_changed
[ctx
->ctxid
])
457 iwlagn_update_qos(priv
, ctx
);
460 mutex_unlock(&priv
->mutex
);
464 static void iwlagn_check_needed_chains(struct iwl_priv
*priv
,
465 struct iwl_rxon_context
*ctx
,
466 struct ieee80211_bss_conf
*bss_conf
)
468 struct ieee80211_vif
*vif
= ctx
->vif
;
469 struct iwl_rxon_context
*tmp
;
470 struct ieee80211_sta
*sta
;
471 struct iwl_ht_config
*ht_conf
= &priv
->current_ht_config
;
472 struct ieee80211_sta_ht_cap
*ht_cap
;
475 lockdep_assert_held(&priv
->mutex
);
478 case NL80211_IFTYPE_STATION
:
480 sta
= ieee80211_find_sta(vif
, bss_conf
->bssid
);
483 * If at all, this can only happen through a race
484 * when the AP disconnects us while we're still
485 * setting up the connection, in that case mac80211
486 * will soon tell us about that.
488 need_multiple
= false;
493 ht_cap
= &sta
->ht_cap
;
495 need_multiple
= true;
498 * If the peer advertises no support for receiving 2 and 3
499 * stream MCS rates, it can't be transmitting them either.
501 if (ht_cap
->mcs
.rx_mask
[1] == 0 &&
502 ht_cap
->mcs
.rx_mask
[2] == 0) {
503 need_multiple
= false;
504 } else if (!(ht_cap
->mcs
.tx_params
&
505 IEEE80211_HT_MCS_TX_DEFINED
)) {
506 /* If it can't TX MCS at all ... */
507 need_multiple
= false;
508 } else if (ht_cap
->mcs
.tx_params
&
509 IEEE80211_HT_MCS_TX_RX_DIFF
) {
513 * But if it can receive them, it might still not
514 * be able to transmit them, which is what we need
515 * to check here -- so check the number of streams
516 * it advertises for TX (if different from RX).
519 maxstreams
= (ht_cap
->mcs
.tx_params
&
520 IEEE80211_HT_MCS_TX_MAX_STREAMS_MASK
);
522 IEEE80211_HT_MCS_TX_MAX_STREAMS_SHIFT
;
526 need_multiple
= false;
531 case NL80211_IFTYPE_ADHOC
:
533 need_multiple
= false;
537 need_multiple
= true;
541 ctx
->ht_need_multiple_chains
= need_multiple
;
543 if (!need_multiple
) {
544 /* check all contexts */
545 for_each_context(priv
, tmp
) {
548 if (tmp
->ht_need_multiple_chains
) {
549 need_multiple
= true;
555 ht_conf
->single_chain_sufficient
= !need_multiple
;
558 void iwlagn_bss_info_changed(struct ieee80211_hw
*hw
,
559 struct ieee80211_vif
*vif
,
560 struct ieee80211_bss_conf
*bss_conf
,
563 struct iwl_priv
*priv
= hw
->priv
;
564 struct iwl_rxon_context
*ctx
= iwl_rxon_ctx_from_vif(vif
);
568 mutex_lock(&priv
->mutex
);
570 if (unlikely(!iwl_is_ready(priv
))) {
571 IWL_DEBUG_MAC80211(priv
, "leave - not ready\n");
572 mutex_unlock(&priv
->mutex
);
576 if (unlikely(!ctx
->vif
)) {
577 IWL_DEBUG_MAC80211(priv
, "leave - vif is NULL\n");
578 mutex_unlock(&priv
->mutex
);
582 if (changes
& BSS_CHANGED_BEACON_INT
)
585 if (changes
& BSS_CHANGED_QOS
) {
586 ctx
->qos_data
.qos_active
= bss_conf
->qos
;
587 iwlagn_update_qos(priv
, ctx
);
590 ctx
->staging
.assoc_id
= cpu_to_le16(vif
->bss_conf
.aid
);
591 if (vif
->bss_conf
.use_short_preamble
)
592 ctx
->staging
.flags
|= RXON_FLG_SHORT_PREAMBLE_MSK
;
594 ctx
->staging
.flags
&= ~RXON_FLG_SHORT_PREAMBLE_MSK
;
596 if (changes
& BSS_CHANGED_ASSOC
) {
597 if (bss_conf
->assoc
) {
598 priv
->timestamp
= bss_conf
->timestamp
;
599 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
602 * If we disassociate while there are pending
603 * frames, just wake up the queues and let the
604 * frames "escape" ... This shouldn't really
605 * be happening to start with, but we should
606 * not get stuck in this case either since it
607 * can happen if userspace gets confused.
609 if (ctx
->last_tx_rejected
) {
610 ctx
->last_tx_rejected
= false;
611 iwl_wake_any_queue(priv
, ctx
);
613 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
617 if (ctx
->ht
.enabled
) {
618 ctx
->ht
.protection
= bss_conf
->ht_operation_mode
&
619 IEEE80211_HT_OP_MODE_PROTECTION
;
620 ctx
->ht
.non_gf_sta_present
= !!(bss_conf
->ht_operation_mode
&
621 IEEE80211_HT_OP_MODE_NON_GF_STA_PRSNT
);
622 iwlagn_check_needed_chains(priv
, ctx
, bss_conf
);
623 iwl_set_rxon_ht(priv
, &priv
->current_ht_config
);
626 if (priv
->cfg
->ops
->hcmd
->set_rxon_chain
)
627 priv
->cfg
->ops
->hcmd
->set_rxon_chain(priv
, ctx
);
629 if (bss_conf
->use_cts_prot
&& (priv
->band
!= IEEE80211_BAND_5GHZ
))
630 ctx
->staging
.flags
|= RXON_FLG_TGG_PROTECT_MSK
;
632 ctx
->staging
.flags
&= ~RXON_FLG_TGG_PROTECT_MSK
;
634 if (bss_conf
->use_cts_prot
)
635 ctx
->staging
.flags
|= RXON_FLG_SELF_CTS_EN
;
637 ctx
->staging
.flags
&= ~RXON_FLG_SELF_CTS_EN
;
639 memcpy(ctx
->staging
.bssid_addr
, bss_conf
->bssid
, ETH_ALEN
);
641 if (vif
->type
== NL80211_IFTYPE_AP
||
642 vif
->type
== NL80211_IFTYPE_ADHOC
) {
643 if (vif
->bss_conf
.enable_beacon
) {
644 ctx
->staging
.filter_flags
|= RXON_FILTER_ASSOC_MSK
;
645 priv
->beacon_ctx
= ctx
;
647 ctx
->staging
.filter_flags
&= ~RXON_FILTER_ASSOC_MSK
;
648 priv
->beacon_ctx
= NULL
;
652 if (force
|| memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
653 iwlagn_commit_rxon(priv
, ctx
);
655 if (changes
& BSS_CHANGED_ASSOC
&& bss_conf
->assoc
) {
657 * The chain noise calibration will enable PM upon
658 * completion. If calibration has already been run
659 * then we need to enable power management here.
661 if (priv
->chain_noise_data
.state
== IWL_CHAIN_NOISE_DONE
)
662 iwl_power_update_mode(priv
, false);
664 /* Enable RX differential gain and sensitivity calibrations */
665 iwl_chain_noise_reset(priv
);
666 priv
->start_calib
= 1;
669 if (changes
& BSS_CHANGED_IBSS
) {
670 ret
= iwlagn_manage_ibss_station(priv
, vif
,
671 bss_conf
->ibss_joined
);
673 IWL_ERR(priv
, "failed to %s IBSS station %pM\n",
674 bss_conf
->ibss_joined
? "add" : "remove",
678 if (changes
& BSS_CHANGED_BEACON
&& vif
->type
== NL80211_IFTYPE_ADHOC
&&
680 if (iwlagn_update_beacon(priv
, vif
))
681 IWL_ERR(priv
, "Error sending IBSS beacon\n");
684 mutex_unlock(&priv
->mutex
);
687 void iwlagn_post_scan(struct iwl_priv
*priv
)
689 struct iwl_rxon_context
*ctx
;
692 * Since setting the RXON may have been deferred while
693 * performing the scan, fire one off if needed
695 for_each_context(priv
, ctx
)
696 if (memcmp(&ctx
->staging
, &ctx
->active
, sizeof(ctx
->staging
)))
697 iwlagn_commit_rxon(priv
, ctx
);
699 if (priv
->cfg
->ops
->hcmd
->set_pan_params
)
700 priv
->cfg
->ops
->hcmd
->set_pan_params(priv
);