As on gfx12, pulse SOFT_RESET_GFX with CPF/CPG in the gfx engine reset,
with MES and RLC F32 halted and the GC drained, so that it recovers hangs
of the fixed-function pipeline too.

Signed-off-by: Jesse Zhang <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 95 ++++++++++++++++++++++----
 1 file changed, 83 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c 
b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
index a0ed3363f84d..824d7914bece 100644
--- a/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
+++ b/drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c
@@ -6827,15 +6827,74 @@ static void gfx_v11_0_emit_mem_sync(struct amdgpu_ring 
*ring)
                                 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 GFX11_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 GFX11_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_v11_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) & GFX11_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 & GFX11_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;
+}
+
 static int gfx_v11_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);
@@ -6856,16 +6915,21 @@ static int gfx_v11_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_v11_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);
 
@@ -6877,7 +6941,14 @@ static int gfx_v11_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;
+       }
 
        tmp = RREG32_SOC15(GC, 0, regCP_ME_CNTL);
        tmp = REG_SET_FIELD(tmp, CP_ME_CNTL, CE_HALT,
-- 
2.50.1

Reply via email to