developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 1 | From edd667417d5bf86af2b0c04679782614a6b8ef8f 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 | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 4 | Subject: [PATCH 020/223] 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 | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 14 | Change-Id: I06369a46f75c0707d9ababd8ade70d79a89b1a1c |
| 15 | Change-Id: I4c8fd2b0a9956d2ee961b70cd28973e2e9410aca |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 16 | Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 17 | --- |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 18 | eeprom.c | 25 +++++++++++++++ |
| 19 | mt76.h | 3 ++ |
| 20 | mt7996/eeprom.c | 76 ++++++++++++++++++++++++++++++++++++++------ |
| 21 | mt7996/eeprom.h | 7 ++++ |
| 22 | mt7996/mt7996.h | 3 ++ |
| 23 | mt7996/mtk_debugfs.c | 41 ++++++++++++++++++++++++ |
| 24 | testmode.h | 2 +- |
| 25 | 7 files changed, 147 insertions(+), 10 deletions(-) |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 26 | |
| 27 | diff --git a/eeprom.c b/eeprom.c |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 28 | index 85935dea..4eb27782 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 29 | --- a/eeprom.c |
| 30 | +++ b/eeprom.c |
| 31 | @@ -161,6 +161,31 @@ static int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int len) |
| 32 | return mt76_get_of_data_from_nvmem(dev, eep, "eeprom", len); |
| 33 | } |
| 34 | |
| 35 | +bool mt76_check_bin_file_mode(struct mt76_dev *dev) |
| 36 | +{ |
| 37 | + struct device_node *np = dev->dev->of_node; |
| 38 | + const char *bin_file_name = NULL; |
| 39 | + |
| 40 | + if (!np) |
| 41 | + return false; |
| 42 | + |
| 43 | + of_property_read_string(np, "bin_file_name", &bin_file_name); |
| 44 | + |
| 45 | + dev->bin_file_name = bin_file_name; |
| 46 | + if (dev->bin_file_name) { |
| 47 | + dev_info(dev->dev, "Using bin file %s\n", dev->bin_file_name); |
| 48 | +#ifdef CONFIG_NL80211_TESTMODE |
| 49 | + dev->test_mtd.name = devm_kstrdup(dev->dev, bin_file_name, GFP_KERNEL); |
| 50 | + dev->test_mtd.offset = -1; |
| 51 | +#endif |
| 52 | + } |
| 53 | + |
| 54 | + of_node_put(np); |
| 55 | + |
| 56 | + return dev->bin_file_name ? true : false; |
| 57 | +} |
| 58 | +EXPORT_SYMBOL_GPL(mt76_check_bin_file_mode); |
| 59 | + |
| 60 | void |
| 61 | mt76_eeprom_override(struct mt76_phy *phy) |
| 62 | { |
| 63 | diff --git a/mt76.h b/mt76.h |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 64 | index ac2de858..924f273b 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 65 | --- a/mt76.h |
| 66 | +++ b/mt76.h |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 67 | @@ -973,6 +973,8 @@ struct mt76_dev { |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 68 | struct mt76_usb usb; |
| 69 | struct mt76_sdio sdio; |
| 70 | }; |
| 71 | + |
| 72 | + const char *bin_file_name; |
| 73 | }; |
| 74 | |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 75 | #define MT76_MAX_AMSDU_NUM 8 |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 76 | @@ -1246,6 +1248,7 @@ void mt76_eeprom_override(struct mt76_phy *phy); |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 77 | int mt76_get_of_data_from_mtd(struct mt76_dev *dev, void *eep, int offset, int len); |
| 78 | int mt76_get_of_data_from_nvmem(struct mt76_dev *dev, void *eep, |
| 79 | const char *cell_name, int len); |
| 80 | +bool mt76_check_bin_file_mode(struct mt76_dev *dev); |
| 81 | |
| 82 | struct mt76_queue * |
| 83 | mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc, |
| 84 | diff --git a/mt7996/eeprom.c b/mt7996/eeprom.c |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 85 | index b091e30c..111fe401 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 86 | --- a/mt7996/eeprom.c |
| 87 | +++ b/mt7996/eeprom.c |
| 88 | @@ -82,10 +82,17 @@ static int mt7996_check_eeprom(struct mt7996_dev *dev) |
| 89 | } |
| 90 | } |
| 91 | |
| 92 | -static char *mt7996_eeprom_name(struct mt7996_dev *dev) |
| 93 | +const char *mt7996_eeprom_name(struct mt7996_dev *dev) |
| 94 | { |
| 95 | - if (dev->testmode_enable) |
| 96 | - return MT7996_EEPROM_DEFAULT_TM; |
| 97 | + if (dev->bin_file_mode) |
| 98 | + return dev->mt76.bin_file_name; |
| 99 | + |
| 100 | + if (dev->testmode_enable) { |
| 101 | + if (is_mt7992(&dev->mt76)) |
| 102 | + return MT7992_EEPROM_DEFAULT_TM; |
| 103 | + else |
| 104 | + return MT7996_EEPROM_DEFAULT_TM; |
| 105 | + } |
| 106 | |
| 107 | switch (mt76_chip(&dev->mt76)) { |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 108 | case 0x7992: |
| 109 | @@ -234,7 +241,10 @@ mt7996_eeprom_check_or_use_default(struct mt7996_dev *dev, bool use_default) |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 110 | return ret; |
| 111 | |
| 112 | if (!fw || !fw->data) { |
| 113 | - dev_err(dev->mt76.dev, "Invalid default bin\n"); |
| 114 | + if (dev->bin_file_mode) |
| 115 | + dev_err(dev->mt76.dev, "Invalid bin (bin file mode)\n"); |
| 116 | + else |
| 117 | + dev_err(dev->mt76.dev, "Invalid default bin\n"); |
| 118 | ret = -EINVAL; |
| 119 | goto out; |
| 120 | } |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 121 | @@ -369,6 +379,7 @@ static int mt7996_eeprom_load(struct mt7996_dev *dev) |
| 122 | goto out; |
| 123 | } |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 124 | } |
| 125 | + dev->eeprom_mode = EFUSE_MODE; |
| 126 | } |
| 127 | |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 128 | out: |
| 129 | @@ -477,22 +488,69 @@ int mt7996_eeprom_parse_hw_cap(struct mt7996_dev *dev, struct mt7996_phy *phy) |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 130 | return mt7996_eeprom_parse_band_config(phy); |
| 131 | } |
| 132 | |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 133 | -int mt7996_eeprom_init(struct mt7996_dev *dev) |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 134 | +static int |
| 135 | +mt7996_eeprom_load_precal_binfile(struct mt7996_dev *dev, u32 offs, u32 size) |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 136 | { |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 137 | + const struct firmware *fw = NULL; |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 138 | int ret; |
| 139 | |
| 140 | - ret = mt7996_get_chip_sku(dev); |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 141 | + ret = request_firmware(&fw, dev->mt76.bin_file_name, dev->mt76.dev); |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 142 | if (ret) |
| 143 | return ret; |
| 144 | |
| 145 | - ret = mt7996_eeprom_load(dev); |
| 146 | - if (ret < 0) |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 147 | + if (!fw || !fw->data) { |
| 148 | + dev_err(dev->mt76.dev, "Invalid bin (bin file mode), load precal fail\n"); |
| 149 | + ret = -EINVAL; |
| 150 | + goto out; |
| 151 | + } |
| 152 | + |
| 153 | + memcpy(dev->cal, fw->data + offs, size); |
| 154 | + |
| 155 | +out: |
| 156 | + release_firmware(fw); |
| 157 | + |
| 158 | + return ret; |
| 159 | +} |
| 160 | + |
| 161 | +static int mt7996_eeprom_load_precal(struct mt7996_dev *dev) |
| 162 | +{ |
| 163 | + struct mt76_dev *mdev = &dev->mt76; |
| 164 | + u8 *eeprom = mdev->eeprom.data; |
| 165 | + u32 offs = MT_EE_DO_PRE_CAL; |
| 166 | + u32 size, val = eeprom[offs]; |
| 167 | + int ret; |
| 168 | + |
| 169 | + mt7996_eeprom_init_precal(dev); |
| 170 | + |
| 171 | + if (!dev->flash_mode || !val) |
| 172 | + return 0; |
| 173 | + |
| 174 | + size = MT_EE_CAL_GROUP_SIZE + MT_EE_CAL_DPD_SIZE; |
| 175 | + |
| 176 | + dev->cal = devm_kzalloc(mdev->dev, size, GFP_KERNEL); |
| 177 | + if (!dev->cal) |
| 178 | + return -ENOMEM; |
| 179 | + |
| 180 | + if (dev->bin_file_mode) |
| 181 | + return mt7996_eeprom_load_precal_binfile(dev, MT_EE_PRECAL, size); |
| 182 | + |
| 183 | + ret = mt76_get_of_data_from_mtd(mdev, dev->cal, offs, size); |
| 184 | + if (!ret) |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 185 | return ret; |
| 186 | |
| 187 | - ret = mt7996_eeprom_load_precal(dev); |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 188 | + return mt76_get_of_data_from_nvmem(mdev, dev->cal, "precal", size); |
| 189 | +} |
| 190 | + |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 191 | +int mt7996_eeprom_init(struct mt7996_dev *dev) |
| 192 | +{ |
| 193 | + int ret; |
| 194 | + |
| 195 | + ret = mt7996_eeprom_load(dev); |
| 196 | if (ret) |
| 197 | return ret; |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 198 | |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 199 | + mt7996_eeprom_load_precal(dev); |
| 200 | + |
| 201 | ret = mt7996_eeprom_parse_hw_cap(dev, &dev->phy); |
| 202 | if (ret < 0) |
| 203 | return ret; |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 204 | diff --git a/mt7996/eeprom.h b/mt7996/eeprom.h |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 205 | index f3a9618b..e90180a0 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 206 | --- a/mt7996/eeprom.h |
| 207 | +++ b/mt7996/eeprom.h |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 208 | @@ -104,6 +104,13 @@ enum mt7996_eeprom_band { |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 209 | MT_EE_BAND_SEL_6GHZ, |
| 210 | }; |
| 211 | |
| 212 | +enum mt7915_eeprom_mode { |
| 213 | + DEFAULT_BIN_MODE, |
| 214 | + EFUSE_MODE, |
| 215 | + FLASH_MODE, |
| 216 | + BIN_FILE_MODE, |
| 217 | +}; |
| 218 | + |
| 219 | static inline int |
| 220 | mt7996_get_channel_group_5g(int channel) |
| 221 | { |
| 222 | diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 223 | index a1a30b33..efb4e74c 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 224 | --- a/mt7996/mt7996.h |
| 225 | +++ b/mt7996/mt7996.h |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 226 | @@ -404,6 +404,8 @@ struct mt7996_dev { |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 227 | } wed_rro; |
| 228 | |
| 229 | bool testmode_enable; |
| 230 | + bool bin_file_mode; |
| 231 | + u8 eeprom_mode; |
| 232 | |
| 233 | bool ibf; |
| 234 | u8 fw_debug_wm; |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 235 | @@ -554,6 +556,7 @@ irqreturn_t mt7996_irq_handler(int irq, void *dev_instance); |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 236 | u64 __mt7996_get_tsf(struct ieee80211_hw *hw, struct mt7996_vif *mvif); |
| 237 | int mt7996_register_device(struct mt7996_dev *dev); |
| 238 | void mt7996_unregister_device(struct mt7996_dev *dev); |
| 239 | +const char *mt7996_eeprom_name(struct mt7996_dev *dev); |
| 240 | int mt7996_eeprom_init(struct mt7996_dev *dev); |
| 241 | int mt7996_eeprom_check_fw_mode(struct mt7996_dev *dev); |
| 242 | int mt7996_eeprom_parse_hw_cap(struct mt7996_dev *dev, struct mt7996_phy *phy); |
| 243 | diff --git a/mt7996/mtk_debugfs.c b/mt7996/mtk_debugfs.c |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 244 | index ad89eccd..078ff279 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 245 | --- a/mt7996/mtk_debugfs.c |
| 246 | +++ b/mt7996/mtk_debugfs.c |
developer | 05f3b2b | 2024-08-19 19:17:34 +0800 | [diff] [blame] | 247 | @@ -2797,6 +2797,44 @@ static const struct file_operations mt7996_txpower_path_fops = { |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 248 | .llseek = default_llseek, |
| 249 | }; |
| 250 | |
| 251 | +static int mt7996_show_eeprom_mode(struct seq_file *s, void *data) |
| 252 | +{ |
| 253 | + struct mt7996_dev *dev = dev_get_drvdata(s->private); |
| 254 | + struct mt76_dev *mdev = &dev->mt76; |
| 255 | +#ifdef CONFIG_NL80211_TESTMODE |
| 256 | + const char *mtd_name = mdev->test_mtd.name; |
| 257 | + u32 mtd_offset = mdev->test_mtd.offset; |
| 258 | +#else |
| 259 | + const char *mtd_name = NULL; |
| 260 | + u32 mtd_offset; |
| 261 | +#endif |
| 262 | + |
| 263 | + seq_printf(s, "Current eeprom mode:\n"); |
| 264 | + |
| 265 | + switch (dev->eeprom_mode) { |
| 266 | + case DEFAULT_BIN_MODE: |
| 267 | + seq_printf(s, " default bin mode\n filename = %s\n", mt7996_eeprom_name(dev)); |
| 268 | + break; |
| 269 | + case EFUSE_MODE: |
| 270 | + seq_printf(s, " efuse mode\n"); |
| 271 | + break; |
| 272 | + case FLASH_MODE: |
| 273 | + if (mtd_name) |
| 274 | + seq_printf(s, " flash mode\n mtd name = %s\n flash offset = 0x%x\n", |
| 275 | + mtd_name, mtd_offset); |
| 276 | + else |
| 277 | + seq_printf(s, " flash mode\n"); |
| 278 | + break; |
| 279 | + case BIN_FILE_MODE: |
| 280 | + seq_printf(s, " bin file mode\n filename = %s\n", mt7996_eeprom_name(dev)); |
| 281 | + break; |
| 282 | + default: |
| 283 | + break; |
| 284 | + } |
| 285 | + |
| 286 | + return 0; |
| 287 | +} |
| 288 | + |
| 289 | int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir) |
| 290 | { |
| 291 | struct mt7996_dev *dev = phy->dev; |
| 292 | @@ -2866,6 +2904,9 @@ int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir) |
| 293 | debugfs_create_file("txpower_sku", 0600, dir, phy, &mt7996_txpower_sku_fops); |
| 294 | debugfs_create_file("txpower_path", 0600, dir, phy, &mt7996_txpower_path_fops); |
| 295 | |
| 296 | + debugfs_create_devm_seqfile(dev->mt76.dev, "eeprom_mode", dir, |
| 297 | + mt7996_show_eeprom_mode); |
| 298 | + |
| 299 | debugfs_create_devm_seqfile(dev->mt76.dev, "wtbl_info", dir, |
| 300 | mt7996_wtbl_read); |
| 301 | |
| 302 | diff --git a/testmode.h b/testmode.h |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 303 | index 3348d0d5..6d79832a 100644 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 304 | --- a/testmode.h |
| 305 | +++ b/testmode.h |
| 306 | @@ -16,7 +16,7 @@ |
| 307 | * @MT76_TM_ATTR_RESET: reset parameters to default (flag) |
| 308 | * @MT76_TM_ATTR_STATE: test state (u32), see &enum mt76_testmode_state |
| 309 | * |
| 310 | - * @MT76_TM_ATTR_MTD_PART: mtd partition used for eeprom data (string) |
| 311 | + * @MT76_TM_ATTR_MTD_PART: mtd partition or binfile used for eeprom data (string) |
| 312 | * @MT76_TM_ATTR_MTD_OFFSET: offset of eeprom data within the partition (u32) |
| 313 | * @MT76_TM_ATTR_BAND_IDX: band idx of the chip (u8) |
| 314 | * |
| 315 | -- |
developer | d0c8945 | 2024-10-11 16:53:27 +0800 | [diff] [blame^] | 316 | 2.45.2 |
developer | 66e89bc | 2024-04-23 14:50:01 +0800 | [diff] [blame] | 317 | |