blob: c8514076c80fb43f9542b411334836c2bfc1dc8b [file] [log] [blame]
developer2324aa22023-04-12 11:30:15 +08001From 62b2e8817ae9746ef33ba0fe478a314c33f0cb06 Mon Sep 17 00:00:00 2001
developerceb40012022-07-07 17:30:32 +08002From: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
3Date: Thu, 7 Jul 2022 11:09:59 +0800
developerc9233442023-04-04 06:06:17 +08004Subject: [PATCH 1020/1031] wifi: mt76: mt7915: implement bin file mode
developerceb40012022-07-07 17:30:32 +08005
developerceb40012022-07-07 17:30:32 +08006Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com>
developer30d39c22022-12-16 10:29:49 +08007Signed-off-by: Shayne Chen <shayne.chen@mediatek.com>
developerceb40012022-07-07 17:30:32 +08008---
developer30d39c22022-12-16 10:29:49 +08009 eeprom.c | 20 ++++++++++++++++++++
10 mt76.h | 3 +++
11 mt7915/eeprom.c | 36 +++++++++++++++++++++++++++++++++---
12 mt7915/eeprom.h | 7 +++++++
13 mt7915/mt7915.h | 9 ++++++---
14 mt7915/mtk_debugfs.c | 41 +++++++++++++++++++++++++++++++++++++++++
15 6 files changed, 110 insertions(+), 6 deletions(-)
developerceb40012022-07-07 17:30:32 +080016
17diff --git a/eeprom.c b/eeprom.c
developer2324aa22023-04-12 11:30:15 +080018index aa88925..412740f 100644
developerceb40012022-07-07 17:30:32 +080019--- a/eeprom.c
20+++ b/eeprom.c
developer30d39c22022-12-16 10:29:49 +080021@@ -104,6 +104,26 @@ out_put_node:
developerceb40012022-07-07 17:30:32 +080022 }
23 EXPORT_SYMBOL_GPL(mt76_get_of_eeprom);
24
25+bool mt76_check_bin_file_mode(struct mt76_dev *dev)
26+{
27+ struct device_node *np = dev->dev->of_node;
developer30d39c22022-12-16 10:29:49 +080028+ const char *bin_file_name = NULL;
developerceb40012022-07-07 17:30:32 +080029+
30+ if (!np)
31+ return false;
32+
developer30d39c22022-12-16 10:29:49 +080033+ of_property_read_string(np, "bin_file_name", &bin_file_name);
34+
35+ dev->bin_file_name = bin_file_name;
36+ if (dev->bin_file_name)
37+ dev_info(dev->dev, "Using bin file %s\n", dev->bin_file_name);
developerceb40012022-07-07 17:30:32 +080038+
39+ of_node_put(np);
developer30d39c22022-12-16 10:29:49 +080040+
41+ return dev->bin_file_name ? true : false;
developerceb40012022-07-07 17:30:32 +080042+}
43+EXPORT_SYMBOL_GPL(mt76_check_bin_file_mode);
44+
45 void
46 mt76_eeprom_override(struct mt76_phy *phy)
47 {
48diff --git a/mt76.h b/mt76.h
developer2324aa22023-04-12 11:30:15 +080049index d7ffe29..68b5457 100644
developerceb40012022-07-07 17:30:32 +080050--- a/mt76.h
51+++ b/mt76.h
developer4f0d84b2023-03-03 14:21:44 +080052@@ -901,9 +901,11 @@ struct mt76_dev {
developer30d39c22022-12-16 10:29:49 +080053 struct mt76_sdio sdio;
54 };
55
56+ /* for mtk internal */
57 struct mt76_connac2_patch_hdr *patch_hdr;
58 struct mt76_connac2_fw_trailer *wm_hdr;
59 struct mt76_connac2_fw_trailer *wa_hdr;
60+ const char *bin_file_name;
61 };
62
63 struct mt76_power_limits {
developer4f0d84b2023-03-03 14:21:44 +080064@@ -1040,6 +1042,7 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str,
developerceb40012022-07-07 17:30:32 +080065 int mt76_eeprom_init(struct mt76_dev *dev, int len);
66 void mt76_eeprom_override(struct mt76_phy *phy);
67 int mt76_get_of_eeprom(struct mt76_dev *dev, void *data, int offset, int len);
68+bool mt76_check_bin_file_mode(struct mt76_dev *dev);
69
70 struct mt76_queue *
71 mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc,
72diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c
developer2324aa22023-04-12 11:30:15 +080073index 77a1047..612be3f 100644
developerceb40012022-07-07 17:30:32 +080074--- a/mt7915/eeprom.c
75+++ b/mt7915/eeprom.c
developer30d39c22022-12-16 10:29:49 +080076@@ -45,8 +45,11 @@ static int mt7915_check_eeprom(struct mt7915_dev *dev)
developer29647af2022-11-15 18:09:16 +080077 }
78 }
79
80-static char *mt7915_eeprom_name(struct mt7915_dev *dev)
developer30d39c22022-12-16 10:29:49 +080081+const char *mt7915_eeprom_name(struct mt7915_dev *dev)
developer29647af2022-11-15 18:09:16 +080082 {
developer30d39c22022-12-16 10:29:49 +080083+ if (dev->bin_file_mode)
84+ return dev->mt76.bin_file_name;
85+
86 switch (mt76_chip(&dev->mt76)) {
87 case 0x7915:
88 return dev->dbdc_support ?
89@@ -84,7 +87,10 @@ mt7915_eeprom_load_default(struct mt7915_dev *dev)
developerceb40012022-07-07 17:30:32 +080090 return ret;
91
92 if (!fw || !fw->data) {
93- dev_err(dev->mt76.dev, "Invalid default bin\n");
94+ if (dev->bin_file_mode)
95+ dev_err(dev->mt76.dev, "Invalid bin (bin file mode)\n");
96+ else
97+ dev_err(dev->mt76.dev, "Invalid default bin\n");
98 ret = -EINVAL;
99 goto out;
100 }
developer30d39c22022-12-16 10:29:49 +0800101@@ -109,6 +115,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev)
developer29647af2022-11-15 18:09:16 +0800102
103 if (ret) {
104 dev->flash_mode = true;
105+ dev->eeprom_mode = FLASH_MODE;
106 } else {
107 u8 free_block_num;
108 u32 block_num, i;
developer30d39c22022-12-16 10:29:49 +0800109@@ -129,6 +136,8 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev)
developereb6a0182022-12-12 18:53:32 +0800110 if (ret < 0)
111 return ret;
112 }
113+
developer29647af2022-11-15 18:09:16 +0800114+ dev->eeprom_mode = EFUSE_MODE;
115 }
116
117 return mt7915_check_eeprom(dev);
developer30d39c22022-12-16 10:29:49 +0800118@@ -234,12 +243,33 @@ int mt7915_eeprom_init(struct mt7915_dev *dev)
developerceb40012022-07-07 17:30:32 +0800119 {
120 int ret;
121
122- ret = mt7915_eeprom_load(dev);
123+ dev->bin_file_mode = mt76_check_bin_file_mode(&dev->mt76);
developerceb40012022-07-07 17:30:32 +0800124+ if (dev->bin_file_mode) {
125+ dev->mt76.eeprom.size = mt7915_eeprom_size(dev);
126+ dev->mt76.eeprom.data = devm_kzalloc(dev->mt76.dev, dev->mt76.eeprom.size,
developer29647af2022-11-15 18:09:16 +0800127+ GFP_KERNEL);
developerceb40012022-07-07 17:30:32 +0800128+ if (!dev->mt76.eeprom.data)
129+ return -ENOMEM;
130+ ret = mt7915_eeprom_load_default(dev);
developer30d39c22022-12-16 10:29:49 +0800131+ if (ret)
132+ return ret;
133+
134+ ret = mt7915_check_eeprom(dev);
135+ if (ret)
136+ return ret;
developer29647af2022-11-15 18:09:16 +0800137+ dev->eeprom_mode = BIN_FILE_MODE;
developerceb40012022-07-07 17:30:32 +0800138+ } else {
139+ ret = mt7915_eeprom_load(dev);
140+ }
141+
142 if (ret < 0) {
143 if (ret != -EINVAL)
144 return ret;
145
developer29647af2022-11-15 18:09:16 +0800146 dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n");
147+ dev->bin_file_mode = false;
148+ dev->eeprom_mode = DEFAULT_BIN_MODE;
developerceb40012022-07-07 17:30:32 +0800149+
150 ret = mt7915_eeprom_load_default(dev);
151 if (ret)
152 return ret;
developer29647af2022-11-15 18:09:16 +0800153diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h
developer2324aa22023-04-12 11:30:15 +0800154index fdae347..9056d78 100644
developer29647af2022-11-15 18:09:16 +0800155--- a/mt7915/eeprom.h
156+++ b/mt7915/eeprom.h
157@@ -108,6 +108,13 @@ enum mt7915_sku_rate_group {
158 MAX_SKU_RATE_GROUP_NUM,
159 };
160
161+enum mt7915_eeprom_mode {
162+ DEFAULT_BIN_MODE,
163+ EFUSE_MODE,
164+ FLASH_MODE,
165+ BIN_FILE_MODE,
166+};
167+
168 static inline int
169 mt7915_get_channel_group_5g(int channel, bool is_7976)
170 {
developerceb40012022-07-07 17:30:32 +0800171diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developer2324aa22023-04-12 11:30:15 +0800172index 05ae67c..0c133a9 100644
developerceb40012022-07-07 17:30:32 +0800173--- a/mt7915/mt7915.h
174+++ b/mt7915/mt7915.h
developer30d39c22022-12-16 10:29:49 +0800175@@ -42,9 +42,9 @@
developer29647af2022-11-15 18:09:16 +0800176 #define MT7986_ROM_PATCH "mediatek/mt7986_rom_patch.bin"
177 #define MT7986_ROM_PATCH_MT7975 "mediatek/mt7986_rom_patch_mt7975.bin"
178
179-#define MT7915_EEPROM_DEFAULT "mediatek/mt7915_eeprom.bin"
180-#define MT7915_EEPROM_DEFAULT_DBDC "mediatek/mt7915_eeprom_dbdc.bin"
181-#define MT7916_EEPROM_DEFAULT "mediatek/mt7916_eeprom.bin"
182+#define MT7915_EEPROM_DEFAULT "mediatek/mt7915_eeprom.bin"
183+#define MT7915_EEPROM_DEFAULT_DBDC "mediatek/mt7915_eeprom_dbdc.bin"
184+#define MT7916_EEPROM_DEFAULT "mediatek/mt7916_eeprom.bin"
185 #define MT7986_EEPROM_MT7975_DEFAULT "mediatek/mt7986_eeprom_mt7975.bin"
186 #define MT7986_EEPROM_MT7975_DUAL_DEFAULT "mediatek/mt7986_eeprom_mt7975_dual.bin"
187 #define MT7986_EEPROM_MT7976_DEFAULT "mediatek/mt7986_eeprom_mt7976.bin"
developerfd8e1152023-02-14 11:29:23 +0800188@@ -403,6 +403,8 @@ struct mt7915_dev {
developerceb40012022-07-07 17:30:32 +0800189
190 bool dbdc_support;
191 bool flash_mode;
192+ bool bin_file_mode;
developer29647af2022-11-15 18:09:16 +0800193+ u8 eeprom_mode;
developerceb40012022-07-07 17:30:32 +0800194 bool muru_debug;
195 bool ibf;
196
developer2324aa22023-04-12 11:30:15 +0800197@@ -779,6 +781,7 @@ void mt7915_dump_tmac_info(u8 *tmac_info);
developer30d39c22022-12-16 10:29:49 +0800198 int mt7915_mcu_set_txpower_level(struct mt7915_phy *phy, u8 drop_level);
199 void mt7915_packet_log_to_host(struct mt7915_dev *dev, const void *data, int len, int type, int des_len);
200 int mt7915_mcu_set_amsdu_algo(struct mt7915_dev *dev, u16 wcid, u8 enable);
201+const char *mt7915_eeprom_name(struct mt7915_dev *dev);
202
203 #define PKT_BIN_DEBUG_MAGIC 0xc8763123
204 enum {
developer29647af2022-11-15 18:09:16 +0800205diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c
developer2324aa22023-04-12 11:30:15 +0800206index 69dc311..4c94ed3 100644
developer29647af2022-11-15 18:09:16 +0800207--- a/mt7915/mtk_debugfs.c
208+++ b/mt7915/mtk_debugfs.c
209@@ -3,6 +3,7 @@
210 #include "mt7915_debug.h"
211 #include "mac.h"
212 #include "mcu.h"
213+#include "eeprom.h"
214
215 #ifdef MTK_DEBUG
216 #define LWTBL_IDX2BASE_ID GENMASK(14, 8)
developer2324aa22023-04-12 11:30:15 +0800217@@ -3602,6 +3603,44 @@ static int mt7915_fw_wm_info_read(struct seq_file *s, void *data)
218 return 0;
219 }
developer29647af2022-11-15 18:09:16 +0800220
221+static int mt7915_show_eeprom_mode(struct seq_file *s, void *data)
222+{
223+ struct mt7915_dev *dev = dev_get_drvdata(s->private);
224+ struct mt76_dev *mdev = &dev->mt76;
developerf84ff072022-11-17 18:04:25 +0800225+#ifdef CONFIG_NL80211_TESTMODE
developereb6a0182022-12-12 18:53:32 +0800226+ const char *mtd_name = mdev->test_mtd.name;
developer29647af2022-11-15 18:09:16 +0800227+ u32 mtd_offset = mdev->test_mtd.offset;
developerf84ff072022-11-17 18:04:25 +0800228+#else
developereb6a0182022-12-12 18:53:32 +0800229+ const char *mtd_name = NULL;
developerf84ff072022-11-17 18:04:25 +0800230+ u32 mtd_offset;
231+#endif
developer29647af2022-11-15 18:09:16 +0800232+
233+ seq_printf(s, "Current eeprom mode:\n");
234+
235+ switch (dev->eeprom_mode) {
236+ case DEFAULT_BIN_MODE:
237+ seq_printf(s, " default bin mode\n filename = %s\n", mt7915_eeprom_name(dev));
238+ break;
239+ case EFUSE_MODE:
240+ seq_printf(s, " efuse mode\n");
241+ break;
242+ case FLASH_MODE:
243+ if (mtd_name)
244+ seq_printf(s, " flash mode\n mtd name = %s\n flash offset = 0x%x\n",
245+ mtd_name, mtd_offset);
246+ else
247+ seq_printf(s, " flash mode\n");
248+ break;
249+ case BIN_FILE_MODE:
250+ seq_printf(s, " bin file mode\n filename = %s\n", mt7915_eeprom_name(dev));
251+ break;
252+ default:
253+ break;
254+ }
255+
256+ return 0;
257+}
258+
259 int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir)
260 {
261 struct mt7915_dev *dev = phy->dev;
developer2324aa22023-04-12 11:30:15 +0800262@@ -3689,6 +3728,8 @@ int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir)
developer29647af2022-11-15 18:09:16 +0800263 debugfs_create_devm_seqfile(dev->mt76.dev, "fw_version", dir,
264 mt7915_dump_version);
265
266+ debugfs_create_devm_seqfile(dev->mt76.dev, "eeprom_mode", dir,
267+ mt7915_show_eeprom_mode);
268 return 0;
269 }
270 #endif
developerceb40012022-07-07 17:30:32 +0800271--
developer2324aa22023-04-12 11:30:15 +08002722.18.0
developerceb40012022-07-07 17:30:32 +0800273