dmaengine: sdxi: add userspace control and management support
cover dmaengine: sdxi: add userspace control and management support
This series extends the existing SDXI phase 1 "base" driver with versioned userspace-facing interfaces for the native SDXI software stack: device discovery and management, process-owned execution contexts, and a constrained vendor-extension framework.
This series applies on top of Nathan Lynch's phase 1 "base" v4 patchset, ending at commit b8b01d7ab1e5 ("dmaengine: sdxi: Add DMA engine provider"). This series is available at:
https://github.com/AMDESE/linux-sdxi/tree/sdxi-phase2-upstream-v1
At a high level, this new series adds:
- A versioned ioctl UAPI and character-device interface for discovery and management.
- Userspace contexts with process-bound context fds, SVA-backed rings, per-context doorbell mappings, and eventfd interrupt delivery.
- A typed vendor-extension path that accepts structured requests rather than raw descriptors, plus an AMD QoS implementation.
- Test coverage (KUnit + kselftests) and MAINTAINERS updates.
Patch map:
- Patches 1-9: hardware and admin groundwork (feature gating, hardware layouts, admin operations, context hierarchy, RKey setup, error logs).
- Patches 10-13: userspace-context foundations (resource separation, process/SVA and context lifetimes, eventfd delivery, and fatal-error cleanup).
- Patches 14-27: versioned ioctl UAPI + character device (discovery and management, context-fd operations, vendor plumbing, tracing, suspend/resume).
- Patches 28-34: AMD QoS vendor feature (capabilities, configuration, assignment, telemetry), with KUnit coverage.
- Patches 35-44: kselftests (context creation, dataplane basics, error paths, ioctls), plus MAINTAINERS updates.
The interface is structured to separate management from the dataplane. A device fd represents one SDXI function and is used for discovery and function-wide management. SDXI_CREATE_CXT binds the caller's mm through IOMMU SVA, programs userspace-owned ring state, and returns a process-bound context fd for context-scoped control and mapping only that context's doorbell. Userspace submits native descriptors through the SVA-backed ring and mapped doorbell; context interrupts are delivered through a bound eventfd. The kernel owns and validates context and key tables and issues administrative operations for lifecycle and management requests.
Function-wide mutation and RKey management require CAP_SYS_ADMIN. Context ioctls and doorbell mappings are restricted to the creating thread group and mm. AKeys written by non-admin callers are limited to the local function and bound PASID. Vendor handlers authorize typed requests. AMD QoS composes descriptors on the kernel-owned admin context and is PF-only and CAP_SYS_ADMIN-gated.
Companion userspace projects are available at:
- libsdxi: userspace library
https://github.com/AMDESE/libsdxi/tree/sdxi-phase2-upstream-v1
- sdxi-cli: command-line tool
https://github.com/AMDESE/sdxi-cli/tree/sdxi-phase2-upstream-v1
libsdxi wraps the UAPI and provides device discovery, context lifecycle, key management, event handling, and vendor helpers. Sample programs provide quick tests:
$ ./samples/memcopy --dev /dev/sdxi0 $ ./samples/cxt_intr --dev sdxi1
sdxi-cli is an SDXI management tool built on libsdxi. Representative device inspection commands are:
$ sdxi devices $ sdxi show sdxi0 --verbose $ sdxi attrs sdxi0
SDXI supports vendor-specific extensions. This patchset adds AMD QoS management through a separate vendor handler (sdxi-amd-qos when built as a module). AMD QoS userspace management is provided in sdxi-cli under a vendor namespace:
$ sdxi amd qos cap sdxi0 $ sdxi amd qos status sdxi0 $ sdxi amd qos assign sdxi0 --pool 1 --cxt 1
This patchset has been tested on both bare metal and virtual machines with a passed-through VF, with the SDXI core, PCI driver, and KUnit tests built as modules.
SDXI (Smart Data Accelerator Interface) is a SNIA standard for a memory-to-memory data mover and acceleration interface, developed by industry contributors including Dell, AMD, VMware, etc. The SDXI specifications and related material are available at:
- SDXI v1.0a and v1.1 specifications: https://www.snia.org/sdxi
Thanks,
-Wei
Wei Huang (44):
dmaengine: sdxi: cache hardware version for feature gating
dmaengine: sdxi: define key and error MMIO registers
dmaengine: sdxi: define SDXI hardware layouts
dmaengine: sdxi: encode admin descriptors
dmaengine: sdxi: support timeout-aware completion waits
dmaengine: sdxi: support the full context table hierarchy
dmaengine: sdxi: implement synchronous admin operations
dmaengine: sdxi: add core RKey table management
dmaengine: sdxi: handle hardware error logs
dmaengine: sdxi: separate context and submission resources
dmaengine: sdxi: support userspace context lifetimes
dmaengine: sdxi: route context interrupts to eventfd
dmaengine: sdxi: kill user contexts on fatal errors
dmaengine: sdxi: define the ioctl UAPI surface
dmaengine: sdxi: add internal ioctl definitions
dmaengine: sdxi: register core character devices
dmaengine: sdxi: implement fixed-size ioctl dispatch
dmaengine: sdxi: implement userspace context file operations
dmaengine: sdxi: validate and copy key ioctl payloads
dmaengine: sdxi: implement RKey management ioctls
dmaengine: sdxi: implement AKey management ioctls
dmaengine: sdxi: expose operation-group discovery
dmaengine: sdxi: implement typed vendor admin transport
dmaengine: sdxi: expose character device attributes
dmaengine: sdxi: add PF and VF device naming
dmaengine: sdxi: add SDXI trace events
dmaengine: sdxi: support suspend and resume
dmaengine: sdxi: amd: define QoS request formats
dmaengine: sdxi: amd: add QoS validation scaffolding
dmaengine: sdxi: amd: build QoS admin descriptors
dmaengine: sdxi: amd: prevalidate QoS operations
dmaengine: sdxi: amd: execute QoS vendor operations
dmaengine: sdxi: amd: register QoS vendor handler
dmaengine: sdxi: amd: test QoS validation with KUnit
selftests: sdxi: add build scaffold
selftests: sdxi: add shared descriptor and context helpers
selftests: sdxi: test context creation
selftests: sdxi: test NOP descriptor submission
selftests: sdxi: test copy submission and ring wrap
selftests: sdxi: exercise dataplane error paths
selftests: sdxi: test device ioctls
selftests: sdxi: test vendor admin ioctls
selftests: sdxi: test RKey ioctls
MAINTAINERS: cover SDXI UAPI, vendor files, and selftests
MAINTAINERS | 3 + drivers/dma/sdxi/.kunitconfig | 1 + drivers/dma/sdxi/Kconfig | 25 +- drivers/dma/sdxi/Makefile | 13 +- drivers/dma/sdxi/admin.c | 290 ++++ drivers/dma/sdxi/admin.h | 45 + drivers/dma/sdxi/amd/Makefile | 6 + drivers/dma/sdxi/amd/qos.c | 1135 ++++++++++++++ drivers/dma/sdxi/amd/qos.h | 95 ++ drivers/dma/sdxi/amd/qos_kunit.c | 180 +++ drivers/dma/sdxi/completion.c | 37 +- drivers/dma/sdxi/completion.h | 4 + drivers/dma/sdxi/context.c | 980 ++++++++++-- drivers/dma/sdxi/context.h | 74 +- drivers/dma/sdxi/descriptor.c | 89 ++ drivers/dma/sdxi/descriptor.h | 27 + drivers/dma/sdxi/descriptor_kunit.c | 150 ++ drivers/dma/sdxi/device.c | 423 +++++- drivers/dma/sdxi/dma.c | 22 +- drivers/dma/sdxi/error.c | 371 +++++ drivers/dma/sdxi/error.h | 18 + drivers/dma/sdxi/hw.h | 80 + drivers/dma/sdxi/intr.c | 320 ++++ drivers/dma/sdxi/intr.h | 21 + drivers/dma/sdxi/ioctl.c | 1331 +++++++++++++++++ drivers/dma/sdxi/ioctl.h | 78 + drivers/dma/sdxi/keys.c | 577 +++++++ drivers/dma/sdxi/keys.h | 29 + drivers/dma/sdxi/mmio.h | 27 +- drivers/dma/sdxi/pci.c | 91 +- drivers/dma/sdxi/process.c | 200 +++ drivers/dma/sdxi/process.h | 43 + drivers/dma/sdxi/sdxi.h | 96 +- drivers/dma/sdxi/sysfs.c | 70 + drivers/dma/sdxi/sysfs.h | 13 + drivers/dma/sdxi/trace.c | 9 + drivers/dma/sdxi/trace.h | 137 ++ drivers/dma/sdxi/vendor.c | 138 ++ drivers/dma/sdxi/vendor.h | 42 + drivers/dma/sdxi/version.h | 32 + include/uapi/linux/sdxi.h | 569 +++++++ tools/testing/selftests/Makefile | 1 + tools/testing/selftests/sdxi/.gitignore | 7 + tools/testing/selftests/sdxi/Makefile | 35 + tools/testing/selftests/sdxi/admin_cmd.c | 104 ++ tools/testing/selftests/sdxi/config | 2 + tools/testing/selftests/sdxi/context.c | 343 +++++ tools/testing/selftests/sdxi/copy.c | 40 + tools/testing/selftests/sdxi/device.c | 245 +++ tools/testing/selftests/sdxi/error.c | 24 + tools/testing/selftests/sdxi/lib/context.c | 195 +++ tools/testing/selftests/sdxi/lib/descriptor.h | 55 + .../selftests/sdxi/lib/fixture-context.h | 126 ++ .../selftests/sdxi/lib/fixture-device.h | 44 + tools/testing/selftests/sdxi/lib/lib.c | 206 +++ tools/testing/selftests/sdxi/lib/lib.h | 61 + tools/testing/selftests/sdxi/nop.c | 30 + tools/testing/selftests/sdxi/rkey.c | 413 +++++ 58 files changed, 9603 insertions(+), 219 deletions(-) create mode 100644 drivers/dma/sdxi/admin.c create mode 100644 drivers/dma/sdxi/admin.h create mode 100644 drivers/dma/sdxi/amd/Makefile create mode 100644 drivers/dma/sdxi/amd/qos.c create mode 100644 drivers/dma/sdxi/amd/qos.h create mode 100644 drivers/dma/sdxi/amd/qos_kunit.c create mode 100644 drivers/dma/sdxi/error.c create mode 100644 drivers/dma/sdxi/error.h create mode 100644 drivers/dma/sdxi/intr.c create mode 100644 drivers/dma/sdxi/intr.h create mode 100644 drivers/dma/sdxi/ioctl.c create mode 100644 drivers/dma/sdxi/ioctl.h create mode 100644 drivers/dma/sdxi/keys.c create mode 100644 drivers/dma/sdxi/keys.h create mode 100644 drivers/dma/sdxi/process.c create mode 100644 drivers/dma/sdxi/process.h create mode 100644 drivers/dma/sdxi/sysfs.c create mode 100644 drivers/dma/sdxi/sysfs.h create mode 100644 drivers/dma/sdxi/trace.c create mode 100644 drivers/dma/sdxi/trace.h create mode 100644 drivers/dma/sdxi/vendor.c create mode 100644 drivers/dma/sdxi/vendor.h create mode 100644 drivers/dma/sdxi/version.h create mode 100644 include/uapi/linux/sdxi.h create mode 100644 tools/testing/selftests/sdxi/.gitignore create mode 100644 tools/testing/selftests/sdxi/Makefile create mode 100644 tools/testing/selftests/sdxi/admin_cmd.c create mode 100644 tools/testing/selftests/sdxi/config create mode 100644 tools/testing/selftests/sdxi/context.c create mode 100644 tools/testing/selftests/sdxi/copy.c create mode 100644 tools/testing/selftests/sdxi/device.c create mode 100644 tools/testing/selftests/sdxi/error.c create mode 100644 tools/testing/selftests/sdxi/lib/context.c create mode 100644 tools/testing/selftests/sdxi/lib/descriptor.h create mode 100644 tools/testing/selftests/sdxi/lib/fixture-context.h create mode 100644 tools/testing/selftests/sdxi/lib/fixture-device.h create mode 100644 tools/testing/selftests/sdxi/lib/lib.c create mode 100644 tools/testing/selftests/sdxi/lib/lib.h create mode 100644 tools/testing/selftests/sdxi/nop.c create mode 100644 tools/testing/selftests/sdxi/rkey.c
Signature · 1 line
2.56.1
PATCH 1/44 dmaengine: sdxi: cache hardware version for feature gating
Cache the SDXI version reported by MMIO_VERSION and add a small comparison helper for later feature gating. This prepares the core for SDXI HW discovery without changing existing behavior.
--- drivers/dma/sdxi/device.c | 9 ++++++--- drivers/dma/sdxi/sdxi.h | 9 +++++++++ drivers/dma/sdxi/version.h | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) create mode 100644 drivers/dma/sdxi/version.h
drivers/dma/sdxi/device.c +6 -3
@@ -326,9 +326,12 @@ static int sdxi_fn_activate(struct sdxi_dev *sdxi)int err; version =sdxi_read64 (sdxi,SDXI_MMIO_VERSION ); -dev_info (sdxi->dev,"SDXI %llu.%llu device found\n" , -FIELD_GET (SDXI_MMIO_VERSION_MAJOR , version), -FIELD_GET (SDXI_MMIO_VERSION_MINOR , version)); + sdxi->sdxi_version = (struct sdxi_version ) { + .major =FIELD_GET (SDXI_MMIO_VERSION_MAJOR , version), + .minor =FIELD_GET (SDXI_MMIO_VERSION_MINOR , version), + }; +dev_info (sdxi->dev,"SDXI %u.%u device found\n" , + sdxi->sdxi_version.major, sdxi->sdxi_version.minor);/* Read capabilities and features. */ cap0 =sdxi_read64 (sdxi,SDXI_MMIO_CAP0 );
drivers/dma/sdxi/sdxi.h +9 -0
@@ -17,6 +17,7 @@#include <linux/xarray.h> #include "mmio.h" +#include "version.h" #define ID_TO_L1_INDEX (id) ((id) & 0x7F)
@@ -66,6 +67,8 @@ struct sdxi_dev {void __iomem *ctrl_regs;/* virt addr of ctrl registers */ void __iomem *dbs;/* virt addr of doorbells */ +struct sdxi_version sdxi_version; +/* hardware capabilities (from cap0 & cap1) */ u32 db_stride;/* doorbell stride in bytes */ u16 max_cxtid;/* Maximum context ID allowed. */
@@ -90,6 +93,12 @@ struct sdxi_dev {const struct sdxi_bus_ops *bus_ops; }; +static inline bool sdxi_dev_compatible (const struct sdxi_dev *sdxi, +struct sdxi_version version) +{ +return sdxi_version_ge (sdxi->sdxi_version, version); +} +/** * sdxi_alloc_vector() - Allocate an interrupt vector. *
drivers/dma/sdxi/version.h new file +32 -0
@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* SDXI version constants and comparison helpers. +* +* Copyright Advanced Micro Devices, Inc. +*/ + +#ifndef DMA_SDXI_VERSION_H +#define DMA_SDXI_VERSION_H + +#include <linux/types.h> + +struct sdxi_version { +u8 major; +u8 minor; +}; + +#define SDXI_VERSION_1_0 ((struct sdxi_version){ .major = 1, .minor = 0 }) +#define SDXI_VERSION_1_1 ((struct sdxi_version){ .major = 1, .minor = 1 }) + +static inline u16 sdxi_version_as_u16 (struct sdxi_version version) +{ +return (version.major <<8 ) | version.minor; +} + +static inline bool sdxi_version_ge (struct sdxi_version version, +struct sdxi_version minimum) +{ +return sdxi_version_as_u16 (version) >=sdxi_version_as_u16 (minimum); +} + +#endif /* DMA_SDXI_VERSION_H */
Signature · 1 line
2.56.1
PATCH 2/44 dmaengine: sdxi: define key and error MMIO registers
In reply to Wei HuangAdd the MMIO offsets and fields required for SDXI RKey management, error logging, function identity, and VF reporting. Keep the definitions limited to registers consumed by subsequent driver patches.
--- drivers/dma/sdxi/mmio.h | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-)
drivers/dma/sdxi/mmio.h +18 -9
@@ -40,6 +40,7 @@ enum sdxi_reg {#define SDXI_MMIO_CTL0_FN_PASID_VL BIT_ULL(2)#define SDXI_MMIO_CTL0_FN_ERR_INTR_EN BIT_ULL(4)#define SDXI_MMIO_CTL0_FN_PASID GENMASK_ULL(27, 8) +#define SDXI_MMIO_CTL0_FN_GRP_ID GENMASK_ULL(63, 32)/* SDXI 1.0 Table 9-4: MMIO_CTL2 */ #define SDXI_MMIO_CTL2_MAX_BUFFER GENMASK_ULL(3, 0)
@@ -52,17 +53,18 @@ enum sdxi_reg {/* SDXI 1.0 Table 9-6: MMIO_CAP0 */ #define SDXI_MMIO_CAP0_SFUNC GENMASK_ULL(15, 0) +#define SDXI_MMIO_CAP0_VF BIT_ULL(16)#define SDXI_MMIO_CAP0_DB_STRIDE GENMASK_ULL(22, 20)#define SDXI_MMIO_CAP0_MAX_DS_RING_SZ GENMASK_ULL(28, 24)/* SDXI 1.0 Table 9-7: MMIO_CAP1 */ -#define SDXI_MMIO_CAP1_MAX_BUFFER GENMASK_ULL(3, 0) -#define SDXI_MMIO_CAP1_RKEY_CAP BIT_ULL(4) -#define SDXI_MMIO_CAP1_MMIO64 BIT_ULL(6) -#define SDXI_MMIO_CAP1_MAX_AKEY_SZ GENMASK_ULL(15, 12) -#define SDXI_MMIO_CAP1_MAX_CXT GENMASK_ULL(31, 16) - -#define SDXI_MMIO_CAP1_OPB_000_CAP GENMASK_ULL(63, 32) +#define SDXI_MMIO_CAP1_MAX_BUFFER GENMASK_ULL(3, 0) +#define SDXI_MMIO_CAP1_RKEY_CAP BIT_ULL(4) +#define SDXI_MMIO_CAP1_MMIO64 BIT_ULL(6) +#define SDXI_MMIO_CAP1_MAX_ERRLOG_SZ GENMASK_ULL(11, 8) +#define SDXI_MMIO_CAP1_MAX_AKEY_SZ GENMASK_ULL(15, 12) +#define SDXI_MMIO_CAP1_MAX_CXT GENMASK_ULL(31, 16) +#define SDXI_MMIO_CAP1_OPB_000_CAP GENMASK_ULL(63, 32)/* SDXI 1.0 Table 9-8: MMIO_VERSION */ #define SDXI_MMIO_VERSION_MINOR GENMASK_ULL(7, 0)
@@ -72,7 +74,12 @@ enum sdxi_reg {#define SDXI_MMIO_CXT_L2_PTR GENMASK_ULL(63, 12)/* SDXI 1.0 Table 9-10: MMIO_RKEY */ -#define SDXI_MMIO_RKEY_EN BIT_ULL(0) +#define SDXI_MMIO_RKEY_EN BIT_ULL(0) +#define SDXI_MMIO_RKEY_SZ GENMASK_ULL(4, 1) +#define SDXI_MMIO_RKEY_PTR GENMASK_ULL(63, 12) + +/* SDXI 1.0 Table 9-11: MMIO_ERR_CTL */ +#define SDXI_MMIO_ERR_CTL_EN BIT_ULL(0)/* SDXI 1.0 Table 9-12: MMIO_ERR_STS (write one to clear) */ #define SDXI_MMIO_ERR_STS_STS_BIT BIT_ULL(0)
@@ -80,6 +87,8 @@ enum sdxi_reg {#define SDXI_MMIO_ERR_STS_ERR_BIT BIT_ULL(3)/* SDXI 1.0 Table 9-13: MMIO_ERR_CFG */ -#define SDXI_MMIO_ERR_CFG_EN BIT_ULL(0) +#define SDXI_MMIO_ERR_CFG_EN BIT_ULL(0) +#define SDXI_MMIO_ERR_CFG_SZ GENMASK_ULL(5, 1) +#define SDXI_MMIO_ERR_CFG_PTR GENMASK_ULL(63, 12)#endif /* DMA_SDXI_MMIO_H */
Signature · 1 line
2.56.1
PATCH 3/44 dmaengine: sdxi: define SDXI hardware layouts
In reply to Wei HuangAdd the RKey and error-log entry formats, AKey fields, operation-group masks, and AdminGrp descriptor layouts needed by the native SDXI interface. Preserve the existing type names, alignment, and completion definitions. No functional change is introduced.
--- drivers/dma/sdxi/hw.h | 80 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+)
drivers/dma/sdxi/hw.h +80 -0
@@ -45,6 +45,13 @@ struct sdxi_cxt_L1_ent {#define SDXI_CXT_L1_ENT_PASID GENMASK(19, 0)#define SDXI_CXT_L1_ENT_MAX_BUFFER GENMASK(23, 20)__le32 opb_000_enb; +#define SDXI_OPB_000_ADMIN BIT(2) +#define SDXI_OPB_000_ATOMIC_FULL BIT(3) +#define SDXI_OPB_000_INTR BIT(4) +#define SDXI_OPB_000_ATOMIC_MIN BIT(5) +#define SDXI_OPB_000_ATOMIC (SDXI_OPB_000_ATOMIC_FULL | \ + SDXI_OPB_000_ATOMIC_MIN) +#define SDXI_OPB_000_DISC_MASK GENMASK(31, 6)__u8 rsvd_0[8 ]; } __packed__aligned(32) ;static_assert (sizeof (struct sdxi_cxt_L1_ent ) ==32 );
@@ -100,9 +107,14 @@ struct sdxi_akey_ent {__le16 intr_num;#define SDXI_AKEY_ENT_VL BIT(0)#define SDXI_AKEY_ENT_IV BIT(1) +#define SDXI_AKEY_ENT_PV BIT(2) +#define SDXI_AKEY_ENT_STE BIT(3)#define SDXI_AKEY_ENT_INTR_NUM GENMASK(14, 4)__le16 tgt_sfunc;__le32 pasid; +#define SDXI_AKEY_ENT_PASID GENMASK(19, 0) +#define SDXI_AKEY_ENT_PR BIT(29) +#define SDXI_AKEY_ENT_PH GENMASK(31, 30)__le16 stag;__u8 rsvd_0[2 ];__le16 rkey;
@@ -110,6 +122,37 @@ struct sdxi_akey_ent { } __packed__aligned(16) ;static_assert (sizeof (struct sdxi_akey_ent ) ==16 ); +/* SDXI 1.0 Table 3-8: RKey Table Entry (RKEY_ENT) */ +struct sdxi_rkey_ent { +__le16 intr_num; +#define SDXI_RKEY_ENT_VL BIT(0) +#define SDXI_RKEY_ENT_IV BIT(1) +#define SDXI_RKEY_ENT_PV BIT(2) +#define SDXI_RKEY_ENT_STE BIT(3) +#define SDXI_RKEY_ENT_INTR_NUM GENMASK(14, 4) +__le16 req_sfunc; +__le32 pasid; +#define SDXI_RKEY_ENT_PASID GENMASK(19, 0) +#define SDXI_RKEY_ENT_PR BIT(29) +#define SDXI_RKEY_ENT_PH GENMASK(31, 30) +__le16 stag; +__u8 rsvd_0[6 ]; +} __packed__aligned(16) ; +static_assert (sizeof (struct sdxi_rkey_ent ) ==16 ); + +/* SDXI 1.0 Table 3-9: Error Log Header Entry (ERRLOG_HD_ENT) */ +struct sdxi_errlog_hd_ent { +__le32 opcode; +__le16 misc0; +__le16 cxt_num; +__le64 dsc_index; +__u8 rsvd_0[28 ]; +__le16 err_class; +__u8 rsvd_1[2 ]; +__le32 vendor[4 ]; +} __packed__aligned(64) ; +static_assert (sizeof (struct sdxi_errlog_hd_ent ) ==64 ); +/* SDXI 1.0 Table 6-4: CST_BLK (Completion Status Block) */ struct sdxi_cst_blk {__le64 signal;
@@ -141,7 +184,9 @@ struct sdxi_desc {#define SDXI_DSC_VL BIT(0)#define SDXI_DSC_SE BIT(1)#define SDXI_DSC_FE BIT(2) +#define SDXI_DSC_CH BIT(3)#define SDXI_DSC_CSR BIT(4) +#define SDXI_DSC_RB BIT(5)#define SDXI_DSC_SUBTYPE GENMASK(15, 8)#define SDXI_DSC_TYPE GENMASK(26, 16)
@@ -227,6 +272,38 @@ struct sdxi_desc {/* For use with sync.cflags */ #define SDXI_DSC_SYNC_FLT GENMASK(2, 0) +/* SDXI 1.0 Table 6-19: DSC_AKEY_UPD Descriptor Format */ +define_sdxi_dsc (sdxi_dsc_akey_upd, akey_upd, + __u8 rsvd_0; + __u8 vflags; + __le16 vf_num; + __le16 cxt_start; + __le16 cxt_end; + __le16 akey_start; + __le16 akey_end; + __u8 rsvd_1[40]; + ); + +/* SDXI 1.0 Table 6-23: DSC_RKEY_UPD Descriptor Format */ +define_sdxi_dsc (sdxi_dsc_rkey_upd, rkey_upd, + __u8 rsvd_0; + __u8 vflags; + __le16 vf_num; + __u8 rsvd_1[4]; +__le16 rkey_start; +__le16 rkey_end; +__u8 rsvd_2[40 ]; + ); + +/* SDXI 1.1 Table 6-27: DSC_DISC Descriptor Format */ +define_sdxi_dsc (sdxi_dsc_disc, disc, + __le16 index_start; + __le16 index_end; + __u8 rsvd_0[8]; +__le64 addr; +__u8 rsvd_1[32 ]; + ); +#undef define_sdxi_dsc }; } __packed__aligned(64) ;
@@ -249,9 +326,12 @@ enum sdxi_dsc_subtype {/* Administrative */ SDXI_DSC_OP_SUBTYPE_CXT_UPD =0x01 , +SDXI_DSC_OP_SUBTYPE_AKEY_UPD =0x02 ,SDXI_DSC_OP_SUBTYPE_CXT_START_NM =0x03 ,SDXI_DSC_OP_SUBTYPE_CXT_STOP =0x04 ,SDXI_DSC_OP_SUBTYPE_SYNC =0x06 , +SDXI_DSC_OP_SUBTYPE_RKEY_UPD =0x07 , + SDXI_DSC_OP_SUBTYPE_DISC = 0x09, };#endif /* DMA_SDXI_HW_H */
Signature · 1 line
2.56.1
PATCH 4/44 dmaengine: sdxi: encode admin descriptors
In reply to Wei HuangExtend the existing descriptor helpers with key-range synchronization, along with new AKey and RKey update operations. Also introduce a descriptor discovery helper based on SDXI 1.1 Spec. For each layout and validation path, add independent packing-based kunit tests.
--- drivers/dma/sdxi/descriptor.c | 89 +++++++++++++++++ drivers/dma/sdxi/descriptor.h | 27 +++++ drivers/dma/sdxi/descriptor_kunit.c | 150 ++++++++++++++++++++++++++++ 3 files changed, 266 insertions(+)
drivers/dma/sdxi/descriptor.c +89 -0
@@ -7,6 +7,7 @@#include <kunit/test-bug.h> #include <kunit/visibility.h> +#include <linux/align.h> #include <linux/bitfield.h> #include <linux/bug.h> #include <linux/range.h>
@@ -211,6 +212,8 @@ int sdxi_encode_sync(struct sdxi_desc *desc, const struct sdxi_sync *params) .cflags = cflags, .cxt_start = cpu_to_le16(params->range.cxt_start), .cxt_end = cpu_to_le16(params->range.cxt_end), + .key_start = cpu_to_le16(params->key_start), + .key_end = cpu_to_le16(params->key_end), .csb_ptr = cpu_to_le64(csb_ptr), }, };
@@ -218,3 +221,89 @@ int sdxi_encode_sync(struct sdxi_desc *desc, const struct sdxi_sync *params)return 0 ; }EXPORT_SYMBOL_IF_KUNIT (sdxi_encode_sync); + +int sdxi_encode_disc (struct sdxi_desc *desc,const struct sdxi_disc *params) +{ +u64 csb_ptr; +u32 opcode; + +if (params->index_start > params->index_end) +return -EINVAL ; +if (params->index_end >2047 ) +return -EINVAL ; +if (!IS_ALIGNED (params->addr,16 )) +return -EINVAL ; + + opcode =FIELD_PREP (SDXI_DSC_SUBTYPE ,SDXI_DSC_OP_SUBTYPE_DISC ) | +FIELD_PREP (SDXI_DSC_TYPE ,SDXI_DSC_OP_TYPE_ADMIN ); + csb_ptr =FIELD_PREP (SDXI_DSC_NP ,1 ); + + *desc = (typeof(*desc)) { + .disc = (typeof(desc->disc)) { + .opcode = cpu_to_le32(opcode), + .index_start = cpu_to_le16(params->index_start), + .index_end = cpu_to_le16(params->index_end), + .addr = cpu_to_le64(params->addr), + .csb_ptr = cpu_to_le64(csb_ptr), + }, + }; + +return 0 ; +} +EXPORT_SYMBOL_IF_KUNIT (sdxi_encode_disc); + +int sdxi_encode_akey_upd (struct sdxi_desc *desc, +const struct sdxi_akey_upd *params) +{ +u64 csb_ptr; +u32 opcode; + +if (params->range.cxt_start > params->range.cxt_end) +return -EINVAL ; +if (params->akey_start > params->akey_end) +return -EINVAL ; + + opcode =FIELD_PREP (SDXI_DSC_SUBTYPE ,SDXI_DSC_OP_SUBTYPE_AKEY_UPD ) | +FIELD_PREP (SDXI_DSC_TYPE ,SDXI_DSC_OP_TYPE_ADMIN ); + csb_ptr =FIELD_PREP (SDXI_DSC_NP ,1 ); + + *desc = (typeof(*desc)) { + .akey_upd = (typeof(desc->akey_upd)) { + .opcode = cpu_to_le32(opcode), + .cxt_start = cpu_to_le16(params->range.cxt_start), + .cxt_end = cpu_to_le16(params->range.cxt_end), + .akey_start = cpu_to_le16(params->akey_start), + .akey_end = cpu_to_le16(params->akey_end), + .csb_ptr = cpu_to_le64(csb_ptr), + }, + }; + +return 0 ; +} +EXPORT_SYMBOL_IF_KUNIT (sdxi_encode_akey_upd); + +int sdxi_encode_rkey_upd (struct sdxi_desc *desc, +const struct sdxi_rkey_upd *params) +{ +u64 csb_ptr; +u32 opcode; + +if (params->rkey_start > params->rkey_end) +return -EINVAL ; + + opcode =FIELD_PREP (SDXI_DSC_SUBTYPE ,SDXI_DSC_OP_SUBTYPE_RKEY_UPD ) | +FIELD_PREP (SDXI_DSC_TYPE ,SDXI_DSC_OP_TYPE_ADMIN ); + csb_ptr =FIELD_PREP (SDXI_DSC_NP ,1 ); + + *desc = (typeof(*desc)) { + .rkey_upd = (typeof(desc->rkey_upd)) { + .opcode = cpu_to_le32(opcode), + .rkey_start = cpu_to_le16(params->rkey_start), + .rkey_end = cpu_to_le16(params->rkey_end), + .csb_ptr = cpu_to_le64(csb_ptr), + }, + }; + +return 0 ; +} +EXPORT_SYMBOL_IF_KUNIT (sdxi_encode_rkey_upd);
drivers/dma/sdxi/descriptor.h +27 -0
@@ -138,8 +138,35 @@ struct sdxi_sync {SDXI_SYNC_FLT_FN =0x4 , } filter;struct sdxi_cxt_range range; +u16 key_start; +u16 key_end; };int sdxi_encode_sync (struct sdxi_desc *desc,const struct sdxi_sync *params); +struct sdxi_disc { +u16 index_start; +u16 index_end; +dma_addr_t addr; +}; + +int sdxi_encode_disc (struct sdxi_desc *desc,const struct sdxi_disc *params); + +struct sdxi_akey_upd { +struct sdxi_cxt_range range; +u16 akey_start; +u16 akey_end; +}; + +int sdxi_encode_akey_upd (struct sdxi_desc *desc, +const struct sdxi_akey_upd *params); + +struct sdxi_rkey_upd { +u16 rkey_start; +u16 rkey_end; +}; + +int sdxi_encode_rkey_upd (struct sdxi_desc *desc, +const struct sdxi_rkey_upd *params); +#endif /* DMA_SDXI_DESCRIPTOR_H */
drivers/dma/sdxi/descriptor_kunit.c +150 -0
186 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH 5/44 dmaengine: sdxi: support timeout-aware completion waits
In reply to Wei HuangExtend the completion status block API with interruptible and non-interruptible timeout waits and raw flag access. These extensions will be used by the descriptor submission code added later. In the meanhile, keep existing CQ ownership and simple completion mode unchanged.
--- drivers/dma/sdxi/completion.c | 37 ++++++++++++++++++++++++++++------- drivers/dma/sdxi/completion.h | 4 ++++ 2 files changed, 34 insertions(+), 7 deletions(-)
drivers/dma/sdxi/completion.c +30 -7
@@ -7,8 +7,10 @@#include <kunit/visibility.h> #include <linux/bitfield.h> #include <linux/bitmap.h> +#include <linux/delay.h> #include <linux/dma-mapping.h> -#include <linux/iopoll.h> +#include <linux/jiffies.h> +#include <linux/sched/signal.h> #include <linux/slab.h> #include <linux/spinlock.h> #include <linux/wait.h>
@@ -176,14 +178,35 @@ enum sdxi_completion_state sdxi_cst_blk_check(const struct sdxi_cst_blk *cst)int sdxi_cst_blk_poll (const struct sdxi_cst_blk *cst) { +return sdxi_cst_blk_wait_timeout (cst,USEC_PER_SEC /USEC_PER_MSEC , + false); +} + +int sdxi_cst_blk_wait_timeout (const struct sdxi_cst_blk *cst, +unsigned int timeout_ms,bool interruptible) +{ +unsigned long deadline =0 ;enum sdxi_completion_state state; -int ret; - ret =read_poll_timeout (sdxi_cst_blk_check, state, - state !=SDXI_COMPLETION_PENDING , -10 ,USEC_PER_SEC , false, cst); -if (ret) -return ret;/* -ETIMEDOUT */ +if (timeout_ms) + deadline = jiffies +msecs_to_jiffies (timeout_ms); + +for (;;) { + state =sdxi_cst_blk_check (cst); +if (state !=SDXI_COMPLETION_PENDING ) +break ; +if (interruptible &&signal_pending (current)) +return -ERESTARTSYS ; +if (timeout_ms &&time_after (jiffies, deadline)) +return -ETIMEDOUT ; +usleep_range (50 ,200 ); + }return state ==SDXI_COMPLETION_ERROR ? -EIO :0 ; } + +u32 sdxi_cst_blk_flags (const struct sdxi_cst_blk *cst) +{ +dma_rmb (); +return le32_to_cpu (READ_ONCE (cst->flags)); +}
drivers/dma/sdxi/completion.h +4 -0
@@ -47,6 +47,10 @@ static inline void sdxi_cst_blk_init(struct sdxi_cst_blk *cst) }int __must_check sdxi_cst_blk_poll (const struct sdxi_cst_blk *cst); +int __must_check sdxi_cst_blk_wait_timeout (const struct sdxi_cst_blk *cst, +unsigned int timeout_ms, +bool interruptible);enum sdxi_completion_state sdxi_cst_blk_check (const struct sdxi_cst_blk *cst); +u32 sdxi_cst_blk_flags (const struct sdxi_cst_blk *cst);#endif /* DMA_SDXI_COMPLETION_H */
Signature · 1 line
2.56.1
PATCH 6/44 dmaengine: sdxi: support the full context table hierarchy
In reply to Wei HuangRemove the single-L1-table context limit and allocate hardware L1 tables on demand for the full context ID range reported by the function. Keep the existing xarray as the authoritative context registry, and serialize table publication and teardown separately.
--- drivers/dma/sdxi/context.c | 78 +++++++++++++++++++++++++++++++++++--- drivers/dma/sdxi/device.c | 28 ++------------ drivers/dma/sdxi/sdxi.h | 11 ++++-- 3 files changed, 84 insertions(+), 33 deletions(-)
drivers/dma/sdxi/context.c +72 -6
@@ -286,13 +286,51 @@ static void invalidate_L1_entry(struct sdxi_cxt_L1_ent *ent) *ent = (typeof(*ent)) { 0 }; } +static struct sdxi_cxt_L1_table * +sdxi_get_L1_table (struct sdxi_dev *sdxi,u16 l2_idx) +{ +struct sdxi_cxt_L1_table *table; +struct sdxi_cxt_L2_ent *L2_ent; +dma_addr_t dma; +u64 lv01_ptr; + +lockdep_assert_held (&sdxi->cxt_lock); + + table = sdxi->L1_tables[l2_idx]; +if (table) +return table; + + table =dmam_alloc_coherent (sdxi->dev,sizeof (*table), &dma,GFP_KERNEL ); +if (!table) +return NULL ; +memset (table,0 ,sizeof (*table)); + + L2_ent = &sdxi->L2_table->entry[l2_idx]; + lv01_ptr =FIELD_PREP (SDXI_CXT_L2_ENT_LV01_PTR , + dma >>ilog2 (SZ_4K )); + L2_ent->lv01_ptr =cpu_to_le64 (lv01_ptr); +dma_wmb (); +FIELD_MODIFY (SDXI_CXT_L2_ENT_VL , &lv01_ptr,1 ); +WRITE_ONCE (L2_ent->lv01_ptr,cpu_to_le64 (lv01_ptr)); + + sdxi->L1_tables[l2_idx] = table; + sdxi->L1_dma[l2_idx] = dma; + +return table; +} -/* Publish the context control block and L1 entry to hardware. */ +/* +* Publish the context control structure hierarchy to the SDXI +* implementation. L1 pages remain allocated until device teardown so a +* cached L2 pointer can never refer to freed memory. +*/ static int sdxi_publish_cxt (const struct sdxi_cxt *cxt) {struct sdxi_cxt_ctl_cfg ctl_cfg;struct sdxi_cxt_L1_cfg L1_cfg; +struct sdxi_cxt_L1_table *L1_table;struct sdxi_cxt_L1_ent *ent; +u16 l2_idx;u8 l1_idx;int err;
@@ -314,9 +352,16 @@ static int sdxi_publish_cxt(const struct sdxi_cxt *cxt)if (err)return err; + l2_idx =ID_TO_L2_INDEX (cxt->id); l1_idx =ID_TO_L1_INDEX (cxt->id); - ent = &cxt->sdxi->L1_table->entry[l1_idx]; +mutex_lock (&cxt->sdxi->cxt_lock); + L1_table =sdxi_get_L1_table (cxt->sdxi, l2_idx); +if (!L1_table) { + err = -ENOMEM ; + goto out_unlock; + } + ent = &L1_table->entry[l1_idx]; L1_cfg = (typeof (L1_cfg )) { .ka =1 ,
@@ -329,7 +374,15 @@ static int sdxi_publish_cxt(const struct sdxi_cxt *cxt) .opb_000_enb = cxt->sdxi->op_grp_cap, }; -return configure_L1_entry (ent, &L1_cfg); + err =configure_L1_entry (ent, &L1_cfg); +if (!err) + cxt->sdxi->L1_users[l2_idx]++; + +out_unlock: +mutex_unlock (&cxt->sdxi->cxt_lock); +if (err) +invalidate_cxt_ctl (cxt->cxt_ctl); +return err; }static void free_admin_cxt (void *ptr)
@@ -561,7 +614,9 @@ void sdxi_cxt_submit(struct sdxi_cxt *cxt, struct sdxi_slot slot,int sdxi_cxt_exit (struct sdxi_cxt *cxt) {struct sdxi_dev *sdxi = cxt->sdxi; -struct sdxi_cxt_L1_ent *ent; +struct sdxi_cxt_L1_table *L1_table; +u16 l2_idx =ID_TO_L2_INDEX (cxt->id); +u8 l1_idx =ID_TO_L1_INDEX (cxt->id);u8 state;int err;
@@ -572,9 +627,15 @@ int sdxi_cxt_exit(struct sdxi_cxt *cxt)if (state !=CXTV_STOP_SW && state !=CXTV_STOP_FN && state !=CXTV_ERR_FN )return -EBUSY ; - ent = &sdxi->L1_table->entry[ID_TO_L1_INDEX (cxt->id)]; -invalidate_L1_entry (ent); +mutex_lock (&sdxi->cxt_lock); + L1_table = sdxi->L1_tables[l2_idx]; +if (WARN_ON_ONCE (!L1_table)) { +mutex_unlock (&sdxi->cxt_lock); +return -EIO ; + } +invalidate_L1_entry (&L1_table->entry[l1_idx]);invalidate_cxt_ctl (cxt->cxt_ctl); +mutex_unlock (&sdxi->cxt_lock); err =sdxi_cxt_update (cxt);if (err) {
@@ -584,6 +645,11 @@ int sdxi_cxt_exit(struct sdxi_cxt *cxt)return err; } +mutex_lock (&sdxi->cxt_lock); +if (!WARN_ON_ONCE (!sdxi->L1_users[l2_idx])) + sdxi->L1_users[l2_idx]--; +mutex_unlock (&sdxi->cxt_lock); +sdxi_free_cxt (cxt);return 0 ; }
drivers/dma/sdxi/device.c +4 -24
@@ -321,8 +321,7 @@ static int sdxi_fn_prepare(struct sdxi_dev *sdxi)*/ static int sdxi_fn_activate (struct sdxi_dev *sdxi) { -u64 version, cap0, cap1, ctl2, cxt_l2, lv01_ptr; -struct sdxi_cxt_L2_ent *L2_ent; +u64 version, cap0, cap1, ctl2, cxt_l2;int err; version =sdxi_read64 (sdxi,SDXI_MMIO_VERSION );
@@ -344,12 +343,7 @@ static int sdxi_fn_activate(struct sdxi_dev *sdxi)dma_set_max_seg_size (sdxi->dev,min ((u64 )SZ_2M << sdxi->max_buffer,U32_MAX )); -/* -* Constrain the number of client contexts supported by the -* driver to what fits in a single L1 table. -*/ - sdxi->max_cxtid =min (SDXI_L1_TABLE_ENTRIES -1 , -FIELD_GET (SDXI_MMIO_CAP1_MAX_CXT , cap1)); + sdxi->max_cxtid =FIELD_GET (SDXI_MMIO_CAP1_MAX_CXT , cap1);/* Apply our configuration. */ ctl2 =FIELD_PREP (SDXI_MMIO_CTL2_MAX_CXT , sdxi->max_cxtid);
@@ -367,26 +361,11 @@ static int sdxi_fn_activate(struct sdxi_dev *sdxi) &sdxi->L2_dma, GFP_KERNEL);if (!sdxi->L2_table)return -ENOMEM ; +memset (sdxi->L2_table,0 ,sizeof (*sdxi->L2_table)); cxt_l2 =FIELD_PREP (SDXI_MMIO_CXT_L2_PTR , sdxi->L2_dma >>ilog2 (SZ_4K ));sdxi_write64 (sdxi,SDXI_MMIO_CXT_L2 , cxt_l2); -/* SDXI 1.0 4.1.8.3 Context Level 1 Table Setup */ - sdxi->L1_table =dmam_alloc_coherent (sdxi->dev, -sizeof (*sdxi->L1_table), - &sdxi->L1_dma,GFP_KERNEL ); -if (!sdxi->L1_table) -return -ENOMEM ; -/* -* SDXI 1.0 4.1.8.3.c: Initialize the Context level 2 table to -* point to the Context Level 1 [table]. -*/ - L2_ent = &sdxi->L2_table->entry[0 ]; - lv01_ptr =FIELD_PREP (SDXI_CXT_L2_ENT_VL ,1 ) | -FIELD_PREP (SDXI_CXT_L2_ENT_LV01_PTR , - sdxi->L1_dma >>ilog2 (SZ_4K )); - L2_ent->lv01_ptr =cpu_to_le64 (lv01_ptr); -/* * SDXI 1.0 4.1.8.4 Administrative Context *
@@ -445,6 +424,7 @@ int sdxi_register(struct device *dev, const struct sdxi_bus_ops *ops) sdxi->bus_ops = ops;ida_init (&sdxi->vectors);xa_init_flags (&sdxi->client_cxts,XA_FLAGS_ALLOC1 ); +mutex_init (&sdxi->cxt_lock);dev_set_drvdata (dev, sdxi); err = sdxi->bus_ops->init (sdxi);
drivers/dma/sdxi/sdxi.h +8 -3
@@ -13,13 +13,16 @@#include <linux/dev_printk.h> #include <linux/idr.h> #include <linux/io.h> +#include <linux/mutex.h> #include <linux/types.h> #include <linux/xarray.h> +#include "hw.h" #include "mmio.h" #include "version.h" -#define ID_TO_L1_INDEX (id) ((id) & 0x7F) +#define ID_TO_L2_INDEX (id) (((id) >> 7) & 0x1ff) +#define ID_TO_L1_INDEX (id) ((id) & 0x7f)#define DESC_RING_BASE_PTR_SHIFT 6#define CXT_STATUS_PTR_SHIFT 4
@@ -77,8 +80,10 @@ struct sdxi_dev {struct sdxi_cxt_L2_table *L2_table;dma_addr_t L2_dma; -struct sdxi_cxt_L1_table *L1_table; -dma_addr_t L1_dma; +struct sdxi_cxt_L1_table *L1_tables[SDXI_L2_TABLE_ENTRIES ]; +dma_addr_t L1_dma[SDXI_L2_TABLE_ENTRIES ]; +u16 L1_users[SDXI_L2_TABLE_ENTRIES ]; +struct mutex cxt_lock;/* context table serialization */ struct dma_pool *cxt_ctl_pool;
Signature · 1 line
2.56.1
PATCH 7/44 dmaengine: sdxi: implement synchronous admin operations
In reply to Wei HuangMove context start and stop submission out of existing context management code into new admin management files, and build the final AdminGrp helper layer on the existing submission queue and completion queue. Implement AKey and RKey sync helpers as part of AdminGrp. To support vendor modules that will be introduced later, a discovery operations plus a generic exported descriptor path are also added.
--- drivers/dma/sdxi/Makefile | 1 + drivers/dma/sdxi/admin.c | 281 +++++++++++++++++++++++++++++++++++++ drivers/dma/sdxi/admin.h | 45 ++++++ drivers/dma/sdxi/context.c | 136 +----------------- drivers/dma/sdxi/context.h | 13 -- drivers/dma/sdxi/device.c | 33 +++++ drivers/dma/sdxi/dma.c | 22 ++- drivers/dma/sdxi/pci.c | 16 +++ drivers/dma/sdxi/sdxi.h | 8 ++ 9 files changed, 402 insertions(+), 153 deletions(-) create mode 100644 drivers/dma/sdxi/admin.c create mode 100644 drivers/dma/sdxi/admin.h
drivers/dma/sdxi/Makefile +1 -0
@@ -1,6 +1,7 @@ # SPDX-License-Identifier: GPL-2.0 obj-$(CONFIG_SDXI_CORE) += sdxi-core.o sdxi-core-y := \ + admin.o \ completion.o \ context.o \ descriptor.o \
drivers/dma/sdxi/admin.c new file +281 -0
281 lines not on this page · raw message
drivers/dma/sdxi/admin.h new file +45 -0
45 lines not on this page · raw message
drivers/dma/sdxi/context.c +2 -134
160 lines not on this page · raw message
drivers/dma/sdxi/context.h +0 -13
@@ -60,9 +60,6 @@ struct sdxi_cxt *sdxi_cxt_new(struct sdxi_dev *sdxi);int sdxi_cxt_exit (struct sdxi_cxt *cxt);void sdxi_client_cxts_exit (struct sdxi_dev *sdxi); -int sdxi_start_cxt (struct sdxi_cxt *cxt); -void sdxi_stop_cxt (struct sdxi_cxt *cxt); -enum sdxi_submit_flags {SDXI_CXT_SUBMIT_KICK =BIT (0 ),SDXI_CXT_SUBMIT_FENCE =BIT (1 ),
@@ -73,16 +70,6 @@ void sdxi_cxt_attach_cst(struct sdxi_slot slot,void sdxi_cxt_submit (struct sdxi_cxt *cxt,struct sdxi_slot slot,const struct sdxi_completion *comp,enum sdxi_submit_flags flags); -static inline struct sdxi_cxt *to_admin_cxt (const struct sdxi_cxt *cxt) -{ -return cxt->sdxi->admin_cxt; -} - -static inline bool sdxi_cxt_is_admin (const struct sdxi_cxt *cxt) -{ -return cxt ==to_admin_cxt (cxt); -} -static inline void sdxi_cxt_kick (struct sdxi_cxt *cxt) {/*
drivers/dma/sdxi/device.c +33 -0
@@ -245,6 +245,38 @@ static int sdxi_dev_start(struct sdxi_dev *sdxi)return 0 ; } +void sdxi_dev_force_quiesce (struct sdxi_dev *sdxi) +{ +enum sdxi_fn_gsv status =sdxi_dev_gsv (sdxi); +int ret; + +if (status ==SDXI_GSV_STOP ) +return ; + +if (status !=SDXI_GSV_ERROR ) { +sdxi_write_fn_gsr (sdxi,SDXI_GSRV_STOP_HD ); + ret =sdxi_dev_gsv_poll (sdxi, status, + status ==SDXI_GSV_STOP || + status ==SDXI_GSV_ERROR ); +if (!ret && status ==SDXI_GSV_STOP ) +return ; + }else { + ret =0 ; + } + +if (!ret && status ==SDXI_GSV_ERROR ) { +sdxi_write_fn_gsr (sdxi,SDXI_GSRV_RESET ); + ret =sdxi_dev_gsv_poll (sdxi, status, + status ==SDXI_GSV_STOP ); +if (!ret) +return ; + } + +dev_err (sdxi->dev,"failed to quiesce function; disabling bus DMA\n" ); +if (sdxi->bus_ops->force_quiesce) + sdxi->bus_ops->force_quiesce (sdxi); +} +/* Stop the function and discard inherited MMIO configuration. */ static int sdxi_fn_prepare (struct sdxi_dev *sdxi) {
@@ -425,6 +457,7 @@ int sdxi_register(struct device *dev, const struct sdxi_bus_ops *ops)ida_init (&sdxi->vectors);xa_init_flags (&sdxi->client_cxts,XA_FLAGS_ALLOC1 );mutex_init (&sdxi->cxt_lock); +mutex_init (&sdxi->admin_lock);dev_set_drvdata (dev, sdxi); err = sdxi->bus_ops->init (sdxi);
drivers/dma/sdxi/dma.c +16 -6
@@ -20,6 +20,7 @@#include "../dmaengine.h" #include "../virt-dma.h" +#include "admin.h" #include "completion.h" #include "context.h" #include "descriptor.h"
@@ -416,9 +417,12 @@ static int sdxi_dma_alloc_chan_resources(struct dma_chan *dma_chan)if (err) goto free_akey; - err =sdxi_start_cxt (sdchan->cxt); -if (err) + err =sdxi_adm_start_cxt (sdchan->cxt); +if (err) { + sdxi->admin_dead = true; +sdxi_dev_force_quiesce (sdxi); goto free_irq; + }return 0 ; free_irq:
@@ -428,25 +432,31 @@ static int sdxi_dma_alloc_chan_resources(struct dma_chan *dma_chan) free_vector:sdxi_free_vector (sdxi, vector); exit_cxt: -sdxi_cxt_exit (sdchan->cxt); +WARN_ON (sdxi_cxt_exit (sdchan->cxt));return err; }static void sdxi_dma_free_chan_resources (struct dma_chan *dma_chan) {struct sdxi_dma_chan *sdchan =to_sdxi_dma_chan (dma_chan); +struct sdxi_dev *sdxi = sdchan->cxt->sdxi;LIST_HEAD (head); +int err; -sdxi_stop_cxt (sdchan->cxt); + err =sdxi_adm_stop_cxt (sdchan->cxt); +if (WARN_ON (err)) { + sdxi->admin_dead = true; +sdxi_dev_force_quiesce (sdxi); + }free_irq (sdchan->irq, sdchan); -sdxi_free_vector (sdchan->cxt->sdxi, sdchan->vector); +sdxi_free_vector (sdxi, sdchan->vector);sdxi_free_akey (sdchan->cxt, sdchan->akey);/* virt-dma does not know about the driver's pending list. */ scoped_guard(spinlock_irqsave, &sdchan->vchan.lock)list_splice_tail_init (&sdchan->pending, &head);vchan_dma_desc_free_list (&sdchan->vchan, &head);vchan_free_chan_resources (to_virt_chan (dma_chan)); -sdxi_cxt_exit (sdchan->cxt); +WARN_ON (sdxi_cxt_exit (sdchan->cxt)); }int sdxi_dma_register (struct sdxi_dev *sdxi)
drivers/dma/sdxi/pci.c +16 -0
@@ -113,10 +113,26 @@ static int sdxi_pci_get_irq(struct sdxi_dev *sdxi, unsigned int nr)return pci_irq_vector (sdxi_to_pci_dev (sdxi), nr); } +static void sdxi_pci_force_quiesce (struct sdxi_dev *sdxi) +{ +struct pci_dev *pdev =sdxi_to_pci_dev (sdxi); +int ret; + +pci_clear_master (pdev); + ret =pci_try_reset_function (pdev); +if (!ret) +return ; + +dev_err (&pdev->dev,"function reset failed: %d\n" , ret); +if (!pci_wait_for_pending_transaction (pdev)) +dev_err (&pdev->dev,"pending PCI transactions did not drain\n" ); +} +static const struct sdxi_bus_ops sdxi_pci_ops = { .init = sdxi_pci_init, .reset = sdxi_pci_reset, .get_irq = sdxi_pci_get_irq, + .force_quiesce = sdxi_pci_force_quiesce, }; static int sdxi_pci_probe(struct pci_dev *pdev,
drivers/dma/sdxi/sdxi.h +8 -0
@@ -63,6 +63,11 @@ struct sdxi_bus_ops {* @get_irq: Map device interrupt index to Linux IRQ number. */ int (*get_irq)(struct sdxi_dev *sdxi,unsigned int index); +/** +* @force_quiesce: Permanently prevent further bus-mastering DMA after +* device recovery fails. +*/ +void (*force_quiesce)(struct sdxi_dev *sdxi); };struct sdxi_dev {
@@ -91,6 +96,8 @@ struct sdxi_dev {struct ida vectors;struct sdxi_cxt *admin_cxt; +struct mutex admin_lock;/* admin submission serialization */ +bool admin_dead;struct xarray client_cxts;/* context id -> (struct sdxi_cxt *) */ bool has_mailbox;
@@ -138,6 +145,7 @@ static inline int sdxi_vector_to_irq(struct sdxi_dev *sdxi, unsigned int nr)int sdxi_register (struct device *dev,const struct sdxi_bus_ops *ops);void sdxi_unregister (struct device *dev); +void sdxi_dev_force_quiesce (struct sdxi_dev *sdxi);static inline u64 sdxi_read64 (const struct sdxi_dev *sdxi,enum sdxi_reg reg) {
Signature · 1 line
2.56.1
PATCH 8/44 dmaengine: sdxi: add core RKey table management
In reply to Wei HuangAllocate the minimum supported function RKey table when the capability is present, program MMIO_RKEY, and disable the table during teardown. Keep userspace key operations for a later UAPI patch.
--- drivers/dma/sdxi/Makefile | 1 + drivers/dma/sdxi/device.c | 11 ++++-- drivers/dma/sdxi/keys.c | 70 +++++++++++++++++++++++++++++++++++++++ drivers/dma/sdxi/keys.h | 18 ++++++++++ drivers/dma/sdxi/sdxi.h | 8 +++++ 5 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 drivers/dma/sdxi/keys.c create mode 100644 drivers/dma/sdxi/keys.h
drivers/dma/sdxi/Makefile +1 -0
@@ -7,6 +7,7 @@ sdxi-core-y := \ descriptor.o \ device.o \ dma.o \ + keys.o \ ring.o obj-$(CONFIG_SDXI_PCI) += sdxi-pci.o
drivers/dma/sdxi/device.c +9 -2
@@ -25,6 +25,7 @@#include "context.h" #include "dma.h" #include "hw.h" +#include "keys.h" #include "mmio.h" #include "sdxi.h"
@@ -387,6 +388,10 @@ static int sdxi_fn_activate(struct sdxi_dev *sdxi) FIELD_GET(SDXI_MMIO_CAP1_OPB_000_CAP, cap1));sdxi_write64 (sdxi,SDXI_MMIO_CTL2 , ctl2); + err =sdxi_keys_init (sdxi, cap1); +if (err) +return err; +/* SDXI 1.0 4.1.8.2 Context Level 2 Table Setup */ sdxi->L2_table = dmam_alloc_coherent(sdxi->dev, sizeof(*sdxi->L2_table),
@@ -458,6 +463,7 @@ int sdxi_register(struct device *dev, const struct sdxi_bus_ops *ops)xa_init_flags (&sdxi->client_cxts,XA_FLAGS_ALLOC1 );mutex_init (&sdxi->cxt_lock);mutex_init (&sdxi->admin_lock); +mutex_init (&sdxi->rkey_lock);dev_set_drvdata (dev, sdxi); err = sdxi->bus_ops->init (sdxi);
@@ -476,9 +482,10 @@ void sdxi_unregister(struct device *dev) {struct sdxi_dev *sdxi =dev_get_drvdata (dev); -/* Stop/reset is best effort if the hardware cannot be quiesced. */ -sdxi_dev_stop (sdxi); +if (sdxi_dev_stop (sdxi)) +sdxi_dev_force_quiesce (sdxi);sdxi_client_cxts_exit (sdxi); +sdxi_keys_exit (sdxi);ida_destroy (&sdxi->vectors); }EXPORT_SYMBOL_NS_GPL (sdxi_unregister,"SDXI" );
drivers/dma/sdxi/keys.c new file +70 -0
70 lines not on this page · raw message
drivers/dma/sdxi/keys.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* SDXI key table management. +* +* Copyright Advanced Micro Devices, Inc. +*/ + +#ifndef DMA_SDXI_KEYS_H +#define DMA_SDXI_KEYS_H + +#include <linux/types.h> + +struct sdxi_dev ; + +int sdxi_keys_init (struct sdxi_dev *sdxi,u64 cap1); +void sdxi_keys_exit (struct sdxi_dev *sdxi); + +#endif /* DMA_SDXI_KEYS_H */
drivers/dma/sdxi/sdxi.h +8 -0
@@ -90,6 +90,14 @@ struct sdxi_dev {u16 L1_users[SDXI_L2_TABLE_ENTRIES ];struct mutex cxt_lock;/* context table serialization */ +/* RKey table */ +struct mutex rkey_lock; +struct sdxi_rkey_ent *rkey_table; +dma_addr_t rkey_table_dma; +u32 rkey_entries; +u8 rkey_order; +bool rkey_cap; +struct dma_pool *cxt_ctl_pool;unsigned int nr_vectors;
Signature · 1 line
2.56.1
PATCH 9/44 dmaengine: sdxi: handle hardware error logs
In reply to Wei HuangConfigure the architected error log on vector zero, decode entries with the packing API, and report hardware failures from a threaded interrupt.
--- 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
drivers/dma/sdxi/Kconfig +1 -1
@@ -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.
drivers/dma/sdxi/Makefile +1 -0
@@ -7,6 +7,7 @@ sdxi-core-y := \ descriptor.o \ device.o \ dma.o \ + error.o \ keys.o \ ring.o
drivers/dma/sdxi/device.c +12 -2
@@ -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);
drivers/dma/sdxi/error.c new file +246 -0
246 lines not on this page · raw message
drivers/dma/sdxi/error.h new file +16 -0
@@ -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 */
drivers/dma/sdxi/sdxi.h +5 -0
@@ -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;
Signature · 1 line
2.56.1
PATCH 10/44 dmaengine: sdxi: separate context and submission resources
In reply to Wei HuangSplit common context allocation from kernel submission queue allocation and make context table programming consume an explicit control configuration. Kernel and admin contexts retain the existing SQ/CQ model while later userspace contexts can provide PASID-backed ring addresses.
--- drivers/dma/sdxi/context.c | 120 ++++++++++++++++++++++++++----------- drivers/dma/sdxi/context.h | 3 + drivers/dma/sdxi/device.c | 2 + drivers/dma/sdxi/pci.c | 1 + drivers/dma/sdxi/sdxi.h | 1 + 5 files changed, 91 insertions(+), 36 deletions(-)
drivers/dma/sdxi/context.c +84 -36
@@ -17,6 +17,7 @@#include <linux/errno.h> #include <linux/idr.h> #include <linux/iommu.h> +#include <linux/overflow.h> #include <linux/slab.h> #include <linux/types.h> #include <asm/barrier.h>
@@ -81,23 +82,14 @@ static struct sdxi_cxt *sdxi_alloc_cxt(struct sdxi_dev *sdxi) cxt->sdxi = sdxi;ida_init (&cxt->akey_ida); - - cxt->ring_state =kzalloc_obj (*cxt->ring_state,GFP_KERNEL ); -if (!cxt->ring_state) -return NULL ; - - cxt->sq =sdxi_sq_alloc (sdxi,DEFAULT_DESC_RING_ENTRIES ); -if (!cxt->sq) -return NULL ; - - cxt->cst_pool =sdxi_cst_pool_create (sdxi,DEFAULT_DESC_RING_ENTRIES ); -if (!cxt->cst_pool) -return NULL ; + cxt->pasid =IOMMU_NO_PASID ; + cxt->opb_000_enb = sdxi->op_grp_cap; cxt->akey_table =dma_alloc_coherent (dev,sizeof (*cxt->akey_table), &cxt->akey_table_dma,GFP_KERNEL );if (!cxt->akey_table)return NULL ; +memset (cxt->akey_table,0 ,sizeof (*cxt->akey_table)); cxt->cxt_ctl =dma_pool_zalloc (sdxi->cxt_ctl_pool,GFP_KERNEL , &cxt->cxt_ctl_dma);
@@ -107,6 +99,25 @@ static struct sdxi_cxt *sdxi_alloc_cxt(struct sdxi_dev *sdxi)return_ptr (cxt); } +static int sdxi_alloc_kernel_submission (struct sdxi_cxt *cxt) +{ + cxt->ring_state =kzalloc_obj (*cxt->ring_state,GFP_KERNEL ); +if (!cxt->ring_state) +return -ENOMEM ; + + cxt->sq =sdxi_sq_alloc (cxt->sdxi,DEFAULT_DESC_RING_ENTRIES ); +if (!cxt->sq) +return -ENOMEM ; + + cxt->cst_pool =sdxi_cst_pool_create (cxt->sdxi, +DEFAULT_DESC_RING_ENTRIES ); +if (!cxt->cst_pool) +return -ENOMEM ; + +sdxi_ring_state_init (cxt->ring_state, cxt->sq); +return 0 ; +} +struct sdxi_cxt_ctl_cfg {dma_addr_t ds_ring_ptr;dma_addr_t cxt_sts_ptr;
@@ -253,9 +264,9 @@ sdxi_get_L1_table(struct sdxi_dev *sdxi, u16 l2_idx)* implementation. L1 pages remain allocated until device teardown so a * cached L2 pointer can never refer to freed memory. */ -static int sdxi_publish_cxt (const struct sdxi_cxt *cxt) +static int sdxi_publish_cxt (const struct sdxi_cxt *cxt, +const struct sdxi_cxt_ctl_cfg *ctl_cfg) { -struct sdxi_cxt_ctl_cfg ctl_cfg;struct sdxi_cxt_L1_cfg L1_cfg;struct sdxi_cxt_L1_table *L1_table;struct sdxi_cxt_L1_ent *ent;
@@ -268,16 +279,7 @@ static int sdxi_publish_cxt(const struct sdxi_cxt *cxt) cxt->id, cxt->sdxi->max_cxtid))return -EINVAL ; - ctl_cfg = (typeof (ctl_cfg )) { - .se =1 , - .csa =1 , - .ds_ring_ptr =sdxi_sq_ring_dma (cxt->sq), - .ds_ring_sz = cxt->sq->count, - .cxt_sts_ptr =sdxi_sq_cxt_sts_dma (cxt->sq), - .write_index_ptr =sdxi_sq_write_index_dma (cxt->sq), - }; - - err =configure_cxt_ctl (cxt->cxt_ctl, &ctl_cfg); + err =configure_cxt_ctl (cxt->cxt_ctl, ctl_cfg);if (err)return err;
@@ -294,13 +296,13 @@ static int sdxi_publish_cxt(const struct sdxi_cxt *cxt) L1_cfg = (typeof (L1_cfg )) { .ka =1 , - .pv =0 , + .pv = cxt->pasid_valid, .cxt_ctl_ptr = cxt->cxt_ctl_dma, .akey_sz =akey_table_order (cxt->akey_table), .akey_ptr = cxt->akey_table_dma, - .cxt_pasid =IOMMU_NO_PASID , + .cxt_pasid = cxt->pasid, .max_buffer = cxt->sdxi->max_buffer, - .opb_000_enb = cxt->sdxi->op_grp_cap, + .opb_000_enb = cxt->opb_000_enb, }; err =configure_L1_entry (ent, &L1_cfg);
@@ -321,23 +323,39 @@ static void free_admin_cxt(void *ptr)sdxi_free_cxt (sdxi->admin_cxt); } +static int sdxi_cxt_set_doorbell (struct sdxi_cxt *cxt); +int sdxi_admin_cxt_init (struct sdxi_dev *sdxi) { -int err; +struct sdxi_cxt_ctl_cfg ctl_cfg;struct sdxi_sq *sq; +int err; struct sdxi_cxt *cxt __free(sdxi_cxt) = sdxi_alloc_cxt(sdxi);if (!cxt)return -ENOMEM ; + err =sdxi_alloc_kernel_submission (cxt); +if (err) +return err; + sq = cxt->sq;/* SDXI 1.0 4.1.8.4.b: Set CXT_STS.state to CXTV_RUN. */ sq->cxt_sts.state =FIELD_PREP (SDXI_CXT_STS_STATE ,CXTV_RUN ); cxt->id =SDXI_ADMIN_CXT_ID ; - cxt->sq->doorbell = sdxi->dbs + cxt->id * sdxi->db_stride; -sdxi_ring_state_init (cxt->ring_state, sq); + err =sdxi_cxt_set_doorbell (cxt); +if (err) +return err; - err =sdxi_publish_cxt (cxt); + ctl_cfg = (typeof (ctl_cfg )) { + .se =1 , + .csa =1 , + .ds_ring_ptr =sdxi_sq_ring_dma (cxt->sq), + .ds_ring_sz = cxt->sq->count, + .cxt_sts_ptr =sdxi_sq_cxt_sts_dma (cxt->sq), + .write_index_ptr =sdxi_sq_write_index_dma (cxt->sq), + }; + err =sdxi_publish_cxt (cxt, &ctl_cfg);if (err)return err;
@@ -382,6 +400,23 @@ static bool sdxi_cxt_id_valid(const struct sdxi_cxt_id *cxt_id)return cxt_id->index >0 ; } +static int sdxi_cxt_set_doorbell (struct sdxi_cxt *cxt) +{ +struct sdxi_dev *sdxi = cxt->sdxi; +size_t offset; + +if (check_mul_overflow ((size_t )cxt->id, (size_t )sdxi->db_stride, + &offset) || + offset > sdxi->db_size || + sdxi->db_stride > sdxi->db_size - offset) +return -ERANGE ; + +if (WARN_ON_ONCE (!cxt->sq)) +return -EINVAL ; + cxt->sq->doorbell = sdxi->dbs + offset; +return 0 ; +} +/* * Transfer the reserved ID to the context and store its pointer in client_cxts. * sdxi_free_cxt() releases the ID.
@@ -401,6 +436,9 @@ static void sdxi_cxt_id_assign(struct sdxi_cxt *cxt, struct sdxi_cxt_id *cxt_id)*/ struct sdxi_cxt *sdxi_cxt_new (struct sdxi_dev *sdxi) { +struct sdxi_cxt_ctl_cfg ctl_cfg; +int err; +/* * Ensure an ID is available before allocating memory for the * context and its control structures.
@@ -413,13 +451,23 @@ struct sdxi_cxt *sdxi_cxt_new(struct sdxi_dev *sdxi)if (!cxt)return NULL ; -sdxi_cxt_id_assign (cxt, &id); - - cxt->sq->doorbell = sdxi->dbs + cxt->id * sdxi->db_stride; + err =sdxi_alloc_kernel_submission (cxt); +if (err) +return NULL ; -sdxi_ring_state_init (cxt->ring_state, cxt->sq); +sdxi_cxt_id_assign (cxt, &id); +if (sdxi_cxt_set_doorbell (cxt)) +return NULL ; -if (sdxi_publish_cxt (cxt)) + ctl_cfg = (typeof (ctl_cfg )) { + .se =1 , + .csa =1 , + .ds_ring_ptr =sdxi_sq_ring_dma (cxt->sq), + .ds_ring_sz = cxt->sq->count, + .cxt_sts_ptr =sdxi_sq_cxt_sts_dma (cxt->sq), + .write_index_ptr =sdxi_sq_write_index_dma (cxt->sq), + }; +if (sdxi_publish_cxt (cxt, &ctl_cfg))return NULL ;return_ptr (cxt);
drivers/dma/sdxi/context.h +3 -0
@@ -36,6 +36,9 @@ static inline u8 akey_table_order(const struct sdxi_akey_table *tbl)struct sdxi_cxt {struct sdxi_dev *sdxi;u16 id; +u32 pasid; +u32 opb_000_enb; +bool pasid_valid;struct sdxi_cxt_ctl *cxt_ctl;dma_addr_t cxt_ctl_dma;
drivers/dma/sdxi/device.c +2 -0
@@ -370,6 +370,8 @@ static int sdxi_fn_activate(struct sdxi_dev *sdxi) cap0 =sdxi_read64 (sdxi,SDXI_MMIO_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) +return -ENODEV ; cap1 =sdxi_read64 (sdxi,SDXI_MMIO_CAP1 ); sdxi->op_grp_cap =FIELD_GET (SDXI_MMIO_CAP1_OPB_000_CAP , cap1);
drivers/dma/sdxi/pci.c +1 -0
@@ -59,6 +59,7 @@ static int sdxi_pci_init(struct sdxi_dev *sdxi)if (IS_ERR (sdxi->dbs))return dev_err_probe (dev,PTR_ERR (sdxi->dbs),"failed to map doorbell region\n" ); + sdxi->db_size =pci_resource_len (pdev,SDXI_PCI_BAR_DOORBELL );/* Mailbox registers are reserved without SR-IOV support. */ sdxi->has_mailbox = pdev->is_virtfn ||
drivers/dma/sdxi/sdxi.h +1 -0
@@ -74,6 +74,7 @@ struct sdxi_dev {struct device *dev;void __iomem *ctrl_regs;/* virt addr of ctrl registers */ void __iomem *dbs;/* virt addr of doorbells */ +size_t db_size;/* mapped doorbell region size */ struct sdxi_version sdxi_version;
Signature · 1 line
2.56.1
PATCH 11/44 dmaengine: sdxi: support userspace context lifetimes
In reply to Wei HuangAdd per-open process state with ordered SVA and MMU-notifier teardown, and extend contexts with refcounted fd/VMA lifetime, deferred quiesce, fatal-state handling, and an internal PASID-backed userspace constructor. These are used to support userspace context later. Note that we still preserve the existing xarray registry and kernel SQ/CQ ownership.
--- drivers/dma/sdxi/.kunitconfig | 1 + drivers/dma/sdxi/Kconfig | 7 +- drivers/dma/sdxi/Makefile | 1 + drivers/dma/sdxi/admin.c | 17 +- drivers/dma/sdxi/context.c | 731 +++++++++++++++++++++++++++++++--- drivers/dma/sdxi/context.h | 39 ++ drivers/dma/sdxi/device.c | 10 + drivers/dma/sdxi/process.c | 186 +++++++++ drivers/dma/sdxi/process.h | 43 ++ drivers/dma/sdxi/sdxi.h | 2 + 10 files changed, 971 insertions(+), 66 deletions(-) create mode 100644 drivers/dma/sdxi/process.c create mode 100644 drivers/dma/sdxi/process.h
drivers/dma/sdxi/.kunitconfig +1 -0
@@ -1,4 +1,5 @@ CONFIG_KUNIT=y CONFIG_DMADEVICES=y +CONFIG_IOMMU_SUPPORT=y CONFIG_SDXI_CORE=y CONFIG_SDXI_KUNIT_TEST=y
drivers/dma/sdxi/Kconfig +5 -2
@@ -2,9 +2,12 @@ config SDXI_CORE tristate "SDXI (Smart Data Accelerator Interface) support" # Doorbell updates require naturally-aligned 64-bit writes, per # SDXI 1.0 9 MMIO Control Registers. - depends on 64BIT + depends on 64BIT && IOMMU_SUPPORT select DMA_ENGINE select DMA_VIRTUAL_CHANNELS + select IOMMU_API + select IOMMU_SVA + select MMU_NOTIFIER select PACKING help Enable support for Smart Data Accelerator Interface (SDXI)
@@ -21,7 +24,7 @@ config SDXI_CORE config SDXI_PCI tristate "SDXI (Smart Data Accelerator Interface) PCI driver" - depends on PCI_MSI && 64BIT + depends on PCI_MSI && 64BIT && IOMMU_SUPPORT select SDXI_CORE help Enable support for PCI-hosted SDXI devices.
drivers/dma/sdxi/Makefile +1 -0
@@ -9,6 +9,7 @@ sdxi-core-y := \ dma.o \ error.o \ keys.o \ + process.o \ ring.o obj-$(CONFIG_SDXI_PCI) += sdxi-pci.o
drivers/dma/sdxi/admin.c +13 -4
@@ -143,8 +143,13 @@ int sdxi_adm_start_cxt_sync(struct sdxi_cxt *cxt, unsigned int timeout_ms,if (ret)return ret; -return sdxi_adm_submit (to_admin_cxt (cxt), descs,ARRAY_SIZE (descs), - timeout_ms, cst_flags, interruptible); +/* A failed or interrupted wait can leave the context running. */ +WRITE_ONCE (cxt->quiesced, false); +WRITE_ONCE (cxt->started, true); + ret =sdxi_adm_submit (to_admin_cxt (cxt), descs,ARRAY_SIZE (descs), + timeout_ms, cst_flags, interruptible); + +return ret; } int sdxi_adm_stop_cxt_sync(struct sdxi_cxt *cxt, unsigned int timeout_ms,
@@ -169,8 +174,12 @@ int sdxi_adm_stop_cxt_sync(struct sdxi_cxt *cxt, unsigned int timeout_ms,if (ret)return ret; -return sdxi_adm_submit (to_admin_cxt (cxt), descs,ARRAY_SIZE (descs), - timeout_ms, cst_flags, interruptible); + ret =sdxi_adm_submit (to_admin_cxt (cxt), descs,ARRAY_SIZE (descs), + timeout_ms, cst_flags, interruptible); +if (!ret) +WRITE_ONCE (cxt->started, false); + +return ret; } int sdxi_adm_rkey_update_sync(struct sdxi_dev *sdxi, u16 rkey_start,
drivers/dma/sdxi/context.c +671 -60
882 lines not on this page · raw message
drivers/dma/sdxi/context.h +39 -0
@@ -10,8 +10,12 @@#include <linux/dma-mapping.h> #include <linux/idr.h> #include <linux/io.h> +#include <linux/mutex.h> +#include <linux/refcount.h> #include <linux/string.h> #include <linux/types.h> +#include <linux/wait.h> +#include <linux/workqueue.h> #include "hw.h" #include "ring.h"
@@ -20,6 +24,7 @@struct sdxi_completion ;struct sdxi_cst_pool ; +struct sdxi_process ;/* Use a 4 KiB AKey table, the minimum architectural size. */ struct sdxi_akey_table {
@@ -35,15 +40,33 @@ static inline u8 akey_table_order(const struct sdxi_akey_table *tbl)struct sdxi_cxt {struct sdxi_dev *sdxi; +refcount_t refs; +struct mutex cleanup_lock;/* lifetime state serialization */ +wait_queue_head_t poll_wq; +struct delayed_work cleanup_work;u16 id; +u32 mmap_gen;u32 pasid;u32 opb_000_enb; +u32 quiesce_cst_flags; +unsigned int vma_refs;bool pasid_valid; +bool handle_closed; +bool mm_dead; +bool fatal; +bool quiesced; +bool cleanup_stopping; +bool resources_released; +bool registered; +bool published; +bool update_pending; +bool started;struct sdxi_cxt_ctl *cxt_ctl;dma_addr_t cxt_ctl_dma;struct ida akey_ida; +struct mutex akey_lock;/* AKey table serialization */ struct sdxi_akey_table *akey_table;dma_addr_t akey_table_dma;
@@ -51,10 +74,14 @@ struct sdxi_cxt {struct sdxi_cst_pool *cst_pool;struct sdxi_ring_state *ring_state; +struct sdxi_process *process; };int sdxi_admin_cxt_init (struct sdxi_dev *sdxi);struct sdxi_cxt *sdxi_cxt_new (struct sdxi_dev *sdxi); +struct sdxi_cxt *sdxi_ucxt_new (struct sdxi_dev *sdxi,u32 ring_entries, +u64 ds_ring,u64 write_index,u64 cxt_sts, +u32 pasid,u32 opb_000_enb);/* * Caller must exclude users and stop the client before release. An update or * synchronization failure retains the invalidated context for device teardown;
@@ -62,6 +89,18 @@ struct sdxi_cxt *sdxi_cxt_new(struct sdxi_dev *sdxi);*/ int sdxi_cxt_exit (struct sdxi_cxt *cxt);void sdxi_client_cxts_exit (struct sdxi_dev *sdxi); +void sdxi_cxt_get (struct sdxi_cxt *cxt); +void sdxi_cxt_put (struct sdxi_cxt *cxt); +struct sdxi_cxt *sdxi_cxt_get_by_id (struct sdxi_dev *sdxi,u16 cxt_id); +int sdxi_cxt_quiesce (struct sdxi_cxt *cxt,unsigned int timeout_ms, +u32 *cst_flags); +bool sdxi_cxt_is_user (const struct sdxi_cxt *cxt); +bool sdxi_cxt_is_fatal (const struct sdxi_cxt *cxt); +void sdxi_cxt_kill (struct sdxi_cxt *cxt); +void sdxi_cxt_release_user_handle (struct sdxi_cxt *cxt); +int sdxi_cxt_notify_mm_release (struct sdxi_cxt *cxt); +void sdxi_cxt_vma_open (struct sdxi_cxt *cxt); +void sdxi_cxt_vma_close (struct sdxi_cxt *cxt);enum sdxi_submit_flags {SDXI_CXT_SUBMIT_KICK =BIT (0 ),
drivers/dma/sdxi/device.c +10 -0
@@ -279,6 +279,16 @@ void sdxi_dev_force_quiesce(struct sdxi_dev *sdxi) sdxi->bus_ops->force_quiesce (sdxi); } +void sdxi_dev_fail (struct sdxi_dev *sdxi) +{ +mutex_lock (&sdxi->admin_lock); +if (!sdxi->admin_dead) { + sdxi->admin_dead = true; +sdxi_dev_force_quiesce (sdxi); + } +mutex_unlock (&sdxi->admin_lock); +} +/* Stop the function and discard inherited MMIO configuration. */ static int sdxi_fn_prepare (struct sdxi_dev *sdxi) {
drivers/dma/sdxi/process.c new file +186 -0
186 lines not on this page · raw message
drivers/dma/sdxi/process.h new file +43 -0
43 lines not on this page · raw message
drivers/dma/sdxi/sdxi.h +2 -0
@@ -113,6 +113,7 @@ struct sdxi_dev {struct mutex admin_lock;/* admin submission serialization */ bool admin_dead;struct xarray client_cxts;/* context id -> (struct sdxi_cxt *) */ +u32 mmap_gen;bool has_mailbox;
@@ -160,6 +161,7 @@ static inline int sdxi_vector_to_irq(struct sdxi_dev *sdxi, unsigned int nr)int sdxi_register (struct device *dev,const struct sdxi_bus_ops *ops);void sdxi_unregister (struct device *dev);void sdxi_dev_force_quiesce (struct sdxi_dev *sdxi); +void sdxi_dev_fail (struct sdxi_dev *sdxi);static inline u64 sdxi_read64 (const struct sdxi_dev *sdxi,enum sdxi_reg reg) {
Signature · 1 line
2.56.1
PATCH 12/44 dmaengine: sdxi: route context interrupts to eventfd
In reply to Wei HuangAllocate userspace context interrupts from the existing vector IDA, route them to eventfds, and reserve a dynamic AKey for interrupt generation. Synchronize AKey cache updates on bind and unbind, and treat an armed interrupt without an eventfd as a fatal context condition.
--- drivers/dma/sdxi/Makefile | 1 + drivers/dma/sdxi/context.c | 6 + drivers/dma/sdxi/context.h | 11 ++ drivers/dma/sdxi/intr.c | 320 +++++++++++++++++++++++++++++++++++++ drivers/dma/sdxi/intr.h | 21 +++ 5 files changed, 359 insertions(+) create mode 100644 drivers/dma/sdxi/intr.c create mode 100644 drivers/dma/sdxi/intr.h
drivers/dma/sdxi/Makefile +1 -0
@@ -8,6 +8,7 @@ sdxi-core-y := \ device.o \ dma.o \ error.o \ + intr.o \ keys.o \ process.o \ ring.o
drivers/dma/sdxi/context.c +6 -0
@@ -29,6 +29,7 @@#include "context.h" #include "descriptor.h" #include "hw.h" +#include "intr.h" #include "process.h" #include "ring.h" #include "sdxi.h"
@@ -91,8 +92,11 @@ static struct sdxi_cxt *sdxi_alloc_cxt(struct sdxi_dev *sdxi)refcount_set (&cxt->refs,1 );mutex_init (&cxt->cleanup_lock);mutex_init (&cxt->akey_lock); +spin_lock_init (&cxt->intr_lock);init_waitqueue_head (&cxt->poll_wq);INIT_DELAYED_WORK (&cxt->cleanup_work, sdxi_cxt_cleanup_workfn); + cxt->intr_vector =-1 ; + cxt->intr_irq =-1 ;ida_init (&cxt->akey_ida); cxt->pasid =IOMMU_NO_PASID ; cxt->opb_000_enb = sdxi->op_grp_cap;
@@ -533,6 +537,8 @@ static void sdxi_cxt_release_resources(struct sdxi_cxt *cxt) {struct sdxi_dev *sdxi = cxt->sdxi; +sdxi_cxt_exit_intr (cxt); +if (cxt->registered) {WARN_ON (xa_erase (&sdxi->client_cxts, cxt->id) != cxt); cxt->registered = false;
drivers/dma/sdxi/context.h +11 -0
@@ -12,6 +12,7 @@#include <linux/io.h> #include <linux/mutex.h> #include <linux/refcount.h> +#include <linux/spinlock.h> #include <linux/string.h> #include <linux/types.h> #include <linux/wait.h>
@@ -31,6 +32,9 @@ struct sdxi_akey_table {struct sdxi_akey_ent entry[SZ_4K /sizeof (struct sdxi_akey_ent )]; }; +struct eventfd_ctx ; +struct sdxi_process ; +/* For encoding the akey table size in CXT_L1_ENT's akey_sz. */ static inline u8 akey_table_order (const struct sdxi_akey_table *tbl) {
@@ -75,6 +79,13 @@ struct sdxi_cxt {struct sdxi_ring_state *ring_state;struct sdxi_process *process; + +spinlock_t intr_lock;/* eventfd and interrupt state */ +struct eventfd_ctx *intr_eventfd; +int intr_vector; +int intr_irq; +u16 intr_akey; +bool intr_armed; };int sdxi_admin_cxt_init (struct sdxi_dev *sdxi);
drivers/dma/sdxi/intr.c new file +320 -0
320 lines not on this page · raw message
drivers/dma/sdxi/intr.h new file +21 -0
@@ -0,0 +1,21 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* SDXI userspace context interrupt routing. +* +* Copyright Advanced Micro Devices, Inc. +*/ + +#ifndef DMA_SDXI_INTR_H +#define DMA_SDXI_INTR_H + +#include <linux/types.h> + +struct sdxi_cxt ; + +int sdxi_cxt_init_intr (struct sdxi_cxt *cxt); +void sdxi_cxt_exit_intr (struct sdxi_cxt *cxt); +int sdxi_cxt_set_intr_fd (struct sdxi_cxt *cxt,int eventfd_fd, +u16 *akey,u32 *intr_num); +bool sdxi_cxt_has_intr_fd (const struct sdxi_cxt *cxt); + +#endif /* DMA_SDXI_INTR_H */
Signature · 1 line
2.56.1
PATCH 13/44 dmaengine: sdxi: kill user contexts on fatal errors
In reply to Wei HuangUse context references from current xarray to translate error-log stop reactions into fatal userspace context cleanup. Kernel and administrative contexts remain under their existing owners.
--- drivers/dma/sdxi/context.c | 21 +++++++++++ drivers/dma/sdxi/context.h | 1 + drivers/dma/sdxi/device.c | 5 +++ drivers/dma/sdxi/error.c | 71 ++++++++++++++++++++++++++++++++++++-- drivers/dma/sdxi/sdxi.h | 1 + 5 files changed, 96 insertions(+), 3 deletions(-)
drivers/dma/sdxi/context.c +21 -0
@@ -1119,6 +1119,27 @@ void sdxi_cxt_kill(struct sdxi_cxt *cxt)wake_up_poll (&cxt->poll_wq,EPOLLERR ); } +void sdxi_cxt_kill_stopped (struct sdxi_cxt *cxt) +{ +bool newly_fatal; + +if (!cxt) +return ; + +mutex_lock (&cxt->cleanup_lock); + newly_fatal = !cxt->fatal; + cxt->fatal = true; + cxt->started = false; + cxt->quiesced = true; + cxt->quiesce_cst_flags =0 ; +if (sdxi_cxt_is_user (cxt)) +sdxi_cxt_queue_cleanup_locked (cxt,0 ); +mutex_unlock (&cxt->cleanup_lock); + +if (newly_fatal) +wake_up_poll (&cxt->poll_wq,EPOLLERR ); +} +void sdxi_cxt_release_user_handle (struct sdxi_cxt *cxt) {if (!cxt)
drivers/dma/sdxi/context.h +1 -0
@@ -108,6 +108,7 @@ int sdxi_cxt_quiesce(struct sdxi_cxt *cxt, unsigned int timeout_ms,bool sdxi_cxt_is_user (const struct sdxi_cxt *cxt);bool sdxi_cxt_is_fatal (const struct sdxi_cxt *cxt);void sdxi_cxt_kill (struct sdxi_cxt *cxt); +void sdxi_cxt_kill_stopped (struct sdxi_cxt *cxt);void sdxi_cxt_release_user_handle (struct sdxi_cxt *cxt);int sdxi_cxt_notify_mm_release (struct sdxi_cxt *cxt);void sdxi_cxt_vma_open (struct sdxi_cxt *cxt);
drivers/dma/sdxi/device.c +5 -0
@@ -96,6 +96,11 @@ static enum sdxi_fn_gsv sdxi_dev_gsv(const struct sdxi_dev *sdxi)return gsv; } +bool sdxi_dev_in_error (const struct sdxi_dev *sdxi) +{ +return sdxi_dev_gsv (sdxi) ==SDXI_GSV_ERROR ; +} +static const unsigned long gsv_poll_interval_us =USEC_PER_MSEC *100 ;static const unsigned long gsv_transition_timeout_us =USEC_PER_SEC *1 ;
drivers/dma/sdxi/error.c +68 -3
126 lines not on this page · raw message
drivers/dma/sdxi/sdxi.h +1 -0
@@ -160,6 +160,7 @@ static inline int sdxi_vector_to_irq(struct sdxi_dev *sdxi, unsigned int nr)int sdxi_register (struct device *dev,const struct sdxi_bus_ops *ops);void sdxi_unregister (struct device *dev); +bool sdxi_dev_in_error (const struct sdxi_dev *sdxi);void sdxi_dev_force_quiesce (struct sdxi_dev *sdxi);void sdxi_dev_fail (struct sdxi_dev *sdxi);
Signature · 1 line
2.56.1
PATCH 14/44 dmaengine: sdxi: define the ioctl UAPI surface
In reply to Wei HuangAdd the SDXI ioctl UAPI header. It covers device attribute detection, context creation, AKey/RKey management, and descriptor group discovery, etc. The ABI uses argsz and reserved fields so future extensions can be added without changing ioctl numbers.
--- include/uapi/linux/sdxi.h | 569 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 569 insertions(+) create mode 100644 include/uapi/linux/sdxi.h
include/uapi/linux/sdxi.h new file +569 -0
@@ -0,0 +1,569 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +#ifndef __LINUX_SDXI_H +#define __LINUX_SDXI_H + +#include <linux/types.h> +#include <linux/ioctl.h> + +/* +* SDXI userspace ABI. +* +* Copyright (C) 2026 Advanced Micro Devices, Inc. +* +* All ioctls below use a struct whose first field is @argsz, the size of +* the struct in bytes. The kernel rejects @argsz smaller than the minimum +* it requires with -EINVAL, and uses @argsz to determine the layout +* version supplied by userspace. Fields not understood by an older kernel +* are ignored on input and zeroed on output, allowing additive UAPI +* extensions under a single ioctl number; incompatible changes bump +* SDXI_UAPI_MAJOR. +* +* Field direction is annotated with one of: +* IN - userspace -> kernel. +* OUT - kernel -> userspace. +* IN/OUT - both directions in the same field. +* For fields whose direction depends on flags or ioctl, the per-call +* directions are called out in the kernel-doc block. +* +* Reserved fields must be zero on input; the kernel zeroes them on output. +* The @flags field of every struct must be zero unless documented bits are +* set; unknown bits return -EINVAL. +*/ + +/* UAPI version and capability discovery. */ +#define SDXI_UAPI_MAJOR 1 +#define SDXI_UAPI_MINOR 0 + +#define SDXI_UAPI_CAP_WORDS 4U + +#define SDXI_UAPI_CAP_DEV_INFO (1ULL << 0) +#define SDXI_UAPI_CAP_DEV_ATTR_MGMT (1ULL << 1) +#define SDXI_UAPI_CAP_RKEY_MGMT (1ULL << 2) +#define SDXI_UAPI_CAP_CXT_CREATE (1ULL << 3) +#define SDXI_UAPI_CAP_CXT_EVENTFD (1ULL << 4) +#define SDXI_UAPI_CAP_AKEY_MGMT (1ULL << 5) +#define SDXI_UAPI_CAP_ADMIN_DISC (1ULL << 6) +#define SDXI_UAPI_CAP_ADMIN_VENDOR (1ULL << 7) + +/** +* struct sdxi_uapi_info_args - argument for SDXI_GET_UAPI_INFO. +* @argsz: IN/OUT: size of this struct in bytes. +* @flags: IN: must be zero. +* @uapi_major: OUT: UAPI generation. +* @uapi_minor: OUT: UAPI revision. +* @cap_words: OUT: number of valid 64-bit words in @caps. +* @rsvd0: reserved, must be zero. +* @caps: OUT: bitmap of SDXI_UAPI_CAP_* features advertised by the +* kernel. @cap_words gives the number of words populated; +* trailing words are zero. +*/ +struct sdxi_uapi_info_args { +__u32 argsz;/* in/out */ +__u32 flags;/* in */ + +__u16 uapi_major;/* out */ +__u16 uapi_minor;/* out */ +__u16 cap_words;/* out */ +__u16 rsvd0;/* reserved */ + +__aligned_u64 caps[SDXI_UAPI_CAP_WORDS ];/* out */ +}; + +/***************/ +/* DEVICE INFO */ +/***************/ +/** +* struct sdxi_dev_info_args - argument for SDXI_GET_DEV_INFO. +* @argsz: IN/OUT: size of this struct in bytes. +* @flags: IN: must be zero. +* @hw_major: OUT: MMIO_VERSION.major. +* @hw_minor: OUT: MMIO_VERSION.minor. +* @rsvd0: reserved, must be zero. +* @cap0: OUT: raw MMIO_CAP0. +* @cap1: OUT: raw MMIO_CAP1. +* @sts0: OUT: raw MMIO_STS0, read upon ioctl entry. +* @rsvd1: reserved for future fields, must be zero. +*/ +struct sdxi_dev_info_args { +__u32 argsz;/* in/out */ +__u32 flags;/* in */ + +__u16 hw_major;/* out */ +__u16 hw_minor;/* out */ +__u32 rsvd0;/* reserved */ + +__aligned_u64 cap0;/* out */ +__aligned_u64 cap1;/* out */ +__aligned_u64 sts0;/* out */ + +__aligned_u64 rsvd1[4 ];/* reserved */ +}; + +/*********************/ +/* DEVICE ATTRIBUTES */ +/*********************/ +/* Device attribute selectors used with SDXI_{GET,SET}_DEV_ATTR. */ +enum sdxi_dev_attr { +SDXI_DEV_ATTR_GSR =1 ,/* MMIO_CTL0.fn_gsr */ +SDXI_DEV_ATTR_GRP_ID =2 ,/* MMIO_CTL0.fn_grp_id */ +SDXI_DEV_ATTR_MAX_BUFFER =3 ,/* MMIO_CTL2.max_buffer */ +SDXI_DEV_ATTR_MAX_AKEY_SZ =4 ,/* MMIO_CTL2.max_akey_sz */ +SDXI_DEV_ATTR_MAX_RKEY_SZ =5 ,/* MMIO_RKEY.max_rkey_sz */ +SDXI_DEV_ATTR_MAX_CXT =6 ,/* MMIO_CTL2.max_cxt */ +}; + +/** +* struct sdxi_dev_attr_args - argument for SDXI_{GET,SET}_DEV_ATTR. +* @argsz: IN/OUT: size of this struct in bytes. +* @flags: IN: must be zero. Unknown bits return -EINVAL. +* @attr: IN: attribute selector, see enum sdxi_dev_attr. Unknown values +* return -EOPNOTSUPP. +* @val: GET: OUT: current value. +* SET: IN: requested value; OUT: value actually applied. +* @rsvd0: reserved, must be zero. +*/ +struct sdxi_dev_attr_args { +__u32 argsz;/* in/out */ +__u32 flags;/* in */ + +__aligned_u64 attr;/* in */ +__aligned_u64 val;/* in/out: see ioctl */ +__aligned_u64 rsvd0[4 ];/* reserved */ +}; + +/******************/ +/* KEY MANAGEMENT */ +/******************/ +/* +* Key tables (RKey and AKey). +* +* RKey and AKey tables share the same wire format below; the table being +* addressed is selected by the fd and the ioctl number, not by any field +* in the struct: +* +* RKey (per-device, CAP_SYS_ADMIN), device fd: +* SDXI_GET_RKEY_LIST, SDXI_GET_RKEYS, SDXI_SET_RKEYS. +* AKey (per-context, user-accessible), context fd: +* SDXI_GET_AKEY_LIST, SDXI_GET_AKEYS, SDXI_SET_AKEYS. +* +* Typical usage: +* 1) *_LIST returns the table size and a bitmap of valid indices. Pass +* buf_size = 0 to learn the required size, then re-issue with a +* sized buffer. +* 2) GET_*KEYS: caller fills entries[i].index for each row of interest; +* the kernel fills entries[i].data[] in place. +* 3) SET_*KEYS: caller supplies fully populated entries[]; the kernel +* writes them to the table and reports a commit summary. +* +* For all key-table structs @argsz covers only the fixed header, not the +* trailing flexible array. +*/ + +/** +* struct sdxi_key_entry - one RKEY_ENT/AKEY_ENT exchanged with userspace. +* @index: IN: table index. +* @rsvd0: reserved, must be zero. +* @data: raw entry dwords in little-endian wire order, used by GET/SET ioctls. +*/ +struct sdxi_key_entry { +__u32 index;/* in */ +__u32 rsvd0;/* reserved */ +__u32 data[4 ];/* in/out: see ioctl */ +}; + +/** +* struct sdxi_key_list_args - argument for SDXI_GET_{R,A}KEY_LIST. +* @argsz: IN/OUT: size of the fixed header in bytes (excludes @data). +* @flags: IN: must be zero. +* @buf_size: IN: bytes available in @data; OUT: bytes required for the +* full bitmap (i.e. ceil(@nentries / 8)). +* @nentries: OUT: total number of entries in the table. +* @nvalid: OUT: number of valid entries (popcount of the full bitmap), +* independent of how many bytes fit in @data. +* @rsvd0: reserved, must be zero. +* @data: OUT: valid bitmap. Index N is valid iff bit (N % 8) of +* byte (N / 8) is set. +* +* If the supplied buffer is too small the ioctl returns -ENOSPC, leaves +* @data untouched and updates @buf_size, @nentries and @nvalid so the +* caller can resize and retry. +*/ +struct sdxi_key_list_args { +__u32 argsz;/* in/out */ +__u32 flags;/* in */ + +__u32 buf_size;/* in/out */ +__u32 nentries;/* out */ +__u32 nvalid;/* out */ +__u32 rsvd0;/* reserved */ + +__u8 data[];/* out */ +}; + +/** +* struct sdxi_get_keys_args - argument for SDXI_GET_{R,A}KEYS. +* @argsz: IN/OUT: size of the fixed header in bytes (excludes @entries). +* @flags: IN: must be zero. +* @nkeys: IN: number of entries requested; OUT: number of entries +* actually populated. Entries beyond the returned @nkeys are +* left untouched. +* @rsvd0: reserved, must be zero. +* @entries: IN: caller writes @entries[i].index to select rows. +* OUT: kernel fills @entries[i].data[] in place. +*/ +struct sdxi_get_keys_args { +__u32 argsz;/* in/out */ +__u32 flags;/* in */ + +__u32 nkeys;/* in/out */ +__u32 rsvd0;/* reserved */ + +struct sdxi_key_entry entries[];/* in/out */ +}; + +/* Commit outcome reported by SDXI_SET_{R,A}KEYS in @commit_state. */ +enum sdxi_key_commit_state { +/* No entry bytes were written. Safe default for pre-zeroed args. */ +SDXI_KEY_COMMIT_NONE =0 , +/* All requested entries committed. */ +SDXI_KEY_COMMIT_ALL =1 , +/* +* One or more entries were written but the driver could not confirm +* the final hardware-visible state. @first_failed_index names the +* lowest entries[] slot whose commit is unconfirmed; entries below +* it are guaranteed committed. +*/ +SDXI_KEY_COMMIT_PARTIAL =2 , +}; + +/* @timeout_ms sentinel: 0 selects the driver default. */ +#define SDXI_KEY_TIMEOUT_DEFAULT 0U + +/** +* struct sdxi_set_keys_args - argument for SDXI_SET_{R,A}KEYS. +* @argsz: IN/OUT: size of the fixed header in bytes +* (excludes @entries). +* @flags: IN: must be zero. +* @timeout_ms: IN: per-call timeout, see SDXI_KEY_TIMEOUT_DEFAULT. +* @nkeys: IN: number of entries to write. +* @cst_flags: OUT: reserved for SDXI_KEY_CST_F_* completion bits; +* none defined yet. Kernel writes zero; userspace +* must ignore unknown bits. +* @commit_state: OUT: enum sdxi_key_commit_state. +* @first_failed_index: OUT: valid only when @commit_state == +* SDXI_KEY_COMMIT_PARTIAL. +* @rsvd0: reserved, must be zero. +* @entries: IN: entries to commit, written to the table in +* order. On partial failure, userspace can retry +* starting from @first_failed_index without +* re-issuing earlier entries. After updating the +* software table, the driver implicitly submits +* the matching DSC_{R,A}KEY_UPD followed by +* DSC_SYNC so userspace does not need separate +* admin update/sync ioctls. +*/ +struct sdxi_set_keys_args { +__u32 argsz;/* in/out */ +__u32 flags;/* in */ + +__u32 timeout_ms;/* in */ +__u32 nkeys;/* in */ + +__u32 cst_flags;/* out */ +__u32 commit_state;/* out */ +__u32 first_failed_index;/* out */ +__u32 rsvd0[5 ];/* reserved */ + +struct sdxi_key_entry entries[];/* in */ +}; + +/**********************/ +/* CONTEXT MANAGEMENT */ +/**********************/ +/** +* struct sdxi_create_cxt_args - argument for SDXI_CREATE_CXT. +* @argsz: IN/OUT: size of this struct in bytes. +* @flags: IN: must be zero. +* @opb_000_enb: IN/OUT: requested operation-group enable mask for the +* context, using the raw SDXI opb_000 bit positions used +* by MMIO_CAP1.opb_000_cap, MMIO_CTL2.opb_000_avl, and +* CXT_L1_ENT.opb_000_enb. Bit N requests opcode type N +* for opcode types 0..31. Function-assigned opcode type +* values are discovered with SDXI_ADMIN_DISC. A value of +* 0 requests the driver default; the kernel returns the +* applied raw mask. +* @pasid: OUT: PASID bound to the owning process/mm for this +* context. +* @ds_ring_entries: IN/OUT: requested descriptor-ring entry count. A value +* of 0 selects the driver default; the kernel returns +* the actual entry count. +* @rsvd0: reserved, must be zero. +* @ds_ring_base: IN: userspace descriptor-ring base address. +* @cxt_sts_base: IN: userspace context-status base address. +* @write_index_base: IN: userspace write-index base address. +* @doorbell_mmap_base: OUT: mmap token for this context's doorbell region. +* @cxt_fd: OUT: context file descriptor returned on success. +* @rsvd1: reserved, must be zero. +* +* Issued on the device fd to create a new userspace context. On success the +* driver has already programmed the context hierarchy, started the context, +* and issued an internal context-sync for the new context before returning +* the resulting cxt_fd to userspace. +*/ +struct sdxi_create_cxt_args { +__u32 argsz;/* in/out */ +__u32 flags;/* in */ + +__u32 opb_000_enb;/* in/out */ + +__u32 pasid;/* out */ +__u32 ds_ring_entries;/* in/out */ +__u32 rsvd0;/* reserved */ +__aligned_u64 ds_ring_base;/* in */ +__aligned_u64 cxt_sts_base;/* in */ +__aligned_u64 write_index_base;/* in */ +__aligned_u64 doorbell_mmap_base;/* out */ + +__s32 cxt_fd;/* out */ +__u32 rsvd1;/* reserved */ +}; + +/** +* struct sdxi_cxt_eventfd_args - argument for SDXI_CXT_EVENTFD. +* @argsz: IN/OUT: size of this struct in bytes. +* @flags: IN: must be zero. +* @eventfd: IN: eventfd file descriptor used for context interrupt +* delivery. A negative value disables the current binding. +* @intr_akey: OUT: driver-reserved AKey slot used for userspace interrupt +* delivery when a binding is active; zero when disabled. +* @rsvd0: reserved, must be zero. +* @intr_num: OUT: MSI/MSI-X message/vector assigned to this context when a +* binding is active; zero when disabled. +* @rsvd1: reserved, must be zero. +* +* Issued on a context fd returned by SDXI_CREATE_CXT. Binds or unbinds the +* userspace eventfd used for context interrupts (for example DSC_INTR). +*/ +struct sdxi_cxt_eventfd_args { +__u32 argsz;/* in/out */ +__u32 flags;/* in */ + +__s32 eventfd;/* in */ +__u16 intr_akey;/* out */ +__u16 rsvd0;/* reserved */ +__u32 intr_num;/* out */ + +__u32 rsvd1[4 ];/* reserved */ +}; + +/* @timeout_ms sentinel: 0 selects the driver default. */ +#define SDXI_CXT_QUIESCE_TIMEOUT_DEFAULT 0U + +/** +* struct sdxi_quiesce_cxt_args - argument for SDXI_QUIESCE_CXT. +* @argsz: IN/OUT: size of this struct in bytes. +* @flags: IN: must be zero. +* @timeout_ms: IN: timeout in milliseconds, or +* SDXI_CXT_QUIESCE_TIMEOUT_DEFAULT (0) for the driver default. +* @cst_flags: OUT: completion status flags returned by the stop-sync path. +* +* Issued on a context fd returned by SDXI_CREATE_CXT. Synchronously stops +* the context so no further DMA traffic is expected from it. The driver +* issues the internal stop plus stop-sync sequence before reporting success. +* The ioctl does not destroy the context; close(2) drops the userspace +* handle and the driver completes final cleanup once the context is +* quiesced and no context mappings remain. +*/ +struct sdxi_quiesce_cxt_args { +__u32 argsz;/* in/out */ +__u32 flags;/* in */ + +__u32 timeout_ms;/* in */ +__u32 cst_flags;/* out */ +}; + +/******************/ +/* ADMIN DSC_DISC */ +/******************/ +/* @timeout_ms sentinel for admin ioctls: 0 selects the driver default. */ +#define SDXI_ADMIN_TIMEOUT_DEFAULT 0U + +/** +* struct sdxi_admin_range - inclusive 16-bit range for admin ioctls. +* @start: IN: first index in the range. +* @end: IN: last index in the range. +*/ +struct sdxi_admin_range { +__u16 start;/* in */ +__u16 end;/* in */ +}; + +/** +* struct sdxi_admin_disc_args - argument for SDXI_ADMIN_DISC. +* @argsz: IN/OUT: size of this struct in bytes. +* @flags: IN: SDXI_ADMIN_DISC_F_* (none defined yet); must be zero. +* @timeout_ms: IN: per-call timeout, see SDXI_ADMIN_TIMEOUT_DEFAULT. +* @cst_flags: OUT: reserved for SDXI_ADMIN_DISC_CST_F_* completion bits; +* none defined yet. Kernel writes zero; userspace must +* ignore unknown bits. +* @index: IN: inclusive [start, end] discovery index range. +* @buf_size: IN: bytes available at @buf_uptr; OUT: bytes the kernel +* would have written. +* @buf_uptr: IN: userspace VA of the result buffer. +* @rsvd0: reserved, must be zero. +* +* Issues an SDXI discovery command on the device's admin context and +* copies the resulting records describing installed components for the +* requested index range into @buf_uptr. This read-only discovery ioctl is +* valid only on the device fd and is supported only on SDXI 1.1+ devices. +* It is available to callers that can open the delegated device node; +* discovering an operation group does not by itself authorize a context to +* enable or submit that operation group. +* +* If @buf_size on input is smaller than the required size, the ioctl +* returns -ENOSPC, leaves @buf_uptr untouched, and updates @buf_size so +* the caller can resize and retry. +*/ +struct sdxi_admin_disc_args { +__u32 argsz;/* in/out */ +__u32 flags;/* in */ + +__u32 timeout_ms;/* in */ +__u32 cst_flags;/* out */ + +struct sdxi_admin_range index;/* in */ + +__u32 buf_size;/* in/out */ +__aligned_u64 buf_uptr;/* in */ + +__u32 rsvd0[6 ];/* reserved */ +}; + +/**************************/ +/* ADMIN VENDOR OPERATION */ +/**************************/ +/* Reserved opcode for SDXI_ADMIN_VENDOR capability probing. */ +#define SDXI_ADMIN_VENDOR_PROBE 0U + +/** +* struct sdxi_admin_vendor_args - argument for SDXI_ADMIN_VENDOR. +* @argsz: IN/OUT: size of this struct in bytes. +* @flags: IN: SDXI_ADMIN_VENDOR_F_* (none defined yet); must be zero. +* @guid: IN: 16-byte vendor feature GUID, as returned by +* SDXI_ADMIN_DISC for an opcode type implementing this +* feature. Stored in SDXI spec discovery record byte order; +* userspace passes the bytes verbatim. +* @op: IN: vendor-defined operation. SDXI_ADMIN_VENDOR_PROBE is +* reserved for capability probing (see below). +* @timeout_ms: IN: per-call timeout, see SDXI_ADMIN_TIMEOUT_DEFAULT. +* @cst_flags: OUT: reserved for SDXI_ADMIN_VENDOR_CST_F_* completion bits; +* none defined yet. Kernel writes zero; userspace must +* ignore unknown bits. +* @rsvd0: reserved, must be zero. +* @in_uptr: IN: userspace VA of structured input (0 if unused). +* @in_size: IN: input size in bytes (0 if unused). +* @rsvd1: reserved, must be zero. +* @out_uptr: IN: userspace VA of the output buffer (0 if unused). +* @out_size: IN: bytes available at @out_uptr; OUT: bytes required. +* @rsvd2: reserved, must be zero. +* +* Typed transport for the SDXI vendor operation group. The kernel never +* accepts a wire descriptor from userspace: the caller passes (@guid, +* @op, structured input, output buffer); the kernel-resident vendor +* handler composes the SDXI descriptor, submits it on the device's admin +* context, and copies decoded results back. Reserved descriptor bits, +* function-targeting bits, and the completion-status block are not under +* userspace control. +* +* Privilege: +* Holding the device fd is required. Per-op privilege escalation +* is enforced by the vendor handler. Read-only telemetry ops MAY be +* allowed without CAP_SYS_ADMIN at the handler's discretion. +* +* Discovery: +* 1. SDXI_ADMIN_DISC enumerates vendor GUIDs installed on the device. +* 2. SDXI_ADMIN_VENDOR with @op == SDXI_ADMIN_VENDOR_PROBE returns 0 if the +* kernel has a registered handler for @guid on this device, or +* -EOPNOTSUPP otherwise. PROBE has no in/out payload. +* 3. Per-op input/output schemas are vendor-specific. +* +* Output buffer sizing: +* Pass @out_size = 0 to learn the required size; the ioctl returns +* -ENOSPC, updates @out_size, and leaves @out_uptr untouched. If +* @out_size is non-zero but smaller than required, the ioctl behaves +* the same way. +* +* Return: +* 0 - descriptor completed; @out_uptr contains valid data. +* -ENOSPC - @out_size too small; @out_size updated, @out_uptr +* untouched. +* -EIO - device reported a CSB error; @cst_flags may carry +* vendor-specific details. +* -ETIMEDOUT - submission may have reached the device but the kernel +* could not confirm completion; callers should treat +* device state as undefined and may retry idempotent ops. +* other - request was rejected before submission; device state +* is unchanged. +*/ +struct sdxi_admin_vendor_args { +__u32 argsz;/* in/out */ +__u32 flags;/* in */ + +__u8 guid[16 ];/* in */ + +__u32 op;/* in */ +__u32 timeout_ms;/* in */ + +__u32 cst_flags;/* out */ +__u32 rsvd0;/* reserved */ + +__aligned_u64 in_uptr;/* in */ +__u32 in_size;/* in */ +__u32 rsvd1;/* reserved */ + +__aligned_u64 out_uptr;/* in */ +__u32 out_size;/* in/out */ +__u32 rsvd2[7 ];/* reserved */ +}; + +/*******************/ +/* IOCTL FUNCTIONS */ +/*******************/ +#define SDXI_IOCTL_BASE 'S' +#define SDXI_IO (nr) _IO(SDXI_IOCTL_BASE, nr) +#define SDXI_IOR (nr, type) _IOR(SDXI_IOCTL_BASE, nr, type) +#define SDXI_IOW (nr, type) _IOW(SDXI_IOCTL_BASE, nr, type) +#define SDXI_IOWR (nr, type) _IOWR(SDXI_IOCTL_BASE, nr, type) + +#define SDXI_GET_UAPI_INFO \ + SDXI_IOWR(0x01, struct sdxi_uapi_info_args) +#define SDXI_GET_DEV_INFO \ + SDXI_IOWR(0x02, struct sdxi_dev_info_args) +#define SDXI_GET_DEV_ATTR \ + SDXI_IOWR(0x03, struct sdxi_dev_attr_args) +#define SDXI_SET_DEV_ATTR \ + SDXI_IOWR(0x04, struct sdxi_dev_attr_args) +#define SDXI_GET_RKEY_LIST \ + SDXI_IOWR(0x05, struct sdxi_key_list_args) +#define SDXI_GET_RKEYS \ + SDXI_IOWR(0x06, struct sdxi_get_keys_args) +#define SDXI_SET_RKEYS \ + SDXI_IOWR(0x07, struct sdxi_set_keys_args) +#define SDXI_CREATE_CXT \ + SDXI_IOWR(0x08, struct sdxi_create_cxt_args) +#define SDXI_CXT_EVENTFD \ + SDXI_IOWR(0x09, struct sdxi_cxt_eventfd_args) +#define SDXI_GET_AKEY_LIST \ + SDXI_IOWR(0x0A, struct sdxi_key_list_args) +#define SDXI_GET_AKEYS \ + SDXI_IOWR(0x0B, struct sdxi_get_keys_args) +#define SDXI_SET_AKEYS \ + SDXI_IOWR(0x0C, struct sdxi_set_keys_args) +#define SDXI_ADMIN_DISC \ + SDXI_IOWR(0x0D, struct sdxi_admin_disc_args) +#define SDXI_ADMIN_VENDOR \ + SDXI_IOWR(0x0E, struct sdxi_admin_vendor_args) +#define SDXI_QUIESCE_CXT \ + SDXI_IOWR(0x0F, struct sdxi_quiesce_cxt_args) + +#endif /* __LINUX_SDXI_H */
Signature · 1 line
2.56.1
PATCH 15/44 dmaengine: sdxi: add internal ioctl definitions
In reply to Wei HuangDefine device and context file classes, ioctl access classes, and the page-aligned context mapping token used by the native SDXI character device. This patch adds no public file operations yet.
--- drivers/dma/sdxi/ioctl.h | 79 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 drivers/dma/sdxi/ioctl.h
drivers/dma/sdxi/ioctl.h new file +79 -0
@@ -0,0 +1,79 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* SDXI ioctl and context mapping definitions. +* +* Copyright Advanced Micro Devices, Inc. +*/ + +#ifndef DMA_SDXI_IOCTL_H +#define DMA_SDXI_IOCTL_H + +#include <linux/bits.h> +#include <linux/types.h> +#include <asm/page.h> + +#include "process.h" + +struct file ; +struct sdxi_cxt ; + +enum sdxi_file_type { +SDXI_FILE_DEVICE , +SDXI_FILE_CONTEXT , +}; + +struct sdxi_file { +enum sdxi_file_type type; +struct sdxi_process *process; +struct sdxi_cxt *cxt; +}; + +typedef int sdxi_ioctl_t (struct file *file,struct sdxi_file *sf,void *data); + +enum sdxi_ioctl_access_class { +SDXI_IOCTL_A_PUBLIC_DEVICE , +SDXI_IOCTL_A_CONTEXT_OWNER , +SDXI_IOCTL_A_ADMIN_DEVICE , +SDXI_IOCTL_A_VENDOR_HANDLER , +}; + +struct sdxi_ioctl_desc { +unsigned int cmd; +unsigned int file_flags; +enum sdxi_ioctl_access_class access; +sdxi_ioctl_t *func; +const char *name; +}; + +#define SDXI_IOCTL_F_DEVICE BIT(0) +#define SDXI_IOCTL_F_CONTEXT BIT(1) + +#define SDXI_MMAP_TYPE_SHIFT 40 +#define SDXI_MMAP_TYPE_DOORBELL (0x4ULL << SDXI_MMAP_TYPE_SHIFT) +#define SDXI_MMAP_TYPE_MASK (0x7ULL << SDXI_MMAP_TYPE_SHIFT) + +#define SDXI_MMAP_CXT_ID_SHIFT 24 +#define SDXI_MMAP_CXT_ID_MASK GENMASK_ULL(39, 24) +#define SDXI_MMAP_GEN_SHIFT PAGE_SHIFT +#define SDXI_MMAP_GEN_MASK GENMASK_ULL(23, PAGE_SHIFT) + +static inline u64 sdxi_mmap_token (u64 type,u32 cxt_id,u32 generation) +{ +return type | + (((u64 )cxt_id <<SDXI_MMAP_CXT_ID_SHIFT ) & +SDXI_MMAP_CXT_ID_MASK ) | + (((u64 )generation <<SDXI_MMAP_GEN_SHIFT ) & +SDXI_MMAP_GEN_MASK ); +} + +static inline u32 sdxi_mmap_token_cxt_id (u64 token) +{ +return (token &SDXI_MMAP_CXT_ID_MASK ) >>SDXI_MMAP_CXT_ID_SHIFT ; +} + +static inline u32 sdxi_mmap_token_gen (u64 token) +{ +return (token &SDXI_MMAP_GEN_MASK ) >>SDXI_MMAP_GEN_SHIFT ; +} + +#endif /* DMA_SDXI_IOCTL_H */
Signature · 1 line
2.56.1
PATCH 16/44 dmaengine: sdxi: register core character devices
In reply to Wei HuangCreate one core-owned SDXI character device per registered function and bind each open file to process state. Preserve the existing core/PCI split; functional ioctls and context mappings remain disabled until their handlers are added later.
--- drivers/dma/sdxi/Makefile | 1 + drivers/dma/sdxi/context.c | 70 ++++++++++++----- drivers/dma/sdxi/context.h | 1 + drivers/dma/sdxi/device.c | 121 +++++++++++++++++++++++++---- drivers/dma/sdxi/ioctl.c | 155 +++++++++++++++++++++++++++++++++++++ drivers/dma/sdxi/keys.c | 11 --- drivers/dma/sdxi/pci.c | 1 + drivers/dma/sdxi/process.c | 12 ++- drivers/dma/sdxi/sdxi.h | 16 ++++ 9 files changed, 340 insertions(+), 48 deletions(-) create mode 100644 drivers/dma/sdxi/ioctl.c
drivers/dma/sdxi/Makefile +1 -0
@@ -9,6 +9,7 @@ sdxi-core-y := \ dma.o \ error.o \ intr.o \ + ioctl.o \ keys.o \ process.o \ ring.o
drivers/dma/sdxi/context.c +50 -20
125 lines not on this page · raw message
drivers/dma/sdxi/context.h +1 -0
@@ -89,6 +89,7 @@ struct sdxi_cxt { };int sdxi_admin_cxt_init (struct sdxi_dev *sdxi); +void sdxi_admin_cxt_exit (struct sdxi_dev *sdxi);struct sdxi_cxt *sdxi_cxt_new (struct sdxi_dev *sdxi); struct sdxi_cxt *sdxi_ucxt_new(struct sdxi_dev *sdxi, u32 ring_entries, u64 ds_ring, u64 write_index, u64 cxt_sts,
drivers/dma/sdxi/device.c +105 -16
186 lines not on this page · raw message
drivers/dma/sdxi/ioctl.c new file +155 -0
155 lines not on this page · raw message
drivers/dma/sdxi/keys.c +0 -11
@@ -6,7 +6,6 @@*/ #include <linux/bitfield.h> -#include <linux/device/devres.h> #include <linux/dma-mapping.h> #include <linux/log2.h> #include <linux/sizes.h>
@@ -17,16 +16,10 @@#include "mmio.h" #include "sdxi.h" -static void sdxi_keys_release (void *data) -{ -sdxi_keys_exit (data); -} -int sdxi_keys_init (struct sdxi_dev *sdxi,u64 cap1) {size_t table_size;u64 reg; -int ret; sdxi->rkey_cap =FIELD_GET (SDXI_MMIO_CAP1_RKEY_CAP , cap1);if (!sdxi->rkey_cap)
@@ -49,10 +42,6 @@ int sdxi_keys_init(struct sdxi_dev *sdxi, u64 cap1)SDXI_MMIO_RKEY_EN ;sdxi_write64 (sdxi,SDXI_MMIO_RKEY , reg); - ret =devm_add_action_or_reset (sdxi->dev, sdxi_keys_release, sdxi); -if (ret) -return ret; -return 0 ; }
drivers/dma/sdxi/pci.c +1 -0
@@ -130,6 +130,7 @@ static void sdxi_pci_force_quiesce(struct sdxi_dev *sdxi) }static const struct sdxi_bus_ops sdxi_pci_ops = { + .owner =THIS_MODULE , .init = sdxi_pci_init, .reset = sdxi_pci_reset, .get_irq = sdxi_pci_get_irq,
drivers/dma/sdxi/process.c +11 -1
@@ -6,6 +6,7 @@*/ #include <linux/iommu.h> +#include <linux/module.h> #include <linux/sched/mm.h> #include <linux/sched/task.h> #include <linux/slab.h>
@@ -100,6 +101,7 @@ void sdxi_process_unbind_sva(struct sdxi_process *process,static void sdxi_process_free (struct sdxi_process *process) { +struct sdxi_dev *sdxi = process->sdxi;struct iommu_sva *sva;u32 pasid;
@@ -111,6 +113,8 @@ static void sdxi_process_free(struct sdxi_process *process)put_task_struct (process->lead_thread);mmdrop (process->mm);kfree (process); +module_put (sdxi->bus_ops->owner); +put_device (&sdxi->chardev); }void sdxi_process_get (struct sdxi_process *process)
@@ -167,10 +171,16 @@ struct sdxi_process *sdxi_process_create(struct sdxi_dev *sdxi)if (!task->mm)return ERR_PTR (-EINVAL ); +if (!try_module_get (sdxi->bus_ops->owner)) +return ERR_PTR (-ENODEV ); +get_device (&sdxi->chardev); process =kzalloc_obj (*process,GFP_KERNEL ); -if (!process) +if (!process) { +put_device (&sdxi->chardev); +module_put (sdxi->bus_ops->owner);return ERR_PTR (-ENOMEM ); + }refcount_set (&process->refs,1 );mutex_init (&process->mutex);
drivers/dma/sdxi/sdxi.h +16 -0
@@ -9,11 +9,14 @@#define DMA_SDXI_H #include <linux/bug.h> +#include <linux/cdev.h> #include <linux/compiler_types.h> +#include <linux/device.h> #include <linux/dev_printk.h> #include <linux/idr.h> #include <linux/io.h> #include <linux/mutex.h> +#include <linux/rwsem.h> #include <linux/types.h> #include <linux/xarray.h>
@@ -44,11 +47,14 @@ enum { };struct sdxi_dev ; +struct module ;/** * struct sdxi_bus_ops - Bus-specific methods for SDXI devices. */ struct sdxi_bus_ops { +/** @owner: Module providing these operations, or NULL if built in. */ +struct module *owner;/** * @init: Map control registers and doorbell region, allocate * IRQ ranges. Invoked before bus-agnostic SDXI
@@ -117,6 +123,12 @@ struct sdxi_dev {bool has_mailbox; +struct cdev cdev; +struct device chardev; +int minor; +bool online; +struct rw_semaphore state_lock;/* online state and user operations */ +const struct sdxi_bus_ops *bus_ops; };
@@ -163,6 +175,10 @@ void sdxi_unregister(struct device *dev);bool sdxi_dev_in_error (const struct sdxi_dev *sdxi);void sdxi_dev_force_quiesce (struct sdxi_dev *sdxi);void sdxi_dev_fail (struct sdxi_dev *sdxi); +int sdxi_chardev_init (void ); +void sdxi_chardev_exit (void ); +int sdxi_chardev_register (struct sdxi_dev *sdxi); +void sdxi_chardev_unregister (struct sdxi_dev *sdxi);static inline u64 sdxi_read64 (const struct sdxi_dev *sdxi,enum sdxi_reg reg) {
Signature · 1 line
2.56.1
PATCH 17/44 dmaengine: sdxi: implement fixed-size ioctl dispatch
In reply to Wei HuangAdd the final ioctl table and access-class checks, with unsupported rows for features that are not wired yet. Implement UAPI discovery, device information UAPI, and bounded device attributes while advertising only those alive capabilities.
--- drivers/dma/sdxi/device.c | 9 +- drivers/dma/sdxi/error.c | 4 + drivers/dma/sdxi/ioctl.c | 413 +++++++++++++++++++++++++++++++++++++- drivers/dma/sdxi/ioctl.h | 1 - drivers/dma/sdxi/sdxi.h | 1 + 5 files changed, 420 insertions(+), 8 deletions(-)
drivers/dma/sdxi/device.c +7 -2
@@ -110,12 +110,14 @@ static const unsigned long gsv_transition_timeout_us = USEC_PER_SEC * 1;static void sdxi_write_fn_gsr (struct sdxi_dev *sdxi,enum sdxi_fn_gsr cmd) { -u64 ctl0 =sdxi_read64 (sdxi,SDXI_MMIO_CTL0 ); +u64 ctl0; +mutex_lock (&sdxi->reg_lock); + ctl0 =sdxi_read64 (sdxi,SDXI_MMIO_CTL0 );dev_dbg (sdxi->dev,"MMIO_CTL0.fn_gsr = %#x (%s)\n" , cmd,gsr_str (cmd)); -FIELD_MODIFY (SDXI_MMIO_CTL0_FN_GSR , &ctl0, cmd);sdxi_write64 (sdxi,SDXI_MMIO_CTL0 , ctl0); +mutex_unlock (&sdxi->reg_lock); }/*
@@ -319,11 +321,13 @@ static int sdxi_fn_prepare(struct sdxi_dev *sdxi)if (err)return err; +mutex_lock (&sdxi->reg_lock); ctl0 =sdxi_read64 (sdxi,SDXI_MMIO_CTL0 );FIELD_MODIFY (SDXI_MMIO_CTL0_FN_ERR_INTR_EN , &ctl0,0 );FIELD_MODIFY (SDXI_MMIO_CTL0_FN_PASID_VL , &ctl0,0 );FIELD_MODIFY (SDXI_MMIO_CTL0_FN_PASID , &ctl0,0 );sdxi_write64 (sdxi,SDXI_MMIO_CTL0 , ctl0); +mutex_unlock (&sdxi->reg_lock);/* Restore CTL2's reset limits, with operation groups disabled. */ cap1 =sdxi_read64 (sdxi,SDXI_MMIO_CAP1 );
@@ -534,6 +538,7 @@ int sdxi_register(struct device *dev, const struct sdxi_bus_ops *ops)ida_init (&sdxi->vectors);xa_init_flags (&sdxi->client_cxts,XA_FLAGS_ALLOC1 );mutex_init (&sdxi->cxt_lock); +mutex_init (&sdxi->reg_lock);mutex_init (&sdxi->admin_lock);mutex_init (&sdxi->rkey_lock); sdxi->error_irq =-1 ;
drivers/dma/sdxi/error.c +4 -0
@@ -267,6 +267,7 @@ int sdxi_error_init(struct sdxi_dev *sdxi)sdxi_write64 (sdxi,SDXI_MMIO_ERR_WRT ,0 );sdxi_write64 (sdxi,SDXI_MMIO_ERR_RD ,0 ); +mutex_lock (&sdxi->reg_lock); reg =sdxi_read64 (sdxi,SDXI_MMIO_ERR_CTL );FIELD_MODIFY (SDXI_MMIO_ERR_CTL_EN , ®,1 );sdxi_write64 (sdxi,SDXI_MMIO_ERR_CTL , reg);
@@ -274,6 +275,7 @@ int sdxi_error_init(struct sdxi_dev *sdxi) reg =sdxi_read64 (sdxi,SDXI_MMIO_CTL0 );FIELD_MODIFY (SDXI_MMIO_CTL0_FN_ERR_INTR_EN , ®,1 );sdxi_write64 (sdxi,SDXI_MMIO_CTL0 , reg); +mutex_unlock (&sdxi->reg_lock); size_order =ilog2 (SDXI_ERRLOG_SIZE ) -ilog2 (SZ_4K ); reg = FIELD_PREP(SDXI_MMIO_ERR_CFG_PTR,
@@ -294,6 +296,7 @@ void sdxi_error_exit(struct sdxi_dev *sdxi)sdxi_write64 (sdxi,SDXI_MMIO_ERR_CFG ,0 ); +mutex_lock (&sdxi->reg_lock); reg =sdxi_read64 (sdxi,SDXI_MMIO_ERR_CTL );FIELD_MODIFY (SDXI_MMIO_ERR_CTL_EN , ®,0 );sdxi_write64 (sdxi,SDXI_MMIO_ERR_CTL , reg);
@@ -301,6 +304,7 @@ void sdxi_error_exit(struct sdxi_dev *sdxi) reg =sdxi_read64 (sdxi,SDXI_MMIO_CTL0 );FIELD_MODIFY (SDXI_MMIO_CTL0_FN_ERR_INTR_EN , ®,0 );sdxi_write64 (sdxi,SDXI_MMIO_CTL0 , reg); +mutex_unlock (&sdxi->reg_lock);if (sdxi->error_irq >=0 )devm_free_irq (sdxi->dev, sdxi->error_irq, sdxi);
drivers/dma/sdxi/ioctl.c +408 -5
439 lines not on this page · raw message
drivers/dma/sdxi/ioctl.h +0 -1
@@ -42,7 +42,6 @@ struct sdxi_ioctl_desc {unsigned int file_flags;enum sdxi_ioctl_access_class access;sdxi_ioctl_t *func; -const char *name; };#define SDXI_IOCTL_F_DEVICE BIT(0)
drivers/dma/sdxi/sdxi.h +1 -0
@@ -96,6 +96,7 @@ struct sdxi_dev {dma_addr_t L1_dma[SDXI_L2_TABLE_ENTRIES ];u16 L1_users[SDXI_L2_TABLE_ENTRIES ];struct mutex cxt_lock;/* context table serialization */ +struct mutex reg_lock;/* MMIO register updates */ /* RKey table */ struct mutex rkey_lock;
Signature · 1 line
2.56.1
PATCH 18/44 dmaengine: sdxi: implement userspace context file operations
In reply to Wei HuangImplement user-space context creation, same-mm context fds, quiesce, eventfd binding, poll, and token-validated doorbell mappings. Let PCI perform the final BAR remap checking against doorbell resource bounds.
--- drivers/dma/sdxi/context.c | 45 ++++- drivers/dma/sdxi/context.h | 4 + drivers/dma/sdxi/device.c | 3 + drivers/dma/sdxi/ioctl.c | 396 ++++++++++++++++++++++++++++++++++++- drivers/dma/sdxi/pci.c | 27 +++ drivers/dma/sdxi/sdxi.h | 8 + 6 files changed, 475 insertions(+), 8 deletions(-)
drivers/dma/sdxi/context.c +41 -4
@@ -15,8 +15,10 @@#include <linux/dma-mapping.h> #include <linux/dmapool.h> #include <linux/errno.h> +#include <linux/fs.h> #include <linux/idr.h> #include <linux/iommu.h> +#include <linux/mm.h> #include <linux/overflow.h> #include <linux/poll.h> #include <linux/slab.h>
@@ -73,6 +75,8 @@ static void sdxi_free_cxt(struct sdxi_cxt *cxt)ida_destroy (&cxt->akey_ida);mutex_destroy (&cxt->akey_lock);mutex_destroy (&cxt->cleanup_lock); +if (cxt->mapping_inode) +iput (cxt->mapping_inode);kfree (cxt->ring_state);kfree (cxt);put_device (&sdxi->chardev);
@@ -388,9 +392,9 @@ static int sdxi_publish_cxt(struct sdxi_cxt *cxt,u8 l1_idx;int err; -if (WARN_ONCE (cxt->id > cxt->sdxi->max_cxtid, +if (WARN_ONCE (cxt->id >READ_ONCE (cxt->sdxi->max_cxtid),"can't install cxt with id %u (limit %u)" , - cxt->id, cxt->sdxi->max_cxtid)) + cxt->id,READ_ONCE (cxt->sdxi->max_cxtid)))return -EINVAL ; err =configure_cxt_ctl (cxt->cxt_ctl, ctl_cfg);
@@ -415,7 +419,7 @@ static int sdxi_publish_cxt(struct sdxi_cxt *cxt, .akey_sz = akey_table_order(cxt->akey_table), .akey_ptr = cxt->akey_table_dma, .cxt_pasid = cxt->pasid, - .max_buffer = cxt->sdxi->max_buffer, + .max_buffer = READ_ONCE(cxt->sdxi->max_buffer), .opb_000_enb = cxt->opb_000_enb, };
@@ -734,6 +738,8 @@ static void sdxi_cxt_force_exit(struct sdxi_cxt *cxt)mutex_lock (&cxt->cleanup_lock); cxt->cleanup_stopping = true;mutex_unlock (&cxt->cleanup_lock); +if (cxt->mapping_inode) +unmap_mapping_range (cxt->mapping_inode->i_mapping,0 ,0 ,1 );cancel_delayed_work_sync (&cxt->cleanup_work);mutex_lock (&cxt->cleanup_lock);
@@ -754,6 +760,16 @@ static void sdxi_cxt_force_exit(struct sdxi_cxt *cxt)sdxi_cxt_put (cxt); } +void sdxi_cxt_abort (struct sdxi_cxt *cxt) +{ +if (!cxt || !sdxi_cxt_exit (cxt)) +return ; + +/* Normal release retained the context; fence DMA before forcing it. */ +sdxi_dev_fail (cxt->sdxi); +sdxi_cxt_force_exit (cxt); +} +static int sdxi_cxt_doorbell_offset (const struct sdxi_cxt *cxt,size_t *offset);static int sdxi_cxt_set_kernel_doorbell (struct sdxi_cxt *cxt);
@@ -827,7 +843,7 @@ static void sdxi_cxt_id_dtor(const struct sdxi_cxt_id *cxt_id)static struct sdxi_cxt_id sdxi_cxt_id_ctor (struct sdxi_dev *sdxi) { -struct xa_limit limit =XA_LIMIT (1 , sdxi->max_cxtid); +struct xa_limit limit =XA_LIMIT (1 ,READ_ONCE (sdxi->max_cxtid));u32 index;return (struct sdxi_cxt_id ) {
@@ -1059,6 +1075,8 @@ int sdxi_cxt_exit(struct sdxi_cxt *cxt)mutex_lock (&cxt->cleanup_lock); cxt->cleanup_stopping = true;mutex_unlock (&cxt->cleanup_lock); +if (cxt->mapping_inode) +unmap_mapping_range (cxt->mapping_inode->i_mapping,0 ,0 ,1 );cancel_delayed_work_sync (&cxt->cleanup_work);mutex_lock (&cxt->cleanup_lock);
@@ -1220,6 +1238,25 @@ void sdxi_cxt_vma_open(struct sdxi_cxt *cxt)mutex_unlock (&cxt->cleanup_lock); } +int sdxi_cxt_vma_acquire (struct sdxi_cxt *cxt) +{ +int ret =0 ; + +if (!cxt) +return -EINVAL ; + +mutex_lock (&cxt->cleanup_lock); +if (cxt->fatal || cxt->cleanup_stopping || cxt->resources_released) { + ret = -ENODEV ; + }else { +sdxi_cxt_get (cxt); + cxt->vma_refs++; + } +mutex_unlock (&cxt->cleanup_lock); + +return ret; +} +void sdxi_cxt_vma_close (struct sdxi_cxt *cxt) {if (!cxt)
drivers/dma/sdxi/context.h +4 -0
@@ -33,6 +33,7 @@ struct sdxi_akey_table { };struct eventfd_ctx ; +struct inode ;struct sdxi_process ;/* For encoding the akey table size in CXT_L1_ENT's akey_sz. */
@@ -79,6 +80,7 @@ struct sdxi_cxt {struct sdxi_ring_state *ring_state;struct sdxi_process *process; +struct inode *mapping_inode;spinlock_t intr_lock;/* eventfd and interrupt state */ struct eventfd_ctx *intr_eventfd;
@@ -100,6 +102,7 @@ struct sdxi_cxt *sdxi_ucxt_new(struct sdxi_dev *sdxi, u32 ring_entries,* the caller must not reuse it. */ int sdxi_cxt_exit (struct sdxi_cxt *cxt); +void sdxi_cxt_abort (struct sdxi_cxt *cxt);void sdxi_client_cxts_exit (struct sdxi_dev *sdxi);void sdxi_cxt_get (struct sdxi_cxt *cxt);void sdxi_cxt_put (struct sdxi_cxt *cxt);
@@ -113,6 +116,7 @@ void sdxi_cxt_kill_stopped(struct sdxi_cxt *cxt);void sdxi_cxt_release_user_handle (struct sdxi_cxt *cxt);int sdxi_cxt_notify_mm_release (struct sdxi_cxt *cxt);void sdxi_cxt_vma_open (struct sdxi_cxt *cxt); +int sdxi_cxt_vma_acquire (struct sdxi_cxt *cxt);void sdxi_cxt_vma_close (struct sdxi_cxt *cxt);enum sdxi_submit_flags {
drivers/dma/sdxi/device.c +3 -0
@@ -391,6 +391,9 @@ static int sdxi_fn_activate(struct sdxi_dev *sdxi) sdxi->db_stride *=1U <<FIELD_GET (SDXI_MMIO_CAP0_DB_STRIDE , cap0);if (sdxi->db_stride > sdxi->db_size)return -ENODEV ; + sdxi->max_ring_entries =SZ_1K ; + sdxi->max_ring_entries <<= +FIELD_GET (SDXI_MMIO_CAP0_MAX_DS_RING_SZ , cap0); cap1 =sdxi_read64 (sdxi,SDXI_MMIO_CAP1 ); sdxi->op_grp_cap =FIELD_GET (SDXI_MMIO_CAP1_OPB_000_CAP , cap1);
drivers/dma/sdxi/ioctl.c +392 -4
468 lines not on this page · raw message
drivers/dma/sdxi/pci.c +27 -0
@@ -11,9 +11,12 @@#include <linux/err.h> #include <linux/io.h> #include <linux/iomap.h> +#include <linux/mm.h> #include <linux/module.h> +#include <linux/overflow.h> #include <linux/pci.h> +#include "context.h" #include "mmio.h" #include "sdxi.h"
@@ -129,12 +132,36 @@ static void sdxi_pci_force_quiesce(struct sdxi_dev *sdxi)dev_err (&pdev->dev,"pending PCI transactions did not drain\n" ); } +static int sdxi_pci_mmap_doorbell (struct sdxi_dev *sdxi, +struct sdxi_cxt *cxt, +struct vm_area_struct *vma) +{ +struct pci_dev *pdev =sdxi_to_pci_dev (sdxi); +resource_size_t offset; +resource_size_t address; + +if (check_mul_overflow ((resource_size_t )cxt->id, + (resource_size_t )sdxi->db_stride, &offset)) +return -EOVERFLOW ; +if (offset >pci_resource_len (pdev,SDXI_PCI_BAR_DOORBELL ) || + sdxi->db_stride > +pci_resource_len (pdev,SDXI_PCI_BAR_DOORBELL ) - offset) +return -EINVAL ; + + address =pci_resource_start (pdev,SDXI_PCI_BAR_DOORBELL ) + offset; + vma->vm_page_prot =pgprot_noncached (vma->vm_page_prot); + +return io_remap_pfn_range (vma, vma->vm_start, address >>PAGE_SHIFT , + sdxi->db_stride, vma->vm_page_prot); +} +static const struct sdxi_bus_ops sdxi_pci_ops = { .owner =THIS_MODULE , .init = sdxi_pci_init, .reset = sdxi_pci_reset, .get_irq = sdxi_pci_get_irq, .force_quiesce = sdxi_pci_force_quiesce, + .mmap_doorbell = sdxi_pci_mmap_doorbell, }; static int sdxi_pci_probe(struct pci_dev *pdev,
drivers/dma/sdxi/sdxi.h +8 -0
@@ -47,7 +47,9 @@ enum { };struct sdxi_dev ; +struct sdxi_cxt ;struct module ; +struct vm_area_struct ;/** * struct sdxi_bus_ops - Bus-specific methods for SDXI devices.
@@ -74,6 +76,11 @@ struct sdxi_bus_ops {* device recovery fails. */ void (*force_quiesce)(struct sdxi_dev *sdxi); +/** +* @mmap_doorbell: Map one context's doorbell region. +*/ +int (*mmap_doorbell)(struct sdxi_dev *sdxi,struct sdxi_cxt *cxt, +struct vm_area_struct *vma); };struct sdxi_dev {
@@ -86,6 +93,7 @@ struct sdxi_dev {/* hardware capabilities (from cap0 & cap1) */ u32 db_stride;/* doorbell stride in bytes */ +u64 max_ring_entries;u16 max_cxtid;/* Maximum context ID allowed. */ u8 max_buffer;/* Configured log2 buffer size minus 21. */ u32 op_grp_cap;/* supported operation group cap */
Signature · 1 line
2.56.1
PATCH 19/44 dmaengine: sdxi: validate and copy key ioctl payloads
In reply to Wei HuangSize variable-length key bitmap and entry payloads from their fixed UAPI headers, validate table bounds before allocation, and copy only the bytes described by the shared AKey/RKey ABI. Key handlers, which will be introduced later, remain unsupported in this patch.
--- drivers/dma/sdxi/ioctl.c | 161 ++++++++++++++++++++++++++++++++++++--- 1 file changed, 150 insertions(+), 11 deletions(-)
drivers/dma/sdxi/ioctl.c +150 -11
@@ -615,17 +615,85 @@ static bool sdxi_ioctl_has_trailing_payload(unsigned int cmd) cmd ==SDXI_GET_AKEYS || cmd ==SDXI_SET_AKEYS ; } +static bool sdxi_key_list_cmd (unsigned int cmd) +{ +return cmd ==SDXI_GET_RKEY_LIST || cmd ==SDXI_GET_AKEY_LIST ; +} + +static bool sdxi_key_entries_cmd (unsigned int cmd) +{ +return cmd ==SDXI_GET_RKEYS || cmd ==SDXI_SET_RKEYS || + cmd ==SDXI_GET_AKEYS || cmd ==SDXI_SET_AKEYS ; +} + +static u32 sdxi_key_table_entries (unsigned int cmd,struct sdxi_file *sf) +{ +if (cmd ==SDXI_GET_RKEY_LIST || cmd ==SDXI_GET_RKEYS || + cmd ==SDXI_SET_RKEYS ) +return sf->process->sdxi->rkey_entries; + +if (!sf->cxt || !sf->cxt->akey_table) +return 0 ; +return ARRAY_SIZE (sf->cxt->akey_table->entry); +} + +static int sdxi_key_ioctl_sizes (unsigned int cmd,struct sdxi_file *sf, +const void *header,size_t header_size, +size_t *copyin_size,size_t *copyout_size, +size_t *allocation_size) +{ +size_t payload_size; +u32 nentries; +u32 nkeys; + + nentries =sdxi_key_table_entries (cmd, sf); + +if (sdxi_key_list_cmd (cmd)) { +const struct sdxi_key_list_args *args = header; +size_t required =DIV_ROUND_UP (nentries,8 ); + + *copyin_size = header_size; + *copyout_size = header_size +min_t (size_t, args->buf_size, + required); + *allocation_size = *copyout_size; +return 0 ; + } + +if (cmd ==SDXI_GET_RKEYS || cmd ==SDXI_GET_AKEYS ) + nkeys = ((const struct sdxi_get_keys_args *)header)->nkeys; +else + nkeys = ((const struct sdxi_set_keys_args *)header)->nkeys; + +if (nkeys >min_t (u32, nentries,4096 )) +return -EINVAL ; +if (check_mul_overflow ((size_t )nkeys,sizeof (struct sdxi_key_entry ), + &payload_size) || +check_add_overflow (header_size, payload_size, allocation_size)) +return -EOVERFLOW ; + + *copyin_size = *allocation_size; +if (cmd ==SDXI_GET_RKEYS || cmd ==SDXI_GET_AKEYS ) + *copyout_size = *allocation_size; +else + *copyout_size = header_size; +return 0 ; +} +static long sdxi_ioctl_live (struct file *file,unsigned int cmd,unsigned long arg) {const struct sdxi_ioctl_desc *desc;struct sdxi_file *sf = file->private_data; +size_t copyout_size; +size_t copyin_size;unsigned int canonical_size;unsigned int user_size; -unsigned int size; +size_t size;unsigned int nr;char stack_data[128 ];void *data = stack_data; +bool header_copied = false; +bool variable;bool allowed;int ret;
@@ -666,32 +734,69 @@ static long sdxi_ioctl_live(struct file *file, unsigned int cmd, canonical_size =_IOC_SIZE (desc->cmd); user_size =_IOC_SIZE (cmd); - size =max (canonical_size, user_size); -if (size >PAGE_SIZE ) + copyin_size = (_IOC_DIR (cmd) & _IOC_WRITE) ? user_size :0 ; + copyout_size = (_IOC_DIR (cmd) & _IOC_READ) ? user_size :0 ; + size =max_t (size_t, canonical_size, user_size); + + variable =sdxi_key_list_cmd (desc->cmd) || +sdxi_key_entries_cmd (desc->cmd); +if (variable) { +if (user_size < canonical_size) +return -EINVAL ; +if (canonical_size >sizeof (stack_data)) +return -E2BIG ; +if (copy_from_user (stack_data, (void __user *)arg, + canonical_size)) +return -EFAULT ; + header_copied = true; + ret =sdxi_key_ioctl_sizes (desc->cmd, sf, stack_data, + canonical_size, ©in_size, + ©out_size, &size); +if (ret) +return ret; + } + +if (size >SZ_1M )return -E2BIG ;if (size >sizeof (stack_data)) { data =kzalloc (size,GFP_KERNEL );if (!data)return -ENOMEM ; - }else { + }else if (!header_copied) {memset (data,0 , size); + }else if (size > canonical_size) { +memset (data + canonical_size,0 , size - canonical_size); } -if ((_IOC_DIR (cmd) & _IOC_WRITE) && -copy_from_user (data, (void __user *)arg, user_size)) { - ret = -EFAULT ; - goto out; +if (_IOC_DIR (cmd) & _IOC_WRITE) { +if (header_copied) { +if (data != stack_data) +memcpy (data, stack_data, canonical_size); +if (copyin_size > canonical_size && +copy_from_user (data + canonical_size, + (void __user *)(arg + canonical_size), + copyin_size - canonical_size)) { + ret = -EFAULT ; + goto out; + } + }else if (copy_from_user (data, (void __user *)arg, + copyin_size)) { + ret = -EFAULT ; + goto out; + } } ret = desc->func (file, sf, data); +if (ret == -ENOSPC &&sdxi_key_list_cmd (desc->cmd)) + copyout_size = canonical_size;if ((_IOC_DIR (cmd) & _IOC_READ) && user_size > canonical_size && !sdxi_ioctl_has_trailing_payload (desc->cmd))memset ((u8 *)data + canonical_size,0 , user_size - canonical_size);if ((_IOC_DIR (cmd) & _IOC_READ) && -copy_to_user ((void __user *)arg, data, user_size)) +copy_to_user ((void __user *)arg, data, copyout_size)) ret = -EFAULT ; out:
@@ -716,7 +821,7 @@ static long sdxi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)return ret; } -static int sdxi_mmap (struct file *file,struct vm_area_struct *vma) +static int sdxi_mmap_live (struct file *file,struct vm_area_struct *vma) {struct sdxi_file *sf = file->private_data;struct sdxi_cxt *cxt;
@@ -781,7 +886,24 @@ static int sdxi_mmap(struct file *file, struct vm_area_struct *vma)return ret; } -static __poll_t sdxi_cxt_poll (struct file *file,poll_table *wait) +static int sdxi_mmap (struct file *file,struct vm_area_struct *vma) +{ +struct sdxi_file *sf = file->private_data; +struct sdxi_dev *sdxi; +int ret; + +if (!sf || !sf->process) +return -EINVAL ; + sdxi = sf->process->sdxi; + +if (!down_read_trylock (&sdxi->state_lock)) +return -EAGAIN ; + ret = sdxi->online ?sdxi_mmap_live (file, vma) : -ENODEV ; +up_read (&sdxi->state_lock); +return ret; +} + +static __poll_t sdxi_cxt_poll_live (struct file *file,poll_table *wait) {struct sdxi_file *sf = file->private_data;struct sdxi_cxt *cxt;
@@ -805,6 +927,23 @@ static __poll_t sdxi_cxt_poll(struct file *file, poll_table *wait)return mask; } +static __poll_t sdxi_cxt_poll (struct file *file,poll_table *wait) +{ +struct sdxi_file *sf = file->private_data; +struct sdxi_dev *sdxi; +__poll_t mask; + +if (!sf || !sf->process) +return EPOLLERR |EPOLLHUP ; + sdxi = sf->process->sdxi; + +down_read (&sdxi->state_lock); + mask = sdxi->online ?sdxi_cxt_poll_live (file, wait) : +EPOLLERR |EPOLLHUP ; +up_read (&sdxi->state_lock); +return mask; +} +static int sdxi_open (struct inode *inode,struct file *file) {struct sdxi_dev *sdxi;
Signature · 1 line
2.56.1
PATCH 20/44 dmaengine: sdxi: implement RKey management ioctls
In reply to Wei HuangImplement admin-only RKey bitmap, read, and write operations over the shared key-table ABI. Validate complete batches before modifying memory, publish valid bits last, and issue RKey update plus sync before reporting commit state.
--- drivers/dma/sdxi/ioctl.c | 8 +- drivers/dma/sdxi/keys.c | 270 +++++++++++++++++++++++++++++++++++++++ drivers/dma/sdxi/keys.h | 6 + 3 files changed, 281 insertions(+), 3 deletions(-)
drivers/dma/sdxi/ioctl.c +5 -3
@@ -31,6 +31,7 @@#include "context.h" #include "intr.h" #include "ioctl.h" +#include "keys.h" #include "mmio.h" #include "process.h" #include "sdxi.h"
@@ -95,6 +96,7 @@ static int sdxi_ioctl_get_uapi_info(struct file *file, struct sdxi_file *sf, .caps = {SDXI_UAPI_CAP_DEV_INFO |SDXI_UAPI_CAP_DEV_ATTR_MGMT | +SDXI_UAPI_CAP_RKEY_MGMT |SDXI_UAPI_CAP_CXT_CREATE | SDXI_UAPI_CAP_CXT_EVENTFD, },
@@ -569,11 +571,11 @@ static const struct sdxi_ioctl_desc sdxi_ioctls[] = { SDXI_IOCTL_A_PUBLIC_DEVICE),SDXI_IOCTL_DEF (0x04 ,SDXI_SET_DEV_ATTR , sdxi_ioctl_set_dev_attr,SDXI_IOCTL_F_DEVICE ,SDXI_IOCTL_A_ADMIN_DEVICE ), -SDXI_IOCTL_DEF (0x05 ,SDXI_GET_RKEY_LIST , sdxi_ioctl_unsupported, +SDXI_IOCTL_DEF (0x05 ,SDXI_GET_RKEY_LIST , sdxi_ioctl_get_rkey_list,SDXI_IOCTL_F_DEVICE ,SDXI_IOCTL_A_ADMIN_DEVICE ), -SDXI_IOCTL_DEF (0x06 ,SDXI_GET_RKEYS , sdxi_ioctl_unsupported, +SDXI_IOCTL_DEF (0x06 ,SDXI_GET_RKEYS , sdxi_ioctl_get_rkeys,SDXI_IOCTL_F_DEVICE ,SDXI_IOCTL_A_ADMIN_DEVICE ), -SDXI_IOCTL_DEF (0x07 ,SDXI_SET_RKEYS , sdxi_ioctl_unsupported, +SDXI_IOCTL_DEF (0x07 ,SDXI_SET_RKEYS , sdxi_ioctl_set_rkeys,SDXI_IOCTL_F_DEVICE ,SDXI_IOCTL_A_ADMIN_DEVICE ),SDXI_IOCTL_DEF (0x08 ,SDXI_CREATE_CXT , sdxi_ioctl_create_cxt, SDXI_IOCTL_F_DEVICE, SDXI_IOCTL_A_PUBLIC_DEVICE),
drivers/dma/sdxi/keys.c +270 -0
288 lines not on this page · raw message
drivers/dma/sdxi/keys.h +6 -0
@@ -11,8 +11,14 @@#include <linux/types.h> struct sdxi_dev ; +struct file ; +struct sdxi_file ;int sdxi_keys_init (struct sdxi_dev *sdxi,u64 cap1);void sdxi_keys_exit (struct sdxi_dev *sdxi); +int sdxi_ioctl_get_rkey_list (struct file *file,struct sdxi_file *sf, +void *data); +int sdxi_ioctl_get_rkeys (struct file *file,struct sdxi_file *sf,void *data); +int sdxi_ioctl_set_rkeys (struct file *file,struct sdxi_file *sf,void *data);#endif /* DMA_SDXI_KEYS_H */
Signature · 1 line
2.56.1
PATCH 21/44 dmaengine: sdxi: implement AKey management ioctls
In reply to Wei HuangImplement context-scoped AKey bitmap, read, and write operations. For security reasons, we constraint caller's requests to local non-privileged PASID and validate interrupt entries against the bound eventfd vector.
--- drivers/dma/sdxi/ioctl.c | 9 +- drivers/dma/sdxi/keys.c | 234 +++++++++++++++++++++++++++++++++++++++ drivers/dma/sdxi/keys.h | 4 + 3 files changed, 243 insertions(+), 4 deletions(-)
drivers/dma/sdxi/ioctl.c +5 -4
@@ -98,7 +98,8 @@ static int sdxi_ioctl_get_uapi_info(struct file *file, struct sdxi_file *sf, SDXI_UAPI_CAP_DEV_ATTR_MGMT | SDXI_UAPI_CAP_RKEY_MGMT | SDXI_UAPI_CAP_CXT_CREATE | - SDXI_UAPI_CAP_CXT_EVENTFD, + SDXI_UAPI_CAP_CXT_EVENTFD | + SDXI_UAPI_CAP_AKEY_MGMT, }, };
@@ -581,11 +582,11 @@ static const struct sdxi_ioctl_desc sdxi_ioctls[] = { SDXI_IOCTL_F_DEVICE, SDXI_IOCTL_A_PUBLIC_DEVICE),SDXI_IOCTL_DEF (0x09 ,SDXI_CXT_EVENTFD , sdxi_ioctl_cxt_eventfd,SDXI_IOCTL_F_CONTEXT ,SDXI_IOCTL_A_CONTEXT_OWNER ), -SDXI_IOCTL_DEF (0x0a ,SDXI_GET_AKEY_LIST , sdxi_ioctl_unsupported, +SDXI_IOCTL_DEF (0x0a ,SDXI_GET_AKEY_LIST , sdxi_ioctl_get_akey_list,SDXI_IOCTL_F_CONTEXT ,SDXI_IOCTL_A_CONTEXT_OWNER ), -SDXI_IOCTL_DEF (0x0b ,SDXI_GET_AKEYS , sdxi_ioctl_unsupported, +SDXI_IOCTL_DEF (0x0b ,SDXI_GET_AKEYS , sdxi_ioctl_get_akeys,SDXI_IOCTL_F_CONTEXT ,SDXI_IOCTL_A_CONTEXT_OWNER ), -SDXI_IOCTL_DEF (0x0c ,SDXI_SET_AKEYS , sdxi_ioctl_unsupported, +SDXI_IOCTL_DEF (0x0c ,SDXI_SET_AKEYS , sdxi_ioctl_set_akeys,SDXI_IOCTL_F_CONTEXT ,SDXI_IOCTL_A_CONTEXT_OWNER ),SDXI_IOCTL_DEF (0x0d ,SDXI_ADMIN_DISC , sdxi_ioctl_unsupported, SDXI_IOCTL_F_DEVICE, SDXI_IOCTL_A_PUBLIC_DEVICE),
drivers/dma/sdxi/keys.c +234 -0
256 lines not on this page · raw message
drivers/dma/sdxi/keys.h +4 -0
@@ -20,5 +20,9 @@ int sdxi_ioctl_get_rkey_list(struct file *file, struct sdxi_file *sf, void *data);int sdxi_ioctl_get_rkeys (struct file *file,struct sdxi_file *sf,void *data);int sdxi_ioctl_set_rkeys (struct file *file,struct sdxi_file *sf,void *data); +int sdxi_ioctl_get_akey_list (struct file *file,struct sdxi_file *sf, +void *data); +int sdxi_ioctl_get_akeys (struct file *file,struct sdxi_file *sf,void *data); +int sdxi_ioctl_set_akeys (struct file *file,struct sdxi_file *sf,void *data);#endif /* DMA_SDXI_KEYS_H */
Signature · 1 line
2.56.1
PATCH 22/44 dmaengine: sdxi: expose operation-group discovery
In reply to Wei HuangExpose read-only SDXI 1.1 discovery on device fds and use discovered GUIDs to authorize raw opb_000 requests for user contexts. For security reasons, deny unknown and admin-only groups. It also enables atomic groups only when PCI requester support is available.
--- drivers/dma/sdxi/ioctl.c | 177 ++++++++++++++++++++++++++++++++++++++- drivers/dma/sdxi/pci.c | 12 +++ drivers/dma/sdxi/sdxi.h | 1 + 3 files changed, 186 insertions(+), 4 deletions(-)
drivers/dma/sdxi/ioctl.c +173 -4
@@ -25,6 +25,7 @@#include <linux/sizes.h> #include <linux/slab.h> #include <linux/uaccess.h> +#include <linux/uuid.h> #include <uapi/linux/sdxi.h> #include "admin.h"
@@ -99,7 +100,8 @@ static int sdxi_ioctl_get_uapi_info(struct file *file, struct sdxi_file *sf, SDXI_UAPI_CAP_RKEY_MGMT | SDXI_UAPI_CAP_CXT_CREATE | SDXI_UAPI_CAP_CXT_EVENTFD | - SDXI_UAPI_CAP_AKEY_MGMT, + SDXI_UAPI_CAP_AKEY_MGMT | + SDXI_UAPI_CAP_ADMIN_DISC, }, };
@@ -321,22 +323,134 @@ static bool sdxi_u32_array_zero(const u32 *values, size_t count)return true; } +enum sdxi_op_group_policy { +SDXI_OP_GROUP_UNKNOWN , +SDXI_OP_GROUP_USER , +SDXI_OP_GROUP_ADMIN_ONLY , +}; + +struct sdxi_op_group_policy_entry { +guid_t guid; +enum sdxi_op_group_policy policy; +}; + +static const struct sdxi_op_group_policy_entry sdxi_op_group_policy[] = { + {GUID_INIT (0x193259fe ,0x150b ,0x4008 ,0xa8 ,0x3f ,0x6f ,0xaf ,0x59 , +0xf5 ,0x27 ,0x2a ),SDXI_OP_GROUP_USER }, + {GUID_INIT (0xd9bc29a1 ,0x91dc ,0x4243 ,0x97 ,0x51 ,0xb6 ,0xb0 ,0x32 , +0x9d ,0xaf ,0xe1 ),SDXI_OP_GROUP_USER }, + {GUID_INIT (0x3ac7630e ,0x7009 ,0x424b ,0x82 ,0x99 ,0x20 ,0xe2 ,0x90 , +0x1e ,0xcc ,0x5e ),SDXI_OP_GROUP_USER }, + {GUID_INIT (0x7fb16347 ,0x4c3a ,0x4d16 ,0x84 ,0x42 ,0xcb ,0xa5 ,0x1e , +0x34 ,0x08 ,0x80 ),SDXI_OP_GROUP_USER }, + {GUID_INIT (0x0af23293 ,0x7595 ,0x4939 ,0xb0 ,0x8a ,0x1c ,0x72 ,0x93 , +0xc2 ,0xe9 ,0x75 ),SDXI_OP_GROUP_USER }, + {GUID_INIT (0x989b9a64 ,0x28d9 ,0x4294 ,0x9c ,0x7b ,0x9a ,0x3f ,0x27 , +0xaf ,0xaf ,0x5c ),SDXI_OP_GROUP_USER }, + {GUID_INIT (0x15114db9 ,0x4a7e ,0x47ab ,0x97 ,0xdd ,0xea ,0x86 ,0xed , +0xa1 ,0x0b ,0x6e ),SDXI_OP_GROUP_USER }, + {GUID_INIT (0xb3e551a3 ,0xf1a9 ,0x4c9a ,0x82 ,0x52 ,0xda ,0xf5 ,0xc0 , +0xd9 ,0x1a ,0x44 ),SDXI_OP_GROUP_USER }, + {GUID_INIT (0x2595c4dc ,0x6fac ,0x49d2 ,0xa3 ,0x31 ,0xb1 ,0x40 ,0x0a , +0x7f ,0x69 ,0x0f ),SDXI_OP_GROUP_USER }, + {GUID_INIT (0xf5b7610b ,0x0dc6 ,0x4c03 ,0xab ,0x79 ,0x65 ,0xf1 ,0xf4 , +0xef ,0xcf ,0x4c ),SDXI_OP_GROUP_ADMIN_ONLY }, +}; + +static enum sdxi_op_group_policy +sdxi_op_group_lookup (const guid_t *guid) +{ +size_t i; + +if (guid_is_null (guid)) +return SDXI_OP_GROUP_UNKNOWN ; + +for (i =0 ; i <ARRAY_SIZE (sdxi_op_group_policy); i++) +if (guid_equal (guid, &sdxi_op_group_policy[i].guid)) +return sdxi_op_group_policy[i].policy; + +return SDXI_OP_GROUP_UNKNOWN ; +} + +#define SDXI_DISC_TIMEOUT_MS 5000U + +static int sdxi_discover_user_op_groups (struct sdxi_dev *sdxi,u32 available, +u32 *allowed,u32 *denied) +{ +const u16 first =1 ; +const u16 last =31 ; +const size_t record_size =sizeof (guid_t); +const size_t size = (last - first +1 ) * record_size; +dma_addr_t dma; +u8 *records; +u16 index; +int ret; + +if (!sdxi_dev_compatible (sdxi,SDXI_VERSION_1_1 ) || + !(available &SDXI_OPB_000_DISC_MASK )) +return 0 ; + + records =dma_alloc_coherent (sdxi->dev, size, &dma,GFP_KERNEL ); +if (!records) +return -ENOMEM ; + + ret =sdxi_adm_disc (sdxi, first, last, dma,SDXI_DISC_TIMEOUT_MS , +NULL ); +if (ret) + goto free_records; + +dma_rmb (); +for (index = first; index <= last; index++) { +enum sdxi_op_group_policy policy; +guid_t guid; +u32 bit =BIT (index); + +if (!(available & bit)) +continue ; + +import_guid (&guid, records + (index - first) * record_size); + policy =sdxi_op_group_lookup (&guid); +if (policy ==SDXI_OP_GROUP_USER ) + *allowed |= bit; +else if (policy ==SDXI_OP_GROUP_ADMIN_ONLY ) + *denied |= bit; + } + +free_records: +dma_free_coherent (sdxi->dev, size, records, dma); +return ret; +} +static int sdxi_user_op_groups (struct sdxi_dev *sdxi,u32 requested,u32 *applied) {u32 available;u32 allowed; +u32 denied =SDXI_OPB_000_ADMIN ; +bool use_default = !requested; +int ret; available =FIELD_GET (SDXI_MMIO_CTL2_OPB_000_AVL ,sdxi_read64 (sdxi,SDXI_MMIO_CTL2 )); allowed = available &SDXI_OPB_000_INTR ; +if (sdxi->atomic_ops_enabled) + allowed |= available &SDXI_OPB_000_ATOMIC ; + + ret =sdxi_discover_user_op_groups (sdxi, available, &allowed, + &denied); +if (ret && !use_default && + (requested &SDXI_OPB_000_DISC_MASK )) +return ret; -if (!requested) +if (use_default) requested = allowed; -if (requested &SDXI_OPB_000_ADMIN ) +if (requested & denied)return -EPERM ;if (requested & ~available)return -EINVAL ; +if ((requested &SDXI_OPB_000_ATOMIC ) && + !sdxi->atomic_ops_enabled) +return -EOPNOTSUPP ;if (requested & ~allowed)return -EOPNOTSUPP ;
@@ -552,6 +666,61 @@ static int sdxi_ioctl_quiesce_cxt(struct file *file, struct sdxi_file *sf,return ret; } +static int sdxi_ioctl_admin_disc (struct file *file,struct sdxi_file *sf, +void *data) +{ +struct sdxi_admin_disc_args *args = data; +size_t required; +dma_addr_t dma; +void *buffer; +u16 start; +u16 end; +u32 timeout_ms; +int ret; + +if (args->argsz <sizeof (*args) || args->flags || + !sdxi_u32_array_zero (args->rsvd0,ARRAY_SIZE (args->rsvd0))) +return -EINVAL ; +if (!sdxi_dev_compatible (sf->process->sdxi,SDXI_VERSION_1_1 )) +return -EOPNOTSUPP ; + + start = args->index.start; + end = args->index.end; +if (start > end || end >2047 ) +return -EINVAL ; + + required = (size_t )(end - start +1 ) *sizeof (guid_t); + args->argsz =sizeof (*args); + args->cst_flags =0 ; +if (args->buf_size < required) { + args->buf_size = required; +return -ENOSPC ; + } +if (!args->buf_uptr) +return -EINVAL ; + + buffer =dma_alloc_coherent (sf->process->sdxi->dev, required, &dma, +GFP_KERNEL ); +if (!buffer) +return -ENOMEM ; + + timeout_ms = args->timeout_ms ?:SDXI_DISC_TIMEOUT_MS ; +if (!capable (CAP_SYS_ADMIN )) + timeout_ms =min (timeout_ms,SDXI_DISC_TIMEOUT_MS ); + ret =sdxi_adm_disc (sf->process->sdxi, start, end, dma, + timeout_ms, &args->cst_flags); +if (!ret) { +dma_rmb (); +if (copy_to_user (u64_to_user_ptr (args->buf_uptr), buffer, + required)) + ret = -EFAULT ; + } + +dma_free_coherent (sf->process->sdxi->dev, required, buffer, dma); + args->buf_size = required; +return ret; +} +#define SDXI_IOCTL_DEF (_nr, _cmd, _func, _files, _access) \ [_nr] = { \ .cmd = (_cmd), \
@@ -588,7 +757,7 @@ static const struct sdxi_ioctl_desc sdxi_ioctls[] = { SDXI_IOCTL_F_CONTEXT, SDXI_IOCTL_A_CONTEXT_OWNER),SDXI_IOCTL_DEF (0x0c ,SDXI_SET_AKEYS , sdxi_ioctl_set_akeys,SDXI_IOCTL_F_CONTEXT ,SDXI_IOCTL_A_CONTEXT_OWNER ), -SDXI_IOCTL_DEF (0x0d ,SDXI_ADMIN_DISC , sdxi_ioctl_unsupported, +SDXI_IOCTL_DEF (0x0d ,SDXI_ADMIN_DISC , sdxi_ioctl_admin_disc,SDXI_IOCTL_F_DEVICE ,SDXI_IOCTL_A_PUBLIC_DEVICE ),SDXI_IOCTL_DEF (0x0e ,SDXI_ADMIN_VENDOR , sdxi_ioctl_unsupported, SDXI_IOCTL_F_DEVICE, SDXI_IOCTL_A_VENDOR_HANDLER),
drivers/dma/sdxi/pci.c +12 -0
@@ -14,6 +14,7 @@#include <linux/mm.h> #include <linux/module.h> #include <linux/overflow.h> +#include <linux/pci-ats.h> #include <linux/pci.h> #include "context.h"
@@ -68,6 +69,17 @@ static int sdxi_pci_init(struct sdxi_dev *sdxi) sdxi->has_mailbox = pdev->is_virtfn ||pci_find_ext_capability (pdev,PCI_EXT_CAP_ID_SRIOV ); +/* +* PCIe defines AtomicOp Requester Enable as a PF-owned control that +* also applies to its VFs. Configure the physical function so VF +* contexts inherit the transport capability correctly. +*/ + ret =pci_enable_atomic_ops_to_root (pci_physfn (pdev), +PCI_EXP_DEVCAP2_ATOMIC_COMP32 | +PCI_EXP_DEVCAP2_ATOMIC_COMP64 ); +if (!ret) + sdxi->atomic_ops_enabled = true; +/* * Allocate the minimum required set of vectors plus one for * each client context supported by the function.
drivers/dma/sdxi/sdxi.h +1 -0
@@ -135,6 +135,7 @@ struct sdxi_dev {struct cdev cdev;struct device chardev;int minor; +bool atomic_ops_enabled;bool online;struct rw_semaphore state_lock;/* online state and user operations */
Signature · 1 line
2.56.1
PATCH 23/44 dmaengine: sdxi: implement typed vendor admin transport
In reply to Wei HuangSDXI allows vendors to define vendor-specific descriptors. Add a module-pinned GUID handler registry and a typed vendor ioctl that never accepts raw descriptors from userspace. It probes the vendor's opcode through SDXI discovery, delegates authorization to the registered handler, and keeps execution on the kernel-owned admin context.
--- drivers/dma/sdxi/Makefile | 3 +- drivers/dma/sdxi/ioctl.c | 107 +++++++++++++++++++++++------ drivers/dma/sdxi/vendor.c | 138 ++++++++++++++++++++++++++++++++++++++ drivers/dma/sdxi/vendor.h | 42 ++++++++++++ 4 files changed, 270 insertions(+), 20 deletions(-) create mode 100644 drivers/dma/sdxi/vendor.c create mode 100644 drivers/dma/sdxi/vendor.h
drivers/dma/sdxi/Makefile +2 -1
@@ -12,7 +12,8 @@ sdxi-core-y := \ ioctl.o \ keys.o \ process.o \ - ring.o + ring.o \ + vendor.o obj-$(CONFIG_SDXI_PCI) += sdxi-pci.o sdxi-pci-y := pci.o
drivers/dma/sdxi/ioctl.c +88 -19
157 lines not on this page · raw message
drivers/dma/sdxi/vendor.c new file +138 -0
138 lines not on this page · raw message
drivers/dma/sdxi/vendor.h new file +42 -0
42 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH 24/44 dmaengine: sdxi: expose character device attributes
In reply to Wei HuangAdd 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.
--- 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
drivers/dma/sdxi/Makefile +1 -0
@@ -13,6 +13,7 @@ sdxi-core-y := \ keys.o \ process.o \ ring.o \ + sysfs.o \ vendor.o obj-$(CONFIG_SDXI_PCI) += sdxi-pci.o
drivers/dma/sdxi/context.c +8 -1
@@ -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);
drivers/dma/sdxi/context.h +1 -0
@@ -65,6 +65,7 @@ struct sdxi_cxt {bool registered;bool published;bool update_pending; +bool counted;bool started;struct sdxi_cxt_ctl *cxt_ctl;
drivers/dma/sdxi/device.c +1 -0
@@ -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)
drivers/dma/sdxi/ioctl.c +2 -0
@@ -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)
drivers/dma/sdxi/sdxi.h +2 -0
@@ -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;
drivers/dma/sdxi/sysfs.c new file +70 -0
70 lines not on this page · raw message
drivers/dma/sdxi/sysfs.h new file +13 -0
@@ -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 */
Signature · 1 line
2.56.1
PATCH 25/44 dmaengine: sdxi: add PF and VF device naming
In reply to Wei HuangLet 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.
--- 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(-)
drivers/dma/sdxi/device.c +1 -0
@@ -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)
drivers/dma/sdxi/ioctl.c +11 -8
@@ -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;
drivers/dma/sdxi/pci.c +28 -1
@@ -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[] = {
drivers/dma/sdxi/sdxi.h +15 -0
@@ -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) {
Signature · 1 line
2.56.1
PATCH 26/44 dmaengine: sdxi: add SDXI trace events
In reply to Wei HuangAdd trace events for context and submission queue creation and destruction, along with process SVA bind and unbind operations. Insert the trace points into the corresponding call sites in SDXI driver.
--- drivers/dma/sdxi/Makefile | 1 + drivers/dma/sdxi/context.c | 31 ++++++--- drivers/dma/sdxi/process.c | 6 +- drivers/dma/sdxi/trace.c | 9 +++ drivers/dma/sdxi/trace.h | 137 +++++++++++++++++++++++++++++++++++++ 5 files changed, 173 insertions(+), 11 deletions(-) create mode 100644 drivers/dma/sdxi/trace.c create mode 100644 drivers/dma/sdxi/trace.h
drivers/dma/sdxi/Makefile +1 -0
@@ -14,6 +14,7 @@ sdxi-core-y := \ process.o \ ring.o \ sysfs.o \ + trace.o \ vendor.o obj-$(CONFIG_SDXI_PCI) += sdxi-pci.o
drivers/dma/sdxi/context.c +21 -10
@@ -36,6 +36,7 @@#include "ring.h" #include "sdxi.h" #include "submission.h" +#include "trace.h" #define DEFAULT_DESC_RING_ENTRIES 1024#define SDXI_CXT_QUIESCE_TIMEOUT_MS 5000U
@@ -50,6 +51,16 @@ enum {static void sdxi_cxt_cleanup_workfn (struct work_struct *work); +static void sdxi_cxt_free_sq (struct sdxi_cxt *cxt) +{ +if (!cxt->sq) +return ; + +trace_sdxi_free_sq (cxt, cxt->sq); +sdxi_sq_free (cxt->sdxi, cxt->sq); + cxt->sq =NULL ; +} +/* * Free context and its resources. @cxt may be partially allocated but * must have ->sdxi set.
@@ -70,8 +81,7 @@ static void sdxi_free_cxt(struct sdxi_cxt *cxt) cxt->akey_table, cxt->akey_table_dma);if (cxt->cst_pool)sdxi_cst_pool_destroy (sdxi, cxt->cst_pool); -if (cxt->sq) -sdxi_sq_free (sdxi, cxt->sq); +sdxi_cxt_free_sq (cxt);ida_destroy (&cxt->akey_ida);mutex_destroy (&cxt->akey_lock);mutex_destroy (&cxt->cleanup_lock);
@@ -205,6 +215,7 @@ static int sdxi_alloc_kernel_submission(struct sdxi_cxt *cxt) cxt->sq =sdxi_sq_alloc (cxt->sdxi,DEFAULT_DESC_RING_ENTRIES );if (!cxt->sq)return -ENOMEM ; +trace_sdxi_create_sq (cxt, cxt->sq); cxt->cst_pool =sdxi_cst_pool_create (cxt->sdxi,DEFAULT_DESC_RING_ENTRIES );
@@ -434,11 +445,13 @@ static int sdxi_publish_cxt(struct sdxi_cxt *cxt,mutex_unlock (&cxt->sdxi->cxt_lock);if (err) {invalidate_cxt_ctl (cxt->cxt_ctl); - }else { - cxt->published = true; - cxt->update_pending = false; +return err; } -return err; + + cxt->published = true; + cxt->update_pending = false; +trace_sdxi_create_cxt (cxt->sdxi, cxt); +return 0 ; }/* Invalidate a context. */
@@ -451,6 +464,7 @@ static void sdxi_rescind_cxt(struct sdxi_cxt *cxt)if (!cxt->published)return ; +trace_sdxi_free_cxt (sdxi, cxt);mutex_lock (&sdxi->cxt_lock); L1_table = sdxi->L1_tables[l2_idx];
@@ -575,10 +589,7 @@ static void sdxi_cxt_release_resources(struct sdxi_cxt *cxt)sdxi_cst_pool_destroy (sdxi, cxt->cst_pool); cxt->cst_pool =NULL ; } -if (cxt->sq) { -sdxi_sq_free (sdxi, cxt->sq); - cxt->sq =NULL ; - } +sdxi_cxt_free_sq (cxt);kfree (cxt->ring_state); cxt->ring_state =NULL ; }
drivers/dma/sdxi/process.c +5 -1
@@ -14,6 +14,7 @@#include "context.h" #include "process.h" #include "sdxi.h" +#include "trace.h" static void sdxi_process_cleanup (struct sdxi_process *process) {
@@ -95,8 +96,10 @@ void sdxi_process_unbind_sva(struct sdxi_process *process,mmu_notifier_unregister (&process->notifier, process->mm); } -if (sva) +if (sva) {iommu_sva_unbind_device (sva); +trace_sdxi_unbind_process (process->sdxi, pasid); + } }static void sdxi_process_free (struct sdxi_process *process)
@@ -157,6 +160,7 @@ int sdxi_process_bind(struct sdxi_process *process) process->pasid = pasid; process->sva = sva; +trace_sdxi_bind_process (process->sdxi, pasid);return 0 ; unbind:
drivers/dma/sdxi/trace.c new file +9 -0
@@ -0,0 +1,9 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* SDXI tracepoints. +* +* Copyright Advanced Micro Devices, Inc. +*/ + +#define CREATE_TRACE_POINTS +#include "trace.h"
drivers/dma/sdxi/trace.h new file +137 -0
137 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH 27/44 dmaengine: sdxi: support suspend and resume
In reply to Wei HuangDuring suspend, save function control state, stop the function with error interrupts disabled. Similarly restore context tables, RKeys, error logging, the admin context, and previously running client contexts on resume. Keep PCI responsible for wiring the core PM callbacks.
--- drivers/dma/sdxi/context.c | 11 +++ drivers/dma/sdxi/context.h | 1 + drivers/dma/sdxi/device.c | 186 +++++++++++++++++++++++++++++++++++++ drivers/dma/sdxi/error.c | 56 +++++++++++ drivers/dma/sdxi/error.h | 2 + drivers/dma/sdxi/keys.c | 14 +++ drivers/dma/sdxi/keys.h | 1 + drivers/dma/sdxi/pci.c | 5 + drivers/dma/sdxi/sdxi.h | 8 ++ 9 files changed, 284 insertions(+)
drivers/dma/sdxi/context.c +11 -0
@@ -1245,6 +1245,17 @@ int sdxi_cxt_notify_mm_release(struct sdxi_cxt *cxt)return ret; } +void sdxi_cxt_resume_cleanup (struct sdxi_cxt *cxt) +{ +if (!cxt) +return ; + +mutex_lock (&cxt->cleanup_lock); +if (sdxi_cxt_is_user (cxt) &&sdxi_cxt_cleanup_requested (cxt)) +sdxi_cxt_queue_cleanup_locked (cxt,0 ); +mutex_unlock (&cxt->cleanup_lock); +} +void sdxi_cxt_vma_open (struct sdxi_cxt *cxt) {if (!cxt)
drivers/dma/sdxi/context.h +1 -0
@@ -116,6 +116,7 @@ void sdxi_cxt_kill(struct sdxi_cxt *cxt);void sdxi_cxt_kill_stopped (struct sdxi_cxt *cxt);void sdxi_cxt_release_user_handle (struct sdxi_cxt *cxt);int sdxi_cxt_notify_mm_release (struct sdxi_cxt *cxt); +void sdxi_cxt_resume_cleanup (struct sdxi_cxt *cxt);void sdxi_cxt_vma_open (struct sdxi_cxt *cxt);int sdxi_cxt_vma_acquire (struct sdxi_cxt *cxt);void sdxi_cxt_vma_close (struct sdxi_cxt *cxt);
drivers/dma/sdxi/device.c +186 -0
204 lines not on this page · raw message
drivers/dma/sdxi/error.c +56 -0
59 lines not on this page · raw message
drivers/dma/sdxi/error.h +2 -0
@@ -12,5 +12,7 @@ struct sdxi_dev;int sdxi_error_init (struct sdxi_dev *sdxi);void sdxi_error_exit (struct sdxi_dev *sdxi); +void sdxi_error_suspend (struct sdxi_dev *sdxi); +void sdxi_error_resume (struct sdxi_dev *sdxi);#endif /* DMA_SDXI_ERROR_H */
drivers/dma/sdxi/keys.c +14 -0
@@ -289,6 +289,20 @@ void sdxi_keys_exit(struct sdxi_dev *sdxi) sdxi->rkey_cap = false; } +void sdxi_keys_resume (struct sdxi_dev *sdxi) +{ +u64 reg; + +if (!sdxi->rkey_cap || !sdxi->rkey_table) +return ; + + reg =FIELD_PREP (SDXI_MMIO_RKEY_PTR , + sdxi->rkey_table_dma >>ilog2 (SZ_4K )) | +FIELD_PREP (SDXI_MMIO_RKEY_SZ , sdxi->rkey_order) | +SDXI_MMIO_RKEY_EN ; +sdxi_write64 (sdxi,SDXI_MMIO_RKEY , reg); +} +int sdxi_ioctl_get_rkey_list (struct file *file,struct sdxi_file *sf,void *data) {
drivers/dma/sdxi/keys.h +1 -0
@@ -16,6 +16,7 @@ struct sdxi_file;int sdxi_keys_init (struct sdxi_dev *sdxi,u64 cap1);void sdxi_keys_exit (struct sdxi_dev *sdxi); +void sdxi_keys_resume (struct sdxi_dev *sdxi);int sdxi_ioctl_get_rkey_list (struct file *file,struct sdxi_file *sf,void *data);int sdxi_ioctl_get_rkeys (struct file *file,struct sdxi_file *sf,void *data);
drivers/dma/sdxi/pci.c +5 -0
@@ -221,12 +221,17 @@ static const struct pci_device_id sdxi_id_table[] = { };MODULE_DEVICE_TABLE (pci, sdxi_id_table); +static const struct dev_pm_ops sdxi_pm_ops = { +SYSTEM_SLEEP_PM_OPS (sdxi_suspend, sdxi_resume) +}; +static struct pci_driver sdxi_driver = { .name ="sdxi" , .id_table = sdxi_id_table, .probe = sdxi_pci_probe, .remove = sdxi_pci_remove, .sriov_configure = pci_sriov_configure_simple, + .driver.pm =pm_sleep_ptr (&sdxi_pm_ops), };MODULE_IMPORT_NS ("SDXI" );
drivers/dma/sdxi/sdxi.h +8 -0
@@ -146,6 +146,12 @@ struct sdxi_dev {bool online;struct rw_semaphore state_lock;/* online state and user operations */ +struct mutex pm_lock;/* suspend and resume serialization */ +bool pm_suspended; +bool pm_fn_was_active; +u64 pm_ctl0; +u64 pm_ctl2; +const struct sdxi_bus_ops *bus_ops; };
@@ -202,6 +208,8 @@ void sdxi_unregister(struct device *dev);bool sdxi_dev_in_error (const struct sdxi_dev *sdxi);void sdxi_dev_force_quiesce (struct sdxi_dev *sdxi);void sdxi_dev_fail (struct sdxi_dev *sdxi); +int sdxi_suspend (struct device *dev); +int sdxi_resume (struct device *dev);int sdxi_chardev_init (void );void sdxi_chardev_exit (void );int sdxi_chardev_register (struct sdxi_dev *sdxi);
Signature · 1 line
2.56.1
PATCH 28/44 dmaengine: sdxi: amd: define QoS request formats
In reply to Wei HuangAMD QoS monitors and controls resource utilization through the SDXI physical function (PF). Add AMD QoS vendor request formats, operation identifiers, and helper prototypes for code introduced later.
--- drivers/dma/sdxi/amd/qos.h | 95 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) create mode 100644 drivers/dma/sdxi/amd/qos.h
drivers/dma/sdxi/amd/qos.h new file +95 -0
@@ -0,0 +1,95 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* AMD SDXI QoS internal definitions. +* +* Copyright (C) 2026 Advanced Micro Devices, Inc. +*/ + +#ifndef __DMA_SDXI_AMD_QOS_H +#define __DMA_SDXI_AMD_QOS_H + +#include <linux/bits.h> +#include <linux/types.h> + +enum sdxi_amd_qos_admin_vendor_op { +SDXI_AMD_QOS_ADMIN_OP_CAP =1 , +SDXI_AMD_QOS_ADMIN_OP_DEVUPD =2 , +SDXI_AMD_QOS_ADMIN_OP_POOLUPD =3 , +SDXI_AMD_QOS_ADMIN_OP_FNUPD =4 , +SDXI_AMD_QOS_ADMIN_OP_TEL =5 , +}; + +enum sdxi_amd_qos_admin_target_flags { +SDXI_AMD_QOS_TARGET_F_CXT =BIT (0 ), +SDXI_AMD_QOS_TARGET_F_VF =BIT (1 ), +}; + +enum sdxi_amd_qos_feature_flags { +SDXI_AMD_QOS_FEATURE_DYNAMIC_POOL_RECONFIG =BIT (0 ), +SDXI_AMD_QOS_FEATURE_DYNAMIC_POOL_REASSIGN =BIT (1 ), +SDXI_AMD_QOS_FEATURE_TEL_TIMESTAMPS =BIT (2 ), +SDXI_AMD_QOS_FEATURE_FLEXIBLE_POOL_SCOPE =BIT (3 ), +}; + +struct sdxi_amd_qos_devupd_req { +u32 device_maxbw; +}; + +struct sdxi_amd_qos_poolupd_req { +u16 pool_num; +u8 pool_operation; +u8 rsvd0; +u32 pool_maxbw; +u32 pool_minbw; +}; + +struct sdxi_amd_qos_fnupd_req { +u16 pool_num; +u16 flags; +u16 vf_num; +u16 cxt_start; +u16 cxt_end; +u16 rsvd0; +}; + +struct sdxi_amd_qos_tel_req { +u16 pool_num; +u16 flags; +u16 vf_num; +u16 cxt_num; +u8 query_type; +u8 rsvd0[3 ]; +}; + +/* AMD SDXI Quality-of-Service Extensions (ASQOSE). */ +#define SDXI_AMD_QOS_DSC_SUBTYPE_CAP 0x00 +#define SDXI_AMD_QOS_DSC_SUBTYPE_DEVUPD 0x01 +#define SDXI_AMD_QOS_DSC_SUBTYPE_POOLUPD 0x02 +#define SDXI_AMD_QOS_DSC_SUBTYPE_FNUPD 0x03 +#define SDXI_AMD_QOS_DSC_SUBTYPE_TEL 0x04 + +#define SDXI_AMD_QOS_TEL_QTYPE_DEVICE 0x0 +#define SDXI_AMD_QOS_TEL_QTYPE_POOL_CONFIG 0x1 +#define SDXI_AMD_QOS_TEL_QTYPE_POOL_ASSIGN 0x2 +#define SDXI_AMD_QOS_TEL_QTYPE_ACTIVE_POOLS 0x3 +#define SDXI_AMD_QOS_TEL_QTYPE_POOL_REPORT 0x4 +#define SDXI_AMD_QOS_TEL_QTYPE_POOL_VARIANCE 0x5 + +#define SDXI_AMD_QOS_POOL_OP_CREATE 0x0 +#define SDXI_AMD_QOS_POOL_OP_UPDATE 0x1 +#define SDXI_AMD_QOS_POOL_OP_DESTROY 0x2 + +u64 sdxi_amd_qos_query_selector (u16 cxt_num,u8 query_type); +u32 sdxi_amd_qos_align_bw (u32 bw,u32 granularity); +int sdxi_amd_qos_validate_devupd_req (u32 device_maxbw,u32 total_allocated_bw, +u32 granularity_bw); +int sdxi_amd_qos_validate_poolupd_req (const struct sdxi_amd_qos_poolupd_req *req, +u16 max_pools,u32 granularity_bw); +int sdxi_amd_qos_validate_fnupd_req (const struct sdxi_amd_qos_fnupd_req *req, +u16 max_pools,u16 max_vfs,u32 max_cxts, +u16 feature_flags); +int sdxi_amd_qos_validate_tel_req (const struct sdxi_amd_qos_tel_req *req, +u16 max_pools,u16 max_vfs,u32 max_cxts, +u16 feature_flags); + +#endif /* __DMA_SDXI_AMD_QOS_H */
Signature · 1 line
2.56.1
PATCH 29/44 dmaengine: sdxi: amd: add QoS validation scaffolding
In reply to Wei HuangCreate the AMD QoS handler source with common user-buffer helpers, GUID discovery, and request validators. The added validators check bandwidth alignment, device and pool updates, function assignments and telemetry selectors.
--- drivers/dma/sdxi/amd/qos.c | 266 +++++++++++++++++++++++++++++++++++++ drivers/dma/sdxi/amd/qos.h | 4 +- 2 files changed, 268 insertions(+), 2 deletions(-) create mode 100644 drivers/dma/sdxi/amd/qos.c
drivers/dma/sdxi/amd/qos.c new file +266 -0
@@ -0,0 +1,266 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* AMD SDXI QoS vendor-command handling. +* +* Copyright (C) 2026 Advanced Micro Devices, Inc. +*/ + +#include <linux/capability.h> +#include <linux/dma-mapping.h> +#include <linux/export.h> +#include <kunit/visibility.h> +#include <linux/module.h> +#include <linux/pci.h> +#include <linux/sizes.h> +#include <linux/slab.h> +#include <linux/string.h> +#include <linux/unaligned.h> +#include <linux/uaccess.h> +#include <uapi/linux/sdxi.h> + +#include "../admin.h" +#include "../sdxi.h" +#include "../vendor.h" +#include "qos.h" + +#define SDXI_AMD_QOS_CAP_BYTES 48U +#define SDXI_AMD_QOS_TEL_FIXED_BYTES 48U +#define SDXI_AMD_QOS_TEL_HDR_BYTES 48U +#define SDXI_AMD_QOS_POOL_REPORT_ENTRY_BYTES 132U +#define SDXI_AMD_QOS_MAX_TEL_BYTES SZ_1M + +struct sdxi_amd_qos_cap_info { +u16 feature_flags; +u16 max_pools; +u32 device_maxbw_cap; +u32 granularity_bw; +}; + +struct sdxi_amd_qos_dev_info { +u32 device_maxbw; +u32 total_allocated_bw; +}; + +struct sdxi_amd_qos_pool_info { +u32 pool_minbw; +u32 pool_maxbw; +u16 assigned_functions; +u16 assigned_contexts; +}; + +/* +* SDXI DSC_DISC uses RFC4122-like GUIDs, but with time_low/time_mid/time_hi +* stored in little-endian order. +*/ +static const u8 sdxi_amd_guid_qos[16 ] = { +0x0b ,0x61 ,0xb7 ,0xf5 ,0xc6 ,0x0d ,0x03 ,0x4c , +0xab ,0x79 ,0x65 ,0xf1 ,0xf4 ,0xef ,0xcf ,0x4c , +}; + +static int +sdxi_amd_qos_copy_input (const struct sdxi_admin_vendor_args *args, +void *dst,size_t size) +{ +void __user *ubuf; + +if (!size) { +if (args->in_size || args->in_uptr) +return -EINVAL ; +return 0 ; + } + +if (args->in_size != size || !args->in_uptr) +return -EINVAL ; + + ubuf =u64_to_user_ptr (args->in_uptr); +if (!access_ok (ubuf, size)) +return -EFAULT ; +if (copy_from_user (dst, ubuf, size)) +return -EFAULT ; +if (args->op ==SDXI_AMD_QOS_ADMIN_OP_FNUPD && + size ==sizeof (struct sdxi_amd_qos_fnupd_req )) { +struct sdxi_amd_qos_fnupd_req *req = dst; + +if (!(req->flags &SDXI_AMD_QOS_TARGET_F_VF )) + req->vf_num =0 ; +if (!(req->flags &SDXI_AMD_QOS_TARGET_F_CXT )) { + req->cxt_start =0 ; + req->cxt_end =0 ; + } + } + +return 0 ; +} + +static int +sdxi_amd_qos_require_no_output (struct sdxi_admin_vendor_args *args) +{ +if (args->out_size || args->out_uptr) +return -EINVAL ; + + args->out_size =0 ; + +return 0 ; +} + +static int +sdxi_amd_qos_prepare_output (struct sdxi_admin_vendor_args *args, +size_t required,void __user **ubuf) +{ +u32 available = args->out_size; + +if (required >U32_MAX ) +return -EOVERFLOW ; + + args->out_size = (u32 )required; +if (available < required) +return -ENOSPC ; +if (!args->out_uptr) +return -EINVAL ; + + *ubuf =u64_to_user_ptr (args->out_uptr); +if (!access_ok (*ubuf, required)) +return -EFAULT ; + +return 0 ; +} + +static int sdxi_amd_qos_admin_ready (const struct sdxi_cxt *adm) +{ +if (!adm || !adm->sq || !adm->ring_state || !adm->sq->cxt_sts) +return -ENODEV ; +if (sdxi_cxt_sts_state (adm->sq->cxt_sts) !=CXTV_RUN ) +return -EIO ; + +return 0 ; +} + +u64 sdxi_amd_qos_query_selector (u16 cxt_num,u8 query_type) +{ +return FIELD_PREP (GENMASK_ULL (15 ,0 ), cxt_num) | +FIELD_PREP (GENMASK_ULL (18 ,16 ), query_type); +} +EXPORT_SYMBOL_IF_KUNIT (sdxi_amd_qos_query_selector); + +u32 sdxi_amd_qos_align_bw (u32 bw,u32 granularity) +{ +if (!granularity) +return bw; + +return (bw / granularity) * granularity; +} +EXPORT_SYMBOL_IF_KUNIT (sdxi_amd_qos_align_bw); + +int sdxi_amd_qos_validate_devupd_req (u32 device_maxbw,u32 device_maxbw_cap, +u32 total_allocated_bw,u32 granularity_bw) +{ +if (device_maxbw > device_maxbw_cap) +return -EINVAL ; + +if (sdxi_amd_qos_align_bw (device_maxbw, granularity_bw) < + total_allocated_bw) +return -EINVAL ; + +return 0 ; +} +EXPORT_SYMBOL_IF_KUNIT (sdxi_amd_qos_validate_devupd_req); + +int sdxi_amd_qos_validate_poolupd_req (const struct sdxi_amd_qos_poolupd_req *req, +u16 max_pools,u32 granularity_bw) +{ +u32 min_bw; +u32 max_bw; + +if (!req || !max_pools) +return -EINVAL ; +if (req->rsvd0) +return -EINVAL ; +if (req->pool_num >= max_pools) +return -EINVAL ; +if (req->pool_operation >SDXI_AMD_QOS_POOL_OP_DESTROY ) +return -EINVAL ; +if ((req->pool_operation ==SDXI_AMD_QOS_POOL_OP_CREATE || + req->pool_operation ==SDXI_AMD_QOS_POOL_OP_DESTROY ) && + !req->pool_num) +return -EINVAL ; +if (req->pool_operation ==SDXI_AMD_QOS_POOL_OP_DESTROY ) +return 0 ; +if (req->pool_minbw > req->pool_maxbw) +return -EINVAL ; + + min_bw =sdxi_amd_qos_align_bw (req->pool_minbw, granularity_bw); + max_bw =sdxi_amd_qos_align_bw (req->pool_maxbw, granularity_bw); +if (min_bw > max_bw) +return -EINVAL ; + +return 0 ; +} +EXPORT_SYMBOL_IF_KUNIT (sdxi_amd_qos_validate_poolupd_req); + +int sdxi_amd_qos_validate_fnupd_req (const struct sdxi_amd_qos_fnupd_req *req, +u16 max_pools,u16 max_vfs,u32 max_cxts, +u16 feature_flags) +{ +if (!req || !max_pools) +return -EINVAL ; +if (req->rsvd0) +return -EINVAL ; +if (req->pool_num >= max_pools) +return -EINVAL ; +if (req->flags & ~(SDXI_AMD_QOS_TARGET_F_CXT | +SDXI_AMD_QOS_TARGET_F_VF )) +return -EINVAL ; +if (req->flags &SDXI_AMD_QOS_TARGET_F_VF ) { +if (!max_vfs || req->vf_num >= max_vfs) +return -EINVAL ; + } + +if (!(req->flags &SDXI_AMD_QOS_TARGET_F_CXT )) +return 0 ; + + (void )feature_flags; +if (req->cxt_start > req->cxt_end) +return -EINVAL ; +if (req->cxt_start >= max_cxts || req->cxt_end >= max_cxts) +return -EINVAL ; + +return 0 ; +} +EXPORT_SYMBOL_IF_KUNIT (sdxi_amd_qos_validate_fnupd_req); + +int sdxi_amd_qos_validate_tel_req (const struct sdxi_amd_qos_tel_req *req, +u16 max_pools,u16 max_vfs,u32 max_cxts, +u16 feature_flags) +{ +if (!req) +return -EINVAL ; +if (req->rsvd0[0 ] || req->rsvd0[1 ] || req->rsvd0[2 ]) +return -EINVAL ; + +switch (req->query_type) { +case SDXI_AMD_QOS_TEL_QTYPE_DEVICE : +case SDXI_AMD_QOS_TEL_QTYPE_ACTIVE_POOLS : +return 0 ; +case SDXI_AMD_QOS_TEL_QTYPE_POOL_CONFIG : +case SDXI_AMD_QOS_TEL_QTYPE_POOL_REPORT : +case SDXI_AMD_QOS_TEL_QTYPE_POOL_VARIANCE : +if (!max_pools || req->pool_num >= max_pools) +return -EINVAL ; +return 0 ; +case SDXI_AMD_QOS_TEL_QTYPE_POOL_ASSIGN : +if (req->flags &SDXI_AMD_QOS_TARGET_F_VF ) { +if (!max_vfs || req->vf_num >= max_vfs) +return -EINVAL ; + } +if (!(req->flags &SDXI_AMD_QOS_TARGET_F_CXT )) +return 0 ; +if (!(feature_flags &SDXI_AMD_QOS_FEATURE_FLEXIBLE_POOL_SCOPE )) +return -EOPNOTSUPP ; +if (req->cxt_num >= max_cxts) +return -EINVAL ; +return 0 ; +default : +return -EINVAL ; + } +} +EXPORT_SYMBOL_IF_KUNIT (sdxi_amd_qos_validate_tel_req);
drivers/dma/sdxi/amd/qos.h +2 -2
@@ -81,8 +81,8 @@ struct sdxi_amd_qos_tel_req {u64 sdxi_amd_qos_query_selector (u16 cxt_num,u8 query_type);u32 sdxi_amd_qos_align_bw (u32 bw,u32 granularity); -int sdxi_amd_qos_validate_devupd_req (u32 device_maxbw,u32 total_allocated_bw, -u32 granularity_bw); +int sdxi_amd_qos_validate_devupd_req (u32 device_maxbw,u32 device_maxbw_cap, +u32 total_allocated_bw,u32 granularity_bw);int sdxi_amd_qos_validate_poolupd_req (const struct sdxi_amd_qos_poolupd_req *req,u16 max_pools,u32 granularity_bw); int sdxi_amd_qos_validate_fnupd_req(const struct sdxi_amd_qos_fnupd_req *req,
Signature · 1 line
2.56.1
PATCH 30/44 dmaengine: sdxi: amd: build QoS admin descriptors
In reply to Wei HuangAdd AMD QoS descriptor setup, capability reads, telemetry reads and helper queries that will be used by execution code paths introduced later.
--- drivers/dma/sdxi/amd/qos.c | 326 +++++++++++++++++++++++++++++++++++++ 1 file changed, 326 insertions(+)
drivers/dma/sdxi/amd/qos.c +326 -0
@@ -264,3 +264,329 @@ int sdxi_amd_qos_validate_tel_req(const struct sdxi_amd_qos_tel_req *req, } }EXPORT_SYMBOL_IF_KUNIT (sdxi_amd_qos_validate_tel_req); + +static void sdxi_amd_qos_desc_init (struct sdxi_desc *desc,u16 opcode_type, +u8 subtype) +{ +memset (desc,0 ,sizeof (*desc)); + desc->opcode =cpu_to_le32 (FIELD_PREP (SDXI_DSC_SUBTYPE , subtype) | +FIELD_PREP (SDXI_DSC_TYPE , opcode_type)); + desc->csb_ptr =cpu_to_le64 (FIELD_PREP (SDXI_DSC_NP ,1 )); +} + +static int sdxi_amd_qos_target_scope (u16 pool_num,u16 flags,u16 vf_num, +u32 *target_scope) +{ +u32 value; + +if (pool_num >0x0fff ) +return -EINVAL ; +if (flags & ~(SDXI_AMD_QOS_TARGET_F_CXT |SDXI_AMD_QOS_TARGET_F_VF )) +return -EINVAL ; +if (!(flags &SDXI_AMD_QOS_TARGET_F_VF ) && vf_num) +return -EINVAL ; + + value = pool_num; +if (flags &SDXI_AMD_QOS_TARGET_F_CXT ) + value |=BIT (12 ); +if (flags &SDXI_AMD_QOS_TARGET_F_VF ) + value |=BIT (15 ); + value |= (u32 )vf_num <<16 ; + + *target_scope = value; +return 0 ; +} + +static u16 sdxi_amd_qos_max_vfs (struct sdxi_dev *sdxi) +{ +struct pci_dev *pdev; +unsigned int totalvfs; + +if (!sdxi ||sdxi_fn_reports_vf (sdxi)) +return 0 ; + + pdev =to_pci_dev (sdxi_to_dev (sdxi)); + totalvfs =pci_sriov_get_totalvfs (pdev); +if (totalvfs >U16_MAX ) +return U16_MAX ; + +return (u16 )totalvfs; +} + +static bool sdxi_amd_qos_pool_active (const u8 *bitmap,u16 pool_num) +{ +if (!bitmap) +return false; + +return bitmap[pool_num /8 ] &BIT (pool_num %8 ); +} + +static int sdxi_amd_qos_get_cap_info (struct sdxi_dev *sdxi, +struct sdxi_cxt *adm, +u16 opcode_type, +unsigned int timeout_ms, +struct sdxi_amd_qos_cap_info *cap) +{ +struct sdxi_desc desc = {}; +dma_addr_t dma; +u8 *buf; +int err; + +if (!cap) +return -EINVAL ; + + err =sdxi_amd_qos_admin_ready (adm); +if (err) +return err; + + buf =dma_alloc_coherent (sdxi_to_dev (sdxi),SDXI_AMD_QOS_CAP_BYTES , &dma, +GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + +memset (buf,0 ,SDXI_AMD_QOS_CAP_BYTES ); + +if (!IS_ALIGNED (dma,SZ_4K )) { + err = -EIO ; + goto out_free; + } + +sdxi_amd_qos_desc_init (&desc, opcode_type, +SDXI_AMD_QOS_DSC_SUBTYPE_CAP ); + +/* capability_ptr is descriptor bits[127:64], starting at byte offset 8. */ +put_unaligned_le64 (dma, &desc.generic.operation[4 ]); + + err =sdxi_adm_submit_desc (adm, &desc, timeout_ms,NULL ); +if (err) + goto out_free; + +dma_rmb (); + cap->feature_flags =get_unaligned_le16 (buf +2 ); + cap->device_maxbw_cap =get_unaligned_le32 (buf +4 ); + cap->max_pools = (u16)(get_unaligned_le32 (buf +8 ) &0x0fff ); + cap->granularity_bw =get_unaligned_le32 (buf +12 ); +if (!cap->max_pools) + err = -EIO ; + +out_free: +dma_free_coherent (sdxi_to_dev (sdxi),SDXI_AMD_QOS_CAP_BYTES , buf, dma); +return err; +} + +static int sdxi_amd_qos_get_dev_info (struct sdxi_dev *sdxi, +struct sdxi_cxt *adm, +u16 opcode_type, +unsigned int timeout_ms, +struct sdxi_amd_qos_dev_info *info) +{ +struct sdxi_desc desc = {}; +dma_addr_t dma; +u8 *buf; +int err; + +if (!info) +return -EINVAL ; + + err =sdxi_amd_qos_admin_ready (adm); +if (err) +return err; + + buf =dma_alloc_coherent (sdxi_to_dev (sdxi),SDXI_AMD_QOS_TEL_FIXED_BYTES , + &dma,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + +memset (buf,0 ,SDXI_AMD_QOS_TEL_FIXED_BYTES ); + +if (!IS_ALIGNED (dma,SZ_4K )) { + err = -EIO ; + goto out_free_dev; + } + +sdxi_amd_qos_desc_init (&desc, opcode_type, +SDXI_AMD_QOS_DSC_SUBTYPE_TEL ); +put_unaligned_le64 (sdxi_amd_qos_query_selector (0 , +SDXI_AMD_QOS_TEL_QTYPE_DEVICE ), + &desc.generic.operation[4 ]); +put_unaligned_le64 (dma, &desc.generic.operation[12 ]); + + err =sdxi_adm_submit_desc (adm, &desc, timeout_ms,NULL ); +if (err) + goto out_free_dev; + +dma_rmb (); + info->device_maxbw =get_unaligned_le32 (buf +4 ); + info->total_allocated_bw =get_unaligned_le32 (buf +12 ); + +out_free_dev: +dma_free_coherent (sdxi_to_dev (sdxi),SDXI_AMD_QOS_TEL_FIXED_BYTES , + buf, dma); +return err; +} + +static int sdxi_amd_qos_get_pool_info (struct sdxi_dev *sdxi, +struct sdxi_cxt *adm, +u16 opcode_type,u16 pool_num, +unsigned int timeout_ms, +struct sdxi_amd_qos_pool_info *info) +{ +struct sdxi_desc desc = {}; +dma_addr_t dma; +u8 *buf; +u32 target_scope; +int err; + +if (!info) +return -EINVAL ; + + err =sdxi_amd_qos_admin_ready (adm); +if (err) +return err; + + buf =dma_alloc_coherent (sdxi_to_dev (sdxi),SDXI_AMD_QOS_TEL_FIXED_BYTES , + &dma,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + +memset (buf,0 ,SDXI_AMD_QOS_TEL_FIXED_BYTES ); + +if (!IS_ALIGNED (dma,SZ_4K )) { + err = -EIO ; + goto out_free_pool; + } + +sdxi_amd_qos_desc_init (&desc, opcode_type, +SDXI_AMD_QOS_DSC_SUBTYPE_TEL ); + target_scope =FIELD_PREP (GENMASK (11 ,0 ), pool_num); +put_unaligned_le32 (target_scope, &desc.generic.operation[0 ]); +put_unaligned_le64 (sdxi_amd_qos_query_selector (0 , +SDXI_AMD_QOS_TEL_QTYPE_POOL_CONFIG ), + &desc.generic.operation[4 ]); +put_unaligned_le64 (dma, &desc.generic.operation[12 ]); + + err =sdxi_adm_submit_desc (adm, &desc, timeout_ms,NULL ); +if (err) + goto out_free_pool; + +dma_rmb (); + info->pool_minbw =get_unaligned_le32 (buf +8 ); + info->pool_maxbw =get_unaligned_le32 (buf +12 ); + info->assigned_functions =get_unaligned_le16 (buf +16 ); + info->assigned_contexts =get_unaligned_le16 (buf +18 ); + +out_free_pool: +dma_free_coherent (sdxi_to_dev (sdxi),SDXI_AMD_QOS_TEL_FIXED_BYTES , + buf, dma); +return err; +} + +static int sdxi_amd_qos_get_active_pools (struct sdxi_dev *sdxi, +struct sdxi_cxt *adm, +u16 opcode_type, +unsigned int timeout_ms, +u16 max_pools,u8 *bitmap) +{ +struct sdxi_desc desc = {}; +dma_addr_t dma; +u8 *buf; +size_t bytes; +int err; + +if (!bitmap || !max_pools) +return -EINVAL ; + + err =sdxi_amd_qos_admin_ready (adm); +if (err) +return err; + + bytes = (size_t )(max_pools +7U ) /8U ; + buf =dma_alloc_coherent (sdxi_to_dev (sdxi),SDXI_AMD_QOS_TEL_HDR_BYTES + bytes, + &dma,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + +memset (buf,0 ,SDXI_AMD_QOS_TEL_HDR_BYTES + bytes); + +if (!IS_ALIGNED (dma,SZ_4K )) { + err = -EIO ; + goto out_free_active; + } + +sdxi_amd_qos_desc_init (&desc, opcode_type, +SDXI_AMD_QOS_DSC_SUBTYPE_TEL ); +put_unaligned_le64 (sdxi_amd_qos_query_selector (0 , +SDXI_AMD_QOS_TEL_QTYPE_ACTIVE_POOLS ), + &desc.generic.operation[4 ]); +put_unaligned_le64 (dma, &desc.generic.operation[12 ]); + + err =sdxi_adm_submit_desc (adm, &desc, timeout_ms,NULL ); +if (err) + goto out_free_active; + +dma_rmb (); +memcpy (bitmap, buf +SDXI_AMD_QOS_TEL_HDR_BYTES , bytes); + +out_free_active: +dma_free_coherent (sdxi_to_dev (sdxi),SDXI_AMD_QOS_TEL_HDR_BYTES + bytes, + buf, dma); +return err; +} + +static int sdxi_amd_qos_get_assigned_functions (struct sdxi_dev *sdxi, +struct sdxi_cxt *adm, +u16 opcode_type,u16 pool_num, +unsigned int timeout_ms, +u16 *assigned_functions) +{ +struct sdxi_desc desc = {}; +dma_addr_t dma; +u8 *buf; +u32 counts; +u32 target_scope; +int err; + +if (!assigned_functions) +return -EINVAL ; + + err =sdxi_amd_qos_admin_ready (adm); +if (err) +return err; + + buf =dma_alloc_coherent (sdxi_to_dev (sdxi),SDXI_AMD_QOS_TEL_FIXED_BYTES , + &dma,GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + +memset (buf,0 ,SDXI_AMD_QOS_TEL_FIXED_BYTES ); + +if (!IS_ALIGNED (dma,SZ_4K )) { + err = -EIO ; + goto out_free; + } + +sdxi_amd_qos_desc_init (&desc, opcode_type, +SDXI_AMD_QOS_DSC_SUBTYPE_TEL ); + + target_scope =FIELD_PREP (GENMASK (11 ,0 ), pool_num); +put_unaligned_le32 (target_scope, &desc.generic.operation[0 ]); +put_unaligned_le64 (sdxi_amd_qos_query_selector (0 , +SDXI_AMD_QOS_TEL_QTYPE_POOL_CONFIG ), + &desc.generic.operation[4 ]); + +/* telemetry_ptr is descriptor bits[191:128], starting at byte offset 16. */ +put_unaligned_le64 (dma, &desc.generic.operation[12 ]); + + err =sdxi_adm_submit_desc (adm, &desc, timeout_ms,NULL ); +if (err) + goto out_free; + +dma_rmb (); + counts =get_unaligned_le32 (buf +16 ); + *assigned_functions = (u16)(counts &0xffff ); + +out_free: +dma_free_coherent (sdxi_to_dev (sdxi),SDXI_AMD_QOS_TEL_FIXED_BYTES , + buf, dma); +return err; +}
Signature · 1 line
2.56.1
PATCH 31/44 dmaengine: sdxi: amd: prevalidate QoS operations
In reply to Wei HuangAdd software prevalidation for QoS pool updates, function assignments and telemetry requests so predictable admin faults are rejected early. These helpers will be used by code introduced later.
--- drivers/dma/sdxi/amd/qos.c | 174 +++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+)
drivers/dma/sdxi/amd/qos.c +174 -0
@@ -590,3 +590,177 @@ static int sdxi_amd_qos_get_assigned_functions(struct sdxi_dev *sdxi, buf, dma);return err; } + +static int sdxi_amd_qos_prevalidate_poolupd (struct sdxi_dev *sdxi, +struct sdxi_cxt *adm, +u16 opcode_type, +unsigned int timeout_ms, +const struct sdxi_amd_qos_cap_info *cap, +const struct sdxi_amd_qos_poolupd_req *req) +{ +struct sdxi_amd_qos_dev_info dev_info; +struct sdxi_amd_qos_pool_info pool_info; +u32 new_minbw; +u32 total_minbw; +size_t bytes; +u8 *bitmap; +bool pool_known; +int err; + + err =sdxi_amd_qos_validate_poolupd_req (req, cap->max_pools, + cap->granularity_bw); +if (err) +return err; + + err =sdxi_amd_qos_get_dev_info (sdxi, adm, opcode_type, timeout_ms, + &dev_info); +if (err) +return err; + + bytes = (size_t )(cap->max_pools +7U ) /8U ; + bitmap =kcalloc (bytes,sizeof (*bitmap),GFP_KERNEL ); +if (!bitmap) +return -ENOMEM ; + + err =sdxi_amd_qos_get_active_pools (sdxi, adm, opcode_type, + timeout_ms, cap->max_pools, + bitmap); +if (err) { +kfree (bitmap); +return err; + } + + pool_known = !req->pool_num || +sdxi_amd_qos_pool_active (bitmap, req->pool_num); + +switch (req->pool_operation) { +case SDXI_AMD_QOS_POOL_OP_CREATE : +if (sdxi_amd_qos_pool_active (bitmap, req->pool_num)) + err = -EEXIST ; +kfree (bitmap); +if (err) +return err; + + new_minbw =sdxi_amd_qos_align_bw (req->pool_minbw, + cap->granularity_bw); +if (dev_info.total_allocated_bw > dev_info.device_maxbw) +return -EIO ; +if (new_minbw > dev_info.device_maxbw - dev_info.total_allocated_bw) +return -EINVAL ; +return 0 ; +case SDXI_AMD_QOS_POOL_OP_UPDATE : +kfree (bitmap); +if (!pool_known) +return -ENOENT ; + err =sdxi_amd_qos_get_pool_info (sdxi, adm, opcode_type, + req->pool_num, timeout_ms, + &pool_info); +if (err) +return err; + +if (pool_info.pool_minbw > dev_info.total_allocated_bw) +return -EIO ; +if (dev_info.total_allocated_bw > dev_info.device_maxbw) +return -EIO ; + + new_minbw =sdxi_amd_qos_align_bw (req->pool_minbw, + cap->granularity_bw); + total_minbw = dev_info.total_allocated_bw - pool_info.pool_minbw; +if (new_minbw > dev_info.device_maxbw - total_minbw) +return -EINVAL ; +return 0 ; +case SDXI_AMD_QOS_POOL_OP_DESTROY : +kfree (bitmap); +if (!pool_known) +return -ENOENT ; + err =sdxi_amd_qos_get_pool_info (sdxi, adm, opcode_type, + req->pool_num, timeout_ms, + &pool_info); +if (err) +return err; + +return 0 ; +default : +kfree (bitmap); +return -EINVAL ; + } +} + +static int sdxi_amd_qos_prevalidate_fnupd (struct sdxi_dev *sdxi, +struct sdxi_cxt *adm, +u16 opcode_type, +unsigned int timeout_ms, +const struct sdxi_amd_qos_cap_info *cap, +const struct sdxi_amd_qos_fnupd_req *req) +{ +size_t bytes; +u8 *bitmap; +int err; + + err =sdxi_amd_qos_validate_fnupd_req (req, cap->max_pools, +sdxi_amd_qos_max_vfs (sdxi), + sdxi->max_cxts, + cap->feature_flags); +if (err) +return err; + +if (!req->pool_num) +return 0 ; + + bytes = (size_t )(cap->max_pools +7U ) /8U ; + bitmap =kcalloc (bytes,sizeof (*bitmap),GFP_KERNEL ); +if (!bitmap) +return -ENOMEM ; + + err =sdxi_amd_qos_get_active_pools (sdxi, adm, opcode_type, timeout_ms, + cap->max_pools, bitmap); +if (!err && !sdxi_amd_qos_pool_active (bitmap, req->pool_num)) + err = -ENOENT ; +kfree (bitmap); +if (err) +return err; + +return 0 ; +} + +static int sdxi_amd_qos_prevalidate_tel (struct sdxi_dev *sdxi, +struct sdxi_cxt *adm, +u16 opcode_type, +unsigned int timeout_ms, +const struct sdxi_amd_qos_cap_info *cap, +const struct sdxi_amd_qos_tel_req *req) +{ +size_t bytes; +u8 *bitmap; +int err; + + err =sdxi_amd_qos_validate_tel_req (req, cap->max_pools, +sdxi_amd_qos_max_vfs (sdxi), + sdxi->max_cxts, + cap->feature_flags); +if (err) +return err; + +switch (req->query_type) { +case SDXI_AMD_QOS_TEL_QTYPE_POOL_CONFIG : +case SDXI_AMD_QOS_TEL_QTYPE_POOL_REPORT : +case SDXI_AMD_QOS_TEL_QTYPE_POOL_VARIANCE : +if (!req->pool_num) +return 0 ; + + bytes = (size_t )(cap->max_pools +7U ) /8U ; + bitmap =kcalloc (bytes,sizeof (*bitmap),GFP_KERNEL ); +if (!bitmap) +return -ENOMEM ; + + err =sdxi_amd_qos_get_active_pools (sdxi, adm, opcode_type, + timeout_ms, cap->max_pools, + bitmap); +if (!err && !sdxi_amd_qos_pool_active (bitmap, req->pool_num)) + err = -ENOENT ; +kfree (bitmap); +return err; +default : +return 0 ; + } +}
Signature · 1 line
2.56.1
PATCH 32/44 dmaengine: sdxi: amd: execute QoS vendor operations
In reply to Wei HuangAdd execution code for AMD QoS capability, device update, pool update, function update and telemetry operations.
--- drivers/dma/sdxi/amd/qos.c | 321 ++++++++++++++++++++++++++++++++++++- 1 file changed, 320 insertions(+), 1 deletion(-)
drivers/dma/sdxi/amd/qos.c +320 -1
@@ -27,7 +27,13 @@#define SDXI_AMD_QOS_TEL_FIXED_BYTES 48U#define SDXI_AMD_QOS_TEL_HDR_BYTES 48U#define SDXI_AMD_QOS_POOL_REPORT_ENTRY_BYTES 132U -#define SDXI_AMD_QOS_MAX_TEL_BYTES SZ_1M + +/* One PF entry plus all 10-bit VF-number entries. */ +#define SDXI_AMD_QOS_POOL_REPORT_MAX_FUNCTIONS 1025U +#define SDXI_AMD_QOS_POOL_REPORT_MAX_BYTES \ + (SDXI_AMD_QOS_TEL_HDR_BYTES + \ + SDXI_AMD_QOS_POOL_REPORT_MAX_FUNCTIONS * \ + SDXI_AMD_QOS_POOL_REPORT_ENTRY_BYTES)struct sdxi_amd_qos_cap_info {u16 feature_flags;
@@ -764,3 +770,316 @@ static int sdxi_amd_qos_prevalidate_tel(struct sdxi_dev *sdxi,return 0 ; } } + +static size_t sdxi_amd_qos_tel_bytes_active_pools (u16 max_pools) +{ +return SDXI_AMD_QOS_TEL_HDR_BYTES + (size_t )(max_pools +7U ) /8U ; +} + +static int sdxi_amd_qos_pool_report_bytes (u16 assigned_functions, +size_t *bytes) +{ +if (assigned_functions >SDXI_AMD_QOS_POOL_REPORT_MAX_FUNCTIONS ) +return -E2BIG ; + + *bytes =SDXI_AMD_QOS_TEL_HDR_BYTES + + (size_t )assigned_functions * +SDXI_AMD_QOS_POOL_REPORT_ENTRY_BYTES ; +return 0 ; +} + +static int sdxi_amd_qos_exec (struct sdxi_dev *sdxi,u16 opcode_type, +struct sdxi_admin_vendor_args *args, +unsigned int timeout_ms) +{ +struct sdxi_cxt *adm = sdxi->admin_cxt; +struct sdxi_amd_qos_cap_info cap; +struct sdxi_desc desc; +void *buf =NULL ; +dma_addr_t buf_dma =0 ; +size_t dma_size =0 ; +size_t required =0 ; +void __user *ubuf =NULL ; +u32 output_available = args->out_size; +bool pool_report = false; +int err; + + err =sdxi_amd_qos_admin_ready (adm); +if (err) +return err; + +switch (args->op) { +case SDXI_AMD_QOS_ADMIN_OP_CAP : + err =sdxi_amd_qos_copy_input (args,NULL ,0 ); +if (err) +return err; + + required =SDXI_AMD_QOS_CAP_BYTES ; + err =sdxi_amd_qos_prepare_output (args, required, &ubuf); +if (err) +return err; + +sdxi_amd_qos_desc_init (&desc, opcode_type, +SDXI_AMD_QOS_DSC_SUBTYPE_CAP ); +break ; +case SDXI_AMD_QOS_ADMIN_OP_DEVUPD : { +struct sdxi_amd_qos_devupd_req req; +struct sdxi_amd_qos_dev_info info; + + err =sdxi_amd_qos_copy_input (args, &req,sizeof (req)); +if (err) +return err; + err =sdxi_amd_qos_get_cap_info (sdxi, adm, opcode_type, + timeout_ms, &cap); +if (err) +return err; + err =sdxi_amd_qos_get_dev_info (sdxi, adm, opcode_type, + timeout_ms, &info); +if (err) +return err; + err =sdxi_amd_qos_validate_devupd_req (req.device_maxbw, + cap.device_maxbw_cap, + info.total_allocated_bw, + cap.granularity_bw); +if (err) +return err; + + err =sdxi_amd_qos_require_no_output (args); +if (err) +return err; + +sdxi_amd_qos_desc_init (&desc, opcode_type, +SDXI_AMD_QOS_DSC_SUBTYPE_DEVUPD ); +put_unaligned_le32 (req.device_maxbw, &desc.generic.operation[4 ]); + +return sdxi_adm_submit_desc (adm, &desc, timeout_ms, + &args->cst_flags); + } +case SDXI_AMD_QOS_ADMIN_OP_POOLUPD : { +struct sdxi_amd_qos_poolupd_req req; +u32 pool_ctl; + + err =sdxi_amd_qos_copy_input (args, &req,sizeof (req)); +if (err) +return err; + err =sdxi_amd_qos_get_cap_info (sdxi, adm, opcode_type, + timeout_ms, &cap); +if (err) +return err; + err =sdxi_amd_qos_prevalidate_poolupd (sdxi, adm, opcode_type, + timeout_ms, &cap, &req); +if (err) +return err; + + err =sdxi_amd_qos_require_no_output (args); +if (err) +return err; + + pool_ctl =FIELD_PREP (GENMASK (11 ,0 ), req.pool_num) | +FIELD_PREP (GENMASK (13 ,12 ), req.pool_operation); + +sdxi_amd_qos_desc_init (&desc, opcode_type, +SDXI_AMD_QOS_DSC_SUBTYPE_POOLUPD ); +put_unaligned_le32 (pool_ctl, &desc.generic.operation[0 ]); +put_unaligned_le32 (req.pool_maxbw, &desc.generic.operation[4 ]); +put_unaligned_le32 (req.pool_minbw, &desc.generic.operation[8 ]); + +return sdxi_adm_submit_desc (adm, &desc, timeout_ms, + &args->cst_flags); + } +case SDXI_AMD_QOS_ADMIN_OP_FNUPD : { +struct sdxi_amd_qos_fnupd_req req; +u32 target_scope; +u32 cxt_range; + + err =sdxi_amd_qos_copy_input (args, &req,sizeof (req)); +if (err) +return err; + err =sdxi_amd_qos_get_cap_info (sdxi, adm, opcode_type, + timeout_ms, &cap); +if (err) +return err; + err =sdxi_amd_qos_prevalidate_fnupd (sdxi, adm, opcode_type, + timeout_ms, &cap, &req); +if (err) +return err; + + err =sdxi_amd_qos_target_scope (req.pool_num, req.flags, + req.vf_num, &target_scope); +if (err) +return err; + + err =sdxi_amd_qos_require_no_output (args); +if (err) +return err; + + cxt_range =FIELD_PREP (GENMASK (15 ,0 ), req.cxt_start) | + ((u32 )req.cxt_end <<16 ); + +sdxi_amd_qos_desc_init (&desc, opcode_type, +SDXI_AMD_QOS_DSC_SUBTYPE_FNUPD ); +put_unaligned_le32 (target_scope, &desc.generic.operation[0 ]); +put_unaligned_le32 (cxt_range, &desc.generic.operation[4 ]); + +return sdxi_adm_submit_desc (adm, &desc, timeout_ms, + &args->cst_flags); + } +case SDXI_AMD_QOS_ADMIN_OP_TEL : { +struct sdxi_amd_qos_tel_req req; +u32 target_scope; +u64 query_selector; +u16 assigned_functions; + + err =sdxi_amd_qos_copy_input (args, &req,sizeof (req)); +if (err) +return err; + err =sdxi_amd_qos_get_cap_info (sdxi, adm, opcode_type, + timeout_ms, &cap); +if (err) +return err; + err =sdxi_amd_qos_prevalidate_tel (sdxi, adm, opcode_type, + timeout_ms, &cap, &req); +if (err) +return err; + +switch (req.query_type) { +case SDXI_AMD_QOS_TEL_QTYPE_DEVICE : + target_scope =0 ; + query_selector =sdxi_amd_qos_query_selector (0 , + req.query_type); + required =SDXI_AMD_QOS_TEL_FIXED_BYTES ; +break ; +case SDXI_AMD_QOS_TEL_QTYPE_POOL_CONFIG : + target_scope =FIELD_PREP (GENMASK (11 ,0 ), + req.pool_num); + query_selector =sdxi_amd_qos_query_selector (0 , + req.query_type); + required =SDXI_AMD_QOS_TEL_FIXED_BYTES ; +break ; +case SDXI_AMD_QOS_TEL_QTYPE_POOL_ASSIGN : + err =sdxi_amd_qos_target_scope (0 , req.flags, + req.vf_num, + &target_scope); +if (err) +return err; +if (!(req.flags &SDXI_AMD_QOS_TARGET_F_CXT )) + req.cxt_num =0 ; + query_selector =sdxi_amd_qos_query_selector (req.cxt_num, + req.query_type); + required =SDXI_AMD_QOS_TEL_FIXED_BYTES ; +break ; +case SDXI_AMD_QOS_TEL_QTYPE_ACTIVE_POOLS : + target_scope =0 ; + query_selector =sdxi_amd_qos_query_selector (0 , + req.query_type); + required = +sdxi_amd_qos_tel_bytes_active_pools (cap.max_pools); +break ; +case SDXI_AMD_QOS_TEL_QTYPE_POOL_REPORT : + target_scope =FIELD_PREP (GENMASK (11 ,0 ), + req.pool_num); + query_selector =sdxi_amd_qos_query_selector (0 , + req.query_type); + err =sdxi_amd_qos_get_assigned_functions (sdxi, adm, + opcode_type, + req.pool_num, + timeout_ms, + &assigned_functions); +if (err) +return err; + + err =sdxi_amd_qos_pool_report_bytes (assigned_functions, + &required); +if (err) +return err; + dma_size =SDXI_AMD_QOS_POOL_REPORT_MAX_BYTES ; + pool_report = true; +break ; +case SDXI_AMD_QOS_TEL_QTYPE_POOL_VARIANCE : + target_scope =FIELD_PREP (GENMASK (11 ,0 ), + req.pool_num); + query_selector =sdxi_amd_qos_query_selector (0 , + req.query_type); + required =SDXI_AMD_QOS_TEL_FIXED_BYTES ; +break ; +default : +return -EINVAL ; + } + + err =sdxi_amd_qos_prepare_output (args, required, &ubuf); +if (err) +return err; + +sdxi_amd_qos_desc_init (&desc, opcode_type, +SDXI_AMD_QOS_DSC_SUBTYPE_TEL ); +put_unaligned_le32 (target_scope, &desc.generic.operation[0 ]); +put_unaligned_le64 (query_selector, &desc.generic.operation[4 ]); +break ; + } +default : +return -EOPNOTSUPP ; + } + +if (!dma_size) + dma_size = required; + + buf =dma_alloc_coherent (sdxi_to_dev (sdxi), dma_size, &buf_dma, +GFP_KERNEL ); +if (!buf) +return -ENOMEM ; + +memset (buf,0 , dma_size); + +if (!IS_ALIGNED (buf_dma,SZ_4K )) { + err = -EIO ; + goto out_free_submit; + } + +switch (args->op) { +case SDXI_AMD_QOS_ADMIN_OP_CAP : +put_unaligned_le64 (buf_dma, &desc.generic.operation[4 ]); +break ; +case SDXI_AMD_QOS_ADMIN_OP_TEL : +put_unaligned_le64 (buf_dma, &desc.generic.operation[12 ]); +break ; +default : + err = -EINVAL ; + goto out_free_submit; + } + + err =sdxi_adm_submit_desc (adm, &desc, timeout_ms, &args->cst_flags); +if (err) + goto out_free_submit; + +dma_rmb (); +if (pool_report) { +size_t actual_required; +u32 data_length =get_unaligned_le32 (buf +20 ); +u16 assigned_functions =get_unaligned_le16 (buf +16 ); + + err =sdxi_amd_qos_pool_report_bytes (assigned_functions, + &actual_required); +if (err || data_length != + actual_required -SDXI_AMD_QOS_TEL_HDR_BYTES ) { + err = -EIO ; + goto out_free_submit; + } + + args->out_size = actual_required; +if (output_available < actual_required) { + err = -ENOSPC ; + goto out_free_submit; + } +if (!access_ok (ubuf, actual_required)) { + err = -EFAULT ; + goto out_free_submit; + } + required = actual_required; + } +if (copy_to_user (ubuf, buf, required)) + err = -EFAULT ; + +out_free_submit: +dma_free_coherent (sdxi_to_dev (sdxi), dma_size, buf, buf_dma); +return err; +}
Signature · 1 line
2.56.1
PATCH 33/44 dmaengine: sdxi: amd: register QoS vendor handler
In reply to Wei HuangRegister the AMD QoS GUID with the SDXI vendor framework and add the Kconfig and module build glue for the handler.
--- drivers/dma/sdxi/Kconfig | 11 +++++++ drivers/dma/sdxi/Makefile | 2 ++ drivers/dma/sdxi/amd/Makefile | 4 +++ drivers/dma/sdxi/amd/qos.c | 58 ++++++++++++++++++++++++++++++++--- 4 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 drivers/dma/sdxi/amd/Makefile
drivers/dma/sdxi/Kconfig +11 -0
@@ -41,3 +41,14 @@ config SDXI_KUNIT_TEST SDXI hardware. If unsure, say N. + +config SDXI_AMD_QOS + tristate "AMD SDXI QoS vendor control" + depends on SDXI_CORE + help + Enable AMD SDXI Quality-of-Service vendor-command handling + through SDXI_ADMIN_VENDOR. This registers the AMD QoS GUID + with the SDXI core and lets the kernel compose the QoS + descriptors on the admin context on behalf of userspace. + + If built as a module, this will be called sdxi-amd-qos.
drivers/dma/sdxi/Makefile +2 -0
@@ -20,6 +20,8 @@ sdxi-core-y := \ obj-$(CONFIG_SDXI_PCI) += sdxi-pci.o sdxi-pci-y := pci.o +obj-y += amd/ + obj-$(CONFIG_SDXI_KUNIT_TEST) += \ completion_kunit.o \ descriptor_kunit.o \
drivers/dma/sdxi/amd/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0 + +obj-$(CONFIG_SDXI_AMD_QOS) += sdxi-amd-qos.o +sdxi-amd-qos-objs := qos.o
drivers/dma/sdxi/amd/qos.c +54 -4
92 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH 34/44 dmaengine: sdxi: amd: test QoS validation with KUnit
In reply to Wei HuangAdd KUnit coverage for AMD QoS validation helpers. Note that hardware execution paths still remain covered by other functional kunit tests.
--- drivers/dma/sdxi/Kconfig | 5 + drivers/dma/sdxi/amd/Makefile | 2 + drivers/dma/sdxi/amd/qos_kunit.c | 180 +++++++++++++++++++++++++++++++ 3 files changed, 187 insertions(+) create mode 100644 drivers/dma/sdxi/amd/qos_kunit.c
drivers/dma/sdxi/Kconfig +5 -0
@@ -52,3 +52,8 @@ config SDXI_AMD_QOS descriptors on the admin context on behalf of userspace. If built as a module, this will be called sdxi-amd-qos. + +config SDXI_AMD_QOS_KUNIT_TEST + tristate + depends on SDXI_AMD_QOS + default SDXI_KUNIT_TEST
drivers/dma/sdxi/amd/Makefile +2 -0
@@ -2,3 +2,5 @@ obj-$(CONFIG_SDXI_AMD_QOS) += sdxi-amd-qos.o sdxi-amd-qos-objs := qos.o + +obj-$(CONFIG_SDXI_AMD_QOS_KUNIT_TEST) += qos_kunit.o
drivers/dma/sdxi/amd/qos_kunit.c new file +180 -0
180 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH 35/44 selftests: sdxi: add build scaffold
In reply to Wei HuangAdd the SDXI selftest directory and the initial build scaffold. Test programs are added later by the patches that introduce individual test sources.
--- tools/testing/selftests/Makefile | 1 + tools/testing/selftests/sdxi/Makefile | 5 +++++ tools/testing/selftests/sdxi/config | 2 ++ 3 files changed, 8 insertions(+) create mode 100644 tools/testing/selftests/sdxi/Makefile create mode 100644 tools/testing/selftests/sdxi/config
tools/testing/selftests/Makefile +1 -0
@@ -122,6 +122,7 @@ TARGETS += rtc TARGETS += rust TARGETS += sched_ext TARGETS += seccomp +TARGETS += sdxi TARGETS += sgx TARGETS += signal TARGETS += size
tools/testing/selftests/sdxi/Makefile new file +5 -0
@@ -0,0 +1,5 @@ +werror := -Werror +CFLAGS += -std=gnu17 -Og -Wall -Wextra $(werror) $(TOOLS_INCLUDES) $(KHDR_INCLUDES) +CPPFLAGS += -I../../../include/ -Ilib/ + +include ../lib.mk
tools/testing/selftests/sdxi/config new file +2 -0
@@ -0,0 +1,2 @@ +CONFIG_SDXI_PCI=m +CONFIG_SDXI_AMD_QOS=m
Signature · 1 line
2.56.1
PATCH 36/44 selftests: sdxi: add shared descriptor and context helpers
In reply to Wei HuangAdd shared helpers for opening SDXI devices, creating contexts and building descriptors used by the functional selftests.
--- tools/testing/selftests/sdxi/Makefile | 28 +++ tools/testing/selftests/sdxi/lib/context.c | 195 +++++++++++++++++ tools/testing/selftests/sdxi/lib/descriptor.h | 55 +++++ .../selftests/sdxi/lib/fixture-context.h | 126 +++++++++++ .../selftests/sdxi/lib/fixture-device.h | 44 ++++ tools/testing/selftests/sdxi/lib/lib.c | 206 ++++++++++++++++++ tools/testing/selftests/sdxi/lib/lib.h | 61 ++++++ 7 files changed, 715 insertions(+) create mode 100644 tools/testing/selftests/sdxi/lib/context.c create mode 100644 tools/testing/selftests/sdxi/lib/descriptor.h create mode 100644 tools/testing/selftests/sdxi/lib/fixture-context.h create mode 100644 tools/testing/selftests/sdxi/lib/fixture-device.h create mode 100644 tools/testing/selftests/sdxi/lib/lib.c create mode 100644 tools/testing/selftests/sdxi/lib/lib.h
tools/testing/selftests/sdxi/Makefile +28 -0
@@ -3,3 +3,31 @@ CFLAGS += -std=gnu17 -Og -Wall -Wextra $(werror) $(TOOLS_INCLUDES) $(KHDR_INCLUD CPPFLAGS += -I../../../include/ -Ilib/ include ../lib.mk + +HOSTAR ?= ar + +LIBDIR := $(OUTPUT)/lib +LIB := $(LIBDIR)/lib.a + +all: $(LIB) + +LIBDEPS := \ + Makefile \ + lib/descriptor.h \ + lib/fixture-context.h \ + lib/fixture-device.h \ + lib/lib.h +# Library +LIBSRC := context.c lib.c +LIBOBJ := $(LIBSRC:%.c=$(LIBDIR)/%.o) +EXTRA_CLEAN += $(LIBOBJ) $(LIB) + +$(LIB): $(LIBOBJ) + $(HOSTAR) rcs $@ $^ + +$(LIBDIR)/%.o: ./lib/%.c $(LIBDEPS) + mkdir -p $(LIBDIR) + $(CC) $< $(CFLAGS) $(CPPFLAGS) -o $@ -c + +$(TEST_GEN_PROGS): $(LIB) +$(TEST_GEN_PROGS_EXTENDED): $(LIB)
tools/testing/selftests/sdxi/lib/context.c new file +195 -0
195 lines not on this page · raw message
tools/testing/selftests/sdxi/lib/descriptor.h new file +55 -0
55 lines not on this page · raw message
tools/testing/selftests/sdxi/lib/fixture-context.h new file +126 -0
126 lines not on this page · raw message
tools/testing/selftests/sdxi/lib/fixture-device.h new file +44 -0
44 lines not on this page · raw message
tools/testing/selftests/sdxi/lib/lib.c new file +206 -0
206 lines not on this page · raw message
tools/testing/selftests/sdxi/lib/lib.h new file +61 -0
61 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH 37/44 selftests: sdxi: test context creation
In reply to Wei HuangAdd basic context creation smoke test for the SDXI selftest suite.
--- tools/testing/selftests/sdxi/.gitignore | 1 + tools/testing/selftests/sdxi/Makefile | 2 + tools/testing/selftests/sdxi/context.c | 343 ++++++++++++++++++++++++ 3 files changed, 346 insertions(+) create mode 100644 tools/testing/selftests/sdxi/.gitignore create mode 100644 tools/testing/selftests/sdxi/context.c
tools/testing/selftests/sdxi/.gitignore new file +1 -0
@@ -0,0 +1 @@ +/context
tools/testing/selftests/sdxi/Makefile +2 -0
@@ -2,6 +2,8 @@ werror := -Werror CFLAGS += -std=gnu17 -Og -Wall -Wextra $(werror) $(TOOLS_INCLUDES) $(KHDR_INCLUDES) CPPFLAGS += -I../../../include/ -Ilib/ +TEST_GEN_PROGS := context + include ../lib.mk HOSTAR ?= ar
tools/testing/selftests/sdxi/context.c new file +343 -0
343 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH 38/44 selftests: sdxi: test NOP descriptor submission
In reply to Wei HuangAdd a NOP descriptor submission and completion test to the SDXI selftest suite.
--- tools/testing/selftests/sdxi/.gitignore | 1 + tools/testing/selftests/sdxi/Makefile | 2 +- tools/testing/selftests/sdxi/nop.c | 30 +++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/sdxi/nop.c
tools/testing/selftests/sdxi/.gitignore +1 -0
@@ -1 +1,2 @@ /context +/nop
tools/testing/selftests/sdxi/Makefile +1 -1
@@ -2,7 +2,7 @@ werror := -Werror CFLAGS += -std=gnu17 -Og -Wall -Wextra $(werror) $(TOOLS_INCLUDES) $(KHDR_INCLUDES) CPPFLAGS += -I../../../include/ -Ilib/ -TEST_GEN_PROGS := context +TEST_GEN_PROGS := context nop include ../lib.mk
tools/testing/selftests/sdxi/nop.c new file +30 -0
@@ -0,0 +1,30 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* SDXI NOP descriptor selftest. +* +* Copyright (C) 2026 Advanced Micro Devices, Inc. +*/ + +#include <stdlib.h> + +#include "lib/descriptor.h" +#include "lib/fixture-context.h" +#include "lib/lib.h" +#include "../kselftest_harness.h" + +TEST_F(sdxi_context, nop) +{ +struct sdxi_desc d =sdxi_dsc_encode_nop (); + +EXPECT_EQ (sdxi_submit_sync (&self->context, &d),0 ); +} + +TEST_F(sdxi_context, nops_wrap) +{ +struct sdxi_desc d =sdxi_dsc_encode_nop (); + +for (size_t i =0 ; i < self->context.n_entries *2 ; ++i) +EXPECT_EQ (sdxi_submit_sync (&self->context, &d),0 ); +} + +TEST_HARNESS_MAIN
Signature · 1 line
2.56.1
PATCH 39/44 selftests: sdxi: test copy submission and ring wrap
In reply to Wei HuangAdd SDXI copy test for the SDXI selftest suite.
--- tools/testing/selftests/sdxi/.gitignore | 1 + tools/testing/selftests/sdxi/Makefile | 2 +- tools/testing/selftests/sdxi/copy.c | 40 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/sdxi/copy.c
tools/testing/selftests/sdxi/.gitignore +1 -0
@@ -1,2 +1,3 @@ /context /nop +/copy
tools/testing/selftests/sdxi/Makefile +1 -1
@@ -2,7 +2,7 @@ werror := -Werror CFLAGS += -std=gnu17 -Og -Wall -Wextra $(werror) $(TOOLS_INCLUDES) $(KHDR_INCLUDES) CPPFLAGS += -I../../../include/ -Ilib/ -TEST_GEN_PROGS := context nop +TEST_GEN_PROGS := context nop copy include ../lib.mk
tools/testing/selftests/sdxi/copy.c new file +40 -0
@@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* SDXI copy descriptor selftest. +* +* Copyright (C) 2026 Advanced Micro Devices, Inc. +*/ + +#include <stdlib.h> + +#include "lib/descriptor.h" +#include "lib/fixture-context.h" +#include "lib/lib.h" +#include "../kselftest_harness.h" + +TEST_F(sdxi_context, copy) +{ +const long src =0xabcdef ; +long dest =0 ; +struct sdxi_desc copy =sdxi_dsc_encode_copy (&dest, &src,sizeof (src)); + +EXPECT_EQ (sdxi_submit_sync (&self->context, ©),0 ); + +EXPECT_EQ (dest, src); +} + +TEST_F(sdxi_context, copy_wrap) +{ + +for (size_t i =0 ; i < self->context.n_entries *2 ; ++i) { +const long src =random (); +long dest =0 ; +struct sdxi_desc copy =sdxi_dsc_encode_copy (&dest, &src,sizeof (src)); + +EXPECT_EQ (sdxi_submit_sync (&self->context, ©),0 ); + +EXPECT_EQ (dest, src); + } +} + +TEST_HARNESS_MAIN
Signature · 1 line
2.56.1
PATCH 40/44 selftests: sdxi: exercise dataplane error paths
In reply to Wei HuangAdd SDXI driver error-path dataplane smoke test for SDXI selftest suite.
--- tools/testing/selftests/sdxi/.gitignore | 1 + tools/testing/selftests/sdxi/Makefile | 2 +- tools/testing/selftests/sdxi/error.c | 24 ++++++++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/sdxi/error.c
tools/testing/selftests/sdxi/.gitignore +1 -0
@@ -1,3 +1,4 @@ /context /nop /copy +/error
tools/testing/selftests/sdxi/Makefile +1 -1
@@ -2,7 +2,7 @@ werror := -Werror CFLAGS += -std=gnu17 -Og -Wall -Wextra $(werror) $(TOOLS_INCLUDES) $(KHDR_INCLUDES) CPPFLAGS += -I../../../include/ -Ilib/ -TEST_GEN_PROGS := context nop copy +TEST_GEN_PROGS := context nop copy error include ../lib.mk
tools/testing/selftests/sdxi/error.c new file +24 -0
@@ -0,0 +1,24 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* +* SDXI error path selftests. +* +* Copyright (C) 2026 Advanced Micro Devices, Inc. +*/ + +#include <stdlib.h> + +#include "lib/descriptor.h" +#include "lib/fixture-context.h" +#include "lib/lib.h" +#include "../kselftest_harness.h" + +TEST_F(sdxi_context, error) +{ +struct sdxi_desc d =sdxi_dsc_encode_rsvd (); + +// Attempt to make the error log wrap +for (size_t i =0 ; i <80 ; ++i) +EXPECT_EQ (sdxi_submit_oneshot (&d),0 ); +} + +TEST_HARNESS_MAIN
Signature · 1 line
2.56.1
PATCH 41/44 selftests: sdxi: test device ioctls
In reply to Wei HuangAdd coverage for UAPI discovery, device information and device attribute ioctls to SDXI selftest suite.
--- tools/testing/selftests/sdxi/.gitignore | 1 + tools/testing/selftests/sdxi/Makefile | 2 +- tools/testing/selftests/sdxi/device.c | 245 ++++++++++++++++++++++++ 3 files changed, 247 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/sdxi/device.c
tools/testing/selftests/sdxi/.gitignore +1 -0
@@ -2,3 +2,4 @@ /nop /copy /error +/device
tools/testing/selftests/sdxi/Makefile +1 -1
@@ -2,7 +2,7 @@ werror := -Werror CFLAGS += -std=gnu17 -Og -Wall -Wextra $(werror) $(TOOLS_INCLUDES) $(KHDR_INCLUDES) CPPFLAGS += -I../../../include/ -Ilib/ -TEST_GEN_PROGS := context nop copy error +TEST_GEN_PROGS := context nop copy error device include ../lib.mk
tools/testing/selftests/sdxi/device.c new file +245 -0
245 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH 42/44 selftests: sdxi: test vendor admin ioctls
In reply to Wei HuangAdd root-only coverage for the SDXI_ADMIN_VENDOR probe path and AMD QoS capability command. Skip the test when the device does not advertise the QoS vendor operation.
--- tools/testing/selftests/sdxi/.gitignore | 1 + tools/testing/selftests/sdxi/Makefile | 2 +- tools/testing/selftests/sdxi/admin_cmd.c | 104 +++++++++++++++++++++++ 3 files changed, 106 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/sdxi/admin_cmd.c
tools/testing/selftests/sdxi/.gitignore +1 -0
@@ -3,3 +3,4 @@ /copy /error /device +/admin_cmd
tools/testing/selftests/sdxi/Makefile +1 -1
@@ -2,7 +2,7 @@ werror := -Werror CFLAGS += -std=gnu17 -Og -Wall -Wextra $(werror) $(TOOLS_INCLUDES) $(KHDR_INCLUDES) CPPFLAGS += -I../../../include/ -Ilib/ -TEST_GEN_PROGS := context nop copy error device +TEST_GEN_PROGS := context nop copy error device admin_cmd include ../lib.mk
tools/testing/selftests/sdxi/admin_cmd.c new file +104 -0
104 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH 43/44 selftests: sdxi: test RKey ioctls
In reply to Wei HuangAdd RKey list, get and set ioctl coverage, including sizing retries and negative cases to SDXI selftest suite.
--- tools/testing/selftests/sdxi/.gitignore | 1 + tools/testing/selftests/sdxi/Makefile | 2 +- tools/testing/selftests/sdxi/rkey.c | 413 ++++++++++++++++++++++++ 3 files changed, 415 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/sdxi/rkey.c
tools/testing/selftests/sdxi/.gitignore +1 -0
@@ -4,3 +4,4 @@ /error /device /admin_cmd +/rkey
tools/testing/selftests/sdxi/Makefile +1 -1
@@ -2,7 +2,7 @@ werror := -Werror CFLAGS += -std=gnu17 -Og -Wall -Wextra $(werror) $(TOOLS_INCLUDES) $(KHDR_INCLUDES) CPPFLAGS += -I../../../include/ -Ilib/ -TEST_GEN_PROGS := context nop copy error device admin_cmd +TEST_GEN_PROGS := context nop copy error device admin_cmd rkey include ../lib.mk
tools/testing/selftests/sdxi/rkey.c new file +413 -0
413 lines not on this page · raw message
Signature · 1 line
2.56.1
PATCH 44/44 MAINTAINERS: cover SDXI UAPI, vendor files, and selftests
In reply to Wei HuangExtend the SDXI maintainer entry to cover the exported UAPI header, AMD vendor support files and the SDXI selftest tree.
--- MAINTAINERS | 3 +++ 1 file changed, 3 insertions(+)
MAINTAINERS +3 -0
@@ -25287,6 +25287,9 @@ M: Wei Huang <[email protected]> L: [email protected] S: Supported F: drivers/dma/sdxi/ +F: drivers/dma/sdxi/amd/ +F: include/uapi/linux/sdxi.h +F: tools/testing/selftests/sdxi/ SECO BOARDS CEC DRIVER M: Ettore Chimenti <[email protected]>
Signature · 1 line
2.56.1