1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66#include <net/mac80211.h>
67#include "fw-api.h"
68#include "mvm.h"
69
70struct iwl_mvm_iface_iterator_data {
71 struct ieee80211_vif *ignore_vif;
72 int idx;
73
74 struct iwl_mvm_phy_ctxt *phyctxt;
75
76 u16 ids[MAX_MACS_IN_BINDING];
77 u16 colors[MAX_MACS_IN_BINDING];
78};
79
80static int iwl_mvm_binding_cmd(struct iwl_mvm *mvm, u32 action,
81 struct iwl_mvm_iface_iterator_data *data)
82{
83 struct iwl_binding_cmd cmd;
84 struct iwl_mvm_phy_ctxt *phyctxt = data->phyctxt;
85 int i, ret;
86 u32 status;
87 int size;
88
89 memset(&cmd, 0, sizeof(cmd));
90
91 if (fw_has_capa(&mvm->fw->ucode_capa,
92 IWL_UCODE_TLV_CAPA_BINDING_CDB_SUPPORT)) {
93 size = sizeof(cmd);
94 if (phyctxt->channel->band == NL80211_BAND_2GHZ ||
95 !iwl_mvm_is_cdb_supported(mvm))
96 cmd.lmac_id = cpu_to_le32(IWL_LMAC_24G_INDEX);
97 else
98 cmd.lmac_id = cpu_to_le32(IWL_LMAC_5G_INDEX);
99 } else {
100 size = IWL_BINDING_CMD_SIZE_V1;
101 }
102
103 cmd.id_and_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(phyctxt->id,
104 phyctxt->color));
105 cmd.action = cpu_to_le32(action);
106 cmd.phy = cpu_to_le32(FW_CMD_ID_AND_COLOR(phyctxt->id,
107 phyctxt->color));
108
109 for (i = 0; i < MAX_MACS_IN_BINDING; i++)
110 cmd.macs[i] = cpu_to_le32(FW_CTXT_INVALID);
111 for (i = 0; i < data->idx; i++)
112 cmd.macs[i] = cpu_to_le32(FW_CMD_ID_AND_COLOR(data->ids[i],
113 data->colors[i]));
114
115 status = 0;
116 ret = iwl_mvm_send_cmd_pdu_status(mvm, BINDING_CONTEXT_CMD,
117 size, &cmd, &status);
118 if (ret) {
119 IWL_ERR(mvm, "Failed to send binding (action:%d): %d\n",
120 action, ret);
121 return ret;
122 }
123
124 if (status) {
125 IWL_ERR(mvm, "Binding command failed: %u\n", status);
126 ret = -EIO;
127 }
128
129 return ret;
130}
131
132static void iwl_mvm_iface_iterator(void *_data, u8 *mac,
133 struct ieee80211_vif *vif)
134{
135 struct iwl_mvm_iface_iterator_data *data = _data;
136 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
137
138 if (vif == data->ignore_vif)
139 return;
140
141 if (mvmvif->phy_ctxt != data->phyctxt)
142 return;
143
144 if (WARN_ON_ONCE(data->idx >= MAX_MACS_IN_BINDING))
145 return;
146
147 data->ids[data->idx] = mvmvif->id;
148 data->colors[data->idx] = mvmvif->color;
149 data->idx++;
150}
151
152static int iwl_mvm_binding_update(struct iwl_mvm *mvm,
153 struct ieee80211_vif *vif,
154 struct iwl_mvm_phy_ctxt *phyctxt,
155 bool add)
156{
157 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
158 struct iwl_mvm_iface_iterator_data data = {
159 .ignore_vif = vif,
160 .phyctxt = phyctxt,
161 };
162 u32 action = FW_CTXT_ACTION_MODIFY;
163
164 lockdep_assert_held(&mvm->mutex);
165
166 ieee80211_iterate_active_interfaces_atomic(mvm->hw,
167 IEEE80211_IFACE_ITER_NORMAL,
168 iwl_mvm_iface_iterator,
169 &data);
170
171
172
173
174
175 if (data.idx == 0) {
176 if (add)
177 action = FW_CTXT_ACTION_ADD;
178 else
179 action = FW_CTXT_ACTION_REMOVE;
180 }
181
182 if (add) {
183 if (WARN_ON_ONCE(data.idx >= MAX_MACS_IN_BINDING))
184 return -EINVAL;
185
186 data.ids[data.idx] = mvmvif->id;
187 data.colors[data.idx] = mvmvif->color;
188 data.idx++;
189 }
190
191 return iwl_mvm_binding_cmd(mvm, action, &data);
192}
193
194int iwl_mvm_binding_add_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
195{
196 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
197
198 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
199 return -EINVAL;
200
201
202
203
204
205 if (iwl_mvm_sf_update(mvm, vif, false))
206 return -EINVAL;
207
208 return iwl_mvm_binding_update(mvm, vif, mvmvif->phy_ctxt, true);
209}
210
211int iwl_mvm_binding_remove_vif(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
212{
213 struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif);
214 int ret;
215
216 if (WARN_ON_ONCE(!mvmvif->phy_ctxt))
217 return -EINVAL;
218
219 ret = iwl_mvm_binding_update(mvm, vif, mvmvif->phy_ctxt, false);
220
221 if (!ret)
222 if (iwl_mvm_sf_update(mvm, vif, true))
223 IWL_ERR(mvm, "Failed to update SF state\n");
224
225 return ret;
226}
227