blob: 273498bd9c804c94755e8a2ae135b2ddbe8d8b72 [file] [log] [blame]
developer1f55fcf2024-10-17 14:52:33 +08001From 9ea195f63990ccc4925cf5f75f730eac744cda95 Mon Sep 17 00:00:00 2001
developer05f3b2b2024-08-19 19:17:34 +08002From: Peter Chiu <chui-hao.chiu@mediatek.com>
3Date: Tue, 30 Jul 2024 19:49:39 +0800
developer1f55fcf2024-10-17 14:52:33 +08004Subject: [PATCH 178/193] mtk: mt76: mt7996: add per-band token limit
developer05f3b2b2024-08-19 19:17:34 +08005
6Add a threshold for per-band token count.
7The bands use the same token pool so a band cannot transmit if
8the other band occupy too many tokens. With this patch, we can
9prevent a band from interfering with the other band.
10
developerd0c89452024-10-11 16:53:27 +080011Change-Id: I53ba83b2144c7576274b0f4b736f201a6ab79b0c
12Change-Id: Ic3974b881fb099f0749ebf97c690141c234b6d1e
developer05f3b2b2024-08-19 19:17:34 +080013Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
14---
15 mt76.h | 6 +++++-
16 mt7996/init.c | 2 ++
17 mt7996/mac.c | 5 ++++-
18 mt7996/mt7996.h | 1 +
19 mt7996/mtk_debugfs.c | 14 ++++++++++++--
20 tx.c | 19 ++++++++++++++++---
21 6 files changed, 40 insertions(+), 7 deletions(-)
22
23diff --git a/mt76.h b/mt76.h
developer1f55fcf2024-10-17 14:52:33 +080024index 14f409b..5d7b8c4 100644
developer05f3b2b2024-08-19 19:17:34 +080025--- a/mt76.h
26+++ b/mt76.h
developerd0c89452024-10-11 16:53:27 +080027@@ -468,6 +468,7 @@ struct mt76_txwi_cache {
developer05f3b2b2024-08-19 19:17:34 +080028 dma_addr_t dma_addr;
29
30 unsigned long jiffies;
31+ u8 phy_idx;
32
33 struct sk_buff *skb;
34 };
developerd0c89452024-10-11 16:53:27 +080035@@ -975,6 +976,7 @@ struct mt76_phy {
developer05f3b2b2024-08-19 19:17:34 +080036 } leds;
37 struct mt76_tx_debug tx_dbg_stats;
38 struct mt76_rx_debug rx_dbg_stats;
39+ int tokens;
40 };
41
42 struct mt76_dev {
developerd0c89452024-10-11 16:53:27 +080043@@ -1024,6 +1026,7 @@ struct mt76_dev {
developer05f3b2b2024-08-19 19:17:34 +080044 u16 wed_token_count;
45 u16 token_count;
46 u16 token_size;
47+ u16 token_threshold;
48
49 spinlock_t rx_token_lock;
50 struct idr rx_token;
developerd0c89452024-10-11 16:53:27 +080051@@ -1895,7 +1898,8 @@ static inline bool mt76_queue_is_wed_rx(struct mt76_queue *q)
developer05f3b2b2024-08-19 19:17:34 +080052
53 struct mt76_txwi_cache *
54 mt76_token_release(struct mt76_dev *dev, int token, bool *wake);
55-int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi);
56+int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi,
57+ u8 phy_idx);
58 void __mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked);
59 struct mt76_rxwi_cache *mt76_rx_token_release(struct mt76_dev *dev, int token);
60 int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr,
61diff --git a/mt7996/init.c b/mt7996/init.c
developer1f55fcf2024-10-17 14:52:33 +080062index 3978560..e9e2ca1 100644
developer05f3b2b2024-08-19 19:17:34 +080063--- a/mt7996/init.c
64+++ b/mt7996/init.c
developer1f55fcf2024-10-17 14:52:33 +080065@@ -1787,6 +1787,8 @@ int mt7996_register_device(struct mt7996_dev *dev)
developer05f3b2b2024-08-19 19:17:34 +080066 if (ret)
67 return ret;
68
69+ dev->mt76.token_threshold = MT7996_PER_BAND_TOKEN_SIZE;
70+
71 ret = mt7996_init_dev_debugfs(&dev->phy);
72 if (ret)
73 goto error;
74diff --git a/mt7996/mac.c b/mt7996/mac.c
developer1f55fcf2024-10-17 14:52:33 +080075index 295bff2..ac51e27 100644
developer05f3b2b2024-08-19 19:17:34 +080076--- a/mt7996/mac.c
77+++ b/mt7996/mac.c
developerd0c89452024-10-11 16:53:27 +080078@@ -971,7 +971,7 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
developer05f3b2b2024-08-19 19:17:34 +080079 t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size);
80 t->skb = tx_info->skb;
81
82- id = mt76_token_consume(mdev, &t);
83+ id = mt76_token_consume(mdev, &t, mconf->mt76.band_idx);
84 if (id < 0) {
85 mdev->tx_dbg_stats.tx_drop[MT_TX_DROP_GET_TOKEN_FAIL]++;
86 return id;
developerd0c89452024-10-11 16:53:27 +080087@@ -1695,8 +1695,11 @@ void mt7996_tx_token_put(struct mt7996_dev *dev)
developer05f3b2b2024-08-19 19:17:34 +080088
89 spin_lock_bh(&dev->mt76.token_lock);
90 idr_for_each_entry(&dev->mt76.token, txwi, id) {
91+ struct mt76_phy *phy = mt76_dev_phy(&dev->mt76, txwi->phy_idx);
92+
93 mt7996_txwi_free(dev, txwi, NULL, NULL, NULL);
94 dev->mt76.token_count--;
95+ phy->tokens--;
96 }
97 spin_unlock_bh(&dev->mt76.token_lock);
98 idr_destroy(&dev->mt76.token);
99diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h
developer1f55fcf2024-10-17 14:52:33 +0800100index 8f8cd7a..38f62d8 100644
developer05f3b2b2024-08-19 19:17:34 +0800101--- a/mt7996/mt7996.h
102+++ b/mt7996/mt7996.h
developerd0c89452024-10-11 16:53:27 +0800103@@ -78,6 +78,7 @@
developer05f3b2b2024-08-19 19:17:34 +0800104 #define MT7996_TOKEN_SIZE 16384
105 #define MT7996_HW_TOKEN_SIZE 8192
106 #define MT7996_SW_TOKEN_SIZE 15360
107+#define MT7996_PER_BAND_TOKEN_SIZE 5120
108
109 #define MT7996_CFEND_RATE_DEFAULT 0x49 /* OFDM 24M */
110 #define MT7996_CFEND_RATE_11B 0x03 /* 11B LP, 11M */
111diff --git a/mt7996/mtk_debugfs.c b/mt7996/mtk_debugfs.c
developer1f55fcf2024-10-17 14:52:33 +0800112index 7845093..96a4a51 100644
developer05f3b2b2024-08-19 19:17:34 +0800113--- a/mt7996/mtk_debugfs.c
114+++ b/mt7996/mtk_debugfs.c
developerd0c89452024-10-11 16:53:27 +0800115@@ -2400,7 +2400,7 @@ static int mt7996_sta_info(struct seq_file *s, void *data)
developer05f3b2b2024-08-19 19:17:34 +0800116 static int mt7996_token_read(struct seq_file *s, void *data)
117 {
118 struct mt7996_dev *dev = dev_get_drvdata(s->private);
119- int msdu_id;
120+ int msdu_id, i;
121 struct mt76_txwi_cache *txwi;
122
123 seq_printf(s, "Token from host:\n");
developerd0c89452024-10-11 16:53:27 +0800124@@ -2409,8 +2409,18 @@ static int mt7996_token_read(struct seq_file *s, void *data)
developer05f3b2b2024-08-19 19:17:34 +0800125 seq_printf(s, "%4d (pending time %u ms)\n", msdu_id,
126 jiffies_to_msecs(jiffies - txwi->jiffies));
127 }
128- spin_unlock_bh(&dev->mt76.token_lock);
129 seq_printf(s, "\n");
130+ for (i = 0; i < __MT_MAX_BAND; i++) {
131+ struct mt76_phy *phy = mt76_dev_phy(&dev->mt76, i);
132+
133+ if (!mt7996_band_valid(dev, i))
134+ continue;
135+
136+ seq_printf(s, "Band%u consume: %d, free: %d total: %d\n",
137+ i, phy->tokens, dev->mt76.token_threshold - phy->tokens,
138+ dev->mt76.token_threshold);
139+ }
140+ spin_unlock_bh(&dev->mt76.token_lock);
141
142 return 0;
143 }
144diff --git a/tx.c b/tx.c
developer1f55fcf2024-10-17 14:52:33 +0800145index e7aba9f..6f594fa 100644
developer05f3b2b2024-08-19 19:17:34 +0800146--- a/tx.c
147+++ b/tx.c
developerd0c89452024-10-11 16:53:27 +0800148@@ -855,20 +855,29 @@ void __mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked)
developer05f3b2b2024-08-19 19:17:34 +0800149 }
150 EXPORT_SYMBOL_GPL(__mt76_set_tx_blocked);
151
152-int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi)
153+int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi,
154+ u8 phy_idx)
155 {
156- int token, start = 0;
157+ int token = -EINVAL, start = 0;
158+ struct mt76_phy *phy = mt76_dev_phy(dev, phy_idx);
159
160 if (mtk_wed_device_active(&dev->mmio.wed))
161 start = dev->mmio.wed.wlan.nbuf;
162
163 spin_lock_bh(&dev->token_lock);
164
165+ if (phy->tokens > dev->token_threshold)
166+ goto out;
167+
168 token = idr_alloc(&dev->token, *ptxwi, start, start + dev->token_size,
169 GFP_ATOMIC);
170- if (token >= start)
171+ if (token >= start) {
172 dev->token_count++;
173
174+ (*ptxwi)->phy_idx = phy_idx;
175+ phy->tokens++;
176+ }
177+
178 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
179 if (mtk_wed_device_active(&dev->mmio.wed) &&
180 token >= dev->mmio.wed.wlan.token_start)
developerd0c89452024-10-11 16:53:27 +0800181@@ -878,6 +887,7 @@ int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi)
developer05f3b2b2024-08-19 19:17:34 +0800182 if (dev->token_count >= dev->token_size - MT76_TOKEN_FREE_THR)
183 __mt76_set_tx_blocked(dev, true);
184
185+out:
186 spin_unlock_bh(&dev->token_lock);
187
188 return token;
developerd0c89452024-10-11 16:53:27 +0800189@@ -911,7 +921,10 @@ mt76_token_release(struct mt76_dev *dev, int token, bool *wake)
developer05f3b2b2024-08-19 19:17:34 +0800190
191 txwi = idr_remove(&dev->token, token);
192 if (txwi) {
193+ struct mt76_phy *phy = mt76_dev_phy(dev, txwi->phy_idx);
194+
195 dev->token_count--;
196+ phy->tokens--;
197
198 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
199 if (mtk_wed_device_active(&dev->mmio.wed) &&
200--
developerd0c89452024-10-11 16:53:27 +08002012.45.2
developer05f3b2b2024-08-19 19:17:34 +0800202