From nobody Thu Apr 9 12:21:45 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CD875C433FE for ; Sat, 5 Nov 2022 03:36:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229763AbiKEDgh (ORCPT ); Fri, 4 Nov 2022 23:36:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35424 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229553AbiKEDgf (ORCPT ); Fri, 4 Nov 2022 23:36:35 -0400 Received: from m12-16.163.com (m12-16.163.com [220.181.12.16]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C94103F07A for ; Fri, 4 Nov 2022 20:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=163.com; s=s110527; h=From:Subject:Date:Message-Id:MIME-Version; bh=1TEi5 MrdrPrl+vCS4MMZ/HSJafuRbIvBzswPEFMXVrI=; b=W/9ZkllBwPN8OlaRQ6Swt 5JlYcwlftTruRsVas/1YRPRKFYkBnXMUJLq7lauPb7t7em3E48chW3Sztr0UQqrs NDxopBapS4OGbaSjDsl/cVBO1F3kRdRrqjadrPXBf1tARzlmi36luikFLcteyjKW jBX1vUZozhTTholgLf9Dqs= Received: from m5510.. (unknown [183.192.225.236]) by smtp12 (Coremail) with SMTP id EMCowACHzOU52mVjRn2lAA--.6785S2; Sat, 05 Nov 2022 11:36:26 +0800 (CST) From: jqlhn To: jassisinghbrar@gmail.com Cc: linux-kernel@vger.kernel.org, jqlhn Subject: [PATCH] drivers:mailbox Using kfifo to store buffered message data Date: Sat, 5 Nov 2022 11:36:23 +0800 Message-Id: <20221105033623.259053-1-jqlhn@163.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-CM-TRANSID: EMCowACHzOU52mVjRn2lAA--.6785S2 X-Coremail-Antispam: 1Uf129KBjvJXoWxKr1DWr4rtFy5CF1UJrWfGrg_yoW7GF18pF WaqFy3JFW8Ja15WF4DK3WrZr12q34kuF98C3sxK3WrZr98Cr93Z3WFy3W0qFWDtF47tFy2 93Z5Xrs7CF1DKr7anT9S1TB71UUUUU7qnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x0pEq2NhUUUUU= X-Originating-IP: [183.192.225.236] X-CM-SenderInfo: hmtox0i6rwjhhfrp/1tbiGQywolyPfO6VuwABsp Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" In current mailbox, a self implemented message array to be used as message fifo, I am replacing it with kernel kfifo, in order to make code cleaner. Signed-off-by: jqlhn --- drivers/mailbox/mailbox.c | 33 ++++++++---------------------- drivers/mailbox/omap-mailbox.c | 3 +-- drivers/mailbox/pcc.c | 3 +-- include/linux/mailbox_controller.h | 10 ++++----- 4 files changed, 14 insertions(+), 35 deletions(-) diff --git a/drivers/mailbox/mailbox.c b/drivers/mailbox/mailbox.c index 4229b9b5da98..d738bb472cd0 100644 --- a/drivers/mailbox/mailbox.c +++ b/drivers/mailbox/mailbox.c @@ -25,59 +25,43 @@ static DEFINE_MUTEX(con_mutex); =20 static int add_to_rbuf(struct mbox_chan *chan, void *mssg) { - int idx; unsigned long flags; =20 spin_lock_irqsave(&chan->lock, flags); =20 /* See if there is any space left */ - if (chan->msg_count =3D=3D MBOX_TX_QUEUE_LEN) { + if (kfifo_is_full(&chan->msg_fifo)) { spin_unlock_irqrestore(&chan->lock, flags); return -ENOBUFS; } =20 - idx =3D chan->msg_free; - chan->msg_data[idx] =3D mssg; - chan->msg_count++; - - if (idx =3D=3D MBOX_TX_QUEUE_LEN - 1) - chan->msg_free =3D 0; - else - chan->msg_free++; + kfifo_put(&chan->msg_fifo, mssg); =20 spin_unlock_irqrestore(&chan->lock, flags); =20 - return idx; + return 0; } =20 static void msg_submit(struct mbox_chan *chan) { - unsigned count, idx; unsigned long flags; void *data; int err =3D -EBUSY; =20 spin_lock_irqsave(&chan->lock, flags); =20 - if (!chan->msg_count || chan->active_req) + if (!kfifo_peek(&chan->msg_fifo, &data) || chan->active_req) goto exit; =20 - count =3D chan->msg_count; - idx =3D chan->msg_free; - if (idx >=3D count) - idx -=3D count; - else - idx +=3D MBOX_TX_QUEUE_LEN - count; - - data =3D chan->msg_data[idx]; - if (chan->cl->tx_prepare) chan->cl->tx_prepare(chan->cl, data); /* 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->msg_count--; + /* Get msg out of fifo */ + if (!kfifo_get(&chan->msg_fifo, &data)) + err =3D -ENODATA; } exit: spin_unlock_irqrestore(&chan->lock, flags); @@ -379,8 +363,7 @@ struct mbox_chan *mbox_request_channel(struct mbox_clie= nt *cl, int index) } =20 spin_lock_irqsave(&chan->lock, flags); - chan->msg_free =3D 0; - chan->msg_count =3D 0; + INIT_KFIFO(chan->msg_fifo); chan->active_req =3D NULL; chan->cl =3D cl; init_completion(&chan->tx_complete); diff --git a/drivers/mailbox/omap-mailbox.c b/drivers/mailbox/omap-mailbox.c index 098c82d87137..b392f79e77b3 100644 --- a/drivers/mailbox/omap-mailbox.c +++ b/drivers/mailbox/omap-mailbox.c @@ -443,8 +443,7 @@ struct mbox_chan *omap_mbox_request_channel(struct mbox= _client *cl, =20 chan =3D mbox->chan; spin_lock_irqsave(&chan->lock, flags); - chan->msg_free =3D 0; - chan->msg_count =3D 0; + INIT_KFIFO(chan->msg_fifo); chan->active_req =3D NULL; chan->cl =3D cl; init_completion(&chan->tx_complete); diff --git a/drivers/mailbox/pcc.c b/drivers/mailbox/pcc.c index 3c2bc0ca454c..2359cba8381e 100644 --- a/drivers/mailbox/pcc.c +++ b/drivers/mailbox/pcc.c @@ -297,8 +297,7 @@ pcc_mbox_request_channel(struct mbox_client *cl, int su= bspace_id) dev =3D chan->mbox->dev; =20 spin_lock_irqsave(&chan->lock, flags); - chan->msg_free =3D 0; - chan->msg_count =3D 0; + INIT_KFIFO(chan->msg_fifo); chan->active_req =3D NULL; chan->cl =3D cl; init_completion(&chan->tx_complete); diff --git a/include/linux/mailbox_controller.h b/include/linux/mailbox_con= troller.h index 6fee33cb52f5..b3bec4f33b6d 100644 --- a/include/linux/mailbox_controller.h +++ b/include/linux/mailbox_controller.h @@ -8,6 +8,7 @@ #include #include #include +#include =20 struct mbox_chan; =20 @@ -100,7 +101,7 @@ struct mbox_controller { * REVISIT: If too many platforms see the "Try increasing MBOX_TX_QUEUE_LE= N" * print, it needs to be taken from config option or somesuch. */ -#define MBOX_TX_QUEUE_LEN 20 +#define MBOX_TX_QUEUE_LEN 32 =20 /** * struct mbox_chan - s/w representation of a communication chan @@ -109,9 +110,7 @@ struct mbox_controller { * @cl: Pointer to the current owner of this channel * @tx_complete: Transmission completion * @active_req: Currently active request hook - * @msg_count: No. of mssg currently queued - * @msg_free: Index of next available mssg slot - * @msg_data: Hook for data packet + * @msg_fifo: Hook for data packet * @lock: Serialise access to the channel * @con_priv: Hook for controller driver to attach private data */ @@ -121,8 +120,7 @@ struct mbox_chan { struct mbox_client *cl; struct completion tx_complete; void *active_req; - unsigned msg_count, msg_free; - void *msg_data[MBOX_TX_QUEUE_LEN]; + DECLARE_KFIFO(msg_fifo, void*, MBOX_TX_QUEUE_LEN); spinlock_t lock; /* Serialise access to the channel */ void *con_priv; }; --=20 2.34.1