[PATCH] mailbox: tegra-hsp: Reuse doorbell slots after failed startup

From: Jiangtian Feng

Date: Thu Dec 03 2026 - 04:30:10 EST


A failed startup leaves the HSP channel and con_priv bound after
mailbox core clears the client. The next xlate skips that stale slot
and allocates a new one, so repeated failures can eventually exhaust
all 32 doorbell channels.

Reuse the existing slot when it has no live client instead of scanning
for another one. Active clients are still rejected with -EBUSY, and a
slot released by a failed startup or normal free remains available for
the next request.

Also restore MBOX_TXDONE_BY_ACK during startup. Generic channel cleanup
changes ACK to POLL, but doorbell clients expect their original ACK mode
and do not initialize polling. Reusing a slot without this restoration
would break subsequent message submission and TX-done handling.

Qoder, an AI coding assistant, helped analyze the failed-startup slot
lifetime and draft this change and description. The submitter reviewed
the change and is responsible for final validation.

Fixes: 0fe88461a0ec ("mailbox: Add Tegra HSP driver")
Signed-off-by: Jiangtian Feng <jiangtianfeng@xxxxxxxxxxxxxxxxx>
---
drivers/mailbox/tegra-hsp.c | 14 +++++++++++---
1 file changed, 11 insertions(+), 3 deletions(-)

diff --git a/drivers/mailbox/tegra-hsp.c b/drivers/mailbox/tegra-hsp.c
index 7902af16433c..30688761eff5 100644
--- a/drivers/mailbox/tegra-hsp.c
+++ b/drivers/mailbox/tegra-hsp.c
@@ -337,6 +337,8 @@ static int tegra_hsp_doorbell_startup(struct mbox_chan *chan)
if (tegra_is_silicon() && !tegra_hsp_doorbell_can_ring(db))
return -ENODEV;

+ chan->txdone_method = MBOX_TXDONE_BY_ACK;
+
spin_lock_irqsave(&hsp->lock, flags);

value = tegra_hsp_channel_readl(&ccplex->channel, HSP_DB_ENABLE);
@@ -609,9 +611,14 @@ static struct mbox_chan *tegra_hsp_db_xlate(struct mbox_controller *mbox,
spin_lock_irqsave(&hsp->lock, flags);

/* A failed startup has no live client and may be retried. */
- if (channel->chan && channel->chan->cl) {
- spin_unlock_irqrestore(&hsp->lock, flags);
- return ERR_PTR(-EBUSY);
+ if (channel->chan) {
+ if (channel->chan->cl) {
+ spin_unlock_irqrestore(&hsp->lock, flags);
+ return ERR_PTR(-EBUSY);
+ }
+
+ chan = channel->chan;
+ goto out;
}

for (i = 0; i < mbox->num_chans; i++) {
@@ -625,6 +632,7 @@ static struct mbox_chan *tegra_hsp_db_xlate(struct mbox_controller *mbox,
chan = NULL;
}

+out:
spin_unlock_irqrestore(&hsp->lock, flags);

return chan ?: ERR_PTR(-EBUSY);
--
2.47.3