| From b33cf2d53b4719f00d96ba1b5280b7df593870cf Mon Sep 17 00:00:00 2001 |
| From: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| Date: Thu, 7 Jul 2022 11:09:59 +0800 |
| Subject: [PATCH] wifi: mt76: mt7915: implement bin file mode |
| |
| Signed-off-by: StanleyYP Wang <StanleyYP.Wang@mediatek.com> |
| Signed-off-by: Shayne Chen <shayne.chen@mediatek.com> |
| --- |
| eeprom.c | 25 +++++++++++++++++ |
| mt76.h | 4 +++ |
| mt7915/eeprom.c | 65 +++++++++++++++++++++++++++++++++++++++++--- |
| mt7915/eeprom.h | 7 +++++ |
| mt7915/mt7915.h | 3 ++ |
| mt7915/mtk_debugfs.c | 44 ++++++++++++++++++++++++++++++ |
| testmode.h | 2 +- |
| 7 files changed, 145 insertions(+), 5 deletions(-) |
| |
| diff --git a/eeprom.c b/eeprom.c |
| index 9b63799..d5b8c56 100644 |
| --- a/eeprom.c |
| +++ b/eeprom.c |
| @@ -159,6 +159,31 @@ int mt76_get_of_eeprom(struct mt76_dev *dev, void *eep, int offset, int len) |
| } |
| EXPORT_SYMBOL_GPL(mt76_get_of_eeprom); |
| |
| +bool mt76_check_bin_file_mode(struct mt76_dev *dev) |
| +{ |
| + struct device_node *np = dev->dev->of_node; |
| + const char *bin_file_name = NULL; |
| + |
| + if (!np) |
| + return false; |
| + |
| + of_property_read_string(np, "bin_file_name", &bin_file_name); |
| + |
| + dev->bin_file_name = bin_file_name; |
| + if (dev->bin_file_name) { |
| + dev_info(dev->dev, "Using bin file %s\n", dev->bin_file_name); |
| +#ifdef CONFIG_NL80211_TESTMODE |
| + dev->test_mtd.name = devm_kstrdup(dev->dev, bin_file_name, GFP_KERNEL); |
| + dev->test_mtd.offset = -1; |
| +#endif |
| + } |
| + |
| + of_node_put(np); |
| + |
| + return dev->bin_file_name ? true : false; |
| +} |
| +EXPORT_SYMBOL_GPL(mt76_check_bin_file_mode); |
| + |
| void |
| mt76_eeprom_override(struct mt76_phy *phy) |
| { |
| diff --git a/mt76.h b/mt76.h |
| index d16accd..9673926 100644 |
| --- a/mt76.h |
| +++ b/mt76.h |
| @@ -943,6 +943,9 @@ struct mt76_dev { |
| struct mt76_usb usb; |
| struct mt76_sdio sdio; |
| }; |
| + |
| + /* for mtk internal */ |
| + const char *bin_file_name; |
| }; |
| |
| /* per-phy stats. */ |
| @@ -1175,6 +1178,7 @@ void mt76_seq_puts_array(struct seq_file *file, const char *str, |
| int mt76_eeprom_init(struct mt76_dev *dev, int len); |
| void mt76_eeprom_override(struct mt76_phy *phy); |
| int mt76_get_of_eeprom(struct mt76_dev *dev, void *data, int offset, int len); |
| +bool mt76_check_bin_file_mode(struct mt76_dev *dev); |
| |
| struct mt76_queue * |
| mt76_init_queue(struct mt76_dev *dev, int qid, int idx, int n_desc, |
| diff --git a/mt7915/eeprom.c b/mt7915/eeprom.c |
| index a5c99a5..5eb9f88 100644 |
| --- a/mt7915/eeprom.c |
| +++ b/mt7915/eeprom.c |
| @@ -5,6 +5,30 @@ |
| #include "mt7915.h" |
| #include "eeprom.h" |
| |
| +static int |
| +mt7915_eeprom_load_precal_binfile(struct mt7915_dev *dev, u32 offs, u32 size) |
| +{ |
| + const struct firmware *fw = NULL; |
| + int ret; |
| + |
| + ret = request_firmware(&fw, dev->mt76.bin_file_name, dev->mt76.dev); |
| + if (ret) |
| + return ret; |
| + |
| + if (!fw || !fw->data) { |
| + dev_err(dev->mt76.dev, "Invalid bin (bin file mode), load precal fail\n"); |
| + ret = -EINVAL; |
| + goto out; |
| + } |
| + |
| + memcpy(dev->cal, fw->data + offs, size); |
| + |
| +out: |
| + release_firmware(fw); |
| + |
| + return ret; |
| +} |
| + |
| static int mt7915_eeprom_load_precal(struct mt7915_dev *dev) |
| { |
| struct mt76_dev *mdev = &dev->mt76; |
| @@ -24,7 +48,10 @@ static int mt7915_eeprom_load_precal(struct mt7915_dev *dev) |
| |
| offs = is_mt7915(&dev->mt76) ? MT_EE_PRECAL : MT_EE_PRECAL_V2; |
| |
| - return mt76_get_of_eeprom(mdev, dev->cal, offs, size); |
| + if (!dev->bin_file_mode) |
| + return mt76_get_of_eeprom(mdev, dev->cal, offs, size); |
| + else |
| + return mt7915_eeprom_load_precal_binfile(dev, offs, size); |
| } |
| |
| static int mt7915_check_eeprom(struct mt7915_dev *dev) |
| @@ -47,8 +74,11 @@ static int mt7915_check_eeprom(struct mt7915_dev *dev) |
| } |
| } |
| |
| -static char *mt7915_eeprom_name(struct mt7915_dev *dev) |
| +const char *mt7915_eeprom_name(struct mt7915_dev *dev) |
| { |
| + if (dev->bin_file_mode) |
| + return dev->mt76.bin_file_name; |
| + |
| switch (mt76_chip(&dev->mt76)) { |
| case 0x7915: |
| return dev->dbdc_support ? |
| @@ -89,7 +119,10 @@ mt7915_eeprom_load_default(struct mt7915_dev *dev) |
| return ret; |
| |
| if (!fw || !fw->data) { |
| - dev_err(dev->mt76.dev, "Invalid default bin\n"); |
| + if (dev->bin_file_mode) |
| + dev_err(dev->mt76.dev, "Invalid bin (bin file mode)\n"); |
| + else |
| + dev_err(dev->mt76.dev, "Invalid default bin\n"); |
| ret = -EINVAL; |
| goto out; |
| } |
| @@ -114,6 +147,7 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev) |
| |
| if (ret) { |
| dev->flash_mode = true; |
| + dev->eeprom_mode = FLASH_MODE; |
| } else { |
| u8 free_block_num; |
| u32 block_num, i; |
| @@ -134,6 +168,8 @@ static int mt7915_eeprom_load(struct mt7915_dev *dev) |
| if (ret < 0) |
| return ret; |
| } |
| + |
| + dev->eeprom_mode = EFUSE_MODE; |
| } |
| |
| return mt7915_check_eeprom(dev); |
| @@ -239,12 +275,33 @@ int mt7915_eeprom_init(struct mt7915_dev *dev) |
| { |
| int ret; |
| |
| - ret = mt7915_eeprom_load(dev); |
| + dev->bin_file_mode = mt76_check_bin_file_mode(&dev->mt76); |
| + if (dev->bin_file_mode) { |
| + dev->mt76.eeprom.size = mt7915_eeprom_size(dev); |
| + dev->mt76.eeprom.data = devm_kzalloc(dev->mt76.dev, dev->mt76.eeprom.size, |
| + GFP_KERNEL); |
| + if (!dev->mt76.eeprom.data) |
| + return -ENOMEM; |
| + ret = mt7915_eeprom_load_default(dev); |
| + if (ret) |
| + return ret; |
| + |
| + ret = mt7915_check_eeprom(dev); |
| + if (ret) |
| + return ret; |
| + dev->eeprom_mode = BIN_FILE_MODE; |
| + } else { |
| + ret = mt7915_eeprom_load(dev); |
| + } |
| + |
| if (ret < 0) { |
| if (ret != -EINVAL) |
| return ret; |
| |
| dev_warn(dev->mt76.dev, "eeprom load fail, use default bin\n"); |
| + dev->bin_file_mode = false; |
| + dev->eeprom_mode = DEFAULT_BIN_MODE; |
| + |
| ret = mt7915_eeprom_load_default(dev); |
| if (ret) |
| return ret; |
| diff --git a/mt7915/eeprom.h b/mt7915/eeprom.h |
| index fdae347..9056d78 100644 |
| --- a/mt7915/eeprom.h |
| +++ b/mt7915/eeprom.h |
| @@ -108,6 +108,13 @@ enum mt7915_sku_rate_group { |
| MAX_SKU_RATE_GROUP_NUM, |
| }; |
| |
| +enum mt7915_eeprom_mode { |
| + DEFAULT_BIN_MODE, |
| + EFUSE_MODE, |
| + FLASH_MODE, |
| + BIN_FILE_MODE, |
| +}; |
| + |
| static inline int |
| mt7915_get_channel_group_5g(int channel, bool is_7976) |
| { |
| diff --git a/mt7915/mt7915.h b/mt7915/mt7915.h |
| index 795af63..992323d 100644 |
| --- a/mt7915/mt7915.h |
| +++ b/mt7915/mt7915.h |
| @@ -351,6 +351,8 @@ struct mt7915_dev { |
| |
| bool dbdc_support; |
| bool flash_mode; |
| + bool bin_file_mode; |
| + u8 eeprom_mode; |
| bool muru_debug; |
| bool ibf; |
| |
| @@ -727,6 +729,7 @@ void mt7915_dump_tmac_info(u8 *tmac_info); |
| int mt7915_mcu_set_txpower_level(struct mt7915_phy *phy, u8 drop_level); |
| void mt7915_packet_log_to_host(struct mt7915_dev *dev, const void *data, int len, int type, int des_len); |
| int mt7915_mcu_set_amsdu_algo(struct mt7915_dev *dev, u16 wcid, u8 enable); |
| +const char *mt7915_eeprom_name(struct mt7915_dev *dev); |
| |
| #define PKT_BIN_DEBUG_MAGIC 0xc8763123 |
| enum { |
| diff --git a/mt7915/mtk_debugfs.c b/mt7915/mtk_debugfs.c |
| index 7105cf0..5c676d8 100644 |
| --- a/mt7915/mtk_debugfs.c |
| +++ b/mt7915/mtk_debugfs.c |
| @@ -3,6 +3,7 @@ |
| #include "mt7915_debug.h" |
| #include "mac.h" |
| #include "mcu.h" |
| +#include "eeprom.h" |
| |
| #ifdef MTK_DEBUG |
| #define LWTBL_IDX2BASE_ID GENMASK(14, 8) |
| @@ -3600,6 +3601,47 @@ static int mt7915_fw_wm_info_read(struct seq_file *s, void *data) |
| return 0; |
| } |
| |
| +static int mt7915_show_eeprom_mode(struct seq_file *s, void *data) |
| +{ |
| + struct mt7915_dev *dev = dev_get_drvdata(s->private); |
| + struct mt76_dev *mdev = &dev->mt76; |
| + u8 free_block_num = 0; |
| +#ifdef CONFIG_NL80211_TESTMODE |
| + const char *mtd_name = mdev->test_mtd.name; |
| + u32 mtd_offset = mdev->test_mtd.offset; |
| +#else |
| + const char *mtd_name = NULL; |
| + u32 mtd_offset; |
| +#endif |
| + |
| + seq_printf(s, "Current eeprom mode:\n"); |
| + |
| + switch (dev->eeprom_mode) { |
| + case DEFAULT_BIN_MODE: |
| + seq_printf(s, " default bin mode\n filename = %s\n", mt7915_eeprom_name(dev)); |
| + break; |
| + case EFUSE_MODE: |
| + seq_printf(s, " efuse mode\n"); |
| + mt7915_mcu_get_eeprom_free_block(dev, &free_block_num); |
| + seq_printf(s, " free block number = %d\n", free_block_num); |
| + break; |
| + case FLASH_MODE: |
| + if (mtd_name) |
| + seq_printf(s, " flash mode\n mtd name = %s\n flash offset = 0x%x\n", |
| + mtd_name, mtd_offset); |
| + else |
| + seq_printf(s, " flash mode\n"); |
| + break; |
| + case BIN_FILE_MODE: |
| + seq_printf(s, " bin file mode\n filename = %s\n", mt7915_eeprom_name(dev)); |
| + break; |
| + default: |
| + break; |
| + } |
| + |
| + return 0; |
| +} |
| + |
| int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir) |
| { |
| struct mt7915_dev *dev = phy->dev; |
| @@ -3686,6 +3728,8 @@ int mt7915_mtk_init_debugfs(struct mt7915_phy *phy, struct dentry *dir) |
| |
| debugfs_create_u8("sku_disable", 0600, dir, &dev->dbg.sku_disable); |
| |
| + debugfs_create_devm_seqfile(dev->mt76.dev, "eeprom_mode", dir, |
| + mt7915_show_eeprom_mode); |
| return 0; |
| } |
| #endif |
| diff --git a/testmode.h b/testmode.h |
| index 20fab3e..91d1e86 100644 |
| --- a/testmode.h |
| +++ b/testmode.h |
| @@ -17,7 +17,7 @@ |
| * @MT76_TM_ATTR_RESET: reset parameters to default (flag) |
| * @MT76_TM_ATTR_STATE: test state (u32), see &enum mt76_testmode_state |
| * |
| - * @MT76_TM_ATTR_MTD_PART: mtd partition used for eeprom data (string) |
| + * @MT76_TM_ATTR_MTD_PART: mtd partition or binfile used for eeprom data (string) |
| * @MT76_TM_ATTR_MTD_OFFSET: offset of eeprom data within the partition (u32) |
| * @MT76_TM_ATTR_BAND_IDX: band idx of the chip (u8) |
| * |
| -- |
| 2.18.0 |
| |