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