aldebaran_mode2_reset() sends a mode2 reset message and waits for the
SMU to acknowledge it.

But the current code has two problems.

First, the wait loop checks for ret == -ETIME, but ret is 0 after a
successful async send. Because of that, the loop is skipped and the code
does not actually wait for the reset acknowledgment.

Second, when an unexpected response is received, the code prints an
error but does not always set an error code. This can make the function
return success even after a failure.

Fix this by initializing ret to -ETIME before entering the wait loop so
the polling runs correctly. Also set proper error codes for failure
cases.

This makes the function correctly wait for ACK and return proper error
values.

Fixes: e42569d02acb ("drm/amd/pm: Modify mode2 msg sequence on aldebaran")
Reported-by: Dan Carpenter <[email protected]>
Cc: Feifei Xu <[email protected]>
Cc: Lijo Lazar <[email protected]>
Cc: Hawking Zhang <[email protected]>
Cc: Alex Deucher <[email protected]>
Cc: Christian König <[email protected]>
Signed-off-by: Srinivasan Shanmugam <[email protected]>
---
 drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c 
b/drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c
index 259e5a13c1bd..c9e0648390c9 100644
--- a/drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c
+++ b/drivers/gpu/drm/amd/pm/swsmu/smu13/aldebaran_ppt.c
@@ -1847,6 +1847,7 @@ static int aldebaran_mode2_reset(struct smu_context *smu)
                amdgpu_device_load_pci_state(adev->pdev);
 
                dev_dbg(adev->dev, "wait for reset ack\n");
+               ret = -ETIME;
                while (ret == -ETIME && timeout)  {
                        ret = smu_msg_wait_response(ctl, 0);
                        /* Wait a bit more time for getting ACK */
@@ -1859,6 +1860,8 @@ static int aldebaran_mode2_reset(struct smu_context *smu)
                        if (ret != 1) {
                                dev_err(adev->dev, "failed to send mode2 
message \tparam: 0x%08x response %#x\n",
                                                SMU_RESET_MODE_2, ret);
+                               if (!ret)
+                                       ret = -EIO;
                                goto out;
                        }
                }
@@ -1866,6 +1869,7 @@ static int aldebaran_mode2_reset(struct smu_context *smu)
        } else {
                dev_err(adev->dev, "smu fw 0x%x does not support 
MSG_GfxDeviceDriverReset MSG\n",
                                smu->smc_fw_version);
+               ret = -EOPNOTSUPP;
        }
 
        if (ret == 1)
-- 
2.34.1

Reply via email to