forked from openwrt/mt76
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mt76: connac: move mt76_connac2_load_patch in connac module
Move mt76_connac2_load_patch utility routine in mt76_connac module since it is shared between mt7921 and mt7915. This is a preliminary patch to support mt7902e driver. Signed-off-by: Lorenzo Bianconi <[email protected]> Signed-off-by: Felix Fietkau <[email protected]>
- Loading branch information
1 parent
16ab6bf
commit 29fd748
Showing
4 changed files
with
123 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2916,5 +2916,118 @@ int mt76_connac2_load_ram(struct mt76_dev *dev, const char *fw_wm, | |
} | ||
EXPORT_SYMBOL_GPL(mt76_connac2_load_ram); | ||
|
||
static u32 mt76_connac2_get_data_mode(struct mt76_dev *dev, u32 info) | ||
{ | ||
u32 mode = DL_MODE_NEED_RSP; | ||
|
||
if (!is_mt7921(dev) || info == PATCH_SEC_NOT_SUPPORT) | ||
return mode; | ||
|
||
switch (FIELD_GET(PATCH_SEC_ENC_TYPE_MASK, info)) { | ||
case PATCH_SEC_ENC_TYPE_PLAIN: | ||
break; | ||
case PATCH_SEC_ENC_TYPE_AES: | ||
mode |= DL_MODE_ENCRYPT; | ||
mode |= FIELD_PREP(DL_MODE_KEY_IDX, | ||
(info & PATCH_SEC_ENC_AES_KEY_MASK)) & DL_MODE_KEY_IDX; | ||
mode |= DL_MODE_RESET_SEC_IV; | ||
break; | ||
case PATCH_SEC_ENC_TYPE_SCRAMBLE: | ||
mode |= DL_MODE_ENCRYPT; | ||
mode |= DL_CONFIG_ENCRY_MODE_SEL; | ||
mode |= DL_MODE_RESET_SEC_IV; | ||
break; | ||
default: | ||
dev_err(dev->dev, "Encryption type not support!\n"); | ||
} | ||
|
||
return mode; | ||
} | ||
|
||
int mt76_connac2_load_patch(struct mt76_dev *dev, const char *fw_name) | ||
{ | ||
int i, ret, sem, max_len = mt76_is_sdio(dev) ? 2048 : 4096; | ||
const struct mt76_connac2_patch_hdr *hdr; | ||
const struct firmware *fw = NULL; | ||
|
||
sem = mt76_connac_mcu_patch_sem_ctrl(dev, true); | ||
switch (sem) { | ||
case PATCH_IS_DL: | ||
return 0; | ||
case PATCH_NOT_DL_SEM_SUCCESS: | ||
break; | ||
default: | ||
dev_err(dev->dev, "Failed to get patch semaphore\n"); | ||
return -EAGAIN; | ||
} | ||
|
||
ret = request_firmware(&fw, fw_name, dev->dev); | ||
if (ret) | ||
goto out; | ||
|
||
if (!fw || !fw->data || fw->size < sizeof(*hdr)) { | ||
dev_err(dev->dev, "Invalid firmware\n"); | ||
ret = -EINVAL; | ||
goto out; | ||
} | ||
|
||
hdr = (const void *)fw->data; | ||
dev_info(dev->dev, "HW/SW Version: 0x%x, Build Time: %.16s\n", | ||
be32_to_cpu(hdr->hw_sw_ver), hdr->build_date); | ||
|
||
for (i = 0; i < be32_to_cpu(hdr->desc.n_region); i++) { | ||
struct mt76_connac2_patch_sec *sec; | ||
u32 len, addr, mode; | ||
const u8 *dl; | ||
u32 sec_info; | ||
|
||
sec = (void *)(fw->data + sizeof(*hdr) + i * sizeof(*sec)); | ||
if ((be32_to_cpu(sec->type) & PATCH_SEC_TYPE_MASK) != | ||
PATCH_SEC_TYPE_INFO) { | ||
ret = -EINVAL; | ||
goto out; | ||
} | ||
|
||
addr = be32_to_cpu(sec->info.addr); | ||
len = be32_to_cpu(sec->info.len); | ||
dl = fw->data + be32_to_cpu(sec->offs); | ||
sec_info = be32_to_cpu(sec->info.sec_key_idx); | ||
mode = mt76_connac2_get_data_mode(dev, sec_info); | ||
|
||
ret = mt76_connac_mcu_init_download(dev, addr, len, mode); | ||
if (ret) { | ||
dev_err(dev->dev, "Download request failed\n"); | ||
goto out; | ||
} | ||
|
||
ret = __mt76_mcu_send_firmware(dev, MCU_CMD(FW_SCATTER), | ||
dl, len, max_len); | ||
if (ret) { | ||
dev_err(dev->dev, "Failed to send patch\n"); | ||
goto out; | ||
} | ||
} | ||
|
||
ret = mt76_connac_mcu_start_patch(dev); | ||
if (ret) | ||
dev_err(dev->dev, "Failed to start patch\n"); | ||
|
||
out: | ||
sem = mt76_connac_mcu_patch_sem_ctrl(dev, false); | ||
switch (sem) { | ||
case PATCH_REL_SEM_SUCCESS: | ||
break; | ||
default: | ||
ret = -EAGAIN; | ||
dev_err(dev->dev, "Failed to release patch semaphore\n"); | ||
break; | ||
} | ||
|
||
release_firmware(fw); | ||
|
||
return ret; | ||
} | ||
EXPORT_SYMBOL_GPL(mt76_connac2_load_patch); | ||
|
||
MODULE_AUTHOR("Lorenzo Bianconi <[email protected]>"); | ||
MODULE_LICENSE("Dual BSD/GPL"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.