mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
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 24/44] dmaengine: sdxi: expose character device attributes
Date: Thu, 19 Nov 2026 14:23:00 -0600	[thread overview]
Message-ID: <20261119202321.1734355-25-wei.huang2@amd.com> (raw)
In-Reply-To: <20261119202321.1734355-1-wei.huang2@amd.com>

Add read-only version, context count, function identity, and NUMA
attributes as sysfs to each SDXI character device. Derive context
accounting from live sessions so users can retrieve accurate
information.

Signed-off-by: Wei Huang <wei.huang2@amd.com>
---
 drivers/dma/sdxi/Makefile  |  1 +
 drivers/dma/sdxi/context.c |  9 ++++-
 drivers/dma/sdxi/context.h |  1 +
 drivers/dma/sdxi/device.c  |  1 +
 drivers/dma/sdxi/ioctl.c   |  2 ++
 drivers/dma/sdxi/sdxi.h    |  2 ++
 drivers/dma/sdxi/sysfs.c   | 70 ++++++++++++++++++++++++++++++++++++++
 drivers/dma/sdxi/sysfs.h   | 13 +++++++
 8 files changed, 98 insertions(+), 1 deletion(-)
 create mode 100644 drivers/dma/sdxi/sysfs.c
 create mode 100644 drivers/dma/sdxi/sysfs.h

diff --git a/drivers/dma/sdxi/Makefile b/drivers/dma/sdxi/Makefile
index 253398a45c74..019038cc91bc 100644
--- a/drivers/dma/sdxi/Makefile
+++ b/drivers/dma/sdxi/Makefile
@@ -13,6 +13,7 @@ sdxi-core-y := \
 	keys.o        \
 	process.o     \
 	ring.o        \
+	sysfs.o       \
 	vendor.o
 
 obj-$(CONFIG_SDXI_PCI) += sdxi-pci.o
diff --git a/drivers/dma/sdxi/context.c b/drivers/dma/sdxi/context.c
index cdaa0f654429..43ffe132cf2e 100644
--- a/drivers/dma/sdxi/context.c
+++ b/drivers/dma/sdxi/context.c
@@ -424,8 +424,11 @@ static int sdxi_publish_cxt(struct sdxi_cxt *cxt,
 	};
 
 	err = configure_L1_entry(ent, &L1_cfg);
-	if (!err)
+	if (!err) {
 		cxt->sdxi->L1_users[l2_idx]++;
+		cxt->sdxi->cxt_count++;
+		cxt->counted = true;
+	}
 
 out_unlock:
 	mutex_unlock(&cxt->sdxi->cxt_lock);
@@ -459,6 +462,10 @@ static void sdxi_rescind_cxt(struct sdxi_cxt *cxt)
 		goto out_unlock;
 
 	sdxi->L1_users[l2_idx]--;
+	if (cxt->counted) {
+		sdxi->cxt_count--;
+		cxt->counted = false;
+	}
 
 out_unlock:
 	mutex_unlock(&sdxi->cxt_lock);
diff --git a/drivers/dma/sdxi/context.h b/drivers/dma/sdxi/context.h
index c245c7ee7841..22a33291020f 100644
--- a/drivers/dma/sdxi/context.h
+++ b/drivers/dma/sdxi/context.h
@@ -65,6 +65,7 @@ struct sdxi_cxt {
 	bool registered;
 	bool published;
 	bool update_pending;
+	bool counted;
 	bool started;
 
 	struct sdxi_cxt_ctl *cxt_ctl;
diff --git a/drivers/dma/sdxi/device.c b/drivers/dma/sdxi/device.c
index 7ebecae3c541..c6b690c39b05 100644
--- a/drivers/dma/sdxi/device.c
+++ b/drivers/dma/sdxi/device.c
@@ -387,6 +387,7 @@ static int sdxi_fn_activate(struct sdxi_dev *sdxi)
 
 	/* Read capabilities and features. */
 	cap0 = sdxi_read64(sdxi, SDXI_MMIO_CAP0);
+	sdxi->sfunc = FIELD_GET(SDXI_MMIO_CAP0_SFUNC, cap0);
 	sdxi->db_stride = SZ_4K;
 	sdxi->db_stride *= 1U << FIELD_GET(SDXI_MMIO_CAP0_DB_STRIDE, cap0);
 	if (sdxi->db_stride > sdxi->db_size)
diff --git a/drivers/dma/sdxi/ioctl.c b/drivers/dma/sdxi/ioctl.c
index feef322a005e..dbd6a916392d 100644
--- a/drivers/dma/sdxi/ioctl.c
+++ b/drivers/dma/sdxi/ioctl.c
@@ -36,6 +36,7 @@
 #include "mmio.h"
 #include "process.h"
 #include "sdxi.h"
+#include "sysfs.h"
 #include "vendor.h"
 
 #define SDXI_MAX_MINORS	256
@@ -1295,6 +1296,7 @@ int sdxi_chardev_register(struct sdxi_dev *sdxi)
 	sdxi->chardev.devt = devt;
 	sdxi->chardev.class = sdxi_class;
 	sdxi->chardev.parent = sdxi->dev;
+	sdxi->chardev.groups = sdxi_dev_groups;
 	dev_set_drvdata(&sdxi->chardev, sdxi);
 	ret = dev_set_name(&sdxi->chardev, "sdxi%d", minor);
 	if (ret)
diff --git a/drivers/dma/sdxi/sdxi.h b/drivers/dma/sdxi/sdxi.h
index 55ca853d6d1c..062ba4be90ad 100644
--- a/drivers/dma/sdxi/sdxi.h
+++ b/drivers/dma/sdxi/sdxi.h
@@ -92,6 +92,7 @@ struct sdxi_dev {
 	struct sdxi_version sdxi_version;
 
 	/* hardware capabilities (from cap0 & cap1) */
+	u16 sfunc;
 	u32 db_stride;			/* doorbell stride in bytes */
 	u64 max_ring_entries;
 	u16 max_cxtid;			/* Maximum context ID allowed. */
@@ -129,6 +130,7 @@ struct sdxi_dev {
 	bool admin_dead;
 	struct xarray client_cxts; /* context id -> (struct sdxi_cxt *) */
 	u32 mmap_gen;
+	unsigned int cxt_count;
 
 	bool has_mailbox;
 
diff --git a/drivers/dma/sdxi/sysfs.c b/drivers/dma/sdxi/sysfs.c
new file mode 100644
index 000000000000..808712952f37
--- /dev/null
+++ b/drivers/dma/sdxi/sysfs.c
@@ -0,0 +1,70 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * SDXI character device attributes.
+ *
+ * Copyright Advanced Micro Devices, Inc.
+ */
+
+#include <linux/device.h>
+#include <linux/sysfs.h>
+
+#include "sdxi.h"
+
+static ssize_t version_show(struct device *dev,
+			    struct device_attribute *attr, char *buf)
+{
+	struct sdxi_dev *sdxi = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%u.%u\n", sdxi->sdxi_version.major,
+			  sdxi->sdxi_version.minor);
+}
+static DEVICE_ATTR_RO(version);
+
+static ssize_t cxt_count_show(struct device *dev,
+			      struct device_attribute *attr, char *buf)
+{
+	struct sdxi_dev *sdxi = dev_get_drvdata(dev);
+	unsigned int count;
+
+	mutex_lock(&sdxi->cxt_lock);
+	count = sdxi->cxt_count;
+	mutex_unlock(&sdxi->cxt_lock);
+
+	return sysfs_emit(buf, "%u\n", count);
+}
+static DEVICE_ATTR_RO(cxt_count);
+
+static ssize_t sfunc_show(struct device *dev,
+			  struct device_attribute *attr, char *buf)
+{
+	struct sdxi_dev *sdxi = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%u\n", sdxi->sfunc);
+}
+static DEVICE_ATTR_RO(sfunc);
+
+static ssize_t numa_node_show(struct device *dev,
+			      struct device_attribute *attr, char *buf)
+{
+	struct sdxi_dev *sdxi = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%d\n", dev_to_node(sdxi->dev));
+}
+static DEVICE_ATTR_RO(numa_node);
+
+static struct attribute *sdxi_dev_attrs[] = {
+	&dev_attr_version.attr,
+	&dev_attr_cxt_count.attr,
+	&dev_attr_sfunc.attr,
+	&dev_attr_numa_node.attr,
+	NULL,
+};
+
+static const struct attribute_group sdxi_dev_group = {
+	.attrs = sdxi_dev_attrs,
+};
+
+const struct attribute_group *sdxi_dev_groups[] = {
+	&sdxi_dev_group,
+	NULL,
+};
diff --git a/drivers/dma/sdxi/sysfs.h b/drivers/dma/sdxi/sysfs.h
new file mode 100644
index 000000000000..91e672bb7adc
--- /dev/null
+++ b/drivers/dma/sdxi/sysfs.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * SDXI sysfs declarations.
+ *
+ * Copyright Advanced Micro Devices, Inc.
+ */
+
+#ifndef DMA_SDXI_SYSFS_H
+#define DMA_SDXI_SYSFS_H
+
+extern const struct attribute_group *sdxi_dev_groups[];
+
+#endif /* DMA_SDXI_SYSFS_H */
-- 
2.56.1


  parent reply	other threads:[~2026-11-19 20:28 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 ` [PATCH v1 09/44] dmaengine: sdxi: handle hardware error logs Wei Huang
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 ` Wei Huang [this message]
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-25-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®