Some IP blocks have engines the hardware can reset on their own, eg.
the graphics and compute engines of the GFX IP. Add an optional
soft_reset_engine() callback, which resets the engine of a ring type and
recovers its user queues. amdgpu_device_ip_soft_reset() uses it instead
of soft_reset(), and then only stops and replays the rings of that type,
holding the reset domain for read: KFD can still add and remove queues
on the other engines.

A hung user queue has no kernel ring, so amdgpu_device_ip_soft_reset()
now takes the device, the ring type and the instance of the engine, and
an optional guilty ring and user queue. On a ring timeout, the instance
is the XCC of the gfx and compute rings, and ring->me of the others.

v3: New patch, replaces the separate engine reset type and helper
    (Timur).
v4: Fold the engine reset into amdgpu_device_ip_soft_reset(), and take
    the ring type instead of a new engine enum (Timur).
    Pass the instance of the engine, needed for the user queues (Lijo).

Suggested-by: Timur Kristóf <[email protected]>
Reviewed-by: Timur Kristóf <[email protected]>
Signed-off-by: Jesse Zhang <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c   | 60 ++++++++++++++++--------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ip.h   |  7 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_job.c  | 16 ++++++-
 drivers/gpu/drm/amd/include/amd_shared.h |  7 +++
 4 files changed, 67 insertions(+), 23 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c
index d0b0d3eaffc5..79bc275e3e0f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ip.c
@@ -421,8 +421,12 @@ static u32 amdgpu_ring_mask_from_ip(const enum 
amd_ip_block_type ip_type)
 /**
  * amdgpu_device_ip_soft_reset() - Perform a graceful soft reset on an IP 
block.
  *
- * @guilty_ring: The ring which is guilty of causing a reset.
- * @guilty_fence: The fence which didn't signal.
+ * @adev: amdgpu device
+ * @ring_type: The type of the ring or user queue that hung.
+ * @inst: The instance of the engine that hung, eg. the XCC or SDMA instance.
+ * @guilty_ring: The ring which is guilty of causing a reset, or NULL.
+ * @guilty_fence: The fence which didn't signal on @guilty_ring.
+ * @guilty_queue: The user queue which is guilty of causing a reset, or NULL.
  *
  * IP block soft reset is used when attempting to recover
  * from a GPU hang in a situation where a more fine grained
@@ -430,55 +434,71 @@ static u32 amdgpu_ring_mask_from_ip(const enum 
amd_ip_block_type ip_type)
  * resets all rings that belong to the same device IP block
  * and re-initializes the device IP block.
  *
+ * IP blocks implementing soft_reset_engine() only reset the engine of
+ * @ring_type on instance @inst and its rings, and recover its user queues.
+ *
  * The reset is handled gracefully, meaning that we try to
  * minimize collateral damage (ie. avoid rejecting non-guilty jobs)
  * as well as back up and restore the contents of all rings
  * so that the system can move on from the hang.
  */
-int amdgpu_device_ip_soft_reset(struct amdgpu_ring *guilty_ring,
-                               struct amdgpu_fence *guilty_fence)
+int amdgpu_device_ip_soft_reset(struct amdgpu_device *adev,
+                               enum amdgpu_ring_type ring_type, u32 inst,
+                               struct amdgpu_ring *guilty_ring,
+                               struct amdgpu_fence *guilty_fence,
+                               struct amdgpu_usermode_queue *guilty_queue)
 {
-       struct amdgpu_device *adev = guilty_ring->adev;
+       const struct amd_ip_funcs *funcs;
        struct amdgpu_ip_block *ip_block;
        enum amd_ip_block_type ip_type;
        u32 ring_type_mask;
+       bool engine;
        int r;
 
-       ip_type = amdgpu_ip_from_ring(guilty_ring->funcs->type);
+       ip_type = amdgpu_ip_from_ring(ring_type);
        ip_block = amdgpu_device_ip_get_ip_block(adev, ip_type);
 
        if (unlikely(!ip_block)) {
-               dev_warn(adev->dev, "IP block not found for ring %s\n",
-                        guilty_ring->name);
+               dev_warn(adev->dev, "IP block not found for ring type %d\n",
+                        ring_type);
                return -EOPNOTSUPP;
        }
 
-       if (!ip_block->version->funcs->soft_reset) {
+       funcs = ip_block->version->funcs;
+       engine = funcs->soft_reset_engine;
+       if (!engine && (!funcs->soft_reset || !guilty_ring)) {
                dev_warn(adev->dev, "IP block soft reset not supported on %s\n",
-                        ip_block->version->funcs->name);
+                        funcs->name);
                return -EOPNOTSUPP;
        }
 
-       dev_err(adev->dev, "Starting %s IP block soft reset\n",
-               ip_block->version->funcs->name);
-
-       ring_type_mask = amdgpu_ring_mask_from_ip(ip_type);
+       dev_err(adev->dev, "Starting %s IP block soft reset\n", funcs->name);
 
-       amdgpu_device_lock_reset_domain(adev->reset_domain);
+       /* An engine reset leaves the others running: let KFD add/remove 
queues. */
+       if (engine) {
+               ring_type_mask = BIT(ring_type);
+               down_read(&adev->reset_domain->sem);
+       } else {
+               ring_type_mask = amdgpu_ring_mask_from_ip(ip_type);
+               amdgpu_device_lock_reset_domain(adev->reset_domain);
+       }
        amdgpu_multi_ring_reset_helper_begin(adev, ring_type_mask, guilty_ring, 
guilty_fence);
 
-       r = ip_block->version->funcs->soft_reset(ip_block);
+       r = engine ? funcs->soft_reset_engine(ip_block, ring_type, inst, 
guilty_queue) :
+                    funcs->soft_reset(ip_block);
 
        r = amdgpu_multi_ring_reset_helper_end(adev, ring_type_mask, 
guilty_ring, r);
-       amdgpu_device_unlock_reset_domain(adev->reset_domain);
+       if (engine)
+               up_read(&adev->reset_domain->sem);
+       else
+               amdgpu_device_unlock_reset_domain(adev->reset_domain);
 
        if (r) {
                dev_err(adev->dev, "Failed %s IP block soft reset: %d\n",
-                       ip_block->version->funcs->name, r);
+                       funcs->name, r);
                return r;
        }
 
-       dev_err(adev->dev, "Successful %s IP block soft reset\n",
-               ip_block->version->funcs->name);
+       dev_err(adev->dev, "Successful %s IP block soft reset\n", funcs->name);
        return 0;
 }
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ip.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ip.h
index 5dd6273982c4..133e7c849a56 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ip.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ip.h
@@ -158,7 +158,10 @@ int amdgpu_device_ip_wait_for_idle(struct amdgpu_device 
*adev,
                                   enum amd_ip_block_type block_type);
 bool amdgpu_device_ip_is_valid(struct amdgpu_device *adev,
                               enum amd_ip_block_type block_type);
-int amdgpu_device_ip_soft_reset(struct amdgpu_ring *guilty_ring,
-                               struct amdgpu_fence *guilty_fence);
+int amdgpu_device_ip_soft_reset(struct amdgpu_device *adev,
+                               enum amdgpu_ring_type ring_type, u32 inst,
+                               struct amdgpu_ring *guilty_ring,
+                               struct amdgpu_fence *guilty_fence,
+                               struct amdgpu_usermode_queue *guilty_queue);
 
 #endif /* __AMDGPU_IP_H__ */
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
index 8689a3c933b2..8d33ae680c5e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_job.c
@@ -85,6 +85,18 @@ static void amdgpu_job_core_dump(struct amdgpu_device *adev,
        }
 }
 
+/* The instance of the IP block engine the ring runs on. */
+static u32 amdgpu_job_ring_inst(struct amdgpu_ring *ring)
+{
+       switch (ring->funcs->type) {
+       case AMDGPU_RING_TYPE_GFX:
+       case AMDGPU_RING_TYPE_COMPUTE:
+               return ring->xcc_id;
+       default:
+               return ring->me;
+       }
+}
+
 static enum drm_gpu_sched_stat amdgpu_job_timedout(struct drm_sched_job *s_job)
 {
        struct amdgpu_ring *ring = to_amdgpu_ring(s_job->sched);
@@ -154,7 +166,9 @@ static enum drm_gpu_sched_stat amdgpu_job_timedout(struct 
drm_sched_job *s_job)
        /* Attempt an IP block soft reset, if supported. */
        if (amdgpu_gpu_recovery &&
            amdgpu_ring_is_reset_type_supported(ring, 
AMDGPU_RESET_TYPE_IP_BLOCK_SOFT_RESET)) {
-               r = amdgpu_device_ip_soft_reset(ring, job->hw_fence);
+               r = amdgpu_device_ip_soft_reset(adev, ring->funcs->type,
+                                               amdgpu_job_ring_inst(ring), 
ring,
+                                               job->hw_fence, NULL);
                if (!r) {
                        atomic_inc(&ring->adev->gpu_reset_counter);
                        drm_dev_wedged_event(adev_to_drm(adev), 
DRM_WEDGE_RECOVERY_NONE, info);
diff --git a/drivers/gpu/drm/amd/include/amd_shared.h 
b/drivers/gpu/drm/amd/include/amd_shared.h
index db24bacb8e0e..8087318c007d 100644
--- a/drivers/gpu/drm/amd/include/amd_shared.h
+++ b/drivers/gpu/drm/amd/include/amd_shared.h
@@ -29,6 +29,7 @@
 
 #define AMD_MAX_USEC_TIMEOUT           1000000  /* 1000 ms */
 struct amdgpu_ip_block;
+struct amdgpu_usermode_queue;
 
 
 /*
@@ -421,6 +422,7 @@ enum DC_DEBUG_MASK {
 };
 
 enum amd_dpm_forced_level;
+enum amdgpu_ring_type;
 
 /**
  * struct amd_ip_funcs - general hooks for managing amdgpu IP Blocks
@@ -441,6 +443,8 @@ enum amd_dpm_forced_level;
  * @complete: handles IP specific changes after resume
  * @wait_for_idle: poll for idle
  * @soft_reset: soft reset the IP block
+ * @soft_reset_engine: soft reset one instance of the engine of a ring type and
+ *                     its user queues
  * @set_clockgating_state: enable/disable cg for the IP block
  * @set_powergating_state: enable/disable pg for the IP block
  * @get_clockgating_state: get current clockgating status
@@ -472,6 +476,9 @@ struct amd_ip_funcs {
        void (*complete)(struct amdgpu_ip_block *ip_block);
        int (*wait_for_idle)(struct amdgpu_ip_block *ip_block);
        int (*soft_reset)(struct amdgpu_ip_block *ip_block);
+       int (*soft_reset_engine)(struct amdgpu_ip_block *ip_block,
+                                enum amdgpu_ring_type ring_type, u32 inst,
+                                struct amdgpu_usermode_queue *guilty_queue);
        int (*set_clockgating_state)(struct amdgpu_ip_block *ip_block,
                                     enum amd_clockgating_state state);
        int (*set_powergating_state)(struct amdgpu_ip_block *ip_block,
-- 
2.50.1

Reply via email to