From: Alex Hung <[email protected]>

[WHAT]
Add KUnit tests for amdgpu_dm_execute_fused_io() covering a matching
reply, and a stale reply that times out and aborts the request.

Cc: Bhawanpreet Lakha <[email protected]>
Signed-off-by: Alex Hung <[email protected]>
Signed-off-by: Chenyu Chen <[email protected]>
---
 .../amd/display/amdgpu_dm/amdgpu_dm_dmub.c    |  1 +
 .../amdgpu_dm/tests/amdgpu_dm_dmub_test.c     | 73 +++++++++++++++++++
 2 files changed, 74 insertions(+)

diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_dmub.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_dmub.c
index 6c26fd361ce4..024c2395d2c2 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_dmub.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_dmub.c
@@ -1018,6 +1018,7 @@ bool amdgpu_dm_execute_fused_io(
        mutex_unlock(&dm->dpia_aux_lock);
        return result;
 }
+EXPORT_IF_KUNIT(amdgpu_dm_execute_fused_io);
 
 int amdgpu_dm_process_dmub_set_config_sync(
                struct dc_context *ctx,
diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_dmub_test.c 
b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_dmub_test.c
index 8117ae4a2aef..9c0171b86c67 100644
--- a/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_dmub_test.c
+++ b/drivers/gpu/drm/amd/display/amdgpu_dm/tests/amdgpu_dm_dmub_test.c
@@ -1589,6 +1589,76 @@ static void dm_test_abort_fused_io_no_dmub_srv(struct 
kunit *test)
        abort_fused_io(ctx, req);
 }
 
+/* Tests for amdgpu_dm_execute_fused_io() */
+
+#define DM_TEST_FUSED_DDC_LINE 2
+#define DM_TEST_FUSED_ID       0x5a
+
+/*
+ * Fill @cmd with a fused IO request the fake DMUB echoes back as accepted, and
+ * seed the reply slot of its DDC line with a reply carrying @reply_id as if
+ * the DMUB outbox callback had already delivered it.
+ */
+static struct completion *dm_test_prepare_fused_io(struct amdgpu_device *adev,
+                                                  union dmub_rb_cmd *cmd, u8 
reply_id)
+{
+       struct fused_io_sync *sync = &adev->dm.fused_io[DM_TEST_FUSED_DDC_LINE];
+       struct dmub_cmd_fused_request *reply = (struct dmub_cmd_fused_request 
*)sync->reply_data;
+
+       cmd->fused_io.header.ret_status = 1;
+       cmd->fused_io.request.status = FUSED_REQUEST_STATUS_SUCCESS;
+       cmd->fused_io.request.identifier = DM_TEST_FUSED_ID;
+       cmd->fused_io.request.u.aux.ddc_line = DM_TEST_FUSED_DDC_LINE;
+
+       init_completion(&sync->replied);
+       reply->status = FUSED_REQUEST_STATUS_REPLY;
+       reply->identifier = reply_id;
+       complete(&sync->replied);
+
+       return &sync->replied;
+}
+
+/**
+ * dm_test_execute_fused_io_reply_matches - Test fused IO returns the matching 
reply
+ * @test: The KUnit test context
+ *
+ * Once DMUB accepts the request, a reply with the same identifier must be
+ * copied into the caller's request and the reply completion rearmed.
+ */
+static void dm_test_execute_fused_io_reply_matches(struct kunit *test)
+{
+       struct amdgpu_device *adev = dm_test_alloc_adev_with_link(test);
+       union dmub_rb_cmd cmd = { 0 };
+       struct completion *replied = dm_test_prepare_fused_io(adev, &cmd, 
DM_TEST_FUSED_ID);
+
+       KUNIT_EXPECT_TRUE(test, amdgpu_dm_execute_fused_io(adev, 
adev->dm.dc->links[0], &cmd, 1,
+                                                          1000));
+       KUNIT_EXPECT_EQ(test, cmd.fused_io.request.status, 
FUSED_REQUEST_STATUS_REPLY);
+       KUNIT_EXPECT_FALSE(test, completion_done(replied));
+}
+
+/**
+ * dm_test_execute_fused_io_reply_mismatch_aborts - Test a stale reply leads 
to abort
+ * @test: The KUnit test context
+ *
+ * A reply for a different identifier is discarded; when no matching reply
+ * arrives before the timeout, the request is marked timed out and an abort
+ * command follows the execute command into the DMUB inbox.
+ */
+static void dm_test_execute_fused_io_reply_mismatch_aborts(struct kunit *test)
+{
+       struct amdgpu_device *adev = dm_test_alloc_adev_with_link(test);
+       u32 wrpt = adev->dm.dmub_srv->inbox1.rb.wrpt;
+       union dmub_rb_cmd cmd = { 0 };
+
+       dm_test_prepare_fused_io(adev, &cmd, DM_TEST_FUSED_ID + 1);
+
+       KUNIT_EXPECT_FALSE(test, amdgpu_dm_execute_fused_io(adev, 
adev->dm.dc->links[0], &cmd, 1,
+                                                           1000));
+       KUNIT_EXPECT_EQ(test, cmd.fused_io.request.status, 
FUSED_REQUEST_STATUS_TIMEOUT);
+       KUNIT_EXPECT_EQ(test, adev->dm.dmub_srv->inbox1.rb.wrpt, wrpt + 2 * 
DMUB_RB_CMD_SIZE);
+}
+
 /*
  * Fake CGS device: the DMUB register callbacks reach the hardware through
  * cgs_read_register()/cgs_write_register(), which dispatch via the ops table
@@ -2191,6 +2261,9 @@ static struct kunit_case amdgpu_dm_dmub_tests[] = {
        KUNIT_CASE_SLOW(dm_test_process_dmub_set_config_sync_timeout),
        /* abort_fused_io() */
        KUNIT_CASE(dm_test_abort_fused_io_no_dmub_srv),
+       /* amdgpu_dm_execute_fused_io() */
+       KUNIT_CASE(dm_test_execute_fused_io_reply_matches),
+       KUNIT_CASE(dm_test_execute_fused_io_reply_mismatch_aborts),
        {}
 };
 
-- 
2.43.0

Reply via email to