From nobody Mon Dec 1 23:33:36 2025 Received: from mail-pf1-f201.google.com (mail-pf1-f201.google.com [209.85.210.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EC2C23ABA9 for ; Wed, 26 Nov 2025 05:00:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.201 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764133214; cv=none; b=YaRZcT89KrbBS2nyiYbfiNRwnkqNm3V2fxqI5ZO7QlRrmMBQF+1pzQhgvKa2MHZUcSrSiJsbM902pXr+D0Wj+hC8TY2GEJFs+1UZHlZqbb3xHVF6J6Fy/vZoK++VeyHrAUVEnK5rSjLboiMtBMQPJmkqTGNZI7yD9OUTLV4V+kY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764133214; c=relaxed/simple; bh=qY7CGqZq5D+pdak+niz7FoGsw4UeUsNPYqxsEAXFwTs=; h=Date:Mime-Version:Message-ID:Subject:From:To:Cc:Content-Type; b=KwbLF2YttWKcBBpISYQo4TutjOsKhWP/PgyCOhqQr95yHjGFx+jvAv7eIEtv1QCMknb0UZCOXU/Lxyy1SOfH4pHIJgoNFcairQ8oIqEn7nnLz7x/R9qSX5sHaD3dLKY8Ga22L9KC+hwv0kG1kUZd0xJ/KpggWZ24vIWsfxqrTE4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--joonwonkang.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=YtodiE7q; arc=none smtp.client-ip=209.85.210.201 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--joonwonkang.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="YtodiE7q" Received: by mail-pf1-f201.google.com with SMTP id d2e1a72fcca58-7c240728e2aso13938307b3a.3 for ; Tue, 25 Nov 2025 21:00:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1764133203; x=1764738003; darn=vger.kernel.org; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=J/juGCbZ/9Uuzu3H5VigzEZvME75EcAYx+P652shVyA=; b=YtodiE7qlPhLb1+4H8QiKI70zV9XM6nGym2fcKw7nBlxUocAULM8NxQwmvOdhggwck gA4JsDhi/ssjJuIroARKqpp+nr5kFmL1z+MNQhTrzX7RCVSkyGLZMn1fm+EC0mkCCynO dO6GUTWnP0vqIfSFf3k+9Rfzk/5nb/0VPtiFhnAzT+FqPP8L4uKwnE4uBV2WU1PX8262 nHY2R+S1sM6sAdNH457vN34IU+RM3O5UOBKHSXFjqNGPMVYPUIUiYF2xWewTsuCZXtFM EhVsIw/jLRTPhN8xC7YExyu4i7bVliDS3eDfK63lLh9YpkM1ArPPJN9jRQMNR5CgZia6 XeVw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764133203; x=1764738003; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=J/juGCbZ/9Uuzu3H5VigzEZvME75EcAYx+P652shVyA=; b=tXMxV3+GjPYpYGXgi9ciLqUxnYaOpVTC5v/DONiVmqEpBDKV/VRd23raBuy7IiLJ+R syf0nj9kj3U2i4WvlY2CKimCJxjWaBE9bGWFbiY5W/Cbzii8quubsTavMBFB7ldIAP8n GHT+iOMNbDq+cPHOanZtXoDAS3TbI6m6o9YqCUNDS67sYwW7Fw1PsWsBz+P8nVPS1X8r 4sbnZ9OR/F1FL5LUSTo3UKsbx2XCrwMUUo5cdft3Zth+TDbgtu7Q/V22PfBmu/wDXR6Z 9+7rxhySr9wZCK6yXKlPZbyqfOUus/qnDXJ4jTLV3vvLle7EXoACvMDJAH5IGcfNI4vl uh3A== X-Forwarded-Encrypted: i=1; AJvYcCXB6sBDaDdxRWoxoH4E3VkeSh8n3FTPiEVyR7ViKRaE7Ic6JxpRN8Qm+ZLeEkt46x5N//hJfiGRD+ybzUM=@vger.kernel.org X-Gm-Message-State: AOJu0Yy6+IqpNMNfU6hjopXuVjx2yh8jzvBEYqXoGnetxPm74fMl56fh KVA/09NjJYuYgKqXr/tLQLn2+92S3PoSLpnQgOIayURRTFVsYeIDTTwCu91Wig1KKjaIdWwf5BP 8u/F54um3wTfotuGOb8NMx7csrw== X-Google-Smtp-Source: AGHT+IEjIfllpY5QsS9v9/lsZrJKZN3Ql+At1NtEBWETULFj6ZCOMj4jkAX45mcXeXXTlO4DApQNJKigjVeCiGBQPQ== X-Received: from pfiy2.prod.google.com ([2002:a05:6a00:1902:b0:781:20d1:845f]) (user=joonwonkang job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a20:e211:b0:35e:f436:ffba with SMTP id adf61e73a8af0-3614eaf586fmr20422522637.6.1764133203017; Tue, 25 Nov 2025 21:00:03 -0800 (PST) Date: Wed, 26 Nov 2025 04:59:26 +0000 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 X-Mailer: git-send-email 2.52.0.487.g5c8c507ade-goog Message-ID: <20251126045926.2413532-1-joonwonkang@google.com> Subject: [PATCH] mailbox: Allow NULL message sending From: Joonwon Kang To: jassisinghbrar@gmail.com Cc: sudeep.holla@arm.com, thierry.reding@gmail.com, jonathanh@nvidia.com, linux-kernel@vger.kernel.org, Joonwon Kang Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Clients may want to send interrupt only without any useful message involved. Since the current mailbox framework does not allow NULL message sending(although it allows receiving it), the clients should allocate a dummy message buffer and pretend sending it. Besides, if the mailbox controller calls `mbox_chan_txdone()` when the client drivers happen to send NULL message anyway, it will result in unexpected results by making the tx status messed up. This commit lifts the limitation and allows the clients to send interrupt only without any message buffer allocated. Signed-off-by: Joonwon Kang --- drivers/mailbox/mailbox.c | 20 ++++++++++++-------- drivers/mailbox/pcc.c | 6 +++--- drivers/mailbox/tegra-hsp.c | 2 +- include/linux/mailbox_controller.h | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 2acc6ec229a4..0007a023112c 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -52,7 +52,7 @@ static void msg_submit(struct mbox_chan *chan) int err =3D -EBUSY; =20 scoped_guard(spinlock_irqsave, &chan->lock) { - if (!chan->msg_count || chan->active_req) + if (!chan->msg_count || chan->active_req >=3D 0) break; =20 count =3D chan->msg_count; @@ -69,7 +69,7 @@ static void msg_submit(struct mbox_chan *chan) /* Try to submit a message to the MBOX controller */ err =3D chan->mbox->ops->send_data(chan, data); if (!err) { - chan->active_req =3D data; + chan->active_req =3D idx; chan->msg_count--; } } @@ -83,17 +83,21 @@ static void msg_submit(struct mbox_chan *chan) =20 static void tx_tick(struct mbox_chan *chan, int r) { + int idx; void *mssg; =20 scoped_guard(spinlock_irqsave, &chan->lock) { - mssg =3D chan->active_req; - chan->active_req =3D NULL; + idx =3D chan->active_req; + if (idx >=3D 0) { + mssg =3D chan->msg_data[idx]; + chan->active_req =3D -1; + } } =20 /* Submit next message */ msg_submit(chan); =20 - if (!mssg) + if (idx < 0) return; =20 /* Notify the client */ @@ -114,7 +118,7 @@ static enum hrtimer_restart txdone_hrtimer(struct hrtim= er *hrtimer) for (i =3D 0; i < mbox->num_chans; i++) { struct mbox_chan *chan =3D &mbox->chans[i]; =20 - if (chan->active_req && chan->cl) { + if (chan->active_req >=3D 0 && chan->cl) { txdone =3D chan->mbox->ops->last_tx_done(chan); if (txdone) tx_tick(chan, 0); @@ -319,7 +323,7 @@ static int __mbox_bind_client(struct mbox_chan *chan, s= truct mbox_client *cl) scoped_guard(spinlock_irqsave, &chan->lock) { chan->msg_free =3D 0; chan->msg_count =3D 0; - chan->active_req =3D NULL; + chan->active_req =3D -1; chan->cl =3D cl; init_completion(&chan->tx_complete); =20 @@ -477,7 +481,7 @@ void mbox_free_channel(struct mbox_chan *chan) /* The queued TX requests are simply aborted, no callbacks are made */ scoped_guard(spinlock_irqsave, &chan->lock) { chan->cl =3D NULL; - chan->active_req =3D NULL; + chan->active_req =3D -1; if (chan->txdone_method =3D=3D TXDONE_BY_ACK) chan->txdone_method =3D TXDONE_BY_POLL; } diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c index 0a00719b2482..7eca06d5ecf6 100644 --- a/drivers/mailbox/pcc.c +++ b/drivers/mailbox/pcc.c @@ -333,7 +333,7 @@ static irqreturn_t pcc_mbox_irq(int irq, void *p) { struct pcc_chan_info *pchan; struct mbox_chan *chan =3D p; - struct pcc_header *pcc_header =3D chan->active_req; + struct pcc_header *pcc_header =3D NULL; void *handle =3D NULL; =20 pchan =3D chan->con_priv; @@ -362,8 +362,8 @@ static irqreturn_t pcc_mbox_irq(int irq, void *p) if (pchan->chan.rx_alloc) handle =3D write_response(pchan); =20 - if (chan->active_req) { - pcc_header =3D chan->active_req; + if (chan->active_req >=3D 0) { + pcc_header =3D chan->msg_data[chan->active_req]; if (pcc_header->flags & PCC_CMD_COMPLETION_NOTIFY) mbox_chan_txdone(chan, 0); } diff --git a/drivers/mailbox/tegra-hsp.c b/drivers/mailbox/tegra-hsp.c index ed9a0bb2bcd8..de7494ce0a9f 100644 --- a/drivers/mailbox/tegra-hsp.c +++ b/drivers/mailbox/tegra-hsp.c @@ -497,7 +497,7 @@ static int tegra_hsp_mailbox_flush(struct mbox_chan *ch= an, mbox_chan_txdone(chan, 0); =20 /* Wait until channel is empty */ - if (chan->active_req !=3D NULL) + if (chan->active_req >=3D 0) continue; =20 return 0; diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_con= troller.h index 80a427c7ca29..230d2669861d 100644 --- a/include/linux/mailbox_controller.h +++ b/include/linux/mailbox_controller.h @@ -123,7 +123,7 @@ struct mbox_chan { unsigned txdone_method; struct mbox_client *cl; struct completion tx_complete; - void *active_req; + int active_req; unsigned msg_count, msg_free; void *msg_data[MBOX_TX_QUEUE_LEN]; spinlock_t lock; /* Serialise access to the channel */ --=20 2.52.0.487.g5c8c507ade-goog