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