18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0-only 28c2ecf20Sopenharmony_ci/****************************************************************************** 38c2ecf20Sopenharmony_ci * 48c2ecf20Sopenharmony_ci * Copyright(c) 2008 - 2014 Intel Corporation. All rights reserved. 58c2ecf20Sopenharmony_ci * Copyright (C) 2019 Intel Corporation 68c2ecf20Sopenharmony_ci * 78c2ecf20Sopenharmony_ci * Contact Information: 88c2ecf20Sopenharmony_ci * Intel Linux Wireless <linuxwifi@intel.com> 98c2ecf20Sopenharmony_ci * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 108c2ecf20Sopenharmony_ci * 118c2ecf20Sopenharmony_ci *****************************************************************************/ 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#include <linux/kernel.h> 148c2ecf20Sopenharmony_ci#include <linux/module.h> 158c2ecf20Sopenharmony_ci#include <linux/sched.h> 168c2ecf20Sopenharmony_ci#include <linux/ieee80211.h> 178c2ecf20Sopenharmony_ci#include "iwl-io.h" 188c2ecf20Sopenharmony_ci#include "iwl-trans.h" 198c2ecf20Sopenharmony_ci#include "iwl-agn-hw.h" 208c2ecf20Sopenharmony_ci#include "dev.h" 218c2ecf20Sopenharmony_ci#include "agn.h" 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_cistatic const u8 tid_to_ac[] = { 248c2ecf20Sopenharmony_ci IEEE80211_AC_BE, 258c2ecf20Sopenharmony_ci IEEE80211_AC_BK, 268c2ecf20Sopenharmony_ci IEEE80211_AC_BK, 278c2ecf20Sopenharmony_ci IEEE80211_AC_BE, 288c2ecf20Sopenharmony_ci IEEE80211_AC_VI, 298c2ecf20Sopenharmony_ci IEEE80211_AC_VI, 308c2ecf20Sopenharmony_ci IEEE80211_AC_VO, 318c2ecf20Sopenharmony_ci IEEE80211_AC_VO, 328c2ecf20Sopenharmony_ci}; 338c2ecf20Sopenharmony_ci 348c2ecf20Sopenharmony_cistatic void iwlagn_tx_cmd_protection(struct iwl_priv *priv, 358c2ecf20Sopenharmony_ci struct ieee80211_tx_info *info, 368c2ecf20Sopenharmony_ci __le16 fc, __le32 *tx_flags) 378c2ecf20Sopenharmony_ci{ 388c2ecf20Sopenharmony_ci if (info->control.rates[0].flags & IEEE80211_TX_RC_USE_RTS_CTS || 398c2ecf20Sopenharmony_ci info->control.rates[0].flags & IEEE80211_TX_RC_USE_CTS_PROTECT || 408c2ecf20Sopenharmony_ci info->flags & IEEE80211_TX_CTL_AMPDU) 418c2ecf20Sopenharmony_ci *tx_flags |= TX_CMD_FLG_PROT_REQUIRE_MSK; 428c2ecf20Sopenharmony_ci} 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_ci/* 458c2ecf20Sopenharmony_ci * handle build REPLY_TX command notification. 468c2ecf20Sopenharmony_ci */ 478c2ecf20Sopenharmony_cistatic void iwlagn_tx_cmd_build_basic(struct iwl_priv *priv, 488c2ecf20Sopenharmony_ci struct sk_buff *skb, 498c2ecf20Sopenharmony_ci struct iwl_tx_cmd *tx_cmd, 508c2ecf20Sopenharmony_ci struct ieee80211_tx_info *info, 518c2ecf20Sopenharmony_ci struct ieee80211_hdr *hdr, u8 sta_id) 528c2ecf20Sopenharmony_ci{ 538c2ecf20Sopenharmony_ci __le16 fc = hdr->frame_control; 548c2ecf20Sopenharmony_ci __le32 tx_flags = tx_cmd->tx_flags; 558c2ecf20Sopenharmony_ci 568c2ecf20Sopenharmony_ci tx_cmd->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; 578c2ecf20Sopenharmony_ci 588c2ecf20Sopenharmony_ci if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) 598c2ecf20Sopenharmony_ci tx_flags |= TX_CMD_FLG_ACK_MSK; 608c2ecf20Sopenharmony_ci else 618c2ecf20Sopenharmony_ci tx_flags &= ~TX_CMD_FLG_ACK_MSK; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci if (ieee80211_is_probe_resp(fc)) 648c2ecf20Sopenharmony_ci tx_flags |= TX_CMD_FLG_TSF_MSK; 658c2ecf20Sopenharmony_ci else if (ieee80211_is_back_req(fc)) 668c2ecf20Sopenharmony_ci tx_flags |= TX_CMD_FLG_ACK_MSK | TX_CMD_FLG_IMM_BA_RSP_MASK; 678c2ecf20Sopenharmony_ci else if (info->band == NL80211_BAND_2GHZ && 688c2ecf20Sopenharmony_ci priv->lib->bt_params && 698c2ecf20Sopenharmony_ci priv->lib->bt_params->advanced_bt_coexist && 708c2ecf20Sopenharmony_ci (ieee80211_is_auth(fc) || ieee80211_is_assoc_req(fc) || 718c2ecf20Sopenharmony_ci ieee80211_is_reassoc_req(fc) || 728c2ecf20Sopenharmony_ci info->control.flags & IEEE80211_TX_CTRL_PORT_CTRL_PROTO)) 738c2ecf20Sopenharmony_ci tx_flags |= TX_CMD_FLG_IGNORE_BT; 748c2ecf20Sopenharmony_ci 758c2ecf20Sopenharmony_ci 768c2ecf20Sopenharmony_ci tx_cmd->sta_id = sta_id; 778c2ecf20Sopenharmony_ci if (ieee80211_has_morefrags(fc)) 788c2ecf20Sopenharmony_ci tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK; 798c2ecf20Sopenharmony_ci 808c2ecf20Sopenharmony_ci if (ieee80211_is_data_qos(fc)) { 818c2ecf20Sopenharmony_ci u8 *qc = ieee80211_get_qos_ctl(hdr); 828c2ecf20Sopenharmony_ci tx_cmd->tid_tspec = qc[0] & 0xf; 838c2ecf20Sopenharmony_ci tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; 848c2ecf20Sopenharmony_ci } else { 858c2ecf20Sopenharmony_ci tx_cmd->tid_tspec = IWL_TID_NON_QOS; 868c2ecf20Sopenharmony_ci if (info->flags & IEEE80211_TX_CTL_ASSIGN_SEQ) 878c2ecf20Sopenharmony_ci tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK; 888c2ecf20Sopenharmony_ci else 898c2ecf20Sopenharmony_ci tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK; 908c2ecf20Sopenharmony_ci } 918c2ecf20Sopenharmony_ci 928c2ecf20Sopenharmony_ci iwlagn_tx_cmd_protection(priv, info, fc, &tx_flags); 938c2ecf20Sopenharmony_ci 948c2ecf20Sopenharmony_ci tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK); 958c2ecf20Sopenharmony_ci if (ieee80211_is_mgmt(fc)) { 968c2ecf20Sopenharmony_ci if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc)) 978c2ecf20Sopenharmony_ci tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(3); 988c2ecf20Sopenharmony_ci else 998c2ecf20Sopenharmony_ci tx_cmd->timeout.pm_frame_timeout = cpu_to_le16(2); 1008c2ecf20Sopenharmony_ci } else { 1018c2ecf20Sopenharmony_ci tx_cmd->timeout.pm_frame_timeout = 0; 1028c2ecf20Sopenharmony_ci } 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci tx_cmd->driver_txop = 0; 1058c2ecf20Sopenharmony_ci tx_cmd->tx_flags = tx_flags; 1068c2ecf20Sopenharmony_ci tx_cmd->next_frame_len = 0; 1078c2ecf20Sopenharmony_ci} 1088c2ecf20Sopenharmony_ci 1098c2ecf20Sopenharmony_cistatic void iwlagn_tx_cmd_build_rate(struct iwl_priv *priv, 1108c2ecf20Sopenharmony_ci struct iwl_tx_cmd *tx_cmd, 1118c2ecf20Sopenharmony_ci struct ieee80211_tx_info *info, 1128c2ecf20Sopenharmony_ci struct ieee80211_sta *sta, 1138c2ecf20Sopenharmony_ci __le16 fc) 1148c2ecf20Sopenharmony_ci{ 1158c2ecf20Sopenharmony_ci u32 rate_flags; 1168c2ecf20Sopenharmony_ci int rate_idx; 1178c2ecf20Sopenharmony_ci u8 rts_retry_limit; 1188c2ecf20Sopenharmony_ci u8 data_retry_limit; 1198c2ecf20Sopenharmony_ci u8 rate_plcp; 1208c2ecf20Sopenharmony_ci 1218c2ecf20Sopenharmony_ci if (priv->wowlan) { 1228c2ecf20Sopenharmony_ci rts_retry_limit = IWLAGN_LOW_RETRY_LIMIT; 1238c2ecf20Sopenharmony_ci data_retry_limit = IWLAGN_LOW_RETRY_LIMIT; 1248c2ecf20Sopenharmony_ci } else { 1258c2ecf20Sopenharmony_ci /* Set retry limit on RTS packets */ 1268c2ecf20Sopenharmony_ci rts_retry_limit = IWLAGN_RTS_DFAULT_RETRY_LIMIT; 1278c2ecf20Sopenharmony_ci 1288c2ecf20Sopenharmony_ci /* Set retry limit on DATA packets and Probe Responses*/ 1298c2ecf20Sopenharmony_ci if (ieee80211_is_probe_resp(fc)) { 1308c2ecf20Sopenharmony_ci data_retry_limit = IWLAGN_MGMT_DFAULT_RETRY_LIMIT; 1318c2ecf20Sopenharmony_ci rts_retry_limit = 1328c2ecf20Sopenharmony_ci min(data_retry_limit, rts_retry_limit); 1338c2ecf20Sopenharmony_ci } else if (ieee80211_is_back_req(fc)) 1348c2ecf20Sopenharmony_ci data_retry_limit = IWLAGN_BAR_DFAULT_RETRY_LIMIT; 1358c2ecf20Sopenharmony_ci else 1368c2ecf20Sopenharmony_ci data_retry_limit = IWLAGN_DEFAULT_TX_RETRY; 1378c2ecf20Sopenharmony_ci } 1388c2ecf20Sopenharmony_ci 1398c2ecf20Sopenharmony_ci tx_cmd->data_retry_limit = data_retry_limit; 1408c2ecf20Sopenharmony_ci tx_cmd->rts_retry_limit = rts_retry_limit; 1418c2ecf20Sopenharmony_ci 1428c2ecf20Sopenharmony_ci /* DATA packets will use the uCode station table for rate/antenna 1438c2ecf20Sopenharmony_ci * selection */ 1448c2ecf20Sopenharmony_ci if (ieee80211_is_data(fc)) { 1458c2ecf20Sopenharmony_ci tx_cmd->initial_rate_index = 0; 1468c2ecf20Sopenharmony_ci tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK; 1478c2ecf20Sopenharmony_ci return; 1488c2ecf20Sopenharmony_ci } else if (ieee80211_is_back_req(fc)) 1498c2ecf20Sopenharmony_ci tx_cmd->tx_flags |= TX_CMD_FLG_STA_RATE_MSK; 1508c2ecf20Sopenharmony_ci 1518c2ecf20Sopenharmony_ci /** 1528c2ecf20Sopenharmony_ci * If the current TX rate stored in mac80211 has the MCS bit set, it's 1538c2ecf20Sopenharmony_ci * not really a TX rate. Thus, we use the lowest supported rate for 1548c2ecf20Sopenharmony_ci * this band. Also use the lowest supported rate if the stored rate 1558c2ecf20Sopenharmony_ci * index is invalid. 1568c2ecf20Sopenharmony_ci */ 1578c2ecf20Sopenharmony_ci rate_idx = info->control.rates[0].idx; 1588c2ecf20Sopenharmony_ci if (info->control.rates[0].flags & IEEE80211_TX_RC_MCS || 1598c2ecf20Sopenharmony_ci (rate_idx < 0) || (rate_idx > IWL_RATE_COUNT_LEGACY)) 1608c2ecf20Sopenharmony_ci rate_idx = rate_lowest_index( 1618c2ecf20Sopenharmony_ci &priv->nvm_data->bands[info->band], sta); 1628c2ecf20Sopenharmony_ci /* For 5 GHZ band, remap mac80211 rate indices into driver indices */ 1638c2ecf20Sopenharmony_ci if (info->band == NL80211_BAND_5GHZ) 1648c2ecf20Sopenharmony_ci rate_idx += IWL_FIRST_OFDM_RATE; 1658c2ecf20Sopenharmony_ci /* Get PLCP rate for tx_cmd->rate_n_flags */ 1668c2ecf20Sopenharmony_ci rate_plcp = iwl_rates[rate_idx].plcp; 1678c2ecf20Sopenharmony_ci /* Zero out flags for this packet */ 1688c2ecf20Sopenharmony_ci rate_flags = 0; 1698c2ecf20Sopenharmony_ci 1708c2ecf20Sopenharmony_ci /* Set CCK flag as needed */ 1718c2ecf20Sopenharmony_ci if ((rate_idx >= IWL_FIRST_CCK_RATE) && (rate_idx <= IWL_LAST_CCK_RATE)) 1728c2ecf20Sopenharmony_ci rate_flags |= RATE_MCS_CCK_MSK; 1738c2ecf20Sopenharmony_ci 1748c2ecf20Sopenharmony_ci /* Set up antennas */ 1758c2ecf20Sopenharmony_ci if (priv->lib->bt_params && 1768c2ecf20Sopenharmony_ci priv->lib->bt_params->advanced_bt_coexist && 1778c2ecf20Sopenharmony_ci priv->bt_full_concurrent) { 1788c2ecf20Sopenharmony_ci /* operated as 1x1 in full concurrency mode */ 1798c2ecf20Sopenharmony_ci priv->mgmt_tx_ant = iwl_toggle_tx_ant(priv, priv->mgmt_tx_ant, 1808c2ecf20Sopenharmony_ci first_antenna(priv->nvm_data->valid_tx_ant)); 1818c2ecf20Sopenharmony_ci } else 1828c2ecf20Sopenharmony_ci priv->mgmt_tx_ant = iwl_toggle_tx_ant( 1838c2ecf20Sopenharmony_ci priv, priv->mgmt_tx_ant, 1848c2ecf20Sopenharmony_ci priv->nvm_data->valid_tx_ant); 1858c2ecf20Sopenharmony_ci rate_flags |= iwl_ant_idx_to_flags(priv->mgmt_tx_ant); 1868c2ecf20Sopenharmony_ci 1878c2ecf20Sopenharmony_ci /* Set the rate in the TX cmd */ 1888c2ecf20Sopenharmony_ci tx_cmd->rate_n_flags = iwl_hw_set_rate_n_flags(rate_plcp, rate_flags); 1898c2ecf20Sopenharmony_ci} 1908c2ecf20Sopenharmony_ci 1918c2ecf20Sopenharmony_cistatic void iwlagn_tx_cmd_build_hwcrypto(struct iwl_priv *priv, 1928c2ecf20Sopenharmony_ci struct ieee80211_tx_info *info, 1938c2ecf20Sopenharmony_ci struct iwl_tx_cmd *tx_cmd, 1948c2ecf20Sopenharmony_ci struct sk_buff *skb_frag) 1958c2ecf20Sopenharmony_ci{ 1968c2ecf20Sopenharmony_ci struct ieee80211_key_conf *keyconf = info->control.hw_key; 1978c2ecf20Sopenharmony_ci 1988c2ecf20Sopenharmony_ci switch (keyconf->cipher) { 1998c2ecf20Sopenharmony_ci case WLAN_CIPHER_SUITE_CCMP: 2008c2ecf20Sopenharmony_ci tx_cmd->sec_ctl = TX_CMD_SEC_CCM; 2018c2ecf20Sopenharmony_ci memcpy(tx_cmd->key, keyconf->key, keyconf->keylen); 2028c2ecf20Sopenharmony_ci if (info->flags & IEEE80211_TX_CTL_AMPDU) 2038c2ecf20Sopenharmony_ci tx_cmd->tx_flags |= TX_CMD_FLG_AGG_CCMP_MSK; 2048c2ecf20Sopenharmony_ci break; 2058c2ecf20Sopenharmony_ci 2068c2ecf20Sopenharmony_ci case WLAN_CIPHER_SUITE_TKIP: 2078c2ecf20Sopenharmony_ci tx_cmd->sec_ctl = TX_CMD_SEC_TKIP; 2088c2ecf20Sopenharmony_ci ieee80211_get_tkip_p2k(keyconf, skb_frag, tx_cmd->key); 2098c2ecf20Sopenharmony_ci break; 2108c2ecf20Sopenharmony_ci 2118c2ecf20Sopenharmony_ci case WLAN_CIPHER_SUITE_WEP104: 2128c2ecf20Sopenharmony_ci tx_cmd->sec_ctl |= TX_CMD_SEC_KEY128; 2138c2ecf20Sopenharmony_ci /* fall through */ 2148c2ecf20Sopenharmony_ci case WLAN_CIPHER_SUITE_WEP40: 2158c2ecf20Sopenharmony_ci tx_cmd->sec_ctl |= (TX_CMD_SEC_WEP | 2168c2ecf20Sopenharmony_ci (keyconf->keyidx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT); 2178c2ecf20Sopenharmony_ci 2188c2ecf20Sopenharmony_ci memcpy(&tx_cmd->key[3], keyconf->key, keyconf->keylen); 2198c2ecf20Sopenharmony_ci 2208c2ecf20Sopenharmony_ci IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption " 2218c2ecf20Sopenharmony_ci "with key %d\n", keyconf->keyidx); 2228c2ecf20Sopenharmony_ci break; 2238c2ecf20Sopenharmony_ci 2248c2ecf20Sopenharmony_ci default: 2258c2ecf20Sopenharmony_ci IWL_ERR(priv, "Unknown encode cipher %x\n", keyconf->cipher); 2268c2ecf20Sopenharmony_ci break; 2278c2ecf20Sopenharmony_ci } 2288c2ecf20Sopenharmony_ci} 2298c2ecf20Sopenharmony_ci 2308c2ecf20Sopenharmony_ci/** 2318c2ecf20Sopenharmony_ci * iwl_sta_id_or_broadcast - return sta_id or broadcast sta 2328c2ecf20Sopenharmony_ci * @context: the current context 2338c2ecf20Sopenharmony_ci * @sta: mac80211 station 2348c2ecf20Sopenharmony_ci * 2358c2ecf20Sopenharmony_ci * In certain circumstances mac80211 passes a station pointer 2368c2ecf20Sopenharmony_ci * that may be %NULL, for example during TX or key setup. In 2378c2ecf20Sopenharmony_ci * that case, we need to use the broadcast station, so this 2388c2ecf20Sopenharmony_ci * inline wraps that pattern. 2398c2ecf20Sopenharmony_ci */ 2408c2ecf20Sopenharmony_cistatic int iwl_sta_id_or_broadcast(struct iwl_rxon_context *context, 2418c2ecf20Sopenharmony_ci struct ieee80211_sta *sta) 2428c2ecf20Sopenharmony_ci{ 2438c2ecf20Sopenharmony_ci int sta_id; 2448c2ecf20Sopenharmony_ci 2458c2ecf20Sopenharmony_ci if (!sta) 2468c2ecf20Sopenharmony_ci return context->bcast_sta_id; 2478c2ecf20Sopenharmony_ci 2488c2ecf20Sopenharmony_ci sta_id = iwl_sta_id(sta); 2498c2ecf20Sopenharmony_ci 2508c2ecf20Sopenharmony_ci /* 2518c2ecf20Sopenharmony_ci * mac80211 should not be passing a partially 2528c2ecf20Sopenharmony_ci * initialised station! 2538c2ecf20Sopenharmony_ci */ 2548c2ecf20Sopenharmony_ci WARN_ON(sta_id == IWL_INVALID_STATION); 2558c2ecf20Sopenharmony_ci 2568c2ecf20Sopenharmony_ci return sta_id; 2578c2ecf20Sopenharmony_ci} 2588c2ecf20Sopenharmony_ci 2598c2ecf20Sopenharmony_ci/* 2608c2ecf20Sopenharmony_ci * start REPLY_TX command process 2618c2ecf20Sopenharmony_ci */ 2628c2ecf20Sopenharmony_ciint iwlagn_tx_skb(struct iwl_priv *priv, 2638c2ecf20Sopenharmony_ci struct ieee80211_sta *sta, 2648c2ecf20Sopenharmony_ci struct sk_buff *skb) 2658c2ecf20Sopenharmony_ci{ 2668c2ecf20Sopenharmony_ci struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data; 2678c2ecf20Sopenharmony_ci struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 2688c2ecf20Sopenharmony_ci struct iwl_station_priv *sta_priv = NULL; 2698c2ecf20Sopenharmony_ci struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; 2708c2ecf20Sopenharmony_ci struct iwl_device_tx_cmd *dev_cmd; 2718c2ecf20Sopenharmony_ci struct iwl_tx_cmd *tx_cmd; 2728c2ecf20Sopenharmony_ci __le16 fc; 2738c2ecf20Sopenharmony_ci u8 hdr_len; 2748c2ecf20Sopenharmony_ci u16 len, seq_number = 0; 2758c2ecf20Sopenharmony_ci u8 sta_id, tid = IWL_MAX_TID_COUNT; 2768c2ecf20Sopenharmony_ci bool is_agg = false, is_data_qos = false; 2778c2ecf20Sopenharmony_ci int txq_id; 2788c2ecf20Sopenharmony_ci 2798c2ecf20Sopenharmony_ci if (info->control.vif) 2808c2ecf20Sopenharmony_ci ctx = iwl_rxon_ctx_from_vif(info->control.vif); 2818c2ecf20Sopenharmony_ci 2828c2ecf20Sopenharmony_ci if (iwl_is_rfkill(priv)) { 2838c2ecf20Sopenharmony_ci IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n"); 2848c2ecf20Sopenharmony_ci goto drop_unlock_priv; 2858c2ecf20Sopenharmony_ci } 2868c2ecf20Sopenharmony_ci 2878c2ecf20Sopenharmony_ci fc = hdr->frame_control; 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUG 2908c2ecf20Sopenharmony_ci if (ieee80211_is_auth(fc)) 2918c2ecf20Sopenharmony_ci IWL_DEBUG_TX(priv, "Sending AUTH frame\n"); 2928c2ecf20Sopenharmony_ci else if (ieee80211_is_assoc_req(fc)) 2938c2ecf20Sopenharmony_ci IWL_DEBUG_TX(priv, "Sending ASSOC frame\n"); 2948c2ecf20Sopenharmony_ci else if (ieee80211_is_reassoc_req(fc)) 2958c2ecf20Sopenharmony_ci IWL_DEBUG_TX(priv, "Sending REASSOC frame\n"); 2968c2ecf20Sopenharmony_ci#endif 2978c2ecf20Sopenharmony_ci 2988c2ecf20Sopenharmony_ci if (unlikely(ieee80211_is_probe_resp(fc))) { 2998c2ecf20Sopenharmony_ci struct iwl_wipan_noa_data *noa_data = 3008c2ecf20Sopenharmony_ci rcu_dereference(priv->noa_data); 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci if (noa_data && 3038c2ecf20Sopenharmony_ci pskb_expand_head(skb, 0, noa_data->length, 3048c2ecf20Sopenharmony_ci GFP_ATOMIC) == 0) { 3058c2ecf20Sopenharmony_ci skb_put_data(skb, noa_data->data, noa_data->length); 3068c2ecf20Sopenharmony_ci hdr = (struct ieee80211_hdr *)skb->data; 3078c2ecf20Sopenharmony_ci } 3088c2ecf20Sopenharmony_ci } 3098c2ecf20Sopenharmony_ci 3108c2ecf20Sopenharmony_ci hdr_len = ieee80211_hdrlen(fc); 3118c2ecf20Sopenharmony_ci 3128c2ecf20Sopenharmony_ci /* For management frames use broadcast id to do not break aggregation */ 3138c2ecf20Sopenharmony_ci if (!ieee80211_is_data(fc)) 3148c2ecf20Sopenharmony_ci sta_id = ctx->bcast_sta_id; 3158c2ecf20Sopenharmony_ci else { 3168c2ecf20Sopenharmony_ci /* Find index into station table for destination station */ 3178c2ecf20Sopenharmony_ci sta_id = iwl_sta_id_or_broadcast(ctx, sta); 3188c2ecf20Sopenharmony_ci if (sta_id == IWL_INVALID_STATION) { 3198c2ecf20Sopenharmony_ci IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n", 3208c2ecf20Sopenharmony_ci hdr->addr1); 3218c2ecf20Sopenharmony_ci goto drop_unlock_priv; 3228c2ecf20Sopenharmony_ci } 3238c2ecf20Sopenharmony_ci } 3248c2ecf20Sopenharmony_ci 3258c2ecf20Sopenharmony_ci if (sta) 3268c2ecf20Sopenharmony_ci sta_priv = (void *)sta->drv_priv; 3278c2ecf20Sopenharmony_ci 3288c2ecf20Sopenharmony_ci if (sta_priv && sta_priv->asleep && 3298c2ecf20Sopenharmony_ci (info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER)) { 3308c2ecf20Sopenharmony_ci /* 3318c2ecf20Sopenharmony_ci * This sends an asynchronous command to the device, 3328c2ecf20Sopenharmony_ci * but we can rely on it being processed before the 3338c2ecf20Sopenharmony_ci * next frame is processed -- and the next frame to 3348c2ecf20Sopenharmony_ci * this station is the one that will consume this 3358c2ecf20Sopenharmony_ci * counter. 3368c2ecf20Sopenharmony_ci * For now set the counter to just 1 since we do not 3378c2ecf20Sopenharmony_ci * support uAPSD yet. 3388c2ecf20Sopenharmony_ci * 3398c2ecf20Sopenharmony_ci * FIXME: If we get two non-bufferable frames one 3408c2ecf20Sopenharmony_ci * after the other, we might only send out one of 3418c2ecf20Sopenharmony_ci * them because this is racy. 3428c2ecf20Sopenharmony_ci */ 3438c2ecf20Sopenharmony_ci iwl_sta_modify_sleep_tx_count(priv, sta_id, 1); 3448c2ecf20Sopenharmony_ci } 3458c2ecf20Sopenharmony_ci 3468c2ecf20Sopenharmony_ci dev_cmd = iwl_trans_alloc_tx_cmd(priv->trans); 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci if (unlikely(!dev_cmd)) 3498c2ecf20Sopenharmony_ci goto drop_unlock_priv; 3508c2ecf20Sopenharmony_ci 3518c2ecf20Sopenharmony_ci dev_cmd->hdr.cmd = REPLY_TX; 3528c2ecf20Sopenharmony_ci tx_cmd = (struct iwl_tx_cmd *) dev_cmd->payload; 3538c2ecf20Sopenharmony_ci 3548c2ecf20Sopenharmony_ci /* Total # bytes to be transmitted */ 3558c2ecf20Sopenharmony_ci len = (u16)skb->len; 3568c2ecf20Sopenharmony_ci tx_cmd->len = cpu_to_le16(len); 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_ci if (info->control.hw_key) 3598c2ecf20Sopenharmony_ci iwlagn_tx_cmd_build_hwcrypto(priv, info, tx_cmd, skb); 3608c2ecf20Sopenharmony_ci 3618c2ecf20Sopenharmony_ci /* TODO need this for burst mode later on */ 3628c2ecf20Sopenharmony_ci iwlagn_tx_cmd_build_basic(priv, skb, tx_cmd, info, hdr, sta_id); 3638c2ecf20Sopenharmony_ci 3648c2ecf20Sopenharmony_ci iwlagn_tx_cmd_build_rate(priv, tx_cmd, info, sta, fc); 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci memset(&info->status, 0, sizeof(info->status)); 3678c2ecf20Sopenharmony_ci memset(info->driver_data, 0, sizeof(info->driver_data)); 3688c2ecf20Sopenharmony_ci 3698c2ecf20Sopenharmony_ci info->driver_data[0] = ctx; 3708c2ecf20Sopenharmony_ci info->driver_data[1] = dev_cmd; 3718c2ecf20Sopenharmony_ci /* From now on, we cannot access info->control */ 3728c2ecf20Sopenharmony_ci 3738c2ecf20Sopenharmony_ci spin_lock(&priv->sta_lock); 3748c2ecf20Sopenharmony_ci 3758c2ecf20Sopenharmony_ci if (ieee80211_is_data_qos(fc) && !ieee80211_is_qos_nullfunc(fc)) { 3768c2ecf20Sopenharmony_ci u8 *qc = NULL; 3778c2ecf20Sopenharmony_ci struct iwl_tid_data *tid_data; 3788c2ecf20Sopenharmony_ci qc = ieee80211_get_qos_ctl(hdr); 3798c2ecf20Sopenharmony_ci tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK; 3808c2ecf20Sopenharmony_ci if (WARN_ON_ONCE(tid >= IWL_MAX_TID_COUNT)) 3818c2ecf20Sopenharmony_ci goto drop_unlock_sta; 3828c2ecf20Sopenharmony_ci tid_data = &priv->tid_data[sta_id][tid]; 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_ci /* aggregation is on for this <sta,tid> */ 3858c2ecf20Sopenharmony_ci if (info->flags & IEEE80211_TX_CTL_AMPDU && 3868c2ecf20Sopenharmony_ci tid_data->agg.state != IWL_AGG_ON) { 3878c2ecf20Sopenharmony_ci IWL_ERR(priv, 3888c2ecf20Sopenharmony_ci "TX_CTL_AMPDU while not in AGG: Tx flags = 0x%08x, agg.state = %d\n", 3898c2ecf20Sopenharmony_ci info->flags, tid_data->agg.state); 3908c2ecf20Sopenharmony_ci IWL_ERR(priv, "sta_id = %d, tid = %d seq_num = %d\n", 3918c2ecf20Sopenharmony_ci sta_id, tid, 3928c2ecf20Sopenharmony_ci IEEE80211_SEQ_TO_SN(tid_data->seq_number)); 3938c2ecf20Sopenharmony_ci goto drop_unlock_sta; 3948c2ecf20Sopenharmony_ci } 3958c2ecf20Sopenharmony_ci 3968c2ecf20Sopenharmony_ci /* We can receive packets from the stack in IWL_AGG_{ON,OFF} 3978c2ecf20Sopenharmony_ci * only. Check this here. 3988c2ecf20Sopenharmony_ci */ 3998c2ecf20Sopenharmony_ci if (WARN_ONCE(tid_data->agg.state != IWL_AGG_ON && 4008c2ecf20Sopenharmony_ci tid_data->agg.state != IWL_AGG_OFF, 4018c2ecf20Sopenharmony_ci "Tx while agg.state = %d\n", tid_data->agg.state)) 4028c2ecf20Sopenharmony_ci goto drop_unlock_sta; 4038c2ecf20Sopenharmony_ci 4048c2ecf20Sopenharmony_ci seq_number = tid_data->seq_number; 4058c2ecf20Sopenharmony_ci seq_number &= IEEE80211_SCTL_SEQ; 4068c2ecf20Sopenharmony_ci hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG); 4078c2ecf20Sopenharmony_ci hdr->seq_ctrl |= cpu_to_le16(seq_number); 4088c2ecf20Sopenharmony_ci seq_number += 0x10; 4098c2ecf20Sopenharmony_ci 4108c2ecf20Sopenharmony_ci if (info->flags & IEEE80211_TX_CTL_AMPDU) 4118c2ecf20Sopenharmony_ci is_agg = true; 4128c2ecf20Sopenharmony_ci is_data_qos = true; 4138c2ecf20Sopenharmony_ci } 4148c2ecf20Sopenharmony_ci 4158c2ecf20Sopenharmony_ci /* Copy MAC header from skb into command buffer */ 4168c2ecf20Sopenharmony_ci memcpy(tx_cmd->hdr, hdr, hdr_len); 4178c2ecf20Sopenharmony_ci 4188c2ecf20Sopenharmony_ci txq_id = info->hw_queue; 4198c2ecf20Sopenharmony_ci 4208c2ecf20Sopenharmony_ci if (is_agg) 4218c2ecf20Sopenharmony_ci txq_id = priv->tid_data[sta_id][tid].agg.txq_id; 4228c2ecf20Sopenharmony_ci else if (info->flags & IEEE80211_TX_CTL_SEND_AFTER_DTIM) { 4238c2ecf20Sopenharmony_ci /* 4248c2ecf20Sopenharmony_ci * The microcode will clear the more data 4258c2ecf20Sopenharmony_ci * bit in the last frame it transmits. 4268c2ecf20Sopenharmony_ci */ 4278c2ecf20Sopenharmony_ci hdr->frame_control |= 4288c2ecf20Sopenharmony_ci cpu_to_le16(IEEE80211_FCTL_MOREDATA); 4298c2ecf20Sopenharmony_ci } 4308c2ecf20Sopenharmony_ci 4318c2ecf20Sopenharmony_ci WARN_ON_ONCE(is_agg && 4328c2ecf20Sopenharmony_ci priv->queue_to_mac80211[txq_id] != info->hw_queue); 4338c2ecf20Sopenharmony_ci 4348c2ecf20Sopenharmony_ci IWL_DEBUG_TX(priv, "TX to [%d|%d] Q:%d - seq: 0x%x\n", sta_id, tid, 4358c2ecf20Sopenharmony_ci txq_id, seq_number); 4368c2ecf20Sopenharmony_ci 4378c2ecf20Sopenharmony_ci if (iwl_trans_tx(priv->trans, skb, dev_cmd, txq_id)) 4388c2ecf20Sopenharmony_ci goto drop_unlock_sta; 4398c2ecf20Sopenharmony_ci 4408c2ecf20Sopenharmony_ci if (is_data_qos && !ieee80211_has_morefrags(fc)) 4418c2ecf20Sopenharmony_ci priv->tid_data[sta_id][tid].seq_number = seq_number; 4428c2ecf20Sopenharmony_ci 4438c2ecf20Sopenharmony_ci spin_unlock(&priv->sta_lock); 4448c2ecf20Sopenharmony_ci 4458c2ecf20Sopenharmony_ci /* 4468c2ecf20Sopenharmony_ci * Avoid atomic ops if it isn't an associated client. 4478c2ecf20Sopenharmony_ci * Also, if this is a packet for aggregation, don't 4488c2ecf20Sopenharmony_ci * increase the counter because the ucode will stop 4498c2ecf20Sopenharmony_ci * aggregation queues when their respective station 4508c2ecf20Sopenharmony_ci * goes to sleep. 4518c2ecf20Sopenharmony_ci */ 4528c2ecf20Sopenharmony_ci if (sta_priv && sta_priv->client && !is_agg) 4538c2ecf20Sopenharmony_ci atomic_inc(&sta_priv->pending_frames); 4548c2ecf20Sopenharmony_ci 4558c2ecf20Sopenharmony_ci return 0; 4568c2ecf20Sopenharmony_ci 4578c2ecf20Sopenharmony_cidrop_unlock_sta: 4588c2ecf20Sopenharmony_ci if (dev_cmd) 4598c2ecf20Sopenharmony_ci iwl_trans_free_tx_cmd(priv->trans, dev_cmd); 4608c2ecf20Sopenharmony_ci spin_unlock(&priv->sta_lock); 4618c2ecf20Sopenharmony_cidrop_unlock_priv: 4628c2ecf20Sopenharmony_ci return -1; 4638c2ecf20Sopenharmony_ci} 4648c2ecf20Sopenharmony_ci 4658c2ecf20Sopenharmony_cistatic int iwlagn_alloc_agg_txq(struct iwl_priv *priv, int mq) 4668c2ecf20Sopenharmony_ci{ 4678c2ecf20Sopenharmony_ci int q; 4688c2ecf20Sopenharmony_ci 4698c2ecf20Sopenharmony_ci for (q = IWLAGN_FIRST_AMPDU_QUEUE; 4708c2ecf20Sopenharmony_ci q < priv->trans->trans_cfg->base_params->num_of_queues; q++) { 4718c2ecf20Sopenharmony_ci if (!test_and_set_bit(q, priv->agg_q_alloc)) { 4728c2ecf20Sopenharmony_ci priv->queue_to_mac80211[q] = mq; 4738c2ecf20Sopenharmony_ci return q; 4748c2ecf20Sopenharmony_ci } 4758c2ecf20Sopenharmony_ci } 4768c2ecf20Sopenharmony_ci 4778c2ecf20Sopenharmony_ci return -ENOSPC; 4788c2ecf20Sopenharmony_ci} 4798c2ecf20Sopenharmony_ci 4808c2ecf20Sopenharmony_cistatic void iwlagn_dealloc_agg_txq(struct iwl_priv *priv, int q) 4818c2ecf20Sopenharmony_ci{ 4828c2ecf20Sopenharmony_ci clear_bit(q, priv->agg_q_alloc); 4838c2ecf20Sopenharmony_ci priv->queue_to_mac80211[q] = IWL_INVALID_MAC80211_QUEUE; 4848c2ecf20Sopenharmony_ci} 4858c2ecf20Sopenharmony_ci 4868c2ecf20Sopenharmony_ciint iwlagn_tx_agg_stop(struct iwl_priv *priv, struct ieee80211_vif *vif, 4878c2ecf20Sopenharmony_ci struct ieee80211_sta *sta, u16 tid) 4888c2ecf20Sopenharmony_ci{ 4898c2ecf20Sopenharmony_ci struct iwl_tid_data *tid_data; 4908c2ecf20Sopenharmony_ci int sta_id, txq_id; 4918c2ecf20Sopenharmony_ci enum iwl_agg_state agg_state; 4928c2ecf20Sopenharmony_ci 4938c2ecf20Sopenharmony_ci sta_id = iwl_sta_id(sta); 4948c2ecf20Sopenharmony_ci 4958c2ecf20Sopenharmony_ci if (sta_id == IWL_INVALID_STATION) { 4968c2ecf20Sopenharmony_ci IWL_ERR(priv, "Invalid station for AGG tid %d\n", tid); 4978c2ecf20Sopenharmony_ci return -ENXIO; 4988c2ecf20Sopenharmony_ci } 4998c2ecf20Sopenharmony_ci 5008c2ecf20Sopenharmony_ci spin_lock_bh(&priv->sta_lock); 5018c2ecf20Sopenharmony_ci 5028c2ecf20Sopenharmony_ci tid_data = &priv->tid_data[sta_id][tid]; 5038c2ecf20Sopenharmony_ci txq_id = tid_data->agg.txq_id; 5048c2ecf20Sopenharmony_ci 5058c2ecf20Sopenharmony_ci switch (tid_data->agg.state) { 5068c2ecf20Sopenharmony_ci case IWL_EMPTYING_HW_QUEUE_ADDBA: 5078c2ecf20Sopenharmony_ci /* 5088c2ecf20Sopenharmony_ci * This can happen if the peer stops aggregation 5098c2ecf20Sopenharmony_ci * again before we've had a chance to drain the 5108c2ecf20Sopenharmony_ci * queue we selected previously, i.e. before the 5118c2ecf20Sopenharmony_ci * session was really started completely. 5128c2ecf20Sopenharmony_ci */ 5138c2ecf20Sopenharmony_ci IWL_DEBUG_HT(priv, "AGG stop before setup done\n"); 5148c2ecf20Sopenharmony_ci goto turn_off; 5158c2ecf20Sopenharmony_ci case IWL_AGG_STARTING: 5168c2ecf20Sopenharmony_ci /* 5178c2ecf20Sopenharmony_ci * This can happen when the session is stopped before 5188c2ecf20Sopenharmony_ci * we receive ADDBA response 5198c2ecf20Sopenharmony_ci */ 5208c2ecf20Sopenharmony_ci IWL_DEBUG_HT(priv, "AGG stop before AGG became operational\n"); 5218c2ecf20Sopenharmony_ci goto turn_off; 5228c2ecf20Sopenharmony_ci case IWL_AGG_ON: 5238c2ecf20Sopenharmony_ci break; 5248c2ecf20Sopenharmony_ci default: 5258c2ecf20Sopenharmony_ci IWL_WARN(priv, 5268c2ecf20Sopenharmony_ci "Stopping AGG while state not ON or starting for %d on %d (%d)\n", 5278c2ecf20Sopenharmony_ci sta_id, tid, tid_data->agg.state); 5288c2ecf20Sopenharmony_ci spin_unlock_bh(&priv->sta_lock); 5298c2ecf20Sopenharmony_ci return 0; 5308c2ecf20Sopenharmony_ci } 5318c2ecf20Sopenharmony_ci 5328c2ecf20Sopenharmony_ci tid_data->agg.ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); 5338c2ecf20Sopenharmony_ci 5348c2ecf20Sopenharmony_ci /* There are still packets for this RA / TID in the HW */ 5358c2ecf20Sopenharmony_ci if (!test_bit(txq_id, priv->agg_q_alloc)) { 5368c2ecf20Sopenharmony_ci IWL_DEBUG_TX_QUEUES(priv, 5378c2ecf20Sopenharmony_ci "stopping AGG on STA/TID %d/%d but hwq %d not used\n", 5388c2ecf20Sopenharmony_ci sta_id, tid, txq_id); 5398c2ecf20Sopenharmony_ci } else if (tid_data->agg.ssn != tid_data->next_reclaimed) { 5408c2ecf20Sopenharmony_ci IWL_DEBUG_TX_QUEUES(priv, 5418c2ecf20Sopenharmony_ci "Can't proceed: ssn %d, next_recl = %d\n", 5428c2ecf20Sopenharmony_ci tid_data->agg.ssn, 5438c2ecf20Sopenharmony_ci tid_data->next_reclaimed); 5448c2ecf20Sopenharmony_ci tid_data->agg.state = IWL_EMPTYING_HW_QUEUE_DELBA; 5458c2ecf20Sopenharmony_ci spin_unlock_bh(&priv->sta_lock); 5468c2ecf20Sopenharmony_ci return 0; 5478c2ecf20Sopenharmony_ci } 5488c2ecf20Sopenharmony_ci 5498c2ecf20Sopenharmony_ci IWL_DEBUG_TX_QUEUES(priv, "Can proceed: ssn = next_recl = %d\n", 5508c2ecf20Sopenharmony_ci tid_data->agg.ssn); 5518c2ecf20Sopenharmony_citurn_off: 5528c2ecf20Sopenharmony_ci agg_state = tid_data->agg.state; 5538c2ecf20Sopenharmony_ci tid_data->agg.state = IWL_AGG_OFF; 5548c2ecf20Sopenharmony_ci 5558c2ecf20Sopenharmony_ci spin_unlock_bh(&priv->sta_lock); 5568c2ecf20Sopenharmony_ci 5578c2ecf20Sopenharmony_ci if (test_bit(txq_id, priv->agg_q_alloc)) { 5588c2ecf20Sopenharmony_ci /* 5598c2ecf20Sopenharmony_ci * If the transport didn't know that we wanted to start 5608c2ecf20Sopenharmony_ci * agreggation, don't tell it that we want to stop them. 5618c2ecf20Sopenharmony_ci * This can happen when we don't get the addBA response on 5628c2ecf20Sopenharmony_ci * time, or we hadn't time to drain the AC queues. 5638c2ecf20Sopenharmony_ci */ 5648c2ecf20Sopenharmony_ci if (agg_state == IWL_AGG_ON) 5658c2ecf20Sopenharmony_ci iwl_trans_txq_disable(priv->trans, txq_id, true); 5668c2ecf20Sopenharmony_ci else 5678c2ecf20Sopenharmony_ci IWL_DEBUG_TX_QUEUES(priv, "Don't disable tx agg: %d\n", 5688c2ecf20Sopenharmony_ci agg_state); 5698c2ecf20Sopenharmony_ci iwlagn_dealloc_agg_txq(priv, txq_id); 5708c2ecf20Sopenharmony_ci } 5718c2ecf20Sopenharmony_ci 5728c2ecf20Sopenharmony_ci ieee80211_stop_tx_ba_cb_irqsafe(vif, sta->addr, tid); 5738c2ecf20Sopenharmony_ci 5748c2ecf20Sopenharmony_ci return 0; 5758c2ecf20Sopenharmony_ci} 5768c2ecf20Sopenharmony_ci 5778c2ecf20Sopenharmony_ciint iwlagn_tx_agg_start(struct iwl_priv *priv, struct ieee80211_vif *vif, 5788c2ecf20Sopenharmony_ci struct ieee80211_sta *sta, u16 tid, u16 *ssn) 5798c2ecf20Sopenharmony_ci{ 5808c2ecf20Sopenharmony_ci struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); 5818c2ecf20Sopenharmony_ci struct iwl_tid_data *tid_data; 5828c2ecf20Sopenharmony_ci int sta_id, txq_id, ret; 5838c2ecf20Sopenharmony_ci 5848c2ecf20Sopenharmony_ci IWL_DEBUG_HT(priv, "TX AGG request on ra = %pM tid = %d\n", 5858c2ecf20Sopenharmony_ci sta->addr, tid); 5868c2ecf20Sopenharmony_ci 5878c2ecf20Sopenharmony_ci sta_id = iwl_sta_id(sta); 5888c2ecf20Sopenharmony_ci if (sta_id == IWL_INVALID_STATION) { 5898c2ecf20Sopenharmony_ci IWL_ERR(priv, "Start AGG on invalid station\n"); 5908c2ecf20Sopenharmony_ci return -ENXIO; 5918c2ecf20Sopenharmony_ci } 5928c2ecf20Sopenharmony_ci if (unlikely(tid >= IWL_MAX_TID_COUNT)) 5938c2ecf20Sopenharmony_ci return -EINVAL; 5948c2ecf20Sopenharmony_ci 5958c2ecf20Sopenharmony_ci if (priv->tid_data[sta_id][tid].agg.state != IWL_AGG_OFF) { 5968c2ecf20Sopenharmony_ci IWL_ERR(priv, "Start AGG when state is not IWL_AGG_OFF !\n"); 5978c2ecf20Sopenharmony_ci return -ENXIO; 5988c2ecf20Sopenharmony_ci } 5998c2ecf20Sopenharmony_ci 6008c2ecf20Sopenharmony_ci txq_id = iwlagn_alloc_agg_txq(priv, ctx->ac_to_queue[tid_to_ac[tid]]); 6018c2ecf20Sopenharmony_ci if (txq_id < 0) { 6028c2ecf20Sopenharmony_ci IWL_DEBUG_TX_QUEUES(priv, 6038c2ecf20Sopenharmony_ci "No free aggregation queue for %pM/%d\n", 6048c2ecf20Sopenharmony_ci sta->addr, tid); 6058c2ecf20Sopenharmony_ci return txq_id; 6068c2ecf20Sopenharmony_ci } 6078c2ecf20Sopenharmony_ci 6088c2ecf20Sopenharmony_ci ret = iwl_sta_tx_modify_enable_tid(priv, sta_id, tid); 6098c2ecf20Sopenharmony_ci if (ret) 6108c2ecf20Sopenharmony_ci return ret; 6118c2ecf20Sopenharmony_ci 6128c2ecf20Sopenharmony_ci spin_lock_bh(&priv->sta_lock); 6138c2ecf20Sopenharmony_ci tid_data = &priv->tid_data[sta_id][tid]; 6148c2ecf20Sopenharmony_ci tid_data->agg.ssn = IEEE80211_SEQ_TO_SN(tid_data->seq_number); 6158c2ecf20Sopenharmony_ci tid_data->agg.txq_id = txq_id; 6168c2ecf20Sopenharmony_ci 6178c2ecf20Sopenharmony_ci *ssn = tid_data->agg.ssn; 6188c2ecf20Sopenharmony_ci 6198c2ecf20Sopenharmony_ci if (*ssn == tid_data->next_reclaimed) { 6208c2ecf20Sopenharmony_ci IWL_DEBUG_TX_QUEUES(priv, "Can proceed: ssn = next_recl = %d\n", 6218c2ecf20Sopenharmony_ci tid_data->agg.ssn); 6228c2ecf20Sopenharmony_ci tid_data->agg.state = IWL_AGG_STARTING; 6238c2ecf20Sopenharmony_ci ret = IEEE80211_AMPDU_TX_START_IMMEDIATE; 6248c2ecf20Sopenharmony_ci } else { 6258c2ecf20Sopenharmony_ci IWL_DEBUG_TX_QUEUES(priv, "Can't proceed: ssn %d, " 6268c2ecf20Sopenharmony_ci "next_reclaimed = %d\n", 6278c2ecf20Sopenharmony_ci tid_data->agg.ssn, 6288c2ecf20Sopenharmony_ci tid_data->next_reclaimed); 6298c2ecf20Sopenharmony_ci tid_data->agg.state = IWL_EMPTYING_HW_QUEUE_ADDBA; 6308c2ecf20Sopenharmony_ci } 6318c2ecf20Sopenharmony_ci spin_unlock_bh(&priv->sta_lock); 6328c2ecf20Sopenharmony_ci 6338c2ecf20Sopenharmony_ci return ret; 6348c2ecf20Sopenharmony_ci} 6358c2ecf20Sopenharmony_ci 6368c2ecf20Sopenharmony_ciint iwlagn_tx_agg_flush(struct iwl_priv *priv, struct ieee80211_vif *vif, 6378c2ecf20Sopenharmony_ci struct ieee80211_sta *sta, u16 tid) 6388c2ecf20Sopenharmony_ci{ 6398c2ecf20Sopenharmony_ci struct iwl_tid_data *tid_data; 6408c2ecf20Sopenharmony_ci enum iwl_agg_state agg_state; 6418c2ecf20Sopenharmony_ci int sta_id, txq_id; 6428c2ecf20Sopenharmony_ci sta_id = iwl_sta_id(sta); 6438c2ecf20Sopenharmony_ci 6448c2ecf20Sopenharmony_ci /* 6458c2ecf20Sopenharmony_ci * First set the agg state to OFF to avoid calling 6468c2ecf20Sopenharmony_ci * ieee80211_stop_tx_ba_cb in iwlagn_check_ratid_empty. 6478c2ecf20Sopenharmony_ci */ 6488c2ecf20Sopenharmony_ci spin_lock_bh(&priv->sta_lock); 6498c2ecf20Sopenharmony_ci 6508c2ecf20Sopenharmony_ci tid_data = &priv->tid_data[sta_id][tid]; 6518c2ecf20Sopenharmony_ci txq_id = tid_data->agg.txq_id; 6528c2ecf20Sopenharmony_ci agg_state = tid_data->agg.state; 6538c2ecf20Sopenharmony_ci IWL_DEBUG_TX_QUEUES(priv, "Flush AGG: sta %d tid %d q %d state %d\n", 6548c2ecf20Sopenharmony_ci sta_id, tid, txq_id, tid_data->agg.state); 6558c2ecf20Sopenharmony_ci 6568c2ecf20Sopenharmony_ci tid_data->agg.state = IWL_AGG_OFF; 6578c2ecf20Sopenharmony_ci 6588c2ecf20Sopenharmony_ci spin_unlock_bh(&priv->sta_lock); 6598c2ecf20Sopenharmony_ci 6608c2ecf20Sopenharmony_ci if (iwlagn_txfifo_flush(priv, BIT(txq_id))) 6618c2ecf20Sopenharmony_ci IWL_ERR(priv, "Couldn't flush the AGG queue\n"); 6628c2ecf20Sopenharmony_ci 6638c2ecf20Sopenharmony_ci if (test_bit(txq_id, priv->agg_q_alloc)) { 6648c2ecf20Sopenharmony_ci /* 6658c2ecf20Sopenharmony_ci * If the transport didn't know that we wanted to start 6668c2ecf20Sopenharmony_ci * agreggation, don't tell it that we want to stop them. 6678c2ecf20Sopenharmony_ci * This can happen when we don't get the addBA response on 6688c2ecf20Sopenharmony_ci * time, or we hadn't time to drain the AC queues. 6698c2ecf20Sopenharmony_ci */ 6708c2ecf20Sopenharmony_ci if (agg_state == IWL_AGG_ON) 6718c2ecf20Sopenharmony_ci iwl_trans_txq_disable(priv->trans, txq_id, true); 6728c2ecf20Sopenharmony_ci else 6738c2ecf20Sopenharmony_ci IWL_DEBUG_TX_QUEUES(priv, "Don't disable tx agg: %d\n", 6748c2ecf20Sopenharmony_ci agg_state); 6758c2ecf20Sopenharmony_ci iwlagn_dealloc_agg_txq(priv, txq_id); 6768c2ecf20Sopenharmony_ci } 6778c2ecf20Sopenharmony_ci 6788c2ecf20Sopenharmony_ci return 0; 6798c2ecf20Sopenharmony_ci} 6808c2ecf20Sopenharmony_ci 6818c2ecf20Sopenharmony_ciint iwlagn_tx_agg_oper(struct iwl_priv *priv, struct ieee80211_vif *vif, 6828c2ecf20Sopenharmony_ci struct ieee80211_sta *sta, u16 tid, u8 buf_size) 6838c2ecf20Sopenharmony_ci{ 6848c2ecf20Sopenharmony_ci struct iwl_station_priv *sta_priv = (void *) sta->drv_priv; 6858c2ecf20Sopenharmony_ci struct iwl_rxon_context *ctx = iwl_rxon_ctx_from_vif(vif); 6868c2ecf20Sopenharmony_ci int q, fifo; 6878c2ecf20Sopenharmony_ci u16 ssn; 6888c2ecf20Sopenharmony_ci 6898c2ecf20Sopenharmony_ci buf_size = min_t(int, buf_size, LINK_QUAL_AGG_FRAME_LIMIT_DEF); 6908c2ecf20Sopenharmony_ci 6918c2ecf20Sopenharmony_ci spin_lock_bh(&priv->sta_lock); 6928c2ecf20Sopenharmony_ci ssn = priv->tid_data[sta_priv->sta_id][tid].agg.ssn; 6938c2ecf20Sopenharmony_ci q = priv->tid_data[sta_priv->sta_id][tid].agg.txq_id; 6948c2ecf20Sopenharmony_ci priv->tid_data[sta_priv->sta_id][tid].agg.state = IWL_AGG_ON; 6958c2ecf20Sopenharmony_ci spin_unlock_bh(&priv->sta_lock); 6968c2ecf20Sopenharmony_ci 6978c2ecf20Sopenharmony_ci fifo = ctx->ac_to_fifo[tid_to_ac[tid]]; 6988c2ecf20Sopenharmony_ci 6998c2ecf20Sopenharmony_ci iwl_trans_txq_enable(priv->trans, q, fifo, sta_priv->sta_id, tid, 7008c2ecf20Sopenharmony_ci buf_size, ssn, 0); 7018c2ecf20Sopenharmony_ci 7028c2ecf20Sopenharmony_ci /* 7038c2ecf20Sopenharmony_ci * If the limit is 0, then it wasn't initialised yet, 7048c2ecf20Sopenharmony_ci * use the default. We can do that since we take the 7058c2ecf20Sopenharmony_ci * minimum below, and we don't want to go above our 7068c2ecf20Sopenharmony_ci * default due to hardware restrictions. 7078c2ecf20Sopenharmony_ci */ 7088c2ecf20Sopenharmony_ci if (sta_priv->max_agg_bufsize == 0) 7098c2ecf20Sopenharmony_ci sta_priv->max_agg_bufsize = 7108c2ecf20Sopenharmony_ci LINK_QUAL_AGG_FRAME_LIMIT_DEF; 7118c2ecf20Sopenharmony_ci 7128c2ecf20Sopenharmony_ci /* 7138c2ecf20Sopenharmony_ci * Even though in theory the peer could have different 7148c2ecf20Sopenharmony_ci * aggregation reorder buffer sizes for different sessions, 7158c2ecf20Sopenharmony_ci * our ucode doesn't allow for that and has a global limit 7168c2ecf20Sopenharmony_ci * for each station. Therefore, use the minimum of all the 7178c2ecf20Sopenharmony_ci * aggregation sessions and our default value. 7188c2ecf20Sopenharmony_ci */ 7198c2ecf20Sopenharmony_ci sta_priv->max_agg_bufsize = 7208c2ecf20Sopenharmony_ci min(sta_priv->max_agg_bufsize, buf_size); 7218c2ecf20Sopenharmony_ci 7228c2ecf20Sopenharmony_ci if (priv->hw_params.use_rts_for_aggregation) { 7238c2ecf20Sopenharmony_ci /* 7248c2ecf20Sopenharmony_ci * switch to RTS/CTS if it is the prefer protection 7258c2ecf20Sopenharmony_ci * method for HT traffic 7268c2ecf20Sopenharmony_ci */ 7278c2ecf20Sopenharmony_ci 7288c2ecf20Sopenharmony_ci sta_priv->lq_sta.lq.general_params.flags |= 7298c2ecf20Sopenharmony_ci LINK_QUAL_FLAGS_SET_STA_TLC_RTS_MSK; 7308c2ecf20Sopenharmony_ci } 7318c2ecf20Sopenharmony_ci priv->agg_tids_count++; 7328c2ecf20Sopenharmony_ci IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n", 7338c2ecf20Sopenharmony_ci priv->agg_tids_count); 7348c2ecf20Sopenharmony_ci 7358c2ecf20Sopenharmony_ci sta_priv->lq_sta.lq.agg_params.agg_frame_cnt_limit = 7368c2ecf20Sopenharmony_ci sta_priv->max_agg_bufsize; 7378c2ecf20Sopenharmony_ci 7388c2ecf20Sopenharmony_ci IWL_DEBUG_HT(priv, "Tx aggregation enabled on ra = %pM tid = %d\n", 7398c2ecf20Sopenharmony_ci sta->addr, tid); 7408c2ecf20Sopenharmony_ci 7418c2ecf20Sopenharmony_ci return iwl_send_lq_cmd(priv, ctx, 7428c2ecf20Sopenharmony_ci &sta_priv->lq_sta.lq, CMD_ASYNC, false); 7438c2ecf20Sopenharmony_ci} 7448c2ecf20Sopenharmony_ci 7458c2ecf20Sopenharmony_cistatic void iwlagn_check_ratid_empty(struct iwl_priv *priv, int sta_id, u8 tid) 7468c2ecf20Sopenharmony_ci{ 7478c2ecf20Sopenharmony_ci struct iwl_tid_data *tid_data = &priv->tid_data[sta_id][tid]; 7488c2ecf20Sopenharmony_ci enum iwl_rxon_context_id ctx; 7498c2ecf20Sopenharmony_ci struct ieee80211_vif *vif; 7508c2ecf20Sopenharmony_ci u8 *addr; 7518c2ecf20Sopenharmony_ci 7528c2ecf20Sopenharmony_ci lockdep_assert_held(&priv->sta_lock); 7538c2ecf20Sopenharmony_ci 7548c2ecf20Sopenharmony_ci addr = priv->stations[sta_id].sta.sta.addr; 7558c2ecf20Sopenharmony_ci ctx = priv->stations[sta_id].ctxid; 7568c2ecf20Sopenharmony_ci vif = priv->contexts[ctx].vif; 7578c2ecf20Sopenharmony_ci 7588c2ecf20Sopenharmony_ci switch (priv->tid_data[sta_id][tid].agg.state) { 7598c2ecf20Sopenharmony_ci case IWL_EMPTYING_HW_QUEUE_DELBA: 7608c2ecf20Sopenharmony_ci /* There are no packets for this RA / TID in the HW any more */ 7618c2ecf20Sopenharmony_ci if (tid_data->agg.ssn == tid_data->next_reclaimed) { 7628c2ecf20Sopenharmony_ci IWL_DEBUG_TX_QUEUES(priv, 7638c2ecf20Sopenharmony_ci "Can continue DELBA flow ssn = next_recl = %d\n", 7648c2ecf20Sopenharmony_ci tid_data->next_reclaimed); 7658c2ecf20Sopenharmony_ci iwl_trans_txq_disable(priv->trans, 7668c2ecf20Sopenharmony_ci tid_data->agg.txq_id, true); 7678c2ecf20Sopenharmony_ci iwlagn_dealloc_agg_txq(priv, tid_data->agg.txq_id); 7688c2ecf20Sopenharmony_ci tid_data->agg.state = IWL_AGG_OFF; 7698c2ecf20Sopenharmony_ci ieee80211_stop_tx_ba_cb_irqsafe(vif, addr, tid); 7708c2ecf20Sopenharmony_ci } 7718c2ecf20Sopenharmony_ci break; 7728c2ecf20Sopenharmony_ci case IWL_EMPTYING_HW_QUEUE_ADDBA: 7738c2ecf20Sopenharmony_ci /* There are no packets for this RA / TID in the HW any more */ 7748c2ecf20Sopenharmony_ci if (tid_data->agg.ssn == tid_data->next_reclaimed) { 7758c2ecf20Sopenharmony_ci IWL_DEBUG_TX_QUEUES(priv, 7768c2ecf20Sopenharmony_ci "Can continue ADDBA flow ssn = next_recl = %d\n", 7778c2ecf20Sopenharmony_ci tid_data->next_reclaimed); 7788c2ecf20Sopenharmony_ci tid_data->agg.state = IWL_AGG_STARTING; 7798c2ecf20Sopenharmony_ci ieee80211_start_tx_ba_cb_irqsafe(vif, addr, tid); 7808c2ecf20Sopenharmony_ci } 7818c2ecf20Sopenharmony_ci break; 7828c2ecf20Sopenharmony_ci default: 7838c2ecf20Sopenharmony_ci break; 7848c2ecf20Sopenharmony_ci } 7858c2ecf20Sopenharmony_ci} 7868c2ecf20Sopenharmony_ci 7878c2ecf20Sopenharmony_cistatic void iwlagn_non_agg_tx_status(struct iwl_priv *priv, 7888c2ecf20Sopenharmony_ci struct iwl_rxon_context *ctx, 7898c2ecf20Sopenharmony_ci const u8 *addr1) 7908c2ecf20Sopenharmony_ci{ 7918c2ecf20Sopenharmony_ci struct ieee80211_sta *sta; 7928c2ecf20Sopenharmony_ci struct iwl_station_priv *sta_priv; 7938c2ecf20Sopenharmony_ci 7948c2ecf20Sopenharmony_ci rcu_read_lock(); 7958c2ecf20Sopenharmony_ci sta = ieee80211_find_sta(ctx->vif, addr1); 7968c2ecf20Sopenharmony_ci if (sta) { 7978c2ecf20Sopenharmony_ci sta_priv = (void *)sta->drv_priv; 7988c2ecf20Sopenharmony_ci /* avoid atomic ops if this isn't a client */ 7998c2ecf20Sopenharmony_ci if (sta_priv->client && 8008c2ecf20Sopenharmony_ci atomic_dec_return(&sta_priv->pending_frames) == 0) 8018c2ecf20Sopenharmony_ci ieee80211_sta_block_awake(priv->hw, sta, false); 8028c2ecf20Sopenharmony_ci } 8038c2ecf20Sopenharmony_ci rcu_read_unlock(); 8048c2ecf20Sopenharmony_ci} 8058c2ecf20Sopenharmony_ci 8068c2ecf20Sopenharmony_ci/* 8078c2ecf20Sopenharmony_ci * translate ucode response to mac80211 tx status control values 8088c2ecf20Sopenharmony_ci */ 8098c2ecf20Sopenharmony_cistatic void iwlagn_hwrate_to_tx_control(struct iwl_priv *priv, u32 rate_n_flags, 8108c2ecf20Sopenharmony_ci struct ieee80211_tx_info *info) 8118c2ecf20Sopenharmony_ci{ 8128c2ecf20Sopenharmony_ci struct ieee80211_tx_rate *r = &info->status.rates[0]; 8138c2ecf20Sopenharmony_ci 8148c2ecf20Sopenharmony_ci info->status.antenna = 8158c2ecf20Sopenharmony_ci ((rate_n_flags & RATE_MCS_ANT_ABC_MSK) >> RATE_MCS_ANT_POS); 8168c2ecf20Sopenharmony_ci if (rate_n_flags & RATE_MCS_HT_MSK) 8178c2ecf20Sopenharmony_ci r->flags |= IEEE80211_TX_RC_MCS; 8188c2ecf20Sopenharmony_ci if (rate_n_flags & RATE_MCS_GF_MSK) 8198c2ecf20Sopenharmony_ci r->flags |= IEEE80211_TX_RC_GREEN_FIELD; 8208c2ecf20Sopenharmony_ci if (rate_n_flags & RATE_MCS_HT40_MSK) 8218c2ecf20Sopenharmony_ci r->flags |= IEEE80211_TX_RC_40_MHZ_WIDTH; 8228c2ecf20Sopenharmony_ci if (rate_n_flags & RATE_MCS_DUP_MSK) 8238c2ecf20Sopenharmony_ci r->flags |= IEEE80211_TX_RC_DUP_DATA; 8248c2ecf20Sopenharmony_ci if (rate_n_flags & RATE_MCS_SGI_MSK) 8258c2ecf20Sopenharmony_ci r->flags |= IEEE80211_TX_RC_SHORT_GI; 8268c2ecf20Sopenharmony_ci r->idx = iwlagn_hwrate_to_mac80211_idx(rate_n_flags, info->band); 8278c2ecf20Sopenharmony_ci} 8288c2ecf20Sopenharmony_ci 8298c2ecf20Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUG 8308c2ecf20Sopenharmony_ciconst char *iwl_get_tx_fail_reason(u32 status) 8318c2ecf20Sopenharmony_ci{ 8328c2ecf20Sopenharmony_ci#define TX_STATUS_FAIL(x) case TX_STATUS_FAIL_ ## x: return #x 8338c2ecf20Sopenharmony_ci#define TX_STATUS_POSTPONE(x) case TX_STATUS_POSTPONE_ ## x: return #x 8348c2ecf20Sopenharmony_ci 8358c2ecf20Sopenharmony_ci switch (status & TX_STATUS_MSK) { 8368c2ecf20Sopenharmony_ci case TX_STATUS_SUCCESS: 8378c2ecf20Sopenharmony_ci return "SUCCESS"; 8388c2ecf20Sopenharmony_ci TX_STATUS_POSTPONE(DELAY); 8398c2ecf20Sopenharmony_ci TX_STATUS_POSTPONE(FEW_BYTES); 8408c2ecf20Sopenharmony_ci TX_STATUS_POSTPONE(BT_PRIO); 8418c2ecf20Sopenharmony_ci TX_STATUS_POSTPONE(QUIET_PERIOD); 8428c2ecf20Sopenharmony_ci TX_STATUS_POSTPONE(CALC_TTAK); 8438c2ecf20Sopenharmony_ci TX_STATUS_FAIL(INTERNAL_CROSSED_RETRY); 8448c2ecf20Sopenharmony_ci TX_STATUS_FAIL(SHORT_LIMIT); 8458c2ecf20Sopenharmony_ci TX_STATUS_FAIL(LONG_LIMIT); 8468c2ecf20Sopenharmony_ci TX_STATUS_FAIL(FIFO_UNDERRUN); 8478c2ecf20Sopenharmony_ci TX_STATUS_FAIL(DRAIN_FLOW); 8488c2ecf20Sopenharmony_ci TX_STATUS_FAIL(RFKILL_FLUSH); 8498c2ecf20Sopenharmony_ci TX_STATUS_FAIL(LIFE_EXPIRE); 8508c2ecf20Sopenharmony_ci TX_STATUS_FAIL(DEST_PS); 8518c2ecf20Sopenharmony_ci TX_STATUS_FAIL(HOST_ABORTED); 8528c2ecf20Sopenharmony_ci TX_STATUS_FAIL(BT_RETRY); 8538c2ecf20Sopenharmony_ci TX_STATUS_FAIL(STA_INVALID); 8548c2ecf20Sopenharmony_ci TX_STATUS_FAIL(FRAG_DROPPED); 8558c2ecf20Sopenharmony_ci TX_STATUS_FAIL(TID_DISABLE); 8568c2ecf20Sopenharmony_ci TX_STATUS_FAIL(FIFO_FLUSHED); 8578c2ecf20Sopenharmony_ci TX_STATUS_FAIL(INSUFFICIENT_CF_POLL); 8588c2ecf20Sopenharmony_ci TX_STATUS_FAIL(PASSIVE_NO_RX); 8598c2ecf20Sopenharmony_ci TX_STATUS_FAIL(NO_BEACON_ON_RADAR); 8608c2ecf20Sopenharmony_ci } 8618c2ecf20Sopenharmony_ci 8628c2ecf20Sopenharmony_ci return "UNKNOWN"; 8638c2ecf20Sopenharmony_ci 8648c2ecf20Sopenharmony_ci#undef TX_STATUS_FAIL 8658c2ecf20Sopenharmony_ci#undef TX_STATUS_POSTPONE 8668c2ecf20Sopenharmony_ci} 8678c2ecf20Sopenharmony_ci#endif /* CONFIG_IWLWIFI_DEBUG */ 8688c2ecf20Sopenharmony_ci 8698c2ecf20Sopenharmony_cistatic void iwlagn_count_agg_tx_err_status(struct iwl_priv *priv, u16 status) 8708c2ecf20Sopenharmony_ci{ 8718c2ecf20Sopenharmony_ci status &= AGG_TX_STATUS_MSK; 8728c2ecf20Sopenharmony_ci 8738c2ecf20Sopenharmony_ci switch (status) { 8748c2ecf20Sopenharmony_ci case AGG_TX_STATE_UNDERRUN_MSK: 8758c2ecf20Sopenharmony_ci priv->reply_agg_tx_stats.underrun++; 8768c2ecf20Sopenharmony_ci break; 8778c2ecf20Sopenharmony_ci case AGG_TX_STATE_BT_PRIO_MSK: 8788c2ecf20Sopenharmony_ci priv->reply_agg_tx_stats.bt_prio++; 8798c2ecf20Sopenharmony_ci break; 8808c2ecf20Sopenharmony_ci case AGG_TX_STATE_FEW_BYTES_MSK: 8818c2ecf20Sopenharmony_ci priv->reply_agg_tx_stats.few_bytes++; 8828c2ecf20Sopenharmony_ci break; 8838c2ecf20Sopenharmony_ci case AGG_TX_STATE_ABORT_MSK: 8848c2ecf20Sopenharmony_ci priv->reply_agg_tx_stats.abort++; 8858c2ecf20Sopenharmony_ci break; 8868c2ecf20Sopenharmony_ci case AGG_TX_STATE_LAST_SENT_TTL_MSK: 8878c2ecf20Sopenharmony_ci priv->reply_agg_tx_stats.last_sent_ttl++; 8888c2ecf20Sopenharmony_ci break; 8898c2ecf20Sopenharmony_ci case AGG_TX_STATE_LAST_SENT_TRY_CNT_MSK: 8908c2ecf20Sopenharmony_ci priv->reply_agg_tx_stats.last_sent_try++; 8918c2ecf20Sopenharmony_ci break; 8928c2ecf20Sopenharmony_ci case AGG_TX_STATE_LAST_SENT_BT_KILL_MSK: 8938c2ecf20Sopenharmony_ci priv->reply_agg_tx_stats.last_sent_bt_kill++; 8948c2ecf20Sopenharmony_ci break; 8958c2ecf20Sopenharmony_ci case AGG_TX_STATE_SCD_QUERY_MSK: 8968c2ecf20Sopenharmony_ci priv->reply_agg_tx_stats.scd_query++; 8978c2ecf20Sopenharmony_ci break; 8988c2ecf20Sopenharmony_ci case AGG_TX_STATE_TEST_BAD_CRC32_MSK: 8998c2ecf20Sopenharmony_ci priv->reply_agg_tx_stats.bad_crc32++; 9008c2ecf20Sopenharmony_ci break; 9018c2ecf20Sopenharmony_ci case AGG_TX_STATE_RESPONSE_MSK: 9028c2ecf20Sopenharmony_ci priv->reply_agg_tx_stats.response++; 9038c2ecf20Sopenharmony_ci break; 9048c2ecf20Sopenharmony_ci case AGG_TX_STATE_DUMP_TX_MSK: 9058c2ecf20Sopenharmony_ci priv->reply_agg_tx_stats.dump_tx++; 9068c2ecf20Sopenharmony_ci break; 9078c2ecf20Sopenharmony_ci case AGG_TX_STATE_DELAY_TX_MSK: 9088c2ecf20Sopenharmony_ci priv->reply_agg_tx_stats.delay_tx++; 9098c2ecf20Sopenharmony_ci break; 9108c2ecf20Sopenharmony_ci default: 9118c2ecf20Sopenharmony_ci priv->reply_agg_tx_stats.unknown++; 9128c2ecf20Sopenharmony_ci break; 9138c2ecf20Sopenharmony_ci } 9148c2ecf20Sopenharmony_ci} 9158c2ecf20Sopenharmony_ci 9168c2ecf20Sopenharmony_cistatic inline u32 iwlagn_get_scd_ssn(struct iwlagn_tx_resp *tx_resp) 9178c2ecf20Sopenharmony_ci{ 9188c2ecf20Sopenharmony_ci return le32_to_cpup((__le32 *)&tx_resp->status + 9198c2ecf20Sopenharmony_ci tx_resp->frame_count) & IEEE80211_MAX_SN; 9208c2ecf20Sopenharmony_ci} 9218c2ecf20Sopenharmony_ci 9228c2ecf20Sopenharmony_cistatic void iwl_rx_reply_tx_agg(struct iwl_priv *priv, 9238c2ecf20Sopenharmony_ci struct iwlagn_tx_resp *tx_resp) 9248c2ecf20Sopenharmony_ci{ 9258c2ecf20Sopenharmony_ci struct agg_tx_status *frame_status = &tx_resp->status; 9268c2ecf20Sopenharmony_ci int tid = (tx_resp->ra_tid & IWLAGN_TX_RES_TID_MSK) >> 9278c2ecf20Sopenharmony_ci IWLAGN_TX_RES_TID_POS; 9288c2ecf20Sopenharmony_ci int sta_id = (tx_resp->ra_tid & IWLAGN_TX_RES_RA_MSK) >> 9298c2ecf20Sopenharmony_ci IWLAGN_TX_RES_RA_POS; 9308c2ecf20Sopenharmony_ci struct iwl_ht_agg *agg = &priv->tid_data[sta_id][tid].agg; 9318c2ecf20Sopenharmony_ci u32 status = le16_to_cpu(tx_resp->status.status); 9328c2ecf20Sopenharmony_ci int i; 9338c2ecf20Sopenharmony_ci 9348c2ecf20Sopenharmony_ci WARN_ON(tid == IWL_TID_NON_QOS); 9358c2ecf20Sopenharmony_ci 9368c2ecf20Sopenharmony_ci if (agg->wait_for_ba) 9378c2ecf20Sopenharmony_ci IWL_DEBUG_TX_REPLY(priv, 9388c2ecf20Sopenharmony_ci "got tx response w/o block-ack\n"); 9398c2ecf20Sopenharmony_ci 9408c2ecf20Sopenharmony_ci agg->rate_n_flags = le32_to_cpu(tx_resp->rate_n_flags); 9418c2ecf20Sopenharmony_ci agg->wait_for_ba = (tx_resp->frame_count > 1); 9428c2ecf20Sopenharmony_ci 9438c2ecf20Sopenharmony_ci /* 9448c2ecf20Sopenharmony_ci * If the BT kill count is non-zero, we'll get this 9458c2ecf20Sopenharmony_ci * notification again. 9468c2ecf20Sopenharmony_ci */ 9478c2ecf20Sopenharmony_ci if (tx_resp->bt_kill_count && tx_resp->frame_count == 1 && 9488c2ecf20Sopenharmony_ci priv->lib->bt_params && 9498c2ecf20Sopenharmony_ci priv->lib->bt_params->advanced_bt_coexist) { 9508c2ecf20Sopenharmony_ci IWL_DEBUG_COEX(priv, "receive reply tx w/ bt_kill\n"); 9518c2ecf20Sopenharmony_ci } 9528c2ecf20Sopenharmony_ci 9538c2ecf20Sopenharmony_ci if (tx_resp->frame_count == 1) 9548c2ecf20Sopenharmony_ci return; 9558c2ecf20Sopenharmony_ci 9568c2ecf20Sopenharmony_ci IWL_DEBUG_TX_REPLY(priv, "TXQ %d initial_rate 0x%x ssn %d frm_cnt %d\n", 9578c2ecf20Sopenharmony_ci agg->txq_id, 9588c2ecf20Sopenharmony_ci le32_to_cpu(tx_resp->rate_n_flags), 9598c2ecf20Sopenharmony_ci iwlagn_get_scd_ssn(tx_resp), tx_resp->frame_count); 9608c2ecf20Sopenharmony_ci 9618c2ecf20Sopenharmony_ci /* Construct bit-map of pending frames within Tx window */ 9628c2ecf20Sopenharmony_ci for (i = 0; i < tx_resp->frame_count; i++) { 9638c2ecf20Sopenharmony_ci u16 fstatus = le16_to_cpu(frame_status[i].status); 9648c2ecf20Sopenharmony_ci u8 retry_cnt = (fstatus & AGG_TX_TRY_MSK) >> AGG_TX_TRY_POS; 9658c2ecf20Sopenharmony_ci 9668c2ecf20Sopenharmony_ci if (status & AGG_TX_STATUS_MSK) 9678c2ecf20Sopenharmony_ci iwlagn_count_agg_tx_err_status(priv, fstatus); 9688c2ecf20Sopenharmony_ci 9698c2ecf20Sopenharmony_ci if (status & (AGG_TX_STATE_FEW_BYTES_MSK | 9708c2ecf20Sopenharmony_ci AGG_TX_STATE_ABORT_MSK)) 9718c2ecf20Sopenharmony_ci continue; 9728c2ecf20Sopenharmony_ci 9738c2ecf20Sopenharmony_ci if (status & AGG_TX_STATUS_MSK || retry_cnt > 1) 9748c2ecf20Sopenharmony_ci IWL_DEBUG_TX_REPLY(priv, 9758c2ecf20Sopenharmony_ci "%d: status %s (0x%04x), try-count (0x%01x)\n", 9768c2ecf20Sopenharmony_ci i, 9778c2ecf20Sopenharmony_ci iwl_get_agg_tx_fail_reason(fstatus), 9788c2ecf20Sopenharmony_ci fstatus & AGG_TX_STATUS_MSK, 9798c2ecf20Sopenharmony_ci retry_cnt); 9808c2ecf20Sopenharmony_ci } 9818c2ecf20Sopenharmony_ci} 9828c2ecf20Sopenharmony_ci 9838c2ecf20Sopenharmony_ci#ifdef CONFIG_IWLWIFI_DEBUG 9848c2ecf20Sopenharmony_ci#define AGG_TX_STATE_FAIL(x) case AGG_TX_STATE_ ## x: return #x 9858c2ecf20Sopenharmony_ci 9868c2ecf20Sopenharmony_ciconst char *iwl_get_agg_tx_fail_reason(u16 status) 9878c2ecf20Sopenharmony_ci{ 9888c2ecf20Sopenharmony_ci status &= AGG_TX_STATUS_MSK; 9898c2ecf20Sopenharmony_ci switch (status) { 9908c2ecf20Sopenharmony_ci case AGG_TX_STATE_TRANSMITTED: 9918c2ecf20Sopenharmony_ci return "SUCCESS"; 9928c2ecf20Sopenharmony_ci AGG_TX_STATE_FAIL(UNDERRUN_MSK); 9938c2ecf20Sopenharmony_ci AGG_TX_STATE_FAIL(BT_PRIO_MSK); 9948c2ecf20Sopenharmony_ci AGG_TX_STATE_FAIL(FEW_BYTES_MSK); 9958c2ecf20Sopenharmony_ci AGG_TX_STATE_FAIL(ABORT_MSK); 9968c2ecf20Sopenharmony_ci AGG_TX_STATE_FAIL(LAST_SENT_TTL_MSK); 9978c2ecf20Sopenharmony_ci AGG_TX_STATE_FAIL(LAST_SENT_TRY_CNT_MSK); 9988c2ecf20Sopenharmony_ci AGG_TX_STATE_FAIL(LAST_SENT_BT_KILL_MSK); 9998c2ecf20Sopenharmony_ci AGG_TX_STATE_FAIL(SCD_QUERY_MSK); 10008c2ecf20Sopenharmony_ci AGG_TX_STATE_FAIL(TEST_BAD_CRC32_MSK); 10018c2ecf20Sopenharmony_ci AGG_TX_STATE_FAIL(RESPONSE_MSK); 10028c2ecf20Sopenharmony_ci AGG_TX_STATE_FAIL(DUMP_TX_MSK); 10038c2ecf20Sopenharmony_ci AGG_TX_STATE_FAIL(DELAY_TX_MSK); 10048c2ecf20Sopenharmony_ci } 10058c2ecf20Sopenharmony_ci 10068c2ecf20Sopenharmony_ci return "UNKNOWN"; 10078c2ecf20Sopenharmony_ci} 10088c2ecf20Sopenharmony_ci#endif /* CONFIG_IWLWIFI_DEBUG */ 10098c2ecf20Sopenharmony_ci 10108c2ecf20Sopenharmony_cistatic void iwlagn_count_tx_err_status(struct iwl_priv *priv, u16 status) 10118c2ecf20Sopenharmony_ci{ 10128c2ecf20Sopenharmony_ci status &= TX_STATUS_MSK; 10138c2ecf20Sopenharmony_ci 10148c2ecf20Sopenharmony_ci switch (status) { 10158c2ecf20Sopenharmony_ci case TX_STATUS_POSTPONE_DELAY: 10168c2ecf20Sopenharmony_ci priv->reply_tx_stats.pp_delay++; 10178c2ecf20Sopenharmony_ci break; 10188c2ecf20Sopenharmony_ci case TX_STATUS_POSTPONE_FEW_BYTES: 10198c2ecf20Sopenharmony_ci priv->reply_tx_stats.pp_few_bytes++; 10208c2ecf20Sopenharmony_ci break; 10218c2ecf20Sopenharmony_ci case TX_STATUS_POSTPONE_BT_PRIO: 10228c2ecf20Sopenharmony_ci priv->reply_tx_stats.pp_bt_prio++; 10238c2ecf20Sopenharmony_ci break; 10248c2ecf20Sopenharmony_ci case TX_STATUS_POSTPONE_QUIET_PERIOD: 10258c2ecf20Sopenharmony_ci priv->reply_tx_stats.pp_quiet_period++; 10268c2ecf20Sopenharmony_ci break; 10278c2ecf20Sopenharmony_ci case TX_STATUS_POSTPONE_CALC_TTAK: 10288c2ecf20Sopenharmony_ci priv->reply_tx_stats.pp_calc_ttak++; 10298c2ecf20Sopenharmony_ci break; 10308c2ecf20Sopenharmony_ci case TX_STATUS_FAIL_INTERNAL_CROSSED_RETRY: 10318c2ecf20Sopenharmony_ci priv->reply_tx_stats.int_crossed_retry++; 10328c2ecf20Sopenharmony_ci break; 10338c2ecf20Sopenharmony_ci case TX_STATUS_FAIL_SHORT_LIMIT: 10348c2ecf20Sopenharmony_ci priv->reply_tx_stats.short_limit++; 10358c2ecf20Sopenharmony_ci break; 10368c2ecf20Sopenharmony_ci case TX_STATUS_FAIL_LONG_LIMIT: 10378c2ecf20Sopenharmony_ci priv->reply_tx_stats.long_limit++; 10388c2ecf20Sopenharmony_ci break; 10398c2ecf20Sopenharmony_ci case TX_STATUS_FAIL_FIFO_UNDERRUN: 10408c2ecf20Sopenharmony_ci priv->reply_tx_stats.fifo_underrun++; 10418c2ecf20Sopenharmony_ci break; 10428c2ecf20Sopenharmony_ci case TX_STATUS_FAIL_DRAIN_FLOW: 10438c2ecf20Sopenharmony_ci priv->reply_tx_stats.drain_flow++; 10448c2ecf20Sopenharmony_ci break; 10458c2ecf20Sopenharmony_ci case TX_STATUS_FAIL_RFKILL_FLUSH: 10468c2ecf20Sopenharmony_ci priv->reply_tx_stats.rfkill_flush++; 10478c2ecf20Sopenharmony_ci break; 10488c2ecf20Sopenharmony_ci case TX_STATUS_FAIL_LIFE_EXPIRE: 10498c2ecf20Sopenharmony_ci priv->reply_tx_stats.life_expire++; 10508c2ecf20Sopenharmony_ci break; 10518c2ecf20Sopenharmony_ci case TX_STATUS_FAIL_DEST_PS: 10528c2ecf20Sopenharmony_ci priv->reply_tx_stats.dest_ps++; 10538c2ecf20Sopenharmony_ci break; 10548c2ecf20Sopenharmony_ci case TX_STATUS_FAIL_HOST_ABORTED: 10558c2ecf20Sopenharmony_ci priv->reply_tx_stats.host_abort++; 10568c2ecf20Sopenharmony_ci break; 10578c2ecf20Sopenharmony_ci case TX_STATUS_FAIL_BT_RETRY: 10588c2ecf20Sopenharmony_ci priv->reply_tx_stats.bt_retry++; 10598c2ecf20Sopenharmony_ci break; 10608c2ecf20Sopenharmony_ci case TX_STATUS_FAIL_STA_INVALID: 10618c2ecf20Sopenharmony_ci priv->reply_tx_stats.sta_invalid++; 10628c2ecf20Sopenharmony_ci break; 10638c2ecf20Sopenharmony_ci case TX_STATUS_FAIL_FRAG_DROPPED: 10648c2ecf20Sopenharmony_ci priv->reply_tx_stats.frag_drop++; 10658c2ecf20Sopenharmony_ci break; 10668c2ecf20Sopenharmony_ci case TX_STATUS_FAIL_TID_DISABLE: 10678c2ecf20Sopenharmony_ci priv->reply_tx_stats.tid_disable++; 10688c2ecf20Sopenharmony_ci break; 10698c2ecf20Sopenharmony_ci case TX_STATUS_FAIL_FIFO_FLUSHED: 10708c2ecf20Sopenharmony_ci priv->reply_tx_stats.fifo_flush++; 10718c2ecf20Sopenharmony_ci break; 10728c2ecf20Sopenharmony_ci case TX_STATUS_FAIL_INSUFFICIENT_CF_POLL: 10738c2ecf20Sopenharmony_ci priv->reply_tx_stats.insuff_cf_poll++; 10748c2ecf20Sopenharmony_ci break; 10758c2ecf20Sopenharmony_ci case TX_STATUS_FAIL_PASSIVE_NO_RX: 10768c2ecf20Sopenharmony_ci priv->reply_tx_stats.fail_hw_drop++; 10778c2ecf20Sopenharmony_ci break; 10788c2ecf20Sopenharmony_ci case TX_STATUS_FAIL_NO_BEACON_ON_RADAR: 10798c2ecf20Sopenharmony_ci priv->reply_tx_stats.sta_color_mismatch++; 10808c2ecf20Sopenharmony_ci break; 10818c2ecf20Sopenharmony_ci default: 10828c2ecf20Sopenharmony_ci priv->reply_tx_stats.unknown++; 10838c2ecf20Sopenharmony_ci break; 10848c2ecf20Sopenharmony_ci } 10858c2ecf20Sopenharmony_ci} 10868c2ecf20Sopenharmony_ci 10878c2ecf20Sopenharmony_cistatic void iwlagn_set_tx_status(struct iwl_priv *priv, 10888c2ecf20Sopenharmony_ci struct ieee80211_tx_info *info, 10898c2ecf20Sopenharmony_ci struct iwlagn_tx_resp *tx_resp) 10908c2ecf20Sopenharmony_ci{ 10918c2ecf20Sopenharmony_ci u16 status = le16_to_cpu(tx_resp->status.status); 10928c2ecf20Sopenharmony_ci 10938c2ecf20Sopenharmony_ci info->flags &= ~IEEE80211_TX_CTL_AMPDU; 10948c2ecf20Sopenharmony_ci 10958c2ecf20Sopenharmony_ci info->status.rates[0].count = tx_resp->failure_frame + 1; 10968c2ecf20Sopenharmony_ci info->flags |= iwl_tx_status_to_mac80211(status); 10978c2ecf20Sopenharmony_ci iwlagn_hwrate_to_tx_control(priv, le32_to_cpu(tx_resp->rate_n_flags), 10988c2ecf20Sopenharmony_ci info); 10998c2ecf20Sopenharmony_ci if (!iwl_is_tx_success(status)) 11008c2ecf20Sopenharmony_ci iwlagn_count_tx_err_status(priv, status); 11018c2ecf20Sopenharmony_ci} 11028c2ecf20Sopenharmony_ci 11038c2ecf20Sopenharmony_cistatic void iwl_check_abort_status(struct iwl_priv *priv, 11048c2ecf20Sopenharmony_ci u8 frame_count, u32 status) 11058c2ecf20Sopenharmony_ci{ 11068c2ecf20Sopenharmony_ci if (frame_count == 1 && status == TX_STATUS_FAIL_RFKILL_FLUSH) { 11078c2ecf20Sopenharmony_ci IWL_ERR(priv, "Tx flush command to flush out all frames\n"); 11088c2ecf20Sopenharmony_ci if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) 11098c2ecf20Sopenharmony_ci queue_work(priv->workqueue, &priv->tx_flush); 11108c2ecf20Sopenharmony_ci } 11118c2ecf20Sopenharmony_ci} 11128c2ecf20Sopenharmony_ci 11138c2ecf20Sopenharmony_civoid iwlagn_rx_reply_tx(struct iwl_priv *priv, struct iwl_rx_cmd_buffer *rxb) 11148c2ecf20Sopenharmony_ci{ 11158c2ecf20Sopenharmony_ci struct iwl_rx_packet *pkt = rxb_addr(rxb); 11168c2ecf20Sopenharmony_ci u16 sequence = le16_to_cpu(pkt->hdr.sequence); 11178c2ecf20Sopenharmony_ci int txq_id = SEQ_TO_QUEUE(sequence); 11188c2ecf20Sopenharmony_ci int cmd_index __maybe_unused = SEQ_TO_INDEX(sequence); 11198c2ecf20Sopenharmony_ci struct iwlagn_tx_resp *tx_resp = (void *)pkt->data; 11208c2ecf20Sopenharmony_ci struct ieee80211_hdr *hdr; 11218c2ecf20Sopenharmony_ci u32 status = le16_to_cpu(tx_resp->status.status); 11228c2ecf20Sopenharmony_ci u16 ssn = iwlagn_get_scd_ssn(tx_resp); 11238c2ecf20Sopenharmony_ci int tid; 11248c2ecf20Sopenharmony_ci int sta_id; 11258c2ecf20Sopenharmony_ci int freed; 11268c2ecf20Sopenharmony_ci struct ieee80211_tx_info *info; 11278c2ecf20Sopenharmony_ci struct sk_buff_head skbs; 11288c2ecf20Sopenharmony_ci struct sk_buff *skb; 11298c2ecf20Sopenharmony_ci struct iwl_rxon_context *ctx; 11308c2ecf20Sopenharmony_ci bool is_agg = (txq_id >= IWLAGN_FIRST_AMPDU_QUEUE); 11318c2ecf20Sopenharmony_ci 11328c2ecf20Sopenharmony_ci tid = (tx_resp->ra_tid & IWLAGN_TX_RES_TID_MSK) >> 11338c2ecf20Sopenharmony_ci IWLAGN_TX_RES_TID_POS; 11348c2ecf20Sopenharmony_ci sta_id = (tx_resp->ra_tid & IWLAGN_TX_RES_RA_MSK) >> 11358c2ecf20Sopenharmony_ci IWLAGN_TX_RES_RA_POS; 11368c2ecf20Sopenharmony_ci 11378c2ecf20Sopenharmony_ci spin_lock_bh(&priv->sta_lock); 11388c2ecf20Sopenharmony_ci 11398c2ecf20Sopenharmony_ci if (is_agg) { 11408c2ecf20Sopenharmony_ci WARN_ON_ONCE(sta_id >= IWLAGN_STATION_COUNT || 11418c2ecf20Sopenharmony_ci tid >= IWL_MAX_TID_COUNT); 11428c2ecf20Sopenharmony_ci if (txq_id != priv->tid_data[sta_id][tid].agg.txq_id) 11438c2ecf20Sopenharmony_ci IWL_ERR(priv, "txq_id mismatch: %d %d\n", txq_id, 11448c2ecf20Sopenharmony_ci priv->tid_data[sta_id][tid].agg.txq_id); 11458c2ecf20Sopenharmony_ci iwl_rx_reply_tx_agg(priv, tx_resp); 11468c2ecf20Sopenharmony_ci } 11478c2ecf20Sopenharmony_ci 11488c2ecf20Sopenharmony_ci __skb_queue_head_init(&skbs); 11498c2ecf20Sopenharmony_ci 11508c2ecf20Sopenharmony_ci if (tx_resp->frame_count == 1) { 11518c2ecf20Sopenharmony_ci u16 next_reclaimed = le16_to_cpu(tx_resp->seq_ctl); 11528c2ecf20Sopenharmony_ci next_reclaimed = IEEE80211_SEQ_TO_SN(next_reclaimed + 0x10); 11538c2ecf20Sopenharmony_ci 11548c2ecf20Sopenharmony_ci if (is_agg) { 11558c2ecf20Sopenharmony_ci /* If this is an aggregation queue, we can rely on the 11568c2ecf20Sopenharmony_ci * ssn since the wifi sequence number corresponds to 11578c2ecf20Sopenharmony_ci * the index in the TFD ring (%256). 11588c2ecf20Sopenharmony_ci * The seq_ctl is the sequence control of the packet 11598c2ecf20Sopenharmony_ci * to which this Tx response relates. But if there is a 11608c2ecf20Sopenharmony_ci * hole in the bitmap of the BA we received, this Tx 11618c2ecf20Sopenharmony_ci * response may allow to reclaim the hole and all the 11628c2ecf20Sopenharmony_ci * subsequent packets that were already acked. 11638c2ecf20Sopenharmony_ci * In that case, seq_ctl != ssn, and the next packet 11648c2ecf20Sopenharmony_ci * to be reclaimed will be ssn and not seq_ctl. 11658c2ecf20Sopenharmony_ci */ 11668c2ecf20Sopenharmony_ci next_reclaimed = ssn; 11678c2ecf20Sopenharmony_ci } 11688c2ecf20Sopenharmony_ci 11698c2ecf20Sopenharmony_ci if (tid != IWL_TID_NON_QOS) { 11708c2ecf20Sopenharmony_ci priv->tid_data[sta_id][tid].next_reclaimed = 11718c2ecf20Sopenharmony_ci next_reclaimed; 11728c2ecf20Sopenharmony_ci IWL_DEBUG_TX_REPLY(priv, "Next reclaimed packet:%d\n", 11738c2ecf20Sopenharmony_ci next_reclaimed); 11748c2ecf20Sopenharmony_ci iwlagn_check_ratid_empty(priv, sta_id, tid); 11758c2ecf20Sopenharmony_ci } 11768c2ecf20Sopenharmony_ci 11778c2ecf20Sopenharmony_ci iwl_trans_reclaim(priv->trans, txq_id, ssn, &skbs); 11788c2ecf20Sopenharmony_ci 11798c2ecf20Sopenharmony_ci freed = 0; 11808c2ecf20Sopenharmony_ci 11818c2ecf20Sopenharmony_ci /* process frames */ 11828c2ecf20Sopenharmony_ci skb_queue_walk(&skbs, skb) { 11838c2ecf20Sopenharmony_ci hdr = (struct ieee80211_hdr *)skb->data; 11848c2ecf20Sopenharmony_ci 11858c2ecf20Sopenharmony_ci if (!ieee80211_is_data_qos(hdr->frame_control)) 11868c2ecf20Sopenharmony_ci priv->last_seq_ctl = tx_resp->seq_ctl; 11878c2ecf20Sopenharmony_ci 11888c2ecf20Sopenharmony_ci info = IEEE80211_SKB_CB(skb); 11898c2ecf20Sopenharmony_ci ctx = info->driver_data[0]; 11908c2ecf20Sopenharmony_ci iwl_trans_free_tx_cmd(priv->trans, 11918c2ecf20Sopenharmony_ci info->driver_data[1]); 11928c2ecf20Sopenharmony_ci 11938c2ecf20Sopenharmony_ci memset(&info->status, 0, sizeof(info->status)); 11948c2ecf20Sopenharmony_ci 11958c2ecf20Sopenharmony_ci if (status == TX_STATUS_FAIL_PASSIVE_NO_RX && 11968c2ecf20Sopenharmony_ci ctx->vif && 11978c2ecf20Sopenharmony_ci ctx->vif->type == NL80211_IFTYPE_STATION) { 11988c2ecf20Sopenharmony_ci /* block and stop all queues */ 11998c2ecf20Sopenharmony_ci priv->passive_no_rx = true; 12008c2ecf20Sopenharmony_ci IWL_DEBUG_TX_QUEUES(priv, 12018c2ecf20Sopenharmony_ci "stop all queues: passive channel\n"); 12028c2ecf20Sopenharmony_ci ieee80211_stop_queues(priv->hw); 12038c2ecf20Sopenharmony_ci 12048c2ecf20Sopenharmony_ci IWL_DEBUG_TX_REPLY(priv, 12058c2ecf20Sopenharmony_ci "TXQ %d status %s (0x%08x) " 12068c2ecf20Sopenharmony_ci "rate_n_flags 0x%x retries %d\n", 12078c2ecf20Sopenharmony_ci txq_id, 12088c2ecf20Sopenharmony_ci iwl_get_tx_fail_reason(status), 12098c2ecf20Sopenharmony_ci status, 12108c2ecf20Sopenharmony_ci le32_to_cpu(tx_resp->rate_n_flags), 12118c2ecf20Sopenharmony_ci tx_resp->failure_frame); 12128c2ecf20Sopenharmony_ci 12138c2ecf20Sopenharmony_ci IWL_DEBUG_TX_REPLY(priv, 12148c2ecf20Sopenharmony_ci "FrameCnt = %d, idx=%d\n", 12158c2ecf20Sopenharmony_ci tx_resp->frame_count, cmd_index); 12168c2ecf20Sopenharmony_ci } 12178c2ecf20Sopenharmony_ci 12188c2ecf20Sopenharmony_ci /* check if BAR is needed */ 12198c2ecf20Sopenharmony_ci if (is_agg && !iwl_is_tx_success(status)) 12208c2ecf20Sopenharmony_ci info->flags |= IEEE80211_TX_STAT_AMPDU_NO_BACK; 12218c2ecf20Sopenharmony_ci iwlagn_set_tx_status(priv, IEEE80211_SKB_CB(skb), 12228c2ecf20Sopenharmony_ci tx_resp); 12238c2ecf20Sopenharmony_ci if (!is_agg) 12248c2ecf20Sopenharmony_ci iwlagn_non_agg_tx_status(priv, ctx, hdr->addr1); 12258c2ecf20Sopenharmony_ci 12268c2ecf20Sopenharmony_ci freed++; 12278c2ecf20Sopenharmony_ci } 12288c2ecf20Sopenharmony_ci 12298c2ecf20Sopenharmony_ci if (tid != IWL_TID_NON_QOS) { 12308c2ecf20Sopenharmony_ci priv->tid_data[sta_id][tid].next_reclaimed = 12318c2ecf20Sopenharmony_ci next_reclaimed; 12328c2ecf20Sopenharmony_ci IWL_DEBUG_TX_REPLY(priv, "Next reclaimed packet:%d\n", 12338c2ecf20Sopenharmony_ci next_reclaimed); 12348c2ecf20Sopenharmony_ci } 12358c2ecf20Sopenharmony_ci 12368c2ecf20Sopenharmony_ci if (!is_agg && freed != 1) 12378c2ecf20Sopenharmony_ci IWL_ERR(priv, "Q: %d, freed %d\n", txq_id, freed); 12388c2ecf20Sopenharmony_ci 12398c2ecf20Sopenharmony_ci IWL_DEBUG_TX_REPLY(priv, "TXQ %d status %s (0x%08x)\n", txq_id, 12408c2ecf20Sopenharmony_ci iwl_get_tx_fail_reason(status), status); 12418c2ecf20Sopenharmony_ci 12428c2ecf20Sopenharmony_ci IWL_DEBUG_TX_REPLY(priv, 12438c2ecf20Sopenharmony_ci "\t\t\t\tinitial_rate 0x%x retries %d, idx=%d ssn=%d seq_ctl=0x%x\n", 12448c2ecf20Sopenharmony_ci le32_to_cpu(tx_resp->rate_n_flags), 12458c2ecf20Sopenharmony_ci tx_resp->failure_frame, 12468c2ecf20Sopenharmony_ci SEQ_TO_INDEX(sequence), ssn, 12478c2ecf20Sopenharmony_ci le16_to_cpu(tx_resp->seq_ctl)); 12488c2ecf20Sopenharmony_ci } 12498c2ecf20Sopenharmony_ci 12508c2ecf20Sopenharmony_ci iwl_check_abort_status(priv, tx_resp->frame_count, status); 12518c2ecf20Sopenharmony_ci spin_unlock_bh(&priv->sta_lock); 12528c2ecf20Sopenharmony_ci 12538c2ecf20Sopenharmony_ci while (!skb_queue_empty(&skbs)) { 12548c2ecf20Sopenharmony_ci skb = __skb_dequeue(&skbs); 12558c2ecf20Sopenharmony_ci ieee80211_tx_status(priv->hw, skb); 12568c2ecf20Sopenharmony_ci } 12578c2ecf20Sopenharmony_ci} 12588c2ecf20Sopenharmony_ci 12598c2ecf20Sopenharmony_ci/* 12608c2ecf20Sopenharmony_ci * iwlagn_rx_reply_compressed_ba - Handler for REPLY_COMPRESSED_BA 12618c2ecf20Sopenharmony_ci * 12628c2ecf20Sopenharmony_ci * Handles block-acknowledge notification from device, which reports success 12638c2ecf20Sopenharmony_ci * of frames sent via aggregation. 12648c2ecf20Sopenharmony_ci */ 12658c2ecf20Sopenharmony_civoid iwlagn_rx_reply_compressed_ba(struct iwl_priv *priv, 12668c2ecf20Sopenharmony_ci struct iwl_rx_cmd_buffer *rxb) 12678c2ecf20Sopenharmony_ci{ 12688c2ecf20Sopenharmony_ci struct iwl_rx_packet *pkt = rxb_addr(rxb); 12698c2ecf20Sopenharmony_ci struct iwl_compressed_ba_resp *ba_resp = (void *)pkt->data; 12708c2ecf20Sopenharmony_ci struct iwl_ht_agg *agg; 12718c2ecf20Sopenharmony_ci struct sk_buff_head reclaimed_skbs; 12728c2ecf20Sopenharmony_ci struct sk_buff *skb; 12738c2ecf20Sopenharmony_ci int sta_id; 12748c2ecf20Sopenharmony_ci int tid; 12758c2ecf20Sopenharmony_ci int freed; 12768c2ecf20Sopenharmony_ci 12778c2ecf20Sopenharmony_ci /* "flow" corresponds to Tx queue */ 12788c2ecf20Sopenharmony_ci u16 scd_flow = le16_to_cpu(ba_resp->scd_flow); 12798c2ecf20Sopenharmony_ci 12808c2ecf20Sopenharmony_ci /* "ssn" is start of block-ack Tx window, corresponds to index 12818c2ecf20Sopenharmony_ci * (in Tx queue's circular buffer) of first TFD/frame in window */ 12828c2ecf20Sopenharmony_ci u16 ba_resp_scd_ssn = le16_to_cpu(ba_resp->scd_ssn); 12838c2ecf20Sopenharmony_ci 12848c2ecf20Sopenharmony_ci if (scd_flow >= priv->trans->trans_cfg->base_params->num_of_queues) { 12858c2ecf20Sopenharmony_ci IWL_ERR(priv, 12868c2ecf20Sopenharmony_ci "BUG_ON scd_flow is bigger than number of queues\n"); 12878c2ecf20Sopenharmony_ci return; 12888c2ecf20Sopenharmony_ci } 12898c2ecf20Sopenharmony_ci 12908c2ecf20Sopenharmony_ci sta_id = ba_resp->sta_id; 12918c2ecf20Sopenharmony_ci tid = ba_resp->tid; 12928c2ecf20Sopenharmony_ci agg = &priv->tid_data[sta_id][tid].agg; 12938c2ecf20Sopenharmony_ci 12948c2ecf20Sopenharmony_ci spin_lock_bh(&priv->sta_lock); 12958c2ecf20Sopenharmony_ci 12968c2ecf20Sopenharmony_ci if (unlikely(!agg->wait_for_ba)) { 12978c2ecf20Sopenharmony_ci if (unlikely(ba_resp->bitmap)) 12988c2ecf20Sopenharmony_ci IWL_ERR(priv, "Received BA when not expected\n"); 12998c2ecf20Sopenharmony_ci spin_unlock_bh(&priv->sta_lock); 13008c2ecf20Sopenharmony_ci return; 13018c2ecf20Sopenharmony_ci } 13028c2ecf20Sopenharmony_ci 13038c2ecf20Sopenharmony_ci if (unlikely(scd_flow != agg->txq_id)) { 13048c2ecf20Sopenharmony_ci /* 13058c2ecf20Sopenharmony_ci * FIXME: this is a uCode bug which need to be addressed, 13068c2ecf20Sopenharmony_ci * log the information and return for now. 13078c2ecf20Sopenharmony_ci * Since it is can possibly happen very often and in order 13088c2ecf20Sopenharmony_ci * not to fill the syslog, don't use IWL_ERR or IWL_WARN 13098c2ecf20Sopenharmony_ci */ 13108c2ecf20Sopenharmony_ci IWL_DEBUG_TX_QUEUES(priv, 13118c2ecf20Sopenharmony_ci "Bad queue mapping txq_id=%d, agg_txq[sta:%d,tid:%d]=%d\n", 13128c2ecf20Sopenharmony_ci scd_flow, sta_id, tid, agg->txq_id); 13138c2ecf20Sopenharmony_ci spin_unlock_bh(&priv->sta_lock); 13148c2ecf20Sopenharmony_ci return; 13158c2ecf20Sopenharmony_ci } 13168c2ecf20Sopenharmony_ci 13178c2ecf20Sopenharmony_ci __skb_queue_head_init(&reclaimed_skbs); 13188c2ecf20Sopenharmony_ci 13198c2ecf20Sopenharmony_ci /* Release all TFDs before the SSN, i.e. all TFDs in front of 13208c2ecf20Sopenharmony_ci * block-ack window (we assume that they've been successfully 13218c2ecf20Sopenharmony_ci * transmitted ... if not, it's too late anyway). */ 13228c2ecf20Sopenharmony_ci iwl_trans_reclaim(priv->trans, scd_flow, ba_resp_scd_ssn, 13238c2ecf20Sopenharmony_ci &reclaimed_skbs); 13248c2ecf20Sopenharmony_ci 13258c2ecf20Sopenharmony_ci IWL_DEBUG_TX_REPLY(priv, "REPLY_COMPRESSED_BA [%d] Received from %pM, " 13268c2ecf20Sopenharmony_ci "sta_id = %d\n", 13278c2ecf20Sopenharmony_ci agg->wait_for_ba, 13288c2ecf20Sopenharmony_ci (u8 *) &ba_resp->sta_addr_lo32, 13298c2ecf20Sopenharmony_ci ba_resp->sta_id); 13308c2ecf20Sopenharmony_ci IWL_DEBUG_TX_REPLY(priv, "TID = %d, SeqCtl = %d, bitmap = 0x%llx, " 13318c2ecf20Sopenharmony_ci "scd_flow = %d, scd_ssn = %d sent:%d, acked:%d\n", 13328c2ecf20Sopenharmony_ci ba_resp->tid, le16_to_cpu(ba_resp->seq_ctl), 13338c2ecf20Sopenharmony_ci (unsigned long long)le64_to_cpu(ba_resp->bitmap), 13348c2ecf20Sopenharmony_ci scd_flow, ba_resp_scd_ssn, ba_resp->txed, 13358c2ecf20Sopenharmony_ci ba_resp->txed_2_done); 13368c2ecf20Sopenharmony_ci 13378c2ecf20Sopenharmony_ci /* Mark that the expected block-ack response arrived */ 13388c2ecf20Sopenharmony_ci agg->wait_for_ba = false; 13398c2ecf20Sopenharmony_ci 13408c2ecf20Sopenharmony_ci /* Sanity check values reported by uCode */ 13418c2ecf20Sopenharmony_ci if (ba_resp->txed_2_done > ba_resp->txed) { 13428c2ecf20Sopenharmony_ci IWL_DEBUG_TX_REPLY(priv, 13438c2ecf20Sopenharmony_ci "bogus sent(%d) and ack(%d) count\n", 13448c2ecf20Sopenharmony_ci ba_resp->txed, ba_resp->txed_2_done); 13458c2ecf20Sopenharmony_ci /* 13468c2ecf20Sopenharmony_ci * set txed_2_done = txed, 13478c2ecf20Sopenharmony_ci * so it won't impact rate scale 13488c2ecf20Sopenharmony_ci */ 13498c2ecf20Sopenharmony_ci ba_resp->txed = ba_resp->txed_2_done; 13508c2ecf20Sopenharmony_ci } 13518c2ecf20Sopenharmony_ci 13528c2ecf20Sopenharmony_ci priv->tid_data[sta_id][tid].next_reclaimed = ba_resp_scd_ssn; 13538c2ecf20Sopenharmony_ci 13548c2ecf20Sopenharmony_ci iwlagn_check_ratid_empty(priv, sta_id, tid); 13558c2ecf20Sopenharmony_ci freed = 0; 13568c2ecf20Sopenharmony_ci 13578c2ecf20Sopenharmony_ci skb_queue_walk(&reclaimed_skbs, skb) { 13588c2ecf20Sopenharmony_ci struct ieee80211_hdr *hdr = (void *)skb->data; 13598c2ecf20Sopenharmony_ci struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); 13608c2ecf20Sopenharmony_ci 13618c2ecf20Sopenharmony_ci if (ieee80211_is_data_qos(hdr->frame_control)) 13628c2ecf20Sopenharmony_ci freed++; 13638c2ecf20Sopenharmony_ci else 13648c2ecf20Sopenharmony_ci WARN_ON_ONCE(1); 13658c2ecf20Sopenharmony_ci 13668c2ecf20Sopenharmony_ci iwl_trans_free_tx_cmd(priv->trans, info->driver_data[1]); 13678c2ecf20Sopenharmony_ci 13688c2ecf20Sopenharmony_ci memset(&info->status, 0, sizeof(info->status)); 13698c2ecf20Sopenharmony_ci /* Packet was transmitted successfully, failures come as single 13708c2ecf20Sopenharmony_ci * frames because before failing a frame the firmware transmits 13718c2ecf20Sopenharmony_ci * it without aggregation at least once. 13728c2ecf20Sopenharmony_ci */ 13738c2ecf20Sopenharmony_ci info->flags |= IEEE80211_TX_STAT_ACK; 13748c2ecf20Sopenharmony_ci 13758c2ecf20Sopenharmony_ci if (freed == 1) { 13768c2ecf20Sopenharmony_ci /* this is the first skb we deliver in this batch */ 13778c2ecf20Sopenharmony_ci /* put the rate scaling data there */ 13788c2ecf20Sopenharmony_ci info = IEEE80211_SKB_CB(skb); 13798c2ecf20Sopenharmony_ci memset(&info->status, 0, sizeof(info->status)); 13808c2ecf20Sopenharmony_ci info->flags |= IEEE80211_TX_STAT_AMPDU; 13818c2ecf20Sopenharmony_ci info->status.ampdu_ack_len = ba_resp->txed_2_done; 13828c2ecf20Sopenharmony_ci info->status.ampdu_len = ba_resp->txed; 13838c2ecf20Sopenharmony_ci iwlagn_hwrate_to_tx_control(priv, agg->rate_n_flags, 13848c2ecf20Sopenharmony_ci info); 13858c2ecf20Sopenharmony_ci } 13868c2ecf20Sopenharmony_ci } 13878c2ecf20Sopenharmony_ci 13888c2ecf20Sopenharmony_ci spin_unlock_bh(&priv->sta_lock); 13898c2ecf20Sopenharmony_ci 13908c2ecf20Sopenharmony_ci while (!skb_queue_empty(&reclaimed_skbs)) { 13918c2ecf20Sopenharmony_ci skb = __skb_dequeue(&reclaimed_skbs); 13928c2ecf20Sopenharmony_ci ieee80211_tx_status(priv->hw, skb); 13938c2ecf20Sopenharmony_ci } 13948c2ecf20Sopenharmony_ci} 1395