developer | 8e5fecd | 2023-05-30 11:58:00 +0800 | [diff] [blame^] | 1 | From 819b0590e6b8ef9e44e3f0a01c3db33eb236f463 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 | 8e5fecd | 2023-05-30 11:58:00 +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 ++++++++++++++++++++ |
developer | 8e5fecd | 2023-05-30 11:58:00 +0800 | [diff] [blame^] | 10 | mt76.h | 4 ++++ |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 11 | mt7915/eeprom.c | 36 +++++++++++++++++++++++++++++++++--- |
| 12 | mt7915/eeprom.h | 7 +++++++ |
developer | ad9333b | 2023-05-22 15:16:16 +0800 | [diff] [blame] | 13 | mt7915/mt7915.h | 3 +++ |
developer | 3a38877 | 2023-04-19 10:12:02 +0800 | [diff] [blame] | 14 | mt7915/mtk_debugfs.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ |
developer | 8e5fecd | 2023-05-30 11:58:00 +0800 | [diff] [blame^] | 15 | 6 files changed, 111 insertions(+), 3 deletions(-) |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 16 | |
| 17 | diff --git a/eeprom.c b/eeprom.c |
developer | 8e5fecd | 2023-05-30 11:58:00 +0800 | [diff] [blame^] | 18 | index aa889258..412740f0 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 | 8e5fecd | 2023-05-30 11:58:00 +0800 | [diff] [blame^] | 49 | index 0e29248d..b49590d5 100644 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 50 | --- a/mt76.h |
| 51 | +++ b/mt76.h |
developer | 8e5fecd | 2023-05-30 11:58:00 +0800 | [diff] [blame^] | 52 | @@ -916,6 +916,9 @@ struct mt76_dev { |
| 53 | struct mt76_usb usb; |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 54 | struct mt76_sdio sdio; |
| 55 | }; |
developer | 8e5fecd | 2023-05-30 11:58:00 +0800 | [diff] [blame^] | 56 | + |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 57 | + /* for mtk internal */ |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 58 | + const char *bin_file_name; |
| 59 | }; |
| 60 | |
| 61 | struct mt76_power_limits { |
developer | 8e5fecd | 2023-05-30 11:58:00 +0800 | [diff] [blame^] | 62 | @@ -1052,6 +1055,7 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str, |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 63 | int mt76_eeprom_init(struct mt76_dev *dev, int len); |
| 64 | void mt76_eeprom_override(struct mt76_phy *phy); |
| 65 | int mt76_get_of_eeprom(struct mt76_dev *dev, void *data, int offset, int len); |
| 66 | +bool mt76_check_bin_file_mode(struct mt76_dev *dev); |
| 67 | |
| 68 | struct mt76_queue * |
| 69 | mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc, |
| 70 | diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c |
developer | 8e5fecd | 2023-05-30 11:58:00 +0800 | [diff] [blame^] | 71 | index a5c99a5e..fd08d42a 100644 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 72 | --- a/mt7915/eeprom.c |
| 73 | +++ b/mt7915/eeprom.c |
developer | ad9333b | 2023-05-22 15:16:16 +0800 | [diff] [blame] | 74 | @@ -47,8 +47,11 @@ static int mt7915_check_eeprom(struct mt7915_dev *dev) |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
| 78 | -static char *mt7915_eeprom_name(struct mt7915_dev *dev) |
| 79 | +const char *mt7915_eeprom_name(struct mt7915_dev *dev) |
| 80 | { |
| 81 | + if (dev->bin_file_mode) |
| 82 | + return dev->mt76.bin_file_name; |
| 83 | + |
| 84 | switch (mt76_chip(&dev->mt76)) { |
| 85 | case 0x7915: |
| 86 | return dev->dbdc_support ? |
developer | ad9333b | 2023-05-22 15:16:16 +0800 | [diff] [blame] | 87 | @@ -89,7 +92,10 @@ mt7915_eeprom_load_default(struct mt7915_dev *dev) |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 88 | return ret; |
| 89 | |
| 90 | if (!fw || !fw->data) { |
| 91 | - dev_err(dev->mt76.dev, "Invalid default bin\n"); |
| 92 | + if (dev->bin_file_mode) |
| 93 | + dev_err(dev->mt76.dev, "Invalid bin (bin file mode)\n"); |
| 94 | + else |
| 95 | + dev_err(dev->mt76.dev, "Invalid default bin\n"); |
| 96 | ret = -EINVAL; |
| 97 | goto out; |
| 98 | } |
developer | ad9333b | 2023-05-22 15:16:16 +0800 | [diff] [blame] | 99 | @@ -114,6 +120,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev) |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 100 | |
| 101 | if (ret) { |
| 102 | dev->flash_mode = true; |
| 103 | + dev->eeprom_mode = FLASH_MODE; |
| 104 | } else { |
| 105 | u8 free_block_num; |
| 106 | u32 block_num, i; |
developer | ad9333b | 2023-05-22 15:16:16 +0800 | [diff] [blame] | 107 | @@ -134,6 +141,8 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev) |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 108 | if (ret < 0) |
| 109 | return ret; |
| 110 | } |
| 111 | + |
| 112 | + dev->eeprom_mode = EFUSE_MODE; |
| 113 | } |
| 114 | |
| 115 | return mt7915_check_eeprom(dev); |
developer | ad9333b | 2023-05-22 15:16:16 +0800 | [diff] [blame] | 116 | @@ -239,12 +248,33 @@ int mt7915_eeprom_init(struct mt7915_dev *dev) |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 117 | { |
| 118 | int ret; |
| 119 | |
| 120 | - ret = mt7915_eeprom_load(dev); |
| 121 | + dev->bin_file_mode = mt76_check_bin_file_mode(&dev->mt76); |
| 122 | + if (dev->bin_file_mode) { |
| 123 | + dev->mt76.eeprom.size = mt7915_eeprom_size(dev); |
| 124 | + dev->mt76.eeprom.data = devm_kzalloc(dev->mt76.dev, dev->mt76.eeprom.size, |
| 125 | + GFP_KERNEL); |
| 126 | + if (!dev->mt76.eeprom.data) |
| 127 | + return -ENOMEM; |
| 128 | + ret = mt7915_eeprom_load_default(dev); |
| 129 | + if (ret) |
| 130 | + return ret; |
| 131 | + |
| 132 | + ret = mt7915_check_eeprom(dev); |
| 133 | + if (ret) |
| 134 | + return ret; |
| 135 | + dev->eeprom_mode = BIN_FILE_MODE; |
| 136 | + } else { |
| 137 | + ret = mt7915_eeprom_load(dev); |
| 138 | + } |
| 139 | + |
| 140 | if (ret < 0) { |
| 141 | if (ret != -EINVAL) |
| 142 | return ret; |
| 143 | |
| 144 | dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n"); |
| 145 | + dev->bin_file_mode = false; |
| 146 | + dev->eeprom_mode = DEFAULT_BIN_MODE; |
| 147 | + |
| 148 | ret = mt7915_eeprom_load_default(dev); |
| 149 | if (ret) |
| 150 | return ret; |
| 151 | diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h |
developer | 8e5fecd | 2023-05-30 11:58:00 +0800 | [diff] [blame^] | 152 | index fdae347e..9056d786 100644 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 153 | --- a/mt7915/eeprom.h |
| 154 | +++ b/mt7915/eeprom.h |
| 155 | @@ -108,6 +108,13 @@ enum mt7915_sku_rate_group { |
| 156 | MAX_SKU_RATE_GROUP_NUM, |
| 157 | }; |
| 158 | |
| 159 | +enum mt7915_eeprom_mode { |
| 160 | + DEFAULT_BIN_MODE, |
| 161 | + EFUSE_MODE, |
| 162 | + FLASH_MODE, |
| 163 | + BIN_FILE_MODE, |
| 164 | +}; |
| 165 | + |
| 166 | static inline int |
| 167 | mt7915_get_channel_group_5g(int channel, bool is_7976) |
| 168 | { |
| 169 | diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
developer | 8e5fecd | 2023-05-30 11:58:00 +0800 | [diff] [blame^] | 170 | index b22990a5..f2ee80e9 100644 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 171 | --- a/mt7915/mt7915.h |
| 172 | +++ b/mt7915/mt7915.h |
developer | ad9333b | 2023-05-22 15:16:16 +0800 | [diff] [blame] | 173 | @@ -400,6 +400,8 @@ struct mt7915_dev { |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 174 | |
| 175 | bool dbdc_support; |
| 176 | bool flash_mode; |
| 177 | + bool bin_file_mode; |
| 178 | + u8 eeprom_mode; |
| 179 | bool muru_debug; |
| 180 | bool ibf; |
| 181 | |
developer | ad9333b | 2023-05-22 15:16:16 +0800 | [diff] [blame] | 182 | @@ -775,6 +777,7 @@ void mt7915_dump_tmac_info(u8 *tmac_info); |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 183 | int mt7915_mcu_set_txpower_level(struct mt7915_phy *phy, u8 drop_level); |
| 184 | void mt7915_packet_log_to_host(struct mt7915_dev *dev, const void *data, int len, int type, int des_len); |
| 185 | int mt7915_mcu_set_amsdu_algo(struct mt7915_dev *dev, u16 wcid, u8 enable); |
| 186 | +const char *mt7915_eeprom_name(struct mt7915_dev *dev); |
| 187 | |
| 188 | #define PKT_BIN_DEBUG_MAGIC 0xc8763123 |
| 189 | enum { |
| 190 | diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c |
developer | 8e5fecd | 2023-05-30 11:58:00 +0800 | [diff] [blame^] | 191 | index be279f7b..809dff3f 100644 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 192 | --- a/mt7915/mtk_debugfs.c |
| 193 | +++ b/mt7915/mtk_debugfs.c |
| 194 | @@ -3,6 +3,7 @@ |
| 195 | #include "mt7915_debug.h" |
| 196 | #include "mac.h" |
| 197 | #include "mcu.h" |
| 198 | +#include "eeprom.h" |
| 199 | |
| 200 | #ifdef MTK_DEBUG |
| 201 | #define LWTBL_IDX2BASE_ID GENMASK(14, 8) |
developer | 3a38877 | 2023-04-19 10:12:02 +0800 | [diff] [blame] | 202 | @@ -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] | 203 | return 0; |
| 204 | } |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 205 | |
| 206 | +static int mt7915_show_eeprom_mode(struct seq_file *s, void *data) |
| 207 | +{ |
| 208 | + struct mt7915_dev *dev = dev_get_drvdata(s->private); |
| 209 | + struct mt76_dev *mdev = &dev->mt76; |
developer | 3a38877 | 2023-04-19 10:12:02 +0800 | [diff] [blame] | 210 | + u8 free_block_num = 0; |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 211 | +#ifdef CONFIG_NL80211_TESTMODE |
| 212 | + const char *mtd_name = mdev->test_mtd.name; |
| 213 | + u32 mtd_offset = mdev->test_mtd.offset; |
| 214 | +#else |
| 215 | + const char *mtd_name = NULL; |
| 216 | + u32 mtd_offset; |
| 217 | +#endif |
| 218 | + |
| 219 | + seq_printf(s, "Current eeprom mode:\n"); |
| 220 | + |
| 221 | + switch (dev->eeprom_mode) { |
| 222 | + case DEFAULT_BIN_MODE: |
| 223 | + seq_printf(s, " default bin mode\n filename = %s\n", mt7915_eeprom_name(dev)); |
| 224 | + break; |
| 225 | + case EFUSE_MODE: |
| 226 | + seq_printf(s, " efuse mode\n"); |
developer | 3a38877 | 2023-04-19 10:12:02 +0800 | [diff] [blame] | 227 | + mt7915_mcu_get_eeprom_free_block(dev, &free_block_num); |
| 228 | + seq_printf(s, " free block number = %d\n", free_block_num); |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 229 | + break; |
| 230 | + case FLASH_MODE: |
| 231 | + if (mtd_name) |
| 232 | + seq_printf(s, " flash mode\n mtd name = %s\n flash offset = 0x%x\n", |
| 233 | + mtd_name, mtd_offset); |
| 234 | + else |
| 235 | + seq_printf(s, " flash mode\n"); |
| 236 | + break; |
| 237 | + case BIN_FILE_MODE: |
| 238 | + seq_printf(s, " bin file mode\n filename = %s\n", mt7915_eeprom_name(dev)); |
| 239 | + break; |
| 240 | + default: |
| 241 | + break; |
| 242 | + } |
| 243 | + |
| 244 | + return 0; |
| 245 | +} |
| 246 | + |
| 247 | int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir) |
| 248 | { |
| 249 | struct mt7915_dev *dev = phy->dev; |
developer | 8e5fecd | 2023-05-30 11:58:00 +0800 | [diff] [blame^] | 250 | @@ -3688,6 +3730,8 @@ int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir) |
| 251 | |
| 252 | debugfs_create_u8("sku_disable", 0600, dir, &dev->dbg.sku_disable); |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 253 | |
| 254 | + debugfs_create_devm_seqfile(dev->mt76.dev, "eeprom_mode", dir, |
| 255 | + mt7915_show_eeprom_mode); |
| 256 | return 0; |
| 257 | } |
| 258 | #endif |
| 259 | -- |
developer | a43cc48 | 2023-04-17 15:57:28 +0800 | [diff] [blame] | 260 | 2.18.0 |
developer | 2aa1e64 | 2022-12-19 11:33:22 +0800 | [diff] [blame] | 261 | |