developer | 064da3c | 2023-06-13 15:57:26 +0800 | [diff] [blame] | 1 | From 2cf8a9517919b39318eb1e878ca69418a499126a Mon Sep 17 00:00:00 2001 |
| 2 | From: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 3 | Date: Fri, 31 Mar 2023 11:36:34 +0800 |
| 4 | Subject: [PATCH 1007/1015] wifi: mt76: mt7996: add binfile mode support |
| 5 | |
| 6 | Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| 7 | --- |
| 8 | eeprom.c | 20 ++++++++++++++++++++ |
| 9 | mt76.h | 3 +++ |
| 10 | mt7996/eeprom.c | 42 +++++++++++++++++++++++++++++++++++++++--- |
| 11 | mt7996/eeprom.h | 7 +++++++ |
| 12 | mt7996/mt7996.h | 3 +++ |
| 13 | mt7996/mtk_debugfs.c | 40 ++++++++++++++++++++++++++++++++++++++++ |
| 14 | 6 files changed, 112 insertions(+), 3 deletions(-) |
| 15 | |
| 16 | diff --git a/eeprom.c b/eeprom.c |
| 17 | index aa889258..412740f0 100644 |
| 18 | --- a/eeprom.c |
| 19 | +++ b/eeprom.c |
| 20 | @@ -104,6 +104,26 @@ out_put_node: |
| 21 | } |
| 22 | EXPORT_SYMBOL_GPL(mt76_get_of_eeprom); |
| 23 | |
| 24 | +bool mt76_check_bin_file_mode(struct mt76_dev *dev) |
| 25 | +{ |
| 26 | + struct device_node *np = dev->dev->of_node; |
| 27 | + const char *bin_file_name = NULL; |
| 28 | + |
| 29 | + if (!np) |
| 30 | + return false; |
| 31 | + |
| 32 | + of_property_read_string(np, "bin_file_name", &bin_file_name); |
| 33 | + |
| 34 | + dev->bin_file_name = bin_file_name; |
| 35 | + if (dev->bin_file_name) |
| 36 | + dev_info(dev->dev, "Using bin file %s\n", dev->bin_file_name); |
| 37 | + |
| 38 | + of_node_put(np); |
| 39 | + |
| 40 | + return dev->bin_file_name ? true : false; |
| 41 | +} |
| 42 | +EXPORT_SYMBOL_GPL(mt76_check_bin_file_mode); |
| 43 | + |
| 44 | void |
| 45 | mt76_eeprom_override(struct mt76_phy *phy) |
| 46 | { |
| 47 | diff --git a/mt76.h b/mt76.h |
| 48 | index 3341720c..7d6e3241 100644 |
| 49 | --- a/mt76.h |
| 50 | +++ b/mt76.h |
| 51 | @@ -894,6 +894,8 @@ struct mt76_dev { |
| 52 | struct mt76_usb usb; |
| 53 | struct mt76_sdio sdio; |
| 54 | }; |
| 55 | + |
| 56 | + const char *bin_file_name; |
| 57 | }; |
| 58 | |
| 59 | struct mt76_power_limits { |
| 60 | @@ -1030,6 +1032,7 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str, |
| 61 | int mt76_eeprom_init(struct mt76_dev *dev, int len); |
| 62 | void mt76_eeprom_override(struct mt76_phy *phy); |
| 63 | int mt76_get_of_eeprom(struct mt76_dev *dev, void *data, int offset, int len); |
| 64 | +bool mt76_check_bin_file_mode(struct mt76_dev *dev); |
| 65 | |
| 66 | struct mt76_queue * |
| 67 | mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc, |
| 68 | diff --git a/mt7996/eeprom.c b/mt7996/eeprom.c |
| 69 | index 60e98463..85d9e057 100644 |
| 70 | --- a/mt7996/eeprom.c |
| 71 | +++ b/mt7996/eeprom.c |
| 72 | @@ -61,8 +61,11 @@ static int mt7996_check_eeprom(struct mt7996_dev *dev) |
| 73 | } |
| 74 | } |
| 75 | |
| 76 | -static char *mt7996_eeprom_name(struct mt7996_dev *dev) |
| 77 | +const char *mt7996_eeprom_name(struct mt7996_dev *dev) |
| 78 | { |
| 79 | + if (dev->bin_file_mode) |
| 80 | + return dev->mt76.bin_file_name; |
| 81 | + |
| 82 | /* reserve for future variants */ |
| 83 | if (dev->testmode_enable) |
| 84 | return MT7996_EEPROM_DEFAULT_TM; |
| 85 | @@ -112,7 +115,10 @@ mt7996_eeprom_load_default(struct mt7996_dev *dev) |
| 86 | return ret; |
| 87 | |
| 88 | if (!fw || !fw->data) { |
| 89 | - dev_err(dev->mt76.dev, "Invalid default bin\n"); |
| 90 | + if (dev->bin_file_mode) |
| 91 | + dev_err(dev->mt76.dev, "Invalid bin (bin file mode)\n"); |
| 92 | + else |
| 93 | + dev_err(dev->mt76.dev, "Invalid default bin\n"); |
| 94 | ret = -EINVAL; |
| 95 | goto out; |
| 96 | } |
| 97 | @@ -126,18 +132,45 @@ out: |
| 98 | return ret; |
| 99 | } |
| 100 | |
| 101 | +static int mt7996_eeprom_load_flash(struct mt7996_dev *dev) |
| 102 | +{ |
| 103 | + int ret = 1; |
| 104 | + |
| 105 | + /* return > 0 for load success, return 0 for load failed, return < 0 for non memory */ |
| 106 | + dev->bin_file_mode = mt76_check_bin_file_mode(&dev->mt76); |
| 107 | + if (dev->bin_file_mode) { |
| 108 | + dev->mt76.eeprom.size = MT7996_EEPROM_SIZE; |
| 109 | + dev->mt76.eeprom.data = devm_kzalloc(dev->mt76.dev, dev->mt76.eeprom.size, |
| 110 | + GFP_KERNEL); |
| 111 | + if (!dev->mt76.eeprom.data) |
| 112 | + return -ENOMEM; |
| 113 | + |
| 114 | + if (mt7996_eeprom_load_default(dev)) |
| 115 | + return 0; |
| 116 | + |
| 117 | + if (mt7996_check_eeprom(dev)) |
| 118 | + return 0; |
| 119 | + } else { |
| 120 | + ret = mt76_eeprom_init(&dev->mt76, MT7996_EEPROM_SIZE); |
| 121 | + } |
| 122 | + |
| 123 | + return ret; |
| 124 | +} |
| 125 | + |
| 126 | int mt7996_eeprom_check_fw_mode(struct mt7996_dev *dev) |
| 127 | { |
| 128 | u8 *eeprom; |
| 129 | int ret; |
| 130 | |
| 131 | /* load eeprom in flash or bin file mode to determine fw mode */ |
| 132 | - ret = mt76_eeprom_init(&dev->mt76, MT7996_EEPROM_SIZE); |
| 133 | + ret = mt7996_eeprom_load_flash(dev); |
| 134 | + |
| 135 | if (ret < 0) |
| 136 | return ret; |
| 137 | |
| 138 | if (ret) { |
| 139 | dev->flash_mode = true; |
| 140 | + dev->eeprom_mode = dev->bin_file_mode ? BIN_FILE_MODE : FLASH_MODE; |
| 141 | eeprom = dev->mt76.eeprom.data; |
| 142 | /* testmode enable priority: eeprom field > module parameter */ |
| 143 | dev->testmode_enable = !mt7996_check_eeprom(dev) ? eeprom[MT_EE_TESTMODE_EN] : |
| 144 | @@ -171,6 +204,7 @@ static int mt7996_eeprom_load(struct mt7996_dev *dev) |
| 145 | if (ret < 0) |
| 146 | return ret; |
| 147 | } |
| 148 | + dev->eeprom_mode = EFUSE_MODE; |
| 149 | } |
| 150 | |
| 151 | return mt7996_check_eeprom(dev); |
| 152 | @@ -306,6 +340,8 @@ int mt7996_eeprom_init(struct mt7996_dev *dev) |
| 153 | return ret; |
| 154 | |
| 155 | dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n"); |
| 156 | + dev->bin_file_mode = false; |
| 157 | + dev->eeprom_mode = DEFAULT_BIN_MODE; |
| 158 | ret = mt7996_eeprom_load_default(dev); |
| 159 | if (ret) |
| 160 | return ret; |
| 161 | diff --git a/mt7996/eeprom.h b/mt7996/eeprom.h |
| 162 | index 7ff290f4..20dd8771 100644 |
| 163 | --- a/mt7996/eeprom.h |
| 164 | +++ b/mt7996/eeprom.h |
| 165 | @@ -99,6 +99,13 @@ enum mt7996_eeprom_band { |
| 166 | MT_EE_BAND_SEL_6GHZ, |
| 167 | }; |
| 168 | |
| 169 | +enum mt7915_eeprom_mode { |
| 170 | + DEFAULT_BIN_MODE, |
| 171 | + EFUSE_MODE, |
| 172 | + FLASH_MODE, |
| 173 | + BIN_FILE_MODE, |
| 174 | +}; |
| 175 | + |
| 176 | static inline int |
| 177 | mt7996_get_channel_group_5g(int channel) |
| 178 | { |
| 179 | diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h |
| 180 | index 9ab86eaf..6ef6bad9 100644 |
| 181 | --- a/mt7996/mt7996.h |
| 182 | +++ b/mt7996/mt7996.h |
| 183 | @@ -380,6 +380,8 @@ struct mt7996_dev { |
| 184 | bool has_eht:1; |
| 185 | |
| 186 | bool testmode_enable; |
| 187 | + bool bin_file_mode; |
| 188 | + u8 eeprom_mode; |
| 189 | |
| 190 | bool ibf; |
| 191 | u8 fw_debug_wm; |
| 192 | @@ -519,6 +521,7 @@ irqreturn_t mt7996_irq_handler(int irq, void *dev_instance); |
| 193 | u64 __mt7996_get_tsf(struct ieee80211_hw *hw, struct mt7996_vif *mvif); |
| 194 | int mt7996_register_device(struct mt7996_dev *dev); |
| 195 | void mt7996_unregister_device(struct mt7996_dev *dev); |
| 196 | +const char *mt7996_eeprom_name(struct mt7996_dev *dev); |
| 197 | int mt7996_eeprom_init(struct mt7996_dev *dev); |
| 198 | int mt7996_eeprom_check_fw_mode(struct mt7996_dev *dev); |
| 199 | int mt7996_eeprom_parse_hw_cap(struct mt7996_dev *dev, struct mt7996_phy *phy); |
| 200 | diff --git a/mt7996/mtk_debugfs.c b/mt7996/mtk_debugfs.c |
| 201 | index 2aee3ab0..2ab2a8a8 100644 |
| 202 | --- a/mt7996/mtk_debugfs.c |
| 203 | +++ b/mt7996/mtk_debugfs.c |
| 204 | @@ -2525,6 +2525,44 @@ static const struct file_operations mt7996_txpower_sku_fops = { |
| 205 | .llseek = default_llseek, |
| 206 | }; |
| 207 | |
| 208 | +static int mt7996_show_eeprom_mode(struct seq_file *s, void *data) |
| 209 | +{ |
| 210 | + struct mt7996_dev *dev = dev_get_drvdata(s->private); |
| 211 | + struct mt76_dev *mdev = &dev->mt76; |
| 212 | +#ifdef CONFIG_NL80211_TESTMODE |
| 213 | + const char *mtd_name = mdev->test_mtd.name; |
| 214 | + u32 mtd_offset = mdev->test_mtd.offset; |
| 215 | +#else |
| 216 | + const char *mtd_name = NULL; |
| 217 | + u32 mtd_offset; |
| 218 | +#endif |
| 219 | + |
| 220 | + seq_printf(s, "Current eeprom mode:\n"); |
| 221 | + |
| 222 | + switch (dev->eeprom_mode) { |
| 223 | + case DEFAULT_BIN_MODE: |
| 224 | + seq_printf(s, " default bin mode\n filename = %s\n", mt7996_eeprom_name(dev)); |
| 225 | + break; |
| 226 | + case EFUSE_MODE: |
| 227 | + seq_printf(s, " efuse mode\n"); |
| 228 | + break; |
| 229 | + case FLASH_MODE: |
| 230 | + if (mtd_name) |
| 231 | + seq_printf(s, " flash mode\n mtd name = %s\n flash offset = 0x%x\n", |
| 232 | + mtd_name, mtd_offset); |
| 233 | + else |
| 234 | + seq_printf(s, " flash mode\n"); |
| 235 | + break; |
| 236 | + case BIN_FILE_MODE: |
| 237 | + seq_printf(s, " bin file mode\n filename = %s\n", mt7996_eeprom_name(dev)); |
| 238 | + break; |
| 239 | + default: |
| 240 | + break; |
| 241 | + } |
| 242 | + |
| 243 | + return 0; |
| 244 | +} |
| 245 | + |
| 246 | int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir) |
| 247 | { |
| 248 | struct mt7996_dev *dev = phy->dev; |
| 249 | @@ -2570,6 +2608,8 @@ int mt7996_mtk_init_debugfs(struct mt7996_phy *phy, struct dentry *dir) |
| 250 | debugfs_create_file("txpower_level", 0600, dir, phy, &fops_txpower_level); |
| 251 | debugfs_create_file("txpower_info", 0600, dir, phy, &mt7996_txpower_info_fops); |
| 252 | debugfs_create_file("txpower_sku", 0600, dir, phy, &mt7996_txpower_sku_fops); |
| 253 | + debugfs_create_devm_seqfile(dev->mt76.dev, "eeprom_mode", dir, |
| 254 | + mt7996_show_eeprom_mode); |
| 255 | |
| 256 | debugfs_create_devm_seqfile(dev->mt76.dev, "wtbl_info", dir, |
| 257 | mt7996_wtbl_read); |
| 258 | -- |
| 259 | 2.39.2 |
| 260 | |