blob: 00b9fc67b04fe4f0124fbabd272fcd2f87912273 [file] [log] [blame]
developer9237f442024-06-14 17:13:04 +08001From 5e960ddb3cd014c0fe80526215319ffd3c497054 Mon Sep 17 00:00:00 2001
developer66e89bc2024-04-23 14:50:01 +08002From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Fri, 31 Mar 2023 11:36:34 +0800
developer9237f442024-06-14 17:13:04 +08004Subject: [PATCH 026/116] mtk: wifi: mt76: mt7996: add binfile mode support
developer66e89bc2024-04-23 14:50:01 +08005
6Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
developer66e89bc2024-04-23 14:50:01 +08007
8Fix binfile cannot sync precal data to atenl
9Binfile is viewed as efuse mode in atenl, so atenl does not allocate
10precal memory for its eeprom file
11Use mtd offset == 0xFFFFFFFF to determine whether it is binfile or flash mode
12Add support for loading precal in binfile mode
13
14Align upstream
15
developer66e89bc2024-04-23 14:50:01 +080016Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
developer66e89bc2024-04-23 14:50:01 +080017---
18 eeprom.c | 25 +++++++++++
19 mt76.h | 3 ++
20 mt7996/eeprom.c | 103 ++++++++++++++++++++++++++++++++++++++++---
21 mt7996/eeprom.h | 7 +++
22 mt7996/mt7996.h | 4 ++
23 mt7996/mtk_debugfs.c | 41 +++++++++++++++++
24 testmode.h | 2 +-
25 7 files changed, 179 insertions(+), 6 deletions(-)
26
27diff --git a/eeprom.c b/eeprom.c
developer9237f442024-06-14 17:13:04 +080028index 11efe29..3da9492 100644
developer66e89bc2024-04-23 14:50:01 +080029--- a/eeprom.c
30+++ b/eeprom.c
31@@ -161,6 +161,31 @@ static int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int len)
32 return mt76_get_of_data_from_nvmem(dev, eep, "eeprom", len);
33 }
34
35+bool mt76_check_bin_file_mode(struct mt76_dev *dev)
36+{
37+ struct device_node *np = dev->dev->of_node;
38+ const char *bin_file_name = NULL;
39+
40+ if (!np)
41+ return false;
42+
43+ of_property_read_string(np, "bin_file_name", &bin_file_name);
44+
45+ dev->bin_file_name = bin_file_name;
46+ if (dev->bin_file_name) {
47+ dev_info(dev->dev, "Using bin file %s\n", dev->bin_file_name);
48+#ifdef CONFIG_NL80211_TESTMODE
49+ dev->test_mtd.name = devm_kstrdup(dev->dev, bin_file_name, GFP_KERNEL);
50+ dev->test_mtd.offset = -1;
51+#endif
52+ }
53+
54+ of_node_put(np);
55+
56+ return dev->bin_file_name ? true : false;
57+}
58+EXPORT_SYMBOL_GPL(mt76_check_bin_file_mode);
59+
60 void
61 mt76_eeprom_override(struct mt76_phy *phy)
62 {
63diff --git a/mt76.h b/mt76.h
developer9237f442024-06-14 17:13:04 +080064index c372e78..dbd8ab9 100644
developer66e89bc2024-04-23 14:50:01 +080065--- a/mt76.h
66+++ b/mt76.h
67@@ -954,6 +954,8 @@ struct mt76_dev {
68 struct mt76_usb usb;
69 struct mt76_sdio sdio;
70 };
71+
72+ const char *bin_file_name;
73 };
74
75 /* per-phy stats. */
76@@ -1225,6 +1227,7 @@ void mt76_eeprom_override(struct mt76_phy *phy);
77 int mt76_get_of_data_from_mtd(struct mt76_dev *dev, void *eep, int offset, int len);
78 int mt76_get_of_data_from_nvmem(struct mt76_dev *dev, void *eep,
79 const char *cell_name, int len);
80+bool mt76_check_bin_file_mode(struct mt76_dev *dev);
81
82 struct mt76_queue *
83 mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc,
84diff --git a/mt7996/eeprom.c b/mt7996/eeprom.c
developer9237f442024-06-14 17:13:04 +080085index 6ac992a..fe8b253 100644
developer66e89bc2024-04-23 14:50:01 +080086--- a/mt7996/eeprom.c
87+++ b/mt7996/eeprom.c
88@@ -82,10 +82,17 @@ static int mt7996_check_eeprom(struct mt7996_dev *dev)
89 }
90 }
91
92-static char *mt7996_eeprom_name(struct mt7996_dev *dev)
93+const char *mt7996_eeprom_name(struct mt7996_dev *dev)
94 {
95- if (dev->testmode_enable)
96- return MT7996_EEPROM_DEFAULT_TM;
97+ if (dev->bin_file_mode)
98+ return dev->mt76.bin_file_name;
99+
100+ if (dev->testmode_enable) {
101+ if (is_mt7992(&dev->mt76))
102+ return MT7992_EEPROM_DEFAULT_TM;
103+ else
104+ return MT7996_EEPROM_DEFAULT_TM;
105+ }
106
107 switch (mt76_chip(&dev->mt76)) {
108 case 0x7990:
109@@ -152,7 +159,10 @@ mt7996_eeprom_load_default(struct mt7996_dev *dev)
110 return ret;
111
112 if (!fw || !fw->data) {
113- dev_err(dev->mt76.dev, "Invalid default bin\n");
114+ if (dev->bin_file_mode)
115+ dev_err(dev->mt76.dev, "Invalid bin (bin file mode)\n");
116+ else
117+ dev_err(dev->mt76.dev, "Invalid default bin\n");
118 ret = -EINVAL;
119 goto out;
120 }
121@@ -166,18 +176,45 @@ out:
122 return ret;
123 }
124
125+static int mt7996_eeprom_load_flash(struct mt7996_dev *dev)
126+{
127+ int ret = 1;
128+
129+ /* return > 0 for load success, return 0 for load failed, return < 0 for non memory */
130+ dev->bin_file_mode = mt76_check_bin_file_mode(&dev->mt76);
131+ if (dev->bin_file_mode) {
132+ dev->mt76.eeprom.size = MT7996_EEPROM_SIZE;
133+ dev->mt76.eeprom.data = devm_kzalloc(dev->mt76.dev, dev->mt76.eeprom.size,
134+ GFP_KERNEL);
135+ if (!dev->mt76.eeprom.data)
136+ return -ENOMEM;
137+
138+ if (mt7996_eeprom_load_default(dev))
139+ return 0;
140+
141+ if (mt7996_check_eeprom(dev))
142+ return 0;
143+ } else {
144+ ret = mt76_eeprom_init(&dev->mt76, MT7996_EEPROM_SIZE);
145+ }
146+
147+ return ret;
148+}
149+
150 int mt7996_eeprom_check_fw_mode(struct mt7996_dev *dev)
151 {
152 u8 *eeprom;
153 int ret;
154
155 /* load eeprom in flash or bin file mode to determine fw mode */
156- ret = mt76_eeprom_init(&dev->mt76, MT7996_EEPROM_SIZE);
157+ ret = mt7996_eeprom_load_flash(dev);
158+
159 if (ret < 0)
160 return ret;
161
162 if (ret) {
163 dev->flash_mode = true;
164+ dev->eeprom_mode = dev->bin_file_mode ? BIN_FILE_MODE : FLASH_MODE;
165 eeprom = dev->mt76.eeprom.data;
166 /* testmode enable priority: eeprom field > module parameter */
167 dev->testmode_enable = !mt7996_check_eeprom(dev) ? eeprom[MT_EE_TESTMODE_EN] :
168@@ -211,6 +248,7 @@ static int mt7996_eeprom_load(struct mt7996_dev *dev)
169 if (ret && ret != -EINVAL)
170 return ret;
171 }
172+ dev->eeprom_mode = EFUSE_MODE;
173 }
174
175 return mt7996_check_eeprom(dev);
176@@ -337,6 +375,59 @@ int mt7996_eeprom_parse_hw_cap(struct mt7996_dev *dev, struct mt7996_phy *phy)
177 return mt7996_eeprom_parse_band_config(phy);
178 }
179
180+static int
181+mt7996_eeprom_load_precal_binfile(struct mt7996_dev *dev, u32 offs, u32 size)
182+{
183+ const struct firmware *fw = NULL;
184+ int ret;
185+
186+ ret = request_firmware(&fw, dev->mt76.bin_file_name, dev->mt76.dev);
187+ if (ret)
188+ return ret;
189+
190+ if (!fw || !fw->data) {
191+ dev_err(dev->mt76.dev, "Invalid bin (bin file mode), load precal fail\n");
192+ ret = -EINVAL;
193+ goto out;
194+ }
195+
196+ memcpy(dev->cal, fw->data + offs, size);
197+
198+out:
199+ release_firmware(fw);
200+
201+ return ret;
202+}
203+
204+static int mt7996_eeprom_load_precal(struct mt7996_dev *dev)
205+{
206+ struct mt76_dev *mdev = &dev->mt76;
207+ u8 *eeprom = mdev->eeprom.data;
208+ u32 offs = MT_EE_DO_PRE_CAL;
209+ u32 size, val = eeprom[offs];
210+ int ret;
211+
212+ mt7996_eeprom_init_precal(dev);
213+
214+ if (!dev->flash_mode || !val)
215+ return 0;
216+
217+ size = MT_EE_CAL_GROUP_SIZE + MT_EE_CAL_DPD_SIZE;
218+
219+ dev->cal = devm_kzalloc(mdev->dev, size, GFP_KERNEL);
220+ if (!dev->cal)
221+ return -ENOMEM;
222+
223+ if (dev->bin_file_mode)
224+ return mt7996_eeprom_load_precal_binfile(dev, MT_EE_PRECAL, size);
225+
226+ ret = mt76_get_of_data_from_mtd(mdev, dev->cal, offs, size);
227+ if (!ret)
228+ return ret;
229+
230+ return mt76_get_of_data_from_nvmem(mdev, dev->cal, "precal", size);
231+}
232+
233 int mt7996_eeprom_init(struct mt7996_dev *dev)
234 {
235 int ret;
236@@ -351,6 +442,8 @@ int mt7996_eeprom_init(struct mt7996_dev *dev)
237 return ret;
238
239 dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n");
240+ dev->bin_file_mode = false;
241+ dev->eeprom_mode = DEFAULT_BIN_MODE;
242 ret = mt7996_eeprom_load_default(dev);
243 if (ret)
244 return ret;
245diff --git a/mt7996/eeprom.h b/mt7996/eeprom.h
developer9237f442024-06-14 17:13:04 +0800246index b19ff06..8f0f87b 100644
developer66e89bc2024-04-23 14:50:01 +0800247--- a/mt7996/eeprom.h
248+++ b/mt7996/eeprom.h
249@@ -102,6 +102,13 @@ enum mt7996_eeprom_band {
250 MT_EE_BAND_SEL_6GHZ,
251 };
252
253+enum mt7915_eeprom_mode {
254+ DEFAULT_BIN_MODE,
255+ EFUSE_MODE,
256+ FLASH_MODE,
257+ BIN_FILE_MODE,
258+};
259+
260 static inline int
261 mt7996_get_channel_group_5g(int channel)
262 {
263diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h
developer9237f442024-06-14 17:13:04 +0800264index 6ab45cc..9d6e85c 100644
developer66e89bc2024-04-23 14:50:01 +0800265--- a/mt7996/mt7996.h
266+++ b/mt7996/mt7996.h
267@@ -62,6 +62,7 @@
268 #define MT7992_EEPROM_DEFAULT_24 "mediatek/mt7996/mt7992_eeprom_24_2i5i.bin"
269 #define MT7992_EEPROM_DEFAULT_23 "mediatek/mt7996/mt7992_eeprom_23_2i5i.bin"
270 #define MT7992_EEPROM_DEFAULT_23_EXT "mediatek/mt7996/mt7992_eeprom_23_2e5e.bin"
271+#define MT7992_EEPROM_DEFAULT_TM "mediatek/mt7996/mt7992_eeprom_tm.bin"
272 #define MT7996_EEPROM_SIZE 7680
273 #define MT7996_EEPROM_BLOCK_SIZE 16
274 #define MT7996_TOKEN_SIZE 16384
275@@ -395,6 +396,8 @@ struct mt7996_dev {
276 } wed_rro;
277
278 bool testmode_enable;
279+ bool bin_file_mode;
280+ u8 eeprom_mode;
281
282 bool ibf;
283 u8 fw_debug_wm;
284@@ -523,6 +526,7 @@ irqreturn_t mt7996_irq_handler(int irq, void *dev_instance);
285 u64 __mt7996_get_tsf(struct ieee80211_hw *hw, struct mt7996_vif *mvif);
286 int mt7996_register_device(struct mt7996_dev *dev);
287 void mt7996_unregister_device(struct mt7996_dev *dev);
288+const char *mt7996_eeprom_name(struct mt7996_dev *dev);
289 int mt7996_eeprom_init(struct mt7996_dev *dev);
290 int mt7996_eeprom_check_fw_mode(struct mt7996_dev *dev);
291 int mt7996_eeprom_parse_hw_cap(struct mt7996_dev *dev, struct mt7996_phy *phy);
292diff --git a/mt7996/mtk_debugfs.c b/mt7996/mtk_debugfs.c
developer9237f442024-06-14 17:13:04 +0800293index 74aabf0..2499f12 100644
developer66e89bc2024-04-23 14:50:01 +0800294--- a/mt7996/mtk_debugfs.c
295+++ b/mt7996/mtk_debugfs.c
296@@ -2798,6 +2798,44 @@ static const struct file_operations mt7996_txpower_path_fops = {
297 .llseek = default_llseek,
298 };
299
300+static int mt7996_show_eeprom_mode(struct seq_file *s, void *data)
301+{
302+ struct mt7996_dev *dev = dev_get_drvdata(s->private);
303+ struct mt76_dev *mdev = &dev->mt76;
304+#ifdef CONFIG_NL80211_TESTMODE
305+ const char *mtd_name = mdev->test_mtd.name;
306+ u32 mtd_offset = mdev->test_mtd.offset;
307+#else
308+ const char *mtd_name = NULL;
309+ u32 mtd_offset;
310+#endif
311+
312+ seq_printf(s, "Current eeprom mode:\n");
313+
314+ switch (dev->eeprom_mode) {
315+ case DEFAULT_BIN_MODE:
316+ seq_printf(s, " default bin mode\n filename = %s\n", mt7996_eeprom_name(dev));
317+ break;
318+ case EFUSE_MODE:
319+ seq_printf(s, " efuse mode\n");
320+ break;
321+ case FLASH_MODE:
322+ if (mtd_name)
323+ seq_printf(s, " flash mode\n mtd name = %s\n flash offset = 0x%x\n",
324+ mtd_name, mtd_offset);
325+ else
326+ seq_printf(s, " flash mode\n");
327+ break;
328+ case BIN_FILE_MODE:
329+ seq_printf(s, " bin file mode\n filename = %s\n", mt7996_eeprom_name(dev));
330+ break;
331+ default:
332+ break;
333+ }
334+
335+ return 0;
336+}
337+
338 int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir)
339 {
340 struct mt7996_dev *dev = phy->dev;
341@@ -2866,6 +2904,9 @@ int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir)
342 debugfs_create_file("txpower_sku", 0600, dir, phy, &mt7996_txpower_sku_fops);
343 debugfs_create_file("txpower_path", 0600, dir, phy, &mt7996_txpower_path_fops);
344
345+ debugfs_create_devm_seqfile(dev->mt76.dev, "eeprom_mode", dir,
346+ mt7996_show_eeprom_mode);
347+
348 debugfs_create_devm_seqfile(dev->mt76.dev, "wtbl_info", dir,
349 mt7996_wtbl_read);
350
351diff --git a/testmode.h b/testmode.h
developer9237f442024-06-14 17:13:04 +0800352index d6601cd..5d677f8 100644
developer66e89bc2024-04-23 14:50:01 +0800353--- a/testmode.h
354+++ b/testmode.h
355@@ -16,7 +16,7 @@
356 * @MT76_TM_ATTR_RESET: reset parameters to default (flag)
357 * @MT76_TM_ATTR_STATE: test state (u32), see &enum mt76_testmode_state
358 *
359- * @MT76_TM_ATTR_MTD_PART: mtd partition used for eeprom data (string)
360+ * @MT76_TM_ATTR_MTD_PART: mtd partition or binfile used for eeprom data (string)
361 * @MT76_TM_ATTR_MTD_OFFSET: offset of eeprom data within the partition (u32)
362 * @MT76_TM_ATTR_BAND_IDX: band idx of the chip (u8)
363 *
364--
developer9237f442024-06-14 17:13:04 +08003652.18.0
developer66e89bc2024-04-23 14:50:01 +0800366