[PATCH 14/23] dmaengine: sdxi: Attach descriptor ring state to contexts

Nathan Lynch via B4 Relay
2026-04-10T13:07:50Z

Attach an instance of struct sdxi_ring_state to each context upon
allocation. Each ring state has the same lifetime has its context and
is freed upon context release.

Co-developed-by: Wei Huang <wei.huang2@amd.com>
Signed-off-by: Wei Huang <wei.huang2@amd.com>
Signed-off-by: Nathan Lynch <nathan.lynch@amd.com>
---
drivers/dma/sdxi/context.c | 13 +++++++++++++
drivers/dma/sdxi/context.h | 2 ++
2 files changed, 15 insertions(+)

diff --git a/drivers/dma/sdxi/context.c b/drivers/dma/sdxi/context.c
index 7cae140c0a20..792b5032203b 100644
--- a/drivers/dma/sdxi/context.c
+++ b/drivers/dma/sdxi/context.c
@@ -24,6 +24,7 @@

#include "context.h"
#include "hw.h"
+#include "ring.h"
#include "sdxi.h"

#define DEFAULT_DESC_RING_ENTRIES 1024
@@ -60,6 +61,7 @@ static void sdxi_free_cxt(struct sdxi_cxt *cxt)
dma_free_coherent(sdxi_to_dev(sdxi), sq->ring_size,
sq->desc_ring, sq->ring_dma);
kfree(cxt->sq);
+ kfree(cxt->ring_state);
kfree(cxt);
}

@@ -77,6 +79,10 @@ static struct sdxi_cxt *sdxi_alloc_cxt(struct sdxi_dev *sdxi)

cxt->sdxi = sdxi;

+ cxt->ring_state = kzalloc_obj(*cxt->ring_state, GFP_KERNEL);
+ if (!cxt->ring_state)
+ return NULL;
+
cxt->sq = kzalloc_obj(*cxt->sq, GFP_KERNEL);
if (!cxt->sq)
return NULL;
@@ -373,6 +379,8 @@ int sdxi_admin_cxt_init(struct sdxi_dev *sdxi)
sq->cxt_sts->state = FIELD_PREP(SDXI_CXT_STS_STATE, CXTV_RUN);
cxt->id = SDXI_ADMIN_CXT_ID;
cxt->db = sdxi->dbs + cxt->id * sdxi->db_stride;
+ sdxi_ring_state_init(cxt->ring_state, &sq->cxt_sts->read_index,
+ sq->write_index, sq->ring_entries, sq->desc_ring);

err = sdxi_publish_cxt(cxt);
if (err)
@@ -389,10 +397,15 @@ int sdxi_admin_cxt_init(struct sdxi_dev *sdxi)
*/
struct sdxi_cxt *sdxi_cxt_new(struct sdxi_dev *sdxi)
{
+ struct sdxi_sq *sq;
+
struct sdxi_cxt *cxt __free(sdxi_cxt) = sdxi_alloc_cxt(sdxi);
if (!cxt)
return NULL;

+ sq = cxt->sq;
+ sdxi_ring_state_init(cxt->ring_state, &sq->cxt_sts->read_index,
+ sq->write_index, sq->ring_entries, sq->desc_ring);
if (register_cxt(sdxi, cxt))
return NULL;

diff --git a/drivers/dma/sdxi/context.h b/drivers/dma/sdxi/context.h
index 5cd78e883c8d..9779b9aa4f86 100644
--- a/drivers/dma/sdxi/context.h
+++ b/drivers/dma/sdxi/context.h
@@ -54,6 +54,8 @@ struct sdxi_cxt {
dma_addr_t akey_table_dma;

struct sdxi_sq *sq;
+
+ struct sdxi_ring_state *ring_state;
};

int sdxi_admin_cxt_init(struct sdxi_dev *sdxi);

--
2.53.0