blob: 230ef8154bd5a64619b147fb92075f2a1f372313 [file] [log] [blame]
developerbf0f2d62023-11-14 17:01:47 +08001From b33cf2d53b4719f00d96ba1b5280b7df593870cf Mon Sep 17 00:00:00 2001
developer2aa1e642022-12-19 11:33:22 +08002From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Thu, 7 Jul 2022 11:09:59 +0800
developerbf0f2d62023-11-14 17:01:47 +08004Subject: [PATCH] wifi: mt76: mt7915: implement bin file mode
developer2aa1e642022-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---
developerbf0f2d62023-11-14 17:01:47 +08009 eeprom.c | 25 +++++++++++++++++
10 mt76.h | 4 +++
11 mt7915/eeprom.c | 65 +++++++++++++++++++++++++++++++++++++++++---
12 mt7915/eeprom.h | 7 +++++
13 mt7915/mt7915.h | 3 ++
14 mt7915/mtk_debugfs.c | 44 ++++++++++++++++++++++++++++++
15 testmode.h | 2 +-
16 7 files changed, 145 insertions(+), 5 deletions(-)
developer2aa1e642022-12-19 11:33:22 +080017
18diff --git a/eeprom.c b/eeprom.c
developerbf0f2d62023-11-14 17:01:47 +080019index 9b63799..d5b8c56 100644
developer2aa1e642022-12-19 11:33:22 +080020--- a/eeprom.c
21+++ b/eeprom.c
developerbf0f2d62023-11-14 17:01:47 +080022@@ -159,6 +159,31 @@ int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len)
developer2aa1e642022-12-19 11:33:22 +080023 }
24 EXPORT_SYMBOL_GPL(mt76_get_of_eeprom);
25
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;
developerbf0f2d62023-11-14 17:01:47 +080037+ if (dev->bin_file_name) {
developer2aa1e642022-12-19 11:33:22 +080038+ dev_info(dev->dev, "Using bin file %s\n", dev->bin_file_name);
developerbf0f2d62023-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+ }
developer2aa1e642022-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
developerbf0f2d62023-11-14 17:01:47 +080055index d16accd..9673926 100644
developer2aa1e642022-12-19 11:33:22 +080056--- a/mt76.h
57+++ b/mt76.h
developerbf0f2d62023-11-14 17:01:47 +080058@@ -943,6 +943,9 @@ struct mt76_dev {
developer8e5fecd2023-05-30 11:58:00 +080059 struct mt76_usb usb;
developer2aa1e642022-12-19 11:33:22 +080060 struct mt76_sdio sdio;
61 };
developer8e5fecd2023-05-30 11:58:00 +080062+
developer2aa1e642022-12-19 11:33:22 +080063+ /* for mtk internal */
developer2aa1e642022-12-19 11:33:22 +080064+ const char *bin_file_name;
65 };
66
developer004e50c2023-06-29 20:33:22 +080067 /* per-phy stats. */
developerbf0f2d62023-11-14 17:01:47 +080068@@ -1175,6 +1178,7 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str,
developer2aa1e642022-12-19 11:33:22 +080069 int mt76_eeprom_init(struct mt76_dev *dev, int len);
70 void mt76_eeprom_override(struct mt76_phy *phy);
71 int mt76_get_of_eeprom(struct mt76_dev *dev, void *data, int offset, int len);
72+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
developerbf0f2d62023-11-14 17:01:47 +080077index a5c99a5..5eb9f88 100644
developer2aa1e642022-12-19 11:33:22 +080078--- a/mt7915/eeprom.c
79+++ b/mt7915/eeprom.c
developerbf0f2d62023-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;
111@@ -24,7 +48,10 @@ static int mt7915_eeprom_load_precal(struct mt7915_dev *dev)
112
113 offs = is_mt7915(&dev->mt76) ? MT_EE_PRECAL : MT_EE_PRECAL_V2;
114
115- return mt76_get_of_eeprom(mdev, dev->cal, offs, size);
116+ if (!dev->bin_file_mode)
117+ return mt76_get_of_eeprom(mdev, dev->cal, offs, size);
118+ else
119+ return mt7915_eeprom_load_precal_binfile(dev, offs, size);
120 }
121
122 static int mt7915_check_eeprom(struct mt7915_dev *dev)
123@@ -47,8 +74,11 @@ static int mt7915_check_eeprom(struct mt7915_dev *dev)
developer2aa1e642022-12-19 11:33:22 +0800124 }
125 }
126
127-static char *mt7915_eeprom_name(struct mt7915_dev *dev)
128+const char *mt7915_eeprom_name(struct mt7915_dev *dev)
129 {
130+ if (dev->bin_file_mode)
131+ return dev->mt76.bin_file_name;
132+
133 switch (mt76_chip(&dev->mt76)) {
134 case 0x7915:
135 return dev->dbdc_support ?
developerbf0f2d62023-11-14 17:01:47 +0800136@@ -89,7 +119,10 @@ mt7915_eeprom_load_default(struct mt7915_dev *dev)
developer2aa1e642022-12-19 11:33:22 +0800137 return ret;
138
139 if (!fw || !fw->data) {
140- dev_err(dev->mt76.dev, "Invalid default bin\n");
141+ if (dev->bin_file_mode)
142+ dev_err(dev->mt76.dev, "Invalid bin (bin file mode)\n");
143+ else
144+ dev_err(dev->mt76.dev, "Invalid default bin\n");
145 ret = -EINVAL;
146 goto out;
147 }
developerbf0f2d62023-11-14 17:01:47 +0800148@@ -114,6 +147,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev)
developer2aa1e642022-12-19 11:33:22 +0800149
150 if (ret) {
151 dev->flash_mode = true;
152+ dev->eeprom_mode = FLASH_MODE;
153 } else {
154 u8 free_block_num;
155 u32 block_num, i;
developerbf0f2d62023-11-14 17:01:47 +0800156@@ -134,6 +168,8 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev)
developer2aa1e642022-12-19 11:33:22 +0800157 if (ret < 0)
158 return ret;
159 }
160+
161+ dev->eeprom_mode = EFUSE_MODE;
162 }
163
164 return mt7915_check_eeprom(dev);
developerbf0f2d62023-11-14 17:01:47 +0800165@@ -239,12 +275,33 @@ int mt7915_eeprom_init(struct mt7915_dev *dev)
developer2aa1e642022-12-19 11:33:22 +0800166 {
167 int ret;
168
169- ret = mt7915_eeprom_load(dev);
170+ dev->bin_file_mode = mt76_check_bin_file_mode(&dev->mt76);
171+ if (dev->bin_file_mode) {
172+ dev->mt76.eeprom.size = mt7915_eeprom_size(dev);
173+ dev->mt76.eeprom.data = devm_kzalloc(dev->mt76.dev, dev->mt76.eeprom.size,
174+ GFP_KERNEL);
175+ if (!dev->mt76.eeprom.data)
176+ return -ENOMEM;
177+ ret = mt7915_eeprom_load_default(dev);
178+ if (ret)
179+ return ret;
180+
181+ ret = mt7915_check_eeprom(dev);
182+ if (ret)
183+ return ret;
184+ dev->eeprom_mode = BIN_FILE_MODE;
185+ } else {
186+ ret = mt7915_eeprom_load(dev);
187+ }
188+
189 if (ret < 0) {
190 if (ret != -EINVAL)
191 return ret;
192
193 dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n");
194+ dev->bin_file_mode = false;
195+ dev->eeprom_mode = DEFAULT_BIN_MODE;
196+
197 ret = mt7915_eeprom_load_default(dev);
198 if (ret)
199 return ret;
200diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h
developere35b8e42023-10-16 11:04:00 +0800201index fdae347..9056d78 100644
developer2aa1e642022-12-19 11:33:22 +0800202--- a/mt7915/eeprom.h
203+++ b/mt7915/eeprom.h
204@@ -108,6 +108,13 @@ enum mt7915_sku_rate_group {
205 MAX_SKU_RATE_GROUP_NUM,
206 };
207
208+enum mt7915_eeprom_mode {
209+ DEFAULT_BIN_MODE,
210+ EFUSE_MODE,
211+ FLASH_MODE,
212+ BIN_FILE_MODE,
213+};
214+
215 static inline int
216 mt7915_get_channel_group_5g(int channel, bool is_7976)
217 {
218diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developerbf0f2d62023-11-14 17:01:47 +0800219index 795af63..992323d 100644
developer2aa1e642022-12-19 11:33:22 +0800220--- a/mt7915/mt7915.h
221+++ b/mt7915/mt7915.h
developerbf0f2d62023-11-14 17:01:47 +0800222@@ -351,6 +351,8 @@ struct mt7915_dev {
developer2aa1e642022-12-19 11:33:22 +0800223
224 bool dbdc_support;
225 bool flash_mode;
226+ bool bin_file_mode;
227+ u8 eeprom_mode;
228 bool muru_debug;
229 bool ibf;
230
developerbf0f2d62023-11-14 17:01:47 +0800231@@ -727,6 +729,7 @@ void mt7915_dump_tmac_info(u8 *tmac_info);
developer2aa1e642022-12-19 11:33:22 +0800232 int mt7915_mcu_set_txpower_level(struct mt7915_phy *phy, u8 drop_level);
233 void mt7915_packet_log_to_host(struct mt7915_dev *dev, const void *data, int len, int type, int des_len);
234 int mt7915_mcu_set_amsdu_algo(struct mt7915_dev *dev, u16 wcid, u8 enable);
235+const char *mt7915_eeprom_name(struct mt7915_dev *dev);
236
237 #define PKT_BIN_DEBUG_MAGIC 0xc8763123
238 enum {
239diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c
developerbf0f2d62023-11-14 17:01:47 +0800240index 7105cf0..5c676d8 100644
developer2aa1e642022-12-19 11:33:22 +0800241--- a/mt7915/mtk_debugfs.c
242+++ b/mt7915/mtk_debugfs.c
243@@ -3,6 +3,7 @@
244 #include "mt7915_debug.h"
245 #include "mac.h"
246 #include "mcu.h"
247+#include "eeprom.h"
248
249 #ifdef MTK_DEBUG
250 #define LWTBL_IDX2BASE_ID GENMASK(14, 8)
developere35b8e42023-10-16 11:04:00 +0800251@@ -3600,6 +3601,47 @@ static int mt7915_fw_wm_info_read(struct seq_file *s, void *data)
developera43cc482023-04-17 15:57:28 +0800252 return 0;
253 }
developer2aa1e642022-12-19 11:33:22 +0800254
255+static int mt7915_show_eeprom_mode(struct seq_file *s, void *data)
256+{
257+ struct mt7915_dev *dev = dev_get_drvdata(s->private);
258+ struct mt76_dev *mdev = &dev->mt76;
developer3a388772023-04-19 10:12:02 +0800259+ u8 free_block_num = 0;
developer2aa1e642022-12-19 11:33:22 +0800260+#ifdef CONFIG_NL80211_TESTMODE
261+ const char *mtd_name = mdev->test_mtd.name;
262+ u32 mtd_offset = mdev->test_mtd.offset;
263+#else
264+ const char *mtd_name = NULL;
265+ u32 mtd_offset;
266+#endif
267+
268+ seq_printf(s, "Current eeprom mode:\n");
269+
270+ switch (dev->eeprom_mode) {
271+ case DEFAULT_BIN_MODE:
272+ seq_printf(s, " default bin mode\n filename = %s\n", mt7915_eeprom_name(dev));
273+ break;
274+ case EFUSE_MODE:
275+ seq_printf(s, " efuse mode\n");
developer3a388772023-04-19 10:12:02 +0800276+ mt7915_mcu_get_eeprom_free_block(dev, &free_block_num);
277+ seq_printf(s, " free block number = %d\n", free_block_num);
developer2aa1e642022-12-19 11:33:22 +0800278+ break;
279+ case FLASH_MODE:
280+ if (mtd_name)
281+ seq_printf(s, " flash mode\n mtd name = %s\n flash offset = 0x%x\n",
282+ mtd_name, mtd_offset);
283+ else
284+ seq_printf(s, " flash mode\n");
285+ break;
286+ case BIN_FILE_MODE:
287+ seq_printf(s, " bin file mode\n filename = %s\n", mt7915_eeprom_name(dev));
288+ break;
289+ default:
290+ break;
291+ }
292+
293+ return 0;
294+}
295+
296 int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir)
297 {
298 struct mt7915_dev *dev = phy->dev;
developere35b8e42023-10-16 11:04:00 +0800299@@ -3686,6 +3728,8 @@ int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir)
developer8e5fecd2023-05-30 11:58:00 +0800300
301 debugfs_create_u8("sku_disable", 0600, dir, &dev->dbg.sku_disable);
developer2aa1e642022-12-19 11:33:22 +0800302
303+ debugfs_create_devm_seqfile(dev->mt76.dev, "eeprom_mode", dir,
304+ mt7915_show_eeprom_mode);
305 return 0;
306 }
307 #endif
developerbf0f2d62023-11-14 17:01:47 +0800308diff --git a/testmode.h b/testmode.h
309index 20fab3e..91d1e86 100644
310--- a/testmode.h
311+++ b/testmode.h
312@@ -17,7 +17,7 @@
313 * @MT76_TM_ATTR_RESET: reset parameters to default (flag)
314 * @MT76_TM_ATTR_STATE: test state (u32), see &enum mt76_testmode_state
315 *
316- * @MT76_TM_ATTR_MTD_PART: mtd partition used for eeprom data (string)
317+ * @MT76_TM_ATTR_MTD_PART: mtd partition or binfile used for eeprom data (string)
318 * @MT76_TM_ATTR_MTD_OFFSET: offset of eeprom data within the partition (u32)
319 * @MT76_TM_ATTR_BAND_IDX: band idx of the chip (u8)
320 *
developer2aa1e642022-12-19 11:33:22 +0800321--
developere35b8e42023-10-16 11:04:00 +08003222.18.0
developer2aa1e642022-12-19 11:33:22 +0800323