developer | efb40c1 | 2022-12-21 18:05:47 +0800 | [diff] [blame] | 1 | From 57fecb7bb0f51f52b23727811f4d2a0612435911 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 |
| 4 | Subject: [PATCH 1123/1131] mt76: mt7915: implement bin file mode |
| 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 ++++++--- |
| 14 | mt7915/mtk_debugfs.c | 41 +++++++++++++++++++++++++++++++++++++++++ |
| 15 | 6 files changed, 110 insertions(+), 6 deletions(-) |
| 16 | |
| 17 | diff --git a/eeprom.c b/eeprom.c |
| 18 | index cb6ff17..05b6dfa 100644 |
| 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 |
| 49 | index c6aefbf..9b6e806 100644 |
| 50 | --- a/mt76.h |
| 51 | +++ b/mt76.h |
| 52 | @@ -894,9 +894,11 @@ struct mt76_dev { |
| 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 { |
| 64 | @@ -1033,6 +1035,7 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str, |
| 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 |
| 73 | index 55ba90a..54803e8 100644 |
| 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 |
| 154 | index fdae347..9056d78 100644 |
| 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 |
| 172 | index 4c370bb..e5cfc77 100644 |
| 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" |
| 188 | @@ -400,6 +400,8 @@ struct mt7915_dev { |
| 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 | |
| 197 | @@ -774,6 +776,7 @@ void mt7915_dump_tmac_info(u8 *tmac_info); |
| 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 |
| 206 | index a2ceb6f..7567666 100644 |
| 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) |
| 217 | @@ -2924,6 +2925,44 @@ mt7915_wa_debug(void *data, u64 val) |
| 218 | DEFINE_DEBUGFS_ATTRIBUTE(fops_wa_debug, NULL, mt7915_wa_debug, |
| 219 | "0x%llx\n"); |
| 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; |
| 225 | +#ifdef CONFIG_NL80211_TESTMODE |
| 226 | + const char *mtd_name = mdev->test_mtd.name; |
| 227 | + u32 mtd_offset = mdev->test_mtd.offset; |
| 228 | +#else |
| 229 | + const char *mtd_name = NULL; |
| 230 | + u32 mtd_offset; |
| 231 | +#endif |
| 232 | + |
| 233 | + seq_printf(s, "Current eeprom mode:\n"); |
| 234 | + |
| 235 | + switch (dev->eeprom_mode) { |
| 236 | + case DEFAULT_BIN_MODE: |
| 237 | + seq_printf(s, " default bin mode\n filename = %s\n", mt7915_eeprom_name(dev)); |
| 238 | + break; |
| 239 | + case EFUSE_MODE: |
| 240 | + seq_printf(s, " efuse mode\n"); |
| 241 | + break; |
| 242 | + case FLASH_MODE: |
| 243 | + if (mtd_name) |
| 244 | + seq_printf(s, " flash mode\n mtd name = %s\n flash offset = 0x%x\n", |
| 245 | + mtd_name, mtd_offset); |
| 246 | + else |
| 247 | + seq_printf(s, " flash mode\n"); |
| 248 | + break; |
| 249 | + case BIN_FILE_MODE: |
| 250 | + seq_printf(s, " bin file mode\n filename = %s\n", mt7915_eeprom_name(dev)); |
| 251 | + break; |
| 252 | + default: |
| 253 | + break; |
| 254 | + } |
| 255 | + |
| 256 | + return 0; |
| 257 | +} |
| 258 | + |
| 259 | int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir) |
| 260 | { |
| 261 | struct mt7915_dev *dev = phy->dev; |
| 262 | @@ -3009,6 +3048,8 @@ int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir) |
| 263 | debugfs_create_devm_seqfile(dev->mt76.dev, "fw_version", dir, |
| 264 | mt7915_dump_version); |
| 265 | |
| 266 | + debugfs_create_devm_seqfile(dev->mt76.dev, "eeprom_mode", dir, |
| 267 | + mt7915_show_eeprom_mode); |
| 268 | return 0; |
| 269 | } |
| 270 | #endif |
| 271 | -- |
| 272 | 2.36.1 |
| 273 | |