[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20260203225821.3293475-2-tanmay.shah@amd.com>
Date: Tue, 3 Feb 2026 14:58:20 -0800
From: Tanmay Shah <tanmay.shah@....com>
To: <jassisinghbrar@...il.com>, <andersson@...nel.org>,
<mathieu.poirier@...aro.org>
CC: <linux-kernel@...r.kernel.org>, <linux-remoteproc@...r.kernel.org>,
"Tanmay Shah" <tanmay.shah@....com>
Subject: [PATCH v4 1/3] mailbox: check mailbox queue is full or not
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. Introduce variable per channel to track available tx msg slots.
Clients can check this variable and decide not to send new message if
it is 0. This will help avoid false positive warning from mailbox
framework "Try increasing MBOX_TX_QUEUE_LEN".
Signed-off-by: Tanmay Shah <tanmay.shah@....com>
---
v4:
- %s/msg_slot_ro/tx_slots_avail_ro/
- do not use msg_count to calculate tx_slots_avail_ro instead modify
it directly
v3:
- move msg_slot_ro to mbox_client instead of mbox_chan
- modify rest of the patch to use msg_slot_ro from mbox_client
v2:
- change design and introduce msg_slot_ro field for each channel
instead of API. Clients can use this variable directly.
- remove mbox_queue_full API and use msg_slot_ro to know if single
slot is available in msg queue or not.
drivers/mailbox/mailbox.c | 3 +++
include/linux/mailbox_client.h | 2 ++
2 files changed, 5 insertions(+)
diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c
index 2acc6ec229a4..8228e6a9ef97 100644
--- a/drivers/mailbox/mailbox.c
+++ b/drivers/mailbox/mailbox.c
@@ -36,6 +36,7 @@ static int add_to_rbuf(struct mbox_chan *chan, void *mssg)
idx = chan->msg_free;
chan->msg_data[idx] = mssg;
chan->msg_count++;
+ chan->cl->tx_slots_avail_ro--;
if (idx == MBOX_TX_QUEUE_LEN - 1)
chan->msg_free = 0;
@@ -71,6 +72,7 @@ static void msg_submit(struct mbox_chan *chan)
if (!err) {
chan->active_req = data;
chan->msg_count--;
+ chan->cl->tx_slots_avail_ro++;
}
}
@@ -321,6 +323,7 @@ static int __mbox_bind_client(struct mbox_chan *chan, struct mbox_client *cl)
chan->msg_count = 0;
chan->active_req = NULL;
chan->cl = cl;
+ chan->cl->tx_slots_avail_ro = MBOX_TX_QUEUE_LEN;
init_completion(&chan->tx_complete);
if (chan->txdone_method == TXDONE_BY_POLL && cl->knows_txdone)
diff --git a/include/linux/mailbox_client.h b/include/linux/mailbox_client.h
index c6eea9afb943..e867f3d5c89b 100644
--- a/include/linux/mailbox_client.h
+++ b/include/linux/mailbox_client.h
@@ -17,6 +17,7 @@ struct mbox_chan;
* @dev: The client device
* @tx_block: If the mbox_send_message should block until data is
* transmitted.
+ * @tx_slots_avail_ro: msg slots remaining for this client's channel.
* @tx_tout: Max block period in ms before TX is assumed failure
* @knows_txdone: If the client could run the TX state machine. Usually
* if the client receives some ACK packet for transmission.
@@ -29,6 +30,7 @@ struct mbox_chan;
struct mbox_client {
struct device *dev;
bool tx_block;
+ unsigned int tx_slots_avail_ro;
unsigned long tx_tout;
bool knows_txdone;
--
2.34.1
Powered by blists - more mailing lists