ath11k/ath12k: implement TX flow control
Subsystems (3)
v5 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.
Note: I will have limited availability from mid-August to mid-September. I will address any review feedback before then or promptly after returning.
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
v5: No modification in patches 1,2 and 3
Remove an unused variable in patch 4
v4: https://lore.kernel.org/all/[email protected]/
--
2.49.0
PATCH v5 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.
---
v5: no modification
v4: 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
@@ -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
PATCH v5 2/4 wifi: ath11k/ath12k: remove skb parameter from get_ring_selector
In reply to Jose Ignacio Tornos MartinezChange 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.
---
v5: no modification
v4: 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v5 3/4 wifi: ath11k: implement custom wake_tx_queue with flow control
In reply to Jose Ignacio Tornos MartinezUnder 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.
---
v5: no modification
v4: 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 | 52 ++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath11k/dp.c +1 -0
@@ -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
@@ -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 +51 -1
60 lines not on this page · raw message
Signature · 1 line
2.54.0
Re: [PATCH v5 3/4] wifi: ath11k: implement custom wake_tx_queue with flow control
Quoted 19 lines · Jose Ignacio Tornos Martinez
Under heavy traffic, ath11k experiences frequent
-ENOMEMerrors ("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_queueoperation that:1. Checks hardware ring space before dequeuing packets from mac80211
2. Uses per-ring locking (wake_tx_lockwithspin_lock_bh) to serialize concurrentwake_tx_queuecalls targeting the same ring and to ensure bottom halves are disabled as required byieee80211_tx_dequeue()
3. Syncs with hardware state to get accurate free slot count
4. Resolves the target TCL ring usingget_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
Quoted 5 lines
This approach follows the pattern used in the iwlwifi driver, adapted for ath11k's hardware ring architecture.
This eliminates
-ENOMEMerrors and improves throughput by optimizing resource usage and preventing unnecessary packet drops.
Missing Tested-on tag
Quoted 50 lines
Signed-off-by Jose Ignacio Tornos Martinez <[email protected]>---
v5: no modification
v4: 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 | 52 ++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 1 deletion(-)drivers/net/wireless/ath/ath11k/dp.c +1
-0@@ -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@@ -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 +6
-0@@ -10065,9 +10065,59 @@ static int ath11k_mac_op_sta_state(struct ieee80211_hw *hw,return ret; } +static void ath11k_mac_op_wake_tx_queue (struct ieee80211_hw *hw, +struct ieee80211_txq *txq) +{ +struct ieee80211_tx_control control = { + .sta = txq->sta, + };
drivers/net/wireless/ath/ath11k/mac.c static int ath11k_mac_op_sta_state(struct ieee80211_hw *hw, · line 10083
Quoted 10 lines
drivers/net/wireless/ath/ath11k/mac.c +10
-0+struct ath11k *ar = hw->priv; +struct dp_tx_ring *tx_ring; +struct hal_srng *tcl_ring; +struct sk_buff *skb; +u32 ring_selector; +int num_free; +u8 ring_id; + +if (!ar) +return ;
ar = hw->priv and the hw->priv space is allocated when hw is allocated. so if hw is valid, hw->priv is valid, and this check is innecessary
Quoted 41 lines
drivers/net/wireless/ath/ath11k/mac.c +35
-1+ + ring_selector = ar->ab->hw_params.hw_ops->get_ring_selector (txq->ac); + ring_id = ring_selector % ar->ab->hw_params.hal_params->num_tx_rings; + tx_ring = &ar->ab->dp.tx_ring[ring_id]; + tcl_ring = &ar->ab->hal.srng_list[tx_ring->tcl_data_ring.ring_id]; + +while (1 ) { +if (unlikely (test_bit (ATH11K_FLAG_CRASH_FLUSH , + &ar->ab->dev_flags))) +break ; + +spin_lock_bh (&tx_ring->wake_tx_lock); + +spin_lock (&tcl_ring->lock); + num_free =ath11k_hal_srng_src_num_free (ar->ab, tcl_ring, true); +spin_unlock (&tcl_ring->lock); + +if (num_free ==0 ) { +spin_unlock_bh (&tx_ring->wake_tx_lock); +break ; + } + + skb =ieee80211_tx_dequeue (hw, txq); +if (!skb) { +spin_unlock_bh (&tx_ring->wake_tx_lock); +break ; + } + +ath11k_mac_op_tx (hw, &control, skb); + +spin_unlock_bh (&tx_ring->wake_tx_lock); + } +} +static const struct ieee80211_ops ath11k_ops = { .tx = ath11k_mac_op_tx, - .wake_tx_queue = ieee80211_handle_wake_tx_queue, + .wake_tx_queue = ath11k_mac_op_wake_tx_queue, .start = ath11k_mac_op_start, .stop = ath11k_mac_op_stop, .reconfig_complete = ath11k_mac_op_reconfig_complete,
Re: [PATCH v5 3/4] wifi: ath11k: implement custom wake_tx_queue with flow control
Thanks for the review, Jeff.
Ok, the if (!ar) check is unnecessary if hw->priv is always valid when hw is valid.
I will fix this and add the Tested-on tag in v6.
Best regards
Jose Ignacio
PATCH v5 4/4 wifi: ath12k: implement custom wake_tx_queue with flow control
In reply to Jose Ignacio Tornos MartinezUnder 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.
---
v5: Remove an unused variable
v4: 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 | 76 +++++++++++++++++++++- 4 files changed, 79 insertions(+), 1 deletion(-)
drivers/net/wireless/ath/ath12k/dp.c +1 -0
@@ -1539,6 +1539,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
@@ -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
@@ -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_GPL (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 +74 -1
83 lines not on this page · raw message
Signature · 1 line
2.54.0
Jeff Johnson
NAKRe: [PATCH v5 4/4] wifi: ath12k: implement custom wake_tx_queue with flow control
Quoted 17 lines · Jose Ignacio Tornos Martinez
Under heavy traffic, ath12k can hang and experiences
-ENOMEMerrors ("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_queueoperation that:1. Checks hardware ring space before dequeuing packets from mac80211
2. Uses per-ring locking (wake_tx_lockwithspin_lock_bh) to serialize concurrentwake_tx_queuecalls targeting the same ring and to ensure bottom halves are disabled as required byieee80211_tx_dequeue()
3. Syncs with hardware state to get accurate free slot count
4. Resolves the target TCL ring once usingget_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
Quoted 5 lines
This approach follows the pattern used in the iwlwifi driver, adapted for ath12k's hardware ring architecture.
This prevents hangs, eliminates
-ENOMEMerrors, and improves throughput by optimizing resource usage and preventing unnecessary packet drops.
Tested-on missing
Quoted 42 lines
Signed-off-by Jose Ignacio Tornos Martinez <[email protected]>---
v5: Remove an unused variable
v4: 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 | 76 +++++++++++++++++++++- 4 files changed, 79 insertions(+), 1 deletion(-)drivers/net/wireless/ath/ath12k/dp.c +1
-0@@ -1539,6 +1539,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@@ -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 +0
-0
drivers/net/wireless/ath/ath12k/hal.c int ath12k_hal_srng_src_num_free(struct ath12k_base *ab, struct hal_srng *srng, · line 393
Quoted 4 lines
drivers/net/wireless/ath/ath12k/hal.c +1
-0@@ -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_GPL (ath12k_hal_srng_src_num_free);
NAK, must be EXPORT_SYMBOL()
The ath12k code was contributed under the license:
// SPDX-License-Identifier: BSD-3-Clause-Clear
Quoted 29 lines
drivers/net/wireless/ath/ath12k/hal.c +0
-0void *ath12k_hal_srng_src_next_peek (struct ath12k_base *ab,struct hal_srng *srng)drivers/net/wireless/ath/ath12k/wifi7/hw.c +18
-0@@ -1100,9 +1100,82 @@ 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;
drivers/net/wireless/ath/ath12k/wifi7/hw.c static void ath12k_wifi7_mac_op_tx(struct ieee80211_hw *hw, · line 1130
Quoted 10 lines
drivers/net/wireless/ath/ath12k/wifi7/hw.c +10
-0+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 ();
does this lock really need to be held for the entire function including the tx loop?
drivers/net/wireless/ath/ath12k/wifi7/hw.c static void ath12k_wifi7_mac_op_tx(struct ieee80211_hw *hw, · line 1139
Quoted 9 lines
drivers/net/wireless/ath/ath12k/wifi7/hw.c +9
-0+ + arvif =rcu_dereference (ahvif->link[link_id]); +if (!arvif || !arvif->ar) { +rcu_read_unlock (); +return ; + } + + ar = arvif->ar; + dp = ar->ab->dp;
or is it sufficient to cache these values and then rcu_read_unlock() here? my LLM reviewer seems to think that would be sufficient
note the spinlock in the while loop will cause the RCU read lock to be held when invoking mac_op_tx(), satisfying the RCU lock requirement there.
drivers/net/wireless/ath/ath12k/wifi7/hw.c static void ath12k_wifi7_mac_op_tx(struct ieee80211_hw *hw, · line 1151
Quoted 12 lines
drivers/net/wireless/ath/ath12k/wifi7/hw.c +12
-0+ + 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 ; + +spin_lock_bh (&tx_ring->wake_tx_lock);
using guard(spinlock_bh)(&tx_ring->wake_tx_lock) would eliminate the need for all the spin_unlock_bh(&tx_ring->wake_tx_lock) calls
drivers/net/wireless/ath/ath12k/wifi7/hw.c static void ath12k_wifi7_mac_op_tx(struct ieee80211_hw *hw, · line 1153
Quoted 2 lines
drivers/net/wireless/ath/ath12k/wifi7/hw.c +2
-0+ +spin_lock (&tcl_ring->lock);
seems this should be spin_lock_bh() to align with all other callers in the driver.
Quoted 29 lines
drivers/net/wireless/ath/ath12k/wifi7/hw.c +23
-1+ num_free =ath12k_hal_srng_src_num_free (ar->ab, tcl_ring, true); +spin_unlock (&tcl_ring->lock); + +if (num_free ==0 ) { +spin_unlock_bh (&tx_ring->wake_tx_lock); +break ; + } + + skb =ieee80211_tx_dequeue (hw, txq); +if (!skb) { +spin_unlock_bh (&tx_ring->wake_tx_lock); +break ; + } + +ath12k_wifi7_mac_op_tx (hw, &control, skb); + +spin_unlock_bh (&tx_ring->wake_tx_lock); + } + +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,
Re: [PATCH v5 4/4] wifi: ath12k: implement custom wake_tx_queue with flow control
Thanks for the review, Jeff.
Quoted 1 line
Tested-on missing
Ok, I will add it in v6
Quoted 3 lines
NAK, must be
EXPORT_SYMBOL()
The ath12k code was contributed under the license:
// SPDX-License-Identifier: BSD-3-Clause-Clear
I did it in an automatic way, I will fix it in v6
Quoted 18 lines
drivers/net/wireless/ath/ath12k/wifi7/hw.c static void ath12k_wifi7_mac_op_tx(struct ieee80211_hw *hw, · line 1130
Quoted 1 line
drivers/net/wireless/ath/ath12k/wifi7/hw.c +1
-0+rcu_read_lock ();does this lock really need to be held for the entire function including the tx loop?
drivers/net/wireless/ath/ath12k/wifi7/hw.c static void ath12k_wifi7_mac_op_tx(struct ieee80211_hw *hw, · line 1139
Quoted 9 lines
drivers/net/wireless/ath/ath12k/wifi7/hw.c +9
-0+ + arvif =rcu_dereference (ahvif->link[link_id]); +if (!arvif || !arvif->ar) { +rcu_read_unlock (); +return ; + } + + ar = arvif->ar; + dp = ar->ab->dp;or is it sufficient to cache these values and then
rcu_read_unlock()here? my LLM reviewer seems to think that would be sufficient
Quoted 2 lines
note the spinlock in the while loop will cause the RCU read lock to be held when invoking
mac_op_tx(), satisfying the RCU lock requirement there.
Keeping rcu_read_lock() for the entire function is intentional. ath12k_wifi7_mac_op_tx() calls rcu_dereference() internally (on ahvif->link[] and ahsta->link[]), and with CONFIG_DEBUG_LOCK_ALLOC, rcu_dereference() checks lock_is_held(&rcu_lock_map) via rcu_read_lock_held().
Only an explicit rcu_read_lock() sets rcu_lock_map and spin_lock_bh() does not, so releasing early would trigger lockdep warnings.
Quoted 2 lines
using guard(spinlock_bh)(&tx_ring->wake_tx_lock) would eliminate the need for all the
spin_unlock_bh(&tx_ring->wake_tx_lock)calls
Better, I will use it in v6
Quoted 4 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ + spin_lock(&tcl_ring->lock);seems this should be
spin_lock_bh()to align with all other callers in the driver.
The outer spin_lock_bh(&tx_ring->wake_tx_lock); already disables BH, so spin_lock() for the inner tcl_ring->lock is correct and sufficient. Using spin_lock_bh() would redundantly disable BH again.
Best regards
Jose Ignacio
Re: [PATCH v5 4/4] wifi: ath12k: implement custom wake_tx_queue with flow control
Quoted 7 lines · Jose Ignacio Tornos Martinez
Quoted 3 lines
drivers/net/wireless/ath/ath12k/wifi7/hw.c static void ath12k_wifi7_mac_op_tx(struct ieee80211_hw *hw, · line 1153
Quoted 1 line
drivers/net/wireless/ath/ath12k/wifi7/hw.c +1
-0+spin_lock (&tcl_ring->lock);seems this should be
spin_lock_bh()to align with all other callers in the driver.The outer
spin_lock_bh(&tx_ring->wake_tx_lock); already disables BH, sospin_lock()for the innertcl_ring->lockis correct and sufficient. Usingspin_lock_bh()would redundantly disable BH again.
Yes, but if that outer spinlock is ever removed, the inner spinlock would no longer be correct. So the defensive pattern is to use _bh in both places, and both of my AI review agents concur with this practice.
/jeff
Re: [PATCH v5 4/4] wifi: ath12k: implement custom wake_tx_queue with flow control
Hello Jeff,
Sorry for the late reply, I was on leave as noted in the v6 cover letter.
Quoted 3 lines
Yes, but if that outer spinlock is ever removed, the inner spinlock would no longer be correct. So the defensive pattern is to use
_bhin both places, and both of my AI review agents concur with this practice.
Ok, changed to spin_lock_bh() in both ath11k and ath12k for v7.
Thanks
Best regards
José Ignacio
Re: [PATCH v5 4/4] wifi: ath12k: implement custom wake_tx_queue with flow control
In reply to Jose Ignacio Tornos MartinezQuoted 6 lines · Jose Ignacio Tornos Martinez
Keeping
rcu_read_lock()for the entire function is intentional.ath12k_wifi7_mac_op_tx()callsrcu_dereference()internally (on ahvif->link[] and ahsta->link[]), and withCONFIG_DEBUG_LOCK_ALLOC,rcu_dereference()checkslock_is_held(&rcu_lock_map)viarcu_read_lock_held().
Only an explicitrcu_read_lock()setsrcu_lock_mapandspin_lock_bh()does not, so releasing early would trigger lockdep warnings.
hmm, so some of the following commits are broken?
https://lore.kernel.org/all/[email protected]/
In particular the one that I merged into ath9k:
https://lore.kernel.org/all/[email protected]/
(quoted diff) +0 -0
b/drivers/net/wireless/ath/ath9k/xmit.c
index 0ac9212e42f7..4a0f465aa2fe 100644
drivers/net/wireless/ath/ath9k/xmit.c +0 -0
@@ -1993,7 +1993,6 @@ void ath_txq_schedule(struct ath_softc *sc, struct
ath_txq *txq)
ieee80211_txq_schedule_start(hw, txq->mac80211_qnum); spin_lock_bh(&sc->chan_lock);
- rcu_read_lock();
if (sc->cur_chan->stopped)
goto out;
@@ -2011,7 +2010,6 @@ void ath_txq_schedule(struct ath_softc *sc, struct ath_txq *txq)
}
out:
- rcu_read_unlock();
spin_unlock_bh(&sc->chan_lock); ieee80211_txq_schedule_end(hw, txq->mac80211_qnum);
}
I fed that into my review agent and it confirms your observation:
The change works correctly on production kernels without CONFIG_DEBUG_LOCK_ALLOC. It will produce a false lockdep splat on debug kernels with CONFIG_PROVE_RCU because rcu_dereference() checks rcu_read_lock_held() which requires an explicit rcu_read_lock(), not just a spinlock.
I have a fixup for ath9k which does:
171 - ratetbl = rcu_dereference(sta->rates);
171 + ratetbl = rcu_dereference_bh(sta->rates);Should ath12k also use rcu_dereference_bh()?
/jeff
Re: [PATCH v5 4/4] wifi: ath12k: implement custom wake_tx_queue with flow control
Hello Jeff,
Sorry for the late reply, I was on leave as noted in the v6 cover letter.
Quoted 5 lines
I have a fixup for ath9k which does:
171 - ratetbl = rcu_dereference(sta->rates); 171 + ratetbl = rcu_dereference_bh(sta->rates);Should ath12k also use
rcu_dereference_bh()?
I think the ath9k and ath12k situations are different.
In ath9k, the rcu_dereference(sta->rates) is already inside the spin_lock_bh(&sc->chan_lock) section, so BH is disabled and switching to rcu_dereference_bh() directly satisfies lockdep without needing rcu_read_lock().
In ath12k, narrowing the rcu_read_lock() scope would require changing the 4 existing rcu_dereference() calls inside ath12k_wifi7_mac_op_tx() to rcu_dereference_bh(), since that function has an existing contract (/* Note: called under rcu_read_lock() */) and is called from wake_tx_queue. That is modifying working code beyond the scope of this series. Happy to do it as a follow-up if you prefer.
Thanks
Best regards
José Ignacio