From patchwork Fri Sep 17 13:34: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: 12502125 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=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,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 A3D8EC433EF for ; Fri, 17 Sep 2021 13:35:41 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 62D6761019 for ; Fri, 17 Sep 2021 13:35:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 62D6761019 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kuJMsL8zU1Ox+7CCZ9WET+G0/fdpTHcmlyMs5RmKn7E=; b=HNOskdnYgOiyxH 9qARiUN1oZAvjD7fHFTOYA4Yh8XH9X2IfmySj68lQSz03G1yRD4wRHrBl/DndclLMyxCm9Am66HHn n/Q0Fh13vnEUML2R2ApXvjKmc+i7qzK1SuVEQuJO2VoA3iRbRKOdNlEe8XOrN1RyM03YiuFsl4pdg Fvok0RKTylU3p1fwlaHSzrkkpG3SgjOzUC0V41x6GNjW1I/cl9Zpg3yeOLIr70FUyN8iGX8mgvCzS jhLKta1NF6vFcdCzhUPHt5QgVyLHdEoE/3uw05PDtzQDRQVdysDY3X2SGTgTUw3v7NVHvrskGBXaT HmVjbq4P0F2ILJpjf1Hw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRE1Z-00EJSU-Je; Fri, 17 Sep 2021 13:35:29 +0000 Received: from mail-eopbgr80047.outbound.protection.outlook.com ([40.107.8.47] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRE13-00EJEg-0c; Fri, 17 Sep 2021 13:34:58 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IvQaDYDgX/rVNK2HEtc8d1kmL8RHkN9HlEYAdHT0H1YVq58r7CkG3SRe8XBBFJ1kxWdtC+Q58Ll1js50yntp67fBt6mpZmKO6FbzygWDCEK3gCRLcZMFTiU3+XWRM8QwQ91GcvbZOs+7qeaLOoa7sZjMhJqMzLEx0HvU7MlyklSHEkHtxM22dNUdNq2WZ9ElOOZ48N/qfVInj+vsAcDubaNlTuB/1FQPQZwYEimNlgD46ZzjezIFvAVkSCRmZLZ/HBGaUWfG7huXzZ96Ev9GzOaG365UUayi7FDcLHcdQGadz+wcbjTr9cNd+c6QkPLnwpJc8Uy//eHjC0YlUcSULQ== 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=pjd39OuiyfPLTnwLybfGezRem2rn9KKpaPy2kqVnG6Y=; b=GRcNKummeMBW1hxBbGha2VmRRAj94HaLqRwgRZk6OmW9z3MW37MIRWYPIWjzswx6aZ/zDCxpKnoLTGwX/6T9kztZyZTf5t28gs0Bxrs4StYNoliOcC/FLcaFs3O7pZCZJxTrOTaVe4vKULwAVdl8TY0NyRxXFIy7ri98+9NPjYWIhZgOC204VqLYtMVannW1fvwJL3x1A5znygEzvRdWhLjie7yHZQnbS1psaWkZcO2Y2lfVG3SMK+toHB/OlGBNtqvaeTNWTf1jI1FhSR2iMAveRe9si1pWde7ggwTwaQRAnzyejfN0MopkSsc8Rym3+WKi/X72h5yj+XWtEjacFg== 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=pjd39OuiyfPLTnwLybfGezRem2rn9KKpaPy2kqVnG6Y=; b=W4BrBG6lAOScpdveFdOmPmDh8G/IuuX5IEQz1c8p6uJOh02tnGRXVMP51s5GUJmb9yi2wLJJ7cSg3w0X32oX06K7A25GpUM03irruYr4bIOgFehM4SaIzWL/xjG3C9vPJHVxbUP+VjtUu6/4kd71qV+IoWJB4+0zo/MOSTNEpHs= 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 VE1PR04MB7341.eurprd04.prod.outlook.com (2603:10a6:800:1a6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16; Fri, 17 Sep 2021 13:34: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.019; Fri, 17 Sep 2021 13:34: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: [PATCH v2 net 1/5] net: mdio: introduce a shutdown method to mdio device drivers Date: Fri, 17 Sep 2021 16:34:32 +0300 Message-Id: <20210917133436.553995-2-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210917133436.553995-1-vladimir.oltean@nxp.com> References: <20210917133436.553995-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR02CA0199.eurprd02.prod.outlook.com (2603:10a6:20b:28f::6) 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 AM0PR02CA0199.eurprd02.prod.outlook.com (2603:10a6:20b:28f::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 13:34:50 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0abbda9d-8b6e-4e9e-f278-08d979dfed8f X-MS-TrafficTypeDiagnostic: VE1PR04MB7341: 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: pDMY4zuRWVVn9kAvXuQE+NMiaqB+YLPIUY3Y6fylArOg/0gUCut7PFA9TmgnYNig5NawxwCEAE2SL3pbneoIw/lJjfjyCPviFRyQt5YxdV2gYBluGY0+PCy7diUuCGqTBSOLVyixT2VixdHpbR6AMLE88NzdrNWeO1Q4QM56jFFgH2FcLylfgj/aZsdpSEUDTaR27VsKdxKGp7DZ9NIhJ+7+QxnqvkSRitK9SbJjwU7LFBoJS+J1wI6W04hsZfrIt7GCS4tLgiep4BwSQZU7FVIWEmKZfEEKhBs47m+IuOnyw5oHYTHZOQnN/UP5kkMiCNmOp7rTH5xiPIdEn8PLFI7dw8uyrX9BoN+6VrO9A5nbAa/uvykdiZw7ysjwJJSx0Fl/pCBxF2CDqaBjRmIJ7RzKjYNO7U955XUgpk345IoyVFUo0JphYYM+VDzMlTbJgbMDKOstPfwV1ZZLGpsIYcfsL2bKgQsQ+YpbrUmI6cdoIuFtC2zxkWPJOiZpBNHySe82OW6+z4FsumDY/Stbcs+wfJ9x2uWQ6dD+IP4LxxNM2nP9bTqe+D3D1Fgc+MjWMJARkihkvFJjtduF7uuLB7QC6wHApcT6aQ7IjyBec7vymnRz+/vUJT7tQvPKTB8edkzu0rDxamwHXyo4J0xvgSlY7kcFUVuZGFH2XPFP9M8x+osIw8KEliOQATT/qpsxvReCoimfNuO8tyoF3oQcWw== 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)(376002)(136003)(39860400002)(346002)(54906003)(316002)(38100700002)(38350700002)(36756003)(44832011)(2616005)(86362001)(6916009)(66556008)(478600001)(6512007)(6666004)(6486002)(8936002)(8676002)(26005)(1076003)(5660300002)(6506007)(52116002)(186003)(83380400001)(2906002)(4326008)(7416002)(66946007)(66476007)(956004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: KS1nV9WOsEYU5h7nsgegyAmNV4t2yYDN0DQSUf8PiKUeiPhnKyLtaZ8+QbdzS3pCDZaIdq1wpEBxYThx08vgfMz2N3MLXV7g77iJOHlTQtp3XoWCFN5r29+4zKISE78ZbopB5jcz2TXLvZWqfQFCgtXvUbPNReKx62WKMzByVczq8JyAwLXqXz7nIGDBoUx4mchKm0TqJxylrtloyClfizYrD6GdkCorUcCDs0fgvtq91w6lsy/wy4MFmAR1wwtYqUgEJ3FcOpA3guIVxEF3QH6UcEcLDJGQ8pJnv987EYG7y8eMHqBlhE28cRexeQxlLsTA7E35V4Gn85KTMgjUohSUXgSpcfpxdgcrM76PcZcqSk52nrsGPNWKoLTU+r9krO/wMWS2fxYx6xbXSkJMzdbK/2uP0mY26nNFlEbJvp/BY/lJA5htWGINq8AMXJ6dUYphevfuNQcankyeszfxfkgx/ha6pnJGZGX79ORt0sCta2RtpO4s7vtV5QwpfMaHTEvtSFmggj9XjrWlcsD1WWeDdoAQRopgerVh55s3W93l75NQpaPZ84AgAKH86WCU2zT03SamIQT5XMb+c28vGrTwv+IZI2Z9N8sraUgdpJXrKYXL0/noP0Af/25q5MvaAfQ0aqoxwzMVgvK3gDttdv3qyOq9ginIxkTrV+hdigZyLHfMwrYS2oSKdAYmIqE+ZzMXcbNjsMh0Ytj2v6A7Ktc4mcBMYZs3qln1/sl/Bvj3kQ4RsbnTQa9L6c+ukRrBzm/QxYV/VyX2Th20OETyxNKN9lAXwsXYJ5a5IRiIjQFnrPJjC4X+QTbAUctK52U3FQ7r4tz6EsINb2dlOmurB3RAYa6g/luCE3n6wYUx4kogJUD7zdBteZbmD8yQm7oSG9HXw4+nXTzhIHswzxHCuSiFpwdi1QKSs+WC/CQsZ0kiZg2iVzux0bmajJ0Hzi0Axkyvt11Ilx/7WIm/dlChrQt7NbQIltnLclYR/4nE3doinlz5XV6tjjjq52+c/F07CFXtrXxNSjBNKfQ4KK0Avw6h0KhlZspub3pbRuxF9pqlxog3mMePQ5w5f/ZnLbtgQRkleTpyhwKfsisPBCsj2FgPpyt9TPoHukzLY9360Ri73bGfo+Mqr4xW/4k6AptV8ENXzlReSBbuBlyMBj6tK4KNDbv3AxzRLxmwEd8HR0DdOtLTNhYjQ7B8WRAwXQ6SXt2jKfN1COnwBqsVBJAMF3M4w10X+8qOcznbrj88/pfnCe8i/pIryAwvbkLzwCtM9k4fWrHQauC2rDFk99wQPBti3XuP6BNKnyciL9TWYlMqjPZhJlDfe1i7LSucVJAz X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0abbda9d-8b6e-4e9e-f278-08d979dfed8f X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2021 13:34:52.2036 (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: xY0Qaj7Fpl00e4Vku2jwdOtpNN0mfaVYX6XJw/5hy6V//PtCqe1Wtzmo1q1X/5ve6GvdptufgyQN2+tzDGiV7w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7341 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210917_063457_083546_EDFD2965 X-CRM114-Status: GOOD ( 17.68 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.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: Andrew Lunn Reviewed-by: Florian Fainelli --- 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 Fri Sep 17 13:34:33 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12502127 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=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,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 67487C433F5 for ; Fri, 17 Sep 2021 13:36:01 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 317AA61019 for ; Fri, 17 Sep 2021 13:36:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 317AA61019 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tMtioyMudHKXrrNtpAiEQT8z8+wbR5D4x9v4l+JZXmk=; b=RjsbytbPSt8aiH OYLKis2PHSsUCnHFK/8Mmsh/B6v+NdcyidU6rCyB41u2LfxXCPe5qpm17UO/LgWVtz3wpwJzBnVy8 s820QwgKsWSV9eHeZvzAmo82rM+yMTozKxKKV5n3e7aXbL/sShdZDLp2VCPjjzfdxF8xU+Xs6m5I1 nS7K49sf5Z6OSXGaEYmyTh7HkVMPiyuoMq//LKVidiHdbnn6oIf+gPdtvnunTroLNs/239h52KIqB nFvqp7CPAGQRAUGnQFxdGKoS/A8Kg+LCmIxvxXue0tr3oui/3HGlK3pOWe97847EvKwmt/hrY21mD bEja01SO+2l1gBacsPjQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRE1p-00EJYo-40; Fri, 17 Sep 2021 13:35:45 +0000 Received: from mail-eopbgr80047.outbound.protection.outlook.com ([40.107.8.47] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRE14-00EJEg-Op; Fri, 17 Sep 2021 13:35:03 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=N8FCEkSvr28ssJw2XzWtGSoTufux535GwuwqTRoZ09Vkei7j8O5p1ZVqUdNOsvQU+8n1CrksmGDC4yq5PUqZh7yp4yElJmY2W93nFFVyJA3HLsBMqfjrzDOAUJ0S6FFXsXo836n/xZ7ySN1quUz+8qy6vH/flOT1NWWuRTeUUaoydrsVcc/yfziONofNnK26px9ObT03raBA/MrTQwihD4ck9qDe8JQ3uVIG+ozUE4Gs9G7nMg5uKjuZLcu79ZfowRfug91thj2WCOUfeBgRdGxYw7YQms2AB/BCseY2yoyFFEsBxEGU7bMJ3o33ZoF5AoUcioLK9yMZ5CQsa1GKAA== 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=q0FRmOARTNKnYbmBJ2EfXg4RlQs9Tli4SrMO84cKIm4=; b=U0VKKdi/bNMlb6Kh5AYKj+xtCmmQhY7YGCR5brQu5h293+3syixCKDY0IhV3NiRoXCBaX6bbxOSH/E2y5WUhQAARJCNiGSDKplWx1hz9ATwhXkuzH3oKHJBNeXiZM7LashCdhKjCB1xT3tm00m0gui9cyubKX6fWyhRvnJ3Zrl7qs3BJUL1xJS8bY5crJy2wf5tQjIYpO4zqGOg6qmegekJE2tKbXnF7peY8wJbHqSdcoogPH8QJ+iT5eGSkKdNSwo2xipD85lxCig+LTKggr/p753X0Xieoevk4Xf60MbFhi5ToQypyYZGfLTsnz5QoxPl6lxDWhvesHq1DsiNrWQ== 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=q0FRmOARTNKnYbmBJ2EfXg4RlQs9Tli4SrMO84cKIm4=; b=NYUsXuQ+Ton5GLF0Jz1rbdN9OIrxZfvSTuX9Z6ea9rdd7fm3AJVuACtgFC9srBTiQYZVZQlSzBLKcU/+MwWxcxc4LOZqxqXrxjzgM82QIlGDJWYE6z2qOOj2lF8uLoNnYLts/evl2JzBZ5dbxn96IL3NfsboGHCgYnu6lMzVq3o= 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 VE1PR04MB7341.eurprd04.prod.outlook.com (2603:10a6:800:1a6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16; Fri, 17 Sep 2021 13:34:55 +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.019; Fri, 17 Sep 2021 13:34:55 +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: [PATCH v2 net 2/5] net: dsa: be compatible with masters which unregister on shutdown Date: Fri, 17 Sep 2021 16:34:33 +0300 Message-Id: <20210917133436.553995-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210917133436.553995-1-vladimir.oltean@nxp.com> References: <20210917133436.553995-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR02CA0199.eurprd02.prod.outlook.com (2603:10a6:20b:28f::6) 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 AM0PR02CA0199.eurprd02.prod.outlook.com (2603:10a6:20b:28f::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 13:34:52 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2e400f53-adcb-4381-92c2-08d979dfef42 X-MS-TrafficTypeDiagnostic: VE1PR04MB7341: 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: 60gDxdy0S14UL88ugQeuUarTNYn7gKgN32JusQlreE1a3MI9CswZhm3VZfKfxoUb/523ooHbi3pEUs/Uqew4K6eU8xA9K3l+L6in1sLaIFVlJXS2yz0mym8vQY+JDNugKlUMt926heXYoZ+lrDp39u90I2gVtonovOzAFBwzwwt1ji3tx8JUxifI7EK73EnHbTI8npjo5Q32dAGUqr2g5Kpinc1Izedlg4tVVe/1t3r6jE1zPtqFx1HJVi8+1EngfRb9qCveFdGFJfz0Ni37gZgo10snAV0peV3qluFt/zI3pnUJeq4a76j/SQGvY9u9+JYGFL8Cv163aJvsNTfg1AOTPFq/v3tr1AvqVolj9TyRiCTWqY/m/ySUPhM78h9T2G5TgH/IV4eLNnMI93dKHbT5ffzwCvCyO6YGhG9R+yjj/nK4fZWXvVl1l/WvbQFuKX9B9t24e0KON8+xOs56KNX4lHQ6ZGAOV18UxLp7ZJagRUD8t3edPrwfIizXBhesw0q1zkkg0OrEvym1NiCbO0nVGCqzj0IZNhZuEAjY1a/dp1CvP8x2oE/TXRG7qbQQtk3tOOhkcjdPkDvYWfNUNZIzvLo5Eg+0IbZS7zRJmXxbh0svBOkC8agD/zOws/z1HSsErAIzni1K+/OFz1jnvJtL4euEQz3IKI6yyZO8RbP8fBxFk2ypl54ALWnDC1Au28EqCIE9VfK+ZJjxeQKwJz3+V9CyVjY4YNKR+UwoLicS7luxilcupDBA6PKAdscsId6A3N9KA96J+LuWbiPI0K6mdwJEhl6bU505cHeFSRE= 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)(376002)(136003)(39860400002)(346002)(30864003)(54906003)(316002)(38100700002)(38350700002)(36756003)(44832011)(2616005)(86362001)(6916009)(66556008)(478600001)(6512007)(6666004)(966005)(6486002)(8936002)(8676002)(26005)(1076003)(5660300002)(6506007)(52116002)(186003)(83380400001)(2906002)(4326008)(7416002)(66946007)(66476007)(956004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ngkbLUS+cKxDHXrHl7pJqI03BszgP79kRJf2cTDZuR2g8VTVBrRnWNzsFEpN9cWxrbaZxjxYIA1rmHesN4QrXXoIQKlyXrDq2+0SLeiPpf9LqJYza3cVkFhPN6R5KpCEcvvFLOvg+a1jP/Xsv8+BtigyQqjUVtgKO4ufxrbvbI8cTGR1uKSP/m1kXluPKUYDtXKQiPkivC4JStR01p1GpP8cIbKmMGagsoVDR6WPgvlzh048cwqV4A9gKardO2tXpw9C3HaH8ITWj+bE5TyGig9a0M3L1KlwtvoqXcptnxJtTjSqcLuklnqI8t62r/7n19Uq0hGEXp7nAZqpnBxMeC1DOOCw1xXMlA3MTxI7ybZBuikkr8ptXCV5Uc9EYp1qE4R1VJWu2W+0EBpWbbj9t5U6ovh2Gd4uirUo3lJnDaQeIM8rIJgEy2W3rTvC43wP7czciVFFPxyjyjvdOlhaJlxcAvTBuHz0CMzR+rdPLAqDaQJkEacMi3gcJGPTM2twSLTLXhjWeL6zAq8vw/HeV92KvyMZkTdxgMoG/Wm2zLP1W3lJfgdGeC5T42yuCLokPAvUVaiWP0S95QzDBvk9HDZxR/O0zrJMhiglSF+0j5GRE/wqrauww3hx+dzfC7aDGBLlvLU7fxx6XnHchPUKYYTiKqdh0QYseGRG3Vdpax8HfWumo4ozfQcD0Scff9sxuwFKi3k2bcuP9iUZmQoH4BZ0RFicQLfvhviDRcKx16+NPLTvfi1A0Ujuv+Aiw6/1JPXilRIGAEx5xvuiy/kNL5WTg6SlpRwqpsmzVxjOTGbWe6PoOTe/+JNuRuAxG46okLWYwAwiyuQGdR05pYfJq5MmJg8ivC5VV7Iuozjk2jt8BRl8E2REP5Bpc8ILl90xzWikoe7TR+V7LGd1d209H2t81MtU4dH0GSQ2z7em9vtuQMXuflouuoPyiFRoXqx+57axkjgvk71QrPoO094LOYMRydHQP0OQx2FzrFW3KKyOYFeS6NPq79V3Nv+QJS6CIRefJDUu1OEWqDEB0iKCu0HF+XdIY9BFcq9l2aMDAU1FbCW7V/Ta5NQWz4oa2HRfM6Z6Vedv54lnJxzlVVXZ0G2aMJU4dl6czhShDzXuKEQNghZCoWfAm7zpFfqcvMD4u/ihYZIirlyjhSvrQDeQMGxc13rt8TNfJ9vzL4bMIdH0swGSqob+pR0bd2JmO+k62BkCgo6CR9HXt/IbqI/mWLJhf98IyqlHZZWNvHdIgNwebUm+ipT8On/NbLTK6FNcv9K+XeBK7T21kYZxudcWA47grFN0cuCqbU0ciMbk4bq77VlQaWNVnV8i0Qk6UGB7 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2e400f53-adcb-4381-92c2-08d979dfef42 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2021 13:34:55.1039 (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: 7DMDpHy02Pr/AkFQAJRRJ29kt+K9RtkPj3XUt9TR10XB2vPm+K3SQwpTqT4t88MqtA0aYbr7C6EZkgiJMyXj7g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7341 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210917_063459_038083_02E41BA2 X-CRM114-Status: GOOD ( 28.70 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.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 | 50 ++++++++++++++++++++++ 30 files changed, 457 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..ae4c79d39bc0 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 void 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 b6c4b3adb171..7578a5c38df5 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 267324889dd6..3ff4b7e177f3 100644 --- a/drivers/net/dsa/lantiq_gswip.c +++ b/drivers/net/dsa/lantiq_gswip.c @@ -2184,6 +2184,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); @@ -2197,9 +2200,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, @@ -2223,6 +2240,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 9e2ac8e46619..11b42fd812e4 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 258867eff230..6e29c0e080f6 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -1046,6 +1046,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 eef13cd20f19..fa88e58705f0 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -1562,3 +1562,53 @@ 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; + LIST_HEAD(unregister_list); + 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_port_is_user(dp)) + 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_queue(slave_dev, &unregister_list); + } + unregister_netdevice_many(&unregister_list); + + rtnl_unlock(); + mutex_unlock(&dsa2_mutex); +} +EXPORT_SYMBOL_GPL(dsa_switch_shutdown); From patchwork Fri Sep 17 13:34:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12502129 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=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,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 C476FC433F5 for ; Fri, 17 Sep 2021 13:36:24 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9609061019 for ; Fri, 17 Sep 2021 13:36:24 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 9609061019 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=ivvcZF+w2FIEPtXta1TOyr8vKC2Z7Vw7Ydf8+WpO9OQ=; b=DCmXciEFbcabhH moQ/qIb2oowCdg0VQMILwaJ4dD58xNGQVyt26/Zo6yCBRzrMMwwg6wTSZkPnQBR5MCzN1RIjAW7qZ rxdN8ejX8oYbmcKp3gUz/5BhT02FjclIjfVcHBK16qEou3Z2Si5pfTHRuYjwDQvNwK/LL9hKegsJ3 j9UYURpGGcdKOyY+FvT5Z41jpNrmzV4uoIc8b22KT1cUB8P69cCs+F1IFaGT0XhmV4RrpYcKkHwPM 40ZaH9Qsxn+nMJJKTsixK9AIyBh5mK2E84UHQhowGY2NWXrGQHh3LhtviycQ05c2zXPcvPVCbrDwW pEHPW9SUBj2Jxb/NGItg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRE2E-00EJkP-1h; Fri, 17 Sep 2021 13:36:10 +0000 Received: from mail-eopbgr80047.outbound.protection.outlook.com ([40.107.8.47] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRE19-00EJEg-KU; Fri, 17 Sep 2021 13:35:05 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JgGywMe2DaJe2WnkA4b+etA5OWppX1lIWr/lGnu/yPR/8P6Vy1MvtxFjMQVVudL4px/xttHMV1vxYYPMuG6Ra4ayGcnunnE/MKtUCQbmHl06ztp+7Ap1fFqEchhZ1ZSetcdVxWaDDPW8kVFt73hziflernEa4r6AT77gRFjbgeRqd2I+V1k2RY76gqBJ3Owy6nOzsjhgUX3GdoIpJQmK2tBoa8BSBVWGYEAqWLBQN4iWotxgsNrCRUHm6zU/qfBLFL82LOxL3xmowGoHPkW6ur1YAogWmwYffj9nP8HYCOUP9jCLs0lg5e5m8o4201IaTxaepPTMqljCd8X/yt4mhw== 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=TpwJk1VxBa92OVrPdLSIOrB9XzMTMsuCoNlrqPpc3+U=; b=Fyzrm40FxOmux2UmeNYzlJdwcECdMAmCzxt4Yxb8O/c7+vU1DGiys2Vi1XR+75vTqd3GAiGoiICrL9FWQ0dmhc+TpAILEw7uXJBXeX/JsrMxf6VMjCagGc5Ivwekl9yzj0TbdlHS3TgZRrsb0LnfasPeLvqLsrMRcWC7RMrifTuKoaz5M9V4xa4tzhlc8rFZZJuIrRhAn9FD5xNt04G1fpzdnKsg7vSghsexhlsKZgDkp2NAqthNatNF7DAB5KwfYNsOAeSDmj4VLai7Y79rFvpddyMGRVEsBfWxiYAhwhagSu7cxnUhIdi8198nBgUeyXk8GY/oi2Cv6IT94Y9YFg== 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=TpwJk1VxBa92OVrPdLSIOrB9XzMTMsuCoNlrqPpc3+U=; b=eKEyX0QR94O7xAOgY7KMAfK+aNTbBDEuDG5ASMtcGxHccs2nDJUQIhkAU6ULM5fZbvHBPRzpp4VCJVRuak1xcu4U8tnfXuB1Cmzd30VuEjkX/lXUJM1fIym0BG+S06c+6ueg6WhzsSLJM+lVT52sQrLdreKk1bxHJ7GjIFKdtaM= 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 VE1PR04MB7341.eurprd04.prod.outlook.com (2603:10a6:800:1a6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16; Fri, 17 Sep 2021 13:34:57 +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.019; Fri, 17 Sep 2021 13:34:57 +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: [PATCH v2 net 3/5] net: dsa: hellcreek: be compatible with masters which unregister on shutdown Date: Fri, 17 Sep 2021 16:34:34 +0300 Message-Id: <20210917133436.553995-4-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210917133436.553995-1-vladimir.oltean@nxp.com> References: <20210917133436.553995-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR02CA0199.eurprd02.prod.outlook.com (2603:10a6:20b:28f::6) 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 AM0PR02CA0199.eurprd02.prod.outlook.com (2603:10a6:20b:28f::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 13:34:55 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 82488cc7-b849-4a07-e1b2-08d979dff0a7 X-MS-TrafficTypeDiagnostic: VE1PR04MB7341: 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: aPdavtuDPMtusnLUKGehamESPhwh+jEzIoLvYiYlIooZXXIn7XUrO+mDIvk1mXEgBI+5DuejkM+iCT7Wtsz54qdq74v/jP8TLo95uTqHKd/GDUr22LJSjrn+hrD7NbiNS2ILMVUe9n+SaCTFT4bGOreZaB2Vsyza/E8a0qmhee59CrocDfidG7jwV/DqlxvI6JQdOndmBfow85oDVEthVMqelOXRkq6+8ZmLKQzM0MSegBRf2mRiJGtMAeOKNgJqvOKyZUdbpT36TfKn3hG2394OI8bxEWbAjatkwPw1aV+rDuTjUyXllbRIa5X5PL9PsvkK/erORti/7391Ejk2AtLcg+dap364s9vzrPTy/s8E9xAjenK/T+w+Y9F0CGwtfi1hiksL0sCM1IPwS37Tpq+gtEDtc2B9q2DMmeLc1Q6oaZEgnqJvsj+7FZ3Cr+plxiOvwr4Jopkb8kcSao7Za3EUPE9ityRLw0g+5enOYWKpKlAj93OGyTIRGc3NhyZViuMRpogZKNjXTru3lK/lTP2JdbbK7M9Th6mdOcEMpxf6JwRRpw+y9fcDIrhjDiwyta9Qxh+g1x4+yMjM/UqxJKBI9hewRcdyLP4ti+5R4HsOPOK/nK4gJe4k/TjAfYCkqClofGW/Xxut57onRGuPv78uVGTUe27aApyR15vgOptrqN4EYaOJutPzAHy4Xw72tB0PK0LLs7t48GvgTRkPiHq9Pt/CLMmwYYVQsrHQQVBwbRuzIPG9E9g487/U1Enz0tA+I8zwTwVncf5rC/1hRnj4mmdcQYEjsKkEda8Ra+I= 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)(376002)(136003)(39860400002)(346002)(54906003)(316002)(38100700002)(38350700002)(36756003)(44832011)(2616005)(86362001)(6916009)(66556008)(478600001)(6512007)(6666004)(966005)(6486002)(8936002)(8676002)(26005)(1076003)(5660300002)(6506007)(52116002)(186003)(83380400001)(2906002)(4326008)(7416002)(66946007)(66476007)(956004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tg8g0H33Ip+xFTrD9wRLQaDXCJjvlAdQDVbvNk8fzTUF0OlxdxLcIrdpcEb+21tiEoBELxwaASfDxG619VixTVdrmVspeaFmr5EPhKhV9GuPku6NDBQJDVgqHean6w62EuZacZSkYIK+k14beevjetbn0YMHwVY/ZDtpNXHSYC5OOeN1qbv48celHhCpGdFGIqXNt+IrMkmtX7X2XH4MufbVXmPfwXsJhhIdziOc6trxd42QDDpaImAZKXAnEDlz6Gd7yaOSyYenaupMLDiBQN+PnjzgQaNnnKx6e7tZ/gRGyAzJptvXLtOksLVSFxecBpYv1gXlNapwXtQG5FlbSej9nkBevpyLG2fRFGscl8YRs/hyQt+XbGOmWS7rVgKELR1fYR+jYoxPW0qK7Y9Z0ZwkIDWWPw2zRKA81ednNPubKGiBqCSBDGQxgDcyvw17ypjpC4dKGTaGy3zNA/xoODRwdbQ9FN7e6MyjWtmV1MQxPFoT99w8w/MP94qr2hoc/KtPWKLvCIKlqFNEObFIVHLNA+apG5c81GBKhyzfJQqeT+ZjCITfAr9qbztL0lHUTki+URL2SswI8Fk8GNg4nsnDrr6KJ2lwRGHvLujX/bCC87Q7szJ8hKlhQdNYTC20jSY6CN9H6tMmptLvbwqToxK2ktBwZS/rztVbnt1Rmb3F+TzG24EzxB/GkRzvUP83uHvGzpw+8JNSn7J1k/G1bJDE63jwc4H4CuCbdXLtlISwkvYqH/ECSBe3b/b7jEvRkeyro/OUHaKaKvbzg5jYPHnb9ko5QMmbqcLJFuYtQEOar2cIzZR+KbJ7m0FNMTsVdZpK4CQsxuLtdaaZkAqy8rpAg94Q5UUxaUTLhpVpKdJhGOANgm/weB9s+KTKCJq33u1zAKm3JjU3Kj7VQ9TFi3yxU02/R94tXFjYTAT4dOZrMYtFXRtCZbhPqIHCRGlhPtlvteDV5NgFqWxw0jRvN4/iDvU2zcBeJRhUI6WHsCbX+VvkjVYSDqtjyD9wSdrOrVc91ZQKGd56NdPoMTnQsF7Vfjj+kKdO0Na/IM+nyaJiGHHa0r4rbLF26MorDjLmX5brur3e2vh4a/KmG1h+oAuym8jehrSjjdKwESFIJMm7/s+e6l027obcpjSvTuZbmDRNNJU4NX60X8mtPXtSS9BQ2tJ/sUCUtutgLvY9hpfZNqv+8MRWyR6hOptcvQEuU8XC+7PO/+U0NZJAPu0z6ovnbZ6WDxQQsfqq1c9zh6gHsMJ0oPTjRS7rGeFiZW/G6Cv6mdFmtnIpiFWl2+m1IiSB4ZqeIb+ztqAuCy8loJuoAgQNg+Kx8/uIWn7Dgo1l X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 82488cc7-b849-4a07-e1b2-08d979dff0a7 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2021 13:34:57.3396 (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: BkKpbqa+l+5Ei1Gpm0D8T/BdNOWJiW7LRQeVN+5XQaX+Zwby2KFsE9gKlfeL8Nrbt459Ys4NHT/Wr3QtHwFo3g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7341 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210917_063503_726204_76C53780 X-CRM114-Status: GOOD ( 19.02 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.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 Reviewed-by: Florian Fainelli 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 Fri Sep 17 13:34:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12502131 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=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,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 657F1C433F5 for ; Fri, 17 Sep 2021 13:37:05 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 355A2611C3 for ; Fri, 17 Sep 2021 13:37:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 355A2611C3 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=L3wYWkIDp9BS0zjWn5igo2j/Pg2/4xj9RWfupQgdVxQ=; b=PZLLKmhP080tUH k6O23fP/Hvcqa+Z+FoDiQ3pdx3crKo61PpCXwH9xpjeROMNV9rnqoR2WUQ0U4LONIOg6XCDcIQw28 20K/JegkutbmdVsk6f7bFphqo8PgAnpM06Ulczs8l1dLGTP3cE1CKXr9MMwGIgyxgnX5/knUHWQcI cUd2Mbcd7TNFK113WWcROGbH7VuJxi0kYk/B+SYwzdYysqJAMC9KnGl2arV6QnWZclgab3No1A468 62IrKpN9kvcMnnMnDWRO05XGU/WruPJWo5zki3k9Vy6lYljbFyZW+aI39LZ82iYT9HcHAmkTafUCN TnrS/lzZoe1XjAQ6FbNQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRE2s-00EK2W-7e; Fri, 17 Sep 2021 13:36:50 +0000 Received: from mail-eopbgr80047.outbound.protection.outlook.com ([40.107.8.47] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRE1B-00EJEg-LK; Fri, 17 Sep 2021 13:35:07 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=b1MTbzM6nGPSCRpGYJ1SMhGOLSvbW5Ao4On0eCzXl8nwVkdind6s+ha4INTut3NAqkeJL9Mqn7ephJlvbJ2AZ6o5Ju5eKOHqdfN+6xfeGNX138Va/CENyAh/9PxwaMPIOMXc5VRtqhthIR5YvRBPBjF7nZfsdRCcC9w6WDKjciCFrNJsV1Vxi5f3xGcQz0AKT1Yr9Rb14vYtr2pqleJtor6YZzV6rJVPcheCeh5PQmNX0bBRCwoqoRFeu1b7Po2XO3KL2eH2gtgn6z+yNI5AsSec7sG/ENQ4xNvxlw1UmkhGCj8aOCmt0aJSgABV27Wt7ruOVn1CtgTsIavl69msnQ== 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=fm/3z1GGwH7cntLPCftroJbrorEsUqgDkRilX1FVpBc=; b=WT8YvVk+TXi9/p25BkngVB4IRVoxjG1sHOlQVfFVKtpaHQJuUN5QYSyZkyaXjJFcE0aoERuLWqQ3fqemK8GefVM7KkLTtdz3Cy7pjWDZZj9xjM5CreFF+kojksP2aPhMeGuVETsVvGsN81dUNG4qXUJEu9NfBoEbBC1jBpzrhIeL8q7RjbqnAwZNS6UaOw6VMA319asvuyfNbTdDwkTMGa/0hchgKg0uWqL2QZdFTkwpYyRzDInGAqtq+KSWG2d4BnAqdqzFnltmQy2qoiGq26PcVQirzjV3Oa/NvODu/x9mvaVsT65Wal43VIyfCBY0lwxdliYSE/u8m6WeS/k2nw== 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=fm/3z1GGwH7cntLPCftroJbrorEsUqgDkRilX1FVpBc=; b=SG6hmLtW8RxkLB0cpTrrvzoaLVQwcA1j/eQ6cfz99mQEnWmX8IBuyaKvPSHM46N30+eJ30pyaAzU3VO0pKs3yx+OjW5gnaTbpl4z+9pjc1fZctJvC7Be+cgSGfoMqqH8FppxReOJAolThZ9P7XsLfkVD/Sy0IHFg/nM/EBhbqxg= 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 VE1PR04MB7341.eurprd04.prod.outlook.com (2603:10a6:800:1a6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16; Fri, 17 Sep 2021 13:34:59 +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.019; Fri, 17 Sep 2021 13:34:59 +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: [PATCH v2 net 4/5] net: dsa: microchip: ksz8863: be compatible with masters which unregister on shutdown Date: Fri, 17 Sep 2021 16:34:35 +0300 Message-Id: <20210917133436.553995-5-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210917133436.553995-1-vladimir.oltean@nxp.com> References: <20210917133436.553995-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR02CA0199.eurprd02.prod.outlook.com (2603:10a6:20b:28f::6) 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 AM0PR02CA0199.eurprd02.prod.outlook.com (2603:10a6:20b:28f::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 13:34:57 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 75f2b4ba-4282-4b46-affb-08d979dff1f7 X-MS-TrafficTypeDiagnostic: VE1PR04MB7341: 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: 36ZryUgOY2Ckl5Zjx/CWeX3QnIi+k1cGJm9wsCLE9+wOJ6g/fyGd+F3Nt8dREzLWhpfWWKOTDHviGB06ZUpD1aYfPOMKYeIyAv0vxAH0v4NCMoO6/9urB8MNtkCpt+3wZrEuPuRbhZc1aDPdjDH/q6BtRJrjtHfjYih1awTRxN5UZ22XDj5icQlJTshBUPwLKws+V/5AorKOtUiqjEky+bjykECeh575F28keSk5Jh/18kxo8ypALcJuADHN7XRF2r7iHwDItgVr0bAdkmzOWvyr17OB/l1br7+5B+v1GIa9uqa9FlKe3c8wMetDiDtjpToytubfWrIPevrasdCEu8Go+yK4pj6psKfaoUFPbrXjLq2EGb63toNOZryA/GgBM71qP/eXCsnL4XzHbfFRpixR4/pmlzugd9n7eQL+pRTy9djefvIKtPFG3xPfrnEL7jjxQwC/Is8Kjo6m9mxt6w12Lma5cAB2yN5cpRlyvu1s01idU+Z3u+tfbJZVaAtDDaqjSpeGzqVYPLEHkGDUGn6k+iXJ077CJeYva/6Oxz/+479cJgWBspMDYc8M9R2j/HIwSJPH59iitFpNAgC9/DprYAFIeDiZATEcbptuvUSTosbrhauGZxXk/fDxCFvhCMfgmPx/RvkmYtbh7VGimAqqt09WcdIofYMfZGwkH8gR7c4cHksSfj5wGiZz0DfHykE+KmJaK7QeakTaddWZNR1u9SyCv2IZyoUNO8HdKeoWGq2Nw3Bdo4rFqGehhO8aMGbY3jin6Z8jOvE7wAE4Hdmjn2XZyPtvseMjzxPtcic= 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)(376002)(136003)(39860400002)(346002)(54906003)(316002)(38100700002)(38350700002)(36756003)(44832011)(2616005)(86362001)(6916009)(66556008)(478600001)(6512007)(6666004)(966005)(6486002)(8936002)(8676002)(26005)(1076003)(5660300002)(6506007)(52116002)(186003)(83380400001)(2906002)(4326008)(7416002)(66946007)(66476007)(956004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: K365jBnbagEs1OMvINCJDFB1X5TLS3tLsG7Lmkr8hug97BDE4eN2ukWhxO59u8pddxK0oeAZ9dcejP27xprJOf05QOkPZ4T5SmvYFYzBABHQ/xbayKC1kmrF2k2Psem5l9FSlCqdDYRsydv2BnoSrRnV+dECdGRqyuloxjo8ZV5+V6M3+QxK/NPM3IAbeHZvCwK3taxnZnoACzmzLKSZZ2i9kZBXoAoGDI9N8umOVxRD9dEvWjIeFBkW1qfMu0Dykno1d3OpOMiBxpuAbjSnJ1yq9cTyezxZQxAOYxlZZVYAyPBmYgeW7kNC3sHcLrksNk3RbaTlW3/Ev3B9K4ipsaSNjsK/AkHN18rnuunZWSnf+8RfyAm8x3pRnB4gAFQk7kA/9WWX1Ttm/KsCC+9dMl+Ug5yw8AB8XAUlvx75akWWWZRS3gg+ZGXD2eu8g2DR8j+94R3i6hvKEQaM+4pbrndLaM9RqD67uEgCMkjXPXFe1uQiA0gKHuuxKbQEVpRau959GW857kkzJA2rkk0gxwG7I+JI9WrPJobRwO1qh888/FkucQ6wP6/TgIqy08wOXMFdonng/pC2kjEe+0STYdm0WF+VVY74gGEEOdXEqzZzzE4boT3E+3OtUlLKup2rVp3hIKS9MbR9gqHGdR4Vu1UVIjTrPgnpZnSvEyrumJso60f6T1xA0AR+TwA8BnZjlnFL6RAl+ravmnNLqydSdVJrjAyeOPAHaQyDX25iaYdVllzNVZWAFVdZg12ynZq67g0zfN7EPB+mtKaaDHnOnjOQlcrezOqnBVafYYbQZU7SpQuctJUTYQf2oSYQAODSKOJpRMUmp9buwAxEXzZCtZBqdfp5ubqB5KvSlyrq/AdKSrtc6JUdepFPsA9HhUeQFOekdgjSPKJ5RbexkzUZSSI1J/Z+4i4FUZI/zcS1+aDiSOAx2Y13JXdUz2twiv8HHQj72Y/IvnsWK1PVCi4ugk7EJySOcfJgPihW+9ToW/A3OfLLxES4nvvvMRC5d/tOubXI336IrR9A1aSWKeZSVvR+UlnmvPBYoib5Rdk9eJ9sJvMlKXDhI+axQfQlBDkdJha4o7HWfA6pgFacEKwLS8dH70E3f60/m4i0IEA3m5zGRwG8hSaKvW9kkbqxBAak66XZdNtqo8jRl8pnsyuP1f+oOWbOz66keFXIFhEa6NV7WTw1wWk2HGfSsbRz/AkwEwik9eb6bSZDj3bTx9NM153ftny1PrX54MQmdqRmDDFtLkf+4h0ek+fu5t73ydUW1JW1lp5QSG2EpQ2H/lYOReGJMbqPthRRmwBvuTXUIC6pQaKegiFut0E/9tQIFcpF X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 75f2b4ba-4282-4b46-affb-08d979dff1f7 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2021 13:34:59.5534 (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: UFjbW5pHkuCy3JDUexrgGNAM+2MdpxAUHfctZfmWQn9O+pk4RLa913gny36ozu/rG9+GV0GPPylSM3GZcY1wnA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7341 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210917_063505_733323_FE3A3AFF X-CRM114-Status: GOOD ( 17.28 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.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 Fri Sep 17 13:34:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12502133 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=-17.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,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 369B8C433EF for ; Fri, 17 Sep 2021 13:38:08 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0A46961108 for ; Fri, 17 Sep 2021 13:38:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 0A46961108 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=nxp.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=KHdQfC94cHVjXVbZWJwgnQBr1ve74AtYJ1QtwNgK7Ww=; b=cz90ZU8i+Xcqxt HEssK/HISWGJ/TUAmm5XyrJFMD57CjtTNK8/T5CVJ5YECD0I+92boYFENBgqvhb+CTeFMWBsnWqCt ZjJ3QIV8E6bQSzt5p0WvUNTwax/FhVKi2K2IDFqtKM7GODIPuc34Qynhs0ziyJvcszpe8nH6HrHVW kmOmJaHMpYyod+JeLuqfPizoYRGpsfjOmIgczA+n+9WitX8xhKzheviiZDVoHRjoGUzkhYtMwU5ls uPRWcFy0fcR7sVc0H6e1nfOaCJDRQzz11piXNKvkEdssMtw3I/iNk5MvjSRGpX8dJF+ZHaIazlV4n L2Mq8iwFgzw2lacnOxHg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRE3t-00EKWU-6g; Fri, 17 Sep 2021 13:37:53 +0000 Received: from mail-eopbgr80047.outbound.protection.outlook.com ([40.107.8.47] helo=EUR04-VI1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mRE1D-00EJEg-LZ; Fri, 17 Sep 2021 13:35:09 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TK4ZT7Nt780/507g//ZhDN+UDdOhxFibC48Vo/hdoRfxRBzvz+zd4f2l+1P6VQCK9q+y+YmwjXLAoUx7ip8FAmKq6ayeCq92ekR08EQJB8a2z8WoilD6xjlorDV9gWZ38FoU2aN0QMZFxTvS+51zVQ4MkjVvdmFQgN+nHNEsqlHTGzDY9iLQHyQpzA9s3CcoEeBF7QovX6+hEk6GK0A2kcAqxXuh+jNDpZ1JClicx+SRTP08wibRuCzqKFqJxauWkdXc4zsyjDAmy746yCt7RZ+0RGUw0m1/QoNIk1GTFVrA1O2Isda1I+yhC/V9oHClNyptzujdSWqlZC0SOujvdw== 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=KUsXF4aAI4TDGevyXhOb/9ck9+IxxSImt8GLo8qzPFU=; b=ZRwVU51jVoxDbv9EIi9FXtiuVk3qqyzBFA3nM6MXatkOK2YjCCeG+9osx+zCJnPnHoi4rQ+m7fJ2qo9MTQJxnFoYHjo9MNIYGOB74lwj6hH5dG5zTUOICAas4XmWhOtCShkFH4WS9ZOccSEFP5+D/m7tRGIMMMKqjVJzP0eO6y4FnARZqkp5UI5nP3bdEMb9+1TxT3FI8Rr7VrfJj2zLg81pplyZQLtedGadtteML61wuH/sQYOZuvWaPSCSB9Lr0re+FTGfzRPwLVUSChRI2BY+AXn5ybwpFOZzWTGxtHk5oNvRXvkx7hHHB3Wioq+BHiQ1ritDdvlBja/rxzRa3Q== 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=KUsXF4aAI4TDGevyXhOb/9ck9+IxxSImt8GLo8qzPFU=; b=jgfw8TvI1Tr4QoVSoRMslLVGhPFGTAgeJC4onu7t58RKksXMX2TuHSZtYtFA7Bwclzt5fav9GkDsx4G7nZt+1+FMb6OzpLM0R+Tl+6Jh0KuLI3PYAykR2WQnFTr+S/UG716XU8+tEW/hXrJo8hQH3XR9XQBF0UE2Snu/cH0oa4k= 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 VE1PR04MB7341.eurprd04.prod.outlook.com (2603:10a6:800:1a6::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.16; Fri, 17 Sep 2021 13:35:01 +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.019; Fri, 17 Sep 2021 13:35:01 +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: [PATCH v2 net 5/5] net: dsa: xrs700x: be compatible with masters which unregister on shutdown Date: Fri, 17 Sep 2021 16:34:36 +0300 Message-Id: <20210917133436.553995-6-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210917133436.553995-1-vladimir.oltean@nxp.com> References: <20210917133436.553995-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR02CA0199.eurprd02.prod.outlook.com (2603:10a6:20b:28f::6) 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 AM0PR02CA0199.eurprd02.prod.outlook.com (2603:10a6:20b:28f::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4523.14 via Frontend Transport; Fri, 17 Sep 2021 13:34:59 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 30c6e4d6-6b99-4b7b-15f3-08d979dff34a X-MS-TrafficTypeDiagnostic: VE1PR04MB7341: 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: lE/Z9/49hIbN0mx0NfXjvN0ux7DUmxSYJ0YY/FJ12u7FH/PNgSi7+M0o9dd+YjLGIwZV9MUAeIrm+UPC49/dzE9NX6LZ/cAT5BgbN8i4/+Ak3t0L/UW4HAVDD+Nz+v5gDAAk2C/96fZB9WeH/kIA+DD89pr9QyFs9Jb/4iZHQvTXE40avbQ3vkvC7GL6kzmvXJQ2v2AadVoMhQHY5Qj+58E49ZANGYa93pEgGn2g2IZKvEqLkgExXAKfVeKYA5eqraJi8Rvu2+Y1Jq9M4MFDSdIXl599aCHA4fOxsxNwx8g00UeoQ0OB9QXTGQ/0nwuHxDCNGbnbzrXrBrzxmNu4nVwoZhKhS65wBC40RLaslZ0gS3LshjxmbVT+1y/UxZQu9sa/hItmdjO4jDf3BBBa//flBam5+0OeGF0xTSAG2AorDgZpe1bjr6GF/xoqliYq5qBWkp0Kxd2CLobiiZKmmYZELy98HRWqL4mSszI8Ck07EretsoUewBUuMxR6nTNiuqNU9HNqW4pmmWXoBUZfRAlRys1EiYcayIpl63jSoozvb65ctAMRmQz5oL0xUhUfRec9N5HdZLUOynTVGBNEI1ancuUpqHtTEwvKGaoerRJtTX/s87xUrNE2mRkolcYD+eqRU1EyrCJ7BglYJ0YIAgIvaIq/QNq1YQAIaVgFHH83b1f/SDXWswyNbjCLwEg5+ijSC9xRdG59tC6GTU9Tgo3LIDvo05DsSdWgrJJwtKZUR3o1WfFIj32+F38/BtkW1GCepvMxwq8EhNyQqLmo7/s5QzvhXYYIAaPRAt2m9bs= 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)(376002)(136003)(39860400002)(346002)(54906003)(316002)(38100700002)(38350700002)(36756003)(44832011)(2616005)(86362001)(6916009)(66556008)(478600001)(6512007)(6666004)(966005)(6486002)(8936002)(8676002)(26005)(1076003)(5660300002)(6506007)(52116002)(186003)(83380400001)(2906002)(4326008)(7416002)(66946007)(66476007)(956004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3V5Q+b3BCOAgRv2BboP3hir75wPRfp/3iwZkdUpafDtd7HtOUPaupY4a5sFIvuX9uPhYSTqDjVl0mFwMFuRG5NfHlgF6FpW3z6qQjS2L0t0mVu8h4EtsVMSKdok6pTmh+g4JsfX/eUlOtMjV+zqVtzsdB+TAdfH000IhZo3IkPoZENbs8c8Z6Nl4+LhiUtsrtuUO92pRMqicdkhG+cgN1W/Lv5CJCJAEXBSLJ6JtRHWENCDAteG2VNuFZrxB+teGLEs3IzMNeoFq4XFJyDTKAl2sW6BGnl27Waav6zOkyB6IFXolC7sqmmENvbuI+JyzQedMa54NosHJLWy+JBt0lKEBBH7m/jTi/jDICedM3GG0XNKV2dIt5pa145qvd0W5JmZH9GSvAizErgyduznglxNBA3gZKyggS5NIWaxt+ihg2X7/v+LbXBfrPxuyNsrWGhk5oWZokJRFPonF8ieUTTErLSrbTr/byJB86i0BnZBUU8GoOWbyVFbaZLRjHsZS4mDxldFV8y2b2cJu8sw/Jow0Sai+F2kv5t+Q7WvS4e4v8VqQAP9M1iMlzhUgT34dL8/6Wg54O8Uu2QmuX7vpOl4ZqNMZT1Ouut+9aAXaB+Xb78BxFcFstJiU4sUzmhBfQElr9rNlTDNpYl3u1+QXq2cel/UKsfND9U8vRe1lBmteQkLIfHcixIAoQaDRlGMozNOK/QuEXOklRaoaEQNFMmEspavmZRGPbeBt6Jdtf/OCTNeQdJd3Bra6rrW4o8BIH4mf0eH0d0zMfYnHWIBNAHptOfzmbF9tszkhfFwzTJT9nKhiRrBuVAKm1Ruy+1SLl9DCDpuoZFZkw97FTvVqqUyfmBNcxRTi0b/fiZkNsjbT1F4Le2c4wcJsjoIaNljlmqvMj/Siu3/1CFVZK/q78fFDugAuxMkqECaAXoHW8wDBXbpYQk5IN0woczEFE2LHDIft902WIW0xBJT4JeQTtxCU2/4b5e3oyn31b4ozpb1R/dM+qEIzDEJNLD3NQwrdMfnWykz7HvdW8vRRvEAyTk3vC4KsAjvWL+LHGrMZg1uIv/xqbRheBt53tiNvZdfLDusXNg6idZSoSWUF5DGjH6vjJcpoZuvlX4eRR7lE9i6eBiHmWa1gEsPgSuG8HiSmdD1gaQemp4vdOQx22Z8envBHF58f7+I2A75Etc7IxuQP/bJWenvQ818R+3688UH+Af5QW20VAUyERcSbGRQDD1T0hk9tnB0cHWZVwS5dZQrfellrSZF3vCl/DStmd3rZIw7wqWy8ledCdzDy41ItW5Z+PIzu6jNmnDSMdPHy5FPvUvX14L6PWPlrYwm4oU1d X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 30c6e4d6-6b99-4b7b-15f3-08d979dff34a X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 17 Sep 2021 13:35:01.7961 (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: MlL8Oo49UjrIJ3IOd4BdtG4Vd8q2g0MVBqxadFErEtVRqsdFhMQlFYovFky5MtJ/CH+osTZ9+7V5Yh2YDJBsfg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7341 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210917_063507_740552_DFE9BA77 X-CRM114-Status: GOOD ( 19.01 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.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);