mt76: connac: move mt76_connac2_load_ram in connac module
Move mt76_connac2_load_ram 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 <lorenzo@kernel.org> Signed-off-by: Felix Fietkau <nbd@nbd.name>
This commit is contained in:
committed by
Felix Fietkau
parent
c132fc7d83
commit
b9ec27102a
@@ -1,6 +1,7 @@
|
|||||||
// SPDX-License-Identifier: ISC
|
// SPDX-License-Identifier: ISC
|
||||||
/* Copyright (C) 2020 MediaTek Inc. */
|
/* Copyright (C) 2020 MediaTek Inc. */
|
||||||
|
|
||||||
|
#include <linux/firmware.h>
|
||||||
#include "mt76_connac_mcu.h"
|
#include "mt76_connac_mcu.h"
|
||||||
|
|
||||||
int mt76_connac_mcu_start_firmware(struct mt76_dev *dev, u32 addr, u32 option)
|
int mt76_connac_mcu_start_firmware(struct mt76_dev *dev, u32 addr, u32 option)
|
||||||
@@ -2808,5 +2809,115 @@ int mt76_connac_mcu_rdd_cmd(struct mt76_dev *dev, int cmd, u8 index,
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL_GPL(mt76_connac_mcu_rdd_cmd);
|
EXPORT_SYMBOL_GPL(mt76_connac_mcu_rdd_cmd);
|
||||||
|
|
||||||
|
static int
|
||||||
|
mt76_connac_mcu_send_ram_firmware(struct mt76_dev *dev,
|
||||||
|
const struct mt76_connac2_fw_trailer *hdr,
|
||||||
|
const u8 *data, bool is_wa)
|
||||||
|
{
|
||||||
|
int i, offset = 0, max_len = mt76_is_sdio(dev) ? 2048 : 4096;
|
||||||
|
u32 override = 0, option = 0;
|
||||||
|
|
||||||
|
for (i = 0; i < hdr->n_region; i++) {
|
||||||
|
const struct mt76_connac2_fw_region *region;
|
||||||
|
u32 len, addr, mode;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
region = (const void *)((const u8 *)hdr -
|
||||||
|
(hdr->n_region - i) * sizeof(*region));
|
||||||
|
mode = mt76_connac_mcu_gen_dl_mode(dev, region->feature_set,
|
||||||
|
is_wa);
|
||||||
|
len = le32_to_cpu(region->len);
|
||||||
|
addr = le32_to_cpu(region->addr);
|
||||||
|
|
||||||
|
if (region->feature_set & FW_FEATURE_OVERRIDE_ADDR)
|
||||||
|
override = addr;
|
||||||
|
|
||||||
|
err = mt76_connac_mcu_init_download(dev, addr, len, mode);
|
||||||
|
if (err) {
|
||||||
|
dev_err(dev->dev, "Download request failed\n");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
err = __mt76_mcu_send_firmware(dev, MCU_CMD(FW_SCATTER),
|
||||||
|
data + offset, len, max_len);
|
||||||
|
if (err) {
|
||||||
|
dev_err(dev->dev, "Failed to send firmware.\n");
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
offset += len;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (override)
|
||||||
|
option |= FW_START_OVERRIDE;
|
||||||
|
if (is_wa)
|
||||||
|
option |= FW_START_WORKING_PDA_CR4;
|
||||||
|
|
||||||
|
return mt76_connac_mcu_start_firmware(dev, override, option);
|
||||||
|
}
|
||||||
|
|
||||||
|
int mt76_connac2_load_ram(struct mt76_dev *dev, const char *fw_wm,
|
||||||
|
const char *fw_wa)
|
||||||
|
{
|
||||||
|
const struct mt76_connac2_fw_trailer *hdr;
|
||||||
|
const struct firmware *fw;
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = request_firmware(&fw, fw_wm, dev->dev);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (!fw || !fw->data || fw->size < sizeof(*hdr)) {
|
||||||
|
dev_err(dev->dev, "Invalid firmware\n");
|
||||||
|
ret = -EINVAL;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
hdr = (const void *)(fw->data + fw->size - sizeof(*hdr));
|
||||||
|
dev_info(dev->dev, "WM Firmware Version: %.10s, Build Time: %.15s\n",
|
||||||
|
hdr->fw_ver, hdr->build_date);
|
||||||
|
|
||||||
|
ret = mt76_connac_mcu_send_ram_firmware(dev, hdr, fw->data, false);
|
||||||
|
if (ret) {
|
||||||
|
dev_err(dev->dev, "Failed to start WM firmware\n");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
release_firmware(fw);
|
||||||
|
|
||||||
|
if (!fw_wa)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
ret = request_firmware(&fw, fw_wa, dev->dev);
|
||||||
|
if (ret)
|
||||||
|
return ret;
|
||||||
|
|
||||||
|
if (!fw || !fw->data || fw->size < sizeof(*hdr)) {
|
||||||
|
dev_err(dev->dev, "Invalid firmware\n");
|
||||||
|
ret = -EINVAL;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
hdr = (const void *)(fw->data + fw->size - sizeof(*hdr));
|
||||||
|
dev_info(dev->dev, "WA Firmware Version: %.10s, Build Time: %.15s\n",
|
||||||
|
hdr->fw_ver, hdr->build_date);
|
||||||
|
|
||||||
|
ret = mt76_connac_mcu_send_ram_firmware(dev, hdr, fw->data, true);
|
||||||
|
if (ret) {
|
||||||
|
dev_err(dev->dev, "Failed to start WA firmware\n");
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
|
snprintf(dev->hw->wiphy->fw_version,
|
||||||
|
sizeof(dev->hw->wiphy->fw_version),
|
||||||
|
"%.10s-%.15s", hdr->fw_ver, hdr->build_date);
|
||||||
|
|
||||||
|
out:
|
||||||
|
release_firmware(fw);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
EXPORT_SYMBOL_GPL(mt76_connac2_load_ram);
|
||||||
|
|
||||||
MODULE_AUTHOR("Lorenzo Bianconi <lorenzo@kernel.org>");
|
MODULE_AUTHOR("Lorenzo Bianconi <lorenzo@kernel.org>");
|
||||||
MODULE_LICENSE("Dual BSD/GPL");
|
MODULE_LICENSE("Dual BSD/GPL");
|
||||||
|
|||||||
@@ -1709,4 +1709,6 @@ int mt76_connac_mcu_set_pm(struct mt76_dev *dev, int band, int enter);
|
|||||||
int mt76_connac_mcu_restart(struct mt76_dev *dev);
|
int mt76_connac_mcu_restart(struct mt76_dev *dev);
|
||||||
int mt76_connac_mcu_rdd_cmd(struct mt76_dev *dev, int cmd, u8 index,
|
int mt76_connac_mcu_rdd_cmd(struct mt76_dev *dev, int cmd, u8 index,
|
||||||
u8 rx_sel, u8 val);
|
u8 rx_sel, u8 val);
|
||||||
|
int mt76_connac2_load_ram(struct mt76_dev *dev, const char *fw_wm,
|
||||||
|
const char *fw_wa);
|
||||||
#endif /* __MT76_CONNAC_MCU_H */
|
#endif /* __MT76_CONNAC_MCU_H */
|
||||||
|
|||||||
@@ -2161,115 +2161,6 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
mt7915_mcu_send_ram_firmware(struct mt7915_dev *dev,
|
|
||||||
const struct mt76_connac2_fw_trailer *hdr,
|
|
||||||
const u8 *data, bool is_wa)
|
|
||||||
{
|
|
||||||
int i, offset = 0;
|
|
||||||
u32 override = 0, option = 0;
|
|
||||||
|
|
||||||
for (i = 0; i < hdr->n_region; i++) {
|
|
||||||
const struct mt76_connac2_fw_region *region;
|
|
||||||
u32 len, addr, mode;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
region = (const void *)((const u8 *)hdr -
|
|
||||||
(hdr->n_region - i) * sizeof(*region));
|
|
||||||
mode = mt76_connac_mcu_gen_dl_mode(&dev->mt76,
|
|
||||||
region->feature_set, is_wa);
|
|
||||||
len = le32_to_cpu(region->len);
|
|
||||||
addr = le32_to_cpu(region->addr);
|
|
||||||
|
|
||||||
if (region->feature_set & FW_FEATURE_OVERRIDE_ADDR)
|
|
||||||
override = addr;
|
|
||||||
|
|
||||||
err = mt76_connac_mcu_init_download(&dev->mt76, addr, len,
|
|
||||||
mode);
|
|
||||||
if (err) {
|
|
||||||
dev_err(dev->mt76.dev, "Download request failed\n");
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = __mt76_mcu_send_firmware(&dev->mt76, MCU_CMD(FW_SCATTER),
|
|
||||||
data + offset, len, 4096);
|
|
||||||
if (err) {
|
|
||||||
dev_err(dev->mt76.dev, "Failed to send firmware.\n");
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
offset += len;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (override)
|
|
||||||
option |= FW_START_OVERRIDE;
|
|
||||||
|
|
||||||
if (is_wa)
|
|
||||||
option |= FW_START_WORKING_PDA_CR4;
|
|
||||||
|
|
||||||
return mt76_connac_mcu_start_firmware(&dev->mt76, override, option);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int mt7915_load_ram(struct mt7915_dev *dev)
|
|
||||||
{
|
|
||||||
const struct mt76_connac2_fw_trailer *hdr;
|
|
||||||
const struct firmware *fw;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = request_firmware(&fw, fw_name_var(dev, FIRMWARE_WM),
|
|
||||||
dev->mt76.dev);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if (!fw || !fw->data || fw->size < sizeof(*hdr)) {
|
|
||||||
dev_err(dev->mt76.dev, "Invalid firmware\n");
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
hdr = (const void *)(fw->data + fw->size - sizeof(*hdr));
|
|
||||||
dev_info(dev->mt76.dev, "WM Firmware Version: %.10s, Build Time: %.15s\n",
|
|
||||||
hdr->fw_ver, hdr->build_date);
|
|
||||||
|
|
||||||
ret = mt7915_mcu_send_ram_firmware(dev, hdr, fw->data, false);
|
|
||||||
if (ret) {
|
|
||||||
dev_err(dev->mt76.dev, "Failed to start WM firmware\n");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
release_firmware(fw);
|
|
||||||
|
|
||||||
ret = request_firmware(&fw, fw_name(dev, FIRMWARE_WA),
|
|
||||||
dev->mt76.dev);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if (!fw || !fw->data || fw->size < sizeof(*hdr)) {
|
|
||||||
dev_err(dev->mt76.dev, "Invalid firmware\n");
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
hdr = (const void *)(fw->data + fw->size - sizeof(*hdr));
|
|
||||||
dev_info(dev->mt76.dev, "WA Firmware Version: %.10s, Build Time: %.15s\n",
|
|
||||||
hdr->fw_ver, hdr->build_date);
|
|
||||||
|
|
||||||
ret = mt7915_mcu_send_ram_firmware(dev, hdr, fw->data, true);
|
|
||||||
if (ret) {
|
|
||||||
dev_err(dev->mt76.dev, "Failed to start WA firmware\n");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(dev->mt76.hw->wiphy->fw_version,
|
|
||||||
sizeof(dev->mt76.hw->wiphy->fw_version),
|
|
||||||
"%.10s-%.15s", hdr->fw_ver, hdr->build_date);
|
|
||||||
|
|
||||||
out:
|
|
||||||
release_firmware(fw);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
mt7915_firmware_state(struct mt7915_dev *dev, bool wa)
|
mt7915_firmware_state(struct mt7915_dev *dev, bool wa)
|
||||||
{
|
{
|
||||||
@@ -2304,7 +2195,8 @@ static int mt7915_load_firmware(struct mt7915_dev *dev)
|
|||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
ret = mt7915_load_ram(dev);
|
ret = mt76_connac2_load_ram(&dev->mt76, fw_name_var(dev, FIRMWARE_WM),
|
||||||
|
fw_name(dev, FIRMWARE_WA));
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
|||||||
@@ -542,57 +542,6 @@ out:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
mt7921_mcu_send_ram_firmware(struct mt7921_dev *dev,
|
|
||||||
const struct mt76_connac2_fw_trailer *hdr,
|
|
||||||
const u8 *data, bool is_wa)
|
|
||||||
{
|
|
||||||
int i, offset = 0, max_len;
|
|
||||||
u32 override = 0, option = 0;
|
|
||||||
|
|
||||||
max_len = mt76_is_sdio(&dev->mt76) ? 2048 : 4096;
|
|
||||||
|
|
||||||
for (i = 0; i < hdr->n_region; i++) {
|
|
||||||
const struct mt76_connac2_fw_region *region;
|
|
||||||
u32 len, addr, mode;
|
|
||||||
int err;
|
|
||||||
|
|
||||||
region = (const void *)((const u8 *)hdr -
|
|
||||||
(hdr->n_region - i) * sizeof(*region));
|
|
||||||
mode = mt76_connac_mcu_gen_dl_mode(&dev->mt76,
|
|
||||||
region->feature_set, is_wa);
|
|
||||||
len = le32_to_cpu(region->len);
|
|
||||||
addr = le32_to_cpu(region->addr);
|
|
||||||
|
|
||||||
if (region->feature_set & FW_FEATURE_OVERRIDE_ADDR)
|
|
||||||
override = addr;
|
|
||||||
|
|
||||||
err = mt76_connac_mcu_init_download(&dev->mt76, addr, len,
|
|
||||||
mode);
|
|
||||||
if (err) {
|
|
||||||
dev_err(dev->mt76.dev, "Download request failed\n");
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
err = __mt76_mcu_send_firmware(&dev->mt76, MCU_CMD(FW_SCATTER),
|
|
||||||
data + offset, len, max_len);
|
|
||||||
if (err) {
|
|
||||||
dev_err(dev->mt76.dev, "Failed to send firmware.\n");
|
|
||||||
return err;
|
|
||||||
}
|
|
||||||
|
|
||||||
offset += len;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (override)
|
|
||||||
option |= FW_START_OVERRIDE;
|
|
||||||
|
|
||||||
if (is_wa)
|
|
||||||
option |= FW_START_WORKING_PDA_CR4;
|
|
||||||
|
|
||||||
return mt76_connac_mcu_start_firmware(&dev->mt76, override, option);
|
|
||||||
}
|
|
||||||
|
|
||||||
static char *mt7921_ram_name(struct mt7921_dev *dev)
|
static char *mt7921_ram_name(struct mt7921_dev *dev)
|
||||||
{
|
{
|
||||||
char *ret;
|
char *ret;
|
||||||
@@ -605,42 +554,6 @@ static char *mt7921_ram_name(struct mt7921_dev *dev)
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int mt7921_load_ram(struct mt7921_dev *dev)
|
|
||||||
{
|
|
||||||
const struct mt76_connac2_fw_trailer *hdr;
|
|
||||||
const struct firmware *fw;
|
|
||||||
int ret;
|
|
||||||
|
|
||||||
ret = request_firmware(&fw, mt7921_ram_name(dev), dev->mt76.dev);
|
|
||||||
if (ret)
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
if (!fw || !fw->data || fw->size < sizeof(*hdr)) {
|
|
||||||
dev_err(dev->mt76.dev, "Invalid firmware\n");
|
|
||||||
ret = -EINVAL;
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
hdr = (const void *)(fw->data + fw->size - sizeof(*hdr));
|
|
||||||
dev_info(dev->mt76.dev, "WM Firmware Version: %.10s, Build Time: %.15s\n",
|
|
||||||
hdr->fw_ver, hdr->build_date);
|
|
||||||
|
|
||||||
ret = mt7921_mcu_send_ram_firmware(dev, hdr, fw->data, false);
|
|
||||||
if (ret) {
|
|
||||||
dev_err(dev->mt76.dev, "Failed to start WM firmware\n");
|
|
||||||
goto out;
|
|
||||||
}
|
|
||||||
|
|
||||||
snprintf(dev->mt76.hw->wiphy->fw_version,
|
|
||||||
sizeof(dev->mt76.hw->wiphy->fw_version),
|
|
||||||
"%.10s-%.15s", hdr->fw_ver, hdr->build_date);
|
|
||||||
|
|
||||||
out:
|
|
||||||
release_firmware(fw);
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
static int mt7921_load_firmware(struct mt7921_dev *dev)
|
static int mt7921_load_firmware(struct mt7921_dev *dev)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret;
|
||||||
@@ -662,7 +575,7 @@ static int mt7921_load_firmware(struct mt7921_dev *dev)
|
|||||||
ret = __mt7921_mcu_drv_pmctrl(dev);
|
ret = __mt7921_mcu_drv_pmctrl(dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = mt7921_load_ram(dev);
|
ret = mt76_connac2_load_ram(&dev->mt76, mt7921_ram_name(dev), NULL);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user