[PATCH 4/4] mailbox: riscv-sbi-mpxy: Move to send_data_sync() for sending messages

Anup Patel anup.patel at oss.qualcomm.com
Wed Sep 30 08:02:13 PDT 2026


Currently, the SBI MPXY mailbox driver retrofits synchronous message
exchanges over existing send_data() callback and client driver explicitly
calls mbox_client_txdone().

As a side effect of this retrofitting, all messages sent via SBI MPXY
mailbox channel are serialized using per-channel spinlock which in-turn
prevents multiple CPUs simultaneously sending messages. On the contrary,
the SBI MPXY specification defines per-CPU MPXY shared memory so multiple
CPUs are allowed to send messages in-parallel.

To address the above, update the SBI MPXY mailbox driver to use the
send_data_sync() callback instead of send_data() callback. This removes
the redundant per-channel spinlock from the message sending path thereby
enabling parallel message sending from multiple CPUs. Also, the "error"
field in struct rpmi_mbox_message is now redundant because it was being
used to save the error dropped by msg_submit() function hence remove it.

Co-developed-by: Amirreza Zarrabi <amirreza.zarrabi at oss.qualcomm.com>
Signed-off-by: Amirreza Zarrabi <amirreza.zarrabi at oss.qualcomm.com>
Signed-off-by: Anup Patel <anup.patel at oss.qualcomm.com>
---
 drivers/clk/clk-rpmi.c                     |  2 +-
 drivers/irqchip/irq-riscv-rpmi-sysmsi.c    |  2 +-
 drivers/mailbox/riscv-sbi-mpxy-mbox.c      | 59 +++++++++++-----------
 include/linux/mailbox/riscv-rpmi-message.h | 18 +------
 4 files changed, 34 insertions(+), 47 deletions(-)

diff --git a/drivers/clk/clk-rpmi.c b/drivers/clk/clk-rpmi.c
index 921296aafa68..e365cb8a8dac 100644
--- a/drivers/clk/clk-rpmi.c
+++ b/drivers/clk/clk-rpmi.c
@@ -527,7 +527,7 @@ 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_sync		= true;
 	context->client.tx_tout		= 0;
 
 	context->chan = mbox_request_channel(&context->client, 0);
diff --git a/drivers/irqchip/irq-riscv-rpmi-sysmsi.c b/drivers/irqchip/irq-riscv-rpmi-sysmsi.c
index 612f3972f7af..ca638900aa74 100644
--- a/drivers/irqchip/irq-riscv-rpmi-sysmsi.c
+++ b/drivers/irqchip/irq-riscv-rpmi-sysmsi.c
@@ -224,7 +224,7 @@ static int rpmi_sysmsi_probe(struct platform_device *pdev)
 	priv->client.dev		= priv->dev;
 	priv->client.rx_callback	= NULL;
 	priv->client.tx_block		= false;
-	priv->client.knows_txdone	= true;
+	priv->client.tx_sync		= true;
 	priv->client.tx_tout		= 0;
 
 	/* Request mailbox channel */
diff --git a/drivers/mailbox/riscv-sbi-mpxy-mbox.c b/drivers/mailbox/riscv-sbi-mpxy-mbox.c
index cba95b8406ee..18d5ed0b1561 100644
--- a/drivers/mailbox/riscv-sbi-mpxy-mbox.c
+++ b/drivers/mailbox/riscv-sbi-mpxy-mbox.c
@@ -112,10 +112,10 @@ struct mpxy_mbox {
 
 /* ====== MPXY RPMI processing ====== */
 
-static void mpxy_mbox_send_rpmi_data(struct mpxy_mbox_channel *mchan,
-				     struct rpmi_mbox_message *msg)
+static int mpxy_mbox_send_rpmi_data(struct mpxy_mbox_channel *mchan,
+				    struct rpmi_mbox_message *msg)
 {
-	msg->error = 0;
+	int error = 0;
 	switch (msg->type) {
 	case RPMI_MBOX_MSG_TYPE_GET_ATTRIBUTE:
 		switch (msg->attr.id) {
@@ -138,52 +138,54 @@ static void mpxy_mbox_send_rpmi_data(struct mpxy_mbox_channel *mchan,
 			msg->attr.value = mchan->rpmi_attrs.impl_version;
 			break;
 		default:
-			msg->error = -EOPNOTSUPP;
+			error = -EOPNOTSUPP;
 			break;
 		}
 		break;
 	case RPMI_MBOX_MSG_TYPE_SET_ATTRIBUTE:
 		/* None of the RPMI linux mailbox attributes are writeable */
-		msg->error = -EOPNOTSUPP;
+		error = -EOPNOTSUPP;
 		break;
 	case RPMI_MBOX_MSG_TYPE_SEND_WITH_RESPONSE:
 		if ((!msg->data.request && msg->data.request_len) ||
 		    (msg->data.request && msg->data.request_len > mchan->max_xfer_len) ||
 		    (!msg->data.response && msg->data.max_response_len)) {
-			msg->error = -EINVAL;
+			error = -EINVAL;
 			break;
 		}
 		if (!(mchan->attrs.capability & SBI_MPXY_CHAN_CAP_SEND_WITH_RESP)) {
-			msg->error = -EIO;
+			error = -EIO;
 			break;
 		}
-		msg->error = sbi_mpxy_send_message_with_resp(mchan->channel_id,
-							     msg->data.service_id,
-							     msg->data.request,
-							     msg->data.request_len,
-							     msg->data.response,
-							     msg->data.max_response_len,
-							     &msg->data.out_response_len);
+		error = sbi_mpxy_send_message_with_resp(mchan->channel_id,
+							msg->data.service_id,
+							msg->data.request,
+							msg->data.request_len,
+							msg->data.response,
+							msg->data.max_response_len,
+							&msg->data.out_response_len);
 		break;
 	case RPMI_MBOX_MSG_TYPE_SEND_WITHOUT_RESPONSE:
 		if ((!msg->data.request && msg->data.request_len) ||
 		    (msg->data.request && msg->data.request_len > mchan->max_xfer_len)) {
-			msg->error = -EINVAL;
+			error = -EINVAL;
 			break;
 		}
 		if (!(mchan->attrs.capability & SBI_MPXY_CHAN_CAP_SEND_WITHOUT_RESP)) {
-			msg->error = -EIO;
+			error = -EIO;
 			break;
 		}
-		msg->error = sbi_mpxy_send_message_without_resp(mchan->channel_id,
-								msg->data.service_id,
-								msg->data.request,
-								msg->data.request_len);
+		error = sbi_mpxy_send_message_without_resp(mchan->channel_id,
+							   msg->data.service_id,
+							   msg->data.request,
+							   msg->data.request_len);
 		break;
 	default:
-		msg->error = -EOPNOTSUPP;
+		error = -EOPNOTSUPP;
 		break;
 	}
+
+	return error;
 }
 
 static void mpxy_mbox_peek_rpmi_data(struct mbox_chan *chan,
@@ -205,7 +207,6 @@ static void mpxy_mbox_peek_rpmi_data(struct mbox_chan *chan,
 			break;
 		msg.notif.event_id = event->event_id;
 		msg.notif.event_data = event->event_data;
-		msg.error = 0;
 
 		mbox_chan_received_data(chan, &msg);
 		pos += sizeof(*event) + msg.notif.event_datalen;
@@ -222,16 +223,16 @@ static int mpxy_mbox_read_rpmi_attrs(struct mpxy_mbox_channel *mchan)
 
 /* ====== MPXY mailbox callbacks ====== */
 
-static int mpxy_mbox_send_data(struct mbox_chan *chan, void *data)
+static int mpxy_mbox_send_data_sync(struct mbox_chan *chan, void *data)
 {
 	struct mpxy_mbox_channel *mchan = chan->con_priv;
 
-	if (mchan->attrs.msg_proto_id == SBI_MPXY_MSGPROTO_RPMI_ID) {
-		mpxy_mbox_send_rpmi_data(mchan, data);
-		return 0;
+	switch (mchan->attrs.msg_proto_id) {
+	case SBI_MPXY_MSGPROTO_RPMI_ID:
+		return mpxy_mbox_send_rpmi_data(mchan, data);
+	default:
+		return -EOPNOTSUPP;
 	}
-
-	return -EOPNOTSUPP;
 }
 
 static bool mpxy_mbox_peek_data(struct mbox_chan *chan)
@@ -423,7 +424,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,
diff --git a/include/linux/mailbox/riscv-rpmi-message.h b/include/linux/mailbox/riscv-rpmi-message.h
index e135c6564d0c..0278f1cee51f 100644
--- a/include/linux/mailbox/riscv-rpmi-message.h
+++ b/include/linux/mailbox/riscv-rpmi-message.h
@@ -164,7 +164,6 @@ struct rpmi_mbox_message {
 			u8 *event_data;
 		} notif;
 	};
-	int error;
 };
 
 /* RPMI Linux mailbox message helper routines */
@@ -174,7 +173,6 @@ static inline void rpmi_mbox_init_get_attribute(struct rpmi_mbox_message *msg,
 	msg->type = RPMI_MBOX_MSG_TYPE_GET_ATTRIBUTE;
 	msg->attr.id = id;
 	msg->attr.value = 0;
-	msg->error = 0;
 }
 
 static inline void rpmi_mbox_init_set_attribute(struct rpmi_mbox_message *msg,
@@ -184,7 +182,6 @@ static inline void rpmi_mbox_init_set_attribute(struct rpmi_mbox_message *msg,
 	msg->type = RPMI_MBOX_MSG_TYPE_SET_ATTRIBUTE;
 	msg->attr.id = id;
 	msg->attr.value = value;
-	msg->error = 0;
 }
 
 static inline void rpmi_mbox_init_send_with_response(struct rpmi_mbox_message *msg,
@@ -201,7 +198,6 @@ static inline void rpmi_mbox_init_send_with_response(struct rpmi_mbox_message *m
 	msg->data.response = response;
 	msg->data.max_response_len = max_response_len;
 	msg->data.out_response_len = 0;
-	msg->error = 0;
 }
 
 static inline void rpmi_mbox_init_send_without_response(struct rpmi_mbox_message *msg,
@@ -216,7 +212,6 @@ static inline void rpmi_mbox_init_send_without_response(struct rpmi_mbox_message
 	msg->data.response = NULL;
 	msg->data.max_response_len = 0;
 	msg->data.out_response_len = 0;
-	msg->error = 0;
 }
 
 static inline void *rpmi_mbox_get_msg_response(struct rpmi_mbox_message *msg)
@@ -227,17 +222,8 @@ 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;
+	/* Send message for the underlying mailbox channel synchronously */
+	return mbox_send_message_sync(chan, msg);
 }
 
 #endif /* _LINUX_RISCV_RPMI_MESSAGE_H_ */
-- 
2.43.0




More information about the linux-riscv mailing list