blob: f747ddc6ccbcc4b674e992c4f7658d9e7c27892e [file] [log] [blame]
developer8e5fecd2023-05-30 11:58:00 +08001From 819b0590e6b8ef9e44e3f0a01c3db33eb236f463 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
developer8e5fecd2023-05-30 11:58:00 +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 ++++++++++++++++++++
developer8e5fecd2023-05-30 11:58:00 +080010 mt76.h | 4 ++++
developer2aa1e642022-12-19 11:33:22 +080011 mt7915/eeprom.c | 36 +++++++++++++++++++++++++++++++++---
12 mt7915/eeprom.h | 7 +++++++
developerad9333b2023-05-22 15:16:16 +080013 mt7915/mt7915.h | 3 +++
developer3a388772023-04-19 10:12:02 +080014 mt7915/mtk_debugfs.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
developer8e5fecd2023-05-30 11:58:00 +080015 6 files changed, 111 insertions(+), 3 deletions(-)
developer2aa1e642022-12-19 11:33:22 +080016
17diff --git a/eeprom.c b/eeprom.c
developer8e5fecd2023-05-30 11:58:00 +080018index aa889258..412740f0 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
developer8e5fecd2023-05-30 11:58:00 +080049index 0e29248d..b49590d5 100644
developer2aa1e642022-12-19 11:33:22 +080050--- a/mt76.h
51+++ b/mt76.h
developer8e5fecd2023-05-30 11:58:00 +080052@@ -916,6 +916,9 @@ struct mt76_dev {
53 struct mt76_usb usb;
developer2aa1e642022-12-19 11:33:22 +080054 struct mt76_sdio sdio;
55 };
developer8e5fecd2023-05-30 11:58:00 +080056+
developer2aa1e642022-12-19 11:33:22 +080057+ /* for mtk internal */
developer2aa1e642022-12-19 11:33:22 +080058+ const char *bin_file_name;
59 };
60
61 struct mt76_power_limits {
developer8e5fecd2023-05-30 11:58:00 +080062@@ -1052,6 +1055,7 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str,
developer2aa1e642022-12-19 11:33:22 +080063 int mt76_eeprom_init(struct mt76_dev *dev, int len);
64 void mt76_eeprom_override(struct mt76_phy *phy);
65 int mt76_get_of_eeprom(struct mt76_dev *dev, void *data, int offset, int len);
66+bool mt76_check_bin_file_mode(struct mt76_dev *dev);
67
68 struct mt76_queue *
69 mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc,
70diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c
developer8e5fecd2023-05-30 11:58:00 +080071index a5c99a5e..fd08d42a 100644
developer2aa1e642022-12-19 11:33:22 +080072--- a/mt7915/eeprom.c
73+++ b/mt7915/eeprom.c
developerad9333b2023-05-22 15:16:16 +080074@@ -47,8 +47,11 @@ static int mt7915_check_eeprom(struct mt7915_dev *dev)
developer2aa1e642022-12-19 11:33:22 +080075 }
76 }
77
78-static char *mt7915_eeprom_name(struct mt7915_dev *dev)
79+const char *mt7915_eeprom_name(struct mt7915_dev *dev)
80 {
81+ if (dev->bin_file_mode)
82+ return dev->mt76.bin_file_name;
83+
84 switch (mt76_chip(&dev->mt76)) {
85 case 0x7915:
86 return dev->dbdc_support ?
developerad9333b2023-05-22 15:16:16 +080087@@ -89,7 +92,10 @@ mt7915_eeprom_load_default(struct mt7915_dev *dev)
developer2aa1e642022-12-19 11:33:22 +080088 return ret;
89
90 if (!fw || !fw->data) {
91- dev_err(dev->mt76.dev, "Invalid default bin\n");
92+ if (dev->bin_file_mode)
93+ dev_err(dev->mt76.dev, "Invalid bin (bin file mode)\n");
94+ else
95+ dev_err(dev->mt76.dev, "Invalid default bin\n");
96 ret = -EINVAL;
97 goto out;
98 }
developerad9333b2023-05-22 15:16:16 +080099@@ -114,6 +120,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev)
developer2aa1e642022-12-19 11:33:22 +0800100
101 if (ret) {
102 dev->flash_mode = true;
103+ dev->eeprom_mode = FLASH_MODE;
104 } else {
105 u8 free_block_num;
106 u32 block_num, i;
developerad9333b2023-05-22 15:16:16 +0800107@@ -134,6 +141,8 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev)
developer2aa1e642022-12-19 11:33:22 +0800108 if (ret < 0)
109 return ret;
110 }
111+
112+ dev->eeprom_mode = EFUSE_MODE;
113 }
114
115 return mt7915_check_eeprom(dev);
developerad9333b2023-05-22 15:16:16 +0800116@@ -239,12 +248,33 @@ int mt7915_eeprom_init(struct mt7915_dev *dev)
developer2aa1e642022-12-19 11:33:22 +0800117 {
118 int ret;
119
120- ret = mt7915_eeprom_load(dev);
121+ dev->bin_file_mode = mt76_check_bin_file_mode(&dev->mt76);
122+ if (dev->bin_file_mode) {
123+ dev->mt76.eeprom.size = mt7915_eeprom_size(dev);
124+ dev->mt76.eeprom.data = devm_kzalloc(dev->mt76.dev, dev->mt76.eeprom.size,
125+ GFP_KERNEL);
126+ if (!dev->mt76.eeprom.data)
127+ return -ENOMEM;
128+ ret = mt7915_eeprom_load_default(dev);
129+ if (ret)
130+ return ret;
131+
132+ ret = mt7915_check_eeprom(dev);
133+ if (ret)
134+ return ret;
135+ dev->eeprom_mode = BIN_FILE_MODE;
136+ } else {
137+ ret = mt7915_eeprom_load(dev);
138+ }
139+
140 if (ret < 0) {
141 if (ret != -EINVAL)
142 return ret;
143
144 dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n");
145+ dev->bin_file_mode = false;
146+ dev->eeprom_mode = DEFAULT_BIN_MODE;
147+
148 ret = mt7915_eeprom_load_default(dev);
149 if (ret)
150 return ret;
151diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h
developer8e5fecd2023-05-30 11:58:00 +0800152index fdae347e..9056d786 100644
developer2aa1e642022-12-19 11:33:22 +0800153--- a/mt7915/eeprom.h
154+++ b/mt7915/eeprom.h
155@@ -108,6 +108,13 @@ enum mt7915_sku_rate_group {
156 MAX_SKU_RATE_GROUP_NUM,
157 };
158
159+enum mt7915_eeprom_mode {
160+ DEFAULT_BIN_MODE,
161+ EFUSE_MODE,
162+ FLASH_MODE,
163+ BIN_FILE_MODE,
164+};
165+
166 static inline int
167 mt7915_get_channel_group_5g(int channel, bool is_7976)
168 {
169diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h
developer8e5fecd2023-05-30 11:58:00 +0800170index b22990a5..f2ee80e9 100644
developer2aa1e642022-12-19 11:33:22 +0800171--- a/mt7915/mt7915.h
172+++ b/mt7915/mt7915.h
developerad9333b2023-05-22 15:16:16 +0800173@@ -400,6 +400,8 @@ struct mt7915_dev {
developer2aa1e642022-12-19 11:33:22 +0800174
175 bool dbdc_support;
176 bool flash_mode;
177+ bool bin_file_mode;
178+ u8 eeprom_mode;
179 bool muru_debug;
180 bool ibf;
181
developerad9333b2023-05-22 15:16:16 +0800182@@ -775,6 +777,7 @@ void mt7915_dump_tmac_info(u8 *tmac_info);
developer2aa1e642022-12-19 11:33:22 +0800183 int mt7915_mcu_set_txpower_level(struct mt7915_phy *phy, u8 drop_level);
184 void mt7915_packet_log_to_host(struct mt7915_dev *dev, const void *data, int len, int type, int des_len);
185 int mt7915_mcu_set_amsdu_algo(struct mt7915_dev *dev, u16 wcid, u8 enable);
186+const char *mt7915_eeprom_name(struct mt7915_dev *dev);
187
188 #define PKT_BIN_DEBUG_MAGIC 0xc8763123
189 enum {
190diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c
developer8e5fecd2023-05-30 11:58:00 +0800191index be279f7b..809dff3f 100644
developer2aa1e642022-12-19 11:33:22 +0800192--- a/mt7915/mtk_debugfs.c
193+++ b/mt7915/mtk_debugfs.c
194@@ -3,6 +3,7 @@
195 #include "mt7915_debug.h"
196 #include "mac.h"
197 #include "mcu.h"
198+#include "eeprom.h"
199
200 #ifdef MTK_DEBUG
201 #define LWTBL_IDX2BASE_ID GENMASK(14, 8)
developer3a388772023-04-19 10:12:02 +0800202@@ -3602,6 +3603,47 @@ static int mt7915_fw_wm_info_read(struct seq_file *s, void *data)
developera43cc482023-04-17 15:57:28 +0800203 return 0;
204 }
developer2aa1e642022-12-19 11:33:22 +0800205
206+static int mt7915_show_eeprom_mode(struct seq_file *s, void *data)
207+{
208+ struct mt7915_dev *dev = dev_get_drvdata(s->private);
209+ struct mt76_dev *mdev = &dev->mt76;
developer3a388772023-04-19 10:12:02 +0800210+ u8 free_block_num = 0;
developer2aa1e642022-12-19 11:33:22 +0800211+#ifdef CONFIG_NL80211_TESTMODE
212+ const char *mtd_name = mdev->test_mtd.name;
213+ u32 mtd_offset = mdev->test_mtd.offset;
214+#else
215+ const char *mtd_name = NULL;
216+ u32 mtd_offset;
217+#endif
218+
219+ seq_printf(s, "Current eeprom mode:\n");
220+
221+ switch (dev->eeprom_mode) {
222+ case DEFAULT_BIN_MODE:
223+ seq_printf(s, " default bin mode\n filename = %s\n", mt7915_eeprom_name(dev));
224+ break;
225+ case EFUSE_MODE:
226+ seq_printf(s, " efuse mode\n");
developer3a388772023-04-19 10:12:02 +0800227+ mt7915_mcu_get_eeprom_free_block(dev, &free_block_num);
228+ seq_printf(s, " free block number = %d\n", free_block_num);
developer2aa1e642022-12-19 11:33:22 +0800229+ break;
230+ case FLASH_MODE:
231+ if (mtd_name)
232+ seq_printf(s, " flash mode\n mtd name = %s\n flash offset = 0x%x\n",
233+ mtd_name, mtd_offset);
234+ else
235+ seq_printf(s, " flash mode\n");
236+ break;
237+ case BIN_FILE_MODE:
238+ seq_printf(s, " bin file mode\n filename = %s\n", mt7915_eeprom_name(dev));
239+ break;
240+ default:
241+ break;
242+ }
243+
244+ return 0;
245+}
246+
247 int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir)
248 {
249 struct mt7915_dev *dev = phy->dev;
developer8e5fecd2023-05-30 11:58:00 +0800250@@ -3688,6 +3730,8 @@ int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir)
251
252 debugfs_create_u8("sku_disable", 0600, dir, &dev->dbg.sku_disable);
developer2aa1e642022-12-19 11:33:22 +0800253
254+ debugfs_create_devm_seqfile(dev->mt76.dev, "eeprom_mode", dir,
255+ mt7915_show_eeprom_mode);
256 return 0;
257 }
258 #endif
259--
developera43cc482023-04-17 15:57:28 +08002602.18.0
developer2aa1e642022-12-19 11:33:22 +0800261