drm/amdgpu/gfx_v11_0: fix GFX11 MEC pipe reset ordering
Subsystems (2)
PATCH 1/5 drm/amdgpu/gfx_v11_0: fix GFX11 MEC pipe reset ordering
Hold MEC pipe reset asserted, walk every queue on that (me, pipe) and tear down CP_HQD_ACTIVE / CP_HQD_DEQUEUE_REQUEST via gfx_v11_0_clear_hqds_on_mec_pipe(), then deassert reset. Avoids releasing pipe reset while HQDs may still be active.
Legacy (non-RS64) path: read CP_MEC_CNTL for the reset mask instead of reusing CP_MEC_RS64_CNTL state.
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 148 +++++++++++++++---------- 1 file changed, 91 insertions(+), 57 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +91 -57
@@ -6906,11 +6906,39 @@ static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring,return amdgpu_ring_reset_helper_end (ring, timedout_fence); } +/* +* With MEC pipe reset asserted, clear CP_HQD_ACTIVE / CP_HQD_DEQUEUE_REQUEST for +* every queue on (me, pipe). HQDs must be torn down while pipe reset stays +* asserted; only then clear the pipe reset bit. +* Caller must hold adev->srbm_mutex. +*/ +static void gfx_v11_0_clear_hqds_on_mec_pipe (struct amdgpu_device *adev,u32 me, +u32 pipe) +{ +unsigned int q; +int j; + +for (q =0 ; q < adev->gfx.mec.num_queue_per_pipe; q++) { +soc21_grbm_select (adev, me, pipe, q,0 ); +/* Start from a clean HQD dequeue state before forcing HQD inactive. */ +WREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE,0 ); +if (RREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE) &1 ) { +WREG32_SOC15 (GC ,0 , regCP_HQD_DEQUEUE_REQUEST,1 ); +for (j =0 ; j < adev->usec_timeout; j++) { +if (!(RREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE) &1 )) +break ; +udelay (1 ); + } + } +WREG32_SOC15 (GC ,0 , regCP_HQD_DEQUEUE_REQUEST,0 ); + } +} +static int gfx_v11_0_reset_compute_pipe (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev; -uint32_t reset_pipe =0 , clean_pipe =0 ; +uint32_t reset_val, clean_val;int r;if (!gfx_v11_pipe_reset_support (adev))
@@ -6920,69 +6948,73 @@ static int gfx_v11_0_reset_compute_pipe(struct amdgpu_ring *ring)mutex_lock (&adev->srbm_mutex);soc21_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); - reset_pipe =RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL); - clean_pipe = reset_pipe; -if (adev->gfx.rs64_enable) { + reset_val =RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL); + clean_val = reset_val;switch (ring->pipe) {case 0 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE0_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE0_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE0_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE0_RESET ,0 );break ;case 1 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE1_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE1_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE1_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE1_RESET ,0 );break ;case 2 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE2_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE2_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE2_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE2_RESET ,0 );break ;case 3 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE3_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE3_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE3_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE3_RESET ,0 );break ;default :break ; } -WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, reset_pipe); -WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, clean_pipe); +WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, reset_val); +gfx_v11_0_clear_hqds_on_mec_pipe (adev, ring->me, ring->pipe); +soc21_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); +WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, clean_val); r = (RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_INSTR_PNTR) <<2 ) -RS64_FW_UC_START_ADDR_LO ; }else { + reset_val =RREG32_SOC15 (GC ,0 , regCP_MEC_CNTL); + clean_val = reset_val; +if (ring->me ==1 ) {switch (ring->pipe) {case 0 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE0_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE0_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME1_PIPE0_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME1_PIPE0_RESET ,0 );break ;case 1 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE1_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE1_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME1_PIPE1_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME1_PIPE1_RESET ,0 );break ;case 2 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE2_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE2_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME1_PIPE2_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME1_PIPE2_RESET ,0 );break ;case 3 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE3_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE3_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME1_PIPE3_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME1_PIPE3_RESET ,0 );break ;default :break ;
@@ -6991,36 +7023,38 @@ static int gfx_v11_0_reset_compute_pipe(struct amdgpu_ring *ring) }else {switch (ring->pipe) {case 0 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE0_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE0_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME2_PIPE0_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME2_PIPE0_RESET ,0 );break ;case 1 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE1_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE1_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME2_PIPE1_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME2_PIPE1_RESET ,0 );break ;case 2 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE2_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE2_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME2_PIPE2_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME2_PIPE2_RESET ,0 );break ;case 3 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE3_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE3_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME2_PIPE3_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME2_PIPE3_RESET ,0 );break ;default :break ; }/* mec2 fw pc: CP:CP_MEC2_INSTR_PNTR */ } -WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, reset_pipe); -WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, clean_pipe); +WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, reset_val); +gfx_v11_0_clear_hqds_on_mec_pipe (adev, ring->me, ring->pipe); +soc21_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); +WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, clean_val); r =RREG32 (SOC15_REG_OFFSET (GC ,0 , regCP_MEC1_INSTR_PNTR)); }
@@ -7028,7 +7062,7 @@ static int gfx_v11_0_reset_compute_pipe(struct amdgpu_ring *ring)mutex_unlock (&adev->srbm_mutex);gfx_v11_0_unset_safe_mode (adev,0 ); -dev_info (adev->dev,"The ring %s pipe resets to MEC FW start PC: %s\n" , ring->name, +dev_dbg (adev->dev,"The ring %s pipe resets to MEC FW start PC: %s\n" , ring->name, r ==0 ?"successfully" :"failed" );/*FIXME:Sometimes driver can't cache the MEC firmware start PC correctly, so the pipe * reset status relies on the compute ring test result.
Signature · 1 line
2.49.0
PATCH 2/5 drm/amdgpu/gfx11: enable per-pipe reset support for compute queues
Previously, the per-pipe reset sequence was incorrect, leading to unreliable recovery and potential firmware hangs. The reset logic has now been fixed to properly handle HQD cleanup while the pipe is held in reset before bringing it out of reset.
--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +8 -1
@@ -1851,6 +1851,7 @@ static int gfx_v11_0_sw_init(struct amdgpu_ip_block *ip_block) !adev->debug_disable_gpu_ring_reset) { adev->gfx.compute_supported_reset |=AMDGPU_RESET_TYPE_PER_QUEUE ; adev->gfx.gfx_supported_reset |=AMDGPU_RESET_TYPE_PER_QUEUE ; + adev->gfx.compute_supported_reset |=AMDGPU_RESET_TYPE_PER_PIPE ; }break ;default :
@@ -1858,6 +1859,7 @@ static int gfx_v11_0_sw_init(struct amdgpu_ip_block *ip_block) !adev->debug_disable_gpu_ring_reset) { adev->gfx.compute_supported_reset |=AMDGPU_RESET_TYPE_PER_QUEUE ; adev->gfx.gfx_supported_reset |=AMDGPU_RESET_TYPE_PER_QUEUE ; + adev->gfx.compute_supported_reset |=AMDGPU_RESET_TYPE_PER_PIPE ; }break ; }
@@ -6906,6 +6908,11 @@ static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring,return amdgpu_ring_reset_helper_end (ring, timedout_fence); } +static bool gfx_v11_compute_pipe_reset_support (struct amdgpu_device *adev) +{ +return !!(adev->gfx.compute_supported_reset &AMDGPU_RESET_TYPE_PER_PIPE ); +} +/* * With MEC pipe reset asserted, clear CP_HQD_ACTIVE / CP_HQD_DEQUEUE_REQUEST for * every queue on (me, pipe). HQDs must be torn down while pipe reset stays
@@ -6941,7 +6948,7 @@ static int gfx_v11_0_reset_compute_pipe(struct amdgpu_ring *ring)uint32_t reset_val, clean_val;int r; -if (!gfx_v11_pipe_reset_support (adev)) +if (!gfx_v11_compute_pipe_reset_support (adev))return -EOPNOTSUPP ;gfx_v11_0_set_safe_mode (adev,0 );
Signature · 1 line
2.49.0
Re: [PATCH 2/5] drm/amdgpu/gfx11: enable per-pipe reset support for compute queues
Quoted 32 lines · Jesse Zhang
Previously, the per-pipe reset sequence was incorrect, leading to unreliable recovery and potential firmware hangs. The reset logic has now been fixed to properly handle HQD cleanup while the pipe is held in reset before bringing it out of reset.
Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-0@@ -1851,6 +1851,7 @@ static int gfx_v11_0_sw_init(struct amdgpu_ip_block *ip_block) !adev->debug_disable_gpu_ring_reset) { adev->gfx.compute_supported_reset |=AMDGPU_RESET_TYPE_PER_QUEUE ; adev->gfx.gfx_supported_reset |=AMDGPU_RESET_TYPE_PER_QUEUE ; + adev->gfx.compute_supported_reset |=AMDGPU_RESET_TYPE_PER_PIPE ; }break ;default :@@ -1858,6 +1859,7 @@ static int gfx_v11_0_sw_init(struct amdgpu_ip_block *ip_block) !adev->debug_disable_gpu_ring_reset) { adev->gfx.compute_supported_reset |=AMDGPU_RESET_TYPE_PER_QUEUE ; adev->gfx.gfx_supported_reset |=AMDGPU_RESET_TYPE_PER_QUEUE ; + adev->gfx.compute_supported_reset |=AMDGPU_RESET_TYPE_PER_PIPE ; }break ; }
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring, · line 6914
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +4
-0@@ -6906,6 +6908,11 @@ static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring,return amdgpu_ring_reset_helper_end (ring, timedout_fence); } +static bool gfx_v11_compute_pipe_reset_support (struct amdgpu_device *adev) +{ +return !!(adev->gfx.compute_supported_reset &AMDGPU_RESET_TYPE_PER_PIPE ); +}
I think you can replace both gfx_v11_compute_pipe_reset_support() and gfx_v11_pipe_reset_support() with amdgpu_ring_is_reset_type_supported(ring, AMDGPU_RESET_TYPE_PER_PIPE).
Alex
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +2
-2+/* * With MEC pipe reset asserted, clear CP_HQD_ACTIVE / CP_HQD_DEQUEUE_REQUEST for * every queue on (me, pipe). HQDs must be torn down while pipe reset stays @@ -6941,7 +6948,7 @@ static int gfx_v11_0_reset_compute_pipe(struct amdgpu_ring *ring)uint32_t reset_val, clean_val;int r; -if (!gfx_v11_pipe_reset_support (adev)) +if (!gfx_v11_compute_pipe_reset_support (adev))return -EOPNOTSUPP ;gfx_v11_0_set_safe_mode (adev,0 ); --2.49.0
PATCH 3/5 drm/amdgpu/gfx_v12_0: set gfx.rs64_enable from PFP header on GFX12
In reply to Jesse Zhanggfx_v12_0_init_microcode() always loads RS64 CP ucode but never set adev->gfx.rs64_enable, so it stayed false and code that branches on it (e.g. MEC pipe reset) used the legacy CP_MEC_CNTL path incorrectly.
Match GFX11: derive RS64 mode from the PFP firmware header (v2.0) via amdgpu_ucode_hdr_version(). Log at debug when RS64 is enabled.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 7 +++++++ 1 file changed, 7 insertions(+)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +7 -0
@@ -602,6 +602,13 @@ static int gfx_v12_0_init_microcode(struct amdgpu_device *adev) "amdgpu/%s_pfp.bin", ucode_prefix);if (err) goto out; + + adev->gfx.rs64_enable =amdgpu_ucode_hdr_version ( + (union amdgpu_firmware_header *) + adev->gfx.pfp_fw->data,2 ,0 ); +if (adev->gfx.rs64_enable) +dev_dbg (adev->dev,"CP RS64 enable\n" ); +amdgpu_gfx_cp_init_microcode (adev,AMDGPU_UCODE_ID_CP_RS64_PFP );amdgpu_gfx_cp_init_microcode (adev,AMDGPU_UCODE_ID_CP_RS64_PFP_P0_STACK );
Signature · 1 line
2.49.0
PATCH 4/5 drm/amdgpu/gfx_v12_0: fix GFX11 MEC pipe reset ordering
In reply to Jesse ZhangHold MEC pipe reset asserted, walk every queue on that (me, pipe) and tear down CP_HQD_ACTIVE / CP_HQD_DEQUEUE_REQUEST via gfx_v11_0_clear_hqds_on_mec_pipe(), then deassert reset. Avoids releasing pipe reset while HQDs may still be active.
Legacy (non-RS64) path: read CP_MEC_CNTL for the reset mask instead of reusing CP_MEC_RS64_CNTL state.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 111 ++++++++++++++++--------- 1 file changed, 71 insertions(+), 40 deletions(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +71 -40
@@ -5362,10 +5362,38 @@ static int gfx_v12_0_reset_kgq(struct amdgpu_ring *ring,return amdgpu_ring_reset_helper_end (ring, timedout_fence); } +/* +* With MEC pipe reset asserted, clear CP_HQD_ACTIVE / CP_HQD_DEQUEUE_REQUEST for +* every queue on (me, pipe). HQDs must be torn down while pipe reset stays +* asserted; only then clear the pipe reset bit. +* Caller must hold adev->srbm_mutex. +*/ +static void gfx_v12_0_clear_hqds_on_mec_pipe (struct amdgpu_device *adev,u32 me, +u32 pipe) +{ +unsigned int q; +int j; + +for (q =0 ; q < adev->gfx.mec.num_queue_per_pipe; q++) { +soc24_grbm_select (adev, me, pipe, q,0 ); +/* Start from a clean HQD dequeue state before forcing HQD inactive. */ +WREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE,0 ); +if (RREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE) &1 ) { +WREG32_SOC15 (GC ,0 , regCP_HQD_DEQUEUE_REQUEST,1 ); +for (j =0 ; j < adev->usec_timeout; j++) { +if (!(RREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE) &1 )) +break ; +udelay (1 ); + } + } +WREG32_SOC15 (GC ,0 , regCP_HQD_DEQUEUE_REQUEST,0 ); + } +} +static int gfx_v12_0_reset_compute_pipe (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev; -uint32_t reset_pipe =0 , clean_pipe =0 ; +uint32_t reset_val, clean_val;int r =0 ;if (!gfx_v12_pipe_reset_support (adev))
@@ -5374,74 +5402,77 @@ static int gfx_v12_0_reset_compute_pipe(struct amdgpu_ring *ring)gfx_v12_0_set_safe_mode (adev,0 );mutex_lock (&adev->srbm_mutex);soc24_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); - - reset_pipe =RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL); - clean_pipe = reset_pipe; -if (adev->gfx.rs64_enable) { + reset_val =RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL); + clean_val = reset_val; +switch (ring->pipe) {case 0 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE0_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE0_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE0_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE0_RESET ,0 );break ;case 1 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE1_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE1_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE1_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE1_RESET ,0 );break ;case 2 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE2_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE2_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE2_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE2_RESET ,0 );break ;case 3 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE3_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE3_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE3_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE3_RESET ,0 );break ;default :break ; } -WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, reset_pipe); -WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, clean_pipe); +WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, reset_val); +gfx_v12_0_clear_hqds_on_mec_pipe (adev, ring->me, ring->pipe); +soc24_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); +WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, clean_val); r = (RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_INSTR_PNTR) <<2 ) -RS64_FW_UC_START_ADDR_LO ; }else { + reset_val =RREG32_SOC15 (GC ,0 , regCP_MEC_CNTL); + clean_val = reset_val; +switch (ring->pipe) {case 0 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE0_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE0_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME1_PIPE0_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME1_PIPE0_RESET ,0 );break ;case 1 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE1_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE1_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME1_PIPE1_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME1_PIPE1_RESET ,0 );break ;default : -break ; +break ; } -WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, reset_pipe); -WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, clean_pipe); -/* Doesn't find the F32 MEC instruction pointer register, and suppose -* the driver won't run into the F32 mode. -*/ + +WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, reset_val); +gfx_v12_0_clear_hqds_on_mec_pipe (adev, ring->me, ring->pipe); +soc24_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); +WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, clean_val); }soc24_grbm_select (adev,0 ,0 ,0 ,0 );mutex_unlock (&adev->srbm_mutex);gfx_v12_0_unset_safe_mode (adev,0 ); -dev_info (adev->dev,"The ring %s pipe resets: %s\n" , ring->name, - r ==0 ?"successfully" :"failed" ); -/* Need the ring test to verify the pipe reset result.*/ +dev_dbg (adev->dev,"The ring %s pipe resets to MEC FW start PC: %s\n" , ring->name, + r ==0 ?"successfully" :"failed" );return 0 ; }
Signature · 1 line
2.49.0
PATCH 5/5 drm/amdgpu/gfx_v12_0: enable compute pipe reset flag
In reply to Jesse ZhangPreviously, the per-pipe reset sequence was incorrect, leading to unreliable recovery and potential firmware hangs. The reset logic has now been fixed to properly handle HQD cleanup while the pipe is held in reset before bringing it out of reset.
--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +7 -1
@@ -1563,6 +1563,7 @@ static int gfx_v12_0_sw_init(struct amdgpu_ip_block *ip_block) !amdgpu_sriov_vf(adev) && !adev->debug_disable_gpu_ring_reset) { adev->gfx.compute_supported_reset |=AMDGPU_RESET_TYPE_PER_QUEUE ; + adev->gfx.compute_supported_reset |=AMDGPU_RESET_TYPE_PER_PIPE ; adev->gfx.gfx_supported_reset |=AMDGPU_RESET_TYPE_PER_QUEUE ; }break ;
@@ -5362,6 +5363,11 @@ static int gfx_v12_0_reset_kgq(struct amdgpu_ring *ring,return amdgpu_ring_reset_helper_end (ring, timedout_fence); } +static bool gfx_v12_compute_pipe_reset_support (struct amdgpu_device *adev) +{ +return !!(adev->gfx.compute_supported_reset &AMDGPU_RESET_TYPE_PER_PIPE ); +} +/* * With MEC pipe reset asserted, clear CP_HQD_ACTIVE / CP_HQD_DEQUEUE_REQUEST for * every queue on (me, pipe). HQDs must be torn down while pipe reset stays
@@ -5396,7 +5402,7 @@ static int gfx_v12_0_reset_compute_pipe(struct amdgpu_ring *ring)uint32_t reset_val, clean_val;int r =0 ; -if (!gfx_v12_pipe_reset_support (adev)) +if (!gfx_v12_compute_pipe_reset_support (adev))return -EOPNOTSUPP ;gfx_v12_0_set_safe_mode (adev,0 );
Signature · 1 line
2.49.0
Re: [PATCH 5/5] drm/amdgpu/gfx_v12_0: enable compute pipe reset flag
Quoted 24 lines · Jesse Zhang
Previously, the per-pipe reset sequence was incorrect, leading to unreliable recovery and potential firmware hangs. The reset logic has now been fixed to properly handle HQD cleanup while the pipe is held in reset before bringing it out of reset.
Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +1
-0@@ -1563,6 +1563,7 @@ static int gfx_v12_0_sw_init(struct amdgpu_ip_block *ip_block) !amdgpu_sriov_vf(adev) && !adev->debug_disable_gpu_ring_reset) { adev->gfx.compute_supported_reset |=AMDGPU_RESET_TYPE_PER_QUEUE ; + adev->gfx.compute_supported_reset |=AMDGPU_RESET_TYPE_PER_PIPE ; adev->gfx.gfx_supported_reset |=AMDGPU_RESET_TYPE_PER_QUEUE ; }break ;
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c static int gfx_v12_0_reset_kgq(struct amdgpu_ring *ring, · line 5369
Quoted 7 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +4
-0@@ -5362,6 +5363,11 @@ static int gfx_v12_0_reset_kgq(struct amdgpu_ring *ring,return amdgpu_ring_reset_helper_end (ring, timedout_fence); } +static bool gfx_v12_compute_pipe_reset_support (struct amdgpu_device *adev) +{ +return !!(adev->gfx.compute_supported_reset &AMDGPU_RESET_TYPE_PER_PIPE ); +}
I think you can replace both gfx_v12_compute_pipe_reset_support() and gfx_v12_pipe_reset_support() with amdgpu_ring_is_reset_type_supported(ring, AMDGPU_RESET_TYPE_PER_PIPE).
Alex
Quoted 16 lines
drivers/gpu/drm/amd/amdgpu/gfx_v12_0.c +2
-2+/* * With MEC pipe reset asserted, clear CP_HQD_ACTIVE / CP_HQD_DEQUEUE_REQUEST for * every queue on (me, pipe). HQDs must be torn down while pipe reset stays @@ -5396,7 +5402,7 @@ static int gfx_v12_0_reset_compute_pipe(struct amdgpu_ring *ring)uint32_t reset_val, clean_val;int r =0 ; -if (!gfx_v12_pipe_reset_support (adev)) +if (!gfx_v12_compute_pipe_reset_support (adev))return -EOPNOTSUPP ;gfx_v12_0_set_safe_mode (adev,0 ); --2.49.0
Quoted 40 lines · Jesse Zhang
Hold MEC pipe reset asserted, walk every queue on that (me, pipe) and tear down
CP_HQD_ACTIVE/CP_HQD_DEQUEUE_REQUESTviagfx_v11_0_clear_hqds_on_mec_pipe(), then deassert reset. Avoids releasing pipe reset while HQDs may still be active.Legacy (non-RS64) path: read
CP_MEC_CNTLfor the reset mask instead of reusingCP_MEC_RS64_CNTLstate.Suggested-by Manu Rastogi <[email protected]>Signed-off-by Jesse Zhang <[email protected]>--- drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c | 148 +++++++++++++++---------- 1 file changed, 91 insertions(+), 57 deletions(-)drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +17
-0@@ -6906,11 +6906,39 @@ static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring,return amdgpu_ring_reset_helper_end (ring, timedout_fence); } +/* +* With MEC pipe reset asserted, clear CP_HQD_ACTIVE / CP_HQD_DEQUEUE_REQUEST for +* every queue on (me, pipe). HQDs must be torn down while pipe reset stays +* asserted; only then clear the pipe reset bit. +* Caller must hold adev->srbm_mutex. +*/ +static void gfx_v11_0_clear_hqds_on_mec_pipe (struct amdgpu_device *adev,u32 me, +u32 pipe) +{ +unsigned int q; +int j; + +for (q =0 ; q < adev->gfx.mec.num_queue_per_pipe; q++) { +soc21_grbm_select (adev, me, pipe, q,0 ); +/* Start from a clean HQD dequeue state before forcing HQD inactive. */ +WREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE,0 ); +if (RREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE) &1 ) {
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c static int gfx_v11_0_reset_kgq(struct amdgpu_ring *ring, · line 6935
Quoted 10 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +10
-0+WREG32_SOC15 (GC ,0 , regCP_HQD_DEQUEUE_REQUEST,1 ); +for (j =0 ; j < adev->usec_timeout; j++) { +if (!(RREG32_SOC15 (GC ,0 , regCP_HQD_ACTIVE) &1 )) +break ; +udelay (1 ); + } + } +WREG32_SOC15 (GC ,0 , regCP_HQD_DEQUEUE_REQUEST,0 ); + } +}
Do we have a way to look up which queue was actually on the pipe? This will lead to all queues on this pipe ultimately timing out the next time they are used since we never re-enable the queues after the reset. I think we need something like amdgpu_vcn_reset_engine() for each compute or gfx pipe. We need to stop the schedulers for all queues on the pipe and then mark the fences with an error and then make sure to re-enable and test all of the queues after the reset. Ideally, we could resume any queues that weren't on the pipe after the reset non-destructively, but I'm not sure if that is possible or not. If the pipe reset doesn't affect any queues which were not on the pipe at the time, then we can just loop over all of the queues on the pipe, and for the non-guilty ones (i.e., the ones not on the pipe), we can save their entire unprocessed ring state and reemit it. For the guilty one, we we already save it's non-guilty state and restore it after the reset. We also need to handle KFD queues. I think we need to preempt the KFD queues at the start of this function and then restore them at the end to make sure they are properly handled as well.
Alex
Quoted 190 lines
drivers/gpu/drm/amd/amdgpu/gfx_v11_0.c +64
-58+static int gfx_v11_0_reset_compute_pipe (struct amdgpu_ring *ring) {struct amdgpu_device *adev = ring->adev; -uint32_t reset_pipe =0 , clean_pipe =0 ; +uint32_t reset_val, clean_val;int r;if (!gfx_v11_pipe_reset_support (adev))@@ -6920,69 +6948,73 @@ static int gfx_v11_0_reset_compute_pipe(struct amdgpu_ring *ring)mutex_lock (&adev->srbm_mutex);soc21_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); - reset_pipe =RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL); - clean_pipe = reset_pipe; -if (adev->gfx.rs64_enable) { + reset_val =RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL); + clean_val = reset_val;switch (ring->pipe) {case 0 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE0_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE0_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE0_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE0_RESET ,0 );break ;case 1 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE1_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE1_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE1_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE1_RESET ,0 );break ;case 2 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE2_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE2_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE2_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE2_RESET ,0 );break ;case 3 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE3_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_RS64_CNTL , -MEC_PIPE3_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_RS64_CNTL , +MEC_PIPE3_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_RS64_CNTL , +MEC_PIPE3_RESET ,0 );break ;default :break ; } -WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, reset_pipe); -WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, clean_pipe); +WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, reset_val); +gfx_v11_0_clear_hqds_on_mec_pipe (adev, ring->me, ring->pipe); +soc21_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); +WREG32_SOC15 (GC ,0 , regCP_MEC_RS64_CNTL, clean_val); r = (RREG32_SOC15 (GC ,0 , regCP_MEC_RS64_INSTR_PNTR) <<2 ) -RS64_FW_UC_START_ADDR_LO ; }else { + reset_val =RREG32_SOC15 (GC ,0 , regCP_MEC_CNTL); + clean_val = reset_val; +if (ring->me ==1 ) {switch (ring->pipe) {case 0 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE0_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE0_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME1_PIPE0_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME1_PIPE0_RESET ,0 );break ;case 1 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE1_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE1_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME1_PIPE1_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME1_PIPE1_RESET ,0 );break ;case 2 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE2_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE2_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME1_PIPE2_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME1_PIPE2_RESET ,0 );break ;case 3 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE3_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME1_PIPE3_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME1_PIPE3_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME1_PIPE3_RESET ,0 );break ;default :break ;@@ -6991,36 +7023,38 @@ static int gfx_v11_0_reset_compute_pipe(struct amdgpu_ring *ring) }else {switch (ring->pipe) {case 0 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE0_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE0_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME2_PIPE0_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME2_PIPE0_RESET ,0 );break ;case 1 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE1_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE1_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME2_PIPE1_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME2_PIPE1_RESET ,0 );break ;case 2 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE2_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE2_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME2_PIPE2_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME2_PIPE2_RESET ,0 );break ;case 3 : - reset_pipe =REG_SET_FIELD (reset_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE3_RESET ,1 ); - clean_pipe =REG_SET_FIELD (clean_pipe,CP_MEC_CNTL , -MEC_ME2_PIPE3_RESET ,0 ); + reset_val =REG_SET_FIELD (reset_val,CP_MEC_CNTL , +MEC_ME2_PIPE3_RESET ,1 ); + clean_val =REG_SET_FIELD (clean_val,CP_MEC_CNTL , +MEC_ME2_PIPE3_RESET ,0 );break ;default :break ; }/* mec2 fw pc: CP:CP_MEC2_INSTR_PNTR */ } -WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, reset_pipe); -WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, clean_pipe); +WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, reset_val); +gfx_v11_0_clear_hqds_on_mec_pipe (adev, ring->me, ring->pipe); +soc21_grbm_select (adev, ring->me, ring->pipe, ring->queue,0 ); +WREG32_SOC15 (GC ,0 , regCP_MEC_CNTL, clean_val); r =RREG32 (SOC15_REG_OFFSET (GC ,0 , regCP_MEC1_INSTR_PNTR)); }@@ -7028,7 +7062,7 @@ static int gfx_v11_0_reset_compute_pipe(struct amdgpu_ring *ring)mutex_unlock (&adev->srbm_mutex);gfx_v11_0_unset_safe_mode (adev,0 ); -dev_info (adev->dev,"The ring %s pipe resets to MEC FW start PC: %s\n" , ring->name, +dev_dbg (adev->dev,"The ring %s pipe resets to MEC FW start PC: %s\n" , ring->name, r ==0 ?"successfully" :"failed" );/*FIXME:Sometimes driver can't cache the MEC firmware start PC correctly, so the pipe * reset status relies on the compute ring test result. -- 2.49.0