From patchwork Sun Sep 12 12:09:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 509695 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E5DE2C433F5 for ; Sun, 12 Sep 2021 12:10:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CA980610A3 for ; Sun, 12 Sep 2021 12:10:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235188AbhILMLF (ORCPT ); Sun, 12 Sep 2021 08:11:05 -0400 Received: from mail-db8eur05on2061.outbound.protection.outlook.com ([40.107.20.61]:24243 "EHLO EUR05-DB8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234976AbhILMLB (ORCPT ); Sun, 12 Sep 2021 08:11:01 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Sdz+Df/vaBRgtmh6WTdU2yTo00GZX/2Te9nW8dxhliHx62Y/PKBtQ7edLpQCzzCCunP63nwm+Am/GqHxi1mKYNI3Nq5LiumaxWodVYNdnjLL44pYSXFQUaByqRznu1I06CVGhvcrkeI42BxSJc/Q0j57mH9U2I/7v/CGmqBQzEnJMypphWY0rcOvBzqf6y4APfT5XHHjDsd7jGhCOpGi95voxqp9VEVXwaCCbtM6MVIkSErhKOfw0jxkA9IQQdsFfbY7DkztLm6wsFtneqnCCUI+ai/hskhtwnc4djmcx59bBljxZoVRa2X6YLPDB38cSKpiPVxw9RpfExHotDbeww== 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=J9ber5dIChVxmuivHBAPLqZNJn6AP/yxw/NPKphN9uI=; b=aN+SmYvgCeYHH2PWEIEGwt67M6SNeMlIxY2oOFYLwRlXBZ5w6G82txVor7ICxnhjbfT2NflWeOBFrxZXuwxpyche0mHuSe67x9wAuorxFxJkx1+gqnaJJK3M4mwwMqHoBBmIB7wrRVBqKMy8B9cvnoX+fRYYAnabhAkHjOeFkkWG4A8JlOmpduugJWfjR2WnqO1Ms+v2pxZkKorVODjvRzLlyrQ8q3xKQi690Q1v+QM/C44Mj00T/9pubUlu0w5WJKmJAxt0og3XuENL9R5hlNikm9qbrem2xkWY00yYnV7QNiP76g4R5SnD7MTvgvSw1F41FtIwTxzIhK9GYUSobw== 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=J9ber5dIChVxmuivHBAPLqZNJn6AP/yxw/NPKphN9uI=; b=CeegYrrLTsJAeHNm+s0R1TeIdpDiNAO/uU4ul7m8k/Wg0B7cv+nbzw5TTVnCfe3zKj5CMy5N7e+uB9/zN4I1UqQNmDFjc2CxRDYKsXVqixww/L8uTI3XdlLDRRuZAA+apih/x3QMB0ldSgsaBZP+n4NJCvDFvYa1xDm5h1UKCms= 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:45 +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:45 +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 1/5] net: mdio: introduce a shutdown method to mdio device drivers Date: Sun, 12 Sep 2021 15:09:28 +0300 Message-Id: <20210912120932.993440-2-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> 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:44 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9303c39e-643e-4cb8-403e-08d975e63585 X-MS-TrafficTypeDiagnostic: VI1PR04MB5854: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1923; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: omcWlLe5pWmMRMbnXdusGRmIErC8aJwm4iNmpEDgLA2B5a4OqI3WcXOq//iHHmQBcjdQuZf/0BfF8kyN21tIlVUFOW6tXCC4ovxoPUYFr1edrnWOb32M7Sv2QCghyYz4O8OTAIY0mRFlJXKWdfEZRUwfggdlPBqNEswKcd8mHhDVZRwSJCjsKLfFn+y1UHZqE7NqT6Ag8E/pV/X7cUpUubKGKZGvcrGMd8RVKvROk9HZAcXlttTUsvJf/VOhwJJ1P+hHFf65t9dlVmi/3mtfn82Z0TUK8kZ07vhJPNXKzpHH43h+nYgeb9Rp0kRMs6cBsNU0XO3nplFne1MX/ek8iRbQ3icZ4tV3DsGzaZqaGhU5wFDjNNZ1MuvFsU/zwCOgfm49QAiw2V40V7BZ6GYgTPww8LvrwnzGLjtPqjEOKwJWlbwgmMcf3QjJHYtkL0by15AOKFzxcruGIqIgmoXrzwQGXsmTEsnhKyxLCwwASDP+EMuJAbbc1WYzKYWMW40QpdF2uw7TbtsOey1AnoJTgkswzvePspwaYQal/xYX5uqtpgZx+qIFIUL5mtvbWeXttL/D3UYlqHXLOk8m7TXr49pGy2DZfIZN+qqZXg0UAxE2QAMhd7Yt+PBoj6mXyApT897sG92zzsj/R1AFd6W6nSdlzrbHU7mBbWDwkbE+f8FLyiC+YL+czrrUTnl6K2yORrtkw/S7KwQ51c4ZbPxO7Q== 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)(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: 8g9DSY4s0SQCpEU6gKR/WR5K+P4TqmoDHOVyUDOy9Mu7U2/Hv0FXI/5vsJn4+A/ODNrR6uMNGevih16tqJVfgLwZef3gjmzTdCISNp6GPsgcrQKbV3KVVKdyuZhKqn7E0taRV8qfIxfqR7VqDkmavdn1NOFnhFWV/N0YygzMxmvxFVKilEJeld1z6m6UfgxfpvbtCONNoZrzcMs6FhEOMMK670FHifmHeLr/XlIcW5O026IlZgoM2I+Ci6RGVoaKPoOx2O2fzH2JSTgZhzIF2+8Co4D2vBXljN4vYsxIMGAagGJUZYfCAN0oMRWs8SylOBhwKlGuXJkH31ZfaVxH9BqP35FVG3xlgIThGyXxRSGjM0doeE/5O6NBkLq4wZXx4tSUCtqBMNs4cK1475FVwT0qyiOE5WcWA/hcrAF/Fv4LcMw26kYCglrp15Sfxxv5Qc4kwnUnM0ccjHIMYBiUD9FlTiPeHdVQgVcDI+g010lD+dF1DmxNm3Bn5hNsB3PNtb310vNr3Q0i4afUVQfbTTJOTyOuaCmKonPg04RzVCRrGT+o7ts9e02q4e+MigRoAM9nsDgdHXRXmRBtcKH/HLhK9Bc5vRCD3UpOCkz/+/tAsmpLT++FyRwKml9U9hbgUQnfrHx+C++Q/bFHXFM6py/ysYENRN35s3g1LQP5IKlrtsCS/PMnpCMewyPyhrUQIe0aZm5+/ZiYCbjl4dYDL7wEy7K+eUQYSKsRABFuppfelU9103F6nVS754+nFcMIdTCGBkCJqZGtU0u9BR64YcPr5/hJE2Aw6JPeP4WqcUDlPo0K7blF9sZCyGaf8FvAzKRc85JQFPqParkB2o35CEnvMIAIZVqb4KqoT6DdyrjaAjw/VkItpQrpu2G3uO9X4Z3aohfBfhknjSk+FGcJW8i1MIyKHRxP7u9qUbxqHQMGlBt5EIg1YTv05ARvaCVyILpg6GcU0hJjn1SUOXpOmeTPi6z+a5pVYOqaYgBjW8QDlbfFsQbJrnCwF3whJEJRlz/LLqELG3LqBy8E45h7qQT+1zHEE2+u5I6fkX3knGpUifkF/UTcZXz0q7ioYq/4GvO1+OeO1bR6q/gF+gj7zqH7iqrjcdF+XauXiK+TNpLS3fdXRQ/P2V/DplNObrhDGAGXmaI5SBY+P7elz6/0JtOlpUmVzDFeLkCpjZgi+1wD+q3vHRpvpUmGlbybrlo2bChWoLhYvIfBYsoaYjLI/iqsFBwAgmlwXB5/NqzpjscPkt0hbNDZvkFeDWMqQC1p793mZ/YL+I1ku31AYvUnL0yIZkxTq2uwtdtJySt/LIbnRRoocA9GwQhqAiIjPeP/ X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9303c39e-643e-4cb8-403e-08d975e63585 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:45.2407 (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: YW7GrZThmFvNKvugdjRZfFRqkrNHUIkxKs50SPgtEUE6y0QAOvg4NFeumPpMXkD2XLRly2qOazU4xO5wi77YuA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5854 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org MDIO-attached devices might have interrupts and other things that might need quiesced when we kexec into a new kernel. Things are even more creepy when those interrupt lines are shared, and in that case it is absolutely mandatory to disable all interrupt sources. Moreover, MDIO devices might be DSA switches, and DSA needs its own shutdown method to unlink from the DSA master, which is a new requirement that appeared after commit 2f1e8ea726e9 ("net: dsa: link interfaces with the DSA master to get rid of lockdep warnings"). So introduce a ->shutdown method in the MDIO device driver structure. Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli Reviewed-by: Andrew Lunn --- drivers/net/phy/mdio_device.c | 11 +++++++++++ include/linux/mdio.h | 3 +++ 2 files changed, 14 insertions(+) diff --git a/drivers/net/phy/mdio_device.c b/drivers/net/phy/mdio_device.c index c94cb5382dc9..250742ffdfd9 100644 --- a/drivers/net/phy/mdio_device.c +++ b/drivers/net/phy/mdio_device.c @@ -179,6 +179,16 @@ static int mdio_remove(struct device *dev) return 0; } +static void mdio_shutdown(struct device *dev) +{ + struct mdio_device *mdiodev = to_mdio_device(dev); + struct device_driver *drv = mdiodev->dev.driver; + struct mdio_driver *mdiodrv = to_mdio_driver(drv); + + if (mdiodrv->shutdown) + mdiodrv->shutdown(mdiodev); +} + /** * mdio_driver_register - register an mdio_driver with the MDIO layer * @drv: new mdio_driver to register @@ -193,6 +203,7 @@ int mdio_driver_register(struct mdio_driver *drv) mdiodrv->driver.bus = &mdio_bus_type; mdiodrv->driver.probe = mdio_probe; mdiodrv->driver.remove = mdio_remove; + mdiodrv->driver.shutdown = mdio_shutdown; retval = driver_register(&mdiodrv->driver); if (retval) { diff --git a/include/linux/mdio.h b/include/linux/mdio.h index ffb787d5ebde..5e6dc38f418e 100644 --- a/include/linux/mdio.h +++ b/include/linux/mdio.h @@ -80,6 +80,9 @@ struct mdio_driver { /* Clears up any memory if needed */ void (*remove)(struct mdio_device *mdiodev); + + /* Quiesces the device on system shutdown, turns off interrupts etc */ + void (*shutdown)(struct mdio_device *mdiodev); }; static inline struct mdio_driver * From patchwork Sun Sep 12 12:09:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 509694 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58F5AC433FE for ; Sun, 12 Sep 2021 12:10:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B92F610A6 for ; Sun, 12 Sep 2021 12:10:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235308AbhILMLJ (ORCPT ); Sun, 12 Sep 2021 08:11:09 -0400 Received: from mail-db8eur05on2061.outbound.protection.outlook.com ([40.107.20.61]:24243 "EHLO EUR05-DB8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235151AbhILMLD (ORCPT ); Sun, 12 Sep 2021 08:11:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=At5fsgWaCr1J4rseed/Z9NRBQc0mAhIpuxAJTsCYGegPMcChMu5kqU2jfqY5hgAD2fwNRmNyJ2PTzEGA4IoRtlwzXTBwOczaOWFQSHyxA4gXoERcT7QaaUZKxcafrJBvyOy83bhrigLbIAfsxVZpiUdvjkxKSrMMKPcYuSlAXxj6ArFVlL7lIGfFUmHFfgzuAtAjDZ52zB7rzS3US2xmoVBpwLQg2VRB+Y5fZJ3EIiciBfDE4AZiXqRHAjY2CSSdbRhgXYHycGGQkIdScG1Kb1lFYkY2rgxhjwB1p77OPJJgoJEewZYWYH0wplaRw6ijBPMyTIwnCxaAe7eRZ0gIWQ== 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=3P6sCjA1S50IUefbEfuY/SFedyb2hEPt0tAEKW2c1Rw=; b=Mfb1lIsf6NPeGfMkjRTHO/52CR/++6/lGRCYsaiR83yinRoD/7/jcS6a6w3IbzZLmMTPJaHZ2xeKmcutPVM9TBtwXCr/laUhBsSldSAuXGJoyRaQYsGb9TPjhIhHqTqmXgWXesiDoO84W4v+dw6oZPQpXiPom0om1oqUaDhSZeGCMHnsYuE+wjzGSSE42/+/3IJEhO8QANtIUYuKAXyV8Z6p9iEE1h8E7J9VQddSSH2iNRSHATAdNMQ5X8aoMT8P4+5W0Vbf0fQEadil0u+KHeTL7iF219AZFZkab+ZQze2es75kimemNAgcrFgDmSEVfvODaexd3p64bHnyOJbWmw== 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=3P6sCjA1S50IUefbEfuY/SFedyb2hEPt0tAEKW2c1Rw=; b=IQXoTzoDkJ5/S3P+mj3uf3xXG0C1hckkAS2Fq8K6nlTAtgn2l6jCw72yFcZKyI+SFeccNg2lm3rzNPWIpvPcAvw75M+yvU6HZdwfkQKtNs5w6Eo67+wygnXHnUWhfNGUw2nnMO83jkVZRoM+JU1d1tUC4hdpYBoc9TyQe0BE3E0= 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:46 +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:46 +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 2/5] net: dsa: be compatible with masters which unregister on shutdown Date: Sun, 12 Sep 2021 15:09:29 +0300 Message-Id: <20210912120932.993440-3-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> 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:45 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c783c576-883b-4f25-78a5-08d975e6363d X-MS-TrafficTypeDiagnostic: VI1PR04MB5854: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qLqxkwuVkOBGJPmBfTqBOd2acoRcI48BUpVeRHQug230/g33wbHLZVYDeKA8xrAESikiVjY5qWQkc3Pp7QFoLTXpn0V7g2ZsSMtuqAQtRCuygJkF5Li96IS42t5W/F9OPTp6gBW8hGvLWCHfvkjE+hkyOWxWxYJqbkuL2rnwRh45VcojaTNpGW1dU5QZpmxZrAGPs9LivUsyTX2mK+gOnmbUL3Y7C8coUzNnwDJxde9Uat5iUe3Vfus8OYxmhpRU0Lx/wtZKFDPGDFstFOQ6D1Y6nYoO8GjvYYRkmUr8jL+3H4/5WjDjtWzefD+yK/IY/+wUUup5sXbn0YtkXWJmmrsLJgJO5jliueFZIXctMdKpRkhgzXPPdCNgzkqsbm4JeQttxLrpWW/JDX05rO1WL3RWY7TCApx4daZByA4+9zLYd4kU4cCESCKMmbIo4kfR2uEtAZnNEvMgtF6JwLAKcjDE4bnFkcKVzrPyQKWcfewILs6rq33ZvXhgZEMaqDMmoeGNFaNZrnFmhqhFykBU5QSOf2Gz9IMqctm9UihRYiNkK84cMFcp96kZ9uSVa+P0at5vUGtXljXzd8h3DRaXU6zuGXuQvxhY65m8w9s5w3DDR0bJkkwBGbmL1j6QzwPfgMUvkuYVVFBgE4dnMOKVpnlZVJgcA24Uh7irUll9LN0lQfqknaNDM3Wylu+yyt8XXP+bcYPhQjCXTmRUp7TKapUrw/gYoEfTNXyRXtzHOlCGF5ywmeqU0u+JKEegMDnzKAxiB/6S6INO/m8mwTC79ME6emRVQAO+OBsUXCtLS7s= 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)(30864003)(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: vq9dy7VVrS+LXVVOopDpA2Vf17mEeTPxcFNMPAHwxzihTbLRztMPZUm/mya66kZeVrOFkZ0HErTQ+l+kteVFZzoJjpBK9MYWDknaDHKkSkN/nsmgLFmiP0dMdWav5/1xNpRiRy38SfZa19pDP3hj5ke5tNrm4U3BhGZRCTmQVJqnjTqD+VEroR1lBJe8q+6t3ho51bH4sPymn33tX6Tjr/ztDDFsMiVmfAv/YJYZtvbZRYrFkUiW7ehsFTVFWOKbUYyglhATDuVgRwSRSv84ANJRYurr96lU6mos3VY0bcVgODWRfmLKOiYD6plZ+mqWQHLENuzsSOziSA5KWoxaRD5Xog7+AAiXWPdL+DD6oZnQfFwN3QW86lsjDR48X7YufC5vu3Q05pTzceJHo93+YgarzGPQamSeFUQHuqvpvQpM9Qc8yld4GajZ0R7BgHItARNpiweAWtzxhVbQ6ZSv1i6K4y6oUWga/KF1MFxwwrbJtfN2TPx1uo+bMZsF18GobPiT6DIOQcRA9KOyHfcob/0l4WF+tCygPsgyccnEK8cjU7MBOeWyEX3++B48c4XFEyvV5y+pVNfJu46F1dUjt50kRnn0rSIIOXLuyDvljJnWNia0GUf7lAfq/YCmvH4JyQaVQ4ul1tUImgDf9bxKscmn1gXB97J2TfqqYaQ4d8aUEdCqucVr4+SbAnLJ6hW4DPTVX7CcOXUcypxoFQjf7KgrKXGxTCVeGYtiaVB7ud50L8Klo9pTvyNVbPe81Eu+xbl4srSiNDwuhU1ATDoqwgmrWpr0dUq8Ez7T2fLCXLWhgp9ALdB5kAkWiwReiadjCJeLyW81yXd+GltBDySOLspagPs2ixAFXECGZ2bx8ETd3ojrPXVbyUQz1OK3Y9cQOgqiPJ/BoS9Xb9wQAHSuBokcI1V0ZzCFN+jfOTeIoKVdyHEJ5SzUFy9IFPpPql4fAKNIHnf6EthVDHhXueyk+UwIBTQ295ahValBMktW/6lFPlA6opSFg0rpdZ5w85W1SQ1A+I84c7Uno7vk8lfeQK4BDbzUe2L5ViVLMuY3gQDgY2YwldCVahZvLEu0OW0TDd5HJIAAbGqKnqnxeFPBhmWPMCrS4D2N6ASQdL+kk1y6Si+aEwzBv4Q0D3uhUWA0+dCB0//TC8ooiVQxK8rXwdumaQADPW3z5Eo4RaN7YU9SDb5KB0f8swetJ70LWibVOBprtDo5bxrMWR/2FKtuVvL5Pg+lzvAZtgY0BkLWg77czTYCssj6c8qrGeTgCCpHzNsp6cOodcpbO8EEACrLGKEtlQyGt/8Y3u+I3UciVUOnu+2uNt0C+eN+RXz+6Exr X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c783c576-883b-4f25-78a5-08d975e6363d 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:46.5260 (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: wnaZLrHoNA0AaK+UBIA6Kk1Eh6neBkWtLqPMGiGfcbD3wNWF1LU0dRVGN1nIMuT3pqFeS/CBILv7gS3RKTx9Vg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5854 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Lino reports that on his system with bcmgenet as DSA master and KSZ9897 as a switch, rebooting or shutting down never works properly. What does the bcmgenet driver have special to trigger this, that other DSA masters do not? It has an implementation of ->shutdown which simply calls its ->remove implementation. Otherwise said, it unregisters its network interface on shutdown. This message can be seen in a loop, and it hangs the reboot process there: unregister_netdevice: waiting for eth0 to become free. Usage count = 3 So why 3? A usage count of 1 is normal for a registered network interface, and any virtual interface which links itself as an upper of that will increment it via dev_hold. In the case of DSA, this is the call path: dsa_slave_create -> netdev_upper_dev_link -> __netdev_upper_dev_link -> __netdev_adjacent_dev_insert -> dev_hold So a DSA switch with 3 interfaces will result in a usage count elevated by two, and netdev_wait_allrefs will wait until they have gone away. Other stacked interfaces, like VLAN, watch NETDEV_UNREGISTER events and delete themselves, but DSA cannot just vanish and go poof, at most it can unbind itself from the switch devices, but that must happen strictly earlier compared to when the DSA master unregisters its net_device, so reacting on the NETDEV_UNREGISTER event is way too late. It seems that it is a pretty established pattern to have a driver's ->shutdown hook redirect to its ->remove hook, so the same code is executed regardless of whether the driver is unbound from the device, or the system is just shutting down. As Florian puts it, it is quite a big hammer for bcmgenet to unregister its net_device during shutdown, but having a common code path with the driver unbind helps ensure it is well tested. So DSA, for better or for worse, has to live with that and engage in an arms race of implementing the ->shutdown hook too, from all individual drivers, and do something sane when paired with masters that unregister their net_device there. The only sane thing to do, of course, is to unlink from the master. However, complications arise really quickly. The pattern of redirecting ->shutdown to ->remove is not unique to bcmgenet or even to net_device drivers. In fact, SPI controllers do it too (see dspi_shutdown -> dspi_remove), and presumably, I2C controllers and MDIO controllers do it too (this is something I have not researched too deeply, but even if this is not the case today, it is certainly plausible to happen in the future, and must be taken into consideration). Since DSA switches might be SPI devices, I2C devices, MDIO devices, the insane implication is that for the exact same DSA switch device, we might have both ->shutdown and ->remove getting called. So we need to do something with that insane environment. The pattern I've come up with is "if this, then not that", so if either ->shutdown or ->remove gets called, we set the device's drvdata to NULL, and in the other hook, we check whether the drvdata is NULL and just do nothing. This is probably not necessary for platform devices, just for devices on buses, but I would really insist for consistency among drivers, because when code is copy-pasted, it is not always copy-pasted from the best sources. So depending on whether the DSA switch's ->remove or ->shutdown will get called first, we cannot really guarantee even for the same driver if rebooting will result in the same code path on all platforms. But nonetheless, we need to do something minimally reasonable on ->shutdown too to fix the bug. Of course, the ->remove will do more (a full teardown of the tree, with all data structures freed, and this is why the bug was not caught for so long). The new ->shutdown method is kept separate from dsa_unregister_switch not because we couldn't have unregistered the switch, but simply in the interest of doing something quick and to the point. The big question is: does the DSA switch's ->shutdown get called earlier than the DSA master's ->shutdown? If not, there is still a risk that we might still trigger the WARN_ON in unregister_netdevice that says we are attempting to unregister a net_device which has uppers. That's no good. Although the reference to the master net_device won't physically go away even if DSA's ->shutdown comes afterwards, remember we have a dev_hold on it. The answer to that question lies in this comment above device_link_add: * A side effect of the link creation is re-ordering of dpm_list and the * devices_kset list by moving the consumer device and all devices depending * on it to the ends of these lists (that does not happen to devices that have * not been registered when this function is called). so the fact that DSA uses device_link_add towards its master is not exactly for nothing. device_shutdown() walks devices_kset from the back, so this is our guarantee that DSA's shutdown happens before the master's shutdown. Fixes: 2f1e8ea726e9 ("net: dsa: link interfaces with the DSA master to get rid of lockdep warnings") Link: https://lore.kernel.org/netdev/20210909095324.12978-1-LinoSanfilippo@gmx.de/ Reported-by: Lino Sanfilippo Signed-off-by: Vladimir Oltean Tested-by: Andrew Lunn --- drivers/net/dsa/b53/b53_mdio.c | 21 +++++++++- drivers/net/dsa/b53/b53_mmap.c | 13 ++++++ drivers/net/dsa/b53/b53_priv.h | 5 +++ drivers/net/dsa/b53/b53_spi.c | 13 ++++++ drivers/net/dsa/b53/b53_srab.c | 21 +++++++++- drivers/net/dsa/bcm_sf2.c | 12 ++++++ drivers/net/dsa/dsa_loop.c | 22 ++++++++++- drivers/net/dsa/lan9303-core.c | 6 +++ drivers/net/dsa/lan9303.h | 1 + drivers/net/dsa/lan9303_i2c.c | 24 +++++++++-- drivers/net/dsa/lan9303_mdio.c | 15 +++++++ drivers/net/dsa/lantiq_gswip.c | 18 +++++++++ drivers/net/dsa/microchip/ksz8795_spi.c | 11 +++++- drivers/net/dsa/microchip/ksz9477_i2c.c | 14 ++++++- drivers/net/dsa/microchip/ksz9477_spi.c | 8 +++- drivers/net/dsa/mt7530.c | 18 +++++++++ drivers/net/dsa/mv88e6060.c | 18 +++++++++ drivers/net/dsa/mv88e6xxx/chip.c | 22 ++++++++++- drivers/net/dsa/ocelot/felix_vsc9959.c | 20 +++++++++- drivers/net/dsa/ocelot/seville_vsc9953.c | 20 +++++++++- drivers/net/dsa/qca/ar9331.c | 18 +++++++++ drivers/net/dsa/qca8k.c | 18 +++++++++ drivers/net/dsa/realtek-smi-core.c | 20 +++++++++- drivers/net/dsa/sja1105/sja1105_main.c | 21 +++++++++- drivers/net/dsa/vitesse-vsc73xx-core.c | 6 +++ drivers/net/dsa/vitesse-vsc73xx-platform.c | 22 ++++++++++- drivers/net/dsa/vitesse-vsc73xx-spi.c | 22 ++++++++++- drivers/net/dsa/vitesse-vsc73xx.h | 1 + include/net/dsa.h | 1 + net/dsa/dsa2.c | 46 ++++++++++++++++++++++ 30 files changed, 453 insertions(+), 24 deletions(-) diff --git a/drivers/net/dsa/b53/b53_mdio.c b/drivers/net/dsa/b53/b53_mdio.c index a533a90e3904..a7aeb3c132c9 100644 --- a/drivers/net/dsa/b53/b53_mdio.c +++ b/drivers/net/dsa/b53/b53_mdio.c @@ -351,9 +351,25 @@ static int b53_mdio_probe(struct mdio_device *mdiodev) static void b53_mdio_remove(struct mdio_device *mdiodev) { struct b53_device *dev = dev_get_drvdata(&mdiodev->dev); - struct dsa_switch *ds = dev->ds; - dsa_unregister_switch(ds); + if (!dev) + return; + + b53_switch_remove(dev); + + dev_set_drvdata(&mdiodev->dev, NULL); +} + +static void b53_mdio_shutdown(struct mdio_device *mdiodev) +{ + struct b53_device *dev = dev_get_drvdata(&mdiodev->dev); + + if (!dev) + return; + + b53_switch_shutdown(dev); + + dev_set_drvdata(&mdiodev->dev, NULL); } static const struct of_device_id b53_of_match[] = { @@ -373,6 +389,7 @@ MODULE_DEVICE_TABLE(of, b53_of_match); static struct mdio_driver b53_mdio_driver = { .probe = b53_mdio_probe, .remove = b53_mdio_remove, + .shutdown = b53_mdio_shutdown, .mdiodrv.driver = { .name = "bcm53xx", .of_match_table = b53_of_match, diff --git a/drivers/net/dsa/b53/b53_mmap.c b/drivers/net/dsa/b53/b53_mmap.c index 82680e083cc2..62ea45f492f3 100644 --- a/drivers/net/dsa/b53/b53_mmap.c +++ b/drivers/net/dsa/b53/b53_mmap.c @@ -316,9 +316,21 @@ static int b53_mmap_remove(struct platform_device *pdev) if (dev) b53_switch_remove(dev); + platform_set_drvdata(pdev, NULL); + return 0; } +static int b53_mmap_shutdown(struct platform_device *pdev) +{ + struct b53_device *dev = platform_get_drvdata(pdev); + + if (dev) + b53_switch_shutdown(dev); + + platform_set_drvdata(pdev, NULL); +} + static const struct of_device_id b53_mmap_of_table[] = { { .compatible = "brcm,bcm3384-switch" }, { .compatible = "brcm,bcm6328-switch" }, @@ -331,6 +343,7 @@ MODULE_DEVICE_TABLE(of, b53_mmap_of_table); static struct platform_driver b53_mmap_driver = { .probe = b53_mmap_probe, .remove = b53_mmap_remove, + .shutdown = b53_mmap_shutdown, .driver = { .name = "b53-switch", .of_match_table = b53_mmap_of_table, diff --git a/drivers/net/dsa/b53/b53_priv.h b/drivers/net/dsa/b53/b53_priv.h index 5d068acf7cf8..959a52d41f0a 100644 --- a/drivers/net/dsa/b53/b53_priv.h +++ b/drivers/net/dsa/b53/b53_priv.h @@ -228,6 +228,11 @@ static inline void b53_switch_remove(struct b53_device *dev) dsa_unregister_switch(dev->ds); } +static inline void b53_switch_shutdown(struct b53_device *dev) +{ + dsa_switch_shutdown(dev->ds); +} + #define b53_build_op(type_op_size, val_type) \ static inline int b53_##type_op_size(struct b53_device *dev, u8 page, \ u8 reg, val_type val) \ diff --git a/drivers/net/dsa/b53/b53_spi.c b/drivers/net/dsa/b53/b53_spi.c index ecb9f7f6b335..01e37b75471e 100644 --- a/drivers/net/dsa/b53/b53_spi.c +++ b/drivers/net/dsa/b53/b53_spi.c @@ -321,9 +321,21 @@ static int b53_spi_remove(struct spi_device *spi) if (dev) b53_switch_remove(dev); + spi_set_drvdata(spi, NULL); + return 0; } +static void b53_spi_shutdown(struct spi_device *spi) +{ + struct b53_device *dev = spi_get_drvdata(spi); + + if (dev) + b53_switch_shutdown(dev); + + spi_set_drvdata(spi, NULL); +} + static const struct of_device_id b53_spi_of_match[] = { { .compatible = "brcm,bcm5325" }, { .compatible = "brcm,bcm5365" }, @@ -344,6 +356,7 @@ static struct spi_driver b53_spi_driver = { }, .probe = b53_spi_probe, .remove = b53_spi_remove, + .shutdown = b53_spi_shutdown, }; module_spi_driver(b53_spi_driver); diff --git a/drivers/net/dsa/b53/b53_srab.c b/drivers/net/dsa/b53/b53_srab.c index 3f4249de70c5..4591bb1c05d2 100644 --- a/drivers/net/dsa/b53/b53_srab.c +++ b/drivers/net/dsa/b53/b53_srab.c @@ -629,17 +629,34 @@ static int b53_srab_probe(struct platform_device *pdev) static int b53_srab_remove(struct platform_device *pdev) { struct b53_device *dev = platform_get_drvdata(pdev); - struct b53_srab_priv *priv = dev->priv; - b53_srab_intr_set(priv, false); + if (!dev) + return 0; + + b53_srab_intr_set(dev->priv, false); b53_switch_remove(dev); + platform_set_drvdata(pdev, NULL); + return 0; } +static void b53_srab_shutdown(struct platform_device *pdev) +{ + struct b53_device *dev = platform_get_drvdata(pdev); + + if (!dev) + return; + + b53_switch_shutdown(dev); + + platform_set_drvdata(pdev, NULL); +} + static struct platform_driver b53_srab_driver = { .probe = b53_srab_probe, .remove = b53_srab_remove, + .shutdown = b53_srab_shutdown, .driver = { .name = "b53-srab-switch", .of_match_table = b53_srab_of_match, diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c index 6ce9ec1283e0..520fbb56c202 100644 --- a/drivers/net/dsa/bcm_sf2.c +++ b/drivers/net/dsa/bcm_sf2.c @@ -1512,6 +1512,9 @@ static int bcm_sf2_sw_remove(struct platform_device *pdev) { struct bcm_sf2_priv *priv = platform_get_drvdata(pdev); + if (!priv) + return 0; + priv->wol_ports_mask = 0; /* Disable interrupts */ bcm_sf2_intr_disable(priv); @@ -1523,6 +1526,8 @@ static int bcm_sf2_sw_remove(struct platform_device *pdev) if (priv->type == BCM7278_DEVICE_ID) reset_control_assert(priv->rcdev); + platform_set_drvdata(pdev, NULL); + return 0; } @@ -1530,6 +1535,9 @@ static void bcm_sf2_sw_shutdown(struct platform_device *pdev) { struct bcm_sf2_priv *priv = platform_get_drvdata(pdev); + if (!priv) + return; + /* For a kernel about to be kexec'd we want to keep the GPHY on for a * successful MDIO bus scan to occur. If we did turn off the GPHY * before (e.g: port_disable), this will also power it back on. @@ -1538,6 +1546,10 @@ static void bcm_sf2_sw_shutdown(struct platform_device *pdev) */ if (priv->hw_params.num_gphy == 1) bcm_sf2_gphy_enable_set(priv->dev->ds, true); + + dsa_switch_shutdown(priv->dev->ds); + + platform_set_drvdata(pdev, NULL); } #ifdef CONFIG_PM_SLEEP diff --git a/drivers/net/dsa/dsa_loop.c b/drivers/net/dsa/dsa_loop.c index bfdf3324aac3..e638e3eea911 100644 --- a/drivers/net/dsa/dsa_loop.c +++ b/drivers/net/dsa/dsa_loop.c @@ -340,10 +340,29 @@ static int dsa_loop_drv_probe(struct mdio_device *mdiodev) static void dsa_loop_drv_remove(struct mdio_device *mdiodev) { struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev); - struct dsa_loop_priv *ps = ds->priv; + struct dsa_loop_priv *ps; + + if (!ds) + return; + + ps = ds->priv; dsa_unregister_switch(ds); dev_put(ps->netdev); + + dev_set_drvdata(&mdiodev->dev, NULL); +} + +static void dsa_loop_drv_shutdown(struct mdio_device *mdiodev) +{ + struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev); + + if (!ds) + return; + + dsa_switch_shutdown(ds); + + dev_set_drvdata(&mdiodev->dev, NULL); } static struct mdio_driver dsa_loop_drv = { @@ -352,6 +371,7 @@ static struct mdio_driver dsa_loop_drv = { }, .probe = dsa_loop_drv_probe, .remove = dsa_loop_drv_remove, + .shutdown = dsa_loop_drv_shutdown, }; #define NUM_FIXED_PHYS (DSA_LOOP_NUM_PORTS - 2) diff --git a/drivers/net/dsa/lan9303-core.c b/drivers/net/dsa/lan9303-core.c index d7ce281570b5..89f920289ae2 100644 --- a/drivers/net/dsa/lan9303-core.c +++ b/drivers/net/dsa/lan9303-core.c @@ -1379,6 +1379,12 @@ int lan9303_remove(struct lan9303 *chip) } EXPORT_SYMBOL(lan9303_remove); +void lan9303_shutdown(struct lan9303 *chip) +{ + dsa_switch_shutdown(chip->ds); +} +EXPORT_SYMBOL(lan9303_shutdown); + MODULE_AUTHOR("Juergen Borleis "); MODULE_DESCRIPTION("Core driver for SMSC/Microchip LAN9303 three port ethernet switch"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/net/dsa/lan9303.h b/drivers/net/dsa/lan9303.h index 11f590b64701..c7f73efa50f0 100644 --- a/drivers/net/dsa/lan9303.h +++ b/drivers/net/dsa/lan9303.h @@ -10,3 +10,4 @@ extern const struct lan9303_phy_ops lan9303_indirect_phy_ops; int lan9303_probe(struct lan9303 *chip, struct device_node *np); int lan9303_remove(struct lan9303 *chip); +void lan9303_shutdown(struct lan9303 *chip); diff --git a/drivers/net/dsa/lan9303_i2c.c b/drivers/net/dsa/lan9303_i2c.c index 9bffaef65a04..8ca4713310fa 100644 --- a/drivers/net/dsa/lan9303_i2c.c +++ b/drivers/net/dsa/lan9303_i2c.c @@ -67,13 +67,28 @@ static int lan9303_i2c_probe(struct i2c_client *client, static int lan9303_i2c_remove(struct i2c_client *client) { - struct lan9303_i2c *sw_dev; + struct lan9303_i2c *sw_dev = i2c_get_clientdata(client); - sw_dev = i2c_get_clientdata(client); if (!sw_dev) - return -ENODEV; + return 0; + + lan9303_remove(&sw_dev->chip); + + i2c_set_clientdata(client, NULL); + + return 0; +} + +static void lan9303_i2c_shutdown(struct i2c_client *client) +{ + struct lan9303_i2c *sw_dev = i2c_get_clientdata(client); + + if (!sw_dev) + return; + + lan9303_shutdown(&sw_dev->chip); - return lan9303_remove(&sw_dev->chip); + i2c_set_clientdata(client, NULL); } /*-------------------------------------------------------------------------*/ @@ -97,6 +112,7 @@ static struct i2c_driver lan9303_i2c_driver = { }, .probe = lan9303_i2c_probe, .remove = lan9303_i2c_remove, + .shutdown = lan9303_i2c_shutdown, .id_table = lan9303_i2c_id, }; module_i2c_driver(lan9303_i2c_driver); diff --git a/drivers/net/dsa/lan9303_mdio.c b/drivers/net/dsa/lan9303_mdio.c index 9cbe80460b53..bbb7032409ba 100644 --- a/drivers/net/dsa/lan9303_mdio.c +++ b/drivers/net/dsa/lan9303_mdio.c @@ -138,6 +138,20 @@ static void lan9303_mdio_remove(struct mdio_device *mdiodev) return; lan9303_remove(&sw_dev->chip); + + dev_set_drvdata(&mdiodev->dev, NULL); +} + +static void lan9303_mdio_shutdown(struct mdio_device *mdiodev) +{ + struct lan9303_mdio *sw_dev = dev_get_drvdata(&mdiodev->dev); + + if (!sw_dev) + return; + + lan9303_shutdown(&sw_dev->chip); + + dev_set_drvdata(&mdiodev->dev, NULL); } /*-------------------------------------------------------------------------*/ @@ -155,6 +169,7 @@ static struct mdio_driver lan9303_mdio_driver = { }, .probe = lan9303_mdio_probe, .remove = lan9303_mdio_remove, + .shutdown = lan9303_mdio_shutdown, }; mdio_module_driver(lan9303_mdio_driver); diff --git a/drivers/net/dsa/lantiq_gswip.c b/drivers/net/dsa/lantiq_gswip.c index 64d6dfa83122..6d8ca3613a42 100644 --- a/drivers/net/dsa/lantiq_gswip.c +++ b/drivers/net/dsa/lantiq_gswip.c @@ -2178,6 +2178,9 @@ static int gswip_remove(struct platform_device *pdev) struct gswip_priv *priv = platform_get_drvdata(pdev); int i; + if (!priv) + return 0; + /* disable the switch */ gswip_mdio_mask(priv, GSWIP_MDIO_GLOB_ENABLE, 0, GSWIP_MDIO_GLOB); @@ -2191,9 +2194,23 @@ static int gswip_remove(struct platform_device *pdev) for (i = 0; i < priv->num_gphy_fw; i++) gswip_gphy_fw_remove(priv, &priv->gphy_fw[i]); + platform_set_drvdata(pdev, NULL); + return 0; } +static void gswip_shutdown(struct platform_device *pdev) +{ + struct gswip_priv *priv = platform_get_drvdata(pdev); + + if (!priv) + return; + + dsa_switch_shutdown(priv->ds); + + platform_set_drvdata(pdev, NULL); +} + static const struct gswip_hw_info gswip_xrx200 = { .max_ports = 7, .cpu_port = 6, @@ -2217,6 +2234,7 @@ MODULE_DEVICE_TABLE(of, gswip_of_match); static struct platform_driver gswip_driver = { .probe = gswip_probe, .remove = gswip_remove, + .shutdown = gswip_shutdown, .driver = { .name = "gswip", .of_match_table = gswip_of_match, diff --git a/drivers/net/dsa/microchip/ksz8795_spi.c b/drivers/net/dsa/microchip/ksz8795_spi.c index ea7550d1b634..866767b70d65 100644 --- a/drivers/net/dsa/microchip/ksz8795_spi.c +++ b/drivers/net/dsa/microchip/ksz8795_spi.c @@ -94,6 +94,8 @@ static int ksz8795_spi_remove(struct spi_device *spi) if (dev) ksz_switch_remove(dev); + spi_set_drvdata(spi, NULL); + return 0; } @@ -101,8 +103,15 @@ static void ksz8795_spi_shutdown(struct spi_device *spi) { struct ksz_device *dev = spi_get_drvdata(spi); - if (dev && dev->dev_ops->shutdown) + if (!dev) + return; + + if (dev->dev_ops->shutdown) dev->dev_ops->shutdown(dev); + + dsa_switch_shutdown(dev->ds); + + spi_set_drvdata(spi, NULL); } static const struct of_device_id ksz8795_dt_ids[] = { diff --git a/drivers/net/dsa/microchip/ksz9477_i2c.c b/drivers/net/dsa/microchip/ksz9477_i2c.c index 4e053a25d077..f3afb8b8c4cc 100644 --- a/drivers/net/dsa/microchip/ksz9477_i2c.c +++ b/drivers/net/dsa/microchip/ksz9477_i2c.c @@ -56,7 +56,10 @@ static int ksz9477_i2c_remove(struct i2c_client *i2c) { struct ksz_device *dev = i2c_get_clientdata(i2c); - ksz_switch_remove(dev); + if (dev) + ksz_switch_remove(dev); + + i2c_set_clientdata(i2c, NULL); return 0; } @@ -65,8 +68,15 @@ static void ksz9477_i2c_shutdown(struct i2c_client *i2c) { struct ksz_device *dev = i2c_get_clientdata(i2c); - if (dev && dev->dev_ops->shutdown) + if (!dev) + return; + + if (dev->dev_ops->shutdown) dev->dev_ops->shutdown(dev); + + dsa_switch_shutdown(dev->ds); + + i2c_set_clientdata(i2c, NULL); } static const struct i2c_device_id ksz9477_i2c_id[] = { diff --git a/drivers/net/dsa/microchip/ksz9477_spi.c b/drivers/net/dsa/microchip/ksz9477_spi.c index 15bc11b3cda4..e3cb0e6c9f6f 100644 --- a/drivers/net/dsa/microchip/ksz9477_spi.c +++ b/drivers/net/dsa/microchip/ksz9477_spi.c @@ -72,6 +72,8 @@ static int ksz9477_spi_remove(struct spi_device *spi) if (dev) ksz_switch_remove(dev); + spi_set_drvdata(spi, NULL); + return 0; } @@ -79,8 +81,10 @@ static void ksz9477_spi_shutdown(struct spi_device *spi) { struct ksz_device *dev = spi_get_drvdata(spi); - if (dev && dev->dev_ops->shutdown) - dev->dev_ops->shutdown(dev); + if (dev) + dsa_switch_shutdown(dev->ds); + + spi_set_drvdata(spi, NULL); } static const struct of_device_id ksz9477_dt_ids[] = { diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index d0cba2d1cd68..094737e5084a 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -3286,6 +3286,9 @@ mt7530_remove(struct mdio_device *mdiodev) struct mt7530_priv *priv = dev_get_drvdata(&mdiodev->dev); int ret = 0; + if (!priv) + return; + ret = regulator_disable(priv->core_pwr); if (ret < 0) dev_err(priv->dev, @@ -3301,11 +3304,26 @@ mt7530_remove(struct mdio_device *mdiodev) dsa_unregister_switch(priv->ds); mutex_destroy(&priv->reg_mutex); + + dev_set_drvdata(&mdiodev->dev, NULL); +} + +static void mt7530_shutdown(struct mdio_device *mdiodev) +{ + struct mt7530_priv *priv = dev_get_drvdata(&mdiodev->dev); + + if (!priv) + return; + + dsa_switch_shutdown(priv->ds); + + dev_set_drvdata(&mdiodev->dev, NULL); } static struct mdio_driver mt7530_mdio_driver = { .probe = mt7530_probe, .remove = mt7530_remove, + .shutdown = mt7530_shutdown, .mdiodrv.driver = { .name = "mt7530", .of_match_table = mt7530_of_match, diff --git a/drivers/net/dsa/mv88e6060.c b/drivers/net/dsa/mv88e6060.c index 24b8219fd607..a4c6eb9a52d0 100644 --- a/drivers/net/dsa/mv88e6060.c +++ b/drivers/net/dsa/mv88e6060.c @@ -290,7 +290,24 @@ static void mv88e6060_remove(struct mdio_device *mdiodev) { struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev); + if (!ds) + return; + dsa_unregister_switch(ds); + + dev_set_drvdata(&mdiodev->dev, NULL); +} + +static void mv88e6060_shutdown(struct mdio_device *mdiodev) +{ + struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev); + + if (!ds) + return; + + dsa_switch_shutdown(ds); + + dev_set_drvdata(&mdiodev->dev, NULL); } static const struct of_device_id mv88e6060_of_match[] = { @@ -303,6 +320,7 @@ static const struct of_device_id mv88e6060_of_match[] = { static struct mdio_driver mv88e6060_driver = { .probe = mv88e6060_probe, .remove = mv88e6060_remove, + .shutdown = mv88e6060_shutdown, .mdiodrv.driver = { .name = "mv88e6060", .of_match_table = mv88e6060_of_match, diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index c45ca2473743..fb10422d2c33 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -6389,7 +6389,12 @@ static int mv88e6xxx_probe(struct mdio_device *mdiodev) static void mv88e6xxx_remove(struct mdio_device *mdiodev) { struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev); - struct mv88e6xxx_chip *chip = ds->priv; + struct mv88e6xxx_chip *chip; + + if (!ds) + return; + + chip = ds->priv; if (chip->info->ptp_support) { mv88e6xxx_hwtstamp_free(chip); @@ -6410,6 +6415,20 @@ static void mv88e6xxx_remove(struct mdio_device *mdiodev) mv88e6xxx_g1_irq_free(chip); else mv88e6xxx_irq_poll_free(chip); + + dev_set_drvdata(&mdiodev->dev, NULL); +} + +static void mv88e6xxx_shutdown(struct mdio_device *mdiodev) +{ + struct dsa_switch *ds = dev_get_drvdata(&mdiodev->dev); + + if (!ds) + return; + + dsa_switch_shutdown(ds); + + dev_set_drvdata(&mdiodev->dev, NULL); } static const struct of_device_id mv88e6xxx_of_match[] = { @@ -6433,6 +6452,7 @@ MODULE_DEVICE_TABLE(of, mv88e6xxx_of_match); static struct mdio_driver mv88e6xxx_driver = { .probe = mv88e6xxx_probe, .remove = mv88e6xxx_remove, + .shutdown = mv88e6xxx_shutdown, .mdiodrv.driver = { .name = "mv88e6085", .of_match_table = mv88e6xxx_of_match, diff --git a/drivers/net/dsa/ocelot/felix_vsc9959.c b/drivers/net/dsa/ocelot/felix_vsc9959.c index f966a253d1c7..75823c6323ad 100644 --- a/drivers/net/dsa/ocelot/felix_vsc9959.c +++ b/drivers/net/dsa/ocelot/felix_vsc9959.c @@ -1472,9 +1472,10 @@ static int felix_pci_probe(struct pci_dev *pdev, static void felix_pci_remove(struct pci_dev *pdev) { - struct felix *felix; + struct felix *felix = pci_get_drvdata(pdev); - felix = pci_get_drvdata(pdev); + if (!felix) + return; dsa_unregister_switch(felix->ds); @@ -1482,6 +1483,20 @@ static void felix_pci_remove(struct pci_dev *pdev) kfree(felix); pci_disable_device(pdev); + + pci_set_drvdata(pdev, NULL); +} + +static void felix_pci_shutdown(struct pci_dev *pdev) +{ + struct felix *felix = pci_get_drvdata(pdev); + + if (!felix) + return; + + dsa_switch_shutdown(felix->ds); + + pci_set_drvdata(pdev, NULL); } static struct pci_device_id felix_ids[] = { @@ -1498,6 +1513,7 @@ static struct pci_driver felix_vsc9959_pci_driver = { .id_table = felix_ids, .probe = felix_pci_probe, .remove = felix_pci_remove, + .shutdown = felix_pci_shutdown, }; module_pci_driver(felix_vsc9959_pci_driver); diff --git a/drivers/net/dsa/ocelot/seville_vsc9953.c b/drivers/net/dsa/ocelot/seville_vsc9953.c index deae923c8b7a..de1d34a1f1e4 100644 --- a/drivers/net/dsa/ocelot/seville_vsc9953.c +++ b/drivers/net/dsa/ocelot/seville_vsc9953.c @@ -1245,18 +1245,33 @@ static int seville_probe(struct platform_device *pdev) static int seville_remove(struct platform_device *pdev) { - struct felix *felix; + struct felix *felix = platform_get_drvdata(pdev); - felix = platform_get_drvdata(pdev); + if (!felix) + return 0; dsa_unregister_switch(felix->ds); kfree(felix->ds); kfree(felix); + platform_set_drvdata(pdev, NULL); + return 0; } +static void seville_shutdown(struct platform_device *pdev) +{ + struct felix *felix = platform_get_drvdata(pdev); + + if (!felix) + return; + + dsa_switch_shutdown(felix->ds); + + platform_set_drvdata(pdev, NULL); +} + static const struct of_device_id seville_of_match[] = { { .compatible = "mscc,vsc9953-switch" }, { }, @@ -1266,6 +1281,7 @@ MODULE_DEVICE_TABLE(of, seville_of_match); static struct platform_driver seville_vsc9953_driver = { .probe = seville_probe, .remove = seville_remove, + .shutdown = seville_shutdown, .driver = { .name = "mscc_seville", .of_match_table = of_match_ptr(seville_of_match), diff --git a/drivers/net/dsa/qca/ar9331.c b/drivers/net/dsa/qca/ar9331.c index 563d8a279030..a6bfb6abc51a 100644 --- a/drivers/net/dsa/qca/ar9331.c +++ b/drivers/net/dsa/qca/ar9331.c @@ -1083,6 +1083,9 @@ static void ar9331_sw_remove(struct mdio_device *mdiodev) struct ar9331_sw_priv *priv = dev_get_drvdata(&mdiodev->dev); unsigned int i; + if (!priv) + return; + for (i = 0; i < ARRAY_SIZE(priv->port); i++) { struct ar9331_sw_port *port = &priv->port[i]; @@ -1094,6 +1097,20 @@ static void ar9331_sw_remove(struct mdio_device *mdiodev) dsa_unregister_switch(&priv->ds); reset_control_assert(priv->sw_reset); + + dev_set_drvdata(&mdiodev->dev, NULL); +} + +static void ar9331_sw_shutdown(struct mdio_device *mdiodev) +{ + struct ar9331_sw_priv *priv = dev_get_drvdata(&mdiodev->dev); + + if (!priv) + return; + + dsa_switch_shutdown(&priv->ds); + + dev_set_drvdata(&mdiodev->dev, NULL); } static const struct of_device_id ar9331_sw_of_match[] = { @@ -1104,6 +1121,7 @@ static const struct of_device_id ar9331_sw_of_match[] = { static struct mdio_driver ar9331_sw_mdio_driver = { .probe = ar9331_sw_probe, .remove = ar9331_sw_remove, + .shutdown = ar9331_sw_shutdown, .mdiodrv.driver = { .name = AR9331_SW_NAME, .of_match_table = ar9331_sw_of_match, diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c index bda5a9bf4f52..a984f06f6f04 100644 --- a/drivers/net/dsa/qca8k.c +++ b/drivers/net/dsa/qca8k.c @@ -1880,10 +1880,27 @@ qca8k_sw_remove(struct mdio_device *mdiodev) struct qca8k_priv *priv = dev_get_drvdata(&mdiodev->dev); int i; + if (!priv) + return; + for (i = 0; i < QCA8K_NUM_PORTS; i++) qca8k_port_set_status(priv, i, 0); dsa_unregister_switch(priv->ds); + + dev_set_drvdata(&mdiodev->dev, NULL); +} + +static void qca8k_sw_shutdown(struct mdio_device *mdiodev) +{ + struct qca8k_priv *priv = dev_get_drvdata(&mdiodev->dev); + + if (!priv) + return; + + dsa_switch_shutdown(priv->ds); + + dev_set_drvdata(&mdiodev->dev, NULL); } #ifdef CONFIG_PM_SLEEP @@ -1940,6 +1957,7 @@ static const struct of_device_id qca8k_of_match[] = { static struct mdio_driver qca8kmdio_driver = { .probe = qca8k_sw_probe, .remove = qca8k_sw_remove, + .shutdown = qca8k_sw_shutdown, .mdiodrv.driver = { .name = "qca8k", .of_match_table = qca8k_of_match, diff --git a/drivers/net/dsa/realtek-smi-core.c b/drivers/net/dsa/realtek-smi-core.c index 8e49d4f85d48..dd2f0d6208b3 100644 --- a/drivers/net/dsa/realtek-smi-core.c +++ b/drivers/net/dsa/realtek-smi-core.c @@ -464,16 +464,33 @@ static int realtek_smi_probe(struct platform_device *pdev) static int realtek_smi_remove(struct platform_device *pdev) { - struct realtek_smi *smi = dev_get_drvdata(&pdev->dev); + struct realtek_smi *smi = platform_get_drvdata(pdev); + + if (!smi) + return 0; dsa_unregister_switch(smi->ds); if (smi->slave_mii_bus) of_node_put(smi->slave_mii_bus->dev.of_node); gpiod_set_value(smi->reset, 1); + platform_set_drvdata(pdev, NULL); + return 0; } +static void realtek_smi_shutdown(struct platform_device *pdev) +{ + struct realtek_smi *smi = platform_get_drvdata(pdev); + + if (!smi) + return; + + dsa_switch_shutdown(smi->ds); + + platform_set_drvdata(pdev, NULL); +} + static const struct of_device_id realtek_smi_of_match[] = { { .compatible = "realtek,rtl8366rb", @@ -495,6 +512,7 @@ static struct platform_driver realtek_smi_driver = { }, .probe = realtek_smi_probe, .remove = realtek_smi_remove, + .shutdown = realtek_smi_shutdown, }; module_platform_driver(realtek_smi_driver); diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index 2f8cc6686c38..7c0db80eff00 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -3335,13 +3335,29 @@ static int sja1105_probe(struct spi_device *spi) static int sja1105_remove(struct spi_device *spi) { struct sja1105_private *priv = spi_get_drvdata(spi); - struct dsa_switch *ds = priv->ds; - dsa_unregister_switch(ds); + if (!priv) + return 0; + + dsa_unregister_switch(priv->ds); + + spi_set_drvdata(spi, NULL); return 0; } +static void sja1105_shutdown(struct spi_device *spi) +{ + struct sja1105_private *priv = spi_get_drvdata(spi); + + if (!priv) + return; + + dsa_switch_shutdown(priv->ds); + + spi_set_drvdata(spi, NULL); +} + static const struct of_device_id sja1105_dt_ids[] = { { .compatible = "nxp,sja1105e", .data = &sja1105e_info }, { .compatible = "nxp,sja1105t", .data = &sja1105t_info }, @@ -3365,6 +3381,7 @@ static struct spi_driver sja1105_driver = { }, .probe = sja1105_probe, .remove = sja1105_remove, + .shutdown = sja1105_shutdown, }; module_spi_driver(sja1105_driver); diff --git a/drivers/net/dsa/vitesse-vsc73xx-core.c b/drivers/net/dsa/vitesse-vsc73xx-core.c index 19ce4aa0973b..a4b1447ff055 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-core.c +++ b/drivers/net/dsa/vitesse-vsc73xx-core.c @@ -1225,6 +1225,12 @@ int vsc73xx_remove(struct vsc73xx *vsc) } EXPORT_SYMBOL(vsc73xx_remove); +void vsc73xx_shutdown(struct vsc73xx *vsc) +{ + dsa_switch_shutdown(vsc->ds); +} +EXPORT_SYMBOL(vsc73xx_shutdown); + MODULE_AUTHOR("Linus Walleij "); MODULE_DESCRIPTION("Vitesse VSC7385/7388/7395/7398 driver"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/net/dsa/vitesse-vsc73xx-platform.c b/drivers/net/dsa/vitesse-vsc73xx-platform.c index 2a57f337b2a2..fe4b154a0a57 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-platform.c +++ b/drivers/net/dsa/vitesse-vsc73xx-platform.c @@ -116,7 +116,26 @@ static int vsc73xx_platform_remove(struct platform_device *pdev) { struct vsc73xx_platform *vsc_platform = platform_get_drvdata(pdev); - return vsc73xx_remove(&vsc_platform->vsc); + if (!vsc_platform) + return 0; + + vsc73xx_remove(&vsc_platform->vsc); + + platform_set_drvdata(pdev, NULL); + + return 0; +} + +static void vsc73xx_platform_shutdown(struct platform_device *pdev) +{ + struct vsc73xx_platform *vsc_platform = platform_get_drvdata(pdev); + + if (!vsc_platform) + return; + + vsc73xx_shutdown(&vsc_platform->vsc); + + platform_set_drvdata(pdev, NULL); } static const struct vsc73xx_ops vsc73xx_platform_ops = { @@ -144,6 +163,7 @@ MODULE_DEVICE_TABLE(of, vsc73xx_of_match); static struct platform_driver vsc73xx_platform_driver = { .probe = vsc73xx_platform_probe, .remove = vsc73xx_platform_remove, + .shutdown = vsc73xx_platform_shutdown, .driver = { .name = "vsc73xx-platform", .of_match_table = vsc73xx_of_match, diff --git a/drivers/net/dsa/vitesse-vsc73xx-spi.c b/drivers/net/dsa/vitesse-vsc73xx-spi.c index 81eca4a5781d..645398901e05 100644 --- a/drivers/net/dsa/vitesse-vsc73xx-spi.c +++ b/drivers/net/dsa/vitesse-vsc73xx-spi.c @@ -163,7 +163,26 @@ static int vsc73xx_spi_remove(struct spi_device *spi) { struct vsc73xx_spi *vsc_spi = spi_get_drvdata(spi); - return vsc73xx_remove(&vsc_spi->vsc); + if (!vsc_spi) + return 0; + + vsc73xx_remove(&vsc_spi->vsc); + + spi_set_drvdata(spi, NULL); + + return 0; +} + +static void vsc73xx_spi_shutdown(struct spi_device *spi) +{ + struct vsc73xx_spi *vsc_spi = spi_get_drvdata(spi); + + if (!vsc_spi) + return; + + vsc73xx_shutdown(&vsc_spi->vsc); + + spi_set_drvdata(spi, NULL); } static const struct vsc73xx_ops vsc73xx_spi_ops = { @@ -191,6 +210,7 @@ MODULE_DEVICE_TABLE(of, vsc73xx_of_match); static struct spi_driver vsc73xx_spi_driver = { .probe = vsc73xx_spi_probe, .remove = vsc73xx_spi_remove, + .shutdown = vsc73xx_spi_shutdown, .driver = { .name = "vsc73xx-spi", .of_match_table = vsc73xx_of_match, diff --git a/drivers/net/dsa/vitesse-vsc73xx.h b/drivers/net/dsa/vitesse-vsc73xx.h index 7478f8d4e0a9..30b951504e65 100644 --- a/drivers/net/dsa/vitesse-vsc73xx.h +++ b/drivers/net/dsa/vitesse-vsc73xx.h @@ -27,3 +27,4 @@ struct vsc73xx_ops { int vsc73xx_is_addr_valid(u8 block, u8 subblock); int vsc73xx_probe(struct vsc73xx *vsc); int vsc73xx_remove(struct vsc73xx *vsc); +void vsc73xx_shutdown(struct vsc73xx *vsc); diff --git a/include/net/dsa.h b/include/net/dsa.h index f9a17145255a..2c39dbac63bd 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -1041,6 +1041,7 @@ static inline int dsa_ndo_eth_ioctl(struct net_device *dev, struct ifreq *ifr, void dsa_unregister_switch(struct dsa_switch *ds); int dsa_register_switch(struct dsa_switch *ds); +void dsa_switch_shutdown(struct dsa_switch *ds); struct dsa_switch *dsa_switch_find(int tree_index, int sw_index); #ifdef CONFIG_PM_SLEEP int dsa_switch_suspend(struct dsa_switch *ds); diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index 1b2b25d7bd02..b94d7bd62277 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -1546,3 +1546,49 @@ void dsa_unregister_switch(struct dsa_switch *ds) mutex_unlock(&dsa2_mutex); } EXPORT_SYMBOL_GPL(dsa_unregister_switch); + +/* If the DSA master chooses to unregister its net_device on .shutdown, DSA is + * blocking that operation from completion, due to the dev_hold taken inside + * netdev_upper_dev_link. Unlink the DSA slave interfaces from being uppers of + * the DSA master, so that the system can reboot successfully. + */ +void dsa_switch_shutdown(struct dsa_switch *ds) +{ + struct net_device *master, *slave_dev; + struct dsa_port *dp; + + mutex_lock(&dsa2_mutex); + rtnl_lock(); + list_for_each_entry(dp, &ds->dst->ports, list) { + if (dp->ds != ds) + continue; + + if (!dsa_is_user_port(ds, dp->index)) + continue; + + master = dp->cpu_dp->master; + slave_dev = dp->slave; + + netdev_upper_dev_unlink(master, slave_dev); + /* Just unlinking ourselves as uppers of the master is not + * sufficient. When the master net device unregisters, that will + * also call dev_close, which we will catch as NETDEV_GOING_DOWN + * and trigger a dev_close on our own devices (dsa_slave_close). + * In turn, that will call dev_mc_unsync on the master's net + * device. If the master is also a DSA switch port, this will + * trigger dsa_slave_set_rx_mode which will call dev_mc_sync on + * its own master. Lockdep will complain about the fact that + * all cascaded masters have the same dsa_master_addr_list_lock_key, + * which it normally would not do if the cascaded masters would + * be in a proper upper/lower relationship, which we've just + * destroyed. + * To suppress the lockdep warnings, let's actually unregister + * the DSA slave interfaces too, to avoid the nonsensical + * multicast address list synchronization on shutdown. + */ + unregister_netdevice(slave_dev); + } + rtnl_unlock(); + mutex_unlock(&dsa2_mutex); +} +EXPORT_SYMBOL_GPL(dsa_switch_shutdown); From patchwork Sun Sep 12 12:09:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 510342 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E25BC43219 for ; Sun, 12 Sep 2021 12:10:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 67872610A3 for ; Sun, 12 Sep 2021 12:10:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235385AbhILMLM (ORCPT ); Sun, 12 Sep 2021 08:11:12 -0400 Received: from mail-db8eur05on2061.outbound.protection.outlook.com ([40.107.20.61]:24243 "EHLO EUR05-DB8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235168AbhILMLE (ORCPT ); Sun, 12 Sep 2021 08:11:04 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jfl+UurBpAGbc758dO5Y5klfBqT7wAwclxUcie5xbd6Z6Lzz/FZQAtUIrpzDQgDMqe9yOxzNi1AQiIEPshGe04crWsNGgWcJH69QBXLvj4oI9VjW/X10aq7N0FzLcUHDVpFllyQG2Hqlol664xcQ2Noe8G75s3qVKUG+HFtOPkw9LhLLftWXgI/XYHqABHvGiPc49yS03wCZ13WNWzhAsXLdIv9JcRIliDnTUs2hs6jLfpH+XVGenCLUNAoWsD60X/JSqtahqsPu2wj+0iio3k/wRP2nJbZO8XUfjsWgqbopQAzpbOUL+qakvyVtavLI5qHEs8UfxzfHWozF3KL84w== 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=koFKcRjGvX0cSv9q2ljRuQWJtgMyMg42Ynk9ZcVTeSk=; b=eN8u9h8jUx67bRIiA38VjIh3LasK3Owfiayzcjx4KGD9mh7e0E3s6vQiKAtH7D9zmQS3MIRnNi7G/slj11sbPKXHHkvs8Ymm4YjLvulKhK/mMg6skvrGwIxjc1RawNKqn0oDsbhxBrPVWMFQgGNSEqdH4rtyKMHEWJ3wOfROxZPjMgdfrW/7A0h40VaxNYmt4l7xdQe7a2xAswz3qEus0phSma5XoZdvt8Uju5JnrQOjO/oCIit4qBmfhHVeaGT0YT3rV20rqh3CWDweIsvti/Be4wbvhHEFO5zdUrJuOSdIu5+9Z8+CC7EYw0UEa+JwCoaYPGVDXKPVe4eF7dF6Qg== 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=koFKcRjGvX0cSv9q2ljRuQWJtgMyMg42Ynk9ZcVTeSk=; b=WCgw+uTDsV/dh7ok2LVQHySLwGIJIP84U6C66DA9K/3zbKAiWpWfM5ciM7tRxhugoUFsly4SWe/8ToKrE9HBGJ/8fRUr13XGRfPbmblr9tKH0JmTI5FXe8tzxy+UtZ5f4evrAUjWI7yqwYVlaMgt+HpN6+AnRmyTGqj0dwjKzLc= 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:47 +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:47 +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 3/5] net: dsa: hellcreek: be compatible with masters which unregister on shutdown Date: Sun, 12 Sep 2021 15:09:30 +0300 Message-Id: <20210912120932.993440-4-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> 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:46 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 11e973ba-206a-4a92-9635-08d975e63701 X-MS-TrafficTypeDiagnostic: VI1PR04MB5854: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2657; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NFV2LbvPlTLCDuPLCIQ7F5rMr47Z0ewUwqgZVJnUyBuc6ZoCdFXRVm8k3m3vlApuDkXtjOO8Jqqf6wqkh4LZdVi0ugVm5OK0+pm484BPSyjZUxVAwiNCByAhcKmma54ixqp6TDd4UqgDUKVi3vjsxYRTTbP9Gc49iQFTnHZaSLwtH9xX8PFMzYYwPdMzjznKCwr7DYFz5Hhktpwgj5lYt0uuxD30IAym+2PodnGY77XIrQ0XrJ3vMegr/gKA50hwZDNuUr9mnMKYmMj3Dmy0ohhGkPMYvCfcb+CHyEacQtvzTa++ppnqclHHHaQXq0qQckCIQ1/E4eL6SfeDQuqMIsq57yaC+rPXgxCsrcYFIGpM2/SQdeajklqFNZM+EYcFcmZKyJLRJnyL1OJOyz50nyvlaMhLYjFHl1VuUggtIb+3zqkw1YafFrP6/35kBWkukAsp0g8S65ClGQYDB5IueNSMsnAmZNqK4X1Z09hsZnmIC27LsZk6BMliuHD1iDowtCtaTiHwIF0wJ1mpDwVJ7fv4+LPs7h3qCxadHb5Mi6j3YhZqoioowjT7Y4q0Pg0ZDZKD1ZrJ+Jq9Vtk3XNd98C9xLycN0yu8g/WxhY45MFqz/acQf/OitPSmBCztwr2eBpM9hLeB5j7oUVxxpk7N3+E9LIptBL6si/e4WNyG8cytqp165M7bv4v9pu/OD0AT6sRXMqNar+O+xKhQuyA3ve9c3cOsSbpr6NBW7MXe7jTCaBBk6/44HKAg8gkNxr+XptbuaJdoVhsF25fir5BmgFWMdutgFx+Bn7r0AumsHzY= 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: smysIpeTXk6+wAxMCAe2bmb4qV6LWhxoUxb3gGaaj3/WhONIaaa6M+f7zQfz2qU9oGv086GBa8t2J1QTBPgMDTxUrW9hbsoOLdsTITOHLFbR0Z7U1pcKsSi1foReTrETR1zAbxGjVDMFueFLm2pZiTyJGniToHtIA9AqF1gGGY+NCXeotc4l52Ci0/t5XJm1CXqKWWjO6Pe5P1XXXWpsb/2XZynBghtbO/Sg8p+0NuQG1E7xstTK0b3QKQWKzEsffTrEdzfiFLbWL0mNUjvgMVoHOkqk7MQHLDRPQJKXNi9scCLjCc7V9IOZ0VYDG5fKp5xi7bJxRRf3XkpsIDcwQPI+1Enat+C7Uq2uNUIoxiP8U0ysZ07JbXL48DJXqqfjFykJB9GsINMM3ZRJwaeN4lOxmgD0UhG3B/Lcxy84YE9Egp6hurmR6nsSo48WDFBjumeoP6m1bHyf3sc8c4KI4ntncYiYQhIFS1002H2OWnyJk0RqpnAGpdV8VtAj0AYmV15sUbrByFYm3tCw8t7/Z6XtKnTcMeSt8ZlnaVlBhe5ZeYrnq5CYXgCrfYukZAB6lIpWj6IXGeFW15THF9OxBBk+KbA/nzpxcp1XIfFA+/q6cu5Tn1tZV4mB+We0YJ8rnkQMwsccU+v0EUwtFm4zuJptOlMiqkM5T6QiKAc1FEM4Lm5a725bjE9ISo0ta85cCJiaJUcmT5VEnBfDKkdWICt7QEMAzxXw04eXJrHbRWCoxLvnpA3WT/H0aY0lBj+3OZYCp62EEVps1TMRfhH83nx2WrNuwgZlHEw5Bi0ZY2vDMzbd77bYBQ3eJH5wMUn2EYajPcQsrhqqAMi7hOem4XbSYo4l6HwVPJLBXJC4GlTG/rSo1wezLaBgcacQebp0jZ2P6dNDk/LJF4KN/+LtEHuPRoXFN8NO4xP+5T/NI7tmaTraI0lJ1cHRrk46NATXxjX5CdiXNQx0Y0KVvaC9n0RuDoSxT+bsCCJXZdPfJZ13bRRZEZB6tiosenR16ia9BuaY6803L1+oEfeesKCnkcI4yiO/2uCcnL6FtmWUgnnaDf6DKoVOJYHsL3XlvkZ8CHzy7UCyTZGdyleAaCTfKAMq7nb3hOQ66LPKW1rFWvU/E7rxzosMqWLPG6w1HHDvYoILziP997vy1Xl8SzC2F8J9QN6orM9PLvieVm0HUMbGQw2NdTy9BzcPPRqSHiNW4mLn1v79zuY/gRx7s3sHrlgHQWAVzjafc7L46IRHFiRcQutSbSQTzs50bi2bySk2C1+iyNju4TsXgLwnovbkSDcUsGG0PxeIBTNShTP8CkfIv+c1Su1Vu6LhKjtboCnm X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 11e973ba-206a-4a92-9635-08d975e63701 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:47.7203 (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: IUWwvXV5L1rP4P7ktgMCy7mLwtnqSei+gbCWq3xqoCsdyg680qy9Yh6AbRRCwMdAcQjI8ff7kzyqrMAYXDPSuw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5854 Precedence: bulk List-ID: X-Mailing-List: netdev@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 hellcreek 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. Hellcreek is a platform device driver, so we probably cannot have the oddities of ->shutdown and ->remove getting both called for the exact same struct device. But to be in line with the pattern from the other device drivers which are on slow buses, implement the same "if this then not that" pattern of either running the ->shutdown or the ->remove hook. The driver's current ->remove implementation makes that very easy because it already zeroes out its device_drvdata on ->remove. Fixes: e4b27ebc780f ("net: dsa: Add DSA driver for Hirschmann Hellcreek switches") Link: https://lore.kernel.org/netdev/20210909095324.12978-1-LinoSanfilippo@gmx.de/ Reported-by: Lino Sanfilippo Signed-off-by: Vladimir Oltean Acked-by: Kurt Kanzenbach --- drivers/net/dsa/hirschmann/hellcreek.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/drivers/net/dsa/hirschmann/hellcreek.c b/drivers/net/dsa/hirschmann/hellcreek.c index 542cfc4ccb08..354655f9ed00 100644 --- a/drivers/net/dsa/hirschmann/hellcreek.c +++ b/drivers/net/dsa/hirschmann/hellcreek.c @@ -1916,6 +1916,9 @@ static int hellcreek_remove(struct platform_device *pdev) { struct hellcreek *hellcreek = platform_get_drvdata(pdev); + if (!hellcreek) + return 0; + hellcreek_hwtstamp_free(hellcreek); hellcreek_ptp_free(hellcreek); dsa_unregister_switch(hellcreek->ds); @@ -1924,6 +1927,18 @@ static int hellcreek_remove(struct platform_device *pdev) return 0; } +static void hellcreek_shutdown(struct platform_device *pdev) +{ + struct hellcreek *hellcreek = platform_get_drvdata(pdev); + + if (!hellcreek) + return; + + dsa_switch_shutdown(hellcreek->ds); + + platform_set_drvdata(pdev, NULL); +} + static const struct hellcreek_platform_data de1soc_r1_pdata = { .name = "r4c30", .num_ports = 4, @@ -1946,6 +1961,7 @@ MODULE_DEVICE_TABLE(of, hellcreek_of_match); static struct platform_driver hellcreek_driver = { .probe = hellcreek_probe, .remove = hellcreek_remove, + .shutdown = hellcreek_shutdown, .driver = { .name = "hellcreek", .of_match_table = hellcreek_of_match, From patchwork Sun Sep 12 12:09:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 510341 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 801B5C433EF for ; Sun, 12 Sep 2021 12:10:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FED3610A6 for ; Sun, 12 Sep 2021 12:10:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235262AbhILMLP (ORCPT ); Sun, 12 Sep 2021 08:11:15 -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 S235210AbhILMLH (ORCPT ); Sun, 12 Sep 2021 08:11:07 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z3YK3QmUWW/ZdSnR2VpSfhs+H7XiIT/wAmq2N7CnB2WmWFEgADSma+ROrn2apLCUf4Uh+LYV8f4j3vX0TciIor2bIvI1CbkP8+2aH4HiWUtfWnim8kTB55ZznaOtrSvnmTYuPjttN1OEyubxC10R3na3+SsE2L+vZY9PDgVySutx/tW24p7u/s5La9ax2l0TsuSCn9+7UcwJVZRoWB+qmoE1b/VkTOoo4h+zYsJKMbvgt4y8geSmc6/huiLnunePl0Z1HalhfGQoGE59h7t2O2dgBPWaa7g91roYhmZQ6HscfMiQh2C4fwaF6E6tuI8FNBR++JsRKpaSK2p0Hi5Rdg== 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=zF5F8yiEmAkVyLfvd9FwoYUgxgfsVgMi+4/IluAypvM=; b=k36pMVaUm+Lhe4Mnq5+n7/I1RwPqzxQ799xIngxoNWctfpi47T8YQVwQmubnMHWynZ+VctM8ZQp0fiigFKsVwl7YKVUOo8Tlb3v6saGMilJVm+iu1ZHd+HSX5/m+2Giq9IhuVZskYjT0WP3w3pqCTPAc8xlrN5w8JvV+/lyT2EHGgTMVZiq4PsX35RIXZLb0qvB9UczGGPlLRatCcs/DmObV5qtb/YfI3E8MawxyaBDozF82/YIYyy8Yv5eNl2zvOwWTlqygvEcVu8n2heh5V9n//1n5GNHVHeVkEDFXrcp+e931AaVc+u3jk1N78wGM187DUMgFmtK5004zxGHxvA== 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=zF5F8yiEmAkVyLfvd9FwoYUgxgfsVgMi+4/IluAypvM=; b=RSUQ8wz0EczcfJWt2JsgqAb0crwO4NdLydxcp6Erg4SocP5sw9i0CTlWFYkRB3n+La+WC44TcoqJyBoHwu7pWvBFahH8ZtJ5F3958x7c8Q7D2ikcrUjLEimih6rB9mAcIxXVsVsOcH+0+0Unqi6TUD+sM8MYWHI9f9ubB2ghpqg= 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:49 +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:49 +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 4/5] net: dsa: microchip: ksz8863: be compatible with masters which unregister on shutdown Date: Sun, 12 Sep 2021 15:09:31 +0300 Message-Id: <20210912120932.993440-5-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> 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:47 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1487b7ba-c3d4-474d-bd4d-08d975e637b8 X-MS-TrafficTypeDiagnostic: VI1PR04MB5854: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3968; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vtDQxE8lgs8cbBE3peJ1JT4j9C0u+7ldt7EiUJS5y1B/taaCwgg84ZH+XKvtfbx9t1RVGogmRBjXT6XQ+7kR7lKRFnaqc7tAu96ZX/K9+/QHdh5ASUQJHX+AToy3/hqigMLZizi9EG75ap3cFngnTNARzvYoIZYsN+WunkvIHJ6fORh6RfhdkeSiGAKSzDKKEDqlJjoI+QZLEGT8q+7hl7d76Krdc4BMWrd9GwwnjAx6N6h9AbrfB7qBfhEAgy6lFByfnuNMxH33bjJfW54Z/H1Zp7P+emlQaihmQ6AYRhNG+5OLEnDE0lfyp8Jhhf3+lrypJ12MioMAZ+8UgT4lrSZisUrT97AKanhFrFQnaddGMX6SfpduZ93sQbaVOif5Re1vrOH1wAWWUEekeOXKNR9YE8aCMsRhNAf9LBaNDdzH5Cm/IVM0HcuQOW/za32WURmPCWGyeGxEfW+H7EFdLzIh0q2yftX/cjWvP+3E/WIpafJDFarN4yQ9IwWzBwpZ2gHQr4ACU8bbu+HerfrSGJ9K5wCmAX+WTnERszOvPbRw2/Rebmwf3dlQd1OKpw7XhwrobERV9WHMlCDjIqHDqCJ79WZEdVyEb2+rURPXk75/pfIwAJMGoJTFVYsrbo6lPw6fbTvL1Z6RzyO7Vrwj0wSJX8Kjvo7dDbmkhX4dhwA1OuQmrRI0+/7tMMCpEswlwbbYKpmz5EtQVw+PqfdukYHFPBRt0Joy535zNKVBX4xw8LAdvmVsc4IfjLD/8M0Tncv+AQ3EJK9/30ekuulQbg== 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: Yvm/pZpu/smrgsIsbPXSzfSIGMLbm3/CTlz6/1lUds8Ghcvt4Ms7CaJJqyzM+fshQa5btGVKtjGA4qdFLuIj8a/oriNvYiEzkhECHljO1ceKKGRs+ZQ+mt1hBTErLNt6EV5FOCDBcdUZnI6gz8xP77Cp3HfAp/TqED0RliOfLOwgYnuISrtQfbV8z4cWxLbr/rY+u53RDHQyBultOM7vZooRGaYz/K997WyXYLpcB1f2gOwY9eDvptTA0cJ15LRRdiO7ivFXnBGM7IhdrSsVHSNVqrA0A/qdE+lC41QfdgsFKUk29KJ4qtJnwou+kn2oZH9axEUxEjl4I3UhAwBufPzBxY6TPu+dU7lF12k4mPKSF1QbNReME2XDJYMk9pJZysOm6SxQ8b63cuKbqRq4eDLOZyMD0vfEyLd8+E1rXkwIY6GH6xA7TRWCzpihloIq1U/w7oxk6u89s3vAemGOop5zTpWlcLCML0QXlyRnX83FwnuKSBjsxbWMWmJYjNjX/M+0OiA/DkTfIvaDXbloq636JHu8SjURKARsA+Sn41nZQOFRNaOz+vAdPJd+wlQlSKZKZDzCdkqewFgtd5XjAMIIdVmFRbXTEy8QyfuwcN3D97ASCcAFPvxxhVj+gfS8hXEaKtqcEfBNECHJR1S08u38F1sXgPoqy+4jcskr1pCAz7BpR+z0iJLuXXV4IoROY0SQC4xo1aVwWCHqWIKdIyB6UmjXRwqqBYNJCz2+521sXsJUi4WflXSLXnlj3bdWzY9Cqhz77T58chgaXkhUSQ0ZXrgdLjCYRQ8VpfiAwNtIzwV5bPFr/Iqwpe0piQRJg1jusbddhWeagHcXeZtDz82j8UieQ/BDOgrWRzpk29NNmkz17dRwyyMsznWK6fNqduQUAkSuUFJTjtHLIke3lBM25HXthuB0PbIkE3kSBG/SKueuGzLXyofaMs+JJdYGntPX72gLto/xehL3Uoue1veq4sucGXm6LhHde9tmLh83mqhUDb6RWOVj3arZW35KwElVcaPGexfT2XrHcQlcJMw6WDuhmgu0dkub4IhU0Mb2LD/gipT5s68Jf4eYM/x0fUonMZseeA9uKsQ7Be/JB64/kA2+54W6hMjqZaxit6DFtmzjtqI97HCDntNn0MuLIhyxaLwrVkIrmGvXrEnK4WwyvrD9CavO0Il4ZR6UNMqwUrB2aAAyZ+MQK99ma9FO7kKqtPWzBA2ohiP7tmZtdV6yMB4OnQKy0OL5xyXv8UPT5l8FAUzLmJrUth7zrqCXxXRjBud7YhV6qbMpv1AbEDg5Y+w/BVqXs5UajR5OOqKZ9Be9xzZvfEC84GjNLzA0 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1487b7ba-c3d4-474d-bd4d-08d975e637b8 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:48.9256 (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: vvSY1Bo3B5xHQxS+Gl753wlHzrHjjquVuBw1Hvgt2QCx/LTqSBMBdgnEwzSv7IQjIxreYG61zIgLaMyKKG+ONg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5854 Precedence: bulk List-ID: X-Mailing-List: netdev@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 Microchip sub-driver for KSZ8863 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. Since this driver expects the MDIO bus to be backed by mdio_bitbang, I don't think there is currently any MDIO bus driver which implements its ->shutdown by redirecting it to ->remove, but in any case, 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: 60a364760002 ("net: dsa: microchip: Add Microchip KSZ8863 SMI based driver support") Link: https://lore.kernel.org/netdev/20210909095324.12978-1-LinoSanfilippo@gmx.de/ Reported-by: Lino Sanfilippo Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- drivers/net/dsa/microchip/ksz8863_smi.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/drivers/net/dsa/microchip/ksz8863_smi.c b/drivers/net/dsa/microchip/ksz8863_smi.c index 11293485138c..5883fa7edda2 100644 --- a/drivers/net/dsa/microchip/ksz8863_smi.c +++ b/drivers/net/dsa/microchip/ksz8863_smi.c @@ -191,6 +191,18 @@ static void ksz8863_smi_remove(struct mdio_device *mdiodev) if (dev) ksz_switch_remove(dev); + + dev_set_drvdata(&mdiodev->dev, NULL); +} + +static void ksz8863_smi_shutdown(struct mdio_device *mdiodev) +{ + struct ksz_device *dev = dev_get_drvdata(&mdiodev->dev); + + if (dev) + dsa_switch_shutdown(dev->ds); + + dev_set_drvdata(&mdiodev->dev, NULL); } static const struct of_device_id ksz8863_dt_ids[] = { @@ -203,6 +215,7 @@ MODULE_DEVICE_TABLE(of, ksz8863_dt_ids); static struct mdio_driver ksz8863_driver = { .probe = ksz8863_smi_probe, .remove = ksz8863_smi_remove, + .shutdown = ksz8863_smi_shutdown, .mdiodrv.driver = { .name = "ksz8863-switch", .of_match_table = ksz8863_dt_ids, From patchwork Sun Sep 12 12:09:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 509693 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7C71C433EF for ; Sun, 12 Sep 2021 12:10:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BE3AE61108 for ; Sun, 12 Sep 2021 12:10:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235490AbhILMLT (ORCPT ); Sun, 12 Sep 2021 08:11:19 -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> 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: JaqXoF1/ZGN4xofkkJp9Nrpc6tyfk+t9zgwv0tetzXXERR9QbFJI/wgVByCQlJiIWxuoMR9SGMOIL6iLtjBIft9V2pTzJxbwhQoENYthPYMTYrk+WKIb1W/VbM1vs2vcKqmV9WtNK4+brmY1yc20udP4FoE4UEWfRWx9fmbr97TrD2r7DWy1boY7cpwJ9PPbz1vqVS0jDmw0njQAGg3Dhwv8SJudOVzz8G8DVdJJi/4DfHg07z1QnTDHYCr1PL7BHUrxjCYWJmvm1/+3Bdms6LT1kT+sDRMxfiT8Xc1v1u6zYylO8am/4yZ2xYRqLMLud+tE//T87owc0sImfh5ewp81dKTBmaYrkwFtpg/DpS4p+gXqQpStfpFckZqsB1RS5I1l8YsoRUnbMw3yxhhH11aLErI32WpYLB25O6uJ2CdM9tDOZfnv8iStGodIciemQ3A9Uyrh8PS98sEquthoruN+1l4tjcyZ8Atmu/8qolF9v1ORvHUScfBPPllolKe8GiNsFAnRpX/xoEhMG7k/8hdWJlxPqzNtrdIEGD/5X0L5L4NeDjlEO9xIc7XdqB3pmv4kRHudDhB81NJrba3UuukZBneFaSA/h77WhxAzPYkLbzMX9NpgJ8wMjg6aVYSrA8rn0stSfWvClWgMIsV9cJUf0C7QHh7u6yjhG+tOwVkcj9LNscjzzCkGpy6dtlMaxda+D5JTMYW5F2OXPhPGrm1YxvNhK2J3ACQO8aBgSdsZk+itROEfPaf4zf/nDNX23YWfvU99AifhHetgvRb/HjxYWSeduq/dPGlF/BhWNKqeLmcQnFk3gq8lS6g068qHqSLvUTkbfFoEO3JwKHq6IU3sFHBjr8iiIOSXJgpDmrDJWOaDYdICzZKySGqXB6GBha1XWRlBEuAh3lX+FsvAQXZFPK8NNDFrHNB2XYviR7IqU2GaBYVZiTi6GESqi2/auHJxIK+nFr9o1GZsTjfg3CJ1Vigzu8YigktsDHC/VnoAo+zzP9kZyet4saIuTpUmbbC38ftQOJyzOzxQPjQbpdv68Pt8ygXz8QosA7MEDLAz0KbkPT+bKNjAfB0Jpy2PPFpENfEo7+yQN7lAUTDbc86h4YwEjRcl6wl5ZsI+fZoWRyfK8Eds7XH4VF3c+igWRpWy6sbmzCk0CjS81xnEPkPzYFZOEiGLQ81b8BOdAZbdEPS2MbVNCOjo2K5tzpRVXv4tX5A3t1xhF0NHrJkZxYHN90ubZyePFkYe3zLfpY8Is0vfb0c7I27Whk73o97Wpf5FKmpKZgaY9IjSNvIF+TvyQ12vVd1Sc05BaE+7d27ScL6q1BI327zf0PVNc49t 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: netdev@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 Reviewed-by: George McCollister Reviewed-by: Florian Fainelli --- 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);