blob: 9099d4864d5c264aa62f4bf4e93153274402f637 [file] [log] [blame]
developera46f6132024-03-26 14:09:54 +08001From 28aa63ac8f3468494eb58e6dfb424dc3507a3396 Mon Sep 17 00:00:00 2001
developer1a173672023-12-21 14:49:33 +08002From: "Allen.Ye" <allen.ye@mediatek.com>
3Date: Mon, 10 Jul 2023 19:56:16 +0800
developereb155692024-01-11 14:08:37 +08004Subject: [PATCH 1008/1044] mtk: wifi: mt76: mt7996: add single sku
developer1a173672023-12-21 14:49:33 +08005
6Add single sku and default enable sku.
7
8Signed-off-by: Allen.Ye <allen.ye@mediatek.com>
9---
10 eeprom.c | 50 ++++++++++++++++++++++++++++++++++++++++++-----
11 mt76.h | 9 +++++++++
12 mt76_connac_mcu.c | 2 +-
13 mt7996/init.c | 2 ++
14 mt7996/main.c | 9 +++++++++
15 mt7996/mcu.c | 41 ++++++++++++++++++++++++++++++++++----
16 mt7996/mt7996.h | 1 +
17 7 files changed, 104 insertions(+), 10 deletions(-)
18
19diff --git a/eeprom.c b/eeprom.c
20index 85bd2a29..c5be2843 100644
21--- a/eeprom.c
22+++ b/eeprom.c
23@@ -341,6 +341,7 @@ mt76_apply_multi_array_limit(s8 *pwr, size_t pwr_len, s8 pwr_num,
24 s8 mt76_get_rate_power_limits(struct mt76_phy *phy,
25 struct ieee80211_channel *chan,
26 struct mt76_power_limits *dest,
27+ struct mt76_power_path_limits *dest_path,
28 s8 target_power)
29 {
30 struct mt76_dev *dev = phy->dev;
31@@ -348,16 +349,20 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy,
32 const __be32 *val;
33 char name[16];
34 u32 mcs_rates = dev->drv->mcs_rates;
35- u32 ru_rates = ARRAY_SIZE(dest->ru[0]);
36 char band;
37 size_t len;
38- s8 max_power = 0;
39+ s8 max_power = -127;
40+ s8 max_power_backoff = -127;
41 s8 txs_delta;
42+ int n_chains = hweight16(phy->chainmask);
43+ s8 target_power_combine = target_power + mt76_tx_power_nss_delta(n_chains);
44
45 if (!mcs_rates)
46- mcs_rates = 10;
47+ mcs_rates = 12;
48
49 memset(dest, target_power, sizeof(*dest));
50+ if (dest_path != NULL)
51+ memset(dest_path, 0, sizeof(*dest_path));
52
53 if (!IS_ENABLED(CONFIG_OF))
54 return target_power;
55@@ -405,12 +410,47 @@ s8 mt76_get_rate_power_limits(struct mt76_phy *phy,
56 ARRAY_SIZE(dest->mcs), val, len,
57 target_power, txs_delta, &max_power);
58
59- val = mt76_get_of_array(np, "rates-ru", &len, ru_rates + 1);
60+ val = mt76_get_of_array(np, "rates-ru", &len, ARRAY_SIZE(dest->ru[0]) + 1);
61 mt76_apply_multi_array_limit(dest->ru[0], ARRAY_SIZE(dest->ru[0]),
62 ARRAY_SIZE(dest->ru), val, len,
63 target_power, txs_delta, &max_power);
64
65- return max_power;
66+ val = mt76_get_of_array(np, "rates-eht", &len, ARRAY_SIZE(dest->eht[0]) + 1);
67+ mt76_apply_multi_array_limit(dest->eht[0], ARRAY_SIZE(dest->eht[0]),
68+ ARRAY_SIZE(dest->eht), val, len,
69+ target_power, txs_delta, &max_power);
70+
71+ if (dest_path == NULL)
72+ return max_power;
73+
74+ max_power_backoff = max_power;
75+
76+ val = mt76_get_of_array(np, "paths-cck", &len, ARRAY_SIZE(dest_path->cck));
77+ mt76_apply_array_limit(dest_path->cck, ARRAY_SIZE(dest_path->cck), val,
78+ target_power_combine, txs_delta, &max_power_backoff);
79+
80+ val = mt76_get_of_array(np, "paths-ofdm", &len, ARRAY_SIZE(dest_path->ofdm));
81+ mt76_apply_array_limit(dest_path->ofdm, ARRAY_SIZE(dest_path->ofdm), val,
82+ target_power_combine, txs_delta, &max_power_backoff);
83+
84+ val = mt76_get_of_array(np, "paths-ofdm-bf", &len, ARRAY_SIZE(dest_path->ofdm_bf));
85+ mt76_apply_array_limit(dest_path->ofdm_bf, ARRAY_SIZE(dest_path->ofdm_bf), val,
86+ target_power_combine, txs_delta, &max_power_backoff);
87+
88+ val = mt76_get_of_array(np, "paths-ru", &len, ARRAY_SIZE(dest_path->ru[0]) + 1);
89+ mt76_apply_multi_array_limit(dest_path->ru[0], ARRAY_SIZE(dest_path->ru[0]),
90+ ARRAY_SIZE(dest_path->ru), val, len,
91+ target_power_combine, txs_delta, &max_power_backoff);
92+
93+ val = mt76_get_of_array(np, "paths-ru-bf", &len, ARRAY_SIZE(dest_path->ru_bf[0]) + 1);
94+ mt76_apply_multi_array_limit(dest_path->ru_bf[0], ARRAY_SIZE(dest_path->ru_bf[0]),
95+ ARRAY_SIZE(dest_path->ru_bf), val, len,
96+ target_power_combine, txs_delta, &max_power_backoff);
97+
98+ if (max_power_backoff == target_power_combine)
99+ return max_power;
100+
101+ return max_power_backoff;
102 }
103 EXPORT_SYMBOL_GPL(mt76_get_rate_power_limits);
104
105diff --git a/mt76.h b/mt76.h
developera46f6132024-03-26 14:09:54 +0800106index 14c5fcb1..630b3903 100644
developer1a173672023-12-21 14:49:33 +0800107--- a/mt76.h
108+++ b/mt76.h
developer753619c2024-02-22 13:42:45 +0800109@@ -1054,6 +1054,14 @@ struct mt76_power_limits {
developer1a173672023-12-21 14:49:33 +0800110 s8 eht[16][16];
111 };
112
113+struct mt76_power_path_limits {
114+ s8 cck[5];
115+ s8 ofdm[5];
116+ s8 ofdm_bf[4];
117+ s8 ru[16][15];
118+ s8 ru_bf[16][15];
119+};
120+
121 struct mt76_ethtool_worker_info {
122 u64 *data;
123 int idx;
developer753619c2024-02-22 13:42:45 +0800124@@ -1664,6 +1672,7 @@ mt76_find_channel_node(struct device_node *np, struct ieee80211_channel *chan);
developer1a173672023-12-21 14:49:33 +0800125 s8 mt76_get_rate_power_limits(struct mt76_phy *phy,
126 struct ieee80211_channel *chan,
127 struct mt76_power_limits *dest,
128+ struct mt76_power_path_limits *dest_path,
129 s8 target_power);
130
131 static inline bool mt76_queue_is_wed_tx_free(struct mt76_queue *q)
132diff --git a/mt76_connac_mcu.c b/mt76_connac_mcu.c
developera46f6132024-03-26 14:09:54 +0800133index 42f12672..75bbb7cc 100644
developer1a173672023-12-21 14:49:33 +0800134--- a/mt76_connac_mcu.c
135+++ b/mt76_connac_mcu.c
136@@ -2150,7 +2150,7 @@ mt76_connac_mcu_rate_txpower_band(struct mt76_phy *phy,
137 sar_power = mt76_get_sar_power(phy, &chan, reg_power);
138
139 mt76_get_rate_power_limits(phy, &chan, limits,
140- sar_power);
141+ NULL, sar_power);
142
143 tx_power_tlv.last_msg = ch_list[idx] == last_ch;
144 sku_tlbv.channel = ch_list[idx];
145diff --git a/mt7996/init.c b/mt7996/init.c
developer753619c2024-02-22 13:42:45 +0800146index 23a9b88b..5f937b26 100644
developer1a173672023-12-21 14:49:33 +0800147--- a/mt7996/init.c
148+++ b/mt7996/init.c
149@@ -295,6 +295,7 @@ static void __mt7996_init_txpower(struct mt7996_phy *phy,
150 int nss_delta = mt76_tx_power_nss_delta(nss);
151 int pwr_delta = mt7996_eeprom_get_power_delta(dev, sband->band);
152 struct mt76_power_limits limits;
153+ struct mt76_power_path_limits limits_path;
154
155 for (i = 0; i < sband->n_channels; i++) {
156 struct ieee80211_channel *chan = &sband->channels[i];
157@@ -303,6 +304,7 @@ static void __mt7996_init_txpower(struct mt7996_phy *phy,
158 target_power += pwr_delta;
159 target_power = mt76_get_rate_power_limits(phy->mt76, chan,
160 &limits,
161+ &limits_path,
162 target_power);
163 target_power += nss_delta;
164 target_power = DIV_ROUND_UP(target_power, 2);
165diff --git a/mt7996/main.c b/mt7996/main.c
developer753619c2024-02-22 13:42:45 +0800166index ffb1f81b..ecfc3dcf 100644
developer1a173672023-12-21 14:49:33 +0800167--- a/mt7996/main.c
168+++ b/mt7996/main.c
169@@ -77,6 +77,15 @@ int mt7996_run(struct ieee80211_hw *hw)
170 if (ret)
171 goto out;
172
173+#ifdef CONFIG_MTK_DEBUG
174+ ret = mt7996_mcu_set_tx_power_ctrl(phy, UNI_TXPOWER_SKU_POWER_LIMIT_CTRL,
175+ !dev->dbg.sku_disable);
176+#else
177+ ret = mt7996_mcu_set_tx_power_ctrl(phy, UNI_TXPOWER_SKU_POWER_LIMIT_CTRL, true);
178+#endif
179+ if (ret)
180+ goto out;
181+
182 set_bit(MT76_STATE_RUNNING, &phy->mt76->state);
183
184 ieee80211_queue_delayed_work(hw, &phy->mt76->mac_work,
185diff --git a/mt7996/mcu.c b/mt7996/mcu.c
developera46f6132024-03-26 14:09:54 +0800186index 62452d6e..e103601f 100644
developer1a173672023-12-21 14:49:33 +0800187--- a/mt7996/mcu.c
188+++ b/mt7996/mcu.c
developera46f6132024-03-26 14:09:54 +0800189@@ -4496,6 +4496,7 @@ int mt7996_mcu_wed_rro_reset_sessions(struct mt7996_dev *dev, u16 id)
developer1a173672023-12-21 14:49:33 +0800190 int mt7996_mcu_set_txpower_sku(struct mt7996_phy *phy)
191 {
192 #define TX_POWER_LIMIT_TABLE_RATE 0
193+#define TX_POWER_LIMIT_TABLE_PATH 1
194 struct mt7996_dev *dev = phy->dev;
195 struct mt76_phy *mphy = phy->mt76;
196 struct ieee80211_hw *hw = mphy->hw;
developera46f6132024-03-26 14:09:54 +0800197@@ -4509,22 +4510,23 @@ int mt7996_mcu_set_txpower_sku(struct mt7996_phy *phy)
developer1a173672023-12-21 14:49:33 +0800198 u8 band_idx;
199 } __packed req = {
200 .tag = cpu_to_le16(UNI_TXPOWER_POWER_LIMIT_TABLE_CTRL),
201- .len = cpu_to_le16(sizeof(req) + MT7996_SKU_RATE_NUM - 4),
202+ .len = cpu_to_le16(sizeof(req) + MT7996_SKU_PATH_NUM - 4),
203 .power_ctrl_id = UNI_TXPOWER_POWER_LIMIT_TABLE_CTRL,
204 .power_limit_type = TX_POWER_LIMIT_TABLE_RATE,
205 .band_idx = phy->mt76->band_idx,
206 };
207 struct mt76_power_limits la = {};
208+ struct mt76_power_path_limits la_path = {};
209 struct sk_buff *skb;
210- int i, tx_power;
211+ int i, ret, tx_power;
212
213 tx_power = mt7996_get_power_bound(phy, hw->conf.power_level);
214 tx_power = mt76_get_rate_power_limits(mphy, mphy->chandef.chan,
215- &la, tx_power);
216+ &la, &la_path, tx_power);
217 mphy->txpower_cur = tx_power;
218
219 skb = mt76_mcu_msg_alloc(&dev->mt76, NULL,
220- sizeof(req) + MT7996_SKU_RATE_NUM);
221+ sizeof(req) + MT7996_SKU_PATH_NUM);
222 if (!skb)
223 return -ENOMEM;
224
developera46f6132024-03-26 14:09:54 +0800225@@ -4548,6 +4550,37 @@ int mt7996_mcu_set_txpower_sku(struct mt7996_phy *phy)
developer1a173672023-12-21 14:49:33 +0800226 /* eht */
227 skb_put_data(skb, &la.eht[0], sizeof(la.eht));
228
229+ /* padding */
230+ skb_put_zero(skb, MT7996_SKU_PATH_NUM - MT7996_SKU_RATE_NUM);
231+
232+ ret = mt76_mcu_skb_send_msg(&dev->mt76, skb,
233+ MCU_WM_UNI_CMD(TXPOWER), true);
234+ if (ret)
235+ return ret;
236+
237+ /* only set per-path power table when it's configured */
238+ if (!la_path.ofdm[0])
239+ return 0;
240+
241+ skb = mt76_mcu_msg_alloc(&dev->mt76, NULL,
242+ sizeof(req) + MT7996_SKU_PATH_NUM);
243+ if (!skb)
244+ return -ENOMEM;
245+ req.power_limit_type = TX_POWER_LIMIT_TABLE_PATH;
246+
247+ skb_put_data(skb, &req, sizeof(req));
248+ skb_put_data(skb, &la_path.cck, sizeof(la_path.cck));
249+ skb_put_data(skb, &la_path.ofdm, sizeof(la_path.ofdm));
250+ skb_put_data(skb, &la_path.ofdm_bf, sizeof(la_path.ofdm_bf));
251+
252+ for (i = 0; i < 32; i++) {
253+ bool bf = i % 2;
254+ u8 idx = i / 2;
255+ s8 *buf = bf ? la_path.ru_bf[idx] : la_path.ru[idx];
256+
257+ skb_put_data(skb, buf, sizeof(la_path.ru[0]));
258+ }
259+
260 return mt76_mcu_skb_send_msg(&dev->mt76, skb,
261 MCU_WM_UNI_CMD(TXPOWER), true);
262 }
263diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h
264index 18a6a46d..7e3d381e 100644
265--- a/mt7996/mt7996.h
266+++ b/mt7996/mt7996.h
267@@ -71,6 +71,7 @@
268 #define MT7996_CFEND_RATE_11B 0x03 /* 11B LP, 11M */
269
270 #define MT7996_SKU_RATE_NUM 417
271+#define MT7996_SKU_PATH_NUM 494
272
273 #define MT7996_MAX_TWT_AGRT 16
274 #define MT7996_MAX_STA_TWT_AGRT 8
275--
2762.18.0
277