From patchwork Wed Nov 23 17:56:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Conor Dooley X-Patchwork-Id: 25099 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2940579wrr; Wed, 23 Nov 2022 10:03:06 -0800 (PST) X-Google-Smtp-Source: AA0mqf6sw7zucFrjTUbWc1dW4/2xdAdRpMOZv2d2VAOp+BzfJ5V6UnAQdVBm62oAtMhf43lqNvRG X-Received: by 2002:a05:6402:28ad:b0:469:2730:1c0f with SMTP id eg45-20020a05640228ad00b0046927301c0fmr13048003edb.215.1669226586003; Wed, 23 Nov 2022 10:03:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669226585; cv=none; d=google.com; s=arc-20160816; b=gehq24sn8RwYslPkD4C6Ugv2KlEsr2QVUo7VbVOMq25B5KrYjzwDko9xF1oh8XwTs2 vyCkWVXFVjQ5t1gJ4OReCO9OZI4BRoSXnoa9syOU2ycnYY+7UZ3a7orWeKf3espwGwTi DTMruTLfNUMaoMFtrRksciaCphnGHD7TNp4I8mY+7GmbwrlnlTOSCOYhZUcU16aR7AV9 5a5joC1/EApKgXxulgw8XZuFTGYCLi/OdhbncIFooBeWFdsromd6qt2VjrtbTRT94VT8 kKMsoaax7pRc7UaPOcRSk0EE9Pjv/djbS7Jl7H9hwTJPxiXy19Z9JgRSc+lIjoTYq5Ru YBRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YTCYfeFIDfjaXYfyhuMzXOKcR3j9k0MucdfkVJjbSv4=; b=pD6Mlq99vGDKSXhAdazN3+Lndv3vsWRxeN1j0rvjvoCvVaextZwSLR0e9KxBEmbO+7 wTk4ns9qlyK74dU8hncBrILy6QGpMU3jkiYiDvajp71cgL6gMY78m4DXqX0mSUOWWB3z jyN/ms40w8H2+czRAXQGTZH0QZ5lmMRO3G4a/6FRG0Q+aDAg9JzyeqT7yjs3fHj2bn6n WEUU1tuZp5ms3WiDCVNeeO5WELPrdtW4JK5x6EFOXVrzjV4ziQr2egrjqrUjx9V5sKxF Lfhe59CPMA07EY7yr0R1nOY4hINOGlk63tProlGR+U4CYzRJs8vVIQWaQgt/Y2UxiY2H 5j7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CSSGDzQi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y15-20020a056402270f00b0045d4a88c735si15564920edd.220.2022.11.23.10.02.30; Wed, 23 Nov 2022 10:03:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=CSSGDzQi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237556AbiKWR53 (ORCPT + 99 others); Wed, 23 Nov 2022 12:57:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47784 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239281AbiKWR5H (ORCPT ); Wed, 23 Nov 2022 12:57:07 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC776C6629 for ; Wed, 23 Nov 2022 09:57:06 -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 7B38EB81FE3 for ; Wed, 23 Nov 2022 17:57:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0FE2DC433D7; Wed, 23 Nov 2022 17:57:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669226224; bh=wxKRNQqmydSopaq3yHKk8toN/2zOQmC1pkaLy1+Ehkg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=CSSGDzQiXa2ILS4WGGBSKvACOhV6QvQI9xRgiwSxlGfkV2yyeixoS4SdtPoL7s7bf 8TNDr2zLF14QRyI88mOpNJ6huU5kny68Y06DWco4M2iFrnoj6jpTfmdFybwo2nKNWE f2aotYGVayYV7QAkW/uHhH97x+fDPIzVGm9NDGyzV7+66P0TXPJ68+bshMVPVj5sc1 fd3SN6HOzG4ir2BQsfuMa2WrVKl7k/r8JBOYCJc4Jd+MPZcBeG3IDcoa6p/0DOJz6b Bcvf8za3qfB52rQWxtOumI6d4ykEtiT5MZMpfM54MBvrE1zTlrPw4N0SmpJmdMrOMd QjbBln1SVarEA== From: Conor Dooley To: Conor Dooley , Jassi Brar Cc: Daire McNamara , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/2] soc: microchip: mpfs: handle failed system service requests Date: Wed, 23 Nov 2022 17:56:51 +0000 Message-Id: <20221123175652.327859-2-conor@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221123175652.327859-1-conor@kernel.org> References: <20221123175652.327859-1-conor@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750310936268790596?= X-GMAIL-MSGID: =?utf-8?q?1750310936268790596?= From: Conor Dooley If a service request fails, a non-zero, per-service error code will be set. Since the individual service drivers may wish to handle things differently, there's little point trying to do anything intelligent in the system controller driver. Let the caller know that things went wrong & leave the details of handling the error to it. Fixes: d0054a470c33 ("soc: add microchip polarfire soc system controller") Signed-off-by: Conor Dooley Reviewed-by: Palmer Dabbelt --- drivers/soc/microchip/mpfs-sys-controller.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/soc/microchip/mpfs-sys-controller.c b/drivers/soc/microchip/mpfs-sys-controller.c index 6e20207b5756..539fc24b397d 100644 --- a/drivers/soc/microchip/mpfs-sys-controller.c +++ b/drivers/soc/microchip/mpfs-sys-controller.c @@ -52,6 +52,12 @@ int mpfs_blocking_transaction(struct mpfs_sys_controller *sys_controller, struct mutex_unlock(&transaction_lock); + if (ret) + return ret; + + if (msg->response->resp_status) + ret = -EIO; + return ret; } EXPORT_SYMBOL(mpfs_blocking_transaction); From patchwork Wed Nov 23 17:56:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Conor Dooley X-Patchwork-Id: 25100 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2940604wrr; Wed, 23 Nov 2022 10:03:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf4JWLNRXCbByylilvSRPc3Goc9EAbIHj54H7/bGvqcccuVLm7V5lxQc9U8jYS0mFyeqsYZZ X-Received: by 2002:a17:906:1546:b0:741:5c0e:1058 with SMTP id c6-20020a170906154600b007415c0e1058mr24433343ejd.472.1669226588013; Wed, 23 Nov 2022 10:03:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669226588; cv=none; d=google.com; s=arc-20160816; b=u4V/SkC5bwz7FIN4Mf3PWhRJOa9ofJN0tHuMn8LHXeCCSmZEZFZMpar6405L8VCl5L qLK9REYeRqqLxolprsJU2BQ0RMtKhmA4H2wcJwlCEyYSXII1diWheS7Jx3Uh9PYmMfO4 5rVvi2nQgVzOp+uPlgwbEh6N8JfRsfb2AT+Ugowjs9fb32x0nvP+jXooji/eCOYYRVot pETzXAqHKwjgSMNf/uUDQdopks+3LllC5SkAC6a5zuFSbRI7WL5U0B2ggdO9BP4FlXzS iC4KJfRZWrcKEgnLRAGnzkojL8U7LylAkH+ECNIVrjGiOSWPYkIsULjnyMAhC3+Eiq1l u4yw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=mtYeyXGO00lpcyUlNjEK7UwygIyj6WMSm8QZNjv/xmg=; b=dDEcf8Ibb6nlFPmXHjbwsjEbXLL5euSRZI2q1D0nYSBMVeGTOtT6WxOphvEUylvTPS dpbVmtPQRrlF39juR6cvLeOOgnOWAUBw2S7D8IKnz+y9nKCtoYrgcz61+moexXUT72pz 8soBi5OdAIVxmvDl+z6cfyMfF7ZfZoQWSnvdvIR51gECwYQCTsVNFWLdowK5SnROM5Nz jjjKJTVGhqNnATZHHsAdRNsVJs4yMjkoJ2gyEVfFTkAOtuLjYqpwSNP5e/9Zh4URtXqc FpJcr/t7Z4i5YsrgaR/dwCgSDjFJg9cCY3L0zw3sI42z8rZp6Z1gj1anRGUGc/M0BLDM UmGw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="DQ4JJSB/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id x24-20020a1709064a9800b007adeb7f8e5bsi11480790eju.913.2022.11.23.10.02.33; Wed, 23 Nov 2022 10:03:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="DQ4JJSB/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239268AbiKWR5d (ORCPT + 99 others); Wed, 23 Nov 2022 12:57:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239329AbiKWR5L (ORCPT ); Wed, 23 Nov 2022 12:57:11 -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 E04CEC6633 for ; Wed, 23 Nov 2022 09:57:06 -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 6A61661E2F for ; Wed, 23 Nov 2022 17:57:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A6A4FC433C1; Wed, 23 Nov 2022 17:57:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1669226225; bh=Qtzc1cobsjubwRvtdGwHlSQ/wf5MdQwUif68mEyoqSU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DQ4JJSB/XOtyPKOjZ1GrOhpinUo5woM9ghzuWgxkGNn6nquKVhFEH0Oc9zXsyPxyr h461ekvrnW3s/gZKpwj8f2NcWktzAFaauDJMuNt8k+yNB43iy4DoVXt3PodhdqINs0 r+du0fRqP/EFf9OUVkSaZDoTn1kOkvNSxpT3BibR0cuS88szRrXi/0Zii5ZewIhRlV UDeIi7A0sQ5bO0UJqSo8GaYLQVmR8J0KwjM6jn0fe3fJwXockgcQJpY1goGijNQvIH JGuHunYoiyohF20Htz04jlP0ax32f0+U5lh005WgSLFlzDW01LzDG5d107DgLd4BZA nVEQmCsXReUrg== From: Conor Dooley To: Conor Dooley , Jassi Brar Cc: Daire McNamara , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 2/2] mailbox: mpfs: read the system controller's status Date: Wed, 23 Nov 2022 17:56:52 +0000 Message-Id: <20221123175652.327859-3-conor@kernel.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221123175652.327859-1-conor@kernel.org> References: <20221123175652.327859-1-conor@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750310938721270326?= X-GMAIL-MSGID: =?utf-8?q?1750310938721270326?= From: Conor Dooley Some services explicitly return an error code in their response, but others rely on the system controller to set a status in its status register. The meaning of the bits varies based on what service is requested, so pass it back up to the driver that requested the service in the first place. The field in the message struct already existed, but was unused until now. If the system controller is busy, in which case we should never actually be in the interrupt handler, or if the service fails the mailbox itself should not be read. Callers should check the status before operating on the response. There's an existing, but unused, #define for the mailbox mask - but it was incorrect. It was doing a GENMASK_ULL(32, 16) which should've just been a GENMASK(31, 16), so fix that up and start using it. Fixes: 83d7b1560810 ("mbox: add polarfire soc system controller mailbox") Signed-off-by: Conor Dooley Reviewed-by: Palmer Dabbelt --- drivers/mailbox/mailbox-mpfs.c | 31 ++++++++++++++++++++++++++++--- 1 file changed, 28 insertions(+), 3 deletions(-) diff --git a/drivers/mailbox/mailbox-mpfs.c b/drivers/mailbox/mailbox-mpfs.c index cfacb3f320a6..853901acaeec 100644 --- a/drivers/mailbox/mailbox-mpfs.c +++ b/drivers/mailbox/mailbox-mpfs.c @@ -2,7 +2,7 @@ /* * Microchip PolarFire SoC (MPFS) system controller/mailbox controller driver * - * Copyright (c) 2020 Microchip Corporation. All rights reserved. + * Copyright (c) 2020-2022 Microchip Corporation. All rights reserved. * * Author: Conor Dooley * @@ -56,7 +56,7 @@ #define SCB_STATUS_NOTIFY_MASK BIT(SCB_STATUS_NOTIFY) #define SCB_STATUS_POS (16) -#define SCB_STATUS_MASK GENMASK_ULL(SCB_STATUS_POS + SCB_MASK_WIDTH, SCB_STATUS_POS) +#define SCB_STATUS_MASK GENMASK(SCB_STATUS_POS + SCB_MASK_WIDTH - 1, SCB_STATUS_POS) struct mpfs_mbox { struct mbox_controller controller; @@ -130,13 +130,38 @@ static void mpfs_mbox_rx_data(struct mbox_chan *chan) struct mpfs_mbox *mbox = (struct mpfs_mbox *)chan->con_priv; struct mpfs_mss_response *response = mbox->response; u16 num_words = ALIGN((response->resp_size), (4)) / 4U; - u32 i; + u32 i, status; if (!response->resp_msg) { dev_err(mbox->dev, "failed to assign memory for response %d\n", -ENOMEM); return; } + /* + * The status is stored in bits 31:16 of the SERVICES_SR register. + * It is only valid when BUSY == 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. + */ + if (mpfs_mbox_busy(mbox)) { + dev_err(mbox->dev, "got an interrupt but system controller is busy\n"); + response->resp_status = 0xDEAD; + return; + } + + status = 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 = (status & SCB_STATUS_MASK) >> SCB_STATUS_POS; + if (response->resp_status) + return; + if (!mpfs_mbox_busy(mbox)) { for (i = 0; i < num_words; i++) { response->resp_msg[i] =