]>
Commit | Line | Data |
---|---|---|
8ca151b5 JB |
1 | /****************************************************************************** |
2 | * | |
3 | * This file is provided under a dual BSD/GPLv2 license. When using or | |
4 | * redistributing this file, you may do so under either license. | |
5 | * | |
6 | * GPL LICENSE SUMMARY | |
7 | * | |
51368bf7 | 8 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
8ca151b5 JB |
9 | * |
10 | * This program is free software; you can redistribute it and/or modify | |
11 | * it under the terms of version 2 of the GNU General Public License as | |
12 | * published by the Free Software Foundation. | |
13 | * | |
14 | * This program is distributed in the hope that it will be useful, but | |
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
17 | * General Public License for more details. | |
18 | * | |
19 | * You should have received a copy of the GNU General Public License | |
20 | * along with this program; if not, write to the Free Software | |
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, | |
22 | * USA | |
23 | * | |
24 | * The full GNU General Public License is included in this distribution | |
410dc5aa | 25 | * in the file called COPYING. |
8ca151b5 JB |
26 | * |
27 | * Contact Information: | |
28 | * Intel Linux Wireless <ilw@linux.intel.com> | |
29 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 | |
30 | * | |
31 | * BSD LICENSE | |
32 | * | |
51368bf7 | 33 | * Copyright(c) 2012 - 2014 Intel Corporation. All rights reserved. |
8ca151b5 JB |
34 | * All rights reserved. |
35 | * | |
36 | * Redistribution and use in source and binary forms, with or without | |
37 | * modification, are permitted provided that the following conditions | |
38 | * are met: | |
39 | * | |
40 | * * Redistributions of source code must retain the above copyright | |
41 | * notice, this list of conditions and the following disclaimer. | |
42 | * * Redistributions in binary form must reproduce the above copyright | |
43 | * notice, this list of conditions and the following disclaimer in | |
44 | * the documentation and/or other materials provided with the | |
45 | * distribution. | |
46 | * * Neither the name Intel Corporation nor the names of its | |
47 | * contributors may be used to endorse or promote products derived | |
48 | * from this software without specific prior written permission. | |
49 | * | |
50 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
51 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
52 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
53 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
54 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
55 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
56 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
57 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
58 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
59 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
60 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
61 | * | |
62 | *****************************************************************************/ | |
63 | #include <net/mac80211.h> | |
64 | ||
65 | #include "mvm.h" | |
66 | #include "sta.h" | |
9ee718aa | 67 | #include "rs.h" |
8ca151b5 | 68 | |
3e56eadf | 69 | static void iwl_mvm_add_sta_cmd_v7_to_v5(struct iwl_mvm_add_sta_cmd_v7 *cmd_v7, |
5a258aae MS |
70 | struct iwl_mvm_add_sta_cmd_v5 *cmd_v5) |
71 | { | |
72 | memset(cmd_v5, 0, sizeof(*cmd_v5)); | |
73 | ||
3e56eadf JB |
74 | cmd_v5->add_modify = cmd_v7->add_modify; |
75 | cmd_v5->tid_disable_tx = cmd_v7->tid_disable_tx; | |
76 | cmd_v5->mac_id_n_color = cmd_v7->mac_id_n_color; | |
77 | memcpy(cmd_v5->addr, cmd_v7->addr, ETH_ALEN); | |
78 | cmd_v5->sta_id = cmd_v7->sta_id; | |
79 | cmd_v5->modify_mask = cmd_v7->modify_mask; | |
80 | cmd_v5->station_flags = cmd_v7->station_flags; | |
81 | cmd_v5->station_flags_msk = cmd_v7->station_flags_msk; | |
82 | cmd_v5->add_immediate_ba_tid = cmd_v7->add_immediate_ba_tid; | |
83 | cmd_v5->remove_immediate_ba_tid = cmd_v7->remove_immediate_ba_tid; | |
84 | cmd_v5->add_immediate_ba_ssn = cmd_v7->add_immediate_ba_ssn; | |
85 | cmd_v5->sleep_tx_count = cmd_v7->sleep_tx_count; | |
86 | cmd_v5->sleep_state_flags = cmd_v7->sleep_state_flags; | |
87 | cmd_v5->assoc_id = cmd_v7->assoc_id; | |
88 | cmd_v5->beamform_flags = cmd_v7->beamform_flags; | |
89 | cmd_v5->tfd_queue_msk = cmd_v7->tfd_queue_msk; | |
5a258aae MS |
90 | } |
91 | ||
92 | static void | |
93 | iwl_mvm_add_sta_key_to_add_sta_cmd_v5(struct iwl_mvm_add_sta_key_cmd *key_cmd, | |
94 | struct iwl_mvm_add_sta_cmd_v5 *sta_cmd, | |
95 | u32 mac_id_n_color) | |
96 | { | |
97 | memset(sta_cmd, 0, sizeof(*sta_cmd)); | |
98 | ||
99 | sta_cmd->sta_id = key_cmd->sta_id; | |
100 | sta_cmd->add_modify = STA_MODE_MODIFY; | |
101 | sta_cmd->modify_mask = STA_MODIFY_KEY; | |
102 | sta_cmd->mac_id_n_color = cpu_to_le32(mac_id_n_color); | |
103 | ||
104 | sta_cmd->key.key_offset = key_cmd->key_offset; | |
105 | sta_cmd->key.key_flags = key_cmd->key_flags; | |
106 | memcpy(sta_cmd->key.key, key_cmd->key, sizeof(sta_cmd->key.key)); | |
107 | sta_cmd->key.tkip_rx_tsc_byte2 = key_cmd->tkip_rx_tsc_byte2; | |
108 | memcpy(sta_cmd->key.tkip_rx_ttak, key_cmd->tkip_rx_ttak, | |
109 | sizeof(sta_cmd->key.tkip_rx_ttak)); | |
110 | } | |
111 | ||
112 | static int iwl_mvm_send_add_sta_cmd_status(struct iwl_mvm *mvm, | |
3e56eadf | 113 | struct iwl_mvm_add_sta_cmd_v7 *cmd, |
5a258aae MS |
114 | int *status) |
115 | { | |
116 | struct iwl_mvm_add_sta_cmd_v5 cmd_v5; | |
117 | ||
118 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_STA_KEY_CMD) | |
119 | return iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, sizeof(*cmd), | |
120 | cmd, status); | |
121 | ||
3e56eadf | 122 | iwl_mvm_add_sta_cmd_v7_to_v5(cmd, &cmd_v5); |
5a258aae MS |
123 | |
124 | return iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, sizeof(cmd_v5), | |
125 | &cmd_v5, status); | |
126 | } | |
127 | ||
128 | static int iwl_mvm_send_add_sta_cmd(struct iwl_mvm *mvm, u32 flags, | |
3e56eadf | 129 | struct iwl_mvm_add_sta_cmd_v7 *cmd) |
5a258aae MS |
130 | { |
131 | struct iwl_mvm_add_sta_cmd_v5 cmd_v5; | |
132 | ||
133 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_STA_KEY_CMD) | |
134 | return iwl_mvm_send_cmd_pdu(mvm, ADD_STA, flags, | |
135 | sizeof(*cmd), cmd); | |
136 | ||
3e56eadf | 137 | iwl_mvm_add_sta_cmd_v7_to_v5(cmd, &cmd_v5); |
5a258aae MS |
138 | |
139 | return iwl_mvm_send_cmd_pdu(mvm, ADD_STA, flags, sizeof(cmd_v5), | |
140 | &cmd_v5); | |
141 | } | |
142 | ||
143 | static int | |
144 | iwl_mvm_send_add_sta_key_cmd_status(struct iwl_mvm *mvm, | |
145 | struct iwl_mvm_add_sta_key_cmd *cmd, | |
146 | u32 mac_id_n_color, | |
147 | int *status) | |
148 | { | |
149 | struct iwl_mvm_add_sta_cmd_v5 sta_cmd; | |
150 | ||
151 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_STA_KEY_CMD) | |
152 | return iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, | |
153 | sizeof(*cmd), cmd, status); | |
154 | ||
155 | iwl_mvm_add_sta_key_to_add_sta_cmd_v5(cmd, &sta_cmd, mac_id_n_color); | |
156 | ||
157 | return iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, sizeof(sta_cmd), | |
158 | &sta_cmd, status); | |
159 | } | |
160 | ||
161 | static int iwl_mvm_send_add_sta_key_cmd(struct iwl_mvm *mvm, | |
162 | u32 flags, | |
163 | struct iwl_mvm_add_sta_key_cmd *cmd, | |
164 | u32 mac_id_n_color) | |
165 | { | |
166 | struct iwl_mvm_add_sta_cmd_v5 sta_cmd; | |
167 | ||
168 | if (mvm->fw->ucode_capa.flags & IWL_UCODE_TLV_FLAGS_STA_KEY_CMD) | |
169 | return iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, flags, | |
170 | sizeof(*cmd), cmd); | |
171 | ||
172 | iwl_mvm_add_sta_key_to_add_sta_cmd_v5(cmd, &sta_cmd, mac_id_n_color); | |
173 | ||
174 | return iwl_mvm_send_cmd_pdu(mvm, ADD_STA, flags, sizeof(sta_cmd), | |
175 | &sta_cmd); | |
176 | } | |
177 | ||
8ca151b5 JB |
178 | static int iwl_mvm_find_free_sta_id(struct iwl_mvm *mvm) |
179 | { | |
180 | int sta_id; | |
181 | ||
182 | WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)); | |
183 | ||
184 | lockdep_assert_held(&mvm->mutex); | |
185 | ||
186 | /* Don't take rcu_read_lock() since we are protected by mvm->mutex */ | |
187 | for (sta_id = 0; sta_id < IWL_MVM_STATION_COUNT; sta_id++) | |
188 | if (!rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], | |
189 | lockdep_is_held(&mvm->mutex))) | |
190 | return sta_id; | |
191 | return IWL_MVM_STATION_COUNT; | |
192 | } | |
193 | ||
7a453973 JB |
194 | /* send station add/update command to firmware */ |
195 | int iwl_mvm_sta_send_to_fw(struct iwl_mvm *mvm, struct ieee80211_sta *sta, | |
196 | bool update) | |
8ca151b5 JB |
197 | { |
198 | struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv; | |
3e56eadf | 199 | struct iwl_mvm_add_sta_cmd_v7 add_sta_cmd; |
8ca151b5 JB |
200 | int ret; |
201 | u32 status; | |
202 | u32 agg_size = 0, mpdu_dens = 0; | |
203 | ||
204 | memset(&add_sta_cmd, 0, sizeof(add_sta_cmd)); | |
205 | ||
206 | add_sta_cmd.sta_id = mvm_sta->sta_id; | |
207 | add_sta_cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); | |
7a453973 JB |
208 | if (!update) { |
209 | add_sta_cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk); | |
210 | memcpy(&add_sta_cmd.addr, sta->addr, ETH_ALEN); | |
211 | } | |
212 | add_sta_cmd.add_modify = update ? 1 : 0; | |
8ca151b5 | 213 | |
5bc5aaad JB |
214 | add_sta_cmd.station_flags_msk |= cpu_to_le32(STA_FLG_FAT_EN_MSK | |
215 | STA_FLG_MIMO_EN_MSK); | |
216 | ||
217 | switch (sta->bandwidth) { | |
218 | case IEEE80211_STA_RX_BW_160: | |
219 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_160MHZ); | |
220 | /* fall through */ | |
221 | case IEEE80211_STA_RX_BW_80: | |
222 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_80MHZ); | |
223 | /* fall through */ | |
224 | case IEEE80211_STA_RX_BW_40: | |
225 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_40MHZ); | |
226 | /* fall through */ | |
227 | case IEEE80211_STA_RX_BW_20: | |
228 | if (sta->ht_cap.ht_supported) | |
229 | add_sta_cmd.station_flags |= | |
230 | cpu_to_le32(STA_FLG_FAT_EN_20MHZ); | |
231 | break; | |
232 | } | |
233 | ||
234 | switch (sta->rx_nss) { | |
235 | case 1: | |
236 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO); | |
237 | break; | |
238 | case 2: | |
239 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO2); | |
240 | break; | |
241 | case 3 ... 8: | |
242 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO3); | |
243 | break; | |
244 | } | |
245 | ||
246 | switch (sta->smps_mode) { | |
247 | case IEEE80211_SMPS_AUTOMATIC: | |
248 | case IEEE80211_SMPS_NUM_MODES: | |
249 | WARN_ON(1); | |
250 | break; | |
251 | case IEEE80211_SMPS_STATIC: | |
252 | /* override NSS */ | |
253 | add_sta_cmd.station_flags &= ~cpu_to_le32(STA_FLG_MIMO_EN_MSK); | |
254 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO); | |
255 | break; | |
256 | case IEEE80211_SMPS_DYNAMIC: | |
257 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_RTS_MIMO_PROT); | |
258 | break; | |
259 | case IEEE80211_SMPS_OFF: | |
260 | /* nothing */ | |
261 | break; | |
262 | } | |
8ca151b5 JB |
263 | |
264 | if (sta->ht_cap.ht_supported) { | |
265 | add_sta_cmd.station_flags_msk |= | |
266 | cpu_to_le32(STA_FLG_MAX_AGG_SIZE_MSK | | |
267 | STA_FLG_AGG_MPDU_DENS_MSK); | |
268 | ||
269 | mpdu_dens = sta->ht_cap.ampdu_density; | |
270 | } | |
271 | ||
272 | if (sta->vht_cap.vht_supported) { | |
273 | agg_size = sta->vht_cap.cap & | |
274 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; | |
275 | agg_size >>= | |
276 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; | |
277 | } else if (sta->ht_cap.ht_supported) { | |
278 | agg_size = sta->ht_cap.ampdu_factor; | |
279 | } | |
280 | ||
281 | add_sta_cmd.station_flags |= | |
282 | cpu_to_le32(agg_size << STA_FLG_MAX_AGG_SIZE_SHIFT); | |
283 | add_sta_cmd.station_flags |= | |
284 | cpu_to_le32(mpdu_dens << STA_FLG_AGG_MPDU_DENS_SHIFT); | |
285 | ||
286 | status = ADD_STA_SUCCESS; | |
5a258aae | 287 | ret = iwl_mvm_send_add_sta_cmd_status(mvm, &add_sta_cmd, &status); |
8ca151b5 JB |
288 | if (ret) |
289 | return ret; | |
290 | ||
291 | switch (status) { | |
292 | case ADD_STA_SUCCESS: | |
293 | IWL_DEBUG_ASSOC(mvm, "ADD_STA PASSED\n"); | |
294 | break; | |
295 | default: | |
296 | ret = -EIO; | |
297 | IWL_ERR(mvm, "ADD_STA failed\n"); | |
298 | break; | |
299 | } | |
300 | ||
301 | return ret; | |
302 | } | |
303 | ||
304 | int iwl_mvm_add_sta(struct iwl_mvm *mvm, | |
305 | struct ieee80211_vif *vif, | |
306 | struct ieee80211_sta *sta) | |
307 | { | |
308 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
309 | struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv; | |
310 | int i, ret, sta_id; | |
311 | ||
312 | lockdep_assert_held(&mvm->mutex); | |
313 | ||
314 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) | |
315 | sta_id = iwl_mvm_find_free_sta_id(mvm); | |
316 | else | |
317 | sta_id = mvm_sta->sta_id; | |
318 | ||
319 | if (WARN_ON_ONCE(sta_id == IWL_MVM_STATION_COUNT)) | |
320 | return -ENOSPC; | |
321 | ||
322 | spin_lock_init(&mvm_sta->lock); | |
323 | ||
324 | mvm_sta->sta_id = sta_id; | |
325 | mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id, | |
326 | mvmvif->color); | |
327 | mvm_sta->vif = vif; | |
328 | mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF; | |
9ee718aa EL |
329 | mvm_sta->tx_protection = 0; |
330 | mvm_sta->tt_tx_protection = false; | |
8ca151b5 JB |
331 | |
332 | /* HW restart, don't assume the memory has been zeroed */ | |
e3d4bc8c | 333 | atomic_set(&mvm->pending_frames[sta_id], 0); |
8ca151b5 JB |
334 | mvm_sta->tid_disable_agg = 0; |
335 | mvm_sta->tfd_queue_msk = 0; | |
336 | for (i = 0; i < IEEE80211_NUM_ACS; i++) | |
337 | if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE) | |
338 | mvm_sta->tfd_queue_msk |= BIT(vif->hw_queue[i]); | |
339 | ||
6d9d32b8 JB |
340 | /* for HW restart - reset everything but the sequence number */ |
341 | for (i = 0; i < IWL_MAX_TID_COUNT; i++) { | |
342 | u16 seq = mvm_sta->tid_data[i].seq_number; | |
343 | memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i])); | |
344 | mvm_sta->tid_data[i].seq_number = seq; | |
345 | } | |
8ca151b5 | 346 | |
7a453973 | 347 | ret = iwl_mvm_sta_send_to_fw(mvm, sta, false); |
8ca151b5 JB |
348 | if (ret) |
349 | return ret; | |
350 | ||
351 | /* The first station added is the AP, the others are TDLS STAs */ | |
352 | if (vif->type == NL80211_IFTYPE_STATION && | |
353 | mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT) | |
354 | mvmvif->ap_sta_id = sta_id; | |
355 | ||
356 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta); | |
357 | ||
358 | return 0; | |
359 | } | |
360 | ||
7a453973 JB |
361 | int iwl_mvm_update_sta(struct iwl_mvm *mvm, |
362 | struct ieee80211_vif *vif, | |
363 | struct ieee80211_sta *sta) | |
364 | { | |
365 | return iwl_mvm_sta_send_to_fw(mvm, sta, true); | |
366 | } | |
367 | ||
8ca151b5 JB |
368 | int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta, |
369 | bool drain) | |
370 | { | |
3e56eadf | 371 | struct iwl_mvm_add_sta_cmd_v7 cmd = {}; |
8ca151b5 JB |
372 | int ret; |
373 | u32 status; | |
374 | ||
375 | lockdep_assert_held(&mvm->mutex); | |
376 | ||
377 | cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color); | |
378 | cmd.sta_id = mvmsta->sta_id; | |
379 | cmd.add_modify = STA_MODE_MODIFY; | |
380 | cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0; | |
381 | cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW); | |
382 | ||
383 | status = ADD_STA_SUCCESS; | |
5a258aae | 384 | ret = iwl_mvm_send_add_sta_cmd_status(mvm, &cmd, &status); |
8ca151b5 JB |
385 | if (ret) |
386 | return ret; | |
387 | ||
388 | switch (status) { | |
389 | case ADD_STA_SUCCESS: | |
390 | IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n", | |
391 | mvmsta->sta_id); | |
392 | break; | |
393 | default: | |
394 | ret = -EIO; | |
395 | IWL_ERR(mvm, "Couldn't drain frames for staid %d\n", | |
396 | mvmsta->sta_id); | |
397 | break; | |
398 | } | |
399 | ||
400 | return ret; | |
401 | } | |
402 | ||
403 | /* | |
404 | * Remove a station from the FW table. Before sending the command to remove | |
405 | * the station validate that the station is indeed known to the driver (sanity | |
406 | * only). | |
407 | */ | |
408 | static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id) | |
409 | { | |
410 | struct ieee80211_sta *sta; | |
411 | struct iwl_mvm_rm_sta_cmd rm_sta_cmd = { | |
412 | .sta_id = sta_id, | |
413 | }; | |
414 | int ret; | |
415 | ||
416 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], | |
417 | lockdep_is_held(&mvm->mutex)); | |
418 | ||
419 | /* Note: internal stations are marked as error values */ | |
420 | if (!sta) { | |
421 | IWL_ERR(mvm, "Invalid station id\n"); | |
422 | return -EINVAL; | |
423 | } | |
424 | ||
425 | ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, CMD_SYNC, | |
426 | sizeof(rm_sta_cmd), &rm_sta_cmd); | |
427 | if (ret) { | |
428 | IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id); | |
429 | return ret; | |
430 | } | |
431 | ||
432 | return 0; | |
433 | } | |
434 | ||
435 | void iwl_mvm_sta_drained_wk(struct work_struct *wk) | |
436 | { | |
437 | struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, sta_drained_wk); | |
438 | u8 sta_id; | |
439 | ||
440 | /* | |
441 | * The mutex is needed because of the SYNC cmd, but not only: if the | |
442 | * work would run concurrently with iwl_mvm_rm_sta, it would run before | |
443 | * iwl_mvm_rm_sta sets the station as busy, and exit. Then | |
444 | * iwl_mvm_rm_sta would set the station as busy, and nobody will clean | |
445 | * that later. | |
446 | */ | |
447 | mutex_lock(&mvm->mutex); | |
448 | ||
449 | for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT) { | |
450 | int ret; | |
451 | struct ieee80211_sta *sta = | |
452 | rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], | |
453 | lockdep_is_held(&mvm->mutex)); | |
454 | ||
1ddbbb0c JB |
455 | /* |
456 | * This station is in use or RCU-removed; the latter happens in | |
457 | * managed mode, where mac80211 removes the station before we | |
458 | * can remove it from firmware (we can only do that after the | |
459 | * MAC is marked unassociated), and possibly while the deauth | |
460 | * frame to disconnect from the AP is still queued. Then, the | |
461 | * station pointer is -ENOENT when the last skb is reclaimed. | |
462 | */ | |
463 | if (!IS_ERR(sta) || PTR_ERR(sta) == -ENOENT) | |
8ca151b5 JB |
464 | continue; |
465 | ||
466 | if (PTR_ERR(sta) == -EINVAL) { | |
467 | IWL_ERR(mvm, "Drained sta %d, but it is internal?\n", | |
468 | sta_id); | |
469 | continue; | |
470 | } | |
471 | ||
472 | if (!sta) { | |
473 | IWL_ERR(mvm, "Drained sta %d, but it was NULL?\n", | |
474 | sta_id); | |
475 | continue; | |
476 | } | |
477 | ||
478 | WARN_ON(PTR_ERR(sta) != -EBUSY); | |
479 | /* This station was removed and we waited until it got drained, | |
480 | * we can now proceed and remove it. | |
481 | */ | |
482 | ret = iwl_mvm_rm_sta_common(mvm, sta_id); | |
483 | if (ret) { | |
484 | IWL_ERR(mvm, | |
485 | "Couldn't remove sta %d after it was drained\n", | |
486 | sta_id); | |
487 | continue; | |
488 | } | |
489 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], NULL); | |
490 | clear_bit(sta_id, mvm->sta_drained); | |
491 | } | |
492 | ||
493 | mutex_unlock(&mvm->mutex); | |
494 | } | |
495 | ||
496 | int iwl_mvm_rm_sta(struct iwl_mvm *mvm, | |
497 | struct ieee80211_vif *vif, | |
498 | struct ieee80211_sta *sta) | |
499 | { | |
500 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
501 | struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv; | |
502 | int ret; | |
503 | ||
504 | lockdep_assert_held(&mvm->mutex); | |
505 | ||
506 | if (vif->type == NL80211_IFTYPE_STATION && | |
507 | mvmvif->ap_sta_id == mvm_sta->sta_id) { | |
80d85655 EG |
508 | /* flush its queues here since we are freeing mvm_sta */ |
509 | ret = iwl_mvm_flush_tx_path(mvm, mvm_sta->tfd_queue_msk, true); | |
510 | ||
8ca151b5 JB |
511 | /* |
512 | * Put a non-NULL since the fw station isn't removed. | |
513 | * It will be removed after the MAC will be set as | |
514 | * unassoc. | |
515 | */ | |
516 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], | |
517 | ERR_PTR(-EINVAL)); | |
518 | ||
8ca151b5 JB |
519 | /* if we are associated - we can't remove the AP STA now */ |
520 | if (vif->bss_conf.assoc) | |
521 | return ret; | |
522 | ||
523 | /* unassoc - go ahead - remove the AP STA now */ | |
524 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; | |
37577fe2 EP |
525 | |
526 | /* clear d0i3_ap_sta_id if no longer relevant */ | |
527 | if (mvm->d0i3_ap_sta_id == mvm_sta->sta_id) | |
528 | mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT; | |
8ca151b5 JB |
529 | } |
530 | ||
e3d4bc8c EG |
531 | /* |
532 | * Make sure that the tx response code sees the station as -EBUSY and | |
533 | * calls the drain worker. | |
534 | */ | |
535 | spin_lock_bh(&mvm_sta->lock); | |
8ca151b5 JB |
536 | /* |
537 | * There are frames pending on the AC queues for this station. | |
538 | * We need to wait until all the frames are drained... | |
539 | */ | |
e3d4bc8c | 540 | if (atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) { |
8ca151b5 JB |
541 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], |
542 | ERR_PTR(-EBUSY)); | |
e3d4bc8c EG |
543 | spin_unlock_bh(&mvm_sta->lock); |
544 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, true); | |
8ca151b5 | 545 | } else { |
e3d4bc8c | 546 | spin_unlock_bh(&mvm_sta->lock); |
8ca151b5 JB |
547 | ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id); |
548 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], NULL); | |
549 | } | |
550 | ||
551 | return ret; | |
552 | } | |
553 | ||
554 | int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm, | |
555 | struct ieee80211_vif *vif, | |
556 | u8 sta_id) | |
557 | { | |
558 | int ret = iwl_mvm_rm_sta_common(mvm, sta_id); | |
559 | ||
560 | lockdep_assert_held(&mvm->mutex); | |
561 | ||
562 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], NULL); | |
563 | return ret; | |
564 | } | |
565 | ||
566 | int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm, struct iwl_mvm_int_sta *sta, | |
567 | u32 qmask) | |
568 | { | |
569 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { | |
570 | sta->sta_id = iwl_mvm_find_free_sta_id(mvm); | |
571 | if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_STATION_COUNT)) | |
572 | return -ENOSPC; | |
573 | } | |
574 | ||
575 | sta->tfd_queue_msk = qmask; | |
576 | ||
577 | /* put a non-NULL value so iterating over the stations won't stop */ | |
578 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL)); | |
579 | return 0; | |
580 | } | |
581 | ||
582 | void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm, struct iwl_mvm_int_sta *sta) | |
583 | { | |
584 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], NULL); | |
585 | memset(sta, 0, sizeof(struct iwl_mvm_int_sta)); | |
586 | sta->sta_id = IWL_MVM_STATION_COUNT; | |
587 | } | |
588 | ||
589 | static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm, | |
590 | struct iwl_mvm_int_sta *sta, | |
591 | const u8 *addr, | |
592 | u16 mac_id, u16 color) | |
593 | { | |
3e56eadf | 594 | struct iwl_mvm_add_sta_cmd_v7 cmd; |
8ca151b5 JB |
595 | int ret; |
596 | u32 status; | |
597 | ||
598 | lockdep_assert_held(&mvm->mutex); | |
599 | ||
3e56eadf | 600 | memset(&cmd, 0, sizeof(struct iwl_mvm_add_sta_cmd_v7)); |
8ca151b5 JB |
601 | cmd.sta_id = sta->sta_id; |
602 | cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id, | |
603 | color)); | |
604 | ||
605 | cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk); | |
606 | ||
607 | if (addr) | |
608 | memcpy(cmd.addr, addr, ETH_ALEN); | |
609 | ||
5a258aae | 610 | ret = iwl_mvm_send_add_sta_cmd_status(mvm, &cmd, &status); |
8ca151b5 JB |
611 | if (ret) |
612 | return ret; | |
613 | ||
614 | switch (status) { | |
615 | case ADD_STA_SUCCESS: | |
616 | IWL_DEBUG_INFO(mvm, "Internal station added.\n"); | |
617 | return 0; | |
618 | default: | |
619 | ret = -EIO; | |
620 | IWL_ERR(mvm, "Add internal station failed, status=0x%x\n", | |
621 | status); | |
622 | break; | |
623 | } | |
624 | return ret; | |
625 | } | |
626 | ||
627 | int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm) | |
628 | { | |
629 | int ret; | |
630 | ||
631 | lockdep_assert_held(&mvm->mutex); | |
632 | ||
633 | /* Add the aux station, but without any queues */ | |
634 | ret = iwl_mvm_allocate_int_sta(mvm, &mvm->aux_sta, 0); | |
635 | if (ret) | |
636 | return ret; | |
637 | ||
638 | ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL, | |
639 | MAC_INDEX_AUX, 0); | |
640 | ||
641 | if (ret) | |
642 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); | |
643 | return ret; | |
644 | } | |
645 | ||
646 | /* | |
647 | * Send the add station command for the vif's broadcast station. | |
648 | * Assumes that the station was already allocated. | |
649 | * | |
650 | * @mvm: the mvm component | |
651 | * @vif: the interface to which the broadcast station is added | |
652 | * @bsta: the broadcast station to add. | |
653 | */ | |
654 | int iwl_mvm_send_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif, | |
655 | struct iwl_mvm_int_sta *bsta) | |
656 | { | |
657 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
5023d966 JB |
658 | static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
659 | static const u8 *baddr = _baddr; | |
8ca151b5 JB |
660 | |
661 | lockdep_assert_held(&mvm->mutex); | |
662 | ||
5023d966 JB |
663 | if (vif->type == NL80211_IFTYPE_ADHOC) |
664 | baddr = vif->bss_conf.bssid; | |
665 | ||
8ca151b5 JB |
666 | if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_STATION_COUNT)) |
667 | return -ENOSPC; | |
668 | ||
669 | return iwl_mvm_add_int_sta_common(mvm, bsta, baddr, | |
670 | mvmvif->id, mvmvif->color); | |
671 | } | |
672 | ||
673 | /* Send the FW a request to remove the station from it's internal data | |
674 | * structures, but DO NOT remove the entry from the local data structures. */ | |
675 | int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm *mvm, | |
676 | struct iwl_mvm_int_sta *bsta) | |
677 | { | |
678 | int ret; | |
679 | ||
680 | lockdep_assert_held(&mvm->mutex); | |
681 | ||
682 | ret = iwl_mvm_rm_sta_common(mvm, bsta->sta_id); | |
683 | if (ret) | |
684 | IWL_WARN(mvm, "Failed sending remove station\n"); | |
685 | return ret; | |
686 | } | |
687 | ||
688 | /* Allocate a new station entry for the broadcast station to the given vif, | |
689 | * and send it to the FW. | |
690 | * Note that each P2P mac should have its own broadcast station. | |
691 | * | |
692 | * @mvm: the mvm component | |
693 | * @vif: the interface to which the broadcast station is added | |
694 | * @bsta: the broadcast station to add. */ | |
695 | int iwl_mvm_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif, | |
696 | struct iwl_mvm_int_sta *bsta) | |
697 | { | |
698 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); | |
699 | static const u8 baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; | |
700 | u32 qmask; | |
701 | int ret; | |
702 | ||
703 | lockdep_assert_held(&mvm->mutex); | |
704 | ||
705 | qmask = iwl_mvm_mac_get_queues_mask(mvm, vif); | |
706 | ret = iwl_mvm_allocate_int_sta(mvm, bsta, qmask); | |
707 | if (ret) | |
708 | return ret; | |
709 | ||
710 | ret = iwl_mvm_add_int_sta_common(mvm, bsta, baddr, | |
711 | mvmvif->id, mvmvif->color); | |
712 | ||
713 | if (ret) | |
714 | iwl_mvm_dealloc_int_sta(mvm, bsta); | |
715 | return ret; | |
716 | } | |
717 | ||
718 | /* | |
719 | * Send the FW a request to remove the station from it's internal data | |
720 | * structures, and in addition remove it from the local data structure. | |
721 | */ | |
722 | int iwl_mvm_rm_bcast_sta(struct iwl_mvm *mvm, struct iwl_mvm_int_sta *bsta) | |
723 | { | |
724 | int ret; | |
725 | ||
726 | lockdep_assert_held(&mvm->mutex); | |
727 | ||
728 | ret = iwl_mvm_rm_sta_common(mvm, bsta->sta_id); | |
729 | if (ret) | |
730 | return ret; | |
731 | ||
732 | iwl_mvm_dealloc_int_sta(mvm, bsta); | |
733 | return ret; | |
734 | } | |
735 | ||
113a0447 EG |
736 | #define IWL_MAX_RX_BA_SESSIONS 16 |
737 | ||
8ca151b5 JB |
738 | int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
739 | int tid, u16 ssn, bool start) | |
740 | { | |
741 | struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv; | |
3e56eadf | 742 | struct iwl_mvm_add_sta_cmd_v7 cmd = {}; |
8ca151b5 JB |
743 | int ret; |
744 | u32 status; | |
745 | ||
746 | lockdep_assert_held(&mvm->mutex); | |
747 | ||
113a0447 EG |
748 | if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) { |
749 | IWL_WARN(mvm, "Not enough RX BA SESSIONS\n"); | |
750 | return -ENOSPC; | |
751 | } | |
752 | ||
8ca151b5 JB |
753 | cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); |
754 | cmd.sta_id = mvm_sta->sta_id; | |
755 | cmd.add_modify = STA_MODE_MODIFY; | |
93a42667 EG |
756 | if (start) { |
757 | cmd.add_immediate_ba_tid = (u8) tid; | |
758 | cmd.add_immediate_ba_ssn = cpu_to_le16(ssn); | |
759 | } else { | |
760 | cmd.remove_immediate_ba_tid = (u8) tid; | |
761 | } | |
8ca151b5 JB |
762 | cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID : |
763 | STA_MODIFY_REMOVE_BA_TID; | |
764 | ||
765 | status = ADD_STA_SUCCESS; | |
5a258aae | 766 | ret = iwl_mvm_send_add_sta_cmd_status(mvm, &cmd, &status); |
8ca151b5 JB |
767 | if (ret) |
768 | return ret; | |
769 | ||
770 | switch (status) { | |
771 | case ADD_STA_SUCCESS: | |
772 | IWL_DEBUG_INFO(mvm, "RX BA Session %sed in fw\n", | |
773 | start ? "start" : "stopp"); | |
774 | break; | |
775 | case ADD_STA_IMMEDIATE_BA_FAILURE: | |
776 | IWL_WARN(mvm, "RX BA Session refused by fw\n"); | |
777 | ret = -ENOSPC; | |
778 | break; | |
779 | default: | |
780 | ret = -EIO; | |
781 | IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n", | |
782 | start ? "start" : "stopp", status); | |
783 | break; | |
784 | } | |
785 | ||
113a0447 EG |
786 | if (!ret) { |
787 | if (start) | |
788 | mvm->rx_ba_sessions++; | |
789 | else if (mvm->rx_ba_sessions > 0) | |
790 | /* check that restart flow didn't zero the counter */ | |
791 | mvm->rx_ba_sessions--; | |
792 | } | |
793 | ||
8ca151b5 JB |
794 | return ret; |
795 | } | |
796 | ||
797 | static int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, | |
798 | int tid, u8 queue, bool start) | |
799 | { | |
800 | struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv; | |
3e56eadf | 801 | struct iwl_mvm_add_sta_cmd_v7 cmd = {}; |
8ca151b5 JB |
802 | int ret; |
803 | u32 status; | |
804 | ||
805 | lockdep_assert_held(&mvm->mutex); | |
806 | ||
807 | if (start) { | |
808 | mvm_sta->tfd_queue_msk |= BIT(queue); | |
809 | mvm_sta->tid_disable_agg &= ~BIT(tid); | |
810 | } else { | |
811 | mvm_sta->tfd_queue_msk &= ~BIT(queue); | |
812 | mvm_sta->tid_disable_agg |= BIT(tid); | |
813 | } | |
814 | ||
815 | cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); | |
816 | cmd.sta_id = mvm_sta->sta_id; | |
817 | cmd.add_modify = STA_MODE_MODIFY; | |
818 | cmd.modify_mask = STA_MODIFY_QUEUES | STA_MODIFY_TID_DISABLE_TX; | |
819 | cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk); | |
820 | cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg); | |
821 | ||
822 | status = ADD_STA_SUCCESS; | |
5a258aae | 823 | ret = iwl_mvm_send_add_sta_cmd_status(mvm, &cmd, &status); |
8ca151b5 JB |
824 | if (ret) |
825 | return ret; | |
826 | ||
827 | switch (status) { | |
828 | case ADD_STA_SUCCESS: | |
829 | break; | |
830 | default: | |
831 | ret = -EIO; | |
832 | IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n", | |
833 | start ? "start" : "stopp", status); | |
834 | break; | |
835 | } | |
836 | ||
837 | return ret; | |
838 | } | |
839 | ||
3e56eadf | 840 | static const u8 tid_to_mac80211_ac[] = { |
8ca151b5 JB |
841 | IEEE80211_AC_BE, |
842 | IEEE80211_AC_BK, | |
843 | IEEE80211_AC_BK, | |
844 | IEEE80211_AC_BE, | |
845 | IEEE80211_AC_VI, | |
846 | IEEE80211_AC_VI, | |
847 | IEEE80211_AC_VO, | |
848 | IEEE80211_AC_VO, | |
849 | }; | |
850 | ||
3e56eadf JB |
851 | static const u8 tid_to_ucode_ac[] = { |
852 | AC_BE, | |
853 | AC_BK, | |
854 | AC_BK, | |
855 | AC_BE, | |
856 | AC_VI, | |
857 | AC_VI, | |
858 | AC_VO, | |
859 | AC_VO, | |
860 | }; | |
861 | ||
8ca151b5 JB |
862 | int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
863 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) | |
864 | { | |
5b577a90 | 865 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
8ca151b5 JB |
866 | struct iwl_mvm_tid_data *tid_data; |
867 | int txq_id; | |
868 | ||
869 | if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT)) | |
870 | return -EINVAL; | |
871 | ||
872 | if (mvmsta->tid_data[tid].state != IWL_AGG_OFF) { | |
873 | IWL_ERR(mvm, "Start AGG when state is not IWL_AGG_OFF %d!\n", | |
874 | mvmsta->tid_data[tid].state); | |
875 | return -ENXIO; | |
876 | } | |
877 | ||
878 | lockdep_assert_held(&mvm->mutex); | |
879 | ||
19e737c9 EL |
880 | for (txq_id = mvm->first_agg_queue; |
881 | txq_id <= mvm->last_agg_queue; txq_id++) | |
8ca151b5 JB |
882 | if (mvm->queue_to_mac80211[txq_id] == |
883 | IWL_INVALID_MAC80211_QUEUE) | |
884 | break; | |
885 | ||
19e737c9 | 886 | if (txq_id > mvm->last_agg_queue) { |
8ca151b5 JB |
887 | IWL_ERR(mvm, "Failed to allocate agg queue\n"); |
888 | return -EIO; | |
889 | } | |
890 | ||
891 | /* the new tx queue is still connected to the same mac80211 queue */ | |
3e56eadf | 892 | mvm->queue_to_mac80211[txq_id] = vif->hw_queue[tid_to_mac80211_ac[tid]]; |
8ca151b5 JB |
893 | |
894 | spin_lock_bh(&mvmsta->lock); | |
895 | tid_data = &mvmsta->tid_data[tid]; | |
9a886586 | 896 | tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
8ca151b5 JB |
897 | tid_data->txq_id = txq_id; |
898 | *ssn = tid_data->ssn; | |
899 | ||
900 | IWL_DEBUG_TX_QUEUES(mvm, | |
901 | "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n", | |
902 | mvmsta->sta_id, tid, txq_id, tid_data->ssn, | |
903 | tid_data->next_reclaimed); | |
904 | ||
905 | if (tid_data->ssn == tid_data->next_reclaimed) { | |
906 | tid_data->state = IWL_AGG_STARTING; | |
907 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); | |
908 | } else { | |
909 | tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA; | |
910 | } | |
911 | ||
912 | spin_unlock_bh(&mvmsta->lock); | |
913 | ||
914 | return 0; | |
915 | } | |
916 | ||
917 | int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm *mvm, struct ieee80211_vif *vif, | |
918 | struct ieee80211_sta *sta, u16 tid, u8 buf_size) | |
919 | { | |
5b577a90 | 920 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
8ca151b5 JB |
921 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
922 | int queue, fifo, ret; | |
923 | u16 ssn; | |
924 | ||
925 | buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF); | |
926 | ||
927 | spin_lock_bh(&mvmsta->lock); | |
928 | ssn = tid_data->ssn; | |
929 | queue = tid_data->txq_id; | |
930 | tid_data->state = IWL_AGG_ON; | |
931 | tid_data->ssn = 0xffff; | |
932 | spin_unlock_bh(&mvmsta->lock); | |
933 | ||
3e56eadf | 934 | fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]]; |
8ca151b5 JB |
935 | |
936 | ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true); | |
937 | if (ret) | |
938 | return -EIO; | |
939 | ||
940 | iwl_trans_txq_enable(mvm->trans, queue, fifo, mvmsta->sta_id, tid, | |
941 | buf_size, ssn); | |
942 | ||
943 | /* | |
944 | * Even though in theory the peer could have different | |
945 | * aggregation reorder buffer sizes for different sessions, | |
946 | * our ucode doesn't allow for that and has a global limit | |
947 | * for each station. Therefore, use the minimum of all the | |
948 | * aggregation sessions and our default value. | |
949 | */ | |
950 | mvmsta->max_agg_bufsize = | |
951 | min(mvmsta->max_agg_bufsize, buf_size); | |
952 | mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize; | |
953 | ||
9ee718aa EL |
954 | IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n", |
955 | sta->addr, tid); | |
956 | ||
9e680946 | 957 | return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false); |
8ca151b5 JB |
958 | } |
959 | ||
960 | int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif, | |
961 | struct ieee80211_sta *sta, u16 tid) | |
962 | { | |
5b577a90 | 963 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
8ca151b5 JB |
964 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
965 | u16 txq_id; | |
966 | int err; | |
967 | ||
f9aa8dd3 EG |
968 | |
969 | /* | |
970 | * If mac80211 is cleaning its state, then say that we finished since | |
971 | * our state has been cleared anyway. | |
972 | */ | |
973 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { | |
974 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); | |
975 | return 0; | |
976 | } | |
977 | ||
8ca151b5 JB |
978 | spin_lock_bh(&mvmsta->lock); |
979 | ||
980 | txq_id = tid_data->txq_id; | |
981 | ||
982 | IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n", | |
983 | mvmsta->sta_id, tid, txq_id, tid_data->state); | |
984 | ||
985 | switch (tid_data->state) { | |
986 | case IWL_AGG_ON: | |
9a886586 | 987 | tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
8ca151b5 JB |
988 | |
989 | IWL_DEBUG_TX_QUEUES(mvm, | |
990 | "ssn = %d, next_recl = %d\n", | |
991 | tid_data->ssn, tid_data->next_reclaimed); | |
992 | ||
993 | /* There are still packets for this RA / TID in the HW */ | |
994 | if (tid_data->ssn != tid_data->next_reclaimed) { | |
995 | tid_data->state = IWL_EMPTYING_HW_QUEUE_DELBA; | |
996 | err = 0; | |
997 | break; | |
998 | } | |
999 | ||
1000 | tid_data->ssn = 0xffff; | |
1001 | iwl_trans_txq_disable(mvm->trans, txq_id); | |
1002 | /* fall through */ | |
1003 | case IWL_AGG_STARTING: | |
1004 | case IWL_EMPTYING_HW_QUEUE_ADDBA: | |
1005 | /* | |
1006 | * The agg session has been stopped before it was set up. This | |
1007 | * can happen when the AddBA timer times out for example. | |
1008 | */ | |
1009 | ||
1010 | /* No barriers since we are under mutex */ | |
1011 | lockdep_assert_held(&mvm->mutex); | |
1012 | mvm->queue_to_mac80211[txq_id] = IWL_INVALID_MAC80211_QUEUE; | |
1013 | ||
1014 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); | |
1015 | tid_data->state = IWL_AGG_OFF; | |
1016 | err = 0; | |
1017 | break; | |
1018 | default: | |
1019 | IWL_ERR(mvm, | |
1020 | "Stopping AGG while state not ON or starting for %d on %d (%d)\n", | |
1021 | mvmsta->sta_id, tid, tid_data->state); | |
1022 | IWL_ERR(mvm, | |
1023 | "\ttid_data->txq_id = %d\n", tid_data->txq_id); | |
1024 | err = -EINVAL; | |
1025 | } | |
1026 | ||
1027 | spin_unlock_bh(&mvmsta->lock); | |
1028 | ||
1029 | return err; | |
1030 | } | |
1031 | ||
e3d9e7ce EG |
1032 | int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
1033 | struct ieee80211_sta *sta, u16 tid) | |
1034 | { | |
5b577a90 | 1035 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
e3d9e7ce EG |
1036 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
1037 | u16 txq_id; | |
b6658ff8 | 1038 | enum iwl_mvm_agg_state old_state; |
e3d9e7ce EG |
1039 | |
1040 | /* | |
1041 | * First set the agg state to OFF to avoid calling | |
1042 | * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty. | |
1043 | */ | |
1044 | spin_lock_bh(&mvmsta->lock); | |
1045 | txq_id = tid_data->txq_id; | |
1046 | IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n", | |
1047 | mvmsta->sta_id, tid, txq_id, tid_data->state); | |
b6658ff8 | 1048 | old_state = tid_data->state; |
e3d9e7ce EG |
1049 | tid_data->state = IWL_AGG_OFF; |
1050 | spin_unlock_bh(&mvmsta->lock); | |
1051 | ||
b6658ff8 JB |
1052 | if (old_state >= IWL_AGG_ON) { |
1053 | if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), true)) | |
1054 | IWL_ERR(mvm, "Couldn't flush the AGG queue\n"); | |
1055 | ||
1056 | iwl_trans_txq_disable(mvm->trans, tid_data->txq_id); | |
1057 | } | |
e3d9e7ce | 1058 | |
e3d9e7ce EG |
1059 | mvm->queue_to_mac80211[tid_data->txq_id] = |
1060 | IWL_INVALID_MAC80211_QUEUE; | |
1061 | ||
1062 | return 0; | |
1063 | } | |
1064 | ||
8ca151b5 JB |
1065 | static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm) |
1066 | { | |
1067 | int i; | |
1068 | ||
1069 | lockdep_assert_held(&mvm->mutex); | |
1070 | ||
1071 | i = find_first_zero_bit(mvm->fw_key_table, STA_KEY_MAX_NUM); | |
1072 | ||
1073 | if (i == STA_KEY_MAX_NUM) | |
1074 | return STA_KEY_IDX_INVALID; | |
1075 | ||
1076 | __set_bit(i, mvm->fw_key_table); | |
1077 | ||
1078 | return i; | |
1079 | } | |
1080 | ||
1081 | static u8 iwl_mvm_get_key_sta_id(struct ieee80211_vif *vif, | |
1082 | struct ieee80211_sta *sta) | |
1083 | { | |
1084 | struct iwl_mvm_vif *mvmvif = (void *)vif->drv_priv; | |
1085 | ||
1086 | if (sta) { | |
1087 | struct iwl_mvm_sta *mvm_sta = (void *)sta->drv_priv; | |
1088 | ||
1089 | return mvm_sta->sta_id; | |
1090 | } | |
1091 | ||
1092 | /* | |
1093 | * The device expects GTKs for station interfaces to be | |
1094 | * installed as GTKs for the AP station. If we have no | |
1095 | * station ID, then use AP's station ID. | |
1096 | */ | |
1097 | if (vif->type == NL80211_IFTYPE_STATION && | |
1098 | mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) | |
1099 | return mvmvif->ap_sta_id; | |
1100 | ||
881acd89 | 1101 | return IWL_MVM_STATION_COUNT; |
8ca151b5 JB |
1102 | } |
1103 | ||
1104 | static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm, | |
1105 | struct iwl_mvm_sta *mvm_sta, | |
1106 | struct ieee80211_key_conf *keyconf, | |
1107 | u8 sta_id, u32 tkip_iv32, u16 *tkip_p1k, | |
1108 | u32 cmd_flags) | |
1109 | { | |
1110 | __le16 key_flags; | |
5a258aae | 1111 | struct iwl_mvm_add_sta_key_cmd cmd = {}; |
8ca151b5 JB |
1112 | int ret, status; |
1113 | u16 keyidx; | |
1114 | int i; | |
5a258aae | 1115 | u32 mac_id_n_color = mvm_sta->mac_id_n_color; |
8ca151b5 JB |
1116 | |
1117 | keyidx = (keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & | |
1118 | STA_KEY_FLG_KEYID_MSK; | |
1119 | key_flags = cpu_to_le16(keyidx); | |
1120 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP); | |
1121 | ||
1122 | switch (keyconf->cipher) { | |
1123 | case WLAN_CIPHER_SUITE_TKIP: | |
1124 | key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP); | |
5a258aae | 1125 | cmd.tkip_rx_tsc_byte2 = tkip_iv32; |
8ca151b5 | 1126 | for (i = 0; i < 5; i++) |
5a258aae MS |
1127 | cmd.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]); |
1128 | memcpy(cmd.key, keyconf->key, keyconf->keylen); | |
8ca151b5 JB |
1129 | break; |
1130 | case WLAN_CIPHER_SUITE_CCMP: | |
1131 | key_flags |= cpu_to_le16(STA_KEY_FLG_CCM); | |
5a258aae | 1132 | memcpy(cmd.key, keyconf->key, keyconf->keylen); |
8ca151b5 JB |
1133 | break; |
1134 | default: | |
e36e5433 MS |
1135 | key_flags |= cpu_to_le16(STA_KEY_FLG_EXT); |
1136 | memcpy(cmd.key, keyconf->key, keyconf->keylen); | |
8ca151b5 JB |
1137 | } |
1138 | ||
1139 | if (!(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE)) | |
1140 | key_flags |= cpu_to_le16(STA_KEY_MULTICAST); | |
1141 | ||
5a258aae MS |
1142 | cmd.key_offset = keyconf->hw_key_idx; |
1143 | cmd.key_flags = key_flags; | |
8ca151b5 JB |
1144 | cmd.sta_id = sta_id; |
1145 | ||
1146 | status = ADD_STA_SUCCESS; | |
1147 | if (cmd_flags == CMD_SYNC) | |
5a258aae MS |
1148 | ret = iwl_mvm_send_add_sta_key_cmd_status(mvm, &cmd, |
1149 | mac_id_n_color, | |
1150 | &status); | |
8ca151b5 | 1151 | else |
5a258aae MS |
1152 | ret = iwl_mvm_send_add_sta_key_cmd(mvm, CMD_ASYNC, &cmd, |
1153 | mac_id_n_color); | |
8ca151b5 JB |
1154 | |
1155 | switch (status) { | |
1156 | case ADD_STA_SUCCESS: | |
1157 | IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n"); | |
1158 | break; | |
1159 | default: | |
1160 | ret = -EIO; | |
1161 | IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n"); | |
1162 | break; | |
1163 | } | |
1164 | ||
1165 | return ret; | |
1166 | } | |
1167 | ||
1168 | static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm, | |
1169 | struct ieee80211_key_conf *keyconf, | |
1170 | u8 sta_id, bool remove_key) | |
1171 | { | |
1172 | struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {}; | |
1173 | ||
1174 | /* verify the key details match the required command's expectations */ | |
1175 | if (WARN_ON((keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC) || | |
1176 | (keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) || | |
1177 | (keyconf->keyidx != 4 && keyconf->keyidx != 5))) | |
1178 | return -EINVAL; | |
1179 | ||
1180 | igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx); | |
1181 | igtk_cmd.sta_id = cpu_to_le32(sta_id); | |
1182 | ||
1183 | if (remove_key) { | |
1184 | igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID); | |
1185 | } else { | |
1186 | struct ieee80211_key_seq seq; | |
1187 | const u8 *pn; | |
1188 | ||
1189 | memcpy(igtk_cmd.IGTK, keyconf->key, keyconf->keylen); | |
1190 | ieee80211_aes_cmac_calculate_k1_k2(keyconf, | |
1191 | igtk_cmd.K1, igtk_cmd.K2); | |
1192 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); | |
1193 | pn = seq.aes_cmac.pn; | |
1194 | igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) | | |
1195 | ((u64) pn[4] << 8) | | |
1196 | ((u64) pn[3] << 16) | | |
1197 | ((u64) pn[2] << 24) | | |
1198 | ((u64) pn[1] << 32) | | |
1199 | ((u64) pn[0] << 40)); | |
1200 | } | |
1201 | ||
1202 | IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n", | |
1203 | remove_key ? "removing" : "installing", | |
1204 | igtk_cmd.sta_id); | |
1205 | ||
1206 | return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, CMD_SYNC, | |
1207 | sizeof(igtk_cmd), &igtk_cmd); | |
1208 | } | |
1209 | ||
1210 | ||
1211 | static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm, | |
1212 | struct ieee80211_vif *vif, | |
1213 | struct ieee80211_sta *sta) | |
1214 | { | |
1215 | struct iwl_mvm_vif *mvmvif = (void *)vif->drv_priv; | |
1216 | ||
1217 | if (sta) | |
1218 | return sta->addr; | |
1219 | ||
1220 | if (vif->type == NL80211_IFTYPE_STATION && | |
1221 | mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { | |
1222 | u8 sta_id = mvmvif->ap_sta_id; | |
1223 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], | |
1224 | lockdep_is_held(&mvm->mutex)); | |
1225 | return sta->addr; | |
1226 | } | |
1227 | ||
1228 | ||
1229 | return NULL; | |
1230 | } | |
1231 | ||
1232 | int iwl_mvm_set_sta_key(struct iwl_mvm *mvm, | |
1233 | struct ieee80211_vif *vif, | |
1234 | struct ieee80211_sta *sta, | |
1235 | struct ieee80211_key_conf *keyconf, | |
1236 | bool have_key_offset) | |
1237 | { | |
1238 | struct iwl_mvm_sta *mvm_sta; | |
1239 | int ret; | |
1240 | u8 *addr, sta_id; | |
1241 | struct ieee80211_key_seq seq; | |
1242 | u16 p1k[5]; | |
1243 | ||
1244 | lockdep_assert_held(&mvm->mutex); | |
1245 | ||
1246 | /* Get the station id from the mvm local station table */ | |
1247 | sta_id = iwl_mvm_get_key_sta_id(vif, sta); | |
881acd89 | 1248 | if (sta_id == IWL_MVM_STATION_COUNT) { |
8ca151b5 JB |
1249 | IWL_ERR(mvm, "Failed to find station id\n"); |
1250 | return -EINVAL; | |
1251 | } | |
1252 | ||
1253 | if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC) { | |
1254 | ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, false); | |
1255 | goto end; | |
1256 | } | |
1257 | ||
1258 | /* | |
1259 | * It is possible that the 'sta' parameter is NULL, and thus | |
1260 | * there is a need to retrieve the sta from the local station table. | |
1261 | */ | |
1262 | if (!sta) { | |
1263 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], | |
1264 | lockdep_is_held(&mvm->mutex)); | |
1265 | if (IS_ERR_OR_NULL(sta)) { | |
1266 | IWL_ERR(mvm, "Invalid station id\n"); | |
1267 | return -EINVAL; | |
1268 | } | |
1269 | } | |
1270 | ||
1271 | mvm_sta = (struct iwl_mvm_sta *)sta->drv_priv; | |
1272 | if (WARN_ON_ONCE(mvm_sta->vif != vif)) | |
1273 | return -EINVAL; | |
1274 | ||
1275 | if (!have_key_offset) { | |
1276 | /* | |
1277 | * The D3 firmware hardcodes the PTK offset to 0, so we have to | |
1278 | * configure it there. As a result, this workaround exists to | |
1279 | * let the caller set the key offset (hw_key_idx), see d3.c. | |
1280 | */ | |
1281 | keyconf->hw_key_idx = iwl_mvm_set_fw_key_idx(mvm); | |
1282 | if (keyconf->hw_key_idx == STA_KEY_IDX_INVALID) | |
1283 | return -ENOSPC; | |
1284 | } | |
1285 | ||
1286 | switch (keyconf->cipher) { | |
1287 | case WLAN_CIPHER_SUITE_TKIP: | |
1288 | addr = iwl_mvm_get_mac_addr(mvm, vif, sta); | |
1289 | /* get phase 1 key from mac80211 */ | |
1290 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); | |
1291 | ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k); | |
1292 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, sta_id, | |
1293 | seq.tkip.iv32, p1k, CMD_SYNC); | |
1294 | break; | |
1295 | case WLAN_CIPHER_SUITE_CCMP: | |
1296 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, sta_id, | |
1297 | 0, NULL, CMD_SYNC); | |
1298 | break; | |
1299 | default: | |
e36e5433 MS |
1300 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, |
1301 | sta_id, 0, NULL, CMD_SYNC); | |
8ca151b5 JB |
1302 | } |
1303 | ||
1304 | if (ret) | |
1305 | __clear_bit(keyconf->hw_key_idx, mvm->fw_key_table); | |
1306 | ||
1307 | end: | |
1308 | IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n", | |
1309 | keyconf->cipher, keyconf->keylen, keyconf->keyidx, | |
1310 | sta->addr, ret); | |
1311 | return ret; | |
1312 | } | |
1313 | ||
1314 | int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, | |
1315 | struct ieee80211_vif *vif, | |
1316 | struct ieee80211_sta *sta, | |
1317 | struct ieee80211_key_conf *keyconf) | |
1318 | { | |
1319 | struct iwl_mvm_sta *mvm_sta; | |
5a258aae | 1320 | struct iwl_mvm_add_sta_key_cmd cmd = {}; |
8ca151b5 JB |
1321 | __le16 key_flags; |
1322 | int ret, status; | |
1323 | u8 sta_id; | |
1324 | ||
1325 | lockdep_assert_held(&mvm->mutex); | |
1326 | ||
1327 | /* Get the station id from the mvm local station table */ | |
1328 | sta_id = iwl_mvm_get_key_sta_id(vif, sta); | |
1329 | ||
1330 | IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n", | |
1331 | keyconf->keyidx, sta_id); | |
1332 | ||
1333 | if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC) | |
1334 | return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true); | |
1335 | ||
1336 | ret = __test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table); | |
1337 | if (!ret) { | |
1338 | IWL_ERR(mvm, "offset %d not used in fw key table.\n", | |
1339 | keyconf->hw_key_idx); | |
1340 | return -ENOENT; | |
1341 | } | |
1342 | ||
881acd89 | 1343 | if (sta_id == IWL_MVM_STATION_COUNT) { |
8ca151b5 JB |
1344 | IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n"); |
1345 | return 0; | |
1346 | } | |
1347 | ||
1348 | /* | |
1349 | * It is possible that the 'sta' parameter is NULL, and thus | |
1350 | * there is a need to retrieve the sta from the local station table, | |
1351 | * for example when a GTK is removed (where the sta_id will then be | |
1352 | * the AP ID, and no station was passed by mac80211.) | |
1353 | */ | |
1354 | if (!sta) { | |
1355 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], | |
1356 | lockdep_is_held(&mvm->mutex)); | |
1357 | if (!sta) { | |
1358 | IWL_ERR(mvm, "Invalid station id\n"); | |
1359 | return -EINVAL; | |
1360 | } | |
1361 | } | |
1362 | ||
1363 | mvm_sta = (struct iwl_mvm_sta *)sta->drv_priv; | |
1364 | if (WARN_ON_ONCE(mvm_sta->vif != vif)) | |
1365 | return -EINVAL; | |
1366 | ||
8115efbd EG |
1367 | key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & |
1368 | STA_KEY_FLG_KEYID_MSK); | |
8ca151b5 JB |
1369 | key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP); |
1370 | key_flags |= cpu_to_le16(STA_KEY_NOT_VALID); | |
1371 | ||
1372 | if (!(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE)) | |
1373 | key_flags |= cpu_to_le16(STA_KEY_MULTICAST); | |
1374 | ||
5a258aae MS |
1375 | cmd.key_flags = key_flags; |
1376 | cmd.key_offset = keyconf->hw_key_idx; | |
8ca151b5 JB |
1377 | cmd.sta_id = sta_id; |
1378 | ||
8ca151b5 | 1379 | status = ADD_STA_SUCCESS; |
5a258aae MS |
1380 | ret = iwl_mvm_send_add_sta_key_cmd_status(mvm, &cmd, |
1381 | mvm_sta->mac_id_n_color, | |
1382 | &status); | |
8ca151b5 JB |
1383 | |
1384 | switch (status) { | |
1385 | case ADD_STA_SUCCESS: | |
1386 | IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n"); | |
1387 | break; | |
1388 | default: | |
1389 | ret = -EIO; | |
1390 | IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n"); | |
1391 | break; | |
1392 | } | |
1393 | ||
1394 | return ret; | |
1395 | } | |
1396 | ||
1397 | void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm, | |
1398 | struct ieee80211_vif *vif, | |
1399 | struct ieee80211_key_conf *keyconf, | |
1400 | struct ieee80211_sta *sta, u32 iv32, | |
1401 | u16 *phase1key) | |
1402 | { | |
c3eb536a | 1403 | struct iwl_mvm_sta *mvm_sta; |
8ca151b5 JB |
1404 | u8 sta_id = iwl_mvm_get_key_sta_id(vif, sta); |
1405 | ||
881acd89 | 1406 | if (WARN_ON_ONCE(sta_id == IWL_MVM_STATION_COUNT)) |
8ca151b5 JB |
1407 | return; |
1408 | ||
c3eb536a BL |
1409 | rcu_read_lock(); |
1410 | ||
1411 | if (!sta) { | |
1412 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); | |
1413 | if (WARN_ON(IS_ERR_OR_NULL(sta))) { | |
1414 | rcu_read_unlock(); | |
1415 | return; | |
1416 | } | |
1417 | } | |
1418 | ||
1419 | mvm_sta = (void *)sta->drv_priv; | |
8ca151b5 JB |
1420 | iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, sta_id, |
1421 | iv32, phase1key, CMD_ASYNC); | |
c3eb536a | 1422 | rcu_read_unlock(); |
8ca151b5 JB |
1423 | } |
1424 | ||
9cc40712 JB |
1425 | void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm, |
1426 | struct ieee80211_sta *sta) | |
8ca151b5 | 1427 | { |
5b577a90 | 1428 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
3e56eadf | 1429 | struct iwl_mvm_add_sta_cmd_v7 cmd = { |
8ca151b5 | 1430 | .add_modify = STA_MODE_MODIFY, |
9cc40712 | 1431 | .sta_id = mvmsta->sta_id, |
5af01772 | 1432 | .station_flags_msk = cpu_to_le32(STA_FLG_PS), |
9cc40712 | 1433 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
8ca151b5 JB |
1434 | }; |
1435 | int ret; | |
1436 | ||
5a258aae | 1437 | ret = iwl_mvm_send_add_sta_cmd(mvm, CMD_ASYNC, &cmd); |
8ca151b5 JB |
1438 | if (ret) |
1439 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); | |
1440 | } | |
1441 | ||
9cc40712 JB |
1442 | void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm, |
1443 | struct ieee80211_sta *sta, | |
8ca151b5 | 1444 | enum ieee80211_frame_release_type reason, |
3e56eadf JB |
1445 | u16 cnt, u16 tids, bool more_data, |
1446 | bool agg) | |
8ca151b5 | 1447 | { |
5b577a90 | 1448 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
3e56eadf | 1449 | struct iwl_mvm_add_sta_cmd_v7 cmd = { |
8ca151b5 | 1450 | .add_modify = STA_MODE_MODIFY, |
9cc40712 | 1451 | .sta_id = mvmsta->sta_id, |
8ca151b5 JB |
1452 | .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT, |
1453 | .sleep_tx_count = cpu_to_le16(cnt), | |
9cc40712 | 1454 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
8ca151b5 | 1455 | }; |
3e56eadf JB |
1456 | int tid, ret; |
1457 | unsigned long _tids = tids; | |
1458 | ||
1459 | /* convert TIDs to ACs - we don't support TSPEC so that's OK | |
1460 | * Note that this field is reserved and unused by firmware not | |
1461 | * supporting GO uAPSD, so it's safe to always do this. | |
1462 | */ | |
1463 | for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) | |
1464 | cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]); | |
1465 | ||
1466 | /* If we're releasing frames from aggregation queues then check if the | |
1467 | * all queues combined that we're releasing frames from have | |
1468 | * - more frames than the service period, in which case more_data | |
1469 | * needs to be set | |
1470 | * - fewer than 'cnt' frames, in which case we need to adjust the | |
1471 | * firmware command (but do that unconditionally) | |
1472 | */ | |
1473 | if (agg) { | |
1474 | int remaining = cnt; | |
1475 | ||
1476 | spin_lock_bh(&mvmsta->lock); | |
1477 | for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) { | |
1478 | struct iwl_mvm_tid_data *tid_data; | |
1479 | u16 n_queued; | |
1480 | ||
1481 | tid_data = &mvmsta->tid_data[tid]; | |
1482 | if (WARN(tid_data->state != IWL_AGG_ON && | |
1483 | tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA, | |
1484 | "TID %d state is %d\n", | |
1485 | tid, tid_data->state)) { | |
1486 | spin_unlock_bh(&mvmsta->lock); | |
1487 | ieee80211_sta_eosp(sta); | |
1488 | return; | |
1489 | } | |
1490 | ||
1491 | n_queued = iwl_mvm_tid_queued(tid_data); | |
1492 | if (n_queued > remaining) { | |
1493 | more_data = true; | |
1494 | remaining = 0; | |
1495 | break; | |
1496 | } | |
1497 | remaining -= n_queued; | |
1498 | } | |
1499 | spin_unlock_bh(&mvmsta->lock); | |
1500 | ||
1501 | cmd.sleep_tx_count = cpu_to_le16(cnt - remaining); | |
1502 | if (WARN_ON(cnt - remaining == 0)) { | |
1503 | ieee80211_sta_eosp(sta); | |
1504 | return; | |
1505 | } | |
1506 | } | |
1507 | ||
1508 | /* Note: this is ignored by firmware not supporting GO uAPSD */ | |
1509 | if (more_data) | |
1510 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_MOREDATA); | |
1511 | ||
1512 | if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) { | |
1513 | mvmsta->next_status_eosp = true; | |
1514 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_PS_POLL); | |
1515 | } else { | |
1516 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_UAPSD); | |
1517 | } | |
8ca151b5 | 1518 | |
5a258aae | 1519 | ret = iwl_mvm_send_add_sta_cmd(mvm, CMD_ASYNC, &cmd); |
8ca151b5 JB |
1520 | if (ret) |
1521 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); | |
1522 | } | |
3e56eadf JB |
1523 | |
1524 | int iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm, | |
1525 | struct iwl_rx_cmd_buffer *rxb, | |
1526 | struct iwl_device_cmd *cmd) | |
1527 | { | |
1528 | struct iwl_rx_packet *pkt = rxb_addr(rxb); | |
1529 | struct iwl_mvm_eosp_notification *notif = (void *)pkt->data; | |
1530 | struct ieee80211_sta *sta; | |
1531 | u32 sta_id = le32_to_cpu(notif->sta_id); | |
1532 | ||
1533 | if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT)) | |
1534 | return 0; | |
1535 | ||
1536 | rcu_read_lock(); | |
1537 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); | |
1538 | if (!IS_ERR_OR_NULL(sta)) | |
1539 | ieee80211_sta_eosp(sta); | |
1540 | rcu_read_unlock(); | |
1541 | ||
1542 | return 0; | |
1543 | } |