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

Commit 63ada55c authored by Jilai Wang's avatar Jilai Wang
Browse files

msm: npu: misc error fixes



This change is to correct some minor problems, such as debug message
format, unused variables, proper function usage and handle error case
properly.

Change-Id: I9390f1f875b52fa0770281a8a999847e32198acc
Signed-off-by: default avatarJilai Wang <jilaiw@codeaurora.org>
parent b90a8e32
Loading
Loading
Loading
Loading
+7 −4
Original line number Diff line number Diff line
@@ -200,7 +200,7 @@ static ssize_t npu_debug_reg_read(struct file *file,
		return 0; /* done reading */

	len = min(count, debugfs->buf_len - (size_t) *ppos);
	pr_debug("read %zi %zi", count, debugfs->buf_len - (size_t) *ppos);
	pr_debug("read %zi %zi\n", count, debugfs->buf_len - (size_t) *ppos);
	if (copy_to_user(user_buf, debugfs->buf + *ppos, len)) {
		pr_err("failed to copy to user\n");
		return -EFAULT;
@@ -305,7 +305,8 @@ static ssize_t npu_debug_log_read(struct file *file,

			if (copy_to_user(dst_addr, src_addr,
				remaining_to_end)) {
				pr_err("%s failed to copy to user", __func__);
				pr_err("%s failed to copy to user\n", __func__);
				mutex_unlock(&debugfs->log_lock);
				return -EFAULT;
			}
			src_addr = debugfs->log_buf;
@@ -313,7 +314,8 @@ static ssize_t npu_debug_log_read(struct file *file,
			if (copy_to_user(dst_addr, src_addr,
				debugfs->log_num_bytes_buffered -
				remaining_to_end)) {
				pr_err("%s failed to copy to user", __func__);
				pr_err("%s failed to copy to user\n", __func__);
				mutex_unlock(&debugfs->log_lock);
				return -EFAULT;
			}
			debugfs->log_read_index =
@@ -323,7 +325,8 @@ static ssize_t npu_debug_log_read(struct file *file,
			if (copy_to_user(user_buf, (debugfs->log_buf +
				debugfs->log_read_index),
				debugfs->log_num_bytes_buffered)) {
				pr_err("%s failed to copy to user", __func__);
				pr_err("%s failed to copy to user\n", __func__);
				mutex_unlock(&debugfs->log_lock);
				return -EFAULT;
			}
			debugfs->log_read_index +=
+22 −15
Original line number Diff line number Diff line
@@ -249,7 +249,7 @@ static ssize_t npu_show_capabilities(struct device *dev,
	struct npu_device *npu_dev = dev_get_drvdata(dev);

	if (!npu_enable_core_power(npu_dev)) {
		if (snprintf(buf, PAGE_SIZE, "hw_version :0x%X",
		if (scnprintf(buf, PAGE_SIZE, "hw_version :0x%X",
			REGR(npu_dev, NPU_HW_VERSION)) < 0)
			ret = -EINVAL;
		npu_disable_core_power(npu_dev);
@@ -270,7 +270,7 @@ static ssize_t npu_show_pwr_state(struct device *dev,
	struct npu_device *npu_dev = dev_get_drvdata(dev);
	struct npu_pwrctrl *pwr = &npu_dev->pwrctrl;

	return snprintf(buf, PAGE_SIZE, "%s\n",
	return scnprintf(buf, PAGE_SIZE, "%s\n",
			(pwr->pwr_vote_num > 0) ? "on" : "off");
}

@@ -1744,7 +1744,7 @@ static int npu_of_parse_pwrlevels(struct npu_device *npu_dev,
	}

	of_property_read_u32(node, "initial-pwrlevel", &init_level_index);
	pr_debug("initial-pwrlevel %d", init_level_index);
	pr_debug("initial-pwrlevel %d\n", init_level_index);

	if (init_level_index >= pwr->num_pwrlevels)
		init_level_index = pwr->num_pwrlevels - 1;
@@ -1813,11 +1813,10 @@ static int npu_thermalctrl_init(struct npu_device *npu_dev)
{
	struct npu_pwrctrl *pwr = &npu_dev->pwrctrl;
	struct npu_thermalctrl *thermalctrl = &npu_dev->thermalctrl;
	int ret = 0;

	thermalctrl->max_state = pwr->num_pwrlevels - 1;
	thermalctrl->current_state = 0;
	return ret;
	return 0;
}

static int npu_irq_init(struct npu_device *npu_dev)
@@ -1877,6 +1876,14 @@ static int npu_mbox_init(struct npu_device *npu_dev)
	return 0;
}

static void npu_mbox_deinit(struct npu_device *npu_dev)
{
	if (npu_dev->mbox_aop.chan) {
		mbox_free_channel(npu_dev->mbox_aop.chan);
		npu_dev->mbox_aop.chan = NULL;
	}
}

/* -------------------------------------------------------------------------
 * Probe/Remove
 * -------------------------------------------------------------------------
@@ -1999,7 +2006,7 @@ static int npu_probe(struct platform_device *pdev)
							  &npu_cooling_ops);
		if (IS_ERR(tcdev)) {
			dev_err(&pdev->dev,
				"npu: failed to register npu as cooling device");
				"npu: failed to register npu as cooling device\n");
			rc = PTR_ERR(tcdev);
			goto error_driver_init;
		}
@@ -2044,11 +2051,12 @@ static int npu_probe(struct platform_device *pdev)

	return rc;
error_driver_init:
	npu_cdsprm_cxlimit_deinit(npu_dev);
	sysfs_remove_group(&npu_dev->device->kobj, &npu_fs_attr_group);
	arm_iommu_detach_device(&(npu_dev->pdev->dev));
	if (!npu_dev->smmu_ctx.mmu_mapping)
		arm_iommu_release_mapping(npu_dev->smmu_ctx.mmu_mapping);
	npu_cdsprm_cxlimit_deinit(npu_dev);
	if (npu_dev->tcdev)
		thermal_cooling_device_unregister(npu_dev->tcdev);
	sysfs_remove_group(&npu_dev->device->kobj, &npu_fs_attr_group);
error_res_init:
	cdev_del(&npu_dev->cdev);
@@ -2058,8 +2066,7 @@ static int npu_probe(struct platform_device *pdev)
	class_destroy(npu_dev->class);
error_class_create:
	unregister_chrdev_region(npu_dev->dev_num, 1);
	if (npu_dev->mbox_aop.chan)
		mbox_free_channel(npu_dev->mbox_aop.chan);
	npu_mbox_deinit(npu_dev);
error_get_dev_num:
	return rc;
}
@@ -2069,20 +2076,20 @@ static int npu_remove(struct platform_device *pdev)
	struct npu_device *npu_dev;

	npu_dev = platform_get_drvdata(pdev);
	thermal_cooling_device_unregister(npu_dev->tcdev);
	npu_cdsprm_cxlimit_deinit(npu_dev);
	npu_debugfs_deinit(npu_dev);
	npu_host_deinit(npu_dev);
	arm_iommu_detach_device(&(npu_dev->pdev->dev));
	arm_iommu_release_mapping(npu_dev->smmu_ctx.mmu_mapping);
	npu_debugfs_deinit(npu_dev);
	npu_cdsprm_cxlimit_deinit(npu_dev);
	if (npu_dev->tcdev)
		thermal_cooling_device_unregister(npu_dev->tcdev);
	sysfs_remove_group(&npu_dev->device->kobj, &npu_fs_attr_group);
	cdev_del(&npu_dev->cdev);
	device_destroy(npu_dev->class, npu_dev->dev_num);
	class_destroy(npu_dev->class);
	unregister_chrdev_region(npu_dev->dev_num, 1);
	platform_set_drvdata(pdev, NULL);
	if (npu_dev->mbox_aop.chan)
		mbox_free_channel(npu_dev->mbox_aop.chan);
	npu_mbox_deinit(npu_dev);

	g_npu_dev = NULL;

+3 −3
Original line number Diff line number Diff line
@@ -175,9 +175,9 @@ static int npu_host_ipc_send_cmd_hfi(struct npu_device *npu_dev,
	}

	if (status == 0)
		pr_debug("Cmd Msg put on Command Queue - SUCCESSS");
		pr_debug("Cmd Msg put on Command Queue - SUCCESSS\n");
	else
		pr_err("Cmd Msg put on Command Queue - FAILURE");
		pr_err("Cmd Msg put on Command Queue - FAILURE\n");

	return status;
}
@@ -238,7 +238,7 @@ static int ipc_queue_read(struct npu_device *npu_dev,
	MEMR(npu_dev, (void *)((size_t)read_ptr), packet, 4);
	packet_size = *((uint32_t *)packet);

	pr_debug("target_que: %d, packet_size: %d ",
	pr_debug("target_que: %d, packet_size: %d\n",
			target_que,
			packet_size);

+1 −3
Original line number Diff line number Diff line
@@ -148,15 +148,13 @@ void npu_interrupt_ack(struct npu_device *npu_dev, uint32_t intr_num)

int32_t npu_interrupt_raise_m0(struct npu_device *npu_dev)
{
	int ret = 0;

	/* Bit 4 is setting IRQ_SOURCE_SELECT to local
	 * and we're triggering a pulse to NPU_MASTER0_IPC_IN_IRQ0
	 */
	npu_reg_write(npu_dev, NPU_MASTERn_IPC_IRQ_IN_CTRL(0), 0x1
		<< NPU_MASTER0_IPC_IRQ_IN_CTRL__IRQ_SOURCE_SELECT___S | 0x1);

	return ret;
	return 0;
}

int32_t npu_interrupt_raise_dsp(struct npu_device *npu_dev)
+8 −9
Original line number Diff line number Diff line
@@ -75,6 +75,7 @@ int fw_init(struct npu_device *npu_dev)
	uint32_t reg_val;
	struct npu_host_ctx *host_ctx = &npu_dev->host_ctx;
	int ret = 0;

	mutex_lock(&host_ctx->lock);
	if (host_ctx->fw_state == FW_ENABLED) {
		host_ctx->fw_ref_cnt++;
@@ -270,8 +271,6 @@ void fw_deinit(struct npu_device *npu_dev, bool ssr, bool fw_alive)
	mutex_unlock(&host_ctx->lock);
	pr_debug("firmware deinit complete\n");
	npu_notify_aop(npu_dev, false);

	return;
}

int npu_host_init(struct npu_device *npu_dev)
@@ -315,7 +314,7 @@ irqreturn_t npu_intr_hdler(int irq, void *ptr)
	INTERRUPT_ACK(npu_dev, irq);

	/* Check that the event thread currently is running */
	if (host_ctx->wq != 0)
	if (host_ctx->wq)
		queue_work(host_ctx->wq, &host_ctx->irq_work);

	return IRQ_HANDLED;
@@ -471,7 +470,7 @@ static int npu_notify_aop(struct npu_device *npu_dev, bool on)
		return 0;
	}

	buf_size = snprintf(buf, MAX_LEN, "{class: bcm, res: npu_on, val: %d}",
	buf_size = scnprintf(buf, MAX_LEN, "{class: bcm, res: npu_on, val: %d}",
		on ? 1 : 0);
	if (buf_size < 0) {
		pr_err("prepare qmp notify buf failed\n");
@@ -656,7 +655,7 @@ static void app_msg_proc(struct npu_host_ctx *host_ctx, uint32_t *msg)

		pr_debug("NPU_IPC_MSG_EXECUTE_DONE status: %d\n",
			exe_rsp_pkt->header.status);
		pr_debug("trans_id : %d", exe_rsp_pkt->header.trans_id);
		pr_debug("trans_id : %d\n", exe_rsp_pkt->header.trans_id);
		pr_debug("e2e_IPC_time: %d (in tick count)\n",
			exe_rsp_pkt->stats.e2e_ipc_tick_count);
		pr_debug("aco_load_time: %d (in tick count)\n",
@@ -709,7 +708,7 @@ static void app_msg_proc(struct npu_host_ctx *host_ctx, uint32_t *msg)

		pr_debug("NPU_IPC_MSG_EXECUTE_V2_DONE status: %d\n",
			exe_rsp_pkt->header.status);
		pr_debug("trans_id : %d", exe_rsp_pkt->header.trans_id);
		pr_debug("trans_id : %d\n", exe_rsp_pkt->header.trans_id);

		network = get_network_by_hdl(host_ctx, NULL,
			exe_rsp_pkt->network_hdl);
@@ -727,7 +726,7 @@ static void app_msg_proc(struct npu_host_ctx *host_ctx, uint32_t *msg)
			break;
		}

		pr_debug("network id : %d", network->id);
		pr_debug("network id : %d\n", network->id);
		stats_size = exe_rsp_pkt->header.size - sizeof(*exe_rsp_pkt);
		pr_debug("stats_size %d:%d\n", exe_rsp_pkt->header.size,
			stats_size);
@@ -1384,7 +1383,7 @@ int32_t npu_host_unload_network(struct npu_client *client,
		pr_err("fw is in error state during unload network\n");
	} else {
		ret = network->cmd_ret_status;
		pr_debug("unload network status %d", ret);
		pr_debug("unload network status %d\n", ret);
	}

free_network:
@@ -1516,7 +1515,7 @@ int32_t npu_host_exec_network(struct npu_client *client,
		pr_err("fw is in error state during execute network\n");
	} else {
		ret = network->cmd_ret_status;
		pr_debug("execution status %d", ret);
		pr_debug("execution status %d\n", ret);
	}

exec_done: