From patchwork Fri Oct 4 22:12:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Chen X-Patchwork-Id: 13823056 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3E256CF8853 for ; Fri, 4 Oct 2024 22:14:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=Z5i2tvARMEKs1BcO4Ftg1r7i2RWQdz+ikPGPGd5oFEA=; b=uMZqYhOWcqAI0aX2EOmKKhX84I C7yjpJaLlh4y35lUyIDUQJGJ+QOVro4fBfdZtXZI+GXyDxUsxMJpj+88fPcMNLKP5JO+bp197kCO/ RXA7E59pWMxR5cplyu2hUnvw3RfxGHu76/7YJ0Ns73QLdRmhzdwpi+kiXKi7St/IcJ64EcGCqHKQ9 u9umo+CnMzJzO9pkPrVrKzrxwDyEYgrWa2d6CyxZvdvlF3jrSnH0ZlvCCONdWYT2PeCd7J3F9FCjq 518vZ2NxzD/mD5yEYUSNEOjADxKTvpuH1AxMy4xGFu5YKdCdEl8qJFmG3Hv98odK4A97niHdU7esO wd8XcHOQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1swqZ3-0000000ELJm-0Sxe; Fri, 04 Oct 2024 22:14:21 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1swqXm-0000000ELED-0pq3 for linux-arm-kernel@lists.infradead.org; Fri, 04 Oct 2024 22:13:04 +0000 Received: by mail-pl1-x635.google.com with SMTP id d9443c01a7336-20b93887decso22415405ad.3 for ; Fri, 04 Oct 2024 15:13:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1728079980; x=1728684780; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Z5i2tvARMEKs1BcO4Ftg1r7i2RWQdz+ikPGPGd5oFEA=; b=KfeFS64xd96BYAKB1xqO5GQ6ztbgKrg3nR6WX9ZfppkpfeoMF5K+GxMOZq+t5sLsIQ ruvOWiCsfp2npY6PBprPAYcbcfQUSMa2JKA2p2oB/Er0ffNdZ3zTxrxIyc3zWV5LTECj yMoe730ioYrYnnx4MrzjmbDSthGdpL+hsDgUs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728079980; x=1728684780; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Z5i2tvARMEKs1BcO4Ftg1r7i2RWQdz+ikPGPGd5oFEA=; b=u7bbBqWJjLxQvVXE2f12goiqq430jNbj1OSiIpyPBpkKfbY83661sq/An+pv3E6IWH ZTfyh290dYr7PG5I+44FIcHSsy3KBWm80CspkFKKTfQ+iJSRofBZRENh09la3os+yAZd 7DzNaDeuyqumfZQKeqXDrtIMuOAlyrt3gIbxRfb12G2Q7mWeW1SU8MqqbP98YiaFPoj8 aasjUPeSaAaHRXC7/s2S2TjqGheNE4jDcOcNUDrC92VOrw4LSb8TRyoypjaZZKbN548R SX3TK5FDNopjY2FHImeEvGQHlNdDgl74po+0rNXiblm5AqYoAl1I+GvA0BqRt63tH8gq kZCA== X-Gm-Message-State: AOJu0YxcmjzYpvCogsQKxcWjZi0TGAzKVKBCmW66AWjgfRzucMCunlYT 5vQXbRhkKO9vssnCJLl7H/ccslqwlr2GAlk5JYJwoHNUqmDOGcbaWEimBV5wNA== X-Google-Smtp-Source: AGHT+IEKg9l8YjuKcXZKUA+ZP6ePVAkCGioCnkA0fIpSBEqrQXBWAbJ1u+ngE0FbeYvWh5Ra6p0JIA== X-Received: by 2002:a17:90a:de83:b0:2d8:c17b:5018 with SMTP id 98e67ed59e1d1-2e1e62275d9mr4960982a91.11.1728079980476; Fri, 04 Oct 2024 15:13:00 -0700 (PDT) Received: from stbirv-lnx-1.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7e9f6c37515sm404734a12.75.2024.10.04.15.12.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Oct 2024 15:13:00 -0700 (PDT) From: Justin Chen To: arm-scmi@vger.kernel.org, cristian.marussi@arm.com, sudeep.holla@arm.com Cc: linux-arm-kernel@lists.infradead.org, peng.fan@nxp.com, bcm-kernel-feedback-list@broadcom.com, florian.fainelli@broadcom.com, Justin Chen Subject: [PATCH] firmware: arm_scmi: Queue in scmi layer for mailbox implementation Date: Fri, 4 Oct 2024 15:12:57 -0700 Message-Id: <20241004221257.2888603-1-justin.chen@broadcom.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241004_151302_450539_948CDECC X-CRM114-Status: GOOD ( 16.43 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org The mailbox layer has its own queue. However this confuses the per message timeouts since the clock starts ticking the moment the messages get queued up. So all messages in the queue have there timeout clocks ticking instead of only the message inflight. To fix this, lets move the queue back into the SCMI layer. Signed-off-by: Justin Chen --- .../firmware/arm_scmi/transports/mailbox.c | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/drivers/firmware/arm_scmi/transports/mailbox.c b/drivers/firmware/arm_scmi/transports/mailbox.c index 1a754dee24f7..30bc2865582f 100644 --- a/drivers/firmware/arm_scmi/transports/mailbox.c +++ b/drivers/firmware/arm_scmi/transports/mailbox.c @@ -33,6 +33,7 @@ struct scmi_mailbox { struct mbox_chan *chan_platform_receiver; struct scmi_chan_info *cinfo; struct scmi_shared_mem __iomem *shmem; + struct mutex chan_lock; }; #define client_to_scmi_mailbox(c) container_of(c, struct scmi_mailbox, cl) @@ -205,6 +206,7 @@ static int mailbox_chan_setup(struct scmi_chan_info *cinfo, struct device *dev, cl->rx_callback = rx_callback; cl->tx_block = false; cl->knows_txdone = tx; + mutex_init(&smbox->chan_lock); smbox->chan = mbox_request_channel(cl, tx ? 0 : p2a_chan); if (IS_ERR(smbox->chan)) { @@ -267,11 +269,21 @@ static int mailbox_send_message(struct scmi_chan_info *cinfo, struct scmi_mailbox *smbox = cinfo->transport_info; int ret; + /* + * The mailbox layer has it's own queue. However the mailbox queue confuses + * the per message SCMI timeouts since the clock starts when the message is + * submitted into the mailbox queue. So when multiple messages are queued up + * the clock starts on all messages instead of only the one inflight. + */ + mutex_lock(&smbox->chan_lock); + ret = mbox_send_message(smbox->chan, xfer); /* mbox_send_message returns non-negative value on success, so reset */ if (ret > 0) ret = 0; + else + mutex_unlock(&smbox->chan_lock); return ret; } @@ -281,13 +293,10 @@ static void mailbox_mark_txdone(struct scmi_chan_info *cinfo, int ret, { struct scmi_mailbox *smbox = cinfo->transport_info; - /* - * NOTE: we might prefer not to need the mailbox ticker to manage the - * transfer queueing since the protocol layer queues things by itself. - * Unfortunately, we have to kick the mailbox framework after we have - * received our message. - */ mbox_client_txdone(smbox->chan, ret); + + /* Release channel */ + mutex_unlock(&smbox->chan_lock); } static void mailbox_fetch_response(struct scmi_chan_info *cinfo,