From: Wei Huang <wei.huang2@amd.com>
To: <dmaengine@vger.kernel.org>
Cc: <vkoul@kernel.org>, <Frank.Li@kernel.org>, <shuah@kernel.org>,
<nathan.lynch@amd.com>, <wei.huang2@amd.com>,
<mario.limonciello@amd.com>, <Stephen.Bates@amd.com>,
<tycho@kernel.org>, <suravee.suthikulpanit@amd.com>,
<rientjes@google.com>, <John.Kariuki@amd.com>, <jic23@kernel.org>,
<weixugc@google.com>, <bhelgaas@google.com>,
<Shyam.Iyer@dell.com>, <linux-kernel@vger.kernel.org>,
<linux-kselftest@vger.kernel.org>, <linux-pci@vger.kernel.org>
Subject: [PATCH v1 34/44] dmaengine: sdxi: amd: test QoS validation with KUnit
Date: Thu, 19 Nov 2026 14:23:10 -0600 [thread overview]
Message-ID: <20261119202321.1734355-35-wei.huang2@amd.com> (raw)
In-Reply-To: <20261119202321.1734355-1-wei.huang2@amd.com>
Add KUnit coverage for AMD QoS validation helpers. Note that hardware
execution paths still remain covered by other functional kunit tests.
Signed-off-by: Wei Huang <wei.huang2@amd.com>
---
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
diff --git a/drivers/dma/sdxi/Kconfig b/drivers/dma/sdxi/Kconfig
index ec89d976c3d3..fc71f1d3bc78 100644
--- a/drivers/dma/sdxi/Kconfig
+++ b/drivers/dma/sdxi/Kconfig
@@ -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
diff --git a/drivers/dma/sdxi/amd/Makefile b/drivers/dma/sdxi/amd/Makefile
index 5aee7e8a2414..7a7baad0247a 100644
--- a/drivers/dma/sdxi/amd/Makefile
+++ b/drivers/dma/sdxi/amd/Makefile
@@ -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
diff --git a/drivers/dma/sdxi/amd/qos_kunit.c b/drivers/dma/sdxi/amd/qos_kunit.c
new file mode 100644
index 000000000000..237e9ad79b19
--- /dev/null
+++ b/drivers/dma/sdxi/amd/qos_kunit.c
@@ -0,0 +1,180 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * AMD SDXI QoS helper tests.
+ *
+ * Copyright (C) 2026 Advanced Micro Devices, Inc.
+ */
+
+#include <kunit/test.h>
+#include <linux/bitfield.h>
+#include <linux/module.h>
+
+#include "qos.h"
+
+MODULE_IMPORT_NS("EXPORTED_FOR_KUNIT_TESTING");
+
+static void sdxi_kunit_qos_query_selector(struct kunit *t)
+{
+ u64 query_selector =
+ sdxi_amd_qos_query_selector(0x1234,
+ SDXI_AMD_QOS_TEL_QTYPE_POOL_CONFIG);
+
+ KUNIT_EXPECT_EQ(t, (u16)0x1234,
+ (u16)FIELD_GET(GENMASK_ULL(15, 0), query_selector));
+ KUNIT_EXPECT_EQ(t, (u8)SDXI_AMD_QOS_TEL_QTYPE_POOL_CONFIG,
+ (u8)FIELD_GET(GENMASK_ULL(18, 16), query_selector));
+ KUNIT_EXPECT_EQ(t, 0U,
+ (u32)FIELD_GET(GENMASK_ULL(31, 19),
+ query_selector));
+}
+
+static void sdxi_kunit_qos_align_bw(struct kunit *t)
+{
+ KUNIT_EXPECT_EQ(t, 0U, sdxi_amd_qos_align_bw(39, 40));
+ KUNIT_EXPECT_EQ(t, 40U, sdxi_amd_qos_align_bw(40, 40));
+ KUNIT_EXPECT_EQ(t, 40U, sdxi_amd_qos_align_bw(79, 40));
+ KUNIT_EXPECT_EQ(t, 80U, sdxi_amd_qos_align_bw(80, 40));
+}
+
+static void sdxi_kunit_qos_validate_devupd(struct kunit *t)
+{
+ KUNIT_EXPECT_EQ(t, 0,
+ sdxi_amd_qos_validate_devupd_req(119, 120, 80, 40));
+ KUNIT_EXPECT_EQ(t, -EINVAL,
+ sdxi_amd_qos_validate_devupd_req(121, 120, 80, 40));
+ KUNIT_EXPECT_EQ(t, -EINVAL,
+ sdxi_amd_qos_validate_devupd_req(79, 120, 80, 40));
+}
+
+static void sdxi_kunit_qos_validate_poolupd(struct kunit *t)
+{
+ const struct sdxi_amd_qos_poolupd_req create = {
+ .pool_num = 1,
+ .pool_operation = SDXI_AMD_QOS_POOL_OP_CREATE,
+ .pool_minbw = 41,
+ .pool_maxbw = 79,
+ };
+ const struct sdxi_amd_qos_poolupd_req invalid_bw = {
+ .pool_num = 1,
+ .pool_operation = SDXI_AMD_QOS_POOL_OP_UPDATE,
+ .pool_minbw = 79,
+ .pool_maxbw = 41,
+ };
+ const struct sdxi_amd_qos_poolupd_req create_pool0 = {
+ .pool_operation = SDXI_AMD_QOS_POOL_OP_CREATE,
+ };
+ const struct sdxi_amd_qos_poolupd_req destroy_pool0 = {
+ .pool_operation = SDXI_AMD_QOS_POOL_OP_DESTROY,
+ };
+
+ KUNIT_EXPECT_EQ(t, 0,
+ sdxi_amd_qos_validate_poolupd_req(&create, 8, 40));
+ KUNIT_EXPECT_EQ(t, -EINVAL,
+ sdxi_amd_qos_validate_poolupd_req(&invalid_bw, 8, 40));
+ KUNIT_EXPECT_EQ(t, -EINVAL,
+ sdxi_amd_qos_validate_poolupd_req(&create_pool0, 8, 40));
+ KUNIT_EXPECT_EQ(t, -EINVAL,
+ sdxi_amd_qos_validate_poolupd_req(&destroy_pool0, 8, 40));
+}
+
+static void sdxi_kunit_qos_validate_fnupd(struct kunit *t)
+{
+ const struct sdxi_amd_qos_fnupd_req function = {
+ .pool_num = 1,
+ .vf_num = 4,
+ .cxt_start = 16,
+ .cxt_end = 16,
+ };
+ const struct sdxi_amd_qos_fnupd_req context = {
+ .pool_num = 1,
+ .flags = SDXI_AMD_QOS_TARGET_F_CXT,
+ .cxt_start = 1,
+ .cxt_end = 1,
+ };
+ const struct sdxi_amd_qos_fnupd_req invalid_context = {
+ .pool_num = 1,
+ .flags = SDXI_AMD_QOS_TARGET_F_CXT,
+ .cxt_start = 16,
+ .cxt_end = 16,
+ };
+ const struct sdxi_amd_qos_fnupd_req invalid_vf = {
+ .pool_num = 1,
+ .flags = SDXI_AMD_QOS_TARGET_F_VF,
+ .vf_num = 4,
+ };
+ const u16 features = SDXI_AMD_QOS_FEATURE_FLEXIBLE_POOL_SCOPE;
+ int ret;
+
+ KUNIT_EXPECT_EQ(t, 0,
+ sdxi_amd_qos_validate_fnupd_req(&function, 8, 0, 16, 0));
+ KUNIT_EXPECT_EQ(t, 0,
+ sdxi_amd_qos_validate_fnupd_req(&context, 8, 0, 16, 0));
+ ret = sdxi_amd_qos_validate_fnupd_req(&invalid_context, 8, 0, 16, features);
+ KUNIT_EXPECT_EQ(t, -EINVAL, ret);
+
+ ret = sdxi_amd_qos_validate_fnupd_req(&invalid_vf, 8, 4, 16, 0);
+ KUNIT_EXPECT_EQ(t, -EINVAL, ret);
+}
+
+static void sdxi_kunit_qos_validate_tel(struct kunit *t)
+{
+ const struct sdxi_amd_qos_tel_req device = {
+ .query_type = SDXI_AMD_QOS_TEL_QTYPE_DEVICE,
+ };
+ const struct sdxi_amd_qos_tel_req pool = {
+ .pool_num = 7,
+ .flags = SDXI_AMD_QOS_TARGET_F_VF,
+ .vf_num = 99,
+ .cxt_num = 99,
+ .query_type = SDXI_AMD_QOS_TEL_QTYPE_POOL_CONFIG,
+ };
+ const struct sdxi_amd_qos_tel_req unsupported = {
+ .flags = SDXI_AMD_QOS_TARGET_F_CXT,
+ .cxt_num = 1,
+ .query_type = SDXI_AMD_QOS_TEL_QTYPE_POOL_ASSIGN,
+ };
+ const struct sdxi_amd_qos_tel_req invalid_context = {
+ .flags = SDXI_AMD_QOS_TARGET_F_CXT,
+ .cxt_num = 16,
+ .query_type = SDXI_AMD_QOS_TEL_QTYPE_POOL_ASSIGN,
+ };
+ const struct sdxi_amd_qos_tel_req invalid_query = {
+ .query_type = 6,
+ };
+ const u16 features = SDXI_AMD_QOS_FEATURE_FLEXIBLE_POOL_SCOPE;
+ int ret;
+
+ KUNIT_EXPECT_EQ(t, 0,
+ sdxi_amd_qos_validate_tel_req(&device, 8, 4, 16, 0));
+ KUNIT_EXPECT_EQ(t, 0,
+ sdxi_amd_qos_validate_tel_req(&pool, 8, 4, 16, 0));
+ ret = sdxi_amd_qos_validate_tel_req(&unsupported, 8, 4, 16, 0);
+ KUNIT_EXPECT_EQ(t, -EOPNOTSUPP, ret);
+
+ ret = sdxi_amd_qos_validate_tel_req(&invalid_context, 8, 4, 16, features);
+ KUNIT_EXPECT_EQ(t, -EINVAL, ret);
+
+ ret = sdxi_amd_qos_validate_tel_req(&invalid_query, 8, 4, 16, 0);
+ KUNIT_EXPECT_EQ(t, -EINVAL, ret);
+}
+
+static struct kunit_case sdxi_qos_cases[] = {
+ KUNIT_CASE(sdxi_kunit_qos_query_selector),
+ KUNIT_CASE(sdxi_kunit_qos_align_bw),
+ KUNIT_CASE(sdxi_kunit_qos_validate_devupd),
+ KUNIT_CASE(sdxi_kunit_qos_validate_poolupd),
+ KUNIT_CASE(sdxi_kunit_qos_validate_fnupd),
+ KUNIT_CASE(sdxi_kunit_qos_validate_tel),
+ {}
+};
+
+static struct kunit_suite sdxi_qos_suite = {
+ .name = "AMD SDXI QoS helpers",
+ .test_cases = sdxi_qos_cases,
+};
+
+kunit_test_suite(sdxi_qos_suite);
+
+MODULE_DESCRIPTION("AMD SDXI QoS helper tests");
+MODULE_AUTHOR("Wei Huang");
+MODULE_LICENSE("GPL");
--
2.56.1
next prev parent reply other threads:[~2026-11-19 20:30 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 20:22 [PATCH v1 00/44] dmaengine: sdxi: add userspace control and management support Wei Huang
2026-11-19 20:22 ` [PATCH v1 01/44] dmaengine: sdxi: cache hardware version for feature gating Wei Huang
2026-11-19 20:22 ` [PATCH v1 02/44] dmaengine: sdxi: define key and error MMIO registers Wei Huang
2026-11-19 20:22 ` [PATCH v1 03/44] dmaengine: sdxi: define SDXI hardware layouts Wei Huang
2026-11-19 20:22 ` [PATCH v1 04/44] dmaengine: sdxi: encode admin descriptors Wei Huang
2026-11-19 20:22 ` [PATCH v1 05/44] dmaengine: sdxi: support timeout-aware completion waits Wei Huang
2026-11-19 20:22 ` [PATCH v1 06/44] dmaengine: sdxi: support the full context table hierarchy Wei Huang
2026-11-19 20:22 ` [PATCH v1 07/44] dmaengine: sdxi: implement synchronous admin operations Wei Huang
2026-11-19 20:22 ` [PATCH v1 08/44] dmaengine: sdxi: add core RKey table management Wei Huang
2026-11-19 20:22 ` [PATCH v1 09/44] dmaengine: sdxi: handle hardware error logs Wei Huang
2026-11-19 20:22 ` [PATCH v1 10/44] dmaengine: sdxi: separate context and submission resources Wei Huang
2026-11-19 20:22 ` [PATCH v1 11/44] dmaengine: sdxi: support userspace context lifetimes Wei Huang
2026-11-19 20:22 ` [PATCH v1 12/44] dmaengine: sdxi: route context interrupts to eventfd Wei Huang
2026-11-19 20:22 ` [PATCH v1 13/44] dmaengine: sdxi: kill user contexts on fatal errors Wei Huang
2026-11-19 20:22 ` [PATCH v1 14/44] dmaengine: sdxi: define the ioctl UAPI surface Wei Huang
2026-11-19 20:22 ` [PATCH v1 15/44] dmaengine: sdxi: add internal ioctl definitions Wei Huang
2026-11-19 20:22 ` [PATCH v1 16/44] dmaengine: sdxi: register core character devices Wei Huang
2026-11-19 20:22 ` [PATCH v1 17/44] dmaengine: sdxi: implement fixed-size ioctl dispatch Wei Huang
2026-11-19 20:22 ` [PATCH v1 18/44] dmaengine: sdxi: implement userspace context file operations Wei Huang
2026-11-19 20:22 ` [PATCH v1 19/44] dmaengine: sdxi: validate and copy key ioctl payloads Wei Huang
2026-11-19 20:22 ` [PATCH v1 20/44] dmaengine: sdxi: implement RKey management ioctls Wei Huang
2026-11-19 20:22 ` [PATCH v1 21/44] dmaengine: sdxi: implement AKey " Wei Huang
2026-11-19 20:22 ` [PATCH v1 22/44] dmaengine: sdxi: expose operation-group discovery Wei Huang
2026-11-19 20:22 ` [PATCH v1 23/44] dmaengine: sdxi: implement typed vendor admin transport Wei Huang
2026-11-19 20:23 ` [PATCH v1 24/44] dmaengine: sdxi: expose character device attributes Wei Huang
2026-11-19 20:23 ` [PATCH v1 25/44] dmaengine: sdxi: add PF and VF device naming Wei Huang
2026-11-19 20:23 ` [PATCH v1 26/44] dmaengine: sdxi: add SDXI trace events Wei Huang
2026-11-19 20:23 ` [PATCH v1 27/44] dmaengine: sdxi: support suspend and resume Wei Huang
2026-11-19 20:23 ` [PATCH v1 28/44] dmaengine: sdxi: amd: define QoS request formats Wei Huang
2026-11-19 20:23 ` [PATCH v1 29/44] dmaengine: sdxi: amd: add QoS validation scaffolding Wei Huang
2026-11-19 20:23 ` [PATCH v1 30/44] dmaengine: sdxi: amd: build QoS admin descriptors Wei Huang
2026-11-19 20:23 ` [PATCH v1 31/44] dmaengine: sdxi: amd: prevalidate QoS operations Wei Huang
2026-11-19 20:23 ` [PATCH v1 32/44] dmaengine: sdxi: amd: execute QoS vendor operations Wei Huang
2026-11-19 20:23 ` [PATCH v1 33/44] dmaengine: sdxi: amd: register QoS vendor handler Wei Huang
2026-11-19 20:23 ` Wei Huang [this message]
2026-11-19 20:23 ` [PATCH v1 35/44] selftests: sdxi: add build scaffold Wei Huang
2026-11-19 20:23 ` [PATCH v1 36/44] selftests: sdxi: add shared descriptor and context helpers Wei Huang
2026-11-19 20:23 ` [PATCH v1 37/44] selftests: sdxi: test context creation Wei Huang
2026-11-19 20:23 ` [PATCH v1 38/44] selftests: sdxi: test NOP descriptor submission Wei Huang
2026-11-19 20:23 ` [PATCH v1 39/44] selftests: sdxi: test copy submission and ring wrap Wei Huang
2026-11-19 20:23 ` [PATCH v1 40/44] selftests: sdxi: exercise dataplane error paths Wei Huang
2026-11-19 20:23 ` [PATCH v1 41/44] selftests: sdxi: test device ioctls Wei Huang
2026-11-19 20:23 ` [PATCH v1 42/44] selftests: sdxi: test vendor admin ioctls Wei Huang
2026-11-19 20:23 ` [PATCH v1 43/44] selftests: sdxi: test RKey ioctls Wei Huang
2026-11-19 20:23 ` [PATCH v1 44/44] MAINTAINERS: cover SDXI UAPI, vendor files, and selftests Wei Huang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261119202321.1734355-35-wei.huang2@amd.com \
--to=wei.huang2@amd.com \
--cc=Frank.Li@kernel.org \
--cc=John.Kariuki@amd.com \
--cc=Shyam.Iyer@dell.com \
--cc=Stephen.Bates@amd.com \
--cc=bhelgaas@google.com \
--cc=dmaengine@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mario.limonciello@amd.com \
--cc=nathan.lynch@amd.com \
--cc=rientjes@google.com \
--cc=shuah@kernel.org \
--cc=suravee.suthikulpanit@amd.com \
--cc=tycho@kernel.org \
--cc=vkoul@kernel.org \
--cc=weixugc@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®