developer | 3a38877 | 2023-04-19 10:12:02 +0800 | [diff] [blame^] | 1 | From c8744205bdfda122ef0cc2bb7b0105dac23b6f8b 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 | 3a38877 | 2023-04-19 10:12:02 +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 | --- |
| 9 | eeprom.c | 20 ++++++++++++++++++++ |
| 10 | mt76.h | 3 +++ |
| 11 | mt7915/eeprom.c | 36 +++++++++++++++++++++++++++++++++--- |
| 12 | mt7915/eeprom.h | 7 +++++++ |
| 13 | mt7915/mt7915.h | 9 ++++++--- |
developer | 3a38877 | 2023-04-19 10:12:02 +0800 | [diff] [blame^] | 14 | mt7915/mtk_debugfs.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ |
| 15 | 6 files changed, 113 insertions(+), 6 deletions(-) |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 16 | |
| 17 | diff --git a/eeprom.c b/eeprom.c |
developer | a43cc48 | 2023-04-17 15:57:28 +0800 | [diff] [blame] | 18 | index aa88925..412740f 100644 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 19 | --- a/eeprom.c |
| 20 | +++ b/eeprom.c |
| 21 | @@ -104,6 +104,26 @@ out_put_node: |
| 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; |
| 28 | + const char *bin_file_name = NULL; |
| 29 | + |
| 30 | + if (!np) |
| 31 | + return false; |
| 32 | + |
| 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); |
| 38 | + |
| 39 | + of_node_put(np); |
| 40 | + |
| 41 | + return dev->bin_file_name ? true : false; |
| 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 | a43cc48 | 2023-04-17 15:57:28 +0800 | [diff] [blame] | 49 | index 699bb77..614c607 100644 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 50 | --- a/mt76.h |
| 51 | +++ b/mt76.h |
developer | a43cc48 | 2023-04-17 15:57:28 +0800 | [diff] [blame] | 52 | @@ -905,9 +905,11 @@ struct mt76_dev { |
developer | 2aa1e64 | 2022-12-19 11:33:22 +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 | a43cc48 | 2023-04-17 15:57:28 +0800 | [diff] [blame] | 64 | @@ -1044,6 +1046,7 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str, |
developer | 2aa1e64 | 2022-12-19 11:33:22 +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 | a43cc48 | 2023-04-17 15:57:28 +0800 | [diff] [blame] | 73 | index 77a1047..612be3f 100644 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 74 | --- a/mt7915/eeprom.c |
| 75 | +++ b/mt7915/eeprom.c |
| 76 | @@ -45,8 +45,11 @@ static int mt7915_check_eeprom(struct mt7915_dev *dev) |
| 77 | } |
| 78 | } |
| 79 | |
| 80 | -static char *mt7915_eeprom_name(struct mt7915_dev *dev) |
| 81 | +const char *mt7915_eeprom_name(struct mt7915_dev *dev) |
| 82 | { |
| 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 ? |
| 89 | @@ -84,7 +87,10 @@ mt7915_eeprom_load_default(struct mt7915_dev *dev) |
| 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 | } |
| 101 | @@ -109,6 +115,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev) |
| 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; |
| 109 | @@ -129,6 +136,8 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev) |
| 110 | if (ret < 0) |
| 111 | return ret; |
| 112 | } |
| 113 | + |
| 114 | + dev->eeprom_mode = EFUSE_MODE; |
| 115 | } |
| 116 | |
| 117 | return mt7915_check_eeprom(dev); |
| 118 | @@ -234,12 +243,33 @@ int mt7915_eeprom_init(struct mt7915_dev *dev) |
| 119 | { |
| 120 | int ret; |
| 121 | |
| 122 | - ret = mt7915_eeprom_load(dev); |
| 123 | + dev->bin_file_mode = mt76_check_bin_file_mode(&dev->mt76); |
| 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, |
| 127 | + GFP_KERNEL); |
| 128 | + if (!dev->mt76.eeprom.data) |
| 129 | + return -ENOMEM; |
| 130 | + ret = mt7915_eeprom_load_default(dev); |
| 131 | + if (ret) |
| 132 | + return ret; |
| 133 | + |
| 134 | + ret = mt7915_check_eeprom(dev); |
| 135 | + if (ret) |
| 136 | + return ret; |
| 137 | + dev->eeprom_mode = BIN_FILE_MODE; |
| 138 | + } else { |
| 139 | + ret = mt7915_eeprom_load(dev); |
| 140 | + } |
| 141 | + |
| 142 | if (ret < 0) { |
| 143 | if (ret != -EINVAL) |
| 144 | return ret; |
| 145 | |
| 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; |
| 149 | + |
| 150 | ret = mt7915_eeprom_load_default(dev); |
| 151 | if (ret) |
| 152 | return ret; |
| 153 | diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h |
developer | a43cc48 | 2023-04-17 15:57:28 +0800 | [diff] [blame] | 154 | index fdae347..9056d78 100644 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +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 | { |
| 171 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
developer | a43cc48 | 2023-04-17 15:57:28 +0800 | [diff] [blame] | 172 | index ca81289..17efd20 100644 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 173 | --- a/mt7915/mt7915.h |
| 174 | +++ b/mt7915/mt7915.h |
| 175 | @@ -42,9 +42,9 @@ |
| 176 | #define MT7986_ROM_PATCH "mediatek/mt7986_rom_patch.bin" |
| 177 | #define MT7986_ROM_PATCH_MT7975 "mediatek/mt7986_rom_patch_mt7975.bin" |
| 178 | |
| 179 | -#define MT7915_EEPROM_DEFAULT "mediatek/mt7915_eeprom.bin" |
| 180 | -#define MT7915_EEPROM_DEFAULT_DBDC "mediatek/mt7915_eeprom_dbdc.bin" |
| 181 | -#define MT7916_EEPROM_DEFAULT "mediatek/mt7916_eeprom.bin" |
| 182 | +#define MT7915_EEPROM_DEFAULT "mediatek/mt7915_eeprom.bin" |
| 183 | +#define MT7915_EEPROM_DEFAULT_DBDC "mediatek/mt7915_eeprom_dbdc.bin" |
| 184 | +#define MT7916_EEPROM_DEFAULT "mediatek/mt7916_eeprom.bin" |
| 185 | #define MT7986_EEPROM_MT7975_DEFAULT "mediatek/mt7986_eeprom_mt7975.bin" |
| 186 | #define MT7986_EEPROM_MT7975_DUAL_DEFAULT "mediatek/mt7986_eeprom_mt7975_dual.bin" |
| 187 | #define MT7986_EEPROM_MT7976_DEFAULT "mediatek/mt7986_eeprom_mt7976.bin" |
developer | a43cc48 | 2023-04-17 15:57:28 +0800 | [diff] [blame] | 188 | @@ -408,6 +408,8 @@ struct mt7915_dev { |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 189 | |
| 190 | bool dbdc_support; |
| 191 | bool flash_mode; |
| 192 | + bool bin_file_mode; |
| 193 | + u8 eeprom_mode; |
| 194 | bool muru_debug; |
| 195 | bool ibf; |
| 196 | |
developer | a43cc48 | 2023-04-17 15:57:28 +0800 | [diff] [blame] | 197 | @@ -785,6 +787,7 @@ void mt7915_dump_tmac_info(u8 *tmac_info); |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 198 | int mt7915_mcu_set_txpower_level(struct mt7915_phy *phy, u8 drop_level); |
| 199 | void mt7915_packet_log_to_host(struct mt7915_dev *dev, const void *data, int len, int type, int des_len); |
| 200 | int mt7915_mcu_set_amsdu_algo(struct mt7915_dev *dev, u16 wcid, u8 enable); |
| 201 | +const char *mt7915_eeprom_name(struct mt7915_dev *dev); |
| 202 | |
| 203 | #define PKT_BIN_DEBUG_MAGIC 0xc8763123 |
| 204 | enum { |
| 205 | diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c |
developer | 3a38877 | 2023-04-19 10:12:02 +0800 | [diff] [blame^] | 206 | index 69dc311..53d10e3 100644 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 207 | --- a/mt7915/mtk_debugfs.c |
| 208 | +++ b/mt7915/mtk_debugfs.c |
| 209 | @@ -3,6 +3,7 @@ |
| 210 | #include "mt7915_debug.h" |
| 211 | #include "mac.h" |
| 212 | #include "mcu.h" |
| 213 | +#include "eeprom.h" |
| 214 | |
| 215 | #ifdef MTK_DEBUG |
| 216 | #define LWTBL_IDX2BASE_ID GENMASK(14, 8) |
developer | 3a38877 | 2023-04-19 10:12:02 +0800 | [diff] [blame^] | 217 | @@ -3602,6 +3603,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] | 218 | return 0; |
| 219 | } |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 220 | |
| 221 | +static int mt7915_show_eeprom_mode(struct seq_file *s, void *data) |
| 222 | +{ |
| 223 | + struct mt7915_dev *dev = dev_get_drvdata(s->private); |
| 224 | + struct mt76_dev *mdev = &dev->mt76; |
developer | 3a38877 | 2023-04-19 10:12:02 +0800 | [diff] [blame^] | 225 | + u8 free_block_num = 0; |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 226 | +#ifdef CONFIG_NL80211_TESTMODE |
| 227 | + const char *mtd_name = mdev->test_mtd.name; |
| 228 | + u32 mtd_offset = mdev->test_mtd.offset; |
| 229 | +#else |
| 230 | + const char *mtd_name = NULL; |
| 231 | + u32 mtd_offset; |
| 232 | +#endif |
| 233 | + |
| 234 | + seq_printf(s, "Current eeprom mode:\n"); |
| 235 | + |
| 236 | + switch (dev->eeprom_mode) { |
| 237 | + case DEFAULT_BIN_MODE: |
| 238 | + seq_printf(s, " default bin mode\n filename = %s\n", mt7915_eeprom_name(dev)); |
| 239 | + break; |
| 240 | + case EFUSE_MODE: |
| 241 | + seq_printf(s, " efuse mode\n"); |
developer | 3a38877 | 2023-04-19 10:12:02 +0800 | [diff] [blame^] | 242 | + mt7915_mcu_get_eeprom_free_block(dev, &free_block_num); |
| 243 | + seq_printf(s, " free block number = %d\n", free_block_num); |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 244 | + break; |
| 245 | + case FLASH_MODE: |
| 246 | + if (mtd_name) |
| 247 | + seq_printf(s, " flash mode\n mtd name = %s\n flash offset = 0x%x\n", |
| 248 | + mtd_name, mtd_offset); |
| 249 | + else |
| 250 | + seq_printf(s, " flash mode\n"); |
| 251 | + break; |
| 252 | + case BIN_FILE_MODE: |
| 253 | + seq_printf(s, " bin file mode\n filename = %s\n", mt7915_eeprom_name(dev)); |
| 254 | + break; |
| 255 | + default: |
| 256 | + break; |
| 257 | + } |
| 258 | + |
| 259 | + return 0; |
| 260 | +} |
| 261 | + |
| 262 | int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir) |
| 263 | { |
| 264 | struct mt7915_dev *dev = phy->dev; |
developer | 3a38877 | 2023-04-19 10:12:02 +0800 | [diff] [blame^] | 265 | @@ -3689,6 +3731,8 @@ int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir) |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 266 | debugfs_create_devm_seqfile(dev->mt76.dev, "fw_version", dir, |
| 267 | mt7915_dump_version); |
| 268 | |
| 269 | + debugfs_create_devm_seqfile(dev->mt76.dev, "eeprom_mode", dir, |
| 270 | + mt7915_show_eeprom_mode); |
| 271 | return 0; |
| 272 | } |
| 273 | #endif |
| 274 | -- |
developer | a43cc48 | 2023-04-17 15:57:28 +0800 | [diff] [blame] | 275 | 2.18.0 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 276 | |