mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Anup Patel <anup.patel@oss.qualcomm.com>
To: Palmer Dabbelt <palmer@dabbelt.com>,
	Paul Walmsley <pjw@kernel.org>,
	Rahul Pathak <rahul@summations.net>,
	Stephen Boyd <sboyd@kernel.org>,
	Brian Masney <bmasney+clk@redhat.com>,
	Jerome Brunet <jbrunet+clk@baylibre.com>,
	Thomas Gleixner <tglx@kernel.org>, Radu Rendec <radu@rendec.net>,
	Jassi Brar <jassisinghbrar@gmail.com>
Cc: Sunil V L <sunilvl@oss.qualcomm.com>,
	Himanshu Chauhan <himanshu.chauhan@oss.qualcomm.com>,
	Atish Patra <atish.patra@linux.dev>,
	Anup Patel <anup@brainfault.org>,
	Amirreza Zarrabi <amirreza.zarrabi@oss.qualcomm.com>,
	linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org,
	linux-clk@vger.kernel.org,
	Anup Patel <anup.patel@oss.qualcomm.com>
Subject: [PATCH v2 5/5] mailbox: convert RISC-V SBI MPXY to direct transmit
Date: Mon, 16 Nov 2026 09:30:49 +0530	[thread overview]
Message-ID: <20261116040049.1795610-6-anup.patel@oss.qualcomm.com> (raw)
In-Reply-To: <20261116040049.1795610-1-anup.patel@oss.qualcomm.com>

From: Jassi Brar <jassisinghbrar@gmail.com>

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@oss.qualcomm.com>
Signed-off-by: Anup Patel <anup.patel@oss.qualcomm.com>
Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com>
---
 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


      parent reply	other threads:[~2026-11-16  4:01 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16  4:00 [PATCH v2 0/5] Parallel message send using SBI MPXY Anup Patel
2026-11-16  4:00 ` [PATCH v2 1/5] RISC-V: Move common MPXY helper routines to arch/riscv Anup Patel
2026-11-16  4:00 ` [PATCH v2 2/5] RISC-V: Use irqsave to prevent interrupt when accessing MPXY shared memory Anup Patel
2026-11-16  4:00 ` [PATCH v2 3/5] mailbox: add direct synchronous transmit API Anup Patel
2026-11-16  4:00 ` [PATCH v2 4/5] mailbox: document direct synchronous transmit Anup Patel
2026-11-16  4:00 ` Anup Patel [this message]

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=20261116040049.1795610-6-anup.patel@oss.qualcomm.com \
    --to=anup.patel@oss.qualcomm.com \
    --cc=amirreza.zarrabi@oss.qualcomm.com \
    --cc=anup@brainfault.org \
    --cc=atish.patra@linux.dev \
    --cc=bmasney+clk@redhat.com \
    --cc=himanshu.chauhan@oss.qualcomm.com \
    --cc=jassisinghbrar@gmail.com \
    --cc=jbrunet+clk@baylibre.com \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=palmer@dabbelt.com \
    --cc=pjw@kernel.org \
    --cc=radu@rendec.net \
    --cc=rahul@summations.net \
    --cc=sboyd@kernel.org \
    --cc=sunilvl@oss.qualcomm.com \
    --cc=tglx@kernel.org \
    /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®