mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Wei Huang <wei.huang2@amd.com>
To: <dmaengine@vger.kernel.org>
Cc: <vkoul@kernel.org>, <Frank.Li@kernel.org>, <shuah@kernel.org>,
	<nathan.lynch@amd.com>, <wei.huang2@amd.com>,
	<mario.limonciello@amd.com>, <Stephen.Bates@amd.com>,
	<tycho@kernel.org>, <suravee.suthikulpanit@amd.com>,
	<rientjes@google.com>, <John.Kariuki@amd.com>, <jic23@kernel.org>,
	<weixugc@google.com>, <bhelgaas@google.com>,
	<Shyam.Iyer@dell.com>, <linux-kernel@vger.kernel.org>,
	<linux-kselftest@vger.kernel.org>, <linux-pci@vger.kernel.org>
Subject: [PATCH v1 32/44] dmaengine: sdxi: amd: execute QoS vendor operations
Date: Thu, 19 Nov 2026 14:23:08 -0600	[thread overview]
Message-ID: <20261119202321.1734355-33-wei.huang2@amd.com> (raw)
In-Reply-To: <20261119202321.1734355-1-wei.huang2@amd.com>

Add execution code for AMD QoS capability, device update, pool update,
function update and telemetry operations.

Signed-off-by: Wei Huang <wei.huang2@amd.com>
---
 drivers/dma/sdxi/amd/qos.c | 321 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 320 insertions(+), 1 deletion(-)

diff --git a/drivers/dma/sdxi/amd/qos.c b/drivers/dma/sdxi/amd/qos.c
index 746e4c8b11e7..7d5dc9b6b32c 100644
--- a/drivers/dma/sdxi/amd/qos.c
+++ b/drivers/dma/sdxi/amd/qos.c
@@ -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;
+}
-- 
2.56.1


  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 ` Wei Huang [this message]
2026-11-19 20:23 ` [PATCH v1 33/44] dmaengine: sdxi: amd: register QoS vendor handler Wei Huang
2026-11-19 20:23 ` [PATCH v1 34/44] dmaengine: sdxi: amd: test QoS validation with KUnit Wei Huang
2026-11-19 20:23 ` [PATCH v1 35/44] selftests: sdxi: add build scaffold Wei Huang
2026-11-19 20:23 ` [PATCH v1 36/44] selftests: sdxi: add shared descriptor and context helpers Wei Huang
2026-11-19 20:23 ` [PATCH v1 37/44] selftests: sdxi: test context creation Wei Huang
2026-11-19 20:23 ` [PATCH v1 38/44] selftests: sdxi: test NOP descriptor submission Wei Huang
2026-11-19 20:23 ` [PATCH v1 39/44] selftests: sdxi: test copy submission and ring wrap Wei Huang
2026-11-19 20:23 ` [PATCH v1 40/44] selftests: sdxi: exercise dataplane error paths Wei Huang
2026-11-19 20:23 ` [PATCH v1 41/44] selftests: sdxi: test device ioctls Wei Huang
2026-11-19 20:23 ` [PATCH v1 42/44] selftests: sdxi: test vendor admin ioctls Wei Huang
2026-11-19 20:23 ` [PATCH v1 43/44] selftests: sdxi: test RKey ioctls Wei Huang
2026-11-19 20:23 ` [PATCH v1 44/44] MAINTAINERS: cover SDXI UAPI, vendor files, and selftests Wei Huang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119202321.1734355-33-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®