The TX completion handler takes base_lock and searches the peer list for every frame, although consecutive completions mostly belong to one peer, and it frees each buffer on its own. Carry the peer's station and TX rate across one completion run and look them up again only when the peer ID changes. Collect the completed buffers on the status free list and free them with napi_consume_skb() at the end of the run. Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.12-01460-QCAHKSWPL_SILICONZ-1 Signed-off-by: Julius Bairaktaris --- drivers/net/wireless/ath/ath11k/dp_tx.c | 49 ++++++++++++++++++------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/dp_tx.c b/drivers/net/wireless/ath/ath11k/dp_tx.c index 5c3ddc8aad41..4f509771d60a 100644 --- a/drivers/net/wireless/ath/ath11k/dp_tx.c +++ b/drivers/net/wireless/ath/ath11k/dp_tx.c @@ -629,9 +629,21 @@ void ath11k_dp_tx_update_txcompl(struct ath11k *ar, struct hal_tx_status *ts) spin_unlock_bh(&ab->base_lock); } +/* + * State carried across one completion run: consecutive frames mostly belong + * to one peer, and the statuses hand their buffers back to be freed in bulk. + */ +struct ath11k_dp_tx_compl { + struct list_head free; + struct ieee80211_sta *sta; + struct rate_info rate; + u16 peer_id; +}; + static void ath11k_dp_tx_complete_msdu(struct ath11k *ar, struct sk_buff *msdu, - struct hal_tx_status *ts) + struct hal_tx_status *ts, + struct ath11k_dp_tx_compl *c) { struct ieee80211_tx_status status = {}; struct ieee80211_rate_status status_rate = {}; @@ -639,8 +651,6 @@ static void ath11k_dp_tx_complete_msdu(struct ath11k *ar, struct ieee80211_tx_info *info; struct ath11k_skb_cb *skb_cb; struct ath11k_peer *peer; - struct ath11k_sta *arsta; - struct rate_info rate; if (WARN_ON_ONCE(ts->buf_rel_source != HAL_WBM_REL_SRC_MODULE_TQM)) { /* Must not happen */ @@ -707,30 +717,34 @@ static void ath11k_dp_tx_complete_msdu(struct ath11k *ar, ath11k_dp_tx_cache_peer_stats(ar, msdu, ts); } - spin_lock_bh(&ab->base_lock); - peer = ath11k_peer_find_by_id(ab, ts->peer_id); - if (!peer || !peer->sta) { + if (!c->sta || c->peer_id != ts->peer_id) { + spin_lock_bh(&ab->base_lock); + peer = ath11k_peer_find_by_id(ab, ts->peer_id); + c->sta = peer ? peer->sta : NULL; + c->peer_id = ts->peer_id; + if (c->sta) + c->rate = ath11k_sta_to_arsta(c->sta)->last_txrate; + spin_unlock_bh(&ab->base_lock); + } + + if (!c->sta) { ath11k_dbg(ab, ATH11K_DBG_DATA, "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); return; } - arsta = ath11k_sta_to_arsta(peer->sta); - status.sta = peer->sta; + status.sta = c->sta; status.skb = msdu; status.info = info; - rate = arsta->last_txrate; + status.free_list = &c->free; - status_rate.rate_idx = rate; + status_rate.rate_idx = c->rate; status_rate.try_count = 1; status.rates = &status_rate; status.n_rates = 1; - spin_unlock_bh(&ab->base_lock); - ieee80211_tx_status_ext(ar->hw, &status); } @@ -775,6 +789,8 @@ int ath11k_dp_tx_completion_handler(struct ath11k_base *ab, int ring_id, struct sk_buff *msdu; struct hal_tx_status ts = {}; struct dp_tx_ring *tx_ring = &dp->tx_ring[ring_id]; + struct ath11k_dp_tx_compl c = { .free = LIST_HEAD_INIT(c.free) }; + struct sk_buff *tmp; unsigned long push = 0; int done = 0; u32 *desc; @@ -848,7 +864,12 @@ int ath11k_dp_tx_completion_handler(struct ath11k_base *ab, int ring_id, if (atomic_dec_and_test(&ar->dp.num_tx_pending)) wake_up(&ar->dp.tx_empty_waitq); - ath11k_dp_tx_complete_msdu(ar, msdu, &ts); + ath11k_dp_tx_complete_msdu(ar, msdu, &ts, &c); + } + + list_for_each_entry_safe(msdu, tmp, &c.free, list) { + skb_list_del_init(msdu); + napi_consume_skb(msdu, budget); } /* A completion returns the airtime the frame was charged, which is -- 2.53.0 Each frame a TXQ hands over took the TCL ring lock twice, read the hardware tail pointer three times and wrote the head pointer once. Take the ring once for the whole dequeue run instead: read the free count at the start, queue the frames on that ring and write the head pointer after the last one. ath11k_dp_tx() takes the ring the caller holds and does not fall back to another ring while it is held. Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.12-01460-QCAHKSWPL_SILICONZ-1 Signed-off-by: Julius Bairaktaris --- drivers/net/wireless/ath/ath11k/dp_tx.c | 37 ++++++++++---- drivers/net/wireless/ath/ath11k/dp_tx.h | 2 +- drivers/net/wireless/ath/ath11k/mac.c | 68 ++++++++++++++++--------- 3 files changed, 72 insertions(+), 35 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/dp_tx.c b/drivers/net/wireless/ath/ath11k/dp_tx.c index 4f509771d60a..bd5edab32a1f 100644 --- a/drivers/net/wireless/ath/ath11k/dp_tx.c +++ b/drivers/net/wireless/ath/ath11k/dp_tx.c @@ -108,8 +108,13 @@ bool ath11k_dp_tx_idr_has_room(struct dp_tx_ring *tx_ring) return atomic_read(&tx_ring->num_txbuf) < DP_TX_IDR_SIZE - 1; } +/* + * A caller that passes @held_ring holds that TCL ring's lock with an access + * open, and ends the access itself once it has queued its last frame; the frame + * goes on that ring or not at all. + */ int ath11k_dp_tx(struct ath11k *ar, struct ath11k_vif *arvif, - struct ath11k_sta *arsta, struct sk_buff *skb) + struct ath11k_sta *arsta, struct sk_buff *skb, int held_ring) { struct ath11k_base *ab = ar->ab; struct ath11k_dp *dp = &ab->dp; @@ -137,7 +142,10 @@ 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_get_queue_mapping(skb)); + if (held_ring >= 0) + ring_selector = held_ring; + else + ring_selector = ab->hw_params.hw_ops->get_ring_selector(skb_get_queue_mapping(skb)); tcl_ring_sel: tcl_ring_retry = false; @@ -157,7 +165,7 @@ int ath11k_dp_tx(struct ath11k *ar, struct ath11k_vif *arvif, spin_unlock_bh(&tx_ring->tx_idr_lock); if (unlikely(ret < 0)) { - if (ring_map == (BIT(num_tx_rings) - 1) || + if (held_ring >= 0 || ring_map == (BIT(num_tx_rings) - 1) || !ab->hw_params.tcl_ring_retry) { atomic_inc(&ab->soc_stats.tx_err.misc_fail); return -ENOSPC; @@ -256,11 +264,17 @@ int ath11k_dp_tx(struct ath11k *ar, struct ath11k_vif *arvif, hal_ring_id = tx_ring->tcl_data_ring.ring_id; tcl_ring = &ab->hal.srng_list[hal_ring_id]; - spin_lock_bh(&tcl_ring->lock); - - ath11k_hal_srng_access_begin(ab, tcl_ring); + if (held_ring < 0) { + spin_lock_bh(&tcl_ring->lock); + ath11k_hal_srng_access_begin(ab, tcl_ring); + } hal_tcl_desc = (void *)ath11k_hal_srng_src_get_next_entry(ab, tcl_ring); + if (unlikely(!hal_tcl_desc && held_ring >= 0)) { + ab->soc_stats.tx_err.desc_na[ti.ring_id]++; + ret = -ENOSPC; + goto fail_unmap_dma; + } if (unlikely(!hal_tcl_desc)) { /* NOTE: It is highly unlikely we'll be running out of tcl_ring * desc because the desc is directly enqueued onto hw queue. @@ -287,11 +301,12 @@ int ath11k_dp_tx(struct ath11k *ar, struct ath11k_vif *arvif, ath11k_hal_tx_cmd_desc_setup(ab, hal_tcl_desc + sizeof(struct hal_tlv_hdr), &ti); - ath11k_hal_srng_access_end(ab, tcl_ring); - - ath11k_dp_shadow_start_timer(ab, tcl_ring, &dp->tx_ring_timer[ti.ring_id]); - - spin_unlock_bh(&tcl_ring->lock); + if (held_ring < 0) { + ath11k_hal_srng_access_end(ab, tcl_ring); + ath11k_dp_shadow_start_timer(ab, tcl_ring, + &dp->tx_ring_timer[ti.ring_id]); + spin_unlock_bh(&tcl_ring->lock); + } ath11k_dbg_dump(ab, ATH11K_DBG_DP_TX, NULL, "dp tx msdu: ", skb->data, skb->len); diff --git a/drivers/net/wireless/ath/ath11k/dp_tx.h b/drivers/net/wireless/ath/ath11k/dp_tx.h index 760251c68b93..380e35e354f5 100644 --- a/drivers/net/wireless/ath/ath11k/dp_tx.h +++ b/drivers/net/wireless/ath/ath11k/dp_tx.h @@ -20,7 +20,7 @@ struct ath11k_dp_htt_wbm_tx_status { void ath11k_dp_tx_update_txcompl(struct ath11k *ar, struct hal_tx_status *ts); int ath11k_dp_tx_htt_h2t_ver_req_msg(struct ath11k_base *ab); int ath11k_dp_tx(struct ath11k *ar, struct ath11k_vif *arvif, - struct ath11k_sta *arsta, struct sk_buff *skb); + struct ath11k_sta *arsta, struct sk_buff *skb, int held_ring); bool ath11k_dp_tx_idr_has_room(struct dp_tx_ring *tx_ring); int ath11k_dp_tx_completion_handler(struct ath11k_base *ab, int ring_id, int budget); diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c index a0f1451a8faf..090df2f1cadf 100644 --- a/drivers/net/wireless/ath/ath11k/mac.c +++ b/drivers/net/wireless/ath/ath11k/mac.c @@ -6521,7 +6521,7 @@ static int ath11k_mac_mgmt_tx(struct ath11k *ar, struct sk_buff *skb, static int ath11k_mac_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control, - struct sk_buff *skb) + struct sk_buff *skb, int held_ring) { struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(skb); struct ath11k *ar = hw->priv; @@ -6559,7 +6559,7 @@ static int ath11k_mac_tx(struct ieee80211_hw *hw, if (control->sta) arsta = ath11k_sta_to_arsta(control->sta); - ret = ath11k_dp_tx(ar, arvif, arsta, skb); + ret = ath11k_dp_tx(ar, arvif, arsta, skb, held_ring); if (unlikely(ret)) { ath11k_warn(ar->ab, "failed to transmit frame %d\n", ret); ieee80211_free_txskb(ar->hw, skb); @@ -6572,7 +6572,7 @@ static void ath11k_mac_op_tx(struct ieee80211_hw *hw, struct ieee80211_tx_control *control, struct sk_buff *skb) { - ath11k_mac_tx(hw, control, skb); + ath11k_mac_tx(hw, control, skb, -1); } void ath11k_mac_drain_tx(struct ath11k *ar) @@ -10118,7 +10118,7 @@ static int ath11k_mac_tx_push_txq(struct ath11k *ar, struct ieee80211_txq *txq) struct hal_srng *tcl_ring; struct sk_buff *skb; u32 ring_selector; - int num_free; + int num_free, avail; int ret; u8 ring_id; @@ -10132,38 +10132,60 @@ static int ath11k_mac_tx_push_txq(struct ath11k *ar, struct ieee80211_txq *txq) * TCL ring or MSDU idr ends the whole round before a frame is taken * from the queue, and so does a frame the hardware refuses anyway, * as long as a frame in flight will restart it. + * + * The run holds the TCL ring for its whole length: the free count is + * read once and the head pointer written once, after the last frame, + * rather than per frame. The head pointer is a device register, which + * is not written while the firmware restarts or when no frame was + * added. */ - while (1) { +again: + if (unlikely(test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags))) + return -ESHUTDOWN; + + spin_lock_bh(&tx_ring->wake_tx_lock); + spin_lock_bh(&tcl_ring->lock); + ath11k_hal_srng_access_begin(ar->ab, tcl_ring); + num_free = ath11k_hal_srng_src_num_free(ar->ab, tcl_ring, false); + avail = num_free; + + ret = 0; + while (num_free) { if (unlikely(test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags))) break; - spin_lock_bh(&tx_ring->wake_tx_lock); - - spin_lock_bh(&tcl_ring->lock); - num_free = ath11k_hal_srng_src_num_free(ar->ab, tcl_ring, true); - spin_unlock_bh(&tcl_ring->lock); - - if (num_free == 0 || !ath11k_dp_tx_idr_has_room(tx_ring)) { - spin_unlock_bh(&tx_ring->wake_tx_lock); - if (ath11k_mac_mark_txq_starved(ar, txq->ac)) - return -ENOSPC; - continue; + if (!ath11k_dp_tx_idr_has_room(tx_ring)) { + ret = -ENOSPC; + break; } skb = ieee80211_tx_dequeue(hw, txq); - if (!skb) { - spin_unlock_bh(&tx_ring->wake_tx_lock); + if (!skb) break; - } - ret = ath11k_mac_tx(hw, &control, skb); + ret = ath11k_mac_tx(hw, &control, skb, ring_id); + if (unlikely(ret == -ENOSPC || ret == -ENOMEM)) + break; + ret = 0; + num_free--; + } - spin_unlock_bh(&tx_ring->wake_tx_lock); + if (num_free != avail && + likely(!test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags))) { + ath11k_hal_srng_access_end(ar->ab, tcl_ring); + ath11k_dp_shadow_start_timer(ar->ab, tcl_ring, + &ar->ab->dp.tx_ring_timer[ring_id]); + } + spin_unlock_bh(&tcl_ring->lock); + spin_unlock_bh(&tx_ring->wake_tx_lock); - if (unlikely(ret == -ENOSPC || ret == -ENOMEM) && - ath11k_mac_mark_txq_starved(ar, txq->ac)) + if (!num_free) + ret = -ENOSPC; + if (unlikely(ret == -ENOSPC || ret == -ENOMEM)) { + if (ath11k_mac_mark_txq_starved(ar, txq->ac)) return ret; + goto again; } return 0; -- 2.53.0 Each frame that the network stack queues from a receive poll wakes its TXQ on its own, and the wake ran a scheduling round at once, so a round handed the hardware a single frame and paid for the ring access, the locks and the scheduler per frame. Record the woken access categories and run their rounds from BH work, which runs after the poll and takes every frame it queued in one round. Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.12-01460-QCAHKSWPL_SILICONZ-1 Signed-off-by: Julius Bairaktaris --- drivers/net/wireless/ath/ath11k/core.h | 3 +++ drivers/net/wireless/ath/ath11k/mac.c | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/drivers/net/wireless/ath/ath11k/core.h b/drivers/net/wireless/ath/ath11k/core.h index 8b7bfb0cefcf..74fbff296b60 100644 --- a/drivers/net/wireless/ath/ath11k/core.h +++ b/drivers/net/wireless/ath/ath11k/core.h @@ -715,6 +715,9 @@ struct ath11k { spinlock_t txq_lock[IEEE80211_NUM_ACS]; /* access categories whose round ended for lack of room */ unsigned long txq_starved; + /* access categories woken since txq_work last ran */ + unsigned long txq_woken; + struct work_struct txq_work; struct list_head arvifs; /* should never be NULL; needed for regular htt rx */ diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c index 090df2f1cadf..0af4f2fe27bb 100644 --- a/drivers/net/wireless/ath/ath11k/mac.c +++ b/drivers/net/wireless/ath/ath11k/mac.c @@ -6791,6 +6791,7 @@ static void ath11k_mac_op_stop(struct ieee80211_hw *hw, bool suspend) cancel_work_sync(&ar->channel_update_work); cancel_work_sync(&ar->regd_update_work); cancel_work_sync(&ar->ab->update_11d_work); + cancel_work_sync(&ar->txq_work); if (ar->state_11d == ATH11K_11D_PREPARING) { ar->state_11d = ATH11K_11D_IDLE; @@ -10211,10 +10212,30 @@ static void ath11k_mac_schedule_txq(struct ath11k *ar, u8 ac) spin_unlock_bh(&ar->txq_lock[ac]); } +/* + * A frame queued from a receive poll wakes its TXQ on its own, so pushing + * from the wake would hand the hardware one frame per round. The rounds run + * from BH work instead, after the poll, and take every frame it queued. + */ +static void ath11k_mac_txq_work(struct work_struct *work) +{ + struct ath11k *ar = container_of(work, struct ath11k, txq_work); + unsigned long woken = xchg(&ar->txq_woken, 0); + u8 ac; + + rcu_read_lock(); + for_each_set_bit(ac, &woken, IEEE80211_NUM_ACS) + ath11k_mac_schedule_txq(ar, ac); + rcu_read_unlock(); +} + static void ath11k_mac_op_wake_tx_queue(struct ieee80211_hw *hw, struct ieee80211_txq *txq) { - ath11k_mac_schedule_txq(hw->priv, txq->ac); + struct ath11k *ar = hw->priv; + + set_bit(txq->ac, &ar->txq_woken); + queue_work(system_bh_wq, &ar->txq_work); } void ath11k_mac_tx_push_pending(struct ath11k *ar, u8 ac) @@ -10953,6 +10974,7 @@ int ath11k_mac_allocate(struct ath11k_base *ab) for (j = 0; j < IEEE80211_NUM_ACS; j++) spin_lock_init(&ar->txq_lock[j]); + INIT_WORK(&ar->txq_work, ath11k_mac_txq_work); INIT_LIST_HEAD(&ar->arvifs); INIT_LIST_HEAD(&ar->ppdu_stats_info); mutex_init(&ar->conf_mutex); -- 2.53.0 Every transmitted frame took a buffer id from an IDR when it was queued and gave it back on completion. Keep the ids of each TCL ring in a table indexed by id with a stack of the free ones, so both steps take constant time. The id range stays the one the IDR handed out. The recovery path that returns the frames a crashed firmware holds walks the table as well. Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.12-01460-QCAHKSWPL_SILICONZ-1 ath11k_dp_tx_idr_has_room() now reads the count of free ids, and the num_txbuf counter it read until now goes away. Signed-off-by: Julius Bairaktaris --- drivers/net/wireless/ath/ath11k/dp.c | 30 ++++--- drivers/net/wireless/ath/ath11k/dp.h | 11 ++- drivers/net/wireless/ath/ath11k/dp_tx.c | 104 ++++++++++++++++++------ drivers/net/wireless/ath/ath11k/dp_tx.h | 2 + drivers/net/wireless/ath/ath11k/mac.c | 20 +++-- 5 files changed, 115 insertions(+), 52 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/dp.c b/drivers/net/wireless/ath/ath11k/dp.c index 833feb981cfc..e7eab9857f29 100644 --- a/drivers/net/wireless/ath/ath11k/dp.c +++ b/drivers/net/wireless/ath/ath11k/dp.c @@ -1015,17 +1015,21 @@ void ath11k_dp_vdev_tx_attach(struct ath11k *ar, struct ath11k_vif *arvif) ath11k_dp_update_vdev_search(arvif); } -static int ath11k_dp_tx_pending_cleanup(int buf_id, void *skb, void *ctx) +static void ath11k_dp_tx_pending_cleanup(struct ath11k_base *ab, + struct dp_tx_ring *tx_ring) { - struct ath11k_base *ab = ctx; - struct sk_buff *msdu = skb; + struct sk_buff *msdu; + u32 id; - dma_unmap_single(ab->dev, ATH11K_SKB_CB(msdu)->paddr, msdu->len, - DMA_TO_DEVICE); - - dev_kfree_skb_any(msdu); + for (id = 0; tx_ring->bufs && id < DP_TX_IDR_SIZE - 1; id++) { + msdu = tx_ring->bufs[id]; + if (!msdu) + continue; - return 0; + dma_unmap_single(ab->dev, ATH11K_SKB_CB(msdu)->paddr, + msdu->len, DMA_TO_DEVICE); + dev_kfree_skb_any(msdu); + } } void ath11k_dp_free(struct ath11k_base *ab) @@ -1042,9 +1046,8 @@ void ath11k_dp_free(struct ath11k_base *ab) for (i = 0; i < ab->hw_params.hal_params->num_tx_rings; i++) { spin_lock_bh(&dp->tx_ring[i].tx_idr_lock); - idr_for_each(&dp->tx_ring[i].txbuf_idr, - ath11k_dp_tx_pending_cleanup, ab); - idr_destroy(&dp->tx_ring[i].txbuf_idr); + ath11k_dp_tx_pending_cleanup(ab, &dp->tx_ring[i]); + ath11k_dp_tx_bufs_free(&dp->tx_ring[i]); spin_unlock_bh(&dp->tx_ring[i].tx_idr_lock); kfree(dp->tx_ring[i].tx_status); dp->tx_ring[i].tx_status = NULL; @@ -1093,8 +1096,9 @@ int ath11k_dp_alloc(struct ath11k_base *ab) size = sizeof(struct hal_wbm_release_ring) * DP_TX_COMP_RING_SIZE; for (i = 0; i < ab->hw_params.hal_params->num_tx_rings; i++) { - idr_init(&dp->tx_ring[i].txbuf_idr); - atomic_set(&dp->tx_ring[i].num_txbuf, 0); + ret = ath11k_dp_tx_bufs_init(&dp->tx_ring[i]); + if (ret) + goto fail_cmn_srng_cleanup; 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; diff --git a/drivers/net/wireless/ath/ath11k/dp.h b/drivers/net/wireless/ath/ath11k/dp.h index bf7439e8b37d..f3dcba777a34 100644 --- a/drivers/net/wireless/ath/ath11k/dp.h +++ b/drivers/net/wireless/ath/ath11k/dp.h @@ -84,13 +84,12 @@ struct dp_tx_ring { u8 tcl_data_ring_id; struct dp_srng tcl_data_ring; struct dp_srng tcl_comp_ring; - struct idr txbuf_idr; - /* Protects txbuf_idr; num_txbuf changes with it and is read without */ + /* Buffers by the id their descriptor carries, and the ids not in use */ + struct sk_buff **bufs; + u32 *free_ids; + u32 num_free; + /* Protects bufs and free_ids */ spinlock_t tx_idr_lock; - /* MSDU ids in use, one per frame between ath11k_dp_tx() and its - * completion - */ - atomic_t num_txbuf; /* Serializes wake_tx_queue operations for this ring */ spinlock_t wake_tx_lock; struct hal_wbm_release_ring *tx_status; diff --git a/drivers/net/wireless/ath/ath11k/dp_tx.c b/drivers/net/wireless/ath/ath11k/dp_tx.c index bd5edab32a1f..feeaba575966 100644 --- a/drivers/net/wireless/ath/ath11k/dp_tx.c +++ b/drivers/net/wireless/ath/ath11k/dp_tx.c @@ -79,33 +79,88 @@ enum hal_encrypt_type ath11k_dp_tx_get_encrypt_type(u32 cipher) } } -/* The caller holds tx_ring->tx_idr_lock. */ -static struct sk_buff *ath11k_dp_tx_idr_remove(struct dp_tx_ring *tx_ring, - int msdu_id) +/* + * The ids a ring hands out, as a table indexed by id with a stack of the free + * ones: the completion's cookie names the buffer directly. Callers of the id + * helpers hold tx_idr_lock. + */ +int ath11k_dp_tx_bufs_init(struct dp_tx_ring *tx_ring) { - struct sk_buff *msdu; + u32 id; + + tx_ring->bufs = kvcalloc(DP_TX_IDR_SIZE - 1, sizeof(*tx_ring->bufs), + GFP_KERNEL); + tx_ring->free_ids = kvcalloc(DP_TX_IDR_SIZE - 1, + sizeof(*tx_ring->free_ids), GFP_KERNEL); + if (!tx_ring->bufs || !tx_ring->free_ids) { + ath11k_dp_tx_bufs_free(tx_ring); + return -ENOMEM; + } + + tx_ring->num_free = 0; + for (id = DP_TX_IDR_SIZE - 1; id--;) + tx_ring->free_ids[tx_ring->num_free++] = id; + + return 0; +} + +void ath11k_dp_tx_bufs_free(struct dp_tx_ring *tx_ring) +{ + kvfree(tx_ring->bufs); + kvfree(tx_ring->free_ids); + tx_ring->bufs = NULL; + tx_ring->free_ids = NULL; + tx_ring->num_free = 0; +} + +static int ath11k_dp_tx_buf_get_id(struct dp_tx_ring *tx_ring, + struct sk_buff *skb) +{ + u32 id; + + if (unlikely(!tx_ring->num_free)) + return -ENOSPC; + + id = tx_ring->free_ids[--tx_ring->num_free]; + tx_ring->bufs[id] = skb; + + return id; +} + +static struct sk_buff *ath11k_dp_tx_buf_put_id(struct dp_tx_ring *tx_ring, + u32 id) +{ + struct sk_buff *skb; + + if (unlikely(id >= DP_TX_IDR_SIZE - 1)) + return NULL; + + skb = tx_ring->bufs[id]; + if (unlikely(!skb)) + return NULL; - msdu = idr_remove(&tx_ring->txbuf_idr, msdu_id); - if (msdu) - atomic_dec(&tx_ring->num_txbuf); + tx_ring->bufs[id] = NULL; + tx_ring->free_ids[tx_ring->num_free++] = id; - return msdu; + return skb; } /** * ath11k_dp_tx_idr_has_room() - tell whether ath11k_dp_tx() can take a frame * @tx_ring: the ring the frame would go to first * - * ath11k_dp_tx() allocates the frame's MSDU id from the ring's idr, which - * holds DP_TX_IDR_SIZE - 1 ids and frees one when the frame completes. A - * caller that takes a frame from mac80211 only to have it refused for a full - * idr loses the frame, so it checks first. + * ath11k_dp_tx() takes the frame's MSDU id from the ring's free ids, of which + * there are DP_TX_IDR_SIZE - 1, and the frame's completion returns it. A caller + * that takes a frame from mac80211 only to have it refused for want of an id + * loses the frame, so it checks first. The count is read without tx_idr_lock: + * an id taken in between costs that one frame, as before the check. * - * Return: true if the idr has an id free. + * Return: true if an id is free. */ bool ath11k_dp_tx_idr_has_room(struct dp_tx_ring *tx_ring) { - return atomic_read(&tx_ring->num_txbuf) < DP_TX_IDR_SIZE - 1; + /* Read without tx_idr_lock: a stale count costs at most one frame. */ + return data_race(tx_ring->num_free) != 0; } /* @@ -158,10 +213,7 @@ int ath11k_dp_tx(struct ath11k *ar, struct ath11k_vif *arvif, tx_ring = &dp->tx_ring[ti.ring_id]; spin_lock_bh(&tx_ring->tx_idr_lock); - ret = idr_alloc(&tx_ring->txbuf_idr, skb, 0, - DP_TX_IDR_SIZE - 1, GFP_ATOMIC); - if (likely(ret >= 0)) - atomic_inc(&tx_ring->num_txbuf); + ret = ath11k_dp_tx_buf_get_id(tx_ring, skb); spin_unlock_bh(&tx_ring->tx_idr_lock); if (unlikely(ret < 0)) { @@ -320,7 +372,7 @@ int ath11k_dp_tx(struct ath11k *ar, struct ath11k_vif *arvif, fail_remove_idr: spin_lock_bh(&tx_ring->tx_idr_lock); - ath11k_dp_tx_idr_remove(tx_ring, + ath11k_dp_tx_buf_put_id(tx_ring, FIELD_GET(DP_TX_DESC_ID_MSDU_ID, ti.desc_id)); spin_unlock_bh(&tx_ring->tx_idr_lock); @@ -340,7 +392,7 @@ static void ath11k_dp_tx_free_txbuf(struct ath11k_base *ab, u8 mac_id, struct ath11k_skb_cb *skb_cb; spin_lock(&tx_ring->tx_idr_lock); - msdu = ath11k_dp_tx_idr_remove(tx_ring, msdu_id); + msdu = ath11k_dp_tx_buf_put_id(tx_ring, msdu_id); spin_unlock(&tx_ring->tx_idr_lock); if (unlikely(!msdu)) { @@ -383,9 +435,11 @@ void ath11k_dp_tx_free_pending(struct ath11k_base *ab) tx_ring = &ab->dp.tx_ring[i]; spin_lock_bh(&tx_ring->tx_idr_lock); - idr_for_each_entry(&tx_ring->txbuf_idr, msdu, msdu_id) { - ath11k_dp_tx_idr_remove(tx_ring, msdu_id); - __skb_queue_tail(&pending, msdu); + for (msdu_id = 0; tx_ring->bufs && msdu_id < DP_TX_IDR_SIZE - 1; + msdu_id++) { + msdu = ath11k_dp_tx_buf_put_id(tx_ring, msdu_id); + if (msdu) + __skb_queue_tail(&pending, msdu); } spin_unlock_bh(&tx_ring->tx_idr_lock); } @@ -412,7 +466,7 @@ ath11k_dp_tx_htt_tx_complete_buf(struct ath11k_base *ab, struct ath11k_peer *peer; spin_lock(&tx_ring->tx_idr_lock); - msdu = ath11k_dp_tx_idr_remove(tx_ring, ts->msdu_id); + msdu = ath11k_dp_tx_buf_put_id(tx_ring, ts->msdu_id); spin_unlock(&tx_ring->tx_idr_lock); if (unlikely(!msdu)) { @@ -862,7 +916,7 @@ int ath11k_dp_tx_completion_handler(struct ath11k_base *ab, int ring_id, } spin_lock(&tx_ring->tx_idr_lock); - msdu = ath11k_dp_tx_idr_remove(tx_ring, msdu_id); + msdu = ath11k_dp_tx_buf_put_id(tx_ring, msdu_id); if (unlikely(!msdu)) { ath11k_warn(ab, "tx completion for unknown msdu_id %d\n", msdu_id); diff --git a/drivers/net/wireless/ath/ath11k/dp_tx.h b/drivers/net/wireless/ath/ath11k/dp_tx.h index 380e35e354f5..50b6178ceb38 100644 --- a/drivers/net/wireless/ath/ath11k/dp_tx.h +++ b/drivers/net/wireless/ath/ath11k/dp_tx.h @@ -22,6 +22,8 @@ int ath11k_dp_tx_htt_h2t_ver_req_msg(struct ath11k_base *ab); int ath11k_dp_tx(struct ath11k *ar, struct ath11k_vif *arvif, struct ath11k_sta *arsta, struct sk_buff *skb, int held_ring); bool ath11k_dp_tx_idr_has_room(struct dp_tx_ring *tx_ring); +int ath11k_dp_tx_bufs_init(struct dp_tx_ring *tx_ring); +void ath11k_dp_tx_bufs_free(struct dp_tx_ring *tx_ring); int ath11k_dp_tx_completion_handler(struct ath11k_base *ab, int ring_id, int budget); void ath11k_dp_tx_free_pending(struct ath11k_base *ab); diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c index 0af4f2fe27bb..513559585371 100644 --- a/drivers/net/wireless/ath/ath11k/mac.c +++ b/drivers/net/wireless/ath/ath11k/mac.c @@ -7361,15 +7361,20 @@ static int ath11k_mac_op_add_interface(struct ieee80211_hw *hw, return ret; } -static int ath11k_mac_vif_unref(int buf_id, void *skb, void *ctx) +static void ath11k_mac_vif_unref(struct dp_tx_ring *tx_ring, + struct ieee80211_vif *vif) { - struct ieee80211_vif *vif = ctx; - struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(skb); + struct ath11k_skb_cb *skb_cb; + u32 id; - if (skb_cb->vif == vif) - skb_cb->vif = NULL; + for (id = 0; id < DP_TX_IDR_SIZE - 1; id++) { + if (!tx_ring->bufs[id]) + continue; - return 0; + skb_cb = ATH11K_SKB_CB(tx_ring->bufs[id]); + if (skb_cb->vif == vif) + skb_cb->vif = NULL; + } } static void ath11k_mac_op_remove_interface(struct ieee80211_hw *hw, @@ -7434,8 +7439,7 @@ static void ath11k_mac_op_remove_interface(struct ieee80211_hw *hw, for (i = 0; i < ab->hw_params.hal_params->num_tx_rings; i++) { spin_lock_bh(&ab->dp.tx_ring[i].tx_idr_lock); - idr_for_each(&ab->dp.tx_ring[i].txbuf_idr, - ath11k_mac_vif_unref, vif); + ath11k_mac_vif_unref(&ab->dp.tx_ring[i], vif); spin_unlock_bh(&ab->dp.tx_ring[i].tx_idr_lock); } -- 2.53.0 mac80211 can hand the driver a TCP batch as one frame with the segments described by gso_size. Sending each segment as its own frame costs an allocation, a mapping and a free per segment on the CPU. The TCL segments a batch itself. The layout of the MSDU extension descriptor, with its TSO fields and six buffer pointers, is that of the HAL_TX_MSDU_EXTENSION_* field offsets in hal/wifi3.0/hal_tx_hw_defines.h of Qualcomm's open-source WLAN host driver on CodeLinaro. A data command of type EXT_DESC points at an MSDU extension descriptor that lists the headers of the batch and the payload of one segment in up to six buffers, and carries the segment's IP length, IP ID, TCP sequence number and flags, which the TCL writes into the headers; it fills in the checksums the data command enables. Queue every segment of a batch that way, with one mapping of the headers and one of each payload piece, and report the batch to mac80211 when the completion of its last segment arrives. Each segment holds a reference on the batch and its own buffer id, so the completion paths release a segment and return the batch only for the last one. Every segment completes on its own: its status counts in the station statistics as that of a frame of its length, and goes into the status of the batch. The batch is reported to mac80211 as acked only if all its segments were acked, with the most tries of any segment, as mac80211 reads the tries as those of one frame at one rate and their sum over the segments would overstate them by the number of segments. The tries now come from the completion for every frame, where mac80211 got a constant 1 before. The ring entries, ids and descriptors of all segments are taken before the first is queued. A batch the TCL cannot take (no free descriptor, more than five payload pieces in a segment, a frame that is not sent with Ethernet encap, a protocol other than TCP, an IPv6 header followed by extension headers, which the descriptor has no length for) is segmented in software with skb_gso_segment(); the frames share the airtime charge of the batch by leaving it on the last one. A frame with fragments but no GSO is sent from one extension descriptor as a batch of one segment without segmentation, with its linear part and up to five fragments as the buffers, and is made linear only if that does not fit; ARP, EAPOL and DHCP frames always stay linear. The transmit loop of a vif with the encap offload takes a frame only while a batch of 16 segments fits in the TCL ring, which is the most the interface offers. Once the firmware crashed, no frame takes this path and the ring is not updated, as for the TXQ push. The frames are built as the vendor host driver of the same TCL (Qualcomm's open-source WLAN host driver on CodeLinaro) builds its TSO frames. The buffer of the headers ends on an 8 byte boundary: that driver moves the headers down into the head room by the excess, with the header offsets, and maps the payload where it was (qdf_nbuf_adj_tso_frag() in qdf/linux/src/qdf_nbuf.c, built with FIX_TXDMA_LIMITATION). Here that is done for every frame sent from an extension descriptor, a frame with fragments too, and the head is copied first only when it lacks the room or is shared. The descriptors fill each 4096 byte block of their coherent memory and none crosses into the next, as in that driver's pool of descriptor pages (dp_tx_ext_desc_pool_alloc_by_id() in dp/wifi3.0/dp_tx_desc.c). A batch enables the IP, UDP and TCP checksums in the data command, as dp_tx_hw_enqueue_li() in dp/wifi3.0/li/dp_li_tx.c does for a TSO frame. On IPQ8074, frames built without these rules are not delivered at all, while built with them TCP batches and scatter-gather frames went out routed and bridged, over IPv4 and IPv6 (observed on the device). The debugfs SOC statistics count the batches and segments, the batches that were segmented in software and the frames sent as scatter-gather. Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.12-01460-QCAHKSWPL_SILICONZ-1 A dequeue run now asks ath11k_dp_tx_idr_has_room() for as many MSDU ids as it reserves TCL entries, since a batch the TCL cannot take whole is segmented in software with an id per segment. Signed-off-by: Julius Bairaktaris --- drivers/net/wireless/ath/ath11k/core.c | 1 + drivers/net/wireless/ath/ath11k/core.h | 14 + drivers/net/wireless/ath/ath11k/debugfs.c | 7 + drivers/net/wireless/ath/ath11k/dp.c | 10 +- drivers/net/wireless/ath/ath11k/dp.h | 37 +- drivers/net/wireless/ath/ath11k/dp_tx.c | 820 +++++++++++++++++++-- drivers/net/wireless/ath/ath11k/dp_tx.h | 15 +- drivers/net/wireless/ath/ath11k/hal_desc.h | 46 ++ drivers/net/wireless/ath/ath11k/hw.h | 1 + drivers/net/wireless/ath/ath11k/mac.c | 42 +- 10 files changed, 912 insertions(+), 81 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/core.c b/drivers/net/wireless/ath/ath11k/core.c index 34cfdedea6ad..f945a7a12744 100644 --- a/drivers/net/wireless/ath/ath11k/core.c +++ b/drivers/net/wireless/ath/ath11k/core.c @@ -120,6 +120,7 @@ static const struct ath11k_hw_params ath11k_hw_params[] = { .sram_dump = {}, .tcl_ring_retry = true, + .tx_tso = true, .tx_ring_size = DP_TCL_DATA_RING_SIZE, .smp2p_wow_exit = false, .support_dual_stations = false, diff --git a/drivers/net/wireless/ath/ath11k/core.h b/drivers/net/wireless/ath/ath11k/core.h index 74fbff296b60..11c79d0f5c34 100644 --- a/drivers/net/wireless/ath/ath11k/core.h +++ b/drivers/net/wireless/ath/ath11k/core.h @@ -122,6 +122,12 @@ struct ath11k_skb_cb { u32 cipher; struct ath11k *ar; struct ieee80211_vif *vif; + /* + * Of a frame sent from an MSDU extension descriptor: the most tries + * of its segments so far, and how many were not acked + */ + u8 tso_try; + u8 tso_bad; } __packed; struct ath11k_skb_rxcb { @@ -908,6 +914,14 @@ struct ath11k_soc_dp_stats { u32 rxdma_error[HAL_REO_ENTR_RING_RXDMA_ECODE_MAX]; u32 reo_error[HAL_REO_DEST_RING_ERROR_CODE_MAX]; u32 hal_reo_error[DP_REO_DST_RING_MAX]; + /* + * TCP batches the TCL segments, their segments, and batches that + * were segmented in software instead + */ + atomic_t tx_tso_batch; + atomic_t tx_tso_seg; + atomic_t tx_tso_sw; + atomic_t tx_sg; struct ath11k_soc_dp_tx_err_stats tx_err; struct ath11k_dp_ring_bp_stats bp_stats; }; diff --git a/drivers/net/wireless/ath/ath11k/debugfs.c b/drivers/net/wireless/ath/ath11k/debugfs.c index ffe1f466aefb..28d3a4d8faab 100644 --- a/drivers/net/wireless/ath/ath11k/debugfs.c +++ b/drivers/net/wireless/ath/ath11k/debugfs.c @@ -703,6 +703,13 @@ static ssize_t ath11k_debugfs_dump_soc_dp_stats(struct file *file, soc_stats->hal_reo_error[2], soc_stats->hal_reo_error[3]); + len += scnprintf(buf + len, size - len, + "TCP batches segmented by the TCL: %d, their segments: %d, segmented in software: %d, frames with fragments sent as scatter-gather: %d\n", + atomic_read(&soc_stats->tx_tso_batch), + atomic_read(&soc_stats->tx_tso_seg), + atomic_read(&soc_stats->tx_tso_sw), + atomic_read(&soc_stats->tx_sg)); + len += scnprintf(buf + len, size - len, "\nSOC TX STATS:\n"); len += scnprintf(buf + len, size - len, "\nTCL Ring Full Failures:\n"); diff --git a/drivers/net/wireless/ath/ath11k/dp.c b/drivers/net/wireless/ath/ath11k/dp.c index e7eab9857f29..1d131ef39b7e 100644 --- a/drivers/net/wireless/ath/ath11k/dp.c +++ b/drivers/net/wireless/ath/ath11k/dp.c @@ -1022,12 +1022,14 @@ static void ath11k_dp_tx_pending_cleanup(struct ath11k_base *ab, u32 id; for (id = 0; tx_ring->bufs && id < DP_TX_IDR_SIZE - 1; id++) { - msdu = tx_ring->bufs[id]; + bool more; + + msdu = ath11k_dp_tx_buf_put_id(ab, tx_ring, id, &more, NULL); if (!msdu) continue; dma_unmap_single(ab->dev, ATH11K_SKB_CB(msdu)->paddr, - msdu->len, DMA_TO_DEVICE); + skb_headlen(msdu), DMA_TO_DEVICE); dev_kfree_skb_any(msdu); } } @@ -1047,8 +1049,8 @@ void ath11k_dp_free(struct ath11k_base *ab) for (i = 0; i < ab->hw_params.hal_params->num_tx_rings; i++) { spin_lock_bh(&dp->tx_ring[i].tx_idr_lock); ath11k_dp_tx_pending_cleanup(ab, &dp->tx_ring[i]); - ath11k_dp_tx_bufs_free(&dp->tx_ring[i]); spin_unlock_bh(&dp->tx_ring[i].tx_idr_lock); + ath11k_dp_tx_bufs_free(ab, &dp->tx_ring[i]); kfree(dp->tx_ring[i].tx_status); dp->tx_ring[i].tx_status = NULL; } @@ -1096,7 +1098,7 @@ int ath11k_dp_alloc(struct ath11k_base *ab) size = sizeof(struct hal_wbm_release_ring) * DP_TX_COMP_RING_SIZE; for (i = 0; i < ab->hw_params.hal_params->num_tx_rings; i++) { - ret = ath11k_dp_tx_bufs_init(&dp->tx_ring[i]); + ret = ath11k_dp_tx_bufs_init(ab, &dp->tx_ring[i]); if (ret) goto fail_cmn_srng_cleanup; spin_lock_init(&dp->tx_ring[i].tx_idr_lock); diff --git a/drivers/net/wireless/ath/ath11k/dp.h b/drivers/net/wireless/ath/ath11k/dp.h index f3dcba777a34..a923ba792e4b 100644 --- a/drivers/net/wireless/ath/ath11k/dp.h +++ b/drivers/net/wireless/ath/ath11k/dp.h @@ -80,6 +80,29 @@ struct dp_rxdma_ring { #define ATH11K_TX_COMPL_NEXT(x) (((x) + 1) % DP_TX_COMP_RING_SIZE) +/* + * The most segments of a TCP batch the TCL takes whole, and the payload + * pieces of one segment past the headers + */ +#define ATH11K_DP_TX_TSO_MAX_SEGS 16 +#define ATH11K_DP_TX_NO_EXT 0xffff + +struct ath11k_dp_tx_ext_map { + u32 dma[HAL_TX_MSDU_EXT_NUM_BUFS - 1]; + u16 len[HAL_TX_MSDU_EXT_NUM_BUFS - 1]; + /* the frame this descriptor makes, headers included */ + u16 seg_len; + u8 num; +}; + +/* What a buffer id held when it was released */ +struct ath11k_dp_tx_seg { + /* the frame, or the batch the segment belongs to */ + struct sk_buff *skb; + /* the length of the segment, or 0 for a frame sent as one buffer */ + u16 len; +}; + struct dp_tx_ring { u8 tcl_data_ring_id; struct dp_srng tcl_data_ring; @@ -88,7 +111,18 @@ struct dp_tx_ring { struct sk_buff **bufs; u32 *free_ids; u32 num_free; - /* Protects bufs and free_ids */ + /* + * MSDU extension descriptors for TSO segments, placed by + * ath11k_dp_tx_ext_off(), the payload mappings of each, the + * descriptor each buffer id uses, and the ones not in use + */ + struct hal_tx_msdu_ext *ext; + dma_addr_t ext_paddr; + struct ath11k_dp_tx_ext_map *ext_map; + u16 *ext_slot; + u16 *ext_free; + u32 ext_num_free; + /* Protects bufs, free_ids, ext_slot and ext_free */ spinlock_t tx_idr_lock; /* Serializes wake_tx_queue operations for this ring */ spinlock_t wake_tx_lock; @@ -212,6 +246,7 @@ struct ath11k_pdev_dp { #define DP_TCL_DATA_RING_SIZE_WCN6750 2048 #define DP_TX_COMP_RING_SIZE 32768 #define DP_TX_IDR_SIZE DP_TX_COMP_RING_SIZE +#define DP_TX_EXT_DESC_NUM 2048 #define DP_TCL_CMD_RING_SIZE 32 #define DP_TCL_STATUS_RING_SIZE 32 #define DP_REO_DST_RING_MAX 4 diff --git a/drivers/net/wireless/ath/ath11k/dp_tx.c b/drivers/net/wireless/ath/ath11k/dp_tx.c index feeaba575966..4fbdd15d1ce0 100644 --- a/drivers/net/wireless/ath/ath11k/dp_tx.c +++ b/drivers/net/wireless/ath/ath11k/dp_tx.c @@ -4,6 +4,9 @@ * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. */ +#include +#include + #include "core.h" #include "dp_tx.h" #include "debug.h" @@ -79,12 +82,36 @@ enum hal_encrypt_type ath11k_dp_tx_get_encrypt_type(u32 cipher) } } +/* + * The MSDU extension descriptors of a ring fill each 4096 byte block of their + * memory from its start, and none crosses into the next block. The memory + * from dma_alloc_coherent() is page aligned, so the blocks are too. + */ +#define ATH11K_DP_TX_EXT_BLOCK 4096 +#define ATH11K_DP_TX_EXT_PER_BLOCK (ATH11K_DP_TX_EXT_BLOCK / \ + sizeof(struct hal_tx_msdu_ext)) +#define ATH11K_DP_TX_EXT_SIZE (DIV_ROUND_UP(DP_TX_EXT_DESC_NUM, \ + ATH11K_DP_TX_EXT_PER_BLOCK) * \ + ATH11K_DP_TX_EXT_BLOCK) + +/* + * The buffer of the headers of an extension descriptor frame ends on this + * boundary + */ +#define ATH11K_DP_TX_EXT_ALIGN 8 + +static size_t ath11k_dp_tx_ext_off(unsigned int slot) +{ + return slot / ATH11K_DP_TX_EXT_PER_BLOCK * ATH11K_DP_TX_EXT_BLOCK + + slot % ATH11K_DP_TX_EXT_PER_BLOCK * sizeof(struct hal_tx_msdu_ext); +} + /* * The ids a ring hands out, as a table indexed by id with a stack of the free * ones: the completion's cookie names the buffer directly. Callers of the id * helpers hold tx_idr_lock. */ -int ath11k_dp_tx_bufs_init(struct dp_tx_ring *tx_ring) +int ath11k_dp_tx_bufs_init(struct ath11k_base *ab, struct dp_tx_ring *tx_ring) { u32 id; @@ -92,25 +119,60 @@ int ath11k_dp_tx_bufs_init(struct dp_tx_ring *tx_ring) GFP_KERNEL); tx_ring->free_ids = kvcalloc(DP_TX_IDR_SIZE - 1, sizeof(*tx_ring->free_ids), GFP_KERNEL); - if (!tx_ring->bufs || !tx_ring->free_ids) { - ath11k_dp_tx_bufs_free(tx_ring); + tx_ring->ext_slot = kvmalloc_array(DP_TX_IDR_SIZE - 1, + sizeof(*tx_ring->ext_slot), + GFP_KERNEL); + if (ab->hw_params.tx_tso) { + tx_ring->ext = dma_alloc_coherent(ab->dev, ATH11K_DP_TX_EXT_SIZE, + &tx_ring->ext_paddr, + GFP_KERNEL); + tx_ring->ext_map = kvcalloc(DP_TX_EXT_DESC_NUM, + sizeof(*tx_ring->ext_map), + GFP_KERNEL); + tx_ring->ext_free = kvcalloc(DP_TX_EXT_DESC_NUM, + sizeof(*tx_ring->ext_free), + GFP_KERNEL); + } + if (!tx_ring->bufs || !tx_ring->free_ids || !tx_ring->ext_slot || + (ab->hw_params.tx_tso && + (!tx_ring->ext || !tx_ring->ext_map || !tx_ring->ext_free))) { + ath11k_dp_tx_bufs_free(ab, tx_ring); return -ENOMEM; } + memset(tx_ring->ext_slot, 0xff, + (DP_TX_IDR_SIZE - 1) * sizeof(*tx_ring->ext_slot)); + tx_ring->num_free = 0; for (id = DP_TX_IDR_SIZE - 1; id--;) tx_ring->free_ids[tx_ring->num_free++] = id; + tx_ring->ext_num_free = 0; + if (tx_ring->ext_free) + for (id = DP_TX_EXT_DESC_NUM; id--;) + tx_ring->ext_free[tx_ring->ext_num_free++] = id; + return 0; } -void ath11k_dp_tx_bufs_free(struct dp_tx_ring *tx_ring) +void ath11k_dp_tx_bufs_free(struct ath11k_base *ab, struct dp_tx_ring *tx_ring) { kvfree(tx_ring->bufs); kvfree(tx_ring->free_ids); + kvfree(tx_ring->ext_slot); + if (tx_ring->ext) + dma_free_coherent(ab->dev, ATH11K_DP_TX_EXT_SIZE, + tx_ring->ext, tx_ring->ext_paddr); + kvfree(tx_ring->ext_map); + kvfree(tx_ring->ext_free); tx_ring->bufs = NULL; tx_ring->free_ids = NULL; + tx_ring->ext_slot = NULL; + tx_ring->ext = NULL; + tx_ring->ext_map = NULL; + tx_ring->ext_free = NULL; tx_ring->num_free = 0; + tx_ring->ext_num_free = 0; } static int ath11k_dp_tx_buf_get_id(struct dp_tx_ring *tx_ring, @@ -127,10 +189,34 @@ static int ath11k_dp_tx_buf_get_id(struct dp_tx_ring *tx_ring, return id; } -static struct sk_buff *ath11k_dp_tx_buf_put_id(struct dp_tx_ring *tx_ring, - u32 id) +static void ath11k_dp_tx_tso_unmap(struct device *dev, + struct ath11k_dp_tx_ext_map *map) +{ + while (map->num--) + dma_unmap_page(dev, map->dma[map->num], map->len[map->num], + DMA_TO_DEVICE); + map->num = 0; +} + +/* + * Releases the buffer of an id. A TSO segment shares its batch with the other + * segments of it: this returns the batch with the completion of its last + * segment only, and NULL with *@more set before that. @seg, if given, gets + * the segment and its batch either way, for the status of the segment. + */ +struct sk_buff *ath11k_dp_tx_buf_put_id(struct ath11k_base *ab, + struct dp_tx_ring *tx_ring, u32 id, + bool *more, + struct ath11k_dp_tx_seg *seg) { struct sk_buff *skb; + u16 slot; + + *more = false; + if (seg) { + seg->skb = NULL; + seg->len = 0; + } if (unlikely(id >= DP_TX_IDR_SIZE - 1)) return NULL; @@ -142,25 +228,45 @@ static struct sk_buff *ath11k_dp_tx_buf_put_id(struct dp_tx_ring *tx_ring, tx_ring->bufs[id] = NULL; tx_ring->free_ids[tx_ring->num_free++] = id; + if (seg) + seg->skb = skb; + + slot = tx_ring->ext_slot[id]; + if (unlikely(slot != ATH11K_DP_TX_NO_EXT)) { + if (seg) + seg->len = tx_ring->ext_map[slot].seg_len; + ath11k_dp_tx_tso_unmap(ab->dev, &tx_ring->ext_map[slot]); + tx_ring->ext_free[tx_ring->ext_num_free++] = slot; + tx_ring->ext_slot[id] = ATH11K_DP_TX_NO_EXT; + + if (!skb_unref(skb)) { + *more = true; + return NULL; + } + } + return skb; } /** * ath11k_dp_tx_idr_has_room() - tell whether ath11k_dp_tx() can take a frame * @tx_ring: the ring the frame would go to first + * @n: the MSDU ids the frame may need, one per segment * - * ath11k_dp_tx() takes the frame's MSDU id from the ring's free ids, of which - * there are DP_TX_IDR_SIZE - 1, and the frame's completion returns it. A caller - * that takes a frame from mac80211 only to have it refused for want of an id - * loses the frame, so it checks first. The count is read without tx_idr_lock: - * an id taken in between costs that one frame, as before the check. + * ath11k_dp_tx() takes the MSDU id of each segment from the ring's free ids, + * of which there are DP_TX_IDR_SIZE - 1, and the segment's completion returns + * it; a TCP batch the TCL cannot take whole is segmented in software and still + * takes an id per segment. A caller that takes a frame from mac80211 only to + * have it refused for want of an id loses the frame, so it checks first. The + * count is read without tx_idr_lock: an id taken in between costs that one + * frame, as before the check. * - * Return: true if an id is free. + * Return: true if @n ids are free. */ -bool ath11k_dp_tx_idr_has_room(struct dp_tx_ring *tx_ring) +bool ath11k_dp_tx_idr_has_room(struct dp_tx_ring *tx_ring, int n) { /* Read without tx_idr_lock: a stale count costs at most one frame. */ - return data_race(tx_ring->num_free) != 0; + return data_race(tx_ring->num_free) >= n; } /* @@ -187,6 +293,7 @@ int ath11k_dp_tx(struct ath11k *ar, struct ath11k_vif *arvif, u32 ring_selector = 0; u8 ring_map = 0; bool tcl_ring_retry; + bool more; if (unlikely(test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags))) return -ESHUTDOWN; @@ -372,8 +479,9 @@ int ath11k_dp_tx(struct ath11k *ar, struct ath11k_vif *arvif, fail_remove_idr: spin_lock_bh(&tx_ring->tx_idr_lock); - ath11k_dp_tx_buf_put_id(tx_ring, - FIELD_GET(DP_TX_DESC_ID_MSDU_ID, ti.desc_id)); + ath11k_dp_tx_buf_put_id(ab, tx_ring, + FIELD_GET(DP_TX_DESC_ID_MSDU_ID, ti.desc_id), + &more, NULL); spin_unlock_bh(&tx_ring->tx_idr_lock); if (tcl_ring_retry) @@ -382,20 +490,524 @@ int ath11k_dp_tx(struct ath11k *ar, struct ath11k_vif *arvif, return ret; } +/* + * Maps the payload of one segment, @len bytes from *@piece at *@off, where + * piece 0 is the linear part past the headers and piece n is fragment n - 1. + */ +static int ath11k_dp_tx_tso_map(struct device *dev, struct sk_buff *skb, + struct ath11k_dp_tx_ext_map *map, + struct hal_tx_msdu_ext *ext, + unsigned int *piece, unsigned int *off, + unsigned int len) +{ + struct skb_shared_info *shinfo = skb_shinfo(skb); + unsigned int avail, take; + dma_addr_t dma; + + map->num = 0; + while (len) { + if (!*piece) + avail = skb_headlen(skb) - *off; + else + avail = skb_frag_size(&shinfo->frags[*piece - 1]) - *off; + if (!avail) { + if (*piece == shinfo->nr_frags) + return -EINVAL; + (*piece)++; + *off = 0; + continue; + } + if (map->num == HAL_TX_MSDU_EXT_NUM_BUFS - 1) + return -E2BIG; + + take = min(avail, len); + /* mapped as pages, as ath11k_dp_tx_tso_unmap() unmaps them */ + if (!*piece) + dma = dma_map_page(dev, virt_to_page(skb->data + *off), + offset_in_page(skb->data + *off), + take, DMA_TO_DEVICE); + else + dma = skb_frag_dma_map(dev, &shinfo->frags[*piece - 1], + *off, take, DMA_TO_DEVICE); + if (dma_mapping_error(dev, dma)) + return -ENOMEM; + + map->dma[map->num] = dma; + map->len[map->num] = take; + map->num++; + ext->buf[map->num].addr_lo = lower_32_bits(dma); + ext->buf[map->num].info = + FIELD_PREP(HAL_TX_MSDU_EXT_BUF_INFO_ADDR_HI, + upper_32_bits(dma)) | + FIELD_PREP(HAL_TX_MSDU_EXT_BUF_INFO_LEN, take); + *off += take; + len -= take; + } + + return 0; +} + +/* + * The frames that stay in one linear buffer: the ones the firmware and the + * stack single out by their header, which are short and rare anyway. + */ +static bool ath11k_dp_tx_ctl_frame(struct sk_buff *skb) +{ + struct ethhdr *eth = (struct ethhdr *)skb->data; + struct udphdr _udp, *udp; + struct ipv6hdr _ip6, *ip6; + struct iphdr _ip, *ip; + __be16 sport, dport; + + switch (ntohs(eth->h_proto)) { + case ETH_P_ARP: + case ETH_P_PAE: + return true; + case ETH_P_IP: + ip = skb_header_pointer(skb, ETH_HLEN, sizeof(_ip), &_ip); + if (!ip || ip->protocol != IPPROTO_UDP || ip->ihl < 5) + return false; + udp = skb_header_pointer(skb, ETH_HLEN + ip->ihl * 4, + sizeof(_udp), &_udp); + break; + case ETH_P_IPV6: + ip6 = skb_header_pointer(skb, ETH_HLEN, sizeof(_ip6), &_ip6); + if (!ip6 || ip6->nexthdr != IPPROTO_UDP) + return false; + udp = skb_header_pointer(skb, ETH_HLEN + sizeof(_ip6), + sizeof(_udp), &_udp); + break; + default: + return false; + } + + if (!udp) + return false; + + /* DHCP and DHCPv6 */ + sport = udp->source; + dport = udp->dest; + return (sport == htons(67) || sport == htons(68) || + dport == htons(67) || dport == htons(68) || + sport == htons(546) || sport == htons(547) || + dport == htons(546) || dport == htons(547)); +} + +/* + * Moves the first @len bytes of the frame, its headers, @pad bytes down into + * the head room, with the offsets of the headers, so that they end @pad bytes + * earlier; the rest of the frame stays where it is, and the frame is @pad + * bytes longer. The caller makes sure of the head room and of a head that is + * not shared. Undone by ath11k_dp_tx_ext_unpad(). + */ +static void ath11k_dp_tx_ext_pad(struct sk_buff *skb, unsigned int len, + unsigned int pad) +{ + skb_push(skb, pad); + memmove(skb->data, skb->data + pad, len); + if (skb_mac_header_was_set(skb)) + skb->mac_header -= pad; + skb->network_header -= pad; + if (skb_transport_header_was_set(skb)) + skb->transport_header -= pad; +} + +static void ath11k_dp_tx_ext_unpad(struct sk_buff *skb, unsigned int len, + unsigned int pad) +{ + memmove(skb->data + pad, skb->data, len); + skb_pull(skb, pad); + if (skb_mac_header_was_set(skb)) + skb->mac_header += pad; + skb->network_header += pad; + if (skb_transport_header_was_set(skb)) + skb->transport_header += pad; +} + +/* + * A TCP batch, or a frame with fragments, that the TCL takes from MSDU + * extension descriptors. Each descriptor lists the buffers of one frame: the + * linear part of the skb, which for a batch holds the headers shared by all + * its segments, and the payload in the fragments. A TCP batch has one + * descriptor for each of its segments, which also gives the segment's IP + * length, IP ID, TCP sequence number and flags for the TCL to write into the + * headers; every segment holds a reference on the batch, and the completion + * of the last one reports the batch to mac80211. A frame with fragments has + * one descriptor, and is a batch of one segment. + * + * Returns -EAGAIN, with the frame untouched, for one the TCL cannot take + * whole. The ids, extension descriptors and ring entries of all segments are + * taken before the first is queued. + */ +static int ath11k_dp_tx_ext(struct ath11k *ar, struct ath11k_vif *arvif, + struct sk_buff *skb, int held_ring) +{ + struct skb_shared_info *shinfo = skb_shinfo(skb); + struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb); + struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(skb); + bool tso = skb_is_gso(skb); + unsigned int n = tso ? shinfo->gso_segs : 1, mss = shinfo->gso_size; + unsigned int hdr_len, l2_len = 0, ip_off = 0, left, piece = 0, off; + struct ath11k_base *ab = ar->ab; + struct hal_tx_info ti = {}; + struct dp_tx_ring *tx_ring; + struct hal_srng *tcl_ring; + u16 ids[ATH11K_DP_TX_TSO_MAX_SEGS], slots[ATH11K_DP_TX_TSO_MAX_SEGS]; + u32 seq = 0, flags = 0, ip_id = 0; + dma_addr_t hdr_dma; + struct tcphdr *th; + unsigned int pad; + int i, j; + + /* a crashed firmware takes no frames; the caller drops this one */ + if (unlikely(test_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags))) + return -EAGAIN; + + if (!ab->hw_params.tx_tso || + !(info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP) || + ath11k_dp_tx_get_encap_type(arvif, skb) != HAL_TCL_ENCAP_TYPE_ETHERNET || + skb_has_frag_list(skb) || refcount_read(&skb->users) != 1 || + n > ATH11K_DP_TX_TSO_MAX_SEGS) + return -EAGAIN; + + if (tso) { + if (!(shinfo->gso_type & (SKB_GSO_TCPV4 | SKB_GSO_TCPV6)) || + shinfo->gso_type & SKB_GSO_FRAGLIST || + skb->ip_summed != CHECKSUM_PARTIAL) + return -EAGAIN; + + hdr_len = skb_tcp_all_headers(skb); + l2_len = skb_network_offset(skb); + /* + * The IP length counts the IPv4 header, but not the IPv6 one. + * An IPv6 batch with extension headers goes to software: the + * descriptor gives the TCL no length of the headers between + * the IPv6 header and TCP. + */ + ip_off = l2_len; + if (shinfo->gso_type & SKB_GSO_TCPV6) { + ip_off = l2_len + sizeof(struct ipv6hdr); + if (skb_transport_offset(skb) != ip_off) + return -EAGAIN; + } + if (hdr_len > skb_headlen(skb) || l2_len > hdr_len) + return -EAGAIN; + } else { + /* the linear part is the first buffer, then the fragments */ + hdr_len = skb_headlen(skb); + if (!shinfo->nr_frags || + shinfo->nr_frags > HAL_TX_MSDU_EXT_NUM_BUFS - 1 || + hdr_len < ETH_HLEN || ath11k_dp_tx_ctl_frame(skb)) + return -EAGAIN; + } + + /* + * The buffer of the headers ends on an 8 byte boundary: if it does + * not, the headers move down into the head room, which has to be + * there and not be shared. + */ + pad = ((unsigned long)skb->data + hdr_len) & (ATH11K_DP_TX_EXT_ALIGN - 1); + if (pad) { + if (skb_cow_head(skb, ATH11K_DP_TX_EXT_ALIGN)) + return -EAGAIN; + shinfo = skb_shinfo(skb); + pad = ((unsigned long)skb->data + hdr_len) & + (ATH11K_DP_TX_EXT_ALIGN - 1); + } + + if (held_ring >= 0) + ti.ring_id = held_ring; + else + ti.ring_id = ab->hw_params.hw_ops->get_ring_selector(skb_get_queue_mapping(skb)) % + ab->hw_params.hal_params->num_tx_rings; + tx_ring = &ab->dp.tx_ring[ti.ring_id]; + tcl_ring = &ab->hal.srng_list[tx_ring->tcl_data_ring.ring_id]; + + spin_lock_bh(&tx_ring->tx_idr_lock); + if (tx_ring->num_free < n || tx_ring->ext_num_free < n) { + spin_unlock_bh(&tx_ring->tx_idr_lock); + return -EAGAIN; + } + for (i = 0; i < n; i++) { + slots[i] = tx_ring->ext_free[--tx_ring->ext_num_free]; + ids[i] = ath11k_dp_tx_buf_get_id(tx_ring, skb); + tx_ring->ext_slot[ids[i]] = slots[i]; + tx_ring->ext_map[slots[i]].num = 0; + } + spin_unlock_bh(&tx_ring->tx_idr_lock); + + if (pad) + ath11k_dp_tx_ext_pad(skb, hdr_len, pad); + + hdr_dma = dma_map_single(ab->dev, skb->data, skb_headlen(skb), + DMA_TO_DEVICE); + if (dma_mapping_error(ab->dev, hdr_dma)) { + i = 0; + goto fail_put; + } + + if (tso) { + th = tcp_hdr(skb); + seq = ntohl(th->seq); + flags = (ntohl(tcp_flag_word(th)) >> 16) & 0x1ff; + if (shinfo->gso_type & SKB_GSO_TCPV4) + ip_id = ntohs(ip_hdr(skb)->id); + } + + /* the payload in the linear part starts after the gap the headers left */ + off = hdr_len + pad; + left = skb->len - off; + for (i = 0; i < n; i++) { + struct hal_tx_msdu_ext *ext = (void *)tx_ring->ext + + ath11k_dp_tx_ext_off(slots[i]); + struct ath11k_dp_tx_ext_map *map = &tx_ring->ext_map[slots[i]]; + unsigned int len = tso ? min(left, mss) : left; + u32 seg_flags = flags; + + if (i) + seg_flags &= ~TCPHDR_CWR; + if (i < n - 1) + seg_flags &= ~(TCPHDR_FIN | TCPHDR_PSH); + + memset(ext, 0, sizeof(*ext)); + if (ath11k_dp_tx_tso_map(ab->dev, skb, map, ext, &piece, &off, + len)) { + ath11k_dp_tx_tso_unmap(ab->dev, map); + goto fail_unmap; + } + + map->seg_len = hdr_len + len; + + if (tso) { + ext->info0 = FIELD_PREP(HAL_TX_MSDU_EXT_INFO0_TSO_ENABLE, 1) | + FIELD_PREP(HAL_TX_MSDU_EXT_INFO0_TCP_FLAG, + seg_flags) | + FIELD_PREP(HAL_TX_MSDU_EXT_INFO0_TCP_FLAG_MASK, + 0x1ff); + ext->info1 = FIELD_PREP(HAL_TX_MSDU_EXT_INFO1_L2_LEN, + l2_len) | + FIELD_PREP(HAL_TX_MSDU_EXT_INFO1_IP_LEN, + hdr_len - ip_off + len); + ext->tcp_seq = seq; + ext->info3 = FIELD_PREP(HAL_TX_MSDU_EXT_INFO3_IP_ID, + ip_id); + } + ext->buf[0].addr_lo = lower_32_bits(hdr_dma); + ext->buf[0].info = + FIELD_PREP(HAL_TX_MSDU_EXT_BUF_INFO_ADDR_HI, + upper_32_bits(hdr_dma)) | + FIELD_PREP(HAL_TX_MSDU_EXT_BUF_INFO_LEN, hdr_len); + + seq += len; + left -= len; + if (!(shinfo->gso_type & SKB_GSO_TCP_FIXEDID)) + ip_id = (ip_id + 1) & 0xffff; + } + + if (held_ring < 0) { + spin_lock_bh(&tcl_ring->lock); + ath11k_hal_srng_access_begin(ab, tcl_ring); + } + if (ath11k_hal_srng_src_num_free(ab, tcl_ring, held_ring < 0) < n) { + if (held_ring < 0) { + ath11k_hal_srng_access_end(ab, tcl_ring); + spin_unlock_bh(&tcl_ring->lock); + } + ab->soc_stats.tx_err.desc_na[ti.ring_id]++; + goto fail_unmap; + } + + skb_cb->paddr = hdr_dma; + skb_cb->vif = arvif->vif; + skb_cb->ar = ar; + skb_cb->tso_try = 0; + skb_cb->tso_bad = 0; + refcount_add(n - 1, &skb->users); + + ti.encap_type = HAL_TCL_ENCAP_TYPE_ETHERNET; + ti.meta_data_flags = arvif->tcl_metadata; + ti.addr_search_flags = arvif->hal_addr_search_flags; + ti.search_type = arvif->search_type; + ti.type = HAL_TCL_DESC_TYPE_EXT_DESC; + ti.lmac_id = ar->lmac_id; + ti.bss_ast_hash = arvif->ast_hash; + ti.bss_ast_idx = arvif->ast_idx; + ti.rbm_id = ab->hw_params.hal_params->tcl2wbm_rbm_map[ti.ring_id].rbm_id; + ti.tid = ath11k_dp_tx_get_tid(skb); + /* the IP, UDP and TCP checksum enables together, also for a batch */ + if (skb->ip_summed == CHECKSUM_PARTIAL) + ti.flags0 = FIELD_PREP(HAL_TCL_DATA_CMD_INFO1_IP4_CKSUM_EN, 1) | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO1_UDP4_CKSUM_EN, 1) | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO1_UDP6_CKSUM_EN, 1) | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO1_TCP4_CKSUM_EN, 1) | + FIELD_PREP(HAL_TCL_DATA_CMD_INFO1_TCP6_CKSUM_EN, 1); + if (ieee80211_vif_is_mesh(arvif->vif)) + ti.enable_mesh = true; + ti.flags1 = FIELD_PREP(HAL_TCL_DATA_CMD_INFO2_TID_OVERWRITE, 1); + /* the TCL reads this much of the extension descriptor */ + ti.data_len = sizeof(*tx_ring->ext); + + for (i = 0; i < n; i++) { + void *desc; + + ti.desc_id = FIELD_PREP(DP_TX_DESC_ID_MAC_ID, ar->pdev_idx) | + FIELD_PREP(DP_TX_DESC_ID_MSDU_ID, ids[i]) | + FIELD_PREP(DP_TX_DESC_ID_POOL_ID, + skb_get_queue_mapping(skb) & + (ATH11K_HW_MAX_QUEUES - 1)); + ti.paddr = tx_ring->ext_paddr + ath11k_dp_tx_ext_off(slots[i]); + /* the command follows the TLV header of the ring entry */ + desc = ath11k_hal_srng_src_get_next_entry(ab, tcl_ring); + ath11k_hal_tx_cmd_desc_setup(ab, desc + sizeof(struct hal_tlv_hdr), + &ti); + } + + if (held_ring < 0) { + /* as the TXQ push: no ring update once the firmware crashed */ + if (likely(!test_bit(ATH11K_FLAG_CRASH_FLUSH, &ab->dev_flags))) { + ath11k_hal_srng_access_end(ab, tcl_ring); + ath11k_dp_shadow_start_timer(ab, tcl_ring, + &ab->dp.tx_ring_timer[ti.ring_id]); + } + spin_unlock_bh(&tcl_ring->lock); + } + + atomic_add(n, &ar->dp.num_tx_pending); + if (tso) { + atomic_inc(&ab->soc_stats.tx_tso_batch); + atomic_add(n, &ab->soc_stats.tx_tso_seg); + } else { + atomic_inc(&ab->soc_stats.tx_sg); + } + + return 0; + +fail_unmap: + for (j = 0; j < i; j++) + ath11k_dp_tx_tso_unmap(ab->dev, &tx_ring->ext_map[slots[j]]); + dma_unmap_single(ab->dev, hdr_dma, skb_headlen(skb), DMA_TO_DEVICE); +fail_put: + if (pad) + ath11k_dp_tx_ext_unpad(skb, hdr_len, pad); + spin_lock_bh(&tx_ring->tx_idr_lock); + for (j = n; j--;) { + /* no reference was taken yet: release the id and slot only */ + tx_ring->bufs[ids[j]] = NULL; + tx_ring->free_ids[tx_ring->num_free++] = ids[j]; + tx_ring->ext_slot[ids[j]] = ATH11K_DP_TX_NO_EXT; + tx_ring->ext_free[tx_ring->ext_num_free++] = slots[j]; + } + spin_unlock_bh(&tx_ring->tx_idr_lock); + + return -EAGAIN; +} + +/* + * A frame with fragments, sent as scatter-gather. Returns -EAGAIN, with the + * frame untouched, for one that has to be made linear instead. + */ +int ath11k_dp_tx_sg(struct ath11k *ar, struct ath11k_vif *arvif, + struct sk_buff *skb, int held_ring) +{ + return ath11k_dp_tx_ext(ar, arvif, skb, held_ring); +} + +/* + * A GSO frame from mac80211 is a batch of frames. The TCL takes a TCP batch + * whole; any other, and a batch the TCL cannot take, is split into frames + * here. The frames share the one status mac80211 expects, and the one airtime + * charge of the batch: the last frame reports the status with the charge, + * and the others carry none. + */ +int ath11k_dp_tx_gso(struct ath11k *ar, struct ath11k_vif *arvif, + struct ath11k_sta *arsta, struct sk_buff *skb, + int held_ring) +{ + struct sk_buff *segs, *seg, *next; + struct ieee80211_tx_info *info; + int ret = 0; + + if (!ath11k_dp_tx_ext(ar, arvif, skb, held_ring)) + return 0; + + atomic_inc(&ar->ab->soc_stats.tx_tso_sw); + + segs = skb_gso_segment(skb, NETIF_F_HW_CSUM); + if (IS_ERR_OR_NULL(segs)) { + ieee80211_free_txskb(ar->hw, skb); + return segs ? PTR_ERR(segs) : -ENOMEM; + } + + /* the frames copy the control buffer, and so the charge */ + consume_skb(skb); + + skb_list_walk_safe(segs, seg, next) { + skb_mark_not_on_list(seg); + if (next) { + info = IEEE80211_SKB_CB(seg); + info->tx_time_est = 0; + } + if (ret) { + ieee80211_free_txskb(ar->hw, seg); + continue; + } + ret = ath11k_dp_tx(ar, arvif, arsta, seg, held_ring); + if (ret) + ieee80211_free_txskb(ar->hw, seg); + } + + return ret; +} + +/* + * Whether a segment went out as the frame asked: acked, or sent when it asked + * for no ack. + */ +static bool ath11k_dp_tx_seg_ok(struct sk_buff *skb, enum hal_wbm_tqm_rel_reason status) +{ + if (IEEE80211_SKB_CB(skb)->flags & IEEE80211_TX_CTL_NO_ACK) + return status == HAL_WBM_TQM_REL_REASON_CMD_REMOVE_TX; + + return status == HAL_WBM_TQM_REL_REASON_FRAME_ACKED; +} + +/* + * Notes the status of a segment that is not the last of its batch: the batch + * is acked only if every segment is, and its tries are the most of any segment. + */ +static void ath11k_dp_tx_seg_note(struct sk_buff *batch, bool ok, u8 try_cnt) +{ + struct ath11k_skb_cb *skb_cb = ATH11K_SKB_CB(batch); + + if (!ok && skb_cb->tso_bad < U8_MAX) + skb_cb->tso_bad++; + if (try_cnt > skb_cb->tso_try) + skb_cb->tso_try = try_cnt; +} + static void ath11k_dp_tx_free_txbuf(struct ath11k_base *ab, u8 mac_id, int msdu_id, struct dp_tx_ring *tx_ring, unsigned long *push) { - struct ath11k *ar; + struct ath11k *ar = ab->pdevs[mac_id].ar; struct sk_buff *msdu; + struct ath11k_dp_tx_seg seg; struct ath11k_skb_cb *skb_cb; + bool more; spin_lock(&tx_ring->tx_idr_lock); - msdu = ath11k_dp_tx_buf_put_id(tx_ring, msdu_id); + msdu = ath11k_dp_tx_buf_put_id(ab, tx_ring, msdu_id, &more, &seg); spin_unlock(&tx_ring->tx_idr_lock); if (unlikely(!msdu)) { + if (more) { + /* the segment was not sent, and so is not acked */ + ath11k_dp_tx_seg_note(seg.skb, false, 0); + if (atomic_dec_and_test(&ar->dp.num_tx_pending)) + wake_up(&ar->dp.tx_empty_waitq); + return; + } ath11k_warn(ab, "tx completion for unknown msdu_id %d\n", msdu_id); return; @@ -403,9 +1015,9 @@ static void ath11k_dp_tx_free_txbuf(struct ath11k_base *ab, u8 mac_id, skb_cb = ATH11K_SKB_CB(msdu); - dma_unmap_single(ab->dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE); + dma_unmap_single(ab->dev, skb_cb->paddr, skb_headlen(msdu), + DMA_TO_DEVICE); - ar = ab->pdevs[mac_id].ar; __set_bit(mac_id * IEEE80211_NUM_ACS + skb_get_queue_mapping(msdu), push); ieee80211_free_txskb(ar->hw, msdu); @@ -428,6 +1040,7 @@ void ath11k_dp_tx_free_pending(struct ath11k_base *ab) struct dp_tx_ring *tx_ring; struct sk_buff *msdu; int i, msdu_id; + bool more; __skb_queue_head_init(&pending); @@ -437,7 +1050,8 @@ void ath11k_dp_tx_free_pending(struct ath11k_base *ab) spin_lock_bh(&tx_ring->tx_idr_lock); for (msdu_id = 0; tx_ring->bufs && msdu_id < DP_TX_IDR_SIZE - 1; msdu_id++) { - msdu = ath11k_dp_tx_buf_put_id(tx_ring, msdu_id); + msdu = ath11k_dp_tx_buf_put_id(ab, tx_ring, msdu_id, + &more, NULL); if (msdu) __skb_queue_tail(&pending, msdu); } @@ -446,14 +1060,14 @@ void ath11k_dp_tx_free_pending(struct ath11k_base *ab) while ((msdu = __skb_dequeue(&pending))) { skb_cb = ATH11K_SKB_CB(msdu); - dma_unmap_single(ab->dev, skb_cb->paddr, msdu->len, + dma_unmap_single(ab->dev, skb_cb->paddr, skb_headlen(msdu), DMA_TO_DEVICE); ieee80211_free_txskb(skb_cb->ar->hw, msdu); } } static void -ath11k_dp_tx_htt_tx_complete_buf(struct ath11k_base *ab, +ath11k_dp_tx_htt_tx_complete_buf(struct ath11k_base *ab, u8 mac_id, struct dp_tx_ring *tx_ring, struct ath11k_dp_htt_wbm_tx_status *ts, unsigned long *push) @@ -461,15 +1075,25 @@ ath11k_dp_tx_htt_tx_complete_buf(struct ath11k_base *ab, struct ieee80211_tx_status status = {}; struct sk_buff *msdu; struct ieee80211_tx_info *info; + struct ath11k_dp_tx_seg seg; struct ath11k_skb_cb *skb_cb; struct ath11k *ar; struct ath11k_peer *peer; + bool more; + bool batch_ok; spin_lock(&tx_ring->tx_idr_lock); - msdu = ath11k_dp_tx_buf_put_id(tx_ring, ts->msdu_id); + msdu = ath11k_dp_tx_buf_put_id(ab, tx_ring, ts->msdu_id, &more, &seg); spin_unlock(&tx_ring->tx_idr_lock); if (unlikely(!msdu)) { + if (more) { + ath11k_dp_tx_seg_note(seg.skb, ts->acked, 0); + ar = ab->pdevs[mac_id].ar; + if (atomic_dec_and_test(&ar->dp.num_tx_pending)) + wake_up(&ar->dp.tx_empty_waitq); + return; + } ath11k_warn(ab, "htt tx completion for unknown msdu_id %d\n", ts->msdu_id); return; @@ -485,16 +1109,20 @@ ath11k_dp_tx_htt_tx_complete_buf(struct ath11k_base *ab, 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); + dma_unmap_single(ab->dev, skb_cb->paddr, skb_headlen(msdu), + DMA_TO_DEVICE); if (!skb_cb->vif) { ieee80211_free_txskb(ar->hw, msdu); return; } + /* the notes of the other segments of a batch share the status */ + batch_ok = !seg.len || !skb_cb->tso_bad; + memset(&info->status, 0, sizeof(info->status)); - if (ts->acked) { + if (ts->acked && batch_ok) { if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) { info->flags |= IEEE80211_TX_STAT_ACK; info->status.ack_signal = ts->ack_rssi; @@ -558,7 +1186,8 @@ ath11k_dp_tx_process_htt_tx_complete(struct ath11k_base *ab, else ts.peer_id = HTT_INVALID_PEER_ID; - ath11k_dp_tx_htt_tx_complete_buf(ab, tx_ring, &ts, push); + ath11k_dp_tx_htt_tx_complete_buf(ab, mac_id, tx_ring, &ts, + push); break; case HAL_WBM_REL_HTT_TX_COMP_STATUS_REINJ: @@ -576,19 +1205,18 @@ ath11k_dp_tx_process_htt_tx_complete(struct ath11k_base *ab, } } -static void ath11k_dp_tx_cache_peer_stats(struct ath11k *ar, - struct sk_buff *msdu, +static void ath11k_dp_tx_cache_peer_stats(struct ath11k *ar, u32 len, struct hal_tx_status *ts) { struct ath11k_per_peer_tx_stats *peer_stats = &ar->cached_stats; if (ts->try_cnt > 1) { peer_stats->retry_pkts += ts->try_cnt - 1; - peer_stats->retry_bytes += (ts->try_cnt - 1) * msdu->len; + peer_stats->retry_bytes += (ts->try_cnt - 1) * len; if (ts->status != HAL_WBM_TQM_REL_REASON_FRAME_ACKED) { peer_stats->failed_pkts += 1; - peer_stats->failed_bytes += msdu->len; + peer_stats->failed_bytes += len; } } } @@ -709,10 +1337,62 @@ struct ath11k_dp_tx_compl { u16 peer_id; }; +/* + * The statistics of the stations that the completion of every frame feeds, + * @len bytes long: the frame, or the segment of a batch. + */ +static void ath11k_dp_tx_account(struct ath11k *ar, u32 len, + struct hal_tx_status *ts) +{ + if (likely(!ath11k_debugfs_is_extd_tx_stats_enabled(ar) && + !ar->ab->hw_params.single_pdev_only)) + return; + + if (ts->flags & HAL_TX_STATUS_FLAGS_FIRST_MSDU) { + if (ar->last_ppdu_id == 0) { + ar->last_ppdu_id = ts->ppdu_id; + } else if (ar->last_ppdu_id == ts->ppdu_id || + ar->cached_ppdu_id == ar->last_ppdu_id) { + ar->cached_ppdu_id = ar->last_ppdu_id; + ar->cached_stats.is_ampdu = true; + ath11k_dp_tx_update_txcompl(ar, ts); + memset(&ar->cached_stats, 0, + sizeof(struct ath11k_per_peer_tx_stats)); + } else { + ar->cached_stats.is_ampdu = false; + ath11k_dp_tx_update_txcompl(ar, ts); + memset(&ar->cached_stats, 0, + sizeof(struct ath11k_per_peer_tx_stats)); + } + ar->last_ppdu_id = ts->ppdu_id; + } + + ath11k_dp_tx_cache_peer_stats(ar, len, ts); +} + +/* + * The completion of a segment that is not the last of its batch. Its + * statistics count as those of a frame, and its status goes into the status + * of the batch, which the completion of the last segment reports. + */ +static void ath11k_dp_tx_complete_seg(struct ath11k *ar, struct sk_buff *batch, + struct hal_tx_status *ts, u16 seg_len) +{ + if (WARN_ON_ONCE(ts->buf_rel_source != HAL_WBM_REL_SRC_MODULE_TQM)) + return; + + ath11k_dp_tx_seg_note(batch, ath11k_dp_tx_seg_ok(batch, ts->status), + ts->try_cnt); + + if (likely(rcu_access_pointer(ar->ab->pdevs_active[ar->pdev_idx]))) + ath11k_dp_tx_account(ar, seg_len, ts); +} + static void ath11k_dp_tx_complete_msdu(struct ath11k *ar, struct sk_buff *msdu, struct hal_tx_status *ts, - struct ath11k_dp_tx_compl *c) + struct ath11k_dp_tx_compl *c, + u16 seg_len) { struct ieee80211_tx_status status = {}; struct ieee80211_rate_status status_rate = {}; @@ -720,6 +1400,8 @@ static void ath11k_dp_tx_complete_msdu(struct ath11k *ar, struct ieee80211_tx_info *info; struct ath11k_skb_cb *skb_cb; struct ath11k_peer *peer; + bool ok; + u8 try_cnt; if (WARN_ON_ONCE(ts->buf_rel_source != HAL_WBM_REL_SRC_MODULE_TQM)) { /* Must not happen */ @@ -728,7 +1410,8 @@ static void ath11k_dp_tx_complete_msdu(struct ath11k *ar, skb_cb = ATH11K_SKB_CB(msdu); - dma_unmap_single(ab->dev, skb_cb->paddr, msdu->len, DMA_TO_DEVICE); + dma_unmap_single(ab->dev, skb_cb->paddr, skb_headlen(msdu), + DMA_TO_DEVICE); if (unlikely(!rcu_access_pointer(ab->pdevs_active[ar->pdev_idx]))) { ieee80211_free_txskb(ar->hw, msdu); @@ -741,13 +1424,27 @@ static void ath11k_dp_tx_complete_msdu(struct ath11k *ar, } info = IEEE80211_SKB_CB(msdu); + + /* + * A batch is acked only if all its segments are, and takes the most + * tries of any: mac80211 reads the tries as those of one frame at one + * rate, which a sum over the segments would overstate by their number. + * The notes of the other segments are in the driver's part of the + * buffer that the status overwrites. + */ + ok = ath11k_dp_tx_seg_ok(msdu, ts->status); + try_cnt = ts->try_cnt; + if (seg_len) { + ok = ok && !skb_cb->tso_bad; + try_cnt = max(try_cnt, skb_cb->tso_try); + } + memset(&info->status, 0, sizeof(info->status)); /* skip tx rate update from ieee80211_status*/ info->status.rates[0].idx = -1; - if (ts->status == HAL_WBM_TQM_REL_REASON_FRAME_ACKED && - !(info->flags & IEEE80211_TX_CTL_NO_ACK)) { + if (ok && !(info->flags & IEEE80211_TX_CTL_NO_ACK)) { info->flags |= IEEE80211_TX_STAT_ACK; info->status.ack_signal = ts->ack_rssi; @@ -758,33 +1455,10 @@ static void ath11k_dp_tx_complete_msdu(struct ath11k *ar, info->status.flags |= IEEE80211_TX_STATUS_ACK_SIGNAL_VALID; } - if (ts->status == HAL_WBM_TQM_REL_REASON_CMD_REMOVE_TX && - (info->flags & IEEE80211_TX_CTL_NO_ACK)) + if (ok && (info->flags & IEEE80211_TX_CTL_NO_ACK)) info->flags |= IEEE80211_TX_STAT_NOACK_TRANSMITTED; - if (unlikely(ath11k_debugfs_is_extd_tx_stats_enabled(ar)) || - ab->hw_params.single_pdev_only) { - if (ts->flags & HAL_TX_STATUS_FLAGS_FIRST_MSDU) { - if (ar->last_ppdu_id == 0) { - ar->last_ppdu_id = ts->ppdu_id; - } else if (ar->last_ppdu_id == ts->ppdu_id || - ar->cached_ppdu_id == ar->last_ppdu_id) { - ar->cached_ppdu_id = ar->last_ppdu_id; - ar->cached_stats.is_ampdu = true; - ath11k_dp_tx_update_txcompl(ar, ts); - memset(&ar->cached_stats, 0, - sizeof(struct ath11k_per_peer_tx_stats)); - } else { - ar->cached_stats.is_ampdu = false; - ath11k_dp_tx_update_txcompl(ar, ts); - memset(&ar->cached_stats, 0, - sizeof(struct ath11k_per_peer_tx_stats)); - } - ar->last_ppdu_id = ts->ppdu_id; - } - - ath11k_dp_tx_cache_peer_stats(ar, msdu, ts); - } + ath11k_dp_tx_account(ar, seg_len ?: msdu->len, ts); if (!c->sta || c->peer_id != ts->peer_id) { spin_lock_bh(&ab->base_lock); @@ -809,7 +1483,7 @@ static void ath11k_dp_tx_complete_msdu(struct ath11k *ar, status.free_list = &c->free; status_rate.rate_idx = c->rate; - status_rate.try_count = 1; + status_rate.try_count = max_t(u8, try_cnt, 1); status.rates = &status_rate; status.n_rates = 1; @@ -859,12 +1533,14 @@ int ath11k_dp_tx_completion_handler(struct ath11k_base *ab, int ring_id, struct hal_tx_status ts = {}; struct dp_tx_ring *tx_ring = &dp->tx_ring[ring_id]; struct ath11k_dp_tx_compl c = { .free = LIST_HEAD_INIT(c.free) }; + struct ath11k_dp_tx_seg seg; struct sk_buff *tmp; unsigned long push = 0; int done = 0; u32 *desc; u32 msdu_id; u8 mac_id, i; + bool more; spin_lock_bh(&status_ring->lock); @@ -916,24 +1592,32 @@ int ath11k_dp_tx_completion_handler(struct ath11k_base *ab, int ring_id, } spin_lock(&tx_ring->tx_idr_lock); - msdu = ath11k_dp_tx_buf_put_id(tx_ring, msdu_id); + msdu = ath11k_dp_tx_buf_put_id(ab, tx_ring, msdu_id, &more, + &seg); + spin_unlock(&tx_ring->tx_idr_lock); + + ar = ab->pdevs[mac_id].ar; + if (unlikely(!msdu)) { + /* not the last segment of a batch */ + if (more) { + ath11k_dp_tx_complete_seg(ar, seg.skb, &ts, + seg.len); + if (atomic_dec_and_test(&ar->dp.num_tx_pending)) + wake_up(&ar->dp.tx_empty_waitq); + continue; + } ath11k_warn(ab, "tx completion for unknown msdu_id %d\n", msdu_id); - spin_unlock(&tx_ring->tx_idr_lock); continue; } - - spin_unlock(&tx_ring->tx_idr_lock); - - ar = ab->pdevs[mac_id].ar; __set_bit(mac_id * IEEE80211_NUM_ACS + skb_get_queue_mapping(msdu), &push); if (atomic_dec_and_test(&ar->dp.num_tx_pending)) wake_up(&ar->dp.tx_empty_waitq); - ath11k_dp_tx_complete_msdu(ar, msdu, &ts, &c); + ath11k_dp_tx_complete_msdu(ar, msdu, &ts, &c, seg.len); } list_for_each_entry_safe(msdu, tmp, &c.free, list) { diff --git a/drivers/net/wireless/ath/ath11k/dp_tx.h b/drivers/net/wireless/ath/ath11k/dp_tx.h index 50b6178ceb38..967f212d33db 100644 --- a/drivers/net/wireless/ath/ath11k/dp_tx.h +++ b/drivers/net/wireless/ath/ath11k/dp_tx.h @@ -21,9 +21,18 @@ void ath11k_dp_tx_update_txcompl(struct ath11k *ar, struct hal_tx_status *ts); int ath11k_dp_tx_htt_h2t_ver_req_msg(struct ath11k_base *ab); int ath11k_dp_tx(struct ath11k *ar, struct ath11k_vif *arvif, struct ath11k_sta *arsta, struct sk_buff *skb, int held_ring); -bool ath11k_dp_tx_idr_has_room(struct dp_tx_ring *tx_ring); -int ath11k_dp_tx_bufs_init(struct dp_tx_ring *tx_ring); -void ath11k_dp_tx_bufs_free(struct dp_tx_ring *tx_ring); +bool ath11k_dp_tx_idr_has_room(struct dp_tx_ring *tx_ring, int n); +int ath11k_dp_tx_gso(struct ath11k *ar, struct ath11k_vif *arvif, + struct ath11k_sta *arsta, struct sk_buff *skb, + int held_ring); +int ath11k_dp_tx_sg(struct ath11k *ar, struct ath11k_vif *arvif, + struct sk_buff *skb, int held_ring); +int ath11k_dp_tx_bufs_init(struct ath11k_base *ab, struct dp_tx_ring *tx_ring); +void ath11k_dp_tx_bufs_free(struct ath11k_base *ab, struct dp_tx_ring *tx_ring); +struct sk_buff *ath11k_dp_tx_buf_put_id(struct ath11k_base *ab, + struct dp_tx_ring *tx_ring, u32 id, + bool *more, + struct ath11k_dp_tx_seg *seg); int ath11k_dp_tx_completion_handler(struct ath11k_base *ab, int ring_id, int budget); void ath11k_dp_tx_free_pending(struct ath11k_base *ab); diff --git a/drivers/net/wireless/ath/ath11k/hal_desc.h b/drivers/net/wireless/ath/ath11k/hal_desc.h index c8b01f6921c0..d10cd6735ffb 100644 --- a/drivers/net/wireless/ath/ath11k/hal_desc.h +++ b/drivers/net/wireless/ath/ath11k/hal_desc.h @@ -1023,6 +1023,52 @@ enum hal_wbm_htt_tx_comp_status { HAL_WBM_REL_HTT_TX_COMP_STATUS_MEC_NOTIFY, }; +#define HAL_TX_MSDU_EXT_INFO0_TSO_ENABLE BIT(0) +#define HAL_TX_MSDU_EXT_INFO0_TCP_FLAG GENMASK(15, 7) +#define HAL_TX_MSDU_EXT_INFO0_TCP_FLAG_MASK GENMASK(24, 16) +#define HAL_TX_MSDU_EXT_INFO1_L2_LEN GENMASK(15, 0) +#define HAL_TX_MSDU_EXT_INFO1_IP_LEN GENMASK(31, 16) +#define HAL_TX_MSDU_EXT_INFO3_IP_ID GENMASK(15, 0) +#define HAL_TX_MSDU_EXT_BUF_INFO_ADDR_HI GENMASK(7, 0) +#define HAL_TX_MSDU_EXT_BUF_INFO_LEN GENMASK(31, 16) +#define HAL_TX_MSDU_EXT_NUM_BUFS 6 + +struct hal_tx_msdu_ext_buf { + u32 addr_lo; + u32 info; +} __packed; + +struct hal_tx_msdu_ext { + u32 info0; + u32 info1; + u32 tcp_seq; + u32 info3; + u32 info4; + u32 info5; + struct hal_tx_msdu_ext_buf buf[HAL_TX_MSDU_EXT_NUM_BUFS]; +} __packed; + +/* + * hal_tx_msdu_ext + * + * A TCL data command of type HAL_TCL_DESC_TYPE_EXT_DESC points at + * this descriptor instead of at the frame. + * + * tso_enable + * The TCL writes tcp_flag under tcp_flag_mask, the IP length, + * the IP ID and the TCP sequence number into the headers in + * the first buffer, and fills in the checksums the TCL data + * command enables. + * + * l2_length, ip_length + * The length of the L2 header, and the IP length of the packet + * this descriptor makes: the IPv4 total length, or the IPv6 + * payload length. + * + * buf + * Up to six buffers that make up the frame, in order. + */ + struct hal_tcl_data_cmd { struct ath11k_buffer_addr buf_addr_info; u32 info0; diff --git a/drivers/net/wireless/ath/ath11k/hw.h b/drivers/net/wireless/ath/ath11k/hw.h index b6bc8b72d812..2cf34af05f8f 100644 --- a/drivers/net/wireless/ath/ath11k/hw.h +++ b/drivers/net/wireless/ath/ath11k/hw.h @@ -223,6 +223,7 @@ struct ath11k_hw_params { } sram_dump; bool tcl_ring_retry; + bool tx_tso; u32 tx_ring_size; bool smp2p_wow_exit; bool support_fw_mac_sequence; diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c index 513559585371..5f2086bf6c5d 100644 --- a/drivers/net/wireless/ath/ath11k/mac.c +++ b/drivers/net/wireless/ath/ath11k/mac.c @@ -6559,6 +6559,25 @@ static int ath11k_mac_tx(struct ieee80211_hw *hw, if (control->sta) arsta = ath11k_sta_to_arsta(control->sta); + /* + * A GSO frame is taken whole by the TCL, or split here. A frame with + * fragments goes to the TCL as scatter-gather, and is made linear + * only if the TCL cannot take it that way. They free the frame + * themselves when they fail. + */ + if (skb_is_gso(skb)) + return ath11k_dp_tx_gso(ar, arvif, arsta, skb, held_ring); + + if (unlikely(skb_is_nonlinear(skb))) { + if (!ath11k_dp_tx_sg(ar, arvif, skb, held_ring)) + return 0; + + if (skb_linearize(skb)) { + ieee80211_free_txskb(ar->hw, skb); + return -ENOMEM; + } + } + ret = ath11k_dp_tx(ar, arvif, arsta, skb, held_ring); if (unlikely(ret)) { ath11k_warn(ar->ab, "failed to transmit frame %d\n", ret); @@ -10123,10 +10142,20 @@ static int ath11k_mac_tx_push_txq(struct ath11k *ar, struct ieee80211_txq *txq) struct hal_srng *tcl_ring; struct sk_buff *skb; u32 ring_selector; - int num_free, avail; + int num_free, avail, reserve; int ret; u8 ring_id; + /* + * A GSO frame uses a ring entry for each of its segments, at most + * ATH11K_DP_TX_TSO_MAX_SEGS, and its frame is not known before it + * is dequeued: a frame is taken only while a batch of that size + * fits. Only a vif with the encap offload gets GSO frames. + */ + reserve = ar->ab->hw_params.tx_tso && + (txq->vif->offload_flags & IEEE80211_OFFLOAD_ENCAP_ENABLED) ? + ATH11K_DP_TX_TSO_MAX_SEGS : 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]; @@ -10155,12 +10184,14 @@ static int ath11k_mac_tx_push_txq(struct ath11k *ar, struct ieee80211_txq *txq) avail = num_free; ret = 0; - while (num_free) { + while (num_free >= reserve) { + int used; + if (unlikely(test_bit(ATH11K_FLAG_CRASH_FLUSH, &ar->ab->dev_flags))) break; - if (!ath11k_dp_tx_idr_has_room(tx_ring)) { + if (!ath11k_dp_tx_idr_has_room(tx_ring, reserve)) { ret = -ENOSPC; break; } @@ -10169,11 +10200,12 @@ static int ath11k_mac_tx_push_txq(struct ath11k *ar, struct ieee80211_txq *txq) if (!skb) break; + used = skb_is_gso(skb) ? skb_shinfo(skb)->gso_segs : 1; ret = ath11k_mac_tx(hw, &control, skb, ring_id); if (unlikely(ret == -ENOSPC || ret == -ENOMEM)) break; ret = 0; - num_free--; + num_free -= min(used, num_free); } if (num_free != avail && @@ -10185,7 +10217,7 @@ static int ath11k_mac_tx_push_txq(struct ath11k *ar, struct ieee80211_txq *txq) spin_unlock_bh(&tcl_ring->lock); spin_unlock_bh(&tx_ring->wake_tx_lock); - if (!num_free) + if (num_free < reserve) ret = -ENOSPC; if (unlikely(ret == -ENOSPC || ret == -ENOMEM)) { if (ath11k_mac_mark_txq_starved(ar, txq->ac)) -- 2.53.0 Tell mac80211 that the AP, AP VLAN and station netdevs may pass TCP batches with fragments (NETIF_F_SG, TSO and TSO6, up to 16 segments) when frames go out with Ethernet encap on a device whose TCL takes them (IPQ8074). mac80211 segments them in software on every other path, and when the airtime of the whole batch would not fit AQL's estimate. Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.12-01460-QCAHKSWPL_SILICONZ-1 Signed-off-by: Julius Bairaktaris --- drivers/net/wireless/ath/ath11k/dp_tx.c | 6 ++++++ drivers/net/wireless/ath/ath11k/dp_tx.h | 1 + drivers/net/wireless/ath/ath11k/mac.c | 12 ++++++++++++ 3 files changed, 19 insertions(+) diff --git a/drivers/net/wireless/ath/ath11k/dp_tx.c b/drivers/net/wireless/ath/ath11k/dp_tx.c index 4fbdd15d1ce0..6d950afb90f1 100644 --- a/drivers/net/wireless/ath/ath11k/dp_tx.c +++ b/drivers/net/wireless/ath/ath11k/dp_tx.c @@ -15,6 +15,12 @@ #include "peer.h" #include "mac.h" +/* Whether the netdevs of this device offer TSO and scatter-gather */ +bool ath11k_dp_tx_tso_wanted(struct ath11k_base *ab) +{ + return ab->hw_params.tx_tso; +} + static enum hal_tcl_encap_type ath11k_dp_tx_get_encap_type(struct ath11k_vif *arvif, struct sk_buff *skb) { diff --git a/drivers/net/wireless/ath/ath11k/dp_tx.h b/drivers/net/wireless/ath/ath11k/dp_tx.h index 967f212d33db..a73b5197fac2 100644 --- a/drivers/net/wireless/ath/ath11k/dp_tx.h +++ b/drivers/net/wireless/ath/ath11k/dp_tx.h @@ -22,6 +22,7 @@ int ath11k_dp_tx_htt_h2t_ver_req_msg(struct ath11k_base *ab); int ath11k_dp_tx(struct ath11k *ar, struct ath11k_vif *arvif, struct ath11k_sta *arsta, struct sk_buff *skb, int held_ring); bool ath11k_dp_tx_idr_has_room(struct dp_tx_ring *tx_ring, int n); +bool ath11k_dp_tx_tso_wanted(struct ath11k_base *ab); int ath11k_dp_tx_gso(struct ath11k *ar, struct ath11k_vif *arvif, struct ath11k_sta *arsta, struct sk_buff *skb, int held_ring); diff --git a/drivers/net/wireless/ath/ath11k/mac.c b/drivers/net/wireless/ath/ath11k/mac.c index 5f2086bf6c5d..1076e3b09cd3 100644 --- a/drivers/net/wireless/ath/ath11k/mac.c +++ b/drivers/net/wireless/ath/ath11k/mac.c @@ -10727,6 +10727,18 @@ static int __ath11k_mac_register(struct ath11k *ar) if (ath11k_frame_mode == ATH11K_HW_TXRX_ETHERNET) { ieee80211_hw_set(ar->hw, SUPPORTS_TX_ENCAP_OFFLOAD); ieee80211_hw_set(ar->hw, SUPPORTS_RX_DECAP_OFFLOAD); + + /* + * The TCL takes a TCP batch whole, with its payload in + * fragments, when the frame goes out with Ethernet encap. + */ + if (ath11k_dp_tx_tso_wanted(ab)) { + ar->hw->encap_netdev_features = NETIF_F_SG | + NETIF_F_TSO | + NETIF_F_TSO6; + ar->hw->encap_gso_max_segs = + ATH11K_DP_TX_TSO_MAX_SEGS; + } } if (cap->nss_ratio_enabled) -- 2.53.0 The netdevs offer ATH11K_DP_TX_TSO_MAX_SEGS (16) as their gso_max_segs, but a bridge or router hands them what GRO built on the ingress port: up to 64 KB (the default gro_max_size), and for a frame list up to 64 segments, where tcp_gro_receive() ends it. At an MSS of 1448 that is 45 segments. gso_features_check() clears the GSO features of every frame with more segments than gso_max_segs, so validate_xmit_skb() cut each such batch into one frame per segment before mac80211, and forwarded TCP downlink reached the TCL one segment at a time under load, when GRO batches are longest. The 16 is no limit of the TCL: each segment of a batch is a ring entry and an MSDU extension descriptor of its own, and a ring has 2048 descriptors. Raise the bound to 64. The transmit loop then takes a frame while 64 of the 512 TCL ring entries are free, and a batch keeps 256 bytes of ids and descriptor slots on the stack. A batch whose airtime does not fit the estimate is still cut by mac80211 before it is queued. Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.12-01460-QCAHKSWPL_SILICONZ-1 Signed-off-by: Julius Bairaktaris --- drivers/net/wireless/ath/ath11k/dp.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/dp.h b/drivers/net/wireless/ath/ath11k/dp.h index a923ba792e4b..1bdf2f564dac 100644 --- a/drivers/net/wireless/ath/ath11k/dp.h +++ b/drivers/net/wireless/ath/ath11k/dp.h @@ -81,10 +81,13 @@ struct dp_rxdma_ring { #define ATH11K_TX_COMPL_NEXT(x) (((x) + 1) % DP_TX_COMP_RING_SIZE) /* - * The most segments of a TCP batch the TCL takes whole, and the payload - * pieces of one segment past the headers + * The most segments of a TCP batch the TCL takes whole: each segment is a + * ring entry and an extension descriptor of its own, so the bound is what the + * stack builds, the 64 segments at which TCP GRO ends a frame list aggregate + * and more than the 64 KB of any other GRO aggregate hold at an MSS of 1024 + * or more. */ -#define ATH11K_DP_TX_TSO_MAX_SEGS 16 +#define ATH11K_DP_TX_TSO_MAX_SEGS 64 #define ATH11K_DP_TX_NO_EXT 0xffff struct ath11k_dp_tx_ext_map { -- 2.53.0 A TSO segment takes a buffer id from the id stack and an MSDU extension descriptor from a second stack, and a table indexed by id records which descriptor the id took. Its completion reads that table, then the payload map of the descriptor, a 36 byte entry that crosses into a second cache line for half of the descriptors. All of these were written when the batch was queued and are cold when its completions come: in a profile of bridged downlink at 900 Mbit/s (IPQ8074, one run), the instruction after the load of the segment length from the map in ath11k_dp_tx_buf_put_id() takes 1.05 % of all samples, the instructions around the load of the payload addresses 0.42 % and the comparison of the table entry 0.19 %. Reserve the ids below DP_TX_EXT_DESC_NUM for the extension descriptors, id n for descriptor n, handed out from the descriptor stack, and the others for frames sent from one buffer. The id then names its descriptor: the table goes, together with its write at queue time and its read and reset at completion. End the payload pieces of a map at the first of length 0, which no mapped piece has, instead of a count, so the map is 32 bytes and, aligned to that, never crosses a cache line. Frames sent from one buffer keep 30719 ids, where they shared 32767 with the segments before. Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.12-01460-QCAHKSWPL_SILICONZ-1 Signed-off-by: Julius Bairaktaris --- drivers/net/wireless/ath/ath11k/dp.h | 21 +++--- drivers/net/wireless/ath/ath11k/dp_tx.c | 95 ++++++++++++------------- 2 files changed, 60 insertions(+), 56 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/dp.h b/drivers/net/wireless/ath/ath11k/dp.h index 1bdf2f564dac..e47949ed7c4a 100644 --- a/drivers/net/wireless/ath/ath11k/dp.h +++ b/drivers/net/wireless/ath/ath11k/dp.h @@ -88,15 +88,18 @@ struct dp_rxdma_ring { * or more. */ #define ATH11K_DP_TX_TSO_MAX_SEGS 64 -#define ATH11K_DP_TX_NO_EXT 0xffff +/* + * The payload mappings of an extension descriptor, which end at the first + * piece of length 0 or after the last one, and the frame the descriptor + * makes, headers included. 32 bytes, so that the map of a completion is one + * cache line. + */ struct ath11k_dp_tx_ext_map { u32 dma[HAL_TX_MSDU_EXT_NUM_BUFS - 1]; u16 len[HAL_TX_MSDU_EXT_NUM_BUFS - 1]; - /* the frame this descriptor makes, headers included */ u16 seg_len; - u8 num; -}; +} __aligned(32); /* What a buffer id held when it was released */ struct ath11k_dp_tx_seg { @@ -116,16 +119,18 @@ struct dp_tx_ring { u32 num_free; /* * MSDU extension descriptors for TSO segments, placed by - * ath11k_dp_tx_ext_off(), the payload mappings of each, the - * descriptor each buffer id uses, and the ones not in use + * ath11k_dp_tx_ext_off(), and the payload mappings of each. The + * buffer ids below ext_ids are those of the extension descriptor of + * the same number and are handed out from ext_free, the others from + * free_ids. */ struct hal_tx_msdu_ext *ext; dma_addr_t ext_paddr; struct ath11k_dp_tx_ext_map *ext_map; - u16 *ext_slot; u16 *ext_free; u32 ext_num_free; - /* Protects bufs, free_ids, ext_slot and ext_free */ + u32 ext_ids; + /* Protects bufs, free_ids and ext_free */ spinlock_t tx_idr_lock; /* Serializes wake_tx_queue operations for this ring */ spinlock_t wake_tx_lock; diff --git a/drivers/net/wireless/ath/ath11k/dp_tx.c b/drivers/net/wireless/ath/ath11k/dp_tx.c index 6d950afb90f1..089696bff4c8 100644 --- a/drivers/net/wireless/ath/ath11k/dp_tx.c +++ b/drivers/net/wireless/ath/ath11k/dp_tx.c @@ -114,8 +114,10 @@ static size_t ath11k_dp_tx_ext_off(unsigned int slot) /* * The ids a ring hands out, as a table indexed by id with a stack of the free - * ones: the completion's cookie names the buffer directly. Callers of the id - * helpers hold tx_idr_lock. + * ones: the completion's cookie names the buffer directly. The ids below + * ext_ids are those of the extension descriptors and have a stack of their + * own, so that a completion finds the descriptor of its id without a table. + * Callers of the id helpers hold tx_idr_lock. */ int ath11k_dp_tx_bufs_init(struct ath11k_base *ab, struct dp_tx_ring *tx_ring) { @@ -125,9 +127,9 @@ int ath11k_dp_tx_bufs_init(struct ath11k_base *ab, struct dp_tx_ring *tx_ring) GFP_KERNEL); tx_ring->free_ids = kvcalloc(DP_TX_IDR_SIZE - 1, sizeof(*tx_ring->free_ids), GFP_KERNEL); - tx_ring->ext_slot = kvmalloc_array(DP_TX_IDR_SIZE - 1, - sizeof(*tx_ring->ext_slot), - GFP_KERNEL); + BUILD_BUG_ON(sizeof(struct ath11k_dp_tx_ext_map) != 32); + BUILD_BUG_ON(DP_TX_EXT_DESC_NUM + 1 >= DP_TX_IDR_SIZE); + if (ab->hw_params.tx_tso) { tx_ring->ext = dma_alloc_coherent(ab->dev, ATH11K_DP_TX_EXT_SIZE, &tx_ring->ext_paddr, @@ -139,24 +141,22 @@ int ath11k_dp_tx_bufs_init(struct ath11k_base *ab, struct dp_tx_ring *tx_ring) sizeof(*tx_ring->ext_free), GFP_KERNEL); } - if (!tx_ring->bufs || !tx_ring->free_ids || !tx_ring->ext_slot || + if (!tx_ring->bufs || !tx_ring->free_ids || (ab->hw_params.tx_tso && (!tx_ring->ext || !tx_ring->ext_map || !tx_ring->ext_free))) { ath11k_dp_tx_bufs_free(ab, tx_ring); return -ENOMEM; } - memset(tx_ring->ext_slot, 0xff, - (DP_TX_IDR_SIZE - 1) * sizeof(*tx_ring->ext_slot)); + tx_ring->ext_ids = tx_ring->ext_free ? DP_TX_EXT_DESC_NUM : 0; tx_ring->num_free = 0; - for (id = DP_TX_IDR_SIZE - 1; id--;) + for (id = DP_TX_IDR_SIZE - 1; id-- > tx_ring->ext_ids;) tx_ring->free_ids[tx_ring->num_free++] = id; tx_ring->ext_num_free = 0; - if (tx_ring->ext_free) - for (id = DP_TX_EXT_DESC_NUM; id--;) - tx_ring->ext_free[tx_ring->ext_num_free++] = id; + for (id = tx_ring->ext_ids; id--;) + tx_ring->ext_free[tx_ring->ext_num_free++] = id; return 0; } @@ -165,7 +165,6 @@ void ath11k_dp_tx_bufs_free(struct ath11k_base *ab, struct dp_tx_ring *tx_ring) { kvfree(tx_ring->bufs); kvfree(tx_ring->free_ids); - kvfree(tx_ring->ext_slot); if (tx_ring->ext) dma_free_coherent(ab->dev, ATH11K_DP_TX_EXT_SIZE, tx_ring->ext, tx_ring->ext_paddr); @@ -173,12 +172,12 @@ void ath11k_dp_tx_bufs_free(struct ath11k_base *ab, struct dp_tx_ring *tx_ring) kvfree(tx_ring->ext_free); tx_ring->bufs = NULL; tx_ring->free_ids = NULL; - tx_ring->ext_slot = NULL; tx_ring->ext = NULL; tx_ring->ext_map = NULL; tx_ring->ext_free = NULL; tx_ring->num_free = 0; tx_ring->ext_num_free = 0; + tx_ring->ext_ids = 0; } static int ath11k_dp_tx_buf_get_id(struct dp_tx_ring *tx_ring, @@ -198,10 +197,11 @@ static int ath11k_dp_tx_buf_get_id(struct dp_tx_ring *tx_ring, static void ath11k_dp_tx_tso_unmap(struct device *dev, struct ath11k_dp_tx_ext_map *map) { - while (map->num--) - dma_unmap_page(dev, map->dma[map->num], map->len[map->num], - DMA_TO_DEVICE); - map->num = 0; + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(map->len) && map->len[i]; i++) + dma_unmap_page(dev, map->dma[i], map->len[i], DMA_TO_DEVICE); + map->len[0] = 0; } /* @@ -215,8 +215,8 @@ struct sk_buff *ath11k_dp_tx_buf_put_id(struct ath11k_base *ab, bool *more, struct ath11k_dp_tx_seg *seg) { + struct ath11k_dp_tx_ext_map *map; struct sk_buff *skb; - u16 slot; *more = false; if (seg) { @@ -232,18 +232,18 @@ struct sk_buff *ath11k_dp_tx_buf_put_id(struct ath11k_base *ab, return NULL; tx_ring->bufs[id] = NULL; - tx_ring->free_ids[tx_ring->num_free++] = id; if (seg) seg->skb = skb; - slot = tx_ring->ext_slot[id]; - if (unlikely(slot != ATH11K_DP_TX_NO_EXT)) { + if (id >= tx_ring->ext_ids) { + tx_ring->free_ids[tx_ring->num_free++] = id; + } else { + map = &tx_ring->ext_map[id]; if (seg) - seg->len = tx_ring->ext_map[slot].seg_len; - ath11k_dp_tx_tso_unmap(ab->dev, &tx_ring->ext_map[slot]); - tx_ring->ext_free[tx_ring->ext_num_free++] = slot; - tx_ring->ext_slot[id] = ATH11K_DP_TX_NO_EXT; + seg->len = map->seg_len; + ath11k_dp_tx_tso_unmap(ab->dev, map); + tx_ring->ext_free[tx_ring->ext_num_free++] = id; if (!skb_unref(skb)) { *more = true; @@ -507,10 +507,11 @@ static int ath11k_dp_tx_tso_map(struct device *dev, struct sk_buff *skb, unsigned int len) { struct skb_shared_info *shinfo = skb_shinfo(skb); - unsigned int avail, take; + unsigned int avail, take, num = 0; dma_addr_t dma; - map->num = 0; + /* every piece mapped has a length, so the first 0 ends them */ + memset(map->len, 0, sizeof(map->len)); while (len) { if (!*piece) avail = skb_headlen(skb) - *off; @@ -523,7 +524,7 @@ static int ath11k_dp_tx_tso_map(struct device *dev, struct sk_buff *skb, *off = 0; continue; } - if (map->num == HAL_TX_MSDU_EXT_NUM_BUFS - 1) + if (num == ARRAY_SIZE(map->len)) return -E2BIG; take = min(avail, len); @@ -538,11 +539,11 @@ static int ath11k_dp_tx_tso_map(struct device *dev, struct sk_buff *skb, if (dma_mapping_error(dev, dma)) return -ENOMEM; - map->dma[map->num] = dma; - map->len[map->num] = take; - map->num++; - ext->buf[map->num].addr_lo = lower_32_bits(dma); - ext->buf[map->num].info = + map->dma[num] = dma; + map->len[num] = take; + num++; + ext->buf[num].addr_lo = lower_32_bits(dma); + ext->buf[num].info = FIELD_PREP(HAL_TX_MSDU_EXT_BUF_INFO_ADDR_HI, upper_32_bits(dma)) | FIELD_PREP(HAL_TX_MSDU_EXT_BUF_INFO_LEN, take); @@ -658,7 +659,7 @@ static int ath11k_dp_tx_ext(struct ath11k *ar, struct ath11k_vif *arvif, struct hal_tx_info ti = {}; struct dp_tx_ring *tx_ring; struct hal_srng *tcl_ring; - u16 ids[ATH11K_DP_TX_TSO_MAX_SEGS], slots[ATH11K_DP_TX_TSO_MAX_SEGS]; + u16 ids[ATH11K_DP_TX_TSO_MAX_SEGS]; u32 seq = 0, flags = 0, ip_id = 0; dma_addr_t hdr_dma; struct tcphdr *th; @@ -730,15 +731,15 @@ static int ath11k_dp_tx_ext(struct ath11k *ar, struct ath11k_vif *arvif, tcl_ring = &ab->hal.srng_list[tx_ring->tcl_data_ring.ring_id]; spin_lock_bh(&tx_ring->tx_idr_lock); - if (tx_ring->num_free < n || tx_ring->ext_num_free < n) { + if (tx_ring->ext_num_free < n) { spin_unlock_bh(&tx_ring->tx_idr_lock); return -EAGAIN; } + /* the id of a segment is the number of its extension descriptor */ for (i = 0; i < n; i++) { - slots[i] = tx_ring->ext_free[--tx_ring->ext_num_free]; - ids[i] = ath11k_dp_tx_buf_get_id(tx_ring, skb); - tx_ring->ext_slot[ids[i]] = slots[i]; - tx_ring->ext_map[slots[i]].num = 0; + ids[i] = tx_ring->ext_free[--tx_ring->ext_num_free]; + tx_ring->bufs[ids[i]] = skb; + tx_ring->ext_map[ids[i]].len[0] = 0; } spin_unlock_bh(&tx_ring->tx_idr_lock); @@ -765,8 +766,8 @@ static int ath11k_dp_tx_ext(struct ath11k *ar, struct ath11k_vif *arvif, left = skb->len - off; for (i = 0; i < n; i++) { struct hal_tx_msdu_ext *ext = (void *)tx_ring->ext + - ath11k_dp_tx_ext_off(slots[i]); - struct ath11k_dp_tx_ext_map *map = &tx_ring->ext_map[slots[i]]; + ath11k_dp_tx_ext_off(ids[i]); + struct ath11k_dp_tx_ext_map *map = &tx_ring->ext_map[ids[i]]; unsigned int len = tso ? min(left, mss) : left; u32 seg_flags = flags; @@ -861,7 +862,7 @@ static int ath11k_dp_tx_ext(struct ath11k *ar, struct ath11k_vif *arvif, FIELD_PREP(DP_TX_DESC_ID_POOL_ID, skb_get_queue_mapping(skb) & (ATH11K_HW_MAX_QUEUES - 1)); - ti.paddr = tx_ring->ext_paddr + ath11k_dp_tx_ext_off(slots[i]); + ti.paddr = tx_ring->ext_paddr + ath11k_dp_tx_ext_off(ids[i]); /* the command follows the TLV header of the ring entry */ desc = ath11k_hal_srng_src_get_next_entry(ab, tcl_ring); ath11k_hal_tx_cmd_desc_setup(ab, desc + sizeof(struct hal_tlv_hdr), @@ -890,18 +891,16 @@ static int ath11k_dp_tx_ext(struct ath11k *ar, struct ath11k_vif *arvif, fail_unmap: for (j = 0; j < i; j++) - ath11k_dp_tx_tso_unmap(ab->dev, &tx_ring->ext_map[slots[j]]); + ath11k_dp_tx_tso_unmap(ab->dev, &tx_ring->ext_map[ids[j]]); dma_unmap_single(ab->dev, hdr_dma, skb_headlen(skb), DMA_TO_DEVICE); fail_put: if (pad) ath11k_dp_tx_ext_unpad(skb, hdr_len, pad); spin_lock_bh(&tx_ring->tx_idr_lock); for (j = n; j--;) { - /* no reference was taken yet: release the id and slot only */ + /* no reference was taken yet: release the id only */ tx_ring->bufs[ids[j]] = NULL; - tx_ring->free_ids[tx_ring->num_free++] = ids[j]; - tx_ring->ext_slot[ids[j]] = ATH11K_DP_TX_NO_EXT; - tx_ring->ext_free[tx_ring->ext_num_free++] = slots[j]; + tx_ring->ext_free[tx_ring->ext_num_free++] = ids[j]; } spin_unlock_bh(&tx_ring->tx_idr_lock); -- 2.53.0 A batch the TCL segments from extension descriptors holds one reference of its skb per segment, taken with refcount_add() when it is sent, and each segment's completion drops one with skb_unref() in ath11k_dp_tx_buf_put_id(). That is an atomic on the skb's reference count line, which nothing else of the completion reads: in a profile of routed downlink at 900 Mbit/s (IPQ8074, one run) the instruction after it takes 0.44 % of all samples. Count the outstanding segments in the frame's control block instead, whose line the completion of the segment reads anyway. The send sets the count before the first descriptor is on the ring, with the frame held only by the driver (its reference count is 1 there), and every release of an id of the batch decrements it: the completion handler and the firmware release paths under the id lock, and the teardown, which runs alone. The send's failure path gives its ids back before any count exists, as it gave them back before any reference was taken. The release that takes the count to zero returns the frame, as skb_unref() did for the last reference, so the frames of a batch complete and are freed in the same order as before. Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.12-01460-QCAHKSWPL_SILICONZ-1 Signed-off-by: Julius Bairaktaris --- drivers/net/wireless/ath/ath11k/core.h | 5 +++++ drivers/net/wireless/ath/ath11k/dp_tx.c | 17 +++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/drivers/net/wireless/ath/ath11k/core.h b/drivers/net/wireless/ath/ath11k/core.h index 11c79d0f5c34..32f24e1a396f 100644 --- a/drivers/net/wireless/ath/ath11k/core.h +++ b/drivers/net/wireless/ath/ath11k/core.h @@ -128,6 +128,11 @@ struct ath11k_skb_cb { */ u8 tso_try; u8 tso_bad; + /* + * Of a batch whose segments are counted here instead of in the skb's + * reference count: the segments whose completion is still to come + */ + u8 tso_left; } __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 089696bff4c8..2d044ed408c0 100644 --- a/drivers/net/wireless/ath/ath11k/dp_tx.c +++ b/drivers/net/wireless/ath/ath11k/dp_tx.c @@ -245,7 +245,7 @@ struct sk_buff *ath11k_dp_tx_buf_put_id(struct ath11k_base *ab, ath11k_dp_tx_tso_unmap(ab->dev, map); tx_ring->ext_free[tx_ring->ext_num_free++] = id; - if (!skb_unref(skb)) { + if (--ATH11K_SKB_CB(skb)->tso_left) { *more = true; return NULL; } @@ -638,9 +638,9 @@ static void ath11k_dp_tx_ext_unpad(struct sk_buff *skb, unsigned int len, * its segments, and the payload in the fragments. A TCP batch has one * descriptor for each of its segments, which also gives the segment's IP * length, IP ID, TCP sequence number and flags for the TCL to write into the - * headers; every segment holds a reference on the batch, and the completion - * of the last one reports the batch to mac80211. A frame with fragments has - * one descriptor, and is a batch of one segment. + * headers; every segment holds a share of the batch's segment count, and the + * completion of the last one reports the batch to mac80211. A frame with + * fragments has one descriptor, and is a batch of one segment. * * Returns -EAGAIN, with the frame untouched, for one the TCL cannot take * whole. The ids, extension descriptors and ring entries of all segments are @@ -829,7 +829,12 @@ static int ath11k_dp_tx_ext(struct ath11k *ar, struct ath11k_vif *arvif, skb_cb->ar = ar; skb_cb->tso_try = 0; skb_cb->tso_bad = 0; - refcount_add(n - 1, &skb->users); + /* + * Each segment's completion gives back one share of the frame, + * counted in the control block under the id lock every release of an + * id holds. + */ + skb_cb->tso_left = n; ti.encap_type = HAL_TCL_ENCAP_TYPE_ETHERNET; ti.meta_data_flags = arvif->tcl_metadata; @@ -898,7 +903,7 @@ static int ath11k_dp_tx_ext(struct ath11k *ar, struct ath11k_vif *arvif, ath11k_dp_tx_ext_unpad(skb, hdr_len, pad); spin_lock_bh(&tx_ring->tx_idr_lock); for (j = n; j--;) { - /* no reference was taken yet: release the id only */ + /* no segment was counted yet: release the id only */ tx_ring->bufs[ids[j]] = NULL; tx_ring->ext_free[tx_ring->ext_num_free++] = ids[j]; } -- 2.53.0