From patchwork Fri Sep 16 19:13:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Foster X-Patchwork-Id: 12978805 X-Patchwork-Delegate: kuba@kernel.org 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 244E3C6FA82 for ; Fri, 16 Sep 2022 19:14:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230137AbiIPTOJ (ORCPT ); Fri, 16 Sep 2022 15:14:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52728 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229561AbiIPTOH (ORCPT ); Fri, 16 Sep 2022 15:14:07 -0400 Received: from NAM10-BN7-obe.outbound.protection.outlook.com (mail-bn7nam10on2131.outbound.protection.outlook.com [40.107.92.131]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0CE9CB95BE; Fri, 16 Sep 2022 12:14:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=KyMiUYS8c5NRCml19fM1BlWFkmiLzXtTpjDfjwlM0F8nqwdcl6qvASIyt94cV1LWxiLh4C0YZ6tvR4O6Mw2GaM2RxFPtDLhLtc2ZvKVYNA9Xb0wdU9HoWM/g5ZeohkRKDg4Rb8dhmtQXI+DLLoSN6CT5ffM6MIo5hGC9S3JRPpHoy7rK8QylyGRqhlrmekWKSSlL+faiF2pd3hCEMY/7ddSFQr1FFcqoAhI5KRuMUcKS6aTOY5JCChDrWzDYPBlbOUpUvP9KBUNREn1edcvtvZEjTPvART41gLIn5yHjrpejIiHPzFSawxBhL8oLmU9uGtjyrP9H0JZxTlcqor05Ww== 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=UJIKaxTzzSw8cnqP4ZShA8X2sgUoJbY5qtHCbUbPKu0=; b=fkUSZwYgt3F0jzJmwP976hm2Qv9sGCl6ria427JWlfr/YJDto598A2nFw+BCuOX57OSFqgKsHv+2B4P3YJFEed/vxZoLvGM2dK23VZeCo7DKlfNC+RrFqrmSQl/NEro4ugk2XCrooh7QnJoMXlkmHj5zI0/QqXBv42ghRG98rf8RXFJTtFSEefRgC4d8+JJwTKMwyMZpMiLim5MSGl+DCZufgYxMvuyHjj26jseZEto1Y9aGFADZVZzzpZQ2XJRHN5viokyRA/NG4+wNA8Xgmu+rRxEOSEM438YbcGPMNiRo454iC8ZqEQV4csUxr+7VRC3iSky0NKnlXe8SFunMHg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=in-advantage.com; dmarc=pass action=none header.from=in-advantage.com; dkim=pass header.d=in-advantage.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=inadvantage.onmicrosoft.com; s=selector2-inadvantage-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UJIKaxTzzSw8cnqP4ZShA8X2sgUoJbY5qtHCbUbPKu0=; b=qed+chpos+TrMJkBn4g8SrKOaeCz63AmB8AGWvU89jYfJmK3l95NG2HHo8VQ99lOQi/Zq/AFV/dbyriBIr9sElci0hF3jSow2fj9IvxfTGliwc1qjx24SE4SHd+6VQ7yxwqLQ1cSA1hLHjG+vdH1PHS43PScZIHDG8zv31pGdfg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=in-advantage.com; Received: from MWHPR1001MB2351.namprd10.prod.outlook.com (2603:10b6:301:35::37) by SA2PR10MB4492.namprd10.prod.outlook.com (2603:10b6:806:11f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5632.17; Fri, 16 Sep 2022 19:14:01 +0000 Received: from MWHPR1001MB2351.namprd10.prod.outlook.com ([fe80::dcf2:ddbd:b18d:bb49]) by MWHPR1001MB2351.namprd10.prod.outlook.com ([fe80::dcf2:ddbd:b18d:bb49%3]) with mapi id 15.20.5632.015; Fri, 16 Sep 2022 19:14:01 +0000 From: Colin Foster To: linux-kernel@vger.kernel.org, netdev@vger.kernel.org Cc: Paolo Abeni , Jakub Kicinski , Eric Dumazet , "David S. Miller" , UNGLinuxDriver@microchip.com, Alexandre Belloni , Claudiu Manoil , Vladimir Oltean Subject: [PATCH v1 net-next 1/2] net: mscc: ocelot: utilize readx_poll_timeout() for chip reset Date: Fri, 16 Sep 2022 12:13:48 -0700 Message-Id: <20220916191349.1659269-2-colin.foster@in-advantage.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220916191349.1659269-1-colin.foster@in-advantage.com> References: <20220916191349.1659269-1-colin.foster@in-advantage.com> X-ClientProxiedBy: BY5PR04CA0015.namprd04.prod.outlook.com (2603:10b6:a03:1d0::25) To MWHPR1001MB2351.namprd10.prod.outlook.com (2603:10b6:301:35::37) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: MWHPR1001MB2351:EE_|SA2PR10MB4492:EE_ X-MS-Office365-Filtering-Correlation-Id: df35bd9c-b11f-4e2e-a15e-08da98179cfc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: A+oGlCp/9vv11v2RepUb7fL/xvc9AAJmndu0RaT+joZ3upmVRV4lT73EkAyDeH0UWcviSoESCC4dJjdmBxhGI8NVBNTc/FT1O4o/8QVXYbjd9qd1pOJw0CsTiZyMftF5lm4ccHO5B9tF5ozsvtMEM03sxn5g+9N0wkgysPY6H4eh3ZF6MKoxXZAZXW6SvDB2d/RLwueu8r920eNAjgRP0ZjXKF1GXuAYSSK/L/44/jvwmR47PHj2zNETf/xBjXSTN99NpDUKexvpQ3vhJHN6hwnoWy4O/iiuDVNoPoj9CjtEOr+Kozc+FCPSmh7sUDCEVVTADUHa6dLojyiGUHcTEB5muPIBHn7VVgWOY0dYJCfuvaHXckkl18B4DGbXpxDD6hr7bnSJd6TvvUoG2du5toMZSKz9yxJER+t32Ezy1KOfMN1cHEGYnSyxGGhC10NkzVDadVqigDx0wO7J+Fhw+ZznZJV+w2Io9J8LZuN2MoshZtLmyWIsYXSxGflfctjE7IVQHqoFPpNtXFwFzKd6bCO2IoxAq7Egqv3ODvID/6rShMr4/qsPcL3QYBckzJC+8Gwqbm3Dktq9HGhQKPvQyGi+7cgVcIrBVuwTdHEmZpxvZuJgU3OTCObxDyOHLYXDll2jBeeCuK4Uh1FBKEL8rrwlWVLhJ4WgFYA7cgINTyjwgq3xSmGXZQZeSvE29ltS5tu2V8iTO5iP9psc8hmJXQf4/HUJodf0dC2n4sax74AY62AO4NyccsUZnvzTgTGMP6ESIs8rDArsObBbnIZSyw== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR1001MB2351.namprd10.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230022)(366004)(39830400003)(396003)(376002)(136003)(346002)(451199015)(38350700002)(38100700002)(86362001)(36756003)(83380400001)(44832011)(6512007)(26005)(2906002)(478600001)(41300700001)(186003)(6486002)(6506007)(2616005)(1076003)(6666004)(52116002)(4326008)(66556008)(316002)(54906003)(66946007)(5660300002)(8676002)(7416002)(8936002)(66476007);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YjCzXdVLlkvA1jGqvK3JvpgB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TRUNEzOhQUoxvaLh0hnUG1bq5ODvy8sBtoBOhh1ElWkkT67sFykgBRf1eAghQ+6ptDkupcRxjihaZhphfkSilHQId706lQVlX27R0K/F/FKqxjI+boB09eE51cHrFFOrURe3m5tKzq2aBmNgi3KoVIij2gpKtdarcCDtWzu2HdopRWtCawZCu+N1O9QEZybEq0yDcCGZaPAhPg8U8umvVrZWsf9EjH4BlJIxf8ACHXmuiyw5T4O5eRDjJvg7PnSyuIBEJT7d39HQPO3pdZxtWGJqzRm6hrXl0ZIs5+WMDicQEK5iGcX4DPFPvN9NCU2qoIf16dkqZ12Zx9gzVgfiuczMp2+eRhIDPHg5rqz2rm3prkS8fdBb5tCbX3yqUZ9Y1tBNKBTMTlXBrfuUytdxi4mco037sEuaGYqnHFTBga4QAKWVDmnKTvodNWlf2+IYlnOYZHDehx50jwzmpYKqg0mOJOiT/7Kj4Cy8sRBDG1zam9w0p38Nm/u2L7X4hqYKn7vsPaVCFTxTmQUZuwgInR8rpDm2M= X-OriginatorOrg: in-advantage.com X-MS-Exchange-CrossTenant-Network-Message-Id: df35bd9c-b11f-4e2e-a15e-08da98179cfc X-MS-Exchange-CrossTenant-AuthSource: MWHPR1001MB2351.namprd10.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Sep 2022 19:14:01.3693 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 48e842ca-fbd8-4633-a79d-0c955a7d3aae X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Oc4qf+GjUt2vq8eXGm4ALbR3ESGs+Pmv4DaJMP1PZLd7jIXwk7gBEyf2DyPnaNvUDXiU4Aw2+yBvmqzLS8HMrzu7uzMzXkHFcPhWWaLAE2M= X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR10MB4492 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Clean up the reset code by utilizing readx_poll_timeout instead of a custom loop. Signed-off-by: Colin Foster Reviewed-by: Vladimir Oltean Reported-by: kernel test robot --- drivers/net/ethernet/mscc/ocelot_vsc7514.c | 32 ++++++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot_vsc7514.c b/drivers/net/ethernet/mscc/ocelot_vsc7514.c index ae42bbba5747..79b7af36b4f4 100644 --- a/drivers/net/ethernet/mscc/ocelot_vsc7514.c +++ b/drivers/net/ethernet/mscc/ocelot_vsc7514.c @@ -6,6 +6,7 @@ */ #include #include +#include #include #include #include @@ -25,6 +26,9 @@ #define VSC7514_VCAP_POLICER_BASE 128 #define VSC7514_VCAP_POLICER_MAX 191 +#define MEM_INIT_SLEEP_US 1000 +#define MEM_INIT_TIMEOUT_US 100000 + static const u32 *ocelot_regmap[TARGET_MAX] = { [ANA] = vsc7514_ana_regmap, [QS] = vsc7514_qs_regmap, @@ -191,22 +195,32 @@ static const struct of_device_id mscc_ocelot_match[] = { }; MODULE_DEVICE_TABLE(of, mscc_ocelot_match); +static int ocelot_mem_init_status(struct ocelot *ocelot) +{ + unsigned int val; + int err; + + err = regmap_field_read(ocelot->regfields[SYS_RESET_CFG_MEM_INIT], + &val); + + return err ?: val; +} + static int ocelot_reset(struct ocelot *ocelot) { - int retries = 100; + int err; u32 val; regmap_field_write(ocelot->regfields[SYS_RESET_CFG_MEM_INIT], 1); regmap_field_write(ocelot->regfields[SYS_RESET_CFG_MEM_ENA], 1); - do { - msleep(1); - regmap_field_read(ocelot->regfields[SYS_RESET_CFG_MEM_INIT], - &val); - } while (val && --retries); - - if (!retries) - return -ETIMEDOUT; + /* MEM_INIT is a self-clearing bit. Wait for it to be cleared (should be + * 100us) before enabling the switch core. + */ + err = readx_poll_timeout(ocelot_mem_init_status, ocelot, val, !val, + MEM_INIT_SLEEP_US, MEM_INIT_TIMEOUT_US); + if (IS_ERR_VALUE(err)) + return err; regmap_field_write(ocelot->regfields[SYS_RESET_CFG_MEM_ENA], 1); regmap_field_write(ocelot->regfields[SYS_RESET_CFG_CORE_ENA], 1);