When neither the queue nor the pipe reset recovered a gfx user queue,
fall back to a soft reset of the gfx engine before a full reset, when
the GFX IP supports it. A hung kernel gfx queue gets there through the
IP block soft reset of the job timeout handler; a user queue has no
kernel ring, so call amdgpu_device_ip_soft_reset() directly, with the
gfx ring type, the master XCC of the queue partition as the engine
instance, and no guilty ring.

The hung queue can't be unmapped before the reset: pass it to the engine
reset, which unmaps it once the reset cleared its HQD, and hangs it,
while the other gfx user queues keep their state.

v4: Call amdgpu_device_ip_soft_reset(), which now takes the ring type
    (Timur).
v5: Pass the XCC of the queue partition as the engine instance (Lijo).

Reviewed-by: Timur Kristóf <[email protected]>
Signed-off-by: Jesse Zhang <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/mes_userqueue.c | 42 ++++++++++++++++++++--
 1 file changed, 39 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c 
b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
index 7abb9d95ef59..8d0cd4575844 100644
--- a/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
+++ b/drivers/gpu/drm/amd/amdgpu/mes_userqueue.c
@@ -235,11 +235,40 @@ int mes_userq_reset_hw(struct amdgpu_usermode_queue 
*queue,
        return 0;
 }
 
+/* The master XCC of the queue partition */
+static u32 mes_userq_gfx_inst(struct amdgpu_usermode_queue *queue)
+{
+       struct amdgpu_device *adev = queue->userq_mgr->adev;
+       u32 xcc_mask;
+
+       if (!adev->xcp_mgr ||
+           amdgpu_xcp_get_inst_details(&adev->xcp_mgr->xcp[queue->xcp_id],
+                                       AMDGPU_XCP_GFX, &xcc_mask) || !xcc_mask)
+               return 0;
+
+       return ffs(xcc_mask) - 1;
+}
+
+static int mes_userq_reset_gfx_engine(struct amdgpu_usermode_queue *queue)
+{
+       return amdgpu_device_ip_soft_reset(queue->userq_mgr->adev,
+                                          AMDGPU_RING_TYPE_GFX,
+                                          mes_userq_gfx_inst(queue), NULL,
+                                          NULL, queue);
+}
+
+static bool mes_userq_gfx_engine_reset_supported(struct amdgpu_device *adev)
+{
+       return adev->gfx.gfx_supported_reset &
+              AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESET;
+}
+
 int mes_userq_reset(struct amdgpu_usermode_queue *queue)
 {
        struct amdgpu_userq_mgr *uq_mgr = queue->userq_mgr;
        struct amdgpu_device *adev = uq_mgr->adev;
        struct mes_reset_queue_input queue_input;
+       int r;
 
        /* already reset by an earlier job's hang-detect; just signal and bail 
*/
        if (queue->state == AMDGPU_USERQ_STATE_HUNG)
@@ -248,8 +277,10 @@ int mes_userq_reset(struct amdgpu_usermode_queue *queue)
        /* A GFX pipe reset also affects the kernel rings on that pipe. */
        if (queue->queue_type == AMDGPU_HW_IP_GFX &&
            adev->gfx.funcs->detect_hung_queue &&
-           amdgpu_gfx_me_pipe_reset_supported(adev))
-               return amdgpu_gfx_reset_mes_gfx(adev, NULL, NULL, queue, 0, 
true);
+           amdgpu_gfx_me_pipe_reset_supported(adev)) {
+               r = amdgpu_gfx_reset_mes_gfx(adev, NULL, NULL, queue, 0, true);
+               goto out;
+       }
 
        memset(&queue_input, 0x0, sizeof(struct mes_reset_queue_input));
        queue_input.doorbell_offset = queue->doorbell_index;
@@ -277,7 +308,12 @@ int mes_userq_reset(struct amdgpu_usermode_queue *queue)
                }
        }
 
-       return mes_userq_reset_hw(queue, &queue_input);
+       r = mes_userq_reset_hw(queue, &queue_input);
+out:
+       if (r && queue->queue_type == AMDGPU_HW_IP_GFX &&
+           mes_userq_gfx_engine_reset_supported(adev))
+               r = mes_userq_reset_gfx_engine(queue);
+       return r;
 }
 
 int mes_userq_reset_queue(struct amdgpu_device *adev,
-- 
2.50.1

Reply via email to