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 06/44] dmaengine: sdxi: support the full context table hierarchy
Date: Thu, 19 Nov 2026 14:22:42 -0600 [thread overview]
Message-ID: <20261119202321.1734355-7-wei.huang2@amd.com> (raw)
In-Reply-To: <20261119202321.1734355-1-wei.huang2@amd.com>
Remove 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.
Co-developed-by: Nathan Lynch <nathan.lynch@amd.com>
Signed-off-by: Nathan Lynch <nathan.lynch@amd.com>
Signed-off-by: Wei Huang <wei.huang2@amd.com>
---
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(-)
diff --git a/drivers/dma/sdxi/context.c b/drivers/dma/sdxi/context.c
index 0979fa35346b..d75668e89e61 100644
--- a/drivers/dma/sdxi/context.c
+++ b/drivers/dma/sdxi/context.c
@@ -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;
}
diff --git a/drivers/dma/sdxi/device.c b/drivers/dma/sdxi/device.c
index e3fa39ee9988..c5b5b39a7fe5 100644
--- a/drivers/dma/sdxi/device.c
+++ b/drivers/dma/sdxi/device.c
@@ -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);
diff --git a/drivers/dma/sdxi/sdxi.h b/drivers/dma/sdxi/sdxi.h
index 0bc08fc6ae75..6d2b9ba88182 100644
--- a/drivers/dma/sdxi/sdxi.h
+++ b/drivers/dma/sdxi/sdxi.h
@@ -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;
--
2.56.1
next prev parent reply other threads:[~2026-11-19 20:24 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 ` Wei Huang [this message]
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 ` [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-7-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®