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