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