Commit cf30339d authored by Ohad Sharabi's avatar Ohad Sharabi Committed by Oded Gabbay
Browse files

habanalabs: modify device_idle interface



Currently this API uses single 64 bits mask for engines idle indication.
Recently, it was observed that more bits are needed for some ASICs.
This patch modifies the use of the idle mask and the idle_extensions
mask.

Signed-off-by: default avatarOhad Sharabi <osharabi@habana.ai>
Reviewed-by: default avatarOded Gabbay <ogabbay@kernel.org>
Signed-off-by: default avatarOded Gabbay <ogabbay@kernel.org>
parent 0811b391
Loading
Loading
Loading
Loading
+5 −4
Original line number Diff line number Diff line
@@ -12,7 +12,7 @@
static void hl_ctx_fini(struct hl_ctx *ctx)
{
	struct hl_device *hdev = ctx->hdev;
	u64 idle_mask = 0;
	u64 idle_mask[HL_BUSY_ENGINES_MASK_EXT_SIZE] = {0};
	int i;

	/* Release all allocated pending cb's, those cb's were never
@@ -55,10 +55,11 @@ static void hl_ctx_fini(struct hl_ctx *ctx)

		if ((!hdev->pldm) && (hdev->pdev) &&
				(!hdev->asic_funcs->is_device_idle(hdev,
							&idle_mask, NULL)))
					idle_mask,
					HL_BUSY_ENGINES_MASK_EXT_SIZE, NULL)))
			dev_notice(hdev->dev,
				"device not idle after user context is closed (0x%llx)\n",
				idle_mask);
					"device not idle after user context is closed (0x%llx, 0x%llx)\n",
						idle_mask[0], idle_mask[1]);
	} else {
		dev_dbg(hdev->dev, "closing kernel context\n");
		hdev->asic_funcs->ctx_fini(ctx);
+1 −1
Original line number Diff line number Diff line
@@ -414,7 +414,7 @@ static int engines_show(struct seq_file *s, void *data)
		return 0;
	}

	hdev->asic_funcs->is_device_idle(hdev, NULL, s);
	hdev->asic_funcs->is_device_idle(hdev, NULL, 0, s);

	return 0;
}
+2 −2
Original line number Diff line number Diff line
@@ -933,8 +933,8 @@ struct hl_asic_funcs {
	void (*set_clock_gating)(struct hl_device *hdev);
	void (*disable_clock_gating)(struct hl_device *hdev);
	int (*debug_coresight)(struct hl_device *hdev, void *data);
	bool (*is_device_idle)(struct hl_device *hdev, u64 *mask,
				struct seq_file *s);
	bool (*is_device_idle)(struct hl_device *hdev, u64 *mask_arr,
					u8 mask_len, struct seq_file *s);
	int (*soft_reset_late_init)(struct hl_device *hdev);
	void (*hw_queues_lock)(struct hl_device *hdev);
	void (*hw_queues_unlock)(struct hl_device *hdev);
+3 −2
Original line number Diff line number Diff line
@@ -145,9 +145,10 @@ static int hw_idle(struct hl_device *hdev, struct hl_info_args *args)
		return -EINVAL;

	hw_idle.is_idle = hdev->asic_funcs->is_device_idle(hdev,
					&hw_idle.busy_engines_mask_ext, NULL);
					hw_idle.busy_engines_mask_ext,
					HL_BUSY_ENGINES_MASK_EXT_SIZE, NULL);
	hw_idle.busy_engines_mask =
			lower_32_bits(hw_idle.busy_engines_mask_ext);
			lower_32_bits(hw_idle.busy_engines_mask_ext[0]);

	return copy_to_user(out, &hw_idle,
		min((size_t) max_size, sizeof(hw_idle))) ? -EFAULT : 0;
+16 −21
Original line number Diff line number Diff line
@@ -4538,7 +4538,6 @@ static int gaudi_scrub_device_mem(struct hl_device *hdev, u64 addr, u64 size)
{
	struct asic_fixed_properties *prop = &hdev->asic_prop;
	struct gaudi_device *gaudi = hdev->asic_specific;
	u64 idle_mask = 0;
	int rc = 0;
	u64 val = 0;

@@ -4551,8 +4550,8 @@ static int gaudi_scrub_device_mem(struct hl_device *hdev, u64 addr, u64 size)
				hdev,
				mmDMA0_CORE_STS0/* dummy */,
				val/* dummy */,
				(hdev->asic_funcs->is_device_idle(hdev,
						&idle_mask, NULL)),
				(hdev->asic_funcs->is_device_idle(hdev, NULL,
						0, NULL)),
						1000,
						HBM_SCRUBBING_TIMEOUT_US);
		if (rc) {
@@ -6423,7 +6422,7 @@ static int gaudi_send_job_on_qman0(struct hl_device *hdev,
	else
		timeout = HL_DEVICE_TIMEOUT_USEC;

	if (!hdev->asic_funcs->is_device_idle(hdev, NULL, NULL)) {
	if (!hdev->asic_funcs->is_device_idle(hdev, NULL, 0, NULL)) {
		dev_err_ratelimited(hdev->dev,
			"Can't send driver job on QMAN0 because the device is not idle\n");
		return -EBUSY;
@@ -7706,13 +7705,14 @@ static int gaudi_cpucp_info_get(struct hl_device *hdev)
	return 0;
}

static bool gaudi_is_device_idle(struct hl_device *hdev, u64 *mask,
					struct seq_file *s)
static bool gaudi_is_device_idle(struct hl_device *hdev, u64 *mask_arr,
					u8 mask_len, struct seq_file *s)
{
	struct gaudi_device *gaudi = hdev->asic_specific;
	const char *fmt = "%-5d%-9s%#-14x%#-12x%#x\n";
	const char *mme_slave_fmt = "%-5d%-9s%-14s%-12s%#x\n";
	const char *nic_fmt = "%-5d%-9s%#-14x%#x\n";
	unsigned long *mask = (unsigned long *)mask_arr;
	u32 qm_glbl_sts0, qm_cgm_sts, dma_core_sts0, tpc_cfg_sts, mme_arch_sts;
	bool is_idle = true, is_eng_idle, is_slave;
	u64 offset;
@@ -7738,9 +7738,8 @@ static bool gaudi_is_device_idle(struct hl_device *hdev, u64 *mask,
				IS_DMA_IDLE(dma_core_sts0);
		is_idle &= is_eng_idle;

		if (mask)
			*mask |= ((u64) !is_eng_idle) <<
					(GAUDI_ENGINE_ID_DMA_0 + dma_id);
		if (mask && !is_eng_idle)
			set_bit(GAUDI_ENGINE_ID_DMA_0 + dma_id, mask);
		if (s)
			seq_printf(s, fmt, dma_id,
				is_eng_idle ? "Y" : "N", qm_glbl_sts0,
@@ -7761,9 +7760,8 @@ static bool gaudi_is_device_idle(struct hl_device *hdev, u64 *mask,
				IS_TPC_IDLE(tpc_cfg_sts);
		is_idle &= is_eng_idle;

		if (mask)
			*mask |= ((u64) !is_eng_idle) <<
						(GAUDI_ENGINE_ID_TPC_0 + i);
		if (mask && !is_eng_idle)
			set_bit(GAUDI_ENGINE_ID_TPC_0 + i, mask);
		if (s)
			seq_printf(s, fmt, i,
				is_eng_idle ? "Y" : "N",
@@ -7790,9 +7788,8 @@ static bool gaudi_is_device_idle(struct hl_device *hdev, u64 *mask,

		is_idle &= is_eng_idle;

		if (mask)
			*mask |= ((u64) !is_eng_idle) <<
						(GAUDI_ENGINE_ID_MME_0 + i);
		if (mask && !is_eng_idle)
			set_bit(GAUDI_ENGINE_ID_MME_0 + i, mask);
		if (s) {
			if (!is_slave)
				seq_printf(s, fmt, i,
@@ -7818,9 +7815,8 @@ static bool gaudi_is_device_idle(struct hl_device *hdev, u64 *mask,
			is_eng_idle = IS_QM_IDLE(qm_glbl_sts0, qm_cgm_sts);
			is_idle &= is_eng_idle;

			if (mask)
				*mask |= ((u64) !is_eng_idle) <<
						(GAUDI_ENGINE_ID_NIC_0 + port);
			if (mask && !is_eng_idle)
				set_bit(GAUDI_ENGINE_ID_NIC_0 + port, mask);
			if (s)
				seq_printf(s, nic_fmt, port,
						is_eng_idle ? "Y" : "N",
@@ -7834,9 +7830,8 @@ static bool gaudi_is_device_idle(struct hl_device *hdev, u64 *mask,
			is_eng_idle = IS_QM_IDLE(qm_glbl_sts0, qm_cgm_sts);
			is_idle &= is_eng_idle;

			if (mask)
				*mask |= ((u64) !is_eng_idle) <<
						(GAUDI_ENGINE_ID_NIC_0 + port);
			if (mask && !is_eng_idle)
				set_bit(GAUDI_ENGINE_ID_NIC_0 + port, mask);
			if (s)
				seq_printf(s, nic_fmt, port,
						is_eng_idle ? "Y" : "N",
Loading