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 | 26d6c16 | 2017-01-03 12:00:19 +0200 | [diff] [blame] | 10 | * Copyright(c) 2016 - 2017 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 | 26d6c16 | 2017-01-03 12:00:19 +0200 | [diff] [blame] | 37 | * Copyright(c) 2016 - 2017 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 | { |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 80 | if (iwl_mvm_has_new_rx_api(mvm) || |
| 81 | fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) |
| 82 | return sizeof(struct iwl_mvm_add_sta_cmd); |
| 83 | else |
| 84 | return sizeof(struct iwl_mvm_add_sta_cmd_v7); |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 85 | } |
| 86 | |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 87 | static int iwl_mvm_find_free_sta_id(struct iwl_mvm *mvm, |
| 88 | enum nl80211_iftype iftype) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 89 | { |
| 90 | int sta_id; |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 91 | u32 reserved_ids = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 92 | |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 93 | BUILD_BUG_ON(IWL_MVM_STATION_COUNT > 32); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 94 | WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)); |
| 95 | |
| 96 | lockdep_assert_held(&mvm->mutex); |
| 97 | |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 98 | /* d0i3/d3 assumes the AP's sta_id (of sta vif) is 0. reserve it. */ |
| 99 | if (iftype != NL80211_IFTYPE_STATION) |
| 100 | reserved_ids = BIT(0); |
| 101 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 102 | /* Don't take rcu_read_lock() since we are protected by mvm->mutex */ |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 103 | for (sta_id = 0; sta_id < ARRAY_SIZE(mvm->fw_id_to_mac_id); sta_id++) { |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 104 | if (BIT(sta_id) & reserved_ids) |
| 105 | continue; |
| 106 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 107 | if (!rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 108 | lockdep_is_held(&mvm->mutex))) |
| 109 | return sta_id; |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 110 | } |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 111 | return IWL_MVM_INVALID_STA; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 112 | } |
| 113 | |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 114 | /* send station add/update command to firmware */ |
| 115 | int iwl_mvm_sta_send_to_fw(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 116 | bool update, unsigned int flags) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 117 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 118 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | 4b8265a | 2014-07-13 08:58:04 +0300 | [diff] [blame] | 119 | struct iwl_mvm_add_sta_cmd add_sta_cmd = { |
| 120 | .sta_id = mvm_sta->sta_id, |
| 121 | .mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color), |
| 122 | .add_modify = update ? 1 : 0, |
| 123 | .station_flags_msk = cpu_to_le32(STA_FLG_FAT_EN_MSK | |
| 124 | STA_FLG_MIMO_EN_MSK), |
Liad Kaufman | cf0cda1 | 2015-09-24 10:44:12 +0200 | [diff] [blame] | 125 | .tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg), |
Emmanuel Grumbach | 4b8265a | 2014-07-13 08:58:04 +0300 | [diff] [blame] | 126 | }; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 127 | int ret; |
| 128 | u32 status; |
| 129 | u32 agg_size = 0, mpdu_dens = 0; |
| 130 | |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 131 | if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) |
| 132 | add_sta_cmd.station_type = mvm_sta->sta_type; |
| 133 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 134 | if (!update || (flags & STA_MODIFY_QUEUES)) { |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 135 | memcpy(&add_sta_cmd.addr, sta->addr, ETH_ALEN); |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 136 | |
Sara Sharon | bb49701 | 2016-09-29 14:52:40 +0300 | [diff] [blame] | 137 | if (!iwl_mvm_has_new_tx_api(mvm)) { |
| 138 | add_sta_cmd.tfd_queue_msk = |
| 139 | cpu_to_le32(mvm_sta->tfd_queue_msk); |
| 140 | |
| 141 | if (flags & STA_MODIFY_QUEUES) |
| 142 | add_sta_cmd.modify_mask |= STA_MODIFY_QUEUES; |
| 143 | } else { |
| 144 | WARN_ON(flags & STA_MODIFY_QUEUES); |
| 145 | } |
Johannes Berg | 7a45397 | 2013-02-12 13:10:44 +0100 | [diff] [blame] | 146 | } |
Johannes Berg | 5bc5aaa | 2013-02-12 14:35:36 +0100 | [diff] [blame] | 147 | |
| 148 | switch (sta->bandwidth) { |
| 149 | case IEEE80211_STA_RX_BW_160: |
| 150 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_160MHZ); |
| 151 | /* fall through */ |
| 152 | case IEEE80211_STA_RX_BW_80: |
| 153 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_80MHZ); |
| 154 | /* fall through */ |
| 155 | case IEEE80211_STA_RX_BW_40: |
| 156 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_40MHZ); |
| 157 | /* fall through */ |
| 158 | case IEEE80211_STA_RX_BW_20: |
| 159 | if (sta->ht_cap.ht_supported) |
| 160 | add_sta_cmd.station_flags |= |
| 161 | cpu_to_le32(STA_FLG_FAT_EN_20MHZ); |
| 162 | break; |
| 163 | } |
| 164 | |
| 165 | switch (sta->rx_nss) { |
| 166 | case 1: |
| 167 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO); |
| 168 | break; |
| 169 | case 2: |
| 170 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO2); |
| 171 | break; |
| 172 | case 3 ... 8: |
| 173 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO3); |
| 174 | break; |
| 175 | } |
| 176 | |
| 177 | switch (sta->smps_mode) { |
| 178 | case IEEE80211_SMPS_AUTOMATIC: |
| 179 | case IEEE80211_SMPS_NUM_MODES: |
| 180 | WARN_ON(1); |
| 181 | break; |
| 182 | case IEEE80211_SMPS_STATIC: |
| 183 | /* override NSS */ |
| 184 | add_sta_cmd.station_flags &= ~cpu_to_le32(STA_FLG_MIMO_EN_MSK); |
| 185 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO); |
| 186 | break; |
| 187 | case IEEE80211_SMPS_DYNAMIC: |
| 188 | add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_RTS_MIMO_PROT); |
| 189 | break; |
| 190 | case IEEE80211_SMPS_OFF: |
| 191 | /* nothing */ |
| 192 | break; |
| 193 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 194 | |
| 195 | if (sta->ht_cap.ht_supported) { |
| 196 | add_sta_cmd.station_flags_msk |= |
| 197 | cpu_to_le32(STA_FLG_MAX_AGG_SIZE_MSK | |
| 198 | STA_FLG_AGG_MPDU_DENS_MSK); |
| 199 | |
| 200 | mpdu_dens = sta->ht_cap.ampdu_density; |
| 201 | } |
| 202 | |
| 203 | if (sta->vht_cap.vht_supported) { |
| 204 | agg_size = sta->vht_cap.cap & |
| 205 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; |
| 206 | agg_size >>= |
| 207 | IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; |
| 208 | } else if (sta->ht_cap.ht_supported) { |
| 209 | agg_size = sta->ht_cap.ampdu_factor; |
| 210 | } |
| 211 | |
| 212 | add_sta_cmd.station_flags |= |
| 213 | cpu_to_le32(agg_size << STA_FLG_MAX_AGG_SIZE_SHIFT); |
| 214 | add_sta_cmd.station_flags |= |
| 215 | cpu_to_le32(mpdu_dens << STA_FLG_AGG_MPDU_DENS_SHIFT); |
Johannes Berg | 6ea29ce | 2016-12-01 16:25:30 +0100 | [diff] [blame] | 216 | if (mvm_sta->associated) |
| 217 | add_sta_cmd.assoc_id = cpu_to_le16(sta->aid); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 218 | |
Johannes Berg | 65e2548 | 2016-04-13 14:24:22 +0200 | [diff] [blame] | 219 | if (sta->wme) { |
| 220 | add_sta_cmd.modify_mask |= STA_MODIFY_UAPSD_ACS; |
| 221 | |
| 222 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) |
Emmanuel Grumbach | c80eb57 | 2017-01-12 15:43:57 +0200 | [diff] [blame] | 223 | add_sta_cmd.uapsd_acs |= BIT(AC_BK); |
Johannes Berg | 65e2548 | 2016-04-13 14:24:22 +0200 | [diff] [blame] | 224 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) |
Emmanuel Grumbach | c80eb57 | 2017-01-12 15:43:57 +0200 | [diff] [blame] | 225 | add_sta_cmd.uapsd_acs |= BIT(AC_BE); |
Johannes Berg | 65e2548 | 2016-04-13 14:24:22 +0200 | [diff] [blame] | 226 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) |
Emmanuel Grumbach | c80eb57 | 2017-01-12 15:43:57 +0200 | [diff] [blame] | 227 | add_sta_cmd.uapsd_acs |= BIT(AC_VI); |
Johannes Berg | 65e2548 | 2016-04-13 14:24:22 +0200 | [diff] [blame] | 228 | if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) |
Emmanuel Grumbach | c80eb57 | 2017-01-12 15:43:57 +0200 | [diff] [blame] | 229 | add_sta_cmd.uapsd_acs |= BIT(AC_VO); |
| 230 | add_sta_cmd.uapsd_acs |= add_sta_cmd.uapsd_acs << 4; |
Emmanuel Grumbach | e71ca5e | 2017-02-08 14:53:32 +0200 | [diff] [blame] | 231 | add_sta_cmd.sp_length = sta->max_sp ? sta->max_sp * 2 : 128; |
Johannes Berg | 65e2548 | 2016-04-13 14:24:22 +0200 | [diff] [blame] | 232 | } |
| 233 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 234 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 235 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 236 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 237 | &add_sta_cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 238 | if (ret) |
| 239 | return ret; |
| 240 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 241 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 242 | case ADD_STA_SUCCESS: |
| 243 | IWL_DEBUG_ASSOC(mvm, "ADD_STA PASSED\n"); |
| 244 | break; |
| 245 | default: |
| 246 | ret = -EIO; |
| 247 | IWL_ERR(mvm, "ADD_STA failed\n"); |
| 248 | break; |
| 249 | } |
| 250 | |
| 251 | return ret; |
| 252 | } |
| 253 | |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 254 | static void iwl_mvm_rx_agg_session_expired(unsigned long data) |
| 255 | { |
| 256 | struct iwl_mvm_baid_data __rcu **rcu_ptr = (void *)data; |
| 257 | struct iwl_mvm_baid_data *ba_data; |
| 258 | struct ieee80211_sta *sta; |
| 259 | struct iwl_mvm_sta *mvm_sta; |
| 260 | unsigned long timeout; |
| 261 | |
| 262 | rcu_read_lock(); |
| 263 | |
| 264 | ba_data = rcu_dereference(*rcu_ptr); |
| 265 | |
| 266 | if (WARN_ON(!ba_data)) |
| 267 | goto unlock; |
| 268 | |
| 269 | if (!ba_data->timeout) |
| 270 | goto unlock; |
| 271 | |
| 272 | timeout = ba_data->last_rx + TU_TO_JIFFIES(ba_data->timeout * 2); |
| 273 | if (time_is_after_jiffies(timeout)) { |
| 274 | mod_timer(&ba_data->session_timer, timeout); |
| 275 | goto unlock; |
| 276 | } |
| 277 | |
| 278 | /* Timer expired */ |
| 279 | sta = rcu_dereference(ba_data->mvm->fw_id_to_mac_id[ba_data->sta_id]); |
| 280 | mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
| 281 | ieee80211_stop_rx_ba_session_offl(mvm_sta->vif, |
| 282 | sta->addr, ba_data->tid); |
| 283 | unlock: |
| 284 | rcu_read_unlock(); |
| 285 | } |
| 286 | |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 287 | static int iwl_mvm_tdls_sta_init(struct iwl_mvm *mvm, |
| 288 | struct ieee80211_sta *sta) |
| 289 | { |
| 290 | unsigned long used_hw_queues; |
| 291 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | 5d42e7b | 2015-03-19 20:04:51 +0200 | [diff] [blame] | 292 | unsigned int wdg_timeout = |
| 293 | iwl_mvm_get_wd_timeout(mvm, NULL, true, false); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 294 | u32 ac; |
| 295 | |
| 296 | lockdep_assert_held(&mvm->mutex); |
| 297 | |
| 298 | used_hw_queues = iwl_mvm_get_used_hw_queues(mvm, NULL); |
| 299 | |
| 300 | /* Find available queues, and allocate them to the ACs */ |
| 301 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 302 | u8 queue = find_first_zero_bit(&used_hw_queues, |
| 303 | mvm->first_agg_queue); |
| 304 | |
| 305 | if (queue >= mvm->first_agg_queue) { |
| 306 | IWL_ERR(mvm, "Failed to allocate STA queue\n"); |
| 307 | return -EBUSY; |
| 308 | } |
| 309 | |
| 310 | __set_bit(queue, &used_hw_queues); |
| 311 | mvmsta->hw_queue[ac] = queue; |
| 312 | } |
| 313 | |
| 314 | /* Found a place for all queues - enable them */ |
| 315 | for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { |
| 316 | iwl_mvm_enable_ac_txq(mvm, mvmsta->hw_queue[ac], |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 317 | mvmsta->hw_queue[ac], |
Liad Kaufman | 5c1156e | 2015-07-22 17:59:53 +0300 | [diff] [blame] | 318 | iwl_mvm_ac_to_tx_fifo[ac], 0, |
| 319 | wdg_timeout); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 320 | mvmsta->tfd_queue_msk |= BIT(mvmsta->hw_queue[ac]); |
| 321 | } |
| 322 | |
| 323 | return 0; |
| 324 | } |
| 325 | |
| 326 | static void iwl_mvm_tdls_sta_deinit(struct iwl_mvm *mvm, |
| 327 | struct ieee80211_sta *sta) |
| 328 | { |
| 329 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 330 | unsigned long sta_msk; |
| 331 | int i; |
| 332 | |
| 333 | lockdep_assert_held(&mvm->mutex); |
| 334 | |
| 335 | /* disable the TDLS STA-specific queues */ |
| 336 | sta_msk = mvmsta->tfd_queue_msk; |
Emmanuel Grumbach | a4ca3ed | 2015-01-20 17:07:10 +0200 | [diff] [blame] | 337 | 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] | 338 | iwl_mvm_disable_txq(mvm, i, i, IWL_MAX_TID_COUNT, 0); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 339 | } |
| 340 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 341 | /* Disable aggregations for a bitmap of TIDs for a given station */ |
| 342 | static int iwl_mvm_invalidate_sta_queue(struct iwl_mvm *mvm, int queue, |
| 343 | unsigned long disable_agg_tids, |
| 344 | bool remove_queue) |
| 345 | { |
| 346 | struct iwl_mvm_add_sta_cmd cmd = {}; |
| 347 | struct ieee80211_sta *sta; |
| 348 | struct iwl_mvm_sta *mvmsta; |
| 349 | u32 status; |
| 350 | u8 sta_id; |
| 351 | int ret; |
| 352 | |
Sara Sharon | bb49701 | 2016-09-29 14:52:40 +0300 | [diff] [blame] | 353 | if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) |
| 354 | return -EINVAL; |
| 355 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 356 | spin_lock_bh(&mvm->queue_info_lock); |
| 357 | sta_id = mvm->queue_info[queue].ra_sta_id; |
| 358 | spin_unlock_bh(&mvm->queue_info_lock); |
| 359 | |
| 360 | rcu_read_lock(); |
| 361 | |
| 362 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); |
| 363 | |
| 364 | if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) { |
| 365 | rcu_read_unlock(); |
| 366 | return -EINVAL; |
| 367 | } |
| 368 | |
| 369 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 370 | |
| 371 | mvmsta->tid_disable_agg |= disable_agg_tids; |
| 372 | |
| 373 | cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color); |
| 374 | cmd.sta_id = mvmsta->sta_id; |
| 375 | cmd.add_modify = STA_MODE_MODIFY; |
| 376 | cmd.modify_mask = STA_MODIFY_QUEUES; |
| 377 | if (disable_agg_tids) |
| 378 | cmd.modify_mask |= STA_MODIFY_TID_DISABLE_TX; |
| 379 | if (remove_queue) |
| 380 | cmd.modify_mask |= STA_MODIFY_QUEUE_REMOVAL; |
| 381 | cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk); |
| 382 | cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg); |
| 383 | |
| 384 | rcu_read_unlock(); |
| 385 | |
| 386 | /* Notify FW of queue removal from the STA queues */ |
| 387 | status = ADD_STA_SUCCESS; |
| 388 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 389 | iwl_mvm_add_sta_cmd_size(mvm), |
| 390 | &cmd, &status); |
| 391 | |
| 392 | return ret; |
| 393 | } |
| 394 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 395 | static int iwl_mvm_get_queue_agg_tids(struct iwl_mvm *mvm, int queue) |
| 396 | { |
| 397 | struct ieee80211_sta *sta; |
| 398 | struct iwl_mvm_sta *mvmsta; |
| 399 | unsigned long tid_bitmap; |
| 400 | unsigned long agg_tids = 0; |
| 401 | s8 sta_id; |
| 402 | int tid; |
| 403 | |
| 404 | lockdep_assert_held(&mvm->mutex); |
| 405 | |
Sara Sharon | bb49701 | 2016-09-29 14:52:40 +0300 | [diff] [blame] | 406 | if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) |
| 407 | return -EINVAL; |
| 408 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 409 | spin_lock_bh(&mvm->queue_info_lock); |
| 410 | sta_id = mvm->queue_info[queue].ra_sta_id; |
| 411 | tid_bitmap = mvm->queue_info[queue].tid_bitmap; |
| 412 | spin_unlock_bh(&mvm->queue_info_lock); |
| 413 | |
| 414 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 415 | lockdep_is_held(&mvm->mutex)); |
| 416 | |
| 417 | if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) |
| 418 | return -EINVAL; |
| 419 | |
| 420 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 421 | |
| 422 | spin_lock_bh(&mvmsta->lock); |
| 423 | for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) { |
| 424 | if (mvmsta->tid_data[tid].state == IWL_AGG_ON) |
| 425 | agg_tids |= BIT(tid); |
| 426 | } |
| 427 | spin_unlock_bh(&mvmsta->lock); |
| 428 | |
| 429 | return agg_tids; |
| 430 | } |
| 431 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 432 | /* |
| 433 | * Remove a queue from a station's resources. |
| 434 | * Note that this only marks as free. It DOESN'T delete a BA agreement, and |
| 435 | * doesn't disable the queue |
| 436 | */ |
| 437 | static int iwl_mvm_remove_sta_queue_marking(struct iwl_mvm *mvm, int queue) |
| 438 | { |
| 439 | struct ieee80211_sta *sta; |
| 440 | struct iwl_mvm_sta *mvmsta; |
| 441 | unsigned long tid_bitmap; |
| 442 | unsigned long disable_agg_tids = 0; |
| 443 | u8 sta_id; |
| 444 | int tid; |
| 445 | |
| 446 | lockdep_assert_held(&mvm->mutex); |
| 447 | |
Sara Sharon | bb49701 | 2016-09-29 14:52:40 +0300 | [diff] [blame] | 448 | if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) |
| 449 | return -EINVAL; |
| 450 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 451 | spin_lock_bh(&mvm->queue_info_lock); |
| 452 | sta_id = mvm->queue_info[queue].ra_sta_id; |
| 453 | tid_bitmap = mvm->queue_info[queue].tid_bitmap; |
| 454 | spin_unlock_bh(&mvm->queue_info_lock); |
| 455 | |
| 456 | rcu_read_lock(); |
| 457 | |
| 458 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); |
| 459 | |
| 460 | if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) { |
| 461 | rcu_read_unlock(); |
| 462 | return 0; |
| 463 | } |
| 464 | |
| 465 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 466 | |
| 467 | spin_lock_bh(&mvmsta->lock); |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 468 | /* Unmap MAC queues and TIDs from this queue */ |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 469 | for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) { |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 470 | if (mvmsta->tid_data[tid].state == IWL_AGG_ON) |
| 471 | disable_agg_tids |= BIT(tid); |
Sara Sharon | 6862fce | 2017-02-22 19:34:17 +0200 | [diff] [blame] | 472 | mvmsta->tid_data[tid].txq_id = IWL_MVM_INVALID_QUEUE; |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 473 | } |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 474 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 475 | mvmsta->tfd_queue_msk &= ~BIT(queue); /* Don't use this queue anymore */ |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 476 | spin_unlock_bh(&mvmsta->lock); |
| 477 | |
| 478 | rcu_read_unlock(); |
| 479 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 480 | return disable_agg_tids; |
| 481 | } |
| 482 | |
Sara Sharon | 01796ff | 2016-11-16 17:04:36 +0200 | [diff] [blame] | 483 | static int iwl_mvm_free_inactive_queue(struct iwl_mvm *mvm, int queue, |
| 484 | bool same_sta) |
| 485 | { |
| 486 | struct iwl_mvm_sta *mvmsta; |
| 487 | u8 txq_curr_ac, sta_id, tid; |
| 488 | unsigned long disable_agg_tids = 0; |
| 489 | int ret; |
| 490 | |
| 491 | lockdep_assert_held(&mvm->mutex); |
| 492 | |
Sara Sharon | bb49701 | 2016-09-29 14:52:40 +0300 | [diff] [blame] | 493 | if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) |
| 494 | return -EINVAL; |
| 495 | |
Sara Sharon | 01796ff | 2016-11-16 17:04:36 +0200 | [diff] [blame] | 496 | spin_lock_bh(&mvm->queue_info_lock); |
| 497 | txq_curr_ac = mvm->queue_info[queue].mac80211_ac; |
| 498 | sta_id = mvm->queue_info[queue].ra_sta_id; |
| 499 | tid = mvm->queue_info[queue].txq_tid; |
| 500 | spin_unlock_bh(&mvm->queue_info_lock); |
| 501 | |
| 502 | mvmsta = iwl_mvm_sta_from_staid_protected(mvm, sta_id); |
Sharon Dvir | e3df1e4 | 2017-02-21 10:41:31 +0200 | [diff] [blame] | 503 | if (WARN_ON(!mvmsta)) |
| 504 | return -EINVAL; |
Sara Sharon | 01796ff | 2016-11-16 17:04:36 +0200 | [diff] [blame] | 505 | |
| 506 | disable_agg_tids = iwl_mvm_remove_sta_queue_marking(mvm, queue); |
| 507 | /* Disable the queue */ |
| 508 | if (disable_agg_tids) |
| 509 | iwl_mvm_invalidate_sta_queue(mvm, queue, |
| 510 | disable_agg_tids, false); |
| 511 | |
| 512 | ret = iwl_mvm_disable_txq(mvm, queue, |
| 513 | mvmsta->vif->hw_queue[txq_curr_ac], |
| 514 | tid, 0); |
| 515 | if (ret) { |
| 516 | /* Re-mark the inactive queue as inactive */ |
| 517 | spin_lock_bh(&mvm->queue_info_lock); |
| 518 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_INACTIVE; |
| 519 | spin_unlock_bh(&mvm->queue_info_lock); |
| 520 | IWL_ERR(mvm, |
| 521 | "Failed to free inactive queue %d (ret=%d)\n", |
| 522 | queue, ret); |
| 523 | |
| 524 | return ret; |
| 525 | } |
| 526 | |
| 527 | /* If TXQ is allocated to another STA, update removal in FW */ |
| 528 | if (!same_sta) |
| 529 | iwl_mvm_invalidate_sta_queue(mvm, queue, 0, true); |
| 530 | |
| 531 | return 0; |
| 532 | } |
| 533 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 534 | static int iwl_mvm_get_shared_queue(struct iwl_mvm *mvm, |
| 535 | unsigned long tfd_queue_mask, u8 ac) |
| 536 | { |
| 537 | int queue = 0; |
| 538 | u8 ac_to_queue[IEEE80211_NUM_ACS]; |
| 539 | int i; |
| 540 | |
| 541 | lockdep_assert_held(&mvm->queue_info_lock); |
Sara Sharon | bb49701 | 2016-09-29 14:52:40 +0300 | [diff] [blame] | 542 | if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) |
| 543 | return -EINVAL; |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 544 | |
| 545 | memset(&ac_to_queue, IEEE80211_INVAL_HW_QUEUE, sizeof(ac_to_queue)); |
| 546 | |
| 547 | /* See what ACs the existing queues for this STA have */ |
| 548 | for_each_set_bit(i, &tfd_queue_mask, IWL_MVM_DQA_MAX_DATA_QUEUE) { |
| 549 | /* Only DATA queues can be shared */ |
| 550 | if (i < IWL_MVM_DQA_MIN_DATA_QUEUE && |
| 551 | i != IWL_MVM_DQA_BSS_CLIENT_QUEUE) |
| 552 | continue; |
| 553 | |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 554 | /* Don't try and take queues being reconfigured */ |
| 555 | if (mvm->queue_info[queue].status == |
| 556 | IWL_MVM_QUEUE_RECONFIGURING) |
| 557 | continue; |
| 558 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 559 | ac_to_queue[mvm->queue_info[i].mac80211_ac] = i; |
| 560 | } |
| 561 | |
| 562 | /* |
| 563 | * The queue to share is chosen only from DATA queues as follows (in |
| 564 | * descending priority): |
| 565 | * 1. An AC_BE queue |
| 566 | * 2. Same AC queue |
| 567 | * 3. Highest AC queue that is lower than new AC |
| 568 | * 4. Any existing AC (there always is at least 1 DATA queue) |
| 569 | */ |
| 570 | |
| 571 | /* Priority 1: An AC_BE queue */ |
| 572 | if (ac_to_queue[IEEE80211_AC_BE] != IEEE80211_INVAL_HW_QUEUE) |
| 573 | queue = ac_to_queue[IEEE80211_AC_BE]; |
| 574 | /* Priority 2: Same AC queue */ |
| 575 | else if (ac_to_queue[ac] != IEEE80211_INVAL_HW_QUEUE) |
| 576 | queue = ac_to_queue[ac]; |
| 577 | /* Priority 3a: If new AC is VO and VI exists - use VI */ |
| 578 | else if (ac == IEEE80211_AC_VO && |
| 579 | ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE) |
| 580 | queue = ac_to_queue[IEEE80211_AC_VI]; |
| 581 | /* Priority 3b: No BE so only AC less than the new one is BK */ |
| 582 | else if (ac_to_queue[IEEE80211_AC_BK] != IEEE80211_INVAL_HW_QUEUE) |
| 583 | queue = ac_to_queue[IEEE80211_AC_BK]; |
| 584 | /* Priority 4a: No BE nor BK - use VI if exists */ |
| 585 | else if (ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE) |
| 586 | queue = ac_to_queue[IEEE80211_AC_VI]; |
| 587 | /* Priority 4b: No BE, BK nor VI - use VO if exists */ |
| 588 | else if (ac_to_queue[IEEE80211_AC_VO] != IEEE80211_INVAL_HW_QUEUE) |
| 589 | queue = ac_to_queue[IEEE80211_AC_VO]; |
| 590 | |
| 591 | /* Make sure queue found (or not) is legal */ |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 592 | if (!iwl_mvm_is_dqa_data_queue(mvm, queue) && |
| 593 | !iwl_mvm_is_dqa_mgmt_queue(mvm, queue) && |
| 594 | (queue != IWL_MVM_DQA_BSS_CLIENT_QUEUE)) { |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 595 | IWL_ERR(mvm, "No DATA queues available to share\n"); |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 596 | return -ENOSPC; |
| 597 | } |
| 598 | |
| 599 | /* Make sure the queue isn't in the middle of being reconfigured */ |
| 600 | if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_RECONFIGURING) { |
| 601 | IWL_ERR(mvm, |
| 602 | "TXQ %d is in the middle of re-config - try again\n", |
| 603 | queue); |
| 604 | return -EBUSY; |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 605 | } |
| 606 | |
| 607 | return queue; |
| 608 | } |
| 609 | |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 610 | /* |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 611 | * If a given queue has a higher AC than the TID stream that is being compared |
| 612 | * to, the queue needs to be redirected to the lower AC. This function does that |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 613 | * in such a case, otherwise - if no redirection required - it does nothing, |
| 614 | * unless the %force param is true. |
| 615 | */ |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 616 | int iwl_mvm_scd_queue_redirect(struct iwl_mvm *mvm, int queue, int tid, |
| 617 | int ac, int ssn, unsigned int wdg_timeout, |
| 618 | bool force) |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 619 | { |
| 620 | struct iwl_scd_txq_cfg_cmd cmd = { |
| 621 | .scd_queue = queue, |
Liad Kaufman | f7c692d | 2016-03-08 10:41:32 +0200 | [diff] [blame] | 622 | .action = SCD_CFG_DISABLE_QUEUE, |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 623 | }; |
| 624 | bool shared_queue; |
| 625 | unsigned long mq; |
| 626 | int ret; |
| 627 | |
Sara Sharon | bb49701 | 2016-09-29 14:52:40 +0300 | [diff] [blame] | 628 | if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) |
| 629 | return -EINVAL; |
| 630 | |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 631 | /* |
| 632 | * If the AC is lower than current one - FIFO needs to be redirected to |
| 633 | * the lowest one of the streams in the queue. Check if this is needed |
| 634 | * here. |
| 635 | * Notice that the enum ieee80211_ac_numbers is "flipped", so BK is with |
| 636 | * value 3 and VO with value 0, so to check if ac X is lower than ac Y |
| 637 | * we need to check if the numerical value of X is LARGER than of Y. |
| 638 | */ |
| 639 | spin_lock_bh(&mvm->queue_info_lock); |
| 640 | if (ac <= mvm->queue_info[queue].mac80211_ac && !force) { |
| 641 | spin_unlock_bh(&mvm->queue_info_lock); |
| 642 | |
| 643 | IWL_DEBUG_TX_QUEUES(mvm, |
| 644 | "No redirection needed on TXQ #%d\n", |
| 645 | queue); |
| 646 | return 0; |
| 647 | } |
| 648 | |
| 649 | cmd.sta_id = mvm->queue_info[queue].ra_sta_id; |
| 650 | cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[mvm->queue_info[queue].mac80211_ac]; |
Liad Kaufman | edbe961 | 2016-02-02 15:43:32 +0200 | [diff] [blame] | 651 | cmd.tid = mvm->queue_info[queue].txq_tid; |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 652 | mq = mvm->hw_queue_to_mac80211[queue]; |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 653 | shared_queue = (mvm->queue_info[queue].hw_queue_refcount > 1); |
| 654 | spin_unlock_bh(&mvm->queue_info_lock); |
| 655 | |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 656 | IWL_DEBUG_TX_QUEUES(mvm, "Redirecting TXQ #%d to FIFO #%d\n", |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 657 | queue, iwl_mvm_ac_to_tx_fifo[ac]); |
| 658 | |
| 659 | /* Stop MAC queues and wait for this queue to empty */ |
| 660 | iwl_mvm_stop_mac_queues(mvm, mq); |
Sara Sharon | a1a5787 | 2017-03-05 11:38:58 +0200 | [diff] [blame] | 661 | ret = iwl_trans_wait_tx_queues_empty(mvm->trans, BIT(queue)); |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 662 | if (ret) { |
| 663 | IWL_ERR(mvm, "Error draining queue %d before reconfig\n", |
| 664 | queue); |
| 665 | ret = -EIO; |
| 666 | goto out; |
| 667 | } |
| 668 | |
| 669 | /* Before redirecting the queue we need to de-activate it */ |
| 670 | iwl_trans_txq_disable(mvm->trans, queue, false); |
| 671 | ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd); |
| 672 | if (ret) |
| 673 | IWL_ERR(mvm, "Failed SCD disable TXQ %d (ret=%d)\n", queue, |
| 674 | ret); |
| 675 | |
| 676 | /* Make sure the SCD wrptr is correctly set before reconfiguring */ |
Sara Sharon | ca3b9c6 | 2016-06-30 16:14:02 +0300 | [diff] [blame] | 677 | iwl_trans_txq_enable_cfg(mvm->trans, queue, ssn, NULL, wdg_timeout); |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 678 | |
Liad Kaufman | edbe961 | 2016-02-02 15:43:32 +0200 | [diff] [blame] | 679 | /* Update the TID "owner" of the queue */ |
| 680 | spin_lock_bh(&mvm->queue_info_lock); |
| 681 | mvm->queue_info[queue].txq_tid = tid; |
| 682 | spin_unlock_bh(&mvm->queue_info_lock); |
| 683 | |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 684 | /* TODO: Work-around SCD bug when moving back by multiples of 0x40 */ |
| 685 | |
| 686 | /* Redirect to lower AC */ |
| 687 | iwl_mvm_reconfig_scd(mvm, queue, iwl_mvm_ac_to_tx_fifo[ac], |
| 688 | cmd.sta_id, tid, LINK_QUAL_AGG_FRAME_LIMIT_DEF, |
| 689 | ssn); |
| 690 | |
| 691 | /* Update AC marking of the queue */ |
| 692 | spin_lock_bh(&mvm->queue_info_lock); |
| 693 | mvm->queue_info[queue].mac80211_ac = ac; |
| 694 | spin_unlock_bh(&mvm->queue_info_lock); |
| 695 | |
| 696 | /* |
| 697 | * Mark queue as shared in transport if shared |
| 698 | * Note this has to be done after queue enablement because enablement |
| 699 | * can also set this value, and there is no indication there to shared |
| 700 | * queues |
| 701 | */ |
| 702 | if (shared_queue) |
| 703 | iwl_trans_txq_set_shared_mode(mvm->trans, queue, true); |
| 704 | |
| 705 | out: |
| 706 | /* Continue using the MAC queues */ |
| 707 | iwl_mvm_start_mac_queues(mvm, mq); |
| 708 | |
| 709 | return ret; |
| 710 | } |
| 711 | |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 712 | static int iwl_mvm_sta_alloc_queue_tvqm(struct iwl_mvm *mvm, |
| 713 | struct ieee80211_sta *sta, u8 ac, |
| 714 | int tid) |
| 715 | { |
| 716 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 717 | unsigned int wdg_timeout = |
| 718 | iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false); |
| 719 | u8 mac_queue = mvmsta->vif->hw_queue[ac]; |
| 720 | int queue = -1; |
| 721 | |
| 722 | lockdep_assert_held(&mvm->mutex); |
| 723 | |
| 724 | IWL_DEBUG_TX_QUEUES(mvm, |
| 725 | "Allocating queue for sta %d on tid %d\n", |
| 726 | mvmsta->sta_id, tid); |
| 727 | queue = iwl_mvm_tvqm_enable_txq(mvm, mac_queue, mvmsta->sta_id, tid, |
| 728 | wdg_timeout); |
| 729 | if (queue < 0) |
| 730 | return queue; |
| 731 | |
| 732 | IWL_DEBUG_TX_QUEUES(mvm, "Allocated queue is %d\n", queue); |
| 733 | |
| 734 | spin_lock_bh(&mvmsta->lock); |
| 735 | mvmsta->tid_data[tid].txq_id = queue; |
| 736 | mvmsta->tid_data[tid].is_tid_active = true; |
| 737 | mvmsta->tfd_queue_msk |= BIT(queue); |
| 738 | spin_unlock_bh(&mvmsta->lock); |
| 739 | |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 740 | return 0; |
| 741 | } |
| 742 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 743 | static int iwl_mvm_sta_alloc_queue(struct iwl_mvm *mvm, |
| 744 | struct ieee80211_sta *sta, u8 ac, int tid, |
| 745 | struct ieee80211_hdr *hdr) |
| 746 | { |
| 747 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 748 | struct iwl_trans_txq_scd_cfg cfg = { |
| 749 | .fifo = iwl_mvm_ac_to_tx_fifo[ac], |
| 750 | .sta_id = mvmsta->sta_id, |
| 751 | .tid = tid, |
| 752 | .frame_limit = IWL_FRAME_LIMIT, |
| 753 | }; |
| 754 | unsigned int wdg_timeout = |
| 755 | iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false); |
| 756 | u8 mac_queue = mvmsta->vif->hw_queue[ac]; |
| 757 | int queue = -1; |
Sara Sharon | 01796ff | 2016-11-16 17:04:36 +0200 | [diff] [blame] | 758 | bool using_inactive_queue = false, same_sta = false; |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 759 | unsigned long disable_agg_tids = 0; |
| 760 | enum iwl_mvm_agg_state queue_state; |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 761 | bool shared_queue = false; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 762 | int ssn; |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 763 | unsigned long tfd_queue_mask; |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 764 | int ret; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 765 | |
| 766 | lockdep_assert_held(&mvm->mutex); |
| 767 | |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 768 | if (iwl_mvm_has_new_tx_api(mvm)) |
| 769 | return iwl_mvm_sta_alloc_queue_tvqm(mvm, sta, ac, tid); |
| 770 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 771 | spin_lock_bh(&mvmsta->lock); |
| 772 | tfd_queue_mask = mvmsta->tfd_queue_msk; |
| 773 | spin_unlock_bh(&mvmsta->lock); |
| 774 | |
Liad Kaufman | d2515a9 | 2016-03-23 16:31:08 +0200 | [diff] [blame] | 775 | spin_lock_bh(&mvm->queue_info_lock); |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 776 | |
| 777 | /* |
| 778 | * Non-QoS, QoS NDP and MGMT frames should go to a MGMT queue, if one |
| 779 | * exists |
| 780 | */ |
| 781 | if (!ieee80211_is_data_qos(hdr->frame_control) || |
| 782 | ieee80211_is_qos_nullfunc(hdr->frame_control)) { |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 783 | queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id, |
| 784 | IWL_MVM_DQA_MIN_MGMT_QUEUE, |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 785 | IWL_MVM_DQA_MAX_MGMT_QUEUE); |
| 786 | if (queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE) |
| 787 | IWL_DEBUG_TX_QUEUES(mvm, "Found free MGMT queue #%d\n", |
| 788 | queue); |
| 789 | |
| 790 | /* If no such queue is found, we'll use a DATA queue instead */ |
| 791 | } |
| 792 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 793 | if ((queue < 0 && mvmsta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) && |
| 794 | (mvm->queue_info[mvmsta->reserved_queue].status == |
| 795 | IWL_MVM_QUEUE_RESERVED || |
| 796 | mvm->queue_info[mvmsta->reserved_queue].status == |
| 797 | IWL_MVM_QUEUE_INACTIVE)) { |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 798 | queue = mvmsta->reserved_queue; |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 799 | mvm->queue_info[queue].reserved = true; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 800 | IWL_DEBUG_TX_QUEUES(mvm, "Using reserved queue #%d\n", queue); |
| 801 | } |
| 802 | |
| 803 | if (queue < 0) |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 804 | queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id, |
| 805 | IWL_MVM_DQA_MIN_DATA_QUEUE, |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 806 | IWL_MVM_DQA_MAX_DATA_QUEUE); |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 807 | |
| 808 | /* |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 809 | * Check if this queue is already allocated but inactive. |
| 810 | * In such a case, we'll need to first free this queue before enabling |
| 811 | * it again, so we'll mark it as reserved to make sure no new traffic |
| 812 | * arrives on it |
| 813 | */ |
| 814 | if (queue > 0 && |
| 815 | mvm->queue_info[queue].status == IWL_MVM_QUEUE_INACTIVE) { |
| 816 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED; |
| 817 | using_inactive_queue = true; |
Sara Sharon | 01796ff | 2016-11-16 17:04:36 +0200 | [diff] [blame] | 818 | same_sta = mvm->queue_info[queue].ra_sta_id == mvmsta->sta_id; |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 819 | IWL_DEBUG_TX_QUEUES(mvm, |
| 820 | "Re-assigning TXQ %d: sta_id=%d, tid=%d\n", |
| 821 | queue, mvmsta->sta_id, tid); |
| 822 | } |
| 823 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 824 | /* No free queue - we'll have to share */ |
| 825 | if (queue <= 0) { |
| 826 | queue = iwl_mvm_get_shared_queue(mvm, tfd_queue_mask, ac); |
| 827 | if (queue > 0) { |
| 828 | shared_queue = true; |
| 829 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_SHARED; |
| 830 | } |
| 831 | } |
| 832 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 833 | /* |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 834 | * Mark TXQ as ready, even though it hasn't been fully configured yet, |
| 835 | * to make sure no one else takes it. |
| 836 | * This will allow avoiding re-acquiring the lock at the end of the |
| 837 | * configuration. On error we'll mark it back as free. |
| 838 | */ |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 839 | if ((queue > 0) && !shared_queue) |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 840 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 841 | |
Liad Kaufman | d2515a9 | 2016-03-23 16:31:08 +0200 | [diff] [blame] | 842 | spin_unlock_bh(&mvm->queue_info_lock); |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 843 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 844 | /* This shouldn't happen - out of queues */ |
| 845 | if (WARN_ON(queue <= 0)) { |
| 846 | IWL_ERR(mvm, "No available queues for tid %d on sta_id %d\n", |
| 847 | tid, cfg.sta_id); |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 848 | return queue; |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 849 | } |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 850 | |
| 851 | /* |
| 852 | * Actual en/disablement of aggregations is through the ADD_STA HCMD, |
| 853 | * but for configuring the SCD to send A-MPDUs we need to mark the queue |
| 854 | * as aggregatable. |
| 855 | * Mark all DATA queues as allowing to be aggregated at some point |
| 856 | */ |
Liad Kaufman | d5216a2 | 2015-08-09 15:50:51 +0300 | [diff] [blame] | 857 | cfg.aggregate = (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE || |
| 858 | queue == IWL_MVM_DQA_BSS_CLIENT_QUEUE); |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 859 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 860 | /* |
| 861 | * If this queue was previously inactive (idle) - we need to free it |
| 862 | * first |
| 863 | */ |
| 864 | if (using_inactive_queue) { |
Sara Sharon | 01796ff | 2016-11-16 17:04:36 +0200 | [diff] [blame] | 865 | ret = iwl_mvm_free_inactive_queue(mvm, queue, same_sta); |
| 866 | if (ret) |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 867 | return ret; |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 868 | } |
| 869 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 870 | IWL_DEBUG_TX_QUEUES(mvm, |
| 871 | "Allocating %squeue #%d to sta %d on tid %d\n", |
| 872 | shared_queue ? "shared " : "", queue, |
| 873 | mvmsta->sta_id, tid); |
| 874 | |
| 875 | if (shared_queue) { |
| 876 | /* Disable any open aggs on this queue */ |
| 877 | disable_agg_tids = iwl_mvm_get_queue_agg_tids(mvm, queue); |
| 878 | |
| 879 | if (disable_agg_tids) { |
| 880 | IWL_DEBUG_TX_QUEUES(mvm, "Disabling aggs on queue %d\n", |
| 881 | queue); |
| 882 | iwl_mvm_invalidate_sta_queue(mvm, queue, |
| 883 | disable_agg_tids, false); |
| 884 | } |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 885 | } |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 886 | |
| 887 | ssn = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl)); |
| 888 | iwl_mvm_enable_txq(mvm, queue, mac_queue, ssn, &cfg, |
| 889 | wdg_timeout); |
| 890 | |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 891 | /* |
| 892 | * Mark queue as shared in transport if shared |
| 893 | * Note this has to be done after queue enablement because enablement |
| 894 | * can also set this value, and there is no indication there to shared |
| 895 | * queues |
| 896 | */ |
| 897 | if (shared_queue) |
| 898 | iwl_trans_txq_set_shared_mode(mvm->trans, queue, true); |
| 899 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 900 | spin_lock_bh(&mvmsta->lock); |
| 901 | mvmsta->tid_data[tid].txq_id = queue; |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 902 | mvmsta->tid_data[tid].is_tid_active = true; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 903 | mvmsta->tfd_queue_msk |= BIT(queue); |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 904 | queue_state = mvmsta->tid_data[tid].state; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 905 | |
| 906 | if (mvmsta->reserved_queue == queue) |
| 907 | mvmsta->reserved_queue = IEEE80211_INVAL_HW_QUEUE; |
| 908 | spin_unlock_bh(&mvmsta->lock); |
| 909 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 910 | if (!shared_queue) { |
| 911 | ret = iwl_mvm_sta_send_to_fw(mvm, sta, true, STA_MODIFY_QUEUES); |
| 912 | if (ret) |
| 913 | goto out_err; |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 914 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 915 | /* If we need to re-enable aggregations... */ |
| 916 | if (queue_state == IWL_AGG_ON) { |
| 917 | ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true); |
| 918 | if (ret) |
| 919 | goto out_err; |
| 920 | } |
Liad Kaufman | 58f2cc5 | 2015-09-30 16:44:28 +0200 | [diff] [blame] | 921 | } else { |
| 922 | /* Redirect queue, if needed */ |
| 923 | ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid, ac, ssn, |
| 924 | wdg_timeout, false); |
| 925 | if (ret) |
| 926 | goto out_err; |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 927 | } |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 928 | |
Liad Kaufman | 42db09c | 2016-05-02 14:01:14 +0300 | [diff] [blame] | 929 | return 0; |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 930 | |
| 931 | out_err: |
| 932 | iwl_mvm_disable_txq(mvm, queue, mac_queue, tid, 0); |
| 933 | |
| 934 | return ret; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 935 | } |
| 936 | |
Liad Kaufman | 19aefa4 | 2016-03-08 14:29:51 +0200 | [diff] [blame] | 937 | static void iwl_mvm_change_queue_owner(struct iwl_mvm *mvm, int queue) |
| 938 | { |
| 939 | struct iwl_scd_txq_cfg_cmd cmd = { |
| 940 | .scd_queue = queue, |
| 941 | .action = SCD_CFG_UPDATE_QUEUE_TID, |
| 942 | }; |
Liad Kaufman | 19aefa4 | 2016-03-08 14:29:51 +0200 | [diff] [blame] | 943 | int tid; |
| 944 | unsigned long tid_bitmap; |
| 945 | int ret; |
| 946 | |
| 947 | lockdep_assert_held(&mvm->mutex); |
| 948 | |
Sara Sharon | bb49701 | 2016-09-29 14:52:40 +0300 | [diff] [blame] | 949 | if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) |
| 950 | return; |
| 951 | |
Liad Kaufman | 19aefa4 | 2016-03-08 14:29:51 +0200 | [diff] [blame] | 952 | spin_lock_bh(&mvm->queue_info_lock); |
Liad Kaufman | 19aefa4 | 2016-03-08 14:29:51 +0200 | [diff] [blame] | 953 | tid_bitmap = mvm->queue_info[queue].tid_bitmap; |
| 954 | spin_unlock_bh(&mvm->queue_info_lock); |
| 955 | |
| 956 | if (WARN(!tid_bitmap, "TXQ %d has no tids assigned to it\n", queue)) |
| 957 | return; |
| 958 | |
| 959 | /* Find any TID for queue */ |
| 960 | tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1); |
| 961 | cmd.tid = tid; |
| 962 | cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]]; |
| 963 | |
| 964 | ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd); |
Liad Kaufman | 341ca40 | 2016-09-18 14:51:59 +0300 | [diff] [blame] | 965 | if (ret) { |
Liad Kaufman | 19aefa4 | 2016-03-08 14:29:51 +0200 | [diff] [blame] | 966 | IWL_ERR(mvm, "Failed to update owner of TXQ %d (ret=%d)\n", |
| 967 | queue, ret); |
Liad Kaufman | 341ca40 | 2016-09-18 14:51:59 +0300 | [diff] [blame] | 968 | return; |
| 969 | } |
| 970 | |
| 971 | spin_lock_bh(&mvm->queue_info_lock); |
| 972 | mvm->queue_info[queue].txq_tid = tid; |
| 973 | spin_unlock_bh(&mvm->queue_info_lock); |
| 974 | IWL_DEBUG_TX_QUEUES(mvm, "Changed TXQ %d ownership to tid %d\n", |
| 975 | queue, tid); |
Liad Kaufman | 19aefa4 | 2016-03-08 14:29:51 +0200 | [diff] [blame] | 976 | } |
| 977 | |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 978 | static void iwl_mvm_unshare_queue(struct iwl_mvm *mvm, int queue) |
| 979 | { |
| 980 | struct ieee80211_sta *sta; |
| 981 | struct iwl_mvm_sta *mvmsta; |
| 982 | s8 sta_id; |
| 983 | int tid = -1; |
| 984 | unsigned long tid_bitmap; |
| 985 | unsigned int wdg_timeout; |
| 986 | int ssn; |
| 987 | int ret = true; |
| 988 | |
Sara Sharon | bb49701 | 2016-09-29 14:52:40 +0300 | [diff] [blame] | 989 | /* queue sharing is disabled on new TX path */ |
| 990 | if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) |
| 991 | return; |
| 992 | |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 993 | lockdep_assert_held(&mvm->mutex); |
| 994 | |
| 995 | spin_lock_bh(&mvm->queue_info_lock); |
| 996 | sta_id = mvm->queue_info[queue].ra_sta_id; |
| 997 | tid_bitmap = mvm->queue_info[queue].tid_bitmap; |
| 998 | spin_unlock_bh(&mvm->queue_info_lock); |
| 999 | |
| 1000 | /* Find TID for queue, and make sure it is the only one on the queue */ |
| 1001 | tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1); |
| 1002 | if (tid_bitmap != BIT(tid)) { |
| 1003 | IWL_ERR(mvm, "Failed to unshare q %d, active tids=0x%lx\n", |
| 1004 | queue, tid_bitmap); |
| 1005 | return; |
| 1006 | } |
| 1007 | |
| 1008 | IWL_DEBUG_TX_QUEUES(mvm, "Unsharing TXQ %d, keeping tid %d\n", queue, |
| 1009 | tid); |
| 1010 | |
| 1011 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 1012 | lockdep_is_held(&mvm->mutex)); |
| 1013 | |
| 1014 | if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) |
| 1015 | return; |
| 1016 | |
| 1017 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 1018 | wdg_timeout = iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false); |
| 1019 | |
| 1020 | ssn = IEEE80211_SEQ_TO_SN(mvmsta->tid_data[tid].seq_number); |
| 1021 | |
| 1022 | ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid, |
| 1023 | tid_to_mac80211_ac[tid], ssn, |
| 1024 | wdg_timeout, true); |
| 1025 | if (ret) { |
| 1026 | IWL_ERR(mvm, "Failed to redirect TXQ %d\n", queue); |
| 1027 | return; |
| 1028 | } |
| 1029 | |
| 1030 | /* If aggs should be turned back on - do it */ |
| 1031 | if (mvmsta->tid_data[tid].state == IWL_AGG_ON) { |
Emmanuel Grumbach | 9cd70e8 | 2016-09-20 13:40:33 +0300 | [diff] [blame] | 1032 | struct iwl_mvm_add_sta_cmd cmd = {0}; |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 1033 | |
| 1034 | mvmsta->tid_disable_agg &= ~BIT(tid); |
| 1035 | |
| 1036 | cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color); |
| 1037 | cmd.sta_id = mvmsta->sta_id; |
| 1038 | cmd.add_modify = STA_MODE_MODIFY; |
| 1039 | cmd.modify_mask = STA_MODIFY_TID_DISABLE_TX; |
| 1040 | cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk); |
| 1041 | cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg); |
| 1042 | |
| 1043 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, |
| 1044 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
| 1045 | if (!ret) { |
| 1046 | IWL_DEBUG_TX_QUEUES(mvm, |
| 1047 | "TXQ #%d is now aggregated again\n", |
| 1048 | queue); |
| 1049 | |
| 1050 | /* Mark queue intenally as aggregating again */ |
| 1051 | iwl_trans_txq_set_shared_mode(mvm->trans, queue, false); |
| 1052 | } |
| 1053 | } |
| 1054 | |
| 1055 | spin_lock_bh(&mvm->queue_info_lock); |
| 1056 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY; |
| 1057 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1058 | } |
| 1059 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1060 | static inline u8 iwl_mvm_tid_to_ac_queue(int tid) |
| 1061 | { |
| 1062 | if (tid == IWL_MAX_TID_COUNT) |
| 1063 | return IEEE80211_AC_VO; /* MGMT */ |
| 1064 | |
| 1065 | return tid_to_mac80211_ac[tid]; |
| 1066 | } |
| 1067 | |
| 1068 | static void iwl_mvm_tx_deferred_stream(struct iwl_mvm *mvm, |
| 1069 | struct ieee80211_sta *sta, int tid) |
| 1070 | { |
| 1071 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 1072 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
| 1073 | struct sk_buff *skb; |
| 1074 | struct ieee80211_hdr *hdr; |
| 1075 | struct sk_buff_head deferred_tx; |
| 1076 | u8 mac_queue; |
| 1077 | bool no_queue = false; /* Marks if there is a problem with the queue */ |
| 1078 | u8 ac; |
| 1079 | |
| 1080 | lockdep_assert_held(&mvm->mutex); |
| 1081 | |
| 1082 | skb = skb_peek(&tid_data->deferred_tx_frames); |
| 1083 | if (!skb) |
| 1084 | return; |
| 1085 | hdr = (void *)skb->data; |
| 1086 | |
| 1087 | ac = iwl_mvm_tid_to_ac_queue(tid); |
| 1088 | mac_queue = IEEE80211_SKB_CB(skb)->hw_queue; |
| 1089 | |
Sara Sharon | 6862fce | 2017-02-22 19:34:17 +0200 | [diff] [blame] | 1090 | if (tid_data->txq_id == IWL_MVM_INVALID_QUEUE && |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1091 | iwl_mvm_sta_alloc_queue(mvm, sta, ac, tid, hdr)) { |
| 1092 | IWL_ERR(mvm, |
| 1093 | "Can't alloc TXQ for sta %d tid %d - dropping frame\n", |
| 1094 | mvmsta->sta_id, tid); |
| 1095 | |
| 1096 | /* |
| 1097 | * Mark queue as problematic so later the deferred traffic is |
| 1098 | * freed, as we can do nothing with it |
| 1099 | */ |
| 1100 | no_queue = true; |
| 1101 | } |
| 1102 | |
| 1103 | __skb_queue_head_init(&deferred_tx); |
| 1104 | |
Liad Kaufman | d2515a9 | 2016-03-23 16:31:08 +0200 | [diff] [blame] | 1105 | /* Disable bottom-halves when entering TX path */ |
| 1106 | local_bh_disable(); |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1107 | spin_lock(&mvmsta->lock); |
| 1108 | skb_queue_splice_init(&tid_data->deferred_tx_frames, &deferred_tx); |
Liad Kaufman | ad5de73 | 2016-09-27 16:01:10 +0300 | [diff] [blame] | 1109 | mvmsta->deferred_traffic_tid_map &= ~BIT(tid); |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1110 | spin_unlock(&mvmsta->lock); |
| 1111 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1112 | while ((skb = __skb_dequeue(&deferred_tx))) |
| 1113 | if (no_queue || iwl_mvm_tx_skb(mvm, skb, sta)) |
| 1114 | ieee80211_free_txskb(mvm->hw, skb); |
| 1115 | local_bh_enable(); |
| 1116 | |
| 1117 | /* Wake queue */ |
| 1118 | iwl_mvm_start_mac_queues(mvm, BIT(mac_queue)); |
| 1119 | } |
| 1120 | |
| 1121 | void iwl_mvm_add_new_dqa_stream_wk(struct work_struct *wk) |
| 1122 | { |
| 1123 | struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, |
| 1124 | add_stream_wk); |
| 1125 | struct ieee80211_sta *sta; |
| 1126 | struct iwl_mvm_sta *mvmsta; |
| 1127 | unsigned long deferred_tid_traffic; |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 1128 | int queue, sta_id, tid; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1129 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 1130 | /* Check inactivity of queues */ |
| 1131 | iwl_mvm_inactivity_check(mvm); |
| 1132 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1133 | mutex_lock(&mvm->mutex); |
| 1134 | |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 1135 | /* No queue reconfiguration in TVQM mode */ |
| 1136 | if (iwl_mvm_has_new_tx_api(mvm)) |
| 1137 | goto alloc_queues; |
| 1138 | |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 1139 | /* Reconfigure queues requiring reconfiguation */ |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 1140 | for (queue = 0; queue < ARRAY_SIZE(mvm->queue_info); queue++) { |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 1141 | bool reconfig; |
Liad Kaufman | 19aefa4 | 2016-03-08 14:29:51 +0200 | [diff] [blame] | 1142 | bool change_owner; |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 1143 | |
| 1144 | spin_lock_bh(&mvm->queue_info_lock); |
| 1145 | reconfig = (mvm->queue_info[queue].status == |
| 1146 | IWL_MVM_QUEUE_RECONFIGURING); |
Liad Kaufman | 19aefa4 | 2016-03-08 14:29:51 +0200 | [diff] [blame] | 1147 | |
| 1148 | /* |
| 1149 | * We need to take into account a situation in which a TXQ was |
| 1150 | * allocated to TID x, and then turned shared by adding TIDs y |
| 1151 | * and z. If TID x becomes inactive and is removed from the TXQ, |
| 1152 | * ownership must be given to one of the remaining TIDs. |
| 1153 | * This is mainly because if TID x continues - a new queue can't |
| 1154 | * be allocated for it as long as it is an owner of another TXQ. |
| 1155 | */ |
| 1156 | change_owner = !(mvm->queue_info[queue].tid_bitmap & |
| 1157 | BIT(mvm->queue_info[queue].txq_tid)) && |
| 1158 | (mvm->queue_info[queue].status == |
| 1159 | IWL_MVM_QUEUE_SHARED); |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 1160 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1161 | |
| 1162 | if (reconfig) |
| 1163 | iwl_mvm_unshare_queue(mvm, queue); |
Liad Kaufman | 19aefa4 | 2016-03-08 14:29:51 +0200 | [diff] [blame] | 1164 | else if (change_owner) |
| 1165 | iwl_mvm_change_queue_owner(mvm, queue); |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 1166 | } |
| 1167 | |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 1168 | alloc_queues: |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1169 | /* Go over all stations with deferred traffic */ |
| 1170 | for_each_set_bit(sta_id, mvm->sta_deferred_frames, |
| 1171 | IWL_MVM_STATION_COUNT) { |
| 1172 | clear_bit(sta_id, mvm->sta_deferred_frames); |
| 1173 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 1174 | lockdep_is_held(&mvm->mutex)); |
| 1175 | if (IS_ERR_OR_NULL(sta)) |
| 1176 | continue; |
| 1177 | |
| 1178 | mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 1179 | deferred_tid_traffic = mvmsta->deferred_traffic_tid_map; |
| 1180 | |
| 1181 | for_each_set_bit(tid, &deferred_tid_traffic, |
| 1182 | IWL_MAX_TID_COUNT + 1) |
| 1183 | iwl_mvm_tx_deferred_stream(mvm, sta, tid); |
| 1184 | } |
| 1185 | |
| 1186 | mutex_unlock(&mvm->mutex); |
| 1187 | } |
| 1188 | |
| 1189 | static int iwl_mvm_reserve_sta_stream(struct iwl_mvm *mvm, |
Liad Kaufman | d5216a2 | 2015-08-09 15:50:51 +0300 | [diff] [blame] | 1190 | struct ieee80211_sta *sta, |
| 1191 | enum nl80211_iftype vif_type) |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1192 | { |
| 1193 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
| 1194 | int queue; |
Sara Sharon | 01796ff | 2016-11-16 17:04:36 +0200 | [diff] [blame] | 1195 | bool using_inactive_queue = false, same_sta = false; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1196 | |
Sara Sharon | 396952e | 2017-02-22 19:40:55 +0200 | [diff] [blame] | 1197 | /* queue reserving is disabled on new TX path */ |
| 1198 | if (WARN_ON(iwl_mvm_has_new_tx_api(mvm))) |
| 1199 | return 0; |
| 1200 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 1201 | /* |
| 1202 | * Check for inactive queues, so we don't reach a situation where we |
| 1203 | * can't add a STA due to a shortage in queues that doesn't really exist |
| 1204 | */ |
| 1205 | iwl_mvm_inactivity_check(mvm); |
| 1206 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1207 | spin_lock_bh(&mvm->queue_info_lock); |
| 1208 | |
| 1209 | /* Make sure we have free resources for this STA */ |
Liad Kaufman | d5216a2 | 2015-08-09 15:50:51 +0300 | [diff] [blame] | 1210 | if (vif_type == NL80211_IFTYPE_STATION && !sta->tdls && |
| 1211 | !mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].hw_queue_refcount && |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 1212 | (mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].status == |
| 1213 | IWL_MVM_QUEUE_FREE)) |
Liad Kaufman | d5216a2 | 2015-08-09 15:50:51 +0300 | [diff] [blame] | 1214 | queue = IWL_MVM_DQA_BSS_CLIENT_QUEUE; |
| 1215 | else |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 1216 | queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id, |
| 1217 | IWL_MVM_DQA_MIN_DATA_QUEUE, |
Liad Kaufman | d5216a2 | 2015-08-09 15:50:51 +0300 | [diff] [blame] | 1218 | IWL_MVM_DQA_MAX_DATA_QUEUE); |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1219 | if (queue < 0) { |
| 1220 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1221 | IWL_ERR(mvm, "No available queues for new station\n"); |
| 1222 | return -ENOSPC; |
Sara Sharon | 01796ff | 2016-11-16 17:04:36 +0200 | [diff] [blame] | 1223 | } else if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_INACTIVE) { |
| 1224 | /* |
| 1225 | * If this queue is already allocated but inactive we'll need to |
| 1226 | * first free this queue before enabling it again, we'll mark |
| 1227 | * it as reserved to make sure no new traffic arrives on it |
| 1228 | */ |
| 1229 | using_inactive_queue = true; |
| 1230 | same_sta = mvm->queue_info[queue].ra_sta_id == mvmsta->sta_id; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1231 | } |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 1232 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1233 | |
| 1234 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1235 | |
| 1236 | mvmsta->reserved_queue = queue; |
| 1237 | |
Sara Sharon | 01796ff | 2016-11-16 17:04:36 +0200 | [diff] [blame] | 1238 | if (using_inactive_queue) |
| 1239 | iwl_mvm_free_inactive_queue(mvm, queue, same_sta); |
| 1240 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1241 | IWL_DEBUG_TX_QUEUES(mvm, "Reserving data queue #%d for sta_id %d\n", |
| 1242 | queue, mvmsta->sta_id); |
| 1243 | |
| 1244 | return 0; |
| 1245 | } |
| 1246 | |
Liad Kaufman | 8d98ae6 | 2016-02-02 16:02:46 +0200 | [diff] [blame] | 1247 | /* |
| 1248 | * In DQA mode, after a HW restart the queues should be allocated as before, in |
| 1249 | * order to avoid race conditions when there are shared queues. This function |
| 1250 | * does the re-mapping and queue allocation. |
| 1251 | * |
| 1252 | * Note that re-enabling aggregations isn't done in this function. |
| 1253 | */ |
| 1254 | static void iwl_mvm_realloc_queues_after_restart(struct iwl_mvm *mvm, |
| 1255 | struct iwl_mvm_sta *mvm_sta) |
| 1256 | { |
| 1257 | unsigned int wdg_timeout = |
| 1258 | iwl_mvm_get_wd_timeout(mvm, mvm_sta->vif, false, false); |
| 1259 | int i; |
| 1260 | struct iwl_trans_txq_scd_cfg cfg = { |
| 1261 | .sta_id = mvm_sta->sta_id, |
| 1262 | .frame_limit = IWL_FRAME_LIMIT, |
| 1263 | }; |
| 1264 | |
Johannes Berg | 03c902b | 2016-12-02 12:03:36 +0100 | [diff] [blame] | 1265 | /* Make sure reserved queue is still marked as such (if allocated) */ |
| 1266 | if (mvm_sta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) |
| 1267 | mvm->queue_info[mvm_sta->reserved_queue].status = |
| 1268 | IWL_MVM_QUEUE_RESERVED; |
Liad Kaufman | 8d98ae6 | 2016-02-02 16:02:46 +0200 | [diff] [blame] | 1269 | |
| 1270 | for (i = 0; i <= IWL_MAX_TID_COUNT; i++) { |
| 1271 | struct iwl_mvm_tid_data *tid_data = &mvm_sta->tid_data[i]; |
| 1272 | int txq_id = tid_data->txq_id; |
| 1273 | int ac; |
| 1274 | u8 mac_queue; |
| 1275 | |
Sara Sharon | 6862fce | 2017-02-22 19:34:17 +0200 | [diff] [blame] | 1276 | if (txq_id == IWL_MVM_INVALID_QUEUE) |
Liad Kaufman | 8d98ae6 | 2016-02-02 16:02:46 +0200 | [diff] [blame] | 1277 | continue; |
| 1278 | |
| 1279 | skb_queue_head_init(&tid_data->deferred_tx_frames); |
| 1280 | |
| 1281 | ac = tid_to_mac80211_ac[i]; |
| 1282 | mac_queue = mvm_sta->vif->hw_queue[ac]; |
| 1283 | |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 1284 | if (iwl_mvm_has_new_tx_api(mvm)) { |
| 1285 | IWL_DEBUG_TX_QUEUES(mvm, |
| 1286 | "Re-mapping sta %d tid %d\n", |
| 1287 | mvm_sta->sta_id, i); |
| 1288 | txq_id = iwl_mvm_tvqm_enable_txq(mvm, mac_queue, |
| 1289 | mvm_sta->sta_id, |
| 1290 | i, wdg_timeout); |
| 1291 | tid_data->txq_id = txq_id; |
| 1292 | } else { |
| 1293 | u16 seq = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
Liad Kaufman | 8d98ae6 | 2016-02-02 16:02:46 +0200 | [diff] [blame] | 1294 | |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 1295 | cfg.tid = i; |
| 1296 | cfg.fifo = iwl_mvm_ac_to_tx_fifo[ac]; |
| 1297 | cfg.aggregate = (txq_id >= IWL_MVM_DQA_MIN_DATA_QUEUE || |
| 1298 | txq_id == |
| 1299 | IWL_MVM_DQA_BSS_CLIENT_QUEUE); |
Liad Kaufman | 8d98ae6 | 2016-02-02 16:02:46 +0200 | [diff] [blame] | 1300 | |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 1301 | IWL_DEBUG_TX_QUEUES(mvm, |
| 1302 | "Re-mapping sta %d tid %d to queue %d\n", |
| 1303 | mvm_sta->sta_id, i, txq_id); |
| 1304 | |
| 1305 | iwl_mvm_enable_txq(mvm, txq_id, mac_queue, seq, &cfg, |
| 1306 | wdg_timeout); |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 1307 | mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_READY; |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 1308 | } |
Liad Kaufman | 8d98ae6 | 2016-02-02 16:02:46 +0200 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | atomic_set(&mvm->pending_frames[mvm_sta->sta_id], 0); |
| 1312 | } |
| 1313 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1314 | int iwl_mvm_add_sta(struct iwl_mvm *mvm, |
| 1315 | struct ieee80211_vif *vif, |
| 1316 | struct ieee80211_sta *sta) |
| 1317 | { |
| 1318 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 1319 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Sara Sharon | a571f5f | 2015-12-07 12:50:58 +0200 | [diff] [blame] | 1320 | struct iwl_mvm_rxq_dup_data *dup_data; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1321 | int i, ret, sta_id; |
| 1322 | |
| 1323 | lockdep_assert_held(&mvm->mutex); |
| 1324 | |
| 1325 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 1326 | sta_id = iwl_mvm_find_free_sta_id(mvm, |
| 1327 | ieee80211_vif_type_p2p(vif)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1328 | else |
| 1329 | sta_id = mvm_sta->sta_id; |
| 1330 | |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 1331 | if (sta_id == IWL_MVM_INVALID_STA) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1332 | return -ENOSPC; |
| 1333 | |
| 1334 | spin_lock_init(&mvm_sta->lock); |
| 1335 | |
Liad Kaufman | 8d98ae6 | 2016-02-02 16:02:46 +0200 | [diff] [blame] | 1336 | /* In DQA mode, if this is a HW restart, re-alloc existing queues */ |
| 1337 | if (iwl_mvm_is_dqa_supported(mvm) && |
| 1338 | test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
| 1339 | iwl_mvm_realloc_queues_after_restart(mvm, mvm_sta); |
| 1340 | goto update_fw; |
| 1341 | } |
| 1342 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1343 | mvm_sta->sta_id = sta_id; |
| 1344 | mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 1345 | mvmvif->color); |
| 1346 | mvm_sta->vif = vif; |
| 1347 | mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF; |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 1348 | mvm_sta->tx_protection = 0; |
| 1349 | mvm_sta->tt_tx_protection = false; |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 1350 | mvm_sta->sta_type = sta->tdls ? IWL_STA_TDLS_LINK : IWL_STA_LINK; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1351 | |
| 1352 | /* HW restart, don't assume the memory has been zeroed */ |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1353 | atomic_set(&mvm->pending_frames[sta_id], 0); |
Liad Kaufman | 69191af | 2015-09-01 18:50:22 +0300 | [diff] [blame] | 1354 | mvm_sta->tid_disable_agg = 0xffff; /* No aggs at first */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1355 | mvm_sta->tfd_queue_msk = 0; |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1356 | |
Liad Kaufman | e3118ad | 2016-06-05 10:49:02 +0300 | [diff] [blame] | 1357 | /* |
| 1358 | * Allocate new queues for a TDLS station, unless we're in DQA mode, |
| 1359 | * and then they'll be allocated dynamically |
| 1360 | */ |
| 1361 | if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls) { |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1362 | ret = iwl_mvm_tdls_sta_init(mvm, sta); |
| 1363 | if (ret) |
| 1364 | return ret; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1365 | } else if (!iwl_mvm_is_dqa_supported(mvm)) { |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1366 | for (i = 0; i < IEEE80211_NUM_ACS; i++) |
| 1367 | if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE) |
| 1368 | mvm_sta->tfd_queue_msk |= BIT(vif->hw_queue[i]); |
| 1369 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1370 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1371 | /* for HW restart - reset everything but the sequence number */ |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1372 | for (i = 0; i <= IWL_MAX_TID_COUNT; i++) { |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1373 | u16 seq = mvm_sta->tid_data[i].seq_number; |
| 1374 | memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i])); |
| 1375 | mvm_sta->tid_data[i].seq_number = seq; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1376 | |
| 1377 | if (!iwl_mvm_is_dqa_supported(mvm)) |
| 1378 | continue; |
| 1379 | |
| 1380 | /* |
| 1381 | * Mark all queues for this STA as unallocated and defer TX |
| 1382 | * frames until the queue is allocated |
| 1383 | */ |
Sara Sharon | 6862fce | 2017-02-22 19:34:17 +0200 | [diff] [blame] | 1384 | mvm_sta->tid_data[i].txq_id = IWL_MVM_INVALID_QUEUE; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1385 | skb_queue_head_init(&mvm_sta->tid_data[i].deferred_tx_frames); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1386 | } |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1387 | mvm_sta->deferred_traffic_tid_map = 0; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 1388 | mvm_sta->agg_tids = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1389 | |
Sara Sharon | a571f5f | 2015-12-07 12:50:58 +0200 | [diff] [blame] | 1390 | if (iwl_mvm_has_new_rx_api(mvm) && |
| 1391 | !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
| 1392 | dup_data = kcalloc(mvm->trans->num_rx_queues, |
| 1393 | sizeof(*dup_data), |
| 1394 | GFP_KERNEL); |
| 1395 | if (!dup_data) |
| 1396 | return -ENOMEM; |
| 1397 | mvm_sta->dup_data = dup_data; |
| 1398 | } |
| 1399 | |
Sara Sharon | 396952e | 2017-02-22 19:40:55 +0200 | [diff] [blame] | 1400 | if (iwl_mvm_is_dqa_supported(mvm) && !iwl_mvm_has_new_tx_api(mvm)) { |
Liad Kaufman | d5216a2 | 2015-08-09 15:50:51 +0300 | [diff] [blame] | 1401 | ret = iwl_mvm_reserve_sta_stream(mvm, sta, |
| 1402 | ieee80211_vif_type_p2p(vif)); |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1403 | if (ret) |
| 1404 | goto err; |
| 1405 | } |
| 1406 | |
Liad Kaufman | 8d98ae6 | 2016-02-02 16:02:46 +0200 | [diff] [blame] | 1407 | update_fw: |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1408 | ret = iwl_mvm_sta_send_to_fw(mvm, sta, false, 0); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1409 | if (ret) |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1410 | goto err; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1411 | |
Johannes Berg | 9e84801 | 2014-08-04 14:33:42 +0200 | [diff] [blame] | 1412 | if (vif->type == NL80211_IFTYPE_STATION) { |
| 1413 | if (!sta->tdls) { |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 1414 | WARN_ON(mvmvif->ap_sta_id != IWL_MVM_INVALID_STA); |
Johannes Berg | 9e84801 | 2014-08-04 14:33:42 +0200 | [diff] [blame] | 1415 | mvmvif->ap_sta_id = sta_id; |
| 1416 | } else { |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 1417 | WARN_ON(mvmvif->ap_sta_id == IWL_MVM_INVALID_STA); |
Johannes Berg | 9e84801 | 2014-08-04 14:33:42 +0200 | [diff] [blame] | 1418 | } |
| 1419 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1420 | |
| 1421 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta); |
| 1422 | |
| 1423 | return 0; |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1424 | |
| 1425 | err: |
Liad Kaufman | e3118ad | 2016-06-05 10:49:02 +0300 | [diff] [blame] | 1426 | if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls) |
| 1427 | iwl_mvm_tdls_sta_deinit(mvm, sta); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1428 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1429 | } |
| 1430 | |
| 1431 | int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta, |
| 1432 | bool drain) |
| 1433 | { |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1434 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1435 | int ret; |
| 1436 | u32 status; |
| 1437 | |
| 1438 | lockdep_assert_held(&mvm->mutex); |
| 1439 | |
| 1440 | cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color); |
| 1441 | cmd.sta_id = mvmsta->sta_id; |
| 1442 | cmd.add_modify = STA_MODE_MODIFY; |
| 1443 | cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0; |
| 1444 | cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW); |
| 1445 | |
| 1446 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 1447 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 1448 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1449 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1450 | if (ret) |
| 1451 | return ret; |
| 1452 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 1453 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1454 | case ADD_STA_SUCCESS: |
| 1455 | IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n", |
| 1456 | mvmsta->sta_id); |
| 1457 | break; |
| 1458 | default: |
| 1459 | ret = -EIO; |
| 1460 | IWL_ERR(mvm, "Couldn't drain frames for staid %d\n", |
| 1461 | mvmsta->sta_id); |
| 1462 | break; |
| 1463 | } |
| 1464 | |
| 1465 | return ret; |
| 1466 | } |
| 1467 | |
| 1468 | /* |
| 1469 | * Remove a station from the FW table. Before sending the command to remove |
| 1470 | * the station validate that the station is indeed known to the driver (sanity |
| 1471 | * only). |
| 1472 | */ |
| 1473 | static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id) |
| 1474 | { |
| 1475 | struct ieee80211_sta *sta; |
| 1476 | struct iwl_mvm_rm_sta_cmd rm_sta_cmd = { |
| 1477 | .sta_id = sta_id, |
| 1478 | }; |
| 1479 | int ret; |
| 1480 | |
| 1481 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 1482 | lockdep_is_held(&mvm->mutex)); |
| 1483 | |
| 1484 | /* Note: internal stations are marked as error values */ |
| 1485 | if (!sta) { |
| 1486 | IWL_ERR(mvm, "Invalid station id\n"); |
| 1487 | return -EINVAL; |
| 1488 | } |
| 1489 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1490 | ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1491 | sizeof(rm_sta_cmd), &rm_sta_cmd); |
| 1492 | if (ret) { |
| 1493 | IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id); |
| 1494 | return ret; |
| 1495 | } |
| 1496 | |
| 1497 | return 0; |
| 1498 | } |
| 1499 | |
| 1500 | void iwl_mvm_sta_drained_wk(struct work_struct *wk) |
| 1501 | { |
| 1502 | struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, sta_drained_wk); |
| 1503 | u8 sta_id; |
| 1504 | |
| 1505 | /* |
| 1506 | * The mutex is needed because of the SYNC cmd, but not only: if the |
| 1507 | * work would run concurrently with iwl_mvm_rm_sta, it would run before |
| 1508 | * iwl_mvm_rm_sta sets the station as busy, and exit. Then |
| 1509 | * iwl_mvm_rm_sta would set the station as busy, and nobody will clean |
| 1510 | * that later. |
| 1511 | */ |
| 1512 | mutex_lock(&mvm->mutex); |
| 1513 | |
| 1514 | for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT) { |
| 1515 | int ret; |
| 1516 | struct ieee80211_sta *sta = |
| 1517 | rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 1518 | lockdep_is_held(&mvm->mutex)); |
| 1519 | |
Johannes Berg | 1ddbbb0 | 2013-12-04 22:39:17 +0100 | [diff] [blame] | 1520 | /* |
| 1521 | * This station is in use or RCU-removed; the latter happens in |
| 1522 | * managed mode, where mac80211 removes the station before we |
| 1523 | * can remove it from firmware (we can only do that after the |
| 1524 | * MAC is marked unassociated), and possibly while the deauth |
| 1525 | * frame to disconnect from the AP is still queued. Then, the |
| 1526 | * station pointer is -ENOENT when the last skb is reclaimed. |
| 1527 | */ |
| 1528 | if (!IS_ERR(sta) || PTR_ERR(sta) == -ENOENT) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1529 | continue; |
| 1530 | |
| 1531 | if (PTR_ERR(sta) == -EINVAL) { |
| 1532 | IWL_ERR(mvm, "Drained sta %d, but it is internal?\n", |
| 1533 | sta_id); |
| 1534 | continue; |
| 1535 | } |
| 1536 | |
| 1537 | if (!sta) { |
| 1538 | IWL_ERR(mvm, "Drained sta %d, but it was NULL?\n", |
| 1539 | sta_id); |
| 1540 | continue; |
| 1541 | } |
| 1542 | |
| 1543 | WARN_ON(PTR_ERR(sta) != -EBUSY); |
| 1544 | /* This station was removed and we waited until it got drained, |
| 1545 | * we can now proceed and remove it. |
| 1546 | */ |
| 1547 | ret = iwl_mvm_rm_sta_common(mvm, sta_id); |
| 1548 | if (ret) { |
| 1549 | IWL_ERR(mvm, |
| 1550 | "Couldn't remove sta %d after it was drained\n", |
| 1551 | sta_id); |
| 1552 | continue; |
| 1553 | } |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 1554 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1555 | clear_bit(sta_id, mvm->sta_drained); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1556 | |
| 1557 | if (mvm->tfd_drained[sta_id]) { |
| 1558 | unsigned long i, msk = mvm->tfd_drained[sta_id]; |
| 1559 | |
Emmanuel Grumbach | a4ca3ed | 2015-01-20 17:07:10 +0200 | [diff] [blame] | 1560 | for_each_set_bit(i, &msk, sizeof(msk) * BITS_PER_BYTE) |
Arik Nemtsov | 06ecdba | 2015-10-12 14:47:11 +0300 | [diff] [blame] | 1561 | iwl_mvm_disable_txq(mvm, i, i, |
| 1562 | IWL_MAX_TID_COUNT, 0); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1563 | |
| 1564 | mvm->tfd_drained[sta_id] = 0; |
| 1565 | IWL_DEBUG_TDLS(mvm, "Drained sta %d, with queues %ld\n", |
| 1566 | sta_id, msk); |
| 1567 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1568 | } |
| 1569 | |
| 1570 | mutex_unlock(&mvm->mutex); |
| 1571 | } |
| 1572 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1573 | static void iwl_mvm_disable_sta_queues(struct iwl_mvm *mvm, |
| 1574 | struct ieee80211_vif *vif, |
| 1575 | struct iwl_mvm_sta *mvm_sta) |
| 1576 | { |
| 1577 | int ac; |
| 1578 | int i; |
| 1579 | |
| 1580 | lockdep_assert_held(&mvm->mutex); |
| 1581 | |
| 1582 | for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) { |
Sara Sharon | 6862fce | 2017-02-22 19:34:17 +0200 | [diff] [blame] | 1583 | if (mvm_sta->tid_data[i].txq_id == IWL_MVM_INVALID_QUEUE) |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1584 | continue; |
| 1585 | |
| 1586 | ac = iwl_mvm_tid_to_ac_queue(i); |
| 1587 | iwl_mvm_disable_txq(mvm, mvm_sta->tid_data[i].txq_id, |
| 1588 | vif->hw_queue[ac], i, 0); |
Sara Sharon | 6862fce | 2017-02-22 19:34:17 +0200 | [diff] [blame] | 1589 | mvm_sta->tid_data[i].txq_id = IWL_MVM_INVALID_QUEUE; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1590 | } |
| 1591 | } |
| 1592 | |
Sara Sharon | d6d517b | 2017-03-06 10:16:11 +0200 | [diff] [blame] | 1593 | int iwl_mvm_wait_sta_queues_empty(struct iwl_mvm *mvm, |
| 1594 | struct iwl_mvm_sta *mvm_sta) |
| 1595 | { |
| 1596 | int i, ret; |
| 1597 | |
| 1598 | for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) { |
| 1599 | u16 txq_id; |
| 1600 | |
| 1601 | spin_lock_bh(&mvm_sta->lock); |
| 1602 | txq_id = mvm_sta->tid_data[i].txq_id; |
| 1603 | spin_unlock_bh(&mvm_sta->lock); |
| 1604 | |
| 1605 | if (txq_id == IWL_MVM_INVALID_QUEUE) |
| 1606 | continue; |
| 1607 | |
| 1608 | ret = iwl_trans_wait_txq_empty(mvm->trans, txq_id); |
| 1609 | if (ret) |
| 1610 | break; |
| 1611 | } |
| 1612 | |
| 1613 | return ret; |
| 1614 | } |
| 1615 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1616 | int iwl_mvm_rm_sta(struct iwl_mvm *mvm, |
| 1617 | struct ieee80211_vif *vif, |
| 1618 | struct ieee80211_sta *sta) |
| 1619 | { |
| 1620 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 1621 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Sara Sharon | 94c3e61 | 2016-12-07 15:04:37 +0200 | [diff] [blame] | 1622 | u8 sta_id = mvm_sta->sta_id; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1623 | int ret; |
| 1624 | |
| 1625 | lockdep_assert_held(&mvm->mutex); |
| 1626 | |
Sara Sharon | a571f5f | 2015-12-07 12:50:58 +0200 | [diff] [blame] | 1627 | if (iwl_mvm_has_new_rx_api(mvm)) |
| 1628 | kfree(mvm_sta->dup_data); |
| 1629 | |
Liad Kaufman | a6f035a | 2015-08-24 15:23:14 +0300 | [diff] [blame] | 1630 | if ((vif->type == NL80211_IFTYPE_STATION && |
Sara Sharon | 94c3e61 | 2016-12-07 15:04:37 +0200 | [diff] [blame] | 1631 | mvmvif->ap_sta_id == sta_id) || |
Liad Kaufman | a6f035a | 2015-08-24 15:23:14 +0300 | [diff] [blame] | 1632 | iwl_mvm_is_dqa_supported(mvm)){ |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 1633 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, true); |
| 1634 | if (ret) |
| 1635 | return ret; |
Emmanuel Grumbach | 80d8565 | 2013-02-19 15:32:42 +0200 | [diff] [blame] | 1636 | /* flush its queues here since we are freeing mvm_sta */ |
Sara Sharon | d49394a | 2017-03-05 13:01:08 +0200 | [diff] [blame] | 1637 | ret = iwl_mvm_flush_sta(mvm, mvm_sta, false, 0); |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 1638 | if (ret) |
| 1639 | return ret; |
Sara Sharon | d6d517b | 2017-03-06 10:16:11 +0200 | [diff] [blame] | 1640 | if (iwl_mvm_has_new_tx_api(mvm)) { |
| 1641 | ret = iwl_mvm_wait_sta_queues_empty(mvm, mvm_sta); |
| 1642 | } else { |
| 1643 | u32 q_mask = mvm_sta->tfd_queue_msk; |
| 1644 | |
| 1645 | ret = iwl_trans_wait_tx_queues_empty(mvm->trans, |
| 1646 | q_mask); |
| 1647 | } |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 1648 | if (ret) |
| 1649 | return ret; |
| 1650 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, false); |
Emmanuel Grumbach | 80d8565 | 2013-02-19 15:32:42 +0200 | [diff] [blame] | 1651 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1652 | /* If DQA is supported - the queues can be disabled now */ |
Sara Sharon | 94c3e61 | 2016-12-07 15:04:37 +0200 | [diff] [blame] | 1653 | if (iwl_mvm_is_dqa_supported(mvm)) { |
Liad Kaufman | 5621474 | 2016-09-22 15:14:08 +0300 | [diff] [blame] | 1654 | iwl_mvm_disable_sta_queues(mvm, vif, mvm_sta); |
Sara Sharon | 94c3e61 | 2016-12-07 15:04:37 +0200 | [diff] [blame] | 1655 | /* |
| 1656 | * If pending_frames is set at this point - it must be |
| 1657 | * driver internal logic error, since queues are empty |
| 1658 | * and removed successuly. |
| 1659 | * warn on it but set it to 0 anyway to avoid station |
| 1660 | * not being removed later in the function |
| 1661 | */ |
| 1662 | WARN_ON(atomic_xchg(&mvm->pending_frames[sta_id], 0)); |
| 1663 | } |
Liad Kaufman | 5621474 | 2016-09-22 15:14:08 +0300 | [diff] [blame] | 1664 | |
| 1665 | /* If there is a TXQ still marked as reserved - free it */ |
| 1666 | if (iwl_mvm_is_dqa_supported(mvm) && |
| 1667 | mvm_sta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) { |
Liad Kaufman | a0315dea | 2016-07-07 13:25:59 +0300 | [diff] [blame] | 1668 | u8 reserved_txq = mvm_sta->reserved_queue; |
| 1669 | enum iwl_mvm_queue_status *status; |
| 1670 | |
Liad Kaufman | a0315dea | 2016-07-07 13:25:59 +0300 | [diff] [blame] | 1671 | /* |
| 1672 | * If no traffic has gone through the reserved TXQ - it |
| 1673 | * is still marked as IWL_MVM_QUEUE_RESERVED, and |
| 1674 | * should be manually marked as free again |
| 1675 | */ |
| 1676 | spin_lock_bh(&mvm->queue_info_lock); |
| 1677 | status = &mvm->queue_info[reserved_txq].status; |
| 1678 | if (WARN((*status != IWL_MVM_QUEUE_RESERVED) && |
| 1679 | (*status != IWL_MVM_QUEUE_FREE), |
| 1680 | "sta_id %d reserved txq %d status %d", |
Sara Sharon | 94c3e61 | 2016-12-07 15:04:37 +0200 | [diff] [blame] | 1681 | sta_id, reserved_txq, *status)) { |
Liad Kaufman | a0315dea | 2016-07-07 13:25:59 +0300 | [diff] [blame] | 1682 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1683 | return -EINVAL; |
| 1684 | } |
| 1685 | |
| 1686 | *status = IWL_MVM_QUEUE_FREE; |
| 1687 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1688 | } |
| 1689 | |
Liad Kaufman | e3118ad | 2016-06-05 10:49:02 +0300 | [diff] [blame] | 1690 | if (vif->type == NL80211_IFTYPE_STATION && |
Sara Sharon | 94c3e61 | 2016-12-07 15:04:37 +0200 | [diff] [blame] | 1691 | mvmvif->ap_sta_id == sta_id) { |
Liad Kaufman | e3118ad | 2016-06-05 10:49:02 +0300 | [diff] [blame] | 1692 | /* if associated - we can't remove the AP STA now */ |
| 1693 | if (vif->bss_conf.assoc) |
| 1694 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1695 | |
Liad Kaufman | e3118ad | 2016-06-05 10:49:02 +0300 | [diff] [blame] | 1696 | /* unassoc - go ahead - remove the AP STA now */ |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 1697 | mvmvif->ap_sta_id = IWL_MVM_INVALID_STA; |
Eliad Peller | 37577fe | 2013-12-05 17:19:39 +0200 | [diff] [blame] | 1698 | |
Liad Kaufman | e3118ad | 2016-06-05 10:49:02 +0300 | [diff] [blame] | 1699 | /* clear d0i3_ap_sta_id if no longer relevant */ |
Sara Sharon | 94c3e61 | 2016-12-07 15:04:37 +0200 | [diff] [blame] | 1700 | if (mvm->d0i3_ap_sta_id == sta_id) |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 1701 | mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA; |
Liad Kaufman | e3118ad | 2016-06-05 10:49:02 +0300 | [diff] [blame] | 1702 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | /* |
Arik Nemtsov | 1d3c3f6 | 2014-10-23 18:03:10 +0300 | [diff] [blame] | 1706 | * This shouldn't happen - the TDLS channel switch should be canceled |
| 1707 | * before the STA is removed. |
| 1708 | */ |
Sara Sharon | 94c3e61 | 2016-12-07 15:04:37 +0200 | [diff] [blame] | 1709 | if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == sta_id)) { |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 1710 | mvm->tdls_cs.peer.sta_id = IWL_MVM_INVALID_STA; |
Arik Nemtsov | 1d3c3f6 | 2014-10-23 18:03:10 +0300 | [diff] [blame] | 1711 | cancel_delayed_work(&mvm->tdls_cs.dwork); |
| 1712 | } |
| 1713 | |
| 1714 | /* |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1715 | * Make sure that the tx response code sees the station as -EBUSY and |
| 1716 | * calls the drain worker. |
| 1717 | */ |
| 1718 | spin_lock_bh(&mvm_sta->lock); |
Sara Sharon | 94c3e61 | 2016-12-07 15:04:37 +0200 | [diff] [blame] | 1719 | |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1720 | /* |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1721 | * There are frames pending on the AC queues for this station. |
| 1722 | * We need to wait until all the frames are drained... |
| 1723 | */ |
Sara Sharon | 94c3e61 | 2016-12-07 15:04:37 +0200 | [diff] [blame] | 1724 | if (atomic_read(&mvm->pending_frames[sta_id])) { |
| 1725 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1726 | ERR_PTR(-EBUSY)); |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1727 | spin_unlock_bh(&mvm_sta->lock); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1728 | |
| 1729 | /* disable TDLS sta queues on drain complete */ |
| 1730 | if (sta->tdls) { |
Sara Sharon | 94c3e61 | 2016-12-07 15:04:37 +0200 | [diff] [blame] | 1731 | mvm->tfd_drained[sta_id] = mvm_sta->tfd_queue_msk; |
| 1732 | IWL_DEBUG_TDLS(mvm, "Draining TDLS sta %d\n", sta_id); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1733 | } |
| 1734 | |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1735 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, true); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1736 | } else { |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1737 | spin_unlock_bh(&mvm_sta->lock); |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1738 | |
Liad Kaufman | e3118ad | 2016-06-05 10:49:02 +0300 | [diff] [blame] | 1739 | if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls) |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1740 | iwl_mvm_tdls_sta_deinit(mvm, sta); |
| 1741 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1742 | ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id); |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 1743 | 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] | 1744 | } |
| 1745 | |
| 1746 | return ret; |
| 1747 | } |
| 1748 | |
| 1749 | int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm, |
| 1750 | struct ieee80211_vif *vif, |
| 1751 | u8 sta_id) |
| 1752 | { |
| 1753 | int ret = iwl_mvm_rm_sta_common(mvm, sta_id); |
| 1754 | |
| 1755 | lockdep_assert_held(&mvm->mutex); |
| 1756 | |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 1757 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1758 | return ret; |
| 1759 | } |
| 1760 | |
Chaya Rachel Ivgi | 0e39eb0 | 2015-12-03 15:51:46 +0200 | [diff] [blame] | 1761 | int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm, |
| 1762 | struct iwl_mvm_int_sta *sta, |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 1763 | u32 qmask, enum nl80211_iftype iftype, |
| 1764 | enum iwl_sta_type type) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1765 | { |
| 1766 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 1767 | sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype); |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 1768 | if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_INVALID_STA)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1769 | return -ENOSPC; |
| 1770 | } |
| 1771 | |
| 1772 | sta->tfd_queue_msk = qmask; |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 1773 | sta->type = type; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1774 | |
| 1775 | /* put a non-NULL value so iterating over the stations won't stop */ |
| 1776 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL)); |
| 1777 | return 0; |
| 1778 | } |
| 1779 | |
Sara Sharon | 26d6c16 | 2017-01-03 12:00:19 +0200 | [diff] [blame] | 1780 | void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm, struct iwl_mvm_int_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1781 | { |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 1782 | 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] | 1783 | memset(sta, 0, sizeof(struct iwl_mvm_int_sta)); |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 1784 | sta->sta_id = IWL_MVM_INVALID_STA; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1785 | } |
| 1786 | |
| 1787 | static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm, |
| 1788 | struct iwl_mvm_int_sta *sta, |
| 1789 | const u8 *addr, |
| 1790 | u16 mac_id, u16 color) |
| 1791 | { |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1792 | struct iwl_mvm_add_sta_cmd cmd; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1793 | int ret; |
| 1794 | u32 status; |
| 1795 | |
| 1796 | lockdep_assert_held(&mvm->mutex); |
| 1797 | |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1798 | memset(&cmd, 0, sizeof(cmd)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1799 | cmd.sta_id = sta->sta_id; |
| 1800 | cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id, |
| 1801 | color)); |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 1802 | if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) |
| 1803 | cmd.station_type = sta->type; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1804 | |
Sara Sharon | bb49701 | 2016-09-29 14:52:40 +0300 | [diff] [blame] | 1805 | if (!iwl_mvm_has_new_tx_api(mvm)) |
| 1806 | cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk); |
Liad Kaufman | cf0cda1 | 2015-09-24 10:44:12 +0200 | [diff] [blame] | 1807 | cmd.tid_disable_tx = cpu_to_le16(0xffff); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1808 | |
| 1809 | if (addr) |
| 1810 | memcpy(cmd.addr, addr, ETH_ALEN); |
| 1811 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 1812 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 1813 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1814 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1815 | if (ret) |
| 1816 | return ret; |
| 1817 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 1818 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1819 | case ADD_STA_SUCCESS: |
| 1820 | IWL_DEBUG_INFO(mvm, "Internal station added.\n"); |
| 1821 | return 0; |
| 1822 | default: |
| 1823 | ret = -EIO; |
| 1824 | IWL_ERR(mvm, "Add internal station failed, status=0x%x\n", |
| 1825 | status); |
| 1826 | break; |
| 1827 | } |
| 1828 | return ret; |
| 1829 | } |
| 1830 | |
Sara Sharon | c5a719e | 2016-11-15 10:20:48 +0200 | [diff] [blame] | 1831 | static void iwl_mvm_enable_aux_queue(struct iwl_mvm *mvm) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1832 | { |
Emmanuel Grumbach | 4cf677f | 2015-01-12 14:38:29 +0200 | [diff] [blame] | 1833 | unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ? |
| 1834 | mvm->cfg->base_params->wd_timeout : |
| 1835 | IWL_WATCHDOG_DISABLED; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1836 | |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 1837 | if (iwl_mvm_has_new_tx_api(mvm)) { |
| 1838 | int queue = iwl_mvm_tvqm_enable_txq(mvm, mvm->aux_queue, |
| 1839 | mvm->aux_sta.sta_id, |
| 1840 | IWL_MAX_TID_COUNT, |
| 1841 | wdg_timeout); |
| 1842 | mvm->aux_queue = queue; |
| 1843 | } else if (iwl_mvm_is_dqa_supported(mvm)) { |
Liad Kaufman | 28d0793 | 2015-09-01 16:36:25 +0300 | [diff] [blame] | 1844 | struct iwl_trans_txq_scd_cfg cfg = { |
| 1845 | .fifo = IWL_MVM_TX_FIFO_MCAST, |
| 1846 | .sta_id = mvm->aux_sta.sta_id, |
| 1847 | .tid = IWL_MAX_TID_COUNT, |
| 1848 | .aggregate = false, |
| 1849 | .frame_limit = IWL_FRAME_LIMIT, |
| 1850 | }; |
| 1851 | |
| 1852 | iwl_mvm_enable_txq(mvm, mvm->aux_queue, mvm->aux_queue, 0, &cfg, |
| 1853 | wdg_timeout); |
Sara Sharon | c5a719e | 2016-11-15 10:20:48 +0200 | [diff] [blame] | 1854 | } else { |
| 1855 | iwl_mvm_enable_ac_txq(mvm, mvm->aux_queue, mvm->aux_queue, |
| 1856 | IWL_MVM_TX_FIFO_MCAST, 0, wdg_timeout); |
Liad Kaufman | 28d0793 | 2015-09-01 16:36:25 +0300 | [diff] [blame] | 1857 | } |
Sara Sharon | c5a719e | 2016-11-15 10:20:48 +0200 | [diff] [blame] | 1858 | } |
| 1859 | |
| 1860 | int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm) |
| 1861 | { |
| 1862 | int ret; |
| 1863 | |
| 1864 | lockdep_assert_held(&mvm->mutex); |
| 1865 | |
| 1866 | /* Allocate aux station and assign to it the aux queue */ |
| 1867 | ret = iwl_mvm_allocate_int_sta(mvm, &mvm->aux_sta, BIT(mvm->aux_queue), |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 1868 | NL80211_IFTYPE_UNSPECIFIED, |
| 1869 | IWL_STA_AUX_ACTIVITY); |
Sara Sharon | c5a719e | 2016-11-15 10:20:48 +0200 | [diff] [blame] | 1870 | if (ret) |
| 1871 | return ret; |
| 1872 | |
| 1873 | /* Map Aux queue to fifo - needs to happen before adding Aux station */ |
| 1874 | if (!iwl_mvm_has_new_tx_api(mvm)) |
| 1875 | iwl_mvm_enable_aux_queue(mvm); |
Liad Kaufman | 28d0793 | 2015-09-01 16:36:25 +0300 | [diff] [blame] | 1876 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1877 | ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL, |
| 1878 | MAC_INDEX_AUX, 0); |
Sara Sharon | c5a719e | 2016-11-15 10:20:48 +0200 | [diff] [blame] | 1879 | if (ret) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1880 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); |
Sara Sharon | c5a719e | 2016-11-15 10:20:48 +0200 | [diff] [blame] | 1881 | return ret; |
| 1882 | } |
| 1883 | |
| 1884 | /* |
| 1885 | * For a000 firmware and on we cannot add queue to a station unknown |
| 1886 | * to firmware so enable queue here - after the station was added |
| 1887 | */ |
| 1888 | if (iwl_mvm_has_new_tx_api(mvm)) |
| 1889 | iwl_mvm_enable_aux_queue(mvm); |
| 1890 | |
| 1891 | return 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1892 | } |
| 1893 | |
Chaya Rachel Ivgi | 0e39eb0 | 2015-12-03 15:51:46 +0200 | [diff] [blame] | 1894 | int iwl_mvm_add_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1895 | { |
| 1896 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1897 | |
| 1898 | lockdep_assert_held(&mvm->mutex); |
| 1899 | return iwl_mvm_add_int_sta_common(mvm, &mvm->snif_sta, vif->addr, |
| 1900 | mvmvif->id, 0); |
| 1901 | } |
| 1902 | |
| 1903 | int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1904 | { |
| 1905 | int ret; |
| 1906 | |
| 1907 | lockdep_assert_held(&mvm->mutex); |
| 1908 | |
| 1909 | ret = iwl_mvm_rm_sta_common(mvm, mvm->snif_sta.sta_id); |
| 1910 | if (ret) |
| 1911 | IWL_WARN(mvm, "Failed sending remove station\n"); |
| 1912 | |
| 1913 | return ret; |
| 1914 | } |
| 1915 | |
| 1916 | void iwl_mvm_dealloc_snif_sta(struct iwl_mvm *mvm) |
| 1917 | { |
| 1918 | iwl_mvm_dealloc_int_sta(mvm, &mvm->snif_sta); |
| 1919 | } |
| 1920 | |
Johannes Berg | 712b24a | 2014-08-04 14:14:14 +0200 | [diff] [blame] | 1921 | void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm) |
| 1922 | { |
| 1923 | lockdep_assert_held(&mvm->mutex); |
| 1924 | |
| 1925 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); |
| 1926 | } |
| 1927 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1928 | /* |
| 1929 | * Send the add station command for the vif's broadcast station. |
| 1930 | * Assumes that the station was already allocated. |
| 1931 | * |
| 1932 | * @mvm: the mvm component |
| 1933 | * @vif: the interface to which the broadcast station is added |
| 1934 | * @bsta: the broadcast station to add. |
| 1935 | */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1936 | 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] | 1937 | { |
| 1938 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1939 | struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta; |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1940 | static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
Johannes Berg | a424340 | 2014-01-20 23:46:38 +0100 | [diff] [blame] | 1941 | const u8 *baddr = _baddr; |
Johannes Berg | 7daa762 | 2017-02-24 12:02:22 +0100 | [diff] [blame] | 1942 | int queue; |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 1943 | int ret; |
Sara Sharon | c5a719e | 2016-11-15 10:20:48 +0200 | [diff] [blame] | 1944 | unsigned int wdg_timeout = |
| 1945 | iwl_mvm_get_wd_timeout(mvm, vif, false, false); |
| 1946 | struct iwl_trans_txq_scd_cfg cfg = { |
| 1947 | .fifo = IWL_MVM_TX_FIFO_VO, |
| 1948 | .sta_id = mvmvif->bcast_sta.sta_id, |
| 1949 | .tid = IWL_MAX_TID_COUNT, |
| 1950 | .aggregate = false, |
| 1951 | .frame_limit = IWL_FRAME_LIMIT, |
| 1952 | }; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1953 | |
| 1954 | lockdep_assert_held(&mvm->mutex); |
| 1955 | |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 1956 | if (iwl_mvm_is_dqa_supported(mvm) && !iwl_mvm_has_new_tx_api(mvm)) { |
Liad Kaufman | 4d33998 | 2017-03-21 17:13:16 +0200 | [diff] [blame] | 1957 | if (vif->type == NL80211_IFTYPE_AP || |
| 1958 | vif->type == NL80211_IFTYPE_ADHOC) |
Sara Sharon | 49f7171 | 2017-01-09 12:07:16 +0200 | [diff] [blame] | 1959 | queue = mvm->probe_queue; |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 1960 | else if (vif->type == NL80211_IFTYPE_P2P_DEVICE) |
Sara Sharon | 49f7171 | 2017-01-09 12:07:16 +0200 | [diff] [blame] | 1961 | queue = mvm->p2p_dev_queue; |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 1962 | else if (WARN(1, "Missing required TXQ for adding bcast STA\n")) |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 1963 | return -EINVAL; |
| 1964 | |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 1965 | bsta->tfd_queue_msk |= BIT(queue); |
Sara Sharon | c5a719e | 2016-11-15 10:20:48 +0200 | [diff] [blame] | 1966 | |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 1967 | iwl_mvm_enable_txq(mvm, queue, vif->hw_queue[0], 0, |
| 1968 | &cfg, wdg_timeout); |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 1969 | } |
| 1970 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1971 | if (vif->type == NL80211_IFTYPE_ADHOC) |
| 1972 | baddr = vif->bss_conf.bssid; |
| 1973 | |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 1974 | if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_INVALID_STA)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1975 | return -ENOSPC; |
| 1976 | |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 1977 | ret = iwl_mvm_add_int_sta_common(mvm, bsta, baddr, |
| 1978 | mvmvif->id, mvmvif->color); |
| 1979 | if (ret) |
| 1980 | return ret; |
| 1981 | |
| 1982 | /* |
Sara Sharon | c5a719e | 2016-11-15 10:20:48 +0200 | [diff] [blame] | 1983 | * For a000 firmware and on we cannot add queue to a station unknown |
| 1984 | * to firmware so enable queue here - after the station was added |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 1985 | */ |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 1986 | if (iwl_mvm_has_new_tx_api(mvm)) { |
Johannes Berg | 7daa762 | 2017-02-24 12:02:22 +0100 | [diff] [blame] | 1987 | queue = iwl_mvm_tvqm_enable_txq(mvm, vif->hw_queue[0], |
| 1988 | bsta->sta_id, |
| 1989 | IWL_MAX_TID_COUNT, |
| 1990 | wdg_timeout); |
| 1991 | |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 1992 | if (vif->type == NL80211_IFTYPE_AP) |
| 1993 | mvm->probe_queue = queue; |
| 1994 | else if (vif->type == NL80211_IFTYPE_P2P_DEVICE) |
| 1995 | mvm->p2p_dev_queue = queue; |
| 1996 | |
| 1997 | bsta->tfd_queue_msk |= BIT(queue); |
| 1998 | } |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 1999 | |
| 2000 | return 0; |
| 2001 | } |
| 2002 | |
| 2003 | static void iwl_mvm_free_bcast_sta_queues(struct iwl_mvm *mvm, |
| 2004 | struct ieee80211_vif *vif) |
| 2005 | { |
| 2006 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2007 | |
| 2008 | lockdep_assert_held(&mvm->mutex); |
| 2009 | |
Sara Sharon | d49394a | 2017-03-05 13:01:08 +0200 | [diff] [blame] | 2010 | iwl_mvm_flush_sta(mvm, &mvmvif->bcast_sta, true, 0); |
| 2011 | |
Liad Kaufman | 4d33998 | 2017-03-21 17:13:16 +0200 | [diff] [blame] | 2012 | if (vif->type == NL80211_IFTYPE_AP || |
| 2013 | vif->type == NL80211_IFTYPE_ADHOC) |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 2014 | iwl_mvm_disable_txq(mvm, vif->cab_queue, vif->cab_queue, |
| 2015 | IWL_MAX_TID_COUNT, 0); |
| 2016 | |
Sara Sharon | 49f7171 | 2017-01-09 12:07:16 +0200 | [diff] [blame] | 2017 | if (mvmvif->bcast_sta.tfd_queue_msk & BIT(mvm->probe_queue)) { |
| 2018 | iwl_mvm_disable_txq(mvm, mvm->probe_queue, |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 2019 | vif->hw_queue[0], IWL_MAX_TID_COUNT, |
| 2020 | 0); |
Sara Sharon | 49f7171 | 2017-01-09 12:07:16 +0200 | [diff] [blame] | 2021 | mvmvif->bcast_sta.tfd_queue_msk &= ~BIT(mvm->probe_queue); |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 2022 | } |
| 2023 | |
Sara Sharon | 49f7171 | 2017-01-09 12:07:16 +0200 | [diff] [blame] | 2024 | if (mvmvif->bcast_sta.tfd_queue_msk & BIT(mvm->p2p_dev_queue)) { |
| 2025 | iwl_mvm_disable_txq(mvm, mvm->p2p_dev_queue, |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 2026 | vif->hw_queue[0], IWL_MAX_TID_COUNT, |
| 2027 | 0); |
Sara Sharon | 49f7171 | 2017-01-09 12:07:16 +0200 | [diff] [blame] | 2028 | mvmvif->bcast_sta.tfd_queue_msk &= ~BIT(mvm->p2p_dev_queue); |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 2029 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2030 | } |
| 2031 | |
| 2032 | /* Send the FW a request to remove the station from it's internal data |
| 2033 | * structures, but DO NOT remove the entry from the local data structures. */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2034 | 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] | 2035 | { |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2036 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2037 | int ret; |
| 2038 | |
| 2039 | lockdep_assert_held(&mvm->mutex); |
| 2040 | |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 2041 | if (iwl_mvm_is_dqa_supported(mvm)) |
| 2042 | iwl_mvm_free_bcast_sta_queues(mvm, vif); |
| 2043 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2044 | ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2045 | if (ret) |
| 2046 | IWL_WARN(mvm, "Failed sending remove station\n"); |
| 2047 | return ret; |
| 2048 | } |
| 2049 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2050 | int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 2051 | { |
| 2052 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 2053 | u32 qmask = 0; |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2054 | |
| 2055 | lockdep_assert_held(&mvm->mutex); |
| 2056 | |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 2057 | if (!iwl_mvm_is_dqa_supported(mvm)) { |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 2058 | qmask = iwl_mvm_mac_get_queues_mask(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2059 | |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 2060 | /* |
| 2061 | * The firmware defines the TFD queue mask to only be relevant |
| 2062 | * for *unicast* queues, so the multicast (CAB) queue shouldn't |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 2063 | * be included. This only happens in NL80211_IFTYPE_AP vif type, |
| 2064 | * so the next line will only have an effect there. |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 2065 | */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2066 | qmask &= ~BIT(vif->cab_queue); |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 2067 | } |
| 2068 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2069 | return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, qmask, |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 2070 | ieee80211_vif_type_p2p(vif), |
| 2071 | IWL_STA_GENERAL_PURPOSE); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2072 | } |
| 2073 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2074 | /* Allocate a new station entry for the broadcast station to the given vif, |
| 2075 | * and send it to the FW. |
| 2076 | * Note that each P2P mac should have its own broadcast station. |
| 2077 | * |
| 2078 | * @mvm: the mvm component |
| 2079 | * @vif: the interface to which the broadcast station is added |
| 2080 | * @bsta: the broadcast station to add. */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2081 | 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] | 2082 | { |
| 2083 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2084 | struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2085 | int ret; |
| 2086 | |
| 2087 | lockdep_assert_held(&mvm->mutex); |
| 2088 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2089 | ret = iwl_mvm_alloc_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2090 | if (ret) |
| 2091 | return ret; |
| 2092 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2093 | ret = iwl_mvm_send_add_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2094 | |
| 2095 | if (ret) |
| 2096 | iwl_mvm_dealloc_int_sta(mvm, bsta); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2097 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2098 | return ret; |
| 2099 | } |
| 2100 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2101 | void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 2102 | { |
| 2103 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2104 | |
| 2105 | iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta); |
| 2106 | } |
| 2107 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2108 | /* |
| 2109 | * Send the FW a request to remove the station from it's internal data |
| 2110 | * structures, and in addition remove it from the local data structure. |
| 2111 | */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2112 | 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] | 2113 | { |
| 2114 | int ret; |
| 2115 | |
| 2116 | lockdep_assert_held(&mvm->mutex); |
| 2117 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2118 | ret = iwl_mvm_send_rm_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2119 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 2120 | iwl_mvm_dealloc_bcast_sta(mvm, vif); |
| 2121 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2122 | return ret; |
| 2123 | } |
| 2124 | |
Sara Sharon | 26d6c16 | 2017-01-03 12:00:19 +0200 | [diff] [blame] | 2125 | /* |
| 2126 | * Allocate a new station entry for the multicast station to the given vif, |
| 2127 | * and send it to the FW. |
| 2128 | * Note that each AP/GO mac should have its own multicast station. |
| 2129 | * |
| 2130 | * @mvm: the mvm component |
| 2131 | * @vif: the interface to which the multicast station is added |
| 2132 | */ |
| 2133 | int iwl_mvm_add_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 2134 | { |
| 2135 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2136 | struct iwl_mvm_int_sta *msta = &mvmvif->mcast_sta; |
| 2137 | static const u8 _maddr[] = {0x03, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 2138 | const u8 *maddr = _maddr; |
| 2139 | struct iwl_trans_txq_scd_cfg cfg = { |
| 2140 | .fifo = IWL_MVM_TX_FIFO_MCAST, |
| 2141 | .sta_id = msta->sta_id, |
| 2142 | .tid = IWL_MAX_TID_COUNT, |
| 2143 | .aggregate = false, |
| 2144 | .frame_limit = IWL_FRAME_LIMIT, |
| 2145 | }; |
| 2146 | unsigned int timeout = iwl_mvm_get_wd_timeout(mvm, vif, false, false); |
| 2147 | int ret; |
| 2148 | |
| 2149 | lockdep_assert_held(&mvm->mutex); |
| 2150 | |
| 2151 | if (!iwl_mvm_is_dqa_supported(mvm)) |
| 2152 | return 0; |
| 2153 | |
Liad Kaufman | ee48b72 | 2017-03-21 17:13:16 +0200 | [diff] [blame] | 2154 | if (WARN_ON(vif->type != NL80211_IFTYPE_AP && |
| 2155 | vif->type != NL80211_IFTYPE_ADHOC)) |
Sara Sharon | 26d6c16 | 2017-01-03 12:00:19 +0200 | [diff] [blame] | 2156 | return -ENOTSUPP; |
| 2157 | |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 2158 | /* |
| 2159 | * While in previous FWs we had to exclude cab queue from TFD queue |
| 2160 | * mask, now it is needed as any other queue. |
| 2161 | */ |
| 2162 | if (!iwl_mvm_has_new_tx_api(mvm) && |
| 2163 | fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) { |
| 2164 | iwl_mvm_enable_txq(mvm, vif->cab_queue, vif->cab_queue, 0, |
| 2165 | &cfg, timeout); |
| 2166 | msta->tfd_queue_msk |= BIT(vif->cab_queue); |
| 2167 | } |
Sara Sharon | 26d6c16 | 2017-01-03 12:00:19 +0200 | [diff] [blame] | 2168 | ret = iwl_mvm_add_int_sta_common(mvm, msta, maddr, |
| 2169 | mvmvif->id, mvmvif->color); |
| 2170 | if (ret) { |
| 2171 | iwl_mvm_dealloc_int_sta(mvm, msta); |
| 2172 | return ret; |
| 2173 | } |
| 2174 | |
| 2175 | /* |
| 2176 | * Enable cab queue after the ADD_STA command is sent. |
| 2177 | * This is needed for a000 firmware which won't accept SCD_QUEUE_CFG |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 2178 | * command with unknown station id, and for FW that doesn't support |
| 2179 | * station API since the cab queue is not included in the |
| 2180 | * tfd_queue_mask. |
Sara Sharon | 26d6c16 | 2017-01-03 12:00:19 +0200 | [diff] [blame] | 2181 | */ |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 2182 | if (iwl_mvm_has_new_tx_api(mvm)) { |
| 2183 | int queue = iwl_mvm_tvqm_enable_txq(mvm, vif->cab_queue, |
| 2184 | msta->sta_id, |
| 2185 | IWL_MAX_TID_COUNT, |
| 2186 | timeout); |
Sara Sharon | e2af3fa | 2017-02-22 19:35:10 +0200 | [diff] [blame] | 2187 | mvmvif->cab_queue = queue; |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 2188 | } else if (!fw_has_api(&mvm->fw->ucode_capa, |
| 2189 | IWL_UCODE_TLV_API_STA_TYPE)) { |
Liad Kaufman | ee48b72 | 2017-03-21 17:13:16 +0200 | [diff] [blame] | 2190 | /* |
| 2191 | * In IBSS, ieee80211_check_queues() sets the cab_queue to be |
| 2192 | * invalid, so make sure we use the queue we want. |
| 2193 | * Note that this is done here as we want to avoid making DQA |
| 2194 | * changes in mac80211 layer. |
| 2195 | */ |
| 2196 | if (vif->type == NL80211_IFTYPE_ADHOC) { |
| 2197 | vif->cab_queue = IWL_MVM_DQA_GCAST_QUEUE; |
| 2198 | mvmvif->cab_queue = vif->cab_queue; |
| 2199 | } |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 2200 | iwl_mvm_enable_txq(mvm, vif->cab_queue, vif->cab_queue, 0, |
| 2201 | &cfg, timeout); |
| 2202 | } |
Sara Sharon | 26d6c16 | 2017-01-03 12:00:19 +0200 | [diff] [blame] | 2203 | |
| 2204 | return 0; |
| 2205 | } |
| 2206 | |
| 2207 | /* |
| 2208 | * Send the FW a request to remove the station from it's internal data |
| 2209 | * structures, and in addition remove it from the local data structure. |
| 2210 | */ |
| 2211 | int iwl_mvm_rm_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 2212 | { |
| 2213 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2214 | int ret; |
| 2215 | |
| 2216 | lockdep_assert_held(&mvm->mutex); |
| 2217 | |
| 2218 | if (!iwl_mvm_is_dqa_supported(mvm)) |
| 2219 | return 0; |
| 2220 | |
Sara Sharon | d49394a | 2017-03-05 13:01:08 +0200 | [diff] [blame] | 2221 | iwl_mvm_flush_sta(mvm, &mvmvif->mcast_sta, true, 0); |
| 2222 | |
Sara Sharon | e2af3fa | 2017-02-22 19:35:10 +0200 | [diff] [blame] | 2223 | iwl_mvm_disable_txq(mvm, mvmvif->cab_queue, vif->cab_queue, |
Sara Sharon | 26d6c16 | 2017-01-03 12:00:19 +0200 | [diff] [blame] | 2224 | IWL_MAX_TID_COUNT, 0); |
| 2225 | |
| 2226 | ret = iwl_mvm_rm_sta_common(mvm, mvmvif->mcast_sta.sta_id); |
| 2227 | if (ret) |
| 2228 | IWL_WARN(mvm, "Failed sending remove station\n"); |
| 2229 | |
| 2230 | return ret; |
| 2231 | } |
| 2232 | |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 2233 | #define IWL_MAX_RX_BA_SESSIONS 16 |
| 2234 | |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2235 | static void iwl_mvm_sync_rxq_del_ba(struct iwl_mvm *mvm, u8 baid) |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2236 | { |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2237 | struct iwl_mvm_delba_notif notif = { |
| 2238 | .metadata.type = IWL_MVM_RXQ_NOTIF_DEL_BA, |
| 2239 | .metadata.sync = 1, |
| 2240 | .delba.baid = baid, |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2241 | }; |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2242 | iwl_mvm_sync_rx_queues_internal(mvm, (void *)¬if, sizeof(notif)); |
| 2243 | }; |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2244 | |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2245 | static void iwl_mvm_free_reorder(struct iwl_mvm *mvm, |
| 2246 | struct iwl_mvm_baid_data *data) |
| 2247 | { |
| 2248 | int i; |
| 2249 | |
| 2250 | iwl_mvm_sync_rxq_del_ba(mvm, data->baid); |
| 2251 | |
| 2252 | for (i = 0; i < mvm->trans->num_rx_queues; i++) { |
| 2253 | int j; |
| 2254 | struct iwl_mvm_reorder_buffer *reorder_buf = |
| 2255 | &data->reorder_buf[i]; |
| 2256 | |
Sara Sharon | 0690405 | 2016-02-28 20:28:17 +0200 | [diff] [blame] | 2257 | spin_lock_bh(&reorder_buf->lock); |
| 2258 | if (likely(!reorder_buf->num_stored)) { |
| 2259 | spin_unlock_bh(&reorder_buf->lock); |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2260 | continue; |
Sara Sharon | 0690405 | 2016-02-28 20:28:17 +0200 | [diff] [blame] | 2261 | } |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2262 | |
| 2263 | /* |
| 2264 | * This shouldn't happen in regular DELBA since the internal |
| 2265 | * delBA notification should trigger a release of all frames in |
| 2266 | * the reorder buffer. |
| 2267 | */ |
| 2268 | WARN_ON(1); |
| 2269 | |
| 2270 | for (j = 0; j < reorder_buf->buf_size; j++) |
| 2271 | __skb_queue_purge(&reorder_buf->entries[j]); |
Sara Sharon | 0690405 | 2016-02-28 20:28:17 +0200 | [diff] [blame] | 2272 | /* |
| 2273 | * Prevent timer re-arm. This prevents a very far fetched case |
| 2274 | * where we timed out on the notification. There may be prior |
| 2275 | * RX frames pending in the RX queue before the notification |
| 2276 | * that might get processed between now and the actual deletion |
| 2277 | * and we would re-arm the timer although we are deleting the |
| 2278 | * reorder buffer. |
| 2279 | */ |
| 2280 | reorder_buf->removed = true; |
| 2281 | spin_unlock_bh(&reorder_buf->lock); |
| 2282 | del_timer_sync(&reorder_buf->reorder_timer); |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2283 | } |
| 2284 | } |
| 2285 | |
| 2286 | static void iwl_mvm_init_reorder_buffer(struct iwl_mvm *mvm, |
| 2287 | u32 sta_id, |
| 2288 | struct iwl_mvm_baid_data *data, |
| 2289 | u16 ssn, u8 buf_size) |
| 2290 | { |
| 2291 | int i; |
| 2292 | |
| 2293 | for (i = 0; i < mvm->trans->num_rx_queues; i++) { |
| 2294 | struct iwl_mvm_reorder_buffer *reorder_buf = |
| 2295 | &data->reorder_buf[i]; |
| 2296 | int j; |
| 2297 | |
| 2298 | reorder_buf->num_stored = 0; |
| 2299 | reorder_buf->head_sn = ssn; |
| 2300 | reorder_buf->buf_size = buf_size; |
Sara Sharon | 0690405 | 2016-02-28 20:28:17 +0200 | [diff] [blame] | 2301 | /* rx reorder timer */ |
| 2302 | reorder_buf->reorder_timer.function = |
| 2303 | iwl_mvm_reorder_timer_expired; |
| 2304 | reorder_buf->reorder_timer.data = (unsigned long)reorder_buf; |
| 2305 | init_timer(&reorder_buf->reorder_timer); |
| 2306 | spin_lock_init(&reorder_buf->lock); |
| 2307 | reorder_buf->mvm = mvm; |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2308 | reorder_buf->queue = i; |
| 2309 | reorder_buf->sta_id = sta_id; |
Sara Sharon | 5d43eab | 2017-02-02 12:51:39 +0200 | [diff] [blame] | 2310 | reorder_buf->valid = false; |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2311 | for (j = 0; j < reorder_buf->buf_size; j++) |
| 2312 | __skb_queue_head_init(&reorder_buf->entries[j]); |
| 2313 | } |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2314 | } |
| 2315 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2316 | int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2317 | int tid, u16 ssn, bool start, u8 buf_size, u16 timeout) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2318 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 2319 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2320 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2321 | struct iwl_mvm_baid_data *baid_data = NULL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2322 | int ret; |
| 2323 | u32 status; |
| 2324 | |
| 2325 | lockdep_assert_held(&mvm->mutex); |
| 2326 | |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 2327 | if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) { |
| 2328 | IWL_WARN(mvm, "Not enough RX BA SESSIONS\n"); |
| 2329 | return -ENOSPC; |
| 2330 | } |
| 2331 | |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2332 | if (iwl_mvm_has_new_rx_api(mvm) && start) { |
| 2333 | /* |
| 2334 | * Allocate here so if allocation fails we can bail out early |
| 2335 | * before starting the BA session in the firmware |
| 2336 | */ |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2337 | baid_data = kzalloc(sizeof(*baid_data) + |
| 2338 | mvm->trans->num_rx_queues * |
| 2339 | sizeof(baid_data->reorder_buf[0]), |
| 2340 | GFP_KERNEL); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2341 | if (!baid_data) |
| 2342 | return -ENOMEM; |
| 2343 | } |
| 2344 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2345 | cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); |
| 2346 | cmd.sta_id = mvm_sta->sta_id; |
| 2347 | cmd.add_modify = STA_MODE_MODIFY; |
Emmanuel Grumbach | 93a4266 | 2013-07-02 13:35:35 +0300 | [diff] [blame] | 2348 | if (start) { |
| 2349 | cmd.add_immediate_ba_tid = (u8) tid; |
| 2350 | cmd.add_immediate_ba_ssn = cpu_to_le16(ssn); |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 2351 | cmd.rx_ba_window = cpu_to_le16((u16)buf_size); |
Emmanuel Grumbach | 93a4266 | 2013-07-02 13:35:35 +0300 | [diff] [blame] | 2352 | } else { |
| 2353 | cmd.remove_immediate_ba_tid = (u8) tid; |
| 2354 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2355 | cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID : |
| 2356 | STA_MODIFY_REMOVE_BA_TID; |
| 2357 | |
| 2358 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 2359 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 2360 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2361 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2362 | if (ret) |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2363 | goto out_free; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2364 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 2365 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2366 | case ADD_STA_SUCCESS: |
Sara Sharon | 35263a0 | 2016-06-21 12:12:10 +0300 | [diff] [blame] | 2367 | IWL_DEBUG_HT(mvm, "RX BA Session %sed in fw\n", |
| 2368 | start ? "start" : "stopp"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2369 | break; |
| 2370 | case ADD_STA_IMMEDIATE_BA_FAILURE: |
| 2371 | IWL_WARN(mvm, "RX BA Session refused by fw\n"); |
| 2372 | ret = -ENOSPC; |
| 2373 | break; |
| 2374 | default: |
| 2375 | ret = -EIO; |
| 2376 | IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n", |
| 2377 | start ? "start" : "stopp", status); |
| 2378 | break; |
| 2379 | } |
| 2380 | |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2381 | if (ret) |
| 2382 | goto out_free; |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 2383 | |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2384 | if (start) { |
| 2385 | u8 baid; |
| 2386 | |
| 2387 | mvm->rx_ba_sessions++; |
| 2388 | |
| 2389 | if (!iwl_mvm_has_new_rx_api(mvm)) |
| 2390 | return 0; |
| 2391 | |
| 2392 | if (WARN_ON(!(status & IWL_ADD_STA_BAID_VALID_MASK))) { |
| 2393 | ret = -EINVAL; |
| 2394 | goto out_free; |
| 2395 | } |
| 2396 | baid = (u8)((status & IWL_ADD_STA_BAID_MASK) >> |
| 2397 | IWL_ADD_STA_BAID_SHIFT); |
| 2398 | baid_data->baid = baid; |
| 2399 | baid_data->timeout = timeout; |
| 2400 | baid_data->last_rx = jiffies; |
Wei Yongjun | 72c240f | 2016-07-12 11:40:57 +0000 | [diff] [blame] | 2401 | setup_timer(&baid_data->session_timer, |
| 2402 | iwl_mvm_rx_agg_session_expired, |
| 2403 | (unsigned long)&mvm->baid_map[baid]); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2404 | baid_data->mvm = mvm; |
| 2405 | baid_data->tid = tid; |
| 2406 | baid_data->sta_id = mvm_sta->sta_id; |
| 2407 | |
| 2408 | mvm_sta->tid_to_baid[tid] = baid; |
| 2409 | if (timeout) |
| 2410 | mod_timer(&baid_data->session_timer, |
| 2411 | TU_TO_EXP_TIME(timeout * 2)); |
| 2412 | |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2413 | iwl_mvm_init_reorder_buffer(mvm, mvm_sta->sta_id, |
| 2414 | baid_data, ssn, buf_size); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2415 | /* |
| 2416 | * protect the BA data with RCU to cover a case where our |
| 2417 | * internal RX sync mechanism will timeout (not that it's |
| 2418 | * supposed to happen) and we will free the session data while |
| 2419 | * RX is being processed in parallel |
| 2420 | */ |
Sara Sharon | 35263a0 | 2016-06-21 12:12:10 +0300 | [diff] [blame] | 2421 | IWL_DEBUG_HT(mvm, "Sta %d(%d) is assigned to BAID %d\n", |
| 2422 | mvm_sta->sta_id, tid, baid); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2423 | WARN_ON(rcu_access_pointer(mvm->baid_map[baid])); |
| 2424 | rcu_assign_pointer(mvm->baid_map[baid], baid_data); |
Sara Sharon | 60dec52 | 2016-06-21 14:14:08 +0300 | [diff] [blame] | 2425 | } else { |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2426 | u8 baid = mvm_sta->tid_to_baid[tid]; |
| 2427 | |
Sara Sharon | 60dec52 | 2016-06-21 14:14:08 +0300 | [diff] [blame] | 2428 | if (mvm->rx_ba_sessions > 0) |
| 2429 | /* check that restart flow didn't zero the counter */ |
| 2430 | mvm->rx_ba_sessions--; |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2431 | if (!iwl_mvm_has_new_rx_api(mvm)) |
| 2432 | return 0; |
| 2433 | |
| 2434 | if (WARN_ON(baid == IWL_RX_REORDER_DATA_INVALID_BAID)) |
| 2435 | return -EINVAL; |
| 2436 | |
| 2437 | baid_data = rcu_access_pointer(mvm->baid_map[baid]); |
| 2438 | if (WARN_ON(!baid_data)) |
| 2439 | return -EINVAL; |
| 2440 | |
| 2441 | /* synchronize all rx queues so we can safely delete */ |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2442 | iwl_mvm_free_reorder(mvm, baid_data); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2443 | del_timer_sync(&baid_data->session_timer); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2444 | RCU_INIT_POINTER(mvm->baid_map[baid], NULL); |
| 2445 | kfree_rcu(baid_data, rcu_head); |
Sara Sharon | 35263a0 | 2016-06-21 12:12:10 +0300 | [diff] [blame] | 2446 | IWL_DEBUG_HT(mvm, "BAID %d is free\n", baid); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2447 | } |
| 2448 | return 0; |
| 2449 | |
| 2450 | out_free: |
| 2451 | kfree(baid_data); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2452 | return ret; |
| 2453 | } |
| 2454 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 2455 | int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
| 2456 | int tid, u8 queue, bool start) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2457 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 2458 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2459 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2460 | int ret; |
| 2461 | u32 status; |
| 2462 | |
| 2463 | lockdep_assert_held(&mvm->mutex); |
| 2464 | |
| 2465 | if (start) { |
| 2466 | mvm_sta->tfd_queue_msk |= BIT(queue); |
| 2467 | mvm_sta->tid_disable_agg &= ~BIT(tid); |
| 2468 | } else { |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2469 | /* In DQA-mode the queue isn't removed on agg termination */ |
| 2470 | if (!iwl_mvm_is_dqa_supported(mvm)) |
| 2471 | mvm_sta->tfd_queue_msk &= ~BIT(queue); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2472 | mvm_sta->tid_disable_agg |= BIT(tid); |
| 2473 | } |
| 2474 | |
| 2475 | cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); |
| 2476 | cmd.sta_id = mvm_sta->sta_id; |
| 2477 | cmd.add_modify = STA_MODE_MODIFY; |
Sara Sharon | bb49701 | 2016-09-29 14:52:40 +0300 | [diff] [blame] | 2478 | if (!iwl_mvm_has_new_tx_api(mvm)) |
| 2479 | cmd.modify_mask = STA_MODIFY_QUEUES; |
| 2480 | cmd.modify_mask |= STA_MODIFY_TID_DISABLE_TX; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2481 | cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk); |
| 2482 | cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg); |
| 2483 | |
| 2484 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 2485 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 2486 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2487 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2488 | if (ret) |
| 2489 | return ret; |
| 2490 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 2491 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2492 | case ADD_STA_SUCCESS: |
| 2493 | break; |
| 2494 | default: |
| 2495 | ret = -EIO; |
| 2496 | IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n", |
| 2497 | start ? "start" : "stopp", status); |
| 2498 | break; |
| 2499 | } |
| 2500 | |
| 2501 | return ret; |
| 2502 | } |
| 2503 | |
Emmanuel Grumbach | b797e3f | 2014-03-06 14:49:36 +0200 | [diff] [blame] | 2504 | const u8 tid_to_mac80211_ac[] = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2505 | IEEE80211_AC_BE, |
| 2506 | IEEE80211_AC_BK, |
| 2507 | IEEE80211_AC_BK, |
| 2508 | IEEE80211_AC_BE, |
| 2509 | IEEE80211_AC_VI, |
| 2510 | IEEE80211_AC_VI, |
| 2511 | IEEE80211_AC_VO, |
| 2512 | IEEE80211_AC_VO, |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 2513 | IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2514 | }; |
| 2515 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2516 | static const u8 tid_to_ucode_ac[] = { |
| 2517 | AC_BE, |
| 2518 | AC_BK, |
| 2519 | AC_BK, |
| 2520 | AC_BE, |
| 2521 | AC_VI, |
| 2522 | AC_VI, |
| 2523 | AC_VO, |
| 2524 | AC_VO, |
| 2525 | }; |
| 2526 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2527 | int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 2528 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) |
| 2529 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 2530 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2531 | struct iwl_mvm_tid_data *tid_data; |
| 2532 | int txq_id; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2533 | int ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2534 | |
| 2535 | if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT)) |
| 2536 | return -EINVAL; |
| 2537 | |
| 2538 | if (mvmsta->tid_data[tid].state != IWL_AGG_OFF) { |
| 2539 | IWL_ERR(mvm, "Start AGG when state is not IWL_AGG_OFF %d!\n", |
| 2540 | mvmsta->tid_data[tid].state); |
| 2541 | return -ENXIO; |
| 2542 | } |
| 2543 | |
| 2544 | lockdep_assert_held(&mvm->mutex); |
| 2545 | |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 2546 | spin_lock_bh(&mvmsta->lock); |
| 2547 | |
| 2548 | /* possible race condition - we entered D0i3 while starting agg */ |
| 2549 | if (test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) { |
| 2550 | spin_unlock_bh(&mvmsta->lock); |
| 2551 | IWL_ERR(mvm, "Entered D0i3 while starting Tx agg\n"); |
| 2552 | return -EIO; |
| 2553 | } |
| 2554 | |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2555 | spin_lock(&mvm->queue_info_lock); |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2556 | |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2557 | /* |
| 2558 | * Note the possible cases: |
| 2559 | * 1. In DQA mode with an enabled TXQ - TXQ needs to become agg'ed |
| 2560 | * 2. Non-DQA mode: the TXQ hasn't yet been enabled, so find a free |
| 2561 | * one and mark it as reserved |
| 2562 | * 3. In DQA mode, but no traffic yet on this TID: same treatment as in |
| 2563 | * non-DQA mode, since the TXQ hasn't yet been allocated |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 2564 | * Don't support case 3 for new TX path as it is not expected to happen |
| 2565 | * and aggregation will be offloaded soon anyway |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2566 | */ |
| 2567 | txq_id = mvmsta->tid_data[tid].txq_id; |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 2568 | if (iwl_mvm_has_new_tx_api(mvm)) { |
| 2569 | if (txq_id == IWL_MVM_INVALID_QUEUE) { |
| 2570 | ret = -ENXIO; |
| 2571 | goto release_locks; |
| 2572 | } |
| 2573 | } else if (iwl_mvm_is_dqa_supported(mvm) && |
| 2574 | unlikely(mvm->queue_info[txq_id].status == |
| 2575 | IWL_MVM_QUEUE_SHARED)) { |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2576 | ret = -ENXIO; |
| 2577 | IWL_DEBUG_TX_QUEUES(mvm, |
| 2578 | "Can't start tid %d agg on shared queue!\n", |
| 2579 | tid); |
| 2580 | goto release_locks; |
| 2581 | } else if (!iwl_mvm_is_dqa_supported(mvm) || |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2582 | mvm->queue_info[txq_id].status != IWL_MVM_QUEUE_READY) { |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 2583 | txq_id = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id, |
| 2584 | mvm->first_agg_queue, |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2585 | mvm->last_agg_queue); |
| 2586 | if (txq_id < 0) { |
| 2587 | ret = txq_id; |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2588 | IWL_ERR(mvm, "Failed to allocate agg queue\n"); |
| 2589 | goto release_locks; |
| 2590 | } |
Sara Sharon | 01796ff | 2016-11-16 17:04:36 +0200 | [diff] [blame] | 2591 | /* |
| 2592 | * TXQ shouldn't be in inactive mode for non-DQA, so getting |
| 2593 | * an inactive queue from iwl_mvm_find_free_queue() is |
| 2594 | * certainly a bug |
| 2595 | */ |
| 2596 | WARN_ON(mvm->queue_info[txq_id].status == |
| 2597 | IWL_MVM_QUEUE_INACTIVE); |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2598 | |
| 2599 | /* TXQ hasn't yet been enabled, so mark it only as reserved */ |
| 2600 | mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_RESERVED; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2601 | } |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2602 | |
| 2603 | spin_unlock(&mvm->queue_info_lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2604 | |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2605 | IWL_DEBUG_TX_QUEUES(mvm, |
| 2606 | "AGG for tid %d will be on queue #%d\n", |
| 2607 | tid, txq_id); |
| 2608 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2609 | tid_data = &mvmsta->tid_data[tid]; |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 2610 | tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2611 | tid_data->txq_id = txq_id; |
| 2612 | *ssn = tid_data->ssn; |
| 2613 | |
| 2614 | IWL_DEBUG_TX_QUEUES(mvm, |
| 2615 | "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n", |
| 2616 | mvmsta->sta_id, tid, txq_id, tid_data->ssn, |
| 2617 | tid_data->next_reclaimed); |
| 2618 | |
| 2619 | if (tid_data->ssn == tid_data->next_reclaimed) { |
| 2620 | tid_data->state = IWL_AGG_STARTING; |
| 2621 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2622 | } else { |
| 2623 | tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA; |
| 2624 | } |
| 2625 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2626 | ret = 0; |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2627 | goto out; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2628 | |
| 2629 | release_locks: |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2630 | spin_unlock(&mvm->queue_info_lock); |
| 2631 | out: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2632 | spin_unlock_bh(&mvmsta->lock); |
| 2633 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2634 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2635 | } |
| 2636 | |
| 2637 | 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] | 2638 | struct ieee80211_sta *sta, u16 tid, u8 buf_size, |
| 2639 | bool amsdu) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2640 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 2641 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2642 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
Emmanuel Grumbach | 5d42e7b | 2015-03-19 20:04:51 +0200 | [diff] [blame] | 2643 | unsigned int wdg_timeout = |
| 2644 | iwl_mvm_get_wd_timeout(mvm, vif, sta->tdls, false); |
Emmanuel Grumbach | eea76c3 | 2016-02-21 16:29:17 +0200 | [diff] [blame] | 2645 | int queue, ret; |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2646 | bool alloc_queue = true; |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2647 | enum iwl_mvm_queue_status queue_status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2648 | u16 ssn; |
| 2649 | |
Emmanuel Grumbach | eea76c3 | 2016-02-21 16:29:17 +0200 | [diff] [blame] | 2650 | struct iwl_trans_txq_scd_cfg cfg = { |
| 2651 | .sta_id = mvmsta->sta_id, |
| 2652 | .tid = tid, |
| 2653 | .frame_limit = buf_size, |
| 2654 | .aggregate = true, |
| 2655 | }; |
| 2656 | |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 2657 | BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE) |
| 2658 | != IWL_MAX_TID_COUNT); |
| 2659 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2660 | buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF); |
| 2661 | |
| 2662 | spin_lock_bh(&mvmsta->lock); |
| 2663 | ssn = tid_data->ssn; |
| 2664 | queue = tid_data->txq_id; |
| 2665 | tid_data->state = IWL_AGG_ON; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 2666 | mvmsta->agg_tids |= BIT(tid); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2667 | tid_data->ssn = 0xffff; |
Emmanuel Grumbach | bb81bb6 | 2015-10-26 16:00:29 +0200 | [diff] [blame] | 2668 | tid_data->amsdu_in_ampdu_allowed = amsdu; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2669 | spin_unlock_bh(&mvmsta->lock); |
| 2670 | |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 2671 | if (iwl_mvm_has_new_tx_api(mvm)) { |
| 2672 | /* |
| 2673 | * If no queue iwl_mvm_sta_tx_agg_start() would have failed so |
| 2674 | * no need to check queue's status |
| 2675 | */ |
| 2676 | if (buf_size < mvmsta->max_agg_bufsize) |
| 2677 | return -ENOTSUPP; |
| 2678 | |
| 2679 | ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true); |
| 2680 | if (ret) |
| 2681 | return -EIO; |
| 2682 | goto out; |
| 2683 | } |
| 2684 | |
Emmanuel Grumbach | eea76c3 | 2016-02-21 16:29:17 +0200 | [diff] [blame] | 2685 | cfg.fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]]; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2686 | |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2687 | spin_lock_bh(&mvm->queue_info_lock); |
| 2688 | queue_status = mvm->queue_info[queue].status; |
| 2689 | spin_unlock_bh(&mvm->queue_info_lock); |
| 2690 | |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2691 | /* In DQA mode, the existing queue might need to be reconfigured */ |
| 2692 | if (iwl_mvm_is_dqa_supported(mvm)) { |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2693 | /* Maybe there is no need to even alloc a queue... */ |
| 2694 | if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_READY) |
| 2695 | alloc_queue = false; |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2696 | |
| 2697 | /* |
| 2698 | * Only reconfig the SCD for the queue if the window size has |
| 2699 | * changed from current (become smaller) |
| 2700 | */ |
| 2701 | if (!alloc_queue && buf_size < mvmsta->max_agg_bufsize) { |
| 2702 | /* |
| 2703 | * If reconfiguring an existing queue, it first must be |
| 2704 | * drained |
| 2705 | */ |
Sara Sharon | a1a5787 | 2017-03-05 11:38:58 +0200 | [diff] [blame] | 2706 | ret = iwl_trans_wait_tx_queues_empty(mvm->trans, |
| 2707 | BIT(queue)); |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2708 | if (ret) { |
| 2709 | IWL_ERR(mvm, |
| 2710 | "Error draining queue before reconfig\n"); |
| 2711 | return ret; |
| 2712 | } |
| 2713 | |
| 2714 | ret = iwl_mvm_reconfig_scd(mvm, queue, cfg.fifo, |
| 2715 | mvmsta->sta_id, tid, |
| 2716 | buf_size, ssn); |
| 2717 | if (ret) { |
| 2718 | IWL_ERR(mvm, |
| 2719 | "Error reconfiguring TXQ #%d\n", queue); |
| 2720 | return ret; |
| 2721 | } |
| 2722 | } |
| 2723 | } |
| 2724 | |
| 2725 | if (alloc_queue) |
| 2726 | iwl_mvm_enable_txq(mvm, queue, |
| 2727 | vif->hw_queue[tid_to_mac80211_ac[tid]], ssn, |
| 2728 | &cfg, wdg_timeout); |
Andrei Otcheretianski | fa7878e | 2015-05-05 09:28:16 +0300 | [diff] [blame] | 2729 | |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2730 | /* Send ADD_STA command to enable aggs only if the queue isn't shared */ |
| 2731 | if (queue_status != IWL_MVM_QUEUE_SHARED) { |
| 2732 | ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true); |
| 2733 | if (ret) |
| 2734 | return -EIO; |
| 2735 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2736 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2737 | /* No need to mark as reserved */ |
| 2738 | spin_lock_bh(&mvm->queue_info_lock); |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2739 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2740 | spin_unlock_bh(&mvm->queue_info_lock); |
| 2741 | |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 2742 | out: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2743 | /* |
| 2744 | * Even though in theory the peer could have different |
| 2745 | * aggregation reorder buffer sizes for different sessions, |
| 2746 | * our ucode doesn't allow for that and has a global limit |
| 2747 | * for each station. Therefore, use the minimum of all the |
| 2748 | * aggregation sessions and our default value. |
| 2749 | */ |
| 2750 | mvmsta->max_agg_bufsize = |
| 2751 | min(mvmsta->max_agg_bufsize, buf_size); |
| 2752 | mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize; |
| 2753 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 2754 | IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n", |
| 2755 | sta->addr, tid); |
| 2756 | |
Eyal Shapira | 9e68094 | 2013-11-09 00:16:16 +0200 | [diff] [blame] | 2757 | return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2758 | } |
| 2759 | |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 2760 | static void iwl_mvm_unreserve_agg_queue(struct iwl_mvm *mvm, |
| 2761 | struct iwl_mvm_sta *mvmsta, |
| 2762 | u16 txq_id) |
| 2763 | { |
| 2764 | if (iwl_mvm_has_new_tx_api(mvm)) |
| 2765 | return; |
| 2766 | |
| 2767 | spin_lock_bh(&mvm->queue_info_lock); |
| 2768 | /* |
| 2769 | * The TXQ is marked as reserved only if no traffic came through yet |
| 2770 | * This means no traffic has been sent on this TID (agg'd or not), so |
| 2771 | * we no longer have use for the queue. Since it hasn't even been |
| 2772 | * allocated through iwl_mvm_enable_txq, so we can just mark it back as |
| 2773 | * free. |
| 2774 | */ |
| 2775 | if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED) |
| 2776 | mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE; |
| 2777 | |
| 2778 | spin_unlock_bh(&mvm->queue_info_lock); |
| 2779 | } |
| 2780 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2781 | int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 2782 | struct ieee80211_sta *sta, u16 tid) |
| 2783 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 2784 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2785 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
| 2786 | u16 txq_id; |
| 2787 | int err; |
| 2788 | |
Emmanuel Grumbach | f9aa8dd | 2013-03-04 09:11:08 +0200 | [diff] [blame] | 2789 | /* |
| 2790 | * If mac80211 is cleaning its state, then say that we finished since |
| 2791 | * our state has been cleared anyway. |
| 2792 | */ |
| 2793 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
| 2794 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2795 | return 0; |
| 2796 | } |
| 2797 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2798 | spin_lock_bh(&mvmsta->lock); |
| 2799 | |
| 2800 | txq_id = tid_data->txq_id; |
| 2801 | |
| 2802 | IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n", |
| 2803 | mvmsta->sta_id, tid, txq_id, tid_data->state); |
| 2804 | |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 2805 | mvmsta->agg_tids &= ~BIT(tid); |
| 2806 | |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 2807 | iwl_mvm_unreserve_agg_queue(mvm, mvmsta, txq_id); |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2808 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2809 | switch (tid_data->state) { |
| 2810 | case IWL_AGG_ON: |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 2811 | tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2812 | |
| 2813 | IWL_DEBUG_TX_QUEUES(mvm, |
| 2814 | "ssn = %d, next_recl = %d\n", |
| 2815 | tid_data->ssn, tid_data->next_reclaimed); |
| 2816 | |
Liad Kaufman | 664e968 | 2017-04-05 10:35:18 +0300 | [diff] [blame] | 2817 | /* |
| 2818 | * There are still packets for this RA / TID in the HW. |
| 2819 | * Not relevant for DQA mode, since there is no need to disable |
| 2820 | * the queue. |
| 2821 | */ |
| 2822 | if (!iwl_mvm_is_dqa_supported(mvm) && |
| 2823 | tid_data->ssn != tid_data->next_reclaimed) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2824 | tid_data->state = IWL_EMPTYING_HW_QUEUE_DELBA; |
| 2825 | err = 0; |
| 2826 | break; |
| 2827 | } |
| 2828 | |
| 2829 | tid_data->ssn = 0xffff; |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 2830 | tid_data->state = IWL_AGG_OFF; |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 2831 | spin_unlock_bh(&mvmsta->lock); |
| 2832 | |
| 2833 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2834 | |
| 2835 | iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false); |
| 2836 | |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2837 | if (!iwl_mvm_is_dqa_supported(mvm)) { |
| 2838 | int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]]; |
| 2839 | |
| 2840 | iwl_mvm_disable_txq(mvm, txq_id, mac_queue, tid, 0); |
| 2841 | } |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 2842 | return 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2843 | case IWL_AGG_STARTING: |
| 2844 | case IWL_EMPTYING_HW_QUEUE_ADDBA: |
| 2845 | /* |
| 2846 | * The agg session has been stopped before it was set up. This |
| 2847 | * can happen when the AddBA timer times out for example. |
| 2848 | */ |
| 2849 | |
| 2850 | /* No barriers since we are under mutex */ |
| 2851 | lockdep_assert_held(&mvm->mutex); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2852 | |
| 2853 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2854 | tid_data->state = IWL_AGG_OFF; |
| 2855 | err = 0; |
| 2856 | break; |
| 2857 | default: |
| 2858 | IWL_ERR(mvm, |
| 2859 | "Stopping AGG while state not ON or starting for %d on %d (%d)\n", |
| 2860 | mvmsta->sta_id, tid, tid_data->state); |
| 2861 | IWL_ERR(mvm, |
| 2862 | "\ttid_data->txq_id = %d\n", tid_data->txq_id); |
| 2863 | err = -EINVAL; |
| 2864 | } |
| 2865 | |
| 2866 | spin_unlock_bh(&mvmsta->lock); |
| 2867 | |
| 2868 | return err; |
| 2869 | } |
| 2870 | |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2871 | int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 2872 | struct ieee80211_sta *sta, u16 tid) |
| 2873 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 2874 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2875 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
| 2876 | u16 txq_id; |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2877 | enum iwl_mvm_agg_state old_state; |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2878 | |
| 2879 | /* |
| 2880 | * First set the agg state to OFF to avoid calling |
| 2881 | * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty. |
| 2882 | */ |
| 2883 | spin_lock_bh(&mvmsta->lock); |
| 2884 | txq_id = tid_data->txq_id; |
| 2885 | IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n", |
| 2886 | mvmsta->sta_id, tid, txq_id, tid_data->state); |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2887 | old_state = tid_data->state; |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2888 | tid_data->state = IWL_AGG_OFF; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 2889 | mvmsta->agg_tids &= ~BIT(tid); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2890 | spin_unlock_bh(&mvmsta->lock); |
| 2891 | |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 2892 | iwl_mvm_unreserve_agg_queue(mvm, mvmsta, txq_id); |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2893 | |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2894 | if (old_state >= IWL_AGG_ON) { |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 2895 | iwl_mvm_drain_sta(mvm, mvmsta, true); |
Luca Coelho | 5888a40 | 2015-10-06 09:54:57 +0300 | [diff] [blame] | 2896 | if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), 0)) |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2897 | IWL_ERR(mvm, "Couldn't flush the AGG queue\n"); |
Sara Sharon | d6d517b | 2017-03-06 10:16:11 +0200 | [diff] [blame] | 2898 | |
| 2899 | if (iwl_mvm_has_new_tx_api(mvm)) |
| 2900 | iwl_trans_wait_txq_empty(mvm->trans, txq_id); |
| 2901 | |
| 2902 | else |
| 2903 | iwl_trans_wait_tx_queues_empty(mvm->trans, BIT(txq_id)); |
| 2904 | |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 2905 | iwl_mvm_drain_sta(mvm, mvmsta, false); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2906 | |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 2907 | iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false); |
| 2908 | |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2909 | if (!iwl_mvm_is_dqa_supported(mvm)) { |
| 2910 | int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]]; |
| 2911 | |
| 2912 | iwl_mvm_disable_txq(mvm, tid_data->txq_id, mac_queue, |
| 2913 | tid, 0); |
| 2914 | } |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2915 | } |
| 2916 | |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2917 | return 0; |
| 2918 | } |
| 2919 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2920 | static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm) |
| 2921 | { |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2922 | int i, max = -1, max_offs = -1; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2923 | |
| 2924 | lockdep_assert_held(&mvm->mutex); |
| 2925 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2926 | /* Pick the unused key offset with the highest 'deleted' |
| 2927 | * counter. Every time a key is deleted, all the counters |
| 2928 | * are incremented and the one that was just deleted is |
| 2929 | * reset to zero. Thus, the highest counter is the one |
| 2930 | * that was deleted longest ago. Pick that one. |
| 2931 | */ |
| 2932 | for (i = 0; i < STA_KEY_MAX_NUM; i++) { |
| 2933 | if (test_bit(i, mvm->fw_key_table)) |
| 2934 | continue; |
| 2935 | if (mvm->fw_key_deleted[i] > max) { |
| 2936 | max = mvm->fw_key_deleted[i]; |
| 2937 | max_offs = i; |
| 2938 | } |
| 2939 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2940 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2941 | if (max_offs < 0) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2942 | return STA_KEY_IDX_INVALID; |
| 2943 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2944 | return max_offs; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2945 | } |
| 2946 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2947 | static struct iwl_mvm_sta *iwl_mvm_get_key_sta(struct iwl_mvm *mvm, |
| 2948 | struct ieee80211_vif *vif, |
| 2949 | struct ieee80211_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2950 | { |
Johannes Berg | 5b530e9 | 2014-12-23 16:00:17 +0100 | [diff] [blame] | 2951 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2952 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2953 | if (sta) |
| 2954 | return iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2955 | |
| 2956 | /* |
| 2957 | * The device expects GTKs for station interfaces to be |
| 2958 | * installed as GTKs for the AP station. If we have no |
| 2959 | * station ID, then use AP's station ID. |
| 2960 | */ |
| 2961 | if (vif->type == NL80211_IFTYPE_STATION && |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 2962 | mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) { |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 2963 | u8 sta_id = mvmvif->ap_sta_id; |
| 2964 | |
Emmanuel Grumbach | 7d6a1ab | 2016-05-15 10:20:29 +0300 | [diff] [blame] | 2965 | sta = rcu_dereference_check(mvm->fw_id_to_mac_id[sta_id], |
| 2966 | lockdep_is_held(&mvm->mutex)); |
| 2967 | |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 2968 | /* |
| 2969 | * It is possible that the 'sta' parameter is NULL, |
| 2970 | * for example when a GTK is removed - the sta_id will then |
| 2971 | * be the AP ID, and no station was passed by mac80211. |
| 2972 | */ |
Emmanuel Grumbach | 7d6a1ab | 2016-05-15 10:20:29 +0300 | [diff] [blame] | 2973 | if (IS_ERR_OR_NULL(sta)) |
| 2974 | return NULL; |
| 2975 | |
| 2976 | return iwl_mvm_sta_from_mac80211(sta); |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 2977 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2978 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2979 | return NULL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2980 | } |
| 2981 | |
| 2982 | static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm, |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 2983 | u32 sta_id, |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 2984 | struct ieee80211_key_conf *key, bool mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2985 | u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags, |
| 2986 | u8 key_offset) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2987 | { |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 2988 | union { |
| 2989 | struct iwl_mvm_add_sta_key_cmd_v1 cmd_v1; |
| 2990 | struct iwl_mvm_add_sta_key_cmd cmd; |
| 2991 | } u = {}; |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2992 | __le16 key_flags; |
Johannes Berg | 7992074 | 2014-11-03 15:43:04 +0100 | [diff] [blame] | 2993 | int ret; |
| 2994 | u32 status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2995 | u16 keyidx; |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 2996 | u64 pn = 0; |
| 2997 | int i, size; |
| 2998 | bool new_api = fw_has_api(&mvm->fw->ucode_capa, |
| 2999 | IWL_UCODE_TLV_API_TKIP_MIC_KEYS); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3000 | |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3001 | if (sta_id == IWL_MVM_INVALID_STA) |
| 3002 | return -EINVAL; |
| 3003 | |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3004 | keyidx = (key->keyidx << STA_KEY_FLG_KEYID_POS) & |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3005 | STA_KEY_FLG_KEYID_MSK; |
| 3006 | key_flags = cpu_to_le16(keyidx); |
| 3007 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP); |
| 3008 | |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3009 | switch (key->cipher) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3010 | case WLAN_CIPHER_SUITE_TKIP: |
| 3011 | key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP); |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3012 | if (new_api) { |
| 3013 | memcpy((void *)&u.cmd.tx_mic_key, |
| 3014 | &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY], |
| 3015 | IWL_MIC_KEY_SIZE); |
| 3016 | |
| 3017 | memcpy((void *)&u.cmd.rx_mic_key, |
| 3018 | &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY], |
| 3019 | IWL_MIC_KEY_SIZE); |
| 3020 | pn = atomic64_read(&key->tx_pn); |
| 3021 | |
| 3022 | } else { |
| 3023 | u.cmd_v1.tkip_rx_tsc_byte2 = tkip_iv32; |
| 3024 | for (i = 0; i < 5; i++) |
| 3025 | u.cmd_v1.tkip_rx_ttak[i] = |
| 3026 | cpu_to_le16(tkip_p1k[i]); |
| 3027 | } |
| 3028 | memcpy(u.cmd.common.key, key->key, key->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3029 | break; |
| 3030 | case WLAN_CIPHER_SUITE_CCMP: |
| 3031 | key_flags |= cpu_to_le16(STA_KEY_FLG_CCM); |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3032 | memcpy(u.cmd.common.key, key->key, key->keylen); |
| 3033 | if (new_api) |
| 3034 | pn = atomic64_read(&key->tx_pn); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3035 | break; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3036 | case WLAN_CIPHER_SUITE_WEP104: |
| 3037 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES); |
John W. Linville | aa0cb08 | 2015-01-12 16:18:11 -0500 | [diff] [blame] | 3038 | /* fall through */ |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3039 | case WLAN_CIPHER_SUITE_WEP40: |
| 3040 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP); |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3041 | memcpy(u.cmd.common.key + 3, key->key, key->keylen); |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3042 | break; |
Ayala Beker | 2a53d16 | 2016-04-07 16:21:57 +0300 | [diff] [blame] | 3043 | case WLAN_CIPHER_SUITE_GCMP_256: |
| 3044 | key_flags |= cpu_to_le16(STA_KEY_FLG_KEY_32BYTES); |
| 3045 | /* fall through */ |
| 3046 | case WLAN_CIPHER_SUITE_GCMP: |
| 3047 | key_flags |= cpu_to_le16(STA_KEY_FLG_GCMP); |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3048 | memcpy(u.cmd.common.key, key->key, key->keylen); |
| 3049 | if (new_api) |
| 3050 | pn = atomic64_read(&key->tx_pn); |
Ayala Beker | 2a53d16 | 2016-04-07 16:21:57 +0300 | [diff] [blame] | 3051 | break; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3052 | default: |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 3053 | key_flags |= cpu_to_le16(STA_KEY_FLG_EXT); |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3054 | memcpy(u.cmd.common.key, key->key, key->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3055 | } |
| 3056 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3057 | if (mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3058 | key_flags |= cpu_to_le16(STA_KEY_MULTICAST); |
| 3059 | |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3060 | u.cmd.common.key_offset = key_offset; |
| 3061 | u.cmd.common.key_flags = key_flags; |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3062 | u.cmd.common.sta_id = sta_id; |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3063 | |
| 3064 | if (new_api) { |
| 3065 | u.cmd.transmit_seq_cnt = cpu_to_le64(pn); |
| 3066 | size = sizeof(u.cmd); |
| 3067 | } else { |
| 3068 | size = sizeof(u.cmd_v1); |
| 3069 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3070 | |
| 3071 | status = ADD_STA_SUCCESS; |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 3072 | if (cmd_flags & CMD_ASYNC) |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3073 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC, size, |
| 3074 | &u.cmd); |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 3075 | else |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3076 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, size, |
| 3077 | &u.cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3078 | |
| 3079 | switch (status) { |
| 3080 | case ADD_STA_SUCCESS: |
| 3081 | IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n"); |
| 3082 | break; |
| 3083 | default: |
| 3084 | ret = -EIO; |
| 3085 | IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n"); |
| 3086 | break; |
| 3087 | } |
| 3088 | |
| 3089 | return ret; |
| 3090 | } |
| 3091 | |
| 3092 | static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm, |
| 3093 | struct ieee80211_key_conf *keyconf, |
| 3094 | u8 sta_id, bool remove_key) |
| 3095 | { |
| 3096 | struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {}; |
| 3097 | |
| 3098 | /* verify the key details match the required command's expectations */ |
Ayala Beker | 8e160ab | 2016-04-11 11:37:38 +0300 | [diff] [blame] | 3099 | if (WARN_ON((keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) || |
| 3100 | (keyconf->keyidx != 4 && keyconf->keyidx != 5) || |
| 3101 | (keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC && |
| 3102 | keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_128 && |
| 3103 | keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_256))) |
| 3104 | return -EINVAL; |
| 3105 | |
| 3106 | if (WARN_ON(!iwl_mvm_has_new_rx_api(mvm) && |
| 3107 | keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3108 | return -EINVAL; |
| 3109 | |
| 3110 | igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx); |
| 3111 | igtk_cmd.sta_id = cpu_to_le32(sta_id); |
| 3112 | |
| 3113 | if (remove_key) { |
| 3114 | igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID); |
| 3115 | } else { |
| 3116 | struct ieee80211_key_seq seq; |
| 3117 | const u8 *pn; |
| 3118 | |
Ayala Beker | aa95052 | 2016-06-01 00:28:09 +0300 | [diff] [blame] | 3119 | switch (keyconf->cipher) { |
| 3120 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 3121 | igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_CCM); |
| 3122 | break; |
Ayala Beker | 8e160ab | 2016-04-11 11:37:38 +0300 | [diff] [blame] | 3123 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 3124 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 3125 | igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_GCMP); |
| 3126 | break; |
Ayala Beker | aa95052 | 2016-06-01 00:28:09 +0300 | [diff] [blame] | 3127 | default: |
| 3128 | return -EINVAL; |
| 3129 | } |
| 3130 | |
Ayala Beker | 8e160ab | 2016-04-11 11:37:38 +0300 | [diff] [blame] | 3131 | memcpy(igtk_cmd.igtk, keyconf->key, keyconf->keylen); |
| 3132 | if (keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) |
| 3133 | igtk_cmd.ctrl_flags |= |
| 3134 | cpu_to_le32(STA_KEY_FLG_KEY_32BYTES); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3135 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); |
| 3136 | pn = seq.aes_cmac.pn; |
| 3137 | igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) | |
| 3138 | ((u64) pn[4] << 8) | |
| 3139 | ((u64) pn[3] << 16) | |
| 3140 | ((u64) pn[2] << 24) | |
| 3141 | ((u64) pn[1] << 32) | |
| 3142 | ((u64) pn[0] << 40)); |
| 3143 | } |
| 3144 | |
| 3145 | IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n", |
| 3146 | remove_key ? "removing" : "installing", |
| 3147 | igtk_cmd.sta_id); |
| 3148 | |
Ayala Beker | 8e160ab | 2016-04-11 11:37:38 +0300 | [diff] [blame] | 3149 | if (!iwl_mvm_has_new_rx_api(mvm)) { |
| 3150 | struct iwl_mvm_mgmt_mcast_key_cmd_v1 igtk_cmd_v1 = { |
| 3151 | .ctrl_flags = igtk_cmd.ctrl_flags, |
| 3152 | .key_id = igtk_cmd.key_id, |
| 3153 | .sta_id = igtk_cmd.sta_id, |
| 3154 | .receive_seq_cnt = igtk_cmd.receive_seq_cnt |
| 3155 | }; |
| 3156 | |
| 3157 | memcpy(igtk_cmd_v1.igtk, igtk_cmd.igtk, |
| 3158 | ARRAY_SIZE(igtk_cmd_v1.igtk)); |
| 3159 | return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0, |
| 3160 | sizeof(igtk_cmd_v1), &igtk_cmd_v1); |
| 3161 | } |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 3162 | return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3163 | sizeof(igtk_cmd), &igtk_cmd); |
| 3164 | } |
| 3165 | |
| 3166 | |
| 3167 | static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm, |
| 3168 | struct ieee80211_vif *vif, |
| 3169 | struct ieee80211_sta *sta) |
| 3170 | { |
Johannes Berg | 5b530e9 | 2014-12-23 16:00:17 +0100 | [diff] [blame] | 3171 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3172 | |
| 3173 | if (sta) |
| 3174 | return sta->addr; |
| 3175 | |
| 3176 | if (vif->type == NL80211_IFTYPE_STATION && |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 3177 | mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3178 | u8 sta_id = mvmvif->ap_sta_id; |
| 3179 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 3180 | lockdep_is_held(&mvm->mutex)); |
| 3181 | return sta->addr; |
| 3182 | } |
| 3183 | |
| 3184 | |
| 3185 | return NULL; |
| 3186 | } |
| 3187 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3188 | static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm, |
| 3189 | struct ieee80211_vif *vif, |
| 3190 | struct ieee80211_sta *sta, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3191 | struct ieee80211_key_conf *keyconf, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3192 | u8 key_offset, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3193 | bool mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3194 | { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3195 | int ret; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3196 | const u8 *addr; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3197 | struct ieee80211_key_seq seq; |
| 3198 | u16 p1k[5]; |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3199 | u32 sta_id; |
| 3200 | |
| 3201 | if (sta) { |
| 3202 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
| 3203 | |
| 3204 | sta_id = mvm_sta->sta_id; |
| 3205 | } else if (vif->type == NL80211_IFTYPE_AP && |
| 3206 | !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE)) { |
| 3207 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 3208 | |
| 3209 | sta_id = mvmvif->mcast_sta.sta_id; |
| 3210 | } else { |
| 3211 | IWL_ERR(mvm, "Failed to find station id\n"); |
| 3212 | return -EINVAL; |
| 3213 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3214 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3215 | switch (keyconf->cipher) { |
| 3216 | case WLAN_CIPHER_SUITE_TKIP: |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3217 | if (vif->type == NL80211_IFTYPE_AP) { |
| 3218 | ret = -EINVAL; |
| 3219 | break; |
| 3220 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3221 | addr = iwl_mvm_get_mac_addr(mvm, vif, sta); |
| 3222 | /* get phase 1 key from mac80211 */ |
| 3223 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); |
| 3224 | ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k); |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3225 | ret = iwl_mvm_send_sta_key(mvm, sta_id, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3226 | seq.tkip.iv32, p1k, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3227 | break; |
| 3228 | case WLAN_CIPHER_SUITE_CCMP: |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3229 | case WLAN_CIPHER_SUITE_WEP40: |
| 3230 | case WLAN_CIPHER_SUITE_WEP104: |
Ayala Beker | 2a53d16 | 2016-04-07 16:21:57 +0300 | [diff] [blame] | 3231 | case WLAN_CIPHER_SUITE_GCMP: |
| 3232 | case WLAN_CIPHER_SUITE_GCMP_256: |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3233 | ret = iwl_mvm_send_sta_key(mvm, sta_id, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3234 | 0, NULL, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3235 | break; |
| 3236 | default: |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3237 | ret = iwl_mvm_send_sta_key(mvm, sta_id, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3238 | 0, NULL, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3239 | } |
| 3240 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3241 | return ret; |
| 3242 | } |
| 3243 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3244 | 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] | 3245 | struct ieee80211_key_conf *keyconf, |
| 3246 | bool mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3247 | { |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3248 | union { |
| 3249 | struct iwl_mvm_add_sta_key_cmd_v1 cmd_v1; |
| 3250 | struct iwl_mvm_add_sta_key_cmd cmd; |
| 3251 | } u = {}; |
| 3252 | bool new_api = fw_has_api(&mvm->fw->ucode_capa, |
| 3253 | IWL_UCODE_TLV_API_TKIP_MIC_KEYS); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3254 | __le16 key_flags; |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3255 | int ret, size; |
Johannes Berg | 7992074 | 2014-11-03 15:43:04 +0100 | [diff] [blame] | 3256 | u32 status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3257 | |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3258 | if (sta_id == IWL_MVM_INVALID_STA) |
| 3259 | return -EINVAL; |
| 3260 | |
Emmanuel Grumbach | 8115efb | 2013-02-05 10:08:35 +0200 | [diff] [blame] | 3261 | key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & |
| 3262 | STA_KEY_FLG_KEYID_MSK); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3263 | key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP); |
| 3264 | key_flags |= cpu_to_le16(STA_KEY_NOT_VALID); |
| 3265 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3266 | if (mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3267 | key_flags |= cpu_to_le16(STA_KEY_MULTICAST); |
| 3268 | |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3269 | /* |
| 3270 | * The fields assigned here are in the same location at the start |
| 3271 | * of the command, so we can do this union trick. |
| 3272 | */ |
| 3273 | u.cmd.common.key_flags = key_flags; |
| 3274 | u.cmd.common.key_offset = keyconf->hw_key_idx; |
| 3275 | u.cmd.common.sta_id = sta_id; |
| 3276 | |
| 3277 | size = new_api ? sizeof(u.cmd) : sizeof(u.cmd_v1); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3278 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3279 | status = ADD_STA_SUCCESS; |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3280 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, size, &u.cmd, |
| 3281 | &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3282 | |
| 3283 | switch (status) { |
| 3284 | case ADD_STA_SUCCESS: |
| 3285 | IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n"); |
| 3286 | break; |
| 3287 | default: |
| 3288 | ret = -EIO; |
| 3289 | IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n"); |
| 3290 | break; |
| 3291 | } |
| 3292 | |
| 3293 | return ret; |
| 3294 | } |
| 3295 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3296 | int iwl_mvm_set_sta_key(struct iwl_mvm *mvm, |
| 3297 | struct ieee80211_vif *vif, |
| 3298 | struct ieee80211_sta *sta, |
| 3299 | struct ieee80211_key_conf *keyconf, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3300 | u8 key_offset) |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3301 | { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3302 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 3303 | struct iwl_mvm_sta *mvm_sta; |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3304 | u8 sta_id = IWL_MVM_INVALID_STA; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3305 | int ret; |
Matti Gottlieb | 11828db | 2015-06-01 15:15:11 +0300 | [diff] [blame] | 3306 | static const u8 __maybe_unused zero_addr[ETH_ALEN] = {0}; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3307 | |
| 3308 | lockdep_assert_held(&mvm->mutex); |
| 3309 | |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3310 | if (vif->type != NL80211_IFTYPE_AP || |
| 3311 | keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) { |
| 3312 | /* Get the station id from the mvm local station table */ |
| 3313 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
| 3314 | if (!mvm_sta) { |
| 3315 | IWL_ERR(mvm, "Failed to find station\n"); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3316 | return -EINVAL; |
| 3317 | } |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3318 | sta_id = mvm_sta->sta_id; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3319 | |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3320 | if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC || |
| 3321 | keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || |
| 3322 | keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) { |
| 3323 | ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, |
| 3324 | false); |
| 3325 | goto end; |
| 3326 | } |
| 3327 | |
| 3328 | /* |
| 3329 | * It is possible that the 'sta' parameter is NULL, and thus |
| 3330 | * there is a need to retrieve the sta from the local station |
| 3331 | * table. |
| 3332 | */ |
| 3333 | if (!sta) { |
| 3334 | sta = rcu_dereference_protected( |
| 3335 | mvm->fw_id_to_mac_id[sta_id], |
| 3336 | lockdep_is_held(&mvm->mutex)); |
| 3337 | if (IS_ERR_OR_NULL(sta)) { |
| 3338 | IWL_ERR(mvm, "Invalid station id\n"); |
| 3339 | return -EINVAL; |
| 3340 | } |
| 3341 | } |
| 3342 | |
| 3343 | if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif)) |
| 3344 | return -EINVAL; |
| 3345 | } |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3346 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3347 | /* If the key_offset is not pre-assigned, we need to find a |
| 3348 | * new offset to use. In normal cases, the offset is not |
| 3349 | * pre-assigned, but during HW_RESTART we want to reuse the |
| 3350 | * same indices, so we pass them when this function is called. |
| 3351 | * |
| 3352 | * In D3 entry, we need to hardcoded the indices (because the |
| 3353 | * firmware hardcodes the PTK offset to 0). In this case, we |
| 3354 | * need to make sure we don't overwrite the hw_key_idx in the |
| 3355 | * keyconf structure, because otherwise we cannot configure |
| 3356 | * the original ones back when resuming. |
| 3357 | */ |
| 3358 | if (key_offset == STA_KEY_IDX_INVALID) { |
| 3359 | key_offset = iwl_mvm_set_fw_key_idx(mvm); |
| 3360 | if (key_offset == STA_KEY_IDX_INVALID) |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3361 | return -ENOSPC; |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3362 | keyconf->hw_key_idx = key_offset; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3363 | } |
| 3364 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3365 | 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] | 3366 | if (ret) |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3367 | goto end; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3368 | |
| 3369 | /* |
| 3370 | * For WEP, the same key is used for multicast and unicast. Upload it |
| 3371 | * again, using the same key offset, and now pointing the other one |
| 3372 | * to the same key slot (offset). |
| 3373 | * If this fails, remove the original as well. |
| 3374 | */ |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3375 | if ((keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 3376 | keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) && |
| 3377 | sta) { |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3378 | ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, |
| 3379 | key_offset, !mcast); |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3380 | if (ret) { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3381 | __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast); |
Luca Coelho | 9c3deeb | 2015-11-11 01:06:17 +0200 | [diff] [blame] | 3382 | goto end; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3383 | } |
| 3384 | } |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3385 | |
Luca Coelho | 9c3deeb | 2015-11-11 01:06:17 +0200 | [diff] [blame] | 3386 | __set_bit(key_offset, mvm->fw_key_table); |
| 3387 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3388 | end: |
| 3389 | IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n", |
| 3390 | keyconf->cipher, keyconf->keylen, keyconf->keyidx, |
Matti Gottlieb | 11828db | 2015-06-01 15:15:11 +0300 | [diff] [blame] | 3391 | sta ? sta->addr : zero_addr, ret); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3392 | return ret; |
| 3393 | } |
| 3394 | |
| 3395 | int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, |
| 3396 | struct ieee80211_vif *vif, |
| 3397 | struct ieee80211_sta *sta, |
| 3398 | struct ieee80211_key_conf *keyconf) |
| 3399 | { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3400 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 3401 | struct iwl_mvm_sta *mvm_sta; |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 3402 | u8 sta_id = IWL_MVM_INVALID_STA; |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 3403 | int ret, i; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3404 | |
| 3405 | lockdep_assert_held(&mvm->mutex); |
| 3406 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 3407 | /* Get the station from the mvm local station table */ |
| 3408 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
Luca Coelho | 71793b7d | 2017-03-30 12:04:47 +0300 | [diff] [blame] | 3409 | if (mvm_sta) |
| 3410 | sta_id = mvm_sta->sta_id; |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3411 | else if (!sta && vif->type == NL80211_IFTYPE_AP && mcast) |
| 3412 | sta_id = iwl_mvm_vif_from_mac80211(vif)->mcast_sta.sta_id; |
| 3413 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3414 | |
| 3415 | IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n", |
| 3416 | keyconf->keyidx, sta_id); |
| 3417 | |
Luca Coelho | 71793b7d | 2017-03-30 12:04:47 +0300 | [diff] [blame] | 3418 | if (mvm_sta && (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC || |
| 3419 | keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || |
| 3420 | keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)) |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3421 | return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true); |
| 3422 | |
| 3423 | if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) { |
| 3424 | IWL_ERR(mvm, "offset %d not used in fw key table.\n", |
| 3425 | keyconf->hw_key_idx); |
| 3426 | return -ENOENT; |
| 3427 | } |
| 3428 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 3429 | /* track which key was deleted last */ |
| 3430 | for (i = 0; i < STA_KEY_MAX_NUM; i++) { |
| 3431 | if (mvm->fw_key_deleted[i] < U8_MAX) |
| 3432 | mvm->fw_key_deleted[i]++; |
| 3433 | } |
| 3434 | mvm->fw_key_deleted[keyconf->hw_key_idx] = 0; |
| 3435 | |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3436 | if (sta && !mvm_sta) { |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3437 | IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n"); |
| 3438 | return 0; |
| 3439 | } |
| 3440 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3441 | ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast); |
| 3442 | if (ret) |
| 3443 | return ret; |
| 3444 | |
| 3445 | /* delete WEP key twice to get rid of (now useless) offset */ |
| 3446 | if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 3447 | keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) |
| 3448 | ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast); |
| 3449 | |
| 3450 | return ret; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3451 | } |
| 3452 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3453 | void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm, |
| 3454 | struct ieee80211_vif *vif, |
| 3455 | struct ieee80211_key_conf *keyconf, |
| 3456 | struct ieee80211_sta *sta, u32 iv32, |
| 3457 | u16 *phase1key) |
| 3458 | { |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 3459 | struct iwl_mvm_sta *mvm_sta; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3460 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3461 | |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 3462 | rcu_read_lock(); |
| 3463 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 3464 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
| 3465 | if (WARN_ON_ONCE(!mvm_sta)) |
Emmanuel Grumbach | 12f1721 | 2015-12-20 14:48:08 +0200 | [diff] [blame] | 3466 | goto unlock; |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3467 | iwl_mvm_send_sta_key(mvm, mvm_sta->sta_id, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3468 | iv32, phase1key, CMD_ASYNC, keyconf->hw_key_idx); |
Emmanuel Grumbach | 12f1721 | 2015-12-20 14:48:08 +0200 | [diff] [blame] | 3469 | |
| 3470 | unlock: |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 3471 | rcu_read_unlock(); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3472 | } |
| 3473 | |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 3474 | void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm, |
| 3475 | struct ieee80211_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3476 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 3477 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 3478 | struct iwl_mvm_add_sta_cmd cmd = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3479 | .add_modify = STA_MODE_MODIFY, |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 3480 | .sta_id = mvmsta->sta_id, |
Emmanuel Grumbach | 5af0177 | 2013-06-09 12:59:24 +0300 | [diff] [blame] | 3481 | .station_flags_msk = cpu_to_le32(STA_FLG_PS), |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 3482 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3483 | }; |
| 3484 | int ret; |
| 3485 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 3486 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, |
| 3487 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3488 | if (ret) |
| 3489 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 3490 | } |
| 3491 | |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 3492 | void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm, |
| 3493 | struct ieee80211_sta *sta, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3494 | enum ieee80211_frame_release_type reason, |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3495 | u16 cnt, u16 tids, bool more_data, |
Sara Sharon | 9a3fcf9 | 2017-03-14 09:50:35 +0200 | [diff] [blame] | 3496 | bool single_sta_queue) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3497 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 3498 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 3499 | struct iwl_mvm_add_sta_cmd cmd = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3500 | .add_modify = STA_MODE_MODIFY, |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 3501 | .sta_id = mvmsta->sta_id, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3502 | .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT, |
| 3503 | .sleep_tx_count = cpu_to_le16(cnt), |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 3504 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3505 | }; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3506 | int tid, ret; |
| 3507 | unsigned long _tids = tids; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3508 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3509 | /* convert TIDs to ACs - we don't support TSPEC so that's OK |
| 3510 | * Note that this field is reserved and unused by firmware not |
| 3511 | * supporting GO uAPSD, so it's safe to always do this. |
| 3512 | */ |
| 3513 | for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) |
| 3514 | cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]); |
| 3515 | |
Sara Sharon | 9a3fcf9 | 2017-03-14 09:50:35 +0200 | [diff] [blame] | 3516 | /* If we're releasing frames from aggregation or dqa queues then check |
| 3517 | * if all the queues that we're releasing frames from, combined, have: |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3518 | * - more frames than the service period, in which case more_data |
| 3519 | * needs to be set |
| 3520 | * - fewer than 'cnt' frames, in which case we need to adjust the |
| 3521 | * firmware command (but do that unconditionally) |
| 3522 | */ |
Sara Sharon | 9a3fcf9 | 2017-03-14 09:50:35 +0200 | [diff] [blame] | 3523 | if (single_sta_queue) { |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3524 | int remaining = cnt; |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 3525 | int sleep_tx_count; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3526 | |
| 3527 | spin_lock_bh(&mvmsta->lock); |
| 3528 | for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) { |
| 3529 | struct iwl_mvm_tid_data *tid_data; |
| 3530 | u16 n_queued; |
| 3531 | |
| 3532 | tid_data = &mvmsta->tid_data[tid]; |
Sara Sharon | 9a3fcf9 | 2017-03-14 09:50:35 +0200 | [diff] [blame] | 3533 | if (WARN(!iwl_mvm_is_dqa_supported(mvm) && |
| 3534 | tid_data->state != IWL_AGG_ON && |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3535 | tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA, |
| 3536 | "TID %d state is %d\n", |
| 3537 | tid, tid_data->state)) { |
| 3538 | spin_unlock_bh(&mvmsta->lock); |
| 3539 | ieee80211_sta_eosp(sta); |
| 3540 | return; |
| 3541 | } |
| 3542 | |
| 3543 | n_queued = iwl_mvm_tid_queued(tid_data); |
| 3544 | if (n_queued > remaining) { |
| 3545 | more_data = true; |
| 3546 | remaining = 0; |
| 3547 | break; |
| 3548 | } |
| 3549 | remaining -= n_queued; |
| 3550 | } |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 3551 | sleep_tx_count = cnt - remaining; |
| 3552 | if (reason == IEEE80211_FRAME_RELEASE_UAPSD) |
| 3553 | mvmsta->sleep_tx_count = sleep_tx_count; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3554 | spin_unlock_bh(&mvmsta->lock); |
| 3555 | |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 3556 | cmd.sleep_tx_count = cpu_to_le16(sleep_tx_count); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3557 | if (WARN_ON(cnt - remaining == 0)) { |
| 3558 | ieee80211_sta_eosp(sta); |
| 3559 | return; |
| 3560 | } |
| 3561 | } |
| 3562 | |
| 3563 | /* Note: this is ignored by firmware not supporting GO uAPSD */ |
| 3564 | if (more_data) |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 3565 | cmd.sleep_state_flags |= STA_SLEEP_STATE_MOREDATA; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3566 | |
| 3567 | if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) { |
| 3568 | mvmsta->next_status_eosp = true; |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 3569 | cmd.sleep_state_flags |= STA_SLEEP_STATE_PS_POLL; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3570 | } else { |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 3571 | cmd.sleep_state_flags |= STA_SLEEP_STATE_UAPSD; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3572 | } |
| 3573 | |
Emmanuel Grumbach | 156f92f | 2015-11-24 14:55:18 +0200 | [diff] [blame] | 3574 | /* block the Tx queues until the FW updated the sleep Tx count */ |
| 3575 | iwl_trans_block_txq_ptrs(mvm->trans, true); |
| 3576 | |
| 3577 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, |
| 3578 | CMD_ASYNC | CMD_WANT_ASYNC_CALLBACK, |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 3579 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3580 | if (ret) |
| 3581 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 3582 | } |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3583 | |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 3584 | void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm, |
| 3585 | struct iwl_rx_cmd_buffer *rxb) |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3586 | { |
| 3587 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 3588 | struct iwl_mvm_eosp_notification *notif = (void *)pkt->data; |
| 3589 | struct ieee80211_sta *sta; |
| 3590 | u32 sta_id = le32_to_cpu(notif->sta_id); |
| 3591 | |
| 3592 | if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT)) |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 3593 | return; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3594 | |
| 3595 | rcu_read_lock(); |
| 3596 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); |
| 3597 | if (!IS_ERR_OR_NULL(sta)) |
| 3598 | ieee80211_sta_eosp(sta); |
| 3599 | rcu_read_unlock(); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3600 | } |
Andrei Otcheretianski | 09b0ce1 | 2014-05-25 17:07:38 +0300 | [diff] [blame] | 3601 | |
| 3602 | void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm, |
| 3603 | struct iwl_mvm_sta *mvmsta, bool disable) |
| 3604 | { |
| 3605 | struct iwl_mvm_add_sta_cmd cmd = { |
| 3606 | .add_modify = STA_MODE_MODIFY, |
| 3607 | .sta_id = mvmsta->sta_id, |
| 3608 | .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0, |
| 3609 | .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX), |
| 3610 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
| 3611 | }; |
| 3612 | int ret; |
| 3613 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 3614 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, |
| 3615 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
Andrei Otcheretianski | 09b0ce1 | 2014-05-25 17:07:38 +0300 | [diff] [blame] | 3616 | if (ret) |
| 3617 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 3618 | } |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 3619 | |
| 3620 | void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm, |
| 3621 | struct ieee80211_sta *sta, |
| 3622 | bool disable) |
| 3623 | { |
| 3624 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
| 3625 | |
| 3626 | spin_lock_bh(&mvm_sta->lock); |
| 3627 | |
| 3628 | if (mvm_sta->disable_tx == disable) { |
| 3629 | spin_unlock_bh(&mvm_sta->lock); |
| 3630 | return; |
| 3631 | } |
| 3632 | |
| 3633 | mvm_sta->disable_tx = disable; |
| 3634 | |
| 3635 | /* |
Sara Sharon | 0d365ae | 2015-03-31 12:24:05 +0300 | [diff] [blame] | 3636 | * Tell mac80211 to start/stop queuing tx for this station, |
| 3637 | * but don't stop queuing if there are still pending frames |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 3638 | * for this station. |
| 3639 | */ |
| 3640 | if (disable || !atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) |
| 3641 | ieee80211_sta_block_awake(mvm->hw, sta, disable); |
| 3642 | |
| 3643 | iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable); |
| 3644 | |
| 3645 | spin_unlock_bh(&mvm_sta->lock); |
| 3646 | } |
| 3647 | |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 3648 | static void iwl_mvm_int_sta_modify_disable_tx(struct iwl_mvm *mvm, |
| 3649 | struct iwl_mvm_vif *mvmvif, |
| 3650 | struct iwl_mvm_int_sta *sta, |
| 3651 | bool disable) |
| 3652 | { |
| 3653 | u32 id = FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color); |
| 3654 | struct iwl_mvm_add_sta_cmd cmd = { |
| 3655 | .add_modify = STA_MODE_MODIFY, |
| 3656 | .sta_id = sta->sta_id, |
| 3657 | .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0, |
| 3658 | .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX), |
| 3659 | .mac_id_n_color = cpu_to_le32(id), |
| 3660 | }; |
| 3661 | int ret; |
| 3662 | |
| 3663 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, 0, |
| 3664 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
| 3665 | if (ret) |
| 3666 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 3667 | } |
| 3668 | |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 3669 | void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm, |
| 3670 | struct iwl_mvm_vif *mvmvif, |
| 3671 | bool disable) |
| 3672 | { |
| 3673 | struct ieee80211_sta *sta; |
| 3674 | struct iwl_mvm_sta *mvm_sta; |
| 3675 | int i; |
| 3676 | |
| 3677 | lockdep_assert_held(&mvm->mutex); |
| 3678 | |
| 3679 | /* Block/unblock all the stations of the given mvmvif */ |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 3680 | for (i = 0; i < ARRAY_SIZE(mvm->fw_id_to_mac_id); i++) { |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 3681 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], |
| 3682 | lockdep_is_held(&mvm->mutex)); |
| 3683 | if (IS_ERR_OR_NULL(sta)) |
| 3684 | continue; |
| 3685 | |
| 3686 | mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
| 3687 | if (mvm_sta->mac_id_n_color != |
| 3688 | FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color)) |
| 3689 | continue; |
| 3690 | |
| 3691 | iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable); |
| 3692 | } |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 3693 | |
| 3694 | if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) |
| 3695 | return; |
| 3696 | |
| 3697 | /* Need to block/unblock also multicast station */ |
| 3698 | if (mvmvif->mcast_sta.sta_id != IWL_MVM_INVALID_STA) |
| 3699 | iwl_mvm_int_sta_modify_disable_tx(mvm, mvmvif, |
| 3700 | &mvmvif->mcast_sta, disable); |
| 3701 | |
| 3702 | /* |
| 3703 | * Only unblock the broadcast station (FW blocks it for immediate |
| 3704 | * quiet, not the driver) |
| 3705 | */ |
| 3706 | if (!disable && mvmvif->bcast_sta.sta_id != IWL_MVM_INVALID_STA) |
| 3707 | iwl_mvm_int_sta_modify_disable_tx(mvm, mvmvif, |
| 3708 | &mvmvif->bcast_sta, disable); |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 3709 | } |
Luciano Coelho | dc88b4b | 2014-11-10 11:10:14 +0200 | [diff] [blame] | 3710 | |
| 3711 | void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 3712 | { |
| 3713 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 3714 | struct iwl_mvm_sta *mvmsta; |
| 3715 | |
| 3716 | rcu_read_lock(); |
| 3717 | |
| 3718 | mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id); |
| 3719 | |
| 3720 | if (!WARN_ON(!mvmsta)) |
| 3721 | iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true); |
| 3722 | |
| 3723 | rcu_read_unlock(); |
| 3724 | } |