Path: blob/main/sys/contrib/dev/iwlwifi/mvm/binding.c
48287 views
// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause1/*2* Copyright (C) 2012-2014, 2020 Intel Corporation3* Copyright (C) 2016 Intel Deutschland GmbH4* Copyright (C) 2022, 2024 Intel Corporation5*/6#include <net/mac80211.h>7#include "fw-api.h"8#include "mvm.h"910struct iwl_mvm_iface_iterator_data {11struct ieee80211_vif *ignore_vif;12int idx;1314struct iwl_mvm_phy_ctxt *phyctxt;1516u16 ids[MAX_MACS_IN_BINDING];17u16 colors[MAX_MACS_IN_BINDING];18};1920static int iwl_mvm_binding_cmd(struct iwl_mvm *mvm, u32 action,21struct iwl_mvm_iface_iterator_data *data)22{23struct iwl_binding_cmd cmd;24struct iwl_mvm_phy_ctxt *phyctxt = data->phyctxt;25int i, ret;26u32 status;27int size;2829memset(&cmd, 0, sizeof(cmd));3031if (fw_has_capa(&mvm->fw->ucode_capa,32IWL_UCODE_TLV_CAPA_BINDING_CDB_SUPPORT)) {33size = sizeof(cmd);34cmd.lmac_id = cpu_to_le32(iwl_mvm_get_lmac_id(mvm,35phyctxt->channel->band));36} else {37size = IWL_BINDING_CMD_SIZE_V1;38}3940cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(phyctxt->id,41phyctxt->color));42cmd.action = cpu_to_le32(action);43cmd.phy = cpu_to_le32(FW_CMD_ID_AND_COLOR(phyctxt->id,44phyctxt->color));4546for (i = 0; i < MAX_MACS_IN_BINDING; i++)47cmd.macs[i] = cpu_to_le32(FW_CTXT_INVALID);48for (i = 0; i < data->idx; i++)49cmd.macs[i] = cpu_to_le32(FW_CMD_ID_AND_COLOR(data->ids[i],50data->colors[i]));5152status = 0;53ret = iwl_mvm_send_cmd_pdu_status(mvm, BINDING_CONTEXT_CMD,54size, &cmd, &status);55if (ret) {56IWL_ERR(mvm, "Failed to send binding (action:%d): %d\n",57action, ret);58return ret;59}6061if (status) {62IWL_ERR(mvm, "Binding command failed: %u\n", status);63ret = -EIO;64}6566return ret;67}6869static void iwl_mvm_iface_iterator(void *_data, u8 *mac,70struct ieee80211_vif *vif)71{72struct iwl_mvm_iface_iterator_data *data = _data;73struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);7475if (vif == data->ignore_vif)76return;7778if (mvmvif->deflink.phy_ctxt != data->phyctxt)79return;8081if (WARN_ON_ONCE(data->idx >= MAX_MACS_IN_BINDING))82return;8384data->ids[data->idx] = mvmvif->id;85data->colors[data->idx] = mvmvif->color;86data->idx++;87}8889static int iwl_mvm_binding_update(struct iwl_mvm *mvm,90struct ieee80211_vif *vif,91struct iwl_mvm_phy_ctxt *phyctxt,92bool add)93{94struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);95struct iwl_mvm_iface_iterator_data data = {96.ignore_vif = vif,97.phyctxt = phyctxt,98};99u32 action = FW_CTXT_ACTION_MODIFY;100101lockdep_assert_held(&mvm->mutex);102103ieee80211_iterate_active_interfaces_atomic(mvm->hw,104IEEE80211_IFACE_ITER_NORMAL,105iwl_mvm_iface_iterator,106&data);107108/*109* If there are no other interfaces yet we110* need to create a new binding.111*/112if (data.idx == 0) {113if (add)114action = FW_CTXT_ACTION_ADD;115else116action = FW_CTXT_ACTION_REMOVE;117}118119if (add) {120if (WARN_ON_ONCE(data.idx >= MAX_MACS_IN_BINDING))121return -EINVAL;122123data.ids[data.idx] = mvmvif->id;124data.colors[data.idx] = mvmvif->color;125data.idx++;126}127128return iwl_mvm_binding_cmd(mvm, action, &data);129}130131int iwl_mvm_binding_add_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif)132{133struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);134135if (WARN_ON_ONCE(!mvmvif->deflink.phy_ctxt))136return -EINVAL;137138/*139* Update SF - Disable if needed. if this fails, SF might still be on140* while many macs are bound, which is forbidden - so fail the binding.141*/142if (iwl_mvm_sf_update(mvm, vif, false))143return -EINVAL;144145return iwl_mvm_binding_update(mvm, vif, mvmvif->deflink.phy_ctxt,146true);147}148149int iwl_mvm_binding_remove_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif)150{151struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);152int ret;153154if (WARN_ON_ONCE(!mvmvif->deflink.phy_ctxt))155return -EINVAL;156157ret = iwl_mvm_binding_update(mvm, vif, mvmvif->deflink.phy_ctxt,158false);159160if (!ret && iwl_mvm_sf_update(mvm, vif, true))161IWL_ERR(mvm, "Failed to update SF state\n");162163return ret;164}165166u32 iwl_mvm_get_lmac_id(struct iwl_mvm *mvm, enum nl80211_band band)167{168if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CDB_SUPPORT) ||169band == NL80211_BAND_2GHZ)170return IWL_LMAC_24G_INDEX;171return IWL_LMAC_5G_INDEX;172}173174175