mirror of https://gitee.com/openkylin/linux.git
carl9170: move checksum and txseq into subfunctions
Signed-off-by: Christian Lamparter <chunkeey@googlemail.com> Signed-off-by: John W. Linville <linville@tuxdriver.com>
This commit is contained in:
parent
3f81f8f152
commit
65a692284d
|
@ -146,13 +146,15 @@ static bool valid_cpu_addr(const u32 address)
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int carl9170_fw(struct ar9170 *ar, const __u8 *data, size_t len)
|
static int carl9170_fw_checksum(struct ar9170 *ar, const __u8 *data,
|
||||||
|
size_t len)
|
||||||
{
|
{
|
||||||
const struct carl9170fw_otus_desc *otus_desc;
|
const struct carl9170fw_otus_desc *otus_desc;
|
||||||
const struct carl9170fw_chk_desc *chk_desc;
|
|
||||||
const struct carl9170fw_last_desc *last_desc;
|
const struct carl9170fw_last_desc *last_desc;
|
||||||
const struct carl9170fw_txsq_desc *txsq_desc;
|
const struct carl9170fw_chk_desc *chk_desc;
|
||||||
u16 if_comb_types;
|
unsigned long fin, diff;
|
||||||
|
unsigned int dsc_len;
|
||||||
|
u32 crc32;
|
||||||
|
|
||||||
last_desc = carl9170_fw_find_desc(ar, LAST_MAGIC,
|
last_desc = carl9170_fw_find_desc(ar, LAST_MAGIC,
|
||||||
sizeof(*last_desc), CARL9170FW_LAST_DESC_CUR_VER);
|
sizeof(*last_desc), CARL9170FW_LAST_DESC_CUR_VER);
|
||||||
|
@ -170,36 +172,68 @@ static int carl9170_fw(struct ar9170 *ar, const __u8 *data, size_t len)
|
||||||
chk_desc = carl9170_fw_find_desc(ar, CHK_MAGIC,
|
chk_desc = carl9170_fw_find_desc(ar, CHK_MAGIC,
|
||||||
sizeof(*chk_desc), CARL9170FW_CHK_DESC_CUR_VER);
|
sizeof(*chk_desc), CARL9170FW_CHK_DESC_CUR_VER);
|
||||||
|
|
||||||
if (chk_desc) {
|
if (!chk_desc) {
|
||||||
unsigned long fin, diff;
|
dev_warn(&ar->udev->dev, "Unprotected firmware image.\n");
|
||||||
unsigned int dsc_len;
|
return 0;
|
||||||
u32 crc32;
|
}
|
||||||
|
|
||||||
dsc_len = min_t(unsigned int, len,
|
dsc_len = min_t(unsigned int, len,
|
||||||
(unsigned long)chk_desc - (unsigned long)otus_desc);
|
(unsigned long)chk_desc - (unsigned long)otus_desc);
|
||||||
|
|
||||||
fin = (unsigned long) last_desc + sizeof(*last_desc);
|
fin = (unsigned long) last_desc + sizeof(*last_desc);
|
||||||
diff = fin - (unsigned long) otus_desc;
|
diff = fin - (unsigned long) otus_desc;
|
||||||
|
|
||||||
if (diff < len)
|
if (diff < len)
|
||||||
len -= diff;
|
len -= diff;
|
||||||
|
|
||||||
if (len < 256)
|
if (len < 256)
|
||||||
return -EIO;
|
return -EIO;
|
||||||
|
|
||||||
crc32 = crc32_le(~0, data, len);
|
crc32 = crc32_le(~0, data, len);
|
||||||
if (cpu_to_le32(crc32) != chk_desc->fw_crc32) {
|
if (cpu_to_le32(crc32) != chk_desc->fw_crc32) {
|
||||||
dev_err(&ar->udev->dev, "fw checksum test failed.\n");
|
dev_err(&ar->udev->dev, "fw checksum test failed.\n");
|
||||||
return -ENOEXEC;
|
return -ENOEXEC;
|
||||||
}
|
}
|
||||||
|
|
||||||
crc32 = crc32_le(crc32, (void *)otus_desc, dsc_len);
|
crc32 = crc32_le(crc32, (void *)otus_desc, dsc_len);
|
||||||
if (cpu_to_le32(crc32) != chk_desc->hdr_crc32) {
|
if (cpu_to_le32(crc32) != chk_desc->hdr_crc32) {
|
||||||
dev_err(&ar->udev->dev, "descriptor check failed.\n");
|
dev_err(&ar->udev->dev, "descriptor check failed.\n");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int carl9170_fw_tx_sequence(struct ar9170 *ar)
|
||||||
|
{
|
||||||
|
const struct carl9170fw_txsq_desc *txsq_desc;
|
||||||
|
|
||||||
|
txsq_desc = carl9170_fw_find_desc(ar, TXSQ_MAGIC, sizeof(*txsq_desc),
|
||||||
|
CARL9170FW_TXSQ_DESC_CUR_VER);
|
||||||
|
if (txsq_desc) {
|
||||||
|
ar->fw.tx_seq_table = le32_to_cpu(txsq_desc->seq_table_addr);
|
||||||
|
if (!valid_cpu_addr(ar->fw.tx_seq_table))
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
dev_warn(&ar->udev->dev, "Unprotected firmware image.\n");
|
ar->fw.tx_seq_table = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int carl9170_fw(struct ar9170 *ar, const __u8 *data, size_t len)
|
||||||
|
{
|
||||||
|
const struct carl9170fw_otus_desc *otus_desc;
|
||||||
|
int err;
|
||||||
|
u16 if_comb_types;
|
||||||
|
|
||||||
|
err = carl9170_fw_checksum(ar, data, len);
|
||||||
|
if (err)
|
||||||
|
return err;
|
||||||
|
|
||||||
|
otus_desc = carl9170_fw_find_desc(ar, OTUS_MAGIC,
|
||||||
|
sizeof(*otus_desc), CARL9170FW_OTUS_DESC_CUR_VER);
|
||||||
|
if (!otus_desc) {
|
||||||
|
return -ENODATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define SUPP(feat) \
|
#define SUPP(feat) \
|
||||||
|
@ -321,19 +355,8 @@ static int carl9170_fw(struct ar9170 *ar, const __u8 *data, size_t len)
|
||||||
|
|
||||||
ar->hw->wiphy->interface_modes |= if_comb_types;
|
ar->hw->wiphy->interface_modes |= if_comb_types;
|
||||||
|
|
||||||
txsq_desc = carl9170_fw_find_desc(ar, TXSQ_MAGIC,
|
|
||||||
sizeof(*txsq_desc), CARL9170FW_TXSQ_DESC_CUR_VER);
|
|
||||||
|
|
||||||
if (txsq_desc) {
|
|
||||||
ar->fw.tx_seq_table = le32_to_cpu(txsq_desc->seq_table_addr);
|
|
||||||
if (!valid_cpu_addr(ar->fw.tx_seq_table))
|
|
||||||
return -EINVAL;
|
|
||||||
} else {
|
|
||||||
ar->fw.tx_seq_table = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#undef SUPPORTED
|
#undef SUPPORTED
|
||||||
return 0;
|
return carl9170_fw_tx_sequence(ar);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct carl9170fw_desc_head *
|
static struct carl9170fw_desc_head *
|
||||||
|
|
Loading…
Reference in New Issue