| From 0d130b8ba58d84007b12bd6984b94b756c5d6d3b Mon Sep 17 00:00:00 2001 |
| From: Peter Chiu <chui-hao.chiu@mediatek.com> |
| Date: Tue, 30 Jul 2024 19:49:39 +0800 |
| Subject: [PATCH 178/223] mtk: mt76: mt7996: add per-band token limit |
| |
| Add a threshold for per-band token count. |
| The bands use the same token pool so a band cannot transmit if |
| the other band occupy too many tokens. With this patch, we can |
| prevent a band from interfering with the other band. |
| |
| Change-Id: I53ba83b2144c7576274b0f4b736f201a6ab79b0c |
| Change-Id: Ic3974b881fb099f0749ebf97c690141c234b6d1e |
| Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com> |
| --- |
| mt76.h | 6 +++++- |
| mt7996/init.c | 2 ++ |
| mt7996/mac.c | 5 ++++- |
| mt7996/mt7996.h | 1 + |
| mt7996/mtk_debugfs.c | 14 ++++++++++++-- |
| tx.c | 19 ++++++++++++++++--- |
| 6 files changed, 40 insertions(+), 7 deletions(-) |
| |
| diff --git a/mt76.h b/mt76.h |
| index 14f409ba..5d7b8c4c 100644 |
| --- a/mt76.h |
| +++ b/mt76.h |
| @@ -468,6 +468,7 @@ struct mt76_txwi_cache { |
| dma_addr_t dma_addr; |
| |
| unsigned long jiffies; |
| + u8 phy_idx; |
| |
| struct sk_buff *skb; |
| }; |
| @@ -975,6 +976,7 @@ struct mt76_phy { |
| } leds; |
| struct mt76_tx_debug tx_dbg_stats; |
| struct mt76_rx_debug rx_dbg_stats; |
| + int tokens; |
| }; |
| |
| struct mt76_dev { |
| @@ -1024,6 +1026,7 @@ struct mt76_dev { |
| u16 wed_token_count; |
| u16 token_count; |
| u16 token_size; |
| + u16 token_threshold; |
| |
| spinlock_t rx_token_lock; |
| struct idr rx_token; |
| @@ -1895,7 +1898,8 @@ static inline bool mt76_queue_is_wed_rx(struct mt76_queue *q) |
| |
| struct mt76_txwi_cache * |
| mt76_token_release(struct mt76_dev *dev, int token, bool *wake); |
| -int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi); |
| +int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi, |
| + u8 phy_idx); |
| void __mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked); |
| struct mt76_rxwi_cache *mt76_rx_token_release(struct mt76_dev *dev, int token); |
| int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr, |
| diff --git a/mt7996/init.c b/mt7996/init.c |
| index ae86c0eb..6e8791c8 100644 |
| --- a/mt7996/init.c |
| +++ b/mt7996/init.c |
| @@ -1790,6 +1790,8 @@ int mt7996_register_device(struct mt7996_dev *dev) |
| if (ret) |
| return ret; |
| |
| + dev->mt76.token_threshold = MT7996_PER_BAND_TOKEN_SIZE; |
| + |
| ret = mt7996_init_dev_debugfs(&dev->phy); |
| if (ret) |
| goto error; |
| diff --git a/mt7996/mac.c b/mt7996/mac.c |
| index 295bff24..ac51e27d 100644 |
| --- a/mt7996/mac.c |
| +++ b/mt7996/mac.c |
| @@ -971,7 +971,7 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr, |
| t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size); |
| t->skb = tx_info->skb; |
| |
| - id = mt76_token_consume(mdev, &t); |
| + id = mt76_token_consume(mdev, &t, mconf->mt76.band_idx); |
| if (id < 0) { |
| mdev->tx_dbg_stats.tx_drop[MT_TX_DROP_GET_TOKEN_FAIL]++; |
| return id; |
| @@ -1695,8 +1695,11 @@ void mt7996_tx_token_put(struct mt7996_dev *dev) |
| |
| spin_lock_bh(&dev->mt76.token_lock); |
| idr_for_each_entry(&dev->mt76.token, txwi, id) { |
| + struct mt76_phy *phy = mt76_dev_phy(&dev->mt76, txwi->phy_idx); |
| + |
| mt7996_txwi_free(dev, txwi, NULL, NULL, NULL); |
| dev->mt76.token_count--; |
| + phy->tokens--; |
| } |
| spin_unlock_bh(&dev->mt76.token_lock); |
| idr_destroy(&dev->mt76.token); |
| diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h |
| index 8f8cd7ae..38f62d89 100644 |
| --- a/mt7996/mt7996.h |
| +++ b/mt7996/mt7996.h |
| @@ -78,6 +78,7 @@ |
| #define MT7996_TOKEN_SIZE 16384 |
| #define MT7996_HW_TOKEN_SIZE 8192 |
| #define MT7996_SW_TOKEN_SIZE 15360 |
| +#define MT7996_PER_BAND_TOKEN_SIZE 5120 |
| |
| #define MT7996_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */ |
| #define MT7996_CFEND_RATE_11B 0x03 /* 11B LP, 11M */ |
| diff --git a/mt7996/mtk_debugfs.c b/mt7996/mtk_debugfs.c |
| index 78450935..96a4a514 100644 |
| --- a/mt7996/mtk_debugfs.c |
| +++ b/mt7996/mtk_debugfs.c |
| @@ -2400,7 +2400,7 @@ static int mt7996_sta_info(struct seq_file *s, void *data) |
| static int mt7996_token_read(struct seq_file *s, void *data) |
| { |
| struct mt7996_dev *dev = dev_get_drvdata(s->private); |
| - int msdu_id; |
| + int msdu_id, i; |
| struct mt76_txwi_cache *txwi; |
| |
| seq_printf(s, "Token from host:\n"); |
| @@ -2409,8 +2409,18 @@ static int mt7996_token_read(struct seq_file *s, void *data) |
| seq_printf(s, "%4d (pending time %u ms)\n", msdu_id, |
| jiffies_to_msecs(jiffies - txwi->jiffies)); |
| } |
| - spin_unlock_bh(&dev->mt76.token_lock); |
| seq_printf(s, "\n"); |
| + for (i = 0; i < __MT_MAX_BAND; i++) { |
| + struct mt76_phy *phy = mt76_dev_phy(&dev->mt76, i); |
| + |
| + if (!mt7996_band_valid(dev, i)) |
| + continue; |
| + |
| + seq_printf(s, "Band%u consume: %d, free: %d total: %d\n", |
| + i, phy->tokens, dev->mt76.token_threshold - phy->tokens, |
| + dev->mt76.token_threshold); |
| + } |
| + spin_unlock_bh(&dev->mt76.token_lock); |
| |
| return 0; |
| } |
| diff --git a/tx.c b/tx.c |
| index c9fda966..9bf43124 100644 |
| --- a/tx.c |
| +++ b/tx.c |
| @@ -855,20 +855,29 @@ void __mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked) |
| } |
| EXPORT_SYMBOL_GPL(__mt76_set_tx_blocked); |
| |
| -int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi) |
| +int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi, |
| + u8 phy_idx) |
| { |
| - int token, start = 0; |
| + int token = -EINVAL, start = 0; |
| + struct mt76_phy *phy = mt76_dev_phy(dev, phy_idx); |
| |
| if (mtk_wed_device_active(&dev->mmio.wed)) |
| start = dev->mmio.wed.wlan.nbuf; |
| |
| spin_lock_bh(&dev->token_lock); |
| |
| + if (phy->tokens > dev->token_threshold) |
| + goto out; |
| + |
| token = idr_alloc(&dev->token, *ptxwi, start, start + dev->token_size, |
| GFP_ATOMIC); |
| - if (token >= start) |
| + if (token >= start) { |
| dev->token_count++; |
| |
| + (*ptxwi)->phy_idx = phy_idx; |
| + phy->tokens++; |
| + } |
| + |
| #ifdef CONFIG_NET_MEDIATEK_SOC_WED |
| if (mtk_wed_device_active(&dev->mmio.wed) && |
| token >= dev->mmio.wed.wlan.token_start) |
| @@ -878,6 +887,7 @@ int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi) |
| if (dev->token_count >= dev->token_size - MT76_TOKEN_FREE_THR) |
| __mt76_set_tx_blocked(dev, true); |
| |
| +out: |
| spin_unlock_bh(&dev->token_lock); |
| |
| return token; |
| @@ -911,7 +921,10 @@ mt76_token_release(struct mt76_dev *dev, int token, bool *wake) |
| |
| txwi = idr_remove(&dev->token, token); |
| if (txwi) { |
| + struct mt76_phy *phy = mt76_dev_phy(dev, txwi->phy_idx); |
| + |
| dev->token_count--; |
| + phy->tokens--; |
| |
| #ifdef CONFIG_NET_MEDIATEK_SOC_WED |
| if (mtk_wed_device_active(&dev->mmio.wed) && |
| -- |
| 2.45.2 |
| |