All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jesse Zhang <Jesse.Zhang@amd.com>
To: <amd-gfx@lists.freedesktop.org>
Cc: <Alexander.Deucher@amd.com>,
	Christian Koenig <christian.koenig@amd.com>,
	 <Lijo.Lazar@amd.com>, <timur.kristof@gmail.com>,
	<Mario.Novales@amd.com>,  <Manu.Rastogi@amd.com>,
	<Jiongyu.Zhu@amd.com>, Jesse Zhang <Jesse.Zhang@amd.com>
Subject: [PATCH v5 11/15] drm/amdgpu/gfx12: include SOFT_RESET_GFX in the gfx engine soft reset
Date: Thu, 26 Nov 2026 17:33:47 +0800	[thread overview]
Message-ID: <20261126093417.192538-11-Jesse.Zhang@amd.com> (raw)
In-Reply-To: <20261126093417.192538-1-Jesse.Zhang@amd.com>

The gfx engine reset only pulses CPF/CPG, which leaves hangs of the
fixed-function pipeline to a full reset. Pulse SOFT_RESET_GFX too.

SOFT_RESET_GFX drops the memory requests in flight through the blocks it
resets, and their clients then wait for them forever: pulsed while RLC
writes its DRAM log, which it still does in safe mode, RLC stays MC_BUSY
and the next TLB invalidation of MES never completes; pulsed while MES
fetches instructions, which it still does with its queues suspended, its
next queue operation times out. Halt MES and RLC F32 across the reset and
wait for the GC memory interfaces to drain before the pulse. A halted MES
or F32 can stay busy, as long as it has no memory request in flight. If
the GC doesn't drain, skip the pulse and fail the reset, so a full reset
follows.

Signed-off-by: Jesse Zhang <Jesse.Zhang@amd.com>
---
 drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 100 +++++++++++++++++++++----
 1 file changed, 87 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
index 69bdae805597..8485d1aabf3b 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c
@@ -3874,16 +3874,78 @@ static int gfx_v12_0_wait_for_idle(struct amdgpu_ip_block *ip_block)
 				 CP_STAT__RCIU_BUSY_MASK | \
 				 CP_STAT__UTCL2IU_BUSY_MASK)
 
-/* Reset CPF/CPG, PFP/ME and the gfx HQDs, then boot PFP/ME again. */
+/*
+ * SOFT_RESET_GFX drops the memory requests in flight through the blocks it
+ * resets, and their clients then wait for them forever: MES still fetches
+ * instructions with its queues suspended, and RLC still writes its DRAM log
+ * in safe mode. The reset halts both, then waits for these busy bits of the
+ * GC memory interfaces to clear.
+ */
+#define GFX12_GC_MEM_BUSY	(GRBM_STATUS2__EA_BUSY_MASK | \
+				 GRBM_STATUS2__EA_LINK_BUSY_MASK | \
+				 GRBM_STATUS2__UTCL2_BUSY_MASK | \
+				 GRBM_STATUS2__UTCL2_RQ_PENDING_MASK | \
+				 GRBM_STATUS2__TCP_BUSY_MASK | \
+				 GRBM_STATUS2__CPC_BUSY_MASK | \
+				 GRBM_STATUS2__RLC_BUSY_MASK | \
+				 GRBM_STATUS2__RLC_RQ_PENDING_MASK | \
+				 GRBM_STATUS2__SDMA_BUSY_MASK | \
+				 GRBM_STATUS2__SDMA_SCH_RQ_PENDING_MASK | \
+				 GRBM_STATUS2__SDMA0_RQ_PENDING_MASK | \
+				 GRBM_STATUS2__SDMA1_RQ_PENDING_MASK)
+
+/* The RLC busy bits of its memory requests */
+#define GFX12_RLC_MEM_BUSY	(RLC_STAT__MC_BUSY_MASK | \
+				 RLC_STAT__RLC_SRM_BUSY_MASK | \
+				 RLC_STAT__RLC_SPM_BUSY_MASK)
+
+/* Wait for the requests in flight in the GC, with MES and RLC F32 halted. */
+static int gfx_v12_0_wait_gc_idle(struct amdgpu_device *adev)
+{
+	u32 busy, cpc, rlc;
+	int i;
+
+	for (i = 0; i < adev->usec_timeout; i++) {
+		busy = RREG32_SOC15(GC, 0, regGRBM_STATUS2) & GFX12_GC_MEM_BUSY;
+		cpc = RREG32_SOC15(GC, 0, regCP_CPC_STATUS);
+		rlc = RREG32_SOC15(GC, 0, regRLC_STAT);
+
+		/* The halted MES and F32 can stay busy, not their memory requests. */
+		if (!(cpc & GENMASK(21, 0) & ~CP_CPC_STATUS__MES_BUSY_MASK))
+			busy &= ~GRBM_STATUS2__CPC_BUSY_MASK;
+		if (!(rlc & GFX12_RLC_MEM_BUSY))
+			busy &= ~GRBM_STATUS2__RLC_BUSY_MASK;
+
+		if (!busy && !(RREG32_SOC15(GC, 0, regGCVM_L2_STATUS) &
+			       GCVM_L2_STATUS__L2_BUSY_MASK))
+			return 0;
+		udelay(1);
+	}
+
+	dev_err(adev->dev, "GC still busy, GRBM_STATUS2 0x%08x CPC 0x%08x RLC 0x%08x\n",
+		RREG32_SOC15(GC, 0, regGRBM_STATUS2), cpc, rlc);
+	return -ETIMEDOUT;
+}
+
+/*
+ * Reset CPF/CPG, PFP/ME, the gfx HQDs and the fixed-function pipeline,
+ * then boot PFP/ME again.
+ */
 static int gfx_v12_0_soft_reset_gfx_cp(struct amdgpu_device *adev)
 {
-	u32 tmp, cntl, me_cntl;
-	int i;
+	u32 tmp, cntl, me_cntl, mes_cntl, rlc_cntl;
+	int i, r = 0;
 
 	amdgpu_gfx_rlc_enter_safe_mode(adev, 0);
 	/* MES fetches its queues through CPF: keep it out of the reset. */
 	amdgpu_mes_lock(&adev->mes);
 
+	/* SOFT_RESET_GFX needs the GC quiet: halt MES and RLC F32. */
+	mes_cntl = RREG32_SOC15(GC, 0, regCP_MES_CNTL);
+	WREG32_SOC15(GC, 0, regCP_MES_CNTL, mes_cntl | CP_MES_CNTL__MES_HALT_MASK);
+	rlc_cntl = RREG32_SOC15(GC, 0, regRLC_CNTL);
+	adev->gfx.rlc.funcs->stop(adev);
+
 	me_cntl = RREG32_SOC15(GC, 0, regCP_ME_CNTL);
 
 	tmp = REG_SET_FIELD(me_cntl, CP_ME_CNTL, ME_HALT, 1);
@@ -3907,16 +3969,21 @@ static int gfx_v12_0_soft_reset_gfx_cp(struct amdgpu_device *adev)
 	tmp = REG_SET_FIELD(tmp, CP_SOFT_RESET_CNTL, GFX_HQD_REG_RESET, 1);
 	WREG32_SOC15(GC, 0, regCP_SOFT_RESET_CNTL, tmp);
 
-	tmp = RREG32_SOC15(GC, 0, regGRBM_SOFT_RESET);
-	tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPF, 1);
-	tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPG, 1);
-	WREG32_SOC15(GC, 0, regGRBM_SOFT_RESET, tmp);
-	tmp = RREG32_SOC15(GC, 0, regGRBM_SOFT_RESET);
-	udelay(50);
-	tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPF, 0);
-	tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPG, 0);
-	WREG32_SOC15(GC, 0, regGRBM_SOFT_RESET, tmp);
-	tmp = RREG32_SOC15(GC, 0, regGRBM_SOFT_RESET);
+	r = gfx_v12_0_wait_gc_idle(adev);
+	if (!r) {
+		tmp = RREG32_SOC15(GC, 0, regGRBM_SOFT_RESET);
+		tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPF, 1);
+		tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPG, 1);
+		tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_GFX, 1);
+		WREG32_SOC15(GC, 0, regGRBM_SOFT_RESET, tmp);
+		tmp = RREG32_SOC15(GC, 0, regGRBM_SOFT_RESET);
+		udelay(50);
+		tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPF, 0);
+		tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_CPG, 0);
+		tmp = REG_SET_FIELD(tmp, GRBM_SOFT_RESET, SOFT_RESET_GFX, 0);
+		WREG32_SOC15(GC, 0, regGRBM_SOFT_RESET, tmp);
+		tmp = RREG32_SOC15(GC, 0, regGRBM_SOFT_RESET);
+	}
 
 	WREG32_SOC15(GC, 0, regCP_SOFT_RESET_CNTL, cntl);
 
@@ -3928,7 +3995,14 @@ static int gfx_v12_0_soft_reset_gfx_cp(struct amdgpu_device *adev)
 	}
 	/* A VMID reset the hung PFP didn't handle survives the reset. */
 	WREG32_SOC15(GC, 0, regCP_VMID_RESET, 0);
+	WREG32_SOC15(GC, 0, regRLC_CNTL, rlc_cntl);
+	WREG32_SOC15(GC, 0, regCP_MES_CNTL, mes_cntl);
 	amdgpu_mes_unlock(&adev->mes);
+	if (r) {
+		/* PFP/ME stay halted: a full reset follows. */
+		amdgpu_gfx_rlc_exit_safe_mode(adev, 0);
+		return r;
+	}
 
 	gfx_v12_0_set_pfp_ucode_start_addr(adev);
 	gfx_v12_0_set_me_ucode_start_addr(adev);
-- 
2.50.1


  parent reply	other threads:[~2026-11-26  9:35 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  9:33 [PATCH v5 01/15] drm/amdgpu: pass the device to the multi ring reset helpers Jesse Zhang
2026-11-26  9:33 ` [PATCH v5 02/15] drm/amdgpu/ring: During multi-queue reset, only call begin helper if needed Jesse Zhang
2026-11-26  9:52   ` sashiko-bot
2026-11-26  9:33 ` [PATCH v5 03/15] drm/amdgpu: add an engine scope to the IP block soft reset Jesse Zhang
2026-11-26 10:00   ` sashiko-bot
2026-11-26  9:33 ` [PATCH v5 04/15] drm/amdgpu/gfx: add callbacks to save and restore a gfx HQD Jesse Zhang
2026-11-26  9:33 ` [PATCH v5 05/15] drm/amdgpu/gfx12: " Jesse Zhang
2026-11-26  9:33 ` [PATCH v5 06/15] drm/amdgpu/gfx11: " Jesse Zhang
2026-11-26  9:33 ` [PATCH v5 07/15] drm/amdgpu/userq: add a helper to signal the fences of a queue up to a point Jesse Zhang
2026-11-26  9:33 ` [PATCH v5 08/15] drm/amdgpu/userq: add helpers to keep the user queues of one engine across a reset Jesse Zhang
2026-11-26 10:03   ` sashiko-bot
2026-11-26  9:33 ` [PATCH v5 09/15] drm/amdgpu/gfx12: add a gfx engine soft reset Jesse Zhang
2026-11-26  9:57   ` sashiko-bot
2026-11-26  9:33 ` [PATCH v5 10/15] drm/amdgpu/gfx11: " Jesse Zhang
2026-11-26  9:59   ` sashiko-bot
2026-11-26  9:33 ` Jesse Zhang [this message]
2026-11-26  9:33 ` [PATCH v5 12/15] drm/amdgpu/gfx11: include SOFT_RESET_GFX in the " Jesse Zhang
2026-11-26  9:57   ` sashiko-bot
2026-11-26  9:33 ` [PATCH v5 13/15] drm/amdgpu/userq: reset the gfx engine when a gfx user queue reset fails Jesse Zhang
2026-11-26 10:15   ` sashiko-bot
2026-11-26  9:33 ` [PATCH v5 14/15] drm/amdgpu/gfx12: enable the gfx engine soft reset Jesse Zhang
2026-11-26  9:33 ` [PATCH v5 15/15] drm/amdgpu/gfx11: " Jesse Zhang
2026-11-26 10:10   ` sashiko-bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126093417.192538-11-Jesse.Zhang@amd.com \
    --to=jesse.zhang@amd.com \
    --cc=Alexander.Deucher@amd.com \
    --cc=Jiongyu.Zhu@amd.com \
    --cc=Lijo.Lazar@amd.com \
    --cc=Manu.Rastogi@amd.com \
    --cc=Mario.Novales@amd.com \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=christian.koenig@amd.com \
    --cc=timur.kristof@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.