blob: 9800bd240b92a1fe7b21c2ff357f62f6c0b8a299 [file] [log] [blame]
developer05f3b2b2024-08-19 19:17:34 +08001From 6aa933c1f0af48d3703f500dce4514b62d9d2121 Mon Sep 17 00:00:00 2001
developerc5ce7502022-12-19 11:33:22 +08002From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Thu, 7 Jul 2022 11:09:59 +0800
developer05f3b2b2024-08-19 19:17:34 +08004Subject: [PATCH 1016/1052] wifi: mt76: mt7915: implement bin file mode
developerc5ce7502022-12-19 11:33:22 +08005
6Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
7Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
8---
developer1a173672023-12-21 14:49:33 +08009 eeprom.c | 25 ++++++++++++++++++
developer70180b02023-11-14 17:01:47 +080010 mt76.h | 4 +++
developer1a173672023-12-21 14:49:33 +080011 mt7915/eeprom.c | 63 +++++++++++++++++++++++++++++++++++++++++---
developer70180b02023-11-14 17:01:47 +080012 mt7915/eeprom.h | 7 +++++
developer1a173672023-12-21 14:49:33 +080013 mt7915/mt7915.h | 3 +++
14 mt7915/mtk_debugfs.c | 44 +++++++++++++++++++++++++++++++
developer70180b02023-11-14 17:01:47 +080015 testmode.h | 2 +-
developer1a173672023-12-21 14:49:33 +080016 7 files changed, 144 insertions(+), 4 deletions(-)
developerc5ce7502022-12-19 11:33:22 +080017
18diff --git a/eeprom.c b/eeprom.c
developer05f3b2b2024-08-19 19:17:34 +080019index 3625b169..9d029c04 100644
developerc5ce7502022-12-19 11:33:22 +080020--- a/eeprom.c
21+++ b/eeprom.c
developer1a173672023-12-21 14:49:33 +080022@@ -161,6 +161,31 @@ static int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int len)
23 return mt76_get_of_data_from_nvmem(dev, eep, "eeprom", len);
developerc5ce7502022-12-19 11:33:22 +080024 }
developerc5ce7502022-12-19 11:33:22 +080025
26+bool mt76_check_bin_file_mode(struct mt76_dev *dev)
27+{
28+ struct device_node *np = dev->dev->of_node;
29+ const char *bin_file_name = NULL;
30+
31+ if (!np)
32+ return false;
33+
34+ of_property_read_string(np, "bin_file_name", &bin_file_name);
35+
36+ dev->bin_file_name = bin_file_name;
developer70180b02023-11-14 17:01:47 +080037+ if (dev->bin_file_name) {
developerc5ce7502022-12-19 11:33:22 +080038+ dev_info(dev->dev, "Using bin file %s\n", dev->bin_file_name);
developer70180b02023-11-14 17:01:47 +080039+#ifdef CONFIG_NL80211_TESTMODE
40+ dev->test_mtd.name = devm_kstrdup(dev->dev, bin_file_name, GFP_KERNEL);
41+ dev->test_mtd.offset = -1;
42+#endif
43+ }
developerc5ce7502022-12-19 11:33:22 +080044+
45+ of_node_put(np);
46+
47+ return dev->bin_file_name ? true : false;
48+}
49+EXPORT_SYMBOL_GPL(mt76_check_bin_file_mode);
50+
51 void
52 mt76_eeprom_override(struct mt76_phy *phy)
53 {
54diff --git a/mt76.h b/mt76.h
developer05f3b2b2024-08-19 19:17:34 +080055index 9597f564..253a564f 100644
developerc5ce7502022-12-19 11:33:22 +080056--- a/mt76.h
57+++ b/mt76.h
developera46f6132024-03-26 14:09:54 +080058@@ -983,6 +983,9 @@ struct mt76_dev {
developer67705712023-05-30 11:58:00 +080059 struct mt76_usb usb;
developerc5ce7502022-12-19 11:33:22 +080060 struct mt76_sdio sdio;
61 };
developer67705712023-05-30 11:58:00 +080062+
developerc5ce7502022-12-19 11:33:22 +080063+ /* for mtk internal */
developerc5ce7502022-12-19 11:33:22 +080064+ const char *bin_file_name;
65 };
66
developer47efbdb2023-06-29 20:33:22 +080067 /* per-phy stats. */
developera46f6132024-03-26 14:09:54 +080068@@ -1246,6 +1249,7 @@ void mt76_eeprom_override(struct mt76_phy *phy);
developer1a173672023-12-21 14:49:33 +080069 int mt76_get_of_data_from_mtd(struct mt76_dev *dev, void *eep, int offset, int len);
70 int mt76_get_of_data_from_nvmem(struct mt76_dev *dev, void *eep,
71 const char *cell_name, int len);
developerc5ce7502022-12-19 11:33:22 +080072+bool mt76_check_bin_file_mode(struct mt76_dev *dev);
73
74 struct mt76_queue *
75 mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc,
76diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c
developer05f3b2b2024-08-19 19:17:34 +080077index f4876fe9..c8b1c18e 100644
developerc5ce7502022-12-19 11:33:22 +080078--- a/mt7915/eeprom.c
79+++ b/mt7915/eeprom.c
developer70180b02023-11-14 17:01:47 +080080@@ -5,6 +5,30 @@
81 #include "mt7915.h"
82 #include "eeprom.h"
83
84+static int
85+mt7915_eeprom_load_precal_binfile(struct mt7915_dev *dev, u32 offs, u32 size)
86+{
87+ const struct firmware *fw = NULL;
88+ int ret;
89+
90+ ret = request_firmware(&fw, dev->mt76.bin_file_name, dev->mt76.dev);
91+ if (ret)
92+ return ret;
93+
94+ if (!fw || !fw->data) {
95+ dev_err(dev->mt76.dev, "Invalid bin (bin file mode), load precal fail\n");
96+ ret = -EINVAL;
97+ goto out;
98+ }
99+
100+ memcpy(dev->cal, fw->data + offs, size);
101+
102+out:
103+ release_firmware(fw);
104+
105+ return ret;
106+}
107+
108 static int mt7915_eeprom_load_precal(struct mt7915_dev *dev)
109 {
110 struct mt76_dev *mdev = &dev->mt76;
developera46f6132024-03-26 14:09:54 +0800111@@ -24,6 +48,9 @@ static int mt7915_eeprom_load_precal(struct mt7915_dev *dev)
developer70180b02023-11-14 17:01:47 +0800112
113 offs = is_mt7915(&dev->mt76) ? MT_EE_PRECAL : MT_EE_PRECAL_V2;
114
developer1a173672023-12-21 14:49:33 +0800115+ if (dev->bin_file_mode)
developer70180b02023-11-14 17:01:47 +0800116+ return mt7915_eeprom_load_precal_binfile(dev, offs, size);
developer1a173672023-12-21 14:49:33 +0800117+
118 ret = mt76_get_of_data_from_mtd(mdev, dev->cal, offs, size);
119 if (!ret)
120 return ret;
developera46f6132024-03-26 14:09:54 +0800121@@ -59,8 +86,11 @@ static int mt7915_check_eeprom(struct mt7915_dev *dev)
developerc5ce7502022-12-19 11:33:22 +0800122 }
123 }
124
125-static char *mt7915_eeprom_name(struct mt7915_dev *dev)
126+const char *mt7915_eeprom_name(struct mt7915_dev *dev)
127 {
128+ if (dev->bin_file_mode)
129+ return dev->mt76.bin_file_name;
130+
131 switch (mt76_chip(&dev->mt76)) {
132 case 0x7915:
133 return dev->dbdc_support ?
developera46f6132024-03-26 14:09:54 +0800134@@ -101,7 +131,10 @@ mt7915_eeprom_load_default(struct mt7915_dev *dev)
developerc5ce7502022-12-19 11:33:22 +0800135 return ret;
136
137 if (!fw || !fw->data) {
138- dev_err(dev->mt76.dev, "Invalid default bin\n");
139+ if (dev->bin_file_mode)
140+ dev_err(dev->mt76.dev, "Invalid bin (bin file mode)\n");
141+ else
142+ dev_err(dev->mt76.dev, "Invalid default bin\n");
143 ret = -EINVAL;
144 goto out;
145 }
developera46f6132024-03-26 14:09:54 +0800146@@ -126,6 +159,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev)
developerc5ce7502022-12-19 11:33:22 +0800147
148 if (ret) {
149 dev->flash_mode = true;
150+ dev->eeprom_mode = FLASH_MODE;
151 } else {
152 u8 free_block_num;
153 u32 block_num, i;
developera46f6132024-03-26 14:09:54 +0800154@@ -146,6 +180,8 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev)
developerc5ce7502022-12-19 11:33:22 +0800155 if (ret < 0)
156 return ret;
157 }
158+
159+ dev->eeprom_mode = EFUSE_MODE;
160 }
161
162 return mt7915_check_eeprom(dev);
developera46f6132024-03-26 14:09:54 +0800163@@ -251,12 +287,33 @@ int mt7915_eeprom_init(struct mt7915_dev *dev)
developerc5ce7502022-12-19 11:33:22 +0800164 {
165 int ret;
166
167- ret = mt7915_eeprom_load(dev);
168+ dev->bin_file_mode = mt76_check_bin_file_mode(&dev->mt76);
169+ if (dev->bin_file_mode) {
170+ dev->mt76.eeprom.size = mt7915_eeprom_size(dev);
171+ dev->mt76.eeprom.data = devm_kzalloc(dev->mt76.dev, dev->mt76.eeprom.size,
172+ GFP_KERNEL);
173+ if (!dev->mt76.eeprom.data)
174+ return -ENOMEM;
175+ ret = mt7915_eeprom_load_default(dev);
176+ if (ret)
177+ return ret;
178+
179+ ret = mt7915_check_eeprom(dev);
180+ if (ret)
181+ return ret;
182+ dev->eeprom_mode = BIN_FILE_MODE;
183+ } else {
184+ ret = mt7915_eeprom_load(dev);
185+ }
186+
187 if (ret < 0) {
188 if (ret != -EINVAL)
189 return ret;
190
191 dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n");
192+ dev->bin_file_mode = false;
193+ dev->eeprom_mode = DEFAULT_BIN_MODE;
194+
195 ret = mt7915_eeprom_load_default(dev);
196 if (ret)
197 return ret;
198diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h
developer05f3b2b2024-08-19 19:17:34 +0800199index 509fb43d..99101f91 100644
developerc5ce7502022-12-19 11:33:22 +0800200--- a/mt7915/eeprom.h
201+++ b/mt7915/eeprom.h
developera46f6132024-03-26 14:09:54 +0800202@@ -109,6 +109,13 @@ enum mt7915_sku_rate_group {
developerc5ce7502022-12-19 11:33:22 +0800203 MAX_SKU_RATE_GROUP_NUM,
204 };
205
206+enum mt7915_eeprom_mode {
207+ DEFAULT_BIN_MODE,
208+ EFUSE_MODE,
209+ FLASH_MODE,
210+ BIN_FILE_MODE,
211+};
212+
213 static inline int
214 mt7915_get_channel_group_5g(int channel, bool is_7976)
215 {
216diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developer05f3b2b2024-08-19 19:17:34 +0800217index 141c151e..2fb8e2fb 100644
developerc5ce7502022-12-19 11:33:22 +0800218--- a/mt7915/mt7915.h
219+++ b/mt7915/mt7915.h
developer05f3b2b2024-08-19 19:17:34 +0800220@@ -414,6 +414,8 @@ struct mt7915_dev {
developerc5ce7502022-12-19 11:33:22 +0800221
222 bool dbdc_support;
223 bool flash_mode;
224+ bool bin_file_mode;
225+ u8 eeprom_mode;
226 bool muru_debug;
227 bool ibf;
228
developer05f3b2b2024-08-19 19:17:34 +0800229@@ -802,6 +804,7 @@ void mt7915_dump_tmac_info(u8 *tmac_info);
developerc5ce7502022-12-19 11:33:22 +0800230 int mt7915_mcu_set_txpower_level(struct mt7915_phy *phy, u8 drop_level);
231 void mt7915_packet_log_to_host(struct mt7915_dev *dev, const void *data, int len, int type, int des_len);
232 int mt7915_mcu_set_amsdu_algo(struct mt7915_dev *dev, u16 wcid, u8 enable);
233+const char *mt7915_eeprom_name(struct mt7915_dev *dev);
234
235 #define PKT_BIN_DEBUG_MAGIC 0xc8763123
236 enum {
237diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c
developer05f3b2b2024-08-19 19:17:34 +0800238index 02fe61a3..76f4849e 100644
developerc5ce7502022-12-19 11:33:22 +0800239--- a/mt7915/mtk_debugfs.c
240+++ b/mt7915/mtk_debugfs.c
241@@ -3,6 +3,7 @@
242 #include "mt7915_debug.h"
243 #include "mac.h"
244 #include "mcu.h"
245+#include "eeprom.h"
246
247 #ifdef MTK_DEBUG
248 #define LWTBL_IDX2BASE_ID GENMASK(14, 8)
developera46f6132024-03-26 14:09:54 +0800249@@ -3728,6 +3729,47 @@ static int mt7915_fw_wm_info_read(struct seq_file *s, void *data)
developer8effbd32023-04-17 15:57:28 +0800250 return 0;
251 }
developerc5ce7502022-12-19 11:33:22 +0800252
253+static int mt7915_show_eeprom_mode(struct seq_file *s, void *data)
254+{
255+ struct mt7915_dev *dev = dev_get_drvdata(s->private);
256+ struct mt76_dev *mdev = &dev->mt76;
developerac332462023-04-19 10:12:02 +0800257+ u8 free_block_num = 0;
developerc5ce7502022-12-19 11:33:22 +0800258+#ifdef CONFIG_NL80211_TESTMODE
259+ const char *mtd_name = mdev->test_mtd.name;
260+ u32 mtd_offset = mdev->test_mtd.offset;
261+#else
262+ const char *mtd_name = NULL;
263+ u32 mtd_offset;
264+#endif
265+
266+ seq_printf(s, "Current eeprom mode:\n");
267+
268+ switch (dev->eeprom_mode) {
269+ case DEFAULT_BIN_MODE:
270+ seq_printf(s, " default bin mode\n filename = %s\n", mt7915_eeprom_name(dev));
271+ break;
272+ case EFUSE_MODE:
273+ seq_printf(s, " efuse mode\n");
developerac332462023-04-19 10:12:02 +0800274+ mt7915_mcu_get_eeprom_free_block(dev, &free_block_num);
275+ seq_printf(s, " free block number = %d\n", free_block_num);
developerc5ce7502022-12-19 11:33:22 +0800276+ break;
277+ case FLASH_MODE:
278+ if (mtd_name)
279+ seq_printf(s, " flash mode\n mtd name = %s\n flash offset = 0x%x\n",
280+ mtd_name, mtd_offset);
281+ else
282+ seq_printf(s, " flash mode\n");
283+ break;
284+ case BIN_FILE_MODE:
285+ seq_printf(s, " bin file mode\n filename = %s\n", mt7915_eeprom_name(dev));
286+ break;
287+ default:
288+ break;
289+ }
290+
291+ return 0;
292+}
293+
294 int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir)
295 {
296 struct mt7915_dev *dev = phy->dev;
developera46f6132024-03-26 14:09:54 +0800297@@ -3814,6 +3856,8 @@ int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir)
developer67705712023-05-30 11:58:00 +0800298
299 debugfs_create_u8("sku_disable", 0600, dir, &dev->dbg.sku_disable);
developerc5ce7502022-12-19 11:33:22 +0800300
301+ debugfs_create_devm_seqfile(dev->mt76.dev, "eeprom_mode", dir,
302+ mt7915_show_eeprom_mode);
303 return 0;
304 }
305 #endif
developer70180b02023-11-14 17:01:47 +0800306diff --git a/testmode.h b/testmode.h
developer05f3b2b2024-08-19 19:17:34 +0800307index 20fab3ec..91d1e867 100644
developer70180b02023-11-14 17:01:47 +0800308--- a/testmode.h
309+++ b/testmode.h
310@@ -17,7 +17,7 @@
311 * @MT76_TM_ATTR_RESET: reset parameters to default (flag)
312 * @MT76_TM_ATTR_STATE: test state (u32), see &enum mt76_testmode_state
313 *
314- * @MT76_TM_ATTR_MTD_PART: mtd partition used for eeprom data (string)
315+ * @MT76_TM_ATTR_MTD_PART: mtd partition or binfile used for eeprom data (string)
316 * @MT76_TM_ATTR_MTD_OFFSET: offset of eeprom data within the partition (u32)
317 * @MT76_TM_ATTR_BAND_IDX: band idx of the chip (u8)
318 *
developerc5ce7502022-12-19 11:33:22 +0800319--
developerbd9fa1e2023-10-16 11:04:00 +08003202.18.0
developerc5ce7502022-12-19 11:33:22 +0800321