mailbox: add API to query available TX queue slots
Clients sometimes need to know whether the mailbox TX queue has room before posting a new message. Rather than exposing internal queue state through a struct field, provide a proper accessor function that returns the number of available slots for a given channel. This lets clients choose to back off when the queue is full instead of hitting the -ENOBUFS error path and the misleading "Try increasing MBOX_TX_QUEUE_LEN" warning. Tested-by: Tanmay Shah <tanmay.shah@amd.com> Signed-off-by: Jassi Brar <jassisinghbrar@gmail.com>master
parent
11439c4635
commit
57df858a46
|
|
@ -218,6 +218,29 @@ bool mbox_client_peek_data(struct mbox_chan *chan)
|
|||
}
|
||||
EXPORT_SYMBOL_GPL(mbox_client_peek_data);
|
||||
|
||||
/**
|
||||
* mbox_chan_tx_slots_available - Query the number of available TX queue slots.
|
||||
* @chan: Mailbox channel to query.
|
||||
*
|
||||
* Clients may call this to check how many messages can be queued via
|
||||
* mbox_send_message() before the channel's TX queue is full. This helps
|
||||
* clients avoid the -ENOBUFS error without needing to increase
|
||||
* MBOX_TX_QUEUE_LEN.
|
||||
* This can be called from atomic context.
|
||||
*
|
||||
* Return: Number of available slots in the channel's TX queue.
|
||||
*/
|
||||
unsigned int mbox_chan_tx_slots_available(struct mbox_chan *chan)
|
||||
{
|
||||
unsigned int ret;
|
||||
|
||||
guard(spinlock_irqsave)(&chan->lock);
|
||||
ret = MBOX_TX_QUEUE_LEN - chan->msg_count;
|
||||
|
||||
return ret;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(mbox_chan_tx_slots_available);
|
||||
|
||||
/**
|
||||
* mbox_send_message - For client to submit a message to be
|
||||
* sent to the remote.
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ int mbox_send_message(struct mbox_chan *chan, void *mssg);
|
|||
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 */
|
||||
unsigned int mbox_chan_tx_slots_available(struct mbox_chan *chan); /* atomic */
|
||||
void mbox_free_channel(struct mbox_chan *chan); /* may sleep */
|
||||
|
||||
#endif /* __MAILBOX_CLIENT_H */
|
||||
|
|
|
|||
Loading…
Reference in New Issue