From patchwork Wed Mar 23 03:44:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Peng Fan (OSS)" X-Patchwork-Id: 12789424 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 2046FC433FE for ; Wed, 23 Mar 2022 03:42:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241618AbiCWDn4 (ORCPT ); Tue, 22 Mar 2022 23:43:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240440AbiCWDnz (ORCPT ); Tue, 22 Mar 2022 23:43:55 -0400 Received: from EUR03-AM5-obe.outbound.protection.outlook.com (mail-eopbgr30062.outbound.protection.outlook.com [40.107.3.62]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42E4670CF9; Tue, 22 Mar 2022 20:42:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=DvmH42ZewpgUu++yLGlSS//qSNrzzEk+L3KWDCMxLh4Ia3zXnJSNPG4hQF78+InxemoQMEOq4GPqQwdboHK023+exmA6VqcSU0Y2fVY/7oOmtB+jErLW/0qbVDqjiG1tZ6Tnc4siNjgzktAMTvJ3k+Dowj8JWnfdf6ksa7xrKf0/Bii/0sVJwrE3SyIEJZoZCU/39hZJwEFqG8ojK3Afbe+ypAv8q+SfTA52v3LMVgXxtrDfuOGEemKF4jRr5r+9JcYMP05en4Dxq3I1VZjbNr4SRE2J5WtcaeV9p3E6n0+5BRvY/7yRePs5IuK1cE4Ouq23cL3J+kWxx3PF12dfEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=iVHg8SrcD1/iCrzLq8zCMg7MJyiD06axkQZdB8BR1Fw=; b=KZhhqD+DtBi396iYX6yZvuP4x1/YMmtTzhM7X9NCpNDFLKN9u1iT+tVI12ZIf08S60Bc9QlFrgv6ziNrf6MMJlI4RyNavtrYlYrBQiOf/rCYk2RsaZiPcM+GKaFhKECK9sBtNHSpFiR9keU3vJg8rxlmyyPEsok+xvDQb4VqHx/FHN6ZVDcb3DZg4ni1LE/JIapHND6+iHPX8W+HoFBaUXI1DSbdoq6yVodRRBfi10aiuVuR3lVWge8yX0o3iLmAbqOBV5r22zOZGN8GuRSjZ04wtAuQu7cukYrnSkg0xdq2lkYD7bwr6dVBJCkYbN/FepwZNxjimN0fEMIMBbU2gg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector2-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iVHg8SrcD1/iCrzLq8zCMg7MJyiD06axkQZdB8BR1Fw=; b=A+bpVrBbGJRNTm4Yb05WvywK8Z3zual3EnTdZ0avskRCSEfPq+HA4keuRjPwXN62dy7czIQzENt7bsOxOYwF/7Sgcbm/QhaN3uc8ZSss+VWDPIzBL5SKIdKjunazVbqheir1QAPN0vkY+PBdeApmkFm8k5SMNNGxvz2R7IVf+ms= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) by AM0PR04MB6868.eurprd04.prod.outlook.com (2603:10a6:208:18c::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5102.17; Wed, 23 Mar 2022 03:42:23 +0000 Received: from DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::1d8b:d8d8:ca2b:efff]) by DU0PR04MB9417.eurprd04.prod.outlook.com ([fe80::1d8b:d8d8:ca2b:efff%3]) with mapi id 15.20.5102.016; Wed, 23 Mar 2022 03:42:23 +0000 From: "Peng Fan (OSS)" To: bjorn.andersson@linaro.org, mathieu.poirier@linaro.org, arnaud.pouliquen@foss.st.com Cc: linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org, peng.fan@nxp.com Subject: [PATCH V4 2/2] remoteproc: support attach recovery after rproc crash Date: Wed, 23 Mar 2022 11:44:05 +0800 Message-Id: <20220323034405.976643-3-peng.fan@oss.nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220323034405.976643-1-peng.fan@oss.nxp.com> References: <20220323034405.976643-1-peng.fan@oss.nxp.com> X-ClientProxiedBy: SG2PR06CA0111.apcprd06.prod.outlook.com (2603:1096:1:1d::13) To DU0PR04MB9417.eurprd04.prod.outlook.com (2603:10a6:10:358::11) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e93f289e-8a02-4cca-a499-08da0c7f241e X-MS-TrafficTypeDiagnostic: AM0PR04MB6868:EE_ X-MS-Exchange-SharedMailbox-RoutingAgent-Processed: True X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FkTD/+EuKG6lDroA37TuU5Uj6dggrHyptK5Vfuhyi1+026X1LPvcXls90HYiCN6rh9HQojWZlskvpxuizp12eNl8dcyeMSO+rzkiAZW/GC/tvFkgC0IN4Rey3NES/J7b0QeHfzpXBxU7SZxCK73LTBaDxMwnMCH2NvUY0Cl68IlfLN9ubqBI9R0gBWBE7lj9eNlCUaPJGPz1MoOUGy22bfuG3X9UrRP2Mwg3QGEUn9RGWHZ0BOuDizIIC5R1EtuBdmKk4sCV8XxyGvUTUrPCYnICw4qU2IJa//uLZAmQHeP0gY57VLWfLA7etNrdCtMdbBvLvAdNfw94GM9IPI5tKwriKXf7Pm1621zo32CA1nn3s1Uz0Cw64esMYVoPu18oiG2+2Skcxxapty6P3FuVkYga+qeO9AuCdN2aWI+N4cWudkdgE+rjlvbjZlhC8o4CFeNq6wb32tRRMPxAFIR2NsJ9e8EOvVh2T3kfmXO1f43md9sVD+yhtkBpX4qF76BruMGP55/cdu4Jc+tDCzm93FtdZf+uU46iz8RwTCRa6OOYmCjuvW8ARWmgfNAJ35s5qG2JQ8y8BtxyIky/Ij0UOk68bWFTVfPEHEVq60yOipEzUonvrvEaqJ56SSp1EDO8veDj424sRSBt0fUBy9VVQsRuFpRWwAW5X+LDlxzL6zVTPH1MiMW0zRu03+7xYityeTSgZNQ1i3FpjfLMbPsBdg== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:DU0PR04MB9417.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230001)(4636009)(366004)(83380400001)(52116002)(38350700002)(38100700002)(26005)(186003)(6512007)(8936002)(2616005)(5660300002)(2906002)(66476007)(66556008)(66946007)(508600001)(6486002)(6506007)(6666004)(316002)(1076003)(86362001)(8676002)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XdsH/WqwsXmDnN3lOHKECrM0M5XwAToDWyOVoCf0asmScxLmM+CRTKqFhmCvXSsGgdMOC0TPnUt/Z7+0ya3oYfV+zo26xzIw/IoBRWN+L8H2Tzo+gT68H5NX304aC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vuMhrrYSoscm38usTRQHLn7eXidI1PPrYok/Jdx2TknRNNuN7iBTUz2w2tbKNNppjp5KVp4p/VR3Ks6LEMvcl8r/vSq1e9jbuywLn0NclgbrxRQLnFKnoISF66KzXGL+OyyNHw/SSBZmHM21GRYlHvzgjnGxRC13dRodTWXKp5ttybDwcJ/axV03e9QOI7HvAXsTh8eCIh95PU51NLJ2WLGB+fZVAs+i/v+LIMvPYDfO6LP2c9sxZeB8hT2rFNiojH8a2o1z+rfAh7 X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e93f289e-8a02-4cca-a499-08da0c7f241e X-MS-Exchange-CrossTenant-AuthSource: DU0PR04MB9417.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2022 03:42:23.5226 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: bt5pyPymTEUsWBHG6DeSStux6kCXVqfbDX2kiamgNkw9U9B2SdrEH2Q+NWg7qoGIYKm5HBUI5Cj5eJp4TdIbzg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM0PR04MB6868 Precedence: bulk List-ID: X-Mailing-List: linux-remoteproc@vger.kernel.org From: Peng Fan Current logic only support main processor to stop/start the remote processor after rproc crash. However to SoC, such as i.MX8QM/QXP, the remote processor could do attach recovery after crash and trigger watchdog reboot. It does not need main processor to load image, or stop/start M4 core. Introduce two functions: rproc_attach_recovery, rproc_firmware_recovery for the two cases. Firmware recovery is as before, let main processor to help recovery, while attach recovery is recover itself withou help. To attach recovery, we only do detach and attach. Signed-off-by: Peng Fan --- drivers/remoteproc/remoteproc_core.c | 67 ++++++++++++++++++++-------- 1 file changed, 48 insertions(+), 19 deletions(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index c510125769b9..ad04515750ef 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1887,6 +1887,50 @@ static int __rproc_detach(struct rproc *rproc) return 0; } +static int rproc_attach_recovery(struct rproc *rproc) +{ + int ret; + + mutex_unlock(&rproc->lock); + ret = rproc_detach(rproc); + mutex_lock(&rproc->lock); + if (ret) + return ret; + + if (atomic_inc_return(&rproc->power) > 1) + return 0; + + return rproc_attach(rproc); +} + +static int rproc_firmware_recovery(struct rproc *rproc) +{ + const struct firmware *firmware_p; + struct device *dev = &rproc->dev; + int ret; + + ret = rproc_stop(rproc, true); + if (ret) + return ret; + + /* generate coredump */ + rproc->ops->coredump(rproc); + + /* load firmware */ + ret = request_firmware(&firmware_p, rproc->firmware, dev); + if (ret < 0) { + dev_err(dev, "request_firmware failed: %d\n", ret); + return ret; + } + + /* boot the remote processor up again */ + ret = rproc_start(rproc, firmware_p); + + release_firmware(firmware_p); + + return ret; +} + /** * rproc_trigger_recovery() - recover a remoteproc * @rproc: the remote processor @@ -1901,7 +1945,6 @@ static int __rproc_detach(struct rproc *rproc) */ int rproc_trigger_recovery(struct rproc *rproc) { - const struct firmware *firmware_p; struct device *dev = &rproc->dev; int ret; @@ -1915,24 +1958,10 @@ int rproc_trigger_recovery(struct rproc *rproc) dev_err(dev, "recovering %s\n", rproc->name); - ret = rproc_stop(rproc, true); - if (ret) - goto unlock_mutex; - - /* generate coredump */ - rproc->ops->coredump(rproc); - - /* load firmware */ - ret = request_firmware(&firmware_p, rproc->firmware, dev); - if (ret < 0) { - dev_err(dev, "request_firmware failed: %d\n", ret); - goto unlock_mutex; - } - - /* boot the remote processor up again */ - ret = rproc_start(rproc, firmware_p); - - release_firmware(firmware_p); + if (rproc_has_feature(rproc, RPROC_FEAT_ATTACH_RECOVERY)) + ret = rproc_attach_recovery(rproc); + else + ret = rproc_firmware_recovery(rproc); unlock_mutex: mutex_unlock(&rproc->lock);