Skip to contentSkip to conversation

ath11k/ath12k: implement TX flow control

PATCH Superseded Jose Ignacio Tornos Martinez 3 participants 11 messages Sep 17 – Oct 20

Subsystems (2)

v7 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v7 cover ath11k/ath12k: implement TX flow control

This series implements custom wake_tx_queue operations for ath11k and ath12k drivers to prevent hardware ring overflow issues under heavy traffic.

Without proper flow control, both drivers experience -ENOMEM errors ("failed to transmit frame -12") when the hardware TCL ring fills up. Additionally, ath12k can hang under sustained high throughput. These issues are more commonly observed in VMs with PCIe passthrough but also occur on bare metal systems.

The implementation follows the pattern used in the iwlwifi driver, adapted for ath11k/ath12k hardware ring architecture, checking hardware ring space before dequeuing packets from mac80211.

Testing shows stable operation with eliminated -ENOMEM errors, no hangs, and improved throughput under heavy traffic conditions.

Jose Ignacio Tornos Martinez (4):
wifi: ath11k: use queue mapping for WCN6750 ring selection
wifi: ath11k/ath12k: remove skb parameter from get_ring_selector
wifi: ath11k: implement custom wake_tx_queue with flow control
wifi: ath12k: implement custom wake_tx_queue with flow control

v7: No modification in patches 1 and 2
Address comments from Jeff Johnson:
Patch 3: Add the defensive pattern _bh in both spinlocks (ath11k) Patch 4: Add the defensive pattern _bh in both spinlocks (ath12k)
v6: https://lore.kernel.org/all/[email protected]/
--
2.49.0

#1 lore raw

PATCH v7 1/4 wifi: ath11k: use queue mapping for WCN6750 ring selection

WCN6750 selects the TCL ring using skb_get_hash() to distribute flows across its 3 TX rings, as introduced in commit 7636c9a6e7d7 ("wifi: ath11k: Add multi TX ring support for WCN6750"). The goal was to prevent out-of-order packet delivery that could occur with smp_processor_id()-based selection, where packets of the same flow could end up on different rings depending on CPU scheduling.

Switch to skb_get_queue_mapping() instead, which returns the AC (access category) assigned by mac80211 in ieee80211_select_queue(). This provides the same ordering guarantee: packets of the same TID always map to the same AC and therefore always land on the same ring, preventing reordering.

Using queue mapping for ring selection also provides QoS-aware distribution, where each traffic class gets a deterministic ring assignment, rather than the random distribution that flow hashing produces. With 3 rings and 4 ACs (VO=0, VI=1, BE=2, BK=3), the mapping becomes: VO and BK share ring 0, VI uses ring 1, and BE uses ring 2.

This matches the approach already used by ath12k for WCN7850, which has the same ring count and uses skb_get_queue_mapping() for its ring selector.

This change also removes the dependency on skb_get_hash(), which is relevant for a subsequent patch that removes the skb parameter from the get_ring_selector hw_ops callback entirely, enabling TX flow control in wake_tx_queue without requiring a complex peek to inspect frames before dequeue.

---
v7: no modification
v6: https://lore.kernel.org/all/[email protected]/

 drivers/net/wireless/ath/ath11k/hw.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)
drivers/net/wireless/ath/ath11k/hw.c +1 -7
index 93f9a03c48dc..d679e39dce03 100644
@@ -891,13 +891,7 @@ static u32 ath11k_hw_ipq8074_get_tcl_ring_selector(struct sk_buff *skb)
 
 static u32 ath11k_hw_wcn6750_get_tcl_ring_selector(struct sk_buff *skb)
 {
-	/* Select the TCL ring based on the flow hash of the SKB instead
-	 * of CPU ID. Since applications pumping the traffic can be scheduled
-	 * on multiple CPUs, there is a chance that packets of the same flow
-	 * could end on different TCL rings, this could sometimes results in
-	 * an out of order arrival of the packets at the receiver.
-	 */
-	return skb_get_hash(skb);
+	return skb_get_queue_mapping(skb);
 }
 
 const struct ath11k_hw_ops ipq8074_ops = {
Signature · 1 line
2.54.0
#2 lore raw

PATCH v7 2/4 wifi: ath11k/ath12k: remove skb parameter from get_ring_selector

In reply to Jose Ignacio Tornos Martinez

Change the get_ring_selector hw_ops callback signature from get_ring_selector(struct sk_buff *skb) to get_ring_selector(u8 ac), removing the dependency on the skb.

After the previous patch switched WCN6750 from skb_get_hash() to skb_get_queue_mapping(), all get_ring_selector implementations fall into two categories:
- smp_processor_id(): ignores the skb entirely
- skb_get_queue_mapping(): only reads the AC value from the skb

Since the AC is the only information extracted from the skb, pass it directly as a u8 parameter instead. Callers in the dp_tx path now pass skb_get_queue_mapping(skb), which preserves the exact same behavior.

This change enables a subsequent patch to call get_ring_selector() from wake_tx_queue using txq->ac, without needing access to the skb. mac80211 guarantees that skb_get_queue_mapping(skb) == txq->ac for any skb dequeued from a given txq, since both values are derived from the same skb->priority through the same AC mapping.

No functional change.

---
v7: no modification
v6: https://lore.kernel.org/all/[email protected]/

 drivers/net/wireless/ath/ath11k/dp_tx.c       |  2 +-
 drivers/net/wireless/ath/ath11k/hw.c          | 16 ++++------------
 drivers/net/wireless/ath/ath11k/hw.h          |  2 +-
 drivers/net/wireless/ath/ath12k/hw.h          |  2 +-
 drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c |  2 +-
 drivers/net/wireless/ath/ath12k/wifi7/hw.c    |  6 +++---
 6 files changed, 11 insertions(+), 19 deletions(-)
drivers/net/wireless/ath/ath11k/dp_tx.c +1 -1
index cac970c92806..083aca8ff355 100644
@@ -108,7 +108,7 @@ int ath11k_dp_tx(struct ath11k *ar, struct ath11k_vif *arvif,
 
 	pool_id = skb_get_queue_mapping(skb) & (ATH11K_HW_MAX_QUEUES - 1);
 
-	ring_selector = ab->hw_params.hw_ops->get_ring_selector(skb);
+	ring_selector = ab->hw_params.hw_ops->get_ring_selector(skb_get_queue_mapping(skb));
 
 tcl_ring_sel:
 	tcl_ring_retry = false;
drivers/net/wireless/ath/ath11k/hw.c +4 -12
index d679e39dce03..8a28c1d4c17b 100644
@@ -876,22 +876,14 @@ static bool ath11k_hw_wcn6855_rx_desc_get_ldpc_support(struct hal_rx_desc *desc)
 			 __le32_to_cpu(desc->u.wcn6855.msdu_start.info2));
 }
 
-static u32 ath11k_hw_ipq8074_get_tcl_ring_selector(struct sk_buff *skb)
-{
-	/* Let the default ring selection be based on current processor
-	 * number, where one of the 3 tcl rings are selected based on
-	 * the smp_processor_id(). In case that ring
-	 * is full/busy, we resort to other available rings.
-	 * If all rings are full, we drop the packet.
-	 *
-	 * TODO: Add throttling logic when all rings are full
-	 */
+static u32 ath11k_hw_ipq8074_get_tcl_ring_selector(u8 ac)
+{
 	return smp_processor_id();
 }
 
-static u32 ath11k_hw_wcn6750_get_tcl_ring_selector(struct sk_buff *skb)
+static u32 ath11k_hw_wcn6750_get_tcl_ring_selector(u8 ac)
 {
-	return skb_get_queue_mapping(skb);
+	return ac;
 }
 
 const struct ath11k_hw_ops ipq8074_ops = {
drivers/net/wireless/ath/ath11k/hw.h +1 -1
index 4996536fbd14..b6bc8b72d812 100644
@@ -273,7 +273,7 @@ struct ath11k_hw_ops {
 	u16 (*mpdu_info_get_peerid)(struct hal_rx_mpdu_info *mpdu_info);
 	bool (*rx_desc_mac_addr2_valid)(struct hal_rx_desc *desc);
 	u8* (*rx_desc_mpdu_start_addr2)(struct hal_rx_desc *desc);
-	u32 (*get_ring_selector)(struct sk_buff *skb);
+	u32 (*get_ring_selector)(u8 ac);
 };
 
 extern const struct ath11k_hw_ops ipq8074_ops;
drivers/net/wireless/ath/ath12k/hw.h +1 -1
index 86fb8b719613..65caa7a2349f 100644
@@ -243,7 +243,7 @@ struct ath12k_hw_ops {
 	int (*mac_id_to_pdev_id)(const struct ath12k_hw_params *hw, int mac_id);
 	int (*mac_id_to_srng_id)(const struct ath12k_hw_params *hw, int mac_id);
 	int (*rxdma_ring_sel_config)(struct ath12k_base *ab);
-	u8 (*get_ring_selector)(struct sk_buff *skb);
+	u8 (*get_ring_selector)(u8 ac);
 	bool (*dp_srng_is_tx_comp_ring)(int ring_num);
 	bool (*is_frame_link_agnostic)(struct ath12k_link_vif *arvif,
 				       struct ieee80211_mgmt *mgmt);
drivers/net/wireless/ath/ath12k/wifi7/dp_tx.c +1 -1
index d2749de44553..74359e8eea47 100644
@@ -111,7 +111,7 @@ int ath12k_wifi7_dp_tx(struct ath12k_pdev_dp *dp_pdev, struct ath12k_link_vif *a
 	 * If all rings are full, we drop the packet.
 	 * TODO: Add throttling logic when all rings are full
 	 */
-	ring_selector = dp->hw_params->hw_ops->get_ring_selector(skb);
+	ring_selector = dp->hw_params->hw_ops->get_ring_selector(skb_get_queue_mapping(skb));
 
 tcl_ring_sel:
 	tcl_ring_retry = false;
drivers/net/wireless/ath/ath12k/wifi7/hw.c +3 -3
index d9fdd2fc8298..7436cf70925a 100644
@@ -49,7 +49,7 @@ ath12k_wifi7_hw_mac_id_to_srng_id_qcn9274(const struct ath12k_hw_params *hw,
 	return 0;
 }
 
-static u8 ath12k_wifi7_hw_get_ring_selector_qcn9274(struct sk_buff *skb)
+static u8 ath12k_wifi7_hw_get_ring_selector_qcn9274(u8 ac)
 {
 	return smp_processor_id();
 }
@@ -83,9 +83,9 @@ ath12k_wifi7_hw_mac_id_to_srng_id_wcn7850(const struct ath12k_hw_params *hw,
 	return mac_id;
 }
 
-static u8 ath12k_wifi7_hw_get_ring_selector_wcn7850(struct sk_buff *skb)
+static u8 ath12k_wifi7_hw_get_ring_selector_wcn7850(u8 ac)
 {
-	return skb_get_queue_mapping(skb);
+	return ac;
 }
 
 static bool ath12k_wifi7_dp_srng_is_comp_ring_wcn7850(int ring_num)
Signature · 1 line
2.54.0
#3 lore raw

PATCH v7 3/4 wifi: ath11k: implement custom wake_tx_queue with flow control

In reply to Jose Ignacio Tornos Martinez

Under heavy traffic, ath11k experiences frequent -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. It is particularly problematic on devices with a single shared TCL ring where all traffic classes compete for the same 512 descriptor slots.

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 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 ath11k's hardware ring architecture.

This eliminates -ENOMEM errors and improves throughput by optimizing resource usage and preventing unnecessary packet drops.

Tested-on: WCN6855 hw2.0 PCI WLAN.HSP.1.1-03125-QCAHSPSWPL_V1_V2_SILICONZ_LITE-3.6510.41

---
v7: Address comments from Jeff Johnson:
- Add the defensive pattern _bh in both spinlocks
v6: https://lore.kernel.org/all/[email protected]/

 drivers/net/wireless/ath/ath11k/dp.c  |  1 +
 drivers/net/wireless/ath/ath11k/dp.h  |  2 ++
 drivers/net/wireless/ath/ath11k/mac.c | 49 ++++++++++++++++++++++++++-
 3 files changed, 51 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath11k/dp.c +1 -0
index f389b97acbdd..2e5978ec2b05 100644
@@ -1087,6 +1087,7 @@ int ath11k_dp_alloc(struct ath11k_base *ab)
 	for (i = 0; i < ab->hw_params.hal_params->num_tx_rings; i++) {
 		idr_init(&dp->tx_ring[i].txbuf_idr);
 		spin_lock_init(&dp->tx_ring[i].tx_idr_lock);
+		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;
drivers/net/wireless/ath/ath11k/dp.h +2 -0
index 84f66839f0c6..6d99501aa269 100644
@@ -87,6 +87,8 @@ struct dp_tx_ring {
 	struct idr txbuf_idr;
 	/* Protects txbuf_idr and num_pending */
 	spinlock_t tx_idr_lock;
+	/* Serializes wake_tx_queue operations for this ring */
+	spinlock_t wake_tx_lock;
 	struct hal_wbm_release_ring *tx_status;
 	int tx_status_head;
 	int tx_status_tail;
drivers/net/wireless/ath/ath11k/mac.c +48 -1

57 lines not on this page · raw message

Signature · 1 line
2.54.0
#4 lore raw

PATCH v7 4/4 wifi: ath12k: implement custom wake_tx_queue with flow control

In reply to Jose Ignacio Tornos Martinez

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

---
v7: Address comments from Jeff Johnson:
- Add the defensive pattern _bh in both spinlocks
v6: https://lore.kernel.org/all/[email protected]/

 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(-)
drivers/net/wireless/ath/ath12k/dp.c +1 -0
index f9b37d75956d..e62fa416b992 100644
@@ -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;
drivers/net/wireless/ath/ath12k/dp.h +2 -0
index bef0f2ba0560..4bf8a8a6d76c 100644
@@ -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;
drivers/net/wireless/ath/ath12k/hal.c +1 -0
index c0c3d2f047ef..fbe4dc41e34b 100644
@@ -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)
drivers/net/wireless/ath/ath12k/wifi7/hw.c +68 -1

77 lines not on this page · raw message

Signature · 1 line
2.54.0
#5 lore raw
In reply to Jose Ignacio Tornos Martinez

Hi Jeff,

Friendly follow-up on this series. v7 addressed your spin_lock_bh comment, and I replied to the rcu_dereference_bh question explaining why ath12k differs from the ath9k case (happy to do it as a follow-up if you'd like). My results with VMs are much better with the TX control, and I think it can help baremetal too.

Any feedback on v7, anything else I can do?
At least, would it be acceptable for ath11k?
For ath12k, if the concern is the locking, the rcu_dereference_bh refactoring would require changes to existing mac_op_tx code. Is that the direction you want?

Thanks

Best regards
José Ignacio

#6 lore raw
In reply to Jose Ignacio Tornos Martinez
Quoted 24 lines · Jose Ignacio Tornos Martinez

This series implements custom wake_tx_queue operations for ath11k and ath12k drivers to prevent hardware ring overflow issues under heavy traffic.

Without proper flow control, both drivers experience -ENOMEM errors ("failed to transmit frame -12") when the hardware TCL ring fills up. Additionally, ath12k can hang under sustained high throughput. These issues are more commonly observed in VMs with PCIe passthrough but also occur on bare metal systems.

The implementation follows the pattern used in the iwlwifi driver, adapted for ath11k/ath12k hardware ring architecture, checking hardware ring space before dequeuing packets from mac80211.

Testing shows stable operation with eliminated -ENOMEM errors, no hangs, and improved throughput under heavy traffic conditions.

Jose Ignacio Tornos Martinez (4):
wifi: ath11k: use queue mapping for WCN6750 ring selection
wifi: ath11k/ath12k: remove skb parameter from get_ring_selector
wifi: ath11k: implement custom wake_tx_queue with flow control
wifi: ath12k: implement custom wake_tx_queue with flow control

Quoted 8 lines

v7: No modification in patches 1 and 2
Address comments from Jeff Johnson:
Patch 3: Add the defensive pattern _bh in both spinlocks (ath11k) Patch 4: Add the defensive pattern _bh in both spinlocks (ath12k)
v6: https://lore.kernel.org/all/[email protected]/
--
2.49.0

There is another series touching the same area: "[PATCH ath-next v4 0/9] wifi: ath11k: airtime queue limits, fairness and a driver TXQ scheduler".
It looks like there are some conflicts between the two. Could you please take a look?

Quoted 1 line
Signature · 1 line
- Tamizh.
#7 lore raw

Hi Tamizh,

Thanks for the heads-up about Julius's series.

I have reviewed it. Both series replace .wake_tx_queue in ath11k, so they conflict textually there, but they solve different problems:
mine stops -ENOMEM by checking the ring space before dequeue, his adds AQL, airtime fairness and a full deficit round-robin scheduler. The two are complementary.

For ath11k, my series is smaller (4 patches, 7 review cycles) and has no external dependencies, so it may be simpler to land first. Julius already offered to rebase onto it in his cover letter [1] and move the ring check into his scheduling round.

Since there is no conflict in ath12k (Julius's series is ath11k only), I could split ath11k and ath12k into separate series to try to unblock both. By the way, any more feedback on the ath12k patches? WDYT?

[1] https://lore.kernel.org/all/[email protected]/

Thanks

Best regards
José Ignacio

#8 lore raw

Hi José Ignacio,

Quoted 4 lines · Jose Ignacio Tornos Martinez

For ath11k, my series is smaller (4 patches, 7 review cycles) and has no external dependencies, so it may be simpler to land first. Julius already offered to rebase onto it in his cover letter [1] and move the ring check into his scheduling round.

Agreed.

One thing on patch 3, from reading the code:

Review

Quoted 4 lines
(quoted diff) +4 -0
+		if (num_free == 0) {
+			spin_unlock_bh(&tx_ring->wake_tx_lock);
+			break;
+		}

When this breaks, the frames stay in the txq and nothing restarts it until mac80211 queues the next frame for that txq. A sender waiting for ACKs then stalls until its retransmit timeout. With AQL I measured this in v4: one download in three stalled, max RTT 347 ms. A restart from ath11k_dp_tx_completion_handler() fixes it.

For patches 1-3:

Julius

#9 lore raw

Hi Julius,

Thanks for the review and the Tested-by.

Quoted 7 lines

One thing on patch 3, from reading the code:

Review

Quoted 4 lines
(quoted diff) +4 -0
+             if (num_free == 0) {
+                     spin_unlock_bh(&tx_ring->wake_tx_lock);
+                     break;
+             }
Quoted 5 lines

When this breaks, the frames stay in the txq and nothing restarts it until mac80211 queues the next frame for that txq. A sender waiting for ACKs then stalls until its retransmit timeout. With AQL I measured this in v4: one download in three stalled, max RTT 347 ms. A restart from ath11k_dp_tx_completion_handler() fixes it.

Good point. The break when the ring is full is intentional, it keeps the frames safe in the txq instead of the current -ENOMEM drop. Your TX completion restart (patch 6) would make the recovery from that stall faster, which is a nice improvement on top. Another reason for both series to land.

Since we agree, I am going to split ath11k and ath12k into separate series to try to unblock both.

Thanks

Best regards
José Ignacio