developer | bbd45e1 | 2023-05-19 08:22:06 +0800 | [diff] [blame] | 1 | From c7577e7c0c00532de4c3aac99b11d96fc178ca43 Mon Sep 17 00:00:00 2001 |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 2 | From: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 3 | Date: Thu, 7 Jul 2022 11:09:59 +0800 |
developer | bbd45e1 | 2023-05-19 08:22:06 +0800 | [diff] [blame] | 4 | Subject: [PATCH 1020/1033] wifi: mt76: mt7915: implement bin file mode |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 5 | |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 6 | Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
developer | 30d39c2 | 2022-12-16 10:29:49 +0800 | [diff] [blame] | 7 | Signed-off-by: Shayne Chen <shayne.chen@mediatek.com> |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 8 | --- |
developer | 30d39c2 | 2022-12-16 10:29:49 +0800 | [diff] [blame] | 9 | eeprom.c | 20 ++++++++++++++++++++ |
| 10 | mt76.h | 3 +++ |
| 11 | mt7915/eeprom.c | 36 +++++++++++++++++++++++++++++++++--- |
| 12 | mt7915/eeprom.h | 7 +++++++ |
developer | bbd45e1 | 2023-05-19 08:22:06 +0800 | [diff] [blame] | 13 | mt7915/mt7915.h | 3 +++ |
developer | e0f7218 | 2023-04-17 10:46:00 +0800 | [diff] [blame] | 14 | mt7915/mtk_debugfs.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ |
developer | bbd45e1 | 2023-05-19 08:22:06 +0800 | [diff] [blame] | 15 | 6 files changed, 110 insertions(+), 3 deletions(-) |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 16 | |
| 17 | diff --git a/eeprom.c b/eeprom.c |
developer | 1d9da7d | 2023-04-15 12:45:34 +0800 | [diff] [blame] | 18 | index aa88925..412740f 100644 |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 19 | --- a/eeprom.c |
| 20 | +++ b/eeprom.c |
developer | 30d39c2 | 2022-12-16 10:29:49 +0800 | [diff] [blame] | 21 | @@ -104,6 +104,26 @@ out_put_node: |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 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; |
developer | 30d39c2 | 2022-12-16 10:29:49 +0800 | [diff] [blame] | 28 | + const char *bin_file_name = NULL; |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 29 | + |
| 30 | + if (!np) |
| 31 | + return false; |
| 32 | + |
developer | 30d39c2 | 2022-12-16 10:29:49 +0800 | [diff] [blame] | 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); |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 38 | + |
| 39 | + of_node_put(np); |
developer | 30d39c2 | 2022-12-16 10:29:49 +0800 | [diff] [blame] | 40 | + |
| 41 | + return dev->bin_file_name ? true : false; |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 42 | +} |
| 43 | +EXPORT_SYMBOL_GPL(mt76_check_bin_file_mode); |
| 44 | + |
| 45 | void |
| 46 | mt76_eeprom_override(struct mt76_phy *phy) |
| 47 | { |
| 48 | diff --git a/mt76.h b/mt76.h |
developer | bbd45e1 | 2023-05-19 08:22:06 +0800 | [diff] [blame] | 49 | index 8e679a1..668ab2b 100644 |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 50 | --- a/mt76.h |
| 51 | +++ b/mt76.h |
developer | bbd45e1 | 2023-05-19 08:22:06 +0800 | [diff] [blame] | 52 | @@ -906,9 +906,11 @@ struct mt76_dev { |
developer | 30d39c2 | 2022-12-16 10:29:49 +0800 | [diff] [blame] | 53 | struct mt76_sdio sdio; |
| 54 | }; |
| 55 | |
| 56 | + /* for mtk internal */ |
| 57 | struct mt76_connac2_patch_hdr *patch_hdr; |
| 58 | struct mt76_connac2_fw_trailer *wm_hdr; |
| 59 | struct mt76_connac2_fw_trailer *wa_hdr; |
| 60 | + const char *bin_file_name; |
| 61 | }; |
| 62 | |
| 63 | struct mt76_power_limits { |
developer | bbd45e1 | 2023-05-19 08:22:06 +0800 | [diff] [blame] | 64 | @@ -1045,6 +1047,7 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str, |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 65 | int mt76_eeprom_init(struct mt76_dev *dev, int len); |
| 66 | void mt76_eeprom_override(struct mt76_phy *phy); |
| 67 | int mt76_get_of_eeprom(struct mt76_dev *dev, void *data, int offset, int len); |
| 68 | +bool mt76_check_bin_file_mode(struct mt76_dev *dev); |
| 69 | |
| 70 | struct mt76_queue * |
| 71 | mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc, |
| 72 | diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c |
developer | bbd45e1 | 2023-05-19 08:22:06 +0800 | [diff] [blame] | 73 | index a5c99a5..fd08d42 100644 |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 74 | --- a/mt7915/eeprom.c |
| 75 | +++ b/mt7915/eeprom.c |
developer | bbd45e1 | 2023-05-19 08:22:06 +0800 | [diff] [blame] | 76 | @@ -47,8 +47,11 @@ static int mt7915_check_eeprom(struct mt7915_dev *dev) |
developer | 29647af | 2022-11-15 18:09:16 +0800 | [diff] [blame] | 77 | } |
| 78 | } |
| 79 | |
| 80 | -static char *mt7915_eeprom_name(struct mt7915_dev *dev) |
developer | 30d39c2 | 2022-12-16 10:29:49 +0800 | [diff] [blame] | 81 | +const char *mt7915_eeprom_name(struct mt7915_dev *dev) |
developer | 29647af | 2022-11-15 18:09:16 +0800 | [diff] [blame] | 82 | { |
developer | 30d39c2 | 2022-12-16 10:29:49 +0800 | [diff] [blame] | 83 | + if (dev->bin_file_mode) |
| 84 | + return dev->mt76.bin_file_name; |
| 85 | + |
| 86 | switch (mt76_chip(&dev->mt76)) { |
| 87 | case 0x7915: |
| 88 | return dev->dbdc_support ? |
developer | bbd45e1 | 2023-05-19 08:22:06 +0800 | [diff] [blame] | 89 | @@ -89,7 +92,10 @@ mt7915_eeprom_load_default(struct mt7915_dev *dev) |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 90 | return ret; |
| 91 | |
| 92 | if (!fw || !fw->data) { |
| 93 | - dev_err(dev->mt76.dev, "Invalid default bin\n"); |
| 94 | + if (dev->bin_file_mode) |
| 95 | + dev_err(dev->mt76.dev, "Invalid bin (bin file mode)\n"); |
| 96 | + else |
| 97 | + dev_err(dev->mt76.dev, "Invalid default bin\n"); |
| 98 | ret = -EINVAL; |
| 99 | goto out; |
| 100 | } |
developer | bbd45e1 | 2023-05-19 08:22:06 +0800 | [diff] [blame] | 101 | @@ -114,6 +120,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev) |
developer | 29647af | 2022-11-15 18:09:16 +0800 | [diff] [blame] | 102 | |
| 103 | if (ret) { |
| 104 | dev->flash_mode = true; |
| 105 | + dev->eeprom_mode = FLASH_MODE; |
| 106 | } else { |
| 107 | u8 free_block_num; |
| 108 | u32 block_num, i; |
developer | bbd45e1 | 2023-05-19 08:22:06 +0800 | [diff] [blame] | 109 | @@ -134,6 +141,8 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev) |
developer | eb6a018 | 2022-12-12 18:53:32 +0800 | [diff] [blame] | 110 | if (ret < 0) |
| 111 | return ret; |
| 112 | } |
| 113 | + |
developer | 29647af | 2022-11-15 18:09:16 +0800 | [diff] [blame] | 114 | + dev->eeprom_mode = EFUSE_MODE; |
| 115 | } |
| 116 | |
| 117 | return mt7915_check_eeprom(dev); |
developer | bbd45e1 | 2023-05-19 08:22:06 +0800 | [diff] [blame] | 118 | @@ -239,12 +248,33 @@ int mt7915_eeprom_init(struct mt7915_dev *dev) |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 119 | { |
| 120 | int ret; |
| 121 | |
| 122 | - ret = mt7915_eeprom_load(dev); |
| 123 | + dev->bin_file_mode = mt76_check_bin_file_mode(&dev->mt76); |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 124 | + if (dev->bin_file_mode) { |
| 125 | + dev->mt76.eeprom.size = mt7915_eeprom_size(dev); |
| 126 | + dev->mt76.eeprom.data = devm_kzalloc(dev->mt76.dev, dev->mt76.eeprom.size, |
developer | 29647af | 2022-11-15 18:09:16 +0800 | [diff] [blame] | 127 | + GFP_KERNEL); |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 128 | + if (!dev->mt76.eeprom.data) |
| 129 | + return -ENOMEM; |
| 130 | + ret = mt7915_eeprom_load_default(dev); |
developer | 30d39c2 | 2022-12-16 10:29:49 +0800 | [diff] [blame] | 131 | + if (ret) |
| 132 | + return ret; |
| 133 | + |
| 134 | + ret = mt7915_check_eeprom(dev); |
| 135 | + if (ret) |
| 136 | + return ret; |
developer | 29647af | 2022-11-15 18:09:16 +0800 | [diff] [blame] | 137 | + dev->eeprom_mode = BIN_FILE_MODE; |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 138 | + } else { |
| 139 | + ret = mt7915_eeprom_load(dev); |
| 140 | + } |
| 141 | + |
| 142 | if (ret < 0) { |
| 143 | if (ret != -EINVAL) |
| 144 | return ret; |
| 145 | |
developer | 29647af | 2022-11-15 18:09:16 +0800 | [diff] [blame] | 146 | dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n"); |
| 147 | + dev->bin_file_mode = false; |
| 148 | + dev->eeprom_mode = DEFAULT_BIN_MODE; |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 149 | + |
| 150 | ret = mt7915_eeprom_load_default(dev); |
| 151 | if (ret) |
| 152 | return ret; |
developer | 29647af | 2022-11-15 18:09:16 +0800 | [diff] [blame] | 153 | diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h |
developer | 1d9da7d | 2023-04-15 12:45:34 +0800 | [diff] [blame] | 154 | index fdae347..9056d78 100644 |
developer | 29647af | 2022-11-15 18:09:16 +0800 | [diff] [blame] | 155 | --- a/mt7915/eeprom.h |
| 156 | +++ b/mt7915/eeprom.h |
| 157 | @@ -108,6 +108,13 @@ enum mt7915_sku_rate_group { |
| 158 | MAX_SKU_RATE_GROUP_NUM, |
| 159 | }; |
| 160 | |
| 161 | +enum mt7915_eeprom_mode { |
| 162 | + DEFAULT_BIN_MODE, |
| 163 | + EFUSE_MODE, |
| 164 | + FLASH_MODE, |
| 165 | + BIN_FILE_MODE, |
| 166 | +}; |
| 167 | + |
| 168 | static inline int |
| 169 | mt7915_get_channel_group_5g(int channel, bool is_7976) |
| 170 | { |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 171 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
developer | bbd45e1 | 2023-05-19 08:22:06 +0800 | [diff] [blame] | 172 | index 2409bf5..25f92e1 100644 |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 173 | --- a/mt7915/mt7915.h |
| 174 | +++ b/mt7915/mt7915.h |
developer | bbd45e1 | 2023-05-19 08:22:06 +0800 | [diff] [blame] | 175 | @@ -400,6 +400,8 @@ struct mt7915_dev { |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 176 | |
| 177 | bool dbdc_support; |
| 178 | bool flash_mode; |
| 179 | + bool bin_file_mode; |
developer | 29647af | 2022-11-15 18:09:16 +0800 | [diff] [blame] | 180 | + u8 eeprom_mode; |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 181 | bool muru_debug; |
| 182 | bool ibf; |
| 183 | |
developer | bbd45e1 | 2023-05-19 08:22:06 +0800 | [diff] [blame] | 184 | @@ -775,6 +777,7 @@ void mt7915_dump_tmac_info(u8 *tmac_info); |
developer | 30d39c2 | 2022-12-16 10:29:49 +0800 | [diff] [blame] | 185 | int mt7915_mcu_set_txpower_level(struct mt7915_phy *phy, u8 drop_level); |
| 186 | void mt7915_packet_log_to_host(struct mt7915_dev *dev, const void *data, int len, int type, int des_len); |
| 187 | int mt7915_mcu_set_amsdu_algo(struct mt7915_dev *dev, u16 wcid, u8 enable); |
| 188 | +const char *mt7915_eeprom_name(struct mt7915_dev *dev); |
| 189 | |
| 190 | #define PKT_BIN_DEBUG_MAGIC 0xc8763123 |
| 191 | enum { |
developer | 29647af | 2022-11-15 18:09:16 +0800 | [diff] [blame] | 192 | diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c |
developer | bbd45e1 | 2023-05-19 08:22:06 +0800 | [diff] [blame] | 193 | index 20133a4..2cccebe 100644 |
developer | 29647af | 2022-11-15 18:09:16 +0800 | [diff] [blame] | 194 | --- a/mt7915/mtk_debugfs.c |
| 195 | +++ b/mt7915/mtk_debugfs.c |
| 196 | @@ -3,6 +3,7 @@ |
| 197 | #include "mt7915_debug.h" |
| 198 | #include "mac.h" |
| 199 | #include "mcu.h" |
| 200 | +#include "eeprom.h" |
| 201 | |
| 202 | #ifdef MTK_DEBUG |
| 203 | #define LWTBL_IDX2BASE_ID GENMASK(14, 8) |
developer | e0f7218 | 2023-04-17 10:46:00 +0800 | [diff] [blame] | 204 | @@ -3602,6 +3603,47 @@ static int mt7915_fw_wm_info_read(struct seq_file *s, void *data) |
developer | 2324aa2 | 2023-04-12 11:30:15 +0800 | [diff] [blame] | 205 | return 0; |
| 206 | } |
developer | 29647af | 2022-11-15 18:09:16 +0800 | [diff] [blame] | 207 | |
| 208 | +static int mt7915_show_eeprom_mode(struct seq_file *s, void *data) |
| 209 | +{ |
| 210 | + struct mt7915_dev *dev = dev_get_drvdata(s->private); |
| 211 | + struct mt76_dev *mdev = &dev->mt76; |
developer | e0f7218 | 2023-04-17 10:46:00 +0800 | [diff] [blame] | 212 | + u8 free_block_num = 0; |
developer | f84ff07 | 2022-11-17 18:04:25 +0800 | [diff] [blame] | 213 | +#ifdef CONFIG_NL80211_TESTMODE |
developer | eb6a018 | 2022-12-12 18:53:32 +0800 | [diff] [blame] | 214 | + const char *mtd_name = mdev->test_mtd.name; |
developer | 29647af | 2022-11-15 18:09:16 +0800 | [diff] [blame] | 215 | + u32 mtd_offset = mdev->test_mtd.offset; |
developer | f84ff07 | 2022-11-17 18:04:25 +0800 | [diff] [blame] | 216 | +#else |
developer | eb6a018 | 2022-12-12 18:53:32 +0800 | [diff] [blame] | 217 | + const char *mtd_name = NULL; |
developer | f84ff07 | 2022-11-17 18:04:25 +0800 | [diff] [blame] | 218 | + u32 mtd_offset; |
| 219 | +#endif |
developer | 29647af | 2022-11-15 18:09:16 +0800 | [diff] [blame] | 220 | + |
| 221 | + seq_printf(s, "Current eeprom mode:\n"); |
| 222 | + |
| 223 | + switch (dev->eeprom_mode) { |
| 224 | + case DEFAULT_BIN_MODE: |
| 225 | + seq_printf(s, " default bin mode\n filename = %s\n", mt7915_eeprom_name(dev)); |
| 226 | + break; |
| 227 | + case EFUSE_MODE: |
| 228 | + seq_printf(s, " efuse mode\n"); |
developer | e0f7218 | 2023-04-17 10:46:00 +0800 | [diff] [blame] | 229 | + mt7915_mcu_get_eeprom_free_block(dev, &free_block_num); |
| 230 | + seq_printf(s, " free block number = %d\n", free_block_num); |
developer | 29647af | 2022-11-15 18:09:16 +0800 | [diff] [blame] | 231 | + break; |
| 232 | + case FLASH_MODE: |
| 233 | + if (mtd_name) |
| 234 | + seq_printf(s, " flash mode\n mtd name = %s\n flash offset = 0x%x\n", |
| 235 | + mtd_name, mtd_offset); |
| 236 | + else |
| 237 | + seq_printf(s, " flash mode\n"); |
| 238 | + break; |
| 239 | + case BIN_FILE_MODE: |
| 240 | + seq_printf(s, " bin file mode\n filename = %s\n", mt7915_eeprom_name(dev)); |
| 241 | + break; |
| 242 | + default: |
| 243 | + break; |
| 244 | + } |
| 245 | + |
| 246 | + return 0; |
| 247 | +} |
| 248 | + |
| 249 | int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir) |
| 250 | { |
| 251 | struct mt7915_dev *dev = phy->dev; |
developer | e0f7218 | 2023-04-17 10:46:00 +0800 | [diff] [blame] | 252 | @@ -3689,6 +3731,8 @@ int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir) |
developer | 29647af | 2022-11-15 18:09:16 +0800 | [diff] [blame] | 253 | debugfs_create_devm_seqfile(dev->mt76.dev, "fw_version", dir, |
| 254 | mt7915_dump_version); |
| 255 | |
| 256 | + debugfs_create_devm_seqfile(dev->mt76.dev, "eeprom_mode", dir, |
| 257 | + mt7915_show_eeprom_mode); |
| 258 | return 0; |
| 259 | } |
| 260 | #endif |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 261 | -- |
developer | 2324aa2 | 2023-04-12 11:30:15 +0800 | [diff] [blame] | 262 | 2.18.0 |
developer | ceb4001 | 2022-07-07 17:30:32 +0800 | [diff] [blame] | 263 | |