Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 38244eca authored by Yuanyuan Liu's avatar Yuanyuan Liu
Browse files

cnss2: re-arch cnss_wlfw_bdf_dnld_send_sync



Re-arch cnss_wlfw_bdf_dnld_send_sync to reduce code complexity.
Create a new function to get BDF file name. This function will
be called later by cnss_wlfw_bdf_dnld_send_sync.

CRs-Fixed: 2510015
Change-Id: I2b6c0e34060c985c07790075796a103e57520ff8
Signed-off-by: default avatarYuanyuan Liu <yuanliu@codeaurora.org>
parent c128dbdf
Loading
Loading
Loading
Loading
+50 −33
Original line number Diff line number Diff line
@@ -432,71 +432,88 @@ int cnss_wlfw_tgt_cap_send_sync(struct cnss_plat_data *plat_priv)
	return ret;
}

int cnss_wlfw_bdf_dnld_send_sync(struct cnss_plat_data *plat_priv,
				 u32 bdf_type)
static int cnss_get_bdf_file_name(struct cnss_plat_data *plat_priv,
				  u32 bdf_type, char *filename,
				  u32 filename_len)
{
	struct wlfw_bdf_download_req_msg_v01 *req;
	struct wlfw_bdf_download_resp_msg_v01 *resp;
	struct qmi_txn txn;
	char filename[MAX_BDF_FILE_NAME];
	const struct firmware *fw_entry;
	const u8 *temp;
	unsigned int remaining;
	int ret = 0;

	cnss_pr_dbg("Sending BDF download message, state: 0x%lx, type: %d\n",
		    plat_priv->driver_state, bdf_type);

	req = kzalloc(sizeof(*req), GFP_KERNEL);
	if (!req)
		return -ENOMEM;

	resp = kzalloc(sizeof(*resp), GFP_KERNEL);
	if (!resp) {
		kfree(req);
		return -ENOMEM;
	}

	switch (bdf_type) {
	case CNSS_BDF_ELF:
		if (plat_priv->board_info.board_id == 0xFF)
			snprintf(filename, sizeof(filename), ELF_BDF_FILE_NAME);
			snprintf(filename, filename_len, ELF_BDF_FILE_NAME);
		else if (plat_priv->board_info.board_id < 0xFF)
			snprintf(filename, sizeof(filename),
			snprintf(filename, filename_len,
				 ELF_BDF_FILE_NAME_PREFIX "%02x",
				 plat_priv->board_info.board_id);
		else
			snprintf(filename, sizeof(filename),
			snprintf(filename, filename_len,
				 BDF_FILE_NAME_PREFIX "%02x.e%02x",
				 plat_priv->board_info.board_id >> 8 & 0xFF,
				 plat_priv->board_info.board_id & 0xFF);
		break;
	case CNSS_BDF_BIN:
		if (plat_priv->board_info.board_id == 0xFF)
			snprintf(filename, sizeof(filename), BIN_BDF_FILE_NAME);
			snprintf(filename, filename_len, BIN_BDF_FILE_NAME);
		else if (plat_priv->board_info.board_id < 0xFF)
			snprintf(filename, sizeof(filename),
			snprintf(filename, filename_len,
				 BIN_BDF_FILE_NAME_PREFIX "%02x",
				 plat_priv->board_info.board_id);
		else
			snprintf(filename, sizeof(filename),
			snprintf(filename, filename_len,
				 BDF_FILE_NAME_PREFIX "%02x.b%02x",
				 plat_priv->board_info.board_id >> 8 & 0xFF,
				 plat_priv->board_info.board_id & 0xFF);
		break;
	case CNSS_BDF_REGDB:
		snprintf(filename, sizeof(filename), REGDB_FILE_NAME);
		snprintf(filename, filename_len, REGDB_FILE_NAME);
		break;
	case CNSS_BDF_DUMMY:
		cnss_pr_dbg("CNSS_BDF_DUMMY is set, sending dummy BDF\n");
		snprintf(filename, sizeof(filename), DUMMY_BDF_FILE_NAME);
		temp = DUMMY_BDF_FILE_NAME;
		remaining = MAX_BDF_FILE_NAME;
		goto bypass_bdf;
		snprintf(filename, filename_len, DUMMY_BDF_FILE_NAME);
		ret = MAX_BDF_FILE_NAME;
		break;
	default:
		cnss_pr_err("Invalid BDF type: %d\n",
			    plat_priv->ctrl_params.bdf_type);
		ret = -EINVAL;
		break;
	}
	return ret;
}

int cnss_wlfw_bdf_dnld_send_sync(struct cnss_plat_data *plat_priv,
				 u32 bdf_type)
{
	struct wlfw_bdf_download_req_msg_v01 *req;
	struct wlfw_bdf_download_resp_msg_v01 *resp;
	struct qmi_txn txn;
	char filename[MAX_BDF_FILE_NAME];
	const struct firmware *fw_entry;
	const u8 *temp;
	unsigned int remaining;
	int ret = 0;

	cnss_pr_dbg("Sending BDF download message, state: 0x%lx, type: %d\n",
		    plat_priv->driver_state, bdf_type);

	req = kzalloc(sizeof(*req), GFP_KERNEL);
	if (!req)
		return -ENOMEM;

	resp = kzalloc(sizeof(*resp), GFP_KERNEL);
	if (!resp) {
		kfree(req);
		return -ENOMEM;
	}

	ret = cnss_get_bdf_file_name(plat_priv, bdf_type,
				     filename, sizeof(filename));
	if (ret > 0) {
		temp = DUMMY_BDF_FILE_NAME;
		remaining = MAX_BDF_FILE_NAME;
		goto bypass_bdf;
	} else if (ret < 0) {
		goto err_req_fw;
	}