From: Mario Limonciello <mario.limonciello@amd.com>
To: Lizhi Hou <lizhi.hou@amd.com>,
ogabbay@kernel.org, quic_jhugo@quicinc.com,
dri-devel@lists.freedesktop.org
Cc: linux-kernel@vger.kernel.org, min.ma@amd.com, max.zhen@amd.com,
sonal.santan@amd.com, king.tam@amd.com
Subject: Re: [PATCH V1 1/7] accel/amdxdna: Add device status for aie2 devices
Date: Wed, 4 Dec 2024 16:26:42 -0600 [thread overview]
Message-ID: <e551fe89-6e39-4393-9e50-cae4a819e947@amd.com> (raw)
In-Reply-To: <20241204213729.3113941-2-lizhi.hou@amd.com>
On 12/4/2024 15:37, Lizhi Hou wrote:
> 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>
> ---
> drivers/accel/amdxdna/aie2_pci.c | 17 +++++++++++++++++
> drivers/accel/amdxdna/aie2_pci.h | 7 +++++++
> drivers/accel/amdxdna/amdxdna_mailbox.c | 6 ------
> 3 files changed, 24 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/accel/amdxdna/aie2_pci.c b/drivers/accel/amdxdna/aie2_pci.c
> index 349ada697e48..19c76b2b204b 100644
> --- a/drivers/accel/amdxdna/aie2_pci.c
> +++ b/drivers/accel/amdxdna/aie2_pci.c
> @@ -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:
> diff --git a/drivers/accel/amdxdna/aie2_pci.h b/drivers/accel/amdxdna/aie2_pci.h
> index 6a2686255c9c..5d262ae5c9bb 100644
> --- a/drivers/accel/amdxdna/aie2_pci.h
> +++ b/drivers/accel/amdxdna/aie2_pci.h
> @@ -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;
> +
> + u32 dev_status;
Shouldn't this be "enum aie2_dev_status" not "u32"?
> };
>
> #define DEFINE_BAR_OFFSET(reg_name, bar, reg_addr) \
> diff --git a/drivers/accel/amdxdna/amdxdna_mailbox.c b/drivers/accel/amdxdna/amdxdna_mailbox.c
> index 415d99abaaa3..eab79dbb8b25 100644
> --- a/drivers/accel/amdxdna/amdxdna_mailbox.c
> +++ b/drivers/accel/amdxdna/amdxdna_mailbox.c
> @@ -530,9 +530,6 @@ xdna_mailbox_create_channel(struct mailbox *mb,
>
> 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);
>
next prev parent reply other threads:[~2024-12-04 22:26 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-04 21:37 [PATCH V1 0/7] AMD NPU driver improvements Lizhi Hou
2024-12-04 21:37 ` [PATCH V1 1/7] accel/amdxdna: Add device status for aie2 devices Lizhi Hou
2024-12-04 22:26 ` Mario Limonciello [this message]
2024-12-05 5:15 ` Lizhi Hou
2024-12-04 21:37 ` [PATCH V1 2/7] accel/amdxdna: Replace mmput with mmput_async to avoid dead lock Lizhi Hou
2024-12-04 21:37 ` [PATCH V1 3/7] accel/amdxdna: Add RyzenAI-npu6 support Lizhi Hou
2024-12-04 21:37 ` [PATCH V1 4/7] accel/amdxdna: Replace idr api with xarray Lizhi Hou
2024-12-04 21:37 ` [PATCH V1 5/7] accel/amdxdna: Add query firmware version Lizhi Hou
2024-12-04 22:24 ` Mario Limonciello
2024-12-05 5:14 ` Lizhi Hou
2024-12-04 21:37 ` [PATCH V1 6/7] accel/amdxdna: Enhance power management settings Lizhi Hou
2024-12-05 3:52 ` Mario Limonciello
2024-12-06 1:13 ` Lizhi Hou
2024-12-04 21:37 ` [PATCH V1 7/7] accel/amdxdna: Read firmware interface version from registers Lizhi Hou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e551fe89-6e39-4393-9e50-cae4a819e947@amd.com \
--to=mario.limonciello@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=king.tam@amd.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizhi.hou@amd.com \
--cc=max.zhen@amd.com \
--cc=min.ma@amd.com \
--cc=ogabbay@kernel.org \
--cc=quic_jhugo@quicinc.com \
--cc=sonal.santan@amd.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®