1e705c121SKalle Valo /****************************************************************************** 2e705c121SKalle Valo * 3e705c121SKalle Valo * This file is provided under a dual BSD/GPLv2 license. When using or 4e705c121SKalle Valo * redistributing this file, you may do so under either license. 5e705c121SKalle Valo * 6e705c121SKalle Valo * GPL LICENSE SUMMARY 7e705c121SKalle Valo * 8e705c121SKalle Valo * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved. 9e705c121SKalle Valo * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH 10854c5705SSara Sharon * Copyright(c) 2016 Intel Deutschland GmbH 11e705c121SKalle Valo * 12e705c121SKalle Valo * This program is free software; you can redistribute it and/or modify 13e705c121SKalle Valo * it under the terms of version 2 of the GNU General Public License as 14e705c121SKalle Valo * published by the Free Software Foundation. 15e705c121SKalle Valo * 16e705c121SKalle Valo * This program is distributed in the hope that it will be useful, but 17e705c121SKalle Valo * WITHOUT ANY WARRANTY; without even the implied warranty of 18e705c121SKalle Valo * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19e705c121SKalle Valo * General Public License for more details. 20e705c121SKalle Valo * 21e705c121SKalle Valo * You should have received a copy of the GNU General Public License 22e705c121SKalle Valo * along with this program; if not, write to the Free Software 23e705c121SKalle Valo * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, 24e705c121SKalle Valo * USA 25e705c121SKalle Valo * 26e705c121SKalle Valo * The full GNU General Public License is included in this distribution 27e705c121SKalle Valo * in the file called COPYING. 28e705c121SKalle Valo * 29e705c121SKalle Valo * Contact Information: 30cb2f8277SEmmanuel Grumbach * Intel Linux Wireless <linuxwifi@intel.com> 31e705c121SKalle Valo * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 32e705c121SKalle Valo * 33e705c121SKalle Valo * BSD LICENSE 34e705c121SKalle Valo * 35e705c121SKalle Valo * Copyright(c) 2012 - 2015 Intel Corporation. All rights reserved. 36e705c121SKalle Valo * Copyright(c) 2013 - 2015 Intel Mobile Communications GmbH 37854c5705SSara Sharon * Copyright(c) 2016 Intel Deutschland GmbH 38e705c121SKalle Valo * All rights reserved. 39e705c121SKalle Valo * 40e705c121SKalle Valo * Redistribution and use in source and binary forms, with or without 41e705c121SKalle Valo * modification, are permitted provided that the following conditions 42e705c121SKalle Valo * are met: 43e705c121SKalle Valo * 44e705c121SKalle Valo * * Redistributions of source code must retain the above copyright 45e705c121SKalle Valo * notice, this list of conditions and the following disclaimer. 46e705c121SKalle Valo * * Redistributions in binary form must reproduce the above copyright 47e705c121SKalle Valo * notice, this list of conditions and the following disclaimer in 48e705c121SKalle Valo * the documentation and/or other materials provided with the 49e705c121SKalle Valo * distribution. 50e705c121SKalle Valo * * Neither the name Intel Corporation nor the names of its 51e705c121SKalle Valo * contributors may be used to endorse or promote products derived 52e705c121SKalle Valo * from this software without specific prior written permission. 53e705c121SKalle Valo * 54e705c121SKalle Valo * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 55e705c121SKalle Valo * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 56e705c121SKalle Valo * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 57e705c121SKalle Valo * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 58e705c121SKalle Valo * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 59e705c121SKalle Valo * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 60e705c121SKalle Valo * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 61e705c121SKalle Valo * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 62e705c121SKalle Valo * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 63e705c121SKalle Valo * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 64e705c121SKalle Valo * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 65e705c121SKalle Valo * 66e705c121SKalle Valo *****************************************************************************/ 67e705c121SKalle Valo #include <net/mac80211.h> 68e705c121SKalle Valo 69e705c121SKalle Valo #include "mvm.h" 70e705c121SKalle Valo #include "sta.h" 71e705c121SKalle Valo #include "rs.h" 72e705c121SKalle Valo 73854c5705SSara Sharon /* 74854c5705SSara Sharon * New version of ADD_STA_sta command added new fields at the end of the 75854c5705SSara Sharon * structure, so sending the size of the relevant API's structure is enough to 76854c5705SSara Sharon * support both API versions. 77854c5705SSara Sharon */ 78854c5705SSara Sharon static inline int iwl_mvm_add_sta_cmd_size(struct iwl_mvm *mvm) 79854c5705SSara Sharon { 80854c5705SSara Sharon return iwl_mvm_has_new_rx_api(mvm) ? 81854c5705SSara Sharon sizeof(struct iwl_mvm_add_sta_cmd) : 82854c5705SSara Sharon sizeof(struct iwl_mvm_add_sta_cmd_v7); 83854c5705SSara Sharon } 84854c5705SSara Sharon 85e705c121SKalle Valo static int iwl_mvm_find_free_sta_id(struct iwl_mvm *mvm, 86e705c121SKalle Valo enum nl80211_iftype iftype) 87e705c121SKalle Valo { 88e705c121SKalle Valo int sta_id; 89e705c121SKalle Valo u32 reserved_ids = 0; 90e705c121SKalle Valo 91e705c121SKalle Valo BUILD_BUG_ON(IWL_MVM_STATION_COUNT > 32); 92e705c121SKalle Valo WARN_ON_ONCE(test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)); 93e705c121SKalle Valo 94e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 95e705c121SKalle Valo 96e705c121SKalle Valo /* d0i3/d3 assumes the AP's sta_id (of sta vif) is 0. reserve it. */ 97e705c121SKalle Valo if (iftype != NL80211_IFTYPE_STATION) 98e705c121SKalle Valo reserved_ids = BIT(0); 99e705c121SKalle Valo 100e705c121SKalle Valo /* Don't take rcu_read_lock() since we are protected by mvm->mutex */ 101e705c121SKalle Valo for (sta_id = 0; sta_id < IWL_MVM_STATION_COUNT; sta_id++) { 102e705c121SKalle Valo if (BIT(sta_id) & reserved_ids) 103e705c121SKalle Valo continue; 104e705c121SKalle Valo 105e705c121SKalle Valo if (!rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], 106e705c121SKalle Valo lockdep_is_held(&mvm->mutex))) 107e705c121SKalle Valo return sta_id; 108e705c121SKalle Valo } 109e705c121SKalle Valo return IWL_MVM_STATION_COUNT; 110e705c121SKalle Valo } 111e705c121SKalle Valo 112e705c121SKalle Valo /* send station add/update command to firmware */ 113e705c121SKalle Valo int iwl_mvm_sta_send_to_fw(struct iwl_mvm *mvm, struct ieee80211_sta *sta, 11424afba76SLiad Kaufman bool update, unsigned int flags) 115e705c121SKalle Valo { 116e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 117e705c121SKalle Valo struct iwl_mvm_add_sta_cmd add_sta_cmd = { 118e705c121SKalle Valo .sta_id = mvm_sta->sta_id, 119e705c121SKalle Valo .mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color), 120e705c121SKalle Valo .add_modify = update ? 1 : 0, 121e705c121SKalle Valo .station_flags_msk = cpu_to_le32(STA_FLG_FAT_EN_MSK | 122e705c121SKalle Valo STA_FLG_MIMO_EN_MSK), 123cf0cda19SLiad Kaufman .tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg), 124e705c121SKalle Valo }; 125e705c121SKalle Valo int ret; 126e705c121SKalle Valo u32 status; 127e705c121SKalle Valo u32 agg_size = 0, mpdu_dens = 0; 128e705c121SKalle Valo 12924afba76SLiad Kaufman if (!update || (flags & STA_MODIFY_QUEUES)) { 130e705c121SKalle Valo add_sta_cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk); 131e705c121SKalle Valo memcpy(&add_sta_cmd.addr, sta->addr, ETH_ALEN); 13224afba76SLiad Kaufman 13324afba76SLiad Kaufman if (flags & STA_MODIFY_QUEUES) 13424afba76SLiad Kaufman add_sta_cmd.modify_mask |= STA_MODIFY_QUEUES; 135e705c121SKalle Valo } 136e705c121SKalle Valo 137e705c121SKalle Valo switch (sta->bandwidth) { 138e705c121SKalle Valo case IEEE80211_STA_RX_BW_160: 139e705c121SKalle Valo add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_160MHZ); 140e705c121SKalle Valo /* fall through */ 141e705c121SKalle Valo case IEEE80211_STA_RX_BW_80: 142e705c121SKalle Valo add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_80MHZ); 143e705c121SKalle Valo /* fall through */ 144e705c121SKalle Valo case IEEE80211_STA_RX_BW_40: 145e705c121SKalle Valo add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_FAT_EN_40MHZ); 146e705c121SKalle Valo /* fall through */ 147e705c121SKalle Valo case IEEE80211_STA_RX_BW_20: 148e705c121SKalle Valo if (sta->ht_cap.ht_supported) 149e705c121SKalle Valo add_sta_cmd.station_flags |= 150e705c121SKalle Valo cpu_to_le32(STA_FLG_FAT_EN_20MHZ); 151e705c121SKalle Valo break; 152e705c121SKalle Valo } 153e705c121SKalle Valo 154e705c121SKalle Valo switch (sta->rx_nss) { 155e705c121SKalle Valo case 1: 156e705c121SKalle Valo add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO); 157e705c121SKalle Valo break; 158e705c121SKalle Valo case 2: 159e705c121SKalle Valo add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO2); 160e705c121SKalle Valo break; 161e705c121SKalle Valo case 3 ... 8: 162e705c121SKalle Valo add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_MIMO3); 163e705c121SKalle Valo break; 164e705c121SKalle Valo } 165e705c121SKalle Valo 166e705c121SKalle Valo switch (sta->smps_mode) { 167e705c121SKalle Valo case IEEE80211_SMPS_AUTOMATIC: 168e705c121SKalle Valo case IEEE80211_SMPS_NUM_MODES: 169e705c121SKalle Valo WARN_ON(1); 170e705c121SKalle Valo break; 171e705c121SKalle Valo case IEEE80211_SMPS_STATIC: 172e705c121SKalle Valo /* override NSS */ 173e705c121SKalle Valo add_sta_cmd.station_flags &= ~cpu_to_le32(STA_FLG_MIMO_EN_MSK); 174e705c121SKalle Valo add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_MIMO_EN_SISO); 175e705c121SKalle Valo break; 176e705c121SKalle Valo case IEEE80211_SMPS_DYNAMIC: 177e705c121SKalle Valo add_sta_cmd.station_flags |= cpu_to_le32(STA_FLG_RTS_MIMO_PROT); 178e705c121SKalle Valo break; 179e705c121SKalle Valo case IEEE80211_SMPS_OFF: 180e705c121SKalle Valo /* nothing */ 181e705c121SKalle Valo break; 182e705c121SKalle Valo } 183e705c121SKalle Valo 184e705c121SKalle Valo if (sta->ht_cap.ht_supported) { 185e705c121SKalle Valo add_sta_cmd.station_flags_msk |= 186e705c121SKalle Valo cpu_to_le32(STA_FLG_MAX_AGG_SIZE_MSK | 187e705c121SKalle Valo STA_FLG_AGG_MPDU_DENS_MSK); 188e705c121SKalle Valo 189e705c121SKalle Valo mpdu_dens = sta->ht_cap.ampdu_density; 190e705c121SKalle Valo } 191e705c121SKalle Valo 192e705c121SKalle Valo if (sta->vht_cap.vht_supported) { 193e705c121SKalle Valo agg_size = sta->vht_cap.cap & 194e705c121SKalle Valo IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK; 195e705c121SKalle Valo agg_size >>= 196e705c121SKalle Valo IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_SHIFT; 197e705c121SKalle Valo } else if (sta->ht_cap.ht_supported) { 198e705c121SKalle Valo agg_size = sta->ht_cap.ampdu_factor; 199e705c121SKalle Valo } 200e705c121SKalle Valo 201e705c121SKalle Valo add_sta_cmd.station_flags |= 202e705c121SKalle Valo cpu_to_le32(agg_size << STA_FLG_MAX_AGG_SIZE_SHIFT); 203e705c121SKalle Valo add_sta_cmd.station_flags |= 204e705c121SKalle Valo cpu_to_le32(mpdu_dens << STA_FLG_AGG_MPDU_DENS_SHIFT); 20519c52f46SEmmanuel Grumbach add_sta_cmd.assoc_id = cpu_to_le16(sta->aid); 206e705c121SKalle Valo 20765e25482SJohannes Berg if (sta->wme) { 20865e25482SJohannes Berg add_sta_cmd.modify_mask |= STA_MODIFY_UAPSD_ACS; 20965e25482SJohannes Berg 21065e25482SJohannes Berg if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK) 21165e25482SJohannes Berg add_sta_cmd.uapsd_trigger_acs |= BIT(AC_BK); 21265e25482SJohannes Berg if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE) 21365e25482SJohannes Berg add_sta_cmd.uapsd_trigger_acs |= BIT(AC_BE); 21465e25482SJohannes Berg if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI) 21565e25482SJohannes Berg add_sta_cmd.uapsd_trigger_acs |= BIT(AC_VI); 21665e25482SJohannes Berg if (sta->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) 21765e25482SJohannes Berg add_sta_cmd.uapsd_trigger_acs |= BIT(AC_VO); 21865e25482SJohannes Berg } 21965e25482SJohannes Berg 220e705c121SKalle Valo status = ADD_STA_SUCCESS; 221854c5705SSara Sharon ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, 222854c5705SSara Sharon iwl_mvm_add_sta_cmd_size(mvm), 223e705c121SKalle Valo &add_sta_cmd, &status); 224e705c121SKalle Valo if (ret) 225e705c121SKalle Valo return ret; 226e705c121SKalle Valo 227837c4da9SSara Sharon switch (status & IWL_ADD_STA_STATUS_MASK) { 228e705c121SKalle Valo case ADD_STA_SUCCESS: 229e705c121SKalle Valo IWL_DEBUG_ASSOC(mvm, "ADD_STA PASSED\n"); 230e705c121SKalle Valo break; 231e705c121SKalle Valo default: 232e705c121SKalle Valo ret = -EIO; 233e705c121SKalle Valo IWL_ERR(mvm, "ADD_STA failed\n"); 234e705c121SKalle Valo break; 235e705c121SKalle Valo } 236e705c121SKalle Valo 237e705c121SKalle Valo return ret; 238e705c121SKalle Valo } 239e705c121SKalle Valo 24010b2b201SSara Sharon static void iwl_mvm_rx_agg_session_expired(unsigned long data) 24110b2b201SSara Sharon { 24210b2b201SSara Sharon struct iwl_mvm_baid_data __rcu **rcu_ptr = (void *)data; 24310b2b201SSara Sharon struct iwl_mvm_baid_data *ba_data; 24410b2b201SSara Sharon struct ieee80211_sta *sta; 24510b2b201SSara Sharon struct iwl_mvm_sta *mvm_sta; 24610b2b201SSara Sharon unsigned long timeout; 24710b2b201SSara Sharon 24810b2b201SSara Sharon rcu_read_lock(); 24910b2b201SSara Sharon 25010b2b201SSara Sharon ba_data = rcu_dereference(*rcu_ptr); 25110b2b201SSara Sharon 25210b2b201SSara Sharon if (WARN_ON(!ba_data)) 25310b2b201SSara Sharon goto unlock; 25410b2b201SSara Sharon 25510b2b201SSara Sharon if (!ba_data->timeout) 25610b2b201SSara Sharon goto unlock; 25710b2b201SSara Sharon 25810b2b201SSara Sharon timeout = ba_data->last_rx + TU_TO_JIFFIES(ba_data->timeout * 2); 25910b2b201SSara Sharon if (time_is_after_jiffies(timeout)) { 26010b2b201SSara Sharon mod_timer(&ba_data->session_timer, timeout); 26110b2b201SSara Sharon goto unlock; 26210b2b201SSara Sharon } 26310b2b201SSara Sharon 26410b2b201SSara Sharon /* Timer expired */ 26510b2b201SSara Sharon sta = rcu_dereference(ba_data->mvm->fw_id_to_mac_id[ba_data->sta_id]); 26610b2b201SSara Sharon mvm_sta = iwl_mvm_sta_from_mac80211(sta); 26710b2b201SSara Sharon ieee80211_stop_rx_ba_session_offl(mvm_sta->vif, 26810b2b201SSara Sharon sta->addr, ba_data->tid); 26910b2b201SSara Sharon unlock: 27010b2b201SSara Sharon rcu_read_unlock(); 27110b2b201SSara Sharon } 27210b2b201SSara Sharon 273e705c121SKalle Valo static int iwl_mvm_tdls_sta_init(struct iwl_mvm *mvm, 274e705c121SKalle Valo struct ieee80211_sta *sta) 275e705c121SKalle Valo { 276e705c121SKalle Valo unsigned long used_hw_queues; 277e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 278e705c121SKalle Valo unsigned int wdg_timeout = 279e705c121SKalle Valo iwl_mvm_get_wd_timeout(mvm, NULL, true, false); 280e705c121SKalle Valo u32 ac; 281e705c121SKalle Valo 282e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 283e705c121SKalle Valo 284e705c121SKalle Valo used_hw_queues = iwl_mvm_get_used_hw_queues(mvm, NULL); 285e705c121SKalle Valo 286e705c121SKalle Valo /* Find available queues, and allocate them to the ACs */ 287e705c121SKalle Valo for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 288e705c121SKalle Valo u8 queue = find_first_zero_bit(&used_hw_queues, 289e705c121SKalle Valo mvm->first_agg_queue); 290e705c121SKalle Valo 291e705c121SKalle Valo if (queue >= mvm->first_agg_queue) { 292e705c121SKalle Valo IWL_ERR(mvm, "Failed to allocate STA queue\n"); 293e705c121SKalle Valo return -EBUSY; 294e705c121SKalle Valo } 295e705c121SKalle Valo 296e705c121SKalle Valo __set_bit(queue, &used_hw_queues); 297e705c121SKalle Valo mvmsta->hw_queue[ac] = queue; 298e705c121SKalle Valo } 299e705c121SKalle Valo 300e705c121SKalle Valo /* Found a place for all queues - enable them */ 301e705c121SKalle Valo for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) { 302e705c121SKalle Valo iwl_mvm_enable_ac_txq(mvm, mvmsta->hw_queue[ac], 303e705c121SKalle Valo mvmsta->hw_queue[ac], 304e705c121SKalle Valo iwl_mvm_ac_to_tx_fifo[ac], 0, 305e705c121SKalle Valo wdg_timeout); 306e705c121SKalle Valo mvmsta->tfd_queue_msk |= BIT(mvmsta->hw_queue[ac]); 307e705c121SKalle Valo } 308e705c121SKalle Valo 309e705c121SKalle Valo return 0; 310e705c121SKalle Valo } 311e705c121SKalle Valo 312e705c121SKalle Valo static void iwl_mvm_tdls_sta_deinit(struct iwl_mvm *mvm, 313e705c121SKalle Valo struct ieee80211_sta *sta) 314e705c121SKalle Valo { 315e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 316e705c121SKalle Valo unsigned long sta_msk; 317e705c121SKalle Valo int i; 318e705c121SKalle Valo 319e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 320e705c121SKalle Valo 321e705c121SKalle Valo /* disable the TDLS STA-specific queues */ 322e705c121SKalle Valo sta_msk = mvmsta->tfd_queue_msk; 323e705c121SKalle Valo for_each_set_bit(i, &sta_msk, sizeof(sta_msk) * BITS_PER_BYTE) 324e705c121SKalle Valo iwl_mvm_disable_txq(mvm, i, i, IWL_MAX_TID_COUNT, 0); 325e705c121SKalle Valo } 326e705c121SKalle Valo 3279794c64fSLiad Kaufman /* Disable aggregations for a bitmap of TIDs for a given station */ 3289794c64fSLiad Kaufman static int iwl_mvm_invalidate_sta_queue(struct iwl_mvm *mvm, int queue, 3299794c64fSLiad Kaufman unsigned long disable_agg_tids, 3309794c64fSLiad Kaufman bool remove_queue) 3319794c64fSLiad Kaufman { 3329794c64fSLiad Kaufman struct iwl_mvm_add_sta_cmd cmd = {}; 3339794c64fSLiad Kaufman struct ieee80211_sta *sta; 3349794c64fSLiad Kaufman struct iwl_mvm_sta *mvmsta; 3359794c64fSLiad Kaufman u32 status; 3369794c64fSLiad Kaufman u8 sta_id; 3379794c64fSLiad Kaufman int ret; 3389794c64fSLiad Kaufman 3399794c64fSLiad Kaufman spin_lock_bh(&mvm->queue_info_lock); 3409794c64fSLiad Kaufman sta_id = mvm->queue_info[queue].ra_sta_id; 3419794c64fSLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 3429794c64fSLiad Kaufman 3439794c64fSLiad Kaufman rcu_read_lock(); 3449794c64fSLiad Kaufman 3459794c64fSLiad Kaufman sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); 3469794c64fSLiad Kaufman 3479794c64fSLiad Kaufman if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) { 3489794c64fSLiad Kaufman rcu_read_unlock(); 3499794c64fSLiad Kaufman return -EINVAL; 3509794c64fSLiad Kaufman } 3519794c64fSLiad Kaufman 3529794c64fSLiad Kaufman mvmsta = iwl_mvm_sta_from_mac80211(sta); 3539794c64fSLiad Kaufman 3549794c64fSLiad Kaufman mvmsta->tid_disable_agg |= disable_agg_tids; 3559794c64fSLiad Kaufman 3569794c64fSLiad Kaufman cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color); 3579794c64fSLiad Kaufman cmd.sta_id = mvmsta->sta_id; 3589794c64fSLiad Kaufman cmd.add_modify = STA_MODE_MODIFY; 3599794c64fSLiad Kaufman cmd.modify_mask = STA_MODIFY_QUEUES; 3609794c64fSLiad Kaufman if (disable_agg_tids) 3619794c64fSLiad Kaufman cmd.modify_mask |= STA_MODIFY_TID_DISABLE_TX; 3629794c64fSLiad Kaufman if (remove_queue) 3639794c64fSLiad Kaufman cmd.modify_mask |= STA_MODIFY_QUEUE_REMOVAL; 3649794c64fSLiad Kaufman cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk); 3659794c64fSLiad Kaufman cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg); 3669794c64fSLiad Kaufman 3679794c64fSLiad Kaufman rcu_read_unlock(); 3689794c64fSLiad Kaufman 3699794c64fSLiad Kaufman /* Notify FW of queue removal from the STA queues */ 3709794c64fSLiad Kaufman status = ADD_STA_SUCCESS; 3719794c64fSLiad Kaufman ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, 3729794c64fSLiad Kaufman iwl_mvm_add_sta_cmd_size(mvm), 3739794c64fSLiad Kaufman &cmd, &status); 3749794c64fSLiad Kaufman 3759794c64fSLiad Kaufman return ret; 3769794c64fSLiad Kaufman } 3779794c64fSLiad Kaufman 37842db09c1SLiad Kaufman static int iwl_mvm_get_queue_agg_tids(struct iwl_mvm *mvm, int queue) 37942db09c1SLiad Kaufman { 38042db09c1SLiad Kaufman struct ieee80211_sta *sta; 38142db09c1SLiad Kaufman struct iwl_mvm_sta *mvmsta; 38242db09c1SLiad Kaufman unsigned long tid_bitmap; 38342db09c1SLiad Kaufman unsigned long agg_tids = 0; 38442db09c1SLiad Kaufman s8 sta_id; 38542db09c1SLiad Kaufman int tid; 38642db09c1SLiad Kaufman 38742db09c1SLiad Kaufman lockdep_assert_held(&mvm->mutex); 38842db09c1SLiad Kaufman 38942db09c1SLiad Kaufman spin_lock_bh(&mvm->queue_info_lock); 39042db09c1SLiad Kaufman sta_id = mvm->queue_info[queue].ra_sta_id; 39142db09c1SLiad Kaufman tid_bitmap = mvm->queue_info[queue].tid_bitmap; 39242db09c1SLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 39342db09c1SLiad Kaufman 39442db09c1SLiad Kaufman sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], 39542db09c1SLiad Kaufman lockdep_is_held(&mvm->mutex)); 39642db09c1SLiad Kaufman 39742db09c1SLiad Kaufman if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) 39842db09c1SLiad Kaufman return -EINVAL; 39942db09c1SLiad Kaufman 40042db09c1SLiad Kaufman mvmsta = iwl_mvm_sta_from_mac80211(sta); 40142db09c1SLiad Kaufman 40242db09c1SLiad Kaufman spin_lock_bh(&mvmsta->lock); 40342db09c1SLiad Kaufman for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) { 40442db09c1SLiad Kaufman if (mvmsta->tid_data[tid].state == IWL_AGG_ON) 40542db09c1SLiad Kaufman agg_tids |= BIT(tid); 40642db09c1SLiad Kaufman } 40742db09c1SLiad Kaufman spin_unlock_bh(&mvmsta->lock); 40842db09c1SLiad Kaufman 40942db09c1SLiad Kaufman return agg_tids; 41042db09c1SLiad Kaufman } 41142db09c1SLiad Kaufman 4129794c64fSLiad Kaufman /* 4139794c64fSLiad Kaufman * Remove a queue from a station's resources. 4149794c64fSLiad Kaufman * Note that this only marks as free. It DOESN'T delete a BA agreement, and 4159794c64fSLiad Kaufman * doesn't disable the queue 4169794c64fSLiad Kaufman */ 4179794c64fSLiad Kaufman static int iwl_mvm_remove_sta_queue_marking(struct iwl_mvm *mvm, int queue) 4189794c64fSLiad Kaufman { 4199794c64fSLiad Kaufman struct ieee80211_sta *sta; 4209794c64fSLiad Kaufman struct iwl_mvm_sta *mvmsta; 4219794c64fSLiad Kaufman unsigned long tid_bitmap; 4229794c64fSLiad Kaufman unsigned long disable_agg_tids = 0; 4239794c64fSLiad Kaufman u8 sta_id; 4249794c64fSLiad Kaufman int tid; 4259794c64fSLiad Kaufman 4269794c64fSLiad Kaufman lockdep_assert_held(&mvm->mutex); 4279794c64fSLiad Kaufman 4289794c64fSLiad Kaufman spin_lock_bh(&mvm->queue_info_lock); 4299794c64fSLiad Kaufman sta_id = mvm->queue_info[queue].ra_sta_id; 4309794c64fSLiad Kaufman tid_bitmap = mvm->queue_info[queue].tid_bitmap; 4319794c64fSLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 4329794c64fSLiad Kaufman 4339794c64fSLiad Kaufman rcu_read_lock(); 4349794c64fSLiad Kaufman 4359794c64fSLiad Kaufman sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); 4369794c64fSLiad Kaufman 4379794c64fSLiad Kaufman if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) { 4389794c64fSLiad Kaufman rcu_read_unlock(); 4399794c64fSLiad Kaufman return 0; 4409794c64fSLiad Kaufman } 4419794c64fSLiad Kaufman 4429794c64fSLiad Kaufman mvmsta = iwl_mvm_sta_from_mac80211(sta); 4439794c64fSLiad Kaufman 4449794c64fSLiad Kaufman spin_lock_bh(&mvmsta->lock); 44542db09c1SLiad Kaufman /* Unmap MAC queues and TIDs from this queue */ 4469794c64fSLiad Kaufman for_each_set_bit(tid, &tid_bitmap, IWL_MAX_TID_COUNT + 1) { 4479794c64fSLiad Kaufman if (mvmsta->tid_data[tid].state == IWL_AGG_ON) 4489794c64fSLiad Kaufman disable_agg_tids |= BIT(tid); 44942db09c1SLiad Kaufman mvmsta->tid_data[tid].txq_id = IEEE80211_INVAL_HW_QUEUE; 4509794c64fSLiad Kaufman } 4519794c64fSLiad Kaufman 45242db09c1SLiad Kaufman mvmsta->tfd_queue_msk &= ~BIT(queue); /* Don't use this queue anymore */ 4539794c64fSLiad Kaufman spin_unlock_bh(&mvmsta->lock); 4549794c64fSLiad Kaufman 4559794c64fSLiad Kaufman rcu_read_unlock(); 4569794c64fSLiad Kaufman 45742db09c1SLiad Kaufman spin_lock_bh(&mvm->queue_info_lock); 4589794c64fSLiad Kaufman /* Unmap MAC queues and TIDs from this queue */ 4599794c64fSLiad Kaufman mvm->queue_info[queue].hw_queue_to_mac80211 = 0; 4609794c64fSLiad Kaufman mvm->queue_info[queue].hw_queue_refcount = 0; 4619794c64fSLiad Kaufman mvm->queue_info[queue].tid_bitmap = 0; 46242db09c1SLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 4639794c64fSLiad Kaufman 4649794c64fSLiad Kaufman return disable_agg_tids; 4659794c64fSLiad Kaufman } 4669794c64fSLiad Kaufman 46742db09c1SLiad Kaufman static int iwl_mvm_get_shared_queue(struct iwl_mvm *mvm, 46842db09c1SLiad Kaufman unsigned long tfd_queue_mask, u8 ac) 46942db09c1SLiad Kaufman { 47042db09c1SLiad Kaufman int queue = 0; 47142db09c1SLiad Kaufman u8 ac_to_queue[IEEE80211_NUM_ACS]; 47242db09c1SLiad Kaufman int i; 47342db09c1SLiad Kaufman 47442db09c1SLiad Kaufman lockdep_assert_held(&mvm->queue_info_lock); 47542db09c1SLiad Kaufman 47642db09c1SLiad Kaufman memset(&ac_to_queue, IEEE80211_INVAL_HW_QUEUE, sizeof(ac_to_queue)); 47742db09c1SLiad Kaufman 47842db09c1SLiad Kaufman /* See what ACs the existing queues for this STA have */ 47942db09c1SLiad Kaufman for_each_set_bit(i, &tfd_queue_mask, IWL_MVM_DQA_MAX_DATA_QUEUE) { 48042db09c1SLiad Kaufman /* Only DATA queues can be shared */ 48142db09c1SLiad Kaufman if (i < IWL_MVM_DQA_MIN_DATA_QUEUE && 48242db09c1SLiad Kaufman i != IWL_MVM_DQA_BSS_CLIENT_QUEUE) 48342db09c1SLiad Kaufman continue; 48442db09c1SLiad Kaufman 4859f9af3d7SLiad Kaufman /* Don't try and take queues being reconfigured */ 4869f9af3d7SLiad Kaufman if (mvm->queue_info[queue].status == 4879f9af3d7SLiad Kaufman IWL_MVM_QUEUE_RECONFIGURING) 4889f9af3d7SLiad Kaufman continue; 4899f9af3d7SLiad Kaufman 49042db09c1SLiad Kaufman ac_to_queue[mvm->queue_info[i].mac80211_ac] = i; 49142db09c1SLiad Kaufman } 49242db09c1SLiad Kaufman 49342db09c1SLiad Kaufman /* 49442db09c1SLiad Kaufman * The queue to share is chosen only from DATA queues as follows (in 49542db09c1SLiad Kaufman * descending priority): 49642db09c1SLiad Kaufman * 1. An AC_BE queue 49742db09c1SLiad Kaufman * 2. Same AC queue 49842db09c1SLiad Kaufman * 3. Highest AC queue that is lower than new AC 49942db09c1SLiad Kaufman * 4. Any existing AC (there always is at least 1 DATA queue) 50042db09c1SLiad Kaufman */ 50142db09c1SLiad Kaufman 50242db09c1SLiad Kaufman /* Priority 1: An AC_BE queue */ 50342db09c1SLiad Kaufman if (ac_to_queue[IEEE80211_AC_BE] != IEEE80211_INVAL_HW_QUEUE) 50442db09c1SLiad Kaufman queue = ac_to_queue[IEEE80211_AC_BE]; 50542db09c1SLiad Kaufman /* Priority 2: Same AC queue */ 50642db09c1SLiad Kaufman else if (ac_to_queue[ac] != IEEE80211_INVAL_HW_QUEUE) 50742db09c1SLiad Kaufman queue = ac_to_queue[ac]; 50842db09c1SLiad Kaufman /* Priority 3a: If new AC is VO and VI exists - use VI */ 50942db09c1SLiad Kaufman else if (ac == IEEE80211_AC_VO && 51042db09c1SLiad Kaufman ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE) 51142db09c1SLiad Kaufman queue = ac_to_queue[IEEE80211_AC_VI]; 51242db09c1SLiad Kaufman /* Priority 3b: No BE so only AC less than the new one is BK */ 51342db09c1SLiad Kaufman else if (ac_to_queue[IEEE80211_AC_BK] != IEEE80211_INVAL_HW_QUEUE) 51442db09c1SLiad Kaufman queue = ac_to_queue[IEEE80211_AC_BK]; 51542db09c1SLiad Kaufman /* Priority 4a: No BE nor BK - use VI if exists */ 51642db09c1SLiad Kaufman else if (ac_to_queue[IEEE80211_AC_VI] != IEEE80211_INVAL_HW_QUEUE) 51742db09c1SLiad Kaufman queue = ac_to_queue[IEEE80211_AC_VI]; 51842db09c1SLiad Kaufman /* Priority 4b: No BE, BK nor VI - use VO if exists */ 51942db09c1SLiad Kaufman else if (ac_to_queue[IEEE80211_AC_VO] != IEEE80211_INVAL_HW_QUEUE) 52042db09c1SLiad Kaufman queue = ac_to_queue[IEEE80211_AC_VO]; 52142db09c1SLiad Kaufman 52242db09c1SLiad Kaufman /* Make sure queue found (or not) is legal */ 5239f9af3d7SLiad Kaufman if (!iwl_mvm_is_dqa_data_queue(mvm, queue) && 5249f9af3d7SLiad Kaufman !iwl_mvm_is_dqa_mgmt_queue(mvm, queue) && 5259f9af3d7SLiad Kaufman (queue != IWL_MVM_DQA_BSS_CLIENT_QUEUE)) { 52642db09c1SLiad Kaufman IWL_ERR(mvm, "No DATA queues available to share\n"); 5279f9af3d7SLiad Kaufman return -ENOSPC; 5289f9af3d7SLiad Kaufman } 5299f9af3d7SLiad Kaufman 5309f9af3d7SLiad Kaufman /* Make sure the queue isn't in the middle of being reconfigured */ 5319f9af3d7SLiad Kaufman if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_RECONFIGURING) { 5329f9af3d7SLiad Kaufman IWL_ERR(mvm, 5339f9af3d7SLiad Kaufman "TXQ %d is in the middle of re-config - try again\n", 5349f9af3d7SLiad Kaufman queue); 5359f9af3d7SLiad Kaufman return -EBUSY; 53642db09c1SLiad Kaufman } 53742db09c1SLiad Kaufman 53842db09c1SLiad Kaufman return queue; 53942db09c1SLiad Kaufman } 54042db09c1SLiad Kaufman 54158f2cc57SLiad Kaufman /* 5429f9af3d7SLiad Kaufman * If a given queue has a higher AC than the TID stream that is being compared 5439f9af3d7SLiad Kaufman * to, the queue needs to be redirected to the lower AC. This function does that 54458f2cc57SLiad Kaufman * in such a case, otherwise - if no redirection required - it does nothing, 54558f2cc57SLiad Kaufman * unless the %force param is true. 54658f2cc57SLiad Kaufman */ 5479f9af3d7SLiad Kaufman int iwl_mvm_scd_queue_redirect(struct iwl_mvm *mvm, int queue, int tid, 54858f2cc57SLiad Kaufman int ac, int ssn, unsigned int wdg_timeout, 54958f2cc57SLiad Kaufman bool force) 55058f2cc57SLiad Kaufman { 55158f2cc57SLiad Kaufman struct iwl_scd_txq_cfg_cmd cmd = { 55258f2cc57SLiad Kaufman .scd_queue = queue, 553f7c692deSLiad Kaufman .action = SCD_CFG_DISABLE_QUEUE, 55458f2cc57SLiad Kaufman }; 55558f2cc57SLiad Kaufman bool shared_queue; 55658f2cc57SLiad Kaufman unsigned long mq; 55758f2cc57SLiad Kaufman int ret; 55858f2cc57SLiad Kaufman 55958f2cc57SLiad Kaufman /* 56058f2cc57SLiad Kaufman * If the AC is lower than current one - FIFO needs to be redirected to 56158f2cc57SLiad Kaufman * the lowest one of the streams in the queue. Check if this is needed 56258f2cc57SLiad Kaufman * here. 56358f2cc57SLiad Kaufman * Notice that the enum ieee80211_ac_numbers is "flipped", so BK is with 56458f2cc57SLiad Kaufman * value 3 and VO with value 0, so to check if ac X is lower than ac Y 56558f2cc57SLiad Kaufman * we need to check if the numerical value of X is LARGER than of Y. 56658f2cc57SLiad Kaufman */ 56758f2cc57SLiad Kaufman spin_lock_bh(&mvm->queue_info_lock); 56858f2cc57SLiad Kaufman if (ac <= mvm->queue_info[queue].mac80211_ac && !force) { 56958f2cc57SLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 57058f2cc57SLiad Kaufman 57158f2cc57SLiad Kaufman IWL_DEBUG_TX_QUEUES(mvm, 57258f2cc57SLiad Kaufman "No redirection needed on TXQ #%d\n", 57358f2cc57SLiad Kaufman queue); 57458f2cc57SLiad Kaufman return 0; 57558f2cc57SLiad Kaufman } 57658f2cc57SLiad Kaufman 57758f2cc57SLiad Kaufman cmd.sta_id = mvm->queue_info[queue].ra_sta_id; 57858f2cc57SLiad Kaufman cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[mvm->queue_info[queue].mac80211_ac]; 579edbe961cSLiad Kaufman cmd.tid = mvm->queue_info[queue].txq_tid; 58058f2cc57SLiad Kaufman mq = mvm->queue_info[queue].hw_queue_to_mac80211; 58158f2cc57SLiad Kaufman shared_queue = (mvm->queue_info[queue].hw_queue_refcount > 1); 58258f2cc57SLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 58358f2cc57SLiad Kaufman 5849f9af3d7SLiad Kaufman IWL_DEBUG_TX_QUEUES(mvm, "Redirecting TXQ #%d to FIFO #%d\n", 58558f2cc57SLiad Kaufman queue, iwl_mvm_ac_to_tx_fifo[ac]); 58658f2cc57SLiad Kaufman 58758f2cc57SLiad Kaufman /* Stop MAC queues and wait for this queue to empty */ 58858f2cc57SLiad Kaufman iwl_mvm_stop_mac_queues(mvm, mq); 58958f2cc57SLiad Kaufman ret = iwl_trans_wait_tx_queue_empty(mvm->trans, BIT(queue)); 59058f2cc57SLiad Kaufman if (ret) { 59158f2cc57SLiad Kaufman IWL_ERR(mvm, "Error draining queue %d before reconfig\n", 59258f2cc57SLiad Kaufman queue); 59358f2cc57SLiad Kaufman ret = -EIO; 59458f2cc57SLiad Kaufman goto out; 59558f2cc57SLiad Kaufman } 59658f2cc57SLiad Kaufman 59758f2cc57SLiad Kaufman /* Before redirecting the queue we need to de-activate it */ 59858f2cc57SLiad Kaufman iwl_trans_txq_disable(mvm->trans, queue, false); 59958f2cc57SLiad Kaufman ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd); 60058f2cc57SLiad Kaufman if (ret) 60158f2cc57SLiad Kaufman IWL_ERR(mvm, "Failed SCD disable TXQ %d (ret=%d)\n", queue, 60258f2cc57SLiad Kaufman ret); 60358f2cc57SLiad Kaufman 60458f2cc57SLiad Kaufman /* Make sure the SCD wrptr is correctly set before reconfiguring */ 605ca3b9c6bSSara Sharon iwl_trans_txq_enable_cfg(mvm->trans, queue, ssn, NULL, wdg_timeout); 60658f2cc57SLiad Kaufman 607edbe961cSLiad Kaufman /* Update the TID "owner" of the queue */ 608edbe961cSLiad Kaufman spin_lock_bh(&mvm->queue_info_lock); 609edbe961cSLiad Kaufman mvm->queue_info[queue].txq_tid = tid; 610edbe961cSLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 611edbe961cSLiad Kaufman 61258f2cc57SLiad Kaufman /* TODO: Work-around SCD bug when moving back by multiples of 0x40 */ 61358f2cc57SLiad Kaufman 61458f2cc57SLiad Kaufman /* Redirect to lower AC */ 61558f2cc57SLiad Kaufman iwl_mvm_reconfig_scd(mvm, queue, iwl_mvm_ac_to_tx_fifo[ac], 61658f2cc57SLiad Kaufman cmd.sta_id, tid, LINK_QUAL_AGG_FRAME_LIMIT_DEF, 61758f2cc57SLiad Kaufman ssn); 61858f2cc57SLiad Kaufman 61958f2cc57SLiad Kaufman /* Update AC marking of the queue */ 62058f2cc57SLiad Kaufman spin_lock_bh(&mvm->queue_info_lock); 62158f2cc57SLiad Kaufman mvm->queue_info[queue].mac80211_ac = ac; 62258f2cc57SLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 62358f2cc57SLiad Kaufman 62458f2cc57SLiad Kaufman /* 62558f2cc57SLiad Kaufman * Mark queue as shared in transport if shared 62658f2cc57SLiad Kaufman * Note this has to be done after queue enablement because enablement 62758f2cc57SLiad Kaufman * can also set this value, and there is no indication there to shared 62858f2cc57SLiad Kaufman * queues 62958f2cc57SLiad Kaufman */ 63058f2cc57SLiad Kaufman if (shared_queue) 63158f2cc57SLiad Kaufman iwl_trans_txq_set_shared_mode(mvm->trans, queue, true); 63258f2cc57SLiad Kaufman 63358f2cc57SLiad Kaufman out: 63458f2cc57SLiad Kaufman /* Continue using the MAC queues */ 63558f2cc57SLiad Kaufman iwl_mvm_start_mac_queues(mvm, mq); 63658f2cc57SLiad Kaufman 63758f2cc57SLiad Kaufman return ret; 63858f2cc57SLiad Kaufman } 63958f2cc57SLiad Kaufman 64024afba76SLiad Kaufman static int iwl_mvm_sta_alloc_queue(struct iwl_mvm *mvm, 64124afba76SLiad Kaufman struct ieee80211_sta *sta, u8 ac, int tid, 64224afba76SLiad Kaufman struct ieee80211_hdr *hdr) 64324afba76SLiad Kaufman { 64424afba76SLiad Kaufman struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 64524afba76SLiad Kaufman struct iwl_trans_txq_scd_cfg cfg = { 64624afba76SLiad Kaufman .fifo = iwl_mvm_ac_to_tx_fifo[ac], 64724afba76SLiad Kaufman .sta_id = mvmsta->sta_id, 64824afba76SLiad Kaufman .tid = tid, 64924afba76SLiad Kaufman .frame_limit = IWL_FRAME_LIMIT, 65024afba76SLiad Kaufman }; 65124afba76SLiad Kaufman unsigned int wdg_timeout = 65224afba76SLiad Kaufman iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false); 65324afba76SLiad Kaufman u8 mac_queue = mvmsta->vif->hw_queue[ac]; 65424afba76SLiad Kaufman int queue = -1; 6559794c64fSLiad Kaufman bool using_inactive_queue = false; 6569794c64fSLiad Kaufman unsigned long disable_agg_tids = 0; 6579794c64fSLiad Kaufman enum iwl_mvm_agg_state queue_state; 65842db09c1SLiad Kaufman bool shared_queue = false; 65924afba76SLiad Kaufman int ssn; 66042db09c1SLiad Kaufman unsigned long tfd_queue_mask; 661cf961e16SLiad Kaufman int ret; 66224afba76SLiad Kaufman 66324afba76SLiad Kaufman lockdep_assert_held(&mvm->mutex); 66424afba76SLiad Kaufman 66542db09c1SLiad Kaufman spin_lock_bh(&mvmsta->lock); 66642db09c1SLiad Kaufman tfd_queue_mask = mvmsta->tfd_queue_msk; 66742db09c1SLiad Kaufman spin_unlock_bh(&mvmsta->lock); 66842db09c1SLiad Kaufman 669d2515a99SLiad Kaufman spin_lock_bh(&mvm->queue_info_lock); 67024afba76SLiad Kaufman 67124afba76SLiad Kaufman /* 67224afba76SLiad Kaufman * Non-QoS, QoS NDP and MGMT frames should go to a MGMT queue, if one 67324afba76SLiad Kaufman * exists 67424afba76SLiad Kaufman */ 67524afba76SLiad Kaufman if (!ieee80211_is_data_qos(hdr->frame_control) || 67624afba76SLiad Kaufman ieee80211_is_qos_nullfunc(hdr->frame_control)) { 6779794c64fSLiad Kaufman queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id, 6789794c64fSLiad Kaufman IWL_MVM_DQA_MIN_MGMT_QUEUE, 67924afba76SLiad Kaufman IWL_MVM_DQA_MAX_MGMT_QUEUE); 68024afba76SLiad Kaufman if (queue >= IWL_MVM_DQA_MIN_MGMT_QUEUE) 68124afba76SLiad Kaufman IWL_DEBUG_TX_QUEUES(mvm, "Found free MGMT queue #%d\n", 68224afba76SLiad Kaufman queue); 68324afba76SLiad Kaufman 68424afba76SLiad Kaufman /* If no such queue is found, we'll use a DATA queue instead */ 68524afba76SLiad Kaufman } 68624afba76SLiad Kaufman 6879794c64fSLiad Kaufman if ((queue < 0 && mvmsta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) && 6889794c64fSLiad Kaufman (mvm->queue_info[mvmsta->reserved_queue].status == 6899794c64fSLiad Kaufman IWL_MVM_QUEUE_RESERVED || 6909794c64fSLiad Kaufman mvm->queue_info[mvmsta->reserved_queue].status == 6919794c64fSLiad Kaufman IWL_MVM_QUEUE_INACTIVE)) { 69224afba76SLiad Kaufman queue = mvmsta->reserved_queue; 6939794c64fSLiad Kaufman mvm->queue_info[queue].reserved = true; 69424afba76SLiad Kaufman IWL_DEBUG_TX_QUEUES(mvm, "Using reserved queue #%d\n", queue); 69524afba76SLiad Kaufman } 69624afba76SLiad Kaufman 69724afba76SLiad Kaufman if (queue < 0) 6989794c64fSLiad Kaufman queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id, 6999794c64fSLiad Kaufman IWL_MVM_DQA_MIN_DATA_QUEUE, 70024afba76SLiad Kaufman IWL_MVM_DQA_MAX_DATA_QUEUE); 701cf961e16SLiad Kaufman 702cf961e16SLiad Kaufman /* 7039794c64fSLiad Kaufman * Check if this queue is already allocated but inactive. 7049794c64fSLiad Kaufman * In such a case, we'll need to first free this queue before enabling 7059794c64fSLiad Kaufman * it again, so we'll mark it as reserved to make sure no new traffic 7069794c64fSLiad Kaufman * arrives on it 7079794c64fSLiad Kaufman */ 7089794c64fSLiad Kaufman if (queue > 0 && 7099794c64fSLiad Kaufman mvm->queue_info[queue].status == IWL_MVM_QUEUE_INACTIVE) { 7109794c64fSLiad Kaufman mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED; 7119794c64fSLiad Kaufman using_inactive_queue = true; 7129794c64fSLiad Kaufman IWL_DEBUG_TX_QUEUES(mvm, 7139794c64fSLiad Kaufman "Re-assigning TXQ %d: sta_id=%d, tid=%d\n", 7149794c64fSLiad Kaufman queue, mvmsta->sta_id, tid); 7159794c64fSLiad Kaufman } 7169794c64fSLiad Kaufman 71742db09c1SLiad Kaufman /* No free queue - we'll have to share */ 71842db09c1SLiad Kaufman if (queue <= 0) { 71942db09c1SLiad Kaufman queue = iwl_mvm_get_shared_queue(mvm, tfd_queue_mask, ac); 72042db09c1SLiad Kaufman if (queue > 0) { 72142db09c1SLiad Kaufman shared_queue = true; 72242db09c1SLiad Kaufman mvm->queue_info[queue].status = IWL_MVM_QUEUE_SHARED; 72342db09c1SLiad Kaufman } 72442db09c1SLiad Kaufman } 72542db09c1SLiad Kaufman 7269794c64fSLiad Kaufman /* 727cf961e16SLiad Kaufman * Mark TXQ as ready, even though it hasn't been fully configured yet, 728cf961e16SLiad Kaufman * to make sure no one else takes it. 729cf961e16SLiad Kaufman * This will allow avoiding re-acquiring the lock at the end of the 730cf961e16SLiad Kaufman * configuration. On error we'll mark it back as free. 731cf961e16SLiad Kaufman */ 73242db09c1SLiad Kaufman if ((queue > 0) && !shared_queue) 733cf961e16SLiad Kaufman mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY; 73424afba76SLiad Kaufman 735d2515a99SLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 73624afba76SLiad Kaufman 73742db09c1SLiad Kaufman /* This shouldn't happen - out of queues */ 73842db09c1SLiad Kaufman if (WARN_ON(queue <= 0)) { 73942db09c1SLiad Kaufman IWL_ERR(mvm, "No available queues for tid %d on sta_id %d\n", 74042db09c1SLiad Kaufman tid, cfg.sta_id); 7419f9af3d7SLiad Kaufman return queue; 74242db09c1SLiad Kaufman } 74324afba76SLiad Kaufman 74424afba76SLiad Kaufman /* 74524afba76SLiad Kaufman * Actual en/disablement of aggregations is through the ADD_STA HCMD, 74624afba76SLiad Kaufman * but for configuring the SCD to send A-MPDUs we need to mark the queue 74724afba76SLiad Kaufman * as aggregatable. 74824afba76SLiad Kaufman * Mark all DATA queues as allowing to be aggregated at some point 74924afba76SLiad Kaufman */ 750d5216a28SLiad Kaufman cfg.aggregate = (queue >= IWL_MVM_DQA_MIN_DATA_QUEUE || 751d5216a28SLiad Kaufman queue == IWL_MVM_DQA_BSS_CLIENT_QUEUE); 75224afba76SLiad Kaufman 7539794c64fSLiad Kaufman /* 7549794c64fSLiad Kaufman * If this queue was previously inactive (idle) - we need to free it 7559794c64fSLiad Kaufman * first 7569794c64fSLiad Kaufman */ 7579794c64fSLiad Kaufman if (using_inactive_queue) { 7589794c64fSLiad Kaufman struct iwl_scd_txq_cfg_cmd cmd = { 7599794c64fSLiad Kaufman .scd_queue = queue, 760f7c692deSLiad Kaufman .action = SCD_CFG_DISABLE_QUEUE, 7619794c64fSLiad Kaufman }; 762d55092b4SLiad Kaufman u8 txq_curr_ac; 7639794c64fSLiad Kaufman 7649794c64fSLiad Kaufman disable_agg_tids = iwl_mvm_remove_sta_queue_marking(mvm, queue); 7659794c64fSLiad Kaufman 76693f436e2SLiad Kaufman spin_lock_bh(&mvm->queue_info_lock); 767d55092b4SLiad Kaufman txq_curr_ac = mvm->queue_info[queue].mac80211_ac; 76893f436e2SLiad Kaufman cmd.sta_id = mvm->queue_info[queue].ra_sta_id; 769d55092b4SLiad Kaufman cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[txq_curr_ac]; 770edbe961cSLiad Kaufman cmd.tid = mvm->queue_info[queue].txq_tid; 77193f436e2SLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 77293f436e2SLiad Kaufman 7739794c64fSLiad Kaufman /* Disable the queue */ 7748d98ae6eSLiad Kaufman if (disable_agg_tids) 7758d98ae6eSLiad Kaufman iwl_mvm_invalidate_sta_queue(mvm, queue, 7768d98ae6eSLiad Kaufman disable_agg_tids, false); 7779794c64fSLiad Kaufman iwl_trans_txq_disable(mvm->trans, queue, false); 7789794c64fSLiad Kaufman ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), 7799794c64fSLiad Kaufman &cmd); 7809794c64fSLiad Kaufman if (ret) { 7819794c64fSLiad Kaufman IWL_ERR(mvm, 7829794c64fSLiad Kaufman "Failed to free inactive queue %d (ret=%d)\n", 7839794c64fSLiad Kaufman queue, ret); 7849794c64fSLiad Kaufman 7859794c64fSLiad Kaufman /* Re-mark the inactive queue as inactive */ 7869794c64fSLiad Kaufman spin_lock_bh(&mvm->queue_info_lock); 7879794c64fSLiad Kaufman mvm->queue_info[queue].status = IWL_MVM_QUEUE_INACTIVE; 7889794c64fSLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 7899794c64fSLiad Kaufman 7909794c64fSLiad Kaufman return ret; 7919794c64fSLiad Kaufman } 7928d98ae6eSLiad Kaufman 7938d98ae6eSLiad Kaufman /* If TXQ is allocated to another STA, update removal in FW */ 7948d98ae6eSLiad Kaufman if (cmd.sta_id != mvmsta->sta_id) 7958d98ae6eSLiad Kaufman iwl_mvm_invalidate_sta_queue(mvm, queue, 0, true); 7969794c64fSLiad Kaufman } 7979794c64fSLiad Kaufman 79842db09c1SLiad Kaufman IWL_DEBUG_TX_QUEUES(mvm, 79942db09c1SLiad Kaufman "Allocating %squeue #%d to sta %d on tid %d\n", 80042db09c1SLiad Kaufman shared_queue ? "shared " : "", queue, 80142db09c1SLiad Kaufman mvmsta->sta_id, tid); 80242db09c1SLiad Kaufman 80342db09c1SLiad Kaufman if (shared_queue) { 80442db09c1SLiad Kaufman /* Disable any open aggs on this queue */ 80542db09c1SLiad Kaufman disable_agg_tids = iwl_mvm_get_queue_agg_tids(mvm, queue); 80642db09c1SLiad Kaufman 80742db09c1SLiad Kaufman if (disable_agg_tids) { 80842db09c1SLiad Kaufman IWL_DEBUG_TX_QUEUES(mvm, "Disabling aggs on queue %d\n", 80942db09c1SLiad Kaufman queue); 81042db09c1SLiad Kaufman iwl_mvm_invalidate_sta_queue(mvm, queue, 81142db09c1SLiad Kaufman disable_agg_tids, false); 81242db09c1SLiad Kaufman } 81342db09c1SLiad Kaufman } 81424afba76SLiad Kaufman 81524afba76SLiad Kaufman ssn = IEEE80211_SEQ_TO_SN(le16_to_cpu(hdr->seq_ctrl)); 81624afba76SLiad Kaufman iwl_mvm_enable_txq(mvm, queue, mac_queue, ssn, &cfg, 81724afba76SLiad Kaufman wdg_timeout); 81824afba76SLiad Kaufman 81958f2cc57SLiad Kaufman /* 82058f2cc57SLiad Kaufman * Mark queue as shared in transport if shared 82158f2cc57SLiad Kaufman * Note this has to be done after queue enablement because enablement 82258f2cc57SLiad Kaufman * can also set this value, and there is no indication there to shared 82358f2cc57SLiad Kaufman * queues 82458f2cc57SLiad Kaufman */ 82558f2cc57SLiad Kaufman if (shared_queue) 82658f2cc57SLiad Kaufman iwl_trans_txq_set_shared_mode(mvm->trans, queue, true); 82758f2cc57SLiad Kaufman 82824afba76SLiad Kaufman spin_lock_bh(&mvmsta->lock); 82924afba76SLiad Kaufman mvmsta->tid_data[tid].txq_id = queue; 8309794c64fSLiad Kaufman mvmsta->tid_data[tid].is_tid_active = true; 83124afba76SLiad Kaufman mvmsta->tfd_queue_msk |= BIT(queue); 8329794c64fSLiad Kaufman queue_state = mvmsta->tid_data[tid].state; 83324afba76SLiad Kaufman 83424afba76SLiad Kaufman if (mvmsta->reserved_queue == queue) 83524afba76SLiad Kaufman mvmsta->reserved_queue = IEEE80211_INVAL_HW_QUEUE; 83624afba76SLiad Kaufman spin_unlock_bh(&mvmsta->lock); 83724afba76SLiad Kaufman 83842db09c1SLiad Kaufman if (!shared_queue) { 839cf961e16SLiad Kaufman ret = iwl_mvm_sta_send_to_fw(mvm, sta, true, STA_MODIFY_QUEUES); 840cf961e16SLiad Kaufman if (ret) 841cf961e16SLiad Kaufman goto out_err; 842cf961e16SLiad Kaufman 8439794c64fSLiad Kaufman /* If we need to re-enable aggregations... */ 84442db09c1SLiad Kaufman if (queue_state == IWL_AGG_ON) { 8459794c64fSLiad Kaufman ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true); 84642db09c1SLiad Kaufman if (ret) 84742db09c1SLiad Kaufman goto out_err; 84842db09c1SLiad Kaufman } 84958f2cc57SLiad Kaufman } else { 85058f2cc57SLiad Kaufman /* Redirect queue, if needed */ 85158f2cc57SLiad Kaufman ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid, ac, ssn, 85258f2cc57SLiad Kaufman wdg_timeout, false); 85358f2cc57SLiad Kaufman if (ret) 85458f2cc57SLiad Kaufman goto out_err; 85542db09c1SLiad Kaufman } 8569794c64fSLiad Kaufman 85742db09c1SLiad Kaufman return 0; 858cf961e16SLiad Kaufman 859cf961e16SLiad Kaufman out_err: 860cf961e16SLiad Kaufman iwl_mvm_disable_txq(mvm, queue, mac_queue, tid, 0); 861cf961e16SLiad Kaufman 862cf961e16SLiad Kaufman return ret; 86324afba76SLiad Kaufman } 86424afba76SLiad Kaufman 86519aefa45SLiad Kaufman static void iwl_mvm_change_queue_owner(struct iwl_mvm *mvm, int queue) 86619aefa45SLiad Kaufman { 86719aefa45SLiad Kaufman struct iwl_scd_txq_cfg_cmd cmd = { 86819aefa45SLiad Kaufman .scd_queue = queue, 86919aefa45SLiad Kaufman .action = SCD_CFG_UPDATE_QUEUE_TID, 87019aefa45SLiad Kaufman }; 87119aefa45SLiad Kaufman s8 sta_id; 87219aefa45SLiad Kaufman int tid; 87319aefa45SLiad Kaufman unsigned long tid_bitmap; 87419aefa45SLiad Kaufman int ret; 87519aefa45SLiad Kaufman 87619aefa45SLiad Kaufman lockdep_assert_held(&mvm->mutex); 87719aefa45SLiad Kaufman 87819aefa45SLiad Kaufman spin_lock_bh(&mvm->queue_info_lock); 87919aefa45SLiad Kaufman sta_id = mvm->queue_info[queue].ra_sta_id; 88019aefa45SLiad Kaufman tid_bitmap = mvm->queue_info[queue].tid_bitmap; 88119aefa45SLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 88219aefa45SLiad Kaufman 88319aefa45SLiad Kaufman if (WARN(!tid_bitmap, "TXQ %d has no tids assigned to it\n", queue)) 88419aefa45SLiad Kaufman return; 88519aefa45SLiad Kaufman 88619aefa45SLiad Kaufman /* Find any TID for queue */ 88719aefa45SLiad Kaufman tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1); 88819aefa45SLiad Kaufman cmd.tid = tid; 88919aefa45SLiad Kaufman cmd.tx_fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]]; 89019aefa45SLiad Kaufman 89119aefa45SLiad Kaufman ret = iwl_mvm_send_cmd_pdu(mvm, SCD_QUEUE_CFG, 0, sizeof(cmd), &cmd); 892341ca402SLiad Kaufman if (ret) { 89319aefa45SLiad Kaufman IWL_ERR(mvm, "Failed to update owner of TXQ %d (ret=%d)\n", 89419aefa45SLiad Kaufman queue, ret); 895341ca402SLiad Kaufman return; 896341ca402SLiad Kaufman } 897341ca402SLiad Kaufman 898341ca402SLiad Kaufman spin_lock_bh(&mvm->queue_info_lock); 899341ca402SLiad Kaufman mvm->queue_info[queue].txq_tid = tid; 900341ca402SLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 90119aefa45SLiad Kaufman IWL_DEBUG_TX_QUEUES(mvm, "Changed TXQ %d ownership to tid %d\n", 90219aefa45SLiad Kaufman queue, tid); 90319aefa45SLiad Kaufman } 90419aefa45SLiad Kaufman 9059f9af3d7SLiad Kaufman static void iwl_mvm_unshare_queue(struct iwl_mvm *mvm, int queue) 9069f9af3d7SLiad Kaufman { 9079f9af3d7SLiad Kaufman struct ieee80211_sta *sta; 9089f9af3d7SLiad Kaufman struct iwl_mvm_sta *mvmsta; 9099f9af3d7SLiad Kaufman s8 sta_id; 9109f9af3d7SLiad Kaufman int tid = -1; 9119f9af3d7SLiad Kaufman unsigned long tid_bitmap; 9129f9af3d7SLiad Kaufman unsigned int wdg_timeout; 9139f9af3d7SLiad Kaufman int ssn; 9149f9af3d7SLiad Kaufman int ret = true; 9159f9af3d7SLiad Kaufman 9169f9af3d7SLiad Kaufman lockdep_assert_held(&mvm->mutex); 9179f9af3d7SLiad Kaufman 9189f9af3d7SLiad Kaufman spin_lock_bh(&mvm->queue_info_lock); 9199f9af3d7SLiad Kaufman sta_id = mvm->queue_info[queue].ra_sta_id; 9209f9af3d7SLiad Kaufman tid_bitmap = mvm->queue_info[queue].tid_bitmap; 9219f9af3d7SLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 9229f9af3d7SLiad Kaufman 9239f9af3d7SLiad Kaufman /* Find TID for queue, and make sure it is the only one on the queue */ 9249f9af3d7SLiad Kaufman tid = find_first_bit(&tid_bitmap, IWL_MAX_TID_COUNT + 1); 9259f9af3d7SLiad Kaufman if (tid_bitmap != BIT(tid)) { 9269f9af3d7SLiad Kaufman IWL_ERR(mvm, "Failed to unshare q %d, active tids=0x%lx\n", 9279f9af3d7SLiad Kaufman queue, tid_bitmap); 9289f9af3d7SLiad Kaufman return; 9299f9af3d7SLiad Kaufman } 9309f9af3d7SLiad Kaufman 9319f9af3d7SLiad Kaufman IWL_DEBUG_TX_QUEUES(mvm, "Unsharing TXQ %d, keeping tid %d\n", queue, 9329f9af3d7SLiad Kaufman tid); 9339f9af3d7SLiad Kaufman 9349f9af3d7SLiad Kaufman sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], 9359f9af3d7SLiad Kaufman lockdep_is_held(&mvm->mutex)); 9369f9af3d7SLiad Kaufman 9379f9af3d7SLiad Kaufman if (WARN_ON_ONCE(IS_ERR_OR_NULL(sta))) 9389f9af3d7SLiad Kaufman return; 9399f9af3d7SLiad Kaufman 9409f9af3d7SLiad Kaufman mvmsta = iwl_mvm_sta_from_mac80211(sta); 9419f9af3d7SLiad Kaufman wdg_timeout = iwl_mvm_get_wd_timeout(mvm, mvmsta->vif, false, false); 9429f9af3d7SLiad Kaufman 9439f9af3d7SLiad Kaufman ssn = IEEE80211_SEQ_TO_SN(mvmsta->tid_data[tid].seq_number); 9449f9af3d7SLiad Kaufman 9459f9af3d7SLiad Kaufman ret = iwl_mvm_scd_queue_redirect(mvm, queue, tid, 9469f9af3d7SLiad Kaufman tid_to_mac80211_ac[tid], ssn, 9479f9af3d7SLiad Kaufman wdg_timeout, true); 9489f9af3d7SLiad Kaufman if (ret) { 9499f9af3d7SLiad Kaufman IWL_ERR(mvm, "Failed to redirect TXQ %d\n", queue); 9509f9af3d7SLiad Kaufman return; 9519f9af3d7SLiad Kaufman } 9529f9af3d7SLiad Kaufman 9539f9af3d7SLiad Kaufman /* If aggs should be turned back on - do it */ 9549f9af3d7SLiad Kaufman if (mvmsta->tid_data[tid].state == IWL_AGG_ON) { 9559cd70e80SEmmanuel Grumbach struct iwl_mvm_add_sta_cmd cmd = {0}; 9569f9af3d7SLiad Kaufman 9579f9af3d7SLiad Kaufman mvmsta->tid_disable_agg &= ~BIT(tid); 9589f9af3d7SLiad Kaufman 9599f9af3d7SLiad Kaufman cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color); 9609f9af3d7SLiad Kaufman cmd.sta_id = mvmsta->sta_id; 9619f9af3d7SLiad Kaufman cmd.add_modify = STA_MODE_MODIFY; 9629f9af3d7SLiad Kaufman cmd.modify_mask = STA_MODIFY_TID_DISABLE_TX; 9639f9af3d7SLiad Kaufman cmd.tfd_queue_msk = cpu_to_le32(mvmsta->tfd_queue_msk); 9649f9af3d7SLiad Kaufman cmd.tid_disable_tx = cpu_to_le16(mvmsta->tid_disable_agg); 9659f9af3d7SLiad Kaufman 9669f9af3d7SLiad Kaufman ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, 9679f9af3d7SLiad Kaufman iwl_mvm_add_sta_cmd_size(mvm), &cmd); 9689f9af3d7SLiad Kaufman if (!ret) { 9699f9af3d7SLiad Kaufman IWL_DEBUG_TX_QUEUES(mvm, 9709f9af3d7SLiad Kaufman "TXQ #%d is now aggregated again\n", 9719f9af3d7SLiad Kaufman queue); 9729f9af3d7SLiad Kaufman 9739f9af3d7SLiad Kaufman /* Mark queue intenally as aggregating again */ 9749f9af3d7SLiad Kaufman iwl_trans_txq_set_shared_mode(mvm->trans, queue, false); 9759f9af3d7SLiad Kaufman } 9769f9af3d7SLiad Kaufman } 9779f9af3d7SLiad Kaufman 9789f9af3d7SLiad Kaufman spin_lock_bh(&mvm->queue_info_lock); 9799f9af3d7SLiad Kaufman mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY; 9809f9af3d7SLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 9819f9af3d7SLiad Kaufman } 9829f9af3d7SLiad Kaufman 98324afba76SLiad Kaufman static inline u8 iwl_mvm_tid_to_ac_queue(int tid) 98424afba76SLiad Kaufman { 98524afba76SLiad Kaufman if (tid == IWL_MAX_TID_COUNT) 98624afba76SLiad Kaufman return IEEE80211_AC_VO; /* MGMT */ 98724afba76SLiad Kaufman 98824afba76SLiad Kaufman return tid_to_mac80211_ac[tid]; 98924afba76SLiad Kaufman } 99024afba76SLiad Kaufman 99124afba76SLiad Kaufman static void iwl_mvm_tx_deferred_stream(struct iwl_mvm *mvm, 99224afba76SLiad Kaufman struct ieee80211_sta *sta, int tid) 99324afba76SLiad Kaufman { 99424afba76SLiad Kaufman struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 99524afba76SLiad Kaufman struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 99624afba76SLiad Kaufman struct sk_buff *skb; 99724afba76SLiad Kaufman struct ieee80211_hdr *hdr; 99824afba76SLiad Kaufman struct sk_buff_head deferred_tx; 99924afba76SLiad Kaufman u8 mac_queue; 100024afba76SLiad Kaufman bool no_queue = false; /* Marks if there is a problem with the queue */ 100124afba76SLiad Kaufman u8 ac; 100224afba76SLiad Kaufman 100324afba76SLiad Kaufman lockdep_assert_held(&mvm->mutex); 100424afba76SLiad Kaufman 100524afba76SLiad Kaufman skb = skb_peek(&tid_data->deferred_tx_frames); 100624afba76SLiad Kaufman if (!skb) 100724afba76SLiad Kaufman return; 100824afba76SLiad Kaufman hdr = (void *)skb->data; 100924afba76SLiad Kaufman 101024afba76SLiad Kaufman ac = iwl_mvm_tid_to_ac_queue(tid); 101124afba76SLiad Kaufman mac_queue = IEEE80211_SKB_CB(skb)->hw_queue; 101224afba76SLiad Kaufman 101324afba76SLiad Kaufman if (tid_data->txq_id == IEEE80211_INVAL_HW_QUEUE && 101424afba76SLiad Kaufman iwl_mvm_sta_alloc_queue(mvm, sta, ac, tid, hdr)) { 101524afba76SLiad Kaufman IWL_ERR(mvm, 101624afba76SLiad Kaufman "Can't alloc TXQ for sta %d tid %d - dropping frame\n", 101724afba76SLiad Kaufman mvmsta->sta_id, tid); 101824afba76SLiad Kaufman 101924afba76SLiad Kaufman /* 102024afba76SLiad Kaufman * Mark queue as problematic so later the deferred traffic is 102124afba76SLiad Kaufman * freed, as we can do nothing with it 102224afba76SLiad Kaufman */ 102324afba76SLiad Kaufman no_queue = true; 102424afba76SLiad Kaufman } 102524afba76SLiad Kaufman 102624afba76SLiad Kaufman __skb_queue_head_init(&deferred_tx); 102724afba76SLiad Kaufman 1028d2515a99SLiad Kaufman /* Disable bottom-halves when entering TX path */ 1029d2515a99SLiad Kaufman local_bh_disable(); 103024afba76SLiad Kaufman spin_lock(&mvmsta->lock); 103124afba76SLiad Kaufman skb_queue_splice_init(&tid_data->deferred_tx_frames, &deferred_tx); 1032ad5de737SLiad Kaufman mvmsta->deferred_traffic_tid_map &= ~BIT(tid); 103324afba76SLiad Kaufman spin_unlock(&mvmsta->lock); 103424afba76SLiad Kaufman 103524afba76SLiad Kaufman while ((skb = __skb_dequeue(&deferred_tx))) 103624afba76SLiad Kaufman if (no_queue || iwl_mvm_tx_skb(mvm, skb, sta)) 103724afba76SLiad Kaufman ieee80211_free_txskb(mvm->hw, skb); 103824afba76SLiad Kaufman local_bh_enable(); 103924afba76SLiad Kaufman 104024afba76SLiad Kaufman /* Wake queue */ 104124afba76SLiad Kaufman iwl_mvm_start_mac_queues(mvm, BIT(mac_queue)); 104224afba76SLiad Kaufman } 104324afba76SLiad Kaufman 104424afba76SLiad Kaufman void iwl_mvm_add_new_dqa_stream_wk(struct work_struct *wk) 104524afba76SLiad Kaufman { 104624afba76SLiad Kaufman struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, 104724afba76SLiad Kaufman add_stream_wk); 104824afba76SLiad Kaufman struct ieee80211_sta *sta; 104924afba76SLiad Kaufman struct iwl_mvm_sta *mvmsta; 105024afba76SLiad Kaufman unsigned long deferred_tid_traffic; 10519f9af3d7SLiad Kaufman int queue, sta_id, tid; 105224afba76SLiad Kaufman 10539794c64fSLiad Kaufman /* Check inactivity of queues */ 10549794c64fSLiad Kaufman iwl_mvm_inactivity_check(mvm); 10559794c64fSLiad Kaufman 105624afba76SLiad Kaufman mutex_lock(&mvm->mutex); 105724afba76SLiad Kaufman 10589f9af3d7SLiad Kaufman /* Reconfigure queues requiring reconfiguation */ 10599f9af3d7SLiad Kaufman for (queue = 0; queue < IWL_MAX_HW_QUEUES; queue++) { 10609f9af3d7SLiad Kaufman bool reconfig; 106119aefa45SLiad Kaufman bool change_owner; 10629f9af3d7SLiad Kaufman 10639f9af3d7SLiad Kaufman spin_lock_bh(&mvm->queue_info_lock); 10649f9af3d7SLiad Kaufman reconfig = (mvm->queue_info[queue].status == 10659f9af3d7SLiad Kaufman IWL_MVM_QUEUE_RECONFIGURING); 106619aefa45SLiad Kaufman 106719aefa45SLiad Kaufman /* 106819aefa45SLiad Kaufman * We need to take into account a situation in which a TXQ was 106919aefa45SLiad Kaufman * allocated to TID x, and then turned shared by adding TIDs y 107019aefa45SLiad Kaufman * and z. If TID x becomes inactive and is removed from the TXQ, 107119aefa45SLiad Kaufman * ownership must be given to one of the remaining TIDs. 107219aefa45SLiad Kaufman * This is mainly because if TID x continues - a new queue can't 107319aefa45SLiad Kaufman * be allocated for it as long as it is an owner of another TXQ. 107419aefa45SLiad Kaufman */ 107519aefa45SLiad Kaufman change_owner = !(mvm->queue_info[queue].tid_bitmap & 107619aefa45SLiad Kaufman BIT(mvm->queue_info[queue].txq_tid)) && 107719aefa45SLiad Kaufman (mvm->queue_info[queue].status == 107819aefa45SLiad Kaufman IWL_MVM_QUEUE_SHARED); 10799f9af3d7SLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 10809f9af3d7SLiad Kaufman 10819f9af3d7SLiad Kaufman if (reconfig) 10829f9af3d7SLiad Kaufman iwl_mvm_unshare_queue(mvm, queue); 108319aefa45SLiad Kaufman else if (change_owner) 108419aefa45SLiad Kaufman iwl_mvm_change_queue_owner(mvm, queue); 10859f9af3d7SLiad Kaufman } 10869f9af3d7SLiad Kaufman 108724afba76SLiad Kaufman /* Go over all stations with deferred traffic */ 108824afba76SLiad Kaufman for_each_set_bit(sta_id, mvm->sta_deferred_frames, 108924afba76SLiad Kaufman IWL_MVM_STATION_COUNT) { 109024afba76SLiad Kaufman clear_bit(sta_id, mvm->sta_deferred_frames); 109124afba76SLiad Kaufman sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], 109224afba76SLiad Kaufman lockdep_is_held(&mvm->mutex)); 109324afba76SLiad Kaufman if (IS_ERR_OR_NULL(sta)) 109424afba76SLiad Kaufman continue; 109524afba76SLiad Kaufman 109624afba76SLiad Kaufman mvmsta = iwl_mvm_sta_from_mac80211(sta); 109724afba76SLiad Kaufman deferred_tid_traffic = mvmsta->deferred_traffic_tid_map; 109824afba76SLiad Kaufman 109924afba76SLiad Kaufman for_each_set_bit(tid, &deferred_tid_traffic, 110024afba76SLiad Kaufman IWL_MAX_TID_COUNT + 1) 110124afba76SLiad Kaufman iwl_mvm_tx_deferred_stream(mvm, sta, tid); 110224afba76SLiad Kaufman } 110324afba76SLiad Kaufman 110424afba76SLiad Kaufman mutex_unlock(&mvm->mutex); 110524afba76SLiad Kaufman } 110624afba76SLiad Kaufman 110724afba76SLiad Kaufman static int iwl_mvm_reserve_sta_stream(struct iwl_mvm *mvm, 1108d5216a28SLiad Kaufman struct ieee80211_sta *sta, 1109d5216a28SLiad Kaufman enum nl80211_iftype vif_type) 111024afba76SLiad Kaufman { 111124afba76SLiad Kaufman struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 111224afba76SLiad Kaufman int queue; 111324afba76SLiad Kaufman 11149794c64fSLiad Kaufman /* 11159794c64fSLiad Kaufman * Check for inactive queues, so we don't reach a situation where we 11169794c64fSLiad Kaufman * can't add a STA due to a shortage in queues that doesn't really exist 11179794c64fSLiad Kaufman */ 11189794c64fSLiad Kaufman iwl_mvm_inactivity_check(mvm); 11199794c64fSLiad Kaufman 112024afba76SLiad Kaufman spin_lock_bh(&mvm->queue_info_lock); 112124afba76SLiad Kaufman 112224afba76SLiad Kaufman /* Make sure we have free resources for this STA */ 1123d5216a28SLiad Kaufman if (vif_type == NL80211_IFTYPE_STATION && !sta->tdls && 1124d5216a28SLiad Kaufman !mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].hw_queue_refcount && 1125cf961e16SLiad Kaufman (mvm->queue_info[IWL_MVM_DQA_BSS_CLIENT_QUEUE].status == 1126cf961e16SLiad Kaufman IWL_MVM_QUEUE_FREE)) 1127d5216a28SLiad Kaufman queue = IWL_MVM_DQA_BSS_CLIENT_QUEUE; 1128d5216a28SLiad Kaufman else 11299794c64fSLiad Kaufman queue = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id, 11309794c64fSLiad Kaufman IWL_MVM_DQA_MIN_DATA_QUEUE, 113124afba76SLiad Kaufman IWL_MVM_DQA_MAX_DATA_QUEUE); 113224afba76SLiad Kaufman if (queue < 0) { 113324afba76SLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 113424afba76SLiad Kaufman IWL_ERR(mvm, "No available queues for new station\n"); 113524afba76SLiad Kaufman return -ENOSPC; 113624afba76SLiad Kaufman } 1137cf961e16SLiad Kaufman mvm->queue_info[queue].status = IWL_MVM_QUEUE_RESERVED; 113824afba76SLiad Kaufman 113924afba76SLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 114024afba76SLiad Kaufman 114124afba76SLiad Kaufman mvmsta->reserved_queue = queue; 114224afba76SLiad Kaufman 114324afba76SLiad Kaufman IWL_DEBUG_TX_QUEUES(mvm, "Reserving data queue #%d for sta_id %d\n", 114424afba76SLiad Kaufman queue, mvmsta->sta_id); 114524afba76SLiad Kaufman 114624afba76SLiad Kaufman return 0; 114724afba76SLiad Kaufman } 114824afba76SLiad Kaufman 11498d98ae6eSLiad Kaufman /* 11508d98ae6eSLiad Kaufman * In DQA mode, after a HW restart the queues should be allocated as before, in 11518d98ae6eSLiad Kaufman * order to avoid race conditions when there are shared queues. This function 11528d98ae6eSLiad Kaufman * does the re-mapping and queue allocation. 11538d98ae6eSLiad Kaufman * 11548d98ae6eSLiad Kaufman * Note that re-enabling aggregations isn't done in this function. 11558d98ae6eSLiad Kaufman */ 11568d98ae6eSLiad Kaufman static void iwl_mvm_realloc_queues_after_restart(struct iwl_mvm *mvm, 11578d98ae6eSLiad Kaufman struct iwl_mvm_sta *mvm_sta) 11588d98ae6eSLiad Kaufman { 11598d98ae6eSLiad Kaufman unsigned int wdg_timeout = 11608d98ae6eSLiad Kaufman iwl_mvm_get_wd_timeout(mvm, mvm_sta->vif, false, false); 11618d98ae6eSLiad Kaufman int i; 11628d98ae6eSLiad Kaufman struct iwl_trans_txq_scd_cfg cfg = { 11638d98ae6eSLiad Kaufman .sta_id = mvm_sta->sta_id, 11648d98ae6eSLiad Kaufman .frame_limit = IWL_FRAME_LIMIT, 11658d98ae6eSLiad Kaufman }; 11668d98ae6eSLiad Kaufman 11678d98ae6eSLiad Kaufman /* Make sure reserved queue is still marked as such (or allocated) */ 11688d98ae6eSLiad Kaufman mvm->queue_info[mvm_sta->reserved_queue].status = 11698d98ae6eSLiad Kaufman IWL_MVM_QUEUE_RESERVED; 11708d98ae6eSLiad Kaufman 11718d98ae6eSLiad Kaufman for (i = 0; i <= IWL_MAX_TID_COUNT; i++) { 11728d98ae6eSLiad Kaufman struct iwl_mvm_tid_data *tid_data = &mvm_sta->tid_data[i]; 11738d98ae6eSLiad Kaufman int txq_id = tid_data->txq_id; 11748d98ae6eSLiad Kaufman int ac; 11758d98ae6eSLiad Kaufman u8 mac_queue; 11768d98ae6eSLiad Kaufman 11778d98ae6eSLiad Kaufman if (txq_id == IEEE80211_INVAL_HW_QUEUE) 11788d98ae6eSLiad Kaufman continue; 11798d98ae6eSLiad Kaufman 11808d98ae6eSLiad Kaufman skb_queue_head_init(&tid_data->deferred_tx_frames); 11818d98ae6eSLiad Kaufman 11828d98ae6eSLiad Kaufman ac = tid_to_mac80211_ac[i]; 11838d98ae6eSLiad Kaufman mac_queue = mvm_sta->vif->hw_queue[ac]; 11848d98ae6eSLiad Kaufman 11858d98ae6eSLiad Kaufman cfg.tid = i; 11868d98ae6eSLiad Kaufman cfg.fifo = iwl_mvm_ac_to_tx_fifo[ac]; 11878d98ae6eSLiad Kaufman cfg.aggregate = (txq_id >= IWL_MVM_DQA_MIN_DATA_QUEUE || 11888d98ae6eSLiad Kaufman txq_id == IWL_MVM_DQA_BSS_CLIENT_QUEUE); 11898d98ae6eSLiad Kaufman 11908d98ae6eSLiad Kaufman IWL_DEBUG_TX_QUEUES(mvm, 11918d98ae6eSLiad Kaufman "Re-mapping sta %d tid %d to queue %d\n", 11928d98ae6eSLiad Kaufman mvm_sta->sta_id, i, txq_id); 11938d98ae6eSLiad Kaufman 11948d98ae6eSLiad Kaufman iwl_mvm_enable_txq(mvm, txq_id, mac_queue, 11958d98ae6eSLiad Kaufman IEEE80211_SEQ_TO_SN(tid_data->seq_number), 11968d98ae6eSLiad Kaufman &cfg, wdg_timeout); 11978d98ae6eSLiad Kaufman 11988d98ae6eSLiad Kaufman mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_READY; 11998d98ae6eSLiad Kaufman } 12008d98ae6eSLiad Kaufman 12018d98ae6eSLiad Kaufman atomic_set(&mvm->pending_frames[mvm_sta->sta_id], 0); 12028d98ae6eSLiad Kaufman } 12038d98ae6eSLiad Kaufman 1204e705c121SKalle Valo int iwl_mvm_add_sta(struct iwl_mvm *mvm, 1205e705c121SKalle Valo struct ieee80211_vif *vif, 1206e705c121SKalle Valo struct ieee80211_sta *sta) 1207e705c121SKalle Valo { 1208e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1209e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 1210a571f5f6SSara Sharon struct iwl_mvm_rxq_dup_data *dup_data; 1211e705c121SKalle Valo int i, ret, sta_id; 1212e705c121SKalle Valo 1213e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1214e705c121SKalle Valo 1215e705c121SKalle Valo if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) 1216e705c121SKalle Valo sta_id = iwl_mvm_find_free_sta_id(mvm, 1217e705c121SKalle Valo ieee80211_vif_type_p2p(vif)); 1218e705c121SKalle Valo else 1219e705c121SKalle Valo sta_id = mvm_sta->sta_id; 1220e705c121SKalle Valo 1221e705c121SKalle Valo if (sta_id == IWL_MVM_STATION_COUNT) 1222e705c121SKalle Valo return -ENOSPC; 1223e705c121SKalle Valo 1224e705c121SKalle Valo spin_lock_init(&mvm_sta->lock); 1225e705c121SKalle Valo 12268d98ae6eSLiad Kaufman /* In DQA mode, if this is a HW restart, re-alloc existing queues */ 12278d98ae6eSLiad Kaufman if (iwl_mvm_is_dqa_supported(mvm) && 12288d98ae6eSLiad Kaufman test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 12298d98ae6eSLiad Kaufman iwl_mvm_realloc_queues_after_restart(mvm, mvm_sta); 12308d98ae6eSLiad Kaufman goto update_fw; 12318d98ae6eSLiad Kaufman } 12328d98ae6eSLiad Kaufman 1233e705c121SKalle Valo mvm_sta->sta_id = sta_id; 1234e705c121SKalle Valo mvm_sta->mac_id_n_color = FW_CMD_ID_AND_COLOR(mvmvif->id, 1235e705c121SKalle Valo mvmvif->color); 1236e705c121SKalle Valo mvm_sta->vif = vif; 1237e705c121SKalle Valo mvm_sta->max_agg_bufsize = LINK_QUAL_AGG_FRAME_LIMIT_DEF; 1238e705c121SKalle Valo mvm_sta->tx_protection = 0; 1239e705c121SKalle Valo mvm_sta->tt_tx_protection = false; 1240e705c121SKalle Valo 1241e705c121SKalle Valo /* HW restart, don't assume the memory has been zeroed */ 1242e705c121SKalle Valo atomic_set(&mvm->pending_frames[sta_id], 0); 1243e705c121SKalle Valo mvm_sta->tid_disable_agg = 0xffff; /* No aggs at first */ 1244e705c121SKalle Valo mvm_sta->tfd_queue_msk = 0; 1245e705c121SKalle Valo 1246e3118ad7SLiad Kaufman /* 1247e3118ad7SLiad Kaufman * Allocate new queues for a TDLS station, unless we're in DQA mode, 1248e3118ad7SLiad Kaufman * and then they'll be allocated dynamically 1249e3118ad7SLiad Kaufman */ 1250e3118ad7SLiad Kaufman if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls) { 1251e705c121SKalle Valo ret = iwl_mvm_tdls_sta_init(mvm, sta); 1252e705c121SKalle Valo if (ret) 1253e705c121SKalle Valo return ret; 125424afba76SLiad Kaufman } else if (!iwl_mvm_is_dqa_supported(mvm)) { 1255e705c121SKalle Valo for (i = 0; i < IEEE80211_NUM_ACS; i++) 1256e705c121SKalle Valo if (vif->hw_queue[i] != IEEE80211_INVAL_HW_QUEUE) 1257e705c121SKalle Valo mvm_sta->tfd_queue_msk |= BIT(vif->hw_queue[i]); 1258e705c121SKalle Valo } 1259e705c121SKalle Valo 1260e705c121SKalle Valo /* for HW restart - reset everything but the sequence number */ 126124afba76SLiad Kaufman for (i = 0; i <= IWL_MAX_TID_COUNT; i++) { 1262e705c121SKalle Valo u16 seq = mvm_sta->tid_data[i].seq_number; 1263e705c121SKalle Valo memset(&mvm_sta->tid_data[i], 0, sizeof(mvm_sta->tid_data[i])); 1264e705c121SKalle Valo mvm_sta->tid_data[i].seq_number = seq; 126524afba76SLiad Kaufman 126624afba76SLiad Kaufman if (!iwl_mvm_is_dqa_supported(mvm)) 126724afba76SLiad Kaufman continue; 126824afba76SLiad Kaufman 126924afba76SLiad Kaufman /* 127024afba76SLiad Kaufman * Mark all queues for this STA as unallocated and defer TX 127124afba76SLiad Kaufman * frames until the queue is allocated 127224afba76SLiad Kaufman */ 127324afba76SLiad Kaufman mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE; 127424afba76SLiad Kaufman skb_queue_head_init(&mvm_sta->tid_data[i].deferred_tx_frames); 1275e705c121SKalle Valo } 127624afba76SLiad Kaufman mvm_sta->deferred_traffic_tid_map = 0; 1277e705c121SKalle Valo mvm_sta->agg_tids = 0; 1278e705c121SKalle Valo 1279a571f5f6SSara Sharon if (iwl_mvm_has_new_rx_api(mvm) && 1280a571f5f6SSara Sharon !test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 1281a571f5f6SSara Sharon dup_data = kcalloc(mvm->trans->num_rx_queues, 1282a571f5f6SSara Sharon sizeof(*dup_data), 1283a571f5f6SSara Sharon GFP_KERNEL); 1284a571f5f6SSara Sharon if (!dup_data) 1285a571f5f6SSara Sharon return -ENOMEM; 1286a571f5f6SSara Sharon mvm_sta->dup_data = dup_data; 1287a571f5f6SSara Sharon } 1288a571f5f6SSara Sharon 128924afba76SLiad Kaufman if (iwl_mvm_is_dqa_supported(mvm)) { 1290d5216a28SLiad Kaufman ret = iwl_mvm_reserve_sta_stream(mvm, sta, 1291d5216a28SLiad Kaufman ieee80211_vif_type_p2p(vif)); 129224afba76SLiad Kaufman if (ret) 129324afba76SLiad Kaufman goto err; 129424afba76SLiad Kaufman } 129524afba76SLiad Kaufman 12968d98ae6eSLiad Kaufman update_fw: 129724afba76SLiad Kaufman ret = iwl_mvm_sta_send_to_fw(mvm, sta, false, 0); 1298e705c121SKalle Valo if (ret) 1299e705c121SKalle Valo goto err; 1300e705c121SKalle Valo 1301e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_STATION) { 1302e705c121SKalle Valo if (!sta->tdls) { 1303e705c121SKalle Valo WARN_ON(mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT); 1304e705c121SKalle Valo mvmvif->ap_sta_id = sta_id; 1305e705c121SKalle Valo } else { 1306e705c121SKalle Valo WARN_ON(mvmvif->ap_sta_id == IWL_MVM_STATION_COUNT); 1307e705c121SKalle Valo } 1308e705c121SKalle Valo } 1309e705c121SKalle Valo 1310e705c121SKalle Valo rcu_assign_pointer(mvm->fw_id_to_mac_id[sta_id], sta); 1311e705c121SKalle Valo 1312e705c121SKalle Valo return 0; 1313e705c121SKalle Valo 1314e705c121SKalle Valo err: 1315e3118ad7SLiad Kaufman if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls) 1316e705c121SKalle Valo iwl_mvm_tdls_sta_deinit(mvm, sta); 1317e705c121SKalle Valo return ret; 1318e705c121SKalle Valo } 1319e705c121SKalle Valo 1320e705c121SKalle Valo int iwl_mvm_drain_sta(struct iwl_mvm *mvm, struct iwl_mvm_sta *mvmsta, 1321e705c121SKalle Valo bool drain) 1322e705c121SKalle Valo { 1323e705c121SKalle Valo struct iwl_mvm_add_sta_cmd cmd = {}; 1324e705c121SKalle Valo int ret; 1325e705c121SKalle Valo u32 status; 1326e705c121SKalle Valo 1327e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1328e705c121SKalle Valo 1329e705c121SKalle Valo cmd.mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color); 1330e705c121SKalle Valo cmd.sta_id = mvmsta->sta_id; 1331e705c121SKalle Valo cmd.add_modify = STA_MODE_MODIFY; 1332e705c121SKalle Valo cmd.station_flags = drain ? cpu_to_le32(STA_FLG_DRAIN_FLOW) : 0; 1333e705c121SKalle Valo cmd.station_flags_msk = cpu_to_le32(STA_FLG_DRAIN_FLOW); 1334e705c121SKalle Valo 1335e705c121SKalle Valo status = ADD_STA_SUCCESS; 1336854c5705SSara Sharon ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, 1337854c5705SSara Sharon iwl_mvm_add_sta_cmd_size(mvm), 1338e705c121SKalle Valo &cmd, &status); 1339e705c121SKalle Valo if (ret) 1340e705c121SKalle Valo return ret; 1341e705c121SKalle Valo 1342837c4da9SSara Sharon switch (status & IWL_ADD_STA_STATUS_MASK) { 1343e705c121SKalle Valo case ADD_STA_SUCCESS: 1344e705c121SKalle Valo IWL_DEBUG_INFO(mvm, "Frames for staid %d will drained in fw\n", 1345e705c121SKalle Valo mvmsta->sta_id); 1346e705c121SKalle Valo break; 1347e705c121SKalle Valo default: 1348e705c121SKalle Valo ret = -EIO; 1349e705c121SKalle Valo IWL_ERR(mvm, "Couldn't drain frames for staid %d\n", 1350e705c121SKalle Valo mvmsta->sta_id); 1351e705c121SKalle Valo break; 1352e705c121SKalle Valo } 1353e705c121SKalle Valo 1354e705c121SKalle Valo return ret; 1355e705c121SKalle Valo } 1356e705c121SKalle Valo 1357e705c121SKalle Valo /* 1358e705c121SKalle Valo * Remove a station from the FW table. Before sending the command to remove 1359e705c121SKalle Valo * the station validate that the station is indeed known to the driver (sanity 1360e705c121SKalle Valo * only). 1361e705c121SKalle Valo */ 1362e705c121SKalle Valo static int iwl_mvm_rm_sta_common(struct iwl_mvm *mvm, u8 sta_id) 1363e705c121SKalle Valo { 1364e705c121SKalle Valo struct ieee80211_sta *sta; 1365e705c121SKalle Valo struct iwl_mvm_rm_sta_cmd rm_sta_cmd = { 1366e705c121SKalle Valo .sta_id = sta_id, 1367e705c121SKalle Valo }; 1368e705c121SKalle Valo int ret; 1369e705c121SKalle Valo 1370e705c121SKalle Valo sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], 1371e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 1372e705c121SKalle Valo 1373e705c121SKalle Valo /* Note: internal stations are marked as error values */ 1374e705c121SKalle Valo if (!sta) { 1375e705c121SKalle Valo IWL_ERR(mvm, "Invalid station id\n"); 1376e705c121SKalle Valo return -EINVAL; 1377e705c121SKalle Valo } 1378e705c121SKalle Valo 1379e705c121SKalle Valo ret = iwl_mvm_send_cmd_pdu(mvm, REMOVE_STA, 0, 1380e705c121SKalle Valo sizeof(rm_sta_cmd), &rm_sta_cmd); 1381e705c121SKalle Valo if (ret) { 1382e705c121SKalle Valo IWL_ERR(mvm, "Failed to remove station. Id=%d\n", sta_id); 1383e705c121SKalle Valo return ret; 1384e705c121SKalle Valo } 1385e705c121SKalle Valo 1386e705c121SKalle Valo return 0; 1387e705c121SKalle Valo } 1388e705c121SKalle Valo 1389e705c121SKalle Valo void iwl_mvm_sta_drained_wk(struct work_struct *wk) 1390e705c121SKalle Valo { 1391e705c121SKalle Valo struct iwl_mvm *mvm = container_of(wk, struct iwl_mvm, sta_drained_wk); 1392e705c121SKalle Valo u8 sta_id; 1393e705c121SKalle Valo 1394e705c121SKalle Valo /* 1395e705c121SKalle Valo * The mutex is needed because of the SYNC cmd, but not only: if the 1396e705c121SKalle Valo * work would run concurrently with iwl_mvm_rm_sta, it would run before 1397e705c121SKalle Valo * iwl_mvm_rm_sta sets the station as busy, and exit. Then 1398e705c121SKalle Valo * iwl_mvm_rm_sta would set the station as busy, and nobody will clean 1399e705c121SKalle Valo * that later. 1400e705c121SKalle Valo */ 1401e705c121SKalle Valo mutex_lock(&mvm->mutex); 1402e705c121SKalle Valo 1403e705c121SKalle Valo for_each_set_bit(sta_id, mvm->sta_drained, IWL_MVM_STATION_COUNT) { 1404e705c121SKalle Valo int ret; 1405e705c121SKalle Valo struct ieee80211_sta *sta = 1406e705c121SKalle Valo rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], 1407e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 1408e705c121SKalle Valo 1409e705c121SKalle Valo /* 1410e705c121SKalle Valo * This station is in use or RCU-removed; the latter happens in 1411e705c121SKalle Valo * managed mode, where mac80211 removes the station before we 1412e705c121SKalle Valo * can remove it from firmware (we can only do that after the 1413e705c121SKalle Valo * MAC is marked unassociated), and possibly while the deauth 1414e705c121SKalle Valo * frame to disconnect from the AP is still queued. Then, the 1415e705c121SKalle Valo * station pointer is -ENOENT when the last skb is reclaimed. 1416e705c121SKalle Valo */ 1417e705c121SKalle Valo if (!IS_ERR(sta) || PTR_ERR(sta) == -ENOENT) 1418e705c121SKalle Valo continue; 1419e705c121SKalle Valo 1420e705c121SKalle Valo if (PTR_ERR(sta) == -EINVAL) { 1421e705c121SKalle Valo IWL_ERR(mvm, "Drained sta %d, but it is internal?\n", 1422e705c121SKalle Valo sta_id); 1423e705c121SKalle Valo continue; 1424e705c121SKalle Valo } 1425e705c121SKalle Valo 1426e705c121SKalle Valo if (!sta) { 1427e705c121SKalle Valo IWL_ERR(mvm, "Drained sta %d, but it was NULL?\n", 1428e705c121SKalle Valo sta_id); 1429e705c121SKalle Valo continue; 1430e705c121SKalle Valo } 1431e705c121SKalle Valo 1432e705c121SKalle Valo WARN_ON(PTR_ERR(sta) != -EBUSY); 1433e705c121SKalle Valo /* This station was removed and we waited until it got drained, 1434e705c121SKalle Valo * we can now proceed and remove it. 1435e705c121SKalle Valo */ 1436e705c121SKalle Valo ret = iwl_mvm_rm_sta_common(mvm, sta_id); 1437e705c121SKalle Valo if (ret) { 1438e705c121SKalle Valo IWL_ERR(mvm, 1439e705c121SKalle Valo "Couldn't remove sta %d after it was drained\n", 1440e705c121SKalle Valo sta_id); 1441e705c121SKalle Valo continue; 1442e705c121SKalle Valo } 1443e705c121SKalle Valo RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL); 1444e705c121SKalle Valo clear_bit(sta_id, mvm->sta_drained); 1445e705c121SKalle Valo 1446e705c121SKalle Valo if (mvm->tfd_drained[sta_id]) { 1447e705c121SKalle Valo unsigned long i, msk = mvm->tfd_drained[sta_id]; 1448e705c121SKalle Valo 1449e705c121SKalle Valo for_each_set_bit(i, &msk, sizeof(msk) * BITS_PER_BYTE) 1450e705c121SKalle Valo iwl_mvm_disable_txq(mvm, i, i, 1451e705c121SKalle Valo IWL_MAX_TID_COUNT, 0); 1452e705c121SKalle Valo 1453e705c121SKalle Valo mvm->tfd_drained[sta_id] = 0; 1454e705c121SKalle Valo IWL_DEBUG_TDLS(mvm, "Drained sta %d, with queues %ld\n", 1455e705c121SKalle Valo sta_id, msk); 1456e705c121SKalle Valo } 1457e705c121SKalle Valo } 1458e705c121SKalle Valo 1459e705c121SKalle Valo mutex_unlock(&mvm->mutex); 1460e705c121SKalle Valo } 1461e705c121SKalle Valo 146224afba76SLiad Kaufman static void iwl_mvm_disable_sta_queues(struct iwl_mvm *mvm, 146324afba76SLiad Kaufman struct ieee80211_vif *vif, 146424afba76SLiad Kaufman struct iwl_mvm_sta *mvm_sta) 146524afba76SLiad Kaufman { 146624afba76SLiad Kaufman int ac; 146724afba76SLiad Kaufman int i; 146824afba76SLiad Kaufman 146924afba76SLiad Kaufman lockdep_assert_held(&mvm->mutex); 147024afba76SLiad Kaufman 147124afba76SLiad Kaufman for (i = 0; i < ARRAY_SIZE(mvm_sta->tid_data); i++) { 147224afba76SLiad Kaufman if (mvm_sta->tid_data[i].txq_id == IEEE80211_INVAL_HW_QUEUE) 147324afba76SLiad Kaufman continue; 147424afba76SLiad Kaufman 147524afba76SLiad Kaufman ac = iwl_mvm_tid_to_ac_queue(i); 147624afba76SLiad Kaufman iwl_mvm_disable_txq(mvm, mvm_sta->tid_data[i].txq_id, 147724afba76SLiad Kaufman vif->hw_queue[ac], i, 0); 147824afba76SLiad Kaufman mvm_sta->tid_data[i].txq_id = IEEE80211_INVAL_HW_QUEUE; 147924afba76SLiad Kaufman } 148024afba76SLiad Kaufman } 148124afba76SLiad Kaufman 1482e705c121SKalle Valo int iwl_mvm_rm_sta(struct iwl_mvm *mvm, 1483e705c121SKalle Valo struct ieee80211_vif *vif, 1484e705c121SKalle Valo struct ieee80211_sta *sta) 1485e705c121SKalle Valo { 1486e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1487e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 1488e705c121SKalle Valo int ret; 1489e705c121SKalle Valo 1490e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1491e705c121SKalle Valo 1492a571f5f6SSara Sharon if (iwl_mvm_has_new_rx_api(mvm)) 1493a571f5f6SSara Sharon kfree(mvm_sta->dup_data); 1494a571f5f6SSara Sharon 1495a6f035a0SLiad Kaufman if ((vif->type == NL80211_IFTYPE_STATION && 1496a6f035a0SLiad Kaufman mvmvif->ap_sta_id == mvm_sta->sta_id) || 1497a6f035a0SLiad Kaufman iwl_mvm_is_dqa_supported(mvm)){ 1498e705c121SKalle Valo ret = iwl_mvm_drain_sta(mvm, mvm_sta, true); 1499e705c121SKalle Valo if (ret) 1500e705c121SKalle Valo return ret; 1501e705c121SKalle Valo /* flush its queues here since we are freeing mvm_sta */ 1502e705c121SKalle Valo ret = iwl_mvm_flush_tx_path(mvm, mvm_sta->tfd_queue_msk, 0); 1503e705c121SKalle Valo if (ret) 1504e705c121SKalle Valo return ret; 1505e705c121SKalle Valo ret = iwl_trans_wait_tx_queue_empty(mvm->trans, 1506e705c121SKalle Valo mvm_sta->tfd_queue_msk); 1507e705c121SKalle Valo if (ret) 1508e705c121SKalle Valo return ret; 1509e705c121SKalle Valo ret = iwl_mvm_drain_sta(mvm, mvm_sta, false); 1510e705c121SKalle Valo 151124afba76SLiad Kaufman /* If DQA is supported - the queues can be disabled now */ 151256214749SLiad Kaufman if (iwl_mvm_is_dqa_supported(mvm)) 151356214749SLiad Kaufman iwl_mvm_disable_sta_queues(mvm, vif, mvm_sta); 151456214749SLiad Kaufman 151556214749SLiad Kaufman /* If there is a TXQ still marked as reserved - free it */ 151656214749SLiad Kaufman if (iwl_mvm_is_dqa_supported(mvm) && 151756214749SLiad Kaufman mvm_sta->reserved_queue != IEEE80211_INVAL_HW_QUEUE) { 1518a0315deaSLiad Kaufman u8 reserved_txq = mvm_sta->reserved_queue; 1519a0315deaSLiad Kaufman enum iwl_mvm_queue_status *status; 1520a0315deaSLiad Kaufman 1521a0315deaSLiad Kaufman /* 1522a0315deaSLiad Kaufman * If no traffic has gone through the reserved TXQ - it 1523a0315deaSLiad Kaufman * is still marked as IWL_MVM_QUEUE_RESERVED, and 1524a0315deaSLiad Kaufman * should be manually marked as free again 1525a0315deaSLiad Kaufman */ 1526a0315deaSLiad Kaufman spin_lock_bh(&mvm->queue_info_lock); 1527a0315deaSLiad Kaufman status = &mvm->queue_info[reserved_txq].status; 1528a0315deaSLiad Kaufman if (WARN((*status != IWL_MVM_QUEUE_RESERVED) && 1529a0315deaSLiad Kaufman (*status != IWL_MVM_QUEUE_FREE), 1530a0315deaSLiad Kaufman "sta_id %d reserved txq %d status %d", 1531a0315deaSLiad Kaufman mvm_sta->sta_id, reserved_txq, *status)) { 1532a0315deaSLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 1533a0315deaSLiad Kaufman return -EINVAL; 1534a0315deaSLiad Kaufman } 1535a0315deaSLiad Kaufman 1536a0315deaSLiad Kaufman *status = IWL_MVM_QUEUE_FREE; 1537a0315deaSLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 1538a0315deaSLiad Kaufman } 1539a0315deaSLiad Kaufman 1540e3118ad7SLiad Kaufman if (vif->type == NL80211_IFTYPE_STATION && 1541e3118ad7SLiad Kaufman mvmvif->ap_sta_id == mvm_sta->sta_id) { 1542e3118ad7SLiad Kaufman /* if associated - we can't remove the AP STA now */ 1543e705c121SKalle Valo if (vif->bss_conf.assoc) 1544e705c121SKalle Valo return ret; 1545e705c121SKalle Valo 1546e705c121SKalle Valo /* unassoc - go ahead - remove the AP STA now */ 1547e705c121SKalle Valo mvmvif->ap_sta_id = IWL_MVM_STATION_COUNT; 1548e705c121SKalle Valo 1549e705c121SKalle Valo /* clear d0i3_ap_sta_id if no longer relevant */ 1550e705c121SKalle Valo if (mvm->d0i3_ap_sta_id == mvm_sta->sta_id) 1551e705c121SKalle Valo mvm->d0i3_ap_sta_id = IWL_MVM_STATION_COUNT; 1552e705c121SKalle Valo } 1553e3118ad7SLiad Kaufman } 1554e705c121SKalle Valo 1555e705c121SKalle Valo /* 1556e705c121SKalle Valo * This shouldn't happen - the TDLS channel switch should be canceled 1557e705c121SKalle Valo * before the STA is removed. 1558e705c121SKalle Valo */ 1559e705c121SKalle Valo if (WARN_ON_ONCE(mvm->tdls_cs.peer.sta_id == mvm_sta->sta_id)) { 1560e705c121SKalle Valo mvm->tdls_cs.peer.sta_id = IWL_MVM_STATION_COUNT; 1561e705c121SKalle Valo cancel_delayed_work(&mvm->tdls_cs.dwork); 1562e705c121SKalle Valo } 1563e705c121SKalle Valo 1564e705c121SKalle Valo /* 1565e705c121SKalle Valo * Make sure that the tx response code sees the station as -EBUSY and 1566e705c121SKalle Valo * calls the drain worker. 1567e705c121SKalle Valo */ 1568e705c121SKalle Valo spin_lock_bh(&mvm_sta->lock); 1569e705c121SKalle Valo /* 1570e705c121SKalle Valo * There are frames pending on the AC queues for this station. 1571e705c121SKalle Valo * We need to wait until all the frames are drained... 1572e705c121SKalle Valo */ 1573e705c121SKalle Valo if (atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) { 1574e705c121SKalle Valo rcu_assign_pointer(mvm->fw_id_to_mac_id[mvm_sta->sta_id], 1575e705c121SKalle Valo ERR_PTR(-EBUSY)); 1576e705c121SKalle Valo spin_unlock_bh(&mvm_sta->lock); 1577e705c121SKalle Valo 1578e705c121SKalle Valo /* disable TDLS sta queues on drain complete */ 1579e705c121SKalle Valo if (sta->tdls) { 1580e705c121SKalle Valo mvm->tfd_drained[mvm_sta->sta_id] = 1581e705c121SKalle Valo mvm_sta->tfd_queue_msk; 1582e705c121SKalle Valo IWL_DEBUG_TDLS(mvm, "Draining TDLS sta %d\n", 1583e705c121SKalle Valo mvm_sta->sta_id); 1584e705c121SKalle Valo } 1585e705c121SKalle Valo 1586e705c121SKalle Valo ret = iwl_mvm_drain_sta(mvm, mvm_sta, true); 1587e705c121SKalle Valo } else { 1588e705c121SKalle Valo spin_unlock_bh(&mvm_sta->lock); 1589e705c121SKalle Valo 1590e3118ad7SLiad Kaufman if (!iwl_mvm_is_dqa_supported(mvm) && sta->tdls) 1591e705c121SKalle Valo iwl_mvm_tdls_sta_deinit(mvm, sta); 1592e705c121SKalle Valo 1593e705c121SKalle Valo ret = iwl_mvm_rm_sta_common(mvm, mvm_sta->sta_id); 1594e705c121SKalle Valo RCU_INIT_POINTER(mvm->fw_id_to_mac_id[mvm_sta->sta_id], NULL); 1595e705c121SKalle Valo } 1596e705c121SKalle Valo 1597e705c121SKalle Valo return ret; 1598e705c121SKalle Valo } 1599e705c121SKalle Valo 1600e705c121SKalle Valo int iwl_mvm_rm_sta_id(struct iwl_mvm *mvm, 1601e705c121SKalle Valo struct ieee80211_vif *vif, 1602e705c121SKalle Valo u8 sta_id) 1603e705c121SKalle Valo { 1604e705c121SKalle Valo int ret = iwl_mvm_rm_sta_common(mvm, sta_id); 1605e705c121SKalle Valo 1606e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1607e705c121SKalle Valo 1608e705c121SKalle Valo RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta_id], NULL); 1609e705c121SKalle Valo return ret; 1610e705c121SKalle Valo } 1611e705c121SKalle Valo 16120e39eb03SChaya Rachel Ivgi int iwl_mvm_allocate_int_sta(struct iwl_mvm *mvm, 1613e705c121SKalle Valo struct iwl_mvm_int_sta *sta, 1614e705c121SKalle Valo u32 qmask, enum nl80211_iftype iftype) 1615e705c121SKalle Valo { 1616e705c121SKalle Valo if (!test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 1617e705c121SKalle Valo sta->sta_id = iwl_mvm_find_free_sta_id(mvm, iftype); 1618e705c121SKalle Valo if (WARN_ON_ONCE(sta->sta_id == IWL_MVM_STATION_COUNT)) 1619e705c121SKalle Valo return -ENOSPC; 1620e705c121SKalle Valo } 1621e705c121SKalle Valo 1622e705c121SKalle Valo sta->tfd_queue_msk = qmask; 1623e705c121SKalle Valo 1624e705c121SKalle Valo /* put a non-NULL value so iterating over the stations won't stop */ 1625e705c121SKalle Valo rcu_assign_pointer(mvm->fw_id_to_mac_id[sta->sta_id], ERR_PTR(-EINVAL)); 1626e705c121SKalle Valo return 0; 1627e705c121SKalle Valo } 1628e705c121SKalle Valo 1629e705c121SKalle Valo static void iwl_mvm_dealloc_int_sta(struct iwl_mvm *mvm, 1630e705c121SKalle Valo struct iwl_mvm_int_sta *sta) 1631e705c121SKalle Valo { 1632e705c121SKalle Valo RCU_INIT_POINTER(mvm->fw_id_to_mac_id[sta->sta_id], NULL); 1633e705c121SKalle Valo memset(sta, 0, sizeof(struct iwl_mvm_int_sta)); 1634e705c121SKalle Valo sta->sta_id = IWL_MVM_STATION_COUNT; 1635e705c121SKalle Valo } 1636e705c121SKalle Valo 1637e705c121SKalle Valo static int iwl_mvm_add_int_sta_common(struct iwl_mvm *mvm, 1638e705c121SKalle Valo struct iwl_mvm_int_sta *sta, 1639e705c121SKalle Valo const u8 *addr, 1640e705c121SKalle Valo u16 mac_id, u16 color) 1641e705c121SKalle Valo { 1642e705c121SKalle Valo struct iwl_mvm_add_sta_cmd cmd; 1643e705c121SKalle Valo int ret; 1644e705c121SKalle Valo u32 status; 1645e705c121SKalle Valo 1646e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1647e705c121SKalle Valo 1648e705c121SKalle Valo memset(&cmd, 0, sizeof(cmd)); 1649e705c121SKalle Valo cmd.sta_id = sta->sta_id; 1650e705c121SKalle Valo cmd.mac_id_n_color = cpu_to_le32(FW_CMD_ID_AND_COLOR(mac_id, 1651e705c121SKalle Valo color)); 1652e705c121SKalle Valo 1653e705c121SKalle Valo cmd.tfd_queue_msk = cpu_to_le32(sta->tfd_queue_msk); 1654cf0cda19SLiad Kaufman cmd.tid_disable_tx = cpu_to_le16(0xffff); 1655e705c121SKalle Valo 1656e705c121SKalle Valo if (addr) 1657e705c121SKalle Valo memcpy(cmd.addr, addr, ETH_ALEN); 1658e705c121SKalle Valo 1659854c5705SSara Sharon ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, 1660854c5705SSara Sharon iwl_mvm_add_sta_cmd_size(mvm), 1661e705c121SKalle Valo &cmd, &status); 1662e705c121SKalle Valo if (ret) 1663e705c121SKalle Valo return ret; 1664e705c121SKalle Valo 1665837c4da9SSara Sharon switch (status & IWL_ADD_STA_STATUS_MASK) { 1666e705c121SKalle Valo case ADD_STA_SUCCESS: 1667e705c121SKalle Valo IWL_DEBUG_INFO(mvm, "Internal station added.\n"); 1668e705c121SKalle Valo return 0; 1669e705c121SKalle Valo default: 1670e705c121SKalle Valo ret = -EIO; 1671e705c121SKalle Valo IWL_ERR(mvm, "Add internal station failed, status=0x%x\n", 1672e705c121SKalle Valo status); 1673e705c121SKalle Valo break; 1674e705c121SKalle Valo } 1675e705c121SKalle Valo return ret; 1676e705c121SKalle Valo } 1677e705c121SKalle Valo 1678e705c121SKalle Valo int iwl_mvm_add_aux_sta(struct iwl_mvm *mvm) 1679e705c121SKalle Valo { 1680e705c121SKalle Valo unsigned int wdg_timeout = iwlmvm_mod_params.tfd_q_hang_detect ? 1681e705c121SKalle Valo mvm->cfg->base_params->wd_timeout : 1682e705c121SKalle Valo IWL_WATCHDOG_DISABLED; 1683e705c121SKalle Valo int ret; 1684e705c121SKalle Valo 1685e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1686e705c121SKalle Valo 1687e705c121SKalle Valo /* Map Aux queue to fifo - needs to happen before adding Aux station */ 168828d0793eSLiad Kaufman if (!iwl_mvm_is_dqa_supported(mvm)) 1689e705c121SKalle Valo iwl_mvm_enable_ac_txq(mvm, mvm->aux_queue, mvm->aux_queue, 1690e705c121SKalle Valo IWL_MVM_TX_FIFO_MCAST, 0, wdg_timeout); 1691e705c121SKalle Valo 1692e705c121SKalle Valo /* Allocate aux station and assign to it the aux queue */ 1693e705c121SKalle Valo ret = iwl_mvm_allocate_int_sta(mvm, &mvm->aux_sta, BIT(mvm->aux_queue), 1694e705c121SKalle Valo NL80211_IFTYPE_UNSPECIFIED); 1695e705c121SKalle Valo if (ret) 1696e705c121SKalle Valo return ret; 1697e705c121SKalle Valo 169828d0793eSLiad Kaufman if (iwl_mvm_is_dqa_supported(mvm)) { 169928d0793eSLiad Kaufman struct iwl_trans_txq_scd_cfg cfg = { 170028d0793eSLiad Kaufman .fifo = IWL_MVM_TX_FIFO_MCAST, 170128d0793eSLiad Kaufman .sta_id = mvm->aux_sta.sta_id, 170228d0793eSLiad Kaufman .tid = IWL_MAX_TID_COUNT, 170328d0793eSLiad Kaufman .aggregate = false, 170428d0793eSLiad Kaufman .frame_limit = IWL_FRAME_LIMIT, 170528d0793eSLiad Kaufman }; 170628d0793eSLiad Kaufman 170728d0793eSLiad Kaufman iwl_mvm_enable_txq(mvm, mvm->aux_queue, mvm->aux_queue, 0, &cfg, 170828d0793eSLiad Kaufman wdg_timeout); 170928d0793eSLiad Kaufman } 171028d0793eSLiad Kaufman 1711e705c121SKalle Valo ret = iwl_mvm_add_int_sta_common(mvm, &mvm->aux_sta, NULL, 1712e705c121SKalle Valo MAC_INDEX_AUX, 0); 1713e705c121SKalle Valo 1714e705c121SKalle Valo if (ret) 1715e705c121SKalle Valo iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); 1716e705c121SKalle Valo return ret; 1717e705c121SKalle Valo } 1718e705c121SKalle Valo 17190e39eb03SChaya Rachel Ivgi int iwl_mvm_add_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 17200e39eb03SChaya Rachel Ivgi { 17210e39eb03SChaya Rachel Ivgi struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 17220e39eb03SChaya Rachel Ivgi 17230e39eb03SChaya Rachel Ivgi lockdep_assert_held(&mvm->mutex); 17240e39eb03SChaya Rachel Ivgi return iwl_mvm_add_int_sta_common(mvm, &mvm->snif_sta, vif->addr, 17250e39eb03SChaya Rachel Ivgi mvmvif->id, 0); 17260e39eb03SChaya Rachel Ivgi } 17270e39eb03SChaya Rachel Ivgi 17280e39eb03SChaya Rachel Ivgi int iwl_mvm_rm_snif_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 17290e39eb03SChaya Rachel Ivgi { 17300e39eb03SChaya Rachel Ivgi int ret; 17310e39eb03SChaya Rachel Ivgi 17320e39eb03SChaya Rachel Ivgi lockdep_assert_held(&mvm->mutex); 17330e39eb03SChaya Rachel Ivgi 17340e39eb03SChaya Rachel Ivgi ret = iwl_mvm_rm_sta_common(mvm, mvm->snif_sta.sta_id); 17350e39eb03SChaya Rachel Ivgi if (ret) 17360e39eb03SChaya Rachel Ivgi IWL_WARN(mvm, "Failed sending remove station\n"); 17370e39eb03SChaya Rachel Ivgi 17380e39eb03SChaya Rachel Ivgi return ret; 17390e39eb03SChaya Rachel Ivgi } 17400e39eb03SChaya Rachel Ivgi 17410e39eb03SChaya Rachel Ivgi void iwl_mvm_dealloc_snif_sta(struct iwl_mvm *mvm) 17420e39eb03SChaya Rachel Ivgi { 17430e39eb03SChaya Rachel Ivgi iwl_mvm_dealloc_int_sta(mvm, &mvm->snif_sta); 17440e39eb03SChaya Rachel Ivgi } 17450e39eb03SChaya Rachel Ivgi 1746e705c121SKalle Valo void iwl_mvm_del_aux_sta(struct iwl_mvm *mvm) 1747e705c121SKalle Valo { 1748e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1749e705c121SKalle Valo 1750e705c121SKalle Valo iwl_mvm_dealloc_int_sta(mvm, &mvm->aux_sta); 1751e705c121SKalle Valo } 1752e705c121SKalle Valo 1753e705c121SKalle Valo /* 1754e705c121SKalle Valo * Send the add station command for the vif's broadcast station. 1755e705c121SKalle Valo * Assumes that the station was already allocated. 1756e705c121SKalle Valo * 1757e705c121SKalle Valo * @mvm: the mvm component 1758e705c121SKalle Valo * @vif: the interface to which the broadcast station is added 1759e705c121SKalle Valo * @bsta: the broadcast station to add. 1760e705c121SKalle Valo */ 1761e705c121SKalle Valo int iwl_mvm_send_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 1762e705c121SKalle Valo { 1763e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1764e705c121SKalle Valo struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta; 1765e705c121SKalle Valo static const u8 _baddr[] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; 1766e705c121SKalle Valo const u8 *baddr = _baddr; 1767e705c121SKalle Valo 1768e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1769e705c121SKalle Valo 1770de24f638SLiad Kaufman if (iwl_mvm_is_dqa_supported(mvm)) { 1771de24f638SLiad Kaufman struct iwl_trans_txq_scd_cfg cfg = { 1772de24f638SLiad Kaufman .fifo = IWL_MVM_TX_FIFO_VO, 1773de24f638SLiad Kaufman .sta_id = mvmvif->bcast_sta.sta_id, 1774de24f638SLiad Kaufman .tid = IWL_MAX_TID_COUNT, 1775de24f638SLiad Kaufman .aggregate = false, 1776de24f638SLiad Kaufman .frame_limit = IWL_FRAME_LIMIT, 1777de24f638SLiad Kaufman }; 1778de24f638SLiad Kaufman unsigned int wdg_timeout = 1779de24f638SLiad Kaufman iwl_mvm_get_wd_timeout(mvm, vif, false, false); 1780de24f638SLiad Kaufman int queue; 1781de24f638SLiad Kaufman 1782de24f638SLiad Kaufman if ((vif->type == NL80211_IFTYPE_AP) && 1783de24f638SLiad Kaufman (mvmvif->bcast_sta.tfd_queue_msk & 1784de24f638SLiad Kaufman BIT(IWL_MVM_DQA_AP_PROBE_RESP_QUEUE))) 1785de24f638SLiad Kaufman queue = IWL_MVM_DQA_AP_PROBE_RESP_QUEUE; 17864c965139SLiad Kaufman else if ((vif->type == NL80211_IFTYPE_P2P_DEVICE) && 17874c965139SLiad Kaufman (mvmvif->bcast_sta.tfd_queue_msk & 17884c965139SLiad Kaufman BIT(IWL_MVM_DQA_P2P_DEVICE_QUEUE))) 17894c965139SLiad Kaufman queue = IWL_MVM_DQA_P2P_DEVICE_QUEUE; 1790de24f638SLiad Kaufman else if (WARN(1, "Missed required TXQ for adding bcast STA\n")) 1791de24f638SLiad Kaufman return -EINVAL; 1792de24f638SLiad Kaufman 1793de24f638SLiad Kaufman iwl_mvm_enable_txq(mvm, queue, vif->hw_queue[0], 0, &cfg, 1794de24f638SLiad Kaufman wdg_timeout); 1795de24f638SLiad Kaufman } 1796de24f638SLiad Kaufman 1797e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_ADHOC) 1798e705c121SKalle Valo baddr = vif->bss_conf.bssid; 1799e705c121SKalle Valo 1800e705c121SKalle Valo if (WARN_ON_ONCE(bsta->sta_id == IWL_MVM_STATION_COUNT)) 1801e705c121SKalle Valo return -ENOSPC; 1802e705c121SKalle Valo 1803e705c121SKalle Valo return iwl_mvm_add_int_sta_common(mvm, bsta, baddr, 1804e705c121SKalle Valo mvmvif->id, mvmvif->color); 1805e705c121SKalle Valo } 1806e705c121SKalle Valo 1807e705c121SKalle Valo /* Send the FW a request to remove the station from it's internal data 1808e705c121SKalle Valo * structures, but DO NOT remove the entry from the local data structures. */ 1809e705c121SKalle Valo int iwl_mvm_send_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 1810e705c121SKalle Valo { 1811e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1812e705c121SKalle Valo int ret; 1813e705c121SKalle Valo 1814e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1815e705c121SKalle Valo 1816e705c121SKalle Valo ret = iwl_mvm_rm_sta_common(mvm, mvmvif->bcast_sta.sta_id); 1817e705c121SKalle Valo if (ret) 1818e705c121SKalle Valo IWL_WARN(mvm, "Failed sending remove station\n"); 1819e705c121SKalle Valo return ret; 1820e705c121SKalle Valo } 1821e705c121SKalle Valo 1822e705c121SKalle Valo int iwl_mvm_alloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 1823e705c121SKalle Valo { 1824e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1825de24f638SLiad Kaufman u32 qmask = 0; 1826e705c121SKalle Valo 1827e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1828e705c121SKalle Valo 1829de24f638SLiad Kaufman if (!iwl_mvm_is_dqa_supported(mvm)) 1830e705c121SKalle Valo qmask = iwl_mvm_mac_get_queues_mask(vif); 1831e705c121SKalle Valo 1832de24f638SLiad Kaufman if (vif->type == NL80211_IFTYPE_AP) { 1833e705c121SKalle Valo /* 1834e705c121SKalle Valo * The firmware defines the TFD queue mask to only be relevant 1835e705c121SKalle Valo * for *unicast* queues, so the multicast (CAB) queue shouldn't 1836e705c121SKalle Valo * be included. 1837e705c121SKalle Valo */ 1838e705c121SKalle Valo qmask &= ~BIT(vif->cab_queue); 1839e705c121SKalle Valo 1840de24f638SLiad Kaufman if (iwl_mvm_is_dqa_supported(mvm)) 1841de24f638SLiad Kaufman qmask |= BIT(IWL_MVM_DQA_AP_PROBE_RESP_QUEUE); 18424c965139SLiad Kaufman } else if (iwl_mvm_is_dqa_supported(mvm) && 18434c965139SLiad Kaufman vif->type == NL80211_IFTYPE_P2P_DEVICE) { 18444c965139SLiad Kaufman qmask |= BIT(IWL_MVM_DQA_P2P_DEVICE_QUEUE); 1845de24f638SLiad Kaufman } 1846de24f638SLiad Kaufman 1847e705c121SKalle Valo return iwl_mvm_allocate_int_sta(mvm, &mvmvif->bcast_sta, qmask, 1848e705c121SKalle Valo ieee80211_vif_type_p2p(vif)); 1849e705c121SKalle Valo } 1850e705c121SKalle Valo 1851e705c121SKalle Valo /* Allocate a new station entry for the broadcast station to the given vif, 1852e705c121SKalle Valo * and send it to the FW. 1853e705c121SKalle Valo * Note that each P2P mac should have its own broadcast station. 1854e705c121SKalle Valo * 1855e705c121SKalle Valo * @mvm: the mvm component 1856e705c121SKalle Valo * @vif: the interface to which the broadcast station is added 1857e705c121SKalle Valo * @bsta: the broadcast station to add. */ 1858e705c121SKalle Valo int iwl_mvm_add_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 1859e705c121SKalle Valo { 1860e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1861e705c121SKalle Valo struct iwl_mvm_int_sta *bsta = &mvmvif->bcast_sta; 1862e705c121SKalle Valo int ret; 1863e705c121SKalle Valo 1864e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1865e705c121SKalle Valo 1866e705c121SKalle Valo ret = iwl_mvm_alloc_bcast_sta(mvm, vif); 1867e705c121SKalle Valo if (ret) 1868e705c121SKalle Valo return ret; 1869e705c121SKalle Valo 1870e705c121SKalle Valo ret = iwl_mvm_send_add_bcast_sta(mvm, vif); 1871e705c121SKalle Valo 1872e705c121SKalle Valo if (ret) 1873e705c121SKalle Valo iwl_mvm_dealloc_int_sta(mvm, bsta); 1874e705c121SKalle Valo 1875e705c121SKalle Valo return ret; 1876e705c121SKalle Valo } 1877e705c121SKalle Valo 1878e705c121SKalle Valo void iwl_mvm_dealloc_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 1879e705c121SKalle Valo { 1880e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 1881e705c121SKalle Valo 1882e705c121SKalle Valo iwl_mvm_dealloc_int_sta(mvm, &mvmvif->bcast_sta); 1883e705c121SKalle Valo } 1884e705c121SKalle Valo 1885e705c121SKalle Valo /* 1886e705c121SKalle Valo * Send the FW a request to remove the station from it's internal data 1887e705c121SKalle Valo * structures, and in addition remove it from the local data structure. 1888e705c121SKalle Valo */ 1889e705c121SKalle Valo int iwl_mvm_rm_bcast_sta(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 1890e705c121SKalle Valo { 1891e705c121SKalle Valo int ret; 1892e705c121SKalle Valo 1893e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1894e705c121SKalle Valo 1895e705c121SKalle Valo ret = iwl_mvm_send_rm_bcast_sta(mvm, vif); 1896e705c121SKalle Valo 1897e705c121SKalle Valo iwl_mvm_dealloc_bcast_sta(mvm, vif); 1898e705c121SKalle Valo 1899e705c121SKalle Valo return ret; 1900e705c121SKalle Valo } 1901e705c121SKalle Valo 1902e705c121SKalle Valo #define IWL_MAX_RX_BA_SESSIONS 16 1903e705c121SKalle Valo 1904b915c101SSara Sharon static void iwl_mvm_sync_rxq_del_ba(struct iwl_mvm *mvm, u8 baid) 190510b2b201SSara Sharon { 1906b915c101SSara Sharon struct iwl_mvm_delba_notif notif = { 1907b915c101SSara Sharon .metadata.type = IWL_MVM_RXQ_NOTIF_DEL_BA, 1908b915c101SSara Sharon .metadata.sync = 1, 1909b915c101SSara Sharon .delba.baid = baid, 1910b915c101SSara Sharon }; 1911b915c101SSara Sharon iwl_mvm_sync_rx_queues_internal(mvm, (void *)¬if, sizeof(notif)); 191210b2b201SSara Sharon }; 191310b2b201SSara Sharon 1914b915c101SSara Sharon static void iwl_mvm_free_reorder(struct iwl_mvm *mvm, 1915b915c101SSara Sharon struct iwl_mvm_baid_data *data) 1916b915c101SSara Sharon { 1917b915c101SSara Sharon int i; 1918b915c101SSara Sharon 1919b915c101SSara Sharon iwl_mvm_sync_rxq_del_ba(mvm, data->baid); 1920b915c101SSara Sharon 1921b915c101SSara Sharon for (i = 0; i < mvm->trans->num_rx_queues; i++) { 1922b915c101SSara Sharon int j; 1923b915c101SSara Sharon struct iwl_mvm_reorder_buffer *reorder_buf = 1924b915c101SSara Sharon &data->reorder_buf[i]; 1925b915c101SSara Sharon 19260690405fSSara Sharon spin_lock_bh(&reorder_buf->lock); 19270690405fSSara Sharon if (likely(!reorder_buf->num_stored)) { 19280690405fSSara Sharon spin_unlock_bh(&reorder_buf->lock); 1929b915c101SSara Sharon continue; 19300690405fSSara Sharon } 1931b915c101SSara Sharon 1932b915c101SSara Sharon /* 1933b915c101SSara Sharon * This shouldn't happen in regular DELBA since the internal 1934b915c101SSara Sharon * delBA notification should trigger a release of all frames in 1935b915c101SSara Sharon * the reorder buffer. 1936b915c101SSara Sharon */ 1937b915c101SSara Sharon WARN_ON(1); 1938b915c101SSara Sharon 1939b915c101SSara Sharon for (j = 0; j < reorder_buf->buf_size; j++) 1940b915c101SSara Sharon __skb_queue_purge(&reorder_buf->entries[j]); 19410690405fSSara Sharon /* 19420690405fSSara Sharon * Prevent timer re-arm. This prevents a very far fetched case 19430690405fSSara Sharon * where we timed out on the notification. There may be prior 19440690405fSSara Sharon * RX frames pending in the RX queue before the notification 19450690405fSSara Sharon * that might get processed between now and the actual deletion 19460690405fSSara Sharon * and we would re-arm the timer although we are deleting the 19470690405fSSara Sharon * reorder buffer. 19480690405fSSara Sharon */ 19490690405fSSara Sharon reorder_buf->removed = true; 19500690405fSSara Sharon spin_unlock_bh(&reorder_buf->lock); 19510690405fSSara Sharon del_timer_sync(&reorder_buf->reorder_timer); 1952b915c101SSara Sharon } 1953b915c101SSara Sharon } 1954b915c101SSara Sharon 1955b915c101SSara Sharon static void iwl_mvm_init_reorder_buffer(struct iwl_mvm *mvm, 1956b915c101SSara Sharon u32 sta_id, 1957b915c101SSara Sharon struct iwl_mvm_baid_data *data, 1958b915c101SSara Sharon u16 ssn, u8 buf_size) 1959b915c101SSara Sharon { 1960b915c101SSara Sharon int i; 1961b915c101SSara Sharon 1962b915c101SSara Sharon for (i = 0; i < mvm->trans->num_rx_queues; i++) { 1963b915c101SSara Sharon struct iwl_mvm_reorder_buffer *reorder_buf = 1964b915c101SSara Sharon &data->reorder_buf[i]; 1965b915c101SSara Sharon int j; 1966b915c101SSara Sharon 1967b915c101SSara Sharon reorder_buf->num_stored = 0; 1968b915c101SSara Sharon reorder_buf->head_sn = ssn; 1969b915c101SSara Sharon reorder_buf->buf_size = buf_size; 19700690405fSSara Sharon /* rx reorder timer */ 19710690405fSSara Sharon reorder_buf->reorder_timer.function = 19720690405fSSara Sharon iwl_mvm_reorder_timer_expired; 19730690405fSSara Sharon reorder_buf->reorder_timer.data = (unsigned long)reorder_buf; 19740690405fSSara Sharon init_timer(&reorder_buf->reorder_timer); 19750690405fSSara Sharon spin_lock_init(&reorder_buf->lock); 19760690405fSSara Sharon reorder_buf->mvm = mvm; 1977b915c101SSara Sharon reorder_buf->queue = i; 1978b915c101SSara Sharon reorder_buf->sta_id = sta_id; 1979b915c101SSara Sharon for (j = 0; j < reorder_buf->buf_size; j++) 1980b915c101SSara Sharon __skb_queue_head_init(&reorder_buf->entries[j]); 1981b915c101SSara Sharon } 198210b2b201SSara Sharon } 198310b2b201SSara Sharon 1984e705c121SKalle Valo int iwl_mvm_sta_rx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, 198510b2b201SSara Sharon int tid, u16 ssn, bool start, u8 buf_size, u16 timeout) 1986e705c121SKalle Valo { 1987e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 1988e705c121SKalle Valo struct iwl_mvm_add_sta_cmd cmd = {}; 198910b2b201SSara Sharon struct iwl_mvm_baid_data *baid_data = NULL; 1990e705c121SKalle Valo int ret; 1991e705c121SKalle Valo u32 status; 1992e705c121SKalle Valo 1993e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 1994e705c121SKalle Valo 1995e705c121SKalle Valo if (start && mvm->rx_ba_sessions >= IWL_MAX_RX_BA_SESSIONS) { 1996e705c121SKalle Valo IWL_WARN(mvm, "Not enough RX BA SESSIONS\n"); 1997e705c121SKalle Valo return -ENOSPC; 1998e705c121SKalle Valo } 1999e705c121SKalle Valo 200010b2b201SSara Sharon if (iwl_mvm_has_new_rx_api(mvm) && start) { 200110b2b201SSara Sharon /* 200210b2b201SSara Sharon * Allocate here so if allocation fails we can bail out early 200310b2b201SSara Sharon * before starting the BA session in the firmware 200410b2b201SSara Sharon */ 2005b915c101SSara Sharon baid_data = kzalloc(sizeof(*baid_data) + 2006b915c101SSara Sharon mvm->trans->num_rx_queues * 2007b915c101SSara Sharon sizeof(baid_data->reorder_buf[0]), 2008b915c101SSara Sharon GFP_KERNEL); 200910b2b201SSara Sharon if (!baid_data) 201010b2b201SSara Sharon return -ENOMEM; 201110b2b201SSara Sharon } 201210b2b201SSara Sharon 2013e705c121SKalle Valo cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); 2014e705c121SKalle Valo cmd.sta_id = mvm_sta->sta_id; 2015e705c121SKalle Valo cmd.add_modify = STA_MODE_MODIFY; 2016e705c121SKalle Valo if (start) { 2017e705c121SKalle Valo cmd.add_immediate_ba_tid = (u8) tid; 2018e705c121SKalle Valo cmd.add_immediate_ba_ssn = cpu_to_le16(ssn); 2019854c5705SSara Sharon cmd.rx_ba_window = cpu_to_le16((u16)buf_size); 2020e705c121SKalle Valo } else { 2021e705c121SKalle Valo cmd.remove_immediate_ba_tid = (u8) tid; 2022e705c121SKalle Valo } 2023e705c121SKalle Valo cmd.modify_mask = start ? STA_MODIFY_ADD_BA_TID : 2024e705c121SKalle Valo STA_MODIFY_REMOVE_BA_TID; 2025e705c121SKalle Valo 2026e705c121SKalle Valo status = ADD_STA_SUCCESS; 2027854c5705SSara Sharon ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, 2028854c5705SSara Sharon iwl_mvm_add_sta_cmd_size(mvm), 2029e705c121SKalle Valo &cmd, &status); 2030e705c121SKalle Valo if (ret) 203110b2b201SSara Sharon goto out_free; 2032e705c121SKalle Valo 2033837c4da9SSara Sharon switch (status & IWL_ADD_STA_STATUS_MASK) { 2034e705c121SKalle Valo case ADD_STA_SUCCESS: 203535263a03SSara Sharon IWL_DEBUG_HT(mvm, "RX BA Session %sed in fw\n", 2036e705c121SKalle Valo start ? "start" : "stopp"); 2037e705c121SKalle Valo break; 2038e705c121SKalle Valo case ADD_STA_IMMEDIATE_BA_FAILURE: 2039e705c121SKalle Valo IWL_WARN(mvm, "RX BA Session refused by fw\n"); 2040e705c121SKalle Valo ret = -ENOSPC; 2041e705c121SKalle Valo break; 2042e705c121SKalle Valo default: 2043e705c121SKalle Valo ret = -EIO; 2044e705c121SKalle Valo IWL_ERR(mvm, "RX BA Session failed %sing, status 0x%x\n", 2045e705c121SKalle Valo start ? "start" : "stopp", status); 2046e705c121SKalle Valo break; 2047e705c121SKalle Valo } 2048e705c121SKalle Valo 204910b2b201SSara Sharon if (ret) 205010b2b201SSara Sharon goto out_free; 205110b2b201SSara Sharon 205210b2b201SSara Sharon if (start) { 205310b2b201SSara Sharon u8 baid; 205410b2b201SSara Sharon 2055e705c121SKalle Valo mvm->rx_ba_sessions++; 205610b2b201SSara Sharon 205710b2b201SSara Sharon if (!iwl_mvm_has_new_rx_api(mvm)) 205810b2b201SSara Sharon return 0; 205910b2b201SSara Sharon 206010b2b201SSara Sharon if (WARN_ON(!(status & IWL_ADD_STA_BAID_VALID_MASK))) { 206110b2b201SSara Sharon ret = -EINVAL; 206210b2b201SSara Sharon goto out_free; 206310b2b201SSara Sharon } 206410b2b201SSara Sharon baid = (u8)((status & IWL_ADD_STA_BAID_MASK) >> 206510b2b201SSara Sharon IWL_ADD_STA_BAID_SHIFT); 206610b2b201SSara Sharon baid_data->baid = baid; 206710b2b201SSara Sharon baid_data->timeout = timeout; 206810b2b201SSara Sharon baid_data->last_rx = jiffies; 206972c240feSWei Yongjun setup_timer(&baid_data->session_timer, 207072c240feSWei Yongjun iwl_mvm_rx_agg_session_expired, 207172c240feSWei Yongjun (unsigned long)&mvm->baid_map[baid]); 207210b2b201SSara Sharon baid_data->mvm = mvm; 207310b2b201SSara Sharon baid_data->tid = tid; 207410b2b201SSara Sharon baid_data->sta_id = mvm_sta->sta_id; 207510b2b201SSara Sharon 207610b2b201SSara Sharon mvm_sta->tid_to_baid[tid] = baid; 207710b2b201SSara Sharon if (timeout) 207810b2b201SSara Sharon mod_timer(&baid_data->session_timer, 207910b2b201SSara Sharon TU_TO_EXP_TIME(timeout * 2)); 208010b2b201SSara Sharon 2081b915c101SSara Sharon iwl_mvm_init_reorder_buffer(mvm, mvm_sta->sta_id, 2082b915c101SSara Sharon baid_data, ssn, buf_size); 208310b2b201SSara Sharon /* 208410b2b201SSara Sharon * protect the BA data with RCU to cover a case where our 208510b2b201SSara Sharon * internal RX sync mechanism will timeout (not that it's 208610b2b201SSara Sharon * supposed to happen) and we will free the session data while 208710b2b201SSara Sharon * RX is being processed in parallel 208810b2b201SSara Sharon */ 208935263a03SSara Sharon IWL_DEBUG_HT(mvm, "Sta %d(%d) is assigned to BAID %d\n", 209035263a03SSara Sharon mvm_sta->sta_id, tid, baid); 209110b2b201SSara Sharon WARN_ON(rcu_access_pointer(mvm->baid_map[baid])); 209210b2b201SSara Sharon rcu_assign_pointer(mvm->baid_map[baid], baid_data); 209360dec523SSara Sharon } else { 209410b2b201SSara Sharon u8 baid = mvm_sta->tid_to_baid[tid]; 209510b2b201SSara Sharon 209660dec523SSara Sharon if (mvm->rx_ba_sessions > 0) 2097e705c121SKalle Valo /* check that restart flow didn't zero the counter */ 2098e705c121SKalle Valo mvm->rx_ba_sessions--; 209910b2b201SSara Sharon if (!iwl_mvm_has_new_rx_api(mvm)) 210010b2b201SSara Sharon return 0; 2101e705c121SKalle Valo 210210b2b201SSara Sharon if (WARN_ON(baid == IWL_RX_REORDER_DATA_INVALID_BAID)) 210310b2b201SSara Sharon return -EINVAL; 210410b2b201SSara Sharon 210510b2b201SSara Sharon baid_data = rcu_access_pointer(mvm->baid_map[baid]); 210610b2b201SSara Sharon if (WARN_ON(!baid_data)) 210710b2b201SSara Sharon return -EINVAL; 210810b2b201SSara Sharon 210910b2b201SSara Sharon /* synchronize all rx queues so we can safely delete */ 2110b915c101SSara Sharon iwl_mvm_free_reorder(mvm, baid_data); 211110b2b201SSara Sharon del_timer_sync(&baid_data->session_timer); 211210b2b201SSara Sharon RCU_INIT_POINTER(mvm->baid_map[baid], NULL); 211310b2b201SSara Sharon kfree_rcu(baid_data, rcu_head); 211435263a03SSara Sharon IWL_DEBUG_HT(mvm, "BAID %d is free\n", baid); 211510b2b201SSara Sharon } 211610b2b201SSara Sharon return 0; 211710b2b201SSara Sharon 211810b2b201SSara Sharon out_free: 211910b2b201SSara Sharon kfree(baid_data); 2120e705c121SKalle Valo return ret; 2121e705c121SKalle Valo } 2122e705c121SKalle Valo 21239794c64fSLiad Kaufman int iwl_mvm_sta_tx_agg(struct iwl_mvm *mvm, struct ieee80211_sta *sta, 2124e705c121SKalle Valo int tid, u8 queue, bool start) 2125e705c121SKalle Valo { 2126e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 2127e705c121SKalle Valo struct iwl_mvm_add_sta_cmd cmd = {}; 2128e705c121SKalle Valo int ret; 2129e705c121SKalle Valo u32 status; 2130e705c121SKalle Valo 2131e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 2132e705c121SKalle Valo 2133e705c121SKalle Valo if (start) { 2134e705c121SKalle Valo mvm_sta->tfd_queue_msk |= BIT(queue); 2135e705c121SKalle Valo mvm_sta->tid_disable_agg &= ~BIT(tid); 2136e705c121SKalle Valo } else { 2137cf961e16SLiad Kaufman /* In DQA-mode the queue isn't removed on agg termination */ 2138cf961e16SLiad Kaufman if (!iwl_mvm_is_dqa_supported(mvm)) 2139e705c121SKalle Valo mvm_sta->tfd_queue_msk &= ~BIT(queue); 2140e705c121SKalle Valo mvm_sta->tid_disable_agg |= BIT(tid); 2141e705c121SKalle Valo } 2142e705c121SKalle Valo 2143e705c121SKalle Valo cmd.mac_id_n_color = cpu_to_le32(mvm_sta->mac_id_n_color); 2144e705c121SKalle Valo cmd.sta_id = mvm_sta->sta_id; 2145e705c121SKalle Valo cmd.add_modify = STA_MODE_MODIFY; 2146e705c121SKalle Valo cmd.modify_mask = STA_MODIFY_QUEUES | STA_MODIFY_TID_DISABLE_TX; 2147e705c121SKalle Valo cmd.tfd_queue_msk = cpu_to_le32(mvm_sta->tfd_queue_msk); 2148e705c121SKalle Valo cmd.tid_disable_tx = cpu_to_le16(mvm_sta->tid_disable_agg); 2149e705c121SKalle Valo 2150e705c121SKalle Valo status = ADD_STA_SUCCESS; 2151854c5705SSara Sharon ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA, 2152854c5705SSara Sharon iwl_mvm_add_sta_cmd_size(mvm), 2153e705c121SKalle Valo &cmd, &status); 2154e705c121SKalle Valo if (ret) 2155e705c121SKalle Valo return ret; 2156e705c121SKalle Valo 2157837c4da9SSara Sharon switch (status & IWL_ADD_STA_STATUS_MASK) { 2158e705c121SKalle Valo case ADD_STA_SUCCESS: 2159e705c121SKalle Valo break; 2160e705c121SKalle Valo default: 2161e705c121SKalle Valo ret = -EIO; 2162e705c121SKalle Valo IWL_ERR(mvm, "TX BA Session failed %sing, status 0x%x\n", 2163e705c121SKalle Valo start ? "start" : "stopp", status); 2164e705c121SKalle Valo break; 2165e705c121SKalle Valo } 2166e705c121SKalle Valo 2167e705c121SKalle Valo return ret; 2168e705c121SKalle Valo } 2169e705c121SKalle Valo 2170e705c121SKalle Valo const u8 tid_to_mac80211_ac[] = { 2171e705c121SKalle Valo IEEE80211_AC_BE, 2172e705c121SKalle Valo IEEE80211_AC_BK, 2173e705c121SKalle Valo IEEE80211_AC_BK, 2174e705c121SKalle Valo IEEE80211_AC_BE, 2175e705c121SKalle Valo IEEE80211_AC_VI, 2176e705c121SKalle Valo IEEE80211_AC_VI, 2177e705c121SKalle Valo IEEE80211_AC_VO, 2178e705c121SKalle Valo IEEE80211_AC_VO, 21799794c64fSLiad Kaufman IEEE80211_AC_VO, /* We treat MGMT as TID 8, which is set as AC_VO */ 2180e705c121SKalle Valo }; 2181e705c121SKalle Valo 2182e705c121SKalle Valo static const u8 tid_to_ucode_ac[] = { 2183e705c121SKalle Valo AC_BE, 2184e705c121SKalle Valo AC_BK, 2185e705c121SKalle Valo AC_BK, 2186e705c121SKalle Valo AC_BE, 2187e705c121SKalle Valo AC_VI, 2188e705c121SKalle Valo AC_VI, 2189e705c121SKalle Valo AC_VO, 2190e705c121SKalle Valo AC_VO, 2191e705c121SKalle Valo }; 2192e705c121SKalle Valo 2193e705c121SKalle Valo int iwl_mvm_sta_tx_agg_start(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 2194e705c121SKalle Valo struct ieee80211_sta *sta, u16 tid, u16 *ssn) 2195e705c121SKalle Valo { 2196e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 2197e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data; 2198e705c121SKalle Valo int txq_id; 2199e705c121SKalle Valo int ret; 2200e705c121SKalle Valo 2201e705c121SKalle Valo if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT)) 2202e705c121SKalle Valo return -EINVAL; 2203e705c121SKalle Valo 2204e705c121SKalle Valo if (mvmsta->tid_data[tid].state != IWL_AGG_OFF) { 2205e705c121SKalle Valo IWL_ERR(mvm, "Start AGG when state is not IWL_AGG_OFF %d!\n", 2206e705c121SKalle Valo mvmsta->tid_data[tid].state); 2207e705c121SKalle Valo return -ENXIO; 2208e705c121SKalle Valo } 2209e705c121SKalle Valo 2210e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 2211e705c121SKalle Valo 2212e705c121SKalle Valo spin_lock_bh(&mvmsta->lock); 2213e705c121SKalle Valo 2214e705c121SKalle Valo /* possible race condition - we entered D0i3 while starting agg */ 2215e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_D0I3, &mvm->status)) { 2216e705c121SKalle Valo spin_unlock_bh(&mvmsta->lock); 2217e705c121SKalle Valo IWL_ERR(mvm, "Entered D0i3 while starting Tx agg\n"); 2218e705c121SKalle Valo return -EIO; 2219e705c121SKalle Valo } 2220e705c121SKalle Valo 22219f9af3d7SLiad Kaufman spin_lock(&mvm->queue_info_lock); 2222e705c121SKalle Valo 2223cf961e16SLiad Kaufman /* 2224cf961e16SLiad Kaufman * Note the possible cases: 2225cf961e16SLiad Kaufman * 1. In DQA mode with an enabled TXQ - TXQ needs to become agg'ed 2226cf961e16SLiad Kaufman * 2. Non-DQA mode: the TXQ hasn't yet been enabled, so find a free 2227cf961e16SLiad Kaufman * one and mark it as reserved 2228cf961e16SLiad Kaufman * 3. In DQA mode, but no traffic yet on this TID: same treatment as in 2229cf961e16SLiad Kaufman * non-DQA mode, since the TXQ hasn't yet been allocated 2230cf961e16SLiad Kaufman */ 2231cf961e16SLiad Kaufman txq_id = mvmsta->tid_data[tid].txq_id; 22329f9af3d7SLiad Kaufman if (iwl_mvm_is_dqa_supported(mvm) && 22339f9af3d7SLiad Kaufman unlikely(mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_SHARED)) { 22349f9af3d7SLiad Kaufman ret = -ENXIO; 22359f9af3d7SLiad Kaufman IWL_DEBUG_TX_QUEUES(mvm, 22369f9af3d7SLiad Kaufman "Can't start tid %d agg on shared queue!\n", 22379f9af3d7SLiad Kaufman tid); 22389f9af3d7SLiad Kaufman goto release_locks; 22399f9af3d7SLiad Kaufman } else if (!iwl_mvm_is_dqa_supported(mvm) || 2240cf961e16SLiad Kaufman mvm->queue_info[txq_id].status != IWL_MVM_QUEUE_READY) { 22419794c64fSLiad Kaufman txq_id = iwl_mvm_find_free_queue(mvm, mvmsta->sta_id, 22429794c64fSLiad Kaufman mvm->first_agg_queue, 2243e705c121SKalle Valo mvm->last_agg_queue); 2244e705c121SKalle Valo if (txq_id < 0) { 2245e705c121SKalle Valo ret = txq_id; 2246e705c121SKalle Valo IWL_ERR(mvm, "Failed to allocate agg queue\n"); 2247e705c121SKalle Valo goto release_locks; 2248e705c121SKalle Valo } 2249cf961e16SLiad Kaufman 2250cf961e16SLiad Kaufman /* TXQ hasn't yet been enabled, so mark it only as reserved */ 2251cf961e16SLiad Kaufman mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_RESERVED; 2252cf961e16SLiad Kaufman } 22539f9af3d7SLiad Kaufman 22549f9af3d7SLiad Kaufman spin_unlock(&mvm->queue_info_lock); 2255e705c121SKalle Valo 2256cf961e16SLiad Kaufman IWL_DEBUG_TX_QUEUES(mvm, 2257cf961e16SLiad Kaufman "AGG for tid %d will be on queue #%d\n", 2258cf961e16SLiad Kaufman tid, txq_id); 2259cf961e16SLiad Kaufman 2260e705c121SKalle Valo tid_data = &mvmsta->tid_data[tid]; 2261e705c121SKalle Valo tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); 2262e705c121SKalle Valo tid_data->txq_id = txq_id; 2263e705c121SKalle Valo *ssn = tid_data->ssn; 2264e705c121SKalle Valo 2265e705c121SKalle Valo IWL_DEBUG_TX_QUEUES(mvm, 2266e705c121SKalle Valo "Start AGG: sta %d tid %d queue %d - ssn = %d, next_recl = %d\n", 2267e705c121SKalle Valo mvmsta->sta_id, tid, txq_id, tid_data->ssn, 2268e705c121SKalle Valo tid_data->next_reclaimed); 2269e705c121SKalle Valo 2270e705c121SKalle Valo if (tid_data->ssn == tid_data->next_reclaimed) { 2271e705c121SKalle Valo tid_data->state = IWL_AGG_STARTING; 2272e705c121SKalle Valo ieee80211_start_tx_ba_cb_irqsafe(vif, sta->addr, tid); 2273e705c121SKalle Valo } else { 2274e705c121SKalle Valo tid_data->state = IWL_EMPTYING_HW_QUEUE_ADDBA; 2275e705c121SKalle Valo } 2276e705c121SKalle Valo 2277e705c121SKalle Valo ret = 0; 22789f9af3d7SLiad Kaufman goto out; 2279e705c121SKalle Valo 2280e705c121SKalle Valo release_locks: 22819f9af3d7SLiad Kaufman spin_unlock(&mvm->queue_info_lock); 22829f9af3d7SLiad Kaufman out: 2283e705c121SKalle Valo spin_unlock_bh(&mvmsta->lock); 2284e705c121SKalle Valo 2285e705c121SKalle Valo return ret; 2286e705c121SKalle Valo } 2287e705c121SKalle Valo 2288e705c121SKalle Valo int iwl_mvm_sta_tx_agg_oper(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 2289bb81bb68SEmmanuel Grumbach struct ieee80211_sta *sta, u16 tid, u8 buf_size, 2290bb81bb68SEmmanuel Grumbach bool amsdu) 2291e705c121SKalle Valo { 2292e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 2293e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 2294e705c121SKalle Valo unsigned int wdg_timeout = 2295e705c121SKalle Valo iwl_mvm_get_wd_timeout(mvm, vif, sta->tdls, false); 2296eea76c36SEmmanuel Grumbach int queue, ret; 2297cf961e16SLiad Kaufman bool alloc_queue = true; 22989f9af3d7SLiad Kaufman enum iwl_mvm_queue_status queue_status; 2299e705c121SKalle Valo u16 ssn; 2300e705c121SKalle Valo 2301eea76c36SEmmanuel Grumbach struct iwl_trans_txq_scd_cfg cfg = { 2302eea76c36SEmmanuel Grumbach .sta_id = mvmsta->sta_id, 2303eea76c36SEmmanuel Grumbach .tid = tid, 2304eea76c36SEmmanuel Grumbach .frame_limit = buf_size, 2305eea76c36SEmmanuel Grumbach .aggregate = true, 2306eea76c36SEmmanuel Grumbach }; 2307eea76c36SEmmanuel Grumbach 2308e705c121SKalle Valo BUILD_BUG_ON((sizeof(mvmsta->agg_tids) * BITS_PER_BYTE) 2309e705c121SKalle Valo != IWL_MAX_TID_COUNT); 2310e705c121SKalle Valo 2311e705c121SKalle Valo buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF); 2312e705c121SKalle Valo 2313e705c121SKalle Valo spin_lock_bh(&mvmsta->lock); 2314e705c121SKalle Valo ssn = tid_data->ssn; 2315e705c121SKalle Valo queue = tid_data->txq_id; 2316e705c121SKalle Valo tid_data->state = IWL_AGG_ON; 2317e705c121SKalle Valo mvmsta->agg_tids |= BIT(tid); 2318e705c121SKalle Valo tid_data->ssn = 0xffff; 2319bb81bb68SEmmanuel Grumbach tid_data->amsdu_in_ampdu_allowed = amsdu; 2320e705c121SKalle Valo spin_unlock_bh(&mvmsta->lock); 2321e705c121SKalle Valo 2322eea76c36SEmmanuel Grumbach cfg.fifo = iwl_mvm_ac_to_tx_fifo[tid_to_mac80211_ac[tid]]; 2323e705c121SKalle Valo 23249f9af3d7SLiad Kaufman spin_lock_bh(&mvm->queue_info_lock); 23259f9af3d7SLiad Kaufman queue_status = mvm->queue_info[queue].status; 23269f9af3d7SLiad Kaufman spin_unlock_bh(&mvm->queue_info_lock); 23279f9af3d7SLiad Kaufman 2328cf961e16SLiad Kaufman /* In DQA mode, the existing queue might need to be reconfigured */ 2329cf961e16SLiad Kaufman if (iwl_mvm_is_dqa_supported(mvm)) { 2330cf961e16SLiad Kaufman /* Maybe there is no need to even alloc a queue... */ 2331cf961e16SLiad Kaufman if (mvm->queue_info[queue].status == IWL_MVM_QUEUE_READY) 2332cf961e16SLiad Kaufman alloc_queue = false; 2333cf961e16SLiad Kaufman 2334cf961e16SLiad Kaufman /* 2335cf961e16SLiad Kaufman * Only reconfig the SCD for the queue if the window size has 2336cf961e16SLiad Kaufman * changed from current (become smaller) 2337cf961e16SLiad Kaufman */ 2338cf961e16SLiad Kaufman if (!alloc_queue && buf_size < mvmsta->max_agg_bufsize) { 2339cf961e16SLiad Kaufman /* 2340cf961e16SLiad Kaufman * If reconfiguring an existing queue, it first must be 2341cf961e16SLiad Kaufman * drained 2342cf961e16SLiad Kaufman */ 2343cf961e16SLiad Kaufman ret = iwl_trans_wait_tx_queue_empty(mvm->trans, 2344cf961e16SLiad Kaufman BIT(queue)); 2345cf961e16SLiad Kaufman if (ret) { 2346cf961e16SLiad Kaufman IWL_ERR(mvm, 2347cf961e16SLiad Kaufman "Error draining queue before reconfig\n"); 2348cf961e16SLiad Kaufman return ret; 2349cf961e16SLiad Kaufman } 2350cf961e16SLiad Kaufman 2351cf961e16SLiad Kaufman ret = iwl_mvm_reconfig_scd(mvm, queue, cfg.fifo, 2352cf961e16SLiad Kaufman mvmsta->sta_id, tid, 2353cf961e16SLiad Kaufman buf_size, ssn); 2354cf961e16SLiad Kaufman if (ret) { 2355cf961e16SLiad Kaufman IWL_ERR(mvm, 2356cf961e16SLiad Kaufman "Error reconfiguring TXQ #%d\n", queue); 2357cf961e16SLiad Kaufman return ret; 2358cf961e16SLiad Kaufman } 2359cf961e16SLiad Kaufman } 2360cf961e16SLiad Kaufman } 2361cf961e16SLiad Kaufman 2362cf961e16SLiad Kaufman if (alloc_queue) 2363cf961e16SLiad Kaufman iwl_mvm_enable_txq(mvm, queue, 2364cf961e16SLiad Kaufman vif->hw_queue[tid_to_mac80211_ac[tid]], ssn, 2365cf961e16SLiad Kaufman &cfg, wdg_timeout); 2366e705c121SKalle Valo 23679f9af3d7SLiad Kaufman /* Send ADD_STA command to enable aggs only if the queue isn't shared */ 23689f9af3d7SLiad Kaufman if (queue_status != IWL_MVM_QUEUE_SHARED) { 2369e705c121SKalle Valo ret = iwl_mvm_sta_tx_agg(mvm, sta, tid, queue, true); 2370e705c121SKalle Valo if (ret) 2371e705c121SKalle Valo return -EIO; 23729f9af3d7SLiad Kaufman } 2373e705c121SKalle Valo 2374e705c121SKalle Valo /* No need to mark as reserved */ 2375e705c121SKalle Valo spin_lock_bh(&mvm->queue_info_lock); 2376cf961e16SLiad Kaufman mvm->queue_info[queue].status = IWL_MVM_QUEUE_READY; 2377e705c121SKalle Valo spin_unlock_bh(&mvm->queue_info_lock); 2378e705c121SKalle Valo 2379e705c121SKalle Valo /* 2380e705c121SKalle Valo * Even though in theory the peer could have different 2381e705c121SKalle Valo * aggregation reorder buffer sizes for different sessions, 2382e705c121SKalle Valo * our ucode doesn't allow for that and has a global limit 2383e705c121SKalle Valo * for each station. Therefore, use the minimum of all the 2384e705c121SKalle Valo * aggregation sessions and our default value. 2385e705c121SKalle Valo */ 2386e705c121SKalle Valo mvmsta->max_agg_bufsize = 2387e705c121SKalle Valo min(mvmsta->max_agg_bufsize, buf_size); 2388e705c121SKalle Valo mvmsta->lq_sta.lq.agg_frame_cnt_limit = mvmsta->max_agg_bufsize; 2389e705c121SKalle Valo 2390e705c121SKalle Valo IWL_DEBUG_HT(mvm, "Tx aggregation enabled on ra = %pM tid = %d\n", 2391e705c121SKalle Valo sta->addr, tid); 2392e705c121SKalle Valo 2393e705c121SKalle Valo return iwl_mvm_send_lq_cmd(mvm, &mvmsta->lq_sta.lq, false); 2394e705c121SKalle Valo } 2395e705c121SKalle Valo 2396e705c121SKalle Valo int iwl_mvm_sta_tx_agg_stop(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 2397e705c121SKalle Valo struct ieee80211_sta *sta, u16 tid) 2398e705c121SKalle Valo { 2399e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 2400e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 2401e705c121SKalle Valo u16 txq_id; 2402e705c121SKalle Valo int err; 2403e705c121SKalle Valo 2404e705c121SKalle Valo /* 2405e705c121SKalle Valo * If mac80211 is cleaning its state, then say that we finished since 2406e705c121SKalle Valo * our state has been cleared anyway. 2407e705c121SKalle Valo */ 2408e705c121SKalle Valo if (test_bit(IWL_MVM_STATUS_IN_HW_RESTART, &mvm->status)) { 2409e705c121SKalle Valo ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); 2410e705c121SKalle Valo return 0; 2411e705c121SKalle Valo } 2412e705c121SKalle Valo 2413e705c121SKalle Valo spin_lock_bh(&mvmsta->lock); 2414e705c121SKalle Valo 2415e705c121SKalle Valo txq_id = tid_data->txq_id; 2416e705c121SKalle Valo 2417e705c121SKalle Valo IWL_DEBUG_TX_QUEUES(mvm, "Stop AGG: sta %d tid %d q %d state %d\n", 2418e705c121SKalle Valo mvmsta->sta_id, tid, txq_id, tid_data->state); 2419e705c121SKalle Valo 2420e705c121SKalle Valo mvmsta->agg_tids &= ~BIT(tid); 2421e705c121SKalle Valo 2422e705c121SKalle Valo spin_lock_bh(&mvm->queue_info_lock); 2423cf961e16SLiad Kaufman /* 2424cf961e16SLiad Kaufman * The TXQ is marked as reserved only if no traffic came through yet 2425cf961e16SLiad Kaufman * This means no traffic has been sent on this TID (agg'd or not), so 2426cf961e16SLiad Kaufman * we no longer have use for the queue. Since it hasn't even been 2427cf961e16SLiad Kaufman * allocated through iwl_mvm_enable_txq, so we can just mark it back as 2428cf961e16SLiad Kaufman * free. 2429cf961e16SLiad Kaufman */ 2430cf961e16SLiad Kaufman if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED) 2431cf961e16SLiad Kaufman mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE; 24329f9af3d7SLiad Kaufman 2433e705c121SKalle Valo spin_unlock_bh(&mvm->queue_info_lock); 2434e705c121SKalle Valo 2435e705c121SKalle Valo switch (tid_data->state) { 2436e705c121SKalle Valo case IWL_AGG_ON: 2437e705c121SKalle Valo tid_data->ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); 2438e705c121SKalle Valo 2439e705c121SKalle Valo IWL_DEBUG_TX_QUEUES(mvm, 2440e705c121SKalle Valo "ssn = %d, next_recl = %d\n", 2441e705c121SKalle Valo tid_data->ssn, tid_data->next_reclaimed); 2442e705c121SKalle Valo 2443e705c121SKalle Valo /* There are still packets for this RA / TID in the HW */ 2444e705c121SKalle Valo if (tid_data->ssn != tid_data->next_reclaimed) { 2445e705c121SKalle Valo tid_data->state = IWL_EMPTYING_HW_QUEUE_DELBA; 2446e705c121SKalle Valo err = 0; 2447e705c121SKalle Valo break; 2448e705c121SKalle Valo } 2449e705c121SKalle Valo 2450e705c121SKalle Valo tid_data->ssn = 0xffff; 2451e705c121SKalle Valo tid_data->state = IWL_AGG_OFF; 2452e705c121SKalle Valo spin_unlock_bh(&mvmsta->lock); 2453e705c121SKalle Valo 2454e705c121SKalle Valo ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); 2455e705c121SKalle Valo 2456e705c121SKalle Valo iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false); 2457e705c121SKalle Valo 2458cf961e16SLiad Kaufman if (!iwl_mvm_is_dqa_supported(mvm)) { 2459cf961e16SLiad Kaufman int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]]; 2460cf961e16SLiad Kaufman 2461cf961e16SLiad Kaufman iwl_mvm_disable_txq(mvm, txq_id, mac_queue, tid, 0); 2462cf961e16SLiad Kaufman } 2463e705c121SKalle Valo return 0; 2464e705c121SKalle Valo case IWL_AGG_STARTING: 2465e705c121SKalle Valo case IWL_EMPTYING_HW_QUEUE_ADDBA: 2466e705c121SKalle Valo /* 2467e705c121SKalle Valo * The agg session has been stopped before it was set up. This 2468e705c121SKalle Valo * can happen when the AddBA timer times out for example. 2469e705c121SKalle Valo */ 2470e705c121SKalle Valo 2471e705c121SKalle Valo /* No barriers since we are under mutex */ 2472e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 2473e705c121SKalle Valo 2474e705c121SKalle Valo ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); 2475e705c121SKalle Valo tid_data->state = IWL_AGG_OFF; 2476e705c121SKalle Valo err = 0; 2477e705c121SKalle Valo break; 2478e705c121SKalle Valo default: 2479e705c121SKalle Valo IWL_ERR(mvm, 2480e705c121SKalle Valo "Stopping AGG while state not ON or starting for %d on %d (%d)\n", 2481e705c121SKalle Valo mvmsta->sta_id, tid, tid_data->state); 2482e705c121SKalle Valo IWL_ERR(mvm, 2483e705c121SKalle Valo "\ttid_data->txq_id = %d\n", tid_data->txq_id); 2484e705c121SKalle Valo err = -EINVAL; 2485e705c121SKalle Valo } 2486e705c121SKalle Valo 2487e705c121SKalle Valo spin_unlock_bh(&mvmsta->lock); 2488e705c121SKalle Valo 2489e705c121SKalle Valo return err; 2490e705c121SKalle Valo } 2491e705c121SKalle Valo 2492e705c121SKalle Valo int iwl_mvm_sta_tx_agg_flush(struct iwl_mvm *mvm, struct ieee80211_vif *vif, 2493e705c121SKalle Valo struct ieee80211_sta *sta, u16 tid) 2494e705c121SKalle Valo { 2495e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 2496e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data = &mvmsta->tid_data[tid]; 2497e705c121SKalle Valo u16 txq_id; 2498e705c121SKalle Valo enum iwl_mvm_agg_state old_state; 2499e705c121SKalle Valo 2500e705c121SKalle Valo /* 2501e705c121SKalle Valo * First set the agg state to OFF to avoid calling 2502e705c121SKalle Valo * ieee80211_stop_tx_ba_cb in iwl_mvm_check_ratid_empty. 2503e705c121SKalle Valo */ 2504e705c121SKalle Valo spin_lock_bh(&mvmsta->lock); 2505e705c121SKalle Valo txq_id = tid_data->txq_id; 2506e705c121SKalle Valo IWL_DEBUG_TX_QUEUES(mvm, "Flush AGG: sta %d tid %d q %d state %d\n", 2507e705c121SKalle Valo mvmsta->sta_id, tid, txq_id, tid_data->state); 2508e705c121SKalle Valo old_state = tid_data->state; 2509e705c121SKalle Valo tid_data->state = IWL_AGG_OFF; 2510e705c121SKalle Valo mvmsta->agg_tids &= ~BIT(tid); 2511e705c121SKalle Valo spin_unlock_bh(&mvmsta->lock); 2512e705c121SKalle Valo 2513e705c121SKalle Valo spin_lock_bh(&mvm->queue_info_lock); 2514cf961e16SLiad Kaufman /* 2515cf961e16SLiad Kaufman * The TXQ is marked as reserved only if no traffic came through yet 2516cf961e16SLiad Kaufman * This means no traffic has been sent on this TID (agg'd or not), so 2517cf961e16SLiad Kaufman * we no longer have use for the queue. Since it hasn't even been 2518cf961e16SLiad Kaufman * allocated through iwl_mvm_enable_txq, so we can just mark it back as 2519cf961e16SLiad Kaufman * free. 2520cf961e16SLiad Kaufman */ 2521cf961e16SLiad Kaufman if (mvm->queue_info[txq_id].status == IWL_MVM_QUEUE_RESERVED) 2522cf961e16SLiad Kaufman mvm->queue_info[txq_id].status = IWL_MVM_QUEUE_FREE; 2523e705c121SKalle Valo spin_unlock_bh(&mvm->queue_info_lock); 2524e705c121SKalle Valo 2525e705c121SKalle Valo if (old_state >= IWL_AGG_ON) { 2526e705c121SKalle Valo iwl_mvm_drain_sta(mvm, mvmsta, true); 2527e705c121SKalle Valo if (iwl_mvm_flush_tx_path(mvm, BIT(txq_id), 0)) 2528e705c121SKalle Valo IWL_ERR(mvm, "Couldn't flush the AGG queue\n"); 2529e705c121SKalle Valo iwl_trans_wait_tx_queue_empty(mvm->trans, 2530e705c121SKalle Valo mvmsta->tfd_queue_msk); 2531e705c121SKalle Valo iwl_mvm_drain_sta(mvm, mvmsta, false); 2532e705c121SKalle Valo 2533e705c121SKalle Valo iwl_mvm_sta_tx_agg(mvm, sta, tid, txq_id, false); 2534e705c121SKalle Valo 2535cf961e16SLiad Kaufman if (!iwl_mvm_is_dqa_supported(mvm)) { 2536cf961e16SLiad Kaufman int mac_queue = vif->hw_queue[tid_to_mac80211_ac[tid]]; 2537cf961e16SLiad Kaufman 2538cf961e16SLiad Kaufman iwl_mvm_disable_txq(mvm, tid_data->txq_id, mac_queue, 2539cf961e16SLiad Kaufman tid, 0); 2540cf961e16SLiad Kaufman } 2541e705c121SKalle Valo } 2542e705c121SKalle Valo 2543e705c121SKalle Valo return 0; 2544e705c121SKalle Valo } 2545e705c121SKalle Valo 2546e705c121SKalle Valo static int iwl_mvm_set_fw_key_idx(struct iwl_mvm *mvm) 2547e705c121SKalle Valo { 2548e705c121SKalle Valo int i, max = -1, max_offs = -1; 2549e705c121SKalle Valo 2550e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 2551e705c121SKalle Valo 2552e705c121SKalle Valo /* Pick the unused key offset with the highest 'deleted' 2553e705c121SKalle Valo * counter. Every time a key is deleted, all the counters 2554e705c121SKalle Valo * are incremented and the one that was just deleted is 2555e705c121SKalle Valo * reset to zero. Thus, the highest counter is the one 2556e705c121SKalle Valo * that was deleted longest ago. Pick that one. 2557e705c121SKalle Valo */ 2558e705c121SKalle Valo for (i = 0; i < STA_KEY_MAX_NUM; i++) { 2559e705c121SKalle Valo if (test_bit(i, mvm->fw_key_table)) 2560e705c121SKalle Valo continue; 2561e705c121SKalle Valo if (mvm->fw_key_deleted[i] > max) { 2562e705c121SKalle Valo max = mvm->fw_key_deleted[i]; 2563e705c121SKalle Valo max_offs = i; 2564e705c121SKalle Valo } 2565e705c121SKalle Valo } 2566e705c121SKalle Valo 2567e705c121SKalle Valo if (max_offs < 0) 2568e705c121SKalle Valo return STA_KEY_IDX_INVALID; 2569e705c121SKalle Valo 2570e705c121SKalle Valo return max_offs; 2571e705c121SKalle Valo } 2572e705c121SKalle Valo 25735f7a1847SJohannes Berg static struct iwl_mvm_sta *iwl_mvm_get_key_sta(struct iwl_mvm *mvm, 25744615fd15SEmmanuel Grumbach struct ieee80211_vif *vif, 2575e705c121SKalle Valo struct ieee80211_sta *sta) 2576e705c121SKalle Valo { 2577e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2578e705c121SKalle Valo 25795f7a1847SJohannes Berg if (sta) 25805f7a1847SJohannes Berg return iwl_mvm_sta_from_mac80211(sta); 2581e705c121SKalle Valo 2582e705c121SKalle Valo /* 2583e705c121SKalle Valo * The device expects GTKs for station interfaces to be 2584e705c121SKalle Valo * installed as GTKs for the AP station. If we have no 2585e705c121SKalle Valo * station ID, then use AP's station ID. 2586e705c121SKalle Valo */ 2587e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_STATION && 25884615fd15SEmmanuel Grumbach mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { 25894615fd15SEmmanuel Grumbach u8 sta_id = mvmvif->ap_sta_id; 25904615fd15SEmmanuel Grumbach 25917d6a1ab6SEmmanuel Grumbach sta = rcu_dereference_check(mvm->fw_id_to_mac_id[sta_id], 25927d6a1ab6SEmmanuel Grumbach lockdep_is_held(&mvm->mutex)); 25937d6a1ab6SEmmanuel Grumbach 25944615fd15SEmmanuel Grumbach /* 25954615fd15SEmmanuel Grumbach * It is possible that the 'sta' parameter is NULL, 25964615fd15SEmmanuel Grumbach * for example when a GTK is removed - the sta_id will then 25974615fd15SEmmanuel Grumbach * be the AP ID, and no station was passed by mac80211. 25984615fd15SEmmanuel Grumbach */ 25997d6a1ab6SEmmanuel Grumbach if (IS_ERR_OR_NULL(sta)) 26007d6a1ab6SEmmanuel Grumbach return NULL; 26017d6a1ab6SEmmanuel Grumbach 26027d6a1ab6SEmmanuel Grumbach return iwl_mvm_sta_from_mac80211(sta); 26034615fd15SEmmanuel Grumbach } 2604e705c121SKalle Valo 26055f7a1847SJohannes Berg return NULL; 2606e705c121SKalle Valo } 2607e705c121SKalle Valo 2608e705c121SKalle Valo static int iwl_mvm_send_sta_key(struct iwl_mvm *mvm, 2609e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta, 2610e705c121SKalle Valo struct ieee80211_key_conf *keyconf, bool mcast, 26114615fd15SEmmanuel Grumbach u32 tkip_iv32, u16 *tkip_p1k, u32 cmd_flags, 26124615fd15SEmmanuel Grumbach u8 key_offset) 2613e705c121SKalle Valo { 2614e705c121SKalle Valo struct iwl_mvm_add_sta_key_cmd cmd = {}; 2615e705c121SKalle Valo __le16 key_flags; 2616e705c121SKalle Valo int ret; 2617e705c121SKalle Valo u32 status; 2618e705c121SKalle Valo u16 keyidx; 2619e705c121SKalle Valo int i; 2620e705c121SKalle Valo u8 sta_id = mvm_sta->sta_id; 2621e705c121SKalle Valo 2622e705c121SKalle Valo keyidx = (keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & 2623e705c121SKalle Valo STA_KEY_FLG_KEYID_MSK; 2624e705c121SKalle Valo key_flags = cpu_to_le16(keyidx); 2625e705c121SKalle Valo key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_KEY_MAP); 2626e705c121SKalle Valo 2627e705c121SKalle Valo switch (keyconf->cipher) { 2628e705c121SKalle Valo case WLAN_CIPHER_SUITE_TKIP: 2629e705c121SKalle Valo key_flags |= cpu_to_le16(STA_KEY_FLG_TKIP); 2630e705c121SKalle Valo cmd.tkip_rx_tsc_byte2 = tkip_iv32; 2631e705c121SKalle Valo for (i = 0; i < 5; i++) 2632e705c121SKalle Valo cmd.tkip_rx_ttak[i] = cpu_to_le16(tkip_p1k[i]); 2633e705c121SKalle Valo memcpy(cmd.key, keyconf->key, keyconf->keylen); 2634e705c121SKalle Valo break; 2635e705c121SKalle Valo case WLAN_CIPHER_SUITE_CCMP: 2636e705c121SKalle Valo key_flags |= cpu_to_le16(STA_KEY_FLG_CCM); 2637e705c121SKalle Valo memcpy(cmd.key, keyconf->key, keyconf->keylen); 2638e705c121SKalle Valo break; 2639e705c121SKalle Valo case WLAN_CIPHER_SUITE_WEP104: 2640e705c121SKalle Valo key_flags |= cpu_to_le16(STA_KEY_FLG_WEP_13BYTES); 2641e705c121SKalle Valo /* fall through */ 2642e705c121SKalle Valo case WLAN_CIPHER_SUITE_WEP40: 2643e705c121SKalle Valo key_flags |= cpu_to_le16(STA_KEY_FLG_WEP); 2644e705c121SKalle Valo memcpy(cmd.key + 3, keyconf->key, keyconf->keylen); 2645e705c121SKalle Valo break; 26462a53d166SAyala Beker case WLAN_CIPHER_SUITE_GCMP_256: 26472a53d166SAyala Beker key_flags |= cpu_to_le16(STA_KEY_FLG_KEY_32BYTES); 26482a53d166SAyala Beker /* fall through */ 26492a53d166SAyala Beker case WLAN_CIPHER_SUITE_GCMP: 26502a53d166SAyala Beker key_flags |= cpu_to_le16(STA_KEY_FLG_GCMP); 26512a53d166SAyala Beker memcpy(cmd.key, keyconf->key, keyconf->keylen); 26522a53d166SAyala Beker break; 2653e705c121SKalle Valo default: 2654e705c121SKalle Valo key_flags |= cpu_to_le16(STA_KEY_FLG_EXT); 2655e705c121SKalle Valo memcpy(cmd.key, keyconf->key, keyconf->keylen); 2656e705c121SKalle Valo } 2657e705c121SKalle Valo 2658e705c121SKalle Valo if (mcast) 2659e705c121SKalle Valo key_flags |= cpu_to_le16(STA_KEY_MULTICAST); 2660e705c121SKalle Valo 26614615fd15SEmmanuel Grumbach cmd.key_offset = key_offset; 2662e705c121SKalle Valo cmd.key_flags = key_flags; 2663e705c121SKalle Valo cmd.sta_id = sta_id; 2664e705c121SKalle Valo 2665e705c121SKalle Valo status = ADD_STA_SUCCESS; 2666e705c121SKalle Valo if (cmd_flags & CMD_ASYNC) 2667e705c121SKalle Valo ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA_KEY, CMD_ASYNC, 2668e705c121SKalle Valo sizeof(cmd), &cmd); 2669e705c121SKalle Valo else 2670e705c121SKalle Valo ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd), 2671e705c121SKalle Valo &cmd, &status); 2672e705c121SKalle Valo 2673e705c121SKalle Valo switch (status) { 2674e705c121SKalle Valo case ADD_STA_SUCCESS: 2675e705c121SKalle Valo IWL_DEBUG_WEP(mvm, "MODIFY_STA: set dynamic key passed\n"); 2676e705c121SKalle Valo break; 2677e705c121SKalle Valo default: 2678e705c121SKalle Valo ret = -EIO; 2679e705c121SKalle Valo IWL_ERR(mvm, "MODIFY_STA: set dynamic key failed\n"); 2680e705c121SKalle Valo break; 2681e705c121SKalle Valo } 2682e705c121SKalle Valo 2683e705c121SKalle Valo return ret; 2684e705c121SKalle Valo } 2685e705c121SKalle Valo 2686e705c121SKalle Valo static int iwl_mvm_send_sta_igtk(struct iwl_mvm *mvm, 2687e705c121SKalle Valo struct ieee80211_key_conf *keyconf, 2688e705c121SKalle Valo u8 sta_id, bool remove_key) 2689e705c121SKalle Valo { 2690e705c121SKalle Valo struct iwl_mvm_mgmt_mcast_key_cmd igtk_cmd = {}; 2691e705c121SKalle Valo 2692e705c121SKalle Valo /* verify the key details match the required command's expectations */ 26938e160ab8SAyala Beker if (WARN_ON((keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE) || 26948e160ab8SAyala Beker (keyconf->keyidx != 4 && keyconf->keyidx != 5) || 26958e160ab8SAyala Beker (keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC && 26968e160ab8SAyala Beker keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_128 && 26978e160ab8SAyala Beker keyconf->cipher != WLAN_CIPHER_SUITE_BIP_GMAC_256))) 26988e160ab8SAyala Beker return -EINVAL; 26998e160ab8SAyala Beker 27008e160ab8SAyala Beker if (WARN_ON(!iwl_mvm_has_new_rx_api(mvm) && 27018e160ab8SAyala Beker keyconf->cipher != WLAN_CIPHER_SUITE_AES_CMAC)) 2702e705c121SKalle Valo return -EINVAL; 2703e705c121SKalle Valo 2704e705c121SKalle Valo igtk_cmd.key_id = cpu_to_le32(keyconf->keyidx); 2705e705c121SKalle Valo igtk_cmd.sta_id = cpu_to_le32(sta_id); 2706e705c121SKalle Valo 2707e705c121SKalle Valo if (remove_key) { 2708e705c121SKalle Valo igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_NOT_VALID); 2709e705c121SKalle Valo } else { 2710e705c121SKalle Valo struct ieee80211_key_seq seq; 2711e705c121SKalle Valo const u8 *pn; 2712e705c121SKalle Valo 2713aa950524SAyala Beker switch (keyconf->cipher) { 2714aa950524SAyala Beker case WLAN_CIPHER_SUITE_AES_CMAC: 2715aa950524SAyala Beker igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_CCM); 2716aa950524SAyala Beker break; 27178e160ab8SAyala Beker case WLAN_CIPHER_SUITE_BIP_GMAC_128: 27188e160ab8SAyala Beker case WLAN_CIPHER_SUITE_BIP_GMAC_256: 27198e160ab8SAyala Beker igtk_cmd.ctrl_flags |= cpu_to_le32(STA_KEY_FLG_GCMP); 27208e160ab8SAyala Beker break; 2721aa950524SAyala Beker default: 2722aa950524SAyala Beker return -EINVAL; 2723aa950524SAyala Beker } 2724aa950524SAyala Beker 27258e160ab8SAyala Beker memcpy(igtk_cmd.igtk, keyconf->key, keyconf->keylen); 27268e160ab8SAyala Beker if (keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) 27278e160ab8SAyala Beker igtk_cmd.ctrl_flags |= 27288e160ab8SAyala Beker cpu_to_le32(STA_KEY_FLG_KEY_32BYTES); 2729e705c121SKalle Valo ieee80211_get_key_rx_seq(keyconf, 0, &seq); 2730e705c121SKalle Valo pn = seq.aes_cmac.pn; 2731e705c121SKalle Valo igtk_cmd.receive_seq_cnt = cpu_to_le64(((u64) pn[5] << 0) | 2732e705c121SKalle Valo ((u64) pn[4] << 8) | 2733e705c121SKalle Valo ((u64) pn[3] << 16) | 2734e705c121SKalle Valo ((u64) pn[2] << 24) | 2735e705c121SKalle Valo ((u64) pn[1] << 32) | 2736e705c121SKalle Valo ((u64) pn[0] << 40)); 2737e705c121SKalle Valo } 2738e705c121SKalle Valo 2739e705c121SKalle Valo IWL_DEBUG_INFO(mvm, "%s igtk for sta %u\n", 2740e705c121SKalle Valo remove_key ? "removing" : "installing", 2741e705c121SKalle Valo igtk_cmd.sta_id); 2742e705c121SKalle Valo 27438e160ab8SAyala Beker if (!iwl_mvm_has_new_rx_api(mvm)) { 27448e160ab8SAyala Beker struct iwl_mvm_mgmt_mcast_key_cmd_v1 igtk_cmd_v1 = { 27458e160ab8SAyala Beker .ctrl_flags = igtk_cmd.ctrl_flags, 27468e160ab8SAyala Beker .key_id = igtk_cmd.key_id, 27478e160ab8SAyala Beker .sta_id = igtk_cmd.sta_id, 27488e160ab8SAyala Beker .receive_seq_cnt = igtk_cmd.receive_seq_cnt 27498e160ab8SAyala Beker }; 27508e160ab8SAyala Beker 27518e160ab8SAyala Beker memcpy(igtk_cmd_v1.igtk, igtk_cmd.igtk, 27528e160ab8SAyala Beker ARRAY_SIZE(igtk_cmd_v1.igtk)); 27538e160ab8SAyala Beker return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0, 27548e160ab8SAyala Beker sizeof(igtk_cmd_v1), &igtk_cmd_v1); 27558e160ab8SAyala Beker } 2756e705c121SKalle Valo return iwl_mvm_send_cmd_pdu(mvm, MGMT_MCAST_KEY, 0, 2757e705c121SKalle Valo sizeof(igtk_cmd), &igtk_cmd); 2758e705c121SKalle Valo } 2759e705c121SKalle Valo 2760e705c121SKalle Valo 2761e705c121SKalle Valo static inline u8 *iwl_mvm_get_mac_addr(struct iwl_mvm *mvm, 2762e705c121SKalle Valo struct ieee80211_vif *vif, 2763e705c121SKalle Valo struct ieee80211_sta *sta) 2764e705c121SKalle Valo { 2765e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 2766e705c121SKalle Valo 2767e705c121SKalle Valo if (sta) 2768e705c121SKalle Valo return sta->addr; 2769e705c121SKalle Valo 2770e705c121SKalle Valo if (vif->type == NL80211_IFTYPE_STATION && 2771e705c121SKalle Valo mvmvif->ap_sta_id != IWL_MVM_STATION_COUNT) { 2772e705c121SKalle Valo u8 sta_id = mvmvif->ap_sta_id; 2773e705c121SKalle Valo sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], 2774e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 2775e705c121SKalle Valo return sta->addr; 2776e705c121SKalle Valo } 2777e705c121SKalle Valo 2778e705c121SKalle Valo 2779e705c121SKalle Valo return NULL; 2780e705c121SKalle Valo } 2781e705c121SKalle Valo 2782e705c121SKalle Valo static int __iwl_mvm_set_sta_key(struct iwl_mvm *mvm, 2783e705c121SKalle Valo struct ieee80211_vif *vif, 2784e705c121SKalle Valo struct ieee80211_sta *sta, 2785e705c121SKalle Valo struct ieee80211_key_conf *keyconf, 27864615fd15SEmmanuel Grumbach u8 key_offset, 2787e705c121SKalle Valo bool mcast) 2788e705c121SKalle Valo { 2789e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 2790e705c121SKalle Valo int ret; 2791e705c121SKalle Valo const u8 *addr; 2792e705c121SKalle Valo struct ieee80211_key_seq seq; 2793e705c121SKalle Valo u16 p1k[5]; 2794e705c121SKalle Valo 2795e705c121SKalle Valo switch (keyconf->cipher) { 2796e705c121SKalle Valo case WLAN_CIPHER_SUITE_TKIP: 2797e705c121SKalle Valo addr = iwl_mvm_get_mac_addr(mvm, vif, sta); 2798e705c121SKalle Valo /* get phase 1 key from mac80211 */ 2799e705c121SKalle Valo ieee80211_get_key_rx_seq(keyconf, 0, &seq); 2800e705c121SKalle Valo ieee80211_get_tkip_rx_p1k(keyconf, addr, seq.tkip.iv32, p1k); 2801e705c121SKalle Valo ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, 28024615fd15SEmmanuel Grumbach seq.tkip.iv32, p1k, 0, key_offset); 2803e705c121SKalle Valo break; 2804e705c121SKalle Valo case WLAN_CIPHER_SUITE_CCMP: 2805e705c121SKalle Valo case WLAN_CIPHER_SUITE_WEP40: 2806e705c121SKalle Valo case WLAN_CIPHER_SUITE_WEP104: 28072a53d166SAyala Beker case WLAN_CIPHER_SUITE_GCMP: 28082a53d166SAyala Beker case WLAN_CIPHER_SUITE_GCMP_256: 2809e705c121SKalle Valo ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, 28104615fd15SEmmanuel Grumbach 0, NULL, 0, key_offset); 2811e705c121SKalle Valo break; 2812e705c121SKalle Valo default: 2813e705c121SKalle Valo ret = iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, 28144615fd15SEmmanuel Grumbach 0, NULL, 0, key_offset); 2815e705c121SKalle Valo } 2816e705c121SKalle Valo 2817e705c121SKalle Valo return ret; 2818e705c121SKalle Valo } 2819e705c121SKalle Valo 2820e705c121SKalle Valo static int __iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, u8 sta_id, 2821e705c121SKalle Valo struct ieee80211_key_conf *keyconf, 2822e705c121SKalle Valo bool mcast) 2823e705c121SKalle Valo { 2824e705c121SKalle Valo struct iwl_mvm_add_sta_key_cmd cmd = {}; 2825e705c121SKalle Valo __le16 key_flags; 2826e705c121SKalle Valo int ret; 2827e705c121SKalle Valo u32 status; 2828e705c121SKalle Valo 2829e705c121SKalle Valo key_flags = cpu_to_le16((keyconf->keyidx << STA_KEY_FLG_KEYID_POS) & 2830e705c121SKalle Valo STA_KEY_FLG_KEYID_MSK); 2831e705c121SKalle Valo key_flags |= cpu_to_le16(STA_KEY_FLG_NO_ENC | STA_KEY_FLG_WEP_KEY_MAP); 2832e705c121SKalle Valo key_flags |= cpu_to_le16(STA_KEY_NOT_VALID); 2833e705c121SKalle Valo 2834e705c121SKalle Valo if (mcast) 2835e705c121SKalle Valo key_flags |= cpu_to_le16(STA_KEY_MULTICAST); 2836e705c121SKalle Valo 2837e705c121SKalle Valo cmd.key_flags = key_flags; 2838e705c121SKalle Valo cmd.key_offset = keyconf->hw_key_idx; 2839e705c121SKalle Valo cmd.sta_id = sta_id; 2840e705c121SKalle Valo 2841e705c121SKalle Valo status = ADD_STA_SUCCESS; 2842e705c121SKalle Valo ret = iwl_mvm_send_cmd_pdu_status(mvm, ADD_STA_KEY, sizeof(cmd), 2843e705c121SKalle Valo &cmd, &status); 2844e705c121SKalle Valo 2845e705c121SKalle Valo switch (status) { 2846e705c121SKalle Valo case ADD_STA_SUCCESS: 2847e705c121SKalle Valo IWL_DEBUG_WEP(mvm, "MODIFY_STA: remove sta key passed\n"); 2848e705c121SKalle Valo break; 2849e705c121SKalle Valo default: 2850e705c121SKalle Valo ret = -EIO; 2851e705c121SKalle Valo IWL_ERR(mvm, "MODIFY_STA: remove sta key failed\n"); 2852e705c121SKalle Valo break; 2853e705c121SKalle Valo } 2854e705c121SKalle Valo 2855e705c121SKalle Valo return ret; 2856e705c121SKalle Valo } 2857e705c121SKalle Valo 2858e705c121SKalle Valo int iwl_mvm_set_sta_key(struct iwl_mvm *mvm, 2859e705c121SKalle Valo struct ieee80211_vif *vif, 2860e705c121SKalle Valo struct ieee80211_sta *sta, 2861e705c121SKalle Valo struct ieee80211_key_conf *keyconf, 28624615fd15SEmmanuel Grumbach u8 key_offset) 2863e705c121SKalle Valo { 2864e705c121SKalle Valo bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); 28655f7a1847SJohannes Berg struct iwl_mvm_sta *mvm_sta; 2866e705c121SKalle Valo u8 sta_id; 2867e705c121SKalle Valo int ret; 2868e705c121SKalle Valo static const u8 __maybe_unused zero_addr[ETH_ALEN] = {0}; 2869e705c121SKalle Valo 2870e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 2871e705c121SKalle Valo 2872e705c121SKalle Valo /* Get the station id from the mvm local station table */ 28735f7a1847SJohannes Berg mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); 28745f7a1847SJohannes Berg if (!mvm_sta) { 28755f7a1847SJohannes Berg IWL_ERR(mvm, "Failed to find station\n"); 2876e705c121SKalle Valo return -EINVAL; 2877e705c121SKalle Valo } 28785f7a1847SJohannes Berg sta_id = mvm_sta->sta_id; 2879e705c121SKalle Valo 28808e160ab8SAyala Beker if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC || 28818e160ab8SAyala Beker keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || 28828e160ab8SAyala Beker keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) { 2883e705c121SKalle Valo ret = iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, false); 2884e705c121SKalle Valo goto end; 2885e705c121SKalle Valo } 2886e705c121SKalle Valo 2887e705c121SKalle Valo /* 2888e705c121SKalle Valo * It is possible that the 'sta' parameter is NULL, and thus 2889e705c121SKalle Valo * there is a need to retrieve the sta from the local station table. 2890e705c121SKalle Valo */ 2891e705c121SKalle Valo if (!sta) { 2892e705c121SKalle Valo sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[sta_id], 2893e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 2894e705c121SKalle Valo if (IS_ERR_OR_NULL(sta)) { 2895e705c121SKalle Valo IWL_ERR(mvm, "Invalid station id\n"); 2896e705c121SKalle Valo return -EINVAL; 2897e705c121SKalle Valo } 2898e705c121SKalle Valo } 2899e705c121SKalle Valo 2900e705c121SKalle Valo if (WARN_ON_ONCE(iwl_mvm_sta_from_mac80211(sta)->vif != vif)) 2901e705c121SKalle Valo return -EINVAL; 2902e705c121SKalle Valo 29034615fd15SEmmanuel Grumbach /* If the key_offset is not pre-assigned, we need to find a 29044615fd15SEmmanuel Grumbach * new offset to use. In normal cases, the offset is not 29054615fd15SEmmanuel Grumbach * pre-assigned, but during HW_RESTART we want to reuse the 29064615fd15SEmmanuel Grumbach * same indices, so we pass them when this function is called. 29074615fd15SEmmanuel Grumbach * 29084615fd15SEmmanuel Grumbach * In D3 entry, we need to hardcoded the indices (because the 29094615fd15SEmmanuel Grumbach * firmware hardcodes the PTK offset to 0). In this case, we 29104615fd15SEmmanuel Grumbach * need to make sure we don't overwrite the hw_key_idx in the 29114615fd15SEmmanuel Grumbach * keyconf structure, because otherwise we cannot configure 29124615fd15SEmmanuel Grumbach * the original ones back when resuming. 2913e705c121SKalle Valo */ 29144615fd15SEmmanuel Grumbach if (key_offset == STA_KEY_IDX_INVALID) { 29154615fd15SEmmanuel Grumbach key_offset = iwl_mvm_set_fw_key_idx(mvm); 29164615fd15SEmmanuel Grumbach if (key_offset == STA_KEY_IDX_INVALID) 2917e705c121SKalle Valo return -ENOSPC; 29184615fd15SEmmanuel Grumbach keyconf->hw_key_idx = key_offset; 2919e705c121SKalle Valo } 2920e705c121SKalle Valo 29214615fd15SEmmanuel Grumbach ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, key_offset, mcast); 29229c3deeb5SLuca Coelho if (ret) 2923e705c121SKalle Valo goto end; 2924e705c121SKalle Valo 2925e705c121SKalle Valo /* 2926e705c121SKalle Valo * For WEP, the same key is used for multicast and unicast. Upload it 2927e705c121SKalle Valo * again, using the same key offset, and now pointing the other one 2928e705c121SKalle Valo * to the same key slot (offset). 2929e705c121SKalle Valo * If this fails, remove the original as well. 2930e705c121SKalle Valo */ 2931e705c121SKalle Valo if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || 2932e705c121SKalle Valo keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) { 29334615fd15SEmmanuel Grumbach ret = __iwl_mvm_set_sta_key(mvm, vif, sta, keyconf, 29344615fd15SEmmanuel Grumbach key_offset, !mcast); 2935e705c121SKalle Valo if (ret) { 2936e705c121SKalle Valo __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast); 29379c3deeb5SLuca Coelho goto end; 2938e705c121SKalle Valo } 2939e705c121SKalle Valo } 2940e705c121SKalle Valo 29419c3deeb5SLuca Coelho __set_bit(key_offset, mvm->fw_key_table); 29429c3deeb5SLuca Coelho 2943e705c121SKalle Valo end: 2944e705c121SKalle Valo IWL_DEBUG_WEP(mvm, "key: cipher=%x len=%d idx=%d sta=%pM ret=%d\n", 2945e705c121SKalle Valo keyconf->cipher, keyconf->keylen, keyconf->keyidx, 2946e705c121SKalle Valo sta ? sta->addr : zero_addr, ret); 2947e705c121SKalle Valo return ret; 2948e705c121SKalle Valo } 2949e705c121SKalle Valo 2950e705c121SKalle Valo int iwl_mvm_remove_sta_key(struct iwl_mvm *mvm, 2951e705c121SKalle Valo struct ieee80211_vif *vif, 2952e705c121SKalle Valo struct ieee80211_sta *sta, 2953e705c121SKalle Valo struct ieee80211_key_conf *keyconf) 2954e705c121SKalle Valo { 2955e705c121SKalle Valo bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); 29565f7a1847SJohannes Berg struct iwl_mvm_sta *mvm_sta; 29575f7a1847SJohannes Berg u8 sta_id = IWL_MVM_STATION_COUNT; 2958e705c121SKalle Valo int ret, i; 2959e705c121SKalle Valo 2960e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 2961e705c121SKalle Valo 29625f7a1847SJohannes Berg /* Get the station from the mvm local station table */ 29635f7a1847SJohannes Berg mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); 2964e705c121SKalle Valo 2965e705c121SKalle Valo IWL_DEBUG_WEP(mvm, "mvm remove dynamic key: idx=%d sta=%d\n", 2966e705c121SKalle Valo keyconf->keyidx, sta_id); 2967e705c121SKalle Valo 29688e160ab8SAyala Beker if (keyconf->cipher == WLAN_CIPHER_SUITE_AES_CMAC || 29698e160ab8SAyala Beker keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_128 || 29708e160ab8SAyala Beker keyconf->cipher == WLAN_CIPHER_SUITE_BIP_GMAC_256) 2971e705c121SKalle Valo return iwl_mvm_send_sta_igtk(mvm, keyconf, sta_id, true); 2972e705c121SKalle Valo 2973e705c121SKalle Valo if (!__test_and_clear_bit(keyconf->hw_key_idx, mvm->fw_key_table)) { 2974e705c121SKalle Valo IWL_ERR(mvm, "offset %d not used in fw key table.\n", 2975e705c121SKalle Valo keyconf->hw_key_idx); 2976e705c121SKalle Valo return -ENOENT; 2977e705c121SKalle Valo } 2978e705c121SKalle Valo 2979e705c121SKalle Valo /* track which key was deleted last */ 2980e705c121SKalle Valo for (i = 0; i < STA_KEY_MAX_NUM; i++) { 2981e705c121SKalle Valo if (mvm->fw_key_deleted[i] < U8_MAX) 2982e705c121SKalle Valo mvm->fw_key_deleted[i]++; 2983e705c121SKalle Valo } 2984e705c121SKalle Valo mvm->fw_key_deleted[keyconf->hw_key_idx] = 0; 2985e705c121SKalle Valo 29865f7a1847SJohannes Berg if (!mvm_sta) { 2987e705c121SKalle Valo IWL_DEBUG_WEP(mvm, "station non-existent, early return.\n"); 2988e705c121SKalle Valo return 0; 2989e705c121SKalle Valo } 2990e705c121SKalle Valo 29915f7a1847SJohannes Berg sta_id = mvm_sta->sta_id; 29925f7a1847SJohannes Berg 2993e705c121SKalle Valo ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, mcast); 2994e705c121SKalle Valo if (ret) 2995e705c121SKalle Valo return ret; 2996e705c121SKalle Valo 2997e705c121SKalle Valo /* delete WEP key twice to get rid of (now useless) offset */ 2998e705c121SKalle Valo if (keyconf->cipher == WLAN_CIPHER_SUITE_WEP40 || 2999e705c121SKalle Valo keyconf->cipher == WLAN_CIPHER_SUITE_WEP104) 3000e705c121SKalle Valo ret = __iwl_mvm_remove_sta_key(mvm, sta_id, keyconf, !mcast); 3001e705c121SKalle Valo 3002e705c121SKalle Valo return ret; 3003e705c121SKalle Valo } 3004e705c121SKalle Valo 3005e705c121SKalle Valo void iwl_mvm_update_tkip_key(struct iwl_mvm *mvm, 3006e705c121SKalle Valo struct ieee80211_vif *vif, 3007e705c121SKalle Valo struct ieee80211_key_conf *keyconf, 3008e705c121SKalle Valo struct ieee80211_sta *sta, u32 iv32, 3009e705c121SKalle Valo u16 *phase1key) 3010e705c121SKalle Valo { 3011e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta; 3012e705c121SKalle Valo bool mcast = !(keyconf->flags & IEEE80211_KEY_FLAG_PAIRWISE); 3013e705c121SKalle Valo 3014e705c121SKalle Valo rcu_read_lock(); 3015e705c121SKalle Valo 30165f7a1847SJohannes Berg mvm_sta = iwl_mvm_get_key_sta(mvm, vif, sta); 30175f7a1847SJohannes Berg if (WARN_ON_ONCE(!mvm_sta)) 301812f17211SEmmanuel Grumbach goto unlock; 3019e705c121SKalle Valo iwl_mvm_send_sta_key(mvm, mvm_sta, keyconf, mcast, 30204615fd15SEmmanuel Grumbach iv32, phase1key, CMD_ASYNC, keyconf->hw_key_idx); 302112f17211SEmmanuel Grumbach 302212f17211SEmmanuel Grumbach unlock: 3023e705c121SKalle Valo rcu_read_unlock(); 3024e705c121SKalle Valo } 3025e705c121SKalle Valo 3026e705c121SKalle Valo void iwl_mvm_sta_modify_ps_wake(struct iwl_mvm *mvm, 3027e705c121SKalle Valo struct ieee80211_sta *sta) 3028e705c121SKalle Valo { 3029e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 3030e705c121SKalle Valo struct iwl_mvm_add_sta_cmd cmd = { 3031e705c121SKalle Valo .add_modify = STA_MODE_MODIFY, 3032e705c121SKalle Valo .sta_id = mvmsta->sta_id, 3033e705c121SKalle Valo .station_flags_msk = cpu_to_le32(STA_FLG_PS), 3034e705c121SKalle Valo .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), 3035e705c121SKalle Valo }; 3036e705c121SKalle Valo int ret; 3037e705c121SKalle Valo 3038854c5705SSara Sharon ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, 3039854c5705SSara Sharon iwl_mvm_add_sta_cmd_size(mvm), &cmd); 3040e705c121SKalle Valo if (ret) 3041e705c121SKalle Valo IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); 3042e705c121SKalle Valo } 3043e705c121SKalle Valo 3044e705c121SKalle Valo void iwl_mvm_sta_modify_sleep_tx_count(struct iwl_mvm *mvm, 3045e705c121SKalle Valo struct ieee80211_sta *sta, 3046e705c121SKalle Valo enum ieee80211_frame_release_type reason, 3047e705c121SKalle Valo u16 cnt, u16 tids, bool more_data, 3048e705c121SKalle Valo bool agg) 3049e705c121SKalle Valo { 3050e705c121SKalle Valo struct iwl_mvm_sta *mvmsta = iwl_mvm_sta_from_mac80211(sta); 3051e705c121SKalle Valo struct iwl_mvm_add_sta_cmd cmd = { 3052e705c121SKalle Valo .add_modify = STA_MODE_MODIFY, 3053e705c121SKalle Valo .sta_id = mvmsta->sta_id, 3054e705c121SKalle Valo .modify_mask = STA_MODIFY_SLEEPING_STA_TX_COUNT, 3055e705c121SKalle Valo .sleep_tx_count = cpu_to_le16(cnt), 3056e705c121SKalle Valo .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), 3057e705c121SKalle Valo }; 3058e705c121SKalle Valo int tid, ret; 3059e705c121SKalle Valo unsigned long _tids = tids; 3060e705c121SKalle Valo 3061e705c121SKalle Valo /* convert TIDs to ACs - we don't support TSPEC so that's OK 3062e705c121SKalle Valo * Note that this field is reserved and unused by firmware not 3063e705c121SKalle Valo * supporting GO uAPSD, so it's safe to always do this. 3064e705c121SKalle Valo */ 3065e705c121SKalle Valo for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) 3066e705c121SKalle Valo cmd.awake_acs |= BIT(tid_to_ucode_ac[tid]); 3067e705c121SKalle Valo 3068e705c121SKalle Valo /* If we're releasing frames from aggregation queues then check if the 3069e705c121SKalle Valo * all queues combined that we're releasing frames from have 3070e705c121SKalle Valo * - more frames than the service period, in which case more_data 3071e705c121SKalle Valo * needs to be set 3072e705c121SKalle Valo * - fewer than 'cnt' frames, in which case we need to adjust the 3073e705c121SKalle Valo * firmware command (but do that unconditionally) 3074e705c121SKalle Valo */ 3075e705c121SKalle Valo if (agg) { 3076e705c121SKalle Valo int remaining = cnt; 307736be0eb6SEmmanuel Grumbach int sleep_tx_count; 3078e705c121SKalle Valo 3079e705c121SKalle Valo spin_lock_bh(&mvmsta->lock); 3080e705c121SKalle Valo for_each_set_bit(tid, &_tids, IWL_MAX_TID_COUNT) { 3081e705c121SKalle Valo struct iwl_mvm_tid_data *tid_data; 3082e705c121SKalle Valo u16 n_queued; 3083e705c121SKalle Valo 3084e705c121SKalle Valo tid_data = &mvmsta->tid_data[tid]; 3085e705c121SKalle Valo if (WARN(tid_data->state != IWL_AGG_ON && 3086e705c121SKalle Valo tid_data->state != IWL_EMPTYING_HW_QUEUE_DELBA, 3087e705c121SKalle Valo "TID %d state is %d\n", 3088e705c121SKalle Valo tid, tid_data->state)) { 3089e705c121SKalle Valo spin_unlock_bh(&mvmsta->lock); 3090e705c121SKalle Valo ieee80211_sta_eosp(sta); 3091e705c121SKalle Valo return; 3092e705c121SKalle Valo } 3093e705c121SKalle Valo 3094e705c121SKalle Valo n_queued = iwl_mvm_tid_queued(tid_data); 3095e705c121SKalle Valo if (n_queued > remaining) { 3096e705c121SKalle Valo more_data = true; 3097e705c121SKalle Valo remaining = 0; 3098e705c121SKalle Valo break; 3099e705c121SKalle Valo } 3100e705c121SKalle Valo remaining -= n_queued; 3101e705c121SKalle Valo } 310236be0eb6SEmmanuel Grumbach sleep_tx_count = cnt - remaining; 310336be0eb6SEmmanuel Grumbach if (reason == IEEE80211_FRAME_RELEASE_UAPSD) 310436be0eb6SEmmanuel Grumbach mvmsta->sleep_tx_count = sleep_tx_count; 3105e705c121SKalle Valo spin_unlock_bh(&mvmsta->lock); 3106e705c121SKalle Valo 310736be0eb6SEmmanuel Grumbach cmd.sleep_tx_count = cpu_to_le16(sleep_tx_count); 3108e705c121SKalle Valo if (WARN_ON(cnt - remaining == 0)) { 3109e705c121SKalle Valo ieee80211_sta_eosp(sta); 3110e705c121SKalle Valo return; 3111e705c121SKalle Valo } 3112e705c121SKalle Valo } 3113e705c121SKalle Valo 3114e705c121SKalle Valo /* Note: this is ignored by firmware not supporting GO uAPSD */ 3115e705c121SKalle Valo if (more_data) 3116e705c121SKalle Valo cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_MOREDATA); 3117e705c121SKalle Valo 3118e705c121SKalle Valo if (reason == IEEE80211_FRAME_RELEASE_PSPOLL) { 3119e705c121SKalle Valo mvmsta->next_status_eosp = true; 3120e705c121SKalle Valo cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_PS_POLL); 3121e705c121SKalle Valo } else { 3122e705c121SKalle Valo cmd.sleep_state_flags |= cpu_to_le16(STA_SLEEP_STATE_UAPSD); 3123e705c121SKalle Valo } 3124e705c121SKalle Valo 3125156f92f2SEmmanuel Grumbach /* block the Tx queues until the FW updated the sleep Tx count */ 3126156f92f2SEmmanuel Grumbach iwl_trans_block_txq_ptrs(mvm->trans, true); 3127156f92f2SEmmanuel Grumbach 3128156f92f2SEmmanuel Grumbach ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, 3129156f92f2SEmmanuel Grumbach CMD_ASYNC | CMD_WANT_ASYNC_CALLBACK, 3130854c5705SSara Sharon iwl_mvm_add_sta_cmd_size(mvm), &cmd); 3131e705c121SKalle Valo if (ret) 3132e705c121SKalle Valo IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); 3133e705c121SKalle Valo } 3134e705c121SKalle Valo 3135e705c121SKalle Valo void iwl_mvm_rx_eosp_notif(struct iwl_mvm *mvm, 3136e705c121SKalle Valo struct iwl_rx_cmd_buffer *rxb) 3137e705c121SKalle Valo { 3138e705c121SKalle Valo struct iwl_rx_packet *pkt = rxb_addr(rxb); 3139e705c121SKalle Valo struct iwl_mvm_eosp_notification *notif = (void *)pkt->data; 3140e705c121SKalle Valo struct ieee80211_sta *sta; 3141e705c121SKalle Valo u32 sta_id = le32_to_cpu(notif->sta_id); 3142e705c121SKalle Valo 3143e705c121SKalle Valo if (WARN_ON_ONCE(sta_id >= IWL_MVM_STATION_COUNT)) 3144e705c121SKalle Valo return; 3145e705c121SKalle Valo 3146e705c121SKalle Valo rcu_read_lock(); 3147e705c121SKalle Valo sta = rcu_dereference(mvm->fw_id_to_mac_id[sta_id]); 3148e705c121SKalle Valo if (!IS_ERR_OR_NULL(sta)) 3149e705c121SKalle Valo ieee80211_sta_eosp(sta); 3150e705c121SKalle Valo rcu_read_unlock(); 3151e705c121SKalle Valo } 3152e705c121SKalle Valo 3153e705c121SKalle Valo void iwl_mvm_sta_modify_disable_tx(struct iwl_mvm *mvm, 3154e705c121SKalle Valo struct iwl_mvm_sta *mvmsta, bool disable) 3155e705c121SKalle Valo { 3156e705c121SKalle Valo struct iwl_mvm_add_sta_cmd cmd = { 3157e705c121SKalle Valo .add_modify = STA_MODE_MODIFY, 3158e705c121SKalle Valo .sta_id = mvmsta->sta_id, 3159e705c121SKalle Valo .station_flags = disable ? cpu_to_le32(STA_FLG_DISABLE_TX) : 0, 3160e705c121SKalle Valo .station_flags_msk = cpu_to_le32(STA_FLG_DISABLE_TX), 3161e705c121SKalle Valo .mac_id_n_color = cpu_to_le32(mvmsta->mac_id_n_color), 3162e705c121SKalle Valo }; 3163e705c121SKalle Valo int ret; 3164e705c121SKalle Valo 3165854c5705SSara Sharon ret = iwl_mvm_send_cmd_pdu(mvm, ADD_STA, CMD_ASYNC, 3166854c5705SSara Sharon iwl_mvm_add_sta_cmd_size(mvm), &cmd); 3167e705c121SKalle Valo if (ret) 3168e705c121SKalle Valo IWL_ERR(mvm, "Failed to send ADD_STA command (%d)\n", ret); 3169e705c121SKalle Valo } 3170e705c121SKalle Valo 3171e705c121SKalle Valo void iwl_mvm_sta_modify_disable_tx_ap(struct iwl_mvm *mvm, 3172e705c121SKalle Valo struct ieee80211_sta *sta, 3173e705c121SKalle Valo bool disable) 3174e705c121SKalle Valo { 3175e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta = iwl_mvm_sta_from_mac80211(sta); 3176e705c121SKalle Valo 3177e705c121SKalle Valo spin_lock_bh(&mvm_sta->lock); 3178e705c121SKalle Valo 3179e705c121SKalle Valo if (mvm_sta->disable_tx == disable) { 3180e705c121SKalle Valo spin_unlock_bh(&mvm_sta->lock); 3181e705c121SKalle Valo return; 3182e705c121SKalle Valo } 3183e705c121SKalle Valo 3184e705c121SKalle Valo mvm_sta->disable_tx = disable; 3185e705c121SKalle Valo 3186e705c121SKalle Valo /* 3187e705c121SKalle Valo * Tell mac80211 to start/stop queuing tx for this station, 3188e705c121SKalle Valo * but don't stop queuing if there are still pending frames 3189e705c121SKalle Valo * for this station. 3190e705c121SKalle Valo */ 3191e705c121SKalle Valo if (disable || !atomic_read(&mvm->pending_frames[mvm_sta->sta_id])) 3192e705c121SKalle Valo ieee80211_sta_block_awake(mvm->hw, sta, disable); 3193e705c121SKalle Valo 3194e705c121SKalle Valo iwl_mvm_sta_modify_disable_tx(mvm, mvm_sta, disable); 3195e705c121SKalle Valo 3196e705c121SKalle Valo spin_unlock_bh(&mvm_sta->lock); 3197e705c121SKalle Valo } 3198e705c121SKalle Valo 3199e705c121SKalle Valo void iwl_mvm_modify_all_sta_disable_tx(struct iwl_mvm *mvm, 3200e705c121SKalle Valo struct iwl_mvm_vif *mvmvif, 3201e705c121SKalle Valo bool disable) 3202e705c121SKalle Valo { 3203e705c121SKalle Valo struct ieee80211_sta *sta; 3204e705c121SKalle Valo struct iwl_mvm_sta *mvm_sta; 3205e705c121SKalle Valo int i; 3206e705c121SKalle Valo 3207e705c121SKalle Valo lockdep_assert_held(&mvm->mutex); 3208e705c121SKalle Valo 3209e705c121SKalle Valo /* Block/unblock all the stations of the given mvmvif */ 3210e705c121SKalle Valo for (i = 0; i < IWL_MVM_STATION_COUNT; i++) { 3211e705c121SKalle Valo sta = rcu_dereference_protected(mvm->fw_id_to_mac_id[i], 3212e705c121SKalle Valo lockdep_is_held(&mvm->mutex)); 3213e705c121SKalle Valo if (IS_ERR_OR_NULL(sta)) 3214e705c121SKalle Valo continue; 3215e705c121SKalle Valo 3216e705c121SKalle Valo mvm_sta = iwl_mvm_sta_from_mac80211(sta); 3217e705c121SKalle Valo if (mvm_sta->mac_id_n_color != 3218e705c121SKalle Valo FW_CMD_ID_AND_COLOR(mvmvif->id, mvmvif->color)) 3219e705c121SKalle Valo continue; 3220e705c121SKalle Valo 3221e705c121SKalle Valo iwl_mvm_sta_modify_disable_tx_ap(mvm, sta, disable); 3222e705c121SKalle Valo } 3223e705c121SKalle Valo } 3224e705c121SKalle Valo 3225e705c121SKalle Valo void iwl_mvm_csa_client_absent(struct iwl_mvm *mvm, struct ieee80211_vif *vif) 3226e705c121SKalle Valo { 3227e705c121SKalle Valo struct iwl_mvm_vif *mvmvif = iwl_mvm_vif_from_mac80211(vif); 3228e705c121SKalle Valo struct iwl_mvm_sta *mvmsta; 3229e705c121SKalle Valo 3230e705c121SKalle Valo rcu_read_lock(); 3231e705c121SKalle Valo 3232e705c121SKalle Valo mvmsta = iwl_mvm_sta_from_staid_rcu(mvm, mvmvif->ap_sta_id); 3233e705c121SKalle Valo 3234e705c121SKalle Valo if (!WARN_ON(!mvmsta)) 3235e705c121SKalle Valo iwl_mvm_sta_modify_disable_tx(mvm, mvmsta, true); 3236e705c121SKalle Valo 3237e705c121SKalle Valo rcu_read_unlock(); 3238e705c121SKalle Valo } 3239