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

Commit 9217418c authored by Jilai Wang's avatar Jilai Wang
Browse files

msm: npu: Retry fw loading if it doesn't boot up properly



If fw doesn't boot up properly, retry couple times to avoid fw
loading failure.

Change-Id: I1078bacbcef7a7be883a1161cdd9f61fa23a168c
Signed-off-by: default avatarJilai Wang <jilaiw@codeaurora.org>
parent 0358bf07
Loading
Loading
Loading
Loading
+17 −3
Original line number Original line Diff line number Diff line
@@ -74,7 +74,8 @@ int fw_init(struct npu_device *npu_dev)
{
{
	uint32_t reg_val;
	uint32_t reg_val;
	struct npu_host_ctx *host_ctx = &npu_dev->host_ctx;
	struct npu_host_ctx *host_ctx = &npu_dev->host_ctx;
	int ret = 0;
	int ret = 0, retry_cnt = 3;
	bool need_retry;


	mutex_lock(&host_ctx->lock);
	mutex_lock(&host_ctx->lock);
	if (host_ctx->fw_state == FW_ENABLED) {
	if (host_ctx->fw_state == FW_ENABLED) {
@@ -83,6 +84,8 @@ int fw_init(struct npu_device *npu_dev)
		return 0;
		return 0;
	}
	}


retry:
	need_retry = false;
	npu_notify_aop(npu_dev, true);
	npu_notify_aop(npu_dev, true);


	if (npu_enable_core_power(npu_dev)) {
	if (npu_enable_core_power(npu_dev)) {
@@ -139,14 +142,19 @@ int fw_init(struct npu_device *npu_dev)
	REGW(npu_dev, REG_NPU_HOST_CTRL_STATUS, reg_val);
	REGW(npu_dev, REG_NPU_HOST_CTRL_STATUS, reg_val);


	/* Initialize the host side IPC */
	/* Initialize the host side IPC */
	npu_host_ipc_pre_init(npu_dev);
	ret = npu_host_ipc_pre_init(npu_dev);
	if (ret) {
		pr_err("npu_host_ipc_pre_init failed %d\n", ret);
		goto enable_post_clk_fail;
	}


	/* Keep reading ctrl status until NPU is ready */
	/* Keep reading ctrl status until NPU is ready */
	pr_debug("waiting for status ready from fw\n");
	pr_debug("waiting for status ready from fw\n");


	if (wait_for_status_ready(npu_dev, REG_NPU_FW_CTRL_STATUS,
	if (wait_for_status_ready(npu_dev, REG_NPU_FW_CTRL_STATUS,
		FW_CTRL_STATUS_MAIN_THREAD_READY_BIT)) {
		FW_CTRL_STATUS_MAIN_THREAD_READY_VAL)) {
		ret = -EPERM;
		ret = -EPERM;
		need_retry = true;
		goto wait_fw_ready_fail;
		goto wait_fw_ready_fail;
	}
	}


@@ -183,7 +191,13 @@ int fw_init(struct npu_device *npu_dev)
enable_sys_cache_fail:
enable_sys_cache_fail:
	npu_disable_core_power(npu_dev);
	npu_disable_core_power(npu_dev);
enable_pw_fail:
enable_pw_fail:
	npu_notify_aop(npu_dev, false);
	host_ctx->fw_state = FW_DISABLED;
	host_ctx->fw_state = FW_DISABLED;
	if (need_retry && (retry_cnt > 0)) {
		retry_cnt--;
		pr_warn("retry fw init %d\n", retry_cnt);
		goto retry;
	}
	mutex_unlock(&host_ctx->lock);
	mutex_unlock(&host_ctx->lock);
	return ret;
	return ret;
}
}