From patchwork Tue Aug 30 19:59:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12959830 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91E21ECAAA1 for ; Tue, 30 Aug 2022 20:00:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229842AbiH3T75 (ORCPT ); Tue, 30 Aug 2022 15:59:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231797AbiH3T7w (ORCPT ); Tue, 30 Aug 2022 15:59:52 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2063.outbound.protection.outlook.com [40.107.20.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8360A108E; Tue, 30 Aug 2022 12:59:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C+iSGpAwRIF+8Zje9nmC/8SPLrPBe3UZXlxESKxLWWpLPbO9wJfORTNSuf7ByTPYtTpHAHPB3ULqIu4Wb65mH64aNr5unACdsBnlGi6beNZR9HMpntaqnzvwEvcr9akYeDrKfh6H4P1uUGBqLytGPu/ujdNXZ3oyadF/2I7ohSlL9y6srcxA71cvBDwLyHEaKMZfjh8UYuBihMqoNG9BCdp+2TDUjmizjXbpsTOtlQYUjkYzCwftKBA3yUFDd1T9fz6Yiv/eL3RKCdGxRzT2Rqc7aOTSG4grKydAN69Xitjk7H3/XgmQ4sr8A4WHz2Vtiw6sx+VZa1wpNA0aBfW80Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=umXZbWuDzLvhEefwGTx3wHuHvXFqLYhD8d2S6wz7vaY=; b=ey6dsRYHLoBcU5PJGslLRHeTNlo4kKHPyHwDoxtIdVshBUVTwZMWz3DUFqmuAgGrn+nimEMyD4QucLf7tRxHCKVSQvgD1rgkiF3ge5CV+TKU96oW9UwTDNbmvXZBKW2PAwdaW+Z9YXR5ct2khMSKGqn+bykwlgaitGyebz9gMvYnSl4/rlb3JE7pwtKKBqHsRT18ZJOmomDLAP8IzpHvgwHEDNHaWEZQJaENeYTNdRL45N+QhqSQl+VfOnri17j+Ak+74qPTQ8Jn7Nm2y54cA78ee4DIeko6g2OagnOWn0TfduLfD21SM+OTzSCTKUDsML0JUvmu2El7K36bjDvdWg== 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=umXZbWuDzLvhEefwGTx3wHuHvXFqLYhD8d2S6wz7vaY=; b=QNjF1+Z5GlScJ0sSPvjxK26A3V7a03OBP/VWb2iEcDw8NwUZNuAIFpD8daumnXFKRi3lIlDLmf4q3bR9sUUtXzF1cPWWFXTKnrC939n7uu6FoQwhE8axfTZUQijUKyXnesUME2MLSxGY08B3CCxd8YJ5/6mhm8i2AA2oR41Wqcc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6270.eurprd04.prod.outlook.com (2603:10a6:803:fb::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.21; Tue, 30 Aug 2022 19:59:44 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3412:9d57:ec73:fef3]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3412:9d57:ec73:fef3%5]) with mapi id 15.20.5588.010; Tue, 30 Aug 2022 19:59:43 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Florian Fainelli , Vivien Didelot , Andrew Lunn , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Colin Foster , Roopa Prabhu , Nikolay Aleksandrov , Tobias Waldekranz , =?utf-8?q?Marek_Beh=C3=BAn?= , Ansuel Smith , DENG Qingfang , =?utf-8?q?Alvin_=C5=A0ipraga?= , Linus Walleij , Luiz Angelo Daros de Luca , Felix Fietkau , John Crispin , Sean Wang Subject: [PATCH net-next 1/9] net: introduce iterators over synced hw addresses Date: Tue, 30 Aug 2022 22:59:24 +0300 Message-Id: <20220830195932.683432-2-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220830195932.683432-1-vladimir.oltean@nxp.com> References: <20220830195932.683432-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: BE0P281CA0005.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:a::15) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3e3fcd36-97fa-4ec4-2559-08da8ac22ea4 X-MS-TrafficTypeDiagnostic: VI1PR04MB6270:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: B5BR5EaM+ztyS2T30mSQTEKPvWdpa/KQVGG5EJq4y0RplQPSTdTaR9kR/mb9KNVG9U+pm3Kpmro2vF5NxSy8TOx8Ugzjn0H+gsZkgHKJHRzWe84+zHodtPupD+QgCGiWglEpiS7eZX3JRaTS8f95levzzoRF+hxxXLIg15pUCPWXn3qszsVGiZ1eRPyhmxr17kyK60pH1VUYDS9LkpfJgLY23x9sqmVq13ga0oDik0oB6L5mQBrTZtq/HTHmwKspB7X3fkQGKDTgxIh0/GzxcdkrGIr+iyIYirC3f3IfRSzL9wj2v5FbdPIZI34ZxmgLD8I03gYHBdfSJqfe0yuaNFXDnnzWBPzJBS4tLqn7o/NtbEi0ReISeRdM3Bt9szpZtRdN1Jh1f8ie7/T+0jCvDaFCtZ7SpxcB+NOxX4PZxF1ETgQSDj7m7O1BEgum5XyWKysf6ZEYZ4K9TlLxpjDi/rLQ0FifKg10IIb0FAi9ZOasTixiwcYmOkCn574PYmQYjJ+CfZ0GrLihpqctV8mSUewJRz+oyYPkj5PzB3hf1Xc9mlT2RvWDINke/DO0AsY7SN4KuHsS9H6lDHIVqZsN1yhmrFFiENE6h5Jxnn75Hy0RJ6SpeFzM3eUJEAZVyDvGZdM02nv/5fZFKrnL8t4c8zqQe+CYZAByypyuzNG8H0Yd/1EcL/+gbeIfZjRfXGX1hx2JL1qtczuHU1GCMgrcy1jrf6CUAFDD7H0YmaplKOJUADXaW7szWQ59FLcOZtmR 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:(13230016)(4636009)(396003)(346002)(366004)(39860400002)(136003)(376002)(41300700001)(66476007)(6486002)(8676002)(4326008)(66946007)(478600001)(66556008)(52116002)(2906002)(83380400001)(44832011)(26005)(5660300002)(6506007)(6512007)(7416002)(6666004)(8936002)(2616005)(316002)(86362001)(6916009)(54906003)(36756003)(38350700002)(1076003)(38100700002)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +6n6ddAECgAdvap7qsUsgd8hOrkLGVCkilvPmY6+uz4ucwMwqUu3DtMddJbQL75per88oEXLSwbyhq/R5Don8ZculB5xtF3d32Nt+fETtfVPOPG2x4CPATe9AKxHkA/r8AEj10EGT3BN3/B7GZ2PdwnOJ5AkSTaOAu0IWeSG/JGCDovAlBHBu2spp88aAt+W0wRj8e5hKF5s5ZAiGdGHpaMHwEacylkemDyTRcz/rCxSC1FcbJmhKIl7Tu/FEt4qa4vySlx1v7xKiBO5zytxaIw3yC7RIHe+UFuWioudjVXhdT45YBep5Hm8aXqbB+ViNIUg6nYhNx3YN9gRzwKDpsWkVbVKRrpo03GsNkVIFV3CzHd1ZuI9kxcn8yQECFMWEKDpYzFbcJhBfV2Gs7h8nTYdRDE6V+1OjiU8aGO1qSVRjsoF40txqMQjoUFLPWwgAm2cZoCmVUFcZTHCWoW+LH0SUkKfDFRHfeMQbiJd8jxRSsKsETK6kyiEefMbmSo1uZl+TJ2d3bhor+hAtamTSlrHtXLrr4RBsmHku0GzOqY7Yt5R+2Jcy7VlB1j10xVyZj47BNRvAdDT0RTbiYLBtDtHM/ozrQet4sbt2eYBxdqOT+VYijhLnlNYIgK1yRSLodenhmyC9iWwOw7olFpABfxRMQQiMSdidSX8ZQ2APBJsTYQl+0qSiGD+ffPS9GzsGW/mWACLPURYyzduk9PTz1vUSOWVeax3VPbkDkG9fgVgGBTWg5oh0QS65ZeoemI2cFqiQ3eEPC7oNdh8vpzqxewE9aUvdglaXmdZKPsKiu1Mshd+I3IypW0aqGW+Daq+rVVCEhwGbOZCHz+COfcIGOFApf3PBJuxeXYB9hFZQuO/pEqQSbViZ5iShs9/htpM508PfoUkvUsphLwOYoZiOm5g65/2/FZQ3u5Hux0D3AIqx5COYIqoV185gL6TMEseMM2iS8set350tPGiRFM7xd3hT3Q1yHCbQrOu8Jc7ofB4mw5qDhLpvawrIalY853Xn8M8YN80GwoG8bXfcwVjwhu4gK1rPVyt0HT/zFYDzS9KoaKi/5Y2o9rFmWzO+m+Mn1sgRV8uAO26xUX/Tm5iB+ek5l46iUvc+oDC5hy7xpXFsSQg+QcwF4xqbjFYmUuTnJNMwTncxdFC51Md2eYKTt458fRpnnuyJDRr/5X5TqE6/6mvU+656vZFad0MCoVT0wBZu/yYbqe33CUjIWUTUeEy0e/8XP/vgWpplPUvf8B4tk7tUYh58rkqjL++m2JwEvEJ+aEcFbm3+p2Gk0RjUzuyfkdRgGhVW3ywNHM/OwOk6HwR1IH/l1AtkNadgUtga2BNu59zYf/lnsLcsQrgoGLrrmXhu0Nr4bgYmI9LQXIOBOc+lDaKgwP3oEHb0144KvXWfx0iAHkqx+9je9mecDvwmIO+WkBAT13fTfVG6mUN6mUCV/VcXVD7o7Wx1DIDN1XayVYjKzBUr5iPwtrORqdntFDk2+G0sDGh8wk6VyxBECQh/abKeziwc/j/GIR64xLs34m018G15e+6G+aDJOAwvfAlSPPYxLMf+0g1RMZR4eol3Q+EeGEB5r7y2ZG+f1+HyBKYQf0lhWjSg6+n6Q== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e3fcd36-97fa-4ec4-2559-08da8ac22ea4 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Aug 2022 19:59:43.9488 (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: 5+h8oljntjcF+3hKDuz4UJ5nrDDiyHaEcrVI0uceru6pKNCyx1r9Epdbhz3mCH420u67KFqwWF4Uh+/ybQ1dWg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6270 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Some network drivers use __dev_mc_sync()/__dev_uc_sync() and therefore program the hardware only with addresses with a non-zero sync_cnt. Some of the above drivers also need to save/restore the address filtering lists when certain events happen, and they need to walk through the struct net_device :: uc and struct net_device :: mc lists. But these lists contain unsynced addresses too. To keep the appearance of an elementary form of data encapsulation, provide iterators through these lists that only look at entries with a non-zero sync_cnt, instead of filtering entries out from device drivers. Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- include/linux/netdevice.h | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index eec35f9b6616..2979293b966c 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -253,11 +253,17 @@ struct netdev_hw_addr_list { #define netdev_uc_empty(dev) netdev_hw_addr_list_empty(&(dev)->uc) #define netdev_for_each_uc_addr(ha, dev) \ netdev_hw_addr_list_for_each(ha, &(dev)->uc) +#define netdev_for_each_synced_uc_addr(_ha, _dev) \ + netdev_for_each_uc_addr((_ha), (_dev)) \ + if ((_ha)->sync_cnt) #define netdev_mc_count(dev) netdev_hw_addr_list_count(&(dev)->mc) #define netdev_mc_empty(dev) netdev_hw_addr_list_empty(&(dev)->mc) #define netdev_for_each_mc_addr(ha, dev) \ netdev_hw_addr_list_for_each(ha, &(dev)->mc) +#define netdev_for_each_synced_mc_addr(_ha, _dev) \ + netdev_for_each_mc_addr((_ha), (_dev)) \ + if ((_ha)->sync_cnt) struct hh_cache { unsigned int hh_len; From patchwork Tue Aug 30 19:59:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12959831 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CDCD3ECAAA1 for ; Tue, 30 Aug 2022 20:00:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231827AbiH3UAb (ORCPT ); Tue, 30 Aug 2022 16:00:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231532AbiH3UAB (ORCPT ); Tue, 30 Aug 2022 16:00:01 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2063.outbound.protection.outlook.com [40.107.20.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D332FD0D; Tue, 30 Aug 2022 12:59:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LNNA2KaxIBNYNemTU1bTjfRRfX0B7b8JHqyEIw/H+gi11KvzzY1JnNnY2f0r1B/4LQXSZxH3Vx5nM5XWdkV3M6jXdu3c190guML2rvPtcGmuNyl/huPpu4UjoTZQV0NnpfOd6eyuF+HQ8ge5VZbEyBzXipnSKjJx3L3VUf+gBySBNUQf225ENb7afg6J00m+ggzW8iab+yx6wmURuc2WEYI4N+UqXY9h6wZlthVP1E76mq9LhIG+jUuwnvj6YVVBYSKvgc1f3XnjQCLRrPzptg5d/6xCC6R4qdrgUZV5AlY0sOCugiaaghWbbW1X0T5enHuLogDAFvSdT2YBaBdrnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=EpbV+onS3SIe0zXprmypWJoVoKOayhcwhxLM/SdeX2g=; b=fB/BVPk9wJc+cfjaag0X4oyhk6v03awcILRrG5Q2GYRPr+lnOYqq6qXIvIp97UoAdsKeBwe4gZxT9wZyyMB0NQ3V8+I22/kNGxpM9Pb5wS/z2joYoTInOQ0fzF1+8o8h2V9kNtxXm0au41+LVjKFSfAYISQwYIvbO24OokbsNYQ+HYm6pRTSl9WufV9nFqetkFMkdWImJdeopb+mGskx41BoMB7atSbrbsXOta0BVJt6ShDDhG7kuzbm9GbFjUljdHHcAbstjt9g7hrXoVkcAZgWB/rfbgf9UuEtXT5/neIcad2+9cpljeoM9UzfQ8mGNQz93SFftkyvhI0UZvb5Iw== 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=EpbV+onS3SIe0zXprmypWJoVoKOayhcwhxLM/SdeX2g=; b=LXZGMs9Qs+qJReikVIY+NJTjA6JivI4bhvfUWVV9ChwzMXILkclAlY8LAkE4n+uSGbP4Ndpr8MpEPbR4GV0mjF6hu3vVJ3JWEkXmngPGnowhv7o26MBtNJ2bY4hOJ9MMkZcLYnTilJfNeS6njOVjuvB/nj6cxKvbg9ymT2WjQPs= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6270.eurprd04.prod.outlook.com (2603:10a6:803:fb::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.21; Tue, 30 Aug 2022 19:59:45 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3412:9d57:ec73:fef3]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3412:9d57:ec73:fef3%5]) with mapi id 15.20.5588.010; Tue, 30 Aug 2022 19:59:45 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Florian Fainelli , Vivien Didelot , Andrew Lunn , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Colin Foster , Roopa Prabhu , Nikolay Aleksandrov , Tobias Waldekranz , =?utf-8?q?Marek_Beh=C3=BAn?= , Ansuel Smith , DENG Qingfang , =?utf-8?q?Alvin_=C5=A0ipraga?= , Linus Walleij , Luiz Angelo Daros de Luca , Felix Fietkau , John Crispin , Sean Wang Subject: [PATCH net-next 2/9] net: dsa: introduce dsa_port_get_master() Date: Tue, 30 Aug 2022 22:59:25 +0300 Message-Id: <20220830195932.683432-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220830195932.683432-1-vladimir.oltean@nxp.com> References: <20220830195932.683432-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: BE0P281CA0005.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:a::15) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8a289791-d83e-4be0-6330-08da8ac22faa X-MS-TrafficTypeDiagnostic: VI1PR04MB6270:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5YLI25I/TVrPrmzYGsk03upnTHnbldoBsODOd5COtsg0hHHspQPT2cU/WQnqlB5uSX4itHbtDLjPOboI1YVaAToq0o6tkLmA3HEyOxr22GNpaa0FLHcKJ+LaTsg0vYGnHR+IYhbWfWkwDGaTmRjks52y4nBXDfTRICN650CVcv9OxvrVdhVIDm5XmSMTWy/5udDPRlN2Y1aBkAhAaa07+YFi80Dl9BSMc/gypfPJiCv+oTFxKs8t/Zm4ff3l5CSdOBPbZofjWoiySVwR4HdLzpsesladsy81rP3X3FcCLJLxClDBZm1/mCa6awNHQhoVuKAGeaX7J4naGBsYQVsZimbKeEfAdU5vqIHH8BcKeJ00maf4DEzkdlTZjahMKMc06+biu112PNqGK+eqChMe/RCQ4t6N9huPFrqnEH6m9YqxWBeIkIp5hgxSiCTewEqQUQmQmPHIyVUjhZnqhH/FScrsEyNXOJkzu7q4z17Pn3ba/FZT9G6RqHTTTJFORSTQRD3unwK9IWacHWkm1kjCo2qQg6tksY1AmtNbXf51zigZSGdBQWTfPHuBK3IaeqKKrBC+gTQX4/VjEcXMKCgDnZXJVdJWpM1xx+Om28u2xlbiPUx5ARi6wCOVgOzavIZ2RNfvwX/nQ+6GL5VrYoVZY9Dvtiwp+MEkvefomBi/5IrwQ6N3yrmlNPnA5NOxj3hZMQiZtnNwISB5HPbb1w8S3zaa1bzsntP+hL27KVYix+kgU/UZ1IM0pskw5H2BhnAE 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:(13230016)(4636009)(396003)(346002)(366004)(39860400002)(136003)(376002)(41300700001)(66476007)(6486002)(8676002)(4326008)(66946007)(478600001)(66556008)(52116002)(2906002)(83380400001)(44832011)(26005)(5660300002)(6506007)(6512007)(7416002)(6666004)(30864003)(8936002)(2616005)(316002)(86362001)(6916009)(54906003)(36756003)(38350700002)(1076003)(38100700002)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DOntuzKZzn++EG7f9uoEiutnUs9EW/dZ3Nmi1l++495+wUEyw//doWg4gqrrA+I8Hj2Wkdjcq/Op/MKrYkZ6CyNappMOMLC+xysJNdpVEyMIIPc9dxZ4XLq1h0zoBM1TGZjyVtIDhKn0CjKN0VigK3fcYDAvmszdoyWKjVk49JMi4X82qhL7oKb/YCggeG7ABKDMEL9YnIK1dYaLUqVa2Do3CIM9/2FXGaqPJiKdASKdG7cSOqignbGVH0yi6PZ1T1K8+0qcsVO8XK61BF0E28ockqTL3T3Gwf4QSKfntWRsuSKYd+kA9fR1PKnaZu3lQ6M1zVr1DAlHr983ntE60kPKXG3i2waoFVkJvZvygGC6Pl9xqo/cbQyGS3AEKjze74ai0HpbZ2+iv62iwTnemCj2TxTKpx8/kTfkENsYd7qDEKjz6XJhaOumFnOumpvK47szqttnEJjxmDcvfWlVM0u84m/vErH2AsKW8RiDtDMe9Y9/6xD8E1WGGOUQW1VL/iWBWUU1ebN/r1rdIKfqjWgFd0LZW+EfOpre0DL93N4LTMHV6oHwqyYolFGEZouFGeuOhiFSYheU56tfk10kswc/0Jb+IUzfTab734khqfkAxiBuKn6pTvtbj2XKws6ZatyxyKU8lOIQ/Xxic2sbuGf9WjBKcCX38QjXoR+evc07QEb4I+AMsYgFQPTxu1LvAOZsHJlayEycQ1sTKYyocMDSLLyCsdzMJS/YyieQmvk5shjnJusj0BgCSnZwcJIl3QWGMewHupO3YY1E+pWnduhTf/kfl+vbiaG0IoZs2uevqnQsigcpQoeyADqBC6ZO/kIwkIwPEUKqZFbVsxfeP66LFi3FOQpCldBGz5gclkHOmGclNon1eji51297G29cqf1bpQhUD+rvAqATuhwbdQHWYfJxZ3a+eKsbd8vkXGqBZMnoyxOP//KjQ4ECXycArgzpR0nr+b8p39dJ99ZQwtmECTof2r9GACFpDQmQqloarsEwdQ0QqqUrZ+jLyZy0dweDqSOW+LhGxRjpbTml2SvUXoCIQbPkuuJZU6y+XwFafrq7L59aCVYVWTsClyvJB50CNe4rOfmu/mYN4F+U6BVcFG3YSAuer6UDdykvpYYZ3QDxUyzlzw2XOtUL3/XnMoIVtJ8rf+tbNLHjFf9RkCHqlhOIQ55BCavmjd5hte35HmHq81s70SydkSu3TO5k8jxB1IalAVaDNZ7ZsWlZVkbWeiqngtt3hMTtKHl2Y/pkzjbf7XAShHN9ADV9BtggWBpRRHgj4JTXANp+PGpsRgmvEt9SQuJFB/HQP9TbigI9v8mh8VjEEH8xCSxD0HGja9w3/dUtP6upkBNnXvWoX864DtnHqVcFwi8v6ocFVF8if0P6vb3lvZB7BV6VUyCVRdVQqXlRmEktI6jeER35SMkwUguxEOuw2B1GOAeQ+Ocl9qeew8orxJM4ZhcKDy4H7tOUMfKiNPxCaajSYVqhoQz0Ur7LTZRmIHmIQf5PTwuaPihjnSE/Nv7GazcdGpIZt2+BpUjdSqOY1JT9XhKiIdBnMtdKpsL8E1Ydv/eEyndpIRFp12quUOt8Q/2u7+vywgPSESWrImwUIdXL+1c0yA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8a289791-d83e-4be0-6330-08da8ac22faa X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Aug 2022 19:59:45.6049 (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: e/FplQVzqFxgYYkNPbWwqlMvSWNMBqj68N6fSc0xR3FawLctuQ7a5NtGyC4TzkloLq6Y5y+dbyOGgfcMIKhqBw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6270 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org There is a desire to support for DSA masters in a LAG. That configuration is intended to work by simply enslaving the master to a bonding/team device. But the physical DSA master (the LAG slave) still has a dev->dsa_ptr, and that cpu_dp still corresponds to the physical CPU port. However, we would like to be able to retrieve the LAG that's the upper of the physical DSA master. In preparation for that, introduce a helper called dsa_port_get_master() that replaces all occurrences of the dp->cpu_dp->master pattern. The distinction between LAG and non-LAG will be made later within the helper itself. Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- drivers/net/dsa/bcm_sf2.c | 4 +-- drivers/net/dsa/bcm_sf2_cfp.c | 4 +-- drivers/net/dsa/lan9303-core.c | 4 +-- .../net/ethernet/mediatek/mtk_ppe_offload.c | 2 +- include/net/dsa.h | 5 ++++ net/dsa/dsa2.c | 8 +++--- net/dsa/dsa_priv.h | 2 +- net/dsa/port.c | 28 +++++++++---------- net/dsa/slave.c | 11 ++++---- net/dsa/tag_8021q.c | 4 +-- 10 files changed, 38 insertions(+), 34 deletions(-) diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c index 572f7450b527..6507663f35e5 100644 --- a/drivers/net/dsa/bcm_sf2.c +++ b/drivers/net/dsa/bcm_sf2.c @@ -983,7 +983,7 @@ static int bcm_sf2_sw_resume(struct dsa_switch *ds) static void bcm_sf2_sw_get_wol(struct dsa_switch *ds, int port, struct ethtool_wolinfo *wol) { - struct net_device *p = dsa_to_port(ds, port)->cpu_dp->master; + struct net_device *p = dsa_port_to_master(dsa_to_port(ds, port)); struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); struct ethtool_wolinfo pwol = { }; @@ -1007,7 +1007,7 @@ static void bcm_sf2_sw_get_wol(struct dsa_switch *ds, int port, static int bcm_sf2_sw_set_wol(struct dsa_switch *ds, int port, struct ethtool_wolinfo *wol) { - struct net_device *p = dsa_to_port(ds, port)->cpu_dp->master; + struct net_device *p = dsa_port_to_master(dsa_to_port(ds, port)); struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index; struct ethtool_wolinfo pwol = { }; diff --git a/drivers/net/dsa/bcm_sf2_cfp.c b/drivers/net/dsa/bcm_sf2_cfp.c index edbe5e7f1cb6..90636ae3db98 100644 --- a/drivers/net/dsa/bcm_sf2_cfp.c +++ b/drivers/net/dsa/bcm_sf2_cfp.c @@ -1102,7 +1102,7 @@ static int bcm_sf2_cfp_rule_get_all(struct bcm_sf2_priv *priv, int bcm_sf2_get_rxnfc(struct dsa_switch *ds, int port, struct ethtool_rxnfc *nfc, u32 *rule_locs) { - struct net_device *p = dsa_to_port(ds, port)->cpu_dp->master; + struct net_device *p = dsa_port_to_master(dsa_to_port(ds, port)); struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); int ret = 0; @@ -1145,7 +1145,7 @@ int bcm_sf2_get_rxnfc(struct dsa_switch *ds, int port, int bcm_sf2_set_rxnfc(struct dsa_switch *ds, int port, struct ethtool_rxnfc *nfc) { - struct net_device *p = dsa_to_port(ds, port)->cpu_dp->master; + struct net_device *p = dsa_port_to_master(dsa_to_port(ds, port)); struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); int ret = 0; diff --git a/drivers/net/dsa/lan9303-core.c b/drivers/net/dsa/lan9303-core.c index e03ff1f267bb..181e082b0919 100644 --- a/drivers/net/dsa/lan9303-core.c +++ b/drivers/net/dsa/lan9303-core.c @@ -1090,7 +1090,7 @@ static int lan9303_port_enable(struct dsa_switch *ds, int port, if (!dsa_port_is_user(dp)) return 0; - vlan_vid_add(dp->cpu_dp->master, htons(ETH_P_8021Q), port); + vlan_vid_add(dsa_port_to_master(dp), htons(ETH_P_8021Q), port); return lan9303_enable_processing_port(chip, port); } @@ -1103,7 +1103,7 @@ static void lan9303_port_disable(struct dsa_switch *ds, int port) if (!dsa_port_is_user(dp)) return; - vlan_vid_del(dp->cpu_dp->master, htons(ETH_P_8021Q), port); + vlan_vid_del(dsa_port_to_master(dp), htons(ETH_P_8021Q), port); lan9303_disable_processing_port(chip, port); lan9303_phy_write(ds, chip->phy_addr_base + port, MII_BMCR, BMCR_PDOWN); diff --git a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c index 25dc3c3aa31d..5a1fc4bcd7a5 100644 --- a/drivers/net/ethernet/mediatek/mtk_ppe_offload.c +++ b/drivers/net/ethernet/mediatek/mtk_ppe_offload.c @@ -173,7 +173,7 @@ mtk_flow_get_dsa_port(struct net_device **dev) if (dp->cpu_dp->tag_ops->proto != DSA_TAG_PROTO_MTK) return -ENODEV; - *dev = dp->cpu_dp->master; + *dev = dsa_port_to_master(dp); return dp->index; #else diff --git a/include/net/dsa.h b/include/net/dsa.h index f2ce12860546..23eac1bda843 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -718,6 +718,11 @@ static inline bool dsa_port_offloads_lag(struct dsa_port *dp, return dsa_port_lag_dev_get(dp) == lag->dev; } +static inline struct net_device *dsa_port_to_master(const struct dsa_port *dp) +{ + return dp->cpu_dp->master; +} + static inline struct net_device *dsa_port_to_bridge_port(const struct dsa_port *dp) { diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index ed56c7a554b8..f1f96e2e56aa 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -1263,11 +1263,11 @@ int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst, * attempts to change the tagging protocol. If we ever lift the IFF_UP * restriction, there needs to be another mutex which serializes this. */ - list_for_each_entry(dp, &dst->ports, list) { - if (dsa_port_is_cpu(dp) && (dp->master->flags & IFF_UP)) + dsa_tree_for_each_user_port(dp, dst) { + if (dsa_port_to_master(dp)->flags & IFF_UP) goto out_unlock; - if (dsa_port_is_user(dp) && (dp->slave->flags & IFF_UP)) + if (dp->slave->flags & IFF_UP) goto out_unlock; } @@ -1797,7 +1797,7 @@ void dsa_switch_shutdown(struct dsa_switch *ds) rtnl_lock(); dsa_switch_for_each_user_port(dp, ds) { - master = dp->cpu_dp->master; + master = dsa_port_to_master(dp); slave_dev = dp->slave; netdev_upper_dev_unlink(master, slave_dev); diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index 614fbba8fe39..c48c5c8ba790 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -322,7 +322,7 @@ dsa_slave_to_master(const struct net_device *dev) { struct dsa_port *dp = dsa_slave_to_port(dev); - return dp->cpu_dp->master; + return dsa_port_to_master(dp); } /* If under a bridge with vlan_filtering=0, make sure to send pvid-tagged diff --git a/net/dsa/port.c b/net/dsa/port.c index 7afc35db0c29..4183e60db4f9 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -1026,7 +1026,7 @@ int dsa_port_standalone_host_fdb_add(struct dsa_port *dp, int dsa_port_bridge_host_fdb_add(struct dsa_port *dp, const unsigned char *addr, u16 vid) { - struct dsa_port *cpu_dp = dp->cpu_dp; + struct net_device *master = dsa_port_to_master(dp); struct dsa_db db = { .type = DSA_DB_BRIDGE, .bridge = *dp->bridge, @@ -1037,8 +1037,8 @@ int dsa_port_bridge_host_fdb_add(struct dsa_port *dp, * requires rtnl_lock(), since we can't guarantee that is held here, * and we can't take it either. */ - if (cpu_dp->master->priv_flags & IFF_UNICAST_FLT) { - err = dev_uc_add(cpu_dp->master, addr); + if (master->priv_flags & IFF_UNICAST_FLT) { + err = dev_uc_add(master, addr); if (err) return err; } @@ -1077,15 +1077,15 @@ int dsa_port_standalone_host_fdb_del(struct dsa_port *dp, int dsa_port_bridge_host_fdb_del(struct dsa_port *dp, const unsigned char *addr, u16 vid) { - struct dsa_port *cpu_dp = dp->cpu_dp; + struct net_device *master = dsa_port_to_master(dp); struct dsa_db db = { .type = DSA_DB_BRIDGE, .bridge = *dp->bridge, }; int err; - if (cpu_dp->master->priv_flags & IFF_UNICAST_FLT) { - err = dev_uc_del(cpu_dp->master, addr); + if (master->priv_flags & IFF_UNICAST_FLT) { + err = dev_uc_del(master, addr); if (err) return err; } @@ -1208,14 +1208,14 @@ int dsa_port_standalone_host_mdb_add(const struct dsa_port *dp, int dsa_port_bridge_host_mdb_add(const struct dsa_port *dp, const struct switchdev_obj_port_mdb *mdb) { - struct dsa_port *cpu_dp = dp->cpu_dp; + struct net_device *master = dsa_port_to_master(dp); struct dsa_db db = { .type = DSA_DB_BRIDGE, .bridge = *dp->bridge, }; int err; - err = dev_mc_add(cpu_dp->master, mdb->addr); + err = dev_mc_add(master, mdb->addr); if (err) return err; @@ -1252,14 +1252,14 @@ int dsa_port_standalone_host_mdb_del(const struct dsa_port *dp, int dsa_port_bridge_host_mdb_del(const struct dsa_port *dp, const struct switchdev_obj_port_mdb *mdb) { - struct dsa_port *cpu_dp = dp->cpu_dp; + struct net_device *master = dsa_port_to_master(dp); struct dsa_db db = { .type = DSA_DB_BRIDGE, .bridge = *dp->bridge, }; int err; - err = dev_mc_del(cpu_dp->master, mdb->addr); + err = dev_mc_del(master, mdb->addr); if (err) return err; @@ -1294,19 +1294,19 @@ int dsa_port_host_vlan_add(struct dsa_port *dp, const struct switchdev_obj_port_vlan *vlan, struct netlink_ext_ack *extack) { + struct net_device *master = dsa_port_to_master(dp); struct dsa_notifier_vlan_info info = { .dp = dp, .vlan = vlan, .extack = extack, }; - struct dsa_port *cpu_dp = dp->cpu_dp; int err; err = dsa_port_notify(dp, DSA_NOTIFIER_HOST_VLAN_ADD, &info); if (err && err != -EOPNOTSUPP) return err; - vlan_vid_add(cpu_dp->master, htons(ETH_P_8021Q), vlan->vid); + vlan_vid_add(master, htons(ETH_P_8021Q), vlan->vid); return err; } @@ -1314,18 +1314,18 @@ int dsa_port_host_vlan_add(struct dsa_port *dp, int dsa_port_host_vlan_del(struct dsa_port *dp, const struct switchdev_obj_port_vlan *vlan) { + struct net_device *master = dsa_port_to_master(dp); struct dsa_notifier_vlan_info info = { .dp = dp, .vlan = vlan, }; - struct dsa_port *cpu_dp = dp->cpu_dp; int err; err = dsa_port_notify(dp, DSA_NOTIFIER_HOST_VLAN_DEL, &info); if (err && err != -EOPNOTSUPP) return err; - vlan_vid_del(cpu_dp->master, htons(ETH_P_8021Q), vlan->vid); + vlan_vid_del(master, htons(ETH_P_8021Q), vlan->vid); return err; } diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 345106b1ed78..55094b94a5ae 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -1503,8 +1503,7 @@ static int dsa_slave_setup_tc_block(struct net_device *dev, static int dsa_slave_setup_ft_block(struct dsa_switch *ds, int port, void *type_data) { - struct dsa_port *cpu_dp = dsa_to_port(ds, port)->cpu_dp; - struct net_device *master = cpu_dp->master; + struct net_device *master = dsa_port_to_master(dsa_to_port(ds, port)); if (!master->netdev_ops->ndo_setup_tc) return -EOPNOTSUPP; @@ -2147,13 +2146,14 @@ static int dsa_slave_fill_forward_path(struct net_device_path_ctx *ctx, struct net_device_path *path) { struct dsa_port *dp = dsa_slave_to_port(ctx->dev); + struct net_device *master = dsa_port_to_master(dp); struct dsa_port *cpu_dp = dp->cpu_dp; path->dev = ctx->dev; path->type = DEV_PATH_DSA; path->dsa.proto = cpu_dp->tag_ops->proto; path->dsa.port = dp->index; - ctx->dev = cpu_dp->master; + ctx->dev = master; return 0; } @@ -2271,9 +2271,9 @@ static int dsa_slave_phy_setup(struct net_device *slave_dev) void dsa_slave_setup_tagger(struct net_device *slave) { struct dsa_port *dp = dsa_slave_to_port(slave); + struct net_device *master = dsa_port_to_master(dp); struct dsa_slave_priv *p = netdev_priv(slave); const struct dsa_port *cpu_dp = dp->cpu_dp; - struct net_device *master = cpu_dp->master; const struct dsa_switch *ds = dp->ds; slave->needed_headroom = cpu_dp->tag_ops->needed_headroom; @@ -2330,8 +2330,7 @@ int dsa_slave_resume(struct net_device *slave_dev) int dsa_slave_create(struct dsa_port *port) { - const struct dsa_port *cpu_dp = port->cpu_dp; - struct net_device *master = cpu_dp->master; + struct net_device *master = dsa_port_to_master(port); struct dsa_switch *ds = port->ds; const char *name = port->name; struct net_device *slave_dev; diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index b5f80bc45ceb..34e5ec5d3e23 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -330,7 +330,7 @@ static int dsa_tag_8021q_port_setup(struct dsa_switch *ds, int port) if (!dsa_port_is_user(dp)) return 0; - master = dp->cpu_dp->master; + master = dsa_port_to_master(dp); err = dsa_port_tag_8021q_vlan_add(dp, vid, false); if (err) { @@ -359,7 +359,7 @@ static void dsa_tag_8021q_port_teardown(struct dsa_switch *ds, int port) if (!dsa_port_is_user(dp)) return; - master = dp->cpu_dp->master; + master = dsa_port_to_master(dp); dsa_port_tag_8021q_vlan_del(dp, vid, false); From patchwork Tue Aug 30 19:59:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12959833 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89AB3ECAAA1 for ; Tue, 30 Aug 2022 20:00:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231549AbiH3UAz (ORCPT ); Tue, 30 Aug 2022 16:00:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231823AbiH3UAa (ORCPT ); Tue, 30 Aug 2022 16:00:30 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2054.outbound.protection.outlook.com [40.107.20.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC88213E8C; Tue, 30 Aug 2022 13:00:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JzRAQlmPHhthDQuarzQVUngj/r8xobmIZsdAFuTKEFu53fovqZJAZBXg3fsFROIRjvFr35nLKbE5Ok8JSTSCCqItLv3PRjpGPiCGAz0WbsgdxW8BxWdGeZ+tuqgDd416f4E9r/hJ9w/TFrUCfIvE5mq4rVqmGHk7MCrr2mJi1gZzqWreOZFCVeu8c438TMntVyE6jyHQ3JpYHxJXkk+dWv++4Mgz01TNnBeHgY/PIOzq916Cm0M8uCe4URBTabhTITNsnhDI759RL2iUNg8/vk9fly+ctKtKkDqN/u7hqie3S2gKq4ex1QcnV1646mXyHy+z8ZpriVxjbVGIfU7N0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=BIKCDrvT3nFEJBtM0/JqYnn0giDd9MJz6FGAWH0SjoY=; b=EajIEEZw4UKgeszcacszPTGlq5j1e8VhJfBcc5DkUfUVOhxB0G7VQssHDjRjALe7QyvW+o9wJRldxmJBMLqReV4x8+sWCfMg3ExhSXIhyJQeUVyw7GAPxRAaUBKBmYmJiSAOYRTjceLtIBDiXEo6uLtTlhbA5gJ13gGfjxK9Dam7R788wEXb+s3x+mFvvn4LEJg27/LX3nOdvUdO7NQzrrX2frG/Tv+6c2bbQ24XvCx/VaWat0u37pmEft50QdtMvFoyU2eGjx8lpN6wuQaRaolXwNB7wU8wLsr3gB30gBrQXuj3TOFgDxScXzNuOUmBuEqzIpszzHG8NAHYeZO8mg== 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=BIKCDrvT3nFEJBtM0/JqYnn0giDd9MJz6FGAWH0SjoY=; b=rcyyNe/htSe7rrmX57NcwOFT5HzdA4b4A8BZJ3ICeRmkvrpk9nLf/GFOg2/rbwPOxnp7X4u7DSSCg3bLZcebLz5TCqKibWmT8mKo4wLj1I966o18rpbIizHvo20TBRFYItYA9HjBoR7ta6MhMdPQsexG2DWhVVnPR8PrRqoZqT4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6270.eurprd04.prod.outlook.com (2603:10a6:803:fb::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.21; Tue, 30 Aug 2022 19:59:47 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3412:9d57:ec73:fef3]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3412:9d57:ec73:fef3%5]) with mapi id 15.20.5588.010; Tue, 30 Aug 2022 19:59:47 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Florian Fainelli , Vivien Didelot , Andrew Lunn , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Colin Foster , Roopa Prabhu , Nikolay Aleksandrov , Tobias Waldekranz , =?utf-8?q?Marek_Beh=C3=BAn?= , Ansuel Smith , DENG Qingfang , =?utf-8?q?Alvin_=C5=A0ipraga?= , Linus Walleij , Luiz Angelo Daros de Luca , Felix Fietkau , John Crispin , Sean Wang Subject: [PATCH net-next 3/9] net: dsa: allow the DSA master to be seen and changed through rtnetlink Date: Tue, 30 Aug 2022 22:59:26 +0300 Message-Id: <20220830195932.683432-4-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220830195932.683432-1-vladimir.oltean@nxp.com> References: <20220830195932.683432-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: BE0P281CA0005.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:a::15) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: caca9032-5e2c-4773-dc64-08da8ac230ab X-MS-TrafficTypeDiagnostic: VI1PR04MB6270:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Fjlp9JadD5M3Ge5OSPOAkV/T3GK6yrznGQalou2qkQ5y9B+skOjl/IrGTzn3dDHF+07Ujad9erP//e61dsEtxc7s9fmYsLT+fe53whUdgXlrSCrXCjg/Tzba7LVaqtdo8eFVvwieUFpM4O1c87xJoSFc/7pijyJy0NpEtz02FuTs9Z4dArd/ZO0EtD2I9UUSW/NUkC0GY7xqEVHPg8K0/nH2/E8Vk98wlUBuQ1iUujFGJlc6a6YYh0Jv1A6BD1EUbGGgyAOnVpl8CDX3YbzkeofW1N7JtxWyYx1FDNs5p69/8SIwVYfGQRKcIRXpX+jCjAy0YbCrDt4OvspH9WTNvV23Q9BxwVlFZobNtz7hS/Gcc8habHUlJlqHq945c3fwZEkdQ6+6gn68vNozNIO8uRGUcllYgxAArzqe1e+LHPtZxuQiZ1kYK1D5pmdGUn1iHr7I1F7qJPnRTdmaZjxRVtjpGTXiYZlY8yWSeVQdTJVrrPDUA5/K5L0uuI2E2u/iiOFbZI/Fkk8YHSyhMloAqIW/tf5yne0nGHY3P4Lt0VamxwpW+52DNIunr9X4vSkV/5AZCpQC1MwSeytQgeVQh+13rGgevLbazF/rdvAfJDF3wwCSWu42G3ZQLH1m2dFOVO4bJzw0tS/OMx9Jy3HARy9yomTIcY72nUZv6hzmKkVYhQ+6AkFlhRFfhBzm/uiLBk6N2BUs7fRgkgMNCJP8itNzvT1qvF7CZcqjx5Mm6iN6NANPTMlzxYTfCmg80yt3 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:(13230016)(4636009)(396003)(346002)(366004)(39860400002)(136003)(376002)(41300700001)(66476007)(6486002)(8676002)(4326008)(66946007)(478600001)(66556008)(52116002)(2906002)(83380400001)(44832011)(26005)(5660300002)(6506007)(6512007)(7416002)(6666004)(30864003)(8936002)(2616005)(316002)(86362001)(6916009)(54906003)(36756003)(38350700002)(1076003)(38100700002)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ceLXvEVSqn6DJv9bkzVMzD/6WAK/XyJZN4Z2e80O7t74YaNreCSIiZnLyZZATGPYN72sbnbzgGyVHd7TPDAiMyWCokU45FGjlML5rGF2jvMm8rf7c8zDTNk3JhXlLp+7wGGsU7lZNyA1kvXdCX+58zmLmw7tlNzLXzeNtyR0qqd9gY2KMGGUy6XFTvrhlVm6JRCGdUmyKqQI8gWeiPBq9ZDIHgFo4L4J5Wys1fPCCZpGfODbwsK1DUuCpVNEzUMk8S6ry8MvQEwYdRJPp9a8yFqvwBxDHhjmnGzBXpTYgyXDTUO4CQb9gQwTR9217p+2HDt/rl/soRJNoDUmVBTqUPrmsO85ScaBHhEeekXWzN0/MWy3vGRv5TZazvfG9zhf1HR/VEpxnhKVoJoHnxL5gsOmVk57lKdrwP2eOpaYGCLuuJR7CCTt+0OGetMqfVYl0FkcqwL3HwSIS10tokn0GWeVLdOyMpVFLxgCCO9tuUv8t+jBAj4b19UDYALARawPf36sPHbKpdBYi2+F6Qzsn3gwVcmFvSd1W/G9zb3GJKUir0LnC/WnaO/ut+k+Znekpku9Z0KIHmNsJXqLutp6PsLrcS8TVjgJjAD+DGV2ksHoDxo4ULPuVLxIo3qTdmD3xj4+2vaPozVokrXIsRG30gOlZ2tzr8bIg35l++i4LUdOjSyfXu4IKZGIpdsMDjPikVs7WHzZ6i+2xRPNbu1MZy/fReNLJo5WgckX+DW7CI1Z3vM/05p0nhDrRAJP+LIbfzJ60NdWQULYQpqyqhzId1jZzba4xvmbBb03aN7xo0+IKBQgcuJRMznmL4ywCjGNz6QDRO6gk0WbWETZ8oil0NPMq1fuS6RQJ0Qeecnb0QF4YV5dEy8gK+w3gXUA8HItGF+AP6RgPN1rlTmA3HD0esMVI32vCdQvb1punX6R7XwZc6AoWco6yHQ2zmJ6DQdBLxs70IpAqyQPzeAUX53eJW9vYzi1KSiFQtpb8GmniYGAdZlD8tgahCr+DvZwwkAWMwTWDXbZmurxm0tWx0hqsiaRmPHrsHoPv58guCYMqh9oS+aXCzucXBDwiRLL3xmvpJBDstAWbKpijiNO7Bv0jVUKF65v+6cMlPDFTCSdIIvnWkT1ezTLd6/ikC7bw9EbJDXpFw3YpY9R7aYzNtzPSIV581h6kDIPsypkf1Zhkn82S6PoW4Y0vvR2DT/f0FGTh3G/FO/7uHNwtAPHhbrahUaEbm2iUMkIkx7e8MVLLXlf/b9A76KJo/u2GrXlS7k3TMdm08jXL/ik6qKcye/+gO/8EMT043o+TZRHqcD5DSAcldk+uS4DP2HNgKyVwy50IFuizG8rdgZASA+cT0QjEbrczQFlVdR95jLYevBwmzilShxh1T/ayXkxlwH9slCy0xAciCngedVSZQVn37T6Tcu9XZi/Ou6d2fOJlqyo2c4B76r67zN8zYqJZoqYT1TkUhDdW8eoZ/yQcJcaHaNcNUEQryL3c4loN09aVUl5kcQj2zvup9/IreczZjg7Es/pjG8isy/1bzgqImvoabTaWrpGmlswB9CD4IhJ5yJf3b1NoxH+vOdqbWBifi94AcI4s3jGHsl2g3Nfxa7EBVnjRg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: caca9032-5e2c-4773-dc64-08da8ac230ab X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Aug 2022 19:59:47.3548 (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: /RS3Fw9gZIhtnsyIleAY1FCLzzmM1zEKcHxx/qjT7i5RTAFc0PJ2Oy0B/6Ja3Yzjj5WChMjR+cfiZfh/jU8tJg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6270 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Some DSA switches have multiple CPU ports, which can be used to improve CPU termination throughput, but DSA, through dsa_tree_setup_cpu_ports(), sets up only the first one, leading to suboptimal use of hardware. The desire is to not change the default configuration but to permit the user to create a dynamic mapping between individual user ports and the CPU port that they are served by, configurable through rtnetlink. It is also intended to permit load balancing between CPU ports, and in that case, the foreseen model is for the DSA master to be a bonding interface whose lowers are the physical DSA masters. To that end, we create a struct rtnl_link_ops for DSA user ports with the "dsa" kind. We expose the IFLA_DSA_MASTER link attribute that contains the ifindex of the newly desired DSA master. Signed-off-by: Vladimir Oltean --- include/net/dsa.h | 8 +++ include/uapi/linux/if_link.h | 10 +++ net/dsa/Makefile | 10 ++- net/dsa/dsa.c | 9 +++ net/dsa/dsa2.c | 14 ++++ net/dsa/dsa_priv.h | 10 +++ net/dsa/netlink.c | 62 +++++++++++++++++ net/dsa/port.c | 131 +++++++++++++++++++++++++++++++++++ net/dsa/slave.c | 120 ++++++++++++++++++++++++++++++++ 9 files changed, 373 insertions(+), 1 deletion(-) create mode 100644 net/dsa/netlink.c diff --git a/include/net/dsa.h b/include/net/dsa.h index 23eac1bda843..3f717c3fcba0 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -559,6 +559,10 @@ static inline bool dsa_is_user_port(struct dsa_switch *ds, int p) list_for_each_entry((_dp), &(_dst)->ports, list) \ if (dsa_port_is_user((_dp))) +#define dsa_tree_for_each_user_port_continue_reverse(_dp, _dst) \ + list_for_each_entry_continue_reverse((_dp), &(_dst)->ports, list) \ + if (dsa_port_is_user((_dp))) + #define dsa_tree_for_each_cpu_port(_dp, _dst) \ list_for_each_entry((_dp), &(_dst)->ports, list) \ if (dsa_port_is_cpu((_dp))) @@ -830,6 +834,10 @@ struct dsa_switch_ops { int (*connect_tag_protocol)(struct dsa_switch *ds, enum dsa_tag_protocol proto); + int (*port_change_master)(struct dsa_switch *ds, int port, + struct net_device *master, + struct netlink_ext_ack *extack); + /* Optional switch-wide initialization and destruction methods */ int (*setup)(struct dsa_switch *ds); void (*teardown)(struct dsa_switch *ds); diff --git a/include/uapi/linux/if_link.h b/include/uapi/linux/if_link.h index e36d9d2c65a7..f032414990bc 100644 --- a/include/uapi/linux/if_link.h +++ b/include/uapi/linux/if_link.h @@ -1374,4 +1374,14 @@ enum { #define IFLA_MCTP_MAX (__IFLA_MCTP_MAX - 1) +/* DSA section */ + +enum { + IFLA_DSA_UNSPEC, + IFLA_DSA_MASTER, + __IFLA_DSA_MAX, +}; + +#define IFLA_DSA_MAX (__IFLA_DSA_MAX - 1) + #endif /* _UAPI_LINUX_IF_LINK_H */ diff --git a/net/dsa/Makefile b/net/dsa/Makefile index af28c24ead18..bf57ef3bce2a 100644 --- a/net/dsa/Makefile +++ b/net/dsa/Makefile @@ -1,7 +1,15 @@ # SPDX-License-Identifier: GPL-2.0 # the core obj-$(CONFIG_NET_DSA) += dsa_core.o -dsa_core-y += dsa.o dsa2.o master.o port.o slave.o switch.o tag_8021q.o +dsa_core-y += \ + dsa.o \ + dsa2.o \ + master.o \ + netlink.o \ + port.o \ + slave.o \ + switch.o \ + tag_8021q.o # tagging formats obj-$(CONFIG_NET_DSA_TAG_AR9331) += tag_ar9331.o diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index be7b320cda76..64b14f655b23 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -536,8 +536,16 @@ static int __init dsa_init_module(void) dsa_tag_driver_register(&DSA_TAG_DRIVER_NAME(none_ops), THIS_MODULE); + rc = rtnl_link_register(&dsa_link_ops); + if (rc) + goto netlink_register_fail; + return 0; +netlink_register_fail: + dsa_tag_driver_unregister(&DSA_TAG_DRIVER_NAME(none_ops)); + dsa_slave_unregister_notifier(); + dev_remove_pack(&dsa_pack_type); register_notifier_fail: destroy_workqueue(dsa_owq); @@ -547,6 +555,7 @@ module_init(dsa_init_module); static void __exit dsa_cleanup_module(void) { + rtnl_link_unregister(&dsa_link_ops); dsa_tag_driver_unregister(&DSA_TAG_DRIVER_NAME(none_ops)); dsa_slave_unregister_notifier(); diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index f1f96e2e56aa..42422ddea59b 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -387,6 +387,20 @@ static struct dsa_port *dsa_tree_find_first_cpu(struct dsa_switch_tree *dst) return NULL; } +struct net_device *dsa_tree_find_first_master(struct dsa_switch_tree *dst) +{ + struct device_node *ethernet; + struct net_device *master; + struct dsa_port *cpu_dp; + + cpu_dp = dsa_tree_find_first_cpu(dst); + ethernet = of_parse_phandle(cpu_dp->dn, "ethernet", 0); + master = of_find_net_device_by_node(ethernet); + of_node_put(ethernet); + + return master; +} + /* Assign the default CPU port (the first one in the tree) to all ports of the * fabric which don't already have one as part of their own switch. */ diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index c48c5c8ba790..d252a04ed725 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -200,6 +200,9 @@ static inline struct net_device *dsa_master_find_slave(struct net_device *dev, return NULL; } +/* netlink.c */ +extern struct rtnl_link_ops dsa_link_ops __read_mostly; + /* port.c */ void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp, const struct dsa_device_ops *tag_ops); @@ -292,6 +295,8 @@ void dsa_port_hsr_leave(struct dsa_port *dp, struct net_device *hsr); int dsa_port_tag_8021q_vlan_add(struct dsa_port *dp, u16 vid, bool broadcast); void dsa_port_tag_8021q_vlan_del(struct dsa_port *dp, u16 vid, bool broadcast); void dsa_port_set_host_flood(struct dsa_port *dp, bool uc, bool mc); +int dsa_port_change_master(struct dsa_port *dp, struct net_device *master, + struct netlink_ext_ack *extack); /* slave.c */ extern const struct dsa_device_ops notag_netdev_ops; @@ -305,8 +310,12 @@ int dsa_slave_suspend(struct net_device *slave_dev); int dsa_slave_resume(struct net_device *slave_dev); int dsa_slave_register_notifier(void); void dsa_slave_unregister_notifier(void); +void dsa_slave_sync_ha(struct net_device *dev); +void dsa_slave_unsync_ha(struct net_device *dev); void dsa_slave_setup_tagger(struct net_device *slave); int dsa_slave_change_mtu(struct net_device *dev, int new_mtu); +int dsa_slave_change_master(struct net_device *dev, struct net_device *master, + struct netlink_ext_ack *extack); int dsa_slave_manage_vlan_filtering(struct net_device *dev, bool vlan_filtering); @@ -542,6 +551,7 @@ void dsa_lag_map(struct dsa_switch_tree *dst, struct dsa_lag *lag); void dsa_lag_unmap(struct dsa_switch_tree *dst, struct dsa_lag *lag); struct dsa_lag *dsa_tree_lag_find(struct dsa_switch_tree *dst, const struct net_device *lag_dev); +struct net_device *dsa_tree_find_first_master(struct dsa_switch_tree *dst); int dsa_tree_notify(struct dsa_switch_tree *dst, unsigned long e, void *v); int dsa_broadcast(unsigned long e, void *v); int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst, diff --git a/net/dsa/netlink.c b/net/dsa/netlink.c new file mode 100644 index 000000000000..0f43bbb94769 --- /dev/null +++ b/net/dsa/netlink.c @@ -0,0 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0 +/* Copyright 2022 NXP + */ +#include +#include + +#include "dsa_priv.h" + +static const struct nla_policy dsa_policy[IFLA_DSA_MAX + 1] = { + [IFLA_DSA_MASTER] = { .type = NLA_U32 }, +}; + +static int dsa_changelink(struct net_device *dev, struct nlattr *tb[], + struct nlattr *data[], + struct netlink_ext_ack *extack) +{ + int err; + + if (!data) + return 0; + + if (data[IFLA_DSA_MASTER]) { + u32 ifindex = nla_get_u32(data[IFLA_DSA_MASTER]); + struct net_device *master; + + master = __dev_get_by_index(dev_net(dev), ifindex); + if (!master) + return -EINVAL; + + err = dsa_slave_change_master(dev, master, extack); + if (err) + return err; + } + + return 0; +} + +static size_t dsa_get_size(const struct net_device *dev) +{ + return nla_total_size(sizeof(u32)) + /* IFLA_DSA_MASTER */ + 0; +} + +static int dsa_fill_info(struct sk_buff *skb, const struct net_device *dev) +{ + struct net_device *master = dsa_slave_to_master(dev); + + if (nla_put_u32(skb, IFLA_DSA_MASTER, master->ifindex)) + return -EMSGSIZE; + + return 0; +} + +struct rtnl_link_ops dsa_link_ops __read_mostly = { + .kind = "dsa", + .priv_size = sizeof(struct dsa_port), + .maxtype = IFLA_DSA_MAX, + .policy = dsa_policy, + .changelink = dsa_changelink, + .get_size = dsa_get_size, + .fill_info = dsa_fill_info, +}; diff --git a/net/dsa/port.c b/net/dsa/port.c index 4183e60db4f9..b719763fe97d 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -7,6 +7,7 @@ */ #include +#include #include #include #include @@ -1374,6 +1375,136 @@ int dsa_port_mrp_del_ring_role(const struct dsa_port *dp, return ds->ops->port_mrp_del_ring_role(ds, dp->index, mrp); } +static int dsa_port_assign_master(struct dsa_port *dp, + struct net_device *master, + struct netlink_ext_ack *extack, + bool fail_on_err) +{ + struct dsa_switch *ds = dp->ds; + int port = dp->index, err; + + err = ds->ops->port_change_master(ds, port, master, extack); + if (err && !fail_on_err) + dev_err(ds->dev, "port %d failed to assign master %s: %pe\n", + port, master->name, ERR_PTR(err)); + + if (err && fail_on_err) + return err; + + dp->cpu_dp = master->dsa_ptr; + + return 0; +} + +/* Change the dp->cpu_dp affinity for a user port. Note that both cross-chip + * notifiers and drivers have implicit assumptions about user-to-CPU-port + * mappings, so we unfortunately cannot delay the deletion of the objects + * (switchdev, standalone addresses, standalone VLANs) on the old CPU port + * until the new CPU port has been set up. So we need to completely tear down + * the old CPU port before changing it, and restore it on errors during the + * bringup of the new one. + */ +int dsa_port_change_master(struct dsa_port *dp, struct net_device *master, + struct netlink_ext_ack *extack) +{ + struct net_device *bridge_dev = dsa_port_bridge_dev_get(dp); + struct net_device *old_master = dsa_port_to_master(dp); + struct net_device *dev = dp->slave; + struct dsa_switch *ds = dp->ds; + int port = dp->index; + bool vlan_filtering; + int err, tmp; + + /* Bridges may hold host FDB, MDB and VLAN objects. These need to be + * migrated, so dynamically unoffload and later reoffload the bridge + * port. + */ + if (bridge_dev) { + dsa_port_pre_bridge_leave(dp, bridge_dev); + dsa_port_bridge_leave(dp, bridge_dev); + } + + /* The port might still be VLAN filtering even if it's no longer + * under a bridge, either due to ds->vlan_filtering_is_global or + * ds->needs_standalone_vlan_filtering. In turn this means VLANs + * on the CPU port. + */ + vlan_filtering = dsa_port_is_vlan_filtering(dp); + if (vlan_filtering) { + err = dsa_slave_manage_vlan_filtering(dev, false); + if (err) { + NL_SET_ERR_MSG_MOD(extack, + "Failed to remove standalone VLANs"); + goto rewind_old_bridge; + } + } + + /* Standalone addresses, and addresses of upper interfaces like + * VLAN, LAG, HSR need to be migrated. + */ + dsa_slave_unsync_ha(dev); + + err = dsa_port_assign_master(dp, master, extack, true); + if (err) + goto rewind_old_addrs; + + dsa_slave_sync_ha(dev); + + if (vlan_filtering) { + err = dsa_slave_manage_vlan_filtering(dev, true); + if (err) { + NL_SET_ERR_MSG_MOD(extack, + "Failed to restore standalone VLANs"); + goto rewind_new_addrs; + } + } + + if (bridge_dev) { + err = dsa_port_bridge_join(dp, bridge_dev, extack); + if (err && err == -EOPNOTSUPP) { + NL_SET_ERR_MSG_MOD(extack, + "Failed to reoffload bridge"); + goto rewind_new_vlan; + } + } + + return 0; + +rewind_new_vlan: + if (vlan_filtering) + dsa_slave_manage_vlan_filtering(dev, false); + +rewind_new_addrs: + dsa_slave_unsync_ha(dev); + + dsa_port_assign_master(dp, old_master, NULL, false); + +/* Restore the objects on the old CPU port */ +rewind_old_addrs: + dsa_slave_sync_ha(dev); + + if (vlan_filtering) { + tmp = dsa_slave_manage_vlan_filtering(dev, true); + if (tmp) { + dev_err(ds->dev, + "port %d failed to restore standalone VLANs: %pe\n", + dp->index, ERR_PTR(tmp)); + } + } + +rewind_old_bridge: + if (bridge_dev) { + tmp = dsa_port_bridge_join(dp, bridge_dev, extack); + if (tmp) { + dev_err(ds->dev, + "port %d failed to rejoin bridge %s: %pe\n", + dp->index, bridge_dev->name, ERR_PTR(tmp)); + } + } + + return err; +} + void dsa_port_set_tag_protocol(struct dsa_port *cpu_dp, const struct dsa_device_ops *tag_ops) { diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 55094b94a5ae..00df6cf07866 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -164,6 +164,48 @@ static int dsa_slave_unsync_mc(struct net_device *dev, return dsa_slave_schedule_standalone_work(dev, DSA_MC_DEL, addr, 0); } +void dsa_slave_sync_ha(struct net_device *dev) +{ + struct dsa_port *dp = dsa_slave_to_port(dev); + struct dsa_switch *ds = dp->ds; + struct netdev_hw_addr *ha; + + netif_addr_lock_bh(dev); + + netdev_for_each_synced_mc_addr(ha, dev) + dsa_slave_sync_mc(dev, ha->addr); + + netdev_for_each_synced_uc_addr(ha, dev) + dsa_slave_sync_uc(dev, ha->addr); + + netif_addr_unlock_bh(dev); + + if (dsa_switch_supports_uc_filtering(ds) || + dsa_switch_supports_mc_filtering(ds)) + dsa_flush_workqueue(); +} + +void dsa_slave_unsync_ha(struct net_device *dev) +{ + struct dsa_port *dp = dsa_slave_to_port(dev); + struct dsa_switch *ds = dp->ds; + struct netdev_hw_addr *ha; + + netif_addr_lock_bh(dev); + + netdev_for_each_synced_uc_addr(ha, dev) + dsa_slave_unsync_uc(dev, ha->addr); + + netdev_for_each_synced_mc_addr(ha, dev) + dsa_slave_unsync_mc(dev, ha->addr); + + netif_addr_unlock_bh(dev); + + if (dsa_switch_supports_uc_filtering(ds) || + dsa_switch_supports_mc_filtering(ds)) + dsa_flush_workqueue(); +} + /* slave mii_bus handling ***************************************************/ static int dsa_slave_phy_read(struct mii_bus *bus, int addr, int reg) { @@ -2346,6 +2388,7 @@ int dsa_slave_create(struct dsa_port *port) if (slave_dev == NULL) return -ENOMEM; + slave_dev->rtnl_link_ops = &dsa_link_ops; slave_dev->ethtool_ops = &dsa_slave_ethtool_ops; #if IS_ENABLED(CONFIG_DCB) slave_dev->dcbnl_ops = &dsa_slave_dcbnl_ops; @@ -2462,6 +2505,83 @@ void dsa_slave_destroy(struct net_device *slave_dev) free_netdev(slave_dev); } +int dsa_slave_change_master(struct net_device *dev, struct net_device *master, + struct netlink_ext_ack *extack) +{ + struct net_device *old_master = dsa_slave_to_master(dev); + struct dsa_port *dp = dsa_slave_to_port(dev); + struct dsa_switch *ds = dp->ds; + struct net_device *upper; + struct list_head *iter; + int err; + + if (master == old_master) + return 0; + + if (!ds->ops->port_change_master) { + NL_SET_ERR_MSG_MOD(extack, + "Driver does not support changing DSA master"); + return -EOPNOTSUPP; + } + + if (!netdev_uses_dsa(master)) { + NL_SET_ERR_MSG_MOD(extack, + "Interface not eligible as DSA master"); + return -EOPNOTSUPP; + } + + netdev_for_each_upper_dev_rcu(master, upper, iter) { + if (dsa_slave_dev_check(upper)) + continue; + if (netif_is_bridge_master(upper)) + continue; + NL_SET_ERR_MSG_MOD(extack, "Cannot join master with unknown uppers"); + return -EOPNOTSUPP; + } + + /* Since we allow live-changing the DSA master, plus we auto-open the + * DSA master when the user port opens => we need to ensure that the + * new DSA master is open too. + */ + if (dev->flags & IFF_UP) { + err = dev_open(master, extack); + if (err) + return err; + } + + netdev_upper_dev_unlink(old_master, dev); + + err = netdev_upper_dev_link(master, dev, extack); + if (err) + goto out_revert_old_master_unlink; + + err = dsa_port_change_master(dp, master, extack); + if (err) + goto out_revert_master_link; + + /* Update the MTU of the new CPU port through cross-chip notifiers */ + err = dsa_slave_change_mtu(dev, dev->mtu); + if (err && err != -EOPNOTSUPP) { + netdev_warn(dev, + "nonfatal error updating MTU with new master: %pe\n", + ERR_PTR(err)); + } + + /* If the port doesn't have its own MAC address and relies on the DSA + * master's one, inherit it again from the new DSA master. + */ + if (is_zero_ether_addr(dp->mac)) + eth_hw_addr_inherit(dev, master); + + return 0; + +out_revert_master_link: + netdev_upper_dev_unlink(master, dev); +out_revert_old_master_unlink: + netdev_upper_dev_link(old_master, dev, NULL); + return err; +} + bool dsa_slave_dev_check(const struct net_device *dev) { return dev->netdev_ops == &dsa_slave_netdev_ops; From patchwork Tue Aug 30 19:59:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12959832 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C53BBECAAD5 for ; Tue, 30 Aug 2022 20:00:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231810AbiH3UAf (ORCPT ); Tue, 30 Aug 2022 16:00:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40280 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231814AbiH3UA2 (ORCPT ); Tue, 30 Aug 2022 16:00:28 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2063.outbound.protection.outlook.com [40.107.20.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 40A7F13EA8; Tue, 30 Aug 2022 13:00:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m54WL4FiihAuMpUQWEL9jpzcPFGsc3KlqCBTKS/fEesa/YqT3v+T6pUxiIqT+1TTbIXmjqOKjVErvxLIZKrpexoQT1TU4Rzw8BzSCWny0PGm9z7Z6OkQmARgGBjhEJtlvbPUy+XDPbV51JPfa6IhezJEWvAe+mqpSfdEyYYj85W0CtHKNtUwrn0SQrV/nWzx1viY+2INHyXKsGV+skD0e7T/oqPduqHXmg03ZdoQggTVkdjGVc0L1vkBLdeyI1sciuQ7WbmAn0c8TVmUUIK+0h8WiUDmvOBT62pRe6tFAHFVrHVzNs02ZOH1LEKvmlQtwdGq5HqtZbiQfDdaJSVPaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=mL5mjKBRvIY70vaSvhVtmMzpXm5fpwReo5FvIBE7zf0=; b=VQQ90FDo7bvy0wB4S4bOMPvExVNpB3+uEPI0zymYzogRgP2fR7394wj8BodZQOtYH2SGIcnWuK70o+KQuPd0pKDhzESDuETeCbYUDC6M2xaTbk8VzYnEJsxJw10Yc/E9Z5sP/O4tbcOcraSsUbePMD3pSkcCmyMx73PByJ+ZJ829B91xhJD04N6Zu5dXph1UlixtoD2bbFILBwBix8FTXK4r52KZPkPSO0E3OhIFBcZsarCksy1m8Thzo77e2/4bteRQxUnPeLPYpcE2auyOpazFrUH/AJ+kP3iUBa72O9OMPWeUOXzSwIjVvGDiOHE7uEQljLv9zocG/EP7FvUSKQ== 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=mL5mjKBRvIY70vaSvhVtmMzpXm5fpwReo5FvIBE7zf0=; b=VP1qxZQ5a6TTgj77rjfPeeJitDsL4M/4w26+9zTcTT16DA0n+X8WDB3OPvl7WBIm8ojGcAbB6Jp8IB5xYVY70pLxezHHcVy4QQwVb2oRM5h/ApaW52dFoY8ognG+k+W9jFmr+NHzyre96eX8cZ+X1dTLsEeU+lA3CDRC1iXHuiM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6270.eurprd04.prod.outlook.com (2603:10a6:803:fb::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.21; Tue, 30 Aug 2022 19:59:49 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3412:9d57:ec73:fef3]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3412:9d57:ec73:fef3%5]) with mapi id 15.20.5588.010; Tue, 30 Aug 2022 19:59:49 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Florian Fainelli , Vivien Didelot , Andrew Lunn , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Colin Foster , Roopa Prabhu , Nikolay Aleksandrov , Tobias Waldekranz , =?utf-8?q?Marek_Beh=C3=BAn?= , Ansuel Smith , DENG Qingfang , =?utf-8?q?Alvin_=C5=A0ipraga?= , Linus Walleij , Luiz Angelo Daros de Luca , Felix Fietkau , John Crispin , Sean Wang Subject: [PATCH net-next 4/9] net: dsa: don't keep track of admin/oper state on LAG DSA masters Date: Tue, 30 Aug 2022 22:59:27 +0300 Message-Id: <20220830195932.683432-5-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220830195932.683432-1-vladimir.oltean@nxp.com> References: <20220830195932.683432-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: BE0P281CA0005.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:a::15) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7e90047a-8d31-4cc1-4119-08da8ac231b9 X-MS-TrafficTypeDiagnostic: VI1PR04MB6270:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5Mzz6JPZ6IPIYWypeFccDohEqmfMdFlDyuPPEvqkQgXBkh3rCUgDt5+0iAUEupUXjQiSe8MdbBc3zzq/x+4JaIRSErfGtq1jjaXjcBEl5M1tS4pp4mpe98OLz2rwiOX7mzDtzbqVv3O8UlypqQI8sTIll4T1COwx3na+K0SAk02xoO4z2ZxfHb+umCPcNp/Dw4/QnnlTKedJPWWQhAG4lf0PYyLPw7ZdIPmqo2XiUc3TNYp7B82IFytAw3GH7alAd5jHaDzaSfxkSUc0bC2LprERDfjMxo3aTijlT3MPttPAd8/h0We7g/SHbszdP7MujwsyVCirEX+5phVixoGglcs42gW79Sij5RwfnxERIbAIsDDhFzvOnoDOFEMPp+lROR27ILCmsADGt1W8WPN+xnxlR5fGjVGGNj7tTJ2pUGq6wWkWrdRwFHOldoIgfz0re0uWhADblj/r6a5+pXfpluRsN1+yPPJMBrroNSUZg9GBF07oXpdsfL1wySJ6YVNcf92Yn01WVY6545LarEFyMnFQ6zoMkPeUSgxG6d6o+BCnPkaY+3UeitIQv82ilqEMABLPo/pPZX3mFwgrWbOntr0yOjPBibA+aJlQTf1DnIvOKft4a43D5DIB4RpuELovhQUPy9BC8KbiwKwELNOVoIyI+E7YENi2CyQvY8P6qDWDn1aJo2mSnihdQZboc44cNQhJcc1sxaSWoGH4Akx7gD+8BHDfxzW4PeNzWtEP+VwFPaIawJedwHUvbZTIjjBys5iMaU3j9AROxzX5LghJxkh4JeV06LFMPX1vYsQzJoQ= 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:(13230016)(4636009)(396003)(346002)(366004)(39860400002)(136003)(376002)(41300700001)(66476007)(6486002)(8676002)(4326008)(66946007)(478600001)(66556008)(52116002)(2906002)(83380400001)(966005)(44832011)(26005)(5660300002)(6506007)(6512007)(7416002)(6666004)(8936002)(2616005)(316002)(86362001)(6916009)(54906003)(36756003)(38350700002)(1076003)(38100700002)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: w5RL+irn59uD+uKNSNEsuJzdisaakogbHgylqcboHhNQPhbSfA9p5cHzhgx7gWGlp71WdKfeT1TW0Lg4NRIFfSNXHGppP2gQJ0ZyaKtdNh5Tms7qDhi3Jw+wRXFk8O8es4mpfUX65DGX81wXFPz3wy5+J6SjldtIkCmCrnxppsnz67cy6KqgaBL27rvgh5qY1fv+4n147DCtpsR2G0pxJUte+8fzvHd1cSqLoQ/gkpcc0VuRDPd+JYFDT7eZCwTPdtHUIdlAJr0ajqsnfTk7E/um6jw+x3WvMsQANLqeu8a20bSZv0D3UVAlIY08kaBKZ3fcPtUifLVykmO5cfRNfvrWkgrGe0W3iYC8WIIL+qI6zvLLocVT+Lw7ZWVdwvQ3MGTiRLUrfOfRkK7VttTIymSoMtReQlN6NqbWyovv41C8H+7azSgyNyja6Vwbyn0zpPYOO9ZWkxm9iLhv+n4vn9DF5WtMT5SSHFNsiZuyTQnXSSVxhD0aO0AOdnWRwUkZIKJ80SRW67MG6x4kHZ492qIWxxRXr1mBb2SA/I2Khrg3H3hYjoYHJpJ4o8JXh78173k5ShFlebDSC8KOB+VDkcAp52n+eSGr+tFW33dlUHYK+64ENXBD2ELyCFlPYUh8LaSy4tpq64EULzxPll7oyAxLEa/Im01rVggIqrylHEi8jKBo+H1tgb+d9ie64EUXb/UCMxAiv0fBY0n5BnQZOk9yEyv3JtPCARTlWUDGvzvvJ1MplXfNjw4uBFk7Yo6qzjMPuqGdu9nNM44FCnB55aYA7uA9G+fI0VEI5o/MpvlttZKCtzs1WtyHz23h35uNb5puh8/5t09k9J1EFGCjWaKnm/jeXih6L763tq40qsZu7HKYtBlJ+HBiKOcMyGMJoGQYoXbb97GkUej+kqbI/SHp9XwibuEX9u0JKzfuhMYVaMPhhr4MHBp8P11nGtt/kxCCEwEQ43Tpds8X7tFCn2sLaBFkzobedzhE/rPPk1apVey+AWgmtwp/jnk1zadc7MPGromYA8JcozSawmi0Z3eIwzIjwXvLkBpC/SpIkvfvxrrdV6VE0QatPZe6rkwe4rMmlET53FFhaOSOD08X6VEs/gY1b6PpmBmBAxT9kW6YCnXOcVPMIymphZJnpq1bRu1u6BKV5wSuIqbvHWbZ9Jize3ObJnWFGK9AYdHZ5q2NCGI/5+78FEX3X30IKMLZNbMTLtx0cmM/47ri7JAKB6M9oNPAnuRr8u+rVOsuCFM9OieMjRgo6pfSmkjJTWYpUCXWqBXKDje7a/yNP3P8QjIYhc6xwMm5mI8+0gStGO5z36hDmVYrR41w+XG0YBYlC+U+VR9dZ2pqx6OiSomhCJ5jdZWA26mBv9wrDf+q5YiH3GlYZ/AlDZ/SuxnII0FRlS0S1mJCwjRJOgV083xS9FMC3czx83KDh+Vo1jZLqANLsgvQGnlJYr/pR/4SLZelGv8/qW8u6RsC26Lh7n2CT2OGHsAcFoauDSUcDOHWH1N1EVAQxKAwJLTK22G0gULAbLQKAeagBmxlOb2/KlL73AixrK2JYxwSulaPq1ep+ftl7C8WHcUeOh3X912/xVhq6IqW2HvZz7BH21u/6TSPEQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7e90047a-8d31-4cc1-4119-08da8ac231b9 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Aug 2022 19:59:49.0421 (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: 8czUwkcxeEXg6edZTYJZt826udHGh8i53EiRj920wTblsV545XuZDu574Gl9bFMBpwxZfIb9OLWCJnCCYuXggQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6270 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org We store information about the DSA master's state in cpu_dp->master_admin_up and cpu_dp->master_oper_up, and this assumes a bijective association between a CPU port and a DSA master. However, when we have CPU ports in a LAG (and DSA masters in a LAG too), the way in which we set up things is that the physical DSA masters still have dev->dsa_ptr pointing to our cpu_dp, but the bonding/team device itself also has its dev->dsa_ptr pointing towards one of the CPU port structures (the first one). So logically speaking, that first cpu_dp can't keep track of both the physical master's admin/oper state, and of the bonding master's state. This isn't even needed; the reason why we keep track of the DSA master's state is to know when it is available for Ethernet-based register access. For that use case, we don't even need LAG; we just need to decide upon one of the physical DSA masters (if there is more than 1 available) and use that. This change suppresses dsa_tree_master_{admin,oper}_state_change() calls on LAG DSA masters (which will be supported in a future change), to allow the tracking of just physical DSA masters. Link: https://lore.kernel.org/netdev/628cc94d.1c69fb81.15b0d.422d@mx.google.com/ Suggested-by: Christian Marangi Signed-off-by: Vladimir Oltean --- net/dsa/dsa2.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index 42422ddea59b..7024e2120de1 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -1326,6 +1326,12 @@ void dsa_tree_master_admin_state_change(struct dsa_switch_tree *dst, struct dsa_port *cpu_dp = master->dsa_ptr; bool notify = false; + /* Don't keep track of admin state on LAG DSA masters, + * but rather just of physical DSA masters + */ + if (netif_is_lag_master(master)) + return; + if ((dsa_port_master_is_operational(cpu_dp)) != (up && cpu_dp->master_oper_up)) notify = true; @@ -1343,6 +1349,12 @@ void dsa_tree_master_oper_state_change(struct dsa_switch_tree *dst, struct dsa_port *cpu_dp = master->dsa_ptr; bool notify = false; + /* Don't keep track of oper state on LAG DSA masters, + * but rather just of physical DSA masters + */ + if (netif_is_lag_master(master)) + return; + if ((dsa_port_master_is_operational(cpu_dp)) != (cpu_dp->master_admin_up && up)) notify = true; From patchwork Tue Aug 30 19:59:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12959834 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF017ECAAA1 for ; Tue, 30 Aug 2022 20:01:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231831AbiH3UBB (ORCPT ); Tue, 30 Aug 2022 16:01:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41284 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231839AbiH3UAc (ORCPT ); Tue, 30 Aug 2022 16:00:32 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2063.outbound.protection.outlook.com [40.107.20.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A9388248CE; Tue, 30 Aug 2022 13:00:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Xn53/oWyjP4HaHaQnPYXfCin0iGd8diCnHBRNkrKoEWSejEnhKKubzJFiSRD/UwQutJ2FlSKA6seTewNrfrsbYn7EhoeYff5XgmN0hXE2YakaUGQC5wSup/t3tDz1LoeJjv0ddblRn+HvHkyxhR80uJwmpFX9OQZ7/PZUit5GN4MR3L1/rOPlh3hpIvyRg5h2escCvwlBAhDpzE95HiShbtzncM4hfhNGHbQSePMdyLrIwHItmv5iYWzOXJXgVsp6scMbRpLR8/ZLYhdqnI8ZahAiRJ0I+PPePbgMiGHwExKSXvg1f/lRht3WrHc/QqwwZgXA1i/UHPTVICMYF01fQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=NpsdEmkxc9C67B5T8k6L60wsiFWrP+l1QjhHW9L0hMI=; b=E52jhXUmXph/L5cf7g4tFWRHlt9di5jtAPj1/+PMnETjMCa+Ia8va1INrv0bIyP8m0AzS4BEXdffFstn5zVv3g3qSk839gcSJ1y6r3oLoo3PSk1fSKC7IBBwJN5dT1w50DCxYmS0nzU+yZhzjusoj3E3pE+eOQ+TZfoGaZaCh7B6niGO6Gp0ZZWBtS1WL14I6zAN2mJCUOet0vebZAhaS85pqpJvVKB+FpRVRUsnpVLlNZAiBvEG4VZXXd4lxdQt0Qc9OJ3OJAMKv6UpTD9drVEOBXejd8Qa3h5OzijMWmhSMBgtGgKf1O3QdaDDd3k39SM64SzjXuUylJL2Yw1BDA== 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=NpsdEmkxc9C67B5T8k6L60wsiFWrP+l1QjhHW9L0hMI=; b=c7Sywb+d+HtcOPJ+1JKlHHsgRHOCVDxMzAk8vQ/Qd/9NCkmw9+33vvXm7bg2p9GvmiPntWEcajDJFtWS5eq24JYjQk4xAkjnYJ3XznJ91d063qEVYE6tqZNDBltAnE8cwF2dyg4sqL4DBF3WFhEMc+PQ6huUy2nLqJKJ65iYd8A= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6270.eurprd04.prod.outlook.com (2603:10a6:803:fb::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.21; Tue, 30 Aug 2022 19:59:50 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3412:9d57:ec73:fef3]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3412:9d57:ec73:fef3%5]) with mapi id 15.20.5588.010; Tue, 30 Aug 2022 19:59:50 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Florian Fainelli , Vivien Didelot , Andrew Lunn , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Colin Foster , Roopa Prabhu , Nikolay Aleksandrov , Tobias Waldekranz , =?utf-8?q?Marek_Beh=C3=BAn?= , Ansuel Smith , DENG Qingfang , =?utf-8?q?Alvin_=C5=A0ipraga?= , Linus Walleij , Luiz Angelo Daros de Luca , Felix Fietkau , John Crispin , Sean Wang Subject: [PATCH net-next 5/9] net: dsa: suppress appending ethtool stats to LAG DSA masters Date: Tue, 30 Aug 2022 22:59:28 +0300 Message-Id: <20220830195932.683432-6-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220830195932.683432-1-vladimir.oltean@nxp.com> References: <20220830195932.683432-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: BE0P281CA0005.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:a::15) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b8b01ff9-d3c7-4cde-9376-08da8ac232b3 X-MS-TrafficTypeDiagnostic: VI1PR04MB6270:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FC2TOZweVZkK7F3THyUd4rKv4VGwkoTcBJCplxiUQoWLWLsk0oATD6q8yhF2FrphhPorLlQs0bRvxFnEyKQM6oR/h99C0kwZXWvnSZx/NBVWj6bKN1RYdfnXmZw74ZeoOE30otSmqWRG5+KVXWykSYVtK01ka28FxWgL3n1mIsDueIIJ7aLc+s4yxdEK00dwGCIUieyxbSQJShkgfB/PxwH/UP4YsI0GRdGxM1htwWTXA7m6CQyJh8eotqRaP0uyrKq/Bxcy2O9ogH/FFDjBE8wnXDbvrxcs56JQ5VPGDRqt4WQreQOkoLrQsjxM1SrDJP63PUtsR/mzLZiBNr0+pvkzFXpt5DUmEwrwkn2+u4UDx1hLT6d9K6VuAqEeXSygL86ZHSx2BE2k9n75ORSAwWP2YR6A3AXyHTCk4t0fhLpM30eBz28Zd2TXL/nW4o0eMQYtqJPwfs9cDZ05j7n3m/CozuMWzSfhzThn61h/MVKH/enGdI7Taz5WshpErQ8gjzENX45o3AANfgLgE5feI2R+EUvbOtXSb5EW85YxCmeGJHuBhvbfuLetOULMUU9nmuMXxNw/rCTnO7sOJq/xzrWk43k4IJUvTnWUUEryQYAzZhdaV17d8ExR2CiiK2iD4HsoNcRZ+xnpCY9etG3QHMxhqZgcuczP2aLGCFBGyTsZKherq3gszj+4pfqk2mIUZ8lSWrQ6kZDrJ5MqV3jOmCcuWwhfb0NhaFaGMt+B8NC1SDHNf1F8GWKG/NkS4VNH 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:(13230016)(4636009)(396003)(346002)(366004)(39860400002)(136003)(376002)(41300700001)(66476007)(6486002)(8676002)(4326008)(66946007)(478600001)(66556008)(52116002)(2906002)(83380400001)(44832011)(26005)(5660300002)(6506007)(6512007)(7416002)(6666004)(8936002)(2616005)(316002)(86362001)(6916009)(54906003)(36756003)(38350700002)(1076003)(38100700002)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zu13r9vWXBHz8+LE5BTuGOZ5NfdTXpSrHkB+Yln6w0F3YkNSWGeOqJbbIw1Al/GOFBfJ9AB3cvnUfKBE8GZya8etjRHkMpAKqdTVX0jleCt0829nvUHNhKfuClNAWYfvriTinW4OC9Ex+5biD11UeZXoIwlVyyQlS661Jd3rJx7l+HtwOgV0U+zGtM6Te3QA2N/yHSKS5Fyf7xwtbQMGdmjB2s6GOpHyg+Njpe53F5KczKCzop7tWBG1O0bOrY+zJv5uOL/OLYLL5ms5DAoGSjl9rqNnbzyhOgq5OdOIKxFMdj4GFIZ0A3BVHvWO0VI4MMCFwfKPC3GvxhguXVK2suUcfEMxLLq8/7z9zpDnMeA+k5/X0aLtZm1eULnACMd0awa4bV4Nk9+EeFJbwkEQc3R0hM4NzNZYaRDObhA6vOMc5naJ9agQRspyqdn2lfu6afHhAoLFZMrbXbbp4SRGycB9+UXKu0yeNl5+libOm0qcZOurORd0Edqzk/9FZXkf+4EiCenJpZdSkap1d30LoR6lPu3ieaxxWFbTe1Xt5W31jwYN8dFoIzrRnECrAtyIc7lbuPzJyY0fWjSDtFys5c400TK4PuaANVvqQzf7WCHflnBbBodef2mcVg7brvDD9i3iK1XPn+g+Kxv1b6FK5aaTuBH9Gxc2U/iopAQNKFDY2w/uhwje3bwMc2kUf0RDgc2qJn1WBilGuM9IlQSlvfi+1GTks3jnLXg8TLUv6TAjAquZH6T1uItV2Ry/tEA8H0J6Ugtrdn9SUN3aC8h6sEzjaM8Ik4/iE0YfEWnYfNi8DK2AdsULlMiHoWeJ9r8NMjPuT0XfXAmJsT+ynA1EfG+rJWzEODvk/urJv6jNtZ0D0M53LvUd37h0CR2bAhomvh/qq8+H7BH2SVZawNRIJxNdcGHzQhbyp7Q3sqNovXobdnhW0Smi9OQwN1ZfTjHlvpjDaqU6N68uWSkh4gRPe2xfBiS8ytYneZGErgnuXIFJAqlrDTfOiDGCXH2tILNSscsSj6eGTY4vsqY34RkSz0aTBtnDPyWZ/DL4FXkTfRZUTRdQiWCLCYN045J8OXjtV5WOusRarjQixz83hn1DlzT1HU/bHu1okfOUq3tHjp0YKXZYUiIwqR7dMI1AYgLAt1aQ9QUnesA2HXuSOFx8DIC+LpmslVO+cGYY+2nyt+YZZQ4+D8nongtkIVKCxxg/x90rKfMun6C4Mby/20KaHj0GLOIjH0iA/UwfF3cCc5098RbgkOtT7CSXQXTVjl4VUuVPskxZ8VL8JAE92Jr9n4xBI4ALnMb5SLOaWHNiubJ/UKvfUSuvI3GNfQakG/+qwv0DivHA48F31Sj3sTS6MYFIiYIkM/1ErYPIXuIL/QfPUQJeUewUwZsk9haRNdp+Qz08Bjb5EQHGzo/4clpoueucAUlDEyyTJQF6mlghkv1d/MOVoK588NyWmf/2s6M8fESG6b8avFqmVugjeft6ytBQ5rPKYRn8vWUjWZeLTo6aOmdv4vGCMSZEcsQOcKKc6K4sXtU4p9ZXsLmaLW97AXs+JAD2ZUAN+gByECxtcI2vz6eKMpcsL2+RLngDiVru0M3MLWk8yUhLuuZrSDaP+w== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b8b01ff9-d3c7-4cde-9376-08da8ac232b3 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Aug 2022 19:59:50.7139 (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: CxzWJUFIwGx2lRoT+z2lu4OgbJZpoqoYiAYXWMLTqnkOD7ZROINKNJJmzLu/phOdu/GoXTkEGFtDYBRBI5zmGA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6270 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Similar to the discussion about tracking the admin/oper state of LAG DSA masters, we have the problem here that struct dsa_port *cpu_dp caches a single pair of orig_ethtool_ops and netdev_ops pointers. So if we call dsa_master_setup(bond0, cpu_dp) where cpu_dp is also the dev->dsa_ptr of one of the physical DSA masters, we'd effectively overwrite what we cached from that physical netdev with what replaced from the bonding interface. We don't need DSA ethtool stats on the bonding interface when used as DSA master, it's good enough to have them just on the physical DSA masters, so suppress this logic. Signed-off-by: Vladimir Oltean --- net/dsa/master.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/net/dsa/master.c b/net/dsa/master.c index fb810edc8281..99d773b24223 100644 --- a/net/dsa/master.c +++ b/net/dsa/master.c @@ -226,6 +226,9 @@ static int dsa_master_ethtool_setup(struct net_device *dev) struct dsa_switch *ds = cpu_dp->ds; struct ethtool_ops *ops; + if (netif_is_lag_master(dev)) + return 0; + ops = devm_kzalloc(ds->dev, sizeof(*ops), GFP_KERNEL); if (!ops) return -ENOMEM; @@ -250,6 +253,9 @@ static void dsa_master_ethtool_teardown(struct net_device *dev) { struct dsa_port *cpu_dp = dev->dsa_ptr; + if (netif_is_lag_master(dev)) + return; + dev->ethtool_ops = cpu_dp->orig_ethtool_ops; cpu_dp->orig_ethtool_ops = NULL; } @@ -257,6 +263,9 @@ static void dsa_master_ethtool_teardown(struct net_device *dev) static void dsa_netdev_ops_set(struct net_device *dev, const struct dsa_netdevice_ops *ops) { + if (netif_is_lag_master(dev)) + return; + dev->dsa_ptr->netdev_ops = ops; } From patchwork Tue Aug 30 19:59:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12959835 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 55E3FECAAA1 for ; Tue, 30 Aug 2022 20:01:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231923AbiH3UBR (ORCPT ); Tue, 30 Aug 2022 16:01:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231843AbiH3UAc (ORCPT ); Tue, 30 Aug 2022 16:00:32 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2054.outbound.protection.outlook.com [40.107.20.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 79C2E26118; Tue, 30 Aug 2022 13:00:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MX9fUD/AJ9Zo1yw6WH7sfiGT3mxINEgfI+iPlh/CF2s1TeR6cZqLM6r7lbz7iGwrcqmhFhROk6IPqzffLvZPlCEJGunyMQyQ3XS824mtj2cYa604kyUAsDD7eikxEDlXhHw/UfdHOo4qDn4j1FH4iPMZIORUAu+Ye82sI9nR1ubuA0pTGwpfu7uYr7lvxqgKwDhqTajyDgTJVxqMpfmYawh4GPYQfo/nt869K8KsbQS8GRqnW4ZYWBeMaOsBS9TupzMOHbA30pdsmrUxiDF/7ypJeE7sGVmb3gH2tSWHbFYWM9/XDricctoL4aFxNklgJtY0haL6SdHTXIWXyvAqTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5h1VvgX8MF+zSQTU/wgwjESwnjvrwOu4/+TM8gKSDzw=; b=gbhHSmufoxGQgIX+NtuNqr0cuiL5/4bxjlz3XoqADt3MaJ+h1gISHGlGSd/LO3POEtdOWNy+wHInp375HMImRQlue6fjUkpoWXheBPq0KXXIyhOndWHx/EPb4HmwILt72MGLSDM8yBk+2yQXcDeyDZepsDEcDB+siC2bRVrB26hkdAvO3N/I/KVjpypnRfK+IfqgZ/hOJgZ3bNP/PCSbwUMheFrAuXeqEfDEibUzFC3QNot52xXLyNWlsHWQdA9ozjWalntWfM+jpwH2RPiEfyPov10qmJ4laUwLyScmntchX1sI1hAEZA39NuREq9DP2DYhHtDxbIQNobXLh76wcQ== 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=5h1VvgX8MF+zSQTU/wgwjESwnjvrwOu4/+TM8gKSDzw=; b=nzxdLwJlxaz52/2/lYTwiJO6WrJcLsCVC+yIx1bWS4sc2O0gkHJ7rEpP3d6URh9dexBA35Y3zo7bjkZgXQ3zY+rydAqChavULHjibwMc0/Ar85VAgo17NCn45MaBbdOeyaKRFD6HuvdzF50cc9KCBYPY2Rl3abmTo+f7udWw8hc= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6270.eurprd04.prod.outlook.com (2603:10a6:803:fb::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.21; Tue, 30 Aug 2022 19:59:52 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3412:9d57:ec73:fef3]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3412:9d57:ec73:fef3%5]) with mapi id 15.20.5588.010; Tue, 30 Aug 2022 19:59:52 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Florian Fainelli , Vivien Didelot , Andrew Lunn , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Colin Foster , Roopa Prabhu , Nikolay Aleksandrov , Tobias Waldekranz , =?utf-8?q?Marek_Beh=C3=BAn?= , Ansuel Smith , DENG Qingfang , =?utf-8?q?Alvin_=C5=A0ipraga?= , Linus Walleij , Luiz Angelo Daros de Luca , Felix Fietkau , John Crispin , Sean Wang Subject: [PATCH net-next 6/9] net: dsa: suppress device links to LAG DSA masters Date: Tue, 30 Aug 2022 22:59:29 +0300 Message-Id: <20220830195932.683432-7-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220830195932.683432-1-vladimir.oltean@nxp.com> References: <20220830195932.683432-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: BE0P281CA0005.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:a::15) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2a29cc30-7549-4d07-0ca6-08da8ac233b5 X-MS-TrafficTypeDiagnostic: VI1PR04MB6270:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u7mMc6YbL2dyR5Dlgft3HDjQL1R34c02ANXzZYtQW7LaES2Qv256F/ph9lsdx63F+WHKvAUbCwh9/cBCNi2vvI3PTw0SEnYB/doY/+FgMZj90LXrlIS5COGEWZHu16RkJ2QwmsOC4Rqlb5N2a9LdKK6U46YCzQUj0lxfk3m30fqfUYQPUl0MFtwDmjr+brzTucNvHESnVSsNwqZ5rO1HuMiizDVFpumpOiAOF2OIASZoFEvs8XCt9eqsdR9M/A9LjGRezuYqTsZPjrZU+4mpsdglenDh442HfvISrxkfAneYNI1by15n82KEf2GLwMH48s6SvOT5/ceBCrG+IL9wDaaOQm8ns71Oin2vwz3rxcJBID9y+YAu3QaFxjLkev9wl8JS5GSUmdyy7CrUhNur/BQJfYTcHelinRaB4ydPD9SwlfrByGf4BiCuV8Iqe3+KqXhctKrSosn8h5iFA0C1/U9BbMLzVVm8jtf+ux2+jMP5D22tN1lFvbBe/LS/9wV4t+l6innv8doyAdeAHgktFVgJaCQmIAHpk8tkdCJEu8haeVwhKXj0/AV6uOZxpD2L0SgLtn6fuZf7acXb1IgkC4kRU7w3mBlGi/+uRvNfjBayk7igNtXDaYeVB6FplpdixkkKk2HrWOIqIspxrGQymGFBlafP7sCcpJUmKuyFDyWdiT0umt4CmJYh3OsnPG54WWb91by17f7z0O8Wr7z+VH1o2GVZGnDJfkyB86QTlgQLV0DGoKsBBgSXV1Pcd5Ao 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:(13230016)(4636009)(396003)(346002)(366004)(39860400002)(136003)(376002)(41300700001)(66476007)(6486002)(8676002)(4326008)(66946007)(478600001)(66556008)(52116002)(2906002)(83380400001)(44832011)(26005)(5660300002)(6506007)(6512007)(7416002)(6666004)(8936002)(2616005)(316002)(86362001)(6916009)(54906003)(36756003)(38350700002)(1076003)(38100700002)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 6LEXVcW47Vw/cPTf1OpT7bGSXlQKhSU7a1duPde37Tt8n3lTToEjJF5zasRqbkQ5n8jJp4p6kt2jJ/fyT4aLdVSwmKehO7J8tJvCrewB+urEJAujlcljr3TYWWInl7cyXxBqXysRlVEsytIaL9jxULi35HfnUhx34rFRLbv8fUOz81Lf0jPbYbt9EV6aVawbUuQ4/eM/TY8J9l3HcodscYbqGAS7qSJPCAe3/cavEajt4oiw5wtmH70ea5zUagxgXxhjzuThUt/b1sWpaNYsvoxlgaLiQlP+uJXy6KFl1mrRXIrBvg/Mg8OEv5TiXJO+y4YTtpoX2iALK/2nz7CJrvnKPYN8Wq7jVBqrCEFX5SZV+fvdbbSMAKaUrRg9oseTqFe8+9rIf/rzwdUUaeVwnH4WJyOSLuPTMV/SyQOs8fOTfiP6KfETXsWbeEeQDQJrpJhh3eDeJ4wwHMi7EHZ+SX9LDYB/yKTuqGKGrNj0HaJwvJNQRs/NlbRCuQejU8Nz3cm9VOiIN81Rn8fLehs9+QPJmMl5DZn2jkX4yEgIQmiT3CRXk+iiWLk4hgI5MWlU8unkOTP+MFMy954OrQ/+76sXE8J7yHlURgg1czX8Nvwxq7x2GThoLY5mfpqCTslW0E4ymWUVE123faHU3J71zpjPZGQeoWeP011o4vHA94rP9u196UYxi2jWcfn8MkTLSIFGGlwkADKAe8x+NT4L4wOyp6pTpZz48E1hNoTijMTVxTww9PGZypqTxC2zusF1mbpNqDX5ial/SdKJxTiAvK/44vamyQJK6uXuBzHvmmigytTZhiZEOE5j52blQtm7eaGGgNKpkON53d1AknE9j7qZESIje9YCvI6istwYLhhVaVFS0fq+rKyMNhD1AWCCj2J7o5jdS7zq4Qu9y5L4OdPkjfD4ghvhLBCq7MQyJMiSBS1mEeXP67pA6R4J5TP7qddIwXbzBCdxTdy11119acLgPaRaCOS8b8j5+Kclxc2oPYjXKXsVGU9VF2ZgArADQid/kS/7t5xTybxEJ3z6uDbVWHs759NBXT+9fDqRK6/MZ4ZlMTpJUgH/h+gffdihAJouQAB6hido5RS6FpeL6cZd2r1jIRerZoOhWESvwbqvOmIM5VDIfWTg8KDhWMfyIOt346gMDeC+ANOQ3eXLoi7DDXglGWzoNjRDod+v+OD2Jmbj5nOKPVzvuLOhFDy8UYPyVa912HVfVvm2+JUjaVA3Y0EZ7Ey0DbzQgXoI3OMD0Aroz6pRO4cVxQXedZDyYK+lahQ8/5lIHoQghwqpH4hWGMVV/EiYuKP0ZOqi3ms209BDRIWp0xRuxZvHz3Ia6o1syDagKF6eY3oAfInEGescM4/BYhIeHfFApyPuGdva+vnDmLaOykWOE1Rr62ql1guaEXHOt4Bie6y3ilCbu0nKmvLNxP5ANf/x5Th0c1TVH8l3ZnpSMVT2QKendkHG6wHzAJkqtL4xFby0EPbJhUwISuQ4Xfii6nTxI+ieLyoBEEYTpfeKdvh0WIx8fYWYg5+VinSbCUtAjEtC3Q217soO+S/sxzKeTdoTFHJyvBAUZBpG3mpZSGA5AtWhWrPFV3jUPr6eKLZeg5tMqfLk2g== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2a29cc30-7549-4d07-0ca6-08da8ac233b5 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Aug 2022 19:59:52.3856 (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: pzOpWh0kyD9v8hKaycQliaunNsjklcCo/migVX+XlKLZN7wTFrxbHz1Z7sLHlORwqAfjdDsd8cNi4kCq2ArXfw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6270 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org These don't work (print a harmless error about the operation failing) and make little sense to have anyway, because when a LAG DSA master goes away, we will introduce logic to move our CPU port back to the first physical DSA master. So suppress these device links in preparation for adding support for LAG DSA masters. Signed-off-by: Vladimir Oltean --- net/dsa/master.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/net/dsa/master.c b/net/dsa/master.c index 99d773b24223..2176c14b97a8 100644 --- a/net/dsa/master.c +++ b/net/dsa/master.c @@ -364,12 +364,14 @@ int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp) mtu = ETH_DATA_LEN + dsa_tag_protocol_overhead(tag_ops); /* The DSA master must use SET_NETDEV_DEV for this to work. */ - consumer_link = device_link_add(ds->dev, dev->dev.parent, - DL_FLAG_AUTOREMOVE_CONSUMER); - if (!consumer_link) - netdev_err(dev, - "Failed to create a device link to DSA switch %s\n", - dev_name(ds->dev)); + if (!netif_is_lag_master(dev)) { + consumer_link = device_link_add(ds->dev, dev->dev.parent, + DL_FLAG_AUTOREMOVE_CONSUMER); + if (!consumer_link) + netdev_err(dev, + "Failed to create a device link to DSA switch %s\n", + dev_name(ds->dev)); + } /* The switch driver may not implement ->port_change_mtu(), case in * which dsa_slave_change_mtu() will not update the master MTU either, From patchwork Tue Aug 30 19:59:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12959836 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9A031ECAAA1 for ; Tue, 30 Aug 2022 20:01:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231944AbiH3UBd (ORCPT ); Tue, 30 Aug 2022 16:01:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231824AbiH3UAy (ORCPT ); Tue, 30 Aug 2022 16:00:54 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2063.outbound.protection.outlook.com [40.107.20.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 952E23F31C; Tue, 30 Aug 2022 13:00:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HNIZ/dInATCuciuwPanBcXIKdWUeyvfzyS/4ocMfwTTim0YpfLYkgFYIx5EeFwYwIaYMkxzZ4jElH571OGj55L31y7eVvQ5DVSMLEQRev8pMmrN8yQ5rPUPsDV2WrzyP+ZUOgkP2VLY/4z+73PVqIItvnQ0nMGy495DzBmofMqn5rdi0ucffe+G+6sGZS5G3iEBqdMo75hYeuYaEJBpWYhcMbqBQSUHS5PsF0rn/iGZLFhX10i3vhi2iouvPRfZRW65A8lzdT4IYE0/MwXI6ERiHJNPldrgqzUiTqYF9j9BWmG5g4B2s0kTR/VFvSkMQ7cE1ogM8hX6OnUxXRUzS3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=UcAZNLbSf/yXu+eVkhbU8dgipt+q54HrAFrCu99ygdE=; b=SIbWLJuWelghorTTXODoYph3ZJzS5v+8xu8Zb0dEXWcXugF8HJxz5x4TyqzYiGUm3ZDDDlNqlRALUjkxOR5OOZ4M24OT9Mf8QfdGuf0nHtz47Px+dBru2BOK4bYnlKwuWjZzjG+4S4KgTY1+h05yJQKKuS0ESc6vMT+rrHm4LS+KBrcang5tcRdgmdgGHAood03L8JyCmXDk+9vVdnO2Zlr2yC7BrjrqNluRu2vq26vO8dCBV2rL7BaZ+pqXZYG3g2KkqgHBCxGYsY4Nsz/J+w7KZzoakBwapXl9qPcVfSkbCLPRQxUF3Pg63qIhuz/B9cVKG+GMnD/X+fBIPCmSUg== 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=UcAZNLbSf/yXu+eVkhbU8dgipt+q54HrAFrCu99ygdE=; b=B+tMAczLxusqnk+OcPw3a9nOiTzIUVTj8Int9EWnXKorOthX7sx9iyFVHTHWyPSonCoMA3YZXAZVoC45DlHAnn68AAJJEBzBl4/EznI2zRSd2Qycvo9urlmze26UDM6IWr1Qy9xVY7qYtgZHJRTizai+FPzqdrK9wk9ouv8Ekfs= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6270.eurprd04.prod.outlook.com (2603:10a6:803:fb::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.21; Tue, 30 Aug 2022 19:59:58 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3412:9d57:ec73:fef3]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3412:9d57:ec73:fef3%5]) with mapi id 15.20.5588.010; Tue, 30 Aug 2022 19:59:58 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Florian Fainelli , Vivien Didelot , Andrew Lunn , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Colin Foster , Roopa Prabhu , Nikolay Aleksandrov , Tobias Waldekranz , =?utf-8?q?Marek_Beh=C3=BAn?= , Ansuel Smith , DENG Qingfang , =?utf-8?q?Alvin_=C5=A0ipraga?= , Linus Walleij , Luiz Angelo Daros de Luca , Felix Fietkau , John Crispin , Sean Wang Subject: [PATCH net-next 7/9] net: dsa: allow masters to join a LAG Date: Tue, 30 Aug 2022 22:59:30 +0300 Message-Id: <20220830195932.683432-8-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220830195932.683432-1-vladimir.oltean@nxp.com> References: <20220830195932.683432-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: BE0P281CA0005.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:a::15) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0b411a09-3638-4a8c-85d8-08da8ac234b6 X-MS-TrafficTypeDiagnostic: VI1PR04MB6270:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 8+xplekzMWFn4qAwivcTWiYwakOVhJiqacHhCWGmTrqqXKtiWJ4VCTO5mxrYwsbvLr7RC4vCzsidt5UstAPZQ1+aJseH1IK7BkP1RAK1NUONVFkMn75rEgt8yv2bG7peXmVokgUx/Jj3XujJa5n0/gweAetXgz6oHwFd9r5C/jFPftf+F9JdAQIldsZfekuN0HoNAhnmGsjH7V7tHoTuKeAK+PAJX+bTcLc7fx2ukkwgLtfwdu+HiDzEwVPmpZ1IMC9mDqOauVzR/BHGTeOrJPqhN8yo3OldZ4OJPx2rrE3ewj661HhwPtVcIf0eONCTPc3VkgtaOJer4wH7vBPJiz3prYV7pr39tj80N/vLerzF/Dbrl2zQvdLR3VrsUaWrrK6zeJrQQKVcm6O08DRE9kjjkQ0OO6N2XF+ZqRQu2HwgIqZRBPoUu6wjD8gq8v6xJT74KCDQ/anfQI71Y5s6Ol+6lb1U53ICGmIRtD8lXqSiBp+idb2OMzqdcWkXFn1hr3g6LoqhZR5nMb30viapSciTZJ6PAVZAkozdN7vOeGhSXCMcIEFThehZxG9axJQGWNg3cv6FkB+fnWyhTqtNr9Nsm5DUM7k6rIgoJyHRBYRk4gB/G0+B8pEllHzGU6UrWtnswopPbcD6KXeZeK6EwpFa771hoNhFfu4O2DKRkxdjzox8G99rwblj55njHZTANzuszBKiAH3Wml+1utH4MFUciR0JwKja6DiU4KtAbezzkLfDOKwJD4LZgUGWudl7 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:(13230016)(4636009)(396003)(346002)(366004)(39860400002)(136003)(376002)(41300700001)(66476007)(6486002)(8676002)(4326008)(66946007)(478600001)(66556008)(52116002)(2906002)(83380400001)(44832011)(26005)(5660300002)(6506007)(6512007)(7416002)(6666004)(30864003)(8936002)(2616005)(316002)(86362001)(6916009)(54906003)(36756003)(38350700002)(1076003)(38100700002)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Qx0svCDuJsUnO6wVJGZq01vlEGdDKv//QVi4ee7yraFQ70UdOabIVceqtwDCeV2n/KDC8mvzZ6bPH7IH1A0aDAAH9edjXoFYFhZ5US8G3VWtdkN6SE7BfaY4QOTEIRSei6lDcVt+7vkzTKYoFJvbYSyYw816C+s8C9ofMzT7UAHw8xuzWlCB/9WPas8NGt3HhnZLRqCKvPS68arnD/czxmlvj1Ao7cIU+2XWdRo6kdBB2varel/8m2F2r+xBr0A3a6Wr5OyNa/zATsA/IMYfTcjSLnILr5sWaaImy4NFg86+ZpPYJL1ICbX7s4+jq0Fsz/y4hVpIRZ5ex0UKKY1LIwd50cD+Vsr84Ypy4OWup3jlhqkyMb5MJ/61AtVSjfwuwVnU6xzdUfXXGrpNt3y4gTFbrp3ZDYb0z+HnZ47nLW68n5lfFX6J/CJg3l8dbTv49bJKBPkIHakneR7G2hude05bfDrwu+075V9G6IIes7yRgOyfc55yf5f0u8EypMQOHE01Moa1Lofz7XoAFqs8YxHbJnkBj5dVF3GxgP2pHVJPISjgjsG1Vtbp0UVuavOCJzH9+UTPC8wvsE5s/QK1pYeT/9Xj55XUaI8cEUHYpO48FOzERe2UBkIv1frzNoBUbFv17jy4BdOv+oQH4mcgisKq+1/GSuvlBsY1QGXu28j7l8YDBNXEE62lwFJ6+1r8c1dFCBtotFPx9JlQD2j88WF3RgLPNzuLcqZVcS/Nq2FILBcZ8TjR2cq56kmTISr3QEJnc2x0qJSF0rsxaB10BAhorBemW9/UJK4y6jtPPW2p9WLmu/SQYfMGldlr+z8grduu4rVreWrlUEZfh9uMdGStBQB6Soc3dlfhckdsOYn8pmlBiLkqxNOZ5cy18zNM1ycO5eMxPdubEXXBAdTwwHh7+km5yFngUBvzcdfMhqpztZ+LWktggXPPGPhmL7ildBbwBiirRh7ma9i9RaGnZvZBCDi9m2Bp7caNzUL2KCKGTgSzGk4zET/Oyvi9ZRqznzDmaW2HguyGz7Evy1FySum9FGim9hmwZ3KuLsn9gVIcmArXhz9AKldIIz6Ysraf3ChndFNNGXiVX9VJeAPrqK0MgFnrm0cgjPOFuROimkLBcWTgdt+wW3X+7r1NHlfx6MryDcRBGPsIsRgtRUC4LggerNUXbyeMzcKXOtqCckQ9xZd2YUsb+442zffxPwIK8a8QrjwTIBvjbBi+sp9dq95lRp6fKpMqugtilZSLjOKAZsVLhA5Uci1pxcpKzyZ/g+Y1pFhmZ6xI71V32SE2jA7DH293MbLN0jKEq3UsaWyr2ds/OAao1GNLiN6VYVCiqxP0J6m0lrjatYfrqBaeOAq7KzFHdftVWw765OA8pIB5xWEDwQrfZXV7+3NF59aRPhI0+RhXPYvS9STJiaYbOSd4PvY/5ERgWBemDs4Fs9CyfkBE0ivvHr0okYdukGS4TUZ364sAcM8CVGqYJJ6Ak8zgFrdihzQ4eMhpWdnEbQhtBo5oRbqEGDYHYsUMZ2lSy7mDQh5Y8ENcB70R+J5Xuy1yL5RdwXjAakSUP3kFDG8Z3awR1GCgLQI5ihlm5FZPqPoAWfBn/jtaKZDB9sfCzg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0b411a09-3638-4a8c-85d8-08da8ac234b6 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Aug 2022 19:59:54.0730 (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: T/K/rCE7rf8JL+io/Zj1LICkprJCO0vvFjKBp4pSThrH7duWwSC1OP/48DkBFh23vXfguVBBqLPDLRVvW5d/RQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6270 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org There are 2 ways in which a DSA user port may become handled by 2 CPU ports in a LAG: (1) its current DSA master joins a LAG ip link del bond0 && ip link add bond0 type bond mode 802.3ad ip link set eno2 master bond0 When this happens, all user ports with "eno2" as DSA master get automatically migrated to "bond0" as DSA master. (2) it is explicitly configured as such by the user # Before, the DSA master was eno3 ip link set swp0 type dsa master bond0 The design of this configuration is that the LAG device dynamically becomes a DSA master through dsa_master_setup() when the first physical DSA master becomes a LAG slave, and stops being so through dsa_master_teardown() when the last physical DSA master leaves. A LAG interface is considered as a valid DSA master only if it contains existing DSA masters, and no other lower interfaces. Therefore, we mainly rely on method (1) to enter this configuration. Each physical DSA master (LAG slave) retains its dev->dsa_ptr for when it becomes a standalone DSA master again. But the LAG master also has a dev->dsa_ptr, and this is actually duplicated from one of the physical LAG slaves, and therefore needs to be balanced when LAG slaves come and go. To the switch driver, putting DSA masters in a LAG is seen as putting their associated CPU ports in a LAG. We need to prepare cross-chip host FDB notifiers for CPU ports in a LAG, by calling the driver's ->lag_fdb_add method rather than ->port_fdb_add. Signed-off-by: Vladimir Oltean --- include/net/dsa.h | 6 ++ net/dsa/dsa_priv.h | 5 ++ net/dsa/master.c | 59 +++++++++++++++++ net/dsa/port.c | 2 +- net/dsa/slave.c | 157 +++++++++++++++++++++++++++++++++++++++++++-- net/dsa/switch.c | 22 +++++-- 6 files changed, 242 insertions(+), 9 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index 3f717c3fcba0..53de8effad60 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -300,6 +300,9 @@ struct dsa_port { u8 master_admin_up:1; u8 master_oper_up:1; + /* Valid only on user ports */ + u8 cpu_port_in_lag:1; + u8 setup:1; struct device_node *dn; @@ -724,6 +727,9 @@ static inline bool dsa_port_offloads_lag(struct dsa_port *dp, static inline struct net_device *dsa_port_to_master(const struct dsa_port *dp) { + if (dp->cpu_port_in_lag) + return dsa_port_lag_dev_get(dp->cpu_dp); + return dp->cpu_dp->master; } diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index d252a04ed725..5628cd5665b0 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -184,6 +184,11 @@ static inline int dsa_tag_protocol_overhead(const struct dsa_device_ops *ops) /* master.c */ int dsa_master_setup(struct net_device *dev, struct dsa_port *cpu_dp); void dsa_master_teardown(struct net_device *dev); +int dsa_master_lag_setup(struct net_device *lag_dev, struct dsa_port *cpu_dp, + struct netdev_lag_upper_info *uinfo, + struct netlink_ext_ack *extack); +void dsa_master_lag_teardown(struct net_device *lag_dev, + struct dsa_port *cpu_dp); static inline struct net_device *dsa_master_find_slave(struct net_device *dev, int device, int port) diff --git a/net/dsa/master.c b/net/dsa/master.c index 2176c14b97a8..9a15135f72db 100644 --- a/net/dsa/master.c +++ b/net/dsa/master.c @@ -428,3 +428,62 @@ void dsa_master_teardown(struct net_device *dev) */ wmb(); } + +int dsa_master_lag_setup(struct net_device *lag_dev, struct dsa_port *cpu_dp, + struct netdev_lag_upper_info *uinfo, + struct netlink_ext_ack *extack) +{ + bool master_setup = false; + struct net_device *lower; + struct list_head *iter; + int err; + + /* To be eligible as a DSA master, a LAG must have all lower + * interfaces be eligible DSA masters. + */ + netdev_for_each_lower_dev(lag_dev, lower, iter) { + if (!netdev_uses_dsa(lower)) { + NL_SET_ERR_MSG_MOD(extack, + "All LAG ports must be eligible as DSA masters"); + return -EINVAL; + } + } + + if (!netdev_uses_dsa(lag_dev)) { + err = dsa_master_setup(lag_dev, cpu_dp); + if (err) + return err; + } + + err = dsa_port_lag_join(cpu_dp, lag_dev, uinfo, extack); + if (err) { + NL_SET_ERR_MSG_MOD(extack, + "CPU port failed to join LAG"); + goto out_master_teardown; + } + + return 0; + +out_master_teardown: + if (master_setup) + dsa_master_teardown(lag_dev); + return err; +} + +/* Tear down a master if there isn't any other user port on it, + * optionally also destroying LAG information. + */ +void dsa_master_lag_teardown(struct net_device *lag_dev, + struct dsa_port *cpu_dp) +{ + struct net_device *upper; + struct list_head *iter; + + dsa_port_lag_leave(cpu_dp, lag_dev); + + netdev_for_each_upper_dev_rcu(lag_dev, upper, iter) + if (dsa_slave_dev_check(upper)) + return; + + dsa_master_teardown(lag_dev); +} diff --git a/net/dsa/port.c b/net/dsa/port.c index b719763fe97d..d152f7c7eb6d 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -1392,6 +1392,7 @@ static int dsa_port_assign_master(struct dsa_port *dp, return err; dp->cpu_dp = master->dsa_ptr; + dp->cpu_port_in_lag = netif_is_lag_master(master); return 0; } @@ -1411,7 +1412,6 @@ int dsa_port_change_master(struct dsa_port *dp, struct net_device *master, struct net_device *old_master = dsa_port_to_master(dp); struct net_device *dev = dp->slave; struct dsa_switch *ds = dp->ds; - int port = dp->index; bool vlan_filtering; int err, tmp; diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 00df6cf07866..1030988d797f 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -2840,6 +2840,10 @@ dsa_master_prechangeupper_sanity_check(struct net_device *master, if (netif_is_bridge_master(info->upper_dev)) return NOTIFY_DONE; + /* Allow LAG uppers */ + if (netif_is_lag_master(info->upper_dev)) + return NOTIFY_DONE; + extack = netdev_notifier_info_to_extack(&info->info); NL_SET_ERR_MSG_MOD(extack, @@ -2887,6 +2891,138 @@ dsa_bridge_prechangelower_sanity_check(struct net_device *new_lower, return NOTIFY_DONE; } +static void dsa_tree_migrate_ports_from_lag_master(struct dsa_switch_tree *dst, + struct net_device *lag_dev) +{ + struct net_device *new_master; + struct dsa_port *dp; + int err; + + new_master = dsa_tree_find_first_master(dst); + + dsa_tree_for_each_user_port(dp, dst) { + if (dsa_port_to_master(dp) != lag_dev) + continue; + + err = dsa_slave_change_master(dp->slave, new_master, NULL); + if (err) { + netdev_err(dp->slave, + "failed to restore master to %s: %pe\n", + new_master->name, ERR_PTR(err)); + } + } +} + +static int dsa_master_lag_join(struct net_device *master, + struct net_device *lag_dev, + struct netdev_lag_upper_info *uinfo, + struct netlink_ext_ack *extack) +{ + struct dsa_port *cpu_dp = master->dsa_ptr; + struct dsa_switch_tree *dst = cpu_dp->dst; + struct dsa_port *dp; + int err; + + err = dsa_master_lag_setup(lag_dev, cpu_dp, uinfo, extack); + if (err) + return err; + + dsa_tree_for_each_user_port(dp, dst) { + if (dsa_port_to_master(dp) != master) + continue; + + err = dsa_slave_change_master(dp->slave, lag_dev, extack); + if (err) + goto restore; + } + + return 0; + +restore: + dsa_tree_for_each_user_port_continue_reverse(dp, dst) { + if (dsa_port_to_master(dp) != lag_dev) + continue; + + err = dsa_slave_change_master(dp->slave, master, NULL); + if (err) { + netdev_err(dp->slave, + "failed to restore master to %s: %pe\n", + master->name, ERR_PTR(err)); + } + } + + dsa_master_lag_teardown(lag_dev, master->dsa_ptr); + + return err; +} + +static void dsa_master_lag_leave(struct net_device *master, + struct net_device *lag_dev) +{ + struct dsa_port *dp, *cpu_dp = lag_dev->dsa_ptr; + struct dsa_switch_tree *dst = cpu_dp->dst; + struct dsa_port *new_cpu_dp = NULL; + struct net_device *lower; + struct list_head *iter; + + netdev_for_each_lower_dev(lag_dev, lower, iter) { + if (netdev_uses_dsa(lower)) { + new_cpu_dp = lower->dsa_ptr; + break; + } + } + + if (new_cpu_dp) { + /* Update the CPU port of the user ports still under the LAG + * so that dsa_port_to_master() continues to work properly + */ + dsa_tree_for_each_user_port(dp, dst) + if (dsa_port_to_master(dp) == lag_dev) + dp->cpu_dp = new_cpu_dp; + + /* Update the index of the virtual CPU port to match the lowest + * physical CPU port + */ + lag_dev->dsa_ptr = new_cpu_dp; + wmb(); + } else { + /* If the LAG DSA master has no ports left, migrate back all + * user ports to the first physical CPU port + */ + dsa_tree_migrate_ports_from_lag_master(dst, lag_dev); + } + + /* This DSA master has left its LAG in any case, so let + * the CPU port leave the hardware LAG as well + */ + dsa_master_lag_teardown(lag_dev, master->dsa_ptr); +} + +static int dsa_master_changeupper(struct net_device *dev, + struct netdev_notifier_changeupper_info *info) +{ + struct netlink_ext_ack *extack; + int err = NOTIFY_DONE; + + if (!netdev_uses_dsa(dev)) + return err; + + extack = netdev_notifier_info_to_extack(&info->info); + + if (netif_is_lag_master(info->upper_dev)) { + if (info->linking) { + err = dsa_master_lag_join(dev, info->upper_dev, + info->upper_info, extack); + err = notifier_from_errno(err); + } else { + dsa_master_lag_leave(dev, info->upper_dev); + err = NOTIFY_OK; + } + } + + return err; +} + static int dsa_slave_netdevice_event(struct notifier_block *nb, unsigned long event, void *ptr) { @@ -2930,6 +3066,10 @@ static int dsa_slave_netdevice_event(struct notifier_block *nb, if (notifier_to_errno(err)) return err; + err = dsa_master_changeupper(dev, ptr); + if (notifier_to_errno(err)) + return err; + break; } case NETDEV_CHANGELOWERSTATE: { @@ -2937,12 +3077,21 @@ static int dsa_slave_netdevice_event(struct notifier_block *nb, struct dsa_port *dp; int err; - if (!dsa_slave_dev_check(dev)) - break; + if (dsa_slave_dev_check(dev)) { + dp = dsa_slave_to_port(dev); + + err = dsa_port_lag_change(dp, info->lower_state_info); + } - dp = dsa_slave_to_port(dev); + /* Mirror LAG port events on DSA masters that are in + * a LAG towards their respective switch CPU ports + */ + if (netdev_uses_dsa(dev)) { + dp = dev->dsa_ptr; + + err = dsa_port_lag_change(dp, info->lower_state_info); + } - err = dsa_port_lag_change(dp, info->lower_state_info); return notifier_from_errno(err); } case NETDEV_CHANGE: diff --git a/net/dsa/switch.c b/net/dsa/switch.c index 4dfd68cf61c5..5c2451fe5461 100644 --- a/net/dsa/switch.c +++ b/net/dsa/switch.c @@ -398,8 +398,15 @@ static int dsa_switch_host_fdb_add(struct dsa_switch *ds, dsa_switch_for_each_port(dp, ds) { if (dsa_port_host_address_match(dp, info->dp)) { - err = dsa_port_do_fdb_add(dp, info->addr, info->vid, - info->db); + if (dsa_port_is_cpu(dp) && info->dp->cpu_port_in_lag) { + err = dsa_switch_do_lag_fdb_add(ds, dp->lag, + info->addr, + info->vid, + info->db); + } else { + err = dsa_port_do_fdb_add(dp, info->addr, + info->vid, info->db); + } if (err) break; } @@ -419,8 +426,15 @@ static int dsa_switch_host_fdb_del(struct dsa_switch *ds, dsa_switch_for_each_port(dp, ds) { if (dsa_port_host_address_match(dp, info->dp)) { - err = dsa_port_do_fdb_del(dp, info->addr, info->vid, - info->db); + if (dsa_port_is_cpu(dp) && info->dp->cpu_port_in_lag) { + err = dsa_switch_do_lag_fdb_del(ds, dp->lag, + info->addr, + info->vid, + info->db); + } else { + err = dsa_port_do_fdb_del(dp, info->addr, + info->vid, info->db); + } if (err) break; } From patchwork Tue Aug 30 19:59:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12959837 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 479D8ECAAD5 for ; Tue, 30 Aug 2022 20:01:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231370AbiH3UBg (ORCPT ); Tue, 30 Aug 2022 16:01:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42962 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229979AbiH3UAy (ORCPT ); Tue, 30 Aug 2022 16:00:54 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2054.outbound.protection.outlook.com [40.107.20.54]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E716F419A2; Tue, 30 Aug 2022 13:00:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=USHtRrzwBrYKjomCRfjF5QLsapn/4fGuX0BbeyRBhmB4OUXRJ8rZEkDhjUCBpW43cD3B9Q4TdFR7xtsANCAXUCBuL9hpFYaOYsafE3wKPS12tDbbFJbLXhfWHpr+z0T5ZahVXJczKFtmoya3LWbu8IDn0HcjO1Qr/MVLb2Ctt9tGiX0XPDz1SAkEWZi1TyyLXlRHOo2MZ4XQE6N1wjYNDyyZloDj8b7Lylfa+9z/cc5On2RPSJhfDHJTQepUgLclg/DiyTZ8OrlFOkpgRzTb4V3b3Miw/b2ydZ2FrXDaZlhSFRkF78n1ozWyCSDvcWFOK7jYauj4IGbz8atX0kUGHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=dHaqs425Z+4EgFP4Z20fZXkhVwDWNtFw8OZJfJzvcmg=; b=CW6+Ft+hFtDe9dG7T3s8AorrGhH0TwkaidudumWTQqNvJfHLhpLjkWpkKFMFUJJNoZ2fgSFQnA+mkltIdhKrBt13nrYrCNRW7DrvTt7AVqsNprPaRPm84+3sqotzFxX+HV8zC4KvkdbjQw/0MbcEWIpf+6RuTNMB0XK4Q5jl6WOr/t5ZqE+xjVBPZM/q2c0COoBIKYnw3hoFvUwMHt6edkKXNmzL3h9IM1Vy8/HQYklaH7M4SWIYQHC3G8w980u5F/JmH10HmfbVL+z4WYx1M2pF35mZsfP0X9S38Zm+APaghUoJK7/xhucGr0cyg0K6PS0IUdLeS7JJIuTS8D+4xg== 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=dHaqs425Z+4EgFP4Z20fZXkhVwDWNtFw8OZJfJzvcmg=; b=DnI55HVdnWbhBNUEwskLeGaDD5GBEGtTfKhOIRW0sO2MHU3uEfUgA+UvZX7cm7teOK4rdWTL6T6VlJDod1nHSigWye0m1f86/QMhaEgdVELWzvkRqQPO1qdJlFbqBhdyCOsgiJE7URfKBj1rocxTMwoGS4XJo90cOe0MXIvV3QQ= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6270.eurprd04.prod.outlook.com (2603:10a6:803:fb::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.21; Tue, 30 Aug 2022 20:00:00 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3412:9d57:ec73:fef3]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3412:9d57:ec73:fef3%5]) with mapi id 15.20.5588.010; Tue, 30 Aug 2022 20:00:00 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Florian Fainelli , Vivien Didelot , Andrew Lunn , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Colin Foster , Roopa Prabhu , Nikolay Aleksandrov , Tobias Waldekranz , =?utf-8?q?Marek_Beh=C3=BAn?= , Ansuel Smith , DENG Qingfang , =?utf-8?q?Alvin_=C5=A0ipraga?= , Linus Walleij , Luiz Angelo Daros de Luca , Felix Fietkau , John Crispin , Sean Wang Subject: [PATCH net-next 8/9] docs: net: dsa: update information about multiple CPU ports Date: Tue, 30 Aug 2022 22:59:31 +0300 Message-Id: <20220830195932.683432-9-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220830195932.683432-1-vladimir.oltean@nxp.com> References: <20220830195932.683432-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: BE0P281CA0005.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:a::15) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 7c7bf1d8-608a-4d52-9cc0-08da8ac235b5 X-MS-TrafficTypeDiagnostic: VI1PR04MB6270:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2YklfE6vYO7q06/sDbL8Z9zNNftr7PxZtkebPAcAwyN7zsIlqdTScyjtQ0IV0gV/GbL3UMp59+sdw8O+cGrvP9y+vVWovTTSvTaS4ziLoUQk7op8H0xmpWdbo1u3dynO/O2soyKripY8c8yGwWkKwVVZ1DTJa1MS63rxc/6n8ZdKBJw9LyeSZDhM69n3BMb7GHN0oPHWa7/xF8y2GdDk960YgDxQgv3aqOuxwL7JTRddmRM4tCaMhU0xhGJFBeWQktlvqgk7ntwOOZq9ZAhzANXeWUxRkWwScCL7168HCW+BL4rfP016Qlcu4JMXbg5386T5SE3nmbzNRpNABFBVvr5IcuGgn3ML2iRVpplpBCZqU8VcI2umcxhBRzKcMP6DQ4yJjK08wXMFPJu0T+uXS4ko5XYe2EbK9CgN4M9CC37yttzqhHYxNdXmoEQ87pPlBv48XK6FTzyzwPHOyT1CXviOG6A5VbOE3dc7Q1vujxFQBWciajkFE30b89xaVcimD4psckixGXDrAm9rbyUlqCbS4zpDu0lHDTnqnQea7bIMo7Y8LQOC3jVr+rQrH/lbnNn3I0hDeUzyTWzjn1JycpBOAdpw28BR878wo1EAz2Y6iWVBmeg963V11wraIxr08Amj/vT+vCaMakq0L8KK9f5XIkqsLWt3NmGuwMc/SSC5vhBF5ay1fDj1Uv6qvdpfxEtUPYzKUa8sSHlqT2TWyzvuV2EySI5JjPVxzpgaNNHcWDtoyBp5mV4ItCbICbhn6VHkyonrBSO/x+xzHUlBLak0DJ/YIrEp3+lVV7RaL7Q= 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:(13230016)(4636009)(396003)(346002)(366004)(39860400002)(136003)(376002)(41300700001)(66476007)(6486002)(8676002)(4326008)(66946007)(478600001)(66556008)(52116002)(2906002)(83380400001)(966005)(44832011)(26005)(5660300002)(6506007)(6512007)(7416002)(6666004)(15650500001)(8936002)(2616005)(316002)(86362001)(6916009)(54906003)(36756003)(38350700002)(1076003)(38100700002)(186003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DJXwP6RGKs5sxwWARUItrsZUkun2X2SC5ZFzzdEYFH4DYW7l/Ih065w/QhaIeSN7SedSVfG/Ni0EpYGuANDTlCoxFcU/uIVBpdBQOE4KaMXbrNYeCTchy0gQri+czGbltFD4I9hbP31QJjoeF32EHRJ7xQIbImaQVV+58nhMj6+eE5joOTU0GLCo3W0FFk7p4pY5qTJHeQfKT1QUi2ZM3Y6viZkJ/csYksQSYyMUdJP7/lCl7p9tFPS3NA5zCprJ7UERYiVBI/bY1/ciUQmOQWpGO+XwMViqkme30XlKx2YJ+WkOQLQxR6zPvzm32cz0EYUSlkHa38VFK/HucsNDXitXd+nCVY8JEzVNjYJkGXC4jYOl/deV2nO0p1Qua6Xx5NZmls9UNlQmbhTXxGM85o6x0grt8Bc7k8l6uCHUFSx785yl/YvfEsKk8fJ32rmJlApPNTG4Pw+zf9MTfsHKU/SvDUxg9V7SJn5TmRORdjed16HCdIXrfEb/UeaaNJR10v7ol8sAbj3YU75Bq5bxMsLlexewupqPmWBTLydT4Y/MLkPG8GPOU3BoeHiqZz5pUqobv6SR2sZfvqcN0yvKNeW9JfNz2m/fY0Feuh0PZRYvHeJOanG7GuEDSaRRHoDUJ2bQaBunW0XYoVhUUbnH8Buf15WFYAgLZlr5peGkBQba2NgBPpgXzGYi/sLg8Oo5e3+/xdxgOh+HJUw8o27Gzg5uZSgn36RFwF4Ul0F038o/+FWEpdxfOe8D6t+puaNPIRHCWobv/IfhA58rawBovA5MQMy/H45lG+ULvbDAMn1WSm08KlJdSgwAsBA8nw5+IkCcvIsM+PgZlOFBQIJAxQtFweTPca+L+OD6NpOvGtvZ1ZaeUMvBEDHi2xCPxhknPLdOIQZsf/VGsYLe3/pxA0DBewU/qBFU/Ok2VHRI7evDiWAG9SyCF6TmUPmyg8rEn5zEUU/tHcZGnbknnfx3QxvUhh/JKn5fWJ8lLoqOsyD82zWZCFhQQ9jkGmoP9JHYPrWdHySg3I6nb2BpSxIxBWbSh9Jj3g+kXh3Ua4TIYe6zQCYeU8Hrd7u6sCudGtNbTVNmLrFGjiWfNarcvWGVGkvD1tX8l9TyUOvBVI3PdHMP12ogoxV1jlFlHfodyrw7+b3TVLJc9uZYHUOct46XGNp1+oNqPRgh5MzzF5hbowO4u10uj2pnyruDD92jHy0Wep4aySY968jHJBTt7s5MSE43gukCzAQX89dQQBZLZr9fi80MOKnRBUa/GLrxV65k3KLVPOap72QSQjeLG+Zo/3LSX6fHfGoSZPJyQ512KghghZXkgHNCgx8qCB9KZl2SfsvOdx5QU+wytepzfweUDWTqBP1Z84U2akOVXVe076BZEpjHgLrJBf8wT1wsZ7sV/rMwNjmmR8AQmse6xcY0Ns/Xy9LR8n7i492rT5sTqMRLRHjDFfm+VKDg8FYWbvUdnHDLFFP3wNf1dxS05+A6WedLPWBl6UNvQh1BGzUAjY0dAtD8/t4oYt9qDrO2OSFZrHY1nMTHPgZPiqAB/1SOOTHHb2HEdE5/SR9OLM9ySB7MhSUDXuKaUvCiwFHIpHuC7zmI+uxi47H7AsLQmWezsw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7c7bf1d8-608a-4d52-9cc0-08da8ac235b5 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Aug 2022 19:59:55.7760 (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: Vjy8z+9DTMJKBEyy+982JutqXfOhiDDoxlIEa8+1u6klCXFJ+CA9WgiyoMpB0asqcC7ZDdtxUvrKIFIfIHBIkg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6270 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org DSA now supports multiple CPU ports, explain the use cases that are covered, the new UAPI, the permitted degrees of freedom, the driver API, and remove some old "hanging fruits". Signed-off-by: Vladimir Oltean --- .../networking/dsa/configuration.rst | 84 +++++++++++++++++++ Documentation/networking/dsa/dsa.rst | 38 +++++++-- 2 files changed, 116 insertions(+), 6 deletions(-) diff --git a/Documentation/networking/dsa/configuration.rst b/Documentation/networking/dsa/configuration.rst index 2b08f1a772d3..5c49c1eef8bb 100644 --- a/Documentation/networking/dsa/configuration.rst +++ b/Documentation/networking/dsa/configuration.rst @@ -49,6 +49,9 @@ In this documentation the following Ethernet interfaces are used: *eth0* the master interface +*eth1* + another master interface, by default unused + *lan1* a slave interface @@ -360,3 +363,84 @@ the ``self`` flag) has been removed. This results in the following changes: Script writers are therefore encouraged to use the ``master static`` set of flags when working with bridge FDB entries on DSA switch interfaces. + +Affinity of user ports to CPU ports +----------------------------------- + +Typically, DSA switches are attached to the host via a single Ethernet +interface, but in cases where the switch chip is discrete, the hardware design +may permit the use of 2 or more ports connected to the host, for an increase in +termination throughput. + +DSA can make use of multiple CPU ports in two ways. First, it is possible to +statically assign the termination traffic associated with a certain user port +to be processed by a certain CPU port. This way, user space can implement +custom policies of static load balancing between user ports, by spreading the +affinities according to the available CPU ports. + +Secondly, it is possible to perform load balancing between CPU ports on a per +packet basis, rather than statically assigning user ports to CPU ports. +This can be achieved by placing the DSA masters under a LAG interface (bonding +or team). DSA monitors this operation and creates a mirror of this software LAG +on the CPU ports facing the physical DSA masters that constitute the LAG slave +devices. + +To make use of multiple CPU ports, the firmware (device tree) description of +the switch must mark all the links between CPU ports and their DSA masters +using the ``ethernet`` reference/phandle. At startup, only a single CPU port +and DSA master will be used - the numerically first port from the firmware +description which has an ``ethernet`` property. It is up to the user to +configure the system for the switch to use other masters. + +DSA uses the ``rtnl_link_ops`` mechanism (with a "dsa" ``kind``) to allow +changing the DSA master of a user port. The ``IFLA_DSA_MASTER`` u32 netlink +attribute contains the ifindex of the master device that handles each slave +device. The DSA master must be a valid candidate based on firmware node +information, or a LAG interface which contains only slaves which are valid +candidates. + +Using iproute2, the following manipulations are possible: + + .. code-block:: sh + + # See the DSA master in current use + ip -d link show dev swp0 + (...) + dsa master eth0 + + # Static CPU port distribution + ip link set swp0 type dsa master eth1 + ip link set swp1 type dsa master eth0 + ip link set swp2 type dsa master eth1 + ip link set swp3 type dsa master eth0 + + # CPU ports in LAG + ip link add bond0 type bond mode balance-xor && ip link set bond0 up + ip link set eth0 down && ip link set eth0 master bond0 + ip link set eth1 down && ip link set eth1 master bond0 + ip -d link show dev swp0 + (...) + dsa master bond0 + +Notice that in the case of CPU ports under a LAG, the use of the +``IFLA_DSA_MASTER`` netlink attribute is not strictly needed, but rather, DSA +reacts to the ``IFLA_MASTER`` attribute change of its present master (``eth0``) +and migrates all user ports to the new upper of ``eth0``, ``bond0``. Similarly, +when ``bond0`` is destroyed using ``RTM_DELLINK``, DSA migrates the user ports +that were assigned to this interface to the first physical DSA master which is +eligible, based on the firmware description (it effectively reverts to the +startup configuration). + +In a setup with more than 2 physical CPU ports, it is therefore possible to mix +static user to CPU port assignment with LAG between DSA masters. It is not +possible to statically assign a user port towards a DSA master that has any +upper interfaces (this includes LAG devices - the master must always be the LAG +in this case). + +Live changing of the DSA master (and thus CPU port) affinity of a user port is +permitted, in order to allow dynamic redistribution in response to traffic. + +Physical DSA masters are allowed to join and leave at any time a LAG interface +used as a DSA master; however, DSA will reject a LAG interface as a valid +candidate for being a DSA master unless it has at least one physical DSA master +as a slave device. diff --git a/Documentation/networking/dsa/dsa.rst b/Documentation/networking/dsa/dsa.rst index d742ba6bd211..a94ddf83348a 100644 --- a/Documentation/networking/dsa/dsa.rst +++ b/Documentation/networking/dsa/dsa.rst @@ -303,6 +303,20 @@ These frames are then queued for transmission using the master network device Ethernet switch will be able to process these incoming frames from the management interface and deliver them to the physical switch port. +When using multiple CPU ports, it is possible to stack a LAG (bonding/team) +device between the DSA slave devices and the physical DSA masters. The LAG +device is thus also a DSA master, but the LAG slave devices continue to be DSA +masters as well (just with no user port assigned to them; this is needed for +recovery in case the LAG DSA master disappears). Thus, the data path of the LAG +DSA master is used asymmetrically. On RX, the ``ETH_P_XDSA`` handler, which +calls ``dsa_switch_rcv()``, is invoked early (on the physical DSA master; +LAG slave). Therefore, the RX data path of the LAG DSA master is not used. +On the other hand, TX takes place linearly: ``dsa_slave_xmit`` calls +``dsa_enqueue_skb``, which calls ``dev_queue_xmit`` towards the LAG DSA master. +The latter calls ``dev_queue_xmit`` towards one physical DSA master or the +other, and in both cases, the packet exits the system through a hardware path +towards the switch. + Graphical representation ------------------------ @@ -629,6 +643,24 @@ Switch configuration PHY cannot be found. In this case, probing of the DSA switch continues without that particular port. +- ``port_change_master``: method through which the affinity (association used + for traffic termination purposes) between a user port and a CPU port can be + changed. By default all user ports from a tree are assigned to the first + available CPU port that makes sense for them (most of the times this means + the user ports of a tree are all assigned to the same CPU port, except for H + topologies as described in commit 2c0b03258b8b). The ``port`` argument + represents the index of the user port, and the ``master`` argument represents + the new DSA master ``net_device``. The CPU port associated with the new + master can be retrieved by looking at ``struct dsa_port *cpu_dp = + master->dsa_ptr``. Additionally, the master can also be a LAG device where + all the slave devices are physical DSA masters. LAG DSA masters also have a + valid ``master->dsa_ptr`` pointer, however this is not unique, but rather a + duplicate of the first physical DSA master's (LAG slave) ``dsa_ptr``. In case + of a LAG DSA master, a further call to ``port_lag_join`` will be emitted + separately for the physical CPU ports associated with the physical DSA + masters, requesting them to create a hardware LAG associated with the LAG + interface. + PHY devices and link management ------------------------------- @@ -1095,9 +1127,3 @@ capable hardware, but does not enforce a strict switch device driver model. On the other DSA enforces a fairly strict device driver model, and deals with most of the switch specific. At some point we should envision a merger between these two subsystems and get the best of both worlds. - -Other hanging fruits --------------------- - -- allowing more than one CPU/management interface: - http://comments.gmane.org/gmane.linux.network/365657 From patchwork Tue Aug 30 19:59:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12959838 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2FD6ECAAA1 for ; Tue, 30 Aug 2022 20:01:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231791AbiH3UBs (ORCPT ); Tue, 30 Aug 2022 16:01:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231887AbiH3UA4 (ORCPT ); Tue, 30 Aug 2022 16:00:56 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2063.outbound.protection.outlook.com [40.107.20.63]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1301A27B35; Tue, 30 Aug 2022 13:00:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Oq8Oo9nud9ifiIvPpWPm2ir4qbkoQVBnBialKczxd/xgUiNgVi+z1AE+VQMjo0Xc+lnARxgJGYP09vLxGHy6QEUl4bnyYnb9AhV6QgncSD1R27A70dwGgiibCxxQNJP7HDrQi3EjlmxrnKDwiLSDd7lGJjamZoDD+HceXXKSxpqqKoe8/FOVZOgRZW6OmdPkmxxvgBNaxbfvvO3aN3FQXMTGqyuRY5JQ+rtUhj6xoRM0CNNE6APK8wZ6krfyogMZ2Ncl2I4RLUG2YG1wGIRgzUQHXntSx4sxwsfJAAk45sKLBabmj8jb2rUsJ09wkNs2+zxouLqOWWTCjKDpVFCMjw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XJ+5l8ZVZIfOaR90pE2Y7Vd0lgUj26CMFgln7XGVys4=; b=nb7MOyO8jCoYhkIJkSaCs8OOLOll4zGsZJa4ziaHTB9+8VMSW2GtPzAooCBnMx+4Jq/aSss5DL60M32+h9ycqqmN8QJEsRETNV+NN+NnBLvAioSJCwrCJ46xZEO9X6nqe5RRQm2WZdOQLaMVdar4wzuqIoxkRySqtR1ZnR/n+n0vXwB+nl3MCpFqX7nyq47OxSmaOnzVvZyvyxo9gljuvzspcyjSnzPTcBpgwBsPf+8FsNntopZdsy5VbCVM+nSFny1pH4JfP+X0ZHtpUaBtdDpcXgYHdtJqIGN7RdxXb8bKdBf1F7u4oD3iqp41HSITyQDNiY0JvplKe7iMTSdjSQ== 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=XJ+5l8ZVZIfOaR90pE2Y7Vd0lgUj26CMFgln7XGVys4=; b=JYVaUUDj4qIDg5U37Hm5hCe3rRtYAmM/hiACajr3FgCfLYjUG/TTVOt6+DyCo8nGJkoXUsj02az8NBrBwy0Xrd+piq4wZQ8KmVcnhrJQ+Hdlzx+ohw9f7fN7MgbN6Zacj+USX0buYSzgTkvZ8N+RgE4eU6VgS4oIu3OkSkBsus8= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6270.eurprd04.prod.outlook.com (2603:10a6:803:fb::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5566.21; Tue, 30 Aug 2022 20:00:04 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3412:9d57:ec73:fef3]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::3412:9d57:ec73:fef3%5]) with mapi id 15.20.5588.010; Tue, 30 Aug 2022 20:00:04 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org, "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni , Florian Fainelli , Vivien Didelot , Andrew Lunn , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Colin Foster , Roopa Prabhu , Nikolay Aleksandrov , Tobias Waldekranz , =?utf-8?q?Marek_Beh=C3=BAn?= , Ansuel Smith , DENG Qingfang , =?utf-8?q?Alvin_=C5=A0ipraga?= , Linus Walleij , Luiz Angelo Daros de Luca , Felix Fietkau , John Crispin , Sean Wang Subject: [PATCH net-next 9/9] net: dsa: felix: add support for changing DSA master Date: Tue, 30 Aug 2022 22:59:32 +0300 Message-Id: <20220830195932.683432-10-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220830195932.683432-1-vladimir.oltean@nxp.com> References: <20220830195932.683432-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: BE0P281CA0005.DEUP281.PROD.OUTLOOK.COM (2603:10a6:b10:a::15) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 42e427b7-ec6d-4dce-eb04-08da8ac236ed X-MS-TrafficTypeDiagnostic: VI1PR04MB6270:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KKT8a3AkH9CuulDVqDo2AiiRGb6VvjK4KVA0cHYKmAIHc+NjB0X8BWcHzd0Qe6wdHJDr560sxRQDCgmw9lHsu7PUXm+MkpkqTc0AoWSVacr4EuvA/exvNbDmXCgxpCwj5ORK5VDi9svGo//hscCKBFBBuW//odNpHOMyPkT/zC582ur/0MHHm/kjy+LnwIgIE8gYqgRAw7kI+CeuATtrvXsp2Ki2gmkSwybsmhN9Z9HDlD1SCulCBvvxAiY1xztaRasfKSuRY6109k/GqWKJ/55A23LPagk7kkXiQnZS4WcK8C8FrTwWQF2t6CsAxTdvfUVevuMhW4+ln4EEP5VeN/EEXde53bPrToAry6kuFR7GYw0ZckeEN0sDdC4aRdJW/KeBkmQfpslfIBFhHUR3g77MSn8lHIjBmEWICfj2GJ1vmaRGrfg0X46r5hRUpjITvohfOeWz5ReNvYY4Xib0hMesu+mEfyhmxV3RhnFWALhotCp1VTfppLU4/Sr4UBET1+5ym6/iSZtHr4UHiOak/v3TX0x8sWVxj/Zokiy1lYeJNLOCDEYrRYzUak2qtxZOkmW3G7KSp+OSYxI1ER489fVaoHFoVCyBehcJrMSKbA33jvtgJBzKvhPBAjODbxROEhChwPzS3NM3egEAwmcZNx2UnsXrTOlJJ5XX7wPNYxu4XBmPfdnNaVB8Ooh9Qp+v2U6sRAH19aai4qDZ53cS+szboYQitG1+6WE+oHUo8mNupQpdreGsDwMPjZ3JxhAX6ktSqjvvmgopB2YM0b+OJVmRepFpznWeLeaSguHYFZ4= 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:(13230016)(4636009)(396003)(346002)(366004)(39860400002)(136003)(376002)(41300700001)(66476007)(6486002)(8676002)(4326008)(66946007)(478600001)(66556008)(52116002)(2906002)(83380400001)(44832011)(26005)(5660300002)(6506007)(6512007)(7416002)(6666004)(30864003)(8936002)(2616005)(316002)(86362001)(6916009)(54906003)(36756003)(38350700002)(1076003)(38100700002)(186003)(309714004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /axK7oufvu/BAhq8hk1T5CvPbdkQtra4F0vX63ceCirq9+700fy6ndSEhhzXacJ5uC1jiz9yojJzASSw6xBtcEAdCTeRmIZojzXigg4VArIGZp15J5w3SOsUPGwAkR0msuCGa1bqz7F9SnA2dg2/npfFIanJVC0IXhcyPx4t34NfW5vVRJxfAJA96gpN9GmJRso5eF0g7tBgSuQ6DPfWJmPihkM7wdRa09Q2SZIsSU1rJCW0BMpa1TK2P8L80IMOUlEzdTAbR6Mj5l3b+ZRerjIj4lGmwW/A2r3P53GJCaJ0eZUNVSEd6ZUngfAnttFN7dz3vYqeQA9seW2k8aD3ZL51jNwPh1pHhzIfD0QUrs1IGYtC2WK7Ib2xSi1Uzsq7TIIKhstZBxtfTc2a6ERE/XTpSnYfX/QeoHxksDssqr+F/Zb4hbVJNdqtUu4x8wgg+8izw9MpmnOOVLnPbpoSAdponTAFu8YUkPODDWjcjQjL6pdFw+WJ2uXZmGkyADhgFwHERB6n7g31Pg81BImdAPbs3p10bzwuB9shI4oqn20BD5RjviyjMmb4sY7TB7zkn1lxk9gg4aF6aaVZ1i0gHakzIPjXhCkxQ1MHAUQmihbOPZVgnivJH/lb9Q8AqnKnbtM5ynxmA2Bfh+8/W2hvvTxSaW286hHcmFOjUQYJVc03z0+3ODswahQNQXY5p0wmF8ji/m5iziQprxZi5jfxt56ExTDGP/l8uoJnwC58o1uFSD3jtZE7RQsOuHtOPVvRIdcwtq10fBox17tsR+gPSwUB3W4cC3LcaMRRuq8UI7m7Rh/m8AUTaYShK+4G6FK6150dDVxPNyf2EyU7iGDlSkcqBZb+dRkkdWNICWKd9nRGFHLiMb3hdLp5z4gBOyofToAs5YxCwp5Pe69liP9pgTkvTH4etd4TSHeOdt1H93VM00J6w0bH7+71+DwpWK0efNF0lDmQvrIoWdm1KiuH3DA0P9qFTkw4uG9i/AcizxGK9mws/z0A0GueabozV6rMaTtFwyCtbMUx4cpAJgEY27LHVN0rNSK6ND3r3Ciio17RrgYKxApUb7/lRQIzrPMMuHg9KENnVHyFsUqkctSkb2T41Ey4StA4FI0q0onET2oIVio6BKYkoYzcj5fu39HLx8AZW8EaXeW/ef/+aDmPr3hBZT87Waev4ykpluAtd3XbIMf7RlafuFD032FytV5Otx8qkZqiotNRaMwEczv3yQjz28sTcVsDBcYuWbaUEA60kkcYiFXL075EVAo/d590jrfH7enNDZaleshlz7Z5dMOYO09ir3+I3ycMS2+HzaGh5qahPHlNCM+Y2VxNL2V5jE+1Vm+CM94lXwzDFxnmOMHnVFI1usWs/k+j1diD3EBHm3H03rUckh3DrDQBgSWqdD+4mci7BjPzHkoYiIck20H62Kg6CMn4n9FbM1vVcWzKcqJjZlOEkMxbr5KPoO9uJOVWqpVuNgewlH9iCX0cjdwhKMQILbzosi/27kMl/829d/NPKuD7YA3SYbgzUP2Wo777pvDHvDxLju55MwzlTwGYIYS0FOiAISooJpjmks+w173hsGqyOnNlNQICwG/ingAMmcqqX+SCOR2MHvv7zg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 42e427b7-ec6d-4dce-eb04-08da8ac236ed X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Aug 2022 19:59:57.8227 (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: TQrMaqKO/hj6iVNdfhs6VNVCSX+QmM22jjcGRNvzZDDQAcfNcyfvqttnL8rbW16/vBvfs2bCuvEfxSwjPhjg9A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6270 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Changing the DSA master means different things depending on the tagging protocol in use. For NPI mode ("ocelot" and "seville"), there is a single port which can be configured as NPI, but DSA only permits changing the CPU port affinity of user ports one by one. So changing a user port to a different NPI port globally changes what the NPI port is, and breaks the user ports still using the old one. To address this while still permitting the change of the NPI port, require that the user ports which are still affine to the old NPI port are down, and cannot be brought up until they are all affine to the same NPI port. The tag_8021q mode ("ocelot-8021q") is more flexible, in that each user port can be freely assigned to one CPU port or to the other. This works by filtering host addresses towards both tag_8021q CPU ports, and then restricting the forwarding from a certain user port only to one of the two tag_8021q CPU ports. Additionally, the 2 tag_8021q CPU ports can be placed in a LAG. This works by enabling forwarding via PGID_SRC from a certain user port towards the logical port ID containing both tag_8021q CPU ports, but then restricting forwarding per packet, via the LAG hash codes in PGID_AGGR, to either one or the other. When we change the DSA master to a LAG device, DSA guarantees us that the LAG has at least one lower interface as a physical DSA master. But DSA masters can come and go as lowers of that LAG, and ds->ops->port_change_master() will not get called, because the DSA master is still the same (the LAG). So we need to hook into the ds->ops->port_lag_{join,leave} calls on the CPU ports and update the logical port ID of the LAG that user ports are assigned to. Signed-off-by: Vladimir Oltean --- drivers/net/dsa/ocelot/felix.c | 117 ++++++++++++++++++++++++++++- drivers/net/dsa/ocelot/felix.h | 3 + drivers/net/ethernet/mscc/ocelot.c | 3 +- include/soc/mscc/ocelot.h | 1 + 4 files changed, 121 insertions(+), 3 deletions(-) diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c index ee19ed96f284..bf9efb4aec6b 100644 --- a/drivers/net/dsa/ocelot/felix.c +++ b/drivers/net/dsa/ocelot/felix.c @@ -42,6 +42,25 @@ static struct net_device *felix_classify_db(struct dsa_db db) } } +static int felix_cpu_port_for_master(struct dsa_switch *ds, + struct net_device *master) +{ + struct ocelot *ocelot = ds->priv; + struct dsa_port *cpu_dp; + int lag; + + if (netif_is_lag_master(master)) { + mutex_lock(&ocelot->fwd_domain_lock); + lag = ocelot_bond_get_id(ocelot, master); + mutex_unlock(&ocelot->fwd_domain_lock); + + return lag; + } + + cpu_dp = master->dsa_ptr; + return cpu_dp->index; +} + /* Set up VCAP ES0 rules for pushing a tag_8021q VLAN towards the CPU such that * the tagger can perform RX source port identification. */ @@ -422,6 +441,39 @@ static unsigned long felix_tag_npi_get_host_fwd_mask(struct dsa_switch *ds) return BIT(ocelot->num_phys_ports); } +static int felix_tag_npi_change_master(struct dsa_switch *ds, int port, + struct net_device *master, + struct netlink_ext_ack *extack) +{ + struct dsa_port *dp = dsa_to_port(ds, port), *other_dp; + struct ocelot *ocelot = ds->priv; + + if (netif_is_lag_master(master)) { + NL_SET_ERR_MSG_MOD(extack, "LAG DSA master only supported using ocelot-8021q"); + return -EOPNOTSUPP; + } + + /* Changing the NPI port breaks user ports still assigned to the old + * one, so only allow it while they're down, and don't allow them to + * come back up until they're all changed to the new one. + */ + dsa_switch_for_each_user_port(other_dp, ds) { + struct net_device *slave = other_dp->slave; + + if (other_dp != dp && (slave->flags & IFF_UP) && + dsa_port_to_master(other_dp) != master) { + NL_SET_ERR_MSG_MOD(extack, + "Cannot change while old master still has users"); + return -EOPNOTSUPP; + } + } + + felix_npi_port_deinit(ocelot, ocelot->npi); + felix_npi_port_init(ocelot, felix_cpu_port_for_master(ds, master)); + + return 0; +} + /* Alternatively to using the NPI functionality, that same hardware MAC * connected internally to the enetc or fman DSA master can be configured to * use the software-defined tag_8021q frame format. As far as the hardware is @@ -433,6 +485,7 @@ static const struct felix_tag_proto_ops felix_tag_npi_proto_ops = { .setup = felix_tag_npi_setup, .teardown = felix_tag_npi_teardown, .get_host_fwd_mask = felix_tag_npi_get_host_fwd_mask, + .change_master = felix_tag_npi_change_master, }; static int felix_tag_8021q_setup(struct dsa_switch *ds) @@ -507,10 +560,24 @@ static unsigned long felix_tag_8021q_get_host_fwd_mask(struct dsa_switch *ds) return dsa_cpu_ports(ds); } +static int felix_tag_8021q_change_master(struct dsa_switch *ds, int port, + struct net_device *master, + struct netlink_ext_ack *extack) +{ + int cpu = felix_cpu_port_for_master(ds, master); + struct ocelot *ocelot = ds->priv; + + ocelot_port_unassign_dsa_8021q_cpu(ocelot, port); + ocelot_port_assign_dsa_8021q_cpu(ocelot, port, cpu); + + return felix_update_trapping_destinations(ds, true); +} + static const struct felix_tag_proto_ops felix_tag_8021q_proto_ops = { .setup = felix_tag_8021q_setup, .teardown = felix_tag_8021q_teardown, .get_host_fwd_mask = felix_tag_8021q_get_host_fwd_mask, + .change_master = felix_tag_8021q_change_master, }; static void felix_set_host_flood(struct dsa_switch *ds, unsigned long mask, @@ -673,6 +740,16 @@ static void felix_port_set_host_flood(struct dsa_switch *ds, int port, !!felix->host_flood_mc_mask, true); } +static int felix_port_change_master(struct dsa_switch *ds, int port, + struct net_device *master, + struct netlink_ext_ack *extack) +{ + struct ocelot *ocelot = ds->priv; + struct felix *felix = ocelot_to_felix(ocelot); + + return felix->tag_proto_ops->change_master(ds, port, master, extack); +} + static int felix_set_ageing_time(struct dsa_switch *ds, unsigned int ageing_time) { @@ -864,8 +941,17 @@ static int felix_lag_join(struct dsa_switch *ds, int port, struct netdev_lag_upper_info *info) { struct ocelot *ocelot = ds->priv; + int err; - return ocelot_port_lag_join(ocelot, port, lag.dev, info); + err = ocelot_port_lag_join(ocelot, port, lag.dev, info); + if (err) + return err; + + /* Update the logical LAG port that serves as tag_8021q CPU port */ + if (!dsa_is_cpu_port(ds, port)) + return 0; + + return felix_port_change_master(ds, port, lag.dev, NULL); } static int felix_lag_leave(struct dsa_switch *ds, int port, @@ -875,7 +961,11 @@ static int felix_lag_leave(struct dsa_switch *ds, int port, ocelot_port_lag_leave(ocelot, port, lag.dev); - return 0; + /* Update the logical LAG port that serves as tag_8021q CPU port */ + if (!dsa_is_cpu_port(ds, port)) + return 0; + + return felix_port_change_master(ds, port, lag.dev, NULL); } static int felix_lag_change(struct dsa_switch *ds, int port) @@ -1013,6 +1103,27 @@ static void felix_phylink_mac_link_up(struct dsa_switch *ds, int port, felix->info->port_sched_speed_set(ocelot, port, speed); } +static int felix_port_enable(struct dsa_switch *ds, int port, + struct phy_device *phydev) +{ + struct dsa_port *dp = dsa_to_port(ds, port); + struct ocelot *ocelot = ds->priv; + + if (!dsa_port_is_user(dp)) + return 0; + + if (ocelot->npi >= 0) { + struct net_device *master = dsa_port_to_master(dp); + + if (felix_cpu_port_for_master(ds, master) != ocelot->npi) { + dev_err(ds->dev, "Multiple masters are not allowed\n"); + return -EINVAL; + } + } + + return 0; +} + static void felix_port_qos_map_init(struct ocelot *ocelot, int port) { int i; @@ -1857,6 +1968,7 @@ const struct dsa_switch_ops felix_switch_ops = { .phylink_mac_select_pcs = felix_phylink_mac_select_pcs, .phylink_mac_link_down = felix_phylink_mac_link_down, .phylink_mac_link_up = felix_phylink_mac_link_up, + .port_enable = felix_port_enable, .port_fast_age = felix_port_fast_age, .port_fdb_dump = felix_fdb_dump, .port_fdb_add = felix_fdb_add, @@ -1912,6 +2024,7 @@ const struct dsa_switch_ops felix_switch_ops = { .port_add_dscp_prio = felix_port_add_dscp_prio, .port_del_dscp_prio = felix_port_del_dscp_prio, .port_set_host_flood = felix_port_set_host_flood, + .port_change_master = felix_port_change_master, }; struct net_device *felix_port_to_netdev(struct ocelot *ocelot, int port) diff --git a/drivers/net/dsa/ocelot/felix.h b/drivers/net/dsa/ocelot/felix.h index deb8dde1fc19..e4fd5eef57a0 100644 --- a/drivers/net/dsa/ocelot/felix.h +++ b/drivers/net/dsa/ocelot/felix.h @@ -71,6 +71,9 @@ struct felix_tag_proto_ops { int (*setup)(struct dsa_switch *ds); void (*teardown)(struct dsa_switch *ds); unsigned long (*get_host_fwd_mask)(struct dsa_switch *ds); + int (*change_master)(struct dsa_switch *ds, int port, + struct net_device *master, + struct netlink_ext_ack *extack); }; extern const struct dsa_switch_ops felix_switch_ops; diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index dddaffdaad9a..9ffe5db90281 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -2054,7 +2054,7 @@ static u32 ocelot_get_bond_mask(struct ocelot *ocelot, struct net_device *bond) /* The logical port number of a LAG is equal to the lowest numbered physical * port ID present in that LAG. It may change if that port ever leaves the LAG. */ -static int ocelot_bond_get_id(struct ocelot *ocelot, struct net_device *bond) +int ocelot_bond_get_id(struct ocelot *ocelot, struct net_device *bond) { int bond_mask = ocelot_get_bond_mask(ocelot, bond); @@ -2063,6 +2063,7 @@ static int ocelot_bond_get_id(struct ocelot *ocelot, struct net_device *bond) return __ffs(bond_mask); } +EXPORT_SYMBOL_GPL(ocelot_bond_get_id); /* Returns the mask of user ports assigned to this DSA tag_8021q CPU port. * Note that when CPU ports are in a LAG, the user ports are assigned to the diff --git a/include/soc/mscc/ocelot.h b/include/soc/mscc/ocelot.h index 2a7e18ee5577..e90ba089d5ba 100644 --- a/include/soc/mscc/ocelot.h +++ b/include/soc/mscc/ocelot.h @@ -1105,6 +1105,7 @@ int ocelot_port_lag_join(struct ocelot *ocelot, int port, void ocelot_port_lag_leave(struct ocelot *ocelot, int port, struct net_device *bond); void ocelot_port_lag_change(struct ocelot *ocelot, int port, bool lag_tx_active); +int ocelot_bond_get_id(struct ocelot *ocelot, struct net_device *bond); int ocelot_devlink_sb_register(struct ocelot *ocelot); void ocelot_devlink_sb_unregister(struct ocelot *ocelot);