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 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1280 | int iwl_mvm_add_sta(struct iwl_mvm *mvm, |
| 1281 | struct ieee80211_vif *vif, |
| 1282 | struct ieee80211_sta *sta) |
| 1283 | { |
| 1284 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 1285 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Sara Sharon | a571f5f | 2015-12-07 12:50:58 +0200 | [diff] [blame] | 1286 | struct iwl_mvm_rxq_dup_data *dup_data; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1287 | int i, ret, sta_id; |
| 1288 | |
| 1289 | lockdep_assert_held(&mvm->mutex); |
| 1290 | |
| 1291 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 1292 | sta_id = iwl_mvm_find_free_sta_id(mvm, |
| 1293 | ieee80211_vif_type_p2p(vif)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1294 | else |
| 1295 | sta_id = mvm_sta->sta_id; |
| 1296 | |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 1297 | if (sta_id == IWL_MVM_INVALID_STA) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1298 | return -ENOSPC; |
| 1299 | |
| 1300 | spin_lock_init(&mvm_sta->lock); |
| 1301 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 1302 | /* if this is a HW restart re-alloc existing queues */ |
| 1303 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
Liad Kaufman | 8d98ae6 | 2016-02-02 16:02:46 +0200 | [diff] [blame] | 1304 | iwl_mvm_realloc_queues_after_restart(mvm, mvm_sta); |
| 1305 | goto update_fw; |
| 1306 | } |
| 1307 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1308 | mvm_sta->sta_id = sta_id; |
| 1309 | mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id, |
| 1310 | mvmvif->color); |
| 1311 | mvm_sta->vif = vif; |
Liad Kaufman | a58bb46 | 2017-05-28 14:20:04 +0300 | [diff] [blame] | 1312 | if (!mvm->trans->cfg->gen2) |
| 1313 | mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF; |
| 1314 | else |
| 1315 | mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_GEN2_DEF; |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 1316 | mvm_sta->tx_protection = 0; |
| 1317 | mvm_sta->tt_tx_protection = false; |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 1318 | 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] | 1319 | |
| 1320 | /* HW restart, don't assume the memory has been zeroed */ |
Liad Kaufman | 69191af | 2015-09-01 18:50:22 +0300 | [diff] [blame] | 1321 | mvm_sta->tid_disable_agg = 0xffff; /* No aggs at first */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1322 | mvm_sta->tfd_queue_msk = 0; |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1323 | |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1324 | /* for HW restart - reset everything but the sequence number */ |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1325 | for (i = 0; i <= IWL_MAX_TID_COUNT; i++) { |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1326 | u16 seq = mvm_sta->tid_data[i].seq_number; |
| 1327 | memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i])); |
| 1328 | mvm_sta->tid_data[i].seq_number = seq; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1329 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1330 | /* |
| 1331 | * Mark all queues for this STA as unallocated and defer TX |
| 1332 | * frames until the queue is allocated |
| 1333 | */ |
Sara Sharon | 6862fce | 2017-02-22 19:34:17 +0200 | [diff] [blame] | 1334 | mvm_sta->tid_data[i].txq_id = IWL_MVM_INVALID_QUEUE; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1335 | skb_queue_head_init(&mvm_sta->tid_data[i].deferred_tx_frames); |
Johannes Berg | 6d9d32b | 2013-08-06 18:58:56 +0200 | [diff] [blame] | 1336 | } |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1337 | mvm_sta->deferred_traffic_tid_map = 0; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 1338 | mvm_sta->agg_tids = 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1339 | |
Sara Sharon | a571f5f | 2015-12-07 12:50:58 +0200 | [diff] [blame] | 1340 | if (iwl_mvm_has_new_rx_api(mvm) && |
| 1341 | !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
Johannes Berg | 92c4dca | 2017-06-07 10:35:54 +0200 | [diff] [blame] | 1342 | int q; |
| 1343 | |
Sara Sharon | a571f5f | 2015-12-07 12:50:58 +0200 | [diff] [blame] | 1344 | dup_data = kcalloc(mvm->trans->num_rx_queues, |
Johannes Berg | 92c4dca | 2017-06-07 10:35:54 +0200 | [diff] [blame] | 1345 | sizeof(*dup_data), GFP_KERNEL); |
Sara Sharon | a571f5f | 2015-12-07 12:50:58 +0200 | [diff] [blame] | 1346 | if (!dup_data) |
| 1347 | return -ENOMEM; |
Johannes Berg | 92c4dca | 2017-06-07 10:35:54 +0200 | [diff] [blame] | 1348 | /* |
| 1349 | * Initialize all the last_seq values to 0xffff which can never |
| 1350 | * compare equal to the frame's seq_ctrl in the check in |
| 1351 | * iwl_mvm_is_dup() since the lower 4 bits are the fragment |
| 1352 | * number and fragmented packets don't reach that function. |
| 1353 | * |
| 1354 | * This thus allows receiving a packet with seqno 0 and the |
| 1355 | * retry bit set as the very first packet on a new TID. |
| 1356 | */ |
| 1357 | for (q = 0; q < mvm->trans->num_rx_queues; q++) |
| 1358 | memset(dup_data[q].last_seq, 0xff, |
| 1359 | sizeof(dup_data[q].last_seq)); |
Sara Sharon | a571f5f | 2015-12-07 12:50:58 +0200 | [diff] [blame] | 1360 | mvm_sta->dup_data = dup_data; |
| 1361 | } |
| 1362 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 1363 | if (!iwl_mvm_has_new_tx_api(mvm)) { |
Liad Kaufman | d5216a2 | 2015-08-09 15:50:51 +0300 | [diff] [blame] | 1364 | ret = iwl_mvm_reserve_sta_stream(mvm, sta, |
| 1365 | ieee80211_vif_type_p2p(vif)); |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1366 | if (ret) |
| 1367 | goto err; |
| 1368 | } |
| 1369 | |
Liad Kaufman | 8d98ae6 | 2016-02-02 16:02:46 +0200 | [diff] [blame] | 1370 | update_fw: |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1371 | ret = iwl_mvm_sta_send_to_fw(mvm, sta, false, 0); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1372 | if (ret) |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1373 | goto err; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1374 | |
Johannes Berg | 9e84801 | 2014-08-04 14:33:42 +0200 | [diff] [blame] | 1375 | if (vif->type == NL80211_IFTYPE_STATION) { |
| 1376 | if (!sta->tdls) { |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 1377 | WARN_ON(mvmvif->ap_sta_id != IWL_MVM_INVALID_STA); |
Johannes Berg | 9e84801 | 2014-08-04 14:33:42 +0200 | [diff] [blame] | 1378 | mvmvif->ap_sta_id = sta_id; |
| 1379 | } else { |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 1380 | WARN_ON(mvmvif->ap_sta_id == IWL_MVM_INVALID_STA); |
Johannes Berg | 9e84801 | 2014-08-04 14:33:42 +0200 | [diff] [blame] | 1381 | } |
| 1382 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1383 | |
| 1384 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta); |
| 1385 | |
| 1386 | return 0; |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1387 | |
| 1388 | err: |
Arik Nemtsov | a0f6bf2 | 2014-09-21 19:10:04 +0300 | [diff] [blame] | 1389 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta, |
| 1393 | bool drain) |
| 1394 | { |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1395 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1396 | int ret; |
| 1397 | u32 status; |
| 1398 | |
| 1399 | lockdep_assert_held(&mvm->mutex); |
| 1400 | |
| 1401 | cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color); |
| 1402 | cmd.sta_id = mvmsta->sta_id; |
| 1403 | cmd.add_modify = STA_MODE_MODIFY; |
| 1404 | cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0; |
| 1405 | cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW); |
| 1406 | |
| 1407 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 1408 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 1409 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1410 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1411 | if (ret) |
| 1412 | return ret; |
| 1413 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 1414 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1415 | case ADD_STA_SUCCESS: |
| 1416 | IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n", |
| 1417 | mvmsta->sta_id); |
| 1418 | break; |
| 1419 | default: |
| 1420 | ret = -EIO; |
| 1421 | IWL_ERR(mvm, "Couldn't drain frames for staid %d\n", |
| 1422 | mvmsta->sta_id); |
| 1423 | break; |
| 1424 | } |
| 1425 | |
| 1426 | return ret; |
| 1427 | } |
| 1428 | |
| 1429 | /* |
| 1430 | * Remove a station from the FW table. Before sending the command to remove |
| 1431 | * the station validate that the station is indeed known to the driver (sanity |
| 1432 | * only). |
| 1433 | */ |
| 1434 | static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id) |
| 1435 | { |
| 1436 | struct ieee80211_sta *sta; |
| 1437 | struct iwl_mvm_rm_sta_cmd rm_sta_cmd = { |
| 1438 | .sta_id = sta_id, |
| 1439 | }; |
| 1440 | int ret; |
| 1441 | |
| 1442 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 1443 | lockdep_is_held(&mvm->mutex)); |
| 1444 | |
| 1445 | /* Note: internal stations are marked as error values */ |
| 1446 | if (!sta) { |
| 1447 | IWL_ERR(mvm, "Invalid station id\n"); |
| 1448 | return -EINVAL; |
| 1449 | } |
| 1450 | |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 1451 | ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1452 | sizeof(rm_sta_cmd), &rm_sta_cmd); |
| 1453 | if (ret) { |
| 1454 | IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id); |
| 1455 | return ret; |
| 1456 | } |
| 1457 | |
| 1458 | return 0; |
| 1459 | } |
| 1460 | |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1461 | static void iwl_mvm_disable_sta_queues(struct iwl_mvm *mvm, |
| 1462 | struct ieee80211_vif *vif, |
| 1463 | struct iwl_mvm_sta *mvm_sta) |
| 1464 | { |
| 1465 | int ac; |
| 1466 | int i; |
| 1467 | |
| 1468 | lockdep_assert_held(&mvm->mutex); |
| 1469 | |
| 1470 | for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) { |
Sara Sharon | 6862fce | 2017-02-22 19:34:17 +0200 | [diff] [blame] | 1471 | if (mvm_sta->tid_data[i].txq_id == IWL_MVM_INVALID_QUEUE) |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1472 | continue; |
| 1473 | |
| 1474 | ac = iwl_mvm_tid_to_ac_queue(i); |
| 1475 | iwl_mvm_disable_txq(mvm, mvm_sta->tid_data[i].txq_id, |
| 1476 | vif->hw_queue[ac], i, 0); |
Sara Sharon | 6862fce | 2017-02-22 19:34:17 +0200 | [diff] [blame] | 1477 | mvm_sta->tid_data[i].txq_id = IWL_MVM_INVALID_QUEUE; |
Liad Kaufman | 24afba7 | 2015-07-28 18:56:08 +0300 | [diff] [blame] | 1478 | } |
| 1479 | } |
| 1480 | |
Sara Sharon | d6d517b | 2017-03-06 10:16:11 +0200 | [diff] [blame] | 1481 | int iwl_mvm_wait_sta_queues_empty(struct iwl_mvm *mvm, |
| 1482 | struct iwl_mvm_sta *mvm_sta) |
| 1483 | { |
Sharon Dvir | bec9522 | 2017-06-12 11:40:33 +0300 | [diff] [blame] | 1484 | int i; |
Sara Sharon | d6d517b | 2017-03-06 10:16:11 +0200 | [diff] [blame] | 1485 | |
| 1486 | for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) { |
| 1487 | u16 txq_id; |
Sharon Dvir | bec9522 | 2017-06-12 11:40:33 +0300 | [diff] [blame] | 1488 | int ret; |
Sara Sharon | d6d517b | 2017-03-06 10:16:11 +0200 | [diff] [blame] | 1489 | |
| 1490 | spin_lock_bh(&mvm_sta->lock); |
| 1491 | txq_id = mvm_sta->tid_data[i].txq_id; |
| 1492 | spin_unlock_bh(&mvm_sta->lock); |
| 1493 | |
| 1494 | if (txq_id == IWL_MVM_INVALID_QUEUE) |
| 1495 | continue; |
| 1496 | |
| 1497 | ret = iwl_trans_wait_txq_empty(mvm->trans, txq_id); |
| 1498 | if (ret) |
Sharon Dvir | bec9522 | 2017-06-12 11:40:33 +0300 | [diff] [blame] | 1499 | return ret; |
Sara Sharon | d6d517b | 2017-03-06 10:16:11 +0200 | [diff] [blame] | 1500 | } |
| 1501 | |
Sharon Dvir | bec9522 | 2017-06-12 11:40:33 +0300 | [diff] [blame] | 1502 | return 0; |
Sara Sharon | d6d517b | 2017-03-06 10:16:11 +0200 | [diff] [blame] | 1503 | } |
| 1504 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1505 | int iwl_mvm_rm_sta(struct iwl_mvm *mvm, |
| 1506 | struct ieee80211_vif *vif, |
| 1507 | struct ieee80211_sta *sta) |
| 1508 | { |
| 1509 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 1510 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Sara Sharon | 94c3e61 | 2016-12-07 15:04:37 +0200 | [diff] [blame] | 1511 | u8 sta_id = mvm_sta->sta_id; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1512 | int ret; |
| 1513 | |
| 1514 | lockdep_assert_held(&mvm->mutex); |
| 1515 | |
Sara Sharon | a571f5f | 2015-12-07 12:50:58 +0200 | [diff] [blame] | 1516 | if (iwl_mvm_has_new_rx_api(mvm)) |
| 1517 | kfree(mvm_sta->dup_data); |
| 1518 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 1519 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, true); |
| 1520 | if (ret) |
| 1521 | return ret; |
Sara Sharon | d6d517b | 2017-03-06 10:16:11 +0200 | [diff] [blame] | 1522 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 1523 | /* flush its queues here since we are freeing mvm_sta */ |
| 1524 | ret = iwl_mvm_flush_sta(mvm, mvm_sta, false, 0); |
| 1525 | if (ret) |
| 1526 | return ret; |
| 1527 | if (iwl_mvm_has_new_tx_api(mvm)) { |
| 1528 | ret = iwl_mvm_wait_sta_queues_empty(mvm, mvm_sta); |
| 1529 | } else { |
| 1530 | u32 q_mask = mvm_sta->tfd_queue_msk; |
Emmanuel Grumbach | 80d8565 | 2013-02-19 15:32:42 +0200 | [diff] [blame] | 1531 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 1532 | ret = iwl_trans_wait_tx_queues_empty(mvm->trans, |
| 1533 | q_mask); |
| 1534 | } |
| 1535 | if (ret) |
| 1536 | return ret; |
Liad Kaufman | 5621474 | 2016-09-22 15:14:08 +0300 | [diff] [blame] | 1537 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 1538 | ret = iwl_mvm_drain_sta(mvm, mvm_sta, false); |
Liad Kaufman | a0315dea | 2016-07-07 13:25:59 +0300 | [diff] [blame] | 1539 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 1540 | iwl_mvm_disable_sta_queues(mvm, vif, mvm_sta); |
Liad Kaufman | a0315dea | 2016-07-07 13:25:59 +0300 | [diff] [blame] | 1541 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 1542 | /* If there is a TXQ still marked as reserved - free it */ |
| 1543 | if (mvm_sta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) { |
| 1544 | u8 reserved_txq = mvm_sta->reserved_queue; |
| 1545 | enum iwl_mvm_queue_status *status; |
| 1546 | |
| 1547 | /* |
| 1548 | * If no traffic has gone through the reserved TXQ - it |
| 1549 | * is still marked as IWL_MVM_QUEUE_RESERVED, and |
| 1550 | * should be manually marked as free again |
| 1551 | */ |
| 1552 | spin_lock_bh(&mvm->queue_info_lock); |
| 1553 | status = &mvm->queue_info[reserved_txq].status; |
| 1554 | if (WARN((*status != IWL_MVM_QUEUE_RESERVED) && |
| 1555 | (*status != IWL_MVM_QUEUE_FREE), |
| 1556 | "sta_id %d reserved txq %d status %d", |
| 1557 | sta_id, reserved_txq, *status)) { |
Liad Kaufman | a0315dea | 2016-07-07 13:25:59 +0300 | [diff] [blame] | 1558 | spin_unlock_bh(&mvm->queue_info_lock); |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 1559 | return -EINVAL; |
Liad Kaufman | a0315dea | 2016-07-07 13:25:59 +0300 | [diff] [blame] | 1560 | } |
| 1561 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 1562 | *status = IWL_MVM_QUEUE_FREE; |
| 1563 | spin_unlock_bh(&mvm->queue_info_lock); |
| 1564 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1565 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 1566 | if (vif->type == NL80211_IFTYPE_STATION && |
| 1567 | mvmvif->ap_sta_id == sta_id) { |
| 1568 | /* if associated - we can't remove the AP STA now */ |
| 1569 | if (vif->bss_conf.assoc) |
| 1570 | return ret; |
Eliad Peller | 37577fe | 2013-12-05 17:19:39 +0200 | [diff] [blame] | 1571 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 1572 | /* unassoc - go ahead - remove the AP STA now */ |
| 1573 | mvmvif->ap_sta_id = IWL_MVM_INVALID_STA; |
| 1574 | |
| 1575 | /* clear d0i3_ap_sta_id if no longer relevant */ |
| 1576 | if (mvm->d0i3_ap_sta_id == sta_id) |
| 1577 | mvm->d0i3_ap_sta_id = IWL_MVM_INVALID_STA; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | /* |
Arik Nemtsov | 1d3c3f6 | 2014-10-23 18:03:10 +0300 | [diff] [blame] | 1581 | * This shouldn't happen - the TDLS channel switch should be canceled |
| 1582 | * before the STA is removed. |
| 1583 | */ |
Sara Sharon | 94c3e61 | 2016-12-07 15:04:37 +0200 | [diff] [blame] | 1584 | if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == sta_id)) { |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 1585 | mvm->tdls_cs.peer.sta_id = IWL_MVM_INVALID_STA; |
Arik Nemtsov | 1d3c3f6 | 2014-10-23 18:03:10 +0300 | [diff] [blame] | 1586 | cancel_delayed_work(&mvm->tdls_cs.dwork); |
| 1587 | } |
| 1588 | |
| 1589 | /* |
Emmanuel Grumbach | e3d4bc8 | 2013-05-07 14:08:24 +0300 | [diff] [blame] | 1590 | * Make sure that the tx response code sees the station as -EBUSY and |
| 1591 | * calls the drain worker. |
| 1592 | */ |
| 1593 | spin_lock_bh(&mvm_sta->lock); |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 1594 | spin_unlock_bh(&mvm_sta->lock); |
Sara Sharon | 94c3e61 | 2016-12-07 15:04:37 +0200 | [diff] [blame] | 1595 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 1596 | ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id); |
| 1597 | 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] | 1598 | |
| 1599 | return ret; |
| 1600 | } |
| 1601 | |
| 1602 | int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm, |
| 1603 | struct ieee80211_vif *vif, |
| 1604 | u8 sta_id) |
| 1605 | { |
| 1606 | int ret = iwl_mvm_rm_sta_common(mvm, sta_id); |
| 1607 | |
| 1608 | lockdep_assert_held(&mvm->mutex); |
| 1609 | |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 1610 | RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1611 | return ret; |
| 1612 | } |
| 1613 | |
Chaya Rachel Ivgi | 0e39eb0 | 2015-12-03 15:51:46 +0200 | [diff] [blame] | 1614 | int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm, |
| 1615 | struct iwl_mvm_int_sta *sta, |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 1616 | u32 qmask, enum nl80211_iftype iftype, |
| 1617 | enum iwl_sta_type type) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1618 | { |
| 1619 | if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
Eliad Peller | b92e661 | 2014-01-23 17:58:23 +0200 | [diff] [blame] | 1620 | sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype); |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 1621 | if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_INVALID_STA)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1622 | return -ENOSPC; |
| 1623 | } |
| 1624 | |
| 1625 | sta->tfd_queue_msk = qmask; |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 1626 | sta->type = type; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1627 | |
| 1628 | /* put a non-NULL value so iterating over the stations won't stop */ |
| 1629 | rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL)); |
| 1630 | return 0; |
| 1631 | } |
| 1632 | |
Sara Sharon | 26d6c16 | 2017-01-03 12:00:19 +0200 | [diff] [blame] | 1633 | 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] | 1634 | { |
Monam Agarwal | c531c77 | 2014-03-24 00:05:56 +0530 | [diff] [blame] | 1635 | 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] | 1636 | memset(sta, 0, sizeof(struct iwl_mvm_int_sta)); |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 1637 | sta->sta_id = IWL_MVM_INVALID_STA; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1638 | } |
| 1639 | |
| 1640 | static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm, |
| 1641 | struct iwl_mvm_int_sta *sta, |
| 1642 | const u8 *addr, |
| 1643 | u16 mac_id, u16 color) |
| 1644 | { |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1645 | struct iwl_mvm_add_sta_cmd cmd; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1646 | int ret; |
| 1647 | u32 status; |
| 1648 | |
| 1649 | lockdep_assert_held(&mvm->mutex); |
| 1650 | |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1651 | memset(&cmd, 0, sizeof(cmd)); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1652 | cmd.sta_id = sta->sta_id; |
| 1653 | cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id, |
| 1654 | color)); |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 1655 | if (fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) |
| 1656 | cmd.station_type = sta->type; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1657 | |
Sara Sharon | bb49701 | 2016-09-29 14:52:40 +0300 | [diff] [blame] | 1658 | if (!iwl_mvm_has_new_tx_api(mvm)) |
| 1659 | cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk); |
Liad Kaufman | cf0cda1 | 2015-09-24 10:44:12 +0200 | [diff] [blame] | 1660 | cmd.tid_disable_tx = cpu_to_le16(0xffff); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1661 | |
| 1662 | if (addr) |
| 1663 | memcpy(cmd.addr, addr, ETH_ALEN); |
| 1664 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 1665 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 1666 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 1667 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1668 | if (ret) |
| 1669 | return ret; |
| 1670 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 1671 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1672 | case ADD_STA_SUCCESS: |
| 1673 | IWL_DEBUG_INFO(mvm, "Internal station added.\n"); |
| 1674 | return 0; |
| 1675 | default: |
| 1676 | ret = -EIO; |
| 1677 | IWL_ERR(mvm, "Add internal station failed, status=0x%x\n", |
| 1678 | status); |
| 1679 | break; |
| 1680 | } |
| 1681 | return ret; |
| 1682 | } |
| 1683 | |
Sara Sharon | c5a719e | 2016-11-15 10:20:48 +0200 | [diff] [blame] | 1684 | static void iwl_mvm_enable_aux_queue(struct iwl_mvm *mvm) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1685 | { |
Emmanuel Grumbach | 4cf677f | 2015-01-12 14:38:29 +0200 | [diff] [blame] | 1686 | unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ? |
| 1687 | mvm->cfg->base_params->wd_timeout : |
| 1688 | IWL_WATCHDOG_DISABLED; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1689 | |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 1690 | if (iwl_mvm_has_new_tx_api(mvm)) { |
| 1691 | int queue = iwl_mvm_tvqm_enable_txq(mvm, mvm->aux_queue, |
| 1692 | mvm->aux_sta.sta_id, |
| 1693 | IWL_MAX_TID_COUNT, |
| 1694 | wdg_timeout); |
| 1695 | mvm->aux_queue = queue; |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 1696 | } else { |
Liad Kaufman | 28d0793 | 2015-09-01 16:36:25 +0300 | [diff] [blame] | 1697 | struct iwl_trans_txq_scd_cfg cfg = { |
| 1698 | .fifo = IWL_MVM_TX_FIFO_MCAST, |
| 1699 | .sta_id = mvm->aux_sta.sta_id, |
| 1700 | .tid = IWL_MAX_TID_COUNT, |
| 1701 | .aggregate = false, |
| 1702 | .frame_limit = IWL_FRAME_LIMIT, |
| 1703 | }; |
| 1704 | |
| 1705 | iwl_mvm_enable_txq(mvm, mvm->aux_queue, mvm->aux_queue, 0, &cfg, |
| 1706 | wdg_timeout); |
| 1707 | } |
Sara Sharon | c5a719e | 2016-11-15 10:20:48 +0200 | [diff] [blame] | 1708 | } |
| 1709 | |
| 1710 | int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm) |
| 1711 | { |
| 1712 | int ret; |
| 1713 | |
| 1714 | lockdep_assert_held(&mvm->mutex); |
| 1715 | |
| 1716 | /* Allocate aux station and assign to it the aux queue */ |
| 1717 | 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] | 1718 | NL80211_IFTYPE_UNSPECIFIED, |
| 1719 | IWL_STA_AUX_ACTIVITY); |
Sara Sharon | c5a719e | 2016-11-15 10:20:48 +0200 | [diff] [blame] | 1720 | if (ret) |
| 1721 | return ret; |
| 1722 | |
| 1723 | /* Map Aux queue to fifo - needs to happen before adding Aux station */ |
| 1724 | if (!iwl_mvm_has_new_tx_api(mvm)) |
| 1725 | iwl_mvm_enable_aux_queue(mvm); |
Liad Kaufman | 28d0793 | 2015-09-01 16:36:25 +0300 | [diff] [blame] | 1726 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1727 | ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL, |
| 1728 | MAC_INDEX_AUX, 0); |
Sara Sharon | c5a719e | 2016-11-15 10:20:48 +0200 | [diff] [blame] | 1729 | if (ret) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1730 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); |
Sara Sharon | c5a719e | 2016-11-15 10:20:48 +0200 | [diff] [blame] | 1731 | return ret; |
| 1732 | } |
| 1733 | |
| 1734 | /* |
| 1735 | * For a000 firmware and on we cannot add queue to a station unknown |
| 1736 | * to firmware so enable queue here - after the station was added |
| 1737 | */ |
| 1738 | if (iwl_mvm_has_new_tx_api(mvm)) |
| 1739 | iwl_mvm_enable_aux_queue(mvm); |
| 1740 | |
| 1741 | return 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1742 | } |
| 1743 | |
Chaya Rachel Ivgi | 0e39eb0 | 2015-12-03 15:51:46 +0200 | [diff] [blame] | 1744 | int iwl_mvm_add_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1745 | { |
| 1746 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1747 | |
| 1748 | lockdep_assert_held(&mvm->mutex); |
| 1749 | return iwl_mvm_add_int_sta_common(mvm, &mvm->snif_sta, vif->addr, |
| 1750 | mvmvif->id, 0); |
| 1751 | } |
| 1752 | |
| 1753 | int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1754 | { |
| 1755 | int ret; |
| 1756 | |
| 1757 | lockdep_assert_held(&mvm->mutex); |
| 1758 | |
| 1759 | ret = iwl_mvm_rm_sta_common(mvm, mvm->snif_sta.sta_id); |
| 1760 | if (ret) |
| 1761 | IWL_WARN(mvm, "Failed sending remove station\n"); |
| 1762 | |
| 1763 | return ret; |
| 1764 | } |
| 1765 | |
| 1766 | void iwl_mvm_dealloc_snif_sta(struct iwl_mvm *mvm) |
| 1767 | { |
| 1768 | iwl_mvm_dealloc_int_sta(mvm, &mvm->snif_sta); |
| 1769 | } |
| 1770 | |
Johannes Berg | 712b24a | 2014-08-04 14:14:14 +0200 | [diff] [blame] | 1771 | void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm) |
| 1772 | { |
| 1773 | lockdep_assert_held(&mvm->mutex); |
| 1774 | |
| 1775 | iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); |
| 1776 | } |
| 1777 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1778 | /* |
| 1779 | * Send the add station command for the vif's broadcast station. |
| 1780 | * Assumes that the station was already allocated. |
| 1781 | * |
| 1782 | * @mvm: the mvm component |
| 1783 | * @vif: the interface to which the broadcast station is added |
| 1784 | * @bsta: the broadcast station to add. |
| 1785 | */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1786 | 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] | 1787 | { |
| 1788 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1789 | struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta; |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1790 | static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; |
Johannes Berg | a424340 | 2014-01-20 23:46:38 +0100 | [diff] [blame] | 1791 | const u8 *baddr = _baddr; |
Johannes Berg | 7daa762 | 2017-02-24 12:02:22 +0100 | [diff] [blame] | 1792 | int queue; |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 1793 | int ret; |
Sara Sharon | c5a719e | 2016-11-15 10:20:48 +0200 | [diff] [blame] | 1794 | unsigned int wdg_timeout = |
| 1795 | iwl_mvm_get_wd_timeout(mvm, vif, false, false); |
| 1796 | struct iwl_trans_txq_scd_cfg cfg = { |
| 1797 | .fifo = IWL_MVM_TX_FIFO_VO, |
| 1798 | .sta_id = mvmvif->bcast_sta.sta_id, |
| 1799 | .tid = IWL_MAX_TID_COUNT, |
| 1800 | .aggregate = false, |
| 1801 | .frame_limit = IWL_FRAME_LIMIT, |
| 1802 | }; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1803 | |
| 1804 | lockdep_assert_held(&mvm->mutex); |
| 1805 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 1806 | if (!iwl_mvm_has_new_tx_api(mvm)) { |
Liad Kaufman | 4d33998 | 2017-03-21 17:13:16 +0200 | [diff] [blame] | 1807 | if (vif->type == NL80211_IFTYPE_AP || |
| 1808 | vif->type == NL80211_IFTYPE_ADHOC) |
Sara Sharon | 49f7171 | 2017-01-09 12:07:16 +0200 | [diff] [blame] | 1809 | queue = mvm->probe_queue; |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 1810 | else if (vif->type == NL80211_IFTYPE_P2P_DEVICE) |
Sara Sharon | 49f7171 | 2017-01-09 12:07:16 +0200 | [diff] [blame] | 1811 | queue = mvm->p2p_dev_queue; |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 1812 | else if (WARN(1, "Missing required TXQ for adding bcast STA\n")) |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 1813 | return -EINVAL; |
| 1814 | |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 1815 | bsta->tfd_queue_msk |= BIT(queue); |
Sara Sharon | c5a719e | 2016-11-15 10:20:48 +0200 | [diff] [blame] | 1816 | |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 1817 | iwl_mvm_enable_txq(mvm, queue, vif->hw_queue[0], 0, |
| 1818 | &cfg, wdg_timeout); |
Liad Kaufman | de24f63 | 2015-08-04 15:19:18 +0300 | [diff] [blame] | 1819 | } |
| 1820 | |
Johannes Berg | 5023d96 | 2013-07-31 14:07:43 +0200 | [diff] [blame] | 1821 | if (vif->type == NL80211_IFTYPE_ADHOC) |
| 1822 | baddr = vif->bss_conf.bssid; |
| 1823 | |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 1824 | if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_INVALID_STA)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1825 | return -ENOSPC; |
| 1826 | |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 1827 | ret = iwl_mvm_add_int_sta_common(mvm, bsta, baddr, |
| 1828 | mvmvif->id, mvmvif->color); |
| 1829 | if (ret) |
| 1830 | return ret; |
| 1831 | |
| 1832 | /* |
Sara Sharon | c5a719e | 2016-11-15 10:20:48 +0200 | [diff] [blame] | 1833 | * For a000 firmware and on we cannot add queue to a station unknown |
| 1834 | * to firmware so enable queue here - after the station was added |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 1835 | */ |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 1836 | if (iwl_mvm_has_new_tx_api(mvm)) { |
Johannes Berg | 7daa762 | 2017-02-24 12:02:22 +0100 | [diff] [blame] | 1837 | queue = iwl_mvm_tvqm_enable_txq(mvm, vif->hw_queue[0], |
| 1838 | bsta->sta_id, |
| 1839 | IWL_MAX_TID_COUNT, |
| 1840 | wdg_timeout); |
| 1841 | |
Luca Coelho | 7b758a1 | 2017-06-20 13:40:03 +0300 | [diff] [blame] | 1842 | if (vif->type == NL80211_IFTYPE_AP || |
| 1843 | vif->type == NL80211_IFTYPE_ADHOC) |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 1844 | mvm->probe_queue = queue; |
| 1845 | else if (vif->type == NL80211_IFTYPE_P2P_DEVICE) |
| 1846 | mvm->p2p_dev_queue = queue; |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 1847 | } |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 1848 | |
| 1849 | return 0; |
| 1850 | } |
| 1851 | |
| 1852 | static void iwl_mvm_free_bcast_sta_queues(struct iwl_mvm *mvm, |
| 1853 | struct ieee80211_vif *vif) |
| 1854 | { |
| 1855 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Mordechai Goodstein | d167e81 | 2017-05-10 16:42:53 +0300 | [diff] [blame] | 1856 | int queue; |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 1857 | |
| 1858 | lockdep_assert_held(&mvm->mutex); |
| 1859 | |
Sara Sharon | d49394a | 2017-03-05 13:01:08 +0200 | [diff] [blame] | 1860 | iwl_mvm_flush_sta(mvm, &mvmvif->bcast_sta, true, 0); |
| 1861 | |
Mordechai Goodstein | d167e81 | 2017-05-10 16:42:53 +0300 | [diff] [blame] | 1862 | switch (vif->type) { |
| 1863 | case NL80211_IFTYPE_AP: |
| 1864 | case NL80211_IFTYPE_ADHOC: |
| 1865 | queue = mvm->probe_queue; |
| 1866 | break; |
| 1867 | case NL80211_IFTYPE_P2P_DEVICE: |
| 1868 | queue = mvm->p2p_dev_queue; |
| 1869 | break; |
| 1870 | default: |
| 1871 | WARN(1, "Can't free bcast queue on vif type %d\n", |
| 1872 | vif->type); |
| 1873 | return; |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 1874 | } |
| 1875 | |
Mordechai Goodstein | d167e81 | 2017-05-10 16:42:53 +0300 | [diff] [blame] | 1876 | iwl_mvm_disable_txq(mvm, queue, vif->hw_queue[0], IWL_MAX_TID_COUNT, 0); |
| 1877 | if (iwl_mvm_has_new_tx_api(mvm)) |
| 1878 | return; |
| 1879 | |
| 1880 | WARN_ON(!(mvmvif->bcast_sta.tfd_queue_msk & BIT(queue))); |
| 1881 | mvmvif->bcast_sta.tfd_queue_msk &= ~BIT(queue); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1882 | } |
| 1883 | |
| 1884 | /* Send the FW a request to remove the station from it's internal data |
| 1885 | * structures, but DO NOT remove the entry from the local data structures. */ |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1886 | 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] | 1887 | { |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1888 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1889 | int ret; |
| 1890 | |
| 1891 | lockdep_assert_held(&mvm->mutex); |
| 1892 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 1893 | iwl_mvm_free_bcast_sta_queues(mvm, vif); |
Liad Kaufman | df88c08 | 2016-11-24 15:31:00 +0200 | [diff] [blame] | 1894 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1895 | ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1896 | if (ret) |
| 1897 | IWL_WARN(mvm, "Failed sending remove station\n"); |
| 1898 | return ret; |
| 1899 | } |
| 1900 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1901 | int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1902 | { |
| 1903 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1904 | |
| 1905 | lockdep_assert_held(&mvm->mutex); |
| 1906 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 1907 | return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, 0, |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 1908 | ieee80211_vif_type_p2p(vif), |
| 1909 | IWL_STA_GENERAL_PURPOSE); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1910 | } |
| 1911 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1912 | /* Allocate a new station entry for the broadcast station to the given vif, |
| 1913 | * and send it to the FW. |
| 1914 | * Note that each P2P mac should have its own broadcast station. |
| 1915 | * |
| 1916 | * @mvm: the mvm component |
| 1917 | * @vif: the interface to which the broadcast station is added |
| 1918 | * @bsta: the broadcast station to add. */ |
Luca Coelho | d197358 | 2017-06-22 16:00:25 +0300 | [diff] [blame] | 1919 | 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] | 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 | struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1923 | int ret; |
| 1924 | |
| 1925 | lockdep_assert_held(&mvm->mutex); |
| 1926 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1927 | ret = iwl_mvm_alloc_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1928 | if (ret) |
| 1929 | return ret; |
| 1930 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1931 | ret = iwl_mvm_send_add_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1932 | |
| 1933 | if (ret) |
| 1934 | iwl_mvm_dealloc_int_sta(mvm, bsta); |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1935 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1936 | return ret; |
| 1937 | } |
| 1938 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1939 | void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1940 | { |
| 1941 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1942 | |
| 1943 | iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta); |
| 1944 | } |
| 1945 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1946 | /* |
| 1947 | * Send the FW a request to remove the station from it's internal data |
| 1948 | * structures, and in addition remove it from the local data structure. |
| 1949 | */ |
Luca Coelho | d197358 | 2017-06-22 16:00:25 +0300 | [diff] [blame] | 1950 | 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] | 1951 | { |
| 1952 | int ret; |
| 1953 | |
| 1954 | lockdep_assert_held(&mvm->mutex); |
| 1955 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1956 | ret = iwl_mvm_send_rm_bcast_sta(mvm, vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1957 | |
Johannes Berg | 013290a | 2014-08-04 13:38:48 +0200 | [diff] [blame] | 1958 | iwl_mvm_dealloc_bcast_sta(mvm, vif); |
| 1959 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 1960 | return ret; |
| 1961 | } |
| 1962 | |
Sara Sharon | 26d6c16 | 2017-01-03 12:00:19 +0200 | [diff] [blame] | 1963 | /* |
| 1964 | * Allocate a new station entry for the multicast station to the given vif, |
| 1965 | * and send it to the FW. |
| 1966 | * Note that each AP/GO mac should have its own multicast station. |
| 1967 | * |
| 1968 | * @mvm: the mvm component |
| 1969 | * @vif: the interface to which the multicast station is added |
| 1970 | */ |
| 1971 | int iwl_mvm_add_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 1972 | { |
| 1973 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 1974 | struct iwl_mvm_int_sta *msta = &mvmvif->mcast_sta; |
| 1975 | static const u8 _maddr[] = {0x03, 0x00, 0x00, 0x00, 0x00, 0x00}; |
| 1976 | const u8 *maddr = _maddr; |
| 1977 | struct iwl_trans_txq_scd_cfg cfg = { |
| 1978 | .fifo = IWL_MVM_TX_FIFO_MCAST, |
| 1979 | .sta_id = msta->sta_id, |
| 1980 | .tid = IWL_MAX_TID_COUNT, |
| 1981 | .aggregate = false, |
| 1982 | .frame_limit = IWL_FRAME_LIMIT, |
| 1983 | }; |
| 1984 | unsigned int timeout = iwl_mvm_get_wd_timeout(mvm, vif, false, false); |
| 1985 | int ret; |
| 1986 | |
| 1987 | lockdep_assert_held(&mvm->mutex); |
| 1988 | |
Liad Kaufman | ee48b72 | 2017-03-21 17:13:16 +0200 | [diff] [blame] | 1989 | if (WARN_ON(vif->type != NL80211_IFTYPE_AP && |
| 1990 | vif->type != NL80211_IFTYPE_ADHOC)) |
Sara Sharon | 26d6c16 | 2017-01-03 12:00:19 +0200 | [diff] [blame] | 1991 | return -ENOTSUPP; |
| 1992 | |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 1993 | /* |
| 1994 | * While in previous FWs we had to exclude cab queue from TFD queue |
| 1995 | * mask, now it is needed as any other queue. |
| 1996 | */ |
| 1997 | if (!iwl_mvm_has_new_tx_api(mvm) && |
| 1998 | fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) { |
| 1999 | iwl_mvm_enable_txq(mvm, vif->cab_queue, vif->cab_queue, 0, |
| 2000 | &cfg, timeout); |
| 2001 | msta->tfd_queue_msk |= BIT(vif->cab_queue); |
| 2002 | } |
Sara Sharon | 26d6c16 | 2017-01-03 12:00:19 +0200 | [diff] [blame] | 2003 | ret = iwl_mvm_add_int_sta_common(mvm, msta, maddr, |
| 2004 | mvmvif->id, mvmvif->color); |
| 2005 | if (ret) { |
| 2006 | iwl_mvm_dealloc_int_sta(mvm, msta); |
| 2007 | return ret; |
| 2008 | } |
| 2009 | |
| 2010 | /* |
| 2011 | * Enable cab queue after the ADD_STA command is sent. |
| 2012 | * 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] | 2013 | * command with unknown station id, and for FW that doesn't support |
| 2014 | * station API since the cab queue is not included in the |
| 2015 | * tfd_queue_mask. |
Sara Sharon | 26d6c16 | 2017-01-03 12:00:19 +0200 | [diff] [blame] | 2016 | */ |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 2017 | if (iwl_mvm_has_new_tx_api(mvm)) { |
| 2018 | int queue = iwl_mvm_tvqm_enable_txq(mvm, vif->cab_queue, |
| 2019 | msta->sta_id, |
| 2020 | IWL_MAX_TID_COUNT, |
| 2021 | timeout); |
Sara Sharon | e2af3fa | 2017-02-22 19:35:10 +0200 | [diff] [blame] | 2022 | mvmvif->cab_queue = queue; |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 2023 | } else if (!fw_has_api(&mvm->fw->ucode_capa, |
| 2024 | IWL_UCODE_TLV_API_STA_TYPE)) { |
Liad Kaufman | ee48b72 | 2017-03-21 17:13:16 +0200 | [diff] [blame] | 2025 | /* |
| 2026 | * In IBSS, ieee80211_check_queues() sets the cab_queue to be |
| 2027 | * invalid, so make sure we use the queue we want. |
| 2028 | * Note that this is done here as we want to avoid making DQA |
| 2029 | * changes in mac80211 layer. |
| 2030 | */ |
| 2031 | if (vif->type == NL80211_IFTYPE_ADHOC) { |
| 2032 | vif->cab_queue = IWL_MVM_DQA_GCAST_QUEUE; |
| 2033 | mvmvif->cab_queue = vif->cab_queue; |
| 2034 | } |
Sara Sharon | 310181e | 2017-01-17 14:27:48 +0200 | [diff] [blame] | 2035 | iwl_mvm_enable_txq(mvm, vif->cab_queue, vif->cab_queue, 0, |
| 2036 | &cfg, timeout); |
| 2037 | } |
Sara Sharon | 26d6c16 | 2017-01-03 12:00:19 +0200 | [diff] [blame] | 2038 | |
| 2039 | return 0; |
| 2040 | } |
| 2041 | |
| 2042 | /* |
| 2043 | * Send the FW a request to remove the station from it's internal data |
| 2044 | * structures, and in addition remove it from the local data structure. |
| 2045 | */ |
| 2046 | int iwl_mvm_rm_mcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 2047 | { |
| 2048 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 2049 | int ret; |
| 2050 | |
| 2051 | lockdep_assert_held(&mvm->mutex); |
| 2052 | |
Sara Sharon | d49394a | 2017-03-05 13:01:08 +0200 | [diff] [blame] | 2053 | iwl_mvm_flush_sta(mvm, &mvmvif->mcast_sta, true, 0); |
| 2054 | |
Sara Sharon | e2af3fa | 2017-02-22 19:35:10 +0200 | [diff] [blame] | 2055 | iwl_mvm_disable_txq(mvm, mvmvif->cab_queue, vif->cab_queue, |
Sara Sharon | 26d6c16 | 2017-01-03 12:00:19 +0200 | [diff] [blame] | 2056 | IWL_MAX_TID_COUNT, 0); |
| 2057 | |
| 2058 | ret = iwl_mvm_rm_sta_common(mvm, mvmvif->mcast_sta.sta_id); |
| 2059 | if (ret) |
| 2060 | IWL_WARN(mvm, "Failed sending remove station\n"); |
| 2061 | |
| 2062 | return ret; |
| 2063 | } |
| 2064 | |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 2065 | #define IWL_MAX_RX_BA_SESSIONS 16 |
| 2066 | |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2067 | 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] | 2068 | { |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2069 | struct iwl_mvm_delba_notif notif = { |
| 2070 | .metadata.type = IWL_MVM_RXQ_NOTIF_DEL_BA, |
| 2071 | .metadata.sync = 1, |
| 2072 | .delba.baid = baid, |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2073 | }; |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2074 | iwl_mvm_sync_rx_queues_internal(mvm, (void *)¬if, sizeof(notif)); |
| 2075 | }; |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2076 | |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2077 | static void iwl_mvm_free_reorder(struct iwl_mvm *mvm, |
| 2078 | struct iwl_mvm_baid_data *data) |
| 2079 | { |
| 2080 | int i; |
| 2081 | |
| 2082 | iwl_mvm_sync_rxq_del_ba(mvm, data->baid); |
| 2083 | |
| 2084 | for (i = 0; i < mvm->trans->num_rx_queues; i++) { |
| 2085 | int j; |
| 2086 | struct iwl_mvm_reorder_buffer *reorder_buf = |
| 2087 | &data->reorder_buf[i]; |
| 2088 | |
Sara Sharon | 0690405 | 2016-02-28 20:28:17 +0200 | [diff] [blame] | 2089 | spin_lock_bh(&reorder_buf->lock); |
| 2090 | if (likely(!reorder_buf->num_stored)) { |
| 2091 | spin_unlock_bh(&reorder_buf->lock); |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2092 | continue; |
Sara Sharon | 0690405 | 2016-02-28 20:28:17 +0200 | [diff] [blame] | 2093 | } |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2094 | |
| 2095 | /* |
| 2096 | * This shouldn't happen in regular DELBA since the internal |
| 2097 | * delBA notification should trigger a release of all frames in |
| 2098 | * the reorder buffer. |
| 2099 | */ |
| 2100 | WARN_ON(1); |
| 2101 | |
| 2102 | for (j = 0; j < reorder_buf->buf_size; j++) |
| 2103 | __skb_queue_purge(&reorder_buf->entries[j]); |
Sara Sharon | 0690405 | 2016-02-28 20:28:17 +0200 | [diff] [blame] | 2104 | /* |
| 2105 | * Prevent timer re-arm. This prevents a very far fetched case |
| 2106 | * where we timed out on the notification. There may be prior |
| 2107 | * RX frames pending in the RX queue before the notification |
| 2108 | * that might get processed between now and the actual deletion |
| 2109 | * and we would re-arm the timer although we are deleting the |
| 2110 | * reorder buffer. |
| 2111 | */ |
| 2112 | reorder_buf->removed = true; |
| 2113 | spin_unlock_bh(&reorder_buf->lock); |
| 2114 | del_timer_sync(&reorder_buf->reorder_timer); |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2115 | } |
| 2116 | } |
| 2117 | |
| 2118 | static void iwl_mvm_init_reorder_buffer(struct iwl_mvm *mvm, |
| 2119 | u32 sta_id, |
| 2120 | struct iwl_mvm_baid_data *data, |
| 2121 | u16 ssn, u8 buf_size) |
| 2122 | { |
| 2123 | int i; |
| 2124 | |
| 2125 | for (i = 0; i < mvm->trans->num_rx_queues; i++) { |
| 2126 | struct iwl_mvm_reorder_buffer *reorder_buf = |
| 2127 | &data->reorder_buf[i]; |
| 2128 | int j; |
| 2129 | |
| 2130 | reorder_buf->num_stored = 0; |
| 2131 | reorder_buf->head_sn = ssn; |
| 2132 | reorder_buf->buf_size = buf_size; |
Sara Sharon | 0690405 | 2016-02-28 20:28:17 +0200 | [diff] [blame] | 2133 | /* rx reorder timer */ |
| 2134 | reorder_buf->reorder_timer.function = |
| 2135 | iwl_mvm_reorder_timer_expired; |
| 2136 | reorder_buf->reorder_timer.data = (unsigned long)reorder_buf; |
| 2137 | init_timer(&reorder_buf->reorder_timer); |
| 2138 | spin_lock_init(&reorder_buf->lock); |
| 2139 | reorder_buf->mvm = mvm; |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2140 | reorder_buf->queue = i; |
| 2141 | reorder_buf->sta_id = sta_id; |
Sara Sharon | 5d43eab | 2017-02-02 12:51:39 +0200 | [diff] [blame] | 2142 | reorder_buf->valid = false; |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2143 | for (j = 0; j < reorder_buf->buf_size; j++) |
| 2144 | __skb_queue_head_init(&reorder_buf->entries[j]); |
| 2145 | } |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2146 | } |
| 2147 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2148 | 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] | 2149 | int tid, u16 ssn, bool start, u8 buf_size, u16 timeout) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2150 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 2151 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2152 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2153 | struct iwl_mvm_baid_data *baid_data = NULL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2154 | int ret; |
| 2155 | u32 status; |
| 2156 | |
| 2157 | lockdep_assert_held(&mvm->mutex); |
| 2158 | |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 2159 | if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) { |
| 2160 | IWL_WARN(mvm, "Not enough RX BA SESSIONS\n"); |
| 2161 | return -ENOSPC; |
| 2162 | } |
| 2163 | |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2164 | if (iwl_mvm_has_new_rx_api(mvm) && start) { |
| 2165 | /* |
| 2166 | * Allocate here so if allocation fails we can bail out early |
| 2167 | * before starting the BA session in the firmware |
| 2168 | */ |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2169 | baid_data = kzalloc(sizeof(*baid_data) + |
| 2170 | mvm->trans->num_rx_queues * |
| 2171 | sizeof(baid_data->reorder_buf[0]), |
| 2172 | GFP_KERNEL); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2173 | if (!baid_data) |
| 2174 | return -ENOMEM; |
| 2175 | } |
| 2176 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2177 | cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); |
| 2178 | cmd.sta_id = mvm_sta->sta_id; |
| 2179 | cmd.add_modify = STA_MODE_MODIFY; |
Emmanuel Grumbach | 93a4266 | 2013-07-02 13:35:35 +0300 | [diff] [blame] | 2180 | if (start) { |
| 2181 | cmd.add_immediate_ba_tid = (u8) tid; |
| 2182 | cmd.add_immediate_ba_ssn = cpu_to_le16(ssn); |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 2183 | cmd.rx_ba_window = cpu_to_le16((u16)buf_size); |
Emmanuel Grumbach | 93a4266 | 2013-07-02 13:35:35 +0300 | [diff] [blame] | 2184 | } else { |
| 2185 | cmd.remove_immediate_ba_tid = (u8) tid; |
| 2186 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2187 | cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID : |
| 2188 | STA_MODIFY_REMOVE_BA_TID; |
| 2189 | |
| 2190 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 2191 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 2192 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2193 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2194 | if (ret) |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2195 | goto out_free; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2196 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 2197 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2198 | case ADD_STA_SUCCESS: |
Sara Sharon | 35263a0 | 2016-06-21 12:12:10 +0300 | [diff] [blame] | 2199 | IWL_DEBUG_HT(mvm, "RX BA Session %sed in fw\n", |
| 2200 | start ? "start" : "stopp"); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2201 | break; |
| 2202 | case ADD_STA_IMMEDIATE_BA_FAILURE: |
| 2203 | IWL_WARN(mvm, "RX BA Session refused by fw\n"); |
| 2204 | ret = -ENOSPC; |
| 2205 | break; |
| 2206 | default: |
| 2207 | ret = -EIO; |
| 2208 | IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n", |
| 2209 | start ? "start" : "stopp", status); |
| 2210 | break; |
| 2211 | } |
| 2212 | |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2213 | if (ret) |
| 2214 | goto out_free; |
Emmanuel Grumbach | 113a044 | 2013-07-02 14:16:38 +0300 | [diff] [blame] | 2215 | |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2216 | if (start) { |
| 2217 | u8 baid; |
| 2218 | |
| 2219 | mvm->rx_ba_sessions++; |
| 2220 | |
| 2221 | if (!iwl_mvm_has_new_rx_api(mvm)) |
| 2222 | return 0; |
| 2223 | |
| 2224 | if (WARN_ON(!(status & IWL_ADD_STA_BAID_VALID_MASK))) { |
| 2225 | ret = -EINVAL; |
| 2226 | goto out_free; |
| 2227 | } |
| 2228 | baid = (u8)((status & IWL_ADD_STA_BAID_MASK) >> |
| 2229 | IWL_ADD_STA_BAID_SHIFT); |
| 2230 | baid_data->baid = baid; |
| 2231 | baid_data->timeout = timeout; |
| 2232 | baid_data->last_rx = jiffies; |
Wei Yongjun | 72c240f | 2016-07-12 11:40:57 +0000 | [diff] [blame] | 2233 | setup_timer(&baid_data->session_timer, |
| 2234 | iwl_mvm_rx_agg_session_expired, |
| 2235 | (unsigned long)&mvm->baid_map[baid]); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2236 | baid_data->mvm = mvm; |
| 2237 | baid_data->tid = tid; |
| 2238 | baid_data->sta_id = mvm_sta->sta_id; |
| 2239 | |
| 2240 | mvm_sta->tid_to_baid[tid] = baid; |
| 2241 | if (timeout) |
| 2242 | mod_timer(&baid_data->session_timer, |
| 2243 | TU_TO_EXP_TIME(timeout * 2)); |
| 2244 | |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2245 | iwl_mvm_init_reorder_buffer(mvm, mvm_sta->sta_id, |
| 2246 | baid_data, ssn, buf_size); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2247 | /* |
| 2248 | * protect the BA data with RCU to cover a case where our |
| 2249 | * internal RX sync mechanism will timeout (not that it's |
| 2250 | * supposed to happen) and we will free the session data while |
| 2251 | * RX is being processed in parallel |
| 2252 | */ |
Sara Sharon | 35263a0 | 2016-06-21 12:12:10 +0300 | [diff] [blame] | 2253 | IWL_DEBUG_HT(mvm, "Sta %d(%d) is assigned to BAID %d\n", |
| 2254 | mvm_sta->sta_id, tid, baid); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2255 | WARN_ON(rcu_access_pointer(mvm->baid_map[baid])); |
| 2256 | rcu_assign_pointer(mvm->baid_map[baid], baid_data); |
Sara Sharon | 60dec52 | 2016-06-21 14:14:08 +0300 | [diff] [blame] | 2257 | } else { |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2258 | u8 baid = mvm_sta->tid_to_baid[tid]; |
| 2259 | |
Sara Sharon | 60dec52 | 2016-06-21 14:14:08 +0300 | [diff] [blame] | 2260 | if (mvm->rx_ba_sessions > 0) |
| 2261 | /* check that restart flow didn't zero the counter */ |
| 2262 | mvm->rx_ba_sessions--; |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2263 | if (!iwl_mvm_has_new_rx_api(mvm)) |
| 2264 | return 0; |
| 2265 | |
| 2266 | if (WARN_ON(baid == IWL_RX_REORDER_DATA_INVALID_BAID)) |
| 2267 | return -EINVAL; |
| 2268 | |
| 2269 | baid_data = rcu_access_pointer(mvm->baid_map[baid]); |
| 2270 | if (WARN_ON(!baid_data)) |
| 2271 | return -EINVAL; |
| 2272 | |
| 2273 | /* synchronize all rx queues so we can safely delete */ |
Sara Sharon | b915c10 | 2016-03-23 16:32:02 +0200 | [diff] [blame] | 2274 | iwl_mvm_free_reorder(mvm, baid_data); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2275 | del_timer_sync(&baid_data->session_timer); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2276 | RCU_INIT_POINTER(mvm->baid_map[baid], NULL); |
| 2277 | kfree_rcu(baid_data, rcu_head); |
Sara Sharon | 35263a0 | 2016-06-21 12:12:10 +0300 | [diff] [blame] | 2278 | IWL_DEBUG_HT(mvm, "BAID %d is free\n", baid); |
Sara Sharon | 10b2b20 | 2016-03-20 16:23:41 +0200 | [diff] [blame] | 2279 | } |
| 2280 | return 0; |
| 2281 | |
| 2282 | out_free: |
| 2283 | kfree(baid_data); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2284 | return ret; |
| 2285 | } |
| 2286 | |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 2287 | int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, |
| 2288 | int tid, u8 queue, bool start) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2289 | { |
Johannes Berg | 9d8ce6a | 2014-12-23 16:02:40 +0100 | [diff] [blame] | 2290 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2291 | struct iwl_mvm_add_sta_cmd cmd = {}; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2292 | int ret; |
| 2293 | u32 status; |
| 2294 | |
| 2295 | lockdep_assert_held(&mvm->mutex); |
| 2296 | |
| 2297 | if (start) { |
| 2298 | mvm_sta->tfd_queue_msk |= BIT(queue); |
| 2299 | mvm_sta->tid_disable_agg &= ~BIT(tid); |
| 2300 | } else { |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2301 | /* In DQA-mode the queue isn't removed on agg termination */ |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2302 | mvm_sta->tid_disable_agg |= BIT(tid); |
| 2303 | } |
| 2304 | |
| 2305 | cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); |
| 2306 | cmd.sta_id = mvm_sta->sta_id; |
| 2307 | cmd.add_modify = STA_MODE_MODIFY; |
Sara Sharon | bb49701 | 2016-09-29 14:52:40 +0300 | [diff] [blame] | 2308 | if (!iwl_mvm_has_new_tx_api(mvm)) |
| 2309 | cmd.modify_mask = STA_MODIFY_QUEUES; |
| 2310 | cmd.modify_mask |= STA_MODIFY_TID_DISABLE_TX; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2311 | cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk); |
| 2312 | cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg); |
| 2313 | |
| 2314 | status = ADD_STA_SUCCESS; |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 2315 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, |
| 2316 | iwl_mvm_add_sta_cmd_size(mvm), |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2317 | &cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2318 | if (ret) |
| 2319 | return ret; |
| 2320 | |
Sara Sharon | 837c4da | 2016-01-07 16:50:45 +0200 | [diff] [blame] | 2321 | switch (status & IWL_ADD_STA_STATUS_MASK) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2322 | case ADD_STA_SUCCESS: |
| 2323 | break; |
| 2324 | default: |
| 2325 | ret = -EIO; |
| 2326 | IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n", |
| 2327 | start ? "start" : "stopp", status); |
| 2328 | break; |
| 2329 | } |
| 2330 | |
| 2331 | return ret; |
| 2332 | } |
| 2333 | |
Emmanuel Grumbach | b797e3f | 2014-03-06 14:49:36 +0200 | [diff] [blame] | 2334 | const u8 tid_to_mac80211_ac[] = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2335 | IEEE80211_AC_BE, |
| 2336 | IEEE80211_AC_BK, |
| 2337 | IEEE80211_AC_BK, |
| 2338 | IEEE80211_AC_BE, |
| 2339 | IEEE80211_AC_VI, |
| 2340 | IEEE80211_AC_VI, |
| 2341 | IEEE80211_AC_VO, |
| 2342 | IEEE80211_AC_VO, |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 2343 | 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] | 2344 | }; |
| 2345 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 2346 | static const u8 tid_to_ucode_ac[] = { |
| 2347 | AC_BE, |
| 2348 | AC_BK, |
| 2349 | AC_BK, |
| 2350 | AC_BE, |
| 2351 | AC_VI, |
| 2352 | AC_VI, |
| 2353 | AC_VO, |
| 2354 | AC_VO, |
| 2355 | }; |
| 2356 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2357 | int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 2358 | struct ieee80211_sta *sta, u16 tid, u16 *ssn) |
| 2359 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 2360 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2361 | struct iwl_mvm_tid_data *tid_data; |
Liad Kaufman | dd32162 | 2017-04-05 16:25:11 +0300 | [diff] [blame] | 2362 | u16 normalized_ssn; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2363 | int txq_id; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2364 | int ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2365 | |
| 2366 | if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT)) |
| 2367 | return -EINVAL; |
| 2368 | |
| 2369 | if (mvmsta->tid_data[tid].state != IWL_AGG_OFF) { |
| 2370 | IWL_ERR(mvm, "Start AGG when state is not IWL_AGG_OFF %d!\n", |
| 2371 | mvmsta->tid_data[tid].state); |
| 2372 | return -ENXIO; |
| 2373 | } |
| 2374 | |
| 2375 | lockdep_assert_held(&mvm->mutex); |
| 2376 | |
Arik Nemtsov | b249250 | 2014-03-13 12:21:50 +0200 | [diff] [blame] | 2377 | spin_lock_bh(&mvmsta->lock); |
| 2378 | |
| 2379 | /* possible race condition - we entered D0i3 while starting agg */ |
| 2380 | if (test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) { |
| 2381 | spin_unlock_bh(&mvmsta->lock); |
| 2382 | IWL_ERR(mvm, "Entered D0i3 while starting Tx agg\n"); |
| 2383 | return -EIO; |
| 2384 | } |
| 2385 | |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2386 | spin_lock(&mvm->queue_info_lock); |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2387 | |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2388 | /* |
| 2389 | * Note the possible cases: |
| 2390 | * 1. In DQA mode with an enabled TXQ - TXQ needs to become agg'ed |
| 2391 | * 2. Non-DQA mode: the TXQ hasn't yet been enabled, so find a free |
| 2392 | * one and mark it as reserved |
| 2393 | * 3. In DQA mode, but no traffic yet on this TID: same treatment as in |
| 2394 | * non-DQA mode, since the TXQ hasn't yet been allocated |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 2395 | * Don't support case 3 for new TX path as it is not expected to happen |
| 2396 | * and aggregation will be offloaded soon anyway |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2397 | */ |
| 2398 | txq_id = mvmsta->tid_data[tid].txq_id; |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 2399 | if (iwl_mvm_has_new_tx_api(mvm)) { |
| 2400 | if (txq_id == IWL_MVM_INVALID_QUEUE) { |
| 2401 | ret = -ENXIO; |
| 2402 | goto release_locks; |
| 2403 | } |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 2404 | } else if (unlikely(mvm->queue_info[txq_id].status == |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 2405 | IWL_MVM_QUEUE_SHARED)) { |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2406 | ret = -ENXIO; |
| 2407 | IWL_DEBUG_TX_QUEUES(mvm, |
| 2408 | "Can't start tid %d agg on shared queue!\n", |
| 2409 | tid); |
| 2410 | goto release_locks; |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 2411 | } else if (mvm->queue_info[txq_id].status != IWL_MVM_QUEUE_READY) { |
Liad Kaufman | 9794c64 | 2015-08-19 17:34:28 +0300 | [diff] [blame] | 2412 | txq_id = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id, |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 2413 | IWL_MVM_DQA_MIN_DATA_QUEUE, |
| 2414 | IWL_MVM_DQA_MAX_DATA_QUEUE); |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2415 | if (txq_id < 0) { |
| 2416 | ret = txq_id; |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2417 | IWL_ERR(mvm, "Failed to allocate agg queue\n"); |
| 2418 | goto release_locks; |
| 2419 | } |
Sara Sharon | 01796ff | 2016-11-16 17:04:36 +0200 | [diff] [blame] | 2420 | /* |
| 2421 | * TXQ shouldn't be in inactive mode for non-DQA, so getting |
| 2422 | * an inactive queue from iwl_mvm_find_free_queue() is |
| 2423 | * certainly a bug |
| 2424 | */ |
| 2425 | WARN_ON(mvm->queue_info[txq_id].status == |
| 2426 | IWL_MVM_QUEUE_INACTIVE); |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2427 | |
| 2428 | /* TXQ hasn't yet been enabled, so mark it only as reserved */ |
| 2429 | mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_RESERVED; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2430 | } |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2431 | |
| 2432 | spin_unlock(&mvm->queue_info_lock); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2433 | |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2434 | IWL_DEBUG_TX_QUEUES(mvm, |
| 2435 | "AGG for tid %d will be on queue #%d\n", |
| 2436 | tid, txq_id); |
| 2437 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2438 | tid_data = &mvmsta->tid_data[tid]; |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 2439 | tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2440 | tid_data->txq_id = txq_id; |
| 2441 | *ssn = tid_data->ssn; |
| 2442 | |
| 2443 | IWL_DEBUG_TX_QUEUES(mvm, |
| 2444 | "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n", |
| 2445 | mvmsta->sta_id, tid, txq_id, tid_data->ssn, |
| 2446 | tid_data->next_reclaimed); |
| 2447 | |
Liad Kaufman | dd32162 | 2017-04-05 16:25:11 +0300 | [diff] [blame] | 2448 | /* |
| 2449 | * In A000 HW, the next_reclaimed index is only 8 bit, so we'll need |
| 2450 | * to align the wrap around of ssn so we compare relevant values. |
| 2451 | */ |
| 2452 | normalized_ssn = tid_data->ssn; |
| 2453 | if (mvm->trans->cfg->gen2) |
| 2454 | normalized_ssn &= 0xff; |
| 2455 | |
| 2456 | if (normalized_ssn == tid_data->next_reclaimed) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2457 | tid_data->state = IWL_AGG_STARTING; |
| 2458 | ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2459 | } else { |
| 2460 | tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA; |
| 2461 | } |
| 2462 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2463 | ret = 0; |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2464 | goto out; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2465 | |
| 2466 | release_locks: |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2467 | spin_unlock(&mvm->queue_info_lock); |
| 2468 | out: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2469 | spin_unlock_bh(&mvmsta->lock); |
| 2470 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2471 | return ret; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2472 | } |
| 2473 | |
| 2474 | 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] | 2475 | struct ieee80211_sta *sta, u16 tid, u8 buf_size, |
| 2476 | bool amsdu) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2477 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 2478 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2479 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
Emmanuel Grumbach | 5d42e7b | 2015-03-19 20:04:51 +0200 | [diff] [blame] | 2480 | unsigned int wdg_timeout = |
| 2481 | iwl_mvm_get_wd_timeout(mvm, vif, sta->tdls, false); |
Emmanuel Grumbach | eea76c3 | 2016-02-21 16:29:17 +0200 | [diff] [blame] | 2482 | int queue, ret; |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2483 | bool alloc_queue = true; |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2484 | enum iwl_mvm_queue_status queue_status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2485 | u16 ssn; |
| 2486 | |
Emmanuel Grumbach | eea76c3 | 2016-02-21 16:29:17 +0200 | [diff] [blame] | 2487 | struct iwl_trans_txq_scd_cfg cfg = { |
| 2488 | .sta_id = mvmsta->sta_id, |
| 2489 | .tid = tid, |
| 2490 | .frame_limit = buf_size, |
| 2491 | .aggregate = true, |
| 2492 | }; |
| 2493 | |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 2494 | BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE) |
| 2495 | != IWL_MAX_TID_COUNT); |
| 2496 | |
Liad Kaufman | a58bb46 | 2017-05-28 14:20:04 +0300 | [diff] [blame] | 2497 | if (!mvm->trans->cfg->gen2) |
| 2498 | buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF); |
| 2499 | else |
| 2500 | buf_size = min_t(int, buf_size, |
| 2501 | LINK_QUAL_AGG_FRAME_LIMIT_GEN2_DEF); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2502 | |
| 2503 | spin_lock_bh(&mvmsta->lock); |
| 2504 | ssn = tid_data->ssn; |
| 2505 | queue = tid_data->txq_id; |
| 2506 | tid_data->state = IWL_AGG_ON; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 2507 | mvmsta->agg_tids |= BIT(tid); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2508 | tid_data->ssn = 0xffff; |
Emmanuel Grumbach | bb81bb6 | 2015-10-26 16:00:29 +0200 | [diff] [blame] | 2509 | tid_data->amsdu_in_ampdu_allowed = amsdu; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2510 | spin_unlock_bh(&mvmsta->lock); |
| 2511 | |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 2512 | if (iwl_mvm_has_new_tx_api(mvm)) { |
| 2513 | /* |
| 2514 | * If no queue iwl_mvm_sta_tx_agg_start() would have failed so |
| 2515 | * no need to check queue's status |
| 2516 | */ |
| 2517 | if (buf_size < mvmsta->max_agg_bufsize) |
| 2518 | return -ENOTSUPP; |
| 2519 | |
| 2520 | ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true); |
| 2521 | if (ret) |
| 2522 | return -EIO; |
| 2523 | goto out; |
| 2524 | } |
| 2525 | |
Emmanuel Grumbach | eea76c3 | 2016-02-21 16:29:17 +0200 | [diff] [blame] | 2526 | 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] | 2527 | |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2528 | spin_lock_bh(&mvm->queue_info_lock); |
| 2529 | queue_status = mvm->queue_info[queue].status; |
| 2530 | spin_unlock_bh(&mvm->queue_info_lock); |
| 2531 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 2532 | /* Maybe there is no need to even alloc a queue... */ |
| 2533 | if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_READY) |
| 2534 | alloc_queue = false; |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2535 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 2536 | /* |
| 2537 | * Only reconfig the SCD for the queue if the window size has |
| 2538 | * changed from current (become smaller) |
| 2539 | */ |
| 2540 | if (!alloc_queue && buf_size < mvmsta->max_agg_bufsize) { |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2541 | /* |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 2542 | * If reconfiguring an existing queue, it first must be |
| 2543 | * drained |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2544 | */ |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 2545 | ret = iwl_trans_wait_tx_queues_empty(mvm->trans, |
| 2546 | BIT(queue)); |
| 2547 | if (ret) { |
| 2548 | IWL_ERR(mvm, |
| 2549 | "Error draining queue before reconfig\n"); |
| 2550 | return ret; |
| 2551 | } |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2552 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 2553 | ret = iwl_mvm_reconfig_scd(mvm, queue, cfg.fifo, |
| 2554 | mvmsta->sta_id, tid, |
| 2555 | buf_size, ssn); |
| 2556 | if (ret) { |
| 2557 | IWL_ERR(mvm, |
| 2558 | "Error reconfiguring TXQ #%d\n", queue); |
| 2559 | return ret; |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2560 | } |
| 2561 | } |
| 2562 | |
| 2563 | if (alloc_queue) |
| 2564 | iwl_mvm_enable_txq(mvm, queue, |
| 2565 | vif->hw_queue[tid_to_mac80211_ac[tid]], ssn, |
| 2566 | &cfg, wdg_timeout); |
Andrei Otcheretianski | fa7878e | 2015-05-05 09:28:16 +0300 | [diff] [blame] | 2567 | |
Liad Kaufman | 9f9af3d | 2015-12-23 16:03:46 +0200 | [diff] [blame] | 2568 | /* Send ADD_STA command to enable aggs only if the queue isn't shared */ |
| 2569 | if (queue_status != IWL_MVM_QUEUE_SHARED) { |
| 2570 | ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true); |
| 2571 | if (ret) |
| 2572 | return -EIO; |
| 2573 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2574 | |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2575 | /* No need to mark as reserved */ |
| 2576 | spin_lock_bh(&mvm->queue_info_lock); |
Liad Kaufman | cf961e1 | 2015-08-13 19:16:08 +0300 | [diff] [blame] | 2577 | mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY; |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2578 | spin_unlock_bh(&mvm->queue_info_lock); |
| 2579 | |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 2580 | out: |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2581 | /* |
| 2582 | * Even though in theory the peer could have different |
| 2583 | * aggregation reorder buffer sizes for different sessions, |
| 2584 | * our ucode doesn't allow for that and has a global limit |
| 2585 | * for each station. Therefore, use the minimum of all the |
| 2586 | * aggregation sessions and our default value. |
| 2587 | */ |
| 2588 | mvmsta->max_agg_bufsize = |
| 2589 | min(mvmsta->max_agg_bufsize, buf_size); |
| 2590 | mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize; |
| 2591 | |
Eytan Lifshitz | 9ee718a | 2013-05-19 19:14:41 +0300 | [diff] [blame] | 2592 | IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n", |
| 2593 | sta->addr, tid); |
| 2594 | |
Eyal Shapira | 9e68094 | 2013-11-09 00:16:16 +0200 | [diff] [blame] | 2595 | return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2596 | } |
| 2597 | |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 2598 | static void iwl_mvm_unreserve_agg_queue(struct iwl_mvm *mvm, |
| 2599 | struct iwl_mvm_sta *mvmsta, |
| 2600 | u16 txq_id) |
| 2601 | { |
| 2602 | if (iwl_mvm_has_new_tx_api(mvm)) |
| 2603 | return; |
| 2604 | |
| 2605 | spin_lock_bh(&mvm->queue_info_lock); |
| 2606 | /* |
| 2607 | * The TXQ is marked as reserved only if no traffic came through yet |
| 2608 | * This means no traffic has been sent on this TID (agg'd or not), so |
| 2609 | * we no longer have use for the queue. Since it hasn't even been |
| 2610 | * allocated through iwl_mvm_enable_txq, so we can just mark it back as |
| 2611 | * free. |
| 2612 | */ |
| 2613 | if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED) |
| 2614 | mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE; |
| 2615 | |
| 2616 | spin_unlock_bh(&mvm->queue_info_lock); |
| 2617 | } |
| 2618 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2619 | int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 2620 | struct ieee80211_sta *sta, u16 tid) |
| 2621 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 2622 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2623 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
| 2624 | u16 txq_id; |
| 2625 | int err; |
| 2626 | |
Emmanuel Grumbach | f9aa8dd | 2013-03-04 09:11:08 +0200 | [diff] [blame] | 2627 | /* |
| 2628 | * If mac80211 is cleaning its state, then say that we finished since |
| 2629 | * our state has been cleared anyway. |
| 2630 | */ |
| 2631 | if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { |
| 2632 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2633 | return 0; |
| 2634 | } |
| 2635 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2636 | spin_lock_bh(&mvmsta->lock); |
| 2637 | |
| 2638 | txq_id = tid_data->txq_id; |
| 2639 | |
| 2640 | IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n", |
| 2641 | mvmsta->sta_id, tid, txq_id, tid_data->state); |
| 2642 | |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 2643 | mvmsta->agg_tids &= ~BIT(tid); |
| 2644 | |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 2645 | iwl_mvm_unreserve_agg_queue(mvm, mvmsta, txq_id); |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2646 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2647 | switch (tid_data->state) { |
| 2648 | case IWL_AGG_ON: |
Johannes Berg | 9a88658 | 2013-02-15 19:25:00 +0100 | [diff] [blame] | 2649 | tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2650 | |
| 2651 | IWL_DEBUG_TX_QUEUES(mvm, |
| 2652 | "ssn = %d, next_recl = %d\n", |
| 2653 | tid_data->ssn, tid_data->next_reclaimed); |
| 2654 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2655 | tid_data->ssn = 0xffff; |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 2656 | tid_data->state = IWL_AGG_OFF; |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 2657 | spin_unlock_bh(&mvmsta->lock); |
| 2658 | |
| 2659 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2660 | |
| 2661 | iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false); |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 2662 | return 0; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2663 | case IWL_AGG_STARTING: |
| 2664 | case IWL_EMPTYING_HW_QUEUE_ADDBA: |
| 2665 | /* |
| 2666 | * The agg session has been stopped before it was set up. This |
| 2667 | * can happen when the AddBA timer times out for example. |
| 2668 | */ |
| 2669 | |
| 2670 | /* No barriers since we are under mutex */ |
| 2671 | lockdep_assert_held(&mvm->mutex); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2672 | |
| 2673 | ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); |
| 2674 | tid_data->state = IWL_AGG_OFF; |
| 2675 | err = 0; |
| 2676 | break; |
| 2677 | default: |
| 2678 | IWL_ERR(mvm, |
| 2679 | "Stopping AGG while state not ON or starting for %d on %d (%d)\n", |
| 2680 | mvmsta->sta_id, tid, tid_data->state); |
| 2681 | IWL_ERR(mvm, |
| 2682 | "\ttid_data->txq_id = %d\n", tid_data->txq_id); |
| 2683 | err = -EINVAL; |
| 2684 | } |
| 2685 | |
| 2686 | spin_unlock_bh(&mvmsta->lock); |
| 2687 | |
| 2688 | return err; |
| 2689 | } |
| 2690 | |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2691 | int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif, |
| 2692 | struct ieee80211_sta *sta, u16 tid) |
| 2693 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 2694 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2695 | struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; |
| 2696 | u16 txq_id; |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2697 | enum iwl_mvm_agg_state old_state; |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2698 | |
| 2699 | /* |
| 2700 | * First set the agg state to OFF to avoid calling |
| 2701 | * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty. |
| 2702 | */ |
| 2703 | spin_lock_bh(&mvmsta->lock); |
| 2704 | txq_id = tid_data->txq_id; |
| 2705 | IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n", |
| 2706 | mvmsta->sta_id, tid, txq_id, tid_data->state); |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2707 | old_state = tid_data->state; |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2708 | tid_data->state = IWL_AGG_OFF; |
Eyal Shapira | efed664 | 2014-09-14 15:58:53 +0300 | [diff] [blame] | 2709 | mvmsta->agg_tids &= ~BIT(tid); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2710 | spin_unlock_bh(&mvmsta->lock); |
| 2711 | |
Sara Sharon | 34e1086 | 2017-02-23 13:15:07 +0200 | [diff] [blame] | 2712 | iwl_mvm_unreserve_agg_queue(mvm, mvmsta, txq_id); |
Liad Kaufman | 4ecafae | 2015-07-14 13:36:18 +0300 | [diff] [blame] | 2713 | |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2714 | if (old_state >= IWL_AGG_ON) { |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 2715 | iwl_mvm_drain_sta(mvm, mvmsta, true); |
Sara Sharon | d6d517b | 2017-03-06 10:16:11 +0200 | [diff] [blame] | 2716 | |
Mordechai Goodstein | d167e81 | 2017-05-10 16:42:53 +0300 | [diff] [blame] | 2717 | if (iwl_mvm_has_new_tx_api(mvm)) { |
| 2718 | if (iwl_mvm_flush_sta_tids(mvm, mvmsta->sta_id, |
| 2719 | BIT(tid), 0)) |
| 2720 | IWL_ERR(mvm, "Couldn't flush the AGG queue\n"); |
Sara Sharon | d6d517b | 2017-03-06 10:16:11 +0200 | [diff] [blame] | 2721 | iwl_trans_wait_txq_empty(mvm->trans, txq_id); |
Mordechai Goodstein | d167e81 | 2017-05-10 16:42:53 +0300 | [diff] [blame] | 2722 | } else { |
| 2723 | if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), 0)) |
| 2724 | IWL_ERR(mvm, "Couldn't flush the AGG queue\n"); |
Sara Sharon | d6d517b | 2017-03-06 10:16:11 +0200 | [diff] [blame] | 2725 | iwl_trans_wait_tx_queues_empty(mvm->trans, BIT(txq_id)); |
Mordechai Goodstein | d167e81 | 2017-05-10 16:42:53 +0300 | [diff] [blame] | 2726 | } |
Sara Sharon | d6d517b | 2017-03-06 10:16:11 +0200 | [diff] [blame] | 2727 | |
Emmanuel Grumbach | fe92e32 | 2015-03-11 09:34:31 +0200 | [diff] [blame] | 2728 | iwl_mvm_drain_sta(mvm, mvmsta, false); |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2729 | |
Johannes Berg | f7f89e7 | 2014-08-05 15:24:44 +0200 | [diff] [blame] | 2730 | iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false); |
Johannes Berg | b6658ff | 2013-07-24 13:55:51 +0200 | [diff] [blame] | 2731 | } |
| 2732 | |
Emmanuel Grumbach | e3d9e7c | 2013-02-19 16:13:53 +0200 | [diff] [blame] | 2733 | return 0; |
| 2734 | } |
| 2735 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2736 | static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm) |
| 2737 | { |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2738 | int i, max = -1, max_offs = -1; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2739 | |
| 2740 | lockdep_assert_held(&mvm->mutex); |
| 2741 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2742 | /* Pick the unused key offset with the highest 'deleted' |
| 2743 | * counter. Every time a key is deleted, all the counters |
| 2744 | * are incremented and the one that was just deleted is |
| 2745 | * reset to zero. Thus, the highest counter is the one |
| 2746 | * that was deleted longest ago. Pick that one. |
| 2747 | */ |
| 2748 | for (i = 0; i < STA_KEY_MAX_NUM; i++) { |
| 2749 | if (test_bit(i, mvm->fw_key_table)) |
| 2750 | continue; |
| 2751 | if (mvm->fw_key_deleted[i] > max) { |
| 2752 | max = mvm->fw_key_deleted[i]; |
| 2753 | max_offs = i; |
| 2754 | } |
| 2755 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2756 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2757 | if (max_offs < 0) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2758 | return STA_KEY_IDX_INVALID; |
| 2759 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 2760 | return max_offs; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2761 | } |
| 2762 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2763 | static struct iwl_mvm_sta *iwl_mvm_get_key_sta(struct iwl_mvm *mvm, |
| 2764 | struct ieee80211_vif *vif, |
| 2765 | struct ieee80211_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2766 | { |
Johannes Berg | 5b530e9 | 2014-12-23 16:00:17 +0100 | [diff] [blame] | 2767 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2768 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2769 | if (sta) |
| 2770 | return iwl_mvm_sta_from_mac80211(sta); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2771 | |
| 2772 | /* |
| 2773 | * The device expects GTKs for station interfaces to be |
| 2774 | * installed as GTKs for the AP station. If we have no |
| 2775 | * station ID, then use AP's station ID. |
| 2776 | */ |
| 2777 | if (vif->type == NL80211_IFTYPE_STATION && |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 2778 | mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) { |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 2779 | u8 sta_id = mvmvif->ap_sta_id; |
| 2780 | |
Emmanuel Grumbach | 7d6a1ab | 2016-05-15 10:20:29 +0300 | [diff] [blame] | 2781 | sta = rcu_dereference_check(mvm->fw_id_to_mac_id[sta_id], |
| 2782 | lockdep_is_held(&mvm->mutex)); |
| 2783 | |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 2784 | /* |
| 2785 | * It is possible that the 'sta' parameter is NULL, |
| 2786 | * for example when a GTK is removed - the sta_id will then |
| 2787 | * be the AP ID, and no station was passed by mac80211. |
| 2788 | */ |
Emmanuel Grumbach | 7d6a1ab | 2016-05-15 10:20:29 +0300 | [diff] [blame] | 2789 | if (IS_ERR_OR_NULL(sta)) |
| 2790 | return NULL; |
| 2791 | |
| 2792 | return iwl_mvm_sta_from_mac80211(sta); |
Avri Altman | 9513c5e | 2015-10-19 16:29:11 +0200 | [diff] [blame] | 2793 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2794 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 2795 | return NULL; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2796 | } |
| 2797 | |
| 2798 | static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm, |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 2799 | u32 sta_id, |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 2800 | struct ieee80211_key_conf *key, bool mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 2801 | u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags, |
| 2802 | u8 key_offset) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2803 | { |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 2804 | union { |
| 2805 | struct iwl_mvm_add_sta_key_cmd_v1 cmd_v1; |
| 2806 | struct iwl_mvm_add_sta_key_cmd cmd; |
| 2807 | } u = {}; |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 2808 | __le16 key_flags; |
Johannes Berg | 7992074 | 2014-11-03 15:43:04 +0100 | [diff] [blame] | 2809 | int ret; |
| 2810 | u32 status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2811 | u16 keyidx; |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 2812 | u64 pn = 0; |
| 2813 | int i, size; |
| 2814 | bool new_api = fw_has_api(&mvm->fw->ucode_capa, |
| 2815 | IWL_UCODE_TLV_API_TKIP_MIC_KEYS); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2816 | |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 2817 | if (sta_id == IWL_MVM_INVALID_STA) |
| 2818 | return -EINVAL; |
| 2819 | |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 2820 | keyidx = (key->keyidx << STA_KEY_FLG_KEYID_POS) & |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2821 | STA_KEY_FLG_KEYID_MSK; |
| 2822 | key_flags = cpu_to_le16(keyidx); |
| 2823 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP); |
| 2824 | |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 2825 | switch (key->cipher) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2826 | case WLAN_CIPHER_SUITE_TKIP: |
| 2827 | key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP); |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 2828 | if (new_api) { |
| 2829 | memcpy((void *)&u.cmd.tx_mic_key, |
| 2830 | &key->key[NL80211_TKIP_DATA_OFFSET_TX_MIC_KEY], |
| 2831 | IWL_MIC_KEY_SIZE); |
| 2832 | |
| 2833 | memcpy((void *)&u.cmd.rx_mic_key, |
| 2834 | &key->key[NL80211_TKIP_DATA_OFFSET_RX_MIC_KEY], |
| 2835 | IWL_MIC_KEY_SIZE); |
| 2836 | pn = atomic64_read(&key->tx_pn); |
| 2837 | |
| 2838 | } else { |
| 2839 | u.cmd_v1.tkip_rx_tsc_byte2 = tkip_iv32; |
| 2840 | for (i = 0; i < 5; i++) |
| 2841 | u.cmd_v1.tkip_rx_ttak[i] = |
| 2842 | cpu_to_le16(tkip_p1k[i]); |
| 2843 | } |
| 2844 | memcpy(u.cmd.common.key, key->key, key->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2845 | break; |
| 2846 | case WLAN_CIPHER_SUITE_CCMP: |
| 2847 | key_flags |= cpu_to_le16(STA_KEY_FLG_CCM); |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 2848 | memcpy(u.cmd.common.key, key->key, key->keylen); |
| 2849 | if (new_api) |
| 2850 | pn = atomic64_read(&key->tx_pn); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2851 | break; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2852 | case WLAN_CIPHER_SUITE_WEP104: |
| 2853 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES); |
John W. Linville | aa0cb08 | 2015-01-12 16:18:11 -0500 | [diff] [blame] | 2854 | /* fall through */ |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2855 | case WLAN_CIPHER_SUITE_WEP40: |
| 2856 | key_flags |= cpu_to_le16(STA_KEY_FLG_WEP); |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 2857 | memcpy(u.cmd.common.key + 3, key->key, key->keylen); |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2858 | break; |
Ayala Beker | 2a53d16 | 2016-04-07 16:21:57 +0300 | [diff] [blame] | 2859 | case WLAN_CIPHER_SUITE_GCMP_256: |
| 2860 | key_flags |= cpu_to_le16(STA_KEY_FLG_KEY_32BYTES); |
| 2861 | /* fall through */ |
| 2862 | case WLAN_CIPHER_SUITE_GCMP: |
| 2863 | key_flags |= cpu_to_le16(STA_KEY_FLG_GCMP); |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 2864 | memcpy(u.cmd.common.key, key->key, key->keylen); |
| 2865 | if (new_api) |
| 2866 | pn = atomic64_read(&key->tx_pn); |
Ayala Beker | 2a53d16 | 2016-04-07 16:21:57 +0300 | [diff] [blame] | 2867 | break; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2868 | default: |
Max Stepanov | e36e543 | 2013-08-27 19:56:13 +0300 | [diff] [blame] | 2869 | key_flags |= cpu_to_le16(STA_KEY_FLG_EXT); |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 2870 | memcpy(u.cmd.common.key, key->key, key->keylen); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2871 | } |
| 2872 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 2873 | if (mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2874 | key_flags |= cpu_to_le16(STA_KEY_MULTICAST); |
| 2875 | |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 2876 | u.cmd.common.key_offset = key_offset; |
| 2877 | u.cmd.common.key_flags = key_flags; |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 2878 | u.cmd.common.sta_id = sta_id; |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 2879 | |
| 2880 | if (new_api) { |
| 2881 | u.cmd.transmit_seq_cnt = cpu_to_le64(pn); |
| 2882 | size = sizeof(u.cmd); |
| 2883 | } else { |
| 2884 | size = sizeof(u.cmd_v1); |
| 2885 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2886 | |
| 2887 | status = ADD_STA_SUCCESS; |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 2888 | if (cmd_flags & CMD_ASYNC) |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 2889 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC, size, |
| 2890 | &u.cmd); |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 2891 | else |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 2892 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, size, |
| 2893 | &u.cmd, &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2894 | |
| 2895 | switch (status) { |
| 2896 | case ADD_STA_SUCCESS: |
| 2897 | IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n"); |
| 2898 | break; |
| 2899 | default: |
| 2900 | ret = -EIO; |
| 2901 | IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n"); |
| 2902 | break; |
| 2903 | } |
| 2904 | |
| 2905 | return ret; |
| 2906 | } |
| 2907 | |
| 2908 | static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm, |
| 2909 | struct ieee80211_key_conf *keyconf, |
| 2910 | u8 sta_id, bool remove_key) |
| 2911 | { |
| 2912 | struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {}; |
| 2913 | |
| 2914 | /* verify the key details match the required command's expectations */ |
Ayala Beker | 8e160ab | 2016-04-11 11:37:38 +0300 | [diff] [blame] | 2915 | if (WARN_ON((keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) || |
| 2916 | (keyconf->keyidx != 4 && keyconf->keyidx != 5) || |
| 2917 | (keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC && |
| 2918 | keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_128 && |
| 2919 | keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_256))) |
| 2920 | return -EINVAL; |
| 2921 | |
| 2922 | if (WARN_ON(!iwl_mvm_has_new_rx_api(mvm) && |
| 2923 | keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC)) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2924 | return -EINVAL; |
| 2925 | |
| 2926 | igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx); |
| 2927 | igtk_cmd.sta_id = cpu_to_le32(sta_id); |
| 2928 | |
| 2929 | if (remove_key) { |
| 2930 | igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID); |
| 2931 | } else { |
| 2932 | struct ieee80211_key_seq seq; |
| 2933 | const u8 *pn; |
| 2934 | |
Ayala Beker | aa95052 | 2016-06-01 00:28:09 +0300 | [diff] [blame] | 2935 | switch (keyconf->cipher) { |
| 2936 | case WLAN_CIPHER_SUITE_AES_CMAC: |
| 2937 | igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_CCM); |
| 2938 | break; |
Ayala Beker | 8e160ab | 2016-04-11 11:37:38 +0300 | [diff] [blame] | 2939 | case WLAN_CIPHER_SUITE_BIP_GMAC_128: |
| 2940 | case WLAN_CIPHER_SUITE_BIP_GMAC_256: |
| 2941 | igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_GCMP); |
| 2942 | break; |
Ayala Beker | aa95052 | 2016-06-01 00:28:09 +0300 | [diff] [blame] | 2943 | default: |
| 2944 | return -EINVAL; |
| 2945 | } |
| 2946 | |
Ayala Beker | 8e160ab | 2016-04-11 11:37:38 +0300 | [diff] [blame] | 2947 | memcpy(igtk_cmd.igtk, keyconf->key, keyconf->keylen); |
| 2948 | if (keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) |
| 2949 | igtk_cmd.ctrl_flags |= |
| 2950 | cpu_to_le32(STA_KEY_FLG_KEY_32BYTES); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2951 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); |
| 2952 | pn = seq.aes_cmac.pn; |
| 2953 | igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) | |
| 2954 | ((u64) pn[4] << 8) | |
| 2955 | ((u64) pn[3] << 16) | |
| 2956 | ((u64) pn[2] << 24) | |
| 2957 | ((u64) pn[1] << 32) | |
| 2958 | ((u64) pn[0] << 40)); |
| 2959 | } |
| 2960 | |
| 2961 | IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n", |
| 2962 | remove_key ? "removing" : "installing", |
| 2963 | igtk_cmd.sta_id); |
| 2964 | |
Ayala Beker | 8e160ab | 2016-04-11 11:37:38 +0300 | [diff] [blame] | 2965 | if (!iwl_mvm_has_new_rx_api(mvm)) { |
| 2966 | struct iwl_mvm_mgmt_mcast_key_cmd_v1 igtk_cmd_v1 = { |
| 2967 | .ctrl_flags = igtk_cmd.ctrl_flags, |
| 2968 | .key_id = igtk_cmd.key_id, |
| 2969 | .sta_id = igtk_cmd.sta_id, |
| 2970 | .receive_seq_cnt = igtk_cmd.receive_seq_cnt |
| 2971 | }; |
| 2972 | |
| 2973 | memcpy(igtk_cmd_v1.igtk, igtk_cmd.igtk, |
| 2974 | ARRAY_SIZE(igtk_cmd_v1.igtk)); |
| 2975 | return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0, |
| 2976 | sizeof(igtk_cmd_v1), &igtk_cmd_v1); |
| 2977 | } |
Emmanuel Grumbach | a102292 | 2014-05-12 11:36:41 +0300 | [diff] [blame] | 2978 | return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2979 | sizeof(igtk_cmd), &igtk_cmd); |
| 2980 | } |
| 2981 | |
| 2982 | |
| 2983 | static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm, |
| 2984 | struct ieee80211_vif *vif, |
| 2985 | struct ieee80211_sta *sta) |
| 2986 | { |
Johannes Berg | 5b530e9 | 2014-12-23 16:00:17 +0100 | [diff] [blame] | 2987 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2988 | |
| 2989 | if (sta) |
| 2990 | return sta->addr; |
| 2991 | |
| 2992 | if (vif->type == NL80211_IFTYPE_STATION && |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 2993 | mvmvif->ap_sta_id != IWL_MVM_INVALID_STA) { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 2994 | u8 sta_id = mvmvif->ap_sta_id; |
| 2995 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], |
| 2996 | lockdep_is_held(&mvm->mutex)); |
| 2997 | return sta->addr; |
| 2998 | } |
| 2999 | |
| 3000 | |
| 3001 | return NULL; |
| 3002 | } |
| 3003 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3004 | static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm, |
| 3005 | struct ieee80211_vif *vif, |
| 3006 | struct ieee80211_sta *sta, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3007 | struct ieee80211_key_conf *keyconf, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3008 | u8 key_offset, |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3009 | bool mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3010 | { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3011 | int ret; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3012 | const u8 *addr; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3013 | struct ieee80211_key_seq seq; |
| 3014 | u16 p1k[5]; |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3015 | u32 sta_id; |
| 3016 | |
| 3017 | if (sta) { |
| 3018 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
| 3019 | |
| 3020 | sta_id = mvm_sta->sta_id; |
| 3021 | } else if (vif->type == NL80211_IFTYPE_AP && |
| 3022 | !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE)) { |
| 3023 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 3024 | |
| 3025 | sta_id = mvmvif->mcast_sta.sta_id; |
| 3026 | } else { |
| 3027 | IWL_ERR(mvm, "Failed to find station id\n"); |
| 3028 | return -EINVAL; |
| 3029 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3030 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3031 | switch (keyconf->cipher) { |
| 3032 | case WLAN_CIPHER_SUITE_TKIP: |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3033 | if (vif->type == NL80211_IFTYPE_AP) { |
| 3034 | ret = -EINVAL; |
| 3035 | break; |
| 3036 | } |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3037 | addr = iwl_mvm_get_mac_addr(mvm, vif, sta); |
| 3038 | /* get phase 1 key from mac80211 */ |
| 3039 | ieee80211_get_key_rx_seq(keyconf, 0, &seq); |
| 3040 | ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k); |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3041 | ret = iwl_mvm_send_sta_key(mvm, sta_id, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3042 | seq.tkip.iv32, p1k, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3043 | break; |
| 3044 | case WLAN_CIPHER_SUITE_CCMP: |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3045 | case WLAN_CIPHER_SUITE_WEP40: |
| 3046 | case WLAN_CIPHER_SUITE_WEP104: |
Ayala Beker | 2a53d16 | 2016-04-07 16:21:57 +0300 | [diff] [blame] | 3047 | case WLAN_CIPHER_SUITE_GCMP: |
| 3048 | case WLAN_CIPHER_SUITE_GCMP_256: |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3049 | ret = iwl_mvm_send_sta_key(mvm, sta_id, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3050 | 0, NULL, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3051 | break; |
| 3052 | default: |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3053 | ret = iwl_mvm_send_sta_key(mvm, sta_id, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3054 | 0, NULL, 0, key_offset); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3055 | } |
| 3056 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3057 | return ret; |
| 3058 | } |
| 3059 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3060 | 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] | 3061 | struct ieee80211_key_conf *keyconf, |
| 3062 | bool mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3063 | { |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3064 | union { |
| 3065 | struct iwl_mvm_add_sta_key_cmd_v1 cmd_v1; |
| 3066 | struct iwl_mvm_add_sta_key_cmd cmd; |
| 3067 | } u = {}; |
| 3068 | bool new_api = fw_has_api(&mvm->fw->ucode_capa, |
| 3069 | IWL_UCODE_TLV_API_TKIP_MIC_KEYS); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3070 | __le16 key_flags; |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3071 | int ret, size; |
Johannes Berg | 7992074 | 2014-11-03 15:43:04 +0100 | [diff] [blame] | 3072 | u32 status; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3073 | |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3074 | if (sta_id == IWL_MVM_INVALID_STA) |
| 3075 | return -EINVAL; |
| 3076 | |
Emmanuel Grumbach | 8115efb | 2013-02-05 10:08:35 +0200 | [diff] [blame] | 3077 | key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & |
| 3078 | STA_KEY_FLG_KEYID_MSK); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3079 | key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP); |
| 3080 | key_flags |= cpu_to_le16(STA_KEY_NOT_VALID); |
| 3081 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3082 | if (mcast) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3083 | key_flags |= cpu_to_le16(STA_KEY_MULTICAST); |
| 3084 | |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3085 | /* |
| 3086 | * The fields assigned here are in the same location at the start |
| 3087 | * of the command, so we can do this union trick. |
| 3088 | */ |
| 3089 | u.cmd.common.key_flags = key_flags; |
| 3090 | u.cmd.common.key_offset = keyconf->hw_key_idx; |
| 3091 | u.cmd.common.sta_id = sta_id; |
| 3092 | |
| 3093 | size = new_api ? sizeof(u.cmd) : sizeof(u.cmd_v1); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3094 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3095 | status = ADD_STA_SUCCESS; |
Sara Sharon | 45c458b | 2016-11-09 15:43:26 +0200 | [diff] [blame] | 3096 | ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, size, &u.cmd, |
| 3097 | &status); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3098 | |
| 3099 | switch (status) { |
| 3100 | case ADD_STA_SUCCESS: |
| 3101 | IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n"); |
| 3102 | break; |
| 3103 | default: |
| 3104 | ret = -EIO; |
| 3105 | IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n"); |
| 3106 | break; |
| 3107 | } |
| 3108 | |
| 3109 | return ret; |
| 3110 | } |
| 3111 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3112 | int iwl_mvm_set_sta_key(struct iwl_mvm *mvm, |
| 3113 | struct ieee80211_vif *vif, |
| 3114 | struct ieee80211_sta *sta, |
| 3115 | struct ieee80211_key_conf *keyconf, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3116 | u8 key_offset) |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3117 | { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3118 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 3119 | struct iwl_mvm_sta *mvm_sta; |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3120 | u8 sta_id = IWL_MVM_INVALID_STA; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3121 | int ret; |
Matti Gottlieb | 11828db | 2015-06-01 15:15:11 +0300 | [diff] [blame] | 3122 | static const u8 __maybe_unused zero_addr[ETH_ALEN] = {0}; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3123 | |
| 3124 | lockdep_assert_held(&mvm->mutex); |
| 3125 | |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3126 | if (vif->type != NL80211_IFTYPE_AP || |
| 3127 | keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) { |
| 3128 | /* Get the station id from the mvm local station table */ |
| 3129 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
| 3130 | if (!mvm_sta) { |
| 3131 | IWL_ERR(mvm, "Failed to find station\n"); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3132 | return -EINVAL; |
| 3133 | } |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3134 | sta_id = mvm_sta->sta_id; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3135 | |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3136 | if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC || |
| 3137 | keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || |
| 3138 | keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) { |
| 3139 | ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, |
| 3140 | false); |
| 3141 | goto end; |
| 3142 | } |
| 3143 | |
| 3144 | /* |
| 3145 | * It is possible that the 'sta' parameter is NULL, and thus |
| 3146 | * there is a need to retrieve the sta from the local station |
| 3147 | * table. |
| 3148 | */ |
| 3149 | if (!sta) { |
| 3150 | sta = rcu_dereference_protected( |
| 3151 | mvm->fw_id_to_mac_id[sta_id], |
| 3152 | lockdep_is_held(&mvm->mutex)); |
| 3153 | if (IS_ERR_OR_NULL(sta)) { |
| 3154 | IWL_ERR(mvm, "Invalid station id\n"); |
| 3155 | return -EINVAL; |
| 3156 | } |
| 3157 | } |
| 3158 | |
| 3159 | if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif)) |
| 3160 | return -EINVAL; |
| 3161 | } |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3162 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3163 | /* If the key_offset is not pre-assigned, we need to find a |
| 3164 | * new offset to use. In normal cases, the offset is not |
| 3165 | * pre-assigned, but during HW_RESTART we want to reuse the |
| 3166 | * same indices, so we pass them when this function is called. |
| 3167 | * |
| 3168 | * In D3 entry, we need to hardcoded the indices (because the |
| 3169 | * firmware hardcodes the PTK offset to 0). In this case, we |
| 3170 | * need to make sure we don't overwrite the hw_key_idx in the |
| 3171 | * keyconf structure, because otherwise we cannot configure |
| 3172 | * the original ones back when resuming. |
| 3173 | */ |
| 3174 | if (key_offset == STA_KEY_IDX_INVALID) { |
| 3175 | key_offset = iwl_mvm_set_fw_key_idx(mvm); |
| 3176 | if (key_offset == STA_KEY_IDX_INVALID) |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3177 | return -ENOSPC; |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3178 | keyconf->hw_key_idx = key_offset; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3179 | } |
| 3180 | |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3181 | 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] | 3182 | if (ret) |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3183 | goto end; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3184 | |
| 3185 | /* |
| 3186 | * For WEP, the same key is used for multicast and unicast. Upload it |
| 3187 | * again, using the same key offset, and now pointing the other one |
| 3188 | * to the same key slot (offset). |
| 3189 | * If this fails, remove the original as well. |
| 3190 | */ |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3191 | if ((keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 3192 | keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) && |
| 3193 | sta) { |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3194 | ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, |
| 3195 | key_offset, !mcast); |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3196 | if (ret) { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3197 | __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast); |
Luca Coelho | 9c3deeb | 2015-11-11 01:06:17 +0200 | [diff] [blame] | 3198 | goto end; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3199 | } |
| 3200 | } |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3201 | |
Luca Coelho | 9c3deeb | 2015-11-11 01:06:17 +0200 | [diff] [blame] | 3202 | __set_bit(key_offset, mvm->fw_key_table); |
| 3203 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3204 | end: |
| 3205 | IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n", |
| 3206 | keyconf->cipher, keyconf->keylen, keyconf->keyidx, |
Matti Gottlieb | 11828db | 2015-06-01 15:15:11 +0300 | [diff] [blame] | 3207 | sta ? sta->addr : zero_addr, ret); |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3208 | return ret; |
| 3209 | } |
| 3210 | |
| 3211 | int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, |
| 3212 | struct ieee80211_vif *vif, |
| 3213 | struct ieee80211_sta *sta, |
| 3214 | struct ieee80211_key_conf *keyconf) |
| 3215 | { |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3216 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 3217 | struct iwl_mvm_sta *mvm_sta; |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 3218 | u8 sta_id = IWL_MVM_INVALID_STA; |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 3219 | int ret, i; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3220 | |
| 3221 | lockdep_assert_held(&mvm->mutex); |
| 3222 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 3223 | /* Get the station from the mvm local station table */ |
| 3224 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
Luca Coelho | 71793b7d | 2017-03-30 12:04:47 +0300 | [diff] [blame] | 3225 | if (mvm_sta) |
| 3226 | sta_id = mvm_sta->sta_id; |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3227 | else if (!sta && vif->type == NL80211_IFTYPE_AP && mcast) |
| 3228 | sta_id = iwl_mvm_vif_from_mac80211(vif)->mcast_sta.sta_id; |
| 3229 | |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3230 | |
| 3231 | IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n", |
| 3232 | keyconf->keyidx, sta_id); |
| 3233 | |
Luca Coelho | 71793b7d | 2017-03-30 12:04:47 +0300 | [diff] [blame] | 3234 | if (mvm_sta && (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC || |
| 3235 | keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || |
| 3236 | keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256)) |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3237 | return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true); |
| 3238 | |
| 3239 | if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) { |
| 3240 | IWL_ERR(mvm, "offset %d not used in fw key table.\n", |
| 3241 | keyconf->hw_key_idx); |
| 3242 | return -ENOENT; |
| 3243 | } |
| 3244 | |
Johannes Berg | 2dc2a15 | 2015-06-16 17:09:18 +0200 | [diff] [blame] | 3245 | /* track which key was deleted last */ |
| 3246 | for (i = 0; i < STA_KEY_MAX_NUM; i++) { |
| 3247 | if (mvm->fw_key_deleted[i] < U8_MAX) |
| 3248 | mvm->fw_key_deleted[i]++; |
| 3249 | } |
| 3250 | mvm->fw_key_deleted[keyconf->hw_key_idx] = 0; |
| 3251 | |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3252 | if (sta && !mvm_sta) { |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3253 | IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n"); |
| 3254 | return 0; |
| 3255 | } |
| 3256 | |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3257 | ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast); |
| 3258 | if (ret) |
| 3259 | return ret; |
| 3260 | |
| 3261 | /* delete WEP key twice to get rid of (now useless) offset */ |
| 3262 | if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || |
| 3263 | keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) |
| 3264 | ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast); |
| 3265 | |
| 3266 | return ret; |
Johannes Berg | 2f6319d | 2014-11-12 23:39:56 +0100 | [diff] [blame] | 3267 | } |
| 3268 | |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3269 | void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm, |
| 3270 | struct ieee80211_vif *vif, |
| 3271 | struct ieee80211_key_conf *keyconf, |
| 3272 | struct ieee80211_sta *sta, u32 iv32, |
| 3273 | u16 *phase1key) |
| 3274 | { |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 3275 | struct iwl_mvm_sta *mvm_sta; |
Johannes Berg | ba3943b | 2014-11-12 23:54:48 +0100 | [diff] [blame] | 3276 | bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3277 | |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 3278 | rcu_read_lock(); |
| 3279 | |
Johannes Berg | 5f7a184 | 2015-12-11 09:36:10 +0100 | [diff] [blame] | 3280 | mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); |
| 3281 | if (WARN_ON_ONCE(!mvm_sta)) |
Emmanuel Grumbach | 12f1721 | 2015-12-20 14:48:08 +0200 | [diff] [blame] | 3282 | goto unlock; |
David Spinadel | 85aeb58 | 2017-03-30 19:43:53 +0300 | [diff] [blame] | 3283 | iwl_mvm_send_sta_key(mvm, mvm_sta->sta_id, keyconf, mcast, |
Luca Coelho | d6ee54a | 2015-11-10 22:13:43 +0200 | [diff] [blame] | 3284 | iv32, phase1key, CMD_ASYNC, keyconf->hw_key_idx); |
Emmanuel Grumbach | 12f1721 | 2015-12-20 14:48:08 +0200 | [diff] [blame] | 3285 | |
| 3286 | unlock: |
Beni Lev | c3eb536 | 2013-02-06 17:22:18 +0200 | [diff] [blame] | 3287 | rcu_read_unlock(); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3288 | } |
| 3289 | |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 3290 | void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm, |
| 3291 | struct ieee80211_sta *sta) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3292 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 3293 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 3294 | struct iwl_mvm_add_sta_cmd cmd = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3295 | .add_modify = STA_MODE_MODIFY, |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 3296 | .sta_id = mvmsta->sta_id, |
Emmanuel Grumbach | 5af0177 | 2013-06-09 12:59:24 +0300 | [diff] [blame] | 3297 | .station_flags_msk = cpu_to_le32(STA_FLG_PS), |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 3298 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3299 | }; |
| 3300 | int ret; |
| 3301 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 3302 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, |
| 3303 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3304 | if (ret) |
| 3305 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 3306 | } |
| 3307 | |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 3308 | void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm, |
| 3309 | struct ieee80211_sta *sta, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3310 | enum ieee80211_frame_release_type reason, |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3311 | u16 cnt, u16 tids, bool more_data, |
Sara Sharon | 9a3fcf9 | 2017-03-14 09:50:35 +0200 | [diff] [blame] | 3312 | bool single_sta_queue) |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3313 | { |
Johannes Berg | 5b577a9 | 2013-11-14 18:20:04 +0100 | [diff] [blame] | 3314 | struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); |
Emmanuel Grumbach | f9dc000 | 2014-03-30 09:53:27 +0300 | [diff] [blame] | 3315 | struct iwl_mvm_add_sta_cmd cmd = { |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3316 | .add_modify = STA_MODE_MODIFY, |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 3317 | .sta_id = mvmsta->sta_id, |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3318 | .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT, |
| 3319 | .sleep_tx_count = cpu_to_le16(cnt), |
Johannes Berg | 9cc4071 | 2013-02-15 22:47:48 +0100 | [diff] [blame] | 3320 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3321 | }; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3322 | int tid, ret; |
| 3323 | unsigned long _tids = tids; |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3324 | |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3325 | /* convert TIDs to ACs - we don't support TSPEC so that's OK |
| 3326 | * Note that this field is reserved and unused by firmware not |
| 3327 | * supporting GO uAPSD, so it's safe to always do this. |
| 3328 | */ |
| 3329 | for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) |
| 3330 | cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]); |
| 3331 | |
Sara Sharon | 9a3fcf9 | 2017-03-14 09:50:35 +0200 | [diff] [blame] | 3332 | /* If we're releasing frames from aggregation or dqa queues then check |
| 3333 | * if all the queues that we're releasing frames from, combined, have: |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3334 | * - more frames than the service period, in which case more_data |
| 3335 | * needs to be set |
| 3336 | * - fewer than 'cnt' frames, in which case we need to adjust the |
| 3337 | * firmware command (but do that unconditionally) |
| 3338 | */ |
Sara Sharon | 9a3fcf9 | 2017-03-14 09:50:35 +0200 | [diff] [blame] | 3339 | if (single_sta_queue) { |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3340 | int remaining = cnt; |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 3341 | int sleep_tx_count; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3342 | |
| 3343 | spin_lock_bh(&mvmsta->lock); |
| 3344 | for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) { |
| 3345 | struct iwl_mvm_tid_data *tid_data; |
| 3346 | u16 n_queued; |
| 3347 | |
| 3348 | tid_data = &mvmsta->tid_data[tid]; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3349 | |
Liad Kaufman | dd32162 | 2017-04-05 16:25:11 +0300 | [diff] [blame] | 3350 | n_queued = iwl_mvm_tid_queued(mvm, tid_data); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3351 | if (n_queued > remaining) { |
| 3352 | more_data = true; |
| 3353 | remaining = 0; |
| 3354 | break; |
| 3355 | } |
| 3356 | remaining -= n_queued; |
| 3357 | } |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 3358 | sleep_tx_count = cnt - remaining; |
| 3359 | if (reason == IEEE80211_FRAME_RELEASE_UAPSD) |
| 3360 | mvmsta->sleep_tx_count = sleep_tx_count; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3361 | spin_unlock_bh(&mvmsta->lock); |
| 3362 | |
Emmanuel Grumbach | 36be0eb | 2015-11-05 10:32:31 +0200 | [diff] [blame] | 3363 | cmd.sleep_tx_count = cpu_to_le16(sleep_tx_count); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3364 | if (WARN_ON(cnt - remaining == 0)) { |
| 3365 | ieee80211_sta_eosp(sta); |
| 3366 | return; |
| 3367 | } |
| 3368 | } |
| 3369 | |
| 3370 | /* Note: this is ignored by firmware not supporting GO uAPSD */ |
| 3371 | if (more_data) |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 3372 | cmd.sleep_state_flags |= STA_SLEEP_STATE_MOREDATA; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3373 | |
| 3374 | if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) { |
| 3375 | mvmsta->next_status_eosp = true; |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 3376 | cmd.sleep_state_flags |= STA_SLEEP_STATE_PS_POLL; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3377 | } else { |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 3378 | cmd.sleep_state_flags |= STA_SLEEP_STATE_UAPSD; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3379 | } |
| 3380 | |
Emmanuel Grumbach | 156f92f | 2015-11-24 14:55:18 +0200 | [diff] [blame] | 3381 | /* block the Tx queues until the FW updated the sleep Tx count */ |
| 3382 | iwl_trans_block_txq_ptrs(mvm->trans, true); |
| 3383 | |
| 3384 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, |
| 3385 | CMD_ASYNC | CMD_WANT_ASYNC_CALLBACK, |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 3386 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
Johannes Berg | 8ca151b | 2013-01-24 14:25:36 +0100 | [diff] [blame] | 3387 | if (ret) |
| 3388 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 3389 | } |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3390 | |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 3391 | void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm, |
| 3392 | struct iwl_rx_cmd_buffer *rxb) |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3393 | { |
| 3394 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
| 3395 | struct iwl_mvm_eosp_notification *notif = (void *)pkt->data; |
| 3396 | struct ieee80211_sta *sta; |
| 3397 | u32 sta_id = le32_to_cpu(notif->sta_id); |
| 3398 | |
| 3399 | if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT)) |
Johannes Berg | 0416841 | 2015-06-23 21:22:09 +0200 | [diff] [blame] | 3400 | return; |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3401 | |
| 3402 | rcu_read_lock(); |
| 3403 | sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); |
| 3404 | if (!IS_ERR_OR_NULL(sta)) |
| 3405 | ieee80211_sta_eosp(sta); |
| 3406 | rcu_read_unlock(); |
Johannes Berg | 3e56ead | 2013-02-15 22:23:18 +0100 | [diff] [blame] | 3407 | } |
Andrei Otcheretianski | 09b0ce1 | 2014-05-25 17:07:38 +0300 | [diff] [blame] | 3408 | |
| 3409 | void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm, |
| 3410 | struct iwl_mvm_sta *mvmsta, bool disable) |
| 3411 | { |
| 3412 | struct iwl_mvm_add_sta_cmd cmd = { |
| 3413 | .add_modify = STA_MODE_MODIFY, |
| 3414 | .sta_id = mvmsta->sta_id, |
| 3415 | .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0, |
| 3416 | .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX), |
| 3417 | .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), |
| 3418 | }; |
| 3419 | int ret; |
| 3420 | |
Sara Sharon | 854c570 | 2016-01-26 13:17:47 +0200 | [diff] [blame] | 3421 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, |
| 3422 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
Andrei Otcheretianski | 09b0ce1 | 2014-05-25 17:07:38 +0300 | [diff] [blame] | 3423 | if (ret) |
| 3424 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 3425 | } |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 3426 | |
| 3427 | void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm, |
| 3428 | struct ieee80211_sta *sta, |
| 3429 | bool disable) |
| 3430 | { |
| 3431 | struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
| 3432 | |
| 3433 | spin_lock_bh(&mvm_sta->lock); |
| 3434 | |
| 3435 | if (mvm_sta->disable_tx == disable) { |
| 3436 | spin_unlock_bh(&mvm_sta->lock); |
| 3437 | return; |
| 3438 | } |
| 3439 | |
| 3440 | mvm_sta->disable_tx = disable; |
| 3441 | |
Johannes Berg | c8f5470 | 2017-06-19 23:50:31 +0200 | [diff] [blame] | 3442 | /* Tell mac80211 to start/stop queuing tx for this station */ |
| 3443 | ieee80211_sta_block_awake(mvm->hw, sta, disable); |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 3444 | |
| 3445 | iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable); |
| 3446 | |
| 3447 | spin_unlock_bh(&mvm_sta->lock); |
| 3448 | } |
| 3449 | |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 3450 | static void iwl_mvm_int_sta_modify_disable_tx(struct iwl_mvm *mvm, |
| 3451 | struct iwl_mvm_vif *mvmvif, |
| 3452 | struct iwl_mvm_int_sta *sta, |
| 3453 | bool disable) |
| 3454 | { |
| 3455 | u32 id = FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color); |
| 3456 | struct iwl_mvm_add_sta_cmd cmd = { |
| 3457 | .add_modify = STA_MODE_MODIFY, |
| 3458 | .sta_id = sta->sta_id, |
| 3459 | .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0, |
| 3460 | .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX), |
| 3461 | .mac_id_n_color = cpu_to_le32(id), |
| 3462 | }; |
| 3463 | int ret; |
| 3464 | |
| 3465 | ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, 0, |
| 3466 | iwl_mvm_add_sta_cmd_size(mvm), &cmd); |
| 3467 | if (ret) |
| 3468 | IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); |
| 3469 | } |
| 3470 | |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 3471 | void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm, |
| 3472 | struct iwl_mvm_vif *mvmvif, |
| 3473 | bool disable) |
| 3474 | { |
| 3475 | struct ieee80211_sta *sta; |
| 3476 | struct iwl_mvm_sta *mvm_sta; |
| 3477 | int i; |
| 3478 | |
| 3479 | lockdep_assert_held(&mvm->mutex); |
| 3480 | |
| 3481 | /* Block/unblock all the stations of the given mvmvif */ |
Sara Sharon | 0ae9881 | 2017-01-04 14:53:58 +0200 | [diff] [blame] | 3482 | 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] | 3483 | sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], |
| 3484 | lockdep_is_held(&mvm->mutex)); |
| 3485 | if (IS_ERR_OR_NULL(sta)) |
| 3486 | continue; |
| 3487 | |
| 3488 | mvm_sta = iwl_mvm_sta_from_mac80211(sta); |
| 3489 | if (mvm_sta->mac_id_n_color != |
| 3490 | FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color)) |
| 3491 | continue; |
| 3492 | |
| 3493 | iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable); |
| 3494 | } |
Sara Sharon | ced19f2 | 2017-02-06 19:09:32 +0200 | [diff] [blame] | 3495 | |
| 3496 | if (!fw_has_api(&mvm->fw->ucode_capa, IWL_UCODE_TLV_API_STA_TYPE)) |
| 3497 | return; |
| 3498 | |
| 3499 | /* Need to block/unblock also multicast station */ |
| 3500 | if (mvmvif->mcast_sta.sta_id != IWL_MVM_INVALID_STA) |
| 3501 | iwl_mvm_int_sta_modify_disable_tx(mvm, mvmvif, |
| 3502 | &mvmvif->mcast_sta, disable); |
| 3503 | |
| 3504 | /* |
| 3505 | * Only unblock the broadcast station (FW blocks it for immediate |
| 3506 | * quiet, not the driver) |
| 3507 | */ |
| 3508 | if (!disable && mvmvif->bcast_sta.sta_id != IWL_MVM_INVALID_STA) |
| 3509 | iwl_mvm_int_sta_modify_disable_tx(mvm, mvmvif, |
| 3510 | &mvmvif->bcast_sta, disable); |
Andrei Otcheretianski | 003e5236 | 2014-05-25 17:24:22 +0300 | [diff] [blame] | 3511 | } |
Luciano Coelho | dc88b4b | 2014-11-10 11:10:14 +0200 | [diff] [blame] | 3512 | |
| 3513 | void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif) |
| 3514 | { |
| 3515 | struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); |
| 3516 | struct iwl_mvm_sta *mvmsta; |
| 3517 | |
| 3518 | rcu_read_lock(); |
| 3519 | |
| 3520 | mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id); |
| 3521 | |
| 3522 | if (!WARN_ON(!mvmsta)) |
| 3523 | iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true); |
| 3524 | |
| 3525 | rcu_read_unlock(); |
| 3526 | } |
Liad Kaufman | dd32162 | 2017-04-05 16:25:11 +0300 | [diff] [blame] | 3527 | |
| 3528 | u16 iwl_mvm_tid_queued(struct iwl_mvm *mvm, struct iwl_mvm_tid_data *tid_data) |
| 3529 | { |
| 3530 | u16 sn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); |
| 3531 | |
| 3532 | /* |
| 3533 | * In A000 HW, the next_reclaimed index is only 8 bit, so we'll need |
| 3534 | * to align the wrap around of ssn so we compare relevant values. |
| 3535 | */ |
| 3536 | if (mvm->trans->cfg->gen2) |
| 3537 | sn &= 0xff; |
| 3538 | |
| 3539 | return ieee80211_sn_sub(sn, tid_data->next_reclaimed); |
| 3540 | } |