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 28C9CD1812A for ; Mon, 14 Oct 2024 16:14:33 +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: Content-Type:In-Reply-To:From:References:Cc:To:Subject:MIME-Version:Date: Message-ID:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=swAPbf29tjWH1ew+gbmEv7orYMapgBFTnu7Bf2gHdR8=; b=aCE2Sel5Kn6YSelwh74cHvyLKT eRhA8M58cIedt5C0cdKwiUWS7j0afsmzM6DJgrm9gwaVO8zjG1L9dFaId7XZSfWDRg7HvonOaQChy B1/QMwDL96o7aGTLgkJw8thW2OzRc3QVlQcJIogx2x9+g3iESubCCkypXTsgAPFX3XlRc9tpaW+u4 GLnfS3NHJcRbmTK2yQLee7YhYTWpo2FAIkh6LFk2Tvjb1mVdxAc2q/vVTsSgkCpcIyew4InJEaJgQ g9LvOAmAMH6sPc6y0kgoO1LUDAoo6nZ9MbrJvl3icINYD9K1m8lU9J950V7MQGdi9tzwgWIe43Iw3 rd4n9xMA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1t0Ni8-00000005pNM-3fCw; Mon, 14 Oct 2024 16:14:21 +0000 Received: from mail-qv1-xf2e.google.com ([2607:f8b0:4864:20::f2e]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1t0Ngi-00000005p2F-2ip6 for linux-arm-kernel@lists.infradead.org; Mon, 14 Oct 2024 16:12:54 +0000 Received: by mail-qv1-xf2e.google.com with SMTP id 6a1803df08f44-6cbd00dd21cso29420186d6.3 for ; Mon, 14 Oct 2024 09:12:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; t=1728922371; x=1729527171; darn=lists.infradead.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=swAPbf29tjWH1ew+gbmEv7orYMapgBFTnu7Bf2gHdR8=; b=E5kgjCVKu4aMD2xF4FHdP/uvC0v5Vq5+AnC58NVEEc5WpizrbHS1pu8dWsdzBsmGMA +KzQkPDCN3uEMnWPEmG6tw6qn0eXWyZcItdpAddun+kniAS7PJm/WftMcSG7vWcjAJFU zwlJvhmQ/l0+wdK1nRcpV6W2HXWSZVUecvWtQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728922371; x=1729527171; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=swAPbf29tjWH1ew+gbmEv7orYMapgBFTnu7Bf2gHdR8=; b=LgjdiXfwHB4dCUzGfgpXO0VH1JsiGAfwypSn0ZdNQomfnHDPDJwXusp7IdlyfJWdYA 2HwgL42oYZuqR7tT9j2Pxgo6vs5K1SmHZL5mB8CoVjW+PJrCPaEf4hdovjOW3Eb7dbdW TtgOVn31OwgUN6HRtt/xIxlwI4d5Sz/sk5KaXa1jJQeQ//x4Sj5EiVFUpCn00ZhZ6E2F R0fI6EceO71Vgm4b+g9Km15a2b0uRX1r70syJSdbVY8L+D7jd2YyRWOT39szbbzzMy7p 0eogSSYYUKG7XA/gcyH2BgZ7IVNy7JH6cAfn5LJha8/OTMcyPXEZcprlleyM7WNFsPrb HHTg== X-Gm-Message-State: AOJu0Yx2iTjo8NZWiUavHcfw+wSCbkSHmhb/3vy8b5AElK2B6cxaAOvb Y9Lerm4meSl0gz5GcDw/D6VSjYtfUo839LXwTid4rY38DOS4JV+9Ro0fjOQqH2Sa/2PU2CH8/FP 0kNgWPFN6I7IHs+It4JuYbtDzIg7HJivPIHG20IUR2cwT79Zn01mIpIsy4AZQlaRDiVgc/UQIsF +7Y5xruhx5ZAFzpO+W+vU+uy1d3HjYarh26jpschat2ORp1rhi8jX7lApK5GdI X-Google-Smtp-Source: AGHT+IGxqBCDV91awxpxSHlWuJLyB0vVtzW3+IefZHcpr084z0GQDTMALqAKkmXV/vA7dFUIHMJwnA== X-Received: by 2002:a05:6214:2b93:b0:6cb:c487:24b7 with SMTP id 6a1803df08f44-6cbf00f2606mr190917106d6.37.1728922371310; Mon, 14 Oct 2024 09:12:51 -0700 (PDT) Received: from [10.230.29.59] ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6cbe860b783sm47009836d6.83.2024.10.14.09.12.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 14 Oct 2024 09:12:50 -0700 (PDT) Message-ID: <2ab0d7ad-e5a6-4310-b3a9-df494e9bf710@broadcom.com> Date: Mon, 14 Oct 2024 09:12:48 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] firmware: arm_scmi: Queue in scmi layer for mailbox implementation To: linux-arm-kernel@lists.infradead.org Cc: viresh.kumar@linaro.org, peng.fan@nxp.com, cristian.marussi@arm.com, sudeep.holla@arm.com, florian.fainelli@broadcom.com, bcm-kernel-feedback-list@broadcom.com References: <20241014160717.1678953-1-justin.chen@broadcom.com> Content-Language: en-US From: Justin Chen In-Reply-To: <20241014160717.1678953-1-justin.chen@broadcom.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20241014_091252_726262_25FC7ABD X-CRM114-Status: GOOD ( 30.01 ) 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 On 10/14/24 9:07 AM, Justin Chen wrote: > send_message() does not block in the MBOX implementation. This is > because the mailbox layer has its own queue. However, this confuses > the per xfer timeouts as they all start their timeout ticks in > parallel. > > Consider a case where the xfer timeout is 30ms and a SCMI transaction > takes 25ms. > > 0ms: Message #0 is queued in mailbox layer and sent out, then sits > at scmi_wait_for_message_response() with a timeout of 30ms > 1ms: Message #1 is queued in mailbox layer but not sent out yet. > Since send_message() doesn't block, it also sits at > scmi_wait_for_message_response() with a timeout of 30ms > ... > 25ms: Message #0 is completed, txdone is called and Message #1 is > sent out > 31ms: Message #1 times out since the count started at 1ms. Even > though it has only been inflight for 6ms. > > Fixes: 5c8a47a5a91d ("firmware: arm_scmi: Make scmi core independent of the transport type") > Signed-off-by: Justin Chen Woops forgot to add these. Reviewed-by: Cristian Marussi Tested-by: Cristian Marussi > --- > > Changes in v3: > - Changed Fixes tag > - Fixed mutex imbalance > - Add Doxygen comment > - Fixed spelling mistake > - Moved mutex init > > Changes in v2 > - Added Fixes tag > - Improved commit message to better capture the issue > > .../firmware/arm_scmi/transports/mailbox.c | 28 +++++++++++++------ > 1 file changed, 19 insertions(+), 9 deletions(-) > > diff --git a/drivers/firmware/arm_scmi/transports/mailbox.c b/drivers/firmware/arm_scmi/transports/mailbox.c > index 1a754dee24f7..af08fb5cc72f 100644 > --- a/drivers/firmware/arm_scmi/transports/mailbox.c > +++ b/drivers/firmware/arm_scmi/transports/mailbox.c > @@ -25,6 +25,7 @@ > * @chan_platform_receiver: Optional Platform Receiver mailbox unidirectional channel > * @cinfo: SCMI channel info > * @shmem: Transmit/Receive shared memory area > + * @chan_lock: Lock that prevents multiple xfers from being queued > */ > struct scmi_mailbox { > struct mbox_client cl; > @@ -33,6 +34,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) > @@ -238,6 +240,7 @@ static int mailbox_chan_setup(struct scmi_chan_info *cinfo, struct device *dev, > > cinfo->transport_info = smbox; > smbox->cinfo = cinfo; > + mutex_init(&smbox->chan_lock); > > return 0; > } > @@ -267,13 +270,23 @@ static int mailbox_send_message(struct scmi_chan_info *cinfo, > struct scmi_mailbox *smbox = cinfo->transport_info; > int ret; > > + /* > + * The mailbox layer has its 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; > + if (ret < 0) { > + mutex_unlock(&smbox->chan_lock); > + return ret; > + } > > - return ret; > + return 0; > } > > static void mailbox_mark_txdone(struct scmi_chan_info *cinfo, int ret, > @@ -281,13 +294,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,