developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 1 | From 6aa933c1f0af48d3703f500dce4514b62d9d2121 Mon Sep 17 00:00:00 2001 |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 2 | From: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 3 | Date: Thu, 7 Jul 2022 11:09:59 +0800 |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 4 | Subject: [PATCH 1016/1052] wifi: mt76: mt7915: implement bin file mode |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 5 | |
| 6 | Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 7 | Signed-off-by: Shayne Chen <shayne.chen@mediatek.com> |
| 8 | --- |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 9 | eeprom.c | 25 ++++++++++++++++++ |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 10 | mt76.h | 4 +++ |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 11 | mt7915/eeprom.c | 63 +++++++++++++++++++++++++++++++++++++++++--- |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 12 | mt7915/eeprom.h | 7 +++++ |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 13 | mt7915/mt7915.h | 3 +++ |
| 14 | mt7915/mtk_debugfs.c | 44 +++++++++++++++++++++++++++++++ |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 15 | testmode.h | 2 +- |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 16 | 7 files changed, 144 insertions(+), 4 deletions(-) |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 17 | |
| 18 | diff --git a/eeprom.c b/eeprom.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 19 | index 3625b169..9d029c04 100644 |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 20 | --- a/eeprom.c |
| 21 | +++ b/eeprom.c |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 22 | @@ -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); |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 24 | } |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 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; |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 37 | + if (dev->bin_file_name) { |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 38 | + dev_info(dev->dev, "Using bin file %s\n", dev->bin_file_name); |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 39 | +#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 | + } |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 44 | + |
| 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 | { |
| 54 | diff --git a/mt76.h b/mt76.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 55 | index 9597f564..253a564f 100644 |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 56 | --- a/mt76.h |
| 57 | +++ b/mt76.h |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 58 | @@ -983,6 +983,9 @@ struct mt76_dev { |
developer | 6770571 | 2023-05-30 11:58:00 +0800 | [diff] [blame] | 59 | struct mt76_usb usb; |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 60 | struct mt76_sdio sdio; |
| 61 | }; |
developer | 6770571 | 2023-05-30 11:58:00 +0800 | [diff] [blame] | 62 | + |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 63 | + /* for mtk internal */ |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 64 | + const char *bin_file_name; |
| 65 | }; |
| 66 | |
developer | 47efbdb | 2023-06-29 20:33:22 +0800 | [diff] [blame] | 67 | /* per-phy stats. */ |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 68 | @@ -1246,6 +1249,7 @@ void mt76_eeprom_override(struct mt76_phy *phy); |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 69 | 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); |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 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, |
| 76 | diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 77 | index f4876fe9..c8b1c18e 100644 |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 78 | --- a/mt7915/eeprom.c |
| 79 | +++ b/mt7915/eeprom.c |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 80 | @@ -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; |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 111 | @@ -24,6 +48,9 @@ static int mt7915_eeprom_load_precal(struct mt7915_dev *dev) |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 112 | |
| 113 | offs = is_mt7915(&dev->mt76) ? MT_EE_PRECAL : MT_EE_PRECAL_V2; |
| 114 | |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 115 | + if (dev->bin_file_mode) |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 116 | + return mt7915_eeprom_load_precal_binfile(dev, offs, size); |
developer | 1a17367 | 2023-12-21 14:49:33 +0800 | [diff] [blame] | 117 | + |
| 118 | ret = mt76_get_of_data_from_mtd(mdev, dev->cal, offs, size); |
| 119 | if (!ret) |
| 120 | return ret; |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 121 | @@ -59,8 +86,11 @@ static int mt7915_check_eeprom(struct mt7915_dev *dev) |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 122 | } |
| 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 ? |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 134 | @@ -101,7 +131,10 @@ mt7915_eeprom_load_default(struct mt7915_dev *dev) |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 135 | 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 | } |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 146 | @@ -126,6 +159,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev) |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 147 | |
| 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; |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 154 | @@ -146,6 +180,8 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev) |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 155 | if (ret < 0) |
| 156 | return ret; |
| 157 | } |
| 158 | + |
| 159 | + dev->eeprom_mode = EFUSE_MODE; |
| 160 | } |
| 161 | |
| 162 | return mt7915_check_eeprom(dev); |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 163 | @@ -251,12 +287,33 @@ int mt7915_eeprom_init(struct mt7915_dev *dev) |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 164 | { |
| 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; |
| 198 | diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 199 | index 509fb43d..99101f91 100644 |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 200 | --- a/mt7915/eeprom.h |
| 201 | +++ b/mt7915/eeprom.h |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 202 | @@ -109,6 +109,13 @@ enum mt7915_sku_rate_group { |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 203 | 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 | { |
| 216 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 217 | index 141c151e..2fb8e2fb 100644 |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 218 | --- a/mt7915/mt7915.h |
| 219 | +++ b/mt7915/mt7915.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 220 | @@ -414,6 +414,8 @@ struct mt7915_dev { |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 221 | |
| 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 | |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 229 | @@ -802,6 +804,7 @@ void mt7915_dump_tmac_info(u8 *tmac_info); |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 230 | 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 { |
| 237 | diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 238 | index 02fe61a3..76f4849e 100644 |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 239 | --- 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) |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 249 | @@ -3728,6 +3729,47 @@ static int mt7915_fw_wm_info_read(struct seq_file *s, void *data) |
developer | 8effbd3 | 2023-04-17 15:57:28 +0800 | [diff] [blame] | 250 | return 0; |
| 251 | } |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 252 | |
| 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; |
developer | ac33246 | 2023-04-19 10:12:02 +0800 | [diff] [blame] | 257 | + u8 free_block_num = 0; |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 258 | +#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"); |
developer | ac33246 | 2023-04-19 10:12:02 +0800 | [diff] [blame] | 274 | + mt7915_mcu_get_eeprom_free_block(dev, &free_block_num); |
| 275 | + seq_printf(s, " free block number = %d\n", free_block_num); |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 276 | + 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; |
developer | a46f613 | 2024-03-26 14:09:54 +0800 | [diff] [blame] | 297 | @@ -3814,6 +3856,8 @@ int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir) |
developer | 6770571 | 2023-05-30 11:58:00 +0800 | [diff] [blame] | 298 | |
| 299 | debugfs_create_u8("sku_disable", 0600, dir, &dev->dbg.sku_disable); |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 300 | |
| 301 | + debugfs_create_devm_seqfile(dev->mt76.dev, "eeprom_mode", dir, |
| 302 | + mt7915_show_eeprom_mode); |
| 303 | return 0; |
| 304 | } |
| 305 | #endif |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 306 | diff --git a/testmode.h b/testmode.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 307 | index 20fab3ec..91d1e867 100644 |
developer | 70180b0 | 2023-11-14 17:01:47 +0800 | [diff] [blame] | 308 | --- 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 | * |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 319 | -- |
developer | bd9fa1e | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 320 | 2.18.0 |
developer | c5ce750 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 321 | |