Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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>

+24
+23
drivers/mailbox/mailbox.c
··· 219 219 EXPORT_SYMBOL_GPL(mbox_client_peek_data); 220 220 221 221 /** 222 + * mbox_chan_tx_slots_available - Query the number of available TX queue slots. 223 + * @chan: Mailbox channel to query. 224 + * 225 + * Clients may call this to check how many messages can be queued via 226 + * mbox_send_message() before the channel's TX queue is full. This helps 227 + * clients avoid the -ENOBUFS error without needing to increase 228 + * MBOX_TX_QUEUE_LEN. 229 + * This can be called from atomic context. 230 + * 231 + * Return: Number of available slots in the channel's TX queue. 232 + */ 233 + unsigned int mbox_chan_tx_slots_available(struct mbox_chan *chan) 234 + { 235 + unsigned int ret; 236 + 237 + guard(spinlock_irqsave)(&chan->lock); 238 + ret = MBOX_TX_QUEUE_LEN - chan->msg_count; 239 + 240 + return ret; 241 + } 242 + EXPORT_SYMBOL_GPL(mbox_chan_tx_slots_available); 243 + 244 + /** 222 245 * mbox_send_message - For client to submit a message to be 223 246 * sent to the remote. 224 247 * @chan: Mailbox channel assigned to this client.
+1
include/linux/mailbox_client.h
··· 45 45 int mbox_flush(struct mbox_chan *chan, unsigned long timeout); 46 46 void mbox_client_txdone(struct mbox_chan *chan, int r); /* atomic */ 47 47 bool mbox_client_peek_data(struct mbox_chan *chan); /* atomic */ 48 + unsigned int mbox_chan_tx_slots_available(struct mbox_chan *chan); /* atomic */ 48 49 void mbox_free_channel(struct mbox_chan *chan); /* may sleep */ 49 50 50 51 #endif /* __MAILBOX_CLIENT_H */