1 From 52ea72ad0daa0f29535b4cef39257616c5a211d3 Mon Sep 17 00:00:00 2001
2 From: Lorenzo Bianconi <lorenzo@kernel.org>
3 Date: Tue, 24 Oct 2023 00:00:19 +0200
4 Subject: [PATCH 1/5] net: ethernet: mtk_wed: fix firmware loading for MT7986
7 The WED mcu firmware does not contain all the memory regions defined in
8 the dts reserved_memory node (e.g. MT7986 WED firmware does not contain
10 Reverse the mtk_wed_mcu_run_firmware() logic to check all the fw
11 sections are defined in the dts reserved_memory node.
13 Fixes: c6d961aeaa77 ("net: ethernet: mtk_wed: move mem_region array out of mtk_wed_mcu_load_firmware")
14 Tested-by: Frank Wunderlich <frank-w@public-files.de>
15 Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
16 Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
17 Link: https://lore.kernel.org/r/d983cbfe8ea562fef9264de8f0c501f7d5705bd5.1698098381.git.lorenzo@kernel.org
18 Signed-off-by: Jakub Kicinski <kuba@kernel.org>
20 drivers/net/ethernet/mediatek/mtk_wed_mcu.c | 48 +++++++++++----------
21 1 file changed, 25 insertions(+), 23 deletions(-)
23 --- a/drivers/net/ethernet/mediatek/mtk_wed_mcu.c
24 +++ b/drivers/net/ethernet/mediatek/mtk_wed_mcu.c
25 @@ -258,16 +258,12 @@ mtk_wed_get_memory_region(struct mtk_wed
29 -mtk_wed_mcu_run_firmware(struct mtk_wed_wo *wo, const struct firmware *fw,
30 - struct mtk_wed_wo_memory_region *region)
31 +mtk_wed_mcu_run_firmware(struct mtk_wed_wo *wo, const struct firmware *fw)
33 const u8 *first_region_ptr, *region_ptr, *trailer_ptr, *ptr = fw->data;
34 const struct mtk_wed_fw_trailer *trailer;
35 const struct mtk_wed_fw_region *fw_region;
37 - if (!region->phy_addr || !region->size)
40 trailer_ptr = fw->data + fw->size - sizeof(*trailer);
41 trailer = (const struct mtk_wed_fw_trailer *)trailer_ptr;
42 region_ptr = trailer_ptr - trailer->num_region * sizeof(*fw_region);
43 @@ -275,33 +271,41 @@ mtk_wed_mcu_run_firmware(struct mtk_wed_
45 while (region_ptr < trailer_ptr) {
49 fw_region = (const struct mtk_wed_fw_region *)region_ptr;
50 length = le32_to_cpu(fw_region->len);
52 - if (region->phy_addr != le32_to_cpu(fw_region->addr))
55 - if (region->size < length)
58 if (first_region_ptr < ptr + length)
61 - if (region->shared && region->consumed)
63 + for (i = 0; i < ARRAY_SIZE(mem_region); i++) {
64 + struct mtk_wed_wo_memory_region *region;
66 - if (!region->shared || !region->consumed) {
67 - memcpy_toio(region->addr, ptr, length);
68 - region->consumed = true;
70 + region = &mem_region[i];
71 + if (region->phy_addr != le32_to_cpu(fw_region->addr))
74 + if (region->size < length)
77 + if (region->shared && region->consumed)
80 + if (!region->shared || !region->consumed) {
81 + memcpy_toio(region->addr, ptr, length);
82 + region->consumed = true;
87 + if (i == ARRAY_SIZE(mem_region))
90 region_ptr += sizeof(*fw_region);
99 @@ -360,11 +364,9 @@ mtk_wed_mcu_load_firmware(struct mtk_wed
100 dev_info(wo->hw->dev, "MTK WED WO Chip ID %02x Region %d\n",
101 trailer->chip_id, trailer->num_region);
103 - for (i = 0; i < ARRAY_SIZE(mem_region); i++) {
104 - ret = mtk_wed_mcu_run_firmware(wo, fw, &mem_region[i]);
108 + ret = mtk_wed_mcu_run_firmware(wo, fw);
112 /* set the start address */
113 if (!mtk_wed_is_v3_or_greater(wo->hw) && wo->hw->index)