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 <[email protected]> --- 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
