From nobody Mon Apr 13 12:05:33 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 1B01CC678D5 for ; Tue, 7 Mar 2023 20:23:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231871AbjCGUXs (ORCPT ); Tue, 7 Mar 2023 15:23:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231829AbjCGUX3 (ORCPT ); Tue, 7 Mar 2023 15:23:29 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EFAC8699 for ; Tue, 7 Mar 2023 12:23:28 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0C4EDB81A1D for ; Tue, 7 Mar 2023 20:23:27 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5EDA2C433A1; Tue, 7 Mar 2023 20:23:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678220605; bh=x+8F7ELtsW/BQB3u+HCi4ETUUZR7Hhz1aXJMSp6UPQU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZtZSFRIoN3Dk9IaS71f+Vi0gbcEz/eCmHEBigAl8IcconSATVF61MN1GhhQwkCitD jAY7f2olbsMcii5YlQxr0YWpqHPD4jS8CFiFI7mnCRkDIh4GzVGOR+BatsULKGv8mA 4Wc9BKdAy1ecelH2XuJoO9v8cNesJSTEa9Bf2MeeOuSBdsZdZUVKjtJ7ed1HzRHX0Q Q1g5o4gHW6LZpwsZQjAPwS5k9KWTMWndaYBkaU2i8p6hUbp+xxyPzp1mnTl3qgADlM 49SwhSxnJUtPSOJmUpUna9vm2yoeTzv/n/K+YsOKZ3FxQhQXQy5Smzy94n1owWRP1D MdgXM/P2+3opw== From: Conor Dooley To: linux-riscv@lists.infradead.org Cc: conor@kernel.org, Conor Dooley , Daire McNamara , Jassi Brar , linux-kernel@vger.kernel.org Subject: [PATCH v3 1/8] mailbox: mpfs: fix an incorrect mask width Date: Tue, 7 Mar 2023 20:22:51 +0000 Message-Id: <20230307202257.1762151-2-conor@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307202257.1762151-1-conor@kernel.org> References: <20230307202257.1762151-1-conor@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1509; i=conor.dooley@microchip.com; h=from:subject; bh=N+Fmo03qeVhPTJ2ouN+nX4YhvmUTQ6mGrE0sJhfEG04=; b=owGbwMvMwCFWscWwfUFT0iXG02pJDCnsc4XOqS91dHS5c+zaHbc75y70ZwR90D7jPWPBYbuAJ f0ua98ZdZSyMIhxMMiKKbIk3u5rkVr/x2WHc89bmDmsTCBDGLg4BWAiH28w/LP80GRfqdDw5M7R GT++qmY5eUXd2nfWRmRK1uO5qVqizCUM/1Nzv7fZZxQuf6hqa2HZ0rDrf+Tyu5xXzqeo6vq357z 7zgEA X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Conor Dooley The system controller registers on PolarFire SoC are 32 bits wide, so 16 + 16 as the first input to GENMASK_ULL() gives a 33 bit wide mask. It probably should have been immediately obvious when it was pointed out during review that the width required using GENMASK_ULL() - but I scarcely knew what I was doing at the time and missed it. The mistake ends up being moot as it is a mask after all, but it is incorrect and should be fixed. No functional change intended. Signed-off-by: Conor Dooley Tested-by: Valentina Fernandez --- drivers/mailbox/mailbox-mpfs.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/mailbox/mailbox-mpfs.c b/drivers/mailbox/mailbox-mpfs.c index 853901acaeec..d37560e91116 100644 --- a/drivers/mailbox/mailbox-mpfs.c +++ b/drivers/mailbox/mailbox-mpfs.c @@ -39,7 +39,7 @@ #define SCB_CTRL_NOTIFY_MASK BIT(SCB_CTRL_NOTIFY) =20 #define SCB_CTRL_POS (16) -#define SCB_CTRL_MASK GENMASK_ULL(SCB_CTRL_POS + SCB_MASK_WIDTH, SCB_CTRL_= POS) +#define SCB_CTRL_MASK GENMASK(SCB_CTRL_POS + SCB_MASK_WIDTH - 1, SCB_CTRL_= POS) =20 /* SCBCTRL service status register */ =20 @@ -118,6 +118,7 @@ static int mpfs_mbox_send_data(struct mbox_chan *chan, = void *data) } =20 opt_sel =3D ((msg->mbox_offset << 7u) | (msg->cmd_opcode & 0x7fu)); + tx_trigger =3D (opt_sel << SCB_CTRL_POS) & SCB_CTRL_MASK; tx_trigger |=3D SCB_CTRL_REQ_MASK | SCB_STATUS_NOTIFY_MASK; writel_relaxed(tx_trigger, mbox->ctrl_base + SERVICES_CR_OFFSET); --=20 2.39.2 From nobody Mon Apr 13 12:05:33 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 11AA8C6FA99 for ; Tue, 7 Mar 2023 20:24:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230467AbjCGUX7 (ORCPT ); Tue, 7 Mar 2023 15:23:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36730 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231205AbjCGUXb (ORCPT ); Tue, 7 Mar 2023 15:23:31 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06B6F149BC for ; Tue, 7 Mar 2023 12:23:30 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id B7CD0B81A13 for ; Tue, 7 Mar 2023 20:23:28 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 28EA2C4339E; Tue, 7 Mar 2023 20:23:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678220607; bh=sx9Ska8GnWbf3HJSlVgv4lIynyLqn9kogPDu8a552jI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HATc+3nZBgpYA7WxgcsLrrwNmWlMvHUUg0l8blmDSDPZMlvnW+Td0ZVFQJk+Bj0k8 AhHpJZw7SDYavoRNPxGJEiXx+j2kTT3jMLN3kz1APKIcIwmEQ9lwbmmckGaJ9NnXk7 ABwuO8G502gOeWuFDtWt12zFs0qMFc+HVEaQ107uRW1AOzg4IF5t3+gL/iVvi+yZ3N N9UOknTK1+HpIcBick8jlK4gP49QeYT5vE28RkRbNYrhtLTw8iMQzhgebFwB+EX8W1 8HTVZbDsAX1Y1SsBd9CSIL1lQ2eab++Y404P4Sy8rHmwYRYL4bRWx0dvr7YVOcGsQT a8I8o8pzvnZLg== From: Conor Dooley To: linux-riscv@lists.infradead.org Cc: conor@kernel.org, Conor Dooley , Daire McNamara , Jassi Brar , linux-kernel@vger.kernel.org Subject: [PATCH v3 2/8] mailbox: mpfs: switch to txdone_poll Date: Tue, 7 Mar 2023 20:22:52 +0000 Message-Id: <20230307202257.1762151-3-conor@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307202257.1762151-1-conor@kernel.org> References: <20230307202257.1762151-1-conor@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=2089; i=conor.dooley@microchip.com; h=from:subject; bh=pqrvE31Z8S43X6j0wjeGX8SFR94cn2rhVr8RYJQR2+M=; b=owGbwMvMwCFWscWwfUFT0iXG02pJDCnsc4W2PxUvdBePK1wZ+ubiL2b7mqTsytN3p0iYqvNO9 Nx92Seoo5SFQYyDQVZMkSXxdl+L1Po/Ljuce97CzGFlAhnCwMUpABOZO4PhD5/qMzbTpXzH10w1 ratfY/Lr+atDlznLH8XkX5vhMSH/XibDH/5tjKUzDJ6e4N7QmMFyxMvcIC/sVNUxj1Mrei6kqGi ZcwMA X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Conor Dooley The system controller on PolarFire SoC has no interrupt to signify that the TX has been completed. The interrupt instead signals that a service requested by the mailbox client has succeeded. If a service fails, there will be no interrupt delivered. Switch to polling the busy register to determine whether transmission has completed. Fixes: 83d7b1560810 ("mbox: add polarfire soc system controller mailbox") Signed-off-by: Conor Dooley Tested-by: Valentina Fernandez --- drivers/mailbox/mailbox-mpfs.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/mailbox/mailbox-mpfs.c b/drivers/mailbox/mailbox-mpfs.c index d37560e91116..e0e825bdbad9 100644 --- a/drivers/mailbox/mailbox-mpfs.c +++ b/drivers/mailbox/mailbox-mpfs.c @@ -79,6 +79,13 @@ static bool mpfs_mbox_busy(struct mpfs_mbox *mbox) return status & SCB_STATUS_BUSY_MASK; } =20 +static bool mpfs_mbox_last_tx_done(struct mbox_chan *chan) +{ + struct mpfs_mbox *mbox =3D (struct mpfs_mbox *)chan->con_priv; + + return !mpfs_mbox_busy(mbox); +} + static int mpfs_mbox_send_data(struct mbox_chan *chan, void *data) { struct mpfs_mbox *mbox =3D (struct mpfs_mbox *)chan->con_priv; @@ -183,7 +190,6 @@ static irqreturn_t mpfs_mbox_inbox_isr(int irq, void *d= ata) =20 mpfs_mbox_rx_data(chan); =20 - mbox_chan_txdone(chan, 0); return IRQ_HANDLED; } =20 @@ -213,6 +219,7 @@ static const struct mbox_chan_ops mpfs_mbox_ops =3D { .send_data =3D mpfs_mbox_send_data, .startup =3D mpfs_mbox_startup, .shutdown =3D mpfs_mbox_shutdown, + .last_tx_done =3D mpfs_mbox_last_tx_done, }; =20 static int mpfs_mbox_probe(struct platform_device *pdev) @@ -248,7 +255,8 @@ static int mpfs_mbox_probe(struct platform_device *pdev) mbox->controller.num_chans =3D 1; mbox->controller.chans =3D mbox->chans; mbox->controller.ops =3D &mpfs_mbox_ops; - mbox->controller.txdone_irq =3D true; + mbox->controller.txdone_poll =3D true; + mbox->controller.txpoll_period =3D 10u; =20 ret =3D devm_mbox_controller_register(&pdev->dev, &mbox->controller); if (ret) { --=20 2.39.2 From nobody Mon Apr 13 12:05:33 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 EF36CC6FA99 for ; Tue, 7 Mar 2023 20:23:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230456AbjCGUXx (ORCPT ); Tue, 7 Mar 2023 15:23:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36006 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231710AbjCGUXc (ORCPT ); Tue, 7 Mar 2023 15:23:32 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4AF3C21964 for ; Tue, 7 Mar 2023 12:23:30 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D59B361535 for ; Tue, 7 Mar 2023 20:23:29 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E8914C433EF; Tue, 7 Mar 2023 20:23:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678220609; bh=VALLXa4RfjgD9/IaizhQxdY6y9Xca49NdnfoOQ47Y+Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nBr9Ztu2PNBF/a1Vij6drPfXyPlA06m7KIJsTbnWXbmOq+UrBScPikzMRIZw3qhfp AQ7rSrhZ1Q8/8FoV0Sw18GSufFJrL0ZKlGVCOQTaOvMwnqqMlvxGfqMyZCcvDQvWWZ YxG9Sp7BixBDAh7MKV8wKP2JNLlxaka50790bIIzqHd9ADjfyC64PUaMtDqnDDMxRq 8UgUatZ7Uzy7BsSFOgXE8PMIJFum2eTkPCIEFs9Wt0jhGuTQJja6QzBKRaR5DfwpJQ cGGi2Ot2fBbXfTXhaQhQyWzlSkzNMSN1Ac54XMdB6Eg+ZFPz7p4lR6kBYnZl7as9Fj 5rguI7kVgEwAg== From: Conor Dooley To: linux-riscv@lists.infradead.org Cc: conor@kernel.org, Conor Dooley , Daire McNamara , Jassi Brar , linux-kernel@vger.kernel.org Subject: [PATCH v3 3/8] mailbox: mpfs: ditch a useless busy check Date: Tue, 7 Mar 2023 20:22:53 +0000 Message-Id: <20230307202257.1762151-4-conor@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307202257.1762151-1-conor@kernel.org> References: <20230307202257.1762151-1-conor@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1067; i=conor.dooley@microchip.com; h=from:subject; bh=3TqNg+2iuqTO/EgEaud+uW5LomESwP/fUE4ltR1iLac=; b=owGbwMvMwCFWscWwfUFT0iXG02pJDCnsc4WyHSY+Wt4RdWbzMT3OCQZ3EuTZs1ns6pn2xYSzr Dzu81iko5SFQYyDQVZMkSXxdl+L1Po/Ljuce97CzGFlAhnCwMUpABOpOsXwP9CY27mex73y3I6j TUdyE4v9GizYw29b9p/yP7F4AvvzdIZ/pkfbvrwXYU14Eihi9rE0IStHwWDL4+zprzc8Yfkj2Li cDQA= X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Conor Dooley mpfs_mbox_rx_data() already checks if the system controller is busy before attempting to do anything, so drop the second check before reading any data. No functional change intended. Signed-off-by: Conor Dooley Tested-by: Valentina Fernandez --- drivers/mailbox/mailbox-mpfs.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/drivers/mailbox/mailbox-mpfs.c b/drivers/mailbox/mailbox-mpfs.c index e0e825bdbad9..0d176aba3462 100644 --- a/drivers/mailbox/mailbox-mpfs.c +++ b/drivers/mailbox/mailbox-mpfs.c @@ -170,12 +170,10 @@ static void mpfs_mbox_rx_data(struct mbox_chan *chan) if (response->resp_status) return; =20 - if (!mpfs_mbox_busy(mbox)) { - for (i =3D 0; i < num_words; i++) { - response->resp_msg[i] =3D - readl_relaxed(mbox->mbox_base - + mbox->resp_offset + i * 0x4); - } + for (i =3D 0; i < num_words; i++) { + response->resp_msg[i] =3D + readl_relaxed(mbox->mbox_base + + mbox->resp_offset + i * 0x4); } =20 mbox_chan_received_data(chan, response); --=20 2.39.2 From nobody Mon Apr 13 12:05:33 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 C7177C6FA99 for ; Tue, 7 Mar 2023 20:24:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231872AbjCGUYC (ORCPT ); Tue, 7 Mar 2023 15:24:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36530 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231815AbjCGUXf (ORCPT ); Tue, 7 Mar 2023 15:23:35 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B99C948E03 for ; Tue, 7 Mar 2023 12:23:33 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6FF6AB819BA for ; Tue, 7 Mar 2023 20:23:32 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B422EC433D2; Tue, 7 Mar 2023 20:23:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678220611; bh=5GC6Xd8kpVJdJrXJgNpGEg8xE8m+vrwYddohfQEV6Qk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=s8ZS4K0ejWbpsXZLRFRCKxmQ4WAZftHhv/K8zgGPeaJuMpuztgTiJw8nyaN7wEbo9 b8yi6Noir/ArspesdwUwYwnwsn0iNEnipMHaiY7aYiZWl6SaDcRUpAsttm+sDldcTJ 7gxhAcL/IdcAepI7KG0cweAjz+G419EuPn8veTX5/nv4WKQ9Pz01IELiovaFxvc6gz 1ZC13+KdGdRfChpLFuaGmcoIVMdcnPug/1cGh1pEaTGMkHNw5t/diZz3/NxmuWiYx4 LE7kJ1HK6LPgFb9tEwR8oVzzLmz0zko9yE+ilV60x9Hy4G5xUSrCHogoFoVCVAJkwb ZdygT8mW5720w== From: Conor Dooley To: linux-riscv@lists.infradead.org Cc: conor@kernel.org, Conor Dooley , Daire McNamara , Jassi Brar , linux-kernel@vger.kernel.org Subject: [PATCH v3 4/8] mailbox: mpfs: check the service status in .tx_done() Date: Tue, 7 Mar 2023 20:22:54 +0000 Message-Id: <20230307202257.1762151-5-conor@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307202257.1762151-1-conor@kernel.org> References: <20230307202257.1762151-1-conor@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3704; i=conor.dooley@microchip.com; h=from:subject; bh=qPU3Aj/HVaUNRSs2BviPXZLOR6A20/dd47WYx9ii+Hk=; b=owGbwMvMwCFWscWwfUFT0iXG02pJDCnsc4WsnV7lmz3Z8qttYi3bP3XuCReyg5iXFPH9tbb74 BNjwmjUUcrCIMbBICumyJJ4u69Fav0flx3OPW9h5rAygQxh4OIUgInMDGRk+HpWR2X74pMnHu5d dSd6XrZM2Pn3dw7kWy5l6OaYqjjfdTfDP4u6W+tETlXGL+TTa3rusV+7xc0hZ93cBd9/ZHjtXB/ 6mB0A X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Conor Dooley Services are supposed to generate an interrupt once completed, whether or not they have do so successfully. What appears to be a bug in the system controller means that interrupts are only generated for *successful* services. Currently, the status of a service is only checked in the mpfs_mbox_rx_data() once an interrupt is received. As it turns out, this is not really helpful where the potentially buggy behaviour is present, as we'll only see the status for successes where it is moot anyway. Jassi suggested moving the check to the .tx_done() callback instead. This makes sense, as the busy bit that tx_done() is polling will be lowered on completion, regardless of whether the service passed or failed. That allows us to check the status bits for all services, whether they generate an interrupt or not & pass something more informative than -EBADMSG back to the drivers implementing individual services. Suggested-by: Jassi Brar Signed-off-by: Conor Dooley Tested-by: Valentina Fernandez --- drivers/mailbox/mailbox-mpfs.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/drivers/mailbox/mailbox-mpfs.c b/drivers/mailbox/mailbox-mpfs.c index 0d176aba3462..162df49654fb 100644 --- a/drivers/mailbox/mailbox-mpfs.c +++ b/drivers/mailbox/mailbox-mpfs.c @@ -82,8 +82,22 @@ static bool mpfs_mbox_busy(struct mpfs_mbox *mbox) static bool mpfs_mbox_last_tx_done(struct mbox_chan *chan) { struct mpfs_mbox *mbox =3D (struct mpfs_mbox *)chan->con_priv; + struct mpfs_mss_response *response =3D mbox->response; + u32 val; + + if (mpfs_mbox_busy(mbox)) + return false; + + /* + * The service status is stored in bits 31:16 of the SERVICES_SR + * register & is only valid when the system controller is not busy. + * Failed services are intended to generated interrupts, but in reality + * this does not happen, so the status must be checked here. + */ + val =3D readl_relaxed(mbox->ctrl_base + SERVICES_SR_OFFSET); + response->resp_status =3D (val & SCB_STATUS_MASK) >> SCB_STATUS_POS; =20 - return !mpfs_mbox_busy(mbox); + return true; } =20 static int mpfs_mbox_send_data(struct mbox_chan *chan, void *data) @@ -138,7 +152,7 @@ static void mpfs_mbox_rx_data(struct mbox_chan *chan) struct mpfs_mbox *mbox =3D (struct mpfs_mbox *)chan->con_priv; struct mpfs_mss_response *response =3D mbox->response; u16 num_words =3D ALIGN((response->resp_size), (4)) / 4U; - u32 i, status; + u32 i; =20 if (!response->resp_msg) { dev_err(mbox->dev, "failed to assign memory for response %d\n", -ENOMEM); @@ -146,8 +160,6 @@ static void mpfs_mbox_rx_data(struct mbox_chan *chan) } =20 /* - * The status is stored in bits 31:16 of the SERVICES_SR register. - * It is only valid when BUSY =3D=3D 0. * We should *never* get an interrupt while the controller is * still in the busy state. If we do, something has gone badly * wrong & the content of the mailbox would not be valid. @@ -158,18 +170,6 @@ static void mpfs_mbox_rx_data(struct mbox_chan *chan) return; } =20 - status =3D readl_relaxed(mbox->ctrl_base + SERVICES_SR_OFFSET); - - /* - * If the status of the individual servers is non-zero, the service has - * failed. The contents of the mailbox at this point are not be valid, - * so don't bother reading them. Set the status so that the driver - * implementing the service can handle the result. - */ - response->resp_status =3D (status & SCB_STATUS_MASK) >> SCB_STATUS_POS; - if (response->resp_status) - return; - for (i =3D 0; i < num_words; i++) { response->resp_msg[i] =3D readl_relaxed(mbox->mbox_base --=20 2.39.2 From nobody Mon Apr 13 12:05:33 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 96342C678D5 for ; Tue, 7 Mar 2023 20:24:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231877AbjCGUYF (ORCPT ); Tue, 7 Mar 2023 15:24:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231219AbjCGUXg (ORCPT ); Tue, 7 Mar 2023 15:23:36 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84A687389F for ; Tue, 7 Mar 2023 12:23:35 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 2CD84B81A31 for ; Tue, 7 Mar 2023 20:23:34 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7D9B4C433EF; Tue, 7 Mar 2023 20:23:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678220612; bh=zr/RXQEP9kEo+EnwwW4EkZXzcH8/Cm+sddrH4zbpuOU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=C2kReW2u9cd8hgfPUoK1mj5efaFk+oe+RpaNULZCMGcXQaXB8pAT2R0JGpv7ybRSh shh8tERapttCn/eBkpt7KrPwQACDKAuXbbb1WwBhbmmQMXQwYgQ7Pl9pdsZKG+oyiJ utdctq3VAWgEuEf0oyuHHsAAxW/oUIR3Tdz0+dYT79CDUKJQkg8S8VYn3OaOmZa8Dm AwZl9dvRI+1X87y5D/vQTvbSoW8qqIOjXmb9wphwdaTPW2DZSHYj7565oLl7UsBYu6 Q4TKNJKLoiWHsZUbva1Bk13dhHLVbyhDU755sGz70xQ6LnbOqQoxi5ASnsCMI9WkzQ hQ+gj5XGk5fzg== From: Conor Dooley To: linux-riscv@lists.infradead.org Cc: conor@kernel.org, Conor Dooley , Daire McNamara , Jassi Brar , linux-kernel@vger.kernel.org Subject: [PATCH v3 5/8] soc: microchip: mpfs: fix some horrible alignment Date: Tue, 7 Mar 2023 20:22:55 +0000 Message-Id: <20230307202257.1762151-6-conor@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307202257.1762151-1-conor@kernel.org> References: <20230307202257.1762151-1-conor@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1038; i=conor.dooley@microchip.com; h=from:subject; bh=MwKJyVjv8Jbuiia0A7TcpOXo3jezcv525pOH2lez0W8=; b=owGbwMvMwCFWscWwfUFT0iXG02pJDCnsc4XYHMSvishN+y87ZUlG/srobd+OFpfOUS+fEKEsP kn97q+jHaUsDGIcDLJiiiyJt/tapNb/cdnh3PMWZg4rE8gQBi5OAZjI6n6Gf+a6tm1cCZtzF2/Z X/tDcaVIYGaJzdcAj39HonZl8R0ULWH4n2i66/HXZzYnlpW5ikszPrp8SkmV8dHxhVlNOu6HI4v zOAA= X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Conor Dooley mpfs_sys_controller_delete() has some horrible alignment that upsets my OCD... Move the RHS of the assignment to a new line for greater satifaction. Signed-off-by: Conor Dooley Tested-by: Valentina Fernandez --- drivers/soc/microchip/mpfs-sys-controller.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/soc/microchip/mpfs-sys-controller.c b/drivers/soc/micr= ochip/mpfs-sys-controller.c index 6e20207b5756..12039cb38b33 100644 --- a/drivers/soc/microchip/mpfs-sys-controller.c +++ b/drivers/soc/microchip/mpfs-sys-controller.c @@ -66,8 +66,8 @@ static void rx_callback(struct mbox_client *client, void = *msg) =20 static void mpfs_sys_controller_delete(struct kref *kref) { - struct mpfs_sys_controller *sys_controller =3D container_of(kref, struct = mpfs_sys_controller, - consumers); + struct mpfs_sys_controller *sys_controller =3D + container_of(kref, struct mpfs_sys_controller, consumers); =20 mbox_free_channel(sys_controller->chan); kfree(sys_controller); --=20 2.39.2 From nobody Mon Apr 13 12:05:33 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 21349C6FA99 for ; Tue, 7 Mar 2023 20:24:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232527AbjCGUYM (ORCPT ); Tue, 7 Mar 2023 15:24:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38444 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230155AbjCGUXi (ORCPT ); Tue, 7 Mar 2023 15:23:38 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 554B2521EB for ; Tue, 7 Mar 2023 12:23:37 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id F1C4DB81A1A for ; Tue, 7 Mar 2023 20:23:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 47D51C4339C; Tue, 7 Mar 2023 20:23:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678220614; bh=9ftp4XSRep9CAFGl5I/cGlZ4Bn7VzUhE3/7xrZNvJco=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Wd5oeeEbSyUVMox8/3SeOUbDKlFtbRdeXF9mclqCpw3C4RnGRUW3XkI4N2cQdqeMY HNTa4jT6BBHAtJSRSvItJ1s8d7UqoDawunE6T9glEmXXSGzkD3HYZqbduxk3M/u37C 2wkPwVEXGAmIMWF2/c7wbstNCL+ZoMdneRmFxcUFV2oOleV3cYKJM6tfkCCgBu5JWN e0vnSP1I6/mzgHXfIiZQNn3dsVPi8Lv0a81dfvHleVpEYgurCq8cKcYvpwd+9rIKll vWnqJwVaVsdH0fZ1FmGTV1ZBEniEB2CSWgg+lu2fiwP1mgDh9XpsAi2M4v3knia7p5 u3gGVujZx1eRw== From: Conor Dooley To: linux-riscv@lists.infradead.org Cc: conor@kernel.org, Conor Dooley , Daire McNamara , Jassi Brar , linux-kernel@vger.kernel.org Subject: [PATCH v3 6/8] soc: microchip: mpfs: use a consistent completion timeout Date: Tue, 7 Mar 2023 20:22:56 +0000 Message-Id: <20230307202257.1762151-7-conor@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307202257.1762151-1-conor@kernel.org> References: <20230307202257.1762151-1-conor@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1695; i=conor.dooley@microchip.com; h=from:subject; bh=ZbvEWn53vw1ASCu/srw+heRkVpLXaO8RXoKnQ2EVF7c=; b=owGbwMvMwCFWscWwfUFT0iXG02pJDCnsc4W7eJJZMt9POxp7cEmjxazMm1nzXhSmnGC8ucvtv dYXc8OQjlIWBjEOBlkxRZbE230tUuv/uOxw7nkLM4eVCWQIAxenAEzk71+Gv+JJD104p1R3PxHg KNmxu0fdrmunZcLsV8eU4y3+z6vyqmFkuDPx/z6e+7YL3Y/vtTPUlrh/at7B+hKBfsXvEhPkC5s +cQMA X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Conor Dooley Completion timeouts use jiffies, so passing a number directly will produce inconsistent timeouts depending on config. Define the timeout in ms and convert it to jiffies instead. Signed-off-by: Conor Dooley Tested-by: Valentina Fernandez --- drivers/soc/microchip/mpfs-sys-controller.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/soc/microchip/mpfs-sys-controller.c b/drivers/soc/micr= ochip/mpfs-sys-controller.c index 12039cb38b33..738ecd624d64 100644 --- a/drivers/soc/microchip/mpfs-sys-controller.c +++ b/drivers/soc/microchip/mpfs-sys-controller.c @@ -11,12 +11,15 @@ #include #include #include +#include #include #include #include #include #include =20 +#define MPFS_SYS_CTRL_TIMEOUT_MS 100 + static DEFINE_MUTEX(transaction_lock); =20 struct mpfs_sys_controller { @@ -28,6 +31,7 @@ struct mpfs_sys_controller { =20 int mpfs_blocking_transaction(struct mpfs_sys_controller *sys_controller, = struct mpfs_mss_msg *msg) { + unsigned long timeout =3D msecs_to_jiffies(MPFS_SYS_CTRL_TIMEOUT_MS); int ret, err; =20 err =3D mutex_lock_interruptible(&transaction_lock); @@ -38,7 +42,7 @@ int mpfs_blocking_transaction(struct mpfs_sys_controller = *sys_controller, struct =20 ret =3D mbox_send_message(sys_controller->chan, msg); if (ret >=3D 0) { - if (wait_for_completion_timeout(&sys_controller->c, HZ)) { + if (wait_for_completion_timeout(&sys_controller->c, timeout)) { ret =3D 0; } else { ret =3D -ETIMEDOUT; --=20 2.39.2 From nobody Mon Apr 13 12:05:33 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 CE426C678D5 for ; Tue, 7 Mar 2023 20:24:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232072AbjCGUYJ (ORCPT ); Tue, 7 Mar 2023 15:24:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38446 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231688AbjCGUXi (ORCPT ); Tue, 7 Mar 2023 15:23:38 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A2397EA0B for ; Tue, 7 Mar 2023 12:23:37 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id F2BEC614DF for ; Tue, 7 Mar 2023 20:23:36 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1252FC433EF; Tue, 7 Mar 2023 20:23:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678220616; bh=Hyj1AzwSvpLlh1c+5n8He7fqMvxbQ+81FBS9Lk+fweU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KPzHXOuv7fRzzZAIoUsTGBHAIQ+kSCElxymLxPu3KJJQFNFj82hJ+TYhuGIuXD9SU 5jvKSpZiiM7iokRN/p15cNZ5Y1R05X/yXWYbdEvptAkHN5EP8931cZnErgzj4OA9G7 Lv2qZ7Ypn+ZVkwh/kpAy9lTEk3yYqLAph4r0mHH+icyhcyOwGzrRWwJU9dcsWaNNdC WH1MYjzvL7pb39MXGy8dHxZ8PTlLSFPRGPGTxbG8YOtTXyLsZiX8/n7zb1VYerk1b/ FwfMBTwbUOH+WsKVtcIGg5qVxBJYVebxSfIxTgvaKluWdhva5CvdN3OPSTNs+uDmYe i09pITodsp17Q== From: Conor Dooley To: linux-riscv@lists.infradead.org Cc: conor@kernel.org, Conor Dooley , Daire McNamara , Jassi Brar , linux-kernel@vger.kernel.org Subject: [PATCH v3 7/8] soc: microchip: mpfs: simplify error handling in mpfs_blocking_transaction() Date: Tue, 7 Mar 2023 20:22:57 +0000 Message-Id: <20230307202257.1762151-8-conor@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307202257.1762151-1-conor@kernel.org> References: <20230307202257.1762151-1-conor@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=1912; i=conor.dooley@microchip.com; h=from:subject; bh=TiTo00L6NEuRkl9W6QwqcYPRUYBdT9OXo1cRIbTtbsQ=; b=owGbwMvMwCFWscWwfUFT0iXG02pJDCnsc4W3n14zrYEnhHdHxbpXh8XmqTFZx2T1bdjlEeM57 zj7Ab3QjlIWBjEOBlkxRZbE230tUuv/uOxw7nkLM4eVCWQIAxenAEykdRsjw2JPr/llRYzH+bbz 5hX98zlQnnWbfefuAytTfq6ZyVP8MpCRYf+rqHO7WuoyNql/u3MxxbOc0/Xaasmgd4xLfA1/9M9 IZQcA X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Conor Dooley The error handling has a kinda weird nested-if setup that is not really adding anything. Switch it to more of an early return arrangement as a predatory step for adding different handing for timeouts and failed services. Signed-off-by: Conor Dooley Tested-by: Valentina Fernandez --- drivers/soc/microchip/mpfs-sys-controller.c | 27 ++++++++++----------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/drivers/soc/microchip/mpfs-sys-controller.c b/drivers/soc/micr= ochip/mpfs-sys-controller.c index 738ecd624d64..e61ba9b7aae3 100644 --- a/drivers/soc/microchip/mpfs-sys-controller.c +++ b/drivers/soc/microchip/mpfs-sys-controller.c @@ -32,28 +32,27 @@ struct mpfs_sys_controller { int mpfs_blocking_transaction(struct mpfs_sys_controller *sys_controller, = struct mpfs_mss_msg *msg) { unsigned long timeout =3D msecs_to_jiffies(MPFS_SYS_CTRL_TIMEOUT_MS); - int ret, err; + int ret; =20 - err =3D mutex_lock_interruptible(&transaction_lock); - if (err) - return err; + ret =3D mutex_lock_interruptible(&transaction_lock); + if (ret) + return ret; =20 reinit_completion(&sys_controller->c); =20 ret =3D mbox_send_message(sys_controller->chan, msg); - if (ret >=3D 0) { - if (wait_for_completion_timeout(&sys_controller->c, timeout)) { - ret =3D 0; - } else { - ret =3D -ETIMEDOUT; - dev_warn(sys_controller->client.dev, - "MPFS sys controller transaction timeout\n"); - } + if (ret < 0) + goto out; + + if (!wait_for_completion_timeout(&sys_controller->c, timeout)) { + ret =3D -ETIMEDOUT; + dev_warn(sys_controller->client.dev, "MPFS sys controller transaction ti= meout\n"); } else { - dev_err(sys_controller->client.dev, - "mpfs sys controller transaction returned %d\n", ret); + /* mbox_send_message() returns positive integers on success */ + ret =3D 0; } =20 +out: mutex_unlock(&transaction_lock); =20 return ret; --=20 2.39.2 From nobody Mon Apr 13 12:05:33 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 621B6C678D5 for ; Tue, 7 Mar 2023 20:24:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231825AbjCGUYQ (ORCPT ); Tue, 7 Mar 2023 15:24:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231831AbjCGUXk (ORCPT ); Tue, 7 Mar 2023 15:23:40 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 319758A6D for ; Tue, 7 Mar 2023 12:23:39 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BC507614DF for ; Tue, 7 Mar 2023 20:23:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D0C12C4339C; Tue, 7 Mar 2023 20:23:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1678220618; bh=zda+VbG39EuOmqkJEqNyN6EQjdt58w158b+x94tcTtA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=rNTBs9H86YYrMsI6GY62OKUY/zA+Y/N4//bAkoDBohiDpxWf3xg5Fvuj3jmSgnsYy 847gso8bU/q2cYiZE1keCVkfpHTHzYgfdyc6i3gXwOSHZlJMhBxhvQcmp294dgO1Y9 smnUpiczFeYWtJuG2zo+5N/mlJgtdI86csYALnq6rArW+1GY5n3ET2TQkw+GmLp8Rm okAAtihHtRyVci0pm0STHpam0M/ms20FbdLvXCBtfrFYs1tgcDkRljYzMuJg/8ncup 2u8Z9OH5FbscqGPaPbNu6lDIodWhb4KXVwMZOJivlCSvi6gM8fYhZneZIrGkPAL9hY /brzgVWQSitJA== From: Conor Dooley To: linux-riscv@lists.infradead.org Cc: conor@kernel.org, Conor Dooley , Daire McNamara , Jassi Brar , linux-kernel@vger.kernel.org Subject: [PATCH v3 8/8] soc: microchip: mpfs: handle timeouts and failed services differently Date: Tue, 7 Mar 2023 20:22:58 +0000 Message-Id: <20230307202257.1762151-9-conor@kernel.org> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230307202257.1762151-1-conor@kernel.org> References: <20230307202257.1762151-1-conor@kernel.org> MIME-Version: 1.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3200; i=conor.dooley@microchip.com; h=from:subject; bh=pwrSJrBRsgiePyr0G5aY+e8m9Q0BM9VvEVyERBwr1ik=; b=owGbwMvMwCFWscWwfUFT0iXG02pJDCnsc4V5zm27ymprZ7VAkrUva0X8rPMu97a4F7ucz+T22 /UxbM6+jlIWBjEOBlkxRZbE230tUuv/uOxw7nkLM4eVCWQIAxenAEykgJeRYfpcZy2PGvs1v1cf urPvW+3Mp3MMjA9oXX7pJvrqyvvgW38Z/pe+cf/f52Ir4R5w0Vrc+t/E/v1Sq/i2zS4umpD0t4r 1CRsA X-Developer-Key: i=conor.dooley@microchip.com; a=openpgp; fpr=F9ECA03CF54F12CD01F1655722E2C55B37CF380C Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Conor Dooley The system controller will only deliver an interrupt if a service succeeds. This leaves us in the unfortunate position with current code where there is no way to differentiate between a legitimate timeout where the service has not completed & where it has completed, but failed. mbox_send_message() has its own completion, and it will time out of the system controller does not lower the busy flag. In this case, a timeout has occurred and the error can be propagated back to the caller. If the busy flag is lowered, but no interrupt has arrived to trigger the rx callback, the service can be deemed to have failed. Report -EBADMSG in this case so that callers can differentiate. Signed-off-by: Conor Dooley Tested-by: Valentina Fernandez --- drivers/soc/microchip/mpfs-sys-controller.c | 27 +++++++++++++++++---- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/drivers/soc/microchip/mpfs-sys-controller.c b/drivers/soc/micr= ochip/mpfs-sys-controller.c index e61ba9b7aae3..ceaeebc1fc6b 100644 --- a/drivers/soc/microchip/mpfs-sys-controller.c +++ b/drivers/soc/microchip/mpfs-sys-controller.c @@ -18,7 +18,11 @@ #include #include =20 -#define MPFS_SYS_CTRL_TIMEOUT_MS 100 +/* + * This timeout must be long, as some services (example: image authenticat= ion) + * take significant time to complete + */ +#define MPFS_SYS_CTRL_TIMEOUT_MS 30000 =20 static DEFINE_MUTEX(transaction_lock); =20 @@ -41,14 +45,26 @@ int mpfs_blocking_transaction(struct mpfs_sys_controlle= r *sys_controller, struct reinit_completion(&sys_controller->c); =20 ret =3D mbox_send_message(sys_controller->chan, msg); - if (ret < 0) + if (ret < 0) { + dev_warn(sys_controller->client.dev, "MPFS sys controller service timeou= t\n"); goto out; + } =20 + /* + * Unfortunately, the system controller will only deliver an interrupt + * if a service succeeds. mbox_send_message() will block until the busy + * flag is gone. If the busy flag is gone but no interrupt has arrived + * to trigger the rx callback then the service can be deemed to have + * failed. + * The caller can then interrogate msg::response::resp_status to + * determine the cause of the failure. + * mbox_send_message() returns positive integers in the success path, so + * ret needs to be cleared if we do get an interrupt. + */ if (!wait_for_completion_timeout(&sys_controller->c, timeout)) { - ret =3D -ETIMEDOUT; - dev_warn(sys_controller->client.dev, "MPFS sys controller transaction ti= meout\n"); + ret =3D -EBADMSG; + dev_warn(sys_controller->client.dev, "MPFS sys controller service failed= \n"); } else { - /* mbox_send_message() returns positive integers on success */ ret =3D 0; } =20 @@ -107,6 +123,7 @@ static int mpfs_sys_controller_probe(struct platform_de= vice *pdev) sys_controller->client.dev =3D dev; sys_controller->client.rx_callback =3D rx_callback; sys_controller->client.tx_block =3D 1U; + sys_controller->client.tx_tout =3D msecs_to_jiffies(MPFS_SYS_CTRL_TIMEOUT= _MS); =20 sys_controller->chan =3D mbox_request_channel(&sys_controller->client, 0); if (IS_ERR(sys_controller->chan)) { --=20 2.39.2