developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 1 | From e6e4969b4c1ae6f9a1fc9ac9744ca6eb76400a51 Mon Sep 17 00:00:00 2001 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 2 | From: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 3 | Date: Fri, 31 Mar 2023 11:36:34 +0800 |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 4 | Subject: [PATCH 032/199] mtk: mt76: mt7996: add binfile mode support |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 5 | |
| 6 | Fix binfile cannot sync precal data to atenl |
| 7 | Binfile is viewed as efuse mode in atenl, so atenl does not allocate |
| 8 | precal memory for its eeprom file |
| 9 | Use mtd offset == 0xFFFFFFFF to determine whether it is binfile or flash mode |
| 10 | Add support for loading precal in binfile mode |
| 11 | |
| 12 | Align upstream |
| 13 | |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 14 | Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 15 | --- |
| 16 | eeprom.c | 25 +++++++++++ |
| 17 | mt76.h | 3 ++ |
| 18 | mt7996/eeprom.c | 103 ++++++++++++++++++++++++++++++++++++++++--- |
| 19 | mt7996/eeprom.h | 7 +++ |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 20 | mt7996/mt7996.h | 3 ++ |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 21 | mt7996/mtk_debugfs.c | 41 +++++++++++++++++ |
| 22 | testmode.h | 2 +- |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 23 | 7 files changed, 178 insertions(+), 6 deletions(-) |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 24 | |
| 25 | diff --git a/eeprom.c b/eeprom.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 26 | index 11efe293..3da94926 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 27 | --- a/eeprom.c |
| 28 | +++ b/eeprom.c |
| 29 | @@ -161,6 +161,31 @@ static int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int len) |
| 30 | return mt76_get_of_data_from_nvmem(dev, eep, "eeprom", len); |
| 31 | } |
| 32 | |
| 33 | +bool mt76_check_bin_file_mode(struct mt76_dev *dev) |
| 34 | +{ |
| 35 | + struct device_node *np = dev->dev->of_node; |
| 36 | + const char *bin_file_name = NULL; |
| 37 | + |
| 38 | + if (!np) |
| 39 | + return false; |
| 40 | + |
| 41 | + of_property_read_string(np, "bin_file_name", &bin_file_name); |
| 42 | + |
| 43 | + dev->bin_file_name = bin_file_name; |
| 44 | + if (dev->bin_file_name) { |
| 45 | + dev_info(dev->dev, "Using bin file %s\n", dev->bin_file_name); |
| 46 | +#ifdef CONFIG_NL80211_TESTMODE |
| 47 | + dev->test_mtd.name = devm_kstrdup(dev->dev, bin_file_name, GFP_KERNEL); |
| 48 | + dev->test_mtd.offset = -1; |
| 49 | +#endif |
| 50 | + } |
| 51 | + |
| 52 | + of_node_put(np); |
| 53 | + |
| 54 | + return dev->bin_file_name ? true : false; |
| 55 | +} |
| 56 | +EXPORT_SYMBOL_GPL(mt76_check_bin_file_mode); |
| 57 | + |
| 58 | void |
| 59 | mt76_eeprom_override(struct mt76_phy *phy) |
| 60 | { |
| 61 | diff --git a/mt76.h b/mt76.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 62 | index 2236bc6b..d4a0f006 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 63 | --- a/mt76.h |
| 64 | +++ b/mt76.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 65 | @@ -958,6 +958,8 @@ struct mt76_dev { |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 66 | struct mt76_usb usb; |
| 67 | struct mt76_sdio sdio; |
| 68 | }; |
| 69 | + |
| 70 | + const char *bin_file_name; |
| 71 | }; |
| 72 | |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 73 | #define MT76_MAX_AMSDU_NUM 8 |
| 74 | @@ -1231,6 +1233,7 @@ void mt76_eeprom_override(struct mt76_phy *phy); |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 75 | int mt76_get_of_data_from_mtd(struct mt76_dev *dev, void *eep, int offset, int len); |
| 76 | int mt76_get_of_data_from_nvmem(struct mt76_dev *dev, void *eep, |
| 77 | const char *cell_name, int len); |
| 78 | +bool mt76_check_bin_file_mode(struct mt76_dev *dev); |
| 79 | |
| 80 | struct mt76_queue * |
| 81 | mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc, |
| 82 | diff --git a/mt7996/eeprom.c b/mt7996/eeprom.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 83 | index 17485bfc..5dc55646 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 84 | --- a/mt7996/eeprom.c |
| 85 | +++ b/mt7996/eeprom.c |
| 86 | @@ -82,10 +82,17 @@ static int mt7996_check_eeprom(struct mt7996_dev *dev) |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | -static char *mt7996_eeprom_name(struct mt7996_dev *dev) |
| 91 | +const char *mt7996_eeprom_name(struct mt7996_dev *dev) |
| 92 | { |
| 93 | - if (dev->testmode_enable) |
| 94 | - return MT7996_EEPROM_DEFAULT_TM; |
| 95 | + if (dev->bin_file_mode) |
| 96 | + return dev->mt76.bin_file_name; |
| 97 | + |
| 98 | + if (dev->testmode_enable) { |
| 99 | + if (is_mt7992(&dev->mt76)) |
| 100 | + return MT7992_EEPROM_DEFAULT_TM; |
| 101 | + else |
| 102 | + return MT7996_EEPROM_DEFAULT_TM; |
| 103 | + } |
| 104 | |
| 105 | switch (mt76_chip(&dev->mt76)) { |
| 106 | case 0x7990: |
| 107 | @@ -152,7 +159,10 @@ mt7996_eeprom_load_default(struct mt7996_dev *dev) |
| 108 | return ret; |
| 109 | |
| 110 | if (!fw || !fw->data) { |
| 111 | - dev_err(dev->mt76.dev, "Invalid default bin\n"); |
| 112 | + if (dev->bin_file_mode) |
| 113 | + dev_err(dev->mt76.dev, "Invalid bin (bin file mode)\n"); |
| 114 | + else |
| 115 | + dev_err(dev->mt76.dev, "Invalid default bin\n"); |
| 116 | ret = -EINVAL; |
| 117 | goto out; |
| 118 | } |
| 119 | @@ -166,18 +176,45 @@ out: |
| 120 | return ret; |
| 121 | } |
| 122 | |
| 123 | +static int mt7996_eeprom_load_flash(struct mt7996_dev *dev) |
| 124 | +{ |
| 125 | + int ret = 1; |
| 126 | + |
| 127 | + /* return > 0 for load success, return 0 for load failed, return < 0 for non memory */ |
| 128 | + dev->bin_file_mode = mt76_check_bin_file_mode(&dev->mt76); |
| 129 | + if (dev->bin_file_mode) { |
| 130 | + dev->mt76.eeprom.size = MT7996_EEPROM_SIZE; |
| 131 | + dev->mt76.eeprom.data = devm_kzalloc(dev->mt76.dev, dev->mt76.eeprom.size, |
| 132 | + GFP_KERNEL); |
| 133 | + if (!dev->mt76.eeprom.data) |
| 134 | + return -ENOMEM; |
| 135 | + |
| 136 | + if (mt7996_eeprom_load_default(dev)) |
| 137 | + return 0; |
| 138 | + |
| 139 | + if (mt7996_check_eeprom(dev)) |
| 140 | + return 0; |
| 141 | + } else { |
| 142 | + ret = mt76_eeprom_init(&dev->mt76, MT7996_EEPROM_SIZE); |
| 143 | + } |
| 144 | + |
| 145 | + return ret; |
| 146 | +} |
| 147 | + |
| 148 | int mt7996_eeprom_check_fw_mode(struct mt7996_dev *dev) |
| 149 | { |
| 150 | u8 *eeprom; |
| 151 | int ret; |
| 152 | |
| 153 | /* load eeprom in flash or bin file mode to determine fw mode */ |
| 154 | - ret = mt76_eeprom_init(&dev->mt76, MT7996_EEPROM_SIZE); |
| 155 | + ret = mt7996_eeprom_load_flash(dev); |
| 156 | + |
| 157 | if (ret < 0) |
| 158 | return ret; |
| 159 | |
| 160 | if (ret) { |
| 161 | dev->flash_mode = true; |
| 162 | + dev->eeprom_mode = dev->bin_file_mode ? BIN_FILE_MODE : FLASH_MODE; |
| 163 | eeprom = dev->mt76.eeprom.data; |
| 164 | /* testmode enable priority: eeprom field > module parameter */ |
| 165 | dev->testmode_enable = !mt7996_check_eeprom(dev) ? eeprom[MT_EE_TESTMODE_EN] : |
| 166 | @@ -211,6 +248,7 @@ static int mt7996_eeprom_load(struct mt7996_dev *dev) |
| 167 | if (ret && ret != -EINVAL) |
| 168 | return ret; |
| 169 | } |
| 170 | + dev->eeprom_mode = EFUSE_MODE; |
| 171 | } |
| 172 | |
| 173 | return mt7996_check_eeprom(dev); |
| 174 | @@ -337,6 +375,59 @@ int mt7996_eeprom_parse_hw_cap(struct mt7996_dev *dev, struct mt7996_phy *phy) |
| 175 | return mt7996_eeprom_parse_band_config(phy); |
| 176 | } |
| 177 | |
| 178 | +static int |
| 179 | +mt7996_eeprom_load_precal_binfile(struct mt7996_dev *dev, u32 offs, u32 size) |
| 180 | +{ |
| 181 | + const struct firmware *fw = NULL; |
| 182 | + int ret; |
| 183 | + |
| 184 | + ret = request_firmware(&fw, dev->mt76.bin_file_name, dev->mt76.dev); |
| 185 | + if (ret) |
| 186 | + return ret; |
| 187 | + |
| 188 | + if (!fw || !fw->data) { |
| 189 | + dev_err(dev->mt76.dev, "Invalid bin (bin file mode), load precal fail\n"); |
| 190 | + ret = -EINVAL; |
| 191 | + goto out; |
| 192 | + } |
| 193 | + |
| 194 | + memcpy(dev->cal, fw->data + offs, size); |
| 195 | + |
| 196 | +out: |
| 197 | + release_firmware(fw); |
| 198 | + |
| 199 | + return ret; |
| 200 | +} |
| 201 | + |
| 202 | +static int mt7996_eeprom_load_precal(struct mt7996_dev *dev) |
| 203 | +{ |
| 204 | + struct mt76_dev *mdev = &dev->mt76; |
| 205 | + u8 *eeprom = mdev->eeprom.data; |
| 206 | + u32 offs = MT_EE_DO_PRE_CAL; |
| 207 | + u32 size, val = eeprom[offs]; |
| 208 | + int ret; |
| 209 | + |
| 210 | + mt7996_eeprom_init_precal(dev); |
| 211 | + |
| 212 | + if (!dev->flash_mode || !val) |
| 213 | + return 0; |
| 214 | + |
| 215 | + size = MT_EE_CAL_GROUP_SIZE + MT_EE_CAL_DPD_SIZE; |
| 216 | + |
| 217 | + dev->cal = devm_kzalloc(mdev->dev, size, GFP_KERNEL); |
| 218 | + if (!dev->cal) |
| 219 | + return -ENOMEM; |
| 220 | + |
| 221 | + if (dev->bin_file_mode) |
| 222 | + return mt7996_eeprom_load_precal_binfile(dev, MT_EE_PRECAL, size); |
| 223 | + |
| 224 | + ret = mt76_get_of_data_from_mtd(mdev, dev->cal, offs, size); |
| 225 | + if (!ret) |
| 226 | + return ret; |
| 227 | + |
| 228 | + return mt76_get_of_data_from_nvmem(mdev, dev->cal, "precal", size); |
| 229 | +} |
| 230 | + |
| 231 | int mt7996_eeprom_init(struct mt7996_dev *dev) |
| 232 | { |
| 233 | int ret; |
| 234 | @@ -351,6 +442,8 @@ int mt7996_eeprom_init(struct mt7996_dev *dev) |
| 235 | return ret; |
| 236 | |
| 237 | dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n"); |
| 238 | + dev->bin_file_mode = false; |
| 239 | + dev->eeprom_mode = DEFAULT_BIN_MODE; |
| 240 | ret = mt7996_eeprom_load_default(dev); |
| 241 | if (ret) |
| 242 | return ret; |
| 243 | diff --git a/mt7996/eeprom.h b/mt7996/eeprom.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 244 | index b19ff068..8f0f87b6 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 245 | --- a/mt7996/eeprom.h |
| 246 | +++ b/mt7996/eeprom.h |
| 247 | @@ -102,6 +102,13 @@ enum mt7996_eeprom_band { |
| 248 | MT_EE_BAND_SEL_6GHZ, |
| 249 | }; |
| 250 | |
| 251 | +enum mt7915_eeprom_mode { |
| 252 | + DEFAULT_BIN_MODE, |
| 253 | + EFUSE_MODE, |
| 254 | + FLASH_MODE, |
| 255 | + BIN_FILE_MODE, |
| 256 | +}; |
| 257 | + |
| 258 | static inline int |
| 259 | mt7996_get_channel_group_5g(int channel) |
| 260 | { |
| 261 | diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 262 | index ff7edcd8..3abb932d 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 263 | --- a/mt7996/mt7996.h |
| 264 | +++ b/mt7996/mt7996.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 265 | @@ -394,6 +394,8 @@ struct mt7996_dev { |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 266 | } wed_rro; |
| 267 | |
| 268 | bool testmode_enable; |
| 269 | + bool bin_file_mode; |
| 270 | + u8 eeprom_mode; |
| 271 | |
| 272 | bool ibf; |
| 273 | u8 fw_debug_wm; |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 274 | @@ -522,6 +524,7 @@ irqreturn_t mt7996_irq_handler(int irq, void *dev_instance); |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 275 | u64 __mt7996_get_tsf(struct ieee80211_hw *hw, struct mt7996_vif *mvif); |
| 276 | int mt7996_register_device(struct mt7996_dev *dev); |
| 277 | void mt7996_unregister_device(struct mt7996_dev *dev); |
| 278 | +const char *mt7996_eeprom_name(struct mt7996_dev *dev); |
| 279 | int mt7996_eeprom_init(struct mt7996_dev *dev); |
| 280 | int mt7996_eeprom_check_fw_mode(struct mt7996_dev *dev); |
| 281 | int mt7996_eeprom_parse_hw_cap(struct mt7996_dev *dev, struct mt7996_phy *phy); |
| 282 | diff --git a/mt7996/mtk_debugfs.c b/mt7996/mtk_debugfs.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 283 | index 3558641c..c096fb6c 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 284 | --- a/mt7996/mtk_debugfs.c |
| 285 | +++ b/mt7996/mtk_debugfs.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 286 | @@ -2797,6 +2797,44 @@ static const struct file_operations mt7996_txpower_path_fops = { |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 287 | .llseek = default_llseek, |
| 288 | }; |
| 289 | |
| 290 | +static int mt7996_show_eeprom_mode(struct seq_file *s, void *data) |
| 291 | +{ |
| 292 | + struct mt7996_dev *dev = dev_get_drvdata(s->private); |
| 293 | + struct mt76_dev *mdev = &dev->mt76; |
| 294 | +#ifdef CONFIG_NL80211_TESTMODE |
| 295 | + const char *mtd_name = mdev->test_mtd.name; |
| 296 | + u32 mtd_offset = mdev->test_mtd.offset; |
| 297 | +#else |
| 298 | + const char *mtd_name = NULL; |
| 299 | + u32 mtd_offset; |
| 300 | +#endif |
| 301 | + |
| 302 | + seq_printf(s, "Current eeprom mode:\n"); |
| 303 | + |
| 304 | + switch (dev->eeprom_mode) { |
| 305 | + case DEFAULT_BIN_MODE: |
| 306 | + seq_printf(s, " default bin mode\n filename = %s\n", mt7996_eeprom_name(dev)); |
| 307 | + break; |
| 308 | + case EFUSE_MODE: |
| 309 | + seq_printf(s, " efuse mode\n"); |
| 310 | + break; |
| 311 | + case FLASH_MODE: |
| 312 | + if (mtd_name) |
| 313 | + seq_printf(s, " flash mode\n mtd name = %s\n flash offset = 0x%x\n", |
| 314 | + mtd_name, mtd_offset); |
| 315 | + else |
| 316 | + seq_printf(s, " flash mode\n"); |
| 317 | + break; |
| 318 | + case BIN_FILE_MODE: |
| 319 | + seq_printf(s, " bin file mode\n filename = %s\n", mt7996_eeprom_name(dev)); |
| 320 | + break; |
| 321 | + default: |
| 322 | + break; |
| 323 | + } |
| 324 | + |
| 325 | + return 0; |
| 326 | +} |
| 327 | + |
| 328 | int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir) |
| 329 | { |
| 330 | struct mt7996_dev *dev = phy->dev; |
| 331 | @@ -2866,6 +2904,9 @@ int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir) |
| 332 | debugfs_create_file("txpower_sku", 0600, dir, phy, &mt7996_txpower_sku_fops); |
| 333 | debugfs_create_file("txpower_path", 0600, dir, phy, &mt7996_txpower_path_fops); |
| 334 | |
| 335 | + debugfs_create_devm_seqfile(dev->mt76.dev, "eeprom_mode", dir, |
| 336 | + mt7996_show_eeprom_mode); |
| 337 | + |
| 338 | debugfs_create_devm_seqfile(dev->mt76.dev, "wtbl_info", dir, |
| 339 | mt7996_wtbl_read); |
| 340 | |
| 341 | diff --git a/testmode.h b/testmode.h |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 342 | index d6601cdc..5d677f8c 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 343 | --- a/testmode.h |
| 344 | +++ b/testmode.h |
| 345 | @@ -16,7 +16,7 @@ |
| 346 | * @MT76_TM_ATTR_RESET: reset parameters to default (flag) |
| 347 | * @MT76_TM_ATTR_STATE: test state (u32), see &enum mt76_testmode_state |
| 348 | * |
| 349 | - * @MT76_TM_ATTR_MTD_PART: mtd partition used for eeprom data (string) |
| 350 | + * @MT76_TM_ATTR_MTD_PART: mtd partition or binfile used for eeprom data (string) |
| 351 | * @MT76_TM_ATTR_MTD_OFFSET: offset of eeprom data within the partition (u32) |
| 352 | * @MT76_TM_ATTR_BAND_IDX: band idx of the chip (u8) |
| 353 | * |
| 354 | -- |
developer | 9237f44 | 2024-06-14 17:13:04 +0800 | [diff] [blame] | 355 | 2.18.0 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 356 | |