Commit 3d8c636c authored by Lorenzo Bianconi's avatar Lorenzo Bianconi Committed by Felix Fietkau

mt76: connac: move shared fw structures in connac module

Move mt76_connac2 fw structures in connac module since they are shared
between mt7921 and mt7915 drivers. This is a preliminary patch to add
mt7902e support.
Signed-off-by: default avatarLorenzo Bianconi <lorenzo@kernel.org>
Signed-off-by: default avatarFelix Fietkau <nbd@nbd.name>
parent 56054087
...@@ -26,6 +26,62 @@ ...@@ -26,6 +26,62 @@
#define PATCH_SEC_TYPE_MASK GENMASK(15, 0) #define PATCH_SEC_TYPE_MASK GENMASK(15, 0)
#define PATCH_SEC_TYPE_INFO 0x2 #define PATCH_SEC_TYPE_INFO 0x2
struct mt76_connac2_patch_hdr {
char build_date[16];
char platform[4];
__be32 hw_sw_ver;
__be32 patch_ver;
__be16 checksum;
u16 rsv;
struct {
__be32 patch_ver;
__be32 subsys;
__be32 feature;
__be32 n_region;
__be32 crc;
u32 rsv[11];
} desc;
} __packed;
struct mt76_connac2_patch_sec {
__be32 type;
__be32 offs;
__be32 size;
union {
__be32 spec[13];
struct {
__be32 addr;
__be32 len;
__be32 sec_key_idx;
__be32 align_len;
u32 rsv[9];
} info;
};
} __packed;
struct mt76_connac2_fw_trailer {
u8 chip_id;
u8 eco_code;
u8 n_region;
u8 format_ver;
u8 format_flag;
u8 rsv[2];
char fw_ver[10];
char build_date[15];
__le32 crc;
} __packed;
struct mt76_connac2_fw_region {
__le32 decomp_crc;
__le32 decomp_len;
__le32 decomp_blk_sz;
u8 rsv[4];
__le32 addr;
__le32 len;
u8 feature_set;
u8 rsv1[15];
} __packed;
struct tlv { struct tlv {
__le16 tag; __le16 tag;
__le16 len; __le16 len;
......
...@@ -8,62 +8,6 @@ ...@@ -8,62 +8,6 @@
#include "mac.h" #include "mac.h"
#include "eeprom.h" #include "eeprom.h"
struct mt7915_patch_hdr {
char build_date[16];
char platform[4];
__be32 hw_sw_ver;
__be32 patch_ver;
__be16 checksum;
u16 reserved;
struct {
__be32 patch_ver;
__be32 subsys;
__be32 feature;
__be32 n_region;
__be32 crc;
u32 reserved[11];
} desc;
} __packed;
struct mt7915_patch_sec {
__be32 type;
__be32 offs;
__be32 size;
union {
__be32 spec[13];
struct {
__be32 addr;
__be32 len;
__be32 sec_key_idx;
__be32 align_len;
u32 reserved[9];
} info;
};
} __packed;
struct mt7915_fw_trailer {
u8 chip_id;
u8 eco_code;
u8 n_region;
u8 format_ver;
u8 format_flag;
u8 reserved[2];
char fw_ver[10];
char build_date[15];
u32 crc;
} __packed;
struct mt7915_fw_region {
__le32 decomp_crc;
__le32 decomp_len;
__le32 decomp_blk_sz;
u8 reserved[4];
__le32 addr;
__le32 len;
u8 feature_set;
u8 reserved1[15];
} __packed;
#define fw_name(_dev, name, ...) ({ \ #define fw_name(_dev, name, ...) ({ \
char *_fw; \ char *_fw; \
switch (mt76_chip(&(_dev)->mt76)) { \ switch (mt76_chip(&(_dev)->mt76)) { \
...@@ -2136,7 +2080,7 @@ static int mt7915_driver_own(struct mt7915_dev *dev, u8 band) ...@@ -2136,7 +2080,7 @@ static int mt7915_driver_own(struct mt7915_dev *dev, u8 band)
static int mt7915_load_patch(struct mt7915_dev *dev) static int mt7915_load_patch(struct mt7915_dev *dev)
{ {
const struct mt7915_patch_hdr *hdr; const struct mt76_connac2_patch_hdr *hdr;
const struct firmware *fw = NULL; const struct firmware *fw = NULL;
int i, ret, sem; int i, ret, sem;
...@@ -2162,18 +2106,17 @@ static int mt7915_load_patch(struct mt7915_dev *dev) ...@@ -2162,18 +2106,17 @@ static int mt7915_load_patch(struct mt7915_dev *dev)
goto out; goto out;
} }
hdr = (const struct mt7915_patch_hdr *)(fw->data); hdr = (const struct mt76_connac2_patch_hdr *)fw->data;
dev_info(dev->mt76.dev, "HW/SW Version: 0x%x, Build Time: %.16s\n", dev_info(dev->mt76.dev, "HW/SW Version: 0x%x, Build Time: %.16s\n",
be32_to_cpu(hdr->hw_sw_ver), hdr->build_date); be32_to_cpu(hdr->hw_sw_ver), hdr->build_date);
for (i = 0; i < be32_to_cpu(hdr->desc.n_region); i++) { for (i = 0; i < be32_to_cpu(hdr->desc.n_region); i++) {
struct mt7915_patch_sec *sec; struct mt76_connac2_patch_sec *sec;
const u8 *dl; const u8 *dl;
u32 len, addr; u32 len, addr;
sec = (struct mt7915_patch_sec *)(fw->data + sizeof(*hdr) + sec = (void *)(fw->data + sizeof(*hdr) + i * sizeof(*sec));
i * sizeof(*sec));
if ((be32_to_cpu(sec->type) & PATCH_SEC_TYPE_MASK) != if ((be32_to_cpu(sec->type) & PATCH_SEC_TYPE_MASK) !=
PATCH_SEC_TYPE_INFO) { PATCH_SEC_TYPE_INFO) {
ret = -EINVAL; ret = -EINVAL;
...@@ -2220,19 +2163,19 @@ static int mt7915_load_patch(struct mt7915_dev *dev) ...@@ -2220,19 +2163,19 @@ static int mt7915_load_patch(struct mt7915_dev *dev)
static int static int
mt7915_mcu_send_ram_firmware(struct mt7915_dev *dev, mt7915_mcu_send_ram_firmware(struct mt7915_dev *dev,
const struct mt7915_fw_trailer *hdr, const struct mt76_connac2_fw_trailer *hdr,
const u8 *data, bool is_wa) const u8 *data, bool is_wa)
{ {
int i, offset = 0; int i, offset = 0;
u32 override = 0, option = 0; u32 override = 0, option = 0;
for (i = 0; i < hdr->n_region; i++) { for (i = 0; i < hdr->n_region; i++) {
const struct mt7915_fw_region *region; const struct mt76_connac2_fw_region *region;
int err;
u32 len, addr, mode; u32 len, addr, mode;
int err;
region = (const struct mt7915_fw_region *)((const u8 *)hdr - region = (const void *)((const u8 *)hdr -
(hdr->n_region - i) * sizeof(*region)); (hdr->n_region - i) * sizeof(*region));
mode = mt76_connac_mcu_gen_dl_mode(&dev->mt76, mode = mt76_connac_mcu_gen_dl_mode(&dev->mt76,
region->feature_set, is_wa); region->feature_set, is_wa);
len = le32_to_cpu(region->len); len = le32_to_cpu(region->len);
...@@ -2269,7 +2212,7 @@ mt7915_mcu_send_ram_firmware(struct mt7915_dev *dev, ...@@ -2269,7 +2212,7 @@ mt7915_mcu_send_ram_firmware(struct mt7915_dev *dev,
static int mt7915_load_ram(struct mt7915_dev *dev) static int mt7915_load_ram(struct mt7915_dev *dev)
{ {
const struct mt7915_fw_trailer *hdr; const struct mt76_connac2_fw_trailer *hdr;
const struct firmware *fw; const struct firmware *fw;
int ret; int ret;
...@@ -2284,9 +2227,7 @@ static int mt7915_load_ram(struct mt7915_dev *dev) ...@@ -2284,9 +2227,7 @@ static int mt7915_load_ram(struct mt7915_dev *dev)
goto out; goto out;
} }
hdr = (const struct mt7915_fw_trailer *)(fw->data + fw->size - hdr = (const void *)(fw->data + fw->size - sizeof(*hdr));
sizeof(*hdr));
dev_info(dev->mt76.dev, "WM Firmware Version: %.10s, Build Time: %.15s\n", dev_info(dev->mt76.dev, "WM Firmware Version: %.10s, Build Time: %.15s\n",
hdr->fw_ver, hdr->build_date); hdr->fw_ver, hdr->build_date);
...@@ -2309,9 +2250,7 @@ static int mt7915_load_ram(struct mt7915_dev *dev) ...@@ -2309,9 +2250,7 @@ static int mt7915_load_ram(struct mt7915_dev *dev)
goto out; goto out;
} }
hdr = (const struct mt7915_fw_trailer *)(fw->data + fw->size - hdr = (const void *)(fw->data + fw->size - sizeof(*hdr));
sizeof(*hdr));
dev_info(dev->mt76.dev, "WA Firmware Version: %.10s, Build Time: %.15s\n", dev_info(dev->mt76.dev, "WA Firmware Version: %.10s, Build Time: %.15s\n",
hdr->fw_ver, hdr->build_date); hdr->fw_ver, hdr->build_date);
......
...@@ -8,62 +8,6 @@ ...@@ -8,62 +8,6 @@
#include "mcu.h" #include "mcu.h"
#include "mac.h" #include "mac.h"
struct mt7921_patch_hdr {
char build_date[16];
char platform[4];
__be32 hw_sw_ver;
__be32 patch_ver;
__be16 checksum;
u16 reserved;
struct {
__be32 patch_ver;
__be32 subsys;
__be32 feature;
__be32 n_region;
__be32 crc;
u32 reserved[11];
} desc;
} __packed;
struct mt7921_patch_sec {
__be32 type;
__be32 offs;
__be32 size;
union {
__be32 spec[13];
struct {
__be32 addr;
__be32 len;
__be32 sec_key_idx;
__be32 align_len;
u32 reserved[9];
} info;
};
} __packed;
struct mt7921_fw_trailer {
u8 chip_id;
u8 eco_code;
u8 n_region;
u8 format_ver;
u8 format_flag;
u8 reserved[2];
char fw_ver[10];
char build_date[15];
u32 crc;
} __packed;
struct mt7921_fw_region {
__le32 decomp_crc;
__le32 decomp_len;
__le32 decomp_blk_sz;
u8 reserved[4];
__le32 addr;
__le32 len;
u8 feature_set;
u8 reserved1[15];
} __packed;
#define MT_STA_BFER BIT(0) #define MT_STA_BFER BIT(0)
#define MT_STA_BFEE BIT(1) #define MT_STA_BFEE BIT(1)
...@@ -512,7 +456,7 @@ static char *mt7921_patch_name(struct mt7921_dev *dev) ...@@ -512,7 +456,7 @@ static char *mt7921_patch_name(struct mt7921_dev *dev)
static int mt7921_load_patch(struct mt7921_dev *dev) static int mt7921_load_patch(struct mt7921_dev *dev)
{ {
const struct mt7921_patch_hdr *hdr; const struct mt76_connac2_patch_hdr *hdr;
const struct firmware *fw = NULL; const struct firmware *fw = NULL;
int i, ret, sem, max_len; int i, ret, sem, max_len;
...@@ -539,19 +483,18 @@ static int mt7921_load_patch(struct mt7921_dev *dev) ...@@ -539,19 +483,18 @@ static int mt7921_load_patch(struct mt7921_dev *dev)
goto out; goto out;
} }
hdr = (const struct mt7921_patch_hdr *)(fw->data); hdr = (const struct mt76_connac2_patch_hdr *)fw->data;
dev_info(dev->mt76.dev, "HW/SW Version: 0x%x, Build Time: %.16s\n", dev_info(dev->mt76.dev, "HW/SW Version: 0x%x, Build Time: %.16s\n",
be32_to_cpu(hdr->hw_sw_ver), hdr->build_date); be32_to_cpu(hdr->hw_sw_ver), hdr->build_date);
for (i = 0; i < be32_to_cpu(hdr->desc.n_region); i++) { for (i = 0; i < be32_to_cpu(hdr->desc.n_region); i++) {
struct mt7921_patch_sec *sec; struct mt76_connac2_patch_sec *sec;
const u8 *dl; const u8 *dl;
u32 len, addr, mode; u32 len, addr, mode;
u32 sec_info = 0; u32 sec_info = 0;
sec = (struct mt7921_patch_sec *)(fw->data + sizeof(*hdr) + sec = (void *)(fw->data + sizeof(*hdr) + i * sizeof(*sec));
i * sizeof(*sec));
if ((be32_to_cpu(sec->type) & PATCH_SEC_TYPE_MASK) != if ((be32_to_cpu(sec->type) & PATCH_SEC_TYPE_MASK) !=
PATCH_SEC_TYPE_INFO) { PATCH_SEC_TYPE_INFO) {
ret = -EINVAL; ret = -EINVAL;
...@@ -608,7 +551,7 @@ static int mt7921_load_patch(struct mt7921_dev *dev) ...@@ -608,7 +551,7 @@ static int mt7921_load_patch(struct mt7921_dev *dev)
static int static int
mt7921_mcu_send_ram_firmware(struct mt7921_dev *dev, mt7921_mcu_send_ram_firmware(struct mt7921_dev *dev,
const struct mt7921_fw_trailer *hdr, const struct mt76_connac2_fw_trailer *hdr,
const u8 *data, bool is_wa) const u8 *data, bool is_wa)
{ {
int i, offset = 0, max_len; int i, offset = 0, max_len;
...@@ -617,12 +560,12 @@ mt7921_mcu_send_ram_firmware(struct mt7921_dev *dev, ...@@ -617,12 +560,12 @@ mt7921_mcu_send_ram_firmware(struct mt7921_dev *dev,
max_len = mt76_is_sdio(&dev->mt76) ? 2048 : 4096; max_len = mt76_is_sdio(&dev->mt76) ? 2048 : 4096;
for (i = 0; i < hdr->n_region; i++) { for (i = 0; i < hdr->n_region; i++) {
const struct mt7921_fw_region *region; const struct mt76_connac2_fw_region *region;
int err;
u32 len, addr, mode; u32 len, addr, mode;
int err;
region = (const struct mt7921_fw_region *)((const u8 *)hdr - region = (const void *)((const u8 *)hdr -
(hdr->n_region - i) * sizeof(*region)); (hdr->n_region - i) * sizeof(*region));
mode = mt76_connac_mcu_gen_dl_mode(&dev->mt76, mode = mt76_connac_mcu_gen_dl_mode(&dev->mt76,
region->feature_set, is_wa); region->feature_set, is_wa);
len = le32_to_cpu(region->len); len = le32_to_cpu(region->len);
...@@ -671,7 +614,7 @@ static char *mt7921_ram_name(struct mt7921_dev *dev) ...@@ -671,7 +614,7 @@ static char *mt7921_ram_name(struct mt7921_dev *dev)
static int mt7921_load_ram(struct mt7921_dev *dev) static int mt7921_load_ram(struct mt7921_dev *dev)
{ {
const struct mt7921_fw_trailer *hdr; const struct mt76_connac2_fw_trailer *hdr;
const struct firmware *fw; const struct firmware *fw;
int ret; int ret;
...@@ -685,9 +628,7 @@ static int mt7921_load_ram(struct mt7921_dev *dev) ...@@ -685,9 +628,7 @@ static int mt7921_load_ram(struct mt7921_dev *dev)
goto out; goto out;
} }
hdr = (const struct mt7921_fw_trailer *)(fw->data + fw->size - hdr = (const void *)(fw->data + fw->size - sizeof(*hdr));
sizeof(*hdr));
dev_info(dev->mt76.dev, "WM Firmware Version: %.10s, Build Time: %.15s\n", dev_info(dev->mt76.dev, "WM Firmware Version: %.10s, Build Time: %.15s\n",
hdr->fw_ver, hdr->build_date); hdr->fw_ver, hdr->build_date);
......
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