Received: by 2002:a05:6a10:6d25:0:0:0:0 with SMTP id gq37csp1004433pxb; Sun, 12 Sep 2021 05:15:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzY2ohKK0IqYCwLQDdXLjoLtp2BPC6y1RnCKo+gvOrlOF0i9TAeuWW3I4UysWaC5Xv42EgZ X-Received: by 2002:a17:907:2662:: with SMTP id ci2mr7127338ejc.107.1631448911854; Sun, 12 Sep 2021 05:15:11 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1631448911; cv=pass; d=google.com; s=arc-20160816; b=ICcNduJhJXfEPLa/0XH0iWYiTeqXw9VubX88rNuddzPri/Z4VjFHaTHeVTMyzUd6no orPWbOZNfbgN6cZlovfQ7K0bMwUpKJNdhMOnBHWx19ci5n0vsSZqv8yXdoNDWZiKiik7 1ihUyuKcTVrADE6HcmoSZ4haD46bxY3WMpY1GgXlbnLOPgko/cAoNRbamMYVuLkeLk86 cZdsoxsVJCle4cPwil3qeoNc/yTUHRC4TQUdxTKXqACzi+tnMsBcxJEKqUh4x6JhxC1+ gCFuXGOsgMWKUpNoXRQuv20GlrTtj+Decnn7OyARdqOJAmkc0LzDMpoIf6OCsVW96VWx 6SMA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=P9pZMiXGVwO5diOksH6Sir5aScxYFqE8gQAMhW0kJwg=; b=kEeb3IGVYIdaYCno0ty70k36dHRVVytGJ87Q5KYj33wCDW6AqzxKDWi44f8Nnqjwgz EpXVJvCUAGlnIypWJdbDjDjyOccci8r2K9WSaj0Rm5/RkmjOIwcjvCWtIktlk+nCh+ic 386LXZ6Hf/QotT6x3WYv06RE6xVBg3wMHBEmRRZ/iIIz9LRrM+UVwcM9U7ucP5rlh0il XUyEcIWebWlQOWGrJrluQuP3GzUNUuZbGvFVco3ZH5WHVaLcxaLc5f4PfeqvbeGhzcy2 WVB/QP9nrds96rKDbaegwTkZt7v9kQGTK4bIhIFDfzdT/LVJ56IiknSl2N1/fmaR4py5 lazg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=HU2MX75Y; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dd7si5597288ejc.41.2021.09.12.05.14.47; Sun, 12 Sep 2021 05:15:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=HU2MX75Y; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235513AbhILMLU (ORCPT + 99 others); Sun, 12 Sep 2021 08:11:20 -0400 Received: from mail-eopbgr40056.outbound.protection.outlook.com ([40.107.4.56]:7737 "EHLO EUR03-DB5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235286AbhILMLJ (ORCPT ); Sun, 12 Sep 2021 08:11:09 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BK6gC/+D4KSnhO7Vs9JVDQoclYaAGo25f6NUe7QbtWRXGrTKW/BWfqXWFgUHFiGD8ngGTNbQ9i32ULdioRRzkpAKXBoc2gsMNx4jJf6LLpB0RYmx6A9pJr++oH9p1cKZBDFTUuExXQL25agT4lnkmtGk2Lk+gJDOC76V8UZnFoDLf7xFUA7ga9FzGat5aRsu1+RE/1P1aHGiRmknxpBt9h4n+f7D/Dxa5bWOR8MyiNUI+47PRQ7KAe814Q06iDgdBEa8k/9rS/rxKSgbgYzyZ339BchIVJiozejrnHelF4BNv2JrySqr+5Rj9MeaAgrcGw6x1i9MhXIYavYzpZBAYg== 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; bh=P9pZMiXGVwO5diOksH6Sir5aScxYFqE8gQAMhW0kJwg=; b=nOo6BIF+CGyk1bQgt6vK7NFh6uumWb4K72PUz5X1+3vIMmwZlHnMzwZ83t3OgpcEtUv2aBvi/jd+FdP9Yfarad0x9weHQqxbE+8GxQBzr6xe4rGWnP8cjTVepmG394M8efhWR5DJFCqWp0O+h53gtjJJ8yAQ0Q6XXYVy/9ovCrWpxgkgbU5AoOuEKC04tWh0pTR9pJ5HHLccLx/KM8UVEIMKVzb7zAxnadAIllu6VaxpkfPc5JlXh+RSK4NdAaMoKCOKegmWb7dHGTh1nvb6W39ThSSSxwbnM8ZlzTe1SHnr0lYhiaTGQBs3dphahwKAldUvLXuXdyWwHp4y8KeftA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=P9pZMiXGVwO5diOksH6Sir5aScxYFqE8gQAMhW0kJwg=; b=HU2MX75Y/m2SipnF5InYeAamO8wfhbRi6oe/ItvIX/moBGFDlEECZ0YQPe4pjPUn8ANdYihToEyQjUhmJ1uZlKMBxzvfjdxclp0VjNnimuao5Xl2/Ts+P0bGaBpgnEHc4sxgy6pQ/V0Et/GCsEr87qCsvW+ntVYT9b5pnWWg/FQ= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none;vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB5854.eurprd04.prod.outlook.com (2603:10a6:803:e2::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4478.19; Sun, 12 Sep 2021 12:09:52 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0%2]) with mapi id 15.20.4500.018; Sun, 12 Sep 2021 12:09:52 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean , "David S. Miller" , Jakub Kicinski , Kurt Kanzenbach , Hauke Mehrtens , Woojung Huh , UNGLinuxDriver@microchip.com, Sean Wang , Landen Chao , DENG Qingfang , Matthias Brugger , Claudiu Manoil , Alexandre Belloni , Linus Walleij , George McCollister , Heiner Kallweit , Russell King , Oleksij Rempel , Michael Grzeschik , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, Lino Sanfilippo Subject: [RFC PATCH net 5/5] net: dsa: xrs700x: be compatible with masters which unregister on shutdown Date: Sun, 12 Sep 2021 15:09:32 +0300 Message-Id: <20210912120932.993440-6-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210912120932.993440-1-vladimir.oltean@nxp.com> References: <20210912120932.993440-1-vladimir.oltean@nxp.com> Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: VI1PR07CA0173.eurprd07.prod.outlook.com (2603:10a6:802:3e::21) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.78.148.104) by VI1PR07CA0173.eurprd07.prod.outlook.com (2603:10a6:802:3e::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.9 via Frontend Transport; Sun, 12 Sep 2021 12:09:49 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b6b2ecc0-6a1f-4b0d-0702-08d975e63872 X-MS-TrafficTypeDiagnostic: VI1PR04MB5854: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2tEDzOUQ8D2AlvHId4iUbbDI8wtXg9seMJLgJADyf+aUFyWlFN4p5YUvreSVWFiUsldYJCTDYeSaCzh8Q+C5NDU3NSaw5V63KMPHlXn8LQtRRPWlCTz1LAnbYIKLEXNraHs2TlQ3xvtkp9ShF5IFtDivodetoSf1Ya+EMp1ul2O330BA/ZDRuZCuYWk79pT6aZes2Kls7wwognROmeMsd90vqeu8RN9OmMk931BXfMT1DtkdktrasXIalsl477iP5qsip8Xs0ZGhR2hCfzYaKXLs825Qg0RnzyiUWQZ6bR7JwvWfqJPupiu9cH4rYUSxYke0Gf4DdCd5O2lfiZxxTn7lkAUF0zkOFOaNDaRMkEWF0Frg2bq5WTufNwqkdu0DXXr6KRaYd1Q7o7Mc0vft27uqfmgpgwXJdVGK/4K5CJGS78retkO38IdGcxkgwcNn8jFWTEnxs+puHGDWTk1kGsT8lAdtvYqucyNKe+whWPg7VuklEhwVTPN+OJ28vwnqBNQ087tmFE59WFZhW8hp+d4Xhtqa+SiWk86Cn2SBDfpMyrkiNYfmVgAYp6j9lJ8yKtuZcNtRlkmDGWeL9LXowJXoArLnAEy+UCGS0BKo3ZZdggtw2V73MvLuW+n+pUe0lG5L6CjL/VEHPxjzmahno7CE9bw9WvkeOBZ/LHHLMZ/6SNiyZ05nBi7+gXY1oiwl7z0EhLNrfjfKkUuj1CrK96SeAoe2QwkM5wFCQq2SdO2tNtWF9DQceOmU+S5nCvsSABusByIW4am/Az4CcPrboocXoyiuYi4S8y0cL+InZ+Q= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5136.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(4636009)(396003)(366004)(346002)(136003)(376002)(39860400002)(966005)(316002)(83380400001)(4326008)(6506007)(86362001)(6512007)(26005)(44832011)(186003)(38100700002)(8936002)(5660300002)(478600001)(54906003)(2616005)(1076003)(7416002)(36756003)(6486002)(66946007)(2906002)(38350700002)(8676002)(6666004)(66476007)(66556008)(52116002)(6916009)(956004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?JaqXoF1/ZGN4xofkkJp9Nrpc6tyfk+t9zgwv0tetzXXERR9QbFJI/wgVByCQ?= =?us-ascii?Q?lJiIWxuoMR9SGMOIL6iLtjBIft9V2pTzJxbwhQoENYthPYMTYrk+WKIb1W/V?= =?us-ascii?Q?bM1vs2vcKqmV9WtNK4+brmY1yc20udP4FoE4UEWfRWx9fmbr97TrD2r7DWy1?= =?us-ascii?Q?boY7cpwJ9PPbz1vqVS0jDmw0njQAGg3Dhwv8SJudOVzz8G8DVdJJi/4DfHg0?= =?us-ascii?Q?7z1QnTDHYCr1PL7BHUrxjCYWJmvm1/+3Bdms6LT1kT+sDRMxfiT8Xc1v1u6z?= =?us-ascii?Q?YylO8am/4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S2?= =?us-ascii?Q?MbVNCOjo2K5tzpRVXv4tX5A3t1xhF0NHrJkZxYHN90ubZyePFkYe3zLfpY8I?= =?us-ascii?Q?s0vfb0c7I27Whk73o97Wpf5FKmpKZgaY9IjSNvIF+TvyQ12vVd1Sc05BaE+7?= =?us-ascii?Q?d27ScL6q1BI327zf0PVNc49t?= X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b6b2ecc0-6a1f-4b0d-0702-08d975e63872 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Sep 2021 12:09:50.1259 (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: +o89nBIPtxDeRwtT7XwbKAsBsAs9zQo9k4eF8e4g+7VQHMDefgaa69cxoXUmWTKgREXK4CSsvIPq2FUlcnwQvg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5854 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Since commit 2f1e8ea726e9 ("net: dsa: link interfaces with the DSA master to get rid of lockdep warnings"), DSA gained a requirement which it did not fulfill, which is to unlink itself from the DSA master at shutdown time. Since the Arrow SpeedChips XRS700x driver was introduced after the bad commit, it has never worked with DSA masters which decide to unregister their net_device on shutdown, effectively hanging the reboot process. To fix that, we need to call dsa_switch_shutdown. These devices can be connected by I2C or by MDIO, and if I search for I2C or MDIO bus drivers that implement their ->shutdown by redirecting it to ->remove I don't see any, however this does not mean it would not be possible. To be compatible with that pattern, it is necessary to implement an "if this then not that" scheme, to avoid ->remove and ->shutdown from being called both for the same struct device. Fixes: ee00b24f32eb ("net: dsa: add Arrow SpeedChips XRS700x driver") Link: https://lore.kernel.org/netdev/20210909095324.12978-1-LinoSanfilippo@gmx.de/ Reported-by: Lino Sanfilippo Signed-off-by: Vladimir Oltean --- drivers/net/dsa/xrs700x/xrs700x.c | 6 ++++++ drivers/net/dsa/xrs700x/xrs700x.h | 1 + drivers/net/dsa/xrs700x/xrs700x_i2c.c | 18 ++++++++++++++++++ drivers/net/dsa/xrs700x/xrs700x_mdio.c | 18 ++++++++++++++++++ 4 files changed, 43 insertions(+) diff --git a/drivers/net/dsa/xrs700x/xrs700x.c b/drivers/net/dsa/xrs700x/xrs700x.c index 130abb0f1438..469420941054 100644 --- a/drivers/net/dsa/xrs700x/xrs700x.c +++ b/drivers/net/dsa/xrs700x/xrs700x.c @@ -822,6 +822,12 @@ void xrs700x_switch_remove(struct xrs700x *priv) } EXPORT_SYMBOL(xrs700x_switch_remove); +void xrs700x_switch_shutdown(struct xrs700x *priv) +{ + dsa_switch_shutdown(priv->ds); +} +EXPORT_SYMBOL(xrs700x_switch_shutdown); + MODULE_AUTHOR("George McCollister "); MODULE_DESCRIPTION("Arrow SpeedChips XRS700x DSA driver"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/net/dsa/xrs700x/xrs700x.h b/drivers/net/dsa/xrs700x/xrs700x.h index ff62cf61b091..4d58257471d2 100644 --- a/drivers/net/dsa/xrs700x/xrs700x.h +++ b/drivers/net/dsa/xrs700x/xrs700x.h @@ -40,3 +40,4 @@ struct xrs700x { struct xrs700x *xrs700x_switch_alloc(struct device *base, void *devpriv); int xrs700x_switch_register(struct xrs700x *priv); void xrs700x_switch_remove(struct xrs700x *priv); +void xrs700x_switch_shutdown(struct xrs700x *priv); diff --git a/drivers/net/dsa/xrs700x/xrs700x_i2c.c b/drivers/net/dsa/xrs700x/xrs700x_i2c.c index 489d9385b4f0..6deae388a0d6 100644 --- a/drivers/net/dsa/xrs700x/xrs700x_i2c.c +++ b/drivers/net/dsa/xrs700x/xrs700x_i2c.c @@ -109,11 +109,28 @@ static int xrs700x_i2c_remove(struct i2c_client *i2c) { struct xrs700x *priv = i2c_get_clientdata(i2c); + if (!priv) + return 0; + xrs700x_switch_remove(priv); + i2c_set_clientdata(i2c, NULL); + return 0; } +static void xrs700x_i2c_shutdown(struct i2c_client *i2c) +{ + struct xrs700x *priv = i2c_get_clientdata(i2c); + + if (!priv) + return; + + xrs700x_switch_shutdown(priv); + + i2c_set_clientdata(i2c, NULL); +} + static const struct i2c_device_id xrs700x_i2c_id[] = { { "xrs700x-switch", 0 }, {}, @@ -137,6 +154,7 @@ static struct i2c_driver xrs700x_i2c_driver = { }, .probe = xrs700x_i2c_probe, .remove = xrs700x_i2c_remove, + .shutdown = xrs700x_i2c_shutdown, .id_table = xrs700x_i2c_id, }; diff --git a/drivers/net/dsa/xrs700x/xrs700x_mdio.c b/drivers/net/dsa/xrs700x/xrs700x_mdio.c index 44f58bee04a4..d01cf1073d49 100644 --- a/drivers/net/dsa/xrs700x/xrs700x_mdio.c +++ b/drivers/net/dsa/xrs700x/xrs700x_mdio.c @@ -136,7 +136,24 @@ static void xrs700x_mdio_remove(struct mdio_device *mdiodev) { struct xrs700x *priv = dev_get_drvdata(&mdiodev->dev); + if (!priv) + return; + xrs700x_switch_remove(priv); + + dev_set_drvdata(&mdiodev->dev, NULL); +} + +static void xrs700x_mdio_shutdown(struct mdio_device *mdiodev) +{ + struct xrs700x *priv = dev_get_drvdata(&mdiodev->dev); + + if (!priv) + return; + + xrs700x_switch_shutdown(priv); + + dev_set_drvdata(&mdiodev->dev, NULL); } static const struct of_device_id __maybe_unused xrs700x_mdio_dt_ids[] = { @@ -155,6 +172,7 @@ static struct mdio_driver xrs700x_mdio_driver = { }, .probe = xrs700x_mdio_probe, .remove = xrs700x_mdio_remove, + .shutdown = xrs700x_mdio_shutdown, }; mdio_module_driver(xrs700x_mdio_driver); -- 2.25.1