From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1792562993; b=p0FIv/B2OsBa+m79IBAUHfXQ/K5RMR0nZeDmpNWySeXxDW8rJpu1XIQLtjAKojHsGzEu wnNn6554CdNNqTC2kQVoHSc8zEYe4kV+S16EIE+j+5LwPhMnBHZ+h2RxFf6041YXGdLEh Mwxer+vR9AsPZcpc+kDrCfwLNdxenS2kafvZTuqHVvUD7JcpaaObuWIgsxg3CGkdtXnIA VrmhOz6Bn0dfL10wz3g0TmrCQjv0wautMbJ8HJsQfIaMF3wofbbhWLyUHXqS4f+SKKwg/ m3pdDvM6RS2IEr2X1bFRW6p2ZaEF28vAEEKnWQ3uZKNjZV6VbSJPybJa8U49U7lRLJQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1792562993; h=DMARC-Filter:DKIM-Signature:Received:X-MC-Unique: X-Mimecast-MFC-AGG-ID:Received:Received:From:To:Cc:Subject:Date: Message-ID:In-Reply-To:References:MIME-Version: Content-Transfer-Encoding:X-Scanned-By; bh=/ULUQfRs7dpUUwo6BvSmvv+J9oUgYVFAYQ9WXncGW04=; b=ZvacXDtSIP4TWRcUYu8UQ5C9mbpvy1SueiFsm8KjrX0u36WzNVDGkzRUZohLNZvocKz7 hKfm5hlj/7CwoSFvw58I4H/u7ukZm0bU9Eriv0HONYomUfrQpQvLPMELyJkil/JwScImP g/uJbBKPV9+V81uPhLCM2fiEMdZC34DNw5RvuXu1+yHZZjChheGcRaji7466/qdXwsUSE E8tPYsk3fEhN3TNb0AjY6Mdr6dYZ0FkHWD4JWZWsDwlDvHofwCipOjwdpDsAJIX3ppx7W trwYVRGhNLfNXs2rl4UQbDMokRDS7+AHZ3Y7hD4yXjOL1gS92vK/TJGvMlwmGIca/gA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b="G3eZnu/R"; arc=none smtp.remote-ip=170.10.133.124 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E120F606A31B for ; Wed, 21 Oct 2026 06:09:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E120F606A31B Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=G3eZnu/R DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1792562992; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/ULUQfRs7dpUUwo6BvSmvv+J9oUgYVFAYQ9WXncGW04=; b=G3eZnu/RlvzedX38t0cegG9HeCTEz+H3EbJQiQcI+1SyHDL87zN3KDO6+F+vh6QxH5bzT9 nIE4LbfW3Ntj35yWJH8fdZN5CaH3iYa3ieV0Ne4f0OSXE8qntbeNbf78gEPxcJtKlp6PCA keFTD61EHf0rPzP1uuzOge5QSdtDUE8= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-482-22M26FMGN1utTps-oAMSWA-1; Wed, 21 Oct 2026 06:09:48 +0000 X-MC-Unique: 22M26FMGN1utTps-oAMSWA-1 X-Mimecast-MFC-AGG-ID: 22M26FMGN1utTps-oAMSWA_1792562987 Received: from mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.93]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 25B391800611; Wed, 21 Oct 2026 06:09:47 +0000 (UTC) Received: from jtornosm-thinkpadp1gen7.rmtes.csb (headnet04.pony-001.prod.iad2.dc.redhat.com [10.2.32.116]) by mx-prod-int-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 886091800347; Wed, 21 Oct 2026 06:09:45 +0000 (UTC) From: Jose Ignacio Tornos Martinez To: jjohnson@kernel.org Cc: ath11k@lists.infradead.org, ath12k@lists.infradead.org, linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org, Jose Ignacio Tornos Martinez Subject: [PATCH v8 2/2] wifi: ath12k: implement custom wake_tx_queue with flow control Date: Wed, 21 Oct 2026 08:09:31 +0200 Message-ID: <20261021060931.249629-3-jtornosm@redhat.com> In-Reply-To: <20261021060931.249629-1-jtornosm@redhat.com> References: <20261021060931.249629-1-jtornosm@redhat.com> X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.93 Under heavy traffic, ath12k can hang and experiences -ENOMEM errors ("failed to transmit frame -12") when the hardware TCL ring fills up. This issue is more commonly observed in VMs with PCIe passthrough but also occurs on bare metal systems. Implement a custom wake_tx_queue operation that: 1. Checks hardware ring space before dequeuing packets from mac80211 2. Uses per-ring locking (wake_tx_lock with spin_lock_bh) to serialize concurrent wake_tx_queue calls targeting the same ring and to ensure bottom halves are disabled as required by ieee80211_tx_dequeue() 3. Syncs with hardware state to get accurate free slot count 4. Resolves the target TCL ring once using get_ring_selector(txq->ac), which selects the ring based on the access category 5. Returns early during firmware crash in the same way as other tx paths This approach follows the pattern used in the iwlwifi driver, adapted for ath12k's hardware ring architecture. This prevents hangs, eliminates -ENOMEM errors, and improves throughput by optimizing resource usage and preventing unnecessary packet drops. Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.1.c7-00108-QCAHMTSWPL_V1.0_V2.0_SILICONZ_UPSTREAM-3 Signed-off-by: Jose Ignacio Tornos Martinez --- v8: Split ath11k and ath12k into separate series to avoid conflict with Julius's airtime queue limits series (ath11k only) and help to unblock both No code changes from v7 v7: https://lore.kernel.org/all/20260917064825.12747-5-jtornosm@redhat.com/ drivers/net/wireless/ath/ath12k/dp.c | 1 + drivers/net/wireless/ath/ath12k/dp.h | 2 + drivers/net/wireless/ath/ath12k/hal.c | 1 + drivers/net/wireless/ath/ath12k/wifi7/hw.c | 69 +++++++++++++++++++++- 4 files changed, 72 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath12k/dp.c b/drivers/net/wireless/ath/ath12k/dp.c index f9b37d75956d..e62fa416b992 100644 --- a/drivers/net/wireless/ath/ath12k/dp.c +++ b/drivers/net/wireless/ath/ath12k/dp.c @@ -1537,6 +1537,7 @@ static int ath12k_dp_setup(struct ath12k_base *ab) } for (i = 0; i < ab->hw_params->max_tx_ring; i++) { + spin_lock_init(&dp->tx_ring[i].wake_tx_lock); dp->tx_ring[i].tcl_data_ring_id = i; dp->tx_ring[i].tx_status_head = 0; diff --git a/drivers/net/wireless/ath/ath12k/dp.h b/drivers/net/wireless/ath/ath12k/dp.h index bef0f2ba0560..4bf8a8a6d76c 100644 --- a/drivers/net/wireless/ath/ath12k/dp.h +++ b/drivers/net/wireless/ath/ath12k/dp.h @@ -58,6 +58,8 @@ struct dp_tx_ring { u8 tcl_data_ring_id; struct dp_srng tcl_data_ring; struct dp_srng tcl_comp_ring; + /* Serializes wake_tx_queue operations for this ring */ + spinlock_t wake_tx_lock; struct hal_wbm_completion_ring_tx *tx_status; int tx_status_head; int tx_status_tail; diff --git a/drivers/net/wireless/ath/ath12k/hal.c b/drivers/net/wireless/ath/ath12k/hal.c index c0c3d2f047ef..fbe4dc41e34b 100644 --- a/drivers/net/wireless/ath/ath12k/hal.c +++ b/drivers/net/wireless/ath/ath12k/hal.c @@ -390,6 +390,7 @@ int ath12k_hal_srng_src_num_free(struct ath12k_base *ab, struct hal_srng *srng, else return ((srng->ring_size - hp + tp) / srng->entry_size) - 1; } +EXPORT_SYMBOL(ath12k_hal_srng_src_num_free); void *ath12k_hal_srng_src_next_peek(struct ath12k_base *ab, struct hal_srng *srng) diff --git a/drivers/net/wireless/ath/ath12k/wifi7/hw.c b/drivers/net/wireless/ath/ath12k/wifi7/hw.c index 678c512a2199..7bfeb9397465 100644 --- a/drivers/net/wireless/ath/ath12k/wifi7/hw.c +++ b/drivers/net/wireless/ath/ath12k/wifi7/hw.c @@ -1160,9 +1160,76 @@ static void ath12k_wifi7_mac_op_tx(struct ieee80211_hw *hw, } } +static void ath12k_wifi7_mac_op_wake_tx_queue(struct ieee80211_hw *hw, + struct ieee80211_txq *txq) +{ + struct ath12k_vif *ahvif = ath12k_vif_to_ahvif(txq->vif); + struct ieee80211_tx_control control = { + .sta = txq->sta, + }; + struct ieee80211_vif *vif = txq->vif; + struct ath12k_link_vif *arvif; + struct dp_tx_ring *tx_ring; + struct hal_srng *tcl_ring; + struct ath12k_sta *ahsta; + struct ath12k_dp *dp; + struct sk_buff *skb; + struct ath12k *ar; + u8 ring_selector; + int num_free; + u8 ring_id; + u8 link_id; + + if (ieee80211_vif_is_mld(vif) && txq->sta) { + ahsta = ath12k_sta_to_ahsta(txq->sta); + link_id = ahsta->assoc_link_id; + } else { + link_id = ahvif->deflink.link_id; + } + + rcu_read_lock(); + + arvif = rcu_dereference(ahvif->link[link_id]); + if (!arvif || !arvif->ar) { + rcu_read_unlock(); + return; + } + + ar = arvif->ar; + dp = ar->ab->dp; + + ring_selector = dp->hw_params->hw_ops->get_ring_selector(txq->ac); + ring_id = ring_selector % dp->hw_params->max_tx_ring; + tx_ring = &dp->tx_ring[ring_id]; + tcl_ring = &dp->hal->srng_list[tx_ring->tcl_data_ring.ring_id]; + + while (1) { + if (unlikely(test_bit(ATH12K_FLAG_CRASH_FLUSH, + &ar->ab->dev_flags))) + break; + + guard(spinlock_bh)(&tx_ring->wake_tx_lock); + + spin_lock_bh(&tcl_ring->lock); + num_free = ath12k_hal_srng_src_num_free(ar->ab, tcl_ring, true); + spin_unlock_bh(&tcl_ring->lock); + + if (num_free == 0) + break; + + skb = ieee80211_tx_dequeue(hw, txq); + if (!skb) + break; + + ath12k_wifi7_mac_op_tx(hw, &control, skb); + } + + rcu_read_unlock(); +} + static const struct ieee80211_ops ath12k_ops_wifi7 = { .tx = ath12k_wifi7_mac_op_tx, - .wake_tx_queue = ieee80211_handle_wake_tx_queue, + .wake_tx_queue = ath12k_wifi7_mac_op_wake_tx_queue, .start = ath12k_mac_op_start, .stop = ath12k_mac_op_stop, .reconfig_complete = ath12k_mac_op_reconfig_complete, -- 2.54.0