1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (C) 2012-2014, 2020 Intel Corporation
4 * Copyright (C) 2016 Intel Deutschland GmbH
5 * Copyright (C) 2022, 2024 Intel Corporation
7 #include <net/mac80211.h>
11 struct iwl_mvm_iface_iterator_data {
12 struct ieee80211_vif *ignore_vif;
15 struct iwl_mvm_phy_ctxt *phyctxt;
17 u16 ids[MAX_MACS_IN_BINDING];
18 u16 colors[MAX_MACS_IN_BINDING];
21 static int iwl_mvm_binding_cmd(struct iwl_mvm *mvm, u32 action,
22 struct iwl_mvm_iface_iterator_data *data)
24 struct iwl_binding_cmd cmd;
25 struct iwl_mvm_phy_ctxt *phyctxt = data->phyctxt;
30 memset(&cmd, 0, sizeof(cmd));
32 if (fw_has_capa(&mvm->fw->ucode_capa,
33 IWL_UCODE_TLV_CAPA_BINDING_CDB_SUPPORT)) {
35 cmd.lmac_id = cpu_to_le32(iwl_mvm_get_lmac_id(mvm,
36 phyctxt->channel->band));
38 size = IWL_BINDING_CMD_SIZE_V1;
41 cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(phyctxt->id,
43 cmd.action = cpu_to_le32(action);
44 cmd.phy = cpu_to_le32(FW_CMD_ID_AND_COLOR(phyctxt->id,
47 for (i = 0; i < MAX_MACS_IN_BINDING; i++)
48 cmd.macs[i] = cpu_to_le32(FW_CTXT_INVALID);
49 for (i = 0; i < data->idx; i++)
50 cmd.macs[i] = cpu_to_le32(FW_CMD_ID_AND_COLOR(data->ids[i],
54 ret = iwl_mvm_send_cmd_pdu_status(mvm, BINDING_CONTEXT_CMD,
57 IWL_ERR(mvm, "Failed to send binding (action:%d): %d\n",
63 IWL_ERR(mvm, "Binding command failed: %u\n", status);
70 static void iwl_mvm_iface_iterator(void *_data, u8 *mac,
71 struct ieee80211_vif *vif)
73 struct iwl_mvm_iface_iterator_data *data = _data;
74 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
76 if (vif == data->ignore_vif)
79 if (mvmvif->deflink.phy_ctxt != data->phyctxt)
82 if (WARN_ON_ONCE(data->idx >= MAX_MACS_IN_BINDING))
85 data->ids[data->idx] = mvmvif->id;
86 data->colors[data->idx] = mvmvif->color;
90 static int iwl_mvm_binding_update(struct iwl_mvm *mvm,
91 struct ieee80211_vif *vif,
92 struct iwl_mvm_phy_ctxt *phyctxt,
95 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
96 struct iwl_mvm_iface_iterator_data data = {
100 u32 action = FW_CTXT_ACTION_MODIFY;
102 lockdep_assert_held(&mvm->mutex);
104 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
105 IEEE80211_IFACE_ITER_NORMAL,
106 iwl_mvm_iface_iterator,
110 * If there are no other interfaces yet we
111 * need to create a new binding.
115 action = FW_CTXT_ACTION_ADD;
117 action = FW_CTXT_ACTION_REMOVE;
121 if (WARN_ON_ONCE(data.idx >= MAX_MACS_IN_BINDING))
124 data.ids[data.idx] = mvmvif->id;
125 data.colors[data.idx] = mvmvif->color;
129 return iwl_mvm_binding_cmd(mvm, action, &data);
132 int iwl_mvm_binding_add_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
134 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
136 if (WARN_ON_ONCE(!mvmvif->deflink.phy_ctxt))
140 * Update SF - Disable if needed. if this fails, SF might still be on
141 * while many macs are bound, which is forbidden - so fail the binding.
143 if (iwl_mvm_sf_update(mvm, vif, false))
146 return iwl_mvm_binding_update(mvm, vif, mvmvif->deflink.phy_ctxt,
150 int iwl_mvm_binding_remove_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
152 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
155 if (WARN_ON_ONCE(!mvmvif->deflink.phy_ctxt))
158 ret = iwl_mvm_binding_update(mvm, vif, mvmvif->deflink.phy_ctxt,
161 if (!ret && iwl_mvm_sf_update(mvm, vif, true))
162 IWL_ERR(mvm, "Failed to update SF state\n");
167 u32 iwl_mvm_get_lmac_id(struct iwl_mvm *mvm, enum nl80211_band band)
169 if (!fw_has_capa(&mvm->fw->ucode_capa, IWL_UCODE_TLV_CAPA_CDB_SUPPORT) ||
170 band == NL80211_BAND_2GHZ)
171 return IWL_LMAC_24G_INDEX;
172 return IWL_LMAC_5G_INDEX;