提交 336e7b53 编写于 作者: A Anilkumar Kolli 提交者: Kalle Valo

ath11k: clean up BDF download functions

In current code, AHB/PCI uses two separate functions to download
BDF file. Refactor code and make a common function to send QMI BDF
download request for both AHB and PCI devices. This patch has no
functional change.

Tested-on: IPQ8074 hw2.0 AHB WLAN.HK.2.4.0.1-00009-QCAHKSWPL_SILICONZ-1
Tested-on: QCN9074 hw1.0 PCI WLAN.HK.2.4.0.1-01838-QCAHKSWPL_SILICONZ-1
Signed-off-by: NAnilkumar Kolli <akolli@codeaurora.org>
Signed-off-by: NJouni Malinen <jouni@codeaurora.org>
Signed-off-by: NKalle Valo <kvalo@codeaurora.org>
Link: https://lore.kernel.org/r/20210721201927.100369-3-jouni@codeaurora.org
上级 c72aa32d
...@@ -1917,98 +1917,72 @@ static int ath11k_qmi_request_target_cap(struct ath11k_base *ab) ...@@ -1917,98 +1917,72 @@ static int ath11k_qmi_request_target_cap(struct ath11k_base *ab)
return ret; return ret;
} }
static int static int ath11k_qmi_load_file_target_mem(struct ath11k_base *ab,
ath11k_qmi_prepare_bdf_download(struct ath11k_base *ab, int type, const u8 *data, u32 len, u8 type)
struct qmi_wlanfw_bdf_download_req_msg_v01 *req,
void __iomem *bdf_addr)
{
const struct firmware *fw_entry;
struct ath11k_board_data bd;
u32 fw_size;
int ret;
switch (type) {
case ATH11K_QMI_FILE_TYPE_BDF_GOLDEN:
memset(&bd, 0, sizeof(bd));
ret = ath11k_core_fetch_bdf(ab, &bd);
if (ret) {
ath11k_warn(ab, "failed to load board file: %d\n", ret);
return ret;
}
fw_size = min_t(u32, ab->hw_params.fw.board_size, bd.len);
memcpy_toio(bdf_addr, bd.data, fw_size);
ath11k_core_free_bdf(ab, &bd);
break;
case ATH11K_QMI_FILE_TYPE_CALDATA:
fw_entry = ath11k_core_firmware_request(ab, ATH11K_DEFAULT_CAL_FILE);
if (IS_ERR(fw_entry)) {
ret = PTR_ERR(fw_entry);
ath11k_warn(ab, "failed to load %s: %d\n",
ATH11K_DEFAULT_CAL_FILE, ret);
return ret;
}
fw_size = min_t(u32, ab->hw_params.fw.board_size,
fw_entry->size);
memcpy_toio(bdf_addr + ab->hw_params.fw.cal_offset,
fw_entry->data, fw_size);
release_firmware(fw_entry);
break;
default:
return -EINVAL;
}
req->total_size = fw_size;
return 0;
}
static int ath11k_qmi_load_bdf_fixed_addr(struct ath11k_base *ab)
{ {
struct qmi_wlanfw_bdf_download_req_msg_v01 *req; struct qmi_wlanfw_bdf_download_req_msg_v01 *req;
struct qmi_wlanfw_bdf_download_resp_msg_v01 resp; struct qmi_wlanfw_bdf_download_resp_msg_v01 resp;
struct qmi_txn txn = {}; struct qmi_txn txn = {};
const u8 *temp = data;
void __iomem *bdf_addr = NULL; void __iomem *bdf_addr = NULL;
int type, ret; int ret;
u32 remaining = len;
req = kzalloc(sizeof(*req), GFP_KERNEL); req = kzalloc(sizeof(*req), GFP_KERNEL);
if (!req) if (!req)
return -ENOMEM; return -ENOMEM;
memset(&resp, 0, sizeof(resp)); memset(&resp, 0, sizeof(resp));
bdf_addr = ioremap(ab->hw_params.bdf_addr, ab->hw_params.fw.board_size); if (ab->bus_params.fixed_bdf_addr) {
if (!bdf_addr) { bdf_addr = ioremap(ab->hw_params.bdf_addr, ab->hw_params.fw.board_size);
ath11k_warn(ab, "failed ioremap for board file\n"); if (!bdf_addr) {
ret = -EIO; ath11k_warn(ab, "qmi ioremap error for bdf_addr\n");
goto out; ret = -EIO;
goto err_free_req;
}
} }
for (type = 0; type < ATH11K_QMI_MAX_FILE_TYPE; type++) { while (remaining) {
req->valid = 1; req->valid = 1;
req->file_id_valid = 1; req->file_id_valid = 1;
req->file_id = ab->qmi.target.board_id; req->file_id = ab->qmi.target.board_id;
req->total_size_valid = 1; req->total_size_valid = 1;
req->total_size = remaining;
req->seg_id_valid = 1; req->seg_id_valid = 1;
req->seg_id = type; req->data_valid = 1;
req->data_valid = 0; req->bdf_type = type;
req->data_len = ATH11K_QMI_MAX_BDF_FILE_NAME_SIZE; req->bdf_type_valid = 1;
req->bdf_type = 0;
req->bdf_type_valid = 0;
req->end_valid = 1; req->end_valid = 1;
req->end = 1; req->end = 0;
ret = ath11k_qmi_prepare_bdf_download(ab, type, req, bdf_addr); if (remaining > QMI_WLANFW_MAX_DATA_SIZE_V01) {
if (ret < 0) req->data_len = QMI_WLANFW_MAX_DATA_SIZE_V01;
goto out_qmi_bdf; } else {
req->data_len = remaining;
req->end = 1;
}
if (ab->bus_params.fixed_bdf_addr) {
req->data_valid = 0;
req->end = 1;
req->data_len = ATH11K_QMI_MAX_BDF_FILE_NAME_SIZE;
} else {
memcpy(req->data, temp, req->data_len);
}
if (ab->bus_params.fixed_bdf_addr) {
if (type == ATH11K_QMI_FILE_TYPE_CALDATA)
bdf_addr += ab->hw_params.fw.cal_offset;
memcpy_toio(bdf_addr, temp, len);
}
ret = qmi_txn_init(&ab->qmi.handle, &txn, ret = qmi_txn_init(&ab->qmi.handle, &txn,
qmi_wlanfw_bdf_download_resp_msg_v01_ei, qmi_wlanfw_bdf_download_resp_msg_v01_ei,
&resp); &resp);
if (ret < 0) if (ret < 0)
goto out_qmi_bdf; goto err_iounmap;
ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi bdf download req fixed addr type %d\n", ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi bdf download req fixed addr type %d\n",
type); type);
...@@ -2019,54 +1993,59 @@ static int ath11k_qmi_load_bdf_fixed_addr(struct ath11k_base *ab) ...@@ -2019,54 +1993,59 @@ static int ath11k_qmi_load_bdf_fixed_addr(struct ath11k_base *ab)
qmi_wlanfw_bdf_download_req_msg_v01_ei, req); qmi_wlanfw_bdf_download_req_msg_v01_ei, req);
if (ret < 0) { if (ret < 0) {
qmi_txn_cancel(&txn); qmi_txn_cancel(&txn);
goto out_qmi_bdf; goto err_iounmap;
} }
ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS)); ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS));
if (ret < 0) if (ret < 0) {
goto out_qmi_bdf; ath11k_warn(ab, "failed to wait board file download request: %d\n",
ret);
goto err_iounmap;
}
if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { if (resp.resp.result != QMI_RESULT_SUCCESS_V01) {
ath11k_warn(ab, "board file download request failed: %d %d\n", ath11k_warn(ab, "board file download request failed: %d %d\n",
resp.resp.result, resp.resp.error); resp.resp.result, resp.resp.error);
ret = -EINVAL; ret = -EINVAL;
goto out_qmi_bdf; goto err_iounmap;
}
if (ab->bus_params.fixed_bdf_addr) {
remaining = 0;
} else {
remaining -= req->data_len;
temp += req->data_len;
req->seg_id++;
ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi bdf download request remaining %i\n",
remaining);
} }
} }
out_qmi_bdf: err_iounmap:
iounmap(bdf_addr); if (ab->bus_params.fixed_bdf_addr)
out: iounmap(bdf_addr);
err_free_req:
kfree(req); kfree(req);
return ret; return ret;
} }
static int ath11k_qmi_load_bdf_qmi(struct ath11k_base *ab) static int ath11k_qmi_load_bdf_qmi(struct ath11k_base *ab)
{ {
struct qmi_wlanfw_bdf_download_req_msg_v01 *req; char filename[ATH11K_QMI_MAX_BDF_FILE_NAME_SIZE];
struct qmi_wlanfw_bdf_download_resp_msg_v01 resp; const struct firmware *fw_entry;
struct ath11k_board_data bd; struct ath11k_board_data bd;
unsigned int remaining; u32 fw_size, file_type;
struct qmi_txn txn = {}; int ret = 0, bdf_type;
int ret;
const u8 *temp;
int bdf_type;
req = kzalloc(sizeof(*req), GFP_KERNEL);
if (!req)
return -ENOMEM;
memset(&resp, 0, sizeof(resp));
memset(&bd, 0, sizeof(bd)); memset(&bd, 0, sizeof(bd));
ret = ath11k_core_fetch_bdf(ab, &bd); ret = ath11k_core_fetch_bdf(ab, &bd);
if (ret) { if (ret) {
ath11k_warn(ab, "failed to fetch board file: %d\n", ret); ath11k_warn(ab, "qmi failed to fetch board file: %d\n", ret);
goto out; goto out;
} }
temp = bd.data;
remaining = bd.len;
if (bd.len >= SELFMAG && memcmp(bd.data, ELFMAG, SELFMAG) == 0) if (bd.len >= SELFMAG && memcmp(bd.data, ELFMAG, SELFMAG) == 0)
bdf_type = ATH11K_QMI_BDF_TYPE_ELF; bdf_type = ATH11K_QMI_BDF_TYPE_ELF;
else else
...@@ -2074,67 +2053,45 @@ static int ath11k_qmi_load_bdf_qmi(struct ath11k_base *ab) ...@@ -2074,67 +2053,45 @@ static int ath11k_qmi_load_bdf_qmi(struct ath11k_base *ab)
ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi bdf_type %d\n", bdf_type); ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi bdf_type %d\n", bdf_type);
while (remaining) { fw_size = bd.len;
req->valid = 1; fw_size = min_t(u32, ab->hw_params.fw.board_size, bd.len);
req->file_id_valid = 1;
req->file_id = ab->qmi.target.board_id;
req->total_size_valid = 1;
req->total_size = bd.len;
req->seg_id_valid = 1;
req->data_valid = 1;
req->data_len = ATH11K_QMI_MAX_BDF_FILE_NAME_SIZE;
req->bdf_type = bdf_type;
req->bdf_type_valid = 1;
req->end_valid = 1;
req->end = 0;
if (remaining > QMI_WLANFW_MAX_DATA_SIZE_V01) {
req->data_len = QMI_WLANFW_MAX_DATA_SIZE_V01;
} else {
req->data_len = remaining;
req->end = 1;
}
memcpy(req->data, temp, req->data_len);
ret = qmi_txn_init(&ab->qmi.handle, &txn,
qmi_wlanfw_bdf_download_resp_msg_v01_ei,
&resp);
if (ret < 0)
goto out_qmi_bdf;
ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi bdf download request remaining %i\n", ret = ath11k_qmi_load_file_target_mem(ab, bd.data, fw_size, bdf_type);
remaining); if (ret < 0) {
ath11k_warn(ab, "qmi failed to load bdf file\n");
goto out;
}
ret = qmi_send_request(&ab->qmi.handle, NULL, &txn, /* QCA6390 does not support cal data file, skip it */
QMI_WLANFW_BDF_DOWNLOAD_REQ_V01, if (bdf_type == ATH11K_QMI_BDF_TYPE_ELF)
QMI_WLANFW_BDF_DOWNLOAD_REQ_MSG_V01_MAX_LEN, goto out;
qmi_wlanfw_bdf_download_req_msg_v01_ei, req);
if (ret < 0) {
qmi_txn_cancel(&txn);
goto out_qmi_bdf;
}
ret = qmi_txn_wait(&txn, msecs_to_jiffies(ATH11K_QMI_WLANFW_TIMEOUT_MS)); file_type = ATH11K_QMI_FILE_TYPE_CALDATA;
if (ret < 0) fw_entry = ath11k_core_firmware_request(ab, ATH11K_DEFAULT_CAL_FILE);
goto out_qmi_bdf; if (IS_ERR(fw_entry)) {
ret = PTR_ERR(fw_entry);
ath11k_warn(ab,
"qmi failed to load CAL data file:%s\n",
filename);
goto out;
}
if (resp.resp.result != QMI_RESULT_SUCCESS_V01) { fw_size = min_t(u32, ab->hw_params.fw.board_size, fw_entry->size);
ath11k_warn(ab, "bdf download request failed: %d %d\n", ret = ath11k_qmi_load_file_target_mem(ab, fw_entry->data, fw_size, file_type);
resp.resp.result, resp.resp.error); if (ret < 0) {
ret = resp.resp.result; ath11k_warn(ab, "qmi failed to load caldata\n");
goto out_qmi_bdf; goto out_qmi_cal;
}
remaining -= req->data_len;
temp += req->data_len;
req->seg_id++;
} }
out_qmi_bdf: ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi caldata downloaded: type: %u\n",
ath11k_core_free_bdf(ab, &bd); file_type);
out_qmi_cal:
release_firmware(fw_entry);
out: out:
kfree(req); ath11k_core_free_bdf(ab, &bd);
ath11k_dbg(ab, ATH11K_DBG_QMI, "qmi BDF download sequence completed\n");
return ret; return ret;
} }
...@@ -2519,10 +2476,7 @@ static int ath11k_qmi_event_load_bdf(struct ath11k_qmi *qmi) ...@@ -2519,10 +2476,7 @@ static int ath11k_qmi_event_load_bdf(struct ath11k_qmi *qmi)
return ret; return ret;
} }
if (ab->bus_params.fixed_bdf_addr) ret = ath11k_qmi_load_bdf_qmi(ab);
ret = ath11k_qmi_load_bdf_fixed_addr(ab);
else
ret = ath11k_qmi_load_bdf_qmi(ab);
if (ret < 0) { if (ret < 0) {
ath11k_warn(ab, "failed to load board data file: %d\n", ret); ath11k_warn(ab, "failed to load board data file: %d\n", ret);
return ret; return ret;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册