public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mailbox: check mailbox queue is full or not
@ 2025-09-25 18:50 Tanmay Shah
  2025-09-26  7:37 ` Peng Fan
  2025-09-30 14:11 ` Jassi Brar
  0 siblings, 2 replies; 13+ messages in thread
From: Tanmay Shah @ 2025-09-25 18:50 UTC (permalink / raw)
  To: jassisinghbrar, andersson, mathieu.poirier
  Cc: linux-kernel, linux-remoteproc, Tanmay Shah

Sometimes clients need to know if mailbox queue is full or not before
posting new message via mailbox. If mailbox queue is full clients can
choose not to post new message. This doesn't mean current queue length
should be increased, but clients may want to wait till previous Tx is
done. This API can help avoid false positive warning from mailbox
framework "Try increasing MBOX_TX_QUEUE_LEN".

Signed-off-by: Tanmay Shah <tanmay.shah@amd.com>
---
 drivers/mailbox/mailbox.c               | 24 ++++++++++++++++++++++++
 drivers/remoteproc/xlnx_r5_remoteproc.c |  4 ++++
 include/linux/mailbox_client.h          |  1 +
 3 files changed, 29 insertions(+)

diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
index 5cd8ae222073..7afdb2c9006d 100644
--- a/drivers/mailbox/mailbox.c
+++ b/drivers/mailbox/mailbox.c
@@ -217,6 +217,30 @@ bool mbox_client_peek_data(struct mbox_chan *chan)
 }
 EXPORT_SYMBOL_GPL(mbox_client_peek_data);
 
+/**
+ * mbox_queue_full - check if mailbox queue is full or not
+ * @chan: Mailbox channel assigned to this client.
+ *
+ * Clients can choose not to send new msg if mbox queue is full.
+ *
+ * Return: true if queue is full else false. < 0 for error
+ */
+int mbox_queue_full(struct mbox_chan *chan)
+{
+	unsigned long flags;
+	int res;
+
+	if (!chan)
+		return -EINVAL;
+
+	spin_lock_irqsave(&chan->lock, flags);
+	res = (chan->msg_count == (MBOX_TX_QUEUE_LEN - 1));
+	spin_unlock_irqrestore(&chan->lock, flags);
+
+	return res;
+}
+EXPORT_SYMBOL_GPL(mbox_queue_full);
+
 /**
  * mbox_send_message -	For client to submit a message to be
  *				sent to the remote.
diff --git a/drivers/remoteproc/xlnx_r5_remoteproc.c b/drivers/remoteproc/xlnx_r5_remoteproc.c
index 0b7b173d0d26..b3262de8a3ac 100644
--- a/drivers/remoteproc/xlnx_r5_remoteproc.c
+++ b/drivers/remoteproc/xlnx_r5_remoteproc.c
@@ -335,6 +335,10 @@ static void zynqmp_r5_rproc_kick(struct rproc *rproc, int vqid)
 	if (!ipi)
 		return;
 
+	/* Do not need new kick as already many kick interrupts are pending. */
+	if (mbox_queue_full(ipi->tx_chan) == true)
+		return;
+
 	mb_msg = (struct zynqmp_ipi_message *)ipi->tx_mc_buf;
 	memcpy(mb_msg->data, &vqid, sizeof(vqid));
 	mb_msg->len = sizeof(vqid);
diff --git a/include/linux/mailbox_client.h b/include/linux/mailbox_client.h
index c6eea9afb943..4a19800af96f 100644
--- a/include/linux/mailbox_client.h
+++ b/include/linux/mailbox_client.h
@@ -46,5 +46,6 @@ int mbox_flush(struct mbox_chan *chan, unsigned long timeout);
 void mbox_client_txdone(struct mbox_chan *chan, int r); /* atomic */
 bool mbox_client_peek_data(struct mbox_chan *chan); /* atomic */
 void mbox_free_channel(struct mbox_chan *chan); /* may sleep */
+int mbox_queue_full(struct mbox_chan *chan);
 
 #endif /* __MAILBOX_CLIENT_H */

base-commit: 56d030ea3330ab737fe6c05f89d52f56208b07ac
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2025-09-30 18:38 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-09-25 18:50 [PATCH] mailbox: check mailbox queue is full or not Tanmay Shah
2025-09-26  7:37 ` Peng Fan
2025-09-26 15:40   ` Tanmay Shah
2025-09-28  7:56     ` Peng Fan
2025-09-29 14:45       ` Mathieu Poirier
2025-09-29 19:26         ` Tanmay Shah
2025-09-29 19:35           ` Tanmay Shah
2025-09-30  2:41           ` Peng Fan
2025-09-30 14:11 ` Jassi Brar
2025-09-30 16:52   ` Tanmay Shah
2025-09-30 17:33     ` Jassi Brar
2025-09-30 17:58       ` Tanmay Shah
2025-09-30 18:38         ` Tanmay Shah

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox