blob: 167f36cddfab6beceebeda9010259f7108afede6 [file] [log] [blame]
developer05f3b2b2024-08-19 19:17:34 +08001From a2f8deaaf6a97b0157e49ec476b003ef1dd234f8 Mon Sep 17 00:00:00 2001
developera46f6132024-03-26 14:09:54 +08002From: Peter Chiu <chui-hao.chiu@mediatek.com>
3Date: Mon, 29 Jan 2024 15:33:24 +0800
developera20cdc22024-05-31 18:57:31 +08004Subject: [PATCH 13/21] wifi: mt76: mt7915: limit per-band token count
developera46f6132024-03-26 14:09:54 +08005
6Add a threshold for per-band token count to prevent a band from interfering
7with the other band.
8
9Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
developera20cdc22024-05-31 18:57:31 +080010---
11 mt76.h | 8 +++++++-
12 mt76_connac_mac.c | 2 ++
13 mt7915/init.c | 3 +++
14 mt7915/mac.c | 3 ++-
15 mt7921/pci_mac.c | 2 +-
16 mt7925/pci_mac.c | 2 +-
17 mt7996/init.c | 5 +++++
18 mt7996/mac.c | 3 ++-
19 tx.c | 20 ++++++++++++++++++--
20 9 files changed, 41 insertions(+), 7 deletions(-)
developera46f6132024-03-26 14:09:54 +080021
22diff --git a/mt76.h b/mt76.h
developer05f3b2b2024-08-19 19:17:34 +080023index 4fb07877..05ee568c 100644
developera46f6132024-03-26 14:09:54 +080024--- a/mt76.h
25+++ b/mt76.h
developerdc9eeae2024-04-08 14:36:46 +080026@@ -407,6 +407,8 @@ struct mt76_txwi_cache {
developera46f6132024-03-26 14:09:54 +080027 struct list_head list;
28 dma_addr_t dma_addr;
29
30+ u8 phy_idx;
31+
32 union {
33 struct sk_buff *skb;
34 void *ptr;
developerdc9eeae2024-04-08 14:36:46 +080035@@ -819,6 +821,7 @@ struct mt76_phy {
developera46f6132024-03-26 14:09:54 +080036 bool al;
37 u8 pin;
38 } leds;
39+ int tokens;
40 };
41
42 struct mt76_dev {
developerdc9eeae2024-04-08 14:36:46 +080043@@ -872,6 +875,8 @@ struct mt76_dev {
developera46f6132024-03-26 14:09:54 +080044 u16 wed_token_count;
45 u16 token_count;
46 u16 token_size;
47+ u16 token_threshold;
48+ u8 num_phy;
49
50 spinlock_t rx_token_lock;
51 struct idr rx_token;
developer05f3b2b2024-08-19 19:17:34 +080052@@ -1674,7 +1679,8 @@ static inline bool mt76_queue_is_wed_rx(struct mt76_queue *q)
developera46f6132024-03-26 14:09:54 +080053
54 struct mt76_txwi_cache *
55 mt76_token_release(struct mt76_dev *dev, int token, bool *wake);
56-int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi);
57+int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi,
58+ u8 phy_idx);
59 void __mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked);
60 struct mt76_txwi_cache *mt76_rx_token_release(struct mt76_dev *dev, int token);
61 int mt76_rx_token_consume(struct mt76_dev *dev, void *ptr,
developer2cd12162024-04-18 17:29:00 +080062diff --git a/mt76_connac_mac.c b/mt76_connac_mac.c
developer05f3b2b2024-08-19 19:17:34 +080063index 630c6402..a92c261d 100644
developer2cd12162024-04-18 17:29:00 +080064--- a/mt76_connac_mac.c
65+++ b/mt76_connac_mac.c
66@@ -1178,6 +1178,8 @@ void mt76_connac2_tx_token_put(struct mt76_dev *dev)
67 idr_for_each_entry(&dev->token, txwi, id) {
68 mt76_connac2_txwi_free(dev, txwi, NULL, NULL);
69 dev->token_count--;
70+ if (dev->num_phy > 1 && dev->phys[txwi->phy_idx])
71+ dev->phys[txwi->phy_idx]->tokens--;
72 }
73 spin_unlock_bh(&dev->token_lock);
74 idr_destroy(&dev->token);
developera46f6132024-03-26 14:09:54 +080075diff --git a/mt7915/init.c b/mt7915/init.c
developer05f3b2b2024-08-19 19:17:34 +080076index 46762827..ea9bc735 100644
developera46f6132024-03-26 14:09:54 +080077--- a/mt7915/init.c
78+++ b/mt7915/init.c
developer05f3b2b2024-08-19 19:17:34 +080079@@ -1223,6 +1223,8 @@ int mt7915_register_device(struct mt7915_dev *dev)
developera46f6132024-03-26 14:09:54 +080080
81 dev->dbdc_support = mt7915_band_config(dev);
82
83+ dev->mt76.num_phy = 1 + !!dev->dbdc_support;
84+
85 phy2 = mt7915_alloc_ext_phy(dev);
86 if (IS_ERR(phy2))
87 return PTR_ERR(phy2);
developer05f3b2b2024-08-19 19:17:34 +080088@@ -1255,6 +1257,7 @@ int mt7915_register_device(struct mt7915_dev *dev)
developera46f6132024-03-26 14:09:54 +080089 }
90
91 dev->recovery.hw_init_done = true;
92+ dev->mt76.token_threshold = dev->mt76.token_size / dev->mt76.num_phy;
93
94 ret = mt7915_init_debugfs(&dev->phy);
95 if (ret)
96diff --git a/mt7915/mac.c b/mt7915/mac.c
developer05f3b2b2024-08-19 19:17:34 +080097index a5d0b096..4604a682 100644
developera46f6132024-03-26 14:09:54 +080098--- a/mt7915/mac.c
99+++ b/mt7915/mac.c
100@@ -738,6 +738,7 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
101 struct mt76_connac_fw_txp *txp;
102 struct mt76_txwi_cache *t;
103 int id, i, nbuf = tx_info->nbuf - 1;
104+ u8 phy_idx = (info->hw_queue & MT_TX_HW_QUEUE_PHY) >> 2;
105 u8 *txwi = (u8 *)txwi_ptr;
106 int pid;
107
108@@ -761,7 +762,7 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
109 t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size);
110 t->skb = tx_info->skb;
111
112- id = mt76_token_consume(mdev, &t);
113+ id = mt76_token_consume(mdev, &t, phy_idx);
114 if (id < 0)
115 return id;
116
117diff --git a/mt7921/pci_mac.c b/mt7921/pci_mac.c
developer05f3b2b2024-08-19 19:17:34 +0800118index 031ba9aa..4c69c55c 100644
developera46f6132024-03-26 14:09:54 +0800119--- a/mt7921/pci_mac.c
120+++ b/mt7921/pci_mac.c
121@@ -27,7 +27,7 @@ int mt7921e_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
122 t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size);
123 t->skb = tx_info->skb;
124
125- id = mt76_token_consume(mdev, &t);
126+ id = mt76_token_consume(mdev, &t, 0);
127 if (id < 0)
128 return id;
129
130diff --git a/mt7925/pci_mac.c b/mt7925/pci_mac.c
developer05f3b2b2024-08-19 19:17:34 +0800131index 9fca8879..f1d615c0 100644
developera46f6132024-03-26 14:09:54 +0800132--- a/mt7925/pci_mac.c
133+++ b/mt7925/pci_mac.c
134@@ -27,7 +27,7 @@ int mt7925e_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
135 t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size);
136 t->skb = tx_info->skb;
137
138- id = mt76_token_consume(mdev, &t);
139+ id = mt76_token_consume(mdev, &t, 0);
140 if (id < 0)
141 return id;
142
143diff --git a/mt7996/init.c b/mt7996/init.c
developer05f3b2b2024-08-19 19:17:34 +0800144index 283df84f..d191a7b7 100644
developera46f6132024-03-26 14:09:54 +0800145--- a/mt7996/init.c
146+++ b/mt7996/init.c
developer05f3b2b2024-08-19 19:17:34 +0800147@@ -635,6 +635,8 @@ static int mt7996_register_phy(struct mt7996_dev *dev, struct mt7996_phy *phy,
developera46f6132024-03-26 14:09:54 +0800148 mtk_wed_device_start(&dev->mt76.mmio.wed_hif2, irq_mask);
149 }
150
151+ dev->mt76.num_phy++;
152+
153 return 0;
154
155 error:
156@@ -1330,6 +1332,8 @@ int mt7996_register_device(struct mt7996_dev *dev)
157 if (ret)
158 return ret;
159
160+ dev->mt76.num_phy = 1;
161+
162 ret = mt7996_register_phy(dev, mt7996_phy2(dev), MT_BAND1);
163 if (ret)
164 return ret;
165@@ -1342,6 +1346,7 @@ int mt7996_register_device(struct mt7996_dev *dev)
166
167 dev->recovery.hw_init_done = true;
168
169+ dev->mt76.token_threshold = dev->mt76.token_size / dev->mt76.num_phy;
170 ret = mt7996_init_debugfs(&dev->phy);
171 if (ret)
172 goto error;
173diff --git a/mt7996/mac.c b/mt7996/mac.c
developer05f3b2b2024-08-19 19:17:34 +0800174index bc7111a7..aa19120b 100644
developera46f6132024-03-26 14:09:54 +0800175--- a/mt7996/mac.c
176+++ b/mt7996/mac.c
177@@ -922,6 +922,7 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
178 struct mt76_txwi_cache *t;
179 int id, i, pid, nbuf = tx_info->nbuf - 1;
180 bool is_8023 = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP;
181+ u8 phy_idx = (info->hw_queue & MT_TX_HW_QUEUE_PHY) >> 2;
182 u8 *txwi = (u8 *)txwi_ptr;
183
184 if (unlikely(tx_info->skb->len <= ETH_HLEN))
185@@ -933,7 +934,7 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
186 t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size);
187 t->skb = tx_info->skb;
188
189- id = mt76_token_consume(mdev, &t);
190+ id = mt76_token_consume(mdev, &t, phy_idx);
191 if (id < 0)
192 return id;
193
194diff --git a/tx.c b/tx.c
developer05f3b2b2024-08-19 19:17:34 +0800195index ab42f69b..0fdf7d83 100644
developera46f6132024-03-26 14:09:54 +0800196--- a/tx.c
197+++ b/tx.c
198@@ -825,16 +825,30 @@ void __mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked)
199 }
200 EXPORT_SYMBOL_GPL(__mt76_set_tx_blocked);
201
202-int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi)
203+int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi,
204+ u8 phy_idx)
205 {
206+ struct mt76_phy *phy = phy_idx < __MT_MAX_BAND ? dev->phys[phy_idx] : NULL;
207 int token;
208
209 spin_lock_bh(&dev->token_lock);
210
211+ if (dev->num_phy > 1 && phy && phy->tokens > dev->token_threshold) {
212+ spin_unlock_bh(&dev->token_lock);
213+
214+ return -EINVAL;
215+ }
216+
217 token = idr_alloc(&dev->token, *ptxwi, 0, dev->token_size, GFP_ATOMIC);
218- if (token >= 0)
219+ if (token >= 0) {
220 dev->token_count++;
221
222+ if (dev->num_phy > 1 && phy) {
223+ (*ptxwi)->phy_idx = phy_idx;
224+ phy->tokens++;
225+ }
226+ }
227+
228 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
229 if (mtk_wed_device_active(&dev->mmio.wed) &&
230 token >= dev->mmio.wed.wlan.token_start)
231@@ -878,6 +892,8 @@ mt76_token_release(struct mt76_dev *dev, int token, bool *wake)
232 txwi = idr_remove(&dev->token, token);
233 if (txwi) {
234 dev->token_count--;
235+ if (dev->num_phy > 1 && dev->phys[txwi->phy_idx])
236+ dev->phys[txwi->phy_idx]->tokens--;
237
238 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
239 if (mtk_wed_device_active(&dev->mmio.wed) &&
240--
2412.18.0
242