[PATCH v3 1/3] wifi: mac80211: add ieee80211_tx_peek API
Jose Ignacio Tornos Martinez <[email protected]> Mon, 20 Jul 2026 09:08:49 +0200
| Newsgroups | org.infradead.lists.ath11k,org.infradead.lists.ath12k,org.kernel.vger.linux-kernel,org.kernel.vger.linux-wireless |
|---|---|
| Message-ID | <[email protected]> |
Add ieee80211_tx_peek() to allow drivers to inspect the next frame in a TXQ without removing it. Drivers implementing custom wake_tx_queue operations may need to determine which hardware TX ring to use before dequeuing a packet, using properties like the skb hash or queue mapping that are only available from the skb itself. The function checks pending fragments first, then iterates through all fair-queue flows (new_flows and old_flows) to find the first queued frame, matching the iteration behavior of fq_tin_dequeue. It also pre-caches the skb hash via skb_get_hash() so that hash-based ring selectors see a stable value through the subsequent dequeue and TX path. Signed-off-by: Jose Ignacio Tornos Martinez <[email protected]> --- v3: no modification v2: https://lore.kernel.org/all/[email protected]/ include/net/mac80211.h | 20 ++++++++++++++++++++ net/mac80211/tx.c | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) diff --git a/include/net/mac80211.h b/include/net/mac80211.h index 4f95da023746..9289b8dca972 100644 --- a/include/net/mac80211.h +++ b/include/net/mac80211.h @@ -7742,6 +7742,26 @@ void ieee80211_unreserve_tid(struct ieee80211_sta *sta, u8 tid); struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, struct ieee80211_txq *txq); +/** + * ieee80211_tx_peek - peek at the next packet in a software tx queue + * + * @hw: pointer as obtained from ieee80211_alloc_hw() + * @txq: pointer obtained from station or virtual interface, or from + * ieee80211_next_txq() + * + * Return: the next skb without dequeuing it, or %NULL if the queue is empty. + * The returned pointer is const — the caller must not modify or free the skb. + * The skb remains queued and will be returned by a subsequent + * ieee80211_tx_dequeue() call. + * + * This is useful for drivers that need to inspect the next frame (e.g. to + * determine the target TX ring) before deciding whether to dequeue. + * + * Must be called in the same context as ieee80211_tx_dequeue(). + */ +const struct sk_buff *ieee80211_tx_peek(struct ieee80211_hw *hw, + struct ieee80211_txq *txq); + /** * ieee80211_tx_dequeue_ni - dequeue a packet from a software tx queue * (in process context) diff --git a/net/mac80211/tx.c b/net/mac80211/tx.c index c13b209fad47..91bfd8ef9428 100644 --- a/net/mac80211/tx.c +++ b/net/mac80211/tx.c @@ -3857,6 +3857,45 @@ static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata, return true; } +const struct sk_buff *ieee80211_tx_peek(struct ieee80211_hw *hw, + struct ieee80211_txq *txq) +{ + struct txq_info *txqi = container_of(txq, struct txq_info, txq); + struct ieee80211_local *local = hw_to_local(hw); + struct fq_tin *tin = &txqi->tin; + struct fq *fq = &local->fq; + struct sk_buff *skb = NULL; + struct fq_flow *flow; + + WARN_ON_ONCE(softirq_count() == 0); + + spin_lock_bh(&fq->lock); + + skb = skb_peek(&txqi->frags); + if (skb) + goto out; + + list_for_each_entry(flow, &tin->new_flows, flowchain) { + skb = skb_peek(&flow->queue); + if (skb) + goto out; + } + + list_for_each_entry(flow, &tin->old_flows, flowchain) { + skb = skb_peek(&flow->queue); + if (skb) + goto out; + } + +out: + if (skb) + skb_get_hash(skb); + + spin_unlock_bh(&fq->lock); + return skb; +} +EXPORT_SYMBOL_GPL(ieee80211_tx_peek); + struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw, struct ieee80211_txq *txq) { -- 2.54.0