From: Wei Huang <wei.huang2@amd.com>
To: <dmaengine@vger.kernel.org>
Cc: <vkoul@kernel.org>, <Frank.Li@kernel.org>, <shuah@kernel.org>,
<nathan.lynch@amd.com>, <wei.huang2@amd.com>,
<mario.limonciello@amd.com>, <Stephen.Bates@amd.com>,
<tycho@kernel.org>, <suravee.suthikulpanit@amd.com>,
<rientjes@google.com>, <John.Kariuki@amd.com>, <jic23@kernel.org>,
<weixugc@google.com>, <bhelgaas@google.com>,
<Shyam.Iyer@dell.com>, <linux-kernel@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>, <linux-pci@vger.kernel.org>
Subject: [PATCH v1 09/44] dmaengine: sdxi: handle hardware error logs
Date: Thu, 19 Nov 2026 14:22:45 -0600 [thread overview]
Message-ID: <20261119202321.1734355-10-wei.huang2@amd.com> (raw)
In-Reply-To: <20261119202321.1734355-1-wei.huang2@amd.com>
Configure the architected error log on vector zero, decode entries
with the packing API, and report hardware failures from a threaded
interrupt.
Co-developed-by: Nathan Lynch <nathan.lynch@amd.com>
Signed-off-by: Nathan Lynch <nathan.lynch@amd.com>
Signed-off-by: Wei Huang <wei.huang2@amd.com>
---
drivers/dma/sdxi/Kconfig | 2 +-
drivers/dma/sdxi/Makefile | 1 +
drivers/dma/sdxi/device.c | 14 ++-
drivers/dma/sdxi/error.c | 246 ++++++++++++++++++++++++++++++++++++++
drivers/dma/sdxi/error.h | 16 +++
drivers/dma/sdxi/sdxi.h | 5 +
6 files changed, 281 insertions(+), 3 deletions(-)
create mode 100644 drivers/dma/sdxi/error.c
create mode 100644 drivers/dma/sdxi/error.h
diff --git a/drivers/dma/sdxi/Kconfig b/drivers/dma/sdxi/Kconfig
index 85e23608405c..e01b5365c154 100644
--- a/drivers/dma/sdxi/Kconfig
+++ b/drivers/dma/sdxi/Kconfig
@@ -5,6 +5,7 @@ config SDXI_CORE
depends on 64BIT
select DMA_ENGINE
select DMA_VIRTUAL_CHANNELS
+ select PACKING
help
Enable support for Smart Data Accelerator Interface (SDXI)
Platform Data Mover devices. SDXI is a vendor-neutral
@@ -32,7 +33,6 @@ config SDXI_KUNIT_TEST
tristate "SDXI unit tests" if !KUNIT_ALL_TESTS
depends on SDXI_CORE && KUNIT
default KUNIT_ALL_TESTS
- select PACKING
help
KUnit tests for parts of the SDXI driver. Does not require
SDXI hardware.
diff --git a/drivers/dma/sdxi/Makefile b/drivers/dma/sdxi/Makefile
index 96d013dcbefd..3f49bc9af955 100644
--- a/drivers/dma/sdxi/Makefile
+++ b/drivers/dma/sdxi/Makefile
@@ -7,6 +7,7 @@ sdxi-core-y := \
descriptor.o \
device.o \
dma.o \
+ error.o \
keys.o \
ring.o
diff --git a/drivers/dma/sdxi/device.c b/drivers/dma/sdxi/device.c
index 0e7d3711ba88..fa9421a5410b 100644
--- a/drivers/dma/sdxi/device.c
+++ b/drivers/dma/sdxi/device.c
@@ -24,6 +24,7 @@
#include "context.h"
#include "dma.h"
+#include "error.h"
#include "hw.h"
#include "keys.h"
#include "mmio.h"
@@ -413,6 +414,10 @@ static int sdxi_fn_activate(struct sdxi_dev *sdxi)
if (err)
return err;
+ err = sdxi_error_init(sdxi);
+ if (err)
+ return err;
+
/*
* SDXI 1.0 4.1.8.9: Set MMIO_CTL0.fn_gsr to GSRV_ACTIVE and
* wait for MMIO_STS0.fn_gsv to reach GSV_ACTIVE or GSV_ERROR.
@@ -423,8 +428,11 @@ static int sdxi_fn_activate(struct sdxi_dev *sdxi)
* code starts client contexts.
*/
err = sdxi_dev_start(sdxi);
- if (err)
- sdxi_dev_stop(sdxi);
+ if (err) {
+ sdxi_error_exit(sdxi);
+ if (sdxi_dev_stop(sdxi))
+ sdxi_dev_force_quiesce(sdxi);
+ }
return err;
}
@@ -464,6 +472,7 @@ int sdxi_register(struct device *dev, const struct sdxi_bus_ops *ops)
mutex_init(&sdxi->cxt_lock);
mutex_init(&sdxi->admin_lock);
mutex_init(&sdxi->rkey_lock);
+ sdxi->error_irq = -1;
dev_set_drvdata(dev, sdxi);
err = sdxi->bus_ops->init(sdxi);
@@ -482,6 +491,7 @@ void sdxi_unregister(struct device *dev)
{
struct sdxi_dev *sdxi = dev_get_drvdata(dev);
+ sdxi_error_exit(sdxi);
if (sdxi_dev_stop(sdxi))
sdxi_dev_force_quiesce(sdxi);
sdxi_client_cxts_exit(sdxi);
diff --git a/drivers/dma/sdxi/error.c b/drivers/dma/sdxi/error.c
new file mode 100644
index 000000000000..561e88d81f41
--- /dev/null
+++ b/drivers/dma/sdxi/error.c
@@ -0,0 +1,246 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * SDXI error log handling.
+ *
+ * Copyright Advanced Micro Devices, Inc.
+ */
+
+#include <linux/bitfield.h>
+#include <linux/device/devres.h>
+#include <linux/dma-mapping.h>
+#include <linux/interrupt.h>
+#include <linux/log2.h>
+#include <linux/packing.h>
+#include <linux/sizes.h>
+#include <linux/string.h>
+
+#include "error.h"
+#include "hw.h"
+#include "mmio.h"
+#include "sdxi.h"
+
+#define SDXI_ERRLOG_TYPE 0x7f7
+#define SDXI_ERRLOG_ENTRIES 64
+#define SDXI_ERRLOG_SIZE (SDXI_ERRLOG_ENTRIES * \
+ sizeof(struct sdxi_errlog_hd_ent))
+
+struct sdxi_errlog_entry {
+ u64 dsc_index;
+ u16 cxt_num;
+ u16 err_class;
+ u16 type;
+ u8 step;
+ u8 buf;
+ u8 sub_step;
+ u8 reaction;
+ bool vl;
+ bool cv;
+ bool div;
+ bool bv;
+};
+
+#define ERRLOG_FIELD(_high, _low, _member) \
+ PACKED_FIELD(_high, _low, struct sdxi_errlog_entry, _member)
+
+static const struct packed_field_u16 sdxi_errlog_fields[] = {
+ ERRLOG_FIELD(0, 0, vl),
+ ERRLOG_FIELD(13, 8, step),
+ ERRLOG_FIELD(26, 16, type),
+ ERRLOG_FIELD(32, 32, cv),
+ ERRLOG_FIELD(33, 33, div),
+ ERRLOG_FIELD(34, 34, bv),
+ ERRLOG_FIELD(38, 36, buf),
+ ERRLOG_FIELD(43, 40, sub_step),
+ ERRLOG_FIELD(46, 44, reaction),
+ ERRLOG_FIELD(63, 48, cxt_num),
+ ERRLOG_FIELD(127, 64, dsc_index),
+ ERRLOG_FIELD(367, 352, err_class),
+};
+
+enum {
+ SDXI_PACKING_QUIRKS = QUIRK_LITTLE_ENDIAN | QUIRK_LSW32_IS_FIRST,
+};
+
+static const char *const sdxi_err_steps[] = {
+ [1] = "internal",
+ [2] = "context L2",
+ [3] = "context L1",
+ [4] = "context control",
+ [5] = "context status",
+ [6] = "write index",
+ [7] = "descriptor",
+ [8] = "completion status",
+ [9] = "atomic return data",
+ [10] = "descriptor buffer",
+ [11] = "AKey lookup",
+ [12] = "RKey lookup",
+};
+
+static const char *sdxi_err_step_name(u8 step)
+{
+ if (step < ARRAY_SIZE(sdxi_err_steps) && sdxi_err_steps[step])
+ return sdxi_err_steps[step];
+
+ return "reserved";
+}
+
+static bool sdxi_errlog_decode(struct sdxi_dev *sdxi,
+ const struct sdxi_errlog_hd_ent *raw,
+ struct sdxi_errlog_entry *entry)
+{
+ unpack_fields(raw, sizeof(*raw), entry, sdxi_errlog_fields,
+ SDXI_PACKING_QUIRKS);
+
+ if (!entry->vl) {
+ dev_err_ratelimited(sdxi->dev,
+ "ignoring error log entry with vl=0\n");
+ return false;
+ }
+ if (entry->type != SDXI_ERRLOG_TYPE) {
+ dev_err_ratelimited(sdxi->dev,
+ "ignoring error log type %#x\n",
+ entry->type);
+ return false;
+ }
+
+ return true;
+}
+
+static void sdxi_errlog_report(struct sdxi_dev *sdxi, u64 read_index,
+ const struct sdxi_errlog_entry *entry)
+{
+ dev_err(sdxi->dev,
+ "error log[%zu]: class=%#x step=%u (%s) substep=%u reaction=%u\n",
+ (size_t)(read_index % SDXI_ERRLOG_ENTRIES), entry->err_class,
+ entry->step, sdxi_err_step_name(entry->step), entry->sub_step,
+ entry->reaction);
+
+ if (entry->cv)
+ dev_err(sdxi->dev, " context=%u\n", entry->cxt_num);
+ if (entry->div)
+ dev_err(sdxi->dev, " descriptor index=%#llx\n",
+ entry->dsc_index);
+ if (entry->bv)
+ dev_err(sdxi->dev, " buffer=%u\n", entry->buf);
+}
+
+static irqreturn_t sdxi_error_irq_thread(int irq, void *data)
+{
+ struct sdxi_dev *sdxi = data;
+ u64 ack_mask = SDXI_MMIO_ERR_STS_STS_BIT |
+ SDXI_MMIO_ERR_STS_OVF_BIT |
+ SDXI_MMIO_ERR_STS_ERR_BIT;
+ u64 write_index;
+ u64 read_index;
+ u64 status;
+ u64 count;
+
+ status = sdxi_read64(sdxi, SDXI_MMIO_ERR_STS);
+ if (!(status & ack_mask))
+ return IRQ_NONE;
+
+ if (status & SDXI_MMIO_ERR_STS_ERR_BIT)
+ dev_err(sdxi->dev, "hardware could not write the error log\n");
+ if (status & SDXI_MMIO_ERR_STS_OVF_BIT)
+ dev_err(sdxi->dev, "error log overflowed\n");
+ if (!(status & SDXI_MMIO_ERR_STS_STS_BIT)) {
+ sdxi_write64(sdxi, SDXI_MMIO_ERR_STS, status & ack_mask);
+ return IRQ_HANDLED;
+ }
+
+ read_index = sdxi_read64(sdxi, SDXI_MMIO_ERR_RD);
+ sdxi_write64(sdxi, SDXI_MMIO_ERR_STS, status & ack_mask);
+ write_index = sdxi_read64(sdxi, SDXI_MMIO_ERR_WRT);
+ dma_rmb();
+
+ if (write_index < read_index) {
+ dev_err(sdxi->dev,
+ "error log index mismatch: read=%#llx write=%#llx\n",
+ read_index, write_index);
+ read_index = write_index;
+ }
+
+ count = write_index - read_index;
+ if (count > SDXI_ERRLOG_ENTRIES)
+ read_index = write_index - SDXI_ERRLOG_ENTRIES;
+
+ while (read_index < write_index) {
+ struct sdxi_errlog_entry entry = {};
+ struct sdxi_errlog_hd_ent raw;
+ size_t index = read_index % SDXI_ERRLOG_ENTRIES;
+
+ memcpy(&raw, &sdxi->err_log[index], sizeof(raw));
+ if (sdxi_errlog_decode(sdxi, &raw, &entry))
+ sdxi_errlog_report(sdxi, read_index, &entry);
+ read_index++;
+ }
+
+ sdxi_write64(sdxi, SDXI_MMIO_ERR_RD, read_index);
+ return IRQ_HANDLED;
+}
+
+int sdxi_error_init(struct sdxi_dev *sdxi)
+{
+ unsigned int size_order;
+ u64 reg;
+ int ret;
+
+ sdxi_write64(sdxi, SDXI_MMIO_ERR_CFG, 0);
+ sdxi_write64(sdxi, SDXI_MMIO_ERR_STS,
+ SDXI_MMIO_ERR_STS_STS_BIT |
+ SDXI_MMIO_ERR_STS_OVF_BIT |
+ SDXI_MMIO_ERR_STS_ERR_BIT);
+
+ sdxi->err_log = dmam_alloc_coherent(sdxi->dev, SDXI_ERRLOG_SIZE,
+ &sdxi->err_log_dma, GFP_KERNEL);
+ if (!sdxi->err_log)
+ return -ENOMEM;
+ memset(sdxi->err_log, 0, SDXI_ERRLOG_SIZE);
+
+ sdxi->error_irq = sdxi->bus_ops->get_irq(sdxi, SDXI_ERROR_VECTOR);
+ if (sdxi->error_irq < 0)
+ return sdxi->error_irq;
+
+ ret = devm_request_threaded_irq(sdxi->dev, sdxi->error_irq, NULL,
+ sdxi_error_irq_thread,
+ IRQF_TRIGGER_NONE, "sdxi-error", sdxi);
+ if (ret)
+ return ret;
+
+ sdxi_write64(sdxi, SDXI_MMIO_ERR_WRT, 0);
+ sdxi_write64(sdxi, SDXI_MMIO_ERR_RD, 0);
+
+ reg = sdxi_read64(sdxi, SDXI_MMIO_ERR_CTL);
+ FIELD_MODIFY(SDXI_MMIO_ERR_CTL_EN, ®, 1);
+ sdxi_write64(sdxi, SDXI_MMIO_ERR_CTL, reg);
+
+ size_order = ilog2(SDXI_ERRLOG_SIZE) - ilog2(SZ_4K);
+ reg = FIELD_PREP(SDXI_MMIO_ERR_CFG_PTR,
+ sdxi->err_log_dma >> ilog2(SZ_4K)) |
+ FIELD_PREP(SDXI_MMIO_ERR_CFG_SZ, size_order) |
+ SDXI_MMIO_ERR_CFG_EN;
+ sdxi_write64(sdxi, SDXI_MMIO_ERR_CFG, reg);
+
+ return 0;
+}
+
+void sdxi_error_exit(struct sdxi_dev *sdxi)
+{
+ u64 reg;
+
+ if (!sdxi->err_log)
+ return;
+
+ sdxi_write64(sdxi, SDXI_MMIO_ERR_CFG, 0);
+
+ reg = sdxi_read64(sdxi, SDXI_MMIO_ERR_CTL);
+ FIELD_MODIFY(SDXI_MMIO_ERR_CTL_EN, ®, 0);
+ sdxi_write64(sdxi, SDXI_MMIO_ERR_CTL, reg);
+
+ if (sdxi->error_irq >= 0)
+ devm_free_irq(sdxi->dev, sdxi->error_irq, sdxi);
+
+ sdxi->error_irq = -1;
+ sdxi->err_log = NULL;
+ sdxi->err_log_dma = 0;
+}
diff --git a/drivers/dma/sdxi/error.h b/drivers/dma/sdxi/error.h
new file mode 100644
index 000000000000..756a4fe45158
--- /dev/null
+++ b/drivers/dma/sdxi/error.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * SDXI error log handling.
+ *
+ * Copyright Advanced Micro Devices, Inc.
+ */
+
+#ifndef DMA_SDXI_ERROR_H
+#define DMA_SDXI_ERROR_H
+
+struct sdxi_dev;
+
+int sdxi_error_init(struct sdxi_dev *sdxi);
+void sdxi_error_exit(struct sdxi_dev *sdxi);
+
+#endif /* DMA_SDXI_ERROR_H */
diff --git a/drivers/dma/sdxi/sdxi.h b/drivers/dma/sdxi/sdxi.h
index 48e4631c621c..65e0191391db 100644
--- a/drivers/dma/sdxi/sdxi.h
+++ b/drivers/dma/sdxi/sdxi.h
@@ -98,6 +98,11 @@ struct sdxi_dev {
u8 rkey_order;
bool rkey_cap;
+ /* Error log */
+ int error_irq;
+ struct sdxi_errlog_hd_ent *err_log;
+ dma_addr_t err_log_dma;
+
struct dma_pool *cxt_ctl_pool;
unsigned int nr_vectors;
--
2.56.1
next prev parent reply other threads:[~2026-11-19 20:25 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 20:22 [PATCH v1 00/44] dmaengine: sdxi: add userspace control and management support Wei Huang
2026-11-19 20:22 ` [PATCH v1 01/44] dmaengine: sdxi: cache hardware version for feature gating Wei Huang
2026-11-19 20:22 ` [PATCH v1 02/44] dmaengine: sdxi: define key and error MMIO registers Wei Huang
2026-11-19 20:22 ` [PATCH v1 03/44] dmaengine: sdxi: define SDXI hardware layouts Wei Huang
2026-11-19 20:22 ` [PATCH v1 04/44] dmaengine: sdxi: encode admin descriptors Wei Huang
2026-11-19 20:22 ` [PATCH v1 05/44] dmaengine: sdxi: support timeout-aware completion waits Wei Huang
2026-11-19 20:22 ` [PATCH v1 06/44] dmaengine: sdxi: support the full context table hierarchy Wei Huang
2026-11-19 20:22 ` [PATCH v1 07/44] dmaengine: sdxi: implement synchronous admin operations Wei Huang
2026-11-19 20:22 ` [PATCH v1 08/44] dmaengine: sdxi: add core RKey table management Wei Huang
2026-11-19 20:22 ` Wei Huang [this message]
2026-11-19 20:22 ` [PATCH v1 10/44] dmaengine: sdxi: separate context and submission resources Wei Huang
2026-11-19 20:22 ` [PATCH v1 11/44] dmaengine: sdxi: support userspace context lifetimes Wei Huang
2026-11-19 20:22 ` [PATCH v1 12/44] dmaengine: sdxi: route context interrupts to eventfd Wei Huang
2026-11-19 20:22 ` [PATCH v1 13/44] dmaengine: sdxi: kill user contexts on fatal errors Wei Huang
2026-11-19 20:22 ` [PATCH v1 14/44] dmaengine: sdxi: define the ioctl UAPI surface Wei Huang
2026-11-19 20:22 ` [PATCH v1 15/44] dmaengine: sdxi: add internal ioctl definitions Wei Huang
2026-11-19 20:22 ` [PATCH v1 16/44] dmaengine: sdxi: register core character devices Wei Huang
2026-11-19 20:22 ` [PATCH v1 17/44] dmaengine: sdxi: implement fixed-size ioctl dispatch Wei Huang
2026-11-19 20:22 ` [PATCH v1 18/44] dmaengine: sdxi: implement userspace context file operations Wei Huang
2026-11-19 20:22 ` [PATCH v1 19/44] dmaengine: sdxi: validate and copy key ioctl payloads Wei Huang
2026-11-19 20:22 ` [PATCH v1 20/44] dmaengine: sdxi: implement RKey management ioctls Wei Huang
2026-11-19 20:22 ` [PATCH v1 21/44] dmaengine: sdxi: implement AKey " Wei Huang
2026-11-19 20:22 ` [PATCH v1 22/44] dmaengine: sdxi: expose operation-group discovery Wei Huang
2026-11-19 20:22 ` [PATCH v1 23/44] dmaengine: sdxi: implement typed vendor admin transport Wei Huang
2026-11-19 20:23 ` [PATCH v1 24/44] dmaengine: sdxi: expose character device attributes Wei Huang
2026-11-19 20:23 ` [PATCH v1 25/44] dmaengine: sdxi: add PF and VF device naming Wei Huang
2026-11-19 20:23 ` [PATCH v1 26/44] dmaengine: sdxi: add SDXI trace events Wei Huang
2026-11-19 20:23 ` [PATCH v1 27/44] dmaengine: sdxi: support suspend and resume Wei Huang
2026-11-19 20:23 ` [PATCH v1 28/44] dmaengine: sdxi: amd: define QoS request formats Wei Huang
2026-11-19 20:23 ` [PATCH v1 29/44] dmaengine: sdxi: amd: add QoS validation scaffolding Wei Huang
2026-11-19 20:23 ` [PATCH v1 30/44] dmaengine: sdxi: amd: build QoS admin descriptors Wei Huang
2026-11-19 20:23 ` [PATCH v1 31/44] dmaengine: sdxi: amd: prevalidate QoS operations Wei Huang
2026-11-19 20:23 ` [PATCH v1 32/44] dmaengine: sdxi: amd: execute QoS vendor operations Wei Huang
2026-11-19 20:23 ` [PATCH v1 33/44] dmaengine: sdxi: amd: register QoS vendor handler Wei Huang
2026-11-19 20:23 ` [PATCH v1 34/44] dmaengine: sdxi: amd: test QoS validation with KUnit Wei Huang
2026-11-19 20:23 ` [PATCH v1 35/44] selftests: sdxi: add build scaffold Wei Huang
2026-11-19 20:23 ` [PATCH v1 36/44] selftests: sdxi: add shared descriptor and context helpers Wei Huang
2026-11-19 20:23 ` [PATCH v1 37/44] selftests: sdxi: test context creation Wei Huang
2026-11-19 20:23 ` [PATCH v1 38/44] selftests: sdxi: test NOP descriptor submission Wei Huang
2026-11-19 20:23 ` [PATCH v1 39/44] selftests: sdxi: test copy submission and ring wrap Wei Huang
2026-11-19 20:23 ` [PATCH v1 40/44] selftests: sdxi: exercise dataplane error paths Wei Huang
2026-11-19 20:23 ` [PATCH v1 41/44] selftests: sdxi: test device ioctls Wei Huang
2026-11-19 20:23 ` [PATCH v1 42/44] selftests: sdxi: test vendor admin ioctls Wei Huang
2026-11-19 20:23 ` [PATCH v1 43/44] selftests: sdxi: test RKey ioctls Wei Huang
2026-11-19 20:23 ` [PATCH v1 44/44] MAINTAINERS: cover SDXI UAPI, vendor files, and selftests Wei Huang
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=20261119202321.1734355-10-wei.huang2@amd.com \
--to=wei.huang2@amd.com \
--cc=Frank.Li@kernel.org \
--cc=John.Kariuki@amd.com \
--cc=Shyam.Iyer@dell.com \
--cc=Stephen.Bates@amd.com \
--cc=bhelgaas@google.com \
--cc=dmaengine@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=nathan.lynch@amd.com \
--cc=rientjes@google.com \
--cc=shuah@kernel.org \
--cc=suravee.suthikulpanit@amd.com \
--cc=tycho@kernel.org \
--cc=vkoul@kernel.org \
--cc=weixugc@google.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®