blob: 4bf0dc1754362d4b2593ded29be2c977d91360ee [file] [log] [blame]
developer1d6610e2022-12-14 13:09:20 +08001From c213af98be4f1ebe14930ce180a0c33b9180a339 Mon Sep 17 00:00:00 2001
2From: Shayne Chen <shayne.chen@mediatek.com>
3Date: Mon, 5 Dec 2022 18:21:51 +0800
4Subject: [PATCH 1129/1129] mt76: mt7915: add bf backoff limit table support
5
6Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
7---
8 eeprom.c | 25 +++++++++-
9 mt76.h | 8 +++
10 mt7915/debugfs.c | 73 ++++++++++++++++++++++++++--
11 mt7915/mcu.c | 124 +++++++++++++++++++++++++++++++++++------------
12 mt7915/mcu.h | 6 +++
13 mt7915/mt7915.h | 4 +-
14 6 files changed, 203 insertions(+), 37 deletions(-)
15
16diff --git a/eeprom.c b/eeprom.c
17index aac70efb..6290156f 100644
18--- a/eeprom.c
19+++ b/eeprom.c
20@@ -308,7 +308,8 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy,
21 if (!mcs_rates)
22 mcs_rates = 10;
23
24- memset(dest, target_power, sizeof(*dest));
25+ memset(dest, target_power, sizeof(*dest) - sizeof(dest->path));
26+ memset(&dest->path, 0, sizeof(dest->path));
27
28 if (!IS_ENABLED(CONFIG_OF))
29 return target_power;
30@@ -361,6 +362,28 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy,
31 ARRAY_SIZE(dest->ru), val, len,
32 target_power, txs_delta, &max_power);
33
34+ val = mt76_get_of_array(np, "paths-cck", &len, ARRAY_SIZE(dest->path.cck));
35+ mt76_apply_array_limit(dest->path.cck, ARRAY_SIZE(dest->path.cck), val,
36+ target_power, txs_delta, &max_power);
37+
38+ val = mt76_get_of_array(np, "paths-ofdm", &len, ARRAY_SIZE(dest->path.ofdm));
39+ mt76_apply_array_limit(dest->path.ofdm, ARRAY_SIZE(dest->path.ofdm), val,
40+ target_power, txs_delta, &max_power);
41+
42+ val = mt76_get_of_array(np, "paths-ofdm-bf", &len, ARRAY_SIZE(dest->path.ofdm_bf));
43+ mt76_apply_array_limit(dest->path.ofdm_bf, ARRAY_SIZE(dest->path.ofdm_bf), val,
44+ target_power, txs_delta, &max_power);
45+
46+ val = mt76_get_of_array(np, "paths-ru", &len, ARRAY_SIZE(dest->path.ru[0]) + 1);
47+ mt76_apply_multi_array_limit(dest->path.ru[0], ARRAY_SIZE(dest->path.ru[0]),
48+ ARRAY_SIZE(dest->path.ru), val, len,
49+ target_power, txs_delta, &max_power);
50+
51+ val = mt76_get_of_array(np, "paths-ru-bf", &len, ARRAY_SIZE(dest->path.ru_bf[0]) + 1);
52+ mt76_apply_multi_array_limit(dest->path.ru_bf[0], ARRAY_SIZE(dest->path.ru_bf[0]),
53+ ARRAY_SIZE(dest->path.ru_bf), val, len,
54+ target_power, txs_delta, &max_power);
55+
56 return max_power;
57 }
58 EXPORT_SYMBOL_GPL(mt76_get_rate_power_limits);
59diff --git a/mt76.h b/mt76.h
60index d102333b..01baceaf 100644
61--- a/mt76.h
62+++ b/mt76.h
63@@ -900,6 +900,14 @@ struct mt76_power_limits {
64 s8 ofdm[8];
65 s8 mcs[4][10];
66 s8 ru[7][12];
67+
68+ struct {
69+ s8 cck[4];
70+ s8 ofdm[4];
71+ s8 ofdm_bf[4];
72+ s8 ru[7][10];
73+ s8 ru_bf[7][10];
74+ } path;
75 };
76
77 struct mt76_ethtool_worker_info {
78diff --git a/mt7915/debugfs.c b/mt7915/debugfs.c
79index f1f3f2f3..3ef2148b 100644
80--- a/mt7915/debugfs.c
81+++ b/mt7915/debugfs.c
82@@ -1024,7 +1024,7 @@ mt7915_rate_txpower_get(struct file *file, char __user *user_buf,
83 if (!buf)
84 return -ENOMEM;
85
86- ret = mt7915_mcu_get_txpower_sku(phy, txpwr, sizeof(txpwr));
87+ ret = mt7915_mcu_get_txpower_sku(phy, txpwr, sizeof(txpwr), TX_POWER_INFO_RATE);
88 if (ret)
89 goto out;
90
91@@ -1134,7 +1134,7 @@ mt7915_rate_txpower_set(struct file *file, const char __user *user_buf,
92
93 mutex_lock(&dev->mt76.mutex);
94 ret = mt7915_mcu_get_txpower_sku(phy, req.txpower_sku,
95- sizeof(req.txpower_sku));
96+ sizeof(req.txpower_sku), TX_POWER_INFO_RATE);
97 if (ret)
98 goto out;
99
100@@ -1176,7 +1176,7 @@ out:
101 return ret ? ret : count;
102 }
103
104-static const struct file_operations mt7915_rate_txpower_fops = {
105+static const struct file_operations mt7915_txpower_fops = {
106 .write = mt7915_rate_txpower_set,
107 .read = mt7915_rate_txpower_get,
108 .open = simple_open,
109@@ -1184,6 +1184,69 @@ static const struct file_operations mt7915_rate_txpower_fops = {
110 .llseek = default_llseek,
111 };
112
113+static int
114+mt7915_path_txpower_show(struct seq_file *file)
115+{
116+ struct mt7915_phy *phy = file->private;
117+ s8 txpower[MT7915_SKU_PATH_NUM], *buf = txpower;
118+ int ret;
119+
120+#define PATH_POWER_SHOW(_name, _len, _skip) do { \
121+ if (_skip) { \
122+ buf -= 1; \
123+ *buf = 0; \
124+ } \
125+ mt76_seq_puts_array(file, _name, buf, _len); \
126+ buf += _len; \
127+ } while(0)
128+
129+ seq_printf(file, "\n%*c", 11, ' ');
130+ seq_printf(file, "1T1S/2T1S/3T1S/4T1S/2T2S/3T2S/4T2S/3T3S/4T3S/4T4S\n");
131+ ret = mt7915_mcu_get_txpower_sku(phy, txpower, sizeof(txpower),
132+ TX_POWER_INFO_PATH);
133+ if (ret)
134+ return ret;
135+
136+ PATH_POWER_SHOW("CCK", 4, 0);
137+ PATH_POWER_SHOW("OFDM", 4, 0);
138+ PATH_POWER_SHOW("BF-OFDM", 4, 1);
139+
140+ PATH_POWER_SHOW("HT20", 10, 0);
141+ PATH_POWER_SHOW("BF-HT20", 10, 1);
142+ PATH_POWER_SHOW("HT40", 10, 0);
143+ PATH_POWER_SHOW("BF-HT40", 10, 1);
144+
145+ PATH_POWER_SHOW("RU242", 10, 0);
146+ PATH_POWER_SHOW("BF-RU242", 10, 1);
147+ PATH_POWER_SHOW("RU484", 10, 0);
148+ PATH_POWER_SHOW("BF-RU484", 10, 1);
149+ PATH_POWER_SHOW("RU996", 10, 0);
150+ PATH_POWER_SHOW("BF-RU996", 10, 1);
151+ PATH_POWER_SHOW("RU2x996", 10, 0);
152+ PATH_POWER_SHOW("BF-RU2x996", 10, 1);
153+ PATH_POWER_SHOW("RU26", 10, 0);
154+ PATH_POWER_SHOW("BF-RU26", 10, 0);
155+ PATH_POWER_SHOW("RU52", 10, 0);
156+ PATH_POWER_SHOW("BF-RU52", 10, 0);
157+ PATH_POWER_SHOW("RU106", 10, 0);
158+ PATH_POWER_SHOW("BF-RU106", 10, 0);
159+#undef PATH_POWER_SHOW
160+
161+ return 0;
162+}
163+
164+static int
165+mt7915_txpower_path_show(struct seq_file *file, void *data)
166+{
167+ struct mt7915_phy *phy = file->private;
168+
169+ seq_printf(file, "\nBand %d\n", phy != &phy->dev->phy);
170+
171+ return mt7915_path_txpower_show(file);
172+}
173+
174+DEFINE_SHOW_ATTRIBUTE(mt7915_txpower_path);
175+
176 static int
177 mt7915_twt_stats(struct seq_file *s, void *data)
178 {
179@@ -1270,7 +1333,9 @@ int mt7915_init_debugfs(struct mt7915_phy *phy)
180 debugfs_create_file("implicit_txbf", 0600, dir, dev,
181 &fops_implicit_txbf);
182 debugfs_create_file("txpower_sku", 0400, dir, phy,
183- &mt7915_rate_txpower_fops);
184+ &mt7915_txpower_fops);
185+ debugfs_create_file("txpower_path", 0400, dir, phy,
186+ &mt7915_txpower_path_fops);
187 debugfs_create_devm_seqfile(dev->mt76.dev, "twt_stats", dir,
188 mt7915_twt_stats);
189 debugfs_create_file("rf_regval", 0600, dir, dev, &fops_rf_regval);
190diff --git a/mt7915/mcu.c b/mt7915/mcu.c
191index 785c3c10..4b7ad450 100644
192--- a/mt7915/mcu.c
193+++ b/mt7915/mcu.c
194@@ -3259,7 +3259,8 @@ int mt7915_mcu_set_txpower_frame(struct mt7915_phy *phy,
195 int ret;
196 s8 txpower_sku[MT7915_SKU_RATE_NUM];
197
198- ret = mt7915_mcu_get_txpower_sku(phy, txpower_sku, sizeof(txpower_sku));
199+ ret = mt7915_mcu_get_txpower_sku(phy, txpower_sku, sizeof(txpower_sku),
200+ TX_POWER_INFO_RATE);
201 if (ret)
202 return ret;
203
204@@ -3301,51 +3302,98 @@ int mt7915_mcu_set_txpower_frame(struct mt7915_phy *phy,
205
206 int mt7915_mcu_set_txpower_sku(struct mt7915_phy *phy)
207 {
208+#define TX_POWER_LIMIT_TABLE_RATE 0
209+#define TX_POWER_LIMIT_TABLE_PATH 1
210 struct mt7915_dev *dev = phy->dev;
211 struct mt76_phy *mphy = phy->mt76;
212 struct ieee80211_hw *hw = mphy->hw;
213- struct mt7915_mcu_txpower_sku req = {
214+ struct mt7915_sku_val {
215+ u8 format_id;
216+ u8 limit_type;
217+ u8 band_idx;
218+ } __packed hdr = {
219 .format_id = TX_POWER_LIMIT_TABLE,
220+ .limit_type = TX_POWER_LIMIT_TABLE_RATE,
221 .band_idx = phy->mt76->band_idx,
222 };
223- struct mt76_power_limits limits_array;
224- s8 *la = (s8 *)&limits_array;
225- int i, idx;
226- int tx_power;
227+ int i, ret, tx_power;
228+ const u8 *len = mt7915_sku_group_len;
229+ struct mt76_power_limits la = {};
230+ struct sk_buff *skb;
231
232 tx_power = mt7915_get_power_bound(phy, hw->conf.power_level);
233 tx_power = mt76_get_rate_power_limits(mphy, mphy->chandef.chan,
234- &limits_array, tx_power);
235+ &la, tx_power);
236 mphy->txpower_cur = tx_power;
237
238- for (i = 0, idx = 0; i < ARRAY_SIZE(mt7915_sku_group_len); i++) {
239- u8 mcs_num, len = mt7915_sku_group_len[i];
240- int j;
241+ skb = mt76_mcu_msg_alloc(&dev->mt76, NULL,
242+ sizeof(hdr) + MT7915_SKU_RATE_NUM);
243+ if (!skb)
244+ return -ENOMEM;
245
246- if (i >= SKU_HT_BW20 && i <= SKU_VHT_BW160) {
247- mcs_num = 10;
248+ skb_put_data(skb, &hdr, sizeof(hdr));
249+ skb_put_data(skb, &la.cck, len[SKU_CCK] + len[SKU_OFDM]);
250+ skb_put_data(skb, &la.mcs[0], len[SKU_HT_BW20]);
251+ skb_put_data(skb, &la.mcs[1], len[SKU_HT_BW40]);
252
253- if (i == SKU_HT_BW20 || i == SKU_VHT_BW20)
254- la = (s8 *)&limits_array + 12;
255- } else {
256- mcs_num = len;
257- }
258+ /* vht */
259+ for (i = 0; i < 4; i++) {
260+ skb_put_data(skb, &la.mcs[i], sizeof(la.mcs[i]));
261+ skb_put_zero(skb, 2); /* padding */
262+ }
263+
264+ /* he */
265+ skb_put_data(skb, &la.ru[0], sizeof(la.ru));
266+
267+ ret = mt76_mcu_skb_send_msg(&dev->mt76, skb,
268+ MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), true);
269+ if (ret)
270+ return ret;
271+
272+ /* only set per-path power table when it's configured */
273+ if (!la.path.ofdm[0])
274+ return 0;
275
276- for (j = 0; j < min_t(u8, mcs_num, len); j++)
277- req.txpower_sku[idx + j] = la[j];
278+ skb = mt76_mcu_msg_alloc(&dev->mt76, NULL,
279+ sizeof(hdr) + MT7915_SKU_PATH_NUM);
280+ if (!skb)
281+ return -ENOMEM;
282
283- la += mcs_num;
284- idx += len;
285+ hdr.limit_type = TX_POWER_LIMIT_TABLE_PATH;
286+ skb_put_data(skb, &hdr, sizeof(hdr));
287+ skb_put_data(skb, &la.path.cck, sizeof(la.path.cck));
288+ skb_put_data(skb, &la.path.ofdm, sizeof(la.path.ofdm));
289+ skb_put_data(skb, &la.path.ofdm_bf[1], sizeof(la.path.ofdm_bf) - 1);
290+
291+ /* HT20 and HT40 */
292+ skb_put_data(skb, &la.path.ru[0], sizeof(la.path.ru[0]));
293+ skb_put_data(skb, &la.path.ru_bf[0][1], sizeof(la.path.ru_bf[0]) - 1);
294+ skb_put_data(skb, &la.path.ru[1], sizeof(la.path.ru[1]));
295+ skb_put_data(skb, &la.path.ru_bf[1][1], sizeof(la.path.ru_bf[1]) - 1);
296+
297+ /* start from non-bf and bf fields of
298+ * BW20/RU242, BW40/RU484, BW80/RU996, BW160/RU2x996,
299+ * RU26, RU52, and RU106
300+ */
301+ for (i = 7; i < 21; i++) {
302+ bool bf = !(i % 2);
303+ u8 idx = (i - 7) / 2;
304+ s8 *buf = bf ? la.path.ru_bf[idx] : la.path.ru[idx];
305+
306+ /* The non-bf fields of RU26 to RU106 are special cases */
307+ if (bf && i < 15)
308+ skb_put_data(skb, buf + 1, 9);
309+ else
310+ skb_put_data(skb, buf, 10);
311 }
312
313- return mt76_mcu_send_msg(&dev->mt76,
314- MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), &req,
315- sizeof(req), true);
316+ return mt76_mcu_skb_send_msg(&dev->mt76, skb,
317+ MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), true);
318 }
319
320-int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len)
321+int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len,
322+ u8 category)
323 {
324-#define RATE_POWER_INFO 2
325 struct mt7915_dev *dev = phy->dev;
326 struct {
327 u8 format_id;
328@@ -3354,10 +3402,9 @@ int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len)
329 u8 _rsv;
330 } __packed req = {
331 .format_id = TX_POWER_LIMIT_INFO,
332- .category = RATE_POWER_INFO,
333+ .category = category,
334 .band_idx = phy->mt76->band_idx,
335 };
336- s8 txpower_sku[MT7915_SKU_RATE_NUM][2];
337 struct sk_buff *skb;
338 int ret, i;
339
340@@ -3367,9 +3414,15 @@ int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len)
341 if (ret)
342 return ret;
343
344- memcpy(txpower_sku, skb->data + 4, sizeof(txpower_sku));
345- for (i = 0; i < len; i++)
346- txpower[i] = txpower_sku[i][req.band_idx];
347+ if (category == TX_POWER_INFO_RATE) {
348+ s8 res[MT7915_SKU_RATE_NUM][2];
349+
350+ memcpy(res, skb->data + 4, sizeof(res));
351+ for (i = 0; i < len; i++)
352+ txpower[i] = res[i][req.band_idx];
353+ } else if (category == TX_POWER_INFO_PATH) {
354+ memcpy(txpower, skb->data + 4, len);
355+ }
356
357 dev_kfree_skb(skb);
358
359@@ -3411,9 +3464,18 @@ int mt7915_mcu_set_sku_en(struct mt7915_phy *phy, bool enable)
360 .band_idx = phy->mt76->band_idx,
361 .sku_enable = enable,
362 };
363+ int ret;
364+
365+ ret = mt76_mcu_send_msg(&dev->mt76,
366+ MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), &req,
367+ sizeof(req), true);
368+ if (ret)
369+ return ret;
370
371 pr_info("%s: enable = %d\n", __func__, enable);
372
373+ req.format_id = TX_POWER_LIMIT_PATH_ENABLE;
374+
375 return mt76_mcu_send_msg(&dev->mt76,
376 MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), &req,
377 sizeof(req), true);
378diff --git a/mt7915/mcu.h b/mt7915/mcu.h
379index 08476eb6..d110e210 100644
380--- a/mt7915/mcu.h
381+++ b/mt7915/mcu.h
382@@ -446,12 +446,18 @@ enum {
383
384 enum {
385 TX_POWER_LIMIT_ENABLE,
386+ TX_POWER_LIMIT_PATH_ENABLE = 0x3,
387 TX_POWER_LIMIT_TABLE = 0x4,
388 TX_POWER_LIMIT_INFO = 0x7,
389 TX_POWER_LIMIT_FRAME = 0x11,
390 TX_POWER_LIMIT_FRAME_MIN = 0x12,
391 };
392
393+enum {
394+ TX_POWER_INFO_PATH = 1,
395+ TX_POWER_INFO_RATE,
396+};
397+
398 enum {
399 SPR_ENABLE = 0x1,
400 SPR_ENABLE_SD = 0x3,
401diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
402index 2d3769c6..2e6519e7 100644
403--- a/mt7915/mt7915.h
404+++ b/mt7915/mt7915.h
405@@ -73,6 +73,7 @@
406 #define MT7915_CDEV_THROTTLE_MAX 99
407
408 #define MT7915_SKU_RATE_NUM 161
409+#define MT7915_SKU_PATH_NUM 185
410
411 #define MT7915_MAX_TWT_AGRT 16
412 #define MT7915_MAX_STA_TWT_AGRT 8
413@@ -624,7 +625,8 @@ int mt7915_mcu_set_test_param(struct mt7915_dev *dev, u8 param, bool test_mode,
414 int mt7915_mcu_set_ser(struct mt7915_dev *dev, u8 action, u8 set, u8 band);
415 int mt7915_mcu_set_sku_en(struct mt7915_phy *phy, bool enable);
416 int mt7915_mcu_set_txpower_sku(struct mt7915_phy *phy);
417-int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len);
418+int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len,
419+ u8 category);
420 int mt7915_mcu_set_txpower_frame_min(struct mt7915_phy *phy, s8 txpower);
421 int mt7915_mcu_set_txpower_frame(struct mt7915_phy *phy,
422 struct ieee80211_vif *vif,
423--
4242.25.1
425