mac80211 charges a frame's airtime to its station when ieee80211_tx_dequeue() hands the frame over. It returns the charge on tx status to the station the driver passes, and in ieee80211_free_txskb() to the station it finds from the 802.11 header. An encap offloaded frame starts with its 802.3 header, so each ath11k path that frees one leaves the charge with its station: the HTT REINJ and INSPECT statuses, the frames in flight at firmware recovery, a completion whose peer is not found or that carries no peer id, a completion for a radio that is no longer active, and a frame ath11k_dp_tx() refuses. Once a station's leaked charge in an access category reaches its high limit, ieee80211_txq_airtime_check() stops that queue until the station reassociates. Keep the address of the frame's station in the skb control block, and hand such an encap frame back with ieee80211_tx_status_ext() with its station and without status info, so mac80211 returns the charge without updating station statistics, then free it as dropped, as ieee80211_free_txskb() does. A frame ath11k_dp_tx() refuses goes back with the station mac80211 passed. Other dropped frames find their station by its address with ieee80211_find_sta(), which does not depend on the firmware peer table; the reset recovery frees the peers before the frames in flight are returned. A socket that asked for an encap frame's status now gets one, with the ack state ath11k set, where it got none. An 802.11 frame is still freed with ieee80211_free_txskb(). Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.12-01460-QCAHKSWPL_SILICONZ-1 Link: https://lore.kernel.org/all/8d674f7c-68db-474f-8cb1-5645542db0ac@nbd.name/ Signed-off-by: Julius Bairaktaris --- v7: new; replaces the mac80211 patch https://lore.kernel.org/all/20261122150541.3117507-1-julius@bairaktaris.de/ which Felix Fietkau asked to be solved in the driver: https://lore.kernel.org/all/8d674f7c-68db-474f-8cb1-5645542db0ac@nbd.name/ drivers/net/wireless/ath/ath11k/core.h | 2 + drivers/net/wireless/ath/ath11k/dp_tx.c | 93 +++++++++++++++++++++++-- drivers/net/wireless/ath/ath11k/dp_tx.h | 2 + drivers/net/wireless/ath/ath11k/mac.c | 7 +- 4 files changed, 96 insertions(+), 8 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/core.h b/drivers/net/wireless/ath/ath11k/core.h index a0d725923ef24..7fa93df81a41d 100644 --- a/drivers/net/wireless/ath/ath11k/core.h +++ b/drivers/net/wireless/ath/ath11k/core.h @@ -113,6 +113,7 @@ static inline enum wme_ac ath11k_tid_to_ac(u32 tid) enum ath11k_skb_flags { ATH11K_SKB_HW_80211_ENCAP = BIT(0), ATH11K_SKB_CIPHER_SET = BIT(1), + ATH11K_SKB_STA = BIT(2), }; struct ath11k_skb_cb { @@ -122,6 +123,7 @@ struct ath11k_skb_cb { u32 cipher; struct ath11k *ar; struct ieee80211_vif *vif; + u8 sta_addr[ETH_ALEN]; } __packed; struct ath11k_skb_rxcb { diff --git a/drivers/net/wireless/ath/ath11k/dp_tx.c b/drivers/net/wireless/ath/ath11k/dp_tx.c index 0e3b4e836001f..25a91681a2192 100644 --- a/drivers/net/wireless/ath/ath11k/dp_tx.c +++ b/drivers/net/wireless/ath/ath11k/dp_tx.c @@ -284,6 +284,66 @@ int ath11k_dp_tx(struct ath11k *ar, struct ath11k_vif *arvif, return ret; } +/** + * ath11k_dp_tx_drop() - return a frame without status info + * @ar: radio the frame was queued on + * @sta: station mac80211 queued the frame to, or NULL + * @msdu: the frame, already unmapped + * + * For a frame that was not transmitted, a completion whose peer is not + * found, or one for a radio that is no longer active. mac80211 charged the + * frame's airtime to its station when it handed the frame over. It finds + * the station of a dropped 802.11 frame from the header; an encap offloaded + * frame starts with its 802.3 header, so it goes back with the station. + * Without status info, mac80211 updates no station statistics for it and + * reports the ack state in the frame's flags to a socket that asked for its + * status. The frame is freed as dropped. + */ +void ath11k_dp_tx_drop(struct ath11k *ar, struct ieee80211_sta *sta, + struct sk_buff *msdu) +{ + LIST_HEAD(free_list); + struct ieee80211_tx_status status = { + .sta = sta, + .skb = msdu, + .free_list = &free_list, + }; + + if (!(IEEE80211_SKB_CB(msdu)->flags & IEEE80211_TX_CTL_HW_80211_ENCAP)) { + ieee80211_free_txskb(ar->hw, msdu); + return; + } + + ieee80211_tx_status_ext(ar->hw, &status); + skb_list_del_init(msdu); + dev_kfree_skb_any(msdu); +} + +/* + * Find the station mac80211 queued a frame to by the address + * ath11k_mac_tx() kept; a station removed since is not found. The caller + * has had BH disabled or held the RCU read lock since before the frame left + * the idr, so the vif is still valid or ath11k_mac_vif_unref() cleared it, + * and a station found stays valid until the frame is reported. + */ +static struct ieee80211_sta *ath11k_dp_tx_find_sta(struct ieee80211_vif *vif, + u8 flags, const u8 *addr) +{ + if (!vif || !(flags & ATH11K_SKB_STA)) + return NULL; + + return ieee80211_find_sta(vif, addr); +} + +static void ath11k_dp_tx_drop_queued(struct ath11k *ar, struct sk_buff *msdu) +{ + struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(msdu); + + ath11k_dp_tx_drop(ar, ath11k_dp_tx_find_sta(skb_cb->vif, skb_cb->flags, + skb_cb->sta_addr), + msdu); +} + static void ath11k_dp_tx_free_txbuf(struct ath11k_base *ab, u8 mac_id, int msdu_id, struct dp_tx_ring *tx_ring) @@ -307,7 +367,7 @@ static void ath11k_dp_tx_free_txbuf(struct ath11k_base *ab, u8 mac_id, dma_unmap_single(ab->dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE); ar = ab->pdevs[mac_id].ar; - ieee80211_free_txskb(ar->hw, msdu); + ath11k_dp_tx_drop_queued(ar, msdu); if (atomic_dec_and_test(&ar->dp.num_tx_pending)) wake_up(&ar->dp.tx_empty_waitq); @@ -330,6 +390,8 @@ void ath11k_dp_tx_free_pending(struct ath11k_base *ab) __skb_queue_head_init(&pending); + rcu_read_lock(); + for (i = 0; i < ab->hw_params.hal_params->num_tx_rings; i++) { tx_ring = &ab->dp.tx_ring[i]; @@ -345,8 +407,10 @@ void ath11k_dp_tx_free_pending(struct ath11k_base *ab) skb_cb = ATH11K_SKB_CB(msdu); dma_unmap_single(ab->dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE); - ieee80211_free_txskb(skb_cb->ar->hw, msdu); + ath11k_dp_tx_drop_queued(skb_cb->ar, msdu); } + + rcu_read_unlock(); } static void @@ -360,6 +424,9 @@ ath11k_dp_tx_htt_tx_complete_buf(struct ath11k_base *ab, struct ath11k_skb_cb *skb_cb; struct ath11k *ar; struct ath11k_peer *peer; + struct ieee80211_vif *vif; + u8 sta_addr[ETH_ALEN]; + u8 flags; spin_lock(&tx_ring->tx_idr_lock); msdu = idr_remove(&tx_ring->txbuf_idr, ts->msdu_id); @@ -375,13 +442,17 @@ ath11k_dp_tx_htt_tx_complete_buf(struct ath11k_base *ab, info = IEEE80211_SKB_CB(msdu); ar = skb_cb->ar; + /* info->status below overwrites skb_cb */ + vif = skb_cb->vif; + flags = skb_cb->flags; + memcpy(sta_addr, skb_cb->sta_addr, ETH_ALEN); if (atomic_dec_and_test(&ar->dp.num_tx_pending)) wake_up(&ar->dp.tx_empty_waitq); dma_unmap_single(ab->dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE); - if (!skb_cb->vif) { + if (!vif) { ieee80211_free_txskb(ar->hw, msdu); return; } @@ -411,7 +482,8 @@ ath11k_dp_tx_htt_tx_complete_buf(struct ath11k_base *ab, "dp_tx: failed to find the peer with peer_id %d\n", ts->peer_id); spin_unlock_bh(&ab->base_lock); - ieee80211_free_txskb(ar->hw, msdu); + ath11k_dp_tx_drop(ar, ath11k_dp_tx_find_sta(vif, flags, sta_addr), + msdu); return; } spin_unlock_bh(&ab->base_lock); @@ -597,6 +669,9 @@ static void ath11k_dp_tx_complete_msdu(struct ath11k *ar, struct ath11k_peer *peer; struct ath11k_sta *arsta; struct rate_info rate; + struct ieee80211_vif *vif; + u8 sta_addr[ETH_ALEN]; + u8 flags; if (WARN_ON_ONCE(ts->buf_rel_source != HAL_WBM_REL_SRC_MODULE_TQM)) { /* Must not happen */ @@ -608,7 +683,7 @@ static void ath11k_dp_tx_complete_msdu(struct ath11k *ar, dma_unmap_single(ab->dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE); if (unlikely(!rcu_access_pointer(ab->pdevs_active[ar->pdev_idx]))) { - ieee80211_free_txskb(ar->hw, msdu); + ath11k_dp_tx_drop_queued(ar, msdu); return; } @@ -617,6 +692,11 @@ static void ath11k_dp_tx_complete_msdu(struct ath11k *ar, return; } + /* info->status below overwrites skb_cb */ + vif = skb_cb->vif; + flags = skb_cb->flags; + memcpy(sta_addr, skb_cb->sta_addr, ETH_ALEN); + info = IEEE80211_SKB_CB(msdu); memset(&info->status, 0, sizeof(info->status)); @@ -670,7 +750,8 @@ static void ath11k_dp_tx_complete_msdu(struct ath11k *ar, "dp_tx: failed to find the peer with peer_id %d\n", ts->peer_id); spin_unlock_bh(&ab->base_lock); - ieee80211_free_txskb(ar->hw, msdu); + ath11k_dp_tx_drop(ar, ath11k_dp_tx_find_sta(vif, flags, sta_addr), + msdu); return; } arsta = ath11k_sta_to_arsta(peer->sta); diff --git a/drivers/net/wireless/ath/ath11k/dp_tx.h b/drivers/net/wireless/ath/ath11k/dp_tx.h index 9a26de411e83a..977cb48de7c0a 100644 --- a/drivers/net/wireless/ath/ath11k/dp_tx.h +++ b/drivers/net/wireless/ath/ath11k/dp_tx.h @@ -23,6 +23,8 @@ int ath11k_dp_tx(struct ath11k *ar, struct ath11k_vif *arvif, struct ath11k_sta *arsta, struct sk_buff *skb); void ath11k_dp_tx_completion_handler(struct ath11k_base *ab, int ring_id); void ath11k_dp_tx_free_pending(struct ath11k_base *ab); +void ath11k_dp_tx_drop(struct ath11k *ar, struct ieee80211_sta *sta, + struct sk_buff *msdu); int ath11k_dp_tx_send_reo_cmd(struct ath11k_base *ab, struct dp_rx_tid *rx_tid, enum hal_reo_cmd_type type, struct ath11k_hal_reo_cmd *cmd, diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c index d6e07b98b65aa..ec92c825f809c 100644 --- a/drivers/net/wireless/ath/ath11k/mac.c +++ b/drivers/net/wireless/ath/ath11k/mac.c @@ -6555,13 +6555,16 @@ static void ath11k_mac_op_tx(struct ieee80211_hw *hw, return; } - if (control->sta) + if (control->sta) { arsta = ath11k_sta_to_arsta(control->sta); + memcpy(skb_cb->sta_addr, control->sta->addr, ETH_ALEN); + skb_cb->flags |= ATH11K_SKB_STA; + } ret = ath11k_dp_tx(ar, arvif, arsta, skb); if (unlikely(ret)) { ath11k_warn(ar->ab, "failed to transmit frame %d\n", ret); - ieee80211_free_txskb(ar->hw, skb); + ath11k_dp_tx_drop(ar, control->sta, skb); } } -- 2.53.0