blob: 09d1f9542cc4db551c95351630a6f1d458c3ab37 [file] [log] [blame]
developer3a388772023-04-19 10:12:02 +08001From c8744205bdfda122ef0cc2bb7b0105dac23b6f8b 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
developer3a388772023-04-19 10:12:02 +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---
9 eeprom.c | 20 ++++++++++++++++++++
10 mt76.h | 3 +++
11 mt7915/eeprom.c | 36 +++++++++++++++++++++++++++++++++---
12 mt7915/eeprom.h | 7 +++++++
13 mt7915/mt7915.h | 9 ++++++---
developer3a388772023-04-19 10:12:02 +080014 mt7915/mtk_debugfs.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
15 6 files changed, 113 insertions(+), 6 deletions(-)
developer2aa1e642022-12-19 11:33:22 +080016
17diff --git a/eeprom.c b/eeprom.c
developera43cc482023-04-17 15:57:28 +080018index aa88925..412740f 100644
developer2aa1e642022-12-19 11:33:22 +080019--- a/eeprom.c
20+++ b/eeprom.c
21@@ -104,6 +104,26 @@ out_put_node:
22 }
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;
28+ const char *bin_file_name = NULL;
29+
30+ if (!np)
31+ return false;
32+
33+ 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);
38+
39+ of_node_put(np);
40+
41+ return dev->bin_file_name ? true : false;
42+}
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
developera43cc482023-04-17 15:57:28 +080049index 699bb77..614c607 100644
developer2aa1e642022-12-19 11:33:22 +080050--- a/mt76.h
51+++ b/mt76.h
developera43cc482023-04-17 15:57:28 +080052@@ -905,9 +905,11 @@ struct mt76_dev {
developer2aa1e642022-12-19 11:33:22 +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 {
developera43cc482023-04-17 15:57:28 +080064@@ -1044,6 +1046,7 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str,
developer2aa1e642022-12-19 11:33:22 +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
developera43cc482023-04-17 15:57:28 +080073index 77a1047..612be3f 100644
developer2aa1e642022-12-19 11:33:22 +080074--- a/mt7915/eeprom.c
75+++ b/mt7915/eeprom.c
76@@ -45,8 +45,11 @@ static int mt7915_check_eeprom(struct mt7915_dev *dev)
77 }
78 }
79
80-static char *mt7915_eeprom_name(struct mt7915_dev *dev)
81+const char *mt7915_eeprom_name(struct mt7915_dev *dev)
82 {
83+ 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)
90 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 }
101@@ -109,6 +115,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev)
102
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;
109@@ -129,6 +136,8 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev)
110 if (ret < 0)
111 return ret;
112 }
113+
114+ dev->eeprom_mode = EFUSE_MODE;
115 }
116
117 return mt7915_check_eeprom(dev);
118@@ -234,12 +243,33 @@ int mt7915_eeprom_init(struct mt7915_dev *dev)
119 {
120 int ret;
121
122- ret = mt7915_eeprom_load(dev);
123+ dev->bin_file_mode = mt76_check_bin_file_mode(&dev->mt76);
124+ 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,
127+ GFP_KERNEL);
128+ if (!dev->mt76.eeprom.data)
129+ return -ENOMEM;
130+ ret = mt7915_eeprom_load_default(dev);
131+ if (ret)
132+ return ret;
133+
134+ ret = mt7915_check_eeprom(dev);
135+ if (ret)
136+ return ret;
137+ dev->eeprom_mode = BIN_FILE_MODE;
138+ } else {
139+ ret = mt7915_eeprom_load(dev);
140+ }
141+
142 if (ret < 0) {
143 if (ret != -EINVAL)
144 return ret;
145
146 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;
149+
150 ret = mt7915_eeprom_load_default(dev);
151 if (ret)
152 return ret;
153diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h
developera43cc482023-04-17 15:57:28 +0800154index fdae347..9056d78 100644
developer2aa1e642022-12-19 11:33:22 +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 {
171diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developera43cc482023-04-17 15:57:28 +0800172index ca81289..17efd20 100644
developer2aa1e642022-12-19 11:33:22 +0800173--- a/mt7915/mt7915.h
174+++ b/mt7915/mt7915.h
175@@ -42,9 +42,9 @@
176 #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"
developera43cc482023-04-17 15:57:28 +0800188@@ -408,6 +408,8 @@ struct mt7915_dev {
developer2aa1e642022-12-19 11:33:22 +0800189
190 bool dbdc_support;
191 bool flash_mode;
192+ bool bin_file_mode;
193+ u8 eeprom_mode;
194 bool muru_debug;
195 bool ibf;
196
developera43cc482023-04-17 15:57:28 +0800197@@ -785,6 +787,7 @@ void mt7915_dump_tmac_info(u8 *tmac_info);
developer2aa1e642022-12-19 11:33:22 +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 {
205diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c
developer3a388772023-04-19 10:12:02 +0800206index 69dc311..53d10e3 100644
developer2aa1e642022-12-19 11:33:22 +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)
developer3a388772023-04-19 10:12:02 +0800217@@ -3602,6 +3603,47 @@ static int mt7915_fw_wm_info_read(struct seq_file *s, void *data)
developera43cc482023-04-17 15:57:28 +0800218 return 0;
219 }
developer2aa1e642022-12-19 11:33:22 +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;
developer3a388772023-04-19 10:12:02 +0800225+ u8 free_block_num = 0;
developer2aa1e642022-12-19 11:33:22 +0800226+#ifdef CONFIG_NL80211_TESTMODE
227+ const char *mtd_name = mdev->test_mtd.name;
228+ u32 mtd_offset = mdev->test_mtd.offset;
229+#else
230+ const char *mtd_name = NULL;
231+ u32 mtd_offset;
232+#endif
233+
234+ seq_printf(s, "Current eeprom mode:\n");
235+
236+ switch (dev->eeprom_mode) {
237+ case DEFAULT_BIN_MODE:
238+ seq_printf(s, " default bin mode\n filename = %s\n", mt7915_eeprom_name(dev));
239+ break;
240+ case EFUSE_MODE:
241+ seq_printf(s, " efuse mode\n");
developer3a388772023-04-19 10:12:02 +0800242+ mt7915_mcu_get_eeprom_free_block(dev, &free_block_num);
243+ seq_printf(s, " free block number = %d\n", free_block_num);
developer2aa1e642022-12-19 11:33:22 +0800244+ break;
245+ case FLASH_MODE:
246+ if (mtd_name)
247+ seq_printf(s, " flash mode\n mtd name = %s\n flash offset = 0x%x\n",
248+ mtd_name, mtd_offset);
249+ else
250+ seq_printf(s, " flash mode\n");
251+ break;
252+ case BIN_FILE_MODE:
253+ seq_printf(s, " bin file mode\n filename = %s\n", mt7915_eeprom_name(dev));
254+ break;
255+ default:
256+ break;
257+ }
258+
259+ return 0;
260+}
261+
262 int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir)
263 {
264 struct mt7915_dev *dev = phy->dev;
developer3a388772023-04-19 10:12:02 +0800265@@ -3689,6 +3731,8 @@ int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir)
developer2aa1e642022-12-19 11:33:22 +0800266 debugfs_create_devm_seqfile(dev->mt76.dev, "fw_version", dir,
267 mt7915_dump_version);
268
269+ debugfs_create_devm_seqfile(dev->mt76.dev, "eeprom_mode", dir,
270+ mt7915_show_eeprom_mode);
271 return 0;
272 }
273 #endif
274--
developera43cc482023-04-17 15:57:28 +08002752.18.0
developer2aa1e642022-12-19 11:33:22 +0800276