developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 1 | From b33cf2d53b4719f00d96ba1b5280b7df593870cf Mon Sep 17 00:00:00 2001 |
developer | 2aa1e64 | 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 | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 4 | Subject: [PATCH] wifi: mt76: mt7915: implement bin file mode |
developer | 2aa1e64 | 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 | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 9 | eeprom.c | 25 +++++++++++++++++ |
| 10 | mt76.h | 4 +++ |
| 11 | mt7915/eeprom.c | 65 +++++++++++++++++++++++++++++++++++++++++--- |
| 12 | mt7915/eeprom.h | 7 +++++ |
| 13 | mt7915/mt7915.h | 3 ++ |
| 14 | mt7915/mtk_debugfs.c | 44 ++++++++++++++++++++++++++++++ |
| 15 | testmode.h | 2 +- |
| 16 | 7 files changed, 145 insertions(+), 5 deletions(-) |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 17 | |
| 18 | diff --git a/eeprom.c b/eeprom.c |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 19 | index 9b63799..d5b8c56 100644 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 20 | --- a/eeprom.c |
| 21 | +++ b/eeprom.c |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 22 | @@ -159,6 +159,31 @@ int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len) |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 23 | } |
| 24 | EXPORT_SYMBOL_GPL(mt76_get_of_eeprom); |
| 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 | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 37 | + if (dev->bin_file_name) { |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 38 | + dev_info(dev->dev, "Using bin file %s\n", dev->bin_file_name); |
developer | bf0f2d6 | 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 | 2aa1e64 | 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 | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 55 | index d16accd..9673926 100644 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 56 | --- a/mt76.h |
| 57 | +++ b/mt76.h |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 58 | @@ -943,6 +943,9 @@ struct mt76_dev { |
developer | 8e5fecd | 2023-05-30 11:58:00 +0800 | [diff] [blame] | 59 | struct mt76_usb usb; |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 60 | struct mt76_sdio sdio; |
| 61 | }; |
developer | 8e5fecd | 2023-05-30 11:58:00 +0800 | [diff] [blame] | 62 | + |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 63 | + /* for mtk internal */ |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 64 | + const char *bin_file_name; |
| 65 | }; |
| 66 | |
developer | 004e50c | 2023-06-29 20:33:22 +0800 | [diff] [blame] | 67 | /* per-phy stats. */ |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 68 | @@ -1175,6 +1178,7 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str, |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 69 | int mt76_eeprom_init(struct mt76_dev *dev, int len); |
| 70 | void mt76_eeprom_override(struct mt76_phy *phy); |
| 71 | int mt76_get_of_eeprom(struct mt76_dev *dev, void *data, int offset, int len); |
| 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 | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 77 | index a5c99a5..5eb9f88 100644 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 78 | --- a/mt7915/eeprom.c |
| 79 | +++ b/mt7915/eeprom.c |
developer | bf0f2d6 | 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; |
| 111 | @@ -24,7 +48,10 @@ static int mt7915_eeprom_load_precal(struct mt7915_dev *dev) |
| 112 | |
| 113 | offs = is_mt7915(&dev->mt76) ? MT_EE_PRECAL : MT_EE_PRECAL_V2; |
| 114 | |
| 115 | - return mt76_get_of_eeprom(mdev, dev->cal, offs, size); |
| 116 | + if (!dev->bin_file_mode) |
| 117 | + return mt76_get_of_eeprom(mdev, dev->cal, offs, size); |
| 118 | + else |
| 119 | + return mt7915_eeprom_load_precal_binfile(dev, offs, size); |
| 120 | } |
| 121 | |
| 122 | static int mt7915_check_eeprom(struct mt7915_dev *dev) |
| 123 | @@ -47,8 +74,11 @@ static int mt7915_check_eeprom(struct mt7915_dev *dev) |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 124 | } |
| 125 | } |
| 126 | |
| 127 | -static char *mt7915_eeprom_name(struct mt7915_dev *dev) |
| 128 | +const char *mt7915_eeprom_name(struct mt7915_dev *dev) |
| 129 | { |
| 130 | + if (dev->bin_file_mode) |
| 131 | + return dev->mt76.bin_file_name; |
| 132 | + |
| 133 | switch (mt76_chip(&dev->mt76)) { |
| 134 | case 0x7915: |
| 135 | return dev->dbdc_support ? |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 136 | @@ -89,7 +119,10 @@ mt7915_eeprom_load_default(struct mt7915_dev *dev) |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 137 | return ret; |
| 138 | |
| 139 | if (!fw || !fw->data) { |
| 140 | - dev_err(dev->mt76.dev, "Invalid default bin\n"); |
| 141 | + if (dev->bin_file_mode) |
| 142 | + dev_err(dev->mt76.dev, "Invalid bin (bin file mode)\n"); |
| 143 | + else |
| 144 | + dev_err(dev->mt76.dev, "Invalid default bin\n"); |
| 145 | ret = -EINVAL; |
| 146 | goto out; |
| 147 | } |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 148 | @@ -114,6 +147,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev) |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 149 | |
| 150 | if (ret) { |
| 151 | dev->flash_mode = true; |
| 152 | + dev->eeprom_mode = FLASH_MODE; |
| 153 | } else { |
| 154 | u8 free_block_num; |
| 155 | u32 block_num, i; |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 156 | @@ -134,6 +168,8 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev) |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 157 | if (ret < 0) |
| 158 | return ret; |
| 159 | } |
| 160 | + |
| 161 | + dev->eeprom_mode = EFUSE_MODE; |
| 162 | } |
| 163 | |
| 164 | return mt7915_check_eeprom(dev); |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 165 | @@ -239,12 +275,33 @@ int mt7915_eeprom_init(struct mt7915_dev *dev) |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 166 | { |
| 167 | int ret; |
| 168 | |
| 169 | - ret = mt7915_eeprom_load(dev); |
| 170 | + dev->bin_file_mode = mt76_check_bin_file_mode(&dev->mt76); |
| 171 | + if (dev->bin_file_mode) { |
| 172 | + dev->mt76.eeprom.size = mt7915_eeprom_size(dev); |
| 173 | + dev->mt76.eeprom.data = devm_kzalloc(dev->mt76.dev, dev->mt76.eeprom.size, |
| 174 | + GFP_KERNEL); |
| 175 | + if (!dev->mt76.eeprom.data) |
| 176 | + return -ENOMEM; |
| 177 | + ret = mt7915_eeprom_load_default(dev); |
| 178 | + if (ret) |
| 179 | + return ret; |
| 180 | + |
| 181 | + ret = mt7915_check_eeprom(dev); |
| 182 | + if (ret) |
| 183 | + return ret; |
| 184 | + dev->eeprom_mode = BIN_FILE_MODE; |
| 185 | + } else { |
| 186 | + ret = mt7915_eeprom_load(dev); |
| 187 | + } |
| 188 | + |
| 189 | if (ret < 0) { |
| 190 | if (ret != -EINVAL) |
| 191 | return ret; |
| 192 | |
| 193 | dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n"); |
| 194 | + dev->bin_file_mode = false; |
| 195 | + dev->eeprom_mode = DEFAULT_BIN_MODE; |
| 196 | + |
| 197 | ret = mt7915_eeprom_load_default(dev); |
| 198 | if (ret) |
| 199 | return ret; |
| 200 | diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 201 | index fdae347..9056d78 100644 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 202 | --- a/mt7915/eeprom.h |
| 203 | +++ b/mt7915/eeprom.h |
| 204 | @@ -108,6 +108,13 @@ enum mt7915_sku_rate_group { |
| 205 | MAX_SKU_RATE_GROUP_NUM, |
| 206 | }; |
| 207 | |
| 208 | +enum mt7915_eeprom_mode { |
| 209 | + DEFAULT_BIN_MODE, |
| 210 | + EFUSE_MODE, |
| 211 | + FLASH_MODE, |
| 212 | + BIN_FILE_MODE, |
| 213 | +}; |
| 214 | + |
| 215 | static inline int |
| 216 | mt7915_get_channel_group_5g(int channel, bool is_7976) |
| 217 | { |
| 218 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 219 | index 795af63..992323d 100644 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 220 | --- a/mt7915/mt7915.h |
| 221 | +++ b/mt7915/mt7915.h |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 222 | @@ -351,6 +351,8 @@ struct mt7915_dev { |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 223 | |
| 224 | bool dbdc_support; |
| 225 | bool flash_mode; |
| 226 | + bool bin_file_mode; |
| 227 | + u8 eeprom_mode; |
| 228 | bool muru_debug; |
| 229 | bool ibf; |
| 230 | |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 231 | @@ -727,6 +729,7 @@ void mt7915_dump_tmac_info(u8 *tmac_info); |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 232 | int mt7915_mcu_set_txpower_level(struct mt7915_phy *phy, u8 drop_level); |
| 233 | void mt7915_packet_log_to_host(struct mt7915_dev *dev, const void *data, int len, int type, int des_len); |
| 234 | int mt7915_mcu_set_amsdu_algo(struct mt7915_dev *dev, u16 wcid, u8 enable); |
| 235 | +const char *mt7915_eeprom_name(struct mt7915_dev *dev); |
| 236 | |
| 237 | #define PKT_BIN_DEBUG_MAGIC 0xc8763123 |
| 238 | enum { |
| 239 | diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 240 | index 7105cf0..5c676d8 100644 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 241 | --- a/mt7915/mtk_debugfs.c |
| 242 | +++ b/mt7915/mtk_debugfs.c |
| 243 | @@ -3,6 +3,7 @@ |
| 244 | #include "mt7915_debug.h" |
| 245 | #include "mac.h" |
| 246 | #include "mcu.h" |
| 247 | +#include "eeprom.h" |
| 248 | |
| 249 | #ifdef MTK_DEBUG |
| 250 | #define LWTBL_IDX2BASE_ID GENMASK(14, 8) |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 251 | @@ -3600,6 +3601,47 @@ static int mt7915_fw_wm_info_read(struct seq_file *s, void *data) |
developer | a43cc48 | 2023-04-17 15:57:28 +0800 | [diff] [blame] | 252 | return 0; |
| 253 | } |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 254 | |
| 255 | +static int mt7915_show_eeprom_mode(struct seq_file *s, void *data) |
| 256 | +{ |
| 257 | + struct mt7915_dev *dev = dev_get_drvdata(s->private); |
| 258 | + struct mt76_dev *mdev = &dev->mt76; |
developer | 3a38877 | 2023-04-19 10:12:02 +0800 | [diff] [blame] | 259 | + u8 free_block_num = 0; |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 260 | +#ifdef CONFIG_NL80211_TESTMODE |
| 261 | + const char *mtd_name = mdev->test_mtd.name; |
| 262 | + u32 mtd_offset = mdev->test_mtd.offset; |
| 263 | +#else |
| 264 | + const char *mtd_name = NULL; |
| 265 | + u32 mtd_offset; |
| 266 | +#endif |
| 267 | + |
| 268 | + seq_printf(s, "Current eeprom mode:\n"); |
| 269 | + |
| 270 | + switch (dev->eeprom_mode) { |
| 271 | + case DEFAULT_BIN_MODE: |
| 272 | + seq_printf(s, " default bin mode\n filename = %s\n", mt7915_eeprom_name(dev)); |
| 273 | + break; |
| 274 | + case EFUSE_MODE: |
| 275 | + seq_printf(s, " efuse mode\n"); |
developer | 3a38877 | 2023-04-19 10:12:02 +0800 | [diff] [blame] | 276 | + mt7915_mcu_get_eeprom_free_block(dev, &free_block_num); |
| 277 | + seq_printf(s, " free block number = %d\n", free_block_num); |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 278 | + break; |
| 279 | + case FLASH_MODE: |
| 280 | + if (mtd_name) |
| 281 | + seq_printf(s, " flash mode\n mtd name = %s\n flash offset = 0x%x\n", |
| 282 | + mtd_name, mtd_offset); |
| 283 | + else |
| 284 | + seq_printf(s, " flash mode\n"); |
| 285 | + break; |
| 286 | + case BIN_FILE_MODE: |
| 287 | + seq_printf(s, " bin file mode\n filename = %s\n", mt7915_eeprom_name(dev)); |
| 288 | + break; |
| 289 | + default: |
| 290 | + break; |
| 291 | + } |
| 292 | + |
| 293 | + return 0; |
| 294 | +} |
| 295 | + |
| 296 | int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir) |
| 297 | { |
| 298 | struct mt7915_dev *dev = phy->dev; |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 299 | @@ -3686,6 +3728,8 @@ int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir) |
developer | 8e5fecd | 2023-05-30 11:58:00 +0800 | [diff] [blame] | 300 | |
| 301 | debugfs_create_u8("sku_disable", 0600, dir, &dev->dbg.sku_disable); |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 302 | |
| 303 | + debugfs_create_devm_seqfile(dev->mt76.dev, "eeprom_mode", dir, |
| 304 | + mt7915_show_eeprom_mode); |
| 305 | return 0; |
| 306 | } |
| 307 | #endif |
developer | bf0f2d6 | 2023-11-14 17:01:47 +0800 | [diff] [blame^] | 308 | diff --git a/testmode.h b/testmode.h |
| 309 | index 20fab3e..91d1e86 100644 |
| 310 | --- a/testmode.h |
| 311 | +++ b/testmode.h |
| 312 | @@ -17,7 +17,7 @@ |
| 313 | * @MT76_TM_ATTR_RESET: reset parameters to default (flag) |
| 314 | * @MT76_TM_ATTR_STATE: test state (u32), see &enum mt76_testmode_state |
| 315 | * |
| 316 | - * @MT76_TM_ATTR_MTD_PART: mtd partition used for eeprom data (string) |
| 317 | + * @MT76_TM_ATTR_MTD_PART: mtd partition or binfile used for eeprom data (string) |
| 318 | * @MT76_TM_ATTR_MTD_OFFSET: offset of eeprom data within the partition (u32) |
| 319 | * @MT76_TM_ATTR_BAND_IDX: band idx of the chip (u8) |
| 320 | * |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 321 | -- |
developer | e35b8e4 | 2023-10-16 11:04:00 +0800 | [diff] [blame] | 322 | 2.18.0 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 323 | |