[PATCH 05/11] crypto: ccp - split v5 command submission from queue run

From: Depei Yang

Date: Wed Nov 25 2026 - 02:47:05 EST


ccp5_do_cmd() copies one descriptor into the ring and immediately runs
the queue and waits for the completion. Some engines prepare several
descriptors for a single operation and only need the queue run once.

Split the descriptor copy from running the queue. ccp5_do_cmd() keeps
its behaviour by calling both helpers back to back; the SM engines will
run the queue through the new ->run action once a whole batch has been
submitted.

Reviewed-by: Shan Chen <chenshan@xxxxxxxx>
Tested-by: Yongwei Xu <xuyongwei@xxxxxxxx>
Signed-off-by: Depei Yang <yangdepei@xxxxxxxx>
---
drivers/crypto/ccp/ccp-dev-v5.c | 38 ++++++++++++++++++++++++++-------
drivers/crypto/ccp/ccp-dev.h | 1 +
2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/drivers/crypto/ccp/ccp-dev-v5.c b/drivers/crypto/ccp/ccp-dev-v5.c
index 372ccf7d1c8b..f7c107b93ccc 100644
--- a/drivers/crypto/ccp/ccp-dev-v5.c
+++ b/drivers/crypto/ccp/ccp-dev-v5.c
@@ -218,14 +218,12 @@ static unsigned int ccp5_get_free_slots(struct ccp_cmd_queue *cmd_q)
return n % COMMANDS_PER_QUEUE; /* Always one unused spot */
}

-static int ccp5_do_cmd(struct ccp5_desc *desc,
- struct ccp_cmd_queue *cmd_q)
+static void ccp5_submit_cmd(struct ccp5_desc *desc,
+ struct ccp_cmd_queue *cmd_q)
{
__le32 *mP;
u32 *dP;
- u32 tail;
- int i;
- int ret = 0;
+ int i;

cmd_q->total_ops++;

@@ -233,6 +231,7 @@ static int ccp5_do_cmd(struct ccp5_desc *desc,
CCP5_CMD_IOC(desc) = 1;
CCP5_CMD_SOC(desc) = 0;
}
+
mutex_lock(&cmd_q->q_mutex);

mP = (__le32 *)&cmd_q->qbase[cmd_q->qidx];
@@ -242,6 +241,16 @@ static int ccp5_do_cmd(struct ccp5_desc *desc,

cmd_q->qidx = (cmd_q->qidx + 1) % COMMANDS_PER_QUEUE;

+ mutex_unlock(&cmd_q->q_mutex);
+}
+
+static int ccp5_run_queue(struct ccp_cmd_queue *cmd_q, bool wait)
+{
+ u32 tail;
+ int ret = 0;
+
+ mutex_lock(&cmd_q->q_mutex);
+
/* The data used by this command must be flushed to memory */
wmb();

@@ -253,7 +262,7 @@ static int ccp5_do_cmd(struct ccp5_desc *desc,
iowrite32(cmd_q->qcontrol | CMD5_Q_RUN, cmd_q->reg_control);
mutex_unlock(&cmd_q->q_mutex);

- if (CCP5_CMD_IOC(desc)) {
+ if (wait) {
/* Wait for the job to complete */
ret = wait_event_interruptible(cmd_q->int_queue,
cmd_q->int_rcvd);
@@ -262,8 +271,7 @@ static int ccp5_do_cmd(struct ccp5_desc *desc,
* moving the head pointer
*/
if (cmd_q->cmd_error)
- ccp_log_error(cmd_q->ccp,
- cmd_q->cmd_error);
+ ccp_log_error(cmd_q->ccp, cmd_q->cmd_error);
iowrite32(tail, cmd_q->reg_head_lo);
if (!ret)
ret = -EIO;
@@ -274,6 +282,19 @@ static int ccp5_do_cmd(struct ccp5_desc *desc,
return ret;
}

+static int ccp5_run_cmd(struct ccp_op *op)
+{
+ return ccp5_run_queue(op->cmd_q, op->ioc);
+}
+
+static int ccp5_do_cmd(struct ccp5_desc *desc,
+ struct ccp_cmd_queue *cmd_q)
+{
+ ccp5_submit_cmd(desc, cmd_q);
+
+ return ccp5_run_queue(cmd_q, CCP5_CMD_IOC(desc));
+}
+
static int ccp5_perform_aes(struct ccp_op *op)
{
struct ccp5_desc desc;
@@ -1111,6 +1132,7 @@ static const struct ccp_actions ccp5_actions = {
.rsa = ccp5_perform_rsa,
.passthru = ccp5_perform_passthru,
.ecc = ccp5_perform_ecc,
+ .run = ccp5_run_cmd,
.sballoc = ccp_lsb_alloc,
.sbfree = ccp_lsb_free,
.init = ccp5_init,
diff --git a/drivers/crypto/ccp/ccp-dev.h b/drivers/crypto/ccp/ccp-dev.h
index ef88962ff6e6..16d5ea7773e2 100644
--- a/drivers/crypto/ccp/ccp-dev.h
+++ b/drivers/crypto/ccp/ccp-dev.h
@@ -659,6 +659,7 @@ struct ccp_actions {
int (*rsa)(struct ccp_op *);
int (*passthru)(struct ccp_op *);
int (*ecc)(struct ccp_op *);
+ int (*run)(struct ccp_op *op);
u32 (*sballoc)(struct ccp_cmd_queue *, unsigned int);
void (*sbfree)(struct ccp_cmd_queue *, unsigned int, unsigned int);
unsigned int (*get_free_slots)(struct ccp_cmd_queue *);
--
2.34.1