From: David Zhang <yidong.zhang@amd.com>
To: <quic_jhugo@quicinc.com>, <karol.wachowski@linux.intel.com>,
<max.zhen@amd.com>, <lizhi.hou@amd.com>, <ogabbay@kernel.org>,
<dri-devel@lists.freedesktop.org>, <linux-kernel@vger.kernel.org>
Cc: Nishad Saraf <nishad.saraf@amd.com>, <sonal.santan@amd.com>,
<mario.limonciello@amd.com>, David Zhang <yidong.zhang@amd.com>
Subject: [PATCH V2 4/5] accel/amdxdna: Handle AIE4 firmware notifications
Date: Mon, 30 Nov 2026 14:59:03 -0800 [thread overview]
Message-ID: <20261130225904.1103363-5-yidong.zhang@amd.com> (raw)
In-Reply-To: <20261130225904.1103363-1-yidong.zhang@amd.com>
From: Nishad Saraf <nishad.saraf@amd.com>
Firmware sends notifications, such as context errors, as messages with
ID 0. Add an optional mailbox handler for ID 0 messages, and use it on
the AIE4 management channel to reset the context on a context error.
Signed-off-by: Nishad Saraf <nishad.saraf@amd.com>
Signed-off-by: David Zhang <yidong.zhang@amd.com>
---
drivers/accel/amdxdna/aie4_error.c | 104 ++++++++++++++++++++++++
drivers/accel/amdxdna/aie4_msg_priv.h | 31 +++++++
drivers/accel/amdxdna/aie4_pci.c | 2 +
drivers/accel/amdxdna/aie4_pci.h | 1 +
drivers/accel/amdxdna/amdxdna_mailbox.c | 18 ++++
drivers/accel/amdxdna/amdxdna_mailbox.h | 17 ++++
6 files changed, 173 insertions(+)
diff --git a/drivers/accel/amdxdna/aie4_error.c b/drivers/accel/amdxdna/aie4_error.c
index a56bf5891bf1..9ca99af3e2c1 100644
--- a/drivers/accel/amdxdna/aie4_error.c
+++ b/drivers/accel/amdxdna/aie4_error.c
@@ -407,3 +407,107 @@ void aie4_async_events_stop(struct amdxdna_dev_hdl *ndev)
if (events)
WRITE_ONCE(events->gen, events->gen + 1);
}
+
+/*
+ * struct aie4_async_note - context error notification from firmware
+ * @work: worker that resets the context
+ * @ndev: device handle
+ * @events: pool owning the workqueue
+ * @gen: @events gen when the notification arrived
+ * @ctx_gen: device context generation when the notification arrived
+ * @ctx_id: firmware context ID
+ */
+struct aie4_async_note {
+ struct work_struct work;
+ struct amdxdna_dev_hdl *ndev;
+ struct aie4_async_events *events;
+ u32 gen;
+ u64 ctx_gen;
+ u32 ctx_id;
+};
+
+static void aie4_async_note_worker(struct work_struct *work)
+{
+ struct aie4_async_note *note = container_of(work, struct aie4_async_note, work);
+ struct amdxdna_dev_hdl *ndev = note->ndev;
+ struct amdxdna_dev *xdna = ndev->aie.xdna;
+
+ mutex_lock(&xdna->dev_lock);
+ /* Skip a notification left over from a previous channel. */
+ if (note->gen != note->events->gen)
+ goto unlock;
+
+ /* There is no report, so record it like a job timeout. */
+ aie4_record_async_error(ndev, AMDXDNA_ERROR_NUM_KDS_EXEC, 0, note->ctx_id);
+ aie4_reset_hwctx_by_id(ndev, note->ctx_id, note->ctx_gen, NULL);
+
+unlock:
+ mutex_unlock(&xdna->dev_lock);
+ kfree(note);
+}
+
+/*
+ * Called from the mailbox receive worker for each message firmware sends on
+ * its own, so defer the context reset to the async event workqueue.
+ */
+int aie4_async_note_cb(void *handle, u32 opcode, void __iomem *data, size_t size)
+{
+ struct amdxdna_dev_hdl *ndev = handle;
+ struct aie4_async_events *events = ndev->async_events;
+ struct amdxdna_dev *xdna = ndev->aie.xdna;
+ struct aie4_async_note *note;
+ u32 event_id, type, ctx_id;
+
+ if (opcode != AIE4_MSG_OP_ASYNC_EVENT_NOTE ||
+ size < sizeof(struct aie4_msg_async_note))
+ return -EINVAL;
+
+ event_id = readl(data + offsetof(struct aie4_msg_async_note, event_id));
+ switch (event_id) {
+ case AIE4_ASYNC_NOTE_CONTEXT_ERROR:
+ ctx_id = readl(data + offsetof(struct aie4_msg_async_note,
+ context_error.ctx_id));
+ XDNA_ERR(xdna, "Firmware reported context %u error", ctx_id);
+ break;
+ case AIE4_ASYNC_NOTE_REPORT_DROPPED:
+ type = readl(data + offsetof(struct aie4_msg_async_note,
+ report_dropped.async_event_type));
+ ctx_id = readl(data + offsetof(struct aie4_msg_async_note,
+ report_dropped.ctx_id));
+ /* An AIE error also sends CONTEXT_ERROR; reset only for this one. */
+ if (type != AIE4_ASYNC_EVENT_TYPE_CTX_ERROR) {
+ XDNA_ERR(xdna, "Firmware had no async event buffer, type %u context %u",
+ type, ctx_id);
+ return 0;
+ }
+ XDNA_ERR(xdna,
+ "TDR or uC error on context %u without a report",
+ ctx_id);
+ break;
+ case AIE4_ASYNC_NOTE_POWER_ERROR:
+ XDNA_ERR(xdna, "Firmware reported a power sequencing error");
+ return 0;
+ default:
+ XDNA_DBG(xdna, "Firmware notification %u ignored", event_id);
+ return 0;
+ }
+
+ /* The PF runs no contexts. */
+ if (!events)
+ return 0;
+
+ /* Called from the mailbox receive worker, which must not block. */
+ note = kzalloc_obj(*note, GFP_NOWAIT);
+ if (!note)
+ return -ENOMEM;
+
+ note->ndev = ndev;
+ note->events = events;
+ note->gen = READ_ONCE(events->gen);
+ /* Contexts created after this notification are not the one it reports. */
+ note->ctx_gen = READ_ONCE(ndev->ctx_gen);
+ note->ctx_id = ctx_id;
+ INIT_WORK(¬e->work, aie4_async_note_worker);
+ queue_work(events->wq, ¬e->work);
+ return 0;
+}
diff --git a/drivers/accel/amdxdna/aie4_msg_priv.h b/drivers/accel/amdxdna/aie4_msg_priv.h
index f8c94cf316fd..7a0f89150bff 100644
--- a/drivers/accel/amdxdna/aie4_msg_priv.h
+++ b/drivers/accel/amdxdna/aie4_msg_priv.h
@@ -16,6 +16,8 @@ enum aie4_msg_opcode {
AIE4_MSG_OP_ASYNC_EVENT_REPORT = 0x10004,
AIE4_MSG_OP_SET_RUNTIME_CONFIG = 0x10007,
AIE4_MSG_OP_QUERY_CERT_FIRMWARE_VERSION = 0x1000F,
+ /* Sent by firmware with message ID 0; no response is expected. */
+ AIE4_MSG_OP_ASYNC_EVENT_NOTE = 0x10012,
AIE4_MSG_OP_CREATE_VFS = 0x20001,
AIE4_MSG_OP_DESTROY_VFS = 0x20002,
@@ -402,4 +404,33 @@ struct aie4_async_ctx_error {
struct aie4_msg_app_health_report app_health_report;
};
+/* Events reported with AIE4_MSG_OP_ASYNC_EVENT_NOTE. */
+enum aie4_msg_async_note_id {
+ AIE4_ASYNC_NOTE_FW_LOG_WATERMARK,
+ AIE4_ASYNC_NOTE_FW_TRACE_WATERMARK,
+ AIE4_ASYNC_NOTE_DEBUG_MODE_ACTIVATED,
+ AIE4_ASYNC_NOTE_CONTEXT_ERROR,
+ AIE4_ASYNC_NOTE_REPORT_DROPPED,
+ AIE4_ASYNC_NOTE_POWER_ERROR,
+};
+
+/*
+ * AIE4_MSG_OP_ASYNC_EVENT_NOTE: an event small enough to fit in the message.
+ * @event_id selects the union member.
+ */
+struct aie4_msg_async_note {
+ __u32 event_id;
+ union {
+ __u32 reserved[4];
+ struct {
+ __u32 ctx_id;
+ } context_error;
+ /* A report that firmware had no async event buffer for. */
+ struct {
+ __u32 async_event_type;
+ __u32 ctx_id;
+ } report_dropped;
+ };
+} __packed;
+
#endif /* _AIE4_MSG_PRIV_H_ */
diff --git a/drivers/accel/amdxdna/aie4_pci.c b/drivers/accel/amdxdna/aie4_pci.c
index a45c6bb21aaf..78a739573ad3 100644
--- a/drivers/accel/amdxdna/aie4_pci.c
+++ b/drivers/accel/amdxdna/aie4_pci.c
@@ -250,6 +250,7 @@ static int aie4_mailbox_start(struct amdxdna_dev *xdna,
XDNA_ERR(xdna, "failed to alloc mailbox channel");
return -ENODEV;
}
+ xdna_mailbox_set_async_cb(ndev->aie.mgmt_chann, ndev, aie4_async_note_cb);
mgmt_mb_irq = pci_irq_vector(pdev, ndev->aie.mgmt_chan_idx);
if (mgmt_mb_irq < 0) {
@@ -491,6 +492,7 @@ static int aie4_vf_hw_start(struct amdxdna_dev_hdl *ndev)
/*
* A VF registers no async event buffers, so firmware keeps none of
* its memory across a VF reset or driver reload.
+ * Firmware reports VF context errors with notifications instead.
*/
ret = aie4_restore_power_mode(ndev);
diff --git a/drivers/accel/amdxdna/aie4_pci.h b/drivers/accel/amdxdna/aie4_pci.h
index b24865c9ebc8..6da2810c3fb4 100644
--- a/drivers/accel/amdxdna/aie4_pci.h
+++ b/drivers/accel/amdxdna/aie4_pci.h
@@ -161,6 +161,7 @@ int aie4_async_events_alloc(struct amdxdna_dev_hdl *ndev, u32 num_events);
void aie4_async_events_free(struct amdxdna_dev_hdl *ndev);
int aie4_async_events_register(struct amdxdna_dev_hdl *ndev, u32 num_events);
void aie4_async_events_stop(struct amdxdna_dev_hdl *ndev);
+int aie4_async_note_cb(void *handle, u32 opcode, void __iomem *data, size_t size);
/* aie4_message.c */
int aie4_query_aie_metadata(struct amdxdna_dev_hdl *ndev,
diff --git a/drivers/accel/amdxdna/amdxdna_mailbox.c b/drivers/accel/amdxdna/amdxdna_mailbox.c
index 967f6f1eb764..2d6cce06ecf6 100644
--- a/drivers/accel/amdxdna/amdxdna_mailbox.c
+++ b/drivers/accel/amdxdna/amdxdna_mailbox.c
@@ -66,6 +66,8 @@ struct mailbox_channel {
struct work_struct rx_work;
u32 i2x_head;
bool bad_state;
+ void *async_handle;
+ xdna_mailbox_async_cb_t async_cb;
/* Pre-allocated message buffer pool */
void *msg_buf;
@@ -302,6 +304,15 @@ mailbox_get_resp(struct mailbox_channel *mb_chann, struct xdna_msg_header *heade
u32 slot;
msg_id = header->id;
+ if (!msg_id && mb_chann->async_cb) {
+ ret = mb_chann->async_cb(mb_chann->async_handle, header->opcode,
+ data, header->total_size);
+ if (ret)
+ MB_ERR(mb_chann, "Async handler for opcode 0x%x ret %d",
+ header->opcode, ret);
+ return 0;
+ }
+
if (!mailbox_validate_msgid(msg_id)) {
MB_ERR(mb_chann, "Bad message ID 0x%x", msg_id);
return -EINVAL;
@@ -549,6 +560,13 @@ struct mailbox_channel *xdna_mailbox_alloc_channel(struct mailbox *mb)
return NULL;
}
+void xdna_mailbox_set_async_cb(struct mailbox_channel *mb_chann, void *async_handle,
+ xdna_mailbox_async_cb_t async_cb)
+{
+ mb_chann->async_handle = async_handle;
+ mb_chann->async_cb = async_cb;
+}
+
void xdna_mailbox_free_channel(struct mailbox_channel *mb_chann)
{
if (!mb_chann)
diff --git a/drivers/accel/amdxdna/amdxdna_mailbox.h b/drivers/accel/amdxdna/amdxdna_mailbox.h
index 7f4a40b4230b..cf06bc8c6c09 100644
--- a/drivers/accel/amdxdna/amdxdna_mailbox.h
+++ b/drivers/accel/amdxdna/amdxdna_mailbox.h
@@ -9,6 +9,10 @@
struct mailbox;
struct mailbox_channel;
+/* Handler for a message firmware sends on its own, with message ID 0. */
+typedef int (*xdna_mailbox_async_cb_t)(void *handle, u32 opcode,
+ void __iomem *data, size_t size);
+
/*
* xdna_mailbox_msg - message struct
*
@@ -102,6 +106,19 @@ xdna_mailbox_start_channel(struct mailbox_channel *mb_chann,
u32 xdna_mailbox_intr_reg,
int mb_irq, u32 n_msg);
+/*
+ * xdna_mailbox_set_async_cb() -- set the handler for firmware notifications
+ *
+ * @mb_chann: the handle return from xdna_mailbox_alloc_channel()
+ * @async_handle: handle passed to @async_cb
+ * @async_cb: called from the receive worker for each message with ID 0;
+ * must not block. Its return value is only logged.
+ *
+ * Call before xdna_mailbox_start_channel().
+ */
+void xdna_mailbox_set_async_cb(struct mailbox_channel *mb_chann, void *async_handle,
+ xdna_mailbox_async_cb_t async_cb);
+
/*
* xdna_mailbox_free_channel() -- free mailbox channel
*
--
2.34.1
next prev parent reply other threads:[~2026-11-30 22:59 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 22:58 [PATCH V2 0/5] accel/amdxdna: Add AIE4 async events and TDR David Zhang
2026-11-30 22:59 ` [PATCH V2 1/5] accel/amdxdna: Add AIE4 async event buffers David Zhang
2026-11-30 22:59 ` [PATCH V2 2/5] accel/amdxdna: Add AIE4 context recovery David Zhang
2026-11-30 22:59 ` [PATCH V2 3/5] accel/amdxdna: Check mailbox message overflow David Zhang
2026-11-30 22:59 ` David Zhang [this message]
2026-11-30 22:59 ` [PATCH V2 5/5] accel/amdxdna: Recover hung AIE4 contexts 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=20261130225904.1103363-5-yidong.zhang@amd.com \
--to=yidong.zhang@amd.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=karol.wachowski@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=lizhi.hou@amd.com \
--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 \
/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®