Add firmware-name property in order to introduce the capability to specify the firmware names used for 'RiscV core' and 'Data section' binaries. This patch is needed because NPU firmware binaries are board specific since they depend on the MediaTek WiFi chip used on the board (e.g. MT7996 or MT7992) and the WiFi chip version info is not available in the NPU driver. This is a preliminary patch to enable MT76 NPU offloading if the Airoha SoC is equipped with MT7996 (Eagle) WiFi chipset. Signed-off-by: Lorenzo Bianconi --- Documentation/devicetree/bindings/net/airoha,en7581-npu.yaml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Documentation/devicetree/bindings/net/airoha,en7581-npu.yaml b/Documentation/devicetree/bindings/net/airoha,en7581-npu.yaml index 19860b41286fd42f2a5ed15d5dc75ee0eb00a639..aefa19c5b42468dad841892fa5b75a47552762a0 100644 --- a/Documentation/devicetree/bindings/net/airoha,en7581-npu.yaml +++ b/Documentation/devicetree/bindings/net/airoha,en7581-npu.yaml @@ -59,6 +59,11 @@ properties: - const: ba minItems: 1 + firmware-name: + items: + - description: Firmware name of RiscV core + - description: Firmware name of Data section + required: - compatible - reg @@ -96,5 +101,7 @@ examples: memory-region = <&npu_firmware>, <&npu_pkt>, <&npu_txpkt>, <&npu_txbufid>, <&npu_ba>; memory-region-names = "firmware", "pkt", "tx-pkt", "tx-bufid", "ba"; + firmware-name = "airoha/en7581_npu_rv32.bin", + "airoha/en7581_npu_data.bin"; }; }; -- 2.52.0 Introduce the capability to read the firmware binary names from device-tree using the firmware-name property if available. This patch is needed because NPU firmware binaries are board specific since they depend on the MediaTek WiFi chip used on the board (e.g. MT7996 or MT7992) and the WiFi chip version info is not available in the NPU driver. This is a preliminary patch to enable MT76 NPU offloading if the Airoha SoC is equipped with MT7996 (Eagle) WiFi chipset. Signed-off-by: Lorenzo Bianconi --- drivers/net/ethernet/airoha/airoha_npu.c | 42 +++++++++++++++++++++++++++----- 1 file changed, 36 insertions(+), 6 deletions(-) diff --git a/drivers/net/ethernet/airoha/airoha_npu.c b/drivers/net/ethernet/airoha/airoha_npu.c index a56b3780bb627cc393b94210b6b5c72cc95baea3..d684e5cc8af2fbde3e274c6fa22c4336474092b5 100644 --- a/drivers/net/ethernet/airoha/airoha_npu.c +++ b/drivers/net/ethernet/airoha/airoha_npu.c @@ -195,18 +195,18 @@ static int airoha_npu_send_msg(struct airoha_npu *npu, int func_id, } static int airoha_npu_load_firmware(struct device *dev, void __iomem *addr, - const struct airoha_npu_fw *fw_info) + const char *fw_name, int fw_max_size) { const struct firmware *fw; int ret; - ret = request_firmware(&fw, fw_info->name, dev); + ret = request_firmware(&fw, fw_name, dev); if (ret) return ret == -ENOENT ? -EPROBE_DEFER : ret; - if (fw->size > fw_info->max_size) { + if (fw->size > fw_max_size) { dev_err(dev, "%s: fw size too overlimit (%zu)\n", - fw_info->name, fw->size); + fw_name, fw->size); ret = -E2BIG; goto out; } @@ -218,6 +218,28 @@ static int airoha_npu_load_firmware(struct device *dev, void __iomem *addr, return ret; } +static int +airoha_npu_load_firmware_from_dts(struct device *dev, void __iomem *addr, + void __iomem *base) +{ + const char *fw_names[2]; + int ret; + + ret = of_property_read_string_array(dev->of_node, "firmware-name", + fw_names, ARRAY_SIZE(fw_names)); + if (ret != ARRAY_SIZE(fw_names)) + return -EINVAL; + + ret = airoha_npu_load_firmware(dev, addr, fw_names[0], + NPU_EN7581_FIRMWARE_RV32_MAX_SIZE); + if (ret) + return ret; + + return airoha_npu_load_firmware(dev, base + REG_NPU_LOCAL_SRAM, + fw_names[1], + NPU_EN7581_FIRMWARE_DATA_MAX_SIZE); +} + static int airoha_npu_run_firmware(struct device *dev, void __iomem *base, struct resource *res) { @@ -233,14 +255,22 @@ static int airoha_npu_run_firmware(struct device *dev, void __iomem *base, if (IS_ERR(addr)) return PTR_ERR(addr); + /* Try to load firmware images using the firmware names provided via + * dts if available. + */ + if (of_find_property(dev->of_node, "firmware-name", NULL)) + return airoha_npu_load_firmware_from_dts(dev, addr, base); + /* Load rv32 npu firmware */ - ret = airoha_npu_load_firmware(dev, addr, &soc->fw_rv32); + ret = airoha_npu_load_firmware(dev, addr, soc->fw_rv32.name, + soc->fw_rv32.max_size); if (ret) return ret; /* Load data npu firmware */ return airoha_npu_load_firmware(dev, base + REG_NPU_LOCAL_SRAM, - &soc->fw_data); + soc->fw_data.name, + soc->fw_data.max_size); } static irqreturn_t airoha_npu_mbox_handler(int irq, void *npu_instance) -- 2.52.0