blob: bce4a14abe93da25260340d39cf350df8c95b26f [file] [log] [blame]
developer7af0f762023-05-22 15:16:16 +08001From cd39ff8dad3bfea4c0ec7ac7e71b92158cfa11b5 Mon Sep 17 00:00:00 2001
developera16be1f2022-12-14 13:09:20 +08002From: Shayne Chen <shayne.chen@mediatek.com>
3Date: Mon, 5 Dec 2022 18:21:51 +0800
developer7af0f762023-05-22 15:16:16 +08004Subject: [PATCH 1027/1033] wifi: mt76: mt7915: add bf backoff limit table
developerda18a742023-04-06 13:44:00 +08005 support
developera16be1f2022-12-14 13:09:20 +08006
7Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
8---
9 eeprom.c | 25 +++++++++-
10 mt76.h | 8 +++
11 mt7915/debugfs.c | 73 ++++++++++++++++++++++++++--
12 mt7915/mcu.c | 124 +++++++++++++++++++++++++++++++++++------------
13 mt7915/mcu.h | 6 +++
14 mt7915/mt7915.h | 4 +-
15 6 files changed, 203 insertions(+), 37 deletions(-)
16
17diff --git a/eeprom.c b/eeprom.c
developer8effbd32023-04-17 15:57:28 +080018index 412740f..b2df0f4 100644
developera16be1f2022-12-14 13:09:20 +080019--- a/eeprom.c
20+++ b/eeprom.c
developerda18a742023-04-06 13:44:00 +080021@@ -317,7 +317,8 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy,
developera16be1f2022-12-14 13:09:20 +080022 if (!mcs_rates)
23 mcs_rates = 10;
24
25- memset(dest, target_power, sizeof(*dest));
26+ memset(dest, target_power, sizeof(*dest) - sizeof(dest->path));
27+ memset(&dest->path, 0, sizeof(dest->path));
28
29 if (!IS_ENABLED(CONFIG_OF))
30 return target_power;
developerda18a742023-04-06 13:44:00 +080031@@ -370,6 +371,28 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy,
developera16be1f2022-12-14 13:09:20 +080032 ARRAY_SIZE(dest->ru), val, len,
33 target_power, txs_delta, &max_power);
34
35+ val = mt76_get_of_array(np, "paths-cck", &len, ARRAY_SIZE(dest->path.cck));
36+ mt76_apply_array_limit(dest->path.cck, ARRAY_SIZE(dest->path.cck), val,
37+ target_power, txs_delta, &max_power);
38+
39+ val = mt76_get_of_array(np, "paths-ofdm", &len, ARRAY_SIZE(dest->path.ofdm));
40+ mt76_apply_array_limit(dest->path.ofdm, ARRAY_SIZE(dest->path.ofdm), val,
41+ target_power, txs_delta, &max_power);
42+
43+ val = mt76_get_of_array(np, "paths-ofdm-bf", &len, ARRAY_SIZE(dest->path.ofdm_bf));
44+ mt76_apply_array_limit(dest->path.ofdm_bf, ARRAY_SIZE(dest->path.ofdm_bf), val,
45+ target_power, txs_delta, &max_power);
46+
47+ val = mt76_get_of_array(np, "paths-ru", &len, ARRAY_SIZE(dest->path.ru[0]) + 1);
48+ mt76_apply_multi_array_limit(dest->path.ru[0], ARRAY_SIZE(dest->path.ru[0]),
49+ ARRAY_SIZE(dest->path.ru), val, len,
50+ target_power, txs_delta, &max_power);
51+
52+ val = mt76_get_of_array(np, "paths-ru-bf", &len, ARRAY_SIZE(dest->path.ru_bf[0]) + 1);
53+ mt76_apply_multi_array_limit(dest->path.ru_bf[0], ARRAY_SIZE(dest->path.ru_bf[0]),
54+ ARRAY_SIZE(dest->path.ru_bf), val, len,
55+ target_power, txs_delta, &max_power);
56+
57 return max_power;
58 }
59 EXPORT_SYMBOL_GPL(mt76_get_rate_power_limits);
60diff --git a/mt76.h b/mt76.h
developer7af0f762023-05-22 15:16:16 +080061index 668ab2b..ea43716 100644
developera16be1f2022-12-14 13:09:20 +080062--- a/mt76.h
63+++ b/mt76.h
developer7af0f762023-05-22 15:16:16 +080064@@ -918,6 +918,14 @@ struct mt76_power_limits {
developera16be1f2022-12-14 13:09:20 +080065 s8 ofdm[8];
66 s8 mcs[4][10];
67 s8 ru[7][12];
68+
69+ struct {
70+ s8 cck[4];
71+ s8 ofdm[4];
72+ s8 ofdm_bf[4];
73+ s8 ru[7][10];
74+ s8 ru_bf[7][10];
75+ } path;
76 };
77
78 struct mt76_ethtool_worker_info {
79diff --git a/mt7915/debugfs.c b/mt7915/debugfs.c
developer7af0f762023-05-22 15:16:16 +080080index 9fca009..a122457 100644
developera16be1f2022-12-14 13:09:20 +080081--- a/mt7915/debugfs.c
82+++ b/mt7915/debugfs.c
developerda18a742023-04-06 13:44:00 +080083@@ -1027,7 +1027,7 @@ mt7915_rate_txpower_get(struct file *file, char __user *user_buf,
developera16be1f2022-12-14 13:09:20 +080084 if (!buf)
85 return -ENOMEM;
86
87- ret = mt7915_mcu_get_txpower_sku(phy, txpwr, sizeof(txpwr));
88+ ret = mt7915_mcu_get_txpower_sku(phy, txpwr, sizeof(txpwr), TX_POWER_INFO_RATE);
89 if (ret)
90 goto out;
91
developerda18a742023-04-06 13:44:00 +080092@@ -1137,7 +1137,7 @@ mt7915_rate_txpower_set(struct file *file, const char __user *user_buf,
developera16be1f2022-12-14 13:09:20 +080093
94 mutex_lock(&dev->mt76.mutex);
95 ret = mt7915_mcu_get_txpower_sku(phy, req.txpower_sku,
96- sizeof(req.txpower_sku));
97+ sizeof(req.txpower_sku), TX_POWER_INFO_RATE);
98 if (ret)
99 goto out;
100
developerda18a742023-04-06 13:44:00 +0800101@@ -1179,7 +1179,7 @@ out:
developera16be1f2022-12-14 13:09:20 +0800102 return ret ? ret : count;
103 }
104
105-static const struct file_operations mt7915_rate_txpower_fops = {
106+static const struct file_operations mt7915_txpower_fops = {
107 .write = mt7915_rate_txpower_set,
108 .read = mt7915_rate_txpower_get,
109 .open = simple_open,
developerda18a742023-04-06 13:44:00 +0800110@@ -1187,6 +1187,69 @@ static const struct file_operations mt7915_rate_txpower_fops = {
developera16be1f2022-12-14 13:09:20 +0800111 .llseek = default_llseek,
112 };
113
114+static int
115+mt7915_path_txpower_show(struct seq_file *file)
116+{
117+ struct mt7915_phy *phy = file->private;
118+ s8 txpower[MT7915_SKU_PATH_NUM], *buf = txpower;
119+ int ret;
120+
121+#define PATH_POWER_SHOW(_name, _len, _skip) do { \
122+ if (_skip) { \
123+ buf -= 1; \
124+ *buf = 0; \
125+ } \
126+ mt76_seq_puts_array(file, _name, buf, _len); \
127+ buf += _len; \
128+ } while(0)
129+
130+ seq_printf(file, "\n%*c", 11, ' ');
131+ seq_printf(file, "1T1S/2T1S/3T1S/4T1S/2T2S/3T2S/4T2S/3T3S/4T3S/4T4S\n");
132+ ret = mt7915_mcu_get_txpower_sku(phy, txpower, sizeof(txpower),
133+ TX_POWER_INFO_PATH);
134+ if (ret)
135+ return ret;
136+
137+ PATH_POWER_SHOW("CCK", 4, 0);
138+ PATH_POWER_SHOW("OFDM", 4, 0);
139+ PATH_POWER_SHOW("BF-OFDM", 4, 1);
140+
141+ PATH_POWER_SHOW("HT20", 10, 0);
142+ PATH_POWER_SHOW("BF-HT20", 10, 1);
143+ PATH_POWER_SHOW("HT40", 10, 0);
144+ PATH_POWER_SHOW("BF-HT40", 10, 1);
145+
146+ PATH_POWER_SHOW("RU242", 10, 0);
147+ PATH_POWER_SHOW("BF-RU242", 10, 1);
148+ PATH_POWER_SHOW("RU484", 10, 0);
149+ PATH_POWER_SHOW("BF-RU484", 10, 1);
150+ PATH_POWER_SHOW("RU996", 10, 0);
151+ PATH_POWER_SHOW("BF-RU996", 10, 1);
152+ PATH_POWER_SHOW("RU2x996", 10, 0);
153+ PATH_POWER_SHOW("BF-RU2x996", 10, 1);
154+ PATH_POWER_SHOW("RU26", 10, 0);
155+ PATH_POWER_SHOW("BF-RU26", 10, 0);
156+ PATH_POWER_SHOW("RU52", 10, 0);
157+ PATH_POWER_SHOW("BF-RU52", 10, 0);
158+ PATH_POWER_SHOW("RU106", 10, 0);
159+ PATH_POWER_SHOW("BF-RU106", 10, 0);
160+#undef PATH_POWER_SHOW
161+
162+ return 0;
163+}
164+
165+static int
166+mt7915_txpower_path_show(struct seq_file *file, void *data)
167+{
168+ struct mt7915_phy *phy = file->private;
169+
170+ seq_printf(file, "\nBand %d\n", phy != &phy->dev->phy);
171+
172+ return mt7915_path_txpower_show(file);
173+}
174+
175+DEFINE_SHOW_ATTRIBUTE(mt7915_txpower_path);
176+
177 static int
178 mt7915_twt_stats(struct seq_file *s, void *data)
179 {
developerda18a742023-04-06 13:44:00 +0800180@@ -1273,7 +1336,9 @@ int mt7915_init_debugfs(struct mt7915_phy *phy)
developera16be1f2022-12-14 13:09:20 +0800181 debugfs_create_file("implicit_txbf", 0600, dir, dev,
182 &fops_implicit_txbf);
183 debugfs_create_file("txpower_sku", 0400, dir, phy,
184- &mt7915_rate_txpower_fops);
185+ &mt7915_txpower_fops);
186+ debugfs_create_file("txpower_path", 0400, dir, phy,
187+ &mt7915_txpower_path_fops);
188 debugfs_create_devm_seqfile(dev->mt76.dev, "twt_stats", dir,
189 mt7915_twt_stats);
190 debugfs_create_file("rf_regval", 0600, dir, dev, &fops_rf_regval);
191diff --git a/mt7915/mcu.c b/mt7915/mcu.c
developer7af0f762023-05-22 15:16:16 +0800192index 7603bd8..0bec0bc 100644
developera16be1f2022-12-14 13:09:20 +0800193--- a/mt7915/mcu.c
194+++ b/mt7915/mcu.c
developer7af0f762023-05-22 15:16:16 +0800195@@ -3260,7 +3260,8 @@ int mt7915_mcu_set_txpower_frame(struct mt7915_phy *phy,
developera16be1f2022-12-14 13:09:20 +0800196 int ret;
197 s8 txpower_sku[MT7915_SKU_RATE_NUM];
198
199- ret = mt7915_mcu_get_txpower_sku(phy, txpower_sku, sizeof(txpower_sku));
200+ ret = mt7915_mcu_get_txpower_sku(phy, txpower_sku, sizeof(txpower_sku),
201+ TX_POWER_INFO_RATE);
202 if (ret)
203 return ret;
204
developer7af0f762023-05-22 15:16:16 +0800205@@ -3302,51 +3303,98 @@ int mt7915_mcu_set_txpower_frame(struct mt7915_phy *phy,
developera16be1f2022-12-14 13:09:20 +0800206
207 int mt7915_mcu_set_txpower_sku(struct mt7915_phy *phy)
208 {
209+#define TX_POWER_LIMIT_TABLE_RATE 0
210+#define TX_POWER_LIMIT_TABLE_PATH 1
211 struct mt7915_dev *dev = phy->dev;
212 struct mt76_phy *mphy = phy->mt76;
213 struct ieee80211_hw *hw = mphy->hw;
214- struct mt7915_mcu_txpower_sku req = {
215+ struct mt7915_sku_val {
216+ u8 format_id;
217+ u8 limit_type;
218+ u8 band_idx;
219+ } __packed hdr = {
220 .format_id = TX_POWER_LIMIT_TABLE,
221+ .limit_type = TX_POWER_LIMIT_TABLE_RATE,
222 .band_idx = phy->mt76->band_idx,
223 };
224- struct mt76_power_limits limits_array;
225- s8 *la = (s8 *)&limits_array;
226- int i, idx;
227- int tx_power;
228+ int i, ret, tx_power;
229+ const u8 *len = mt7915_sku_group_len;
230+ struct mt76_power_limits la = {};
231+ struct sk_buff *skb;
232
233 tx_power = mt7915_get_power_bound(phy, hw->conf.power_level);
234 tx_power = mt76_get_rate_power_limits(mphy, mphy->chandef.chan,
235- &limits_array, tx_power);
236+ &la, tx_power);
237 mphy->txpower_cur = tx_power;
238
239- for (i = 0, idx = 0; i < ARRAY_SIZE(mt7915_sku_group_len); i++) {
240- u8 mcs_num, len = mt7915_sku_group_len[i];
241- int j;
242+ skb = mt76_mcu_msg_alloc(&dev->mt76, NULL,
243+ sizeof(hdr) + MT7915_SKU_RATE_NUM);
244+ if (!skb)
245+ return -ENOMEM;
246
247- if (i >= SKU_HT_BW20 && i <= SKU_VHT_BW160) {
248- mcs_num = 10;
249+ skb_put_data(skb, &hdr, sizeof(hdr));
250+ skb_put_data(skb, &la.cck, len[SKU_CCK] + len[SKU_OFDM]);
251+ skb_put_data(skb, &la.mcs[0], len[SKU_HT_BW20]);
252+ skb_put_data(skb, &la.mcs[1], len[SKU_HT_BW40]);
253
254- if (i == SKU_HT_BW20 || i == SKU_VHT_BW20)
255- la = (s8 *)&limits_array + 12;
256- } else {
257- mcs_num = len;
258- }
259+ /* vht */
260+ for (i = 0; i < 4; i++) {
261+ skb_put_data(skb, &la.mcs[i], sizeof(la.mcs[i]));
262+ skb_put_zero(skb, 2); /* padding */
263+ }
developerc5ce7502022-12-19 11:33:22 +0800264
265- for (j = 0; j < min_t(u8, mcs_num, len); j++)
266- req.txpower_sku[idx + j] = la[j];
developera16be1f2022-12-14 13:09:20 +0800267+ /* he */
268+ skb_put_data(skb, &la.ru[0], sizeof(la.ru));
developerc5ce7502022-12-19 11:33:22 +0800269
270- la += mcs_num;
271- idx += len;
developera16be1f2022-12-14 13:09:20 +0800272+ ret = mt76_mcu_skb_send_msg(&dev->mt76, skb,
273+ MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), true);
274+ if (ret)
275+ return ret;
276+
277+ /* only set per-path power table when it's configured */
278+ if (!la.path.ofdm[0])
279+ return 0;
developerc5ce7502022-12-19 11:33:22 +0800280+
developera16be1f2022-12-14 13:09:20 +0800281+ skb = mt76_mcu_msg_alloc(&dev->mt76, NULL,
282+ sizeof(hdr) + MT7915_SKU_PATH_NUM);
283+ if (!skb)
284+ return -ENOMEM;
developerc5ce7502022-12-19 11:33:22 +0800285+
developera16be1f2022-12-14 13:09:20 +0800286+ hdr.limit_type = TX_POWER_LIMIT_TABLE_PATH;
287+ skb_put_data(skb, &hdr, sizeof(hdr));
288+ skb_put_data(skb, &la.path.cck, sizeof(la.path.cck));
289+ skb_put_data(skb, &la.path.ofdm, sizeof(la.path.ofdm));
290+ skb_put_data(skb, &la.path.ofdm_bf[1], sizeof(la.path.ofdm_bf) - 1);
291+
292+ /* HT20 and HT40 */
293+ skb_put_data(skb, &la.path.ru[0], sizeof(la.path.ru[0]));
294+ skb_put_data(skb, &la.path.ru_bf[0][1], sizeof(la.path.ru_bf[0]) - 1);
295+ skb_put_data(skb, &la.path.ru[1], sizeof(la.path.ru[1]));
296+ skb_put_data(skb, &la.path.ru_bf[1][1], sizeof(la.path.ru_bf[1]) - 1);
297+
298+ /* start from non-bf and bf fields of
299+ * BW20/RU242, BW40/RU484, BW80/RU996, BW160/RU2x996,
300+ * RU26, RU52, and RU106
301+ */
302+ for (i = 7; i < 21; i++) {
303+ bool bf = !(i % 2);
304+ u8 idx = (i - 7) / 2;
305+ s8 *buf = bf ? la.path.ru_bf[idx] : la.path.ru[idx];
306+
307+ /* The non-bf fields of RU26 to RU106 are special cases */
308+ if (bf && i < 15)
309+ skb_put_data(skb, buf + 1, 9);
310+ else
311+ skb_put_data(skb, buf, 10);
312 }
313
314- return mt76_mcu_send_msg(&dev->mt76,
315- MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), &req,
316- sizeof(req), true);
317+ return mt76_mcu_skb_send_msg(&dev->mt76, skb,
developerc5ce7502022-12-19 11:33:22 +0800318+ MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), true);
developera16be1f2022-12-14 13:09:20 +0800319 }
320
321-int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len)
322+int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len,
323+ u8 category)
324 {
325-#define RATE_POWER_INFO 2
326 struct mt7915_dev *dev = phy->dev;
327 struct {
328 u8 format_id;
developer7af0f762023-05-22 15:16:16 +0800329@@ -3355,10 +3403,9 @@ int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len)
developera16be1f2022-12-14 13:09:20 +0800330 u8 _rsv;
331 } __packed req = {
332 .format_id = TX_POWER_LIMIT_INFO,
333- .category = RATE_POWER_INFO,
334+ .category = category,
335 .band_idx = phy->mt76->band_idx,
336 };
337- s8 txpower_sku[MT7915_SKU_RATE_NUM][2];
338 struct sk_buff *skb;
339 int ret, i;
340
developer7af0f762023-05-22 15:16:16 +0800341@@ -3368,9 +3415,15 @@ int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len)
developera16be1f2022-12-14 13:09:20 +0800342 if (ret)
343 return ret;
344
345- memcpy(txpower_sku, skb->data + 4, sizeof(txpower_sku));
346- for (i = 0; i < len; i++)
347- txpower[i] = txpower_sku[i][req.band_idx];
348+ if (category == TX_POWER_INFO_RATE) {
349+ s8 res[MT7915_SKU_RATE_NUM][2];
350+
351+ memcpy(res, skb->data + 4, sizeof(res));
352+ for (i = 0; i < len; i++)
353+ txpower[i] = res[i][req.band_idx];
354+ } else if (category == TX_POWER_INFO_PATH) {
355+ memcpy(txpower, skb->data + 4, len);
356+ }
357
358 dev_kfree_skb(skb);
359
developer7af0f762023-05-22 15:16:16 +0800360@@ -3412,9 +3465,18 @@ int mt7915_mcu_set_sku_en(struct mt7915_phy *phy, bool enable)
developera16be1f2022-12-14 13:09:20 +0800361 .band_idx = phy->mt76->band_idx,
362 .sku_enable = enable,
363 };
364+ int ret;
365+
366+ ret = mt76_mcu_send_msg(&dev->mt76,
367+ MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), &req,
368+ sizeof(req), true);
369+ if (ret)
370+ return ret;
371
372 pr_info("%s: enable = %d\n", __func__, enable);
373
374+ req.format_id = TX_POWER_LIMIT_PATH_ENABLE;
developerc5ce7502022-12-19 11:33:22 +0800375+
developera16be1f2022-12-14 13:09:20 +0800376 return mt76_mcu_send_msg(&dev->mt76,
377 MCU_EXT_CMD(TX_POWER_FEATURE_CTRL), &req,
378 sizeof(req), true);
379diff --git a/mt7915/mcu.h b/mt7915/mcu.h
developer7af0f762023-05-22 15:16:16 +0800380index 3da650c..240a315 100644
developera16be1f2022-12-14 13:09:20 +0800381--- a/mt7915/mcu.h
382+++ b/mt7915/mcu.h
developer7af0f762023-05-22 15:16:16 +0800383@@ -502,12 +502,18 @@ enum {
developera16be1f2022-12-14 13:09:20 +0800384
385 enum {
386 TX_POWER_LIMIT_ENABLE,
387+ TX_POWER_LIMIT_PATH_ENABLE = 0x3,
388 TX_POWER_LIMIT_TABLE = 0x4,
389 TX_POWER_LIMIT_INFO = 0x7,
390 TX_POWER_LIMIT_FRAME = 0x11,
391 TX_POWER_LIMIT_FRAME_MIN = 0x12,
392 };
393
394+enum {
395+ TX_POWER_INFO_PATH = 1,
396+ TX_POWER_INFO_RATE,
397+};
398+
399 enum {
400 SPR_ENABLE = 0x1,
401 SPR_ENABLE_SD = 0x3,
402diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developer7af0f762023-05-22 15:16:16 +0800403index e2f196b..b4644f6 100644
developera16be1f2022-12-14 13:09:20 +0800404--- a/mt7915/mt7915.h
405+++ b/mt7915/mt7915.h
developer7af0f762023-05-22 15:16:16 +0800406@@ -72,6 +72,7 @@
developera16be1f2022-12-14 13:09:20 +0800407 #define MT7915_CDEV_THROTTLE_MAX 99
408
409 #define MT7915_SKU_RATE_NUM 161
410+#define MT7915_SKU_PATH_NUM 185
411
412 #define MT7915_MAX_TWT_AGRT 16
413 #define MT7915_MAX_STA_TWT_AGRT 8
developer7af0f762023-05-22 15:16:16 +0800414@@ -621,7 +622,8 @@ int mt7915_mcu_set_test_param(struct mt7915_dev *dev, u8 param, bool test_mode,
developera16be1f2022-12-14 13:09:20 +0800415 int mt7915_mcu_set_ser(struct mt7915_dev *dev, u8 action, u8 set, u8 band);
416 int mt7915_mcu_set_sku_en(struct mt7915_phy *phy, bool enable);
417 int mt7915_mcu_set_txpower_sku(struct mt7915_phy *phy);
418-int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len);
419+int mt7915_mcu_get_txpower_sku(struct mt7915_phy *phy, s8 *txpower, int len,
420+ u8 category);
421 int mt7915_mcu_set_txpower_frame_min(struct mt7915_phy *phy, s8 txpower);
422 int mt7915_mcu_set_txpower_frame(struct mt7915_phy *phy,
423 struct ieee80211_vif *vif,
424--
developer8effbd32023-04-17 15:57:28 +08004252.18.0
developera16be1f2022-12-14 13:09:20 +0800426