blob: 78737b8706e2702a59fe985dfccb14655cad636c [file] [log] [blame]
From 08bab29bc70a7b21150167f2ae502d8e5538c743 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 190/199] 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.
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 1858f542..e5e5529d 100644
--- a/mt76.h
+++ b/mt76.h
@@ -462,6 +462,7 @@ struct mt76_txwi_cache {
dma_addr_t dma_addr;
unsigned long jiffies;
+ u8 phy_idx;
struct sk_buff *skb;
};
@@ -960,6 +961,7 @@ struct mt76_phy {
} leds;
struct mt76_tx_debug tx_dbg_stats;
struct mt76_rx_debug rx_dbg_stats;
+ int tokens;
};
struct mt76_dev {
@@ -1009,6 +1011,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;
@@ -1879,7 +1882,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 2f43c0ff..bad4b1b7 100644
--- a/mt7996/init.c
+++ b/mt7996/init.c
@@ -1770,6 +1770,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 32f5b859..f9344f28 100644
--- a/mt7996/mac.c
+++ b/mt7996/mac.c
@@ -959,7 +959,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;
@@ -1683,8 +1683,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 fa884316..04832b0c 100644
--- a/mt7996/mt7996.h
+++ b/mt7996/mt7996.h
@@ -76,6 +76,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 fa8de2db..a4703b07 100644
--- a/mt7996/mtk_debugfs.c
+++ b/mt7996/mtk_debugfs.c
@@ -2401,7 +2401,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");
@@ -2410,8 +2410,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 5e6e433f..c965f0e3 100644
--- a/tx.c
+++ b/tx.c
@@ -837,20 +837,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)
@@ -860,6 +869,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;
@@ -893,7 +903,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.18.0