[PATCH v2 5/5] mailbox: convert RISC-V SBI MPXY to direct transmit

From: Anup Patel

Date: Sun Nov 15 2026 - 23:01:38 EST


From: Jassi Brar <jassisinghbrar@xxxxxxxxx>

The MPXY controller completes RPMI requests synchronously in
the caller's context, and the RPMI clients currently use the
tx_block=false plus knows_txdone retrofit. That retrofit is
tied to the single active_req slot and reports the wrong result
when two CPUs send on the same channel.

Advertise MBOX_CHAN_CAP_SYNC_ATOMIC for RPMI MPXY channels,
implement send_data_sync() returning msg->error. Switch
rpmi_mbox_send_message() to mbox_send_message_sync() and
drop the mbox_client_txdone() side channel and the obsolete
client flags.

Co-developed-by: Anup Patel <anup.patel@xxxxxxxxxxxxxxxx>
Signed-off-by: Anup Patel <anup.patel@xxxxxxxxxxxxxxxx>
Signed-off-by: Jassi Brar <jassisinghbrar@xxxxxxxxx>
---
drivers/clk/clk-rpmi.c | 3 --
drivers/irqchip/irq-riscv-rpmi-sysmsi.c | 3 --
drivers/mailbox/riscv-sbi-mpxy-mbox.c | 29 +++++++++++++++++--
.../pmdomain/riscv/riscv-rpmi-device-power.c | 3 --
include/linux/mailbox/riscv-rpmi-message.h | 17 ++++-------
5 files changed, 33 insertions(+), 22 deletions(-)

diff --git a/drivers/clk/clk-rpmi.c b/drivers/clk/clk-rpmi.c
index 40c11c373556..32af5b4e4dea 100644
--- a/drivers/clk/clk-rpmi.c
+++ b/drivers/clk/clk-rpmi.c
@@ -526,9 +526,6 @@ static int rpmi_clk_probe(struct platform_device *pdev)

context->client.dev = context->dev;
context->client.rx_callback = NULL;
- context->client.tx_block = false;
- context->client.knows_txdone = true;
- context->client.tx_tout = 0;

context->chan = mbox_request_channel(&context->client, 0);
if (IS_ERR(context->chan))
diff --git a/drivers/irqchip/irq-riscv-rpmi-sysmsi.c b/drivers/irqchip/irq-riscv-rpmi-sysmsi.c
index 7461d5339ddf..4e76303bd786 100644
--- a/drivers/irqchip/irq-riscv-rpmi-sysmsi.c
+++ b/drivers/irqchip/irq-riscv-rpmi-sysmsi.c
@@ -223,9 +223,6 @@ static int rpmi_sysmsi_probe(struct platform_device *pdev)
/* Setup mailbox client */
priv->client.dev = priv->dev;
priv->client.rx_callback = NULL;
- priv->client.tx_block = false;
- priv->client.knows_txdone = true;
- priv->client.tx_tout = 0;

/* Request mailbox channel */
priv->chan = mbox_request_channel(&priv->client, 0);
diff --git a/drivers/mailbox/riscv-sbi-mpxy-mbox.c b/drivers/mailbox/riscv-sbi-mpxy-mbox.c
index 432972195e46..5134a88fa984 100644
--- a/drivers/mailbox/riscv-sbi-mpxy-mbox.c
+++ b/drivers/mailbox/riscv-sbi-mpxy-mbox.c
@@ -234,6 +234,24 @@ static int mpxy_mbox_send_data(struct mbox_chan *chan, void *data)
return -EOPNOTSUPP;
}

+static int mpxy_mbox_send_data_sync(struct mbox_chan *chan, void *data)
+{
+ struct mpxy_mbox_channel *mchan = chan->con_priv;
+ struct rpmi_mbox_message *msg = data;
+
+ if (mchan->attrs.msg_proto_id != SBI_MPXY_MSGPROTO_RPMI_ID)
+ return -EOPNOTSUPP;
+ if (!msg)
+ return -EINVAL;
+
+ /*
+ * The MPXY helpers take the per-CPU shared-memory guard and complete
+ * the SBI call synchronously, so msg->error is this call's result.
+ */
+ mpxy_mbox_send_rpmi_data(mchan, msg);
+ return msg->error;
+}
+
static bool mpxy_mbox_peek_data(struct mbox_chan *chan)
{
struct mpxy_mbox_channel *mchan = chan->con_priv;
@@ -424,6 +442,7 @@ static void mpxy_mbox_shutdown(struct mbox_chan *chan)

static const struct mbox_chan_ops mpxy_mbox_ops = {
.send_data = mpxy_mbox_send_data,
+ .send_data_sync = mpxy_mbox_send_data_sync,
.peek_data = mpxy_mbox_peek_data,
.startup = mpxy_mbox_startup,
.shutdown = mpxy_mbox_shutdown,
@@ -586,8 +605,14 @@ static int mpxy_mbox_probe(struct platform_device *pdev)
mbox->channel_count);
if (!mbox->controller.chans)
return -ENOMEM;
- for (i = 0; i < mbox->channel_count; i++)
- mbox->controller.chans[i].con_priv = &mbox->channels[i];
+ for (i = 0; i < mbox->channel_count; i++) {
+ struct mbox_chan *chan = &mbox->controller.chans[i];
+ struct mpxy_mbox_channel *mchan = &mbox->channels[i];
+
+ chan->con_priv = mchan;
+ if (mchan->attrs.msg_proto_id == SBI_MPXY_MSGPROTO_RPMI_ID)
+ chan->sync_caps = MBOX_CHAN_CAP_SYNC_ATOMIC;
+ }

/* Setup MSIs for mailbox (if required) */
if (mbox->msi_count) {
diff --git a/drivers/pmdomain/riscv/riscv-rpmi-device-power.c b/drivers/pmdomain/riscv/riscv-rpmi-device-power.c
index 86b58ab29ca5..558e3dc0ef5e 100644
--- a/drivers/pmdomain/riscv/riscv-rpmi-device-power.c
+++ b/drivers/pmdomain/riscv/riscv-rpmi-device-power.c
@@ -347,9 +347,6 @@ static int rpmi_pm_domain_probe(struct platform_device *pdev)
/* Setup mailbox client */
mpxy_ctx->client.dev = dev;
mpxy_ctx->client.rx_callback = NULL;
- mpxy_ctx->client.tx_block = false;
- mpxy_ctx->client.knows_txdone = true;
- mpxy_ctx->client.tx_tout = 0;

/* Request mailbox channel */
mpxy_ctx->chan = mbox_request_channel(&mpxy_ctx->client, 0);
diff --git a/include/linux/mailbox/riscv-rpmi-message.h b/include/linux/mailbox/riscv-rpmi-message.h
index d5362b5821f9..be7c803292f2 100644
--- a/include/linux/mailbox/riscv-rpmi-message.h
+++ b/include/linux/mailbox/riscv-rpmi-message.h
@@ -238,17 +238,12 @@ static inline void *rpmi_mbox_get_msg_response(struct rpmi_mbox_message *msg)
static inline int rpmi_mbox_send_message(struct mbox_chan *chan,
struct rpmi_mbox_message *msg)
{
- int ret;
-
- /* Send message for the underlying mailbox channel */
- ret = mbox_send_message(chan, msg);
- if (ret < 0)
- return ret;
-
- /* Explicitly signal txdone for mailbox channel */
- ret = msg->error;
- mbox_client_txdone(chan, ret);
- return ret;
+ /*
+ * RPMI mailbox channels complete the request synchronously and return
+ * the per-call protocol result. Do not use the queued mailbox state
+ * machine or its txdone side channel.
+ */
+ return mbox_send_message_sync(chan, msg);
}

#endif /* _LINUX_RISCV_RPMI_MESSAGE_H_ */
--
2.43.0