Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 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 | * |
Andrei Otcheretianski | fa7878e | 2015-05-05 09:28:16 +0300 | [diff] [blame] | 8 | * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved. |
| 9 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 10 | * Copyright(c) 2016 Intel Deutschland GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of version 2 of the GNU General Public License as |
| 14 | * published by the Free Software Foundation. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, but |
| 17 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 19 | * General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 24 | * USA |
| 25 | * |
| 26 | * The full GNU General Public License is included in this distribution |
Emmanuel Grumbach | 410dc5a | 2013-02-18 09:22:28 +0200 | [diff] [blame] | 27 | * in the file called COPYING. |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 28 | * |
| 29 | * Contact Information: |
Emmanuel Grumbach | cb2f827 | 2015-11-17 15:39:56 +0200 | [diff] [blame] | 30 | * Intel Linux Wireless <linuxwifi@intel.com> |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 31 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 32 | * |
| 33 | * BSD LICENSE |
| 34 | * |
Andrei Otcheretianski | fa7878e | 2015-05-05 09:28:16 +0300 | [diff] [blame] | 35 | * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved. |
| 36 | * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 37 | * Copyright(c) 2016 Intel Deutschland GmbH |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 38 | * All rights reserved. |
| 39 | * |
| 40 | * Redistribution and use in source and binary forms, with or without |
| 41 | * modification, are permitted provided that the following conditions |
| 42 | * are met: |
| 43 | * |
| 44 | * * Redistributions of source code must retain the above copyright |
| 45 | * notice, this list of conditions and the following disclaimer. |
| 46 | * * Redistributions in binary form must reproduce the above copyright |
| 47 | * notice, this list of conditions and the following disclaimer in |
| 48 | * the documentation and/or other materials provided with the |
| 49 | * distribution. |
| 50 | * * Neither the name Intel Corporation nor the names of its |
| 51 | * contributors may be used to endorse or promote products derived |
| 52 | * from this software without specific prior written permission. |
| 53 | * |
| 54 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 55 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 56 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 57 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 58 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 59 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 60 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 61 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 62 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 63 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 64 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 65 | * |
| 66 | *****************************************************************************/ |
| 67 | #include <net/mac80211.h> |
| 68 | |
| 69 | #include "mvm.h" |
| 70 | #include "sta.h" |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 71 | #include "rs.h" |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 72 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 73 | /* |
| 74 | * New version of ADD_STA_sta command added new fields at the end of the |
| 75 | * structure, so sending the size of the relevant API's structure is enough to |
| 76 | * support both API versions. |
| 77 | */ |
| 78 | static inline int iwl_mvm_add_sta_cmd_size(struct iwl_mvm *mvm) |
| 79 | { |
| 80 | return iwl_mvm_has_new_rx_api(mvm) ? |
| 81 | sizeof(struct iwl_mvm_add_sta_cmd) : |
| 82 | sizeof(struct iwl_mvm_add_sta_cmd_v7); |
| 83 | } |
| 84 | |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 85 | static int iwl_mvm_find_free_sta_id(struct iwl_mvm *mvm, |
| 86 | enum nl80211_iftype iftype) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 87 | { |
| 88 | int sta_id; |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 89 | u32 reserved_ids = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 90 | |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 91 | BUILD_BUG_ON(IWL_MVM_STATION_COUNT > 32); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 92 | WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)); |
| 93 | |
| 94 | lockdep_assert_held(&mvm->mutex); |
| 95 | |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 96 | /* d0i3/d3 assumes the AP's sta_id (of sta vif) is 0. reserve it. */ |
| 97 | if (iftype != NL80211_IFTYPE_STATION) |
| 98 | reserved_ids = BIT(0); |
| 99 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 100 | /* Don't take rcu_read_lock() since we are protected by mvm->mutex */ |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 101 | for (sta_id = 0; sta_id < IWL_MVM_STATION_COUNT; sta_id++) { |
| 102 | if (BIT(sta_id) & reserved_ids) |
| 103 | continue; |
| 104 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 105 | if (!rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 106 | lockdep_is_held(&mvm->mutex))) |
| 107 | return sta_id; |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 108 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 109 | return IWL_MVM_STATION_COUNT; |
| 110 | } |
| 111 | |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 112 | /* send station add/update command to firmware */ |
| 113 | int iwl_mvm_sta_send_to_fw(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
| 114 | bool update) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 115 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 116 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | 4b8265a | 2014-07-13 08:58:04 +0300 | [diff] [blame] | 117 | struct iwl_mvm_add_sta_cmd add_sta_cmd = { |
| 118 | .sta_id = mvm_sta->sta_id, |
| 119 | .mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color), |
| 120 | .add_modify = update ? 1 : 0, |
| 121 | .station_flags_msk = cpu_to_le32(STA_FLG_FAT_EN_MSK | |
| 122 | STA_FLG_MIMO_EN_MSK), |
Liad Kaufman | cf0cda1 | 2015-09-24 10:44:12 +0200 | [diff] [blame] | 123 | .tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg), |
Emmanuel Grumbach | 4b8265a | 2014-07-13 08:58:04 +0300 | [diff] [blame] | 124 | }; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 125 | int ret; |
| 126 | u32 status; |
| 127 | u32 agg_size = 0, mpdu_dens = 0; |
| 128 | |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 129 | if (!update) { |
| 130 | add_sta_cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk); |
| 131 | memcpy(&add_sta_cmd.addr, sta->addr, ETH_ALEN); |
| 132 | } |
Johannes Berg | 5bc5aaa | 2013-02-12 14:35:36 +0100 | [diff] [blame] | 133 | |
| 134 | switch (sta->bandwidth) { |
| 135 | case IEEE80211_STA_RX_BW_160: |
| 136 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_160MHZ); |
| 137 | /* fall through */ |
| 138 | case IEEE80211_STA_RX_BW_80: |
| 139 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_80MHZ); |
| 140 | /* fall through */ |
| 141 | case IEEE80211_STA_RX_BW_40: |
| 142 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_40MHZ); |
| 143 | /* fall through */ |
| 144 | case IEEE80211_STA_RX_BW_20: |
| 145 | if (sta->ht_cap.ht_supported) |
| 146 | add_sta_cmd.station_flags |= |
| 147 | cpu_to_le32(STA_FLG_FAT_EN_20MHZ); |
| 148 | break; |
| 149 | } |
| 150 | |
| 151 | switch (sta->rx_nss) { |
| 152 | case 1: |
| 153 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO); |
| 154 | break; |
| 155 | case 2: |
| 156 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO2); |
| 157 | break; |
| 158 | case 3 ... 8: |
| 159 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO3); |
| 160 | break; |
| 161 | } |
| 162 | |
| 163 | switch (sta->smps_mode) { |
| 164 | case IEEE80211_SMPS_AUTOMATIC: |
| 165 | case IEEE80211_SMPS_NUM_MODES: |
| 166 | WARN_ON(1); |
| 167 | break; |
| 168 | case IEEE80211_SMPS_STATIC: |
| 169 | /* override NSS */ |
| 170 | add_sta_cmd.station_flags &= ~cpu_to_le32(STA_FLG_MIMO_EN_MSK); |
| 171 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO); |
| 172 | break; |
| 173 | case IEEE80211_SMPS_DYNAMIC: |
| 174 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_RTS_MIMO_PROT); |
| 175 | break; |
| 176 | case IEEE80211_SMPS_OFF: |
| 177 | /* nothing */ |
| 178 | break; |
| 179 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 180 | |
| 181 | if (sta->ht_cap.ht_supported) { |
| 182 | add_sta_cmd.station_flags_msk |= |
| 183 | cpu_to_le32(STA_FLG_MAX_AGG_SIZE_MSK | |
| 184 | STA_FLG_AGG_MPDU_DENS_MSK); |
| 185 | |
| 186 | mpdu_dens = sta->ht_cap.ampdu_density; |
| 187 | } |
| 188 | |
| 189 | if (sta->vht_cap.vht_supported) { |
| 190 | agg_size = sta->vht_cap.cap & |
| 191 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; |
| 192 | agg_size >>= |
| 193 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; |
| 194 | } else if (sta->ht_cap.ht_supported) { |
| 195 | agg_size = sta->ht_cap.ampdu_factor; |
| 196 | } |
| 197 | |
| 198 | add_sta_cmd.station_flags |= |
| 199 | cpu_to_le32(agg_size << STA_FLG_MAX_AGG_SIZE_SHIFT); |
| 200 | add_sta_cmd.station_flags |= |
| 201 | cpu_to_le32(mpdu_dens << STA_FLG_AGG_MPDU_DENS_SHIFT); |
| 202 | |
| 203 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 204 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 205 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 206 | &add_sta_cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 207 | if (ret) |
| 208 | return ret; |
| 209 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 210 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 211 | case ADD_STA_SUCCESS: |
| 212 | IWL_DEBUG_ASSOC(mvm, "ADD_STA PASSED\n"); |
| 213 | break; |
| 214 | default: |
| 215 | ret = -EIO; |
| 216 | IWL_ERR(mvm, "ADD_STA failed\n"); |
| 217 | break; |
| 218 | } |
| 219 | |
| 220 | return ret; |
| 221 | } |
| 222 | |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 223 | static int iwl_mvm_tdls_sta_init(struct iwl_mvm *mvm, |
| 224 | struct ieee80211_sta *sta) |
| 225 | { |
| 226 | unsigned long used_hw_queues; |
| 227 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | 5d42e7b | 2015-03-19 20:04:51 +0200 | [diff] [blame] | 228 | unsigned int wdg_timeout = |
| 229 | iwl_mvm_get_wd_timeout(mvm, NULL, true, false); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 230 | u32 ac; |
| 231 | |
| 232 | lockdep_assert_held(&mvm->mutex); |
| 233 | |
| 234 | used_hw_queues = iwl_mvm_get_used_hw_queues(mvm, NULL); |
| 235 | |
| 236 | /* Find available queues, and allocate them to the ACs */ |
| 237 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 238 | u8 queue = find_first_zero_bit(&used_hw_queues, |
| 239 | mvm->first_agg_queue); |
| 240 | |
| 241 | if (queue >= mvm->first_agg_queue) { |
| 242 | IWL_ERR(mvm, "Failed to allocate STA queue\n"); |
| 243 | return -EBUSY; |
| 244 | } |
| 245 | |
| 246 | __set_bit(queue, &used_hw_queues); |
| 247 | mvmsta->hw_queue[ac] = queue; |
| 248 | } |
| 249 | |
| 250 | /* Found a place for all queues - enable them */ |
| 251 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 252 | iwl_mvm_enable_ac_txq(mvm, mvmsta->hw_queue[ac], |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 253 | mvmsta->hw_queue[ac], |
Liad Kaufman | 5c1156e | 2015-07-22 17:59:53 +0300 | [diff] [blame] | 254 | iwl_mvm_ac_to_tx_fifo[ac], 0, |
| 255 | wdg_timeout); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 256 | mvmsta->tfd_queue_msk |= BIT(mvmsta->hw_queue[ac]); |
| 257 | } |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
| 262 | static void iwl_mvm_tdls_sta_deinit(struct iwl_mvm *mvm, |
| 263 | struct ieee80211_sta *sta) |
| 264 | { |
| 265 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 266 | unsigned long sta_msk; |
| 267 | int i; |
| 268 | |
| 269 | lockdep_assert_held(&mvm->mutex); |
| 270 | |
| 271 | /* disable the TDLS STA-specific queues */ |
| 272 | sta_msk = mvmsta->tfd_queue_msk; |
Emmanuel Grumbach | a4ca3ed | 2015-01-20 17:07:10 +0200 | [diff] [blame] | 273 | for_each_set_bit(i, &sta_msk, sizeof(sta_msk) * BITS_PER_BYTE) |
Arik Nemtsov | 06ecdba | 2015-10-12 14:47:11 +0300 | [diff] [blame] | 274 | iwl_mvm_disable_txq(mvm, i, i, IWL_MAX_TID_COUNT, 0); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 275 | } |
| 276 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 277 | int iwl_mvm_add_sta(struct iwl_mvm *mvm, |
| 278 | struct ieee80211_vif *vif, |
| 279 | struct ieee80211_sta *sta) |
| 280 | { |
| 281 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 282 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 283 | int i, ret, sta_id; |
| 284 | |
| 285 | lockdep_assert_held(&mvm->mutex); |
| 286 | |
| 287 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 288 | sta_id = iwl_mvm_find_free_sta_id(mvm, |
| 289 | ieee80211_vif_type_p2p(vif)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 290 | else |
| 291 | sta_id = mvm_sta->sta_id; |
| 292 | |
Johannes Berg | 36f4631 | 2015-03-10 20:32:08 +0100 | [diff] [blame] | 293 | if (sta_id == IWL_MVM_STATION_COUNT) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 294 | return -ENOSPC; |
| 295 | |
| 296 | spin_lock_init(&mvm_sta->lock); |
| 297 | |
| 298 | mvm_sta->sta_id = sta_id; |
| 299 | mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 300 | mvmvif->color); |
| 301 | mvm_sta->vif = vif; |
| 302 | mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF; |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 303 | mvm_sta->tx_protection = 0; |
| 304 | mvm_sta->tt_tx_protection = false; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 305 | |
| 306 | /* HW restart, don't assume the memory has been zeroed */ |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 307 | atomic_set(&mvm->pending_frames[sta_id], 0); |
Liad Kaufman | 69191af | 2015-09-01 18:50:22 +0300 | [diff] [blame] | 308 | mvm_sta->tid_disable_agg = 0xffff; /* No aggs at first */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 309 | mvm_sta->tfd_queue_msk = 0; |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 310 | |
| 311 | /* allocate new queues for a TDLS station */ |
| 312 | if (sta->tdls) { |
| 313 | ret = iwl_mvm_tdls_sta_init(mvm, sta); |
| 314 | if (ret) |
| 315 | return ret; |
| 316 | } else { |
| 317 | for (i = 0; i < IEEE80211_NUM_ACS; i++) |
| 318 | if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE) |
| 319 | mvm_sta->tfd_queue_msk |= BIT(vif->hw_queue[i]); |
| 320 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 321 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 322 | /* for HW restart - reset everything but the sequence number */ |
| 323 | for (i = 0; i < IWL_MAX_TID_COUNT; i++) { |
| 324 | u16 seq = mvm_sta->tid_data[i].seq_number; |
| 325 | memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i])); |
| 326 | mvm_sta->tid_data[i].seq_number = seq; |
| 327 | } |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 328 | mvm_sta->agg_tids = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 329 | |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 330 | ret = iwl_mvm_sta_send_to_fw(mvm, sta, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 331 | if (ret) |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 332 | goto err; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 333 | |
Johannes Berg | 9e84801 | 2014-08-04 14:33:42 +0200 | [diff] [blame] | 334 | if (vif->type == NL80211_IFTYPE_STATION) { |
| 335 | if (!sta->tdls) { |
| 336 | WARN_ON(mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT); |
| 337 | mvmvif->ap_sta_id = sta_id; |
| 338 | } else { |
| 339 | WARN_ON(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT); |
| 340 | } |
| 341 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 342 | |
| 343 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta); |
| 344 | |
| 345 | return 0; |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 346 | |
| 347 | err: |
| 348 | iwl_mvm_tdls_sta_deinit(mvm, sta); |
| 349 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 350 | } |
| 351 | |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 352 | int iwl_mvm_update_sta(struct iwl_mvm *mvm, |
| 353 | struct ieee80211_vif *vif, |
| 354 | struct ieee80211_sta *sta) |
| 355 | { |
| 356 | return iwl_mvm_sta_send_to_fw(mvm, sta, true); |
| 357 | } |
| 358 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 359 | int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta, |
| 360 | bool drain) |
| 361 | { |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 362 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 363 | int ret; |
| 364 | u32 status; |
| 365 | |
| 366 | lockdep_assert_held(&mvm->mutex); |
| 367 | |
| 368 | cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color); |
| 369 | cmd.sta_id = mvmsta->sta_id; |
| 370 | cmd.add_modify = STA_MODE_MODIFY; |
| 371 | cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0; |
| 372 | cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW); |
| 373 | |
| 374 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 375 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 376 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 377 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 378 | if (ret) |
| 379 | return ret; |
| 380 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 381 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 382 | case ADD_STA_SUCCESS: |
| 383 | IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n", |
| 384 | mvmsta->sta_id); |
| 385 | break; |
| 386 | default: |
| 387 | ret = -EIO; |
| 388 | IWL_ERR(mvm, "Couldn't drain frames for staid %d\n", |
| 389 | mvmsta->sta_id); |
| 390 | break; |
| 391 | } |
| 392 | |
| 393 | return ret; |
| 394 | } |
| 395 | |
| 396 | /* |
| 397 | * Remove a station from the FW table. Before sending the command to remove |
| 398 | * the station validate that the station is indeed known to the driver (sanity |
| 399 | * only). |
| 400 | */ |
| 401 | static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id) |
| 402 | { |
| 403 | struct ieee80211_sta *sta; |
| 404 | struct iwl_mvm_rm_sta_cmd rm_sta_cmd = { |
| 405 | .sta_id = sta_id, |
| 406 | }; |
| 407 | int ret; |
| 408 | |
| 409 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 410 | lockdep_is_held(&mvm->mutex)); |
| 411 | |
| 412 | /* Note: internal stations are marked as error values */ |
| 413 | if (!sta) { |
| 414 | IWL_ERR(mvm, "Invalid station id\n"); |
| 415 | return -EINVAL; |
| 416 | } |
| 417 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 418 | ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 419 | sizeof(rm_sta_cmd), &rm_sta_cmd); |
| 420 | if (ret) { |
| 421 | IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id); |
| 422 | return ret; |
| 423 | } |
| 424 | |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | void iwl_mvm_sta_drained_wk(struct work_struct *wk) |
| 429 | { |
| 430 | struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, sta_drained_wk); |
| 431 | u8 sta_id; |
| 432 | |
| 433 | /* |
| 434 | * The mutex is needed because of the SYNC cmd, but not only: if the |
| 435 | * work would run concurrently with iwl_mvm_rm_sta, it would run before |
| 436 | * iwl_mvm_rm_sta sets the station as busy, and exit. Then |
| 437 | * iwl_mvm_rm_sta would set the station as busy, and nobody will clean |
| 438 | * that later. |
| 439 | */ |
| 440 | mutex_lock(&mvm->mutex); |
| 441 | |
| 442 | for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT) { |
| 443 | int ret; |
| 444 | struct ieee80211_sta *sta = |
| 445 | rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 446 | lockdep_is_held(&mvm->mutex)); |
| 447 | |
Johannes Berg | 1ddbbb0 | 2013-12-04 22:39:17 +0100 | [diff] [blame] | 448 | /* |
| 449 | * This station is in use or RCU-removed; the latter happens in |
| 450 | * managed mode, where mac80211 removes the station before we |
| 451 | * can remove it from firmware (we can only do that after the |
| 452 | * MAC is marked unassociated), and possibly while the deauth |
| 453 | * frame to disconnect from the AP is still queued. Then, the |
| 454 | * station pointer is -ENOENT when the last skb is reclaimed. |
| 455 | */ |
| 456 | if (!IS_ERR(sta) || PTR_ERR(sta) == -ENOENT) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 457 | continue; |
| 458 | |
| 459 | if (PTR_ERR(sta) == -EINVAL) { |
| 460 | IWL_ERR(mvm, "Drained sta %d, but it is internal?\n", |
| 461 | sta_id); |
| 462 | continue; |
| 463 | } |
| 464 | |
| 465 | if (!sta) { |
| 466 | IWL_ERR(mvm, "Drained sta %d, but it was NULL?\n", |
| 467 | sta_id); |
| 468 | continue; |
| 469 | } |
| 470 | |
| 471 | WARN_ON(PTR_ERR(sta) != -EBUSY); |
| 472 | /* This station was removed and we waited until it got drained, |
| 473 | * we can now proceed and remove it. |
| 474 | */ |
| 475 | ret = iwl_mvm_rm_sta_common(mvm, sta_id); |
| 476 | if (ret) { |
| 477 | IWL_ERR(mvm, |
| 478 | "Couldn't remove sta %d after it was drained\n", |
| 479 | sta_id); |
| 480 | continue; |
| 481 | } |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 482 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 483 | clear_bit(sta_id, mvm->sta_drained); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 484 | |
| 485 | if (mvm->tfd_drained[sta_id]) { |
| 486 | unsigned long i, msk = mvm->tfd_drained[sta_id]; |
| 487 | |
Emmanuel Grumbach | a4ca3ed | 2015-01-20 17:07:10 +0200 | [diff] [blame] | 488 | for_each_set_bit(i, &msk, sizeof(msk) * BITS_PER_BYTE) |
Arik Nemtsov | 06ecdba | 2015-10-12 14:47:11 +0300 | [diff] [blame] | 489 | iwl_mvm_disable_txq(mvm, i, i, |
| 490 | IWL_MAX_TID_COUNT, 0); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 491 | |
| 492 | mvm->tfd_drained[sta_id] = 0; |
| 493 | IWL_DEBUG_TDLS(mvm, "Drained sta %d, with queues %ld\n", |
| 494 | sta_id, msk); |
| 495 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 496 | } |
| 497 | |
| 498 | mutex_unlock(&mvm->mutex); |
| 499 | } |
| 500 | |
| 501 | int iwl_mvm_rm_sta(struct iwl_mvm *mvm, |
| 502 | struct ieee80211_vif *vif, |
| 503 | struct ieee80211_sta *sta) |
| 504 | { |
| 505 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 506 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 507 | int ret; |
| 508 | |
| 509 | lockdep_assert_held(&mvm->mutex); |
| 510 | |
| 511 | if (vif->type == NL80211_IFTYPE_STATION && |
| 512 | mvmvif->ap_sta_id == mvm_sta->sta_id) { |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 513 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, true); |
| 514 | if (ret) |
| 515 | return ret; |
Emmanuel Grumbach | 80d8565 | 2013-02-19 15:32:42 +0200 | [diff] [blame] | 516 | /* flush its queues here since we are freeing mvm_sta */ |
Luca Coelho | 5888a40 | 2015-10-06 09:54:57 +0300 | [diff] [blame] | 517 | ret = iwl_mvm_flush_tx_path(mvm, mvm_sta->tfd_queue_msk, 0); |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 518 | if (ret) |
| 519 | return ret; |
| 520 | ret = iwl_trans_wait_tx_queue_empty(mvm->trans, |
| 521 | mvm_sta->tfd_queue_msk); |
| 522 | if (ret) |
| 523 | return ret; |
| 524 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, false); |
Emmanuel Grumbach | 80d8565 | 2013-02-19 15:32:42 +0200 | [diff] [blame] | 525 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 526 | /* if we are associated - we can't remove the AP STA now */ |
| 527 | if (vif->bss_conf.assoc) |
| 528 | return ret; |
| 529 | |
| 530 | /* unassoc - go ahead - remove the AP STA now */ |
| 531 | mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; |
Eliad Peller | 37577fe | 2013-12-05 17:19:39 +0200 | [diff] [blame] | 532 | |
| 533 | /* clear d0i3_ap_sta_id if no longer relevant */ |
| 534 | if (mvm->d0i3_ap_sta_id == mvm_sta->sta_id) |
| 535 | mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 536 | } |
| 537 | |
| 538 | /* |
Arik Nemtsov | 1d3c3f6 | 2014-10-23 18:03:10 +0300 | [diff] [blame] | 539 | * This shouldn't happen - the TDLS channel switch should be canceled |
| 540 | * before the STA is removed. |
| 541 | */ |
| 542 | if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == mvm_sta->sta_id)) { |
| 543 | mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT; |
| 544 | cancel_delayed_work(&mvm->tdls_cs.dwork); |
| 545 | } |
| 546 | |
| 547 | /* |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 548 | * Make sure that the tx response code sees the station as -EBUSY and |
| 549 | * calls the drain worker. |
| 550 | */ |
| 551 | spin_lock_bh(&mvm_sta->lock); |
| 552 | /* |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 553 | * There are frames pending on the AC queues for this station. |
| 554 | * We need to wait until all the frames are drained... |
| 555 | */ |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 556 | if (atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 557 | rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], |
| 558 | ERR_PTR(-EBUSY)); |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 559 | spin_unlock_bh(&mvm_sta->lock); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 560 | |
| 561 | /* disable TDLS sta queues on drain complete */ |
| 562 | if (sta->tdls) { |
| 563 | mvm->tfd_drained[mvm_sta->sta_id] = |
| 564 | mvm_sta->tfd_queue_msk; |
| 565 | IWL_DEBUG_TDLS(mvm, "Draining TDLS sta %d\n", |
| 566 | mvm_sta->sta_id); |
| 567 | } |
| 568 | |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 569 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, true); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 570 | } else { |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 571 | spin_unlock_bh(&mvm_sta->lock); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 572 | |
| 573 | if (sta->tdls) |
| 574 | iwl_mvm_tdls_sta_deinit(mvm, sta); |
| 575 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 576 | ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id); |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 577 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[mvm_sta->sta_id], NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | return ret; |
| 581 | } |
| 582 | |
| 583 | int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm, |
| 584 | struct ieee80211_vif *vif, |
| 585 | u8 sta_id) |
| 586 | { |
| 587 | int ret = iwl_mvm_rm_sta_common(mvm, sta_id); |
| 588 | |
| 589 | lockdep_assert_held(&mvm->mutex); |
| 590 | |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 591 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 592 | return ret; |
| 593 | } |
| 594 | |
Chaya Rachel Ivgi | 0e39eb0 | 2015-12-03 15:51:46 +0200 | [diff] [blame] | 595 | int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm, |
| 596 | struct iwl_mvm_int_sta *sta, |
| 597 | u32 qmask, enum nl80211_iftype iftype) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 598 | { |
| 599 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 600 | sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 601 | if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_STATION_COUNT)) |
| 602 | return -ENOSPC; |
| 603 | } |
| 604 | |
| 605 | sta->tfd_queue_msk = qmask; |
| 606 | |
| 607 | /* put a non-NULL value so iterating over the stations won't stop */ |
| 608 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL)); |
| 609 | return 0; |
| 610 | } |
| 611 | |
Johannes Berg | 712b24a | 2014-08-04 14:14:14 +0200 | [diff] [blame] | 612 | static void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm, |
| 613 | struct iwl_mvm_int_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 614 | { |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 615 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta->sta_id], NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 616 | memset(sta, 0, sizeof(struct iwl_mvm_int_sta)); |
| 617 | sta->sta_id = IWL_MVM_STATION_COUNT; |
| 618 | } |
| 619 | |
| 620 | static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm, |
| 621 | struct iwl_mvm_int_sta *sta, |
| 622 | const u8 *addr, |
| 623 | u16 mac_id, u16 color) |
| 624 | { |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 625 | struct iwl_mvm_add_sta_cmd cmd; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 626 | int ret; |
| 627 | u32 status; |
| 628 | |
| 629 | lockdep_assert_held(&mvm->mutex); |
| 630 | |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 631 | memset(&cmd, 0, sizeof(cmd)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 632 | cmd.sta_id = sta->sta_id; |
| 633 | cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id, |
| 634 | color)); |
| 635 | |
| 636 | cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk); |
Liad Kaufman | cf0cda1 | 2015-09-24 10:44:12 +0200 | [diff] [blame] | 637 | cmd.tid_disable_tx = cpu_to_le16(0xffff); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 638 | |
| 639 | if (addr) |
| 640 | memcpy(cmd.addr, addr, ETH_ALEN); |
| 641 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 642 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 643 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 644 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 645 | if (ret) |
| 646 | return ret; |
| 647 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 648 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 649 | case ADD_STA_SUCCESS: |
| 650 | IWL_DEBUG_INFO(mvm, "Internal station added.\n"); |
| 651 | return 0; |
| 652 | default: |
| 653 | ret = -EIO; |
| 654 | IWL_ERR(mvm, "Add internal station failed, status=0x%x\n", |
| 655 | status); |
| 656 | break; |
| 657 | } |
| 658 | return ret; |
| 659 | } |
| 660 | |
| 661 | int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm) |
| 662 | { |
Emmanuel Grumbach | 4cf677f | 2015-01-12 14:38:29 +0200 | [diff] [blame] | 663 | unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ? |
| 664 | mvm->cfg->base_params->wd_timeout : |
| 665 | IWL_WATCHDOG_DISABLED; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 666 | int ret; |
| 667 | |
| 668 | lockdep_assert_held(&mvm->mutex); |
| 669 | |
Ariej Marjieh | 7da91b0 | 2014-07-07 12:09:40 +0300 | [diff] [blame] | 670 | /* Map Aux queue to fifo - needs to happen before adding Aux station */ |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 671 | iwl_mvm_enable_ac_txq(mvm, mvm->aux_queue, mvm->aux_queue, |
Liad Kaufman | 5c1156e | 2015-07-22 17:59:53 +0300 | [diff] [blame] | 672 | IWL_MVM_TX_FIFO_MCAST, 0, wdg_timeout); |
Ariej Marjieh | 7da91b0 | 2014-07-07 12:09:40 +0300 | [diff] [blame] | 673 | |
| 674 | /* Allocate aux station and assign to it the aux queue */ |
| 675 | ret = iwl_mvm_allocate_int_sta(mvm, &mvm->aux_sta, BIT(mvm->aux_queue), |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 676 | NL80211_IFTYPE_UNSPECIFIED); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 677 | if (ret) |
| 678 | return ret; |
| 679 | |
| 680 | ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL, |
| 681 | MAC_INDEX_AUX, 0); |
| 682 | |
| 683 | if (ret) |
| 684 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); |
| 685 | return ret; |
| 686 | } |
| 687 | |
Chaya Rachel Ivgi | 0e39eb0 | 2015-12-03 15:51:46 +0200 | [diff] [blame] | 688 | int iwl_mvm_add_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 689 | { |
| 690 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 691 | |
| 692 | lockdep_assert_held(&mvm->mutex); |
| 693 | return iwl_mvm_add_int_sta_common(mvm, &mvm->snif_sta, vif->addr, |
| 694 | mvmvif->id, 0); |
| 695 | } |
| 696 | |
| 697 | int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 698 | { |
| 699 | int ret; |
| 700 | |
| 701 | lockdep_assert_held(&mvm->mutex); |
| 702 | |
| 703 | ret = iwl_mvm_rm_sta_common(mvm, mvm->snif_sta.sta_id); |
| 704 | if (ret) |
| 705 | IWL_WARN(mvm, "Failed sending remove station\n"); |
| 706 | |
| 707 | return ret; |
| 708 | } |
| 709 | |
| 710 | void iwl_mvm_dealloc_snif_sta(struct iwl_mvm *mvm) |
| 711 | { |
| 712 | iwl_mvm_dealloc_int_sta(mvm, &mvm->snif_sta); |
| 713 | } |
| 714 | |
Johannes Berg | 712b24a | 2014-08-04 14:14:14 +0200 | [diff] [blame] | 715 | void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm) |
| 716 | { |
| 717 | lockdep_assert_held(&mvm->mutex); |
| 718 | |
| 719 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); |
| 720 | } |
| 721 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 722 | /* |
| 723 | * Send the add station command for the vif's broadcast station. |
| 724 | * Assumes that the station was already allocated. |
| 725 | * |
| 726 | * @mvm: the mvm component |
| 727 | * @vif: the interface to which the broadcast station is added |
| 728 | * @bsta: the broadcast station to add. |
| 729 | */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 730 | int iwl_mvm_send_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 731 | { |
| 732 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 733 | struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta; |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 734 | static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
Johannes Berg | a424340 | 2014-01-20 23:46:38 +0100 | [diff] [blame] | 735 | const u8 *baddr = _baddr; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 736 | |
| 737 | lockdep_assert_held(&mvm->mutex); |
| 738 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 739 | if (vif->type == NL80211_IFTYPE_ADHOC) |
| 740 | baddr = vif->bss_conf.bssid; |
| 741 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 742 | if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_STATION_COUNT)) |
| 743 | return -ENOSPC; |
| 744 | |
| 745 | return iwl_mvm_add_int_sta_common(mvm, bsta, baddr, |
| 746 | mvmvif->id, mvmvif->color); |
| 747 | } |
| 748 | |
| 749 | /* Send the FW a request to remove the station from it's internal data |
| 750 | * structures, but DO NOT remove the entry from the local data structures. */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 751 | int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 752 | { |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 753 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 754 | int ret; |
| 755 | |
| 756 | lockdep_assert_held(&mvm->mutex); |
| 757 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 758 | ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 759 | if (ret) |
| 760 | IWL_WARN(mvm, "Failed sending remove station\n"); |
| 761 | return ret; |
| 762 | } |
| 763 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 764 | int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 765 | { |
| 766 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 767 | u32 qmask; |
| 768 | |
| 769 | lockdep_assert_held(&mvm->mutex); |
| 770 | |
Arik Nemtsov | d92b732e | 2014-09-21 19:00:42 +0300 | [diff] [blame] | 771 | qmask = iwl_mvm_mac_get_queues_mask(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 772 | |
| 773 | /* |
| 774 | * The firmware defines the TFD queue mask to only be relevant |
| 775 | * for *unicast* queues, so the multicast (CAB) queue shouldn't |
| 776 | * be included. |
| 777 | */ |
| 778 | if (vif->type == NL80211_IFTYPE_AP) |
| 779 | qmask &= ~BIT(vif->cab_queue); |
| 780 | |
| 781 | return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, qmask, |
| 782 | ieee80211_vif_type_p2p(vif)); |
| 783 | } |
| 784 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 785 | /* Allocate a new station entry for the broadcast station to the given vif, |
| 786 | * and send it to the FW. |
| 787 | * Note that each P2P mac should have its own broadcast station. |
| 788 | * |
| 789 | * @mvm: the mvm component |
| 790 | * @vif: the interface to which the broadcast station is added |
| 791 | * @bsta: the broadcast station to add. */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 792 | int iwl_mvm_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 793 | { |
| 794 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 795 | struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 796 | int ret; |
| 797 | |
| 798 | lockdep_assert_held(&mvm->mutex); |
| 799 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 800 | ret = iwl_mvm_alloc_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 801 | if (ret) |
| 802 | return ret; |
| 803 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 804 | ret = iwl_mvm_send_add_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 805 | |
| 806 | if (ret) |
| 807 | iwl_mvm_dealloc_int_sta(mvm, bsta); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 808 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 809 | return ret; |
| 810 | } |
| 811 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 812 | void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 813 | { |
| 814 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 815 | |
| 816 | iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta); |
| 817 | } |
| 818 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 819 | /* |
| 820 | * Send the FW a request to remove the station from it's internal data |
| 821 | * structures, and in addition remove it from the local data structure. |
| 822 | */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 823 | int iwl_mvm_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 824 | { |
| 825 | int ret; |
| 826 | |
| 827 | lockdep_assert_held(&mvm->mutex); |
| 828 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 829 | ret = iwl_mvm_send_rm_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 830 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 831 | iwl_mvm_dealloc_bcast_sta(mvm, vif); |
| 832 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 833 | return ret; |
| 834 | } |
| 835 | |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 836 | #define IWL_MAX_RX_BA_SESSIONS 16 |
| 837 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 838 | int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 839 | int tid, u16 ssn, bool start, u8 buf_size) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 840 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 841 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 842 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 843 | int ret; |
| 844 | u32 status; |
| 845 | |
| 846 | lockdep_assert_held(&mvm->mutex); |
| 847 | |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 848 | if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) { |
| 849 | IWL_WARN(mvm, "Not enough RX BA SESSIONS\n"); |
| 850 | return -ENOSPC; |
| 851 | } |
| 852 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 853 | cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); |
| 854 | cmd.sta_id = mvm_sta->sta_id; |
| 855 | cmd.add_modify = STA_MODE_MODIFY; |
Emmanuel Grumbach | 93a4266 | 2013-07-02 13:35:35 +0300 | [diff] [blame] | 856 | if (start) { |
| 857 | cmd.add_immediate_ba_tid = (u8) tid; |
| 858 | cmd.add_immediate_ba_ssn = cpu_to_le16(ssn); |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 859 | cmd.rx_ba_window = cpu_to_le16((u16)buf_size); |
Emmanuel Grumbach | 93a4266 | 2013-07-02 13:35:35 +0300 | [diff] [blame] | 860 | } else { |
| 861 | cmd.remove_immediate_ba_tid = (u8) tid; |
| 862 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 863 | cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID : |
| 864 | STA_MODIFY_REMOVE_BA_TID; |
| 865 | |
| 866 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 867 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 868 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 869 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 870 | if (ret) |
| 871 | return ret; |
| 872 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 873 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 874 | case ADD_STA_SUCCESS: |
| 875 | IWL_DEBUG_INFO(mvm, "RX BA Session %sed in fw\n", |
| 876 | start ? "start" : "stopp"); |
| 877 | break; |
| 878 | case ADD_STA_IMMEDIATE_BA_FAILURE: |
| 879 | IWL_WARN(mvm, "RX BA Session refused by fw\n"); |
| 880 | ret = -ENOSPC; |
| 881 | break; |
| 882 | default: |
| 883 | ret = -EIO; |
| 884 | IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n", |
| 885 | start ? "start" : "stopp", status); |
| 886 | break; |
| 887 | } |
| 888 | |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 889 | if (!ret) { |
| 890 | if (start) |
| 891 | mvm->rx_ba_sessions++; |
| 892 | else if (mvm->rx_ba_sessions > 0) |
| 893 | /* check that restart flow didn't zero the counter */ |
| 894 | mvm->rx_ba_sessions--; |
| 895 | } |
| 896 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 897 | return ret; |
| 898 | } |
| 899 | |
| 900 | static int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
| 901 | int tid, u8 queue, bool start) |
| 902 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 903 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 904 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 905 | int ret; |
| 906 | u32 status; |
| 907 | |
| 908 | lockdep_assert_held(&mvm->mutex); |
| 909 | |
| 910 | if (start) { |
| 911 | mvm_sta->tfd_queue_msk |= BIT(queue); |
| 912 | mvm_sta->tid_disable_agg &= ~BIT(tid); |
| 913 | } else { |
| 914 | mvm_sta->tfd_queue_msk &= ~BIT(queue); |
| 915 | mvm_sta->tid_disable_agg |= BIT(tid); |
| 916 | } |
| 917 | |
| 918 | cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); |
| 919 | cmd.sta_id = mvm_sta->sta_id; |
| 920 | cmd.add_modify = STA_MODE_MODIFY; |
| 921 | cmd.modify_mask = STA_MODIFY_QUEUES | STA_MODIFY_TID_DISABLE_TX; |
| 922 | cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk); |
| 923 | cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg); |
| 924 | |
| 925 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 926 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 927 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 928 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 929 | if (ret) |
| 930 | return ret; |
| 931 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 932 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 933 | case ADD_STA_SUCCESS: |
| 934 | break; |
| 935 | default: |
| 936 | ret = -EIO; |
| 937 | IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n", |
| 938 | start ? "start" : "stopp", status); |
| 939 | break; |
| 940 | } |
| 941 | |
| 942 | return ret; |
| 943 | } |
| 944 | |
Emmanuel Grumbach | b797e3f | 2014-03-06 14:49:36 +0200 | [diff] [blame] | 945 | const u8 tid_to_mac80211_ac[] = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 946 | IEEE80211_AC_BE, |
| 947 | IEEE80211_AC_BK, |
| 948 | IEEE80211_AC_BK, |
| 949 | IEEE80211_AC_BE, |
| 950 | IEEE80211_AC_VI, |
| 951 | IEEE80211_AC_VI, |
| 952 | IEEE80211_AC_VO, |
| 953 | IEEE80211_AC_VO, |
| 954 | }; |
| 955 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 956 | static const u8 tid_to_ucode_ac[] = { |
| 957 | AC_BE, |
| 958 | AC_BK, |
| 959 | AC_BK, |
| 960 | AC_BE, |
| 961 | AC_VI, |
| 962 | AC_VI, |
| 963 | AC_VO, |
| 964 | AC_VO, |
| 965 | }; |
| 966 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 967 | int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 968 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) |
| 969 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 970 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 971 | struct iwl_mvm_tid_data *tid_data; |
| 972 | int txq_id; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 973 | int ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 974 | |
| 975 | if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT)) |
| 976 | return -EINVAL; |
| 977 | |
| 978 | if (mvmsta->tid_data[tid].state != IWL_AGG_OFF) { |
| 979 | IWL_ERR(mvm, "Start AGG when state is not IWL_AGG_OFF %d!\n", |
| 980 | mvmsta->tid_data[tid].state); |
| 981 | return -ENXIO; |
| 982 | } |
| 983 | |
| 984 | lockdep_assert_held(&mvm->mutex); |
| 985 | |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 986 | spin_lock_bh(&mvmsta->lock); |
| 987 | |
| 988 | /* possible race condition - we entered D0i3 while starting agg */ |
| 989 | if (test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) { |
| 990 | spin_unlock_bh(&mvmsta->lock); |
| 991 | IWL_ERR(mvm, "Entered D0i3 while starting Tx agg\n"); |
| 992 | return -EIO; |
| 993 | } |
| 994 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 995 | spin_lock_bh(&mvm->queue_info_lock); |
| 996 | |
| 997 | txq_id = iwl_mvm_find_free_queue(mvm, mvm->first_agg_queue, |
| 998 | mvm->last_agg_queue); |
| 999 | if (txq_id < 0) { |
| 1000 | ret = txq_id; |
| 1001 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1002 | IWL_ERR(mvm, "Failed to allocate agg queue\n"); |
| 1003 | goto release_locks; |
| 1004 | } |
| 1005 | mvm->queue_info[txq_id].setup_reserved = true; |
| 1006 | spin_unlock_bh(&mvm->queue_info_lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1007 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1008 | tid_data = &mvmsta->tid_data[tid]; |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 1009 | tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1010 | tid_data->txq_id = txq_id; |
| 1011 | *ssn = tid_data->ssn; |
| 1012 | |
| 1013 | IWL_DEBUG_TX_QUEUES(mvm, |
| 1014 | "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n", |
| 1015 | mvmsta->sta_id, tid, txq_id, tid_data->ssn, |
| 1016 | tid_data->next_reclaimed); |
| 1017 | |
| 1018 | if (tid_data->ssn == tid_data->next_reclaimed) { |
| 1019 | tid_data->state = IWL_AGG_STARTING; |
| 1020 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 1021 | } else { |
| 1022 | tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA; |
| 1023 | } |
| 1024 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1025 | ret = 0; |
| 1026 | |
| 1027 | release_locks: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1028 | spin_unlock_bh(&mvmsta->lock); |
| 1029 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1030 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
Emmanuel Grumbach | bb81bb6 | 2015-10-26 16:00:29 +0200 | [diff] [blame^] | 1034 | struct ieee80211_sta *sta, u16 tid, u8 buf_size, |
| 1035 | bool amsdu) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1036 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1037 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1038 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
Emmanuel Grumbach | 5d42e7b | 2015-03-19 20:04:51 +0200 | [diff] [blame] | 1039 | unsigned int wdg_timeout = |
| 1040 | iwl_mvm_get_wd_timeout(mvm, vif, sta->tdls, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1041 | int queue, fifo, ret; |
| 1042 | u16 ssn; |
| 1043 | |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 1044 | BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE) |
| 1045 | != IWL_MAX_TID_COUNT); |
| 1046 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1047 | buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF); |
| 1048 | |
| 1049 | spin_lock_bh(&mvmsta->lock); |
| 1050 | ssn = tid_data->ssn; |
| 1051 | queue = tid_data->txq_id; |
| 1052 | tid_data->state = IWL_AGG_ON; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 1053 | mvmsta->agg_tids |= BIT(tid); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1054 | tid_data->ssn = 0xffff; |
Emmanuel Grumbach | bb81bb6 | 2015-10-26 16:00:29 +0200 | [diff] [blame^] | 1055 | tid_data->amsdu_in_ampdu_allowed = amsdu; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1056 | spin_unlock_bh(&mvmsta->lock); |
| 1057 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1058 | fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]]; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1059 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1060 | iwl_mvm_enable_agg_txq(mvm, queue, |
| 1061 | vif->hw_queue[tid_to_mac80211_ac[tid]], fifo, |
| 1062 | mvmsta->sta_id, tid, buf_size, ssn, wdg_timeout); |
Andrei Otcheretianski | fa7878e | 2015-05-05 09:28:16 +0300 | [diff] [blame] | 1063 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1064 | ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true); |
| 1065 | if (ret) |
| 1066 | return -EIO; |
| 1067 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1068 | /* No need to mark as reserved */ |
| 1069 | spin_lock_bh(&mvm->queue_info_lock); |
| 1070 | mvm->queue_info[queue].setup_reserved = false; |
| 1071 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1072 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1073 | /* |
| 1074 | * Even though in theory the peer could have different |
| 1075 | * aggregation reorder buffer sizes for different sessions, |
| 1076 | * our ucode doesn't allow for that and has a global limit |
| 1077 | * for each station. Therefore, use the minimum of all the |
| 1078 | * aggregation sessions and our default value. |
| 1079 | */ |
| 1080 | mvmsta->max_agg_bufsize = |
| 1081 | min(mvmsta->max_agg_bufsize, buf_size); |
| 1082 | mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize; |
| 1083 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 1084 | IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n", |
| 1085 | sta->addr, tid); |
| 1086 | |
Eyal Shapira | 9e68094 | 2013-11-09 00:16:16 +0200 | [diff] [blame] | 1087 | return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1088 | } |
| 1089 | |
| 1090 | int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 1091 | struct ieee80211_sta *sta, u16 tid) |
| 1092 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1093 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1094 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
| 1095 | u16 txq_id; |
| 1096 | int err; |
| 1097 | |
Emmanuel Grumbach | f9aa8dd | 2013-03-04 09:11:08 +0200 | [diff] [blame] | 1098 | |
| 1099 | /* |
| 1100 | * If mac80211 is cleaning its state, then say that we finished since |
| 1101 | * our state has been cleared anyway. |
| 1102 | */ |
| 1103 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
| 1104 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 1105 | return 0; |
| 1106 | } |
| 1107 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1108 | spin_lock_bh(&mvmsta->lock); |
| 1109 | |
| 1110 | txq_id = tid_data->txq_id; |
| 1111 | |
| 1112 | IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n", |
| 1113 | mvmsta->sta_id, tid, txq_id, tid_data->state); |
| 1114 | |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 1115 | mvmsta->agg_tids &= ~BIT(tid); |
| 1116 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1117 | /* No need to mark as reserved anymore */ |
| 1118 | spin_lock_bh(&mvm->queue_info_lock); |
| 1119 | mvm->queue_info[txq_id].setup_reserved = false; |
| 1120 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1121 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1122 | switch (tid_data->state) { |
| 1123 | case IWL_AGG_ON: |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 1124 | tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1125 | |
| 1126 | IWL_DEBUG_TX_QUEUES(mvm, |
| 1127 | "ssn = %d, next_recl = %d\n", |
| 1128 | tid_data->ssn, tid_data->next_reclaimed); |
| 1129 | |
| 1130 | /* There are still packets for this RA / TID in the HW */ |
| 1131 | if (tid_data->ssn != tid_data->next_reclaimed) { |
| 1132 | tid_data->state = IWL_EMPTYING_HW_QUEUE_DELBA; |
| 1133 | err = 0; |
| 1134 | break; |
| 1135 | } |
| 1136 | |
| 1137 | tid_data->ssn = 0xffff; |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 1138 | tid_data->state = IWL_AGG_OFF; |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 1139 | spin_unlock_bh(&mvmsta->lock); |
| 1140 | |
| 1141 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 1142 | |
| 1143 | iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false); |
| 1144 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1145 | iwl_mvm_disable_txq(mvm, txq_id, |
| 1146 | vif->hw_queue[tid_to_mac80211_ac[tid]], tid, |
| 1147 | 0); |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 1148 | return 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1149 | case IWL_AGG_STARTING: |
| 1150 | case IWL_EMPTYING_HW_QUEUE_ADDBA: |
| 1151 | /* |
| 1152 | * The agg session has been stopped before it was set up. This |
| 1153 | * can happen when the AddBA timer times out for example. |
| 1154 | */ |
| 1155 | |
| 1156 | /* No barriers since we are under mutex */ |
| 1157 | lockdep_assert_held(&mvm->mutex); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1158 | |
| 1159 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 1160 | tid_data->state = IWL_AGG_OFF; |
| 1161 | err = 0; |
| 1162 | break; |
| 1163 | default: |
| 1164 | IWL_ERR(mvm, |
| 1165 | "Stopping AGG while state not ON or starting for %d on %d (%d)\n", |
| 1166 | mvmsta->sta_id, tid, tid_data->state); |
| 1167 | IWL_ERR(mvm, |
| 1168 | "\ttid_data->txq_id = %d\n", tid_data->txq_id); |
| 1169 | err = -EINVAL; |
| 1170 | } |
| 1171 | |
| 1172 | spin_unlock_bh(&mvmsta->lock); |
| 1173 | |
| 1174 | return err; |
| 1175 | } |
| 1176 | |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1177 | int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 1178 | struct ieee80211_sta *sta, u16 tid) |
| 1179 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1180 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1181 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
| 1182 | u16 txq_id; |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 1183 | enum iwl_mvm_agg_state old_state; |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1184 | |
| 1185 | /* |
| 1186 | * First set the agg state to OFF to avoid calling |
| 1187 | * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty. |
| 1188 | */ |
| 1189 | spin_lock_bh(&mvmsta->lock); |
| 1190 | txq_id = tid_data->txq_id; |
| 1191 | IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n", |
| 1192 | mvmsta->sta_id, tid, txq_id, tid_data->state); |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 1193 | old_state = tid_data->state; |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1194 | tid_data->state = IWL_AGG_OFF; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 1195 | mvmsta->agg_tids &= ~BIT(tid); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1196 | spin_unlock_bh(&mvmsta->lock); |
| 1197 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1198 | /* No need to mark as reserved */ |
| 1199 | spin_lock_bh(&mvm->queue_info_lock); |
| 1200 | mvm->queue_info[txq_id].setup_reserved = false; |
| 1201 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1202 | |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 1203 | if (old_state >= IWL_AGG_ON) { |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 1204 | iwl_mvm_drain_sta(mvm, mvmsta, true); |
Luca Coelho | 5888a40 | 2015-10-06 09:54:57 +0300 | [diff] [blame] | 1205 | if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), 0)) |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 1206 | IWL_ERR(mvm, "Couldn't flush the AGG queue\n"); |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 1207 | iwl_trans_wait_tx_queue_empty(mvm->trans, |
| 1208 | mvmsta->tfd_queue_msk); |
| 1209 | iwl_mvm_drain_sta(mvm, mvmsta, false); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1210 | |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 1211 | iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false); |
| 1212 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 1213 | iwl_mvm_disable_txq(mvm, tid_data->txq_id, |
| 1214 | vif->hw_queue[tid_to_mac80211_ac[tid]], tid, |
| 1215 | 0); |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 1216 | } |
| 1217 | |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 1218 | return 0; |
| 1219 | } |
| 1220 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1221 | static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm) |
| 1222 | { |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1223 | int i, max = -1, max_offs = -1; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1224 | |
| 1225 | lockdep_assert_held(&mvm->mutex); |
| 1226 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1227 | /* Pick the unused key offset with the highest 'deleted' |
| 1228 | * counter. Every time a key is deleted, all the counters |
| 1229 | * are incremented and the one that was just deleted is |
| 1230 | * reset to zero. Thus, the highest counter is the one |
| 1231 | * that was deleted longest ago. Pick that one. |
| 1232 | */ |
| 1233 | for (i = 0; i < STA_KEY_MAX_NUM; i++) { |
| 1234 | if (test_bit(i, mvm->fw_key_table)) |
| 1235 | continue; |
| 1236 | if (mvm->fw_key_deleted[i] > max) { |
| 1237 | max = mvm->fw_key_deleted[i]; |
| 1238 | max_offs = i; |
| 1239 | } |
| 1240 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1241 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1242 | if (max_offs < 0) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1243 | return STA_KEY_IDX_INVALID; |
| 1244 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1245 | return max_offs; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1246 | } |
| 1247 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1248 | static struct iwl_mvm_sta *iwl_mvm_get_key_sta(struct iwl_mvm *mvm, |
| 1249 | struct ieee80211_vif *vif, |
| 1250 | struct ieee80211_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1251 | { |
Johannes Berg | 5b530e9 | 2014-12-23 16:00:17 +0100 | [diff] [blame] | 1252 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1253 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1254 | if (sta) |
| 1255 | return iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1256 | |
| 1257 | /* |
| 1258 | * The device expects GTKs for station interfaces to be |
| 1259 | * installed as GTKs for the AP station. If we have no |
| 1260 | * station ID, then use AP's station ID. |
| 1261 | */ |
| 1262 | if (vif->type == NL80211_IFTYPE_STATION && |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 1263 | mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
| 1264 | u8 sta_id = mvmvif->ap_sta_id; |
| 1265 | |
Emmanuel Grumbach | 12f1721 | 2015-12-20 14:48:08 +0200 | [diff] [blame] | 1266 | sta = rcu_dereference_check(mvm->fw_id_to_mac_id[sta_id], |
| 1267 | lockdep_is_held(&mvm->mutex)); |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 1268 | /* |
| 1269 | * It is possible that the 'sta' parameter is NULL, |
| 1270 | * for example when a GTK is removed - the sta_id will then |
| 1271 | * be the AP ID, and no station was passed by mac80211. |
| 1272 | */ |
| 1273 | if (IS_ERR_OR_NULL(sta)) |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1274 | return NULL; |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 1275 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1276 | return iwl_mvm_sta_from_mac80211(sta); |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 1277 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1278 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1279 | return NULL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1280 | } |
| 1281 | |
| 1282 | static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm, |
| 1283 | struct iwl_mvm_sta *mvm_sta, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1284 | struct ieee80211_key_conf *keyconf, bool mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1285 | u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags, |
| 1286 | u8 key_offset) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1287 | { |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1288 | struct iwl_mvm_add_sta_key_cmd cmd = {}; |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1289 | __le16 key_flags; |
Johannes Berg | 7992074 | 2014-11-03 15:43:04 +0100 | [diff] [blame] | 1290 | int ret; |
| 1291 | u32 status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1292 | u16 keyidx; |
| 1293 | int i; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1294 | u8 sta_id = mvm_sta->sta_id; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1295 | |
| 1296 | keyidx = (keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & |
| 1297 | STA_KEY_FLG_KEYID_MSK; |
| 1298 | key_flags = cpu_to_le16(keyidx); |
| 1299 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP); |
| 1300 | |
| 1301 | switch (keyconf->cipher) { |
| 1302 | case WLAN_CIPHER_SUITE_TKIP: |
| 1303 | key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP); |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1304 | cmd.tkip_rx_tsc_byte2 = tkip_iv32; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1305 | for (i = 0; i < 5; i++) |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1306 | cmd.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]); |
| 1307 | memcpy(cmd.key, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1308 | break; |
| 1309 | case WLAN_CIPHER_SUITE_CCMP: |
| 1310 | key_flags |= cpu_to_le16(STA_KEY_FLG_CCM); |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1311 | memcpy(cmd.key, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1312 | break; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1313 | case WLAN_CIPHER_SUITE_WEP104: |
| 1314 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES); |
John W. Linville | aa0cb08 | 2015-01-12 16:18:11 -0500 | [diff] [blame] | 1315 | /* fall through */ |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1316 | case WLAN_CIPHER_SUITE_WEP40: |
| 1317 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP); |
| 1318 | memcpy(cmd.key + 3, keyconf->key, keyconf->keylen); |
| 1319 | break; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1320 | default: |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 1321 | key_flags |= cpu_to_le16(STA_KEY_FLG_EXT); |
| 1322 | memcpy(cmd.key, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1323 | } |
| 1324 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1325 | if (mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1326 | key_flags |= cpu_to_le16(STA_KEY_MULTICAST); |
| 1327 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1328 | cmd.key_offset = key_offset; |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1329 | cmd.key_flags = key_flags; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1330 | cmd.sta_id = sta_id; |
| 1331 | |
| 1332 | status = ADD_STA_SUCCESS; |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1333 | if (cmd_flags & CMD_ASYNC) |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1334 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC, |
| 1335 | sizeof(cmd), &cmd); |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1336 | else |
| 1337 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd), |
| 1338 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1339 | |
| 1340 | switch (status) { |
| 1341 | case ADD_STA_SUCCESS: |
| 1342 | IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n"); |
| 1343 | break; |
| 1344 | default: |
| 1345 | ret = -EIO; |
| 1346 | IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n"); |
| 1347 | break; |
| 1348 | } |
| 1349 | |
| 1350 | return ret; |
| 1351 | } |
| 1352 | |
| 1353 | static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm, |
| 1354 | struct ieee80211_key_conf *keyconf, |
| 1355 | u8 sta_id, bool remove_key) |
| 1356 | { |
| 1357 | struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {}; |
| 1358 | |
| 1359 | /* verify the key details match the required command's expectations */ |
| 1360 | if (WARN_ON((keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC) || |
| 1361 | (keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) || |
| 1362 | (keyconf->keyidx != 4 && keyconf->keyidx != 5))) |
| 1363 | return -EINVAL; |
| 1364 | |
| 1365 | igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx); |
| 1366 | igtk_cmd.sta_id = cpu_to_le32(sta_id); |
| 1367 | |
| 1368 | if (remove_key) { |
| 1369 | igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID); |
| 1370 | } else { |
| 1371 | struct ieee80211_key_seq seq; |
| 1372 | const u8 *pn; |
| 1373 | |
| 1374 | memcpy(igtk_cmd.IGTK, keyconf->key, keyconf->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1375 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); |
| 1376 | pn = seq.aes_cmac.pn; |
| 1377 | igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) | |
| 1378 | ((u64) pn[4] << 8) | |
| 1379 | ((u64) pn[3] << 16) | |
| 1380 | ((u64) pn[2] << 24) | |
| 1381 | ((u64) pn[1] << 32) | |
| 1382 | ((u64) pn[0] << 40)); |
| 1383 | } |
| 1384 | |
| 1385 | IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n", |
| 1386 | remove_key ? "removing" : "installing", |
| 1387 | igtk_cmd.sta_id); |
| 1388 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1389 | return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1390 | sizeof(igtk_cmd), &igtk_cmd); |
| 1391 | } |
| 1392 | |
| 1393 | |
| 1394 | static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm, |
| 1395 | struct ieee80211_vif *vif, |
| 1396 | struct ieee80211_sta *sta) |
| 1397 | { |
Johannes Berg | 5b530e9 | 2014-12-23 16:00:17 +0100 | [diff] [blame] | 1398 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1399 | |
| 1400 | if (sta) |
| 1401 | return sta->addr; |
| 1402 | |
| 1403 | if (vif->type == NL80211_IFTYPE_STATION && |
| 1404 | mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { |
| 1405 | u8 sta_id = mvmvif->ap_sta_id; |
| 1406 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 1407 | lockdep_is_held(&mvm->mutex)); |
| 1408 | return sta->addr; |
| 1409 | } |
| 1410 | |
| 1411 | |
| 1412 | return NULL; |
| 1413 | } |
| 1414 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1415 | static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm, |
| 1416 | struct ieee80211_vif *vif, |
| 1417 | struct ieee80211_sta *sta, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1418 | struct ieee80211_key_conf *keyconf, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1419 | u8 key_offset, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1420 | bool mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1421 | { |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1422 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1423 | int ret; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1424 | const u8 *addr; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1425 | struct ieee80211_key_seq seq; |
| 1426 | u16 p1k[5]; |
| 1427 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1428 | switch (keyconf->cipher) { |
| 1429 | case WLAN_CIPHER_SUITE_TKIP: |
| 1430 | addr = iwl_mvm_get_mac_addr(mvm, vif, sta); |
| 1431 | /* get phase 1 key from mac80211 */ |
| 1432 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); |
| 1433 | ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k); |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1434 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1435 | seq.tkip.iv32, p1k, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1436 | break; |
| 1437 | case WLAN_CIPHER_SUITE_CCMP: |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1438 | case WLAN_CIPHER_SUITE_WEP40: |
| 1439 | case WLAN_CIPHER_SUITE_WEP104: |
| 1440 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1441 | 0, NULL, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1442 | break; |
| 1443 | default: |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1444 | ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1445 | 0, NULL, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1446 | } |
| 1447 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1448 | return ret; |
| 1449 | } |
| 1450 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1451 | static int __iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, u8 sta_id, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1452 | struct ieee80211_key_conf *keyconf, |
| 1453 | bool mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1454 | { |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1455 | struct iwl_mvm_add_sta_key_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1456 | __le16 key_flags; |
Johannes Berg | 7992074 | 2014-11-03 15:43:04 +0100 | [diff] [blame] | 1457 | int ret; |
| 1458 | u32 status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1459 | |
Emmanuel Grumbach | 8115efb | 2013-02-05 10:08:35 +0200 | [diff] [blame] | 1460 | key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & |
| 1461 | STA_KEY_FLG_KEYID_MSK); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1462 | key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP); |
| 1463 | key_flags |= cpu_to_le16(STA_KEY_NOT_VALID); |
| 1464 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1465 | if (mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1466 | key_flags |= cpu_to_le16(STA_KEY_MULTICAST); |
| 1467 | |
Max Stepanov | 5a258aa | 2013-04-07 09:11:21 +0300 | [diff] [blame] | 1468 | cmd.key_flags = key_flags; |
| 1469 | cmd.key_offset = keyconf->hw_key_idx; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1470 | cmd.sta_id = sta_id; |
| 1471 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1472 | status = ADD_STA_SUCCESS; |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1473 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd), |
| 1474 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1475 | |
| 1476 | switch (status) { |
| 1477 | case ADD_STA_SUCCESS: |
| 1478 | IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n"); |
| 1479 | break; |
| 1480 | default: |
| 1481 | ret = -EIO; |
| 1482 | IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n"); |
| 1483 | break; |
| 1484 | } |
| 1485 | |
| 1486 | return ret; |
| 1487 | } |
| 1488 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1489 | int iwl_mvm_set_sta_key(struct iwl_mvm *mvm, |
| 1490 | struct ieee80211_vif *vif, |
| 1491 | struct ieee80211_sta *sta, |
| 1492 | struct ieee80211_key_conf *keyconf, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1493 | u8 key_offset) |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1494 | { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1495 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1496 | struct iwl_mvm_sta *mvm_sta; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1497 | u8 sta_id; |
| 1498 | int ret; |
Matti Gottlieb | 11828db | 2015-06-01 15:15:11 +0300 | [diff] [blame] | 1499 | static const u8 __maybe_unused zero_addr[ETH_ALEN] = {0}; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1500 | |
| 1501 | lockdep_assert_held(&mvm->mutex); |
| 1502 | |
| 1503 | /* Get the station id from the mvm local station table */ |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1504 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
| 1505 | if (!mvm_sta) { |
| 1506 | IWL_ERR(mvm, "Failed to find station\n"); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1507 | return -EINVAL; |
| 1508 | } |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1509 | sta_id = mvm_sta->sta_id; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1510 | |
| 1511 | if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC) { |
| 1512 | ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, false); |
| 1513 | goto end; |
| 1514 | } |
| 1515 | |
| 1516 | /* |
| 1517 | * It is possible that the 'sta' parameter is NULL, and thus |
| 1518 | * there is a need to retrieve the sta from the local station table. |
| 1519 | */ |
| 1520 | if (!sta) { |
| 1521 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 1522 | lockdep_is_held(&mvm->mutex)); |
| 1523 | if (IS_ERR_OR_NULL(sta)) { |
| 1524 | IWL_ERR(mvm, "Invalid station id\n"); |
| 1525 | return -EINVAL; |
| 1526 | } |
| 1527 | } |
| 1528 | |
| 1529 | if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif)) |
| 1530 | return -EINVAL; |
| 1531 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1532 | /* If the key_offset is not pre-assigned, we need to find a |
| 1533 | * new offset to use. In normal cases, the offset is not |
| 1534 | * pre-assigned, but during HW_RESTART we want to reuse the |
| 1535 | * same indices, so we pass them when this function is called. |
| 1536 | * |
| 1537 | * In D3 entry, we need to hardcoded the indices (because the |
| 1538 | * firmware hardcodes the PTK offset to 0). In this case, we |
| 1539 | * need to make sure we don't overwrite the hw_key_idx in the |
| 1540 | * keyconf structure, because otherwise we cannot configure |
| 1541 | * the original ones back when resuming. |
| 1542 | */ |
| 1543 | if (key_offset == STA_KEY_IDX_INVALID) { |
| 1544 | key_offset = iwl_mvm_set_fw_key_idx(mvm); |
| 1545 | if (key_offset == STA_KEY_IDX_INVALID) |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1546 | return -ENOSPC; |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1547 | keyconf->hw_key_idx = key_offset; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1548 | } |
| 1549 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1550 | ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, key_offset, mcast); |
Luca Coelho | 9c3deeb | 2015-11-11 01:06:17 +0200 | [diff] [blame] | 1551 | if (ret) |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1552 | goto end; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1553 | |
| 1554 | /* |
| 1555 | * For WEP, the same key is used for multicast and unicast. Upload it |
| 1556 | * again, using the same key offset, and now pointing the other one |
| 1557 | * to the same key slot (offset). |
| 1558 | * If this fails, remove the original as well. |
| 1559 | */ |
| 1560 | if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 1561 | keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) { |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1562 | ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, |
| 1563 | key_offset, !mcast); |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1564 | if (ret) { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1565 | __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast); |
Luca Coelho | 9c3deeb | 2015-11-11 01:06:17 +0200 | [diff] [blame] | 1566 | goto end; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1567 | } |
| 1568 | } |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1569 | |
Luca Coelho | 9c3deeb | 2015-11-11 01:06:17 +0200 | [diff] [blame] | 1570 | __set_bit(key_offset, mvm->fw_key_table); |
| 1571 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1572 | end: |
| 1573 | IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n", |
| 1574 | keyconf->cipher, keyconf->keylen, keyconf->keyidx, |
Matti Gottlieb | 11828db | 2015-06-01 15:15:11 +0300 | [diff] [blame] | 1575 | sta ? sta->addr : zero_addr, ret); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1576 | return ret; |
| 1577 | } |
| 1578 | |
| 1579 | int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, |
| 1580 | struct ieee80211_vif *vif, |
| 1581 | struct ieee80211_sta *sta, |
| 1582 | struct ieee80211_key_conf *keyconf) |
| 1583 | { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1584 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1585 | struct iwl_mvm_sta *mvm_sta; |
| 1586 | u8 sta_id = IWL_MVM_STATION_COUNT; |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1587 | int ret, i; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1588 | |
| 1589 | lockdep_assert_held(&mvm->mutex); |
| 1590 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1591 | /* Get the station from the mvm local station table */ |
| 1592 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1593 | |
| 1594 | IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n", |
| 1595 | keyconf->keyidx, sta_id); |
| 1596 | |
| 1597 | if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC) |
| 1598 | return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true); |
| 1599 | |
| 1600 | if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) { |
| 1601 | IWL_ERR(mvm, "offset %d not used in fw key table.\n", |
| 1602 | keyconf->hw_key_idx); |
| 1603 | return -ENOENT; |
| 1604 | } |
| 1605 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 1606 | /* track which key was deleted last */ |
| 1607 | for (i = 0; i < STA_KEY_MAX_NUM; i++) { |
| 1608 | if (mvm->fw_key_deleted[i] < U8_MAX) |
| 1609 | mvm->fw_key_deleted[i]++; |
| 1610 | } |
| 1611 | mvm->fw_key_deleted[keyconf->hw_key_idx] = 0; |
| 1612 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1613 | if (!mvm_sta) { |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1614 | IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n"); |
| 1615 | return 0; |
| 1616 | } |
| 1617 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1618 | sta_id = mvm_sta->sta_id; |
| 1619 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1620 | ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast); |
| 1621 | if (ret) |
| 1622 | return ret; |
| 1623 | |
| 1624 | /* delete WEP key twice to get rid of (now useless) offset */ |
| 1625 | if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 1626 | keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) |
| 1627 | ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast); |
| 1628 | |
| 1629 | return ret; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 1630 | } |
| 1631 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1632 | void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm, |
| 1633 | struct ieee80211_vif *vif, |
| 1634 | struct ieee80211_key_conf *keyconf, |
| 1635 | struct ieee80211_sta *sta, u32 iv32, |
| 1636 | u16 *phase1key) |
| 1637 | { |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 1638 | struct iwl_mvm_sta *mvm_sta; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1639 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1640 | |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 1641 | rcu_read_lock(); |
| 1642 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 1643 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
| 1644 | if (WARN_ON_ONCE(!mvm_sta)) |
Emmanuel Grumbach | 12f1721 | 2015-12-20 14:48:08 +0200 | [diff] [blame] | 1645 | goto unlock; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 1646 | iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 1647 | iv32, phase1key, CMD_ASYNC, keyconf->hw_key_idx); |
Emmanuel Grumbach | 12f1721 | 2015-12-20 14:48:08 +0200 | [diff] [blame] | 1648 | |
| 1649 | unlock: |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 1650 | rcu_read_unlock(); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1651 | } |
| 1652 | |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1653 | void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm, |
| 1654 | struct ieee80211_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1655 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1656 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1657 | struct iwl_mvm_add_sta_cmd cmd = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1658 | .add_modify = STA_MODE_MODIFY, |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1659 | .sta_id = mvmsta->sta_id, |
Emmanuel Grumbach | 5af0177 | 2013-06-09 12:59:24 +0300 | [diff] [blame] | 1660 | .station_flags_msk = cpu_to_le32(STA_FLG_PS), |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1661 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1662 | }; |
| 1663 | int ret; |
| 1664 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 1665 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, |
| 1666 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1667 | if (ret) |
| 1668 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 1669 | } |
| 1670 | |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1671 | void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm, |
| 1672 | struct ieee80211_sta *sta, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1673 | enum ieee80211_frame_release_type reason, |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1674 | u16 cnt, u16 tids, bool more_data, |
| 1675 | bool agg) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1676 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 1677 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1678 | struct iwl_mvm_add_sta_cmd cmd = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1679 | .add_modify = STA_MODE_MODIFY, |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1680 | .sta_id = mvmsta->sta_id, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1681 | .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT, |
| 1682 | .sleep_tx_count = cpu_to_le16(cnt), |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 1683 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1684 | }; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1685 | int tid, ret; |
| 1686 | unsigned long _tids = tids; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1687 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1688 | /* convert TIDs to ACs - we don't support TSPEC so that's OK |
| 1689 | * Note that this field is reserved and unused by firmware not |
| 1690 | * supporting GO uAPSD, so it's safe to always do this. |
| 1691 | */ |
| 1692 | for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) |
| 1693 | cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]); |
| 1694 | |
| 1695 | /* If we're releasing frames from aggregation queues then check if the |
| 1696 | * all queues combined that we're releasing frames from have |
| 1697 | * - more frames than the service period, in which case more_data |
| 1698 | * needs to be set |
| 1699 | * - fewer than 'cnt' frames, in which case we need to adjust the |
| 1700 | * firmware command (but do that unconditionally) |
| 1701 | */ |
| 1702 | if (agg) { |
| 1703 | int remaining = cnt; |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 1704 | int sleep_tx_count; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1705 | |
| 1706 | spin_lock_bh(&mvmsta->lock); |
| 1707 | for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) { |
| 1708 | struct iwl_mvm_tid_data *tid_data; |
| 1709 | u16 n_queued; |
| 1710 | |
| 1711 | tid_data = &mvmsta->tid_data[tid]; |
| 1712 | if (WARN(tid_data->state != IWL_AGG_ON && |
| 1713 | tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA, |
| 1714 | "TID %d state is %d\n", |
| 1715 | tid, tid_data->state)) { |
| 1716 | spin_unlock_bh(&mvmsta->lock); |
| 1717 | ieee80211_sta_eosp(sta); |
| 1718 | return; |
| 1719 | } |
| 1720 | |
| 1721 | n_queued = iwl_mvm_tid_queued(tid_data); |
| 1722 | if (n_queued > remaining) { |
| 1723 | more_data = true; |
| 1724 | remaining = 0; |
| 1725 | break; |
| 1726 | } |
| 1727 | remaining -= n_queued; |
| 1728 | } |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 1729 | sleep_tx_count = cnt - remaining; |
| 1730 | if (reason == IEEE80211_FRAME_RELEASE_UAPSD) |
| 1731 | mvmsta->sleep_tx_count = sleep_tx_count; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1732 | spin_unlock_bh(&mvmsta->lock); |
| 1733 | |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 1734 | cmd.sleep_tx_count = cpu_to_le16(sleep_tx_count); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1735 | if (WARN_ON(cnt - remaining == 0)) { |
| 1736 | ieee80211_sta_eosp(sta); |
| 1737 | return; |
| 1738 | } |
| 1739 | } |
| 1740 | |
| 1741 | /* Note: this is ignored by firmware not supporting GO uAPSD */ |
| 1742 | if (more_data) |
| 1743 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_MOREDATA); |
| 1744 | |
| 1745 | if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) { |
| 1746 | mvmsta->next_status_eosp = true; |
| 1747 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_PS_POLL); |
| 1748 | } else { |
| 1749 | cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_UAPSD); |
| 1750 | } |
| 1751 | |
Emmanuel Grumbach | 156f92f | 2015-11-24 14:55:18 +0200 | [diff] [blame] | 1752 | /* block the Tx queues until the FW updated the sleep Tx count */ |
| 1753 | iwl_trans_block_txq_ptrs(mvm->trans, true); |
| 1754 | |
| 1755 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, |
| 1756 | CMD_ASYNC | CMD_WANT_ASYNC_CALLBACK, |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 1757 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1758 | if (ret) |
| 1759 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 1760 | } |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1761 | |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 1762 | void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm, |
| 1763 | struct iwl_rx_cmd_buffer *rxb) |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1764 | { |
| 1765 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 1766 | struct iwl_mvm_eosp_notification *notif = (void *)pkt->data; |
| 1767 | struct ieee80211_sta *sta; |
| 1768 | u32 sta_id = le32_to_cpu(notif->sta_id); |
| 1769 | |
| 1770 | if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT)) |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 1771 | return; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1772 | |
| 1773 | rcu_read_lock(); |
| 1774 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); |
| 1775 | if (!IS_ERR_OR_NULL(sta)) |
| 1776 | ieee80211_sta_eosp(sta); |
| 1777 | rcu_read_unlock(); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 1778 | } |
Andrei Otcheretianski | 09b0ce1 | 2014-05-25 17:07:38 +0300 | [diff] [blame] | 1779 | |
| 1780 | void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm, |
| 1781 | struct iwl_mvm_sta *mvmsta, bool disable) |
| 1782 | { |
| 1783 | struct iwl_mvm_add_sta_cmd cmd = { |
| 1784 | .add_modify = STA_MODE_MODIFY, |
| 1785 | .sta_id = mvmsta->sta_id, |
| 1786 | .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0, |
| 1787 | .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX), |
| 1788 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
| 1789 | }; |
| 1790 | int ret; |
| 1791 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 1792 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, |
| 1793 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
Andrei Otcheretianski | 09b0ce1 | 2014-05-25 17:07:38 +0300 | [diff] [blame] | 1794 | if (ret) |
| 1795 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 1796 | } |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 1797 | |
| 1798 | void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm, |
| 1799 | struct ieee80211_sta *sta, |
| 1800 | bool disable) |
| 1801 | { |
| 1802 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
| 1803 | |
| 1804 | spin_lock_bh(&mvm_sta->lock); |
| 1805 | |
| 1806 | if (mvm_sta->disable_tx == disable) { |
| 1807 | spin_unlock_bh(&mvm_sta->lock); |
| 1808 | return; |
| 1809 | } |
| 1810 | |
| 1811 | mvm_sta->disable_tx = disable; |
| 1812 | |
| 1813 | /* |
Sara Sharon | 0d365ae | 2015-03-31 12:24:05 +0300 | [diff] [blame] | 1814 | * Tell mac80211 to start/stop queuing tx for this station, |
| 1815 | * but don't stop queuing if there are still pending frames |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 1816 | * for this station. |
| 1817 | */ |
| 1818 | if (disable || !atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) |
| 1819 | ieee80211_sta_block_awake(mvm->hw, sta, disable); |
| 1820 | |
| 1821 | iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable); |
| 1822 | |
| 1823 | spin_unlock_bh(&mvm_sta->lock); |
| 1824 | } |
| 1825 | |
| 1826 | void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm, |
| 1827 | struct iwl_mvm_vif *mvmvif, |
| 1828 | bool disable) |
| 1829 | { |
| 1830 | struct ieee80211_sta *sta; |
| 1831 | struct iwl_mvm_sta *mvm_sta; |
| 1832 | int i; |
| 1833 | |
| 1834 | lockdep_assert_held(&mvm->mutex); |
| 1835 | |
| 1836 | /* Block/unblock all the stations of the given mvmvif */ |
| 1837 | for (i = 0; i < IWL_MVM_STATION_COUNT; i++) { |
| 1838 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], |
| 1839 | lockdep_is_held(&mvm->mutex)); |
| 1840 | if (IS_ERR_OR_NULL(sta)) |
| 1841 | continue; |
| 1842 | |
| 1843 | mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
| 1844 | if (mvm_sta->mac_id_n_color != |
| 1845 | FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color)) |
| 1846 | continue; |
| 1847 | |
| 1848 | iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable); |
| 1849 | } |
| 1850 | } |
Luciano Coelho | dc88b4b | 2014-11-10 11:10:14 +0200 | [diff] [blame] | 1851 | |
| 1852 | void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1853 | { |
| 1854 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1855 | struct iwl_mvm_sta *mvmsta; |
| 1856 | |
| 1857 | rcu_read_lock(); |
| 1858 | |
| 1859 | mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id); |
| 1860 | |
| 1861 | if (!WARN_ON(!mvmsta)) |
| 1862 | iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true); |
| 1863 | |
| 1864 | rcu_read_unlock(); |
| 1865 | } |