3b0795c5368b7b4fb1895e54413ccc4c4d3cbf89
[openwrt/staging/wigyori.git] /
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
5 SoC
6
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
9 cpu-boot region).
10 Reverse the mtk_wed_mcu_run_firmware() logic to check all the fw
11 sections are defined in the dts reserved_memory node.
12
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>
19 ---
20 drivers/net/ethernet/mediatek/mtk_wed_mcu.c | 48 +++++++++++----------
21 1 file changed, 25 insertions(+), 23 deletions(-)
22
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
26 }
27
28 static int
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)
32 {
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;
36
37 - if (!region->phy_addr || !region->size)
38 - return 0;
39 -
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_
44
45 while (region_ptr < trailer_ptr) {
46 u32 length;
47 + int i;
48
49 fw_region = (const struct mtk_wed_fw_region *)region_ptr;
50 length = le32_to_cpu(fw_region->len);
51 -
52 - if (region->phy_addr != le32_to_cpu(fw_region->addr))
53 - goto next;
54 -
55 - if (region->size < length)
56 - goto next;
57 -
58 if (first_region_ptr < ptr + length)
59 goto next;
60
61 - if (region->shared && region->consumed)
62 - return 0;
63 + for (i = 0; i < ARRAY_SIZE(mem_region); i++) {
64 + struct mtk_wed_wo_memory_region *region;
65
66 - if (!region->shared || !region->consumed) {
67 - memcpy_toio(region->addr, ptr, length);
68 - region->consumed = true;
69 - return 0;
70 + region = &mem_region[i];
71 + if (region->phy_addr != le32_to_cpu(fw_region->addr))
72 + continue;
73 +
74 + if (region->size < length)
75 + continue;
76 +
77 + if (region->shared && region->consumed)
78 + break;
79 +
80 + if (!region->shared || !region->consumed) {
81 + memcpy_toio(region->addr, ptr, length);
82 + region->consumed = true;
83 + break;
84 + }
85 }
86 +
87 + if (i == ARRAY_SIZE(mem_region))
88 + return -EINVAL;
89 next:
90 region_ptr += sizeof(*fw_region);
91 ptr += length;
92 }
93
94 - return -EINVAL;
95 + return 0;
96 }
97
98 static int
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);
102
103 - for (i = 0; i < ARRAY_SIZE(mem_region); i++) {
104 - ret = mtk_wed_mcu_run_firmware(wo, fw, &mem_region[i]);
105 - if (ret)
106 - goto out;
107 - }
108 + ret = mtk_wed_mcu_run_firmware(wo, fw);
109 + if (ret)
110 + goto out;
111
112 /* set the start address */
113 if (!mtk_wed_is_v3_or_greater(wo->hw) && wo->hw->index)