blob: 0301e1e1f462508f2058f1a55fd416483d43ec3f [file] [log] [blame]
developer78848c62023-04-06 13:44:00 +08001From a23a49eb89ce2abc3370f452bc1915a061b864bd Mon Sep 17 00:00:00 2001
developerf8871e82023-03-08 17:22:32 +08002From: Peter Chiu <chui-hao.chiu@mediatek.com>
3Date: Fri, 17 Feb 2023 14:13:38 +0800
developerd5789dc2023-03-27 11:22:06 +08004Subject: [PATCH 16/29] wifi: mt76: mt7996: add dsp firmware download
developerf8871e82023-03-08 17:22:32 +08005
6Add DSP firmware for phy related control. Without this patch,the
7firmware state would not be ready.
8
9Signed-off-by: Peter Chiu <chui-hao.chiu@mediatek.com>
10---
11 mt76_connac_mcu.h | 1 +
12 mt7996/mcu.c | 94 +++++++++++++++++++++--------------------------
13 mt7996/mt7996.h | 7 ++++
14 mt7996/pci.c | 1 +
15 4 files changed, 50 insertions(+), 53 deletions(-)
16
17diff --git a/mt76_connac_mcu.h b/mt76_connac_mcu.h
developer78848c62023-04-06 13:44:00 +080018index fa10d82..79dde31 100644
developerf8871e82023-03-08 17:22:32 +080019--- a/mt76_connac_mcu.h
20+++ b/mt76_connac_mcu.h
21@@ -22,6 +22,7 @@
22
23 #define FW_START_OVERRIDE BIT(0)
24 #define FW_START_WORKING_PDA_CR4 BIT(2)
25+#define FW_START_WORKING_PDA_DSP BIT(3)
26
27 #define PATCH_SEC_NOT_SUPPORT GENMASK(31, 0)
28 #define PATCH_SEC_TYPE_MASK GENMASK(15, 0)
29diff --git a/mt7996/mcu.c b/mt7996/mcu.c
developer78848c62023-04-06 13:44:00 +080030index a949ff7..09800ff 100644
developerf8871e82023-03-08 17:22:32 +080031--- a/mt7996/mcu.c
32+++ b/mt7996/mcu.c
33@@ -2353,7 +2353,7 @@ out:
34 static int
35 mt7996_mcu_send_ram_firmware(struct mt7996_dev *dev,
36 const struct mt7996_fw_trailer *hdr,
37- const u8 *data, bool is_wa)
38+ const u8 *data, enum mt7996_ram_type type)
39 {
40 int i, offset = 0;
41 u32 override = 0, option = 0;
42@@ -2365,8 +2365,10 @@ mt7996_mcu_send_ram_firmware(struct mt7996_dev *dev,
43
44 region = (const struct mt7996_fw_region *)((const u8 *)hdr -
45 (hdr->n_region - i) * sizeof(*region));
46+ /* DSP and WA use same mode */
47 mode = mt76_connac_mcu_gen_dl_mode(&dev->mt76,
48- region->feature_set, is_wa);
49+ region->feature_set,
50+ type != MT7996_RAM_TYPE_WM);
51 len = le32_to_cpu(region->len);
52 addr = le32_to_cpu(region->addr);
53
54@@ -2393,8 +2395,10 @@ mt7996_mcu_send_ram_firmware(struct mt7996_dev *dev,
55 if (override)
56 option |= FW_START_OVERRIDE;
57
58- if (is_wa)
59+ if (type == MT7996_RAM_TYPE_WA)
60 option |= FW_START_WORKING_PDA_CR4;
61+ else if (type == MT7996_RAM_TYPE_DSP)
62+ option |= FW_START_WORKING_PDA_DSP;
63
64 return mt76_connac_mcu_start_firmware(&dev->mt76, override, option);
65 }
66@@ -2405,56 +2409,40 @@ static int mt7996_load_ram(struct mt7996_dev *dev)
67 const struct firmware *fw;
68 int ret;
69
70- ret = request_firmware(&fw, MT7996_FIRMWARE_WM, dev->mt76.dev);
71- if (ret)
72- return ret;
73-
74- if (!fw || !fw->data || fw->size < sizeof(*hdr)) {
75- dev_err(dev->mt76.dev, "Invalid firmware\n");
76- ret = -EINVAL;
77- goto out;
78- }
79-
80- hdr = (const struct mt7996_fw_trailer *)(fw->data + fw->size - sizeof(*hdr));
81-
82- dev_info(dev->mt76.dev, "WM Firmware Version: %.10s, Build Time: %.15s\n",
83- hdr->fw_ver, hdr->build_date);
84-
85- ret = mt7996_mcu_send_ram_firmware(dev, hdr, fw->data, false);
86- if (ret) {
87- dev_err(dev->mt76.dev, "Failed to start WM firmware\n");
88- goto out;
89- }
90-
91- release_firmware(fw);
92-
93- ret = request_firmware(&fw, MT7996_FIRMWARE_WA, dev->mt76.dev);
94- if (ret)
95- return ret;
96-
97- if (!fw || !fw->data || fw->size < sizeof(*hdr)) {
98- dev_err(dev->mt76.dev, "Invalid firmware\n");
99- ret = -EINVAL;
100- goto out;
101- }
102-
103- hdr = (const struct mt7996_fw_trailer *)(fw->data + fw->size - sizeof(*hdr));
104-
105- dev_info(dev->mt76.dev, "WA Firmware Version: %.10s, Build Time: %.15s\n",
106- hdr->fw_ver, hdr->build_date);
107-
108- ret = mt7996_mcu_send_ram_firmware(dev, hdr, fw->data, true);
109- if (ret) {
110- dev_err(dev->mt76.dev, "Failed to start WA firmware\n");
111- goto out;
112- }
113-
114- snprintf(dev->mt76.hw->wiphy->fw_version,
115- sizeof(dev->mt76.hw->wiphy->fw_version),
116- "%.10s-%.15s", hdr->fw_ver, hdr->build_date);
117-
118-out:
119- release_firmware(fw);
120+#define LOAD_RAM(_type) \
121+ do { \
122+ ret = request_firmware(&fw, MT7996_FIRMWARE_##_type, dev->mt76.dev); \
123+ if (ret) \
124+ return ret; \
125+ \
126+ if (!fw || !fw->data || fw->size < sizeof(*hdr)) { \
127+ dev_err(dev->mt76.dev, "Invalid firmware\n"); \
128+ release_firmware(fw); \
129+ return -EINVAL; \
130+ } \
131+ \
132+ hdr = (const struct mt7996_fw_trailer *) \
133+ (fw->data + fw->size - sizeof(*hdr)); \
134+ \
135+ dev_info(dev->mt76.dev, \
136+ "%s Firmware Version: %.10s, Build Time: %.15s\n", \
137+ #_type, hdr->fw_ver, hdr->build_date); \
138+ \
139+ ret = mt7996_mcu_send_ram_firmware(dev, hdr, fw->data, \
140+ MT7996_RAM_TYPE_##_type); \
141+ if (ret) { \
142+ dev_err(dev->mt76.dev, "Failed to start %s firmware\n", #_type);\
143+ release_firmware(fw); \
144+ return ret; \
145+ } \
146+ \
147+ release_firmware(fw); \
148+ } while (0)
149+
150+ LOAD_RAM(WM);
151+ LOAD_RAM(DSP);
152+ LOAD_RAM(WA);
153+#undef LOAD_RAM
154
155 return ret;
156 }
157diff --git a/mt7996/mt7996.h b/mt7996/mt7996.h
developer78848c62023-04-06 13:44:00 +0800158index 923e6fc..c2f8900 100644
developerf8871e82023-03-08 17:22:32 +0800159--- a/mt7996/mt7996.h
160+++ b/mt7996/mt7996.h
161@@ -29,6 +29,7 @@
162
163 #define MT7996_FIRMWARE_WA "mediatek/mt7996/mt7996_wa.bin"
164 #define MT7996_FIRMWARE_WM "mediatek/mt7996/mt7996_wm.bin"
165+#define MT7996_FIRMWARE_DSP "mediatek/mt7996/mt7996_dsp.bin"
166 #define MT7996_ROM_PATCH "mediatek/mt7996/mt7996_rom_patch.bin"
167
168 #define MT7996_EEPROM_DEFAULT "mediatek/mt7996/mt7996_eeprom.bin"
169@@ -55,6 +56,12 @@ struct mt7996_sta;
170 struct mt7996_dfs_pulse;
171 struct mt7996_dfs_pattern;
172
173+enum mt7996_ram_type {
174+ MT7996_RAM_TYPE_WM = 0,
175+ MT7996_RAM_TYPE_WA,
176+ MT7996_RAM_TYPE_DSP,
177+};
178+
179 enum mt7996_txq_id {
180 MT7996_TXQ_FWDL = 16,
181 MT7996_TXQ_MCU_WM,
182diff --git a/mt7996/pci.c b/mt7996/pci.c
developer78848c62023-04-06 13:44:00 +0800183index 64aee3f..c530105 100644
developerf8871e82023-03-08 17:22:32 +0800184--- a/mt7996/pci.c
185+++ b/mt7996/pci.c
186@@ -219,4 +219,5 @@ MODULE_DEVICE_TABLE(pci, mt7996_pci_device_table);
187 MODULE_DEVICE_TABLE(pci, mt7996_hif_device_table);
188 MODULE_FIRMWARE(MT7996_FIRMWARE_WA);
189 MODULE_FIRMWARE(MT7996_FIRMWARE_WM);
190+MODULE_FIRMWARE(MT7996_FIRMWARE_DSP);
191 MODULE_FIRMWARE(MT7996_ROM_PATCH);
192--
developer78848c62023-04-06 13:44:00 +08001932.18.0
developerf8871e82023-03-08 17:22:32 +0800194