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 25/44] dmaengine: sdxi: add PF and VF device naming
Date: Thu, 19 Nov 2026 14:23:01 -0600	[thread overview]
Message-ID: <20261119202321.1734355-26-wei.huang2@amd.com> (raw)
In-Reply-To: <20261119202321.1734355-1-wei.huang2@amd.com>

Let the PCI transport format character device names after the core
allocates a minor. Physical functions use sdxiN, while SR-IOV virtual
functions inherit the PF minor and use sdxiNvM as device names. Also
defer VF probe until the PF is registered.

Signed-off-by: Wei Huang <wei.huang2@amd.com>
---
 drivers/dma/sdxi/device.c |  1 +
 drivers/dma/sdxi/ioctl.c  | 19 +++++++++++--------
 drivers/dma/sdxi/pci.c    | 29 ++++++++++++++++++++++++++++-
 drivers/dma/sdxi/sdxi.h   | 15 +++++++++++++++
 4 files changed, 55 insertions(+), 9 deletions(-)

diff --git a/drivers/dma/sdxi/device.c b/drivers/dma/sdxi/device.c
index c6b690c39b05..cb7056916c3d 100644
--- a/drivers/dma/sdxi/device.c
+++ b/drivers/dma/sdxi/device.c
@@ -388,6 +388,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->is_vf = FIELD_GET(SDXI_MMIO_CAP0_VF, 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 dbd6a916392d..98bba3a91ca7 100644
--- a/drivers/dma/sdxi/ioctl.c
+++ b/drivers/dma/sdxi/ioctl.c
@@ -8,7 +8,6 @@
 #include <linux/cdev.h>
 #include <linux/bitfield.h>
 #include <linux/capability.h>
-#include <linux/cleanup.h>
 #include <linux/compat.h>
 #include <linux/anon_inodes.h>
 #include <linux/device.h>
@@ -17,6 +16,7 @@
 #include <linux/fs.h>
 #include <linux/idr.h>
 #include <linux/limits.h>
+#include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/minmax.h>
 #include <linux/module.h>
@@ -1067,7 +1067,6 @@ static int sdxi_mmap_live(struct file *file, struct vm_area_struct *vma)
 {
 	struct sdxi_file *sf = file->private_data;
 	struct sdxi_cxt *cxt;
-	struct sdxi_dev *sdxi;
 	u64 allowed_mask;
 	u64 token;
 	u64 type;
@@ -1081,11 +1080,6 @@ static int sdxi_mmap_live(struct file *file, struct vm_area_struct *vma)
 	if (ret)
 		return ret;
 
-	sdxi = sf->process->sdxi;
-	guard(rwsem_read)(&sdxi->state_lock);
-	if (!sdxi->online)
-		return -ENODEV;
-
 	cxt = sf->cxt;
 	if (!cxt || !cxt->id)
 		return -EINVAL;
@@ -1282,6 +1276,7 @@ void sdxi_chardev_exit(void)
 
 int sdxi_chardev_register(struct sdxi_dev *sdxi)
 {
+	char name[32];
 	dev_t devt;
 	int minor;
 	int ret;
@@ -1292,13 +1287,21 @@ int sdxi_chardev_register(struct sdxi_dev *sdxi)
 		return minor;
 
 	sdxi->minor = minor;
+	if (sdxi->bus_ops->chardev_name) {
+		ret = sdxi->bus_ops->chardev_name(sdxi, name, sizeof(name));
+		if (ret < 0)
+			goto free_minor;
+	} else {
+		scnprintf(name, sizeof(name), "sdxi%d", minor);
+	}
+
 	devt = MKDEV(MAJOR(sdxi_devt), minor);
 	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);
+	ret = dev_set_name(&sdxi->chardev, "%s", name);
 	if (ret)
 		goto free_minor;
 
diff --git a/drivers/dma/sdxi/pci.c b/drivers/dma/sdxi/pci.c
index 52bdaeda08ff..abef318cfd7c 100644
--- a/drivers/dma/sdxi/pci.c
+++ b/drivers/dma/sdxi/pci.c
@@ -11,6 +11,7 @@
 #include <linux/err.h>
 #include <linux/io.h>
 #include <linux/iomap.h>
+#include <linux/kernel.h>
 #include <linux/mm.h>
 #include <linux/module.h>
 #include <linux/overflow.h>
@@ -26,6 +27,8 @@ enum sdxi_mmio_bars {
 	SDXI_PCI_BAR_DOORBELL = 2,
 };
 
+static struct pci_driver sdxi_driver;
+
 static struct pci_dev *sdxi_to_pci_dev(const struct sdxi_dev *sdxi)
 {
 	return to_pci_dev(sdxi->dev);
@@ -167,6 +170,29 @@ static int sdxi_pci_mmap_doorbell(struct sdxi_dev *sdxi,
 				  sdxi->db_stride, vma->vm_page_prot);
 }
 
+static int sdxi_pci_chardev_name(struct sdxi_dev *sdxi, char *name,
+				 size_t size)
+{
+	struct pci_dev *pdev = sdxi_to_pci_dev(sdxi);
+	struct sdxi_dev *pf_sdxi;
+	int vf_id;
+
+	if (!pdev->is_virtfn)
+		return scnprintf(name, size, "sdxi%d", sdxi->minor);
+	if (!sdxi->is_vf)
+		return -EINVAL;
+
+	pf_sdxi = pci_iov_get_pf_drvdata(pdev, &sdxi_driver);
+	if (IS_ERR_OR_NULL(pf_sdxi) || pf_sdxi->minor < 0)
+		return -EPROBE_DEFER;
+
+	vf_id = pci_iov_vf_id(pdev);
+	if (vf_id < 0)
+		return vf_id;
+
+	return scnprintf(name, size, "sdxi%dv%d", pf_sdxi->minor, vf_id);
+}
+
 static const struct sdxi_bus_ops sdxi_pci_ops = {
 	.owner = THIS_MODULE,
 	.init = sdxi_pci_init,
@@ -174,6 +200,7 @@ static const struct sdxi_bus_ops sdxi_pci_ops = {
 	.get_irq = sdxi_pci_get_irq,
 	.force_quiesce = sdxi_pci_force_quiesce,
 	.mmap_doorbell = sdxi_pci_mmap_doorbell,
+	.chardev_name = sdxi_pci_chardev_name,
 };
 
 static int sdxi_pci_probe(struct pci_dev *pdev,
@@ -184,8 +211,8 @@ static int sdxi_pci_probe(struct pci_dev *pdev,
 
 static void sdxi_pci_remove(struct pci_dev *pdev)
 {
-	sdxi_unregister(&pdev->dev);
 	pci_disable_sriov(pdev);
+	sdxi_unregister(&pdev->dev);
 }
 
 static const struct pci_device_id sdxi_id_table[] = {
diff --git a/drivers/dma/sdxi/sdxi.h b/drivers/dma/sdxi/sdxi.h
index 062ba4be90ad..93b4eb80358c 100644
--- a/drivers/dma/sdxi/sdxi.h
+++ b/drivers/dma/sdxi/sdxi.h
@@ -81,6 +81,10 @@ struct sdxi_bus_ops {
 	 */
 	int (*mmap_doorbell)(struct sdxi_dev *sdxi, struct sdxi_cxt *cxt,
 			     struct vm_area_struct *vma);
+	/**
+	 * @chardev_name: Format a bus-specific character device name.
+	 */
+	int (*chardev_name)(struct sdxi_dev *sdxi, char *name, size_t size);
 };
 
 struct sdxi_dev {
@@ -137,6 +141,7 @@ struct sdxi_dev {
 	struct cdev cdev;
 	struct device chardev;
 	int minor;
+	bool is_vf;
 	bool atomic_ops_enabled;
 	bool online;
 	struct rw_semaphore state_lock;	/* online state and user operations */
@@ -144,6 +149,16 @@ struct sdxi_dev {
 	const struct sdxi_bus_ops *bus_ops;
 };
 
+static inline struct device *sdxi_to_dev(const struct sdxi_dev *sdxi)
+{
+	return sdxi->dev;
+}
+
+static inline bool sdxi_fn_reports_vf(const struct sdxi_dev *sdxi)
+{
+	return sdxi->is_vf;
+}
+
 static inline bool sdxi_dev_compatible(const struct sdxi_dev *sdxi,
 				       struct sdxi_version version)
 {
-- 
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 ` [PATCH v1 24/44] dmaengine: sdxi: expose character device attributes Wei Huang
2026-11-19 20:23 ` Wei Huang [this message]
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-26-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®