]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
accel/amdxdna: Add device status for aie2 devices
authorLizhi Hou <lizhi.hou@amd.com>
Fri, 6 Dec 2024 21:59:54 +0000 (13:59 -0800)
committerJeffrey Hugo <quic_jhugo@quicinc.com>
Fri, 13 Dec 2024 16:29:04 +0000 (09:29 -0700)
Add device status to track if aie2_hw_start() or aie2_hw_stop() is
re-entered. In aie2_hw_stop(), call drmm_kfree to free mbox.

Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
Reviewed-by: Mario Limonciello <mario.limonciello@amd.com>
Reviewed-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
Signed-off-by: Jeffrey Hugo <quic_jhugo@quicinc.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20241206220001.164049-2-lizhi.hou@amd.com
drivers/accel/amdxdna/aie2_pci.c
drivers/accel/amdxdna/aie2_pci.h
drivers/accel/amdxdna/amdxdna_mailbox.c

index 349ada697e4849742df63734a6551c02751c50e5..19c76b2b204b3cd37c2719812d34be3a04cf7402 100644 (file)
@@ -267,12 +267,22 @@ static void aie2_hw_stop(struct amdxdna_dev *xdna)
        struct pci_dev *pdev = to_pci_dev(xdna->ddev.dev);
        struct amdxdna_dev_hdl *ndev = xdna->dev_handle;
 
+       if (ndev->dev_status <= AIE2_DEV_INIT) {
+               XDNA_ERR(xdna, "device is already stopped");
+               return;
+       }
+
        aie2_mgmt_fw_fini(ndev);
        xdna_mailbox_stop_channel(ndev->mgmt_chann);
        xdna_mailbox_destroy_channel(ndev->mgmt_chann);
+       ndev->mgmt_chann = NULL;
+       drmm_kfree(&xdna->ddev, ndev->mbox);
+       ndev->mbox = NULL;
        aie2_psp_stop(ndev->psp_hdl);
        aie2_smu_fini(ndev);
        pci_disable_device(pdev);
+
+       ndev->dev_status = AIE2_DEV_INIT;
 }
 
 static int aie2_hw_start(struct amdxdna_dev *xdna)
@@ -283,6 +293,11 @@ static int aie2_hw_start(struct amdxdna_dev *xdna)
        u32 xdna_mailbox_intr_reg;
        int mgmt_mb_irq, ret;
 
+       if (ndev->dev_status >= AIE2_DEV_START) {
+               XDNA_INFO(xdna, "device is already started");
+               return 0;
+       }
+
        ret = pci_enable_device(pdev);
        if (ret) {
                XDNA_ERR(xdna, "failed to enable device, ret %d", ret);
@@ -345,6 +360,8 @@ static int aie2_hw_start(struct amdxdna_dev *xdna)
                goto destroy_mgmt_chann;
        }
 
+       ndev->dev_status = AIE2_DEV_START;
+
        return 0;
 
 destroy_mgmt_chann:
index 6a2686255c9c04e5c7d29fec4b561b504dffdcd9..1c6f07d9b805dcf145d5d1f63775c2462a1f0d33 100644 (file)
@@ -149,6 +149,11 @@ struct amdxdna_hwctx_priv {
        struct drm_syncobj              *syncobj;
 };
 
+enum aie2_dev_status {
+       AIE2_DEV_INIT,
+       AIE2_DEV_START,
+};
+
 struct amdxdna_dev_hdl {
        struct amdxdna_dev              *xdna;
        const struct amdxdna_dev_priv   *priv;
@@ -171,6 +176,8 @@ struct amdxdna_dev_hdl {
        struct mailbox                  *mbox;
        struct mailbox_channel          *mgmt_chann;
        struct async_events             *async_events;
+
+       enum aie2_dev_status            dev_status;
 };
 
 #define DEFINE_BAR_OFFSET(reg_name, bar, reg_addr) \
index 415d99abaaa3b27353108599bf59ce1528832fcc..eab79dbb8b251b54e759d8174c97abb2adca1157 100644 (file)
@@ -530,9 +530,6 @@ free_and_out:
 
 int xdna_mailbox_destroy_channel(struct mailbox_channel *mb_chann)
 {
-       if (!mb_chann)
-               return 0;
-
        MB_DBG(mb_chann, "IRQ disabled and RX work cancelled");
        free_irq(mb_chann->msix_irq, mb_chann);
        destroy_workqueue(mb_chann->work_q);
@@ -548,9 +545,6 @@ int xdna_mailbox_destroy_channel(struct mailbox_channel *mb_chann)
 
 void xdna_mailbox_stop_channel(struct mailbox_channel *mb_chann)
 {
-       if (!mb_chann)
-               return;
-
        /* Disable an irq and wait. This might sleep. */
        disable_irq(mb_chann->msix_irq);