mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lizhi Hou <lizhi.hou@amd.com>
To: David Zhang <yidong.zhang@amd.com>, <quic_jhugo@quicinc.com>,
	<karol.wachowski@linux.intel.com>, <max.zhen@amd.com>,
	<ogabbay@kernel.org>, <dri-devel@lists.freedesktop.org>,
	<linux-kernel@vger.kernel.org>
Cc: <sonal.santan@amd.com>, <mario.limonciello@amd.com>,
	Nishad Saraf <nishad.saraf@amd.com>
Subject: Re: [PATCH V0 08/21] accel/amdxdna: Restore power mode override on AIE4 hardware start
Date: Mon, 28 Sep 2026 11:48:45 -0700	[thread overview]
Message-ID: <4911a7fd-036c-1319-3ad8-d1ef8dc7f461@amd.com> (raw)
In-Reply-To: <20260926013448.3840921-9-yidong.zhang@amd.com>


On 9/25/26 18:34, David Zhang wrote:
> Firmware boots in POWER_MODE_DEFAULT after a reload, so re-send the
> cached user power mode override whenever the hardware starts. This
> ensures the driver cache (ndev->pw_mode) and the firmware power state
> remain consistent when the hardware is reinitialized (e.g. across
> suspend/resume and runtime PM cycles).
>
> Add aie4_restore_power_mode() to re-send the cached override once the
> mailbox is initialized in aie4_pf_hw_start(), aie4_vf_hw_start(), and
> aie4_classic_hw_start(). On a fresh probe, pw_mode is POWER_MODE_DEFAULT
> so this is a no-op. Failure is returned to the caller so hardware start
> aborts cleanly, preventing the driver from continuing with a dead
> management channel if a timeout occurs.
>
> In aie4_classic_hw_start(), if aie4_restore_power_mode() fails after
> aie4_partition_init() has already succeeded, tear down the partition
> before releasing the mailbox so the firmware partition created just
> above isn't leaked on this error path. aie4_vf_hw_start() needs no such
> fix: it never calls aie4_partition_init() itself, so partition teardown
> is not its responsibility; the PF reclaims VF partitions.
>
> Note that system and runtime suspend/resume callbacks (.suspend and
> .resume) for AIE4 are implemented in a subsequent patch ("accel/amdxdna:
> Implement AIE4 suspend and resume"), where the resume handlers invoke
> these hw_start functions and trigger this power mode restoration.
>
> Co-developed-by: Nishad Saraf <nishad.saraf@amd.com>
> Signed-off-by: Nishad Saraf <nishad.saraf@amd.com>
> Signed-off-by: David Zhang <yidong.zhang@amd.com>
> ---
>   drivers/accel/amdxdna/aie4_message.c |  7 ++++--
>   drivers/accel/amdxdna/aie4_pci.c     | 35 ++++++++++++++++++++++++++++
>   drivers/accel/amdxdna/aie4_pci.h     |  3 +++
>   3 files changed, 43 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/accel/amdxdna/aie4_message.c b/drivers/accel/amdxdna/aie4_message.c
> index a7025995d0e0..f5a17e10cc86 100644
> --- a/drivers/accel/amdxdna/aie4_message.c
> +++ b/drivers/accel/amdxdna/aie4_message.c
> @@ -166,7 +166,10 @@ int aie4_msg_set_power_mode(struct amdxdna_dev_hdl *ndev, u8 power_mode)
>   
>   	ret = aie_send_mgmt_msg_wait(&ndev->aie, &msg);
>   	if (ret)
> -		return ret;
> +		XDNA_WARN(ndev->aie.xdna,
> +			  "Failed to set power mode %u, ret %d", (u32)power_mode, ret);
> +	else
> +		XDNA_DBG(ndev->aie.xdna, "Power mode set to %u", (u32)power_mode);
>   
> -	return 0;
> +	return ret;

Should this be part of patch 07/21?

Lizhi

>   }
> diff --git a/drivers/accel/amdxdna/aie4_pci.c b/drivers/accel/amdxdna/aie4_pci.c
> index 3a063d3ffa94..f72d0dac8263 100644
> --- a/drivers/accel/amdxdna/aie4_pci.c
> +++ b/drivers/accel/amdxdna/aie4_pci.c
> @@ -295,6 +295,27 @@ static int aie4_query(struct amdxdna_dev_hdl *ndev)
>   	return 0;
>   }
>   
> +/*
> + * Firmware always boots in POWER_MODE_DEFAULT after a (re)load, so re-send the
> + * cached user override whenever the hardware starts. This keeps the driver
> + * cache (ndev->pw_mode) and the firmware power state consistent across
> + * suspend/resume and runtime PM cycles. On a fresh probe pw_mode is
> + * POWER_MODE_DEFAULT and this is a no-op.
> + *
> + * Power override is a per-VF property in firmware: each supervisor (VF) stores
> + * its own requested mode and the hypervisor arbitrates globally by taking the
> + * highest mode across all supervisors. A full firmware reload on suspend clears
> + * every supervisor override back to default, so each device type (PF, VF and
> + * classic) must re-send its own cached override on resume.
> + */
> +int aie4_restore_power_mode(struct amdxdna_dev_hdl *ndev)
> +{
> +	if (ndev->pw_mode == POWER_MODE_DEFAULT)
> +		return 0;
> +
> +	return aie4_msg_set_power_mode(ndev, ndev->pw_mode);
> +}
> +
>   static int aie4_pf_hw_start(struct amdxdna_dev_hdl *ndev)
>   {
>   	int ret;
> @@ -311,6 +332,10 @@ static int aie4_pf_hw_start(struct amdxdna_dev_hdl *ndev)
>   	if (ret)
>   		goto mbox_fini;
>   
> +	ret = aie4_restore_power_mode(ndev);
> +	if (ret)
> +		goto mbox_fini;
> +
>   	return 0;
>   
>   mbox_fini:
> @@ -348,6 +373,10 @@ static int aie4_vf_hw_start(struct amdxdna_dev_hdl *ndev)
>   	if (ret)
>   		goto mailbox_fini;
>   
> +	ret = aie4_restore_power_mode(ndev);
> +	if (ret)
> +		goto mailbox_fini;
> +
>   	return 0;
>   
>   mailbox_fini:
> @@ -389,8 +418,14 @@ static int aie4_classic_hw_start(struct amdxdna_dev_hdl *ndev)
>   	if (ret)
>   		goto mailbox_fini;
>   
> +	ret = aie4_restore_power_mode(ndev);
> +	if (ret)
> +		goto partition_fini;
> +
>   	return 0;
>   
> +partition_fini:
> +	aie4_partition_fini(ndev);
>   mailbox_fini:
>   	aie4_mailbox_fini(ndev);
>   stop_fw:
> diff --git a/drivers/accel/amdxdna/aie4_pci.h b/drivers/accel/amdxdna/aie4_pci.h
> index 98b637279257..fd2c50dc8080 100644
> --- a/drivers/accel/amdxdna/aie4_pci.h
> +++ b/drivers/accel/amdxdna/aie4_pci.h
> @@ -87,6 +87,9 @@ int aie4_hwctx_init(struct amdxdna_hwctx *hwctx);
>   void aie4_hwctx_fini(struct amdxdna_hwctx *hwctx);
>   int aie4_cmd_wait(struct amdxdna_hwctx *hwctx, u64 seq, u32 timeout);
>   
> +/* aie4_pci.c */
> +int aie4_restore_power_mode(struct amdxdna_dev_hdl *ndev);
> +
>   /* aie4_sriov.c */
>   #if IS_ENABLED(CONFIG_PCI_IOV)
>   int aie4_sriov_configure(struct amdxdna_dev *xdna, int num_vfs);

  reply	other threads:[~2026-09-28 18:48 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-26  1:34 [PATCH V0 00/21] accel/amdxdna: Kernel submission and PM for AIE4 David Zhang
2026-09-26  1:34 ` [PATCH V0 01/21] accel/amdxdna: Rename NPU3 firmware files David Zhang
2026-09-26  1:34 ` [PATCH V0 02/21] accel/amdxdna: Remove mmap for doorbell David Zhang
2026-09-26  1:34 ` [PATCH V0 03/21] accel/amdxdna: Add CERT firmware version support David Zhang
2026-09-26  1:34 ` [PATCH V0 04/21] accel/amdxdna: Upgrade firmware version to 6.0 David Zhang
2026-09-28 17:08   ` Lizhi Hou
2026-09-26  1:34 ` [PATCH V0 05/21] accel/amdxdna: Add NPU3 classic device support David Zhang
2026-09-26  1:34 ` [PATCH V0 06/21] accel/amdxdna: Add AIE version query to aie4_get_info David Zhang
2026-09-26  1:34 ` [PATCH V0 07/21] accel/amdxdna: Add get and set power_mode for AIE4 David Zhang
2026-09-28 18:39   ` Lizhi Hou
2026-09-26  1:34 ` [PATCH V0 08/21] accel/amdxdna: Restore power mode override on AIE4 hardware start David Zhang
2026-09-28 18:48   ` Lizhi Hou [this message]
2026-09-26  1:34 ` [PATCH V0 09/21] accel/amdxdna: Add clock, DPM frequency, and resource info queries for AIE4 David Zhang
2026-09-26  1:34 ` [PATCH V0 10/21] accel/amdxdna: Add context switch hysteresis with debugfs control David Zhang
2026-09-26  1:34 ` [PATCH V0 11/21] accel/amdxdna: Refactor AIE4 hardware initialization sequence David Zhang
2026-09-26  1:34 ` [PATCH V0 12/21] accel/amdxdna: Decouple AIE4 doorbell and MSI-X notification transport hooks David Zhang
2026-09-28 20:16   ` Lizhi Hou
2026-09-26  1:34 ` [PATCH V0 13/21] accel/amdxdna: Implement AIE4 kernel queue lifecycle and memory layout David Zhang
2026-09-26  1:34 ` [PATCH V0 14/21] accel/amdxdna: Fix fence timeline name and context allocation David Zhang
2026-09-28 21:06   ` Lizhi Hou
2026-09-26  1:34 ` [PATCH V0 15/21] accel/amdxdna: Prepare for AIE4 command submission David Zhang
2026-09-26  1:34 ` [PATCH V0 16/21] accel/amdxdna: Implement AIE4 command packet building and submission David Zhang
2026-09-26  1:34 ` [PATCH V0 17/21] accel/amdxdna: Finalize runtime PM before acquiring dev_lock on removal David Zhang
2026-09-26  1:34 ` [PATCH V0 18/21] accel/amdxdna: Implement AIE4 suspend and resume David Zhang
2026-09-26  1:34 ` [PATCH V0 19/21] accel/amdxdna: Link SR-IOV VFs for power management sequencing David Zhang
2026-09-26  1:34 ` [PATCH V0 20/21] accel/amdxdna: Implement runtime suspend and resume support David Zhang
2026-09-26  1:34 ` [PATCH V0 21/21] accel/amdxdna: Add stub hwctx_config for AIE4 David Zhang

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=4911a7fd-036c-1319-3ad8-d1ef8dc7f461@amd.com \
    --to=lizhi.hou@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=karol.wachowski@linux.intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mario.limonciello@amd.com \
    --cc=max.zhen@amd.com \
    --cc=nishad.saraf@amd.com \
    --cc=ogabbay@kernel.org \
    --cc=quic_jhugo@quicinc.com \
    --cc=sonal.santan@amd.com \
    --cc=yidong.zhang@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®