blob: 64dcad93c729e34e597ec6160ec60ada672c26de [file] [log] [blame]
developera46f6132024-03-26 14:09:54 +08001From 0c5bff805c1692b90a8f5935876b76dff903f8c4 Mon Sep 17 00:00:00 2001
2From: Peter Chiu <chui-hao.chiu@mediatek.com>
3Date: Mon, 29 Jan 2024 15:33:24 +0800
4Subject: [PATCH 13/14] wifi: mt76: mt7915: limit per-band token count
5
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>
10---
11 mt76.h | 8 +++++++-
12 mt7915/init.c | 3 +++
13 mt7915/mac.c | 3 ++-
14 mt7921/pci_mac.c | 2 +-
15 mt7925/pci_mac.c | 2 +-
16 mt7996/init.c | 5 +++++
17 mt7996/mac.c | 3 ++-
18 tx.c | 20 ++++++++++++++++++--
19 8 files changed, 39 insertions(+), 7 deletions(-)
20
21diff --git a/mt76.h b/mt76.h
22index 52a20868..9ad4f8e1 100644
23--- a/mt76.h
24+++ b/mt76.h
25@@ -402,6 +402,8 @@ struct mt76_txwi_cache {
26 struct list_head list;
27 dma_addr_t dma_addr;
28
29+ u8 phy_idx;
30+
31 union {
32 struct sk_buff *skb;
33 void *ptr;
34@@ -814,6 +816,7 @@ struct mt76_phy {
35 bool al;
36 u8 pin;
37 } leds;
38+ int tokens;
39 };
40
41 struct mt76_dev {
42@@ -867,6 +870,8 @@ struct mt76_dev {
43 u16 wed_token_count;
44 u16 token_count;
45 u16 token_size;
46+ u16 token_threshold;
47+ u8 num_phy;
48
49 spinlock_t rx_token_lock;
50 struct idr rx_token;
51@@ -1657,7 +1662,8 @@ static inline bool mt76_queue_is_wed_rx(struct mt76_queue *q)
52
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_txwi_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/mt7915/init.c b/mt7915/init.c
62index 4f1e6e71..d6bcc6f5 100644
63--- a/mt7915/init.c
64+++ b/mt7915/init.c
65@@ -1225,6 +1225,8 @@ int mt7915_register_device(struct mt7915_dev *dev)
66
67 dev->dbdc_support = mt7915_band_config(dev);
68
69+ dev->mt76.num_phy = 1 + !!dev->dbdc_support;
70+
71 phy2 = mt7915_alloc_ext_phy(dev);
72 if (IS_ERR(phy2))
73 return PTR_ERR(phy2);
74@@ -1257,6 +1259,7 @@ int mt7915_register_device(struct mt7915_dev *dev)
75 }
76
77 dev->recovery.hw_init_done = true;
78+ dev->mt76.token_threshold = dev->mt76.token_size / dev->mt76.num_phy;
79
80 ret = mt7915_init_debugfs(&dev->phy);
81 if (ret)
82diff --git a/mt7915/mac.c b/mt7915/mac.c
83index a5d0b096..4604a682 100644
84--- a/mt7915/mac.c
85+++ b/mt7915/mac.c
86@@ -738,6 +738,7 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
87 struct mt76_connac_fw_txp *txp;
88 struct mt76_txwi_cache *t;
89 int id, i, nbuf = tx_info->nbuf - 1;
90+ u8 phy_idx = (info->hw_queue & MT_TX_HW_QUEUE_PHY) >> 2;
91 u8 *txwi = (u8 *)txwi_ptr;
92 int pid;
93
94@@ -761,7 +762,7 @@ int mt7915_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
95 t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size);
96 t->skb = tx_info->skb;
97
98- id = mt76_token_consume(mdev, &t);
99+ id = mt76_token_consume(mdev, &t, phy_idx);
100 if (id < 0)
101 return id;
102
103diff --git a/mt7921/pci_mac.c b/mt7921/pci_mac.c
104index c866144f..3282507a 100644
105--- a/mt7921/pci_mac.c
106+++ b/mt7921/pci_mac.c
107@@ -27,7 +27,7 @@ int mt7921e_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
108 t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size);
109 t->skb = tx_info->skb;
110
111- id = mt76_token_consume(mdev, &t);
112+ id = mt76_token_consume(mdev, &t, 0);
113 if (id < 0)
114 return id;
115
116diff --git a/mt7925/pci_mac.c b/mt7925/pci_mac.c
117index 9fca8879..f1d615c0 100644
118--- a/mt7925/pci_mac.c
119+++ b/mt7925/pci_mac.c
120@@ -27,7 +27,7 @@ int mt7925e_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
121 t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size);
122 t->skb = tx_info->skb;
123
124- id = mt76_token_consume(mdev, &t);
125+ id = mt76_token_consume(mdev, &t, 0);
126 if (id < 0)
127 return id;
128
129diff --git a/mt7996/init.c b/mt7996/init.c
130index 9aa97e4a..7549a108 100644
131--- a/mt7996/init.c
132+++ b/mt7996/init.c
133@@ -634,6 +634,8 @@ static int mt7996_register_phy(struct mt7996_dev *dev, struct mt7996_phy *phy,
134 mtk_wed_device_start(&dev->mt76.mmio.wed_hif2, irq_mask);
135 }
136
137+ dev->mt76.num_phy++;
138+
139 return 0;
140
141 error:
142@@ -1330,6 +1332,8 @@ int mt7996_register_device(struct mt7996_dev *dev)
143 if (ret)
144 return ret;
145
146+ dev->mt76.num_phy = 1;
147+
148 ret = mt7996_register_phy(dev, mt7996_phy2(dev), MT_BAND1);
149 if (ret)
150 return ret;
151@@ -1342,6 +1346,7 @@ int mt7996_register_device(struct mt7996_dev *dev)
152
153 dev->recovery.hw_init_done = true;
154
155+ dev->mt76.token_threshold = dev->mt76.token_size / dev->mt76.num_phy;
156 ret = mt7996_init_debugfs(&dev->phy);
157 if (ret)
158 goto error;
159diff --git a/mt7996/mac.c b/mt7996/mac.c
160index bc7111a7..aa19120b 100644
161--- a/mt7996/mac.c
162+++ b/mt7996/mac.c
163@@ -922,6 +922,7 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
164 struct mt76_txwi_cache *t;
165 int id, i, pid, nbuf = tx_info->nbuf - 1;
166 bool is_8023 = info->flags & IEEE80211_TX_CTL_HW_80211_ENCAP;
167+ u8 phy_idx = (info->hw_queue & MT_TX_HW_QUEUE_PHY) >> 2;
168 u8 *txwi = (u8 *)txwi_ptr;
169
170 if (unlikely(tx_info->skb->len <= ETH_HLEN))
171@@ -933,7 +934,7 @@ int mt7996_tx_prepare_skb(struct mt76_dev *mdev, void *txwi_ptr,
172 t = (struct mt76_txwi_cache *)(txwi + mdev->drv->txwi_size);
173 t->skb = tx_info->skb;
174
175- id = mt76_token_consume(mdev, &t);
176+ id = mt76_token_consume(mdev, &t, phy_idx);
177 if (id < 0)
178 return id;
179
180diff --git a/tx.c b/tx.c
181index ab42f69b..0fdf7d83 100644
182--- a/tx.c
183+++ b/tx.c
184@@ -825,16 +825,30 @@ void __mt76_set_tx_blocked(struct mt76_dev *dev, bool blocked)
185 }
186 EXPORT_SYMBOL_GPL(__mt76_set_tx_blocked);
187
188-int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi)
189+int mt76_token_consume(struct mt76_dev *dev, struct mt76_txwi_cache **ptxwi,
190+ u8 phy_idx)
191 {
192+ struct mt76_phy *phy = phy_idx < __MT_MAX_BAND ? dev->phys[phy_idx] : NULL;
193 int token;
194
195 spin_lock_bh(&dev->token_lock);
196
197+ if (dev->num_phy > 1 && phy && phy->tokens > dev->token_threshold) {
198+ spin_unlock_bh(&dev->token_lock);
199+
200+ return -EINVAL;
201+ }
202+
203 token = idr_alloc(&dev->token, *ptxwi, 0, dev->token_size, GFP_ATOMIC);
204- if (token >= 0)
205+ if (token >= 0) {
206 dev->token_count++;
207
208+ if (dev->num_phy > 1 && phy) {
209+ (*ptxwi)->phy_idx = phy_idx;
210+ phy->tokens++;
211+ }
212+ }
213+
214 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
215 if (mtk_wed_device_active(&dev->mmio.wed) &&
216 token >= dev->mmio.wed.wlan.token_start)
217@@ -878,6 +892,8 @@ mt76_token_release(struct mt76_dev *dev, int token, bool *wake)
218 txwi = idr_remove(&dev->token, token);
219 if (txwi) {
220 dev->token_count--;
221+ if (dev->num_phy > 1 && dev->phys[txwi->phy_idx])
222+ dev->phys[txwi->phy_idx]->tokens--;
223
224 #ifdef CONFIG_NET_MEDIATEK_SOC_WED
225 if (mtk_wed_device_active(&dev->mmio.wed) &&
226--
2272.18.0
228