Commit 79394f40 authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau

mt76: unify firmware header between mt76x0 and mt76x2

Move mt76x2_fw_header definition in mt76x02_mcu.h and remove
duplicated code
Signed-off-by: default avatarLorenzo Bianconi <lorenzo.bianconi@redhat.com>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent 8cff1237
...@@ -73,17 +73,8 @@ mt76x0_mcu_calibrate(struct mt76x0_dev *dev, enum mcu_calibrate cal, u32 val) ...@@ -73,17 +73,8 @@ mt76x0_mcu_calibrate(struct mt76x0_dev *dev, enum mcu_calibrate cal, u32 val)
return mt76_mcu_send_msg(dev, skb, CMD_CALIBRATION_OP, true); return mt76_mcu_send_msg(dev, skb, CMD_CALIBRATION_OP, true);
} }
struct mt76_fw_header {
__le32 ilm_len;
__le32 dlm_len;
__le16 build_ver;
__le16 fw_ver;
u8 pad[4];
char build_time[16];
};
struct mt76_fw { struct mt76_fw {
struct mt76_fw_header hdr; struct mt76x02_fw_header hdr;
u8 ivb[MT_MCU_IVB_SIZE]; u8 ivb[MT_MCU_IVB_SIZE];
u8 ilm[]; u8 ilm[];
}; };
...@@ -140,7 +131,7 @@ mt76x0_upload_firmware(struct mt76x0_dev *dev, const struct mt76_fw *fw) ...@@ -140,7 +131,7 @@ mt76x0_upload_firmware(struct mt76x0_dev *dev, const struct mt76_fw *fw)
static int mt76x0_load_firmware(struct mt76x0_dev *dev) static int mt76x0_load_firmware(struct mt76x0_dev *dev)
{ {
const struct firmware *fw; const struct firmware *fw;
const struct mt76_fw_header *hdr; const struct mt76x02_fw_header *hdr;
int len, ret; int len, ret;
u32 val; u32 val;
...@@ -157,7 +148,7 @@ static int mt76x0_load_firmware(struct mt76x0_dev *dev) ...@@ -157,7 +148,7 @@ static int mt76x0_load_firmware(struct mt76x0_dev *dev)
if (!fw || !fw->data || fw->size < sizeof(*hdr)) if (!fw || !fw->data || fw->size < sizeof(*hdr))
goto err_inv_fw; goto err_inv_fw;
hdr = (const struct mt76_fw_header *) fw->data; hdr = (const struct mt76x02_fw_header *)fw->data;
if (le32_to_cpu(hdr->ilm_len) <= MT_MCU_IVB_SIZE) if (le32_to_cpu(hdr->ilm_len) <= MT_MCU_IVB_SIZE)
goto err_inv_fw; goto err_inv_fw;
......
...@@ -68,4 +68,21 @@ enum mcu_function { ...@@ -68,4 +68,21 @@ enum mcu_function {
GET_FW_VERSION = 5, GET_FW_VERSION = 5,
}; };
struct mt76x02_fw_header {
__le32 ilm_len;
__le32 dlm_len;
__le16 build_ver;
__le16 fw_ver;
u8 pad[4];
char build_time[16];
};
struct mt76x02_patch_header {
char build_time[16];
char platform[4];
char hw_version[4];
char patch_version[4];
u8 pad[2];
};
#endif /* __MT76x02_MCU_H */ #endif /* __MT76x02_MCU_H */
...@@ -104,7 +104,7 @@ static int ...@@ -104,7 +104,7 @@ static int
mt76pci_load_rom_patch(struct mt76x2_dev *dev) mt76pci_load_rom_patch(struct mt76x2_dev *dev)
{ {
const struct firmware *fw = NULL; const struct firmware *fw = NULL;
struct mt76x2_patch_header *hdr; struct mt76x02_patch_header *hdr;
bool rom_protect = !is_mt7612(dev); bool rom_protect = !is_mt7612(dev);
int len, ret = 0; int len, ret = 0;
__le32 *cur; __le32 *cur;
...@@ -139,7 +139,7 @@ mt76pci_load_rom_patch(struct mt76x2_dev *dev) ...@@ -139,7 +139,7 @@ mt76pci_load_rom_patch(struct mt76x2_dev *dev)
goto out; goto out;
} }
hdr = (struct mt76x2_patch_header *) fw->data; hdr = (struct mt76x02_patch_header *)fw->data;
dev_info(dev->mt76.dev, "ROM patch build: %.15s\n", hdr->build_time); dev_info(dev->mt76.dev, "ROM patch build: %.15s\n", hdr->build_time);
mt76_wr(dev, MT_MCU_PCIE_REMAP_BASE4, MT_MCU_ROM_PATCH_OFFSET); mt76_wr(dev, MT_MCU_PCIE_REMAP_BASE4, MT_MCU_ROM_PATCH_OFFSET);
...@@ -170,7 +170,7 @@ static int ...@@ -170,7 +170,7 @@ static int
mt76pci_load_firmware(struct mt76x2_dev *dev) mt76pci_load_firmware(struct mt76x2_dev *dev)
{ {
const struct firmware *fw; const struct firmware *fw;
const struct mt76x2_fw_header *hdr; const struct mt76x02_fw_header *hdr;
int len, ret; int len, ret;
__le32 *cur; __le32 *cur;
u32 offset, val; u32 offset, val;
...@@ -182,7 +182,7 @@ mt76pci_load_firmware(struct mt76x2_dev *dev) ...@@ -182,7 +182,7 @@ mt76pci_load_firmware(struct mt76x2_dev *dev)
if (!fw || !fw->data || fw->size < sizeof(*hdr)) if (!fw || !fw->data || fw->size < sizeof(*hdr))
goto error; goto error;
hdr = (const struct mt76x2_fw_header *) fw->data; hdr = (const struct mt76x02_fw_header *)fw->data;
len = sizeof(*hdr); len = sizeof(*hdr);
len += le32_to_cpu(hdr->ilm_len); len += le32_to_cpu(hdr->ilm_len);
......
...@@ -101,23 +101,6 @@ struct mt76x2_tssi_comp { ...@@ -101,23 +101,6 @@ struct mt76x2_tssi_comp {
u8 offset1; u8 offset1;
} __packed __aligned(4); } __packed __aligned(4);
struct mt76x2_fw_header {
__le32 ilm_len;
__le32 dlm_len;
__le16 build_ver;
__le16 fw_ver;
u8 pad[4];
char build_time[16];
};
struct mt76x2_patch_header {
char build_time[16];
char platform[4];
char hw_version[4];
char patch_version[4];
u8 pad[2];
};
int mt76x2_mcu_calibrate(struct mt76x2_dev *dev, enum mcu_calibration type, int mt76x2_mcu_calibrate(struct mt76x2_dev *dev, enum mcu_calibration type,
u32 param); u32 param);
int mt76x2_mcu_tssi_comp(struct mt76x2_dev *dev, struct mt76x2_tssi_comp *tssi_data); int mt76x2_mcu_tssi_comp(struct mt76x2_dev *dev, struct mt76x2_tssi_comp *tssi_data);
......
...@@ -236,7 +236,7 @@ static void mt76x2u_mcu_reset_wmt(struct mt76x2_dev *dev) ...@@ -236,7 +236,7 @@ static void mt76x2u_mcu_reset_wmt(struct mt76x2_dev *dev)
static int mt76x2u_mcu_load_rom_patch(struct mt76x2_dev *dev) static int mt76x2u_mcu_load_rom_patch(struct mt76x2_dev *dev)
{ {
bool rom_protect = !is_mt7612(dev); bool rom_protect = !is_mt7612(dev);
struct mt76x2_patch_header *hdr; struct mt76x02_patch_header *hdr;
u32 val, patch_mask, patch_reg; u32 val, patch_mask, patch_reg;
const struct firmware *fw; const struct firmware *fw;
int err; int err;
...@@ -271,7 +271,7 @@ static int mt76x2u_mcu_load_rom_patch(struct mt76x2_dev *dev) ...@@ -271,7 +271,7 @@ static int mt76x2u_mcu_load_rom_patch(struct mt76x2_dev *dev)
goto out; goto out;
} }
hdr = (struct mt76x2_patch_header *)fw->data; hdr = (struct mt76x02_patch_header *)fw->data;
dev_info(dev->mt76.dev, "ROM patch build: %.15s\n", hdr->build_time); dev_info(dev->mt76.dev, "ROM patch build: %.15s\n", hdr->build_time);
/* enable USB_DMA_CFG */ /* enable USB_DMA_CFG */
...@@ -323,7 +323,7 @@ static int mt76x2u_mcu_load_rom_patch(struct mt76x2_dev *dev) ...@@ -323,7 +323,7 @@ static int mt76x2u_mcu_load_rom_patch(struct mt76x2_dev *dev)
static int mt76x2u_mcu_load_firmware(struct mt76x2_dev *dev) static int mt76x2u_mcu_load_firmware(struct mt76x2_dev *dev)
{ {
u32 val, dlm_offset = MT76U_MCU_DLM_OFFSET; u32 val, dlm_offset = MT76U_MCU_DLM_OFFSET;
const struct mt76x2_fw_header *hdr; const struct mt76x02_fw_header *hdr;
int err, len, ilm_len, dlm_len; int err, len, ilm_len, dlm_len;
const struct firmware *fw; const struct firmware *fw;
...@@ -336,7 +336,7 @@ static int mt76x2u_mcu_load_firmware(struct mt76x2_dev *dev) ...@@ -336,7 +336,7 @@ static int mt76x2u_mcu_load_firmware(struct mt76x2_dev *dev)
goto out; goto out;
} }
hdr = (const struct mt76x2_fw_header *)fw->data; hdr = (const struct mt76x02_fw_header *)fw->data;
ilm_len = le32_to_cpu(hdr->ilm_len); ilm_len = le32_to_cpu(hdr->ilm_len);
dlm_len = le32_to_cpu(hdr->dlm_len); dlm_len = le32_to_cpu(hdr->dlm_len);
len = sizeof(*hdr) + ilm_len + dlm_len; len = sizeof(*hdr) + ilm_len + dlm_len;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment