regd = iwl_parse_nvm_mcc_info(mvm->trans,
__le32_to_cpu(resp->n_channels),
resp->channels,
__le16_to_cpu(resp->mcc),
__le16_to_cpu(resp->geo_info),
le32_to_cpu(resp->cap), resp_ver); /* Store the return source id */
src_id = resp->source_id; if (IS_ERR_OR_NULL(regd)) {
IWL_DEBUG_LAR(mvm, "Could not get parse update from FW %d\n",
PTR_ERR_OR_ZERO(regd)); goto out;
}
IWL_DEBUG_LAR(mvm, "setting alpha2 from FW to %s (0x%x, 0x%x) src=%d\n",
regd->alpha2, regd->alpha2[0], regd->alpha2[1], src_id);
mvm->lar_regdom_set = true;
mvm->mcc_src = src_id;
regd = iwl_mvm_get_current_regdomain(mvm, &changed); if (!IS_ERR_OR_NULL(regd)) { /* only update the regulatory core if changed */ if (changed)
regulatory_set_wiphy_regd(mvm->hw->wiphy, regd);
/* save the last source in case we overwrite it below */
used_src = mvm->mcc_src; if (iwl_mvm_is_wifi_mcc_supported(mvm)) { /* Notify the firmware we support wifi location updates */
regd = iwl_mvm_get_current_regdomain(mvm, NULL); if (!IS_ERR_OR_NULL(regd))
kfree(regd);
}
/* Now set our last stored MCC and source */
regd = iwl_mvm_get_regdomain(mvm->hw->wiphy, r->alpha2, used_src,
&changed); if (IS_ERR_OR_NULL(regd)) return -EIO;
/* update cfg80211 if the regdomain was changed or the caller explicitly * asked to update regdomain
*/ if (changed || force_regd_sync)
ret = regulatory_set_wiphy_regd_sync(mvm->hw->wiphy, regd); else
ret = 0;
kfree(regd); return ret;
}
/* Each capability added here should also be add to tm_if_types_ext_capa_sta */ staticconst u8 he_if_types_ext_capa_sta[] = {
[0] = WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING,
[2] = WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT,
[7] = WLAN_EXT_CAPA8_OPMODE_NOTIF |
WLAN_EXT_CAPA8_MAX_MSDU_IN_AMSDU_LSB,
[8] = WLAN_EXT_CAPA9_MAX_MSDU_IN_AMSDU_MSB,
};
int iwl_mvm_op_set_antenna(struct ieee80211_hw *hw, int radio_idx, u32 tx_ant,
u32 rx_ant)
{ struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
/* This has been tested on those devices only */ if (mvm->trans->mac_cfg->device_family != IWL_DEVICE_FAMILY_9000 &&
mvm->trans->mac_cfg->device_family != IWL_DEVICE_FAMILY_22000 &&
mvm->trans->mac_cfg->device_family != IWL_DEVICE_FAMILY_AX210) return -EOPNOTSUPP;
if (!mvm->nvm_data) return -EBUSY;
/* mac80211 ensures the device is not started, * so the firmware cannot be running
*/
/* Set this early since we need to have it for the check below */ if (mvm->mld_api_is_used && mvm->nvm_data->sku_cap_11be_enable &&
!iwlwifi_mod_params.disable_11ax &&
!iwlwifi_mod_params.disable_11be) {
hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_MLO; /* we handle this already earlier, but need it for MLO */
ieee80211_hw_set(hw, HANDLES_QUIET_CSA);
}
/* With MLD FW API, it tracks timing by itself, * no need for any timing from the host
*/ if (!mvm->mld_api_is_used)
ieee80211_hw_set(hw, TIMING_BEACON_ONLY);
/* * On older devices, enabling TX A-MSDU occasionally leads to * something getting messed up, the command read from the FIFO * gets out of sync and isn't a TX command, so that we have an * assert EDC. * * It's not clear where the bug is, but since we didn't used to * support A-MSDU until moving the mac80211 iTXQs, just leave it * for older devices. We also don't see this issue on any newer * devices.
*/ if (mvm->trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_9000)
ieee80211_hw_set(hw, TX_AMSDU);
ieee80211_hw_set(hw, TX_FRAG_LIST);
if (iwl_mvm_has_tlc_offload(mvm)) {
ieee80211_hw_set(hw, TX_AMPDU_SETUP_IN_HW);
ieee80211_hw_set(hw, HAS_RATE_CONTROL);
}
/* We want to use the mac80211's reorder buffer for 9000 */ if (iwl_mvm_has_new_rx_api(mvm) &&
mvm->trans->mac_cfg->device_family > IWL_DEVICE_FAMILY_9000)
ieee80211_hw_set(hw, SUPPORTS_REORDERING_BUFFER);
if (fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_STA_PM_NOTIF)) {
ieee80211_hw_set(hw, AP_LINK_PS);
} elseif (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) { /* * we absolutely need this for the new TX API since that comes * with many more queues than the current code can deal with * for station powersave
*/ return -EINVAL;
}
if (mvm->trans->info.num_rxqs > 1)
ieee80211_hw_set(hw, USES_RSS);
if (mvm->trans->info.max_skb_frags)
hw->netdev_features = NETIF_F_HIGHDMA | NETIF_F_SG;
hw->radiotap_timestamp.units_pos =
IEEE80211_RADIOTAP_TIMESTAMP_UNIT_US |
IEEE80211_RADIOTAP_TIMESTAMP_SPOS_PLCP_SIG_ACQ; /* this is the case for CCK frames, it's better (only 8) for OFDM */
hw->radiotap_timestamp.accuracy = 22;
if (!iwl_mvm_has_tlc_offload(mvm))
hw->rate_control_algorithm = RS_NAME;
if (fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_FTM_CALIBRATED)) {
wiphy_ext_feature_set(hw->wiphy,
NL80211_EXT_FEATURE_ENABLE_FTM_RESPONDER);
hw->wiphy->pmsr_capa = &iwl_mvm_pmsr_capa;
}
/* * beacon protection must be handled by firmware, * so cannot be done with fips_enabled
*/ if (!fips_enabled && sec_key_ver &&
fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_BIGTK_TX_SUPPORT))
wiphy_ext_feature_set(hw->wiphy,
NL80211_EXT_FEATURE_BEACON_PROTECTION); elseif (!fips_enabled &&
fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_BIGTK_SUPPORT))
wiphy_ext_feature_set(hw->wiphy,
NL80211_EXT_FEATURE_BEACON_PROTECTION_CLIENT);
if (fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_TIME_SYNC_BOTH_FTM_TM))
hw->wiphy->hw_timestamp_max_peers = 1;
if (fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_SPP_AMSDU_SUPPORT))
wiphy_ext_feature_set(hw->wiphy,
NL80211_EXT_FEATURE_SPP_AMSDU_SUPPORT);
/* The new Tx API does not allow to pass the key or keyid of a MPDU to * the hw, preventing us to control which key(id) to use per MPDU. * Till that's fixed we can't use Extended Key ID for the newer cards.
*/ if (!iwl_mvm_has_new_tx_api(mvm))
wiphy_ext_feature_set(hw->wiphy,
NL80211_EXT_FEATURE_EXT_KEY_ID);
hw->wiphy->features |= NL80211_FEATURE_HT_IBSS;
/* Extract additional MAC addresses if available */
num_mac = (mvm->nvm_data->n_hw_addrs > 1) ?
min(IWL_MVM_MAX_ADDRESSES, mvm->nvm_data->n_hw_addrs) : 1;
for (i = 1; i < num_mac; i++) {
memcpy(mvm->addresses[i].addr, mvm->addresses[i-1].addr,
ETH_ALEN);
mvm->addresses[i].addr[5]++;
hw->wiphy->n_addresses++;
}
hw->wiphy->max_sched_scan_reqs = 1;
hw->wiphy->max_sched_scan_ssids = PROBE_OPTION_MAX;
hw->wiphy->max_match_sets = iwl_umac_scan_get_max_profiles(mvm->fw); /* we create the 802.11 header and zero length SSID IE. */
hw->wiphy->max_sched_scan_ie_len =
SCAN_OFFLOAD_PROBE_REQ_SIZE - 24 - 2;
hw->wiphy->max_sched_scan_plans = IWL_MAX_SCHED_SCAN_PLANS;
hw->wiphy->max_sched_scan_plan_interval = U16_MAX;
/* * the firmware uses u8 for num of iterations, but 0xff is saved for * infinite loop, so the maximum number of iterations is actually 254.
*/
hw->wiphy->max_sched_scan_plan_iterations = 254;
/* when firmware supports RLC/SMPS offload, do not set these * driver features, since it's no longer supported by driver.
*/ if (!iwl_mvm_has_rlc_offload(mvm))
hw->wiphy->features |= NL80211_FEATURE_STATIC_SMPS |
NL80211_FEATURE_DYNAMIC_SMPS;
if (fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_TXPOWER_INSERTION_SUPPORT))
hw->wiphy->features |= NL80211_FEATURE_TX_POWER_INSERTION; if (fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_QUIET_PERIOD_SUPPORT))
hw->wiphy->features |= NL80211_FEATURE_QUIET;
if (fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_DS_PARAM_SET_IE_SUPPORT))
hw->wiphy->features |=
NL80211_FEATURE_DS_PARAM_SET_IE_IN_PROBES;
if (fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_WFA_TPC_REP_IE_SUPPORT))
hw->wiphy->features |= NL80211_FEATURE_WFA_TPC_IE_IN_PROBES;
if (iwl_fw_lookup_cmd_ver(mvm->fw, WOWLAN_KEK_KCK_MATERIAL,
IWL_FW_CMD_VER_UNKNOWN) >= 3)
hw->wiphy->flags |= WIPHY_FLAG_SUPPORTS_EXT_KEK_KCK;
if (fw_has_api(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_API_SCAN_TSF_REPORT)) {
wiphy_ext_feature_set(hw->wiphy,
NL80211_EXT_FEATURE_SCAN_START_TIME);
wiphy_ext_feature_set(hw->wiphy,
NL80211_EXT_FEATURE_BSS_PARENT_TSF);
}
if (iwl_mvm_is_oce_supported(mvm)) {
u8 scan_ver = iwl_fw_lookup_cmd_ver(mvm->fw, SCAN_REQ_UMAC, 0);
/* Old firmware also supports probe deferral and suppression */ if (scan_ver < 15)
wiphy_ext_feature_set(hw->wiphy,
NL80211_EXT_FEATURE_OCE_PROBE_REQ_DEFERRAL_SUPPRESSION);
}
if (offchannel &&
!test_bit(IWL_MVM_STATUS_ROC_P2P_RUNNING, &mvm->status) &&
!test_bit(IWL_MVM_STATUS_ROC_AUX_RUNNING, &mvm->status)) goto drop;
/* * bufferable MMPDUs or MMPDUs on STA interfaces come via TXQs * so we treat the others as broadcast
*/ if (ieee80211_is_mgmt(hdr->frame_control))
sta = NULL;
/* this shouldn't even happen: just drop */ if (!sta && info->control.vif->type == NL80211_IFTYPE_STATION &&
!offchannel) goto drop;
/* if sta is NULL, the frame is a management frame */
mgmt = (void *)hdr;
memcpy(mgmt->da, link_sta->addr, ETH_ALEN);
memcpy(mgmt->sa, link_conf->addr, ETH_ALEN);
memcpy(mgmt->bssid, link_conf->bssid, ETH_ALEN);
}
/* * No need for threads to be pending here, they can leave the first * taker all the work. * * mvmtxq->tx_request logic: * * If 0, no one is currently TXing, set to 1 to indicate current thread * will now start TX and other threads should quit. * * If 1, another thread is currently TXing, set to 2 to indicate to * that thread that there was another request. Since that request may * have raced with the check whether the queue is empty, the TXing * thread should check the queue's status one more time before leaving. * This check is done in order to not leave any TX hanging in the queue * until the next TX invocation (which may not even happen). * * If 2, another thread is currently TXing, and it will already double * check the queue, so do nothing.
*/ if (atomic_fetch_add_unless(&mvmtxq->tx_request, 1, 2)) return;
rcu_read_lock(); do { while (likely(!test_bit(IWL_MVM_TXQ_STATE_STOP_FULL,
&mvmtxq->state) &&
!test_bit(IWL_MVM_TXQ_STATE_STOP_REDIRECT,
&mvmtxq->state) &&
!test_bit(IWL_MVM_TXQ_STATE_STOP_AP_CSA,
&mvmtxq->state) &&
!test_bit(IWL_MVM_STATUS_IN_D3, &mvm->status))) {
skb = ieee80211_tx_dequeue(hw, txq);
if (!skb) { if (txq->sta)
IWL_DEBUG_TX(mvm, "TXQ of sta %pM tid %d is now empty\n",
txq->sta->addr,
txq->tid); break;
}
iwl_mvm_tx_skb(mvm, skb, txq->sta);
}
} while (atomic_dec_return(&mvmtxq->tx_request));
rcu_read_unlock();
}
if (likely(test_bit(IWL_MVM_TXQ_STATE_READY, &mvmtxq->state)) ||
!txq->sta) {
iwl_mvm_mac_itxq_xmit(hw, txq); return;
}
/* iwl_mvm_mac_itxq_xmit() will later be called by the worker * to handle any packets we leave on the txq now
*/
spin_lock_bh(&mvm->add_stream_lock); /* The list is being deleted only after the queue is fully allocated. */ if (list_empty(&mvmtxq->list) && /* recheck under lock */
!test_bit(IWL_MVM_TXQ_STATE_READY, &mvmtxq->state)) {
list_add_tail(&mvmtxq->list, &mvm->add_stream_txqs);
schedule_work(&mvm->add_stream_wk);
}
spin_unlock_bh(&mvm->add_stream_lock);
}
#define CHECK_BA_TRIGGER(_mvm, _trig, _tid_bm, _tid, _fmt...) \ do { \ if (!(le16_to_cpu(_tid_bm) & BIT(_tid))) \ break; \
iwl_fw_dbg_collect_trig(&(_mvm)->fwrt, _trig, _fmt); \
} while (0)
mvm_link_sta =
rcu_dereference_check(mvm_sta->link[link_id],
lockdep_is_held(&mvm->mutex)); if (mvm_link_sta && !(vif->active_links & BIT(link_id))) { /* * We have a link STA but the link is inactive in * mac80211. This will happen if we failed to * deactivate the link but mac80211 roll back the * deactivation of the link. * Delete the stale data to avoid issues later on.
*/
iwl_mvm_mld_free_sta_link(mvm, mvm_sta, mvm_link_sta,
link_id);
}
}
}
/* just in case one was running */
iwl_mvm_cleanup_roc_te(mvm);
ieee80211_remain_on_channel_expired(mvm->hw);
iwl_mvm_ftm_restart(mvm);
/* * cleanup all interfaces, even inactive ones, as some might have * gone down during the HW restart
*/
ieee80211_iterate_interfaces(mvm->hw, 0, iwl_mvm_cleanup_iterator, mvm);
/* cleanup stations as links may be gone after restart */
ieee80211_iterate_stations_atomic(mvm->hw,
iwl_mvm_cleanup_sta_iterator, mvm);
int __iwl_mvm_mac_start(struct iwl_mvm *mvm)
{ bool fast_resume = false; int ret;
lockdep_assert_held(&mvm->mutex);
ret = iwl_mvm_mei_get_ownership(mvm); if (ret) return ret;
if (mvm->mei_nvm_data) { /* We got the NIC, we can now free the MEI NVM data */
kfree(mvm->mei_nvm_data);
mvm->mei_nvm_data = NULL;
/* * We can't free the nvm_data we allocated based on the SAP * data because we registered to cfg80211 with the channels * allocated on mvm->nvm_data. Keep a pointer in temp_nvm_data * just in order to be able free it later. * NULLify nvm_data so that we will read the NVM from the * firmware this time.
*/
mvm->temp_nvm_data = mvm->nvm_data;
mvm->nvm_data = NULL;
}
#ifdef CONFIG_PM_SLEEP /* fast_resume will be cleared by iwl_mvm_fast_resume */
fast_resume = mvm->fast_resume;
if (fast_resume) {
iwl_mvm_mei_device_state(mvm, true);
ret = iwl_mvm_fast_resume(mvm); if (ret) {
iwl_mvm_stop_device(mvm); /* iwl_mvm_up() will be called further down */
} else { /* * We clear IWL_MVM_STATUS_FIRMWARE_RUNNING upon * mac_down() so that debugfs will stop honoring * requests after we flush all the workers. * Set the IWL_MVM_STATUS_FIRMWARE_RUNNING bit again * now that we are back. This is a bit abusing the * flag since the firmware wasn't really ever stopped, * but this still serves the purpose.
*/
set_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
}
} #endif/* CONFIG_PM_SLEEP */
if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status)) { /* * Now convert the HW_RESTART_REQUESTED flag to IN_HW_RESTART * so later code will - from now on - see that we're doing it.
*/
set_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status); /* Clean up some internal and mac80211 state on restart */
iwl_mvm_restart_cleanup(mvm);
}
/* we also want to load the firmware if fast_resume failed */ if (!fast_resume || ret)
ret = iwl_mvm_up(mvm);
if (ret && test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { /* Something went wrong - we need to finish some cleanup * that normally iwl_mvm_mac_restart_complete() below * would do.
*/
clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status);
}
return ret;
}
int iwl_mvm_mac_start(struct ieee80211_hw *hw)
{ struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); int ret; int retry, max_retry = 0;
mutex_lock(&mvm->mutex);
/* we are starting the mac not in error flow, and restart is enabled */ if (!test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED, &mvm->status) &&
iwlwifi_mod_params.fw_restart)
max_retry = IWL_MAX_INIT_RETRY;
for (retry = 0; retry <= max_retry; retry++) {
ret = __iwl_mvm_mac_start(mvm); if (ret != -ETIMEDOUT) break;
IWL_ERR(mvm, "mac start retry %d\n", retry);
}
mutex_unlock(&mvm->mutex);
iwl_mvm_mei_set_sw_rfkill_state(mvm);
return ret;
}
staticvoid iwl_mvm_restart_complete(struct iwl_mvm *mvm)
{ int ret;
/* * If we have TDLS peers, remove them. We don't know the last seqno/PN * of packets the FW sent out, so we must reconnect.
*/
iwl_mvm_teardown_tdls_peers(mvm);
/* firmware counters are obviously reset now, but we shouldn't * partially track so also clear the fw_reset_accu counters.
*/
memset(&mvm->accu_radio_stats, 0, sizeof(mvm->accu_radio_stats));
/* async_handlers_wk is now blocked */
if (!iwl_mvm_has_new_station_api(mvm->fw))
iwl_mvm_rm_aux_sta(mvm);
if (suspend &&
mvm->trans->mac_cfg->device_family >= IWL_DEVICE_FAMILY_22000) {
iwl_mvm_fast_suspend(mvm); /* From this point on, we won't touch the device */
iwl_mvm_mei_device_state(mvm, false);
} else {
iwl_mvm_stop_device(mvm);
}
iwl_mvm_async_handlers_purge(mvm); /* async_handlers_list is empty and will stay empty: HW is stopped */
/* * Clear IN_HW_RESTART and HW_RESTART_REQUESTED flag when stopping the * hw (as restart_complete() won't be called in this case) and mac80211 * won't execute the restart. * But make sure to cleanup interfaces that have gone down before/during * HW restart was requested.
*/ if (test_and_clear_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) ||
test_and_clear_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
&mvm->status))
ieee80211_iterate_interfaces(mvm->hw, 0,
iwl_mvm_cleanup_iterator, mvm);
/* We shouldn't have any UIDs still set. Loop over all the UIDs to * make sure there's nothing left there and warn if any is found.
*/ if (fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_UMAC_SCAN)) { int i;
for (i = 0; i < mvm->max_scans; i++) { if (WARN_ONCE(mvm->scan_uid_status[i], "UMAC scan UID %d status was not cleaned\n",
i))
mvm->scan_uid_status[i] = 0;
}
}
}
/* * Lock and clear the firmware running bit here already, so that * new commands coming in elsewhere, e.g. from debugfs, will not * be able to proceed. This is important here because one of those * debugfs files causes the firmware dump to be triggered, and if we * don't stop debugfs accesses before canceling that it could be * retriggered after we flush it but before we've cleared the bit.
*/
clear_bit(IWL_MVM_STATUS_FIRMWARE_RUNNING, &mvm->status);
/* * The worker might have been waiting for the mutex, let it run and * discover that its list is now empty.
*/
cancel_work_sync(&mvm->async_handlers_wk);
wiphy_work_cancel(hw->wiphy, &mvm->async_handlers_wiphy_wk);
}
/* Those fields sit on the same place for v9 and v10 */
cmd_v9_v10.common.set_mode = cpu_to_le32(IWL_TX_POWER_MODE_SET_LINK);
cmd_v9_v10.common.link_id = cpu_to_le32(link_id);
cmd_v9_v10.common.pwr_restriction = cpu_to_le16(u_tx_power);
cmd_data = &cmd_v9_v10;
}
if (cmd_ver == 10)
len = sizeof(cmd_v9_v10.v10); elseif (cmd_ver == 9)
len = sizeof(cmd_v9_v10.v9); elseif (cmd_ver == 8)
len = sizeof(cmd.v8); elseif (fw_has_api(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_API_REDUCE_TX_POWER))
len = sizeof(cmd.v5); elseif (fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_TX_POWER_ACK))
len = sizeof(cmd.v4); else
len = sizeof(cmd.v3);
/* all structs have the same common part, add its length */
len += sizeof(cmd.common);
if (!fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
ret = iwl_mvm_enable_beacon_filter(mvm, vif); if (ret) goto out_unlock;
/* * In the new flow since FW is in charge of the timing, * if driver has canceled the channel switch he will receive the * CHANNEL_SWITCH_START_NOTIF notification from FW and then cancel it
*/ if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
CHANNEL_SWITCH_ERROR_NOTIF, 0)) return;
IWL_DEBUG_MAC80211(mvm, "Abort CSA on mac %d\n", mvmvif->id);
/* data is bw wide so the start is half the width */
data_start = chandef->center_freq1 - bw / 2; /* control is 20Mhz width */
control_start = chandef->chan->center_freq - 10;
ret = iwl_mvm_alloc_bcast_sta(mvm, vif); if (ret) {
IWL_ERR(mvm, "Failed to allocate bcast sta\n"); return ret;
}
/* Only queue for this station is the mcast queue, * which shouldn't be in TFD mask anyway
*/ return iwl_mvm_allocate_int_sta(mvm, &mvmvif->deflink.mcast_sta, 0,
vif->type,
IWL_STA_MULTICAST);
}
/* the first link always points to the default one */
mvmvif->deflink.fw_link_id = IWL_MVM_FW_LINK_ID_INVALID;
mvmvif->deflink.active = 0;
mvmvif->link[0] = &mvmvif->deflink;
/* * Not much to do here. The stack will not allow interface * types or combinations that we didn't advertise, so we * don't really have to check the types.
*/
/* make sure that beacon statistics don't go backwards with FW reset */ if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
for_each_mvm_vif_valid_link(mvmvif, i)
mvmvif->link[i]->beacon_stats.accu_num_beacons +=
mvmvif->link[i]->beacon_stats.num_beacons;
/* Allocate resources for the MAC context, and add it to the fw */
ret = iwl_mvm_mac_ctxt_init(mvm, vif); if (ret) goto out;
/* * The AP binding flow can be done only after the beacon * template is configured (which happens only in the mac80211 * start_ap() flow), and adding the broadcast station can happen * only after the binding. * In addition, since modifying the MAC before adding a bcast * station is not allowed by the FW, delay the adding of MAC context to * the point where we can also add the bcast station. * In short: there's not much we can do at this point, other than * allocating resources :)
*/ if (vif->type == NL80211_IFTYPE_AP ||
vif->type == NL80211_IFTYPE_ADHOC) { if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
iwl_mvm_vif_dbgfs_add_link(mvm, vif);
ret = 0; goto out;
}
mvmvif->features |= hw->netdev_features;
ret = iwl_mvm_mac_ctxt_add(mvm, vif); if (ret) goto out_unlock;
ret = iwl_mvm_power_update_mac(mvm); if (ret) goto out_remove_mac;
/* beacon filtering */
ret = iwl_mvm_disable_beacon_filter(mvm, vif); if (ret) goto out_remove_mac;
if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { /* * Flush the ROC worker which will flush the OFFCHANNEL queue. * We assume here that all the packets sent to the OFFCHANNEL * queue are sent in ROC session.
*/
flush_work(&mvm->roc_done_wk);
}
if (vif->bss_conf.ftm_responder)
memset(&mvm->ftm_resp_stats, 0, sizeof(mvm->ftm_resp_stats));
iwl_mvm_vif_dbgfs_rm_link(mvm, vif);
/* * For AP/GO interface, the tear down of the resources allocated to the * interface is be handled as part of the stop_ap flow.
*/ if (vif->type == NL80211_IFTYPE_AP ||
vif->type == NL80211_IFTYPE_ADHOC) goto out;
iwl_mvm_power_update_mac(mvm);
/* Before the interface removal, mac80211 would cancel the ROC, and the * ROC worker would be scheduled if needed. The worker would be flushed * in iwl_mvm_prepare_mac_removal() and thus at this point there is no * binding etc. so nothing needs to be done here.
*/ if (vif->type == NL80211_IFTYPE_P2P_DEVICE) { if (mvmvif->deflink.phy_ctxt) {
iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt);
mvmvif->deflink.phy_ctxt = NULL;
}
mvm->p2p_device_vif = NULL;
}
/* * Send a (synchronous) ech command so that we wait for the * multiple asynchronous MCAST_FILTER_CMD commands sent by * the interface iterator. Otherwise, we might get here over * and over again (by userspace just sending a lot of these) * and the CPU can send them faster than the firmware can * process them. * Note that the CPU is still faster - but with this we'll * actually send fewer commands overall because the CPU will * not schedule the work in mac80211 as frequently if it's * still running when rescheduled (possibly multiple times).
*/
ret = iwl_mvm_send_cmd_pdu(mvm, ECHO_CMD, 0, 0, NULL); if (ret)
IWL_ERR(mvm, "Failed to synchronize multicast groups update\n");
}
/* * MU-MIMO Group Id action frame is little endian. We treat * the data received from firmware as if it came from the * action frame, so no conversion is needed.
*/
ieee80211_update_mu_groups(vif, 0,
(u8 *)¬if->membership_status,
(u8 *)¬if->user_position);
}
}
/* * If bit_num > 5, we have to combine bits with next byte. * Calculate how many bits we need to take from current byte (called * here "residue_bits"), and add them to bits from next byte.
*/
/* * FW currently supports only nss == MAX_HE_SUPP_NSS * * If nss > MAX: we can ignore values we don't support * If nss < MAX: we can set zeros in other streams
*/ if (nss > MAX_HE_SUPP_NSS) {
IWL_DEBUG_INFO(mvm, "Got NSS = %d - trimming to %d\n", nss,
MAX_HE_SUPP_NSS);
nss = MAX_HE_SUPP_NSS;
}
for (i = 0; i < nss; i++) {
u8 ru_index_tmp = ru_index_bitmap << 1;
u8 low_th = IWL_HE_PKT_EXT_NONE, high_th = IWL_HE_PKT_EXT_NONE;
u8 bw;
/* * According to the 11be spec, if for a specific BW the PPE Thresholds * isn't present - it should inherit the thresholds from the last * BW for which we had PPE Thresholds. In 11ax though, we don't have * this inheritance - continue in this case
*/ if (!(ru_index_tmp & 1)) { if (inheritance) goto set_thresholds; else continue;
}
staticint
iwl_mvm_set_pkt_ext_from_nominal_padding(struct iwl_he_pkt_ext_v2 *pkt_ext,
u8 nominal_padding)
{ int low_th = -1; int high_th = -1; int i;
/* all the macros are the same for EHT and HE */ switch (nominal_padding) { case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_0US:
low_th = IWL_HE_PKT_EXT_NONE;
high_th = IWL_HE_PKT_EXT_NONE; break; case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_8US:
low_th = IWL_HE_PKT_EXT_BPSK;
high_th = IWL_HE_PKT_EXT_NONE; break; case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_16US: case IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_20US:
low_th = IWL_HE_PKT_EXT_NONE;
high_th = IWL_HE_PKT_EXT_BPSK; break;
}
if (low_th < 0 || high_th < 0) return -EINVAL;
/* Set the PPE thresholds accordingly */ for (i = 0; i < MAX_HE_SUPP_NSS; i++) {
u8 bw;
/* Set the pkt_ext field according to PPE Thresholds element */ int iwl_mvm_set_sta_pkt_ext(struct iwl_mvm *mvm, struct ieee80211_link_sta *link_sta, struct iwl_he_pkt_ext_v2 *pkt_ext)
{
u8 nominal_padding; int i, ret = 0;
if (WARN_ON(!link_sta)) return -EINVAL;
/* Initialize the PPE thresholds to "None" (7), as described in Table * 9-262ac of 80211.ax/D3.0.
*/
memset(pkt_ext, IWL_HE_PKT_EXT_NONE, sizeof(struct iwl_he_pkt_ext_v2));
if (link_sta->eht_cap.has_eht) {
nominal_padding =
u8_get_bits(link_sta->eht_cap.eht_cap_elem.phy_cap_info[5],
IEEE80211_EHT_PHY_CAP5_COMMON_NOMINAL_PKT_PAD_MASK);
/* If PPE Thresholds exists, parse them into a FW-familiar * format.
*/ if (link_sta->eht_cap.eht_cap_elem.phy_cap_info[5] &
IEEE80211_EHT_PHY_CAP5_PPE_THRESHOLD_PRESENT) {
u8 nss = (link_sta->eht_cap.eht_ppe_thres[0] &
IEEE80211_EHT_PPE_THRES_NSS_MASK) + 1;
u8 *ppe = &link_sta->eht_cap.eht_ppe_thres[0];
u8 ru_index_bitmap =
u16_get_bits(*ppe,
IEEE80211_EHT_PPE_THRES_RU_INDEX_BITMASK_MASK); /* Starting after PPE header */
u8 ppe_pos_bit = IEEE80211_EHT_PPE_THRES_INFO_HEADER_SIZE;
iwl_mvm_parse_ppe(mvm, pkt_ext, nss, ru_index_bitmap,
ppe, ppe_pos_bit, true); /* EHT PPE Thresholds doesn't exist - set the API according to * HE PPE Tresholds
*/
} elseif (link_sta->he_cap.he_cap_elem.phy_cap_info[6] &
IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) { /* Even though HE Capabilities IE doesn't contain PPE * Thresholds for BW 320Mhz, thresholds for this BW will * be filled in with the same values as 160Mhz, due to * the inheritance, as required.
*/
iwl_mvm_set_pkt_ext_from_he_ppe(mvm, link_sta, pkt_ext, true);
/* According to the requirements, for MCSs 12-13 the * maximum value between HE PPE Threshold and Common * Nominal Packet Padding needs to be taken
*/
iwl_mvm_get_optimal_ppe_info(pkt_ext, nominal_padding);
/* if PPE Thresholds doesn't present in both EHT IE and HE IE - * take the Thresholds from Common Nominal Packet Padding field
*/
} else {
ret = iwl_mvm_set_pkt_ext_from_nominal_padding(pkt_ext,
nominal_padding);
}
} elseif (link_sta->he_cap.has_he) { /* If PPE Thresholds exist, parse them into a FW-familiar format. */ if (link_sta->he_cap.he_cap_elem.phy_cap_info[6] &
IEEE80211_HE_PHY_CAP6_PPE_THRESHOLD_PRESENT) {
iwl_mvm_set_pkt_ext_from_he_ppe(mvm, link_sta, pkt_ext, false); /* PPE Thresholds doesn't exist - set the API PPE values * according to Common Nominal Packet Padding field.
*/
} else {
nominal_padding =
u8_get_bits(link_sta->he_cap.he_cap_elem.phy_cap_info[9],
IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_MASK); if (nominal_padding != IEEE80211_HE_PHY_CAP9_NOMINAL_PKT_PADDING_RESERVED)
ret = iwl_mvm_set_pkt_ext_from_nominal_padding(pkt_ext,
nominal_padding);
}
}
/* * This function sets the MU EDCA parameters ans returns whether MU EDCA * is enabled or not
*/ bool iwl_mvm_set_fw_mu_edca_params(struct iwl_mvm *mvm, conststruct iwl_mvm_vif_link_info *link_info, struct iwl_he_backoff_conf *trig_based_txf)
{ int i; /* Mark MU EDCA as enabled, unless none detected on some AC */ bool mu_edca_enabled = true;
for (i = 0; i < IEEE80211_NUM_ACS; i++) { conststruct ieee80211_he_mu_edca_param_ac_rec *mu_edca =
&link_info->queue_params[i].mu_edca_param_rec;
u8 ac = iwl_mvm_mac80211_ac_to_ucode_ac(i);
if (!link_info->queue_params[i].mu_edca) {
mu_edca_enabled = false; break;
}
/* This capability is the same for all bands, * so take it from one of them.
*/
sband = mvm->hw->wiphy->bands[NL80211_BAND_2GHZ];
own_he_cap = ieee80211_get_he_iftype_cap_vif(sband, vif);
if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_MBSSID_HE))
ver = 1;
switch (ver) { case 1: /* same layout as v2 except some data at the end */
cmd = &sta_ctxt_cmd_v2;
size = sizeof(struct iwl_he_sta_context_cmd_v1); break; case 2:
cmd = &sta_ctxt_cmd_v2;
size = sizeof(struct iwl_he_sta_context_cmd_v2); break; case 3:
cmd = &sta_ctxt_cmd;
size = sizeof(struct iwl_he_sta_context_cmd_v3); break; default:
IWL_ERR(mvm, "bad STA_HE_CTXT_CMD version %d\n", ver); return;
}
rcu_read_lock();
sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_ctxt_cmd.sta_id]); if (IS_ERR_OR_NULL(sta)) {
rcu_read_unlock();
WARN(1, "Can't find STA to configure HE\n"); return;
}
if (!sta->deflink.he_cap.has_he) {
rcu_read_unlock(); return;
}
if (duration_override > duration)
duration = duration_override;
/* Try really hard to protect the session and hear a beacon * The new session protection command allows us to protect the * session for a much longer time since the firmware will internally * create two events: a 300TU one with a very high priority that * won't be fragmented which should be enough for 99% of the cases, * and another one (which we configure here to be 900TU long) which * will have a slightly lower priority, but more importantly, can be * fragmented so that it'll allow other activities to run.
*/ if (fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD))
iwl_mvm_schedule_session_protection(mvm, vif, 900,
min_duration, false,
link_id); else
iwl_mvm_protect_session(mvm, vif, duration,
min_duration, 500, false);
}
/* Handle association common part to MLD and non-MLD modes */ void iwl_mvm_bss_info_changed_station_assoc(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
u64 changes)
{ struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); int ret; int link_id;
/* The firmware tracks the MU-MIMO group on its own. * However, on HW restart we should restore this data.
*/ if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
(changes & BSS_CHANGED_MU_GROUPS) && vif->bss_conf.mu_mimo_owner) {
ret = iwl_mvm_update_mu_groups(mvm, vif); if (ret)
IWL_ERR(mvm, "failed to update VHT MU_MIMO groups\n");
}
iwl_mvm_bt_coex_vif_change(mvm);
iwl_mvm_update_smps_on_active_links(mvm, vif, IWL_MVM_SMPS_REQ_TT,
IEEE80211_SMPS_AUTOMATIC); if (fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_UMAC_SCAN))
iwl_mvm_config_scan(mvm);
}
/* Execute the common part for MLD and non-MLD modes */ void
iwl_mvm_bss_info_changed_station_common(struct iwl_mvm *mvm, struct ieee80211_vif *vif, struct ieee80211_bss_conf *link_conf,
u64 changes)
{ struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); int ret;
if (changes & BSS_CHANGED_BEACON_INFO) { /* We received a beacon from the associated AP so * remove the session protection.
*/
iwl_mvm_stop_session_protection(mvm, vif);
if (changes & (BSS_CHANGED_PS | BSS_CHANGED_P2P_PS | BSS_CHANGED_QOS | /* Send power command on every beacon change, * because we may have not enabled beacon abort yet.
*/
BSS_CHANGED_BEACON_INFO)) {
ret = iwl_mvm_power_update_mac(mvm); if (ret)
IWL_ERR(mvm, "failed to update power mode\n");
}
if (changes & BSS_CHANGED_CQM) { struct iwl_mvm_vif_link_info *link_info =
mvmvif->link[link_conf->link_id];
IWL_DEBUG_MAC80211(mvm, "CQM info_changed\n"); if (link_info)
link_info->bf_data.last_cqm_event = 0;
if (mvmvif->bf_enabled) { /* FIXME: need to update per link when FW API will * support it
*/
ret = iwl_mvm_enable_beacon_filter(mvm, vif); if (ret)
IWL_ERR(mvm, "failed to update CQM thresholds\n");
}
}
if (changes & BSS_CHANGED_BANDWIDTH)
iwl_mvm_update_link_smps(vif, link_conf);
/* * Re-calculate the tsf id, as the leader-follower relations depend * on the beacon interval, which was not known when the station * interface was added.
*/ if (changes & BSS_CHANGED_ASSOC && vif->cfg.assoc) { if ((vif->bss_conf.he_support &&
!iwlwifi_mod_params.disable_11ax))
iwl_mvm_cfg_he_sta(mvm, vif, mvmvif->deflink.ap_sta_id);
/* * If we're not associated yet, take the (new) BSSID before associating * so the firmware knows. If we're already associated, then use the old * BSSID here, and we'll send a cleared one later in the CHANGED_ASSOC * branch for disassociation below.
*/ if (changes & BSS_CHANGED_BSSID && !mvmvif->associated)
memcpy(mvmvif->deflink.bssid, bss_conf->bssid, ETH_ALEN);
ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, mvmvif->deflink.bssid); if (ret)
IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
/* after sending it once, adopt mac80211 data */
memcpy(mvmvif->deflink.bssid, bss_conf->bssid, ETH_ALEN);
mvmvif->associated = vif->cfg.assoc;
if (changes & BSS_CHANGED_ASSOC) { if (vif->cfg.assoc) {
mvmvif->session_prot_connection_loss = false;
/* clear statistics to get clean beacon counter */
iwl_mvm_request_statistics(mvm, true);
for_each_mvm_vif_valid_link(mvmvif, i)
memset(&mvmvif->link[i]->beacon_stats, 0, sizeof(mvmvif->link[i]->beacon_stats));
/* add quota for this interface */
ret = iwl_mvm_update_quotas(mvm, true, NULL); if (ret) {
IWL_ERR(mvm, "failed to update quotas\n"); return;
}
if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
&mvm->status) &&
!fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_SESSION_PROT_CMD)) { /* * If we're restarting then the firmware will * obviously have lost synchronisation with * the AP. It will attempt to synchronise by * itself, but we can make it more reliable by * scheduling a session protection time event. * * The firmware needs to receive a beacon to * catch up with synchronisation, use 110% of * the beacon interval. * * Set a large maximum delay to allow for more * than a single interface. * * For new firmware versions, rely on the * firmware. This is relevant for DCM scenarios * only anyway.
*/
u32 dur = (11 * vif->bss_conf.beacon_int) / 10;
iwl_mvm_protect_session(mvm, vif, dur, dur,
5 * dur, false);
} elseif (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART,
&mvm->status) &&
!vif->bss_conf.dtim_period) { /* * If we're not restarting and still haven't * heard a beacon (dtim period unknown) then * make sure we still have enough minimum time * remaining in the time event, since the auth * might actually have taken quite a while * (especially for SAE) and so the remaining * time could be small without us having heard * a beacon yet.
*/
iwl_mvm_protect_assoc(mvm, vif, 0, 0);
}
iwl_mvm_sf_update(mvm, vif, false);
iwl_mvm_power_vif_assoc(mvm, vif); if (vif->p2p) {
iwl_mvm_update_smps(mvm, vif,
IWL_MVM_SMPS_REQ_PROT,
IEEE80211_SMPS_DYNAMIC, 0);
}
} elseif (mvmvif->deflink.ap_sta_id != IWL_INVALID_STA) {
iwl_mvm_mei_host_disassociated(mvm); /* * If update fails - SF might be running in associated * mode while disassociated - which is forbidden.
*/
ret = iwl_mvm_sf_update(mvm, vif, false);
WARN_ONCE(ret &&
!test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
&mvm->status), "Failed to update SF upon disassociation\n");
/* remove quota for this interface */
ret = iwl_mvm_update_quotas(mvm, false, NULL); if (ret)
IWL_ERR(mvm, "failed to update quotas\n");
/* this will take the cleared BSSID from bss_conf */
ret = iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL); if (ret)
IWL_ERR(mvm, "failed to update MAC %pM (clear after unassoc)\n",
vif->addr);
}
/* must be set before quota calculations */
mvmvif->ap_ibss_active = true;
/* send all the early keys to the device now */ for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) { struct ieee80211_key_conf *key = mvmvif->ap_early_keys[i];
/* * Re-calculate the tsf id, as the leader-follower relations depend on * the beacon interval, which was not known when the AP interface * was added.
*/ if (vif->type == NL80211_IFTYPE_AP)
iwl_mvm_mac_ctxt_recalc_tsf_id(mvm, vif);
/* For older devices need to send beacon template before adding mac * context. For the newer, the beacon is a resource that belongs to a * MAC, so need to send beacon template after adding the mac.
*/ if (mvm->trans->mac_cfg->device_family > IWL_DEVICE_FAMILY_22000) { /* Add the mac context */
ret = iwl_mvm_mac_ctxt_add(mvm, vif); if (ret) goto out_unlock;
/* Send the beacon template */
ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf); if (ret) goto out_unlock;
} else { /* Send the beacon template */
ret = iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, link_conf); if (ret) goto out_unlock;
/* Add the mac context */
ret = iwl_mvm_mac_ctxt_add(mvm, vif); if (ret) goto out_unlock;
}
/* Perform the binding */
ret = iwl_mvm_binding_add_vif(mvm, vif); if (ret) goto out_remove;
/* * This is not very nice, but the simplest: * For older FWs adding the mcast sta before the bcast station may * cause assert 0x2b00. * This is fixed in later FW so make the order of removal depend on * the TLV
*/ if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) {
ret = iwl_mvm_add_mcast_sta(mvm, vif); if (ret) goto out_unbind; /* * Send the bcast station. At this stage the TBTT and DTIM time * events are added and applied to the scheduler
*/
ret = iwl_mvm_send_add_bcast_sta(mvm, vif); if (ret) {
iwl_mvm_rm_mcast_sta(mvm, vif); goto out_unbind;
}
} else { /* * Send the bcast station. At this stage the TBTT and DTIM time * events are added and applied to the scheduler
*/
ret = iwl_mvm_send_add_bcast_sta(mvm, vif); if (ret) goto out_unbind;
ret = iwl_mvm_add_mcast_sta(mvm, vif); if (ret) {
iwl_mvm_send_rm_bcast_sta(mvm, vif); goto out_unbind;
}
}
if (iwl_mvm_start_ap_ibss_common(hw, vif, &ret)) goto out_failed;
ret = iwl_mvm_update_quotas(mvm, false, NULL); if (ret) goto out_failed;
/* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ if (vif->p2p && mvm->p2p_device_vif)
iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
iwl_mvm_bt_coex_vif_change(mvm);
/* we don't support TDLS during DCM */ if (iwl_mvm_phy_ctx_count(mvm) > 1)
iwl_mvm_teardown_tdls_peers(mvm);
/* Need to update the P2P Device MAC (only GO, IBSS is single vif) */ if (vif->p2p && mvm->p2p_device_vif)
iwl_mvm_mac_ctxt_changed(mvm, mvm->p2p_device_vif, false, NULL);
iwl_mvm_update_quotas(mvm, false, NULL);
iwl_mvm_ftm_responder_clear(mvm, vif);
/* * This is not very nice, but the simplest: * For older FWs removing the mcast sta before the bcast station may * cause assert 0x2b00. * This is fixed in later FW (which will stop beaconing when removing * bcast station). * So make the order of removal depend on the TLV
*/ if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
iwl_mvm_rm_mcast_sta(mvm, vif);
iwl_mvm_send_rm_bcast_sta(mvm, vif); if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE))
iwl_mvm_rm_mcast_sta(mvm, vif);
iwl_mvm_binding_remove_vif(mvm, vif);
/* Changes will be applied when the AP/IBSS is started */ if (!mvmvif->ap_ibss_active) return;
if (changes & (BSS_CHANGED_ERP_CTS_PROT | BSS_CHANGED_HT |
BSS_CHANGED_BANDWIDTH | BSS_CHANGED_QOS) &&
iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL))
IWL_ERR(mvm, "failed to update MAC %pM\n", vif->addr);
/* Need to send a new beacon template to the FW */ if (changes & BSS_CHANGED_BEACON &&
iwl_mvm_mac_ctxt_beacon_changed(mvm, vif, &vif->bss_conf))
IWL_WARN(mvm, "Failed updating beacon data\n");
if (changes & BSS_CHANGED_FTM_RESPONDER) { int ret = iwl_mvm_ftm_start_responder(mvm, vif, &vif->bss_conf);
if (ret)
IWL_WARN(mvm, "Failed to enable FTM responder (%d)\n",
ret);
}
/* Due to a race condition, it's possible that mac80211 asks * us to stop a hw_scan when it's already stopped. This can * happen, for instance, if we stopped the scan ourselves, * called ieee80211_scan_completed() and the userspace called * cancel scan before ieee80211_scan_work() could run. * To handle that, simply return if the scan is not running.
*/ if (mvm->scan_status & IWL_MVM_SCAN_REGULAR)
iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_REGULAR, true);
}
/* * If we have TVQM then we get too high queue numbers - luckily * we really shouldn't get here with that because such hardware * should have firmware supporting buffer station offload.
*/ if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) return;
spin_lock_bh(&mvmsta->lock); for (tid = 0; tid < ARRAY_SIZE(mvmsta->tid_data); tid++) { struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid];
if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE) continue;
__set_bit(tid_data->txq_id, &txqs);
if (iwl_mvm_tid_queued(mvm, tid_data) == 0) continue;
if (txqs)
iwl_trans_freeze_txq_timer(mvm->trans, txqs, true); /* * The fw updates the STA to be asleep. Tx packets on the Tx * queues to this station will not be transmitted. The fw will * send a Tx response with TX_STATUS_FAIL_DEST_PS.
*/ break; case STA_NOTIFY_AWAKE: if (WARN_ON(mvmsta->deflink.sta_id == IWL_INVALID_STA)) break;
if (sleeping) { switch (notif->type) { case IWL_MVM_PM_EVENT_AWAKE: case IWL_MVM_PM_EVENT_ASLEEP: break; case IWL_MVM_PM_EVENT_UAPSD:
ieee80211_sta_uapsd_trigger(sta, IEEE80211_NUM_TIDS); break; case IWL_MVM_PM_EVENT_PS_POLL:
ieee80211_sta_pspoll(sta); break; default: break;
}
}
/* * This is called before mac80211 does RCU synchronisation, * so here we already invalidate our internal RCU-protected * station pointer. The rest of the code will thus no longer * be able to find the station this way, and we don't rely * on further RCU synchronisation after the sta_state() * callback deleted the station. * Since there's mvm->mutex here, no need to have RCU lock for * mvm_sta->link access.
*/
guard(mvm)(mvm); for (link_id = 0; link_id < ARRAY_SIZE(mvm_sta->link); link_id++) { struct iwl_mvm_link_sta *link_sta;
u32 sta_id;
for (i = 0; i < IWL_MVM_UAPSD_NOAGG_LIST_LEN; i++) { if (ether_addr_equal(mvm->uapsd_noagg_bssids[i].addr, bssid)) {
vif->driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD; return;
}
}
/* * If there is at least one AP on radar channel that cannot * tolerate 26-tone RU UL OFDMA transmissions using HE TB PPDU.
*/
mvmvif->link[link_id]->he_ru_2mhz_block = !iter_data.tolerated;
}
/* FIXME: temporary making two assumptions in all sta handling functions: * (1) when setting sta state, the link exists and protected * (2) if a link is valid in sta then it's valid in vif (can * use same index in the link array)
*/ staticvoid iwl_mvm_rs_rate_init_all_links(struct iwl_mvm *mvm, struct ieee80211_vif *vif, struct ieee80211_sta *sta)
{ struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); unsignedint link_id;
/* Beacon interval check - firmware will crash if the beacon * interval is less than 16. We can't avoid connecting at all, * so refuse the station state change, this will cause mac80211 * to abandon attempts to connect to this AP, and eventually * wpa_s will blocklist the AP...
*/
if (link_conf->beacon_int < IWL_MVM_MIN_BEACON_INTERVAL_TU) {
IWL_ERR(mvm, "Beacon interval %d for AP %pM is too small\n",
link_conf->beacon_int, link_sta->addr); returnfalse;
}
if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
mvmvif->ap_sta = sta;
/* * Initialize the rates here already - this really tells * the firmware only what the supported legacy rates are * (may be) since it's initialized already from what the * AP advertised in the beacon/probe response. This will * allow the firmware to send auth/assoc frames with one * of the supported rates already, rather than having to * use a mandatory rate. * If we're the AP, we'll just assume mandatory rates at * this point, but we know nothing about the STA anyway.
*/
iwl_mvm_rs_rate_init_all_links(mvm, vif, sta);
/* since the below is not for MLD API, it's ok to use * the default bss_conf
*/ if (!mvm->mld_api_is_used &&
(vif->bss_conf.he_support &&
!iwlwifi_mod_params.disable_11ax))
iwl_mvm_cfg_he_sta(mvm, vif, mvm_sta->deflink.sta_id);
} elseif (vif->type == NL80211_IFTYPE_STATION) {
iwl_mvm_vif_set_he_support(hw, vif, sta, true);
/* Block until FW notif will arrive */
iwl_mvm_block_esr(mvm, vif, IWL_MVM_ESR_BLOCKED_FW, 0);
/* when client is authorized (AP station marked as such), * try to enable the best link(s).
*/ if (vif->type == NL80211_IFTYPE_STATION &&
!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
iwl_mvm_select_links(mvm, vif);
}
mvm_sta->authorized = true;
/* MFP is set by default before the station is authorized. * Clear it here in case it's not used.
*/ if (!sta->mfp) { int ret = callbacks->update_sta(mvm, vif, sta);
/* once we move into assoc state, need to update rate scale to * disable using wide bandwidth
*/
iwl_mvm_rs_rate_init_all_links(mvm, vif, sta);
if (!sta->tdls) { /* Set this but don't call iwl_mvm_mac_ctxt_changed() * yet to avoid sending high prio again for a little * time.
*/
mvmvif->authorized = 0;
mvmvif->link_selection_res = 0;
if (!iwl_mvm_has_rlc_offload(mvm) ||
iwl_fw_lookup_cmd_ver(mvm->fw, MAC_PM_POWER_TABLE, 0) >= 2) return;
mvmvif->ps_disabled = !vif->cfg.ps;
if (update)
iwl_mvm_power_update_mac(mvm);
}
/* Common part for MLD and non-MLD modes */ int iwl_mvm_mac_sta_state_common(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_sta *sta, enum ieee80211_sta_state old_state, enum ieee80211_sta_state new_state, conststruct iwl_mvm_sta_state_ops *callbacks)
{ struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); struct ieee80211_link_sta *link_sta; unsignedint link_id; int ret;
IWL_DEBUG_MAC80211(mvm, "station %pM state change %d->%d\n",
sta->addr, old_state, new_state);
/* * If we are in a STA removal flow and in DQA mode: * * This is after the sync_rcu part, so the queues have already been * flushed. No more TXs on their way in mac80211's path, and no more in * the queues. * Also, we won't be getting any new TX frames for this station. * What we might have are deferred TX frames that need to be taken care * of. * * Drop any still-queued deferred-frame before removing the STA, and * make sure the worker is no longer handling frames for this STA.
*/ if (old_state == IEEE80211_STA_NONE &&
new_state == IEEE80211_STA_NOTEXIST) {
flush_work(&mvm->add_stream_wk);
/* * No need to make sure deferred TX indication is off since the * worker will already remove it if it was on
*/
/* * Additionally, reset the 40 MHz capability if we disconnected * from the AP now.
*/
iwl_mvm_reset_cca_40mhz_workaround(mvm, vif);
/* Also free dup data just in case any assertions below fail */
kfree(mvm_sta->dup_data);
}
mutex_lock(&mvm->mutex);
/* this would be a mac80211 bug ... but don't crash, unless we had a * firmware crash while we were activating a link, in which case it is * legit to have phy_ctxt = NULL. Don't bother not to WARN if we are in * recovery flow since we spit tons of error messages anyway.
*/
for_each_sta_active_link(vif, sta, link_sta, link_id) { if (WARN_ON_ONCE(!mvmvif->link[link_id] ||
!mvmvif->link[link_id]->phy_ctxt)) {
mutex_unlock(&mvm->mutex); return test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
&mvm->status) ? 0 : -EINVAL;
}
}
/* track whether or not the station is associated */
mvm_sta->sta_state = new_state;
if (old_state == IEEE80211_STA_NOTEXIST &&
new_state == IEEE80211_STA_NONE) {
ret = iwl_mvm_sta_state_notexist_to_none(mvm, vif, sta,
callbacks); if (ret < 0) goto out_unlock;
} elseif (old_state == IEEE80211_STA_NONE &&
new_state == IEEE80211_STA_AUTH) { /* * EBS may be disabled due to previous failures reported by FW. * Reset EBS status here assuming environment has been changed.
*/
mvm->last_ebs_successful = true;
iwl_mvm_check_uapsd(mvm, vif, sta->addr);
ret = 0;
} elseif (old_state == IEEE80211_STA_AUTH &&
new_state == IEEE80211_STA_ASSOC) {
ret = iwl_mvm_sta_state_auth_to_assoc(hw, mvm, vif, sta,
callbacks);
} elseif (old_state == IEEE80211_STA_ASSOC &&
new_state == IEEE80211_STA_AUTHORIZED) {
ret = iwl_mvm_sta_state_assoc_to_authorized(mvm, vif, sta,
callbacks);
iwl_mvm_smps_workaround(mvm, vif, true);
} elseif (old_state == IEEE80211_STA_AUTHORIZED &&
new_state == IEEE80211_STA_ASSOC) {
ret = iwl_mvm_sta_state_authorized_to_assoc(mvm, vif, sta,
callbacks);
} elseif (old_state == IEEE80211_STA_ASSOC &&
new_state == IEEE80211_STA_AUTH) { if (vif->type == NL80211_IFTYPE_AP) {
mvmvif->ap_assoc_sta_count--;
callbacks->mac_ctxt_changed(mvm, vif, false);
} elseif (vif->type == NL80211_IFTYPE_STATION && !sta->tdls)
iwl_mvm_stop_session_protection(mvm, vif);
ret = 0;
} elseif (old_state == IEEE80211_STA_AUTH &&
new_state == IEEE80211_STA_NONE) {
ret = 0;
} elseif (old_state == IEEE80211_STA_NONE &&
new_state == IEEE80211_STA_NOTEXIST) { if (vif->type == NL80211_IFTYPE_STATION && !sta->tdls) {
iwl_mvm_stop_session_protection(mvm, vif);
mvmvif->ap_sta = NULL;
}
ret = callbacks->rm_sta(mvm, vif, sta); if (sta->tdls) {
iwl_mvm_recalc_tdls_state(mvm, vif, false);
iwl_mvm_tdls_check_trigger(mvm, vif, sta->addr,
NL80211_TDLS_DISABLE_LINK);
}
if (unlikely(ret &&
test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
&mvm->status)))
ret = 0;
} else {
ret = -EIO;
}
out_unlock:
mutex_unlock(&mvm->mutex);
if (sta->tdls && ret == 0) { if (old_state == IEEE80211_STA_NOTEXIST &&
new_state == IEEE80211_STA_NONE)
ieee80211_reserve_tid(sta, IWL_MVM_TDLS_FW_TID); elseif (old_state == IEEE80211_STA_NONE &&
new_state == IEEE80211_STA_NOTEXIST)
ieee80211_unreserve_tid(sta, IWL_MVM_TDLS_FW_TID);
}
return ret;
}
int iwl_mvm_mac_set_rts_threshold(struct ieee80211_hw *hw, int radio_idx,
u32 value)
{ struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw);
/* * No need to update right away, we'll get BSS_CHANGED_QOS * The exception is P2P_DEVICE interface which needs immediate update.
*/ if (vif->type == NL80211_IFTYPE_P2P_DEVICE) {
guard(mvm)(mvm); return iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
} return 0;
}
int iwl_mvm_mac_sched_scan_stop(struct ieee80211_hw *hw, struct ieee80211_vif *vif)
{ struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); int ret;
mutex_lock(&mvm->mutex);
/* Due to a race condition, it's possible that mac80211 asks * us to stop a sched_scan when it's already stopped. This * can happen, for instance, if we stopped the scan ourselves, * called ieee80211_sched_scan_stopped() and the userspace called * stop sched scan before ieee80211_sched_scan_stopped_work() * could run. To handle this, simply return if the scan is * not running.
*/ if (!(mvm->scan_status & IWL_MVM_SCAN_SCHED)) {
mutex_unlock(&mvm->mutex); return 0;
}
ret = iwl_mvm_scan_stop(mvm, IWL_MVM_SCAN_SCHED, false);
mutex_unlock(&mvm->mutex);
iwl_mvm_wait_for_async_handlers(mvm);
if ((vif->type == NL80211_IFTYPE_ADHOC ||
vif->type == NL80211_IFTYPE_AP) && !sta) { /* * GTK on AP interface is a TX-only key, return 0; * on IBSS they're per-station and because we're lazy * we don't support them for RX, so do the same. * CMAC/GMAC in AP/IBSS modes must be done in software * on older NICs. * * Except, of course, beacon protection - it must be * offloaded since we just set a beacon template, and * then we must also offload the IGTK (not just BIGTK) * for firmware reasons. * * So just check for beacon protection - if we don't * have it we cannot get here with keyidx >= 6, and * if we do have it we need to send the key to FW in * all cases (CMAC/GMAC).
*/ if (!wiphy_ext_feature_isset(hw->wiphy,
NL80211_EXT_FEATURE_BEACON_PROTECTION) &&
(key->cipher == WLAN_CIPHER_SUITE_AES_CMAC ||
key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 ||
key->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)) {
ret = -EOPNOTSUPP; break;
}
if (key->cipher != WLAN_CIPHER_SUITE_GCMP &&
key->cipher != WLAN_CIPHER_SUITE_GCMP_256 &&
!iwl_mvm_has_new_tx_api(mvm)) {
key->hw_key_idx = STA_KEY_IDX_INVALID;
ret = 0; break;
}
if (!mvmvif->ap_ibss_active) { for (i = 0;
i < ARRAY_SIZE(mvmvif->ap_early_keys);
i++) { if (!mvmvif->ap_early_keys[i]) {
mvmvif->ap_early_keys[i] = key; break;
}
}
if (i >= ARRAY_SIZE(mvmvif->ap_early_keys))
ret = -ENOSPC; else
ret = 0;
break;
}
}
/* During FW restart, in order to restore the state as it was, * don't try to reprogram keys we previously failed for.
*/ if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status) &&
key->hw_key_idx == STA_KEY_IDX_INVALID) {
IWL_DEBUG_MAC80211(mvm, "skip invalid idx key programming during restart\n");
ret = 0; break;
}
WARN_ON(rcu_access_pointer(mvmsta->ptk_pn[keyidx]));
ptk_pn = kzalloc(struct_size(ptk_pn, q,
mvm->trans->info.num_rxqs),
GFP_KERNEL); if (!ptk_pn) {
ret = -ENOMEM; break;
}
for (tid = 0; tid < IWL_MAX_TID_COUNT; tid++) {
ieee80211_get_key_rx_seq(key, tid, &seq); for (q = 0; q < mvm->trans->info.num_rxqs; q++)
memcpy(ptk_pn->q[q].pn[tid],
seq.ccmp.pn,
IEEE80211_CCMP_PN_LEN);
}
/* in HW restart reuse the index, otherwise request a new one */ if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status))
key_offset = key->hw_key_idx; else
key_offset = STA_KEY_IDX_INVALID;
if (mvmsta && key->flags & IEEE80211_KEY_FLAG_PAIRWISE)
mvmsta->pairwise_cipher = key->cipher;
if (sec_key_ver)
ret = iwl_mvm_sec_key_add(mvm, vif, sta, key); else
ret = iwl_mvm_set_sta_key(mvm, vif, sta, key, key_offset);
if (ret) {
IWL_WARN(mvm, "set key failed\n");
key->hw_key_idx = STA_KEY_IDX_INVALID; if (ptk_pn) {
RCU_INIT_POINTER(mvmsta->ptk_pn[keyidx], NULL);
kfree(ptk_pn);
} /* * can't add key for RX, but we don't need it * in the device for TX so still return 0, * unless we have new TX API where we cannot * put key material into the TX_CMD
*/ if (iwl_mvm_has_new_tx_api(mvm))
ret = -EOPNOTSUPP; else
ret = 0;
}
break; case DISABLE_KEY: if (vif->type == NL80211_IFTYPE_STATION &&
(keyidx == 6 || keyidx == 7))
RCU_INIT_POINTER(mvmvif->bcn_prot.keys[keyidx - 6],
NULL);
ret = -ENOENT; for (i = 0; i < ARRAY_SIZE(mvmvif->ap_early_keys); i++) { if (mvmvif->ap_early_keys[i] == key) {
mvmvif->ap_early_keys[i] = NULL;
ret = 0;
}
}
/* found in pending list - don't do anything else */ if (ret == 0) break;
if (key->hw_key_idx == STA_KEY_IDX_INVALID) {
ret = 0; break;
}
/* Set the channel info data */
iwl_mvm_set_chan_info(mvm, &aux_roc_req.channel_info, channel->hw_value,
iwl_mvm_phy_band_from_nl80211(channel->band),
IWL_PHY_CHANNEL_MODE20,
0);
/* Set the time and duration */
tail->apply_time = cpu_to_le32(iwl_mvm_get_systime(mvm));
/* * Use a notification wait, which really just processes the * command response and doesn't wait for anything, in order * to be able to process the response and get the UID inside * the RX path. Using CMD_WANT_SKB doesn't work because it * stores the buffer and then wakes up this thread, by which * time another notification (that the time event started) * might already be processed unsuccessfully.
*/
iwl_init_notification_wait(&mvm->notif_wait, &wait_time_event,
time_event_response,
ARRAY_SIZE(time_event_response),
iwl_mvm_rx_aux_roc, te_data);
res = iwl_mvm_send_cmd_pdu(mvm, HOT_SPOT_CMD, 0, len,
&aux_roc_req);
/* No need to wait for anything, so just pass 1 (0 isn't valid) */
res = iwl_wait_notification(&mvm->notif_wait, &wait_time_event, 1); /* should never fail */
WARN_ON_ONCE(res);
if (res) {
out_clear_te:
spin_lock_bh(&mvm->time_event_lock);
iwl_mvm_te_clear_data(mvm, te_data);
spin_unlock_bh(&mvm->time_event_lock);
}
return res;
}
staticint iwl_mvm_add_aux_sta_for_hs20(struct iwl_mvm *mvm, u32 lmac_id)
{ int ret = 0;
lockdep_assert_held(&mvm->mutex);
if (!fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_HOTSPOT_SUPPORT)) {
IWL_ERR(mvm, "hotspot not supported\n"); return -EINVAL;
}
if (iwl_mvm_has_new_station_api(mvm->fw)) {
ret = iwl_mvm_add_aux_sta(mvm, lmac_id);
WARN(ret, "Failed to allocate aux station");
}
return ret;
}
staticint iwl_mvm_roc_link(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
{ int ret;
lockdep_assert_held(&mvm->mutex);
ret = iwl_mvm_binding_add_vif(mvm, vif); if (WARN(ret, "Failed binding P2P_DEVICE\n")) return ret;
/* The station and queue allocation must be done only after the binding * is done, as otherwise the FW might incorrectly configure its state.
*/ return iwl_mvm_add_p2p_bcast_sta(mvm, vif);
}
/* We already have a phy_ctxt, but it's not on the right channel */ if (mvmvif->deflink.phy_ctxt)
iwl_mvm_phy_ctxt_unref(mvm, mvmvif->deflink.phy_ctxt);
mvmvif->deflink.phy_ctxt = iwl_mvm_get_free_phy_ctxt(mvm); if (!mvmvif->deflink.phy_ctxt) return -ENOSPC;
/* * Flush the done work, just in case it's still pending, so that * the work it does can complete and we can accept new frames.
*/
flush_work(&mvm->roc_done_wk);
if (!IS_ERR_OR_NULL(bss_vif)) {
ret = iwl_mvm_block_esr_sync(mvm, bss_vif,
IWL_MVM_ESR_BLOCKED_ROC); if (ret) return ret;
}
guard(mvm)(mvm);
switch (vif->type) { case NL80211_IFTYPE_STATION:
lmac_id = iwl_mvm_get_lmac_id(mvm, channel->band);
/* Use aux roc framework (HS20) */
ret = ops->add_aux_sta_for_hs20(mvm, lmac_id); if (!ret)
ret = iwl_mvm_roc_station(mvm, channel, vif, duration); return ret; case NL80211_IFTYPE_P2P_DEVICE: /* handle below */ break; default:
IWL_ERR(mvm, "ROC: Invalid vif type=%u\n", vif->type); return -EINVAL;
}
if (iwl_mvm_has_p2p_over_aux(mvm)) {
ret = iwl_mvm_roc_p2p(mvm, channel, vif, duration, type); return ret;
}
ret = iwl_mvm_p2p_find_phy_ctxt(mvm, vif, channel); if (ret) return ret;
/* * This function executes the common part for MLD and non-MLD modes. * * Returns true if we're done assigning the chanctx * (either on failure or success)
*/ staticbool
__iwl_mvm_assign_vif_chanctx_common(struct iwl_mvm *mvm, struct ieee80211_vif *vif, struct ieee80211_chanctx_conf *ctx, bool switching_chanctx, int *ret)
{
u16 *phy_ctxt_id = (u16 *)ctx->drv_priv; struct iwl_mvm_phy_ctxt *phy_ctxt = &mvm->phy_ctxts[*phy_ctxt_id]; struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
lockdep_assert_held(&mvm->mutex);
mvmvif->deflink.phy_ctxt = phy_ctxt;
switch (vif->type) { case NL80211_IFTYPE_AP: /* only needed if we're switching chanctx (i.e. during CSA) */ if (switching_chanctx) {
mvmvif->ap_ibss_active = true; break;
}
fallthrough; case NL80211_IFTYPE_ADHOC: /* * The AP binding flow is handled as part of the start_ap flow * (in bss_info_changed), similarly for IBSS.
*/
*ret = 0; returntrue; case NL80211_IFTYPE_STATION: break; case NL80211_IFTYPE_MONITOR: /* always disable PS when a monitor interface is active */
mvmvif->ps_disabled = true; break; default:
*ret = -EINVAL; returntrue;
} returnfalse;
}
if (__iwl_mvm_assign_vif_chanctx_common(mvm, vif, ctx,
switching_chanctx, &ret)) goto out;
ret = iwl_mvm_binding_add_vif(mvm, vif); if (ret) goto out;
/* * Power state must be updated before quotas, * otherwise fw will complain.
*/
iwl_mvm_power_update_mac(mvm);
/* Setting the quota at this stage is only required for monitor * interfaces. For the other types, the bss_info changed flow * will handle quota settings.
*/ if (vif->type == NL80211_IFTYPE_MONITOR) {
mvmvif->monitor_active = true;
ret = iwl_mvm_update_quotas(mvm, false, NULL); if (ret) goto out_remove_binding;
ret = iwl_mvm_add_snif_sta(mvm, vif); if (ret) goto out_remove_binding;
}
/* Handle binding during CSA */ if (vif->type == NL80211_IFTYPE_AP) {
iwl_mvm_update_quotas(mvm, false, NULL);
iwl_mvm_mac_ctxt_changed(mvm, vif, false, NULL);
}
if (vif->type == NL80211_IFTYPE_STATION) { if (!switching_chanctx) {
mvmvif->csa_bcn_pending = false; goto out;
}
mvmvif->csa_bcn_pending = true;
if (!fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
u32 duration = 5 * vif->bss_conf.beacon_int;
/* Protect the session to make sure we hear the first * beacon on the new channel.
*/
iwl_mvm_protect_session(mvm, vif, duration, duration,
vif->bss_conf.beacon_int / 2, true);
}
/* * This function executes the common part for MLD and non-MLD modes. * * Returns if chanctx unassign chanctx is done * (either on failure or success)
*/ staticbool __iwl_mvm_unassign_vif_chanctx_common(struct iwl_mvm *mvm, struct ieee80211_vif *vif, bool switching_chanctx)
{ struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
switch (vif->type) { case NL80211_IFTYPE_ADHOC: returntrue; case NL80211_IFTYPE_MONITOR:
mvmvif->monitor_active = false;
mvmvif->ps_disabled = false; break; case NL80211_IFTYPE_AP: /* This part is triggered only during CSA */ if (!switching_chanctx || !mvmvif->ap_ibss_active) returntrue;
mvmvif->csa_countdown = false;
/* Set CS bit on all the stations */
iwl_mvm_modify_all_sta_disable_tx(mvm, mvmvif, true);
/* Save blocked iface, the timeout is set on the next beacon */
rcu_assign_pointer(mvm->csa_tx_blocked_vif, vif);
ret = ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf,
vifs[0].new_ctx, true); if (ret) {
IWL_ERR(mvm, "failed to assign new_ctx during channel switch\n"); goto out_reassign;
}
return 0;
out_reassign: if (ops->__assign_vif_chanctx(mvm, vifs[0].vif, vifs[0].link_conf,
vifs[0].old_ctx, true)) {
IWL_ERR(mvm, "failed to reassign old_ctx after failure.\n"); goto out_restart;
}
return ret;
out_restart: /* things keep failing, better restart the hw */
iwl_force_nmi(mvm->trans); return ret;
}
/* Execute the common part for both MLD and non-MLD modes */ int
iwl_mvm_switch_vif_chanctx_common(struct ieee80211_hw *hw, struct ieee80211_vif_chanctx_switch *vifs, int n_vifs, enum ieee80211_chanctx_switch_mode mode, conststruct iwl_mvm_switch_vif_chanctx_ops *ops)
{ struct iwl_mvm *mvm = IWL_MAC80211_GET_MVM(hw); int ret;
/* we only support a single-vif right now */ if (n_vifs > 1) return -EOPNOTSUPP;
switch (mode) { case CHANCTX_SWMODE_SWAP_CONTEXTS:
ret = iwl_mvm_switch_vif_chanctx_swap(mvm, vifs, ops); break; case CHANCTX_SWMODE_REASSIGN_VIF:
ret = iwl_mvm_switch_vif_chanctx_reassign(mvm, vifs, ops); break; default:
ret = -EOPNOTSUPP; break;
}
void iwl_mvm_channel_switch(struct ieee80211_hw *hw, struct ieee80211_vif *vif, struct ieee80211_channel_switch *chsw)
{ /* By implementing this operation, we prevent mac80211 from * starting its own channel switch timer, so that we can call * ieee80211_chswitch_done() ourselves at the right time * (which is when the absence time event starts).
*/
/* Schedule the time event to a bit before beacon 1, * to make sure we're in the new channel when the * GO/AP arrives. In case count <= 1 immediately schedule the * TE (this might result with some packet loss or connection * loss).
*/ if (chsw->count <= 1)
apply_time = 0; else
apply_time = chsw->device_timestamp +
((vif->bss_conf.beacon_int * (chsw->count - 1) -
IWL_MVM_CHANNEL_SWITCH_TIME_CLIENT) * 1024);
if (chsw->block_tx)
iwl_mvm_csa_client_absent(mvm, vif);
if (mvmvif->bf_enabled) { int ret = iwl_mvm_disable_beacon_filter(mvm, vif);
switch (vif->type) { case NL80211_IFTYPE_AP:
csa_vif =
rcu_dereference_protected(mvm->csa_vif,
lockdep_is_held(&mvm->mutex)); if (WARN_ONCE(csa_vif && csa_vif->bss_conf.csa_active, "Another CSA is already in progress")) return -EBUSY;
/* we still didn't unblock tx. prevent new CS meanwhile */ if (rcu_dereference_protected(mvm->csa_tx_blocked_vif,
lockdep_is_held(&mvm->mutex))) return -EBUSY;
rcu_assign_pointer(mvm->csa_vif, vif);
if (WARN_ONCE(mvmvif->csa_countdown, "Previous CSA countdown didn't complete")) return -EBUSY;
if (!chsw->block_tx) break; /* don't need blocking in driver otherwise - mac80211 will do */ if (!ieee80211_hw_check(mvm->hw, HANDLES_QUIET_CSA)) break;
/* * In the new flow FW is in charge of timing the switch so there * is no need for all of this
*/ if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
CHANNEL_SWITCH_ERROR_NOTIF,
0)) break;
/* * We haven't configured the firmware to be associated yet since * we don't know the dtim period. In this case, the firmware can't * track the beacons.
*/ if (!vif->cfg.assoc || !vif->bss_conf.dtim_period) return -EBUSY;
if (chsw->delay > IWL_MAX_CSA_BLOCK_TX &&
hweight16(vif->valid_links) <= 1)
schedule_delayed_work(&mvmvif->csa_work, 0);
if (chsw->block_tx) { /* * In case of undetermined / long time with immediate * quiet monitor status to gracefully disconnect
*/ if (!chsw->count ||
chsw->count * vif->bss_conf.beacon_int >
IWL_MAX_CSA_BLOCK_TX)
schedule_delayed_work(&mvmvif->csa_work,
msecs_to_jiffies(IWL_MAX_CSA_BLOCK_TX));
}
if (!fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_CHANNEL_SWITCH_CMD)) {
ret = iwl_mvm_old_pre_chan_sw_sta(mvm, vif, chsw); if (ret) return ret;
} else {
iwl_mvm_schedule_client_csa(mvm, vif, chsw);
}
/* * In the new flow FW is in charge of timing the switch so there is no * need for all of this
*/ if (iwl_fw_lookup_notif_ver(mvm->fw, MAC_CONF_GROUP,
CHANNEL_SWITCH_ERROR_NOTIF, 0)) return;
if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CS_MODIFY)) return;
IWL_DEBUG_MAC80211(mvm, "Modify CSA on mac %d count = %d (old %d) mode = %d\n",
mvmvif->id, chsw->count, mvmvif->csa_count, chsw->block_tx);
if (chsw->count >= mvmvif->csa_count && chsw->block_tx) { if (mvmvif->csa_misbehave) { struct ieee80211_bss_conf *link_conf;
/* Second time, give up on this AP*/
link_conf = wiphy_dereference(hw->wiphy,
vif->link_conf[chsw->link_id]); if (WARN_ON(!link_conf)) return;
if (!iwl_mvm_has_new_tx_api(mvm)) { /* we can't ask the firmware anything if it is dead */ if (test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
&mvm->status)) return; if (drop) {
guard(mvm)(mvm);
iwl_mvm_flush_tx_path(mvm,
iwl_mvm_flushable_queues(mvm) & queues);
} else {
iwl_trans_wait_tx_queues_empty(mvm->trans, queues);
} return;
}
guard(mvm)(mvm); for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) { struct ieee80211_sta *sta;
sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
lockdep_is_held(&mvm->mutex)); if (IS_ERR_OR_NULL(sta)) continue;
if (drop)
iwl_mvm_flush_sta_tids(mvm, i, 0xFFFF); else
iwl_mvm_wait_sta_queues_empty(mvm,
iwl_mvm_sta_from_mac80211(sta));
}
}
if (!vif) {
iwl_mvm_flush_no_vif(mvm, queues, drop); return;
}
if (!drop && hweight16(vif->active_links) <= 1) { int link_id = vif->active_links ? __ffs(vif->active_links) : 0; struct ieee80211_bss_conf *link_conf;
link_conf = wiphy_dereference(hw->wiphy,
vif->link_conf[link_id]); if (WARN_ON(!link_conf)) return; if (link_conf->csa_active && mvmvif->csa_blocks_tx)
drop = true;
}
/* Make sure we're done with the deferred traffic before flushing */
flush_work(&mvm->add_stream_wk);
mutex_lock(&mvm->mutex);
/* flush the AP-station and all TDLS peers */ for (i = 0; i < mvm->fw->ucode_capa.num_stations; i++) {
sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i],
lockdep_is_held(&mvm->mutex)); if (IS_ERR_OR_NULL(sta)) continue;
mvmsta = iwl_mvm_sta_from_mac80211(sta); if (mvmsta->vif != vif) continue;
if (sta == mvmvif->ap_sta) { if (ap_sta_done) continue;
ap_sta_done = true;
}
if (drop) { if (iwl_mvm_flush_sta(mvm, mvmsta->deflink.sta_id,
mvmsta->tfd_queue_msk))
IWL_ERR(mvm, "flush request fail\n");
} else { if (iwl_mvm_has_new_tx_api(mvm))
iwl_mvm_wait_sta_queues_empty(mvm, mvmsta); else/* only used for !iwl_mvm_has_new_tx_api() below */
msk |= mvmsta->tfd_queue_msk;
}
}
mutex_unlock(&mvm->mutex);
/* this can take a while, and we may need/want other operations * to succeed while doing this, so do it without the mutex held * If the firmware is dead, this can't work...
*/ if (!drop && !iwl_mvm_has_new_tx_api(mvm) &&
!test_bit(IWL_MVM_STATUS_HW_RESTART_REQUESTED,
&mvm->status))
iwl_trans_wait_tx_queues_empty(mvm->trans, msk);
}
if (iwl_mvm_flush_sta(mvm, mvm_link_sta->sta_id,
mvmsta->tfd_queue_msk))
IWL_ERR(mvm, "flush request fail\n");
}
}
staticint iwl_mvm_mac_get_acs_survey(struct iwl_mvm *mvm, int idx, struct survey_info *survey)
{ int chan_idx; enum nl80211_band band; int ret;
mutex_lock(&mvm->mutex);
if (!mvm->acs_survey) {
ret = -ENOENT; goto out;
}
/* Find and return the next entry that has a non-zero active time */ for (band = 0; band < NUM_NL80211_BANDS; band++) { struct ieee80211_supported_band *sband =
mvm->hw->wiphy->bands[band];
if (!fw_has_capa(&mvm->fw->ucode_capa,
IWL_UCODE_TLV_CAPA_RADIO_BEACON_STATS)) return -ENOENT;
/* * Return the beacon stats at index zero and pass on following indices * to the function returning the full survey, most likely for ACS * (Automatic Channel Selection).
*/ if (idx > 0) return iwl_mvm_mac_get_acs_survey(mvm, idx - 1, survey);
guard(mvm)(mvm);
if (iwl_mvm_firmware_running(mvm)) { int ret = iwl_mvm_request_statistics(mvm, false);
if (rate_n_flags & RATE_MCS_SGI_MSK)
rinfo->flags |= RATE_INFO_FLAGS_SHORT_GI;
switch (format) { case RATE_MCS_MOD_TYPE_EHT: /* TODO: GI/LTF/RU. How does the firmware encode them? */
rinfo->flags |= RATE_INFO_FLAGS_EHT_MCS; break; case RATE_MCS_MOD_TYPE_HE:
gi_ltf = u32_get_bits(rate_n_flags, RATE_MCS_HE_GI_LTF_MSK);
sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_RX); if (mvmvif->deflink.beacon_stats.avg_signal) { /* firmware only reports a value after RXing a few beacons */
sinfo->rx_beacon_signal_avg =
mvmvif->deflink.beacon_stats.avg_signal;
sinfo->filled |= BIT_ULL(NL80211_STA_INFO_BEACON_SIGNAL_AVG);
}
}
ret = iwl_mvm_send_cmd(mvm, &hcmd); if (ret) {
IWL_ERR(mvm, "Failed to trigger RX queues sync (%d)\n", ret); goto out;
}
if (sync) {
lockdep_assert_held(&mvm->mutex);
ret = wait_event_timeout(mvm->rx_sync_waitq,
READ_ONCE(mvm->queue_sync_state) == 0,
SYNC_RX_QUEUE_TIMEOUT);
WARN_ONCE(!ret, "queue sync: failed to sync, state is 0x%lx, cookie %d\n",
mvm->queue_sync_state,
mvm->queue_sync_cookie);
}
out: if (sync) {
mvm->queue_sync_state = 0;
mvm->queue_sync_cookie++;
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.