From patchwork Mon Jul 12 15:21:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 473343 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E541C07E99 for ; Mon, 12 Jul 2021 15:22:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5E3646120D for ; Mon, 12 Jul 2021 15:22:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235448AbhGLPZC (ORCPT ); Mon, 12 Jul 2021 11:25:02 -0400 Received: from mail-eopbgr80041.outbound.protection.outlook.com ([40.107.8.41]:27617 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232203AbhGLPY7 (ORCPT ); Mon, 12 Jul 2021 11:24:59 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AdNxwc4ilikKionUpiBvWxpQsWAw2Lx5cmuXOUgEvo1nadKYKmCbqBEBmTg0dyVToHiyxpYItAAlFBiLhvPl4aFLOGZzGjsmuIvdATWUhKd0Zs14vkhdgA1APHRZwfb3GQ4TAf5iOp1U5us2lFjBLBG7C/tkSkouoQkCK+1VPAaDicd1fC/cOEpWo5ZsX1oLkM/a6199Yc240eNCRwoRpFxB9dpjFZl4jYUJoQ1uLG/z939aLDpURCT0f3a+wkIPPHmhnjJi67u6LPwuaIzFOn461VO2AUVWgFO5zSGawwkAFKbDUg75G7Nx9xiT31TdsRs08o+/GSI0QeogvT4cUQ== 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-SenderADCheck; bh=4fa/GIxMWj0fNCHBGxwYOP+lgVtD3UA9ZDx31dli7Pw=; b=Z4T6eS6aG0uuTUAvpX72IIwf2iUaqEmDuGpCRUUacFnsjhHEirPm9Gw5nfnF6X4VtpZYI1CHuA7l3MMzU3OrWZ5CnncrPQkyFAVslWHHwbExt6EF6nbJmRDbp8Unuz4qMpbI98mrm61/cpx2Lt4mnLxqy4KzqaRGsCH0pw6a+nJKX8exmMMckC5BSoqzL7Yp49ECLIq56ugEbrMoo5Ejx3uFH7s01nzlLiRCFQ7NFKp637yjlctoakO9sg2bdwCjIeFHTRI0VehIEfDPe4jdehkIkAMo32IueBhdVwn9erPbtdYC4p/S/OWsxZy0mmY7tfXCODVtoRzwVezwoIBlpA== 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=4fa/GIxMWj0fNCHBGxwYOP+lgVtD3UA9ZDx31dli7Pw=; b=s5FkBeqg0yyHqFKzJDdmQQAHFISYBCizsiW0mIRSXOx0ov3lgf/QiQwS0UMDb/u35BtZB2afouG7YJgEs17xxlP1bYZZ6i2jxRn1ZFkcCyzSmuUKUvgdUPi0p6U2/6QkHqUNZD20eqeidxzmP9M9DOKD5eCq/Vr+iJahageXxSk= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR0402MB3549.eurprd04.prod.outlook.com (2603:10a6:803:8::30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.23; Mon, 12 Jul 2021 15:22:09 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab%7]) with mapi id 15.20.4308.026; Mon, 12 Jul 2021 15:22:09 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Jiri Pirko , Ido Schimmel , Tobias Waldekranz , Roopa Prabhu , Nikolay Aleksandrov , Stephen Hemminger , bridge@lists.linux-foundation.org, Grygorii Strashko Subject: [RFC PATCH v3 net-next 02/24] net: dpaa2-switch: refactor prechangeupper sanity checks Date: Mon, 12 Jul 2021 18:21:20 +0300 Message-Id: <20210712152142.800651-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712152142.800651-1-vladimir.oltean@nxp.com> References: <20210712152142.800651-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20 via Frontend Transport; Mon, 12 Jul 2021 15:22:08 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: e8b748bb-5ad9-4425-027a-08d94548d0c2 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3549: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1107; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: x51m05w023YkAWRM04+dt/YYMWmXytG7vQ0H4R2t+eTkQAY4nyToeJneZ/9JUc7RSvEE1d57AdUIK8w4mTCtj+XY1/xQz5vaInWVmwNOVSETc7y84d/mV2yChx1WbmNK1LJjQnvw2AzvXD9o48koO7wXpfpzqOIGwBGb0DiGiTrdK70q/jxnXogLJZ010mndlF3i/seysO1NajO7QgLI/3OJ/MzsotEzIMEok30ZFcaEg+hiKKNa7rCb7U4bp1ykeY2fCYyNOeG+ADnV750eV8YSAr9nUN705gkb+FYczlXgNmi52jHK9el7hb3UGa0oNVm6GsFNA+NHyNrAfISzS5KsVAYVryJbNOSHnA96FX106Vwd+5nvDH+Io6BDNn5BgONl0m+/tYXUsEjNyE3n6FHaAHXwCp85GbLepKoLzPEObzkOuf7nVoclix286W0beVXpO+F42CuvFrTYgY2V/VLsOnwqETxek5BKRZiEzDvK4PLsdzJ0/saM5QOl96WXYe9cdrDk1kAlzQseuhoU3wI7PSHijdlb00OqFwEMm1YYf4STRUa94+CRy5yPnx/qZ73Zj+TpUwEKRKXr/+F5DPVCszn+Vely1O3vGVi9iELqGd+vAJNaAUcUon/FmLpA0gKK0nA0SoVyffITEZNua+YDDC3mHxBTjRwVtVBcw7FulWv9NQ6wFtS70OZb0VWaCv0HBtvov48btVrdii0b7Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(396003)(346002)(376002)(39850400004)(136003)(366004)(6506007)(6666004)(478600001)(26005)(186003)(83380400001)(66476007)(66556008)(2616005)(2906002)(7416002)(6512007)(316002)(956004)(44832011)(54906003)(110136005)(4326008)(8676002)(66946007)(8936002)(86362001)(38100700002)(52116002)(1076003)(5660300002)(6486002)(38350700002)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gj29oo30wGJ30S0UIxS4ICRya4p3XaKzPGA6Qp+O9RANhMX7ZgsHKjFzHp35kuLlDJ6Qyjl5jKFfpoGsGa1/7yaKTHtHJa1mqCBy/GZ5yrLyNEy/rbwYTV199EH+AKdOrnVFzn67kO7BF1iqRFonA4+WyWyLnd6BWPogNKkxFxnTqwX6ubc6Rw/ls4ru9m88lwgwR0bTOmvSvusBiuGRJoY6ezU7ocmPX2TM98Jeif1dyLlBONZfuS71+str3Xe5ilv+eqP+Yeummoua+hwsbL0hU/y1JAgNOZUJ0LaK6SbZrPalhYE6cqbtB3mmyzxNRe2RskP1j/LiQrpQ1ZakZAQD3cN+e6v/ZSVtAlqnwgy4ZfMlGJTmGMSI+2PfgUKu/Isou2gs/QBZcXb5i05q9d181rvxXT4DkAjgXZVzhq8O1nHKiOJg4H4cFu4LL0Zxr853B0CHUnymrp2UhkhvE6b3JgD3M/IZkSf7KlQRNWq4UGtUmrzdvCNjqloXye8/tiAYWFV/mBCUXe6zqvK4JGvGawdfPr5tLT5aDAJWQL6wM1hGFw98kI1s7gDcJ4cM4es4cyOS9sd+9dhXRkCCwGQW6IYYxuf9fDTis45J/BkmX19HeMRdp4bvr8V4aQgC98+LQZup8utmlnhNKWzpiClo46VZXahThW8+FYv5Jg/lq6SqdxDa/kI1lpPpXCxVSUG9hJ5Rke+UaWjQfJFHKp22HUKH5QvVcdJBYqdh+zKFNuOnjandu4wRrwwUYHSuH+KhIHNQZvwAbCS7TwI8WxQmjKj2VMijkYFCmVgLYCcUcDY6EcE2pLAy+5y0vE1Bl3coEeFTL7GePokODiao2UudqV39hN0y6PqHrYV9ojiDcJn8K2PicaHgLZOwPbutKG4bo/IiOUvisTVZcmv/vJmhdOE+cLZuNJlxRRYFakWQEJ3s7VvZleErHC82aSGWujCxORmV8W+AJvMAvBKwOjAhP7TPvF36TSHwjVDhkq7G9E/NuBi56gADECjH56tRRXpHK9u8ay2eSlgD12jJ3nNYe5WblIfWVI3WqJEp8RRkWVsBusnJ2sWQhFbMfHG2ogR2IBlraG8KMzNpIEBX19i6qK/Y2qFqY49uAa+x98nen7sL6px0/EcDZKJeAJXkRVniaCElthPaA16yJud85johsgMxPmYtykXWUPN2HdaNLM1yclVT8YCBj1pWZwaOo1SfLa1ZTKc3fQvZTFGnHUMBk8Gdjf5YK/52dJYps8DDVQjudZ5sH+D7sBLvULNN4vMX6MGKy46jrD+96ojfLJ2Hb5OaY8E5/HHdrHXk/QpzID75nojy8KOZ/doKvnjZ X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: e8b748bb-5ad9-4425-027a-08d94548d0c2 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2021 15:22:09.3542 (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: WOs3rK+JNtV5L/C8mSi7KQmh8Sna8I+hdG4mz8qsJYBTq33UBIt7gJH7zOOmeSIk0PEZEaNAfHVRpw7W+3T0SQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3549 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Make more room for some extra code in the NETDEV_PRECHANGEUPPER handler by moving what already exists into a dedicated function. Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- .../ethernet/freescale/dpaa2/dpaa2-switch.c | 37 +++++++++++++------ 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c index 62d322ebf1f2..f6d4cf053ff7 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c @@ -2030,6 +2030,28 @@ static int dpaa2_switch_prevent_bridging_with_8021q_upper(struct net_device *net return 0; } +static int +dpaa2_switch_prechangeupper_sanity_checks(struct net_device *dev, + struct net_device *upper_dev, + struct netlink_ext_ack *extack) +{ + int err; + + if (!br_vlan_enabled(upper_dev)) { + NL_SET_ERR_MSG_MOD(extack, "Cannot join a VLAN-unaware bridge"); + return -EOPNOTSUPP; + } + + err = dpaa2_switch_prevent_bridging_with_8021q_upper(netdev); + if (err) { + NL_SET_ERR_MSG_MOD(extack, + "Cannot join a bridge while VLAN uppers are present"); + return 0; + } + + return 0; +} + static int dpaa2_switch_port_netdevice_event(struct notifier_block *nb, unsigned long event, void *ptr) { @@ -2050,18 +2072,11 @@ static int dpaa2_switch_port_netdevice_event(struct notifier_block *nb, if (!netif_is_bridge_master(upper_dev)) break; - if (!br_vlan_enabled(upper_dev)) { - NL_SET_ERR_MSG_MOD(extack, "Cannot join a VLAN-unaware bridge"); - err = -EOPNOTSUPP; - goto out; - } - - err = dpaa2_switch_prevent_bridging_with_8021q_upper(netdev); - if (err) { - NL_SET_ERR_MSG_MOD(extack, - "Cannot join a bridge while VLAN uppers are present"); + err = dpaa2_switch_prechangeupper_sanity_checks(netdev, + upper_dev, + extack); + if (err) goto out; - } break; case NETDEV_CHANGEUPPER: From patchwork Mon Jul 12 15:21:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 473342 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8BFAC07E9A for ; Mon, 12 Jul 2021 15:22:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2A3E61008 for ; Mon, 12 Jul 2021 15:22:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235458AbhGLPZG (ORCPT ); Mon, 12 Jul 2021 11:25:06 -0400 Received: from mail-am6eur05on2085.outbound.protection.outlook.com ([40.107.22.85]:46304 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232203AbhGLPZD (ORCPT ); Mon, 12 Jul 2021 11:25:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hS2CrvE6L4d8H3TSpuPVLOmH51y5s2MgJ2hz3F3mHyrS3aJPjaZyu8oOgAIv+J9EZwqK9a8LGlpMZ4LlpOyByIfULG3FmHPFMdocNncNuMAfjVwsovUUlVdsyLdA5/LzQjYNtDOm17rB6eP287nv+TQhpBxcOwAoI2QdeeYY3eWk4EMZEpxBShtWls9MH2zryHZaiL2VPJXODo8OF57NQ/iMlP8DL76hJCiMm2jpPlk8Fi0DcKjWrJ4FqioQ7CUhfAFl0ZRmh3YRPgPredEoIj+rDaTGII8u9vVQLIJ0MipB5JMbnleuHImrn7GYDu+bZ3E3CcUZQR2Ilrx789zGTg== 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-SenderADCheck; bh=hQGZqA4YLYAdJOm/W3LrzcL1Llu3tBJ7wawN8JJFNl0=; b=h0xaMTEfgl7M/mRRLhdbY9B+L/8/hha1b30q2u56Z4b1ucI1ffp9i800+lwfcJ8mFrANlI/gh5e4l5J7FDAZzuadvs5oB5U2sW7iIUsVQczqm42f0TH/XKuz7/O+m7IDiavGKZ6q7rJ3ztVM+BgMVJhOEJfwcFDHhlA51Mm9WZ8m42gHbXSxBNydXrg38sN0on238dvVYjX/Y+JsSTKIMnx69+EZGv2+1oduDJtMoiU8K7XF/OTZm3VpjU3mBf+TjXYtl9hJEYrogXWV3gbSO+/CGPOTFiAOP9YXagGLtpyBdXoA/IYnwv6V7VyHoLDe+dsz9nLDneHy/0QG6Yarug== 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=hQGZqA4YLYAdJOm/W3LrzcL1Llu3tBJ7wawN8JJFNl0=; b=mOGXrMWfOZ51fpM8UYk0FlhfkAuSpJVolRUGgvBmUo44XMtWAD7Rx2fPtktrAqZ57tSQzgbEWniB2cVjMS4sT6dx8xWzxn3Ph2jtQBFdjSDXBB7Xl7AyOXdD6XDQ5PIx3432SsjGhTyj5yU8wgRCasjIjS5CXxxvB04AcQay34c= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6271.eurprd04.prod.outlook.com (2603:10a6:803:f7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20; Mon, 12 Jul 2021 15:22:12 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab%7]) with mapi id 15.20.4308.026; Mon, 12 Jul 2021 15:22:12 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Jiri Pirko , Ido Schimmel , Tobias Waldekranz , Roopa Prabhu , Nikolay Aleksandrov , Stephen Hemminger , bridge@lists.linux-foundation.org, Grygorii Strashko Subject: [RFC PATCH v3 net-next 04/24] net: ocelot: fix switchdev objects synced for wrong netdev with LAG offload Date: Mon, 12 Jul 2021 18:21:22 +0300 Message-Id: <20210712152142.800651-5-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712152142.800651-1-vladimir.oltean@nxp.com> References: <20210712152142.800651-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20 via Frontend Transport; Mon, 12 Jul 2021 15:22:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a59790fe-9293-4d8b-f53d-08d94548d272 X-MS-TrafficTypeDiagnostic: VI1PR04MB6271: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3631; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dHf7I5VGvQQYwyBBkKlf+J3BSkRtLDRGkyCALTrgw1gCHh10nC9XPHCEVC8rQJ0DceEtUzrc+pfNOzhpUiXGmflo865ywWySd39bZ3GZ+jlIdos+l01jOKAZ7ftHS/Z7UMeXbuqY5Ij/s5z4RDB/BnYaUl/4XWtNFlwOzzOLMknFYu03aFcCDmomt5tNscQEUh4q6s6uT0//DK4sGC/iwtrIJ6BTqwSgGGEULYoQE6cpDWoxDGWGmVCG5GyqkkzBZJ4f0qx4yxiKLDD5dySU9RXZKd9bUICNzDVhqjj8pNz6wSge8E9FYE1nhDH2L0pXDRk3wL6vBVLaMgy+qCfZ8v75SXp61oyjfmqu9azEeDEdWRa/fBn+YJ+hHWpBKVkBN5zhShQd+TlLGPw9s9ixlyodvwZI0+2LxT3M7aMMGDHe/3r7zQ+XUdRW9Yr9Xj1L+dl7KxceylA8F6/ELnBu5iowZqI4Ik+qzkY9meztBa6VTuKEgZ0v1GCQ1ksjjuLiDQfS/sZpiHNxED+TeiEI+lZwTQDb4x4QkjqUsf7TSPBAC3cTnBsa/dO3lpbWzKf+EqoAcslopo77Iv9Pa9MYHG9MtHAPdRVi8GmiZ5fu8kv4QwQIJhnL/fYdEWJ5+TMYewes4lCbnykh5rnHUDzSY18TkwwZwTGCXQzsqj2pLu2SAAC9Ikz86PzyTpkM1XRbZ4z0CNTQAVtPBF6Q8zP5uQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(136003)(39850400004)(396003)(346002)(366004)(26005)(2906002)(66476007)(6666004)(83380400001)(66556008)(38100700002)(8676002)(38350700002)(66946007)(5660300002)(4326008)(54906003)(52116002)(7416002)(1076003)(110136005)(6506007)(316002)(86362001)(44832011)(478600001)(2616005)(956004)(6486002)(8936002)(36756003)(186003)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3QDNmSwpkO9JwKnxlRsjTpPoRS3tp4BInrjgmC9DSsxQZlH2ne8ecsZlh+aGtQ5nsrf6cVkhnZOFf7E/8yB8W1DXrxJMHikD94Ein+Zl4hhhj3M2LFqC+XH8SrMHhjoenA5klt4J4L+Wz1YjRK70F8E68L2WBmMGgvdrlpxVBcMs6etEMzGy/kqwiFBLPxq6wyG+cxudPaMZW1wqcb0Xm4bJ1xuMLYvnfEGVRu9ph0HGE8Xw+m9KkWOQ+lejfo6Ayi+/WwO+PdtJgU2sg4Qw0jws7PKQjEoLgnZ4sF8qxdTrzCCckP+W2EF85B2BgO6Dl1yaVNXhqGup0nSpgVTPjMrJqGkHQpD+fy3/CUbfP032VjqQsN2CzF0Jm30paA+k6963DPoVwTwqzoLzcsRjLp+V4opB+q9j2CFBj7QcZwPYgcsgmLQg/2rdakM5C9Sac8XJUVTNIZ+r0WTfh2hDodBxDKJWOwtCLr87T1eCS3MGC2OKU55rmzCZf1WdEjULZXK/ecD7HOEMdsCRF3W9U5b/1jhTjzYjy0SwOAziSF0rPyuI6dr48CMWvLJjFnWDkCurZrsTZDcIv7pMBSM5jZWqvOIGIRiJvP0ib8CQxPyVgGY0iTx6o35wRUEILV5T8Sq6GNNvzJOsu8zPqzcUWj1d1A4Cy20imqY7UzdlnlXByYPkQ46M98AdV1a8KnAEodzU3WC8w3p+J9Nw7hw4r4WIByPYjRHjRYuuaWw2VxiTvSpIgoa5yN8vFSxNE6e+fipMYjrc/Q8n/ge0ptv7Lg1gs29KRkwWOMop3K03m2tqgo5b6CZ87wuZDrDXrfbHv9gVydk66ZRIVmjr02JgeuHk9UszuCOFPVdGEoMiyvdlqLwqMx9vQX/GlSIVW73AzDFvFJHMgjMP423HPebt+ricpPeZ7rXc4E04xbN6D4IJh9YxhSumwm6+PaqyIuweacIGM9uGpVIm2Rvx0NfnOXIScDKZgUKvxhxvsodDi9sWocPYAGIvExmRpEQOWhsLBhQCEKgN2xezdJK4gnye3q1DTg1/KHU/DEbirmjGkM3Ec/pifkpyFRwZ4h4EXDAwDSWaXU5HxIK/CTHcP9WJNj08Rs7pqlbsp4RBeih1UXuH4jXwG3fF5/hbPLH/XCSwZYw9aSqGqueNxXG3k7SS/hx6HzLMbtlcxuXVbgRISAREm0hM7hbvt5sFx3p7dUUHovdaHrbMmucLo2XREC9ySyYoEPRB1N65bwR7YCq37cuEl6saR04HFOw9SHsuaxJIyj8RrtUB0pnhI3VG7iVOQXOQuv36H4jtJJGxaMVou2Q0RMeoJ7PDui5xSCN7xzRu X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: a59790fe-9293-4d8b-f53d-08d94548d272 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2021 15:22:12.1876 (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: 23Skls0cf9MazAKJdKfeuxRiX3C+vpqkeGIpsVyW2V9IvPL5JXU68th+E1hX+pTUXDyrDY0QghQj1qmLvdN/Ug== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6271 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The point with a *dev and a *brport_dev is that when we have a LAG net device that is a bridge port, *dev is an ocelot net device and *brport_dev is the bonding/team net device. The ocelot net device beneath the LAG does not exist from the bridge's perspective, so we need to sync the switchdev objects belonging to the brport_dev and not to the dev. Fixes: e4bd44e89dcf ("net: ocelot: replay switchdev events when joining bridge") Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/mscc/ocelot_net.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c index 3e89e34f86d5..e9d260d84bf3 100644 --- a/drivers/net/ethernet/mscc/ocelot_net.c +++ b/drivers/net/ethernet/mscc/ocelot_net.c @@ -1298,6 +1298,7 @@ static int ocelot_netdevice_lag_leave(struct net_device *dev, } static int ocelot_netdevice_changeupper(struct net_device *dev, + struct net_device *brport_dev, struct netdev_notifier_changeupper_info *info) { struct netlink_ext_ack *extack; @@ -1307,11 +1308,11 @@ static int ocelot_netdevice_changeupper(struct net_device *dev, if (netif_is_bridge_master(info->upper_dev)) { if (info->linking) - err = ocelot_netdevice_bridge_join(dev, dev, + err = ocelot_netdevice_bridge_join(dev, brport_dev, info->upper_dev, extack); else - err = ocelot_netdevice_bridge_leave(dev, dev, + err = ocelot_netdevice_bridge_leave(dev, brport_dev, info->upper_dev); } if (netif_is_lag_master(info->upper_dev)) { @@ -1346,7 +1347,7 @@ ocelot_netdevice_lag_changeupper(struct net_device *dev, if (ocelot_port->bond != dev) return NOTIFY_OK; - err = ocelot_netdevice_changeupper(lower, info); + err = ocelot_netdevice_changeupper(lower, dev, info); if (err) return notifier_from_errno(err); } @@ -1385,7 +1386,7 @@ static int ocelot_netdevice_event(struct notifier_block *unused, struct netdev_notifier_changeupper_info *info = ptr; if (ocelot_netdevice_dev_check(dev)) - return ocelot_netdevice_changeupper(dev, info); + return ocelot_netdevice_changeupper(dev, dev, info); if (netif_is_lag_master(dev)) return ocelot_netdevice_lag_changeupper(dev, info); From patchwork Mon Jul 12 15:21:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 473341 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 87975C07E9A for ; Mon, 12 Jul 2021 15:22:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 631E661008 for ; Mon, 12 Jul 2021 15:22:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235485AbhGLPZJ (ORCPT ); Mon, 12 Jul 2021 11:25:09 -0400 Received: from mail-am6eur05on2085.outbound.protection.outlook.com ([40.107.22.85]:46304 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235443AbhGLPZF (ORCPT ); Mon, 12 Jul 2021 11:25:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FNsx2FSEe6AnAKEBVGb1ZhMS3hRyl9QSPg6W5hh87zt8pTzPrU6x6ggdiYrLnGHTmzJatG+0/BL5T1GqlJWB1P481QT5RquTbQDJOVjNF4bHHh4Ir3HIt0bKGXTENnT//l1WdEPJk5b3ZlDhwgMsNgnYPEfTcfulhO7SG36BU1YRzHMsfNwZViC7IqQ1SPb4XRsMShgGPWg220KRpHGrMI9C/UcTuHw2iJa5AseDmif4HSE8BLab0koPSJu9FrjyQqB0S7YuMJXU0ghlKn1txzf1fvhdpcqK/jidrwGhVgdVPci0CkquI4b58fQMYeItB0L0FhPy3KDh9UfzYrvmiQ== 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-SenderADCheck; bh=J1D061jnBAD0XbtV38n3i24VJY2RK3DQPlT/pABNFSo=; b=MrBrLu8dlKeg4/tZ8ylRa44B/quey6Jaw3R08ISaVfwvc1qxlmMeW6gu3tHAzWACErPDO6bwbxZUFSip1ydO//g27lWerc/N64Fvmtf6/C24X5otas9mLE00TMJKczo1KYo7AG86rAllDx6wM9mu5Yi4ghu4R7D9X2CvUVRxwR2Ggod/5MsT8hJO3PzeR2XHNMdJmwqaoQdi2IZPkUCOpanbwrE4RA3qohchU63lzO78tuNfHUCNabclcXLAGOfukMhOXVrjkD9FlR66gO0m0pDS8bavC5IWVrQswYdJs+8y/coAI80cn2Tlky9FumhL1kj1B81YNgfgBJzz3onxsA== 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=J1D061jnBAD0XbtV38n3i24VJY2RK3DQPlT/pABNFSo=; b=IHY0Lks8Npr9kpjSCNbxzrmpftBieLO7O1RTHtgJwc31TMWP8zjAEH6N8DzeKX6DTcuNarBL0GDEiGt6FO2DNCKjPkFkzCkoADOLQVqWHL0/PUVKXkal6JxrMZhkvnkZ85pD0qDhGa25i8virHRSHEldndXb4u7pLmi6RpdKeFc= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6271.eurprd04.prod.outlook.com (2603:10a6:803:f7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20; Mon, 12 Jul 2021 15:22:15 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab%7]) with mapi id 15.20.4308.026; Mon, 12 Jul 2021 15:22:15 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Jiri Pirko , Ido Schimmel , Tobias Waldekranz , Roopa Prabhu , Nikolay Aleksandrov , Stephen Hemminger , bridge@lists.linux-foundation.org, Grygorii Strashko Subject: [RFC PATCH v3 net-next 06/24] net: prestera: refactor prechangeupper sanity checks Date: Mon, 12 Jul 2021 18:21:24 +0300 Message-Id: <20210712152142.800651-7-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712152142.800651-1-vladimir.oltean@nxp.com> References: <20210712152142.800651-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20 via Frontend Transport; Mon, 12 Jul 2021 15:22:13 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d3382ae1-9e7e-4924-5dc1-08d94548d41b X-MS-TrafficTypeDiagnostic: VI1PR04MB6271: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3173; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Cr0/QzpnOYGpLYvQVUJ4XFg+cXw8WRFPJyTklUYhu61Rh2aggZ+Kp6W7A/Gi30yWmjtvI7CIhPUIbg07xAkgfM+XnhSOSZh2wVfLmuCcY2KBxl5JMtLJUMEIg2FqyVixQ5B2gZ9dMo7Ywm4Ko56DUZl3SkA9kkY3XnBDS4IVGLajcAXLRG5F0+u7yrj0DHTnl6Qi+W+GcuHUY+glOjGCMfSHvaRWdI4PPw+a5s5TsfiMNnHUX2sc5tkSQVrVqLgU/Dnp0mL3lmtqGAji25wnHFxTmhEjDZ26MKwZNLJ404WCiDgII5yDaonQW1voHLQDgjlGDGmnRpSCi25N8XZ0ZtayHLYM8gt/+FUH3vtPdOuuc7zbjkRKjJP9GLiTdXdIzGOFx3FbTWmAcBJU7IRRaRuobPXyNs4G1wP/ThxRcpfG9ynoPayGlXQ7Ei9f2DiaDzpi8mgVNa01v65Mbj4ZvcW3UJ04pPaO2WsummH5GMKIQ5dWKXptam+vaO1l/gSTkCdn7JK2LMSjNHaXbPfeQW/CrdTbmtn+2Q5ykaAWhrK7tjYyYW9XQAfcXnYcNyXsz52Cji0RWUl6Vqah+nIHWg53GERcGvmZbTFpnQmwcCmb4Zgon8n90YJWO2+1YKJg/mlVA4bCtAx13hLqiRuS/GRDOliwvmoXwWvvWHcqTd3QBwfdEIYHCCvdXpM8FU0Yj/MnrOz9fQYK2b6iGel3rQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(136003)(39850400004)(396003)(346002)(366004)(26005)(2906002)(66476007)(6666004)(83380400001)(66556008)(38100700002)(8676002)(38350700002)(66946007)(5660300002)(4326008)(54906003)(52116002)(7416002)(1076003)(110136005)(6506007)(316002)(86362001)(44832011)(478600001)(2616005)(956004)(6486002)(8936002)(36756003)(186003)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9HifCo3iT7c27gMfFuECXVZvZpdd+nRW0HpnjGuRLmRDaIIZ+noUC7rYx7q8kalofVWZjipiiWu94mP054WFMObo+dsXhRA55eNKXIPSyO0gETQBHySIPMBQoHOqEhRrUJOOIqN/uOuRzVoZO33Y0MiE5v1HpwMNyxCDyml70KgxrOGyQBiQXw2J5Ux8scc5vHCjDU59xnnMtVKYppXbntChOZGa6kgS0Mie1hWSk/u+McQz4QKCyOuLuFjO8SPQhqdW6/fNqoZuf/2jvIullh2f1EQYWH3PmtDEwEkYdA7+fHMRaEN3cnlhaaD2iOMhT4t/Um65fioXVaaqVzc8HDgJVL+VScxowk05qqA6UE145dXpbv44a7bL1mcYzA52sbxNm2Wa5TL9nxJGia9fecRfONEy/4Nsn259NMwIBLiSDu0ACMqlmoDSvbDikg36ExoWjPiUMNlvt7+JXfEQiee6JjtdH3PYmhzg60WkRwXr8lq77sHiCKK/QNt5XPtC6LN6q8dHSDZmaAFRHTjgybZZdhiSHF54nepMH+vHKGK6GYjqu4NFDkvnWwFdSKLXND8s2GGfQRoc8q/jYXy5JUvAu2npCo+YpWemk48SIPu05rqo5wrNXd6Fa8bGWnL1eszkx9T1bjui0YLkVps9GreAqBgCVib1J7yFwWbLZkuD3kmolkOLSoTqqpdiAmc/7aQRwZwh81r5cWRwLD+Kr3rlmZ/VN0BC01jCsEH5ssO5Sc726iFyoU+OFMWJEbNwjDf0gVfqtIw48CtTtRthaASvlI8LTP4wxEKwOjrqHClabdqwpg8T092A/+lCrxI3fr5xVRfRcEzdnyLGvcOzmYJSLVDj6DuXfLpD4Fl5semmA3n/AKITRSVIH7HFtRY41ASLPFTSLNSTW/ccne5pZtNczatG66aJ7h3aHjufBel1DM/pFH36wWBiPPK3W8HZBJgs58V2GVA5HAzj4pjU1rASuTFhRpSpu5PeP4A0JCu1YC7/i2l94P18NwKfii+MXjvesFpx8//hl8pySGYa6VdgIfbDEfYB+dOgmtgxJRiCTCbwXBtQdMTYVWZZrtpqOusByXkKZSmmTlWlcEWJYxr4X6KILuNhQdkmACP+81D/aXwvPT0auYHF+PtaVSYobU78wZ9/2/LXwWmFPXtrisTYv9j0vmp/aucHee82ZJHoD1MbRdj8lcaR6G2XG4uOVr6YWam2KUdEMY3wJIRzp4P9r/gVega8d9UK37XUHrIMs+dcGq2iN7TCpkElteAnPcaBTsMrEDLjkS+SnGSe+15CYdTnfbfC4e/FwQAHcuISwJDRMAwMDQE4Pywcr88h X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: d3382ae1-9e7e-4924-5dc1-08d94548d41b X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2021 15:22:14.9919 (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: KdACpMhwIrkmqWiDROYONBDFBZih0m5D+yLrWweg3g1bt/UzLX8Ez7dc/sT0U4jFLDNRepGOiSPckltrxUQ9hw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6271 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In preparation of adding more code to the NETDEV_PRECHANGEUPPER handler, move the existing sanity checks into a dedicated function. Signed-off-by: Vladimir Oltean --- .../ethernet/marvell/prestera/prestera_main.c | 71 ++++++++++++------- 1 file changed, 44 insertions(+), 27 deletions(-) diff --git a/drivers/net/ethernet/marvell/prestera/prestera_main.c b/drivers/net/ethernet/marvell/prestera/prestera_main.c index 979214ce1952..508c03cc8edb 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_main.c +++ b/drivers/net/ethernet/marvell/prestera/prestera_main.c @@ -707,6 +707,45 @@ static bool prestera_lag_master_check(struct net_device *lag_dev, return true; } +static int prestera_prechangeupper_sanity_checks(struct net_device *dev, + struct net_device *upper, + struct netdev_notifier_changeupper_info *info, + struct netlink_ext_ack *extack) +{ + if (!netif_is_bridge_master(upper) && + !netif_is_lag_master(upper)) { + NL_SET_ERR_MSG_MOD(extack, "Unknown upper device type"); + return -EINVAL; + } + + if (!info->linking) + return 0; + + if (netdev_has_any_upper_dev(upper)) { + NL_SET_ERR_MSG_MOD(extack, "Upper device is already enslaved"); + return -EINVAL; + } + + if (netif_is_lag_master(upper) && + !prestera_lag_master_check(upper, info->upper_info, extack)) + return -EOPNOTSUPP; + + if (netif_is_lag_master(upper) && vlan_uses_dev(dev)) { + NL_SET_ERR_MSG_MOD(extack, + "Master device is a LAG master and port has a VLAN"); + return -EINVAL; + } + + if (netif_is_lag_port(dev) && is_vlan_dev(upper) && + !netif_is_lag_master(vlan_dev_real_dev(upper))) { + NL_SET_ERR_MSG_MOD(extack, + "Can not put a VLAN on a LAG port"); + return -EINVAL; + } + + return 0; +} + static int prestera_netdev_port_event(struct net_device *lower, struct net_device *dev, unsigned long event, void *ptr) @@ -715,40 +754,18 @@ static int prestera_netdev_port_event(struct net_device *lower, struct prestera_port *port = netdev_priv(dev); struct netlink_ext_ack *extack; struct net_device *upper; + int err; extack = netdev_notifier_info_to_extack(&info->info); upper = info->upper_dev; switch (event) { case NETDEV_PRECHANGEUPPER: - if (!netif_is_bridge_master(upper) && - !netif_is_lag_master(upper)) { - NL_SET_ERR_MSG_MOD(extack, "Unknown upper device type"); - return -EINVAL; - } - - if (!info->linking) - break; - - if (netdev_has_any_upper_dev(upper)) { - NL_SET_ERR_MSG_MOD(extack, "Upper device is already enslaved"); - return -EINVAL; - } + err = prestera_prechangeupper_sanity_checks(dev, upper, info, + extack); + if (err) + return err; - if (netif_is_lag_master(upper) && - !prestera_lag_master_check(upper, info->upper_info, extack)) - return -EOPNOTSUPP; - if (netif_is_lag_master(upper) && vlan_uses_dev(dev)) { - NL_SET_ERR_MSG_MOD(extack, - "Master device is a LAG master and port has a VLAN"); - return -EINVAL; - } - if (netif_is_lag_port(dev) && is_vlan_dev(upper) && - !netif_is_lag_master(vlan_dev_real_dev(upper))) { - NL_SET_ERR_MSG_MOD(extack, - "Can not put a VLAN on a LAG port"); - return -EINVAL; - } break; case NETDEV_CHANGEUPPER: From patchwork Mon Jul 12 15:21:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 473340 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59A92C07E9A for ; Mon, 12 Jul 2021 15:22:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4344C61008 for ; Mon, 12 Jul 2021 15:22:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235494AbhGLPZM (ORCPT ); Mon, 12 Jul 2021 11:25:12 -0400 Received: from mail-am6eur05on2085.outbound.protection.outlook.com ([40.107.22.85]:46304 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232203AbhGLPZL (ORCPT ); Mon, 12 Jul 2021 11:25:11 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mjHnkL545LaxTq7QAzVSlZUrYZGGXlhVqDIfrHaThqeHfCGLW3IkUJ7c3D+9TCZLIapHwKRE7ie0Oz8OExFmoNwtZDFkbyv5hGeTqmlRp3SHStATCo/bfJxRl/zaKLvW22n33UtnX0IX67A1KlJ3QxZ6Pl6ArTLnUFyU419SpnTmUL6Vf92wpwCOsyV0bjM99abFJZ+Exl/lZ5yCXNOABx69WZRdz2Kle5nfED7dsHwb89h/KtW+MgC5C6z4+mrzyNQOiaSwW+hjkH+CP1aW7XDSSH3A8mVmwRkZdsQMbz1bt2qM+RRuEWNcBqvTGIh6faUwDtA14hkESo4e/LVEFA== 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-SenderADCheck; bh=AEgvkFxIKhFi4/Lc1IhTUlb99C35DWTo4eSdHg+w4q8=; b=OMPtMmAtvDXUcTiNm6ZY5GolxaHIMqy/yWI5jXicij00G3Y3F6h+5+Jp27uWszH/R/KfFKOZW6G6sV3eQGkU/up48l55oQq4y2fV1x6hnuRw+DJotJgwVCZ5xwiLIy70rlktaJMFBez1nH1ak6B4cqAC278djyfsXdpLLWEXxE4R+X+mQap/TSg+jO53j3y34Gx4ozcwrK14J5HfYb5eKvuAfNEuMmntsGjIWkL0syCwOYvWYP0QKZDjMIZWZqGDa/LZ0HglJvxl+vcnaZ2zsWcIcncxeVVIl//P367Ia3lZKsEDrls6IxbdBiTZS3iEn5vBWWd+Oce8Xi0Bywfd9w== 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=AEgvkFxIKhFi4/Lc1IhTUlb99C35DWTo4eSdHg+w4q8=; b=b4+5vlJ3XZd8Pi+jDiTfMcs5R7BxgDmpJljw1382qZ9NES6QlLhHbeWA4z3Nu5CIC0BJM2g1Q+2N8VwrnOmGTU2GpJ3DEEh9S6iTYar4iJUByT0vQlHJfBL3OrtMKDbwK4LJNO9vbto2ZybsLnEMQKDyw05EYM25Q/cUZyxP8V4= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6271.eurprd04.prod.outlook.com (2603:10a6:803:f7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20; Mon, 12 Jul 2021 15:22:17 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab%7]) with mapi id 15.20.4308.026; Mon, 12 Jul 2021 15:22:17 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Jiri Pirko , Ido Schimmel , Tobias Waldekranz , Roopa Prabhu , Nikolay Aleksandrov , Stephen Hemminger , bridge@lists.linux-foundation.org, Grygorii Strashko Subject: [RFC PATCH v3 net-next 08/24] net: bridge: switchdev: recycle unused hwdoms Date: Mon, 12 Jul 2021 18:21:26 +0300 Message-Id: <20210712152142.800651-9-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712152142.800651-1-vladimir.oltean@nxp.com> References: <20210712152142.800651-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20 via Frontend Transport; Mon, 12 Jul 2021 15:22:16 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0a0e6e0e-d807-4115-b834-08d94548d5d2 X-MS-TrafficTypeDiagnostic: VI1PR04MB6271: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7691; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kcTxdLai+gKJb8wGgqtdrzOwVcJmDajX+BgPscgLTVTnfOxpPew2Xy9KrqtgP7aL3ws+KImPZeubRDNfdn5wnScqKFYX//egNTRndRqRT0VBE3RTouSwZxiUvCCYBAecXbNFUfM5S3yidKJnbqW6kaMdF4TO8+jA2td60uQHZjFFVYKltF1o5mEbDY5pTa7WiKemCh465+51FGRslg570AcCqZgmPkfUYxmjP4DtHzFmYO+yrGPuOIBpWadfAiMlvPg+bfvg9Y8vgsvvrH5kL/lpriAC5R6fS1dfgJeny2gzjO3US9au3U3FrvHUE804FoZdNU57eqIVA69/xY/9c47y3BuYou+fGJv8t3HCjikREXbGKLFMNjVvWgBbv8rimiN2sYSb1Zj+/7gbwe+oSBrQe52TVdtfSQX0Ca3lO45nppudB8jlRbsdGvo6n4QTAh6gOYgjtKYki31d+Cb6Nn5PqLKFRPG2aorNhL8ox3z9lzSSiZI0jgtqX4ar7M71emyiIuQAPFp8GZo+mIpi7knv/exOx8LmZN6xtaml/t1QkyZWlKnkiIM4dV/NLMmwDxRLDU0PnyHm3SV4GTa5+fCHiFtaJUxE/JU4aKyRHVk3urnV/3CtXyi+ebCXX8VKCNYRPW19W9oD+4UndzKQrIU36LPprvSIXdslhGw8UsN8oOuBZHRwwrlfw0F/+FPiZ2pYJ5mWIsYSwogQGi/eYg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(136003)(39850400004)(396003)(346002)(366004)(26005)(2906002)(66476007)(6666004)(83380400001)(66556008)(38100700002)(8676002)(38350700002)(66946007)(5660300002)(4326008)(54906003)(52116002)(7416002)(1076003)(110136005)(6506007)(316002)(86362001)(44832011)(478600001)(2616005)(956004)(6486002)(8936002)(36756003)(186003)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cVCDgEGuOJSlnG1tkPli3ueoAs5lBhVZE5T+fRnB//QOO/LdykwStqYgS4ZXA+r7+UeTctojDP+U1swGzPa6AhHhMxlqAdk1JxlAzQRbBkD2BFyWEpC6tyPkEA756xqivMLztDxDwyU1oqobWGR79/LTLH6ixrNf9/1SZapSfqkqOeMX1xHvM8wsSOfBNxg8emmi2CfMklwXNXqZZbc7CpxtBz0czT5UM62xfiYrBCqQN+5xrqxir90PZPwM6osufLmS47ZqeX6YVAZcZN/hJk3lU7owTcfAWkoo1CP0yAhmyAW5Oi1DS5ErsY21y5yMjGcU2DcWlixMjSriHKFGPRm7MMX+ctEq9OoPbhD8SFRY/moa5ygtG4rOrh0Z1ohP3A977kA0QBoe7fw7mMvJxbzWMtp3nWzc4kEFwm5rq5u8OwTVJo9BugT1kK+dVIhYcUZAz3dCdSD0F+EAxYxc51CbiuQLkjnKJ3ZAvMc61SdlZ4Zq51LRcyawE62+JkRcv+QcBtFKs1rHr8mkMyXKvo7dHdDp6iv5VEBlQ6KJu2EPKachvEmcJP14GNkmdRdAOHWptLlcTLiMpeFOAtbSIMbv0qwzwVFHr6ve9bVAGBdryvk/pKaOa7eanbsSJgVa0r0hJSpSlPks1w75tuC/7W6qffvzBI5bQdpAZxcQpR8d2ayOW3x8oP+emYcMXdJghTFAE4Z901XVTKqXqLwWDOtxR5OINHOYUKo99wBuwIq5WTbOH6yzEICZAz7fljYpOFjvy7f0XoeAMPZ8s/nYIQBovXq9kSBqaL1dwQxdABZslgzQYLr6SoKk5zPF+tzbOM2Ob1EDkKsymvppn4wPB5rZA39BjBHRhRRKFrbbFwk6+3poewXnqq02+GtcNOqlHcQQFVB70vxp9D1ynCgQxRy0fBm1bxbVunpms6GG+a2t5TAt0g9LCHRvXSCSny5M6qfbE49soSPoJZusk/+ekOQ5DQWk5/FPolbi7tqjgXPefIRuA2LbJmJHw4mlhNcfetD6MMtr7ayUGFdWHHryWmTbWDEeOU6iON6Un1aWj0kqt5/3oDjRwnSgoJRgkuFQMFfC9rgPfghoH2TEmLrsbXOpIhFlFCQk4T7ED0ofYgBGnR97rdy8/jb8DTgms7fKeDnpgLkmUxD0fWiwcg3wqyuHNVPZ+RxPnjAsGauKuArDeemGUkqtLU4r7DIVSCEJAIM+U7hvgfrnISACDYD1X6DwFRkt0c4q242Mth84R/rh51qH77I4+zyh2Kp/CPWXjkv3CmaNJY3EyDK+aP54hVzjCoHw8kG5YUAAruFo9j0fl3p9OHKOPttEvekRgSMD X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0a0e6e0e-d807-4115-b834-08d94548d5d2 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2021 15:22:17.8533 (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: JP8tvCbNM5c6sLKr4JjtrK2O96xImNQdXUCGeNke/HFMuqKUw8m/NtZNwlCgR4cdAlxvlU+TnX7zlj+CTJY/3A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6271 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Tobias Waldekranz Since hwdoms have only been used thus far for equality comparisons, the bridge has used the simplest possible assignment policy; using a counter to keep track of the last value handed out. With the upcoming transmit offloading, we need to perform set operations efficiently based on hwdoms, e.g. we want to answer questions like "has this skb been forwarded to any port within this hwdom?" Move to a bitmap-based allocation scheme that recycles hwdoms once all members leaves the bridge. This means that we can use a single unsigned long to keep track of the hwdoms that have received an skb. v1->v2: convert the typedef DECLARE_BITMAP(br_hwdom_map_t, BR_HWDOM_MAX) into a plain unsigned long. Signed-off-by: Tobias Waldekranz Signed-off-by: Vladimir Oltean --- net/bridge/br_if.c | 4 +- net/bridge/br_private.h | 27 ++++++++--- net/bridge/br_switchdev.c | 94 ++++++++++++++++++++++++++------------- 3 files changed, 86 insertions(+), 39 deletions(-) diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c index 73fa703f8df5..adaf78e45c23 100644 --- a/net/bridge/br_if.c +++ b/net/bridge/br_if.c @@ -349,6 +349,7 @@ static void del_nbp(struct net_bridge_port *p) nbp_backup_clear(p); nbp_update_port_count(br); + nbp_switchdev_del(p); netdev_upper_dev_unlink(dev, br->dev); @@ -643,7 +644,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev, if (err) goto err5; - err = nbp_switchdev_hwdom_set(p); + err = nbp_switchdev_add(p); if (err) goto err6; @@ -704,6 +705,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev, list_del_rcu(&p->list); br_fdb_delete_by_port(br, p, 0, 1); nbp_update_port_count(br); + nbp_switchdev_del(p); err6: netdev_upper_dev_unlink(dev, br->dev); err5: diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 54e29a8576a1..a23c565b8970 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -29,6 +29,8 @@ #define BR_MULTICAST_DEFAULT_HASH_MAX 4096 +#define BR_HWDOM_MAX BITS_PER_LONG + #define BR_VERSION "2.3" /* Control of forwarding link local multicast */ @@ -483,6 +485,8 @@ struct net_bridge { * identifiers in case a bridge spans multiple switchdev instances. */ int last_hwdom; + /* Bit mask of hardware domain numbers in use */ + unsigned long busy_hwdoms; #endif struct hlist_head fdb_list; @@ -1656,7 +1660,6 @@ static inline void br_sysfs_delbr(struct net_device *dev) { return; } /* br_switchdev.c */ #ifdef CONFIG_NET_SWITCHDEV -int nbp_switchdev_hwdom_set(struct net_bridge_port *p); void nbp_switchdev_frame_mark(const struct net_bridge_port *p, struct sk_buff *skb); bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p, @@ -1670,17 +1673,15 @@ void br_switchdev_fdb_notify(struct net_bridge *br, int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags, struct netlink_ext_ack *extack); int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid); +int nbp_switchdev_add(struct net_bridge_port *p); +void nbp_switchdev_del(struct net_bridge_port *p); +void br_switchdev_init(struct net_bridge *br); static inline void br_switchdev_frame_unmark(struct sk_buff *skb) { skb->offload_fwd_mark = 0; } #else -static inline int nbp_switchdev_hwdom_set(struct net_bridge_port *p) -{ - return 0; -} - static inline void nbp_switchdev_frame_mark(const struct net_bridge_port *p, struct sk_buff *skb) { @@ -1721,6 +1722,20 @@ br_switchdev_fdb_notify(struct net_bridge *br, static inline void br_switchdev_frame_unmark(struct sk_buff *skb) { } + +static inline int nbp_switchdev_add(struct net_bridge_port *p) +{ + return 0; +} + +static inline void nbp_switchdev_del(struct net_bridge_port *p) +{ +} + +static inline void br_switchdev_init(struct net_bridge *br) +{ +} + #endif /* CONFIG_NET_SWITCHDEV */ /* br_arp_nd_proxy.c */ diff --git a/net/bridge/br_switchdev.c b/net/bridge/br_switchdev.c index 833fd30482c2..f3120f13c293 100644 --- a/net/bridge/br_switchdev.c +++ b/net/bridge/br_switchdev.c @@ -8,38 +8,6 @@ #include "br_private.h" -static int br_switchdev_hwdom_get(struct net_bridge *br, struct net_device *dev) -{ - struct net_bridge_port *p; - - /* dev is yet to be added to the port list. */ - list_for_each_entry(p, &br->port_list, list) { - if (netdev_port_same_parent_id(dev, p->dev)) - return p->hwdom; - } - - return ++br->last_hwdom; -} - -int nbp_switchdev_hwdom_set(struct net_bridge_port *p) -{ - struct netdev_phys_item_id ppid = { }; - int err; - - ASSERT_RTNL(); - - err = dev_get_port_parent_id(p->dev, &ppid, true); - if (err) { - if (err == -EOPNOTSUPP) - return 0; - return err; - } - - p->hwdom = br_switchdev_hwdom_get(p->br, p->dev); - - return 0; -} - void nbp_switchdev_frame_mark(const struct net_bridge_port *p, struct sk_buff *skb) { @@ -156,3 +124,65 @@ int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid) return switchdev_port_obj_del(dev, &v.obj); } + +static int nbp_switchdev_hwdom_set(struct net_bridge_port *joining) +{ + struct net_bridge *br = joining->br; + struct net_bridge_port *p; + int hwdom; + + /* joining is yet to be added to the port list. */ + list_for_each_entry(p, &br->port_list, list) { + if (netdev_port_same_parent_id(joining->dev, p->dev)) { + joining->hwdom = p->hwdom; + return 0; + } + } + + hwdom = find_next_zero_bit(&br->busy_hwdoms, BR_HWDOM_MAX, 1); + if (hwdom >= BR_HWDOM_MAX) + return -EBUSY; + + set_bit(hwdom, &br->busy_hwdoms); + joining->hwdom = hwdom; + return 0; +} + +static void nbp_switchdev_hwdom_put(struct net_bridge_port *leaving) +{ + struct net_bridge *br = leaving->br; + struct net_bridge_port *p; + + /* leaving is no longer in the port list. */ + list_for_each_entry(p, &br->port_list, list) { + if (p->hwdom == leaving->hwdom) + return; + } + + clear_bit(leaving->hwdom, &br->busy_hwdoms); +} + +int nbp_switchdev_add(struct net_bridge_port *p) +{ + struct netdev_phys_item_id ppid = { }; + int err; + + ASSERT_RTNL(); + + err = dev_get_port_parent_id(p->dev, &ppid, true); + if (err) { + if (err == -EOPNOTSUPP) + return 0; + return err; + } + + return nbp_switchdev_hwdom_set(p); +} + +void nbp_switchdev_del(struct net_bridge_port *p) +{ + ASSERT_RTNL(); + + if (p->hwdom) + nbp_switchdev_hwdom_put(p); +} From patchwork Mon Jul 12 15:21:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 473339 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 09BE9C07E99 for ; Mon, 12 Jul 2021 15:22:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E049E60720 for ; Mon, 12 Jul 2021 15:22:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232203AbhGLPZT (ORCPT ); Mon, 12 Jul 2021 11:25:19 -0400 Received: from mail-am6eur05on2085.outbound.protection.outlook.com ([40.107.22.85]:46304 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235436AbhGLPZM (ORCPT ); Mon, 12 Jul 2021 11:25:12 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cbamjdU/BcO+WFqqVACs44BSKT3mYA3XJeNn2/Zm9jnyZPz91h9/HZMSu5vMph/bLWV1EfZqke4gtwJSCm6/xPS0qDNDXLt/rk2zNumWzw5Gl3yWBBoA0LbhBiGeaYcraNjAflbQg6SUEJbblJ+1xoIUhamwUc+21A9xkrpuiL6NpWe+9VC5pB61pciW3mps2CCmTyvg5txJmfW2VUYXCSmlnXL2yxhjFBlZJfnQfvhY7+LnOc02GDHsmRKG42VP6MayHbNVao55EFTeWNKG08w6Vu8SI4kIRdJXKMUNFE2QypW8x67yarHG4ft1XfNjWG98N5fvH49GLgtNzjT7YQ== 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-SenderADCheck; bh=3a2LA9lylvvI1GJM+h9wiUd37vOyGZzEgB1T+z4T9go=; b=OvLYYBzsObiJRUzT7qEEIrjMOYKBPd1ey6yNJUp9D3F6d4aQY/cyymAT/1oGDKmfN1idl8MoH4IPR1Uyl780CdNyEwiJBU8YysXNVlECzwhz5v2NW1eyweC1MiM33e+yleYQDkv4PUQt/48nlVbwegoSTG8GBP3Ry3Zwou3lSQ8TtH8v8W7dD82m5THWl6bhF6H2R562JM1Hvd/6gPJHMOLTdUshjwtsm3LlaStxo5S4B2H18ISJMqTEAXeeULo4IyI1Wmotgh+IYnW/MH3EybaV2FanHJ8yaj+IZgul3Ut4qbqfiejn62FMRW9d0fcRBplZSVQJ4bx6s+oI7OGJRA== 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=3a2LA9lylvvI1GJM+h9wiUd37vOyGZzEgB1T+z4T9go=; b=LMK8CgQhP6PFb2VxSFOS5Ed7Pd6kAHY8RwI2wmhj7uTvnEdJwpk/GpkVUU29sGf/WkcBxCLnZFb7Q3lIK5a2rFO7n6v1M8pMhbRg7tja5J9L/DWP6/wCLAi/joyTPY7kM3nn4QGddoRxPK/rwPTOUdYA7LTjVA4ovAF289Y0Qp8= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6271.eurprd04.prod.outlook.com (2603:10a6:803:f7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20; Mon, 12 Jul 2021 15:22:19 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab%7]) with mapi id 15.20.4308.026; Mon, 12 Jul 2021 15:22:19 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Jiri Pirko , Ido Schimmel , Tobias Waldekranz , Roopa Prabhu , Nikolay Aleksandrov , Stephen Hemminger , bridge@lists.linux-foundation.org, Grygorii Strashko Subject: [RFC PATCH v3 net-next 09/24] net: bridge: switchdev: let drivers inform which bridge ports are offloaded Date: Mon, 12 Jul 2021 18:21:27 +0300 Message-Id: <20210712152142.800651-10-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712152142.800651-1-vladimir.oltean@nxp.com> References: <20210712152142.800651-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20 via Frontend Transport; Mon, 12 Jul 2021 15:22:18 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 9b7c91b5-8ad6-4fa3-81e1-08d94548d6aa X-MS-TrafficTypeDiagnostic: VI1PR04MB6271: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Dd497EvXu6Op7JgNExmyzg/ZrCpLIO9Wow42bfeiwoYqESnkL4E73rcXfHE3Rqzx7vZABtMLh1u2neH4eT+MdXUs1D1mDPpTUVLLNirZrJa1+zqpsb8Cuj3vQXfVNVqt/twPz178bPBVqLdCFs8fbuzsy/eOn7pKhjItht0PqjjnBYSAhCg/7FOJDcTbsksbonHBIGrdOkUvn89TC+Y0AyMzIFe8DZzw6cKjCDNkLEtBylCXRaDlVkDvnQ5K7JfLxeDosK7ssWHfIqUb24ZzOISqrVEoZyrDlRPxNgpj2hBGIojTcEWbEuToPM9E4oU4Tpn1H1/UNu8VOERfzxS26kZyzUy98HrnLc64zzh/6XuBLsrnXU23MRHilfdSz4AGdEIW/OVtaFcyS47WGQ8keXO34KCDLGfO67zyxLqa1nIRGOVZVCQKNJOpU95TGhUC6LGLfWkujNwJvdTMgy0a5H4lMGdTadK5vV0ezu27CMvYpEVzFRqg5y1W8pXnfvpLya4SOh1xGV1psR+g1cRDSLwVMmkd5nsB9DsI4yACVESUKK/JLM0/2TKw7b4HJsNHjRbcq+Dd9Q7r51l3O0sCCNk6Dksr4S+ATV3rYelo8GnXb7AJaGDP26P+EY7nW3hkSFKYtZV3GIDDjbzXsqY60E0dUt4fHlCS4X/r6RE3YdBomw/Dc3OYSCmVX1swDErH X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(136003)(39850400004)(396003)(346002)(366004)(26005)(2906002)(66476007)(6666004)(83380400001)(66556008)(38100700002)(8676002)(30864003)(38350700002)(66946007)(5660300002)(4326008)(54906003)(52116002)(7416002)(1076003)(110136005)(6506007)(316002)(86362001)(44832011)(478600001)(2616005)(956004)(6486002)(8936002)(36756003)(186003)(6512007)(579004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: V3RzSaym2xP7Qr2xoX+onR0pvyGTBRT5wJxu4jHGpCxjV6oHyXqqs9KjP7SZXomDtXbqQAxzUyx6egk4XftjFtnpt9J0/FWHDG5Rij2bMyokYwjvZe24FGwAAva0DCVbvjTt8icazJvy7XVdaPwbnpT2ZYadEXOttoTTopBMmTljT7sZU7h7rrqeGFNMVLICb0zusC9618sDPl3FjJLfdMaaIob18+ohIFmds38feUroM8bRwKZiH91p2Xno59iHB/4NO2Iil2cNi3UtUg2SlNmo45dzr67dmxh0cJFxa+SSeW7EizMrvH+Fd0pxtvV+h+uS8dARjUR8svFnRx7Schojc3Oht/SvhsY9R6FZzE3Wqen9sTP8T7Tux+GpNdnJcKRXaWZEBj6YieV57XxngLWpin6Zo4hgRYTJ+WGzPydFIxnkNXAI21RkiAdrWH7WvOwu/5jwztOekkC65PtaCDiX27hJMWjARNIaE9PsDmb4EU0r6gwPd6Zl11ZTwC33NuWuRp2wRK6tz/5TPUCIds6/sj5kmy1KwApVnadJYD5KrVSKcP/YECYY/wqr8AJr6+D3mCoKkGxpV863ECfbdHqpuNMGhJFJ5H25C/34BOo3mvpvWbLJ5lfuP/Wx06DEG9gmYnd67yD5Pgc/ujF/Au9Ouo7rhQA5tBRV0bDvGrG8JTDGn8jtdmbz6pC3vLy++lvDRz7RpynClshZ+I8ziR7dQXqphCpA7403rEBxxFahJyxxggs2ZpqBDdTt047MD7EOo+9fl6JxjVYghExU6pa0xnz/QvG3x+rxPPO+qhhuBIc3GnVmNrokPXlohtOyyruvPDg83sDc8y1a6OI++X9z1yrlo7J+CkXCSDe5XHpblhDjN8HFmyBwUm5ya+YtMPxqyDliWWFLVKiTQwfMdmY/KwGrE0UVBH8jB21KdddnjQ9t9DCme+zn+r3nRw2Xd82vxGuTx7axJAp7tFbba3dUX6STYaEL91zTUWQbnXYjvs1YlXB9e6UCyCs3xde5aJR51jjtuN63kaaUbPoU4ZpiTQO68upwBj6rhTjjYwVaJFakrWjbcXPEc+Mnbf1BsGH+O5wqHKcuMUtx5dtqvdVAyd33CS0ZNOC1C6ccpC6Nd4E1srAjc1kM0kD72NRg6EAZZ0OKQ8hOca1ZBoPFCYSdfh92VoQz2zxnW7VWtsA2UfbCrpq6GF82tikGm8dmkxpCXw2/saVmepwmDCBIXux0EsUFcK346bDt7kC6yld6otqCVjqAZNHblRNJaxh92NhHeXiXyukZdj9/FQ/f/E/hh45HZ9ec24RFzzpn0bq/vizSI9pJ8gOjR7LOwofr X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9b7c91b5-8ad6-4fa3-81e1-08d94548d6aa X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2021 15:22:19.4154 (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: MF5mSEixK1PItlTfBTjCpijOElob0D5epnYrt6BUfvRKvks+TreYrZuhA4T9LDJaOQfzemZlLJy59CUgE5tGIQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6271 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On reception of an skb, the bridge checks if it was marked as 'already forwarded in hardware' (checks if skb->offload_fwd_mark == 1), and if it is, it assigns the source hardware domain of that skb based on the hardware domain of the ingress port. Then during forwarding, it enforces that the egress port must have a different hardware domain than the ingress one (this is done in nbp_switchdev_allowed_egress). Non-switchdev drivers don't report any physical switch id (neither through devlink nor .ndo_get_port_parent_id), therefore the bridge assigns them a hardware domain of 0, and packets coming from them will always have skb->offload_fwd_mark = 0. So there aren't any restrictions. Problems appear due to the fact that DSA would like to perform software fallback for bonding and team interfaces that the physical switch cannot offload. +-- br0 ---+ / / | \ / / | \ / | | bond0 / | | / \ swp0 swp1 swp2 swp3 swp4 There, it is desirable that the presence of swp3 and swp4 under a non-offloaded LAG does not preclude us from doing hardware bridging beteen swp0, swp1 and swp2. The bandwidth of the CPU is often times high enough that software bridging between {swp0,swp1,swp2} and bond0 is not impractical. But this creates an impossible paradox given the current way in which port hardware domains are assigned. When the driver receives a packet from swp0 (say, due to flooding), it must set skb->offload_fwd_mark to something. - If we set it to 0, then the bridge will forward it towards swp1, swp2 and bond0. But the switch has already forwarded it towards swp1 and swp2 (not to bond0, remember, that isn't offloaded, so as far as the switch is concerned, ports swp3 and swp4 are not looking up the FDB, and the entire bond0 is a destination that is strictly behind the CPU). But we don't want duplicated traffic towards swp1 and swp2, so it's not ok to set skb->offload_fwd_mark = 0. - If we set it to 1, then the bridge will not forward the skb towards the ports with the same switchdev mark, i.e. not to swp1, swp2 and bond0. Towards swp1 and swp2 that's ok, but towards bond0? It should have forwarded the skb there. So the real issue is that bond0 will be assigned the same hardware domain as {swp0,swp1,swp2}, because the function that assigns hardware domains to bridge ports, nbp_switchdev_add(), recurses through bond0's lower interfaces until it finds something that implements devlink (calls dev_get_port_parent_id with bool recurse = true). This is a problem because the fact that bond0 can be offloaded by swp3 and swp4 in our example is merely an assumption. A solution is to give the bridge explicit hints as to what hardware domain it should use for each port. Currently, the bridging offload is very 'silent': a driver registers a netdevice notifier, which is put on the netns's notifier chain, and which sniffs around for NETDEV_CHANGEUPPER events where the upper is a bridge, and the lower is an interface it knows about (one registered by this driver, normally). Then, from within that notifier, it does a bunch of stuff behind the bridge's back, without the bridge necessarily knowing that there's somebody offloading that port. It looks like this: ip link set swp0 master br0 | v br_add_if() calls netdev_master_upper_dev_link() | v call_netdevice_notifiers | v dsa_slave_netdevice_event | v oh, hey! it's for me! | v .port_bridge_join What we do to solve the conundrum is to be less silent, and change the switchdev drivers to present themselves to the bridge. Something like this: ip link set swp0 master br0 | v br_add_if() calls netdev_master_upper_dev_link() | v bridge: Aye! I'll use this call_netdevice_notifiers ^ ppid as the | | hardware domain for v | this port, and zero dsa_slave_netdevice_event | if I got nothing. | | v | oh, hey! it's for me! | | | v | .port_bridge_join | | | +------------------------+ switchdev_bridge_port_offload(swp0, swp0) Then stacked interfaces (like bond0 on top of swp3/swp4) would be treated differently in DSA, depending on whether we can or cannot offload them. The offload case: ip link set bond0 master br0 | v br_add_if() calls netdev_master_upper_dev_link() | v bridge: Aye! I'll use this call_netdevice_notifiers ^ ppid as the | | switchdev mark for v | bond0. dsa_slave_netdevice_event | Coincidentally (or not), | | bond0 and swp0, swp1, swp2 v | all have the same switchdev hmm, it's not quite for me, | mark now, since the ASIC but my driver has already | is able to forward towards called .port_lag_join | all these ports in hw. for it, because I have | a port with dp->lag_dev == bond0. | | | v | .port_bridge_join | for swp3 and swp4 | | | +------------------------+ switchdev_bridge_port_offload(bond0, swp3) switchdev_bridge_port_offload(bond0, swp4) And the non-offload case: ip link set bond0 master br0 | v br_add_if() calls netdev_master_upper_dev_link() | v bridge waiting: call_netdevice_notifiers ^ huh, switchdev_bridge_port_offload | | wasn't called, okay, I'll use a v | hwdom of zero for this one. dsa_slave_netdevice_event : Then packets received on swp0 will | : not be software-forwarded towards v : swp1, but they will towards bond0. it's not for me, but bond0 is an upper of swp3 and swp4, but their dp->lag_dev is NULL because they couldn't offload it. Basically we can draw the conclusion that the lowers of a bridge port can come and go, so depending on the configuration of lowers for a bridge port, it can dynamically toggle between offloaded and unoffloaded. Therefore, we need an equivalent switchdev_bridge_port_unoffload too. This patch changes the way any switchdev driver interacts with the bridge. From now on, everybody needs to call switchdev_bridge_port_offload and switchdev_bridge_port_unoffload, otherwise the bridge will treat the port as non-offloaded and allow software flooding to other ports from the same ASIC. Note that these functions lay the ground for a more complex handshake between switchdev drivers and the bridge in the future. During the info->linking == false path, switchdev_bridge_port_unoffload() is strategically put in the NETDEV_PRECHANGEUPPER notifier as opposed to NETDEV_CHANGEUPPER. The reason for this has to do with a future migration of the switchdev object replay helpers (br_*_replay) from a pull mode (completely initiated by the driver) to a semi-push mode (the bridge initiates the replay when the switchdev driver declares that it offloads a port). On deletion, the switchdev object replay helpers need the netdev adjacency lists to be valid, and that is only true in NETDEV_PRECHANGEUPPER. So we need to add trivial glue code to all drivers to handle a "pre bridge leave" event, and that is where we hook the switchdev_bridge_port_unoffload() call. Signed-off-by: Vladimir Oltean --- .../ethernet/freescale/dpaa2/dpaa2-switch.c | 14 ++- .../ethernet/marvell/prestera/prestera_main.c | 32 ++++++- .../marvell/prestera/prestera_switchdev.c | 29 +++++- .../marvell/prestera/prestera_switchdev.h | 7 +- .../net/ethernet/mellanox/mlxsw/spectrum.c | 12 +++ .../net/ethernet/mellanox/mlxsw/spectrum.h | 4 + .../mellanox/mlxsw/spectrum_switchdev.c | 13 ++- .../microchip/sparx5/sparx5_switchdev.c | 41 +++++++- drivers/net/ethernet/mscc/ocelot_net.c | 81 ++++++++++++++++ drivers/net/ethernet/rocker/rocker.h | 6 +- drivers/net/ethernet/rocker/rocker_main.c | 30 +++++- drivers/net/ethernet/rocker/rocker_ofdpa.c | 37 +++++++- drivers/net/ethernet/ti/am65-cpsw-nuss.c | 28 +++++- drivers/net/ethernet/ti/cpsw_new.c | 26 ++++- include/linux/if_bridge.h | 26 +++++ net/bridge/br_if.c | 13 +-- net/bridge/br_private.h | 13 +-- net/bridge/br_switchdev.c | 94 +++++++++++++++++-- net/dsa/port.c | 20 +++- 19 files changed, 470 insertions(+), 56 deletions(-) diff --git a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c index f6d4cf053ff7..927502043910 100644 --- a/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c +++ b/drivers/net/ethernet/freescale/dpaa2/dpaa2-switch.c @@ -1930,7 +1930,7 @@ static int dpaa2_switch_port_bridge_join(struct net_device *netdev, if (err) goto err_egress_flood; - return 0; + return switchdev_bridge_port_offload(netdev, netdev, extack); err_egress_flood: dpaa2_switch_port_set_fdb(port_priv, NULL); @@ -1957,6 +1957,13 @@ static int dpaa2_switch_port_restore_rxvlan(struct net_device *vdev, int vid, vo return dpaa2_switch_port_vlan_add(arg, vlan_proto, vid); } +static int dpaa2_switch_port_pre_bridge_leave(struct net_device *netdev, + struct net_device *upper_dev, + struct netlink_ext_ack *extack) +{ + return switchdev_bridge_port_unoffload(netdev, netdev, extack); +} + static int dpaa2_switch_port_bridge_leave(struct net_device *netdev) { struct ethsw_port_priv *port_priv = netdev_priv(netdev); @@ -2078,6 +2085,11 @@ static int dpaa2_switch_port_netdevice_event(struct notifier_block *nb, if (err) goto out; + if (!info->linking) + err = dpaa2_switch_port_pre_bridge_leave(netdev, + upper_dev, + extack); + break; case NETDEV_CHANGEUPPER: upper_dev = info->upper_dev; diff --git a/drivers/net/ethernet/marvell/prestera/prestera_main.c b/drivers/net/ethernet/marvell/prestera/prestera_main.c index 508c03cc8edb..90da8902c95e 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_main.c +++ b/drivers/net/ethernet/marvell/prestera/prestera_main.c @@ -540,7 +540,8 @@ static void prestera_lag_destroy(struct prestera_switch *sw, } static int prestera_lag_port_add(struct prestera_port *port, - struct net_device *lag_dev) + struct net_device *lag_dev, + struct netlink_ext_ack *extack) { struct prestera_switch *sw = port->sw; struct prestera_lag *lag; @@ -572,7 +573,22 @@ static int prestera_lag_port_add(struct prestera_port *port, br_dev = netdev_master_upper_dev_get(lag_dev); - return prestera_bridge_port_join(br_dev, port); + return prestera_bridge_port_join(br_dev, port, extack); + } + + return 0; +} + +static int prestera_pre_lag_leave(struct prestera_port *port, + struct net_device *lag_dev, + struct netlink_ext_ack *extack) +{ + if (netif_is_bridge_port(lag_dev)) { + struct net_device *br_dev; + + br_dev = netdev_master_upper_dev_get(lag_dev); + + return prestera_pre_bridge_port_leave(br_dev, port, extack); } return 0; @@ -766,17 +782,25 @@ static int prestera_netdev_port_event(struct net_device *lower, if (err) return err; + if (netif_is_bridge_master(upper) && !info->linking) + return prestera_pre_bridge_port_leave(upper, port, + extack); + else if (netif_is_lag_master(upper) && !info->linking) + return prestera_pre_lag_leave(port, upper, extack); + break; case NETDEV_CHANGEUPPER: if (netif_is_bridge_master(upper)) { if (info->linking) - return prestera_bridge_port_join(upper, port); + return prestera_bridge_port_join(upper, port, + extack); else prestera_bridge_port_leave(upper, port); } else if (netif_is_lag_master(upper)) { if (info->linking) - return prestera_lag_port_add(port, upper); + return prestera_lag_port_add(port, upper, + extack); else prestera_lag_port_del(port); } diff --git a/drivers/net/ethernet/marvell/prestera/prestera_switchdev.c b/drivers/net/ethernet/marvell/prestera/prestera_switchdev.c index 0b3e8f2db294..ae117104a23a 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_switchdev.c +++ b/drivers/net/ethernet/marvell/prestera/prestera_switchdev.c @@ -480,7 +480,8 @@ prestera_bridge_1d_port_join(struct prestera_bridge_port *br_port) } int prestera_bridge_port_join(struct net_device *br_dev, - struct prestera_port *port) + struct prestera_port *port, + struct netlink_ext_ack *extack) { struct prestera_switchdev *swdev = port->sw->swdev; struct prestera_bridge_port *br_port; @@ -500,6 +501,10 @@ int prestera_bridge_port_join(struct net_device *br_dev, goto err_brport_create; } + err = switchdev_bridge_port_offload(br_port->dev, port->dev, extack); + if (err) + goto err_brport_offload; + if (bridge->vlan_enabled) return 0; @@ -510,12 +515,34 @@ int prestera_bridge_port_join(struct net_device *br_dev, return 0; err_port_join: + switchdev_bridge_port_unoffload(br_port->dev, port->dev, extack); +err_brport_offload: prestera_bridge_port_put(br_port); err_brport_create: prestera_bridge_put(bridge); return err; } +int prestera_pre_bridge_port_leave(struct net_device *br_dev, + struct prestera_port *port, + struct netlink_ext_ack *extack) +{ + struct prestera_switchdev *swdev = port->sw->swdev; + struct prestera_bridge_port *br_port; + struct prestera_bridge *bridge; + + bridge = prestera_bridge_by_dev(swdev, br_dev); + if (!bridge) + return -ENODEV; + + br_port = __prestera_bridge_port_by_dev(bridge, port->dev); + if (!br_port) + return -ENODEV; + + return switchdev_bridge_port_unoffload(br_port->dev, port->dev, + extack); +} + static void prestera_bridge_1q_port_leave(struct prestera_bridge_port *br_port) { struct prestera_port *port = netdev_priv(br_port->dev); diff --git a/drivers/net/ethernet/marvell/prestera/prestera_switchdev.h b/drivers/net/ethernet/marvell/prestera/prestera_switchdev.h index a91bc35d235f..05ec54e2af26 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_switchdev.h +++ b/drivers/net/ethernet/marvell/prestera/prestera_switchdev.h @@ -8,7 +8,12 @@ int prestera_switchdev_init(struct prestera_switch *sw); void prestera_switchdev_fini(struct prestera_switch *sw); int prestera_bridge_port_join(struct net_device *br_dev, - struct prestera_port *port); + struct prestera_port *port, + struct netlink_ext_ack *extack); + +int prestera_pre_bridge_port_leave(struct net_device *br_dev, + struct prestera_port *port, + struct netlink_ext_ack *extack); void prestera_bridge_port_leave(struct net_device *br_dev, struct prestera_port *port); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c index 985bae6cf083..11fa8bc6e7cd 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.c @@ -4187,6 +4187,12 @@ static int mlxsw_sp_netdevice_port_upper_event(struct net_device *lower_dev, if (err) return err; + if (netif_is_bridge_master(upper_dev) && !info->linking) + err = mlxsw_sp_port_pre_bridge_leave(mlxsw_sp_port, + lower_dev, + upper_dev, + extack); + break; case NETDEV_CHANGEUPPER: upper_dev = info->upper_dev; @@ -4358,6 +4364,12 @@ static int mlxsw_sp_netdevice_port_vlan_event(struct net_device *vlan_dev, if (err) return err; + if (netif_is_bridge_master(upper_dev) && !info->linking) + err = mlxsw_sp_port_pre_bridge_leave(mlxsw_sp_port, + vlan_dev, + upper_dev, + extack); + break; case NETDEV_CHANGEUPPER: upper_dev = info->upper_dev; diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h index f99db88ee884..54d22ecee4e2 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum.h +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum.h @@ -596,6 +596,10 @@ int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port, struct net_device *brport_dev, struct net_device *br_dev, struct netlink_ext_ack *extack); +int mlxsw_sp_port_pre_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port, + struct net_device *brport_dev, + struct net_device *br_dev, + struct netlink_ext_ack *extack); void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port, struct net_device *brport_dev, struct net_device *br_dev); diff --git a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c index c5ef9aa64efe..cbcf38338f3e 100644 --- a/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c +++ b/drivers/net/ethernet/mellanox/mlxsw/spectrum_switchdev.c @@ -2363,6 +2363,7 @@ int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port, { struct mlxsw_sp *mlxsw_sp = mlxsw_sp_port->mlxsw_sp; struct mlxsw_sp_bridge_device *bridge_device; + struct net_device *dev = mlxsw_sp_port->dev; struct mlxsw_sp_bridge_port *bridge_port; int err; @@ -2377,13 +2378,23 @@ int mlxsw_sp_port_bridge_join(struct mlxsw_sp_port *mlxsw_sp_port, if (err) goto err_port_join; - return 0; + return switchdev_bridge_port_offload(brport_dev, dev, extack); err_port_join: mlxsw_sp_bridge_port_put(mlxsw_sp->bridge, bridge_port); return err; } +int mlxsw_sp_port_pre_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port, + struct net_device *brport_dev, + struct net_device *br_dev, + struct netlink_ext_ack *extack) +{ + struct net_device *dev = mlxsw_sp_port->dev; + + return switchdev_bridge_port_unoffload(brport_dev, dev, extack); +} + void mlxsw_sp_port_bridge_leave(struct mlxsw_sp_port *mlxsw_sp_port, struct net_device *brport_dev, struct net_device *br_dev) diff --git a/drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c b/drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c index a72e3b3b596e..270b9fabce91 100644 --- a/drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c +++ b/drivers/net/ethernet/microchip/sparx5/sparx5_switchdev.c @@ -93,9 +93,11 @@ static int sparx5_port_attr_set(struct net_device *dev, const void *ctx, } static int sparx5_port_bridge_join(struct sparx5_port *port, - struct net_device *bridge) + struct net_device *bridge, + struct netlink_ext_ack *extack) { struct sparx5 *sparx5 = port->sparx5; + struct net_device *ndev = port->ndev; if (bitmap_empty(sparx5->bridge_mask, SPX5_PORTS)) /* First bridged port */ @@ -112,9 +114,17 @@ static int sparx5_port_bridge_join(struct sparx5_port *port, /* Port enters in bridge mode therefor don't need to copy to CPU * frames for multicast in case the bridge is not requesting them */ - __dev_mc_unsync(port->ndev, sparx5_mc_unsync); + __dev_mc_unsync(ndev, sparx5_mc_unsync); - return 0; + return switchdev_bridge_port_offload(ndev, ndev, extack); +} + +static int sparx5_port_pre_bridge_leave(struct sparx5_port *port, + struct netlink_ext_ack *extack) +{ + struct net_device *ndev = port->ndev; + + return switchdev_bridge_port_unoffload(ndev, ndev, extack); } static void sparx5_port_bridge_leave(struct sparx5_port *port, @@ -135,15 +145,35 @@ static void sparx5_port_bridge_leave(struct sparx5_port *port, __dev_mc_sync(port->ndev, sparx5_mc_sync, sparx5_mc_unsync); } +static int +sparx5_port_prechangeupper(struct net_device *dev, + struct netdev_notifier_changeupper_info *info) +{ + struct sparx5_port *port = netdev_priv(dev); + struct netlink_ext_ack *extack; + int err = 0; + + extack = netdev_notifier_info_to_extack(&info->info); + + if (netif_is_bridge_master(info->upper_dev) && !info->linking) + err = sparx5_port_pre_bridge_leave(port, extack); + + return err; +} + static int sparx5_port_changeupper(struct net_device *dev, struct netdev_notifier_changeupper_info *info) { struct sparx5_port *port = netdev_priv(dev); + struct netlink_ext_ack *extack; int err = 0; + extack = netdev_notifier_info_to_extack(&info->info); + if (netif_is_bridge_master(info->upper_dev)) { if (info->linking) - err = sparx5_port_bridge_join(port, info->upper_dev); + err = sparx5_port_bridge_join(port, info->upper_dev, + extack); else sparx5_port_bridge_leave(port, info->upper_dev); @@ -177,6 +207,9 @@ static int sparx5_netdevice_port_event(struct net_device *dev, return 0; switch (event) { + case NETDEV_PRECHANGEUPPER: + err = sparx5_port_prechangeupper(dev, ptr); + break; case NETDEV_CHANGEUPPER: err = sparx5_port_changeupper(dev, ptr); break; diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c index e9d260d84bf3..dcb393a35c0e 100644 --- a/drivers/net/ethernet/mscc/ocelot_net.c +++ b/drivers/net/ethernet/mscc/ocelot_net.c @@ -1216,6 +1216,10 @@ static int ocelot_netdevice_bridge_join(struct net_device *dev, ocelot_port_bridge_join(ocelot, port, bridge); + err = switchdev_bridge_port_offload(brport_dev, dev, extack); + if (err) + goto err_switchdev_offload; + err = ocelot_switchdev_sync(ocelot, port, brport_dev, bridge, extack); if (err) goto err_switchdev_sync; @@ -1223,10 +1227,19 @@ static int ocelot_netdevice_bridge_join(struct net_device *dev, return 0; err_switchdev_sync: + switchdev_bridge_port_unoffload(brport_dev, dev, extack); +err_switchdev_offload: ocelot_port_bridge_leave(ocelot, port, bridge); return err; } +static int ocelot_netdevice_pre_bridge_leave(struct net_device *dev, + struct net_device *brport_dev, + struct netlink_ext_ack *extack) +{ + return switchdev_bridge_port_unoffload(brport_dev, dev, extack); +} + static int ocelot_netdevice_bridge_leave(struct net_device *dev, struct net_device *brport_dev, struct net_device *bridge) @@ -1279,6 +1292,19 @@ static int ocelot_netdevice_lag_join(struct net_device *dev, return err; } +static int ocelot_netdevice_pre_lag_leave(struct net_device *dev, + struct net_device *bond, + struct netlink_ext_ack *extack) +{ + struct net_device *bridge_dev; + + bridge_dev = netdev_master_upper_dev_get(bond); + if (!bridge_dev || !netif_is_bridge_master(bridge_dev)) + return 0; + + return ocelot_netdevice_pre_bridge_leave(dev, bond, extack); +} + static int ocelot_netdevice_lag_leave(struct net_device *dev, struct net_device *bond) { @@ -1355,6 +1381,50 @@ ocelot_netdevice_lag_changeupper(struct net_device *dev, return NOTIFY_DONE; } +static int +ocelot_netdevice_prechangeupper(struct net_device *dev, + struct net_device *brport_dev, + struct netdev_notifier_changeupper_info *info) +{ + struct netlink_ext_ack *extack; + int err = 0; + + extack = netdev_notifier_info_to_extack(&info->info); + + if (netif_is_bridge_master(info->upper_dev) && !info->linking) + err = ocelot_netdevice_pre_bridge_leave(dev, brport_dev, + extack); + + if (netif_is_lag_master(info->upper_dev) && !info->linking) + err = ocelot_netdevice_pre_lag_leave(dev, info->upper_dev, + extack); + + return notifier_from_errno(err); +} + +static int +ocelot_netdevice_lag_prechangeupper(struct net_device *dev, + struct netdev_notifier_changeupper_info *info) +{ + struct net_device *lower; + struct list_head *iter; + int err = NOTIFY_DONE; + + netdev_for_each_lower_dev(dev, lower, iter) { + struct ocelot_port_private *priv = netdev_priv(lower); + struct ocelot_port *ocelot_port = &priv->port; + + if (ocelot_port->bond != dev) + return NOTIFY_OK; + + err = ocelot_netdevice_prechangeupper(dev, lower, info); + if (err) + return notifier_from_errno(err); + } + + return NOTIFY_DONE; +} + static int ocelot_netdevice_changelowerstate(struct net_device *dev, struct netdev_lag_lower_state_info *info) @@ -1382,6 +1452,17 @@ static int ocelot_netdevice_event(struct notifier_block *unused, struct net_device *dev = netdev_notifier_info_to_dev(ptr); switch (event) { + case NETDEV_PRECHANGEUPPER: { + struct netdev_notifier_changeupper_info *info = ptr; + + if (ocelot_netdevice_dev_check(dev)) + return ocelot_netdevice_prechangeupper(dev, dev, info); + + if (netif_is_lag_master(dev)) + return ocelot_netdevice_lag_prechangeupper(dev, info); + + break; + } case NETDEV_CHANGEUPPER: { struct netdev_notifier_changeupper_info *info = ptr; diff --git a/drivers/net/ethernet/rocker/rocker.h b/drivers/net/ethernet/rocker/rocker.h index 315a6e5c0f59..d31cee1cdda9 100644 --- a/drivers/net/ethernet/rocker/rocker.h +++ b/drivers/net/ethernet/rocker/rocker.h @@ -119,7 +119,11 @@ struct rocker_world_ops { int (*port_obj_fdb_del)(struct rocker_port *rocker_port, u16 vid, const unsigned char *addr); int (*port_master_linked)(struct rocker_port *rocker_port, - struct net_device *master); + struct net_device *master, + struct netlink_ext_ack *extack); + int (*port_master_pre_unlink)(struct rocker_port *rocker_port, + struct net_device *master, + struct netlink_ext_ack *extack); int (*port_master_unlinked)(struct rocker_port *rocker_port, struct net_device *master); int (*port_neigh_update)(struct rocker_port *rocker_port, diff --git a/drivers/net/ethernet/rocker/rocker_main.c b/drivers/net/ethernet/rocker/rocker_main.c index a46633606cae..2e3e413406ac 100644 --- a/drivers/net/ethernet/rocker/rocker_main.c +++ b/drivers/net/ethernet/rocker/rocker_main.c @@ -1670,13 +1670,25 @@ rocker_world_port_fdb_del(struct rocker_port *rocker_port, } static int rocker_world_port_master_linked(struct rocker_port *rocker_port, - struct net_device *master) + struct net_device *master, + struct netlink_ext_ack *extack) { struct rocker_world_ops *wops = rocker_port->rocker->wops; if (!wops->port_master_linked) return -EOPNOTSUPP; - return wops->port_master_linked(rocker_port, master); + return wops->port_master_linked(rocker_port, master, extack); +} + +static int rocker_world_port_master_pre_unlink(struct rocker_port *rocker_port, + struct net_device *master, + struct netlink_ext_ack *extack) +{ + struct rocker_world_ops *wops = rocker_port->rocker->wops; + + if (!wops->port_master_pre_unlink) + return -EOPNOTSUPP; + return wops->port_master_pre_unlink(rocker_port, master, extack); } static int rocker_world_port_master_unlinked(struct rocker_port *rocker_port, @@ -3107,6 +3119,7 @@ struct rocker_port *rocker_port_dev_lower_find(struct net_device *dev, static int rocker_netdevice_event(struct notifier_block *unused, unsigned long event, void *ptr) { + struct netlink_ext_ack *extack = netdev_notifier_info_to_extack(ptr); struct net_device *dev = netdev_notifier_info_to_dev(ptr); struct netdev_notifier_changeupper_info *info; struct rocker_port *rocker_port; @@ -3116,6 +3129,16 @@ static int rocker_netdevice_event(struct notifier_block *unused, return NOTIFY_DONE; switch (event) { + case NETDEV_PRECHANGEUPPER: + info = ptr; + if (!info->master) + goto out; + rocker_port = netdev_priv(dev); + if (!info->linking) + err = rocker_world_port_master_pre_unlink(rocker_port, + info->upper_dev, + extack); + break; case NETDEV_CHANGEUPPER: info = ptr; if (!info->master) @@ -3123,7 +3146,8 @@ static int rocker_netdevice_event(struct notifier_block *unused, rocker_port = netdev_priv(dev); if (info->linking) { err = rocker_world_port_master_linked(rocker_port, - info->upper_dev); + info->upper_dev, + extack); if (err) netdev_warn(dev, "failed to reflect master linked (err %d)\n", err); diff --git a/drivers/net/ethernet/rocker/rocker_ofdpa.c b/drivers/net/ethernet/rocker/rocker_ofdpa.c index 967a634ee9ac..3569227e3a72 100644 --- a/drivers/net/ethernet/rocker/rocker_ofdpa.c +++ b/drivers/net/ethernet/rocker/rocker_ofdpa.c @@ -2571,8 +2571,10 @@ static int ofdpa_port_obj_fdb_del(struct rocker_port *rocker_port, } static int ofdpa_port_bridge_join(struct ofdpa_port *ofdpa_port, - struct net_device *bridge) + struct net_device *bridge, + struct netlink_ext_ack *extack) { + struct net_device *dev = ofdpa_port->dev; int err; /* Port is joining bridge, so the internal VLAN for the @@ -2592,7 +2594,19 @@ static int ofdpa_port_bridge_join(struct ofdpa_port *ofdpa_port, ofdpa_port->bridge_dev = bridge; - return ofdpa_port_vlan_add(ofdpa_port, OFDPA_UNTAGGED_VID, 0); + err = ofdpa_port_vlan_add(ofdpa_port, OFDPA_UNTAGGED_VID, 0); + if (err) + return err; + + return switchdev_bridge_port_offload(dev, dev, extack); +} + +static int ofdpa_port_pre_bridge_leave(struct ofdpa_port *ofdpa_port, + struct netlink_ext_ack *extack) +{ + struct net_device *dev = ofdpa_port->dev; + + return switchdev_bridge_port_unoffload(dev, dev, extack); } static int ofdpa_port_bridge_leave(struct ofdpa_port *ofdpa_port) @@ -2637,18 +2651,32 @@ static int ofdpa_port_ovs_changed(struct ofdpa_port *ofdpa_port, } static int ofdpa_port_master_linked(struct rocker_port *rocker_port, - struct net_device *master) + struct net_device *master, + struct netlink_ext_ack *extack) { struct ofdpa_port *ofdpa_port = rocker_port->wpriv; int err = 0; if (netif_is_bridge_master(master)) - err = ofdpa_port_bridge_join(ofdpa_port, master); + err = ofdpa_port_bridge_join(ofdpa_port, master, extack); else if (netif_is_ovs_master(master)) err = ofdpa_port_ovs_changed(ofdpa_port, master); return err; } + +static int ofdpa_port_master_pre_unlink(struct rocker_port *rocker_port, + struct net_device *master, + struct netlink_ext_ack *extack) +{ + struct ofdpa_port *ofdpa_port = rocker_port->wpriv; + int err = 0; + + if (netif_is_bridge_master(master)) + err = ofdpa_port_pre_bridge_leave(ofdpa_port, extack); + return err; +} + static int ofdpa_port_master_unlinked(struct rocker_port *rocker_port, struct net_device *master) { @@ -2800,6 +2828,7 @@ struct rocker_world_ops rocker_ofdpa_ops = { .port_obj_fdb_add = ofdpa_port_obj_fdb_add, .port_obj_fdb_del = ofdpa_port_obj_fdb_del, .port_master_linked = ofdpa_port_master_linked, + .port_master_pre_unlink = ofdpa_port_master_pre_unlink, .port_master_unlinked = ofdpa_port_master_unlinked, .port_neigh_update = ofdpa_port_neigh_update, .port_neigh_destroy = ofdpa_port_neigh_destroy, diff --git a/drivers/net/ethernet/ti/am65-cpsw-nuss.c b/drivers/net/ethernet/ti/am65-cpsw-nuss.c index 718539cdd2f2..30e8b21dc6db 100644 --- a/drivers/net/ethernet/ti/am65-cpsw-nuss.c +++ b/drivers/net/ethernet/ti/am65-cpsw-nuss.c @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -2077,10 +2078,13 @@ bool am65_cpsw_port_dev_check(const struct net_device *ndev) return false; } -static int am65_cpsw_netdevice_port_link(struct net_device *ndev, struct net_device *br_ndev) +static int am65_cpsw_netdevice_port_link(struct net_device *ndev, + struct net_device *br_ndev, + struct netlink_ext_ack *extack) { struct am65_cpsw_common *common = am65_ndev_to_common(ndev); struct am65_cpsw_ndev_priv *priv = am65_ndev_to_priv(ndev); + int err; if (!common->br_members) { common->hw_bridge_dev = br_ndev; @@ -2092,6 +2096,10 @@ static int am65_cpsw_netdevice_port_link(struct net_device *ndev, struct net_dev return -EOPNOTSUPP; } + err = switchdev_bridge_port_offload(ndev, ndev, extack); + if (err) + return err; + common->br_members |= BIT(priv->port->port_id); am65_cpsw_port_offload_fwd_mark_update(common); @@ -2099,6 +2107,12 @@ static int am65_cpsw_netdevice_port_link(struct net_device *ndev, struct net_dev return NOTIFY_DONE; } +static int am65_cpsw_netdevice_port_pre_unlink(struct net_device *ndev, + struct netlink_ext_ack *extack) +{ + return switchdev_bridge_port_unoffload(ndev, ndev, extack); +} + static void am65_cpsw_netdevice_port_unlink(struct net_device *ndev) { struct am65_cpsw_common *common = am65_ndev_to_common(ndev); @@ -2116,6 +2130,7 @@ static void am65_cpsw_netdevice_port_unlink(struct net_device *ndev) static int am65_cpsw_netdevice_event(struct notifier_block *unused, unsigned long event, void *ptr) { + struct netlink_ext_ack *extack = netdev_notifier_info_to_extack(ptr); struct net_device *ndev = netdev_notifier_info_to_dev(ptr); struct netdev_notifier_changeupper_info *info; int ret = NOTIFY_DONE; @@ -2124,12 +2139,21 @@ static int am65_cpsw_netdevice_event(struct notifier_block *unused, return NOTIFY_DONE; switch (event) { + case NETDEV_PRECHANGEUPPER: + info = ptr; + + if (netif_is_bridge_master(info->upper_dev) && !info->linking) + ret = am65_cpsw_netdevice_port_pre_unlink(ndev, extack); + + break; case NETDEV_CHANGEUPPER: info = ptr; if (netif_is_bridge_master(info->upper_dev)) { if (info->linking) - ret = am65_cpsw_netdevice_port_link(ndev, info->upper_dev); + ret = am65_cpsw_netdevice_port_link(ndev, + info->upper_dev, + extack); else am65_cpsw_netdevice_port_unlink(ndev); } diff --git a/drivers/net/ethernet/ti/cpsw_new.c b/drivers/net/ethernet/ti/cpsw_new.c index 57d279fdcc9f..8c586d1ff7d7 100644 --- a/drivers/net/ethernet/ti/cpsw_new.c +++ b/drivers/net/ethernet/ti/cpsw_new.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -1499,10 +1500,12 @@ static void cpsw_port_offload_fwd_mark_update(struct cpsw_common *cpsw) } static int cpsw_netdevice_port_link(struct net_device *ndev, - struct net_device *br_ndev) + struct net_device *br_ndev, + struct netlink_ext_ack *extack) { struct cpsw_priv *priv = netdev_priv(ndev); struct cpsw_common *cpsw = priv->cpsw; + int err; if (!cpsw->br_members) { cpsw->hw_bridge_dev = br_ndev; @@ -1514,6 +1517,10 @@ static int cpsw_netdevice_port_link(struct net_device *ndev, return -EOPNOTSUPP; } + err = switchdev_bridge_port_offload(ndev, ndev, extack); + if (err) + return err; + cpsw->br_members |= BIT(priv->emac_port); cpsw_port_offload_fwd_mark_update(cpsw); @@ -1521,6 +1528,12 @@ static int cpsw_netdevice_port_link(struct net_device *ndev, return NOTIFY_DONE; } +static int cpsw_netdevice_port_pre_unlink(struct net_device *ndev, + struct netlink_ext_ack *extack) +{ + return switchdev_bridge_port_unoffload(ndev, ndev, extack); +} + static void cpsw_netdevice_port_unlink(struct net_device *ndev) { struct cpsw_priv *priv = netdev_priv(ndev); @@ -1538,6 +1551,7 @@ static void cpsw_netdevice_port_unlink(struct net_device *ndev) static int cpsw_netdevice_event(struct notifier_block *unused, unsigned long event, void *ptr) { + struct netlink_ext_ack *extack = netdev_notifier_info_to_extack(ptr); struct net_device *ndev = netdev_notifier_info_to_dev(ptr); struct netdev_notifier_changeupper_info *info; int ret = NOTIFY_DONE; @@ -1546,13 +1560,21 @@ static int cpsw_netdevice_event(struct notifier_block *unused, return NOTIFY_DONE; switch (event) { + case NETDEV_PRECHANGEUPPER: + info = ptr; + + if (netif_is_bridge_master(info->upper_dev) && !info->linking) + ret = cpsw_netdevice_port_pre_unlink(ndev, extack); + + break; case NETDEV_CHANGEUPPER: info = ptr; if (netif_is_bridge_master(info->upper_dev)) { if (info->linking) ret = cpsw_netdevice_port_link(ndev, - info->upper_dev); + info->upper_dev, + extack); else cpsw_netdevice_port_unlink(ndev); } diff --git a/include/linux/if_bridge.h b/include/linux/if_bridge.h index b651c5e32a28..d0bec83488b9 100644 --- a/include/linux/if_bridge.h +++ b/include/linux/if_bridge.h @@ -206,4 +206,30 @@ static inline int br_fdb_replay(const struct net_device *br_dev, } #endif +#if IS_ENABLED(CONFIG_BRIDGE) && IS_ENABLED(CONFIG_NET_SWITCHDEV) + +int switchdev_bridge_port_offload(struct net_device *brport_dev, + struct net_device *dev, + struct netlink_ext_ack *extack); +int switchdev_bridge_port_unoffload(struct net_device *brport_dev, + struct net_device *dev, + struct netlink_ext_ack *extack); + +#else + +static inline int switchdev_bridge_port_offload(struct net_device *brport_dev, + struct net_device *dev, + struct netlink_ext_ack *extack) +{ + return -EINVAL; +} + +static inline int switchdev_bridge_port_unoffload(struct net_device *brport_dev, + struct net_device *dev, + struct netlink_ext_ack *extack) +{ + return -EINVAL; +} +#endif + #endif diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c index adaf78e45c23..930a09f27e0d 100644 --- a/net/bridge/br_if.c +++ b/net/bridge/br_if.c @@ -349,7 +349,6 @@ static void del_nbp(struct net_bridge_port *p) nbp_backup_clear(p); nbp_update_port_count(br); - nbp_switchdev_del(p); netdev_upper_dev_unlink(dev, br->dev); @@ -644,10 +643,6 @@ int br_add_if(struct net_bridge *br, struct net_device *dev, if (err) goto err5; - err = nbp_switchdev_add(p); - if (err) - goto err6; - dev_disable_lro(dev); list_add_rcu(&p->list, &br->port_list); @@ -672,13 +667,13 @@ int br_add_if(struct net_bridge *br, struct net_device *dev, */ err = dev_pre_changeaddr_notify(br->dev, dev->dev_addr, extack); if (err) - goto err7; + goto err6; } err = nbp_vlan_init(p, extack); if (err) { netdev_err(dev, "failed to initialize vlan filtering on this port\n"); - goto err7; + goto err6; } spin_lock_bh(&br->lock); @@ -701,12 +696,10 @@ int br_add_if(struct net_bridge *br, struct net_device *dev, return 0; -err7: +err6: list_del_rcu(&p->list); br_fdb_delete_by_port(br, p, 0, 1); nbp_update_port_count(br); - nbp_switchdev_del(p); -err6: netdev_upper_dev_unlink(dev, br->dev); err5: dev->priv_flags &= ~IFF_BRIDGE_PORT; diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index a23c565b8970..46236302eed5 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -335,6 +335,8 @@ struct net_bridge_port { * hardware domain. */ int hwdom; + int offload_count; + struct netdev_phys_item_id ppid; #endif u16 group_fwd_mask; u16 backup_redirected_cnt; @@ -1673,8 +1675,6 @@ void br_switchdev_fdb_notify(struct net_bridge *br, int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags, struct netlink_ext_ack *extack); int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid); -int nbp_switchdev_add(struct net_bridge_port *p); -void nbp_switchdev_del(struct net_bridge_port *p); void br_switchdev_init(struct net_bridge *br); static inline void br_switchdev_frame_unmark(struct sk_buff *skb) @@ -1723,15 +1723,6 @@ static inline void br_switchdev_frame_unmark(struct sk_buff *skb) { } -static inline int nbp_switchdev_add(struct net_bridge_port *p) -{ - return 0; -} - -static inline void nbp_switchdev_del(struct net_bridge_port *p) -{ -} - static inline void br_switchdev_init(struct net_bridge *br) { } diff --git a/net/bridge/br_switchdev.c b/net/bridge/br_switchdev.c index f3120f13c293..e335cbcc8ce5 100644 --- a/net/bridge/br_switchdev.c +++ b/net/bridge/br_switchdev.c @@ -162,27 +162,101 @@ static void nbp_switchdev_hwdom_put(struct net_bridge_port *leaving) clear_bit(leaving->hwdom, &br->busy_hwdoms); } -int nbp_switchdev_add(struct net_bridge_port *p) +static int nbp_switchdev_add(struct net_bridge_port *p, + struct netdev_phys_item_id ppid, + struct netlink_ext_ack *extack) { - struct netdev_phys_item_id ppid = { }; - int err; + if (p->offload_count) { + /* Prevent unsupported configurations such as a bridge port + * which is a bonding interface, and the member ports are from + * different hardware switches. + */ + if (!netdev_phys_item_id_same(&p->ppid, &ppid)) { + NL_SET_ERR_MSG_MOD(extack, + "Same bridge port cannot be offloaded by two physical switches"); + return -EBUSY; + } - ASSERT_RTNL(); + /* Tolerate drivers that call switchdev_bridge_port_offload() + * more than once for the same bridge port, such as when the + * bridge port is an offloaded bonding/team interface. + */ + p->offload_count++; - err = dev_get_port_parent_id(p->dev, &ppid, true); - if (err) { - if (err == -EOPNOTSUPP) - return 0; - return err; + return 0; } + p->ppid = ppid; + p->offload_count = 1; + return nbp_switchdev_hwdom_set(p); } -void nbp_switchdev_del(struct net_bridge_port *p) +static void nbp_switchdev_del(struct net_bridge_port *p, + struct netdev_phys_item_id ppid) { ASSERT_RTNL(); + if (WARN_ON(!netdev_phys_item_id_same(&p->ppid, &ppid))) + return; + + if (WARN_ON(!p->offload_count)) + return; + + p->offload_count--; + + if (p->offload_count) + return; + if (p->hwdom) nbp_switchdev_hwdom_put(p); } + +/* Let the bridge know that this port is offloaded, so that it can assign a + * switchdev hardware domain to it. + */ +int switchdev_bridge_port_offload(struct net_device *brport_dev, + struct net_device *dev, + struct netlink_ext_ack *extack) +{ + struct netdev_phys_item_id ppid; + struct net_bridge_port *p; + int err; + + ASSERT_RTNL(); + + p = br_port_get_rtnl(brport_dev); + if (!p) + return -ENODEV; + + err = dev_get_port_parent_id(dev, &ppid, false); + if (err) + return err; + + return nbp_switchdev_add(p, ppid, extack); +} +EXPORT_SYMBOL_GPL(switchdev_bridge_port_offload); + +int switchdev_bridge_port_unoffload(struct net_device *brport_dev, + struct net_device *dev, + struct netlink_ext_ack *extack) +{ + struct netdev_phys_item_id ppid; + struct net_bridge_port *p; + int err; + + ASSERT_RTNL(); + + p = br_port_get_rtnl(dev); + if (!p) + return -ENODEV; + + err = dev_get_port_parent_id(dev, &ppid, false); + if (err) + return err; + + nbp_switchdev_del(p, ppid); + + return 0; +} +EXPORT_SYMBOL_GPL(switchdev_bridge_port_unoffload); diff --git a/net/dsa/port.c b/net/dsa/port.c index 28b45b7e66df..b824b6f8aa84 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -292,6 +292,8 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br, .port = dp->index, .br = br, }; + struct net_device *dev = dp->slave; + struct net_device *brport_dev; int err; /* Here the interface is already bridged. Reflect the current @@ -299,16 +301,24 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br, */ dp->bridge_dev = br; + brport_dev = dsa_port_to_bridge_port(dp); + err = dsa_broadcast(DSA_NOTIFIER_BRIDGE_JOIN, &info); if (err) goto out_rollback; - err = dsa_port_switchdev_sync(dp, extack); + err = switchdev_bridge_port_offload(brport_dev, dev, extack); if (err) goto out_rollback_unbridge; + err = dsa_port_switchdev_sync(dp, extack); + if (err) + goto out_rollback_unoffload; + return 0; +out_rollback_unoffload: + switchdev_bridge_port_unoffload(brport_dev, dev, extack); out_rollback_unbridge: dsa_broadcast(DSA_NOTIFIER_BRIDGE_LEAVE, &info); out_rollback: @@ -319,6 +329,14 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br, int dsa_port_pre_bridge_leave(struct dsa_port *dp, struct net_device *br, struct netlink_ext_ack *extack) { + struct net_device *brport_dev = dsa_port_to_bridge_port(dp); + struct net_device *dev = dp->slave; + int err; + + err = switchdev_bridge_port_unoffload(brport_dev, dev, extack); + if (err) + return err; + return dsa_port_switchdev_unsync_objs(dp, br, extack); } From patchwork Mon Jul 12 15:21:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 473338 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F852C07E99 for ; Mon, 12 Jul 2021 15:22:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16B7D61008 for ; Mon, 12 Jul 2021 15:22:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235567AbhGLPZ1 (ORCPT ); Mon, 12 Jul 2021 11:25:27 -0400 Received: from mail-eopbgr80084.outbound.protection.outlook.com ([40.107.8.84]:42723 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235496AbhGLPZT (ORCPT ); Mon, 12 Jul 2021 11:25:19 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HdgYEc6N5Ib2CYoV8ZN6a7y2Bv1oFeTat+Vtc8diOxI4bfsaUvK9RGcJuIYFGw8Y91nUEofONmbUWFY84Ui8KrXVdf9rkD5QJo1JfxZQPwhRlLhx3teTMUAiQQHk3HXnEenP4ZbKPXo1GPSNDgIod3xJEV3pwvFZ3uQW80c3UkPL1G4+rZQcggXXz3mlQgVyO0E7E3ZIsKipP4E6dEGiYjuFHqvw0f1nmKoyBJt+umK4syKdSuxo4cV2NdaeP4pVk67vMZNlzXh9zJ5kOpukmcCsz1ypMSDmsZw6mZnA3kSkjjNjr3So9xesa+Ev575IL7J1pZ4UH8tCvp/4ZWEdIA== 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-SenderADCheck; bh=Ab4neqNso9HPVLudAtgiKoIKBgR3rYQRHaMn/xx3sss=; b=ScqzCjpyggv0p36KQG/xu4tiouU9IyceBt+Npl7O9R/TIPaDVN2Ks9WFpy1UD55RxCW+DbUA7pWCZhuQGZvUHKsDpj4bU54ozajNNou4SJdNQOSOofTdmpf48oyjj9nmDduB6JHCNTbWSMp7QsJe+OkN98aGdkUdXmcXJfumnVR+gybY/fBE23862xEXj9HOV91gXquehikd8OvzLA/wbX5YlQPKU3k2/K1vkKk+vCnyVluhVJEbvGjvlYznA6Y2JRpbABFBylBASiys3mpLtgqYWvEqgf8LlrTpcF/lm+OSmt2f/6cZ5a6VeconpGeQLKy8B0a/40bPrxv8JUAxog== 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=Ab4neqNso9HPVLudAtgiKoIKBgR3rYQRHaMn/xx3sss=; b=Fu+/ydRgpynQP1/3cQxL82H04Ts+mhgKAoXrhMmWU7+onSJTqpBpCiu4QLBjFmEp+Rk4/9XO5FCtZu4m5bayl7Jy/bIAuQzCo7/OgXfxMILusMWwCClG9mY1yEqe0Ug3ypgyqUTcW9QLv6qn0wxBCt/7utW9cynuqzoo3jHOOVs= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6271.eurprd04.prod.outlook.com (2603:10a6:803:f7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20; Mon, 12 Jul 2021 15:22:20 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab%7]) with mapi id 15.20.4308.026; Mon, 12 Jul 2021 15:22:20 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Jiri Pirko , Ido Schimmel , Tobias Waldekranz , Roopa Prabhu , Nikolay Aleksandrov , Stephen Hemminger , bridge@lists.linux-foundation.org, Grygorii Strashko Subject: [RFC PATCH v3 net-next 10/24] net: prestera: guard against multiple switchdev obj replays on same bridge port Date: Mon, 12 Jul 2021 18:21:28 +0300 Message-Id: <20210712152142.800651-11-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712152142.800651-1-vladimir.oltean@nxp.com> References: <20210712152142.800651-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20 via Frontend Transport; Mon, 12 Jul 2021 15:22:19 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 859df2bd-6f86-450f-52a3-08d94548d799 X-MS-TrafficTypeDiagnostic: VI1PR04MB6271: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4941; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oJ0pLvn373TGr0H8QkyKshYIQtTzPtZuQk/dyeEB7vH0Sb4jXc/e59jYz0bDG39q0oKAdnD8bz3YnlkPA84pGSTUHY8bSLwug9XhVSkBpFBZ2pvK77ahR4SPaCHruq898jn9AbLst2pniNaZjC0VgEa4p2bns/Cf8+uiWE4zanHs2YKdL4W7gWjruq4A0jGGl3hjCLI167KTb8I2ByFKgNhn4q0DXNfWlKXA52oR/YTX/341GtoFdvE9EpQvuaPAaVOjG6hkHA9aBj+707nMOiQAWpAZNA/HZ7VDuUqSz9O7IFMicQ1dXpaxYMm6P/EBIrUBe8lvD9Q+xvOECgqPMerGKcK3hWGoRxWP8KClV8ngc/AX1OrFdjFVE7aNa70bG6iS/9RhjLK8EiZwR3I0+YnQF2RpveLGHrQ1F0tgdi13zQLDBW9PDqfq1BJ/4NOO9qMY9polzfi/zg8GGXucrE1NRvl8k81FJijnkU7mC3oP+RaB5nD8RS3TfUHhUSoReoadQY9x4dusZ8fePh06CC7vIiYhq6FnmXRfOOht7LVWgJquJJrZmTgSnQp4vWWdnsU1ugaNGpnO6exDA4urOGRhCwN2HgTJ5NstYeWJrdVY84UK7ya1EsRHRILWMXl8crq70lBK+5vbHhPR02elZp1W8a9uCqt8MtjL1D1LKIllsyfZVyD9PmL2EjIhhdyNkCrGxiPfZsHyHETccfU1gg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(136003)(39850400004)(396003)(346002)(366004)(26005)(2906002)(66476007)(6666004)(66556008)(38100700002)(8676002)(38350700002)(66946007)(5660300002)(4326008)(54906003)(52116002)(7416002)(1076003)(110136005)(6506007)(316002)(86362001)(44832011)(478600001)(2616005)(956004)(6486002)(8936002)(36756003)(186003)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 5seQHW5VdXhab7PjlgyXRFSzd4b/Ir3NhyxY8c0Qeo3XcS8KP/MB9Qp4mcDEUTFlgdtdzNtbXkeVxrv5mqKjDZGH+FGyv85TZJCe4IvlgQCxFRx3xAj8AQ8XaJiIQfmez1s28YVYvMvp74Dfi0ofC46wktt3oJOzX6NFKq/oUF6GftLEpX2c9j/aA99m02XdLiQ2LmE6ELZbQ3wthx/VYPDFsGA+6PVYge1VbKaGraaehaLyRVs5C9vMGaLyMW0NCfc3QmA/rBSaCYZBkXiIoW+g0kV0Hc4dJM0zK9Eh/CJ8mm9Id3Xdw3dio1sPAn4CyLbTThUWPl+IrK9RfrI+GeKSbnBVrgdV45wOa2ZQo2Z8RGmQuh9dLSfG/YcwW/G9XKqTsQBfLLsKqdZbJHYSIaVIqwlzJEQiSEX5Kym0M8gMbew8QcUEArt8isOrp+VRMgBcwJXF3ZPA0x9pWr9CSnv6JJAiDYxkESslQxzMcnJxOoc9Irh3GXl5yoDn7GFJ6VgkaogHKJeHWIXRnc7V0Ud3qboo8eiemnly96XIaBI8QfkBM5lHKilDJYFfjr+l11dpB4BClNQLR6odhD8VMejgrf1MtP+yzGuOdoUyHuSHBesUhNfoMPBh4dFoU9qYHIl2lWeHYyHeHgTftgkAknt7ZJrQMUhjNZQ2h9H7L9UmQdKQzq3XXN2O7soYevOHlgX6yB3rtOl2rnHH0ypWHTiFeZljU5uK7P/+RaVvqEJUxzLLZ62b7gh9f6w3DBgL8G5LdE0rve5S/pvJpdO8dfrLneG0f+x2ZKDOKJ9L5qptMEi7GAmPEM5B3OIvx00p7HqWq7rQ0Qo7r1C8iGTJYDENCsk5mIuFDt0+e6FVJ3WuByc/vvKM30zwNIZHcTGlvsd9B9RtsYqyWv6xKKfmxzO8WPKw4JsxhitHTZ9tpaOgv9rIZE6jCXwl/Bp2GhxcyKRxQe0h8U9TrxMiLQBrt0EHv44nhdgcTR0lb4VwJTxqeoPWT15qZd1QBCGU6Jag1/crrE9aVUCDk5Y1QVyQ3SC3GZXPgRFeFY/+M5H1OM2nsxVcmZT8Hwpnf3A3BOsNEe63hmbhp/gYKZCS1u1op++IvMNty9cwHOqGIH7ymMXDZ2bpC/ZPrSJ/xAL+cmLJVpUgdzEMonUQSjwtXcPR4p43dkCTAMo3yKRsHY6RWVrOMnm/THPfPYW8RGGQh0yPF7xfkcU/0G29uEO3e3zjtBolx+sDuGja0yvLy6pXv7OisN3eI2sYdE0jyVyOOjdmjtP2YVJrhlNaeNzewwMIo3Fev7wtnfvVPP8blJd/tHrUi68xXOTyPSrC0hra/t5o X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 859df2bd-6f86-450f-52a3-08d94548d799 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2021 15:22:20.8476 (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: n5F6iVe6/D/ZWLiLzMg2+p/PTcCF7kM82A6N+jgJEdPvlZ4aSMzDrURtF9dsrVNtj3l6qwyo/E71vI0vBHEPsw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6271 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Prepare the prestera driver, which supports LAG offload, to deal with bridge switchdev objects being replayed on the LAG bridge port multiple times, once for each time a physical port beneath the LAG calls switchdev_bridge_port_offload(). Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/marvell/prestera/prestera_switchdev.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/net/ethernet/marvell/prestera/prestera_switchdev.c b/drivers/net/ethernet/marvell/prestera/prestera_switchdev.c index ae117104a23a..4be82c043991 100644 --- a/drivers/net/ethernet/marvell/prestera/prestera_switchdev.c +++ b/drivers/net/ethernet/marvell/prestera/prestera_switchdev.c @@ -1074,6 +1074,9 @@ static int prestera_port_obj_add(struct net_device *dev, const void *ctx, struct prestera_port *port = netdev_priv(dev); const struct switchdev_obj_port_vlan *vlan; + if (ctx && ctx != port) + return 0; + switch (obj->id) { case SWITCHDEV_OBJ_ID_PORT_VLAN: vlan = SWITCHDEV_OBJ_PORT_VLAN(obj); @@ -1110,6 +1113,9 @@ static int prestera_port_obj_del(struct net_device *dev, const void *ctx, { struct prestera_port *port = netdev_priv(dev); + if (ctx && ctx != port) + return 0; + switch (obj->id) { case SWITCHDEV_OBJ_ID_PORT_VLAN: return prestera_port_vlans_del(port, SWITCHDEV_OBJ_PORT_VLAN(obj)); From patchwork Mon Jul 12 15:21:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 473337 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE50FC07E99 for ; Mon, 12 Jul 2021 15:22:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8ED0961008 for ; Mon, 12 Jul 2021 15:22:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235553AbhGLPZb (ORCPT ); Mon, 12 Jul 2021 11:25:31 -0400 Received: from mail-am6eur05on2085.outbound.protection.outlook.com ([40.107.22.85]:46304 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235511AbhGLPZT (ORCPT ); Mon, 12 Jul 2021 11:25:19 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ajoj2t7PEyIu10xH4omQgex9bYQ5o9amUF1L265spWfs9pNz3/BIgtPp2l18TSSwqyC2cwQpMHHZllHvC3+BbGZKo/+LZZoeImUTq/1LYRjtisUu7PTwlbF09jzfNOkXYNtDWWpGSUXiysRR5R0VRBuZvlnx8Q18kxXahQ2IIog+r1mzkxPtN4zo8MuZF8MTFpFK5llCjgO0PFQUzBxWiIJWLD8i8p6ME6DhLJduGxudTIvtlR8IdRdXzig0R9bJB/bKzCKzkCB+nRQtZQtriFWPSguEZsfeYRWJeIEIz4VMG9A8qkb3/VHnFgfAE1umuwZRxpjg4NCjpSL9yByFJw== 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-SenderADCheck; bh=lKBM7Fl6q1XMHGHXHcaKF/ZFWalOLNVhEubPkfDeL4w=; b=Evr4Ur8tiNyKHhYXQHK2cDqybQySd+LZ6P1ry7ac9h0P8IUnteyhqhAqde+ONmFVy8kUegOI/41S1wNkpqqiAvUVSV40tKzvz7qhEPWKo5hTrQmotKZbMAvfp8yUIWt7S61JEdv12F26wowtaNrQ/tGwPNzcakR4WW9mtl5vDgV+004UkIK+utuX6ySNW8krWrWPRI962u6dNxzKcCaBTJLFF0PaPkvDPgqxzEzmL73ceJ5J6EgU9YjPCOOWX6p/uPOtD882Uj5IAIxCnGk9SEJ+Wh6/yZFo0vGUxXEowNKdmjMU8uCwili6vKkNpqHgXM77/LZ08UQgUHzwQoe77Q== 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=lKBM7Fl6q1XMHGHXHcaKF/ZFWalOLNVhEubPkfDeL4w=; b=f8OW6qD//2ld8FH9FLRr5yy1/9SLRXFAxM3wNxhJR6WCMYXmw3SarqI931pJYs0jdSAi0p/tsuflxbTPsPfqOir4Af9N4Zh1IRak/pFW6FkMrcZqaMhrVbznTRugywbxcRcJZT4Aorwij0CbVNNE8pvRJHAX2ropJuV9XRWEjp0= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6271.eurprd04.prod.outlook.com (2603:10a6:803:f7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20; Mon, 12 Jul 2021 15:22:25 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab%7]) with mapi id 15.20.4308.026; Mon, 12 Jul 2021 15:22:25 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Jiri Pirko , Ido Schimmel , Tobias Waldekranz , Roopa Prabhu , Nikolay Aleksandrov , Stephen Hemminger , bridge@lists.linux-foundation.org, Grygorii Strashko Subject: [RFC PATCH v3 net-next 13/24] net: bridge: use the public notifier chain for br_fdb_replay Date: Mon, 12 Jul 2021 18:21:31 +0300 Message-Id: <20210712152142.800651-14-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712152142.800651-1-vladimir.oltean@nxp.com> References: <20210712152142.800651-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20 via Frontend Transport; Mon, 12 Jul 2021 15:22:23 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 27e74d2b-7177-4e73-72f4-08d94548da21 X-MS-TrafficTypeDiagnostic: VI1PR04MB6271: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RQxES6N/cDzMK+k5vg56lsnl8JsxuNQBXosEuWd7TvWrQJbcLGLbU/Gt6w35SPyBQci0K8RPSS4+7QPrfrst6LYAD/ZUkKqpkeR1t53GrVjKe0KbQ+IMacMBBDj0lBGI21ueCqr4MUdVEnRD28NZCKJYCPjv9+Dvc0bUAOu3ABpxMhIJ3uVxxL3yt88u9jYb/9RfqxQYJFmC66RvhDj1i2J9r14P8dhJbdH2qQP8Z8axbnCk1rI9gtsHYamsa+LuCqJzEMb0wh6eDcwI7g2bXQA16ycnqPu9s6VGPb6o9K4/xp/PEJ5HGFnuidi1HTqedh2kN+F5oVXcZWefZC4BJmmcz9SHZmq2f6K/tDqz+34XIttsxvkqaU7FTnroLV6iBTZUcDOuNAZohnw0iePrIyPXxMMZmh0beAodJsRPhtb7GSJ7+m+dkVy2iynE7/Wh28WFFwaKfw+XuPfY/WMTh/pT5kDQN+UQBCuswj2C3jG75SzJzlnzcllJyqQ9vRYDMGb+S5aV9xWz5zYfS5ihMHqPTbLWM9BGm77ql4F03c4743fWCz7VX9l0rcqkYYm0vjNAtGoNfoThQPnZr3rQhZuf2nPQ2SMdZmoz+RPkEA89kk1lnXrP+GSsmmYVbEEbxciVjswod/G4htZdlcmsGYEbXpbDFPRUOq9Lr77WN38E6ZAwrFDmx/N+jIsR60hpGVjzjOijGjtYB+PyJeJ3rw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(136003)(39850400004)(396003)(346002)(366004)(26005)(2906002)(66476007)(6666004)(83380400001)(66556008)(38100700002)(8676002)(38350700002)(66946007)(5660300002)(4326008)(54906003)(52116002)(7416002)(1076003)(110136005)(6506007)(316002)(86362001)(44832011)(478600001)(2616005)(956004)(6486002)(8936002)(36756003)(186003)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2Nv0/ub9jYrfUnKPjqao3iZFaUaq94IXLOQCmFdZ6hRj+CV6/JY4VMgZOcGkjEMRi0rVQ6Our6DQYIT0oX6ZmH5g89imq8LZH4GNYGBGl6sZZBqwnhTOoOJjBQ6T7Fr729G21UaLrLfzVYbSC2LzQKtTWRoJYdo/+IsCEbjvJryG3OY1VdOVGfrrNRNlXXG6bwI7hvI/arWrTBlanykXO9j9bheNlV95upPXPSNGMOYuJHJk0f6KIt8o0wSxszq0I8yjJdHq45pCH3RtCvLZNzgopG4iVzox6F7foGYuoL5TFv+Rvp9srlVp2yfptNUbPEuXJZnCJxagZIpPLKXUEsvSwsdwIY1J/oN+FPWyfdT9ylEMppSaCiG/fql9RK41wlT3V9itXDc9ZX01384e8Eo5v10r8055LC4SNRJLe67qSC7y5Frj36MoZxe69O6+lOoP62fygG/W7PM+z37l+bk/XyLD3SSOlSQcI15cgUnIUUqmS6UhGd5Zyfa6bH5KS9wphVMvA1ihCHZ3LtDsT5+AzCuBj55Qn4Wo9ctpR7PvWMdT/0PEj9/fZcSBBL/7wkxunFvK9cidAONcgfEMiuiMwzArPISncTisv35/p7PVsCEGvsWTu6HGNVJ11HxXvk4DHRzFGBAfrZt3Sbk5J3dWnRK3hfWc1aWEFoKYWMeAMApBoB/iilq33wPS1v/5lY4OFvglrjrPFJ0V6i/OPiuXWpgGUJzaS8vBpLflRJxM206BR++KdA8eKY5V0/iHy66ogD2MROZb5Xw5BXXer3Q3rllIV0E+Im3MsrJMlPb9LxdnkWuonEL83eW/PRWfaKQOBI6klF4k94yipUf4SuQZEdQChObklAoctapH4MzD56p5lkgPGkI21k/ENPx/IXMmxM6eX9APNHAOGsi5v2TUAKE7dUpZ7owggSpbzr8D6rPtEZ7PgCdq8ycO8vAWnY8JmGUTBlfLRI8i0P/hvxUgTMeGO0ryqbxmwU8UZ1YA/hSvOalCWHnCvtTcUs7suoGaVsrar8BBxKoE5zPMQ+mT/sGF96Jo5OB7oqKqSERHcweM+3B2HFj7/1yGKBixv/BXhIWDdD2SMsn53RkQXMdYqNP3viveV0bzyXFRe4BxmNPgLYhzJewMqJA0YX/oBp1D61BLdyFp9GNj+Ru8XIcBuKgMAImTtgC57vUF2oc5rtpqHHIui5Z+EFp2wMJg8hbUJ/LIJp4f6qPiTagLoD0eGZAIG3D/0jziN8Rm7Uto5WBCazakMlvjYJcQarSx2UStqrmn3cJR0uxWtYUE3HUy4FcY3mp2z5k+JCEaTuAs0iZgpTMe1/3wvbhq9nIY X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 27e74d2b-7177-4e73-72f4-08d94548da21 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2021 15:22:25.0811 (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: asdR3QcINuvDC/McIst9zVBbNzdmlWJuj9xGuYkC6GtJTq9N6FRnq2VphBnpaZhdtPTtcf7EppENAfutXnZOAA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6271 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Currently, switchdev users of br_fdb_replay pass a pointer to their atomic notifier block for the bridge to replay the FDB entries on the port and local to the bridge, and the bridge whispers those FDB entries to that driver only, and not publicly on the switchdev atomic notifier call chain. Going forward we would like to introduce push-mode FDB replays for all switchdev drivers, and there are at least two reasons why the current setup is not ideal. First and most obvious, every driver would have to be changed to pass its atomic notifier block to the switchdev_bridge_port_offload() and switchdev_bridge_port_unoffload() calls, which gets a bit cumbersome. The second is that it wasn't a good idea in the first place for the other switchdev drivers to not hear anything about the FDB entries on foreign interfaces. For example, DSA treats these FDB entries in a special way since commit 3068d466a67e ("net: dsa: sync static FDB entries on foreign interfaces to hardware"). With the static FDB entry addition being public on everybody's notifier block but the deletion being whispered only to the driver whose port leaves the bridge, DSA would have a lingering static FDB entry pointing towards the host. Making br_fdb_replay() use the atomic switchdev call chain solves both problems. Signed-off-by: Vladimir Oltean --- include/linux/if_bridge.h | 4 ++-- net/bridge/br_fdb.c | 43 +++++++-------------------------------- net/dsa/dsa_priv.h | 1 - net/dsa/port.c | 10 ++++----- net/dsa/slave.c | 2 +- 5 files changed, 14 insertions(+), 46 deletions(-) diff --git a/include/linux/if_bridge.h b/include/linux/if_bridge.h index 13acc1ff476c..8d4a157d249d 100644 --- a/include/linux/if_bridge.h +++ b/include/linux/if_bridge.h @@ -168,7 +168,7 @@ bool br_port_flag_is_set(const struct net_device *dev, unsigned long flag); u8 br_port_get_stp_state(const struct net_device *dev); clock_t br_get_ageing_time(const struct net_device *br_dev); int br_fdb_replay(const struct net_device *br_dev, const struct net_device *dev, - bool adding, struct notifier_block *nb); + bool adding); #else static inline struct net_device * br_fdb_find_port(const struct net_device *br_dev, @@ -200,7 +200,7 @@ static inline clock_t br_get_ageing_time(const struct net_device *br_dev) static inline int br_fdb_replay(const struct net_device *br_dev, const struct net_device *dev, - bool adding, struct notifier_block *nb) + bool adding) { return -EOPNOTSUPP; } diff --git a/net/bridge/br_fdb.c b/net/bridge/br_fdb.c index c93a2b3a0ad8..4434aee4cfbc 100644 --- a/net/bridge/br_fdb.c +++ b/net/bridge/br_fdb.c @@ -732,31 +732,12 @@ static inline size_t fdb_nlmsg_size(void) + nla_total_size(sizeof(u8)); /* NFEA_ACTIVITY_NOTIFY */ } -static int br_fdb_replay_one(struct notifier_block *nb, - const struct net_bridge_fdb_entry *fdb, - struct net_device *dev, unsigned long action) -{ - struct switchdev_notifier_fdb_info item; - int err; - - item.addr = fdb->key.addr.addr; - item.vid = fdb->key.vlan_id; - item.added_by_user = test_bit(BR_FDB_ADDED_BY_USER, &fdb->flags); - item.offloaded = test_bit(BR_FDB_OFFLOADED, &fdb->flags); - item.is_local = test_bit(BR_FDB_LOCAL, &fdb->flags); - item.info.dev = dev; - - err = nb->notifier_call(nb, action, &item); - return notifier_to_errno(err); -} - int br_fdb_replay(const struct net_device *br_dev, const struct net_device *dev, - bool adding, struct notifier_block *nb) + bool adding) { struct net_bridge_fdb_entry *fdb; struct net_bridge *br; - unsigned long action; - int err = 0; + int type; if (!netif_is_bridge_master(br_dev)) return -EINVAL; @@ -767,28 +748,18 @@ int br_fdb_replay(const struct net_device *br_dev, const struct net_device *dev, br = netdev_priv(br_dev); if (adding) - action = SWITCHDEV_FDB_ADD_TO_DEVICE; + type = RTM_NEWNEIGH; else - action = SWITCHDEV_FDB_DEL_TO_DEVICE; + type = RTM_DELNEIGH; rcu_read_lock(); - hlist_for_each_entry_rcu(fdb, &br->fdb_list, fdb_node) { - const struct net_bridge_port *dst = READ_ONCE(fdb->dst); - struct net_device *dst_dev; - - dst_dev = dst ? dst->dev : br->dev; - if (dst_dev != br_dev && dst_dev != dev) - continue; - - err = br_fdb_replay_one(nb, fdb, dst_dev, action); - if (err) - break; - } + hlist_for_each_entry_rcu(fdb, &br->fdb_list, fdb_node) + br_switchdev_fdb_notify(br, fdb, type); rcu_read_unlock(); - return err; + return 0; } EXPORT_SYMBOL_GPL(br_fdb_replay); diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index f201c33980bf..20003512d8f8 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -285,7 +285,6 @@ static inline bool dsa_tree_offloads_bridge_port(struct dsa_switch_tree *dst, /* slave.c */ extern const struct dsa_device_ops notag_netdev_ops; -extern struct notifier_block dsa_slave_switchdev_notifier; extern struct notifier_block dsa_slave_switchdev_blocking_notifier; void dsa_slave_mii_bus_init(struct dsa_switch *ds); diff --git a/net/dsa/port.c b/net/dsa/port.c index 34b7f64348c2..ccf11bc518fe 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -200,13 +200,12 @@ static int dsa_port_switchdev_sync(struct dsa_port *dp, return err; /* Forwarding and termination FDB entries on the port */ - err = br_fdb_replay(br, brport_dev, true, - &dsa_slave_switchdev_notifier); + err = br_fdb_replay(br, brport_dev, true); if (err && err != -EOPNOTSUPP) return err; /* Termination FDB entries on the bridge itself */ - err = br_fdb_replay(br, br, true, &dsa_slave_switchdev_notifier); + err = br_fdb_replay(br, br, true); if (err && err != -EOPNOTSUPP) return err; @@ -232,13 +231,12 @@ static int dsa_port_switchdev_unsync_objs(struct dsa_port *dp, return err; /* Forwarding and termination FDB entries on the port */ - err = br_fdb_replay(br, brport_dev, false, - &dsa_slave_switchdev_notifier); + err = br_fdb_replay(br, brport_dev, false); if (err && err != -EOPNOTSUPP) return err; /* Termination FDB entries on the bridge itself */ - err = br_fdb_replay(br, br, false, &dsa_slave_switchdev_notifier); + err = br_fdb_replay(br, br, false); if (err && err != -EOPNOTSUPP) return err; diff --git a/net/dsa/slave.c b/net/dsa/slave.c index ffbba1e71551..461c80bc066a 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -2517,7 +2517,7 @@ static struct notifier_block dsa_slave_nb __read_mostly = { .notifier_call = dsa_slave_netdevice_event, }; -struct notifier_block dsa_slave_switchdev_notifier = { +static struct notifier_block dsa_slave_switchdev_notifier = { .notifier_call = dsa_slave_switchdev_event, }; From patchwork Mon Jul 12 15:21:34 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 473336 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F0EFEC07E99 for ; Mon, 12 Jul 2021 15:22:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DA1AD60720 for ; Mon, 12 Jul 2021 15:22:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235588AbhGLPZe (ORCPT ); Mon, 12 Jul 2021 11:25:34 -0400 Received: from mail-eopbgr80084.outbound.protection.outlook.com ([40.107.8.84]:42723 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235529AbhGLPZV (ORCPT ); Mon, 12 Jul 2021 11:25:21 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Cx3ocUsrva9iq8QIvHNksmVNdTOE7SE0UOyyFOBT8yAS/dn33XPsnegBl4aBtAguhejLOn6wUTEsnjCZg/8FnKkV/wisa1vwbgqFxzI4rgDPnXgAbcI824E1mpS25HzH7lieVC2S1uUhctYYTuRUTPX/zLD2hMANI7k3f1shXR0tl1EyhQpDtWh4yGZj9PPRVUp2CexQzZ4682ZPdHcY8WR/an0vF8lXpZr/ZyZSckwgTdXxuL2vCfA/fzh8WJ+9sgPWUUhJ9t/jWRoq4Bab+731m2TXh9uOWng9vKD/SaVfLqo+sVLkSEJzu4Set7gFXoalCrf51VejWRe4NBBg/w== 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-SenderADCheck; bh=zO5GO8v4tjOgZUiRtjtciq9L3Y+FWYdUxnxBxmGQESM=; b=mB0jMuvSsK3wCuzCIgeJ44aMNn11gNH6chbq0+KpB65jBbIMgqzNkoxzSwr82CBgx771G2BROYLOJMTSGVFNkr5pfrQWt9HQIphKJaSI98oEyN5UhFaoYFWZKUw65ZE0G2Im+Dkc4sApVFq5ZWOhIdOuc3BPiE2W0nTxOiqVOpv3SRtdcy2LvTdjqL7+hc6Pt0/0CtRj3yO9oJkvfvgHLDBrjEtHZw8M4kiZGIGqizoVvlkBTjPGYYWeSfuuiMifvhgKdcHToMrKelfdXMsXGeH1qWk0UWhYsxRNth4Q64XcdIrSeigQ/brb+IWd4OKJvWU9UNiizf5liL2XZZaq9g== 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=zO5GO8v4tjOgZUiRtjtciq9L3Y+FWYdUxnxBxmGQESM=; b=j28MwkjWthzmhT7bf4y2E/LpNCLknuEItz5NpX3WH8EVM6pUioIJ8EqrBalxFmKYcgF6PtIEqyIa1/tgm6mYvSUjqr3KtoXdvnMBDdXMBtollZ/3pKua+nDJeNuUItz1L0vvQ4nG0DS47Je3kAW1FkTU9vapUN+P515VIMqtZPY= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6271.eurprd04.prod.outlook.com (2603:10a6:803:f7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20; Mon, 12 Jul 2021 15:22:29 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab%7]) with mapi id 15.20.4308.026; Mon, 12 Jul 2021 15:22:29 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Jiri Pirko , Ido Schimmel , Tobias Waldekranz , Roopa Prabhu , Nikolay Aleksandrov , Stephen Hemminger , bridge@lists.linux-foundation.org, Grygorii Strashko Subject: [RFC PATCH v3 net-next 16/24] net: bridge: propagate ctx to br_switchdev_port_vlan_{add, del} Date: Mon, 12 Jul 2021 18:21:34 +0300 Message-Id: <20210712152142.800651-17-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712152142.800651-1-vladimir.oltean@nxp.com> References: <20210712152142.800651-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20 via Frontend Transport; Mon, 12 Jul 2021 15:22:28 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 697902a4-3228-40c3-0c30-08d94548dcb1 X-MS-TrafficTypeDiagnostic: VI1PR04MB6271: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2201; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o3FreaHOUI2lOoM4wdZWTRXVFjMlGfAVeZRHJDn86X8iOtJTncEmdxbQw2z3IP+u8AVpdgjo27DUCwqLWUcllC5HlJeBO54H0fdbAF1BrXqubHTmew9v7MRv7EegGl8Xp3RlBt0CvDruX6M3ocl8e10Ij5q5EOLoDqtpkqWid3fSyPBWR4uXnl2plFQvHj+hcvoMD1/louur5HHmU7C7ByL955MP+V7cbpXnHNACRRBP9QJOCVZbMWjGfVPF1d4JoI7kONJfSb46uer9Ywcb8zxD3wB8vneWd/2C6Tm+GVMlA5IA41SGcygjQ0CgG767nIyzVvgfUwC8qWqrY5o2MWa7YzAeNLfNRMd4IEG8eCJQDQYac92ZU5sLVEaKb+I0JOmpOJhMGEC+/0+tjvOJcdYhetj2eDUu4bvlRfudgQXwZpuTfUmXftNIO3m4S4ZcCVWRv/D4KU57+f7uD3Fp0BUac471APCDtclgUZGC5GXO2P6EDWCRmk43JIQMyYWSQSqEnWYNrqUa7vC9NWD8KkXLYTqEd+qgkBW1YKXyvG+D6xRqUmAVq/5cJJMVngh8LP89J2ablXKfPRzw7GkLkGksr2F6jfQtMPZHLVU8vedrGp0e3UCXNZ8BSkZLq5GWNKXuzy5RZ8+d01Yr/kxo24Yoq721ZTRZRoKN7DTV8wvk5AARqjjSC6QI8UZLgtY5nx4XzAQlK9AEQzAaiNMOxw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(136003)(39850400004)(396003)(346002)(366004)(26005)(2906002)(66476007)(6666004)(83380400001)(66556008)(38100700002)(8676002)(38350700002)(66946007)(5660300002)(4326008)(54906003)(52116002)(7416002)(1076003)(110136005)(6506007)(316002)(86362001)(44832011)(478600001)(2616005)(956004)(6486002)(8936002)(36756003)(186003)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: E4Q8uqDDjgrPWv/3ZuYhD9Am6UrmgXPw0xgK/NTpM5elmuT7L7aDgLwur3oTHiePw9mdPyUDpdPJxpfN5uTSVI34JUbYldUbDT3CtloH30JWV5SrCRYLHvS6YK5I3hNLqaOxy2Y4Y4bbGT0pScKqaJQvmA0GKuc9a3e2vjrs/q0Ig7lBXBgV04lq8wRJE/qrC2ygY5jDy0pAZe91PCC6NUJQq2Wv3bnqdux/TtvdEu2zRO0facIp8OHSyEcuQDdy1eUVtt3IDuXscWgxsBepIfClljuExRs8ag3dwJvBxCQcL4db5lw+w6zJbBGlktwghWiHMq4cjKYhLCiOuX2h8B32X2jdTNq471ui/8zDuj0/TrJhG9eX4zVrthUbStoyg812zLZhJDEbW3I2y1Nb1AMFNZQazzJgHKnm77g9M9sKDT1bWaoEKe4eOaX0BaQFKeMAa4OvgdzJYUAUjROZlfAKqB+Q7mEky5INiH0hilkibXCafzxkQkZtHK1H9eMMu3o5C4YtL8HpsvuiyQR7j8WQzsayd0L5OpdGcC6oNYnaiKmMvk4DLKNnSGPc5Jtzz4LOOsOdJzfaKjjRkJ3mjGBvvBrvbuspoAZyGOd+wyWiuu1brNgaZXVDl4ZZIogMAvyLO9qjLquJ/CbhblsTWe/HMm3hDJGQ/S9HVkenSuuMzSgw71hhcns00Hr65odRUPtvlmjH6WSaAkpugMx2L3EzxWYJYyrt6XrPIa0j4tJbPKT5U/R9KRBWSS2x2ljsxwHh9na0nuqp94gurGrdauuIzojOG6LHQKlNyyCOj1iLbP/Odw8xoZ3L9CqHfzApRnQTITWeq0jikOVd+MZgVLZqcEazR7d14iyyPIFB24eEfezU6bN6hccLCLLIFZ5Bbi1UHekRnWbjGfdQLGVEfdlowmj2OLy/MvETu1KXeUoBsO4+wfzIMM6bZnjcKHPcQAlHXY/tS3dMkcZ4wPlTHklVM/SoWFWUCrGHVDEVFjIYNV8C0C/zQxoFDJh5wj4rSF3WsroSHB5zVADeYQvXbDP4qQPEffGNlC6seHJs5f88R3yiGvA68Vn80WRcg6md9yxKV6UzV9Ir0d9Wz2tC2wnv7yGQa3fL5bhj8SQ8WM9Byx2SjevvgszK5u+8E4PvuqsnwONhBcJqGwOT2Wyp7Dcg3RXZ6sDfwv/2ZM4UzW7wWwg3B0nRCFHU0YdkUnyyeJLDzbdd5wf2CFctze6gjjzt4XFsUZG15l5EtSS4OvuH7b+c1wPWCl+QfqNgawoEBD1d9ottPqlecHY229MwxmeHR5JUBram0wYawtsaC/piq5WcDbt8GYo+r27k13Yk X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 697902a4-3228-40c3-0c30-08d94548dcb1 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2021 15:22:29.4037 (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: cJ5EDeZvpT76J6wHFweqUcw6Q4wGI/aL3upPO2FSWj3ZkBhEKt3X2s2AfHn2XyoObN6DFPmyPivs0UvAD5N/DA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6271 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Make br_switchdev_port_vlan_add() and br_switchdev_port_vlan_del() callable by br_vlan_replay() too, by exposing a void *ctx argument. Signed-off-by: Vladimir Oltean --- net/bridge/br_private.h | 8 ++++++-- net/bridge/br_switchdev.c | 8 +++++--- net/bridge/br_vlan.c | 19 +++++++++++-------- 3 files changed, 22 insertions(+), 13 deletions(-) diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 46236302eed5..763de4a503d9 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -1673,8 +1673,10 @@ int br_switchdev_set_port_flag(struct net_bridge_port *p, void br_switchdev_fdb_notify(struct net_bridge *br, const struct net_bridge_fdb_entry *fdb, int type); int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags, + const void *ctx, struct netlink_ext_ack *extack); -int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid); +int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid, + const void *ctx); void br_switchdev_init(struct net_bridge *br); static inline void br_switchdev_frame_unmark(struct sk_buff *skb) @@ -1703,12 +1705,14 @@ static inline int br_switchdev_set_port_flag(struct net_bridge_port *p, static inline int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags, + const void *ctx, struct netlink_ext_ack *extack) { return -EOPNOTSUPP; } -static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid) +static inline int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid, + const void *ctx) { return -EOPNOTSUPP; } diff --git a/net/bridge/br_switchdev.c b/net/bridge/br_switchdev.c index c961d86bc323..90aad6a4c32c 100644 --- a/net/bridge/br_switchdev.c +++ b/net/bridge/br_switchdev.c @@ -102,6 +102,7 @@ br_switchdev_fdb_notify(struct net_bridge *br, } int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags, + const void *ctx, struct netlink_ext_ack *extack) { struct switchdev_obj_port_vlan v = { @@ -111,10 +112,11 @@ int br_switchdev_port_vlan_add(struct net_device *dev, u16 vid, u16 flags, .vid = vid, }; - return switchdev_port_obj_add(dev, &v.obj, NULL, extack); + return switchdev_port_obj_add(dev, &v.obj, ctx, extack); } -int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid) +int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid, + const void *ctx) { struct switchdev_obj_port_vlan v = { .obj.orig_dev = dev, @@ -122,7 +124,7 @@ int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid) .vid = vid, }; - return switchdev_port_obj_del(dev, &v.obj, NULL); + return switchdev_port_obj_del(dev, &v.obj, ctx); } static int nbp_switchdev_hwdom_set(struct net_bridge_port *joining) diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index a08e9f193009..14f10203d121 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -92,7 +92,7 @@ static int __vlan_vid_add(struct net_device *dev, struct net_bridge *br, /* Try switchdev op first. In case it is not supported, fallback to * 8021q add. */ - err = br_switchdev_port_vlan_add(dev, v->vid, flags, extack); + err = br_switchdev_port_vlan_add(dev, v->vid, flags, NULL, extack); if (err == -EOPNOTSUPP) return vlan_vid_add(dev, br->vlan_proto, v->vid); v->priv_flags |= BR_VLFLAG_ADDED_BY_SWITCHDEV; @@ -132,7 +132,7 @@ static int __vlan_vid_del(struct net_device *dev, struct net_bridge *br, /* Try switchdev op first. In case it is not supported, fallback to * 8021q del. */ - err = br_switchdev_port_vlan_del(dev, v->vid); + err = br_switchdev_port_vlan_del(dev, v->vid, NULL); if (!(v->priv_flags & BR_VLFLAG_ADDED_BY_SWITCHDEV)) vlan_vid_del(dev, br->vlan_proto, v->vid); return err == -EOPNOTSUPP ? 0 : err; @@ -281,7 +281,8 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags, v->stats = masterv->stats; } } else { - err = br_switchdev_port_vlan_add(dev, v->vid, flags, extack); + err = br_switchdev_port_vlan_add(dev, v->vid, flags, NULL, + extack); if (err && err != -EOPNOTSUPP) goto out; } @@ -330,7 +331,7 @@ static int __vlan_add(struct net_bridge_vlan *v, u16 flags, v->brvlan = NULL; } } else { - br_switchdev_port_vlan_del(dev, v->vid); + br_switchdev_port_vlan_del(dev, v->vid, NULL); } goto out; @@ -357,7 +358,7 @@ static int __vlan_del(struct net_bridge_vlan *v) if (err) goto out; } else { - err = br_switchdev_port_vlan_del(v->br->dev, v->vid); + err = br_switchdev_port_vlan_del(v->br->dev, v->vid, NULL); if (err && err != -EOPNOTSUPP) goto out; err = 0; @@ -650,7 +651,8 @@ static int br_vlan_add_existing(struct net_bridge *br, { int err; - err = br_switchdev_port_vlan_add(br->dev, vlan->vid, flags, extack); + err = br_switchdev_port_vlan_add(br->dev, vlan->vid, flags, NULL, + extack); if (err && err != -EOPNOTSUPP) return err; @@ -681,7 +683,7 @@ static int br_vlan_add_existing(struct net_bridge *br, err_fdb_insert: err_flags: - br_switchdev_port_vlan_del(br->dev, vlan->vid); + br_switchdev_port_vlan_del(br->dev, vlan->vid, NULL); return err; } @@ -1219,7 +1221,8 @@ int nbp_vlan_add(struct net_bridge_port *port, u16 vid, u16 flags, vlan = br_vlan_find(nbp_vlan_group(port), vid); if (vlan) { /* Pass the flags to the hardware bridge */ - ret = br_switchdev_port_vlan_add(port->dev, vid, flags, extack); + ret = br_switchdev_port_vlan_add(port->dev, vid, flags, NULL, + extack); if (ret && ret != -EOPNOTSUPP) return ret; *changed = __vlan_add_flags(vlan, flags); From patchwork Mon Jul 12 15:21:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 473335 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E76F6C07E99 for ; Mon, 12 Jul 2021 15:22:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D1CF861004 for ; Mon, 12 Jul 2021 15:22:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235436AbhGLPZj (ORCPT ); Mon, 12 Jul 2021 11:25:39 -0400 Received: from mail-eopbgr80084.outbound.protection.outlook.com ([40.107.8.84]:42723 "EHLO EUR04-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235519AbhGLPZW (ORCPT ); Mon, 12 Jul 2021 11:25:22 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MR2P+bGQRxFXkZq06pDcSYCR+LDTzzKMZbAKRa212w4htS7X3ZbYgudqKPT3c3uC61zsomnHk0yiu7N/6xiBO/anRM41dr8WoB7dMnJ5To+4y4fpXH/vhxFqcA0+cuTuzlE8CHaBRc/bov8CeAv7ZsNgagNq82J2oDiuH4KpYWz+pxUBiOt9eqDWeqfrzZI4+WUf2lVKaOAiifuEfvf/9emVtQ4athaDO7nweevY9whAuPI8fzPuMQnMGnnpFRqrvIn0l4MMEqeqPVoOl7kzGtNO7J0NpA8TWam2tVRVqp5DeuYYNzaHmd1dA+wzIVe/W3tZWTJnCk/CYen0gZK4wg== 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-SenderADCheck; bh=XLP1enISVA6/MDMdAX4ko1JVDKim4QW0eI18R+Wa7Bs=; b=aKzEdPDnkTS64jWnLuoHb0baUJcDT1xWgXA1d0JaYGse7zscW4PjeSNng0usdAKpAau6Wy2bUvoePvswjAQbJYyUp7bxYjcYl/ehIXeiaVDIoVIxg76HNaamTTSRkAiYJK0I8MNDBLcKfxkNh3X8NdTfXu4C4QcFhvJQ+cFGL0G5sV/4s+4TTBd9pzGduJO5X5r3TFq+Qszb1Nv846DrDE/dN7KGEGEhLSXfN58kFVvI9ahi3F+1yWI3qeYMSqG6fPaN4dKV7kvXI1H6sJaMgdGpZz0hw7c56D+9PkzHnaH1TGCovyaKjHi4Bw8pAQg/qsh9PqVI107AIRgzQqs/NA== 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=XLP1enISVA6/MDMdAX4ko1JVDKim4QW0eI18R+Wa7Bs=; b=jJ4OK0i+cGXBtTuU7T1c4B77vtAH/lnacElMZjhcWt7Y9/R5Npul13RJXYUz0OBO5U4LxYzMtZ0PZ41Bj5qoW38ed+TDqQfFyYde6kOD4obXdg1YiJJB1GKDsE2U6lYb3+VFmLKjJCCpBxEYzO7CGGuervwJ0+F3+ZVhkRslRvo= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6271.eurprd04.prod.outlook.com (2603:10a6:803:f7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20; Mon, 12 Jul 2021 15:22:32 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab%7]) with mapi id 15.20.4308.026; Mon, 12 Jul 2021 15:22:32 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Jiri Pirko , Ido Schimmel , Tobias Waldekranz , Roopa Prabhu , Nikolay Aleksandrov , Stephen Hemminger , bridge@lists.linux-foundation.org, Grygorii Strashko Subject: [RFC PATCH v3 net-next 18/24] net: bridge: replay vlan entries on the public switchdev notifier Date: Mon, 12 Jul 2021 18:21:36 +0300 Message-Id: <20210712152142.800651-19-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712152142.800651-1-vladimir.oltean@nxp.com> References: <20210712152142.800651-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20 via Frontend Transport; Mon, 12 Jul 2021 15:22:31 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 58689837-165d-4f26-89d8-08d94548de61 X-MS-TrafficTypeDiagnostic: VI1PR04MB6271: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: k2VFozJiXdXjDR/0PWMXiNcKs/xAEtkjBWlAacHufuoJlhnFCDu5tmqX29VU+YohlPM9Q0bXINIEzbv3taJUmt4VJAG+R1FGGkXgZoD0h2uD24WIZ3PpwNdpFXjTt2gfyUo6peUZZiHKwD2hKxWTlfLatdWm7JhbylfQ9BtrJSChE0M+J4ZPWwEEEK5eumCWVwJML+ltHsYxZ4RaQON5xadpQnabRYLI1S+a3/vsGhsgPdLFnEd6azIDEOsXUtJwC4KRnxJa9hALjRPjJQKGP01b9sXPdBhvKle8cuaRkdFzeVIjON7Er/Mfk/Ac6FitxkKFrUuc+XEaLn/gI/uuWxmZch0pD+hcgpNnkEqfV5Dw1s0aniZz6xmkwqBxJPdTJRNKFvOZ6rYpBTrIatMjgAB0h+jFfpqh5qIKesJOSsqPlnIxf5eeOXeA1aXRZozU3ssmdo8oSDnLHoEfsJ8fs5UMlMR4dDEWxu83gPaUtgoq3/W+BPNUYxFkcqqcLSMJ0SJaDEJ8maU2bCTD5X3MO+2FJ6Pk/cTSlbcWJZKR8rN8htlVPptWRCXHIG9/qOlYGeiXLulluFUYcp9Q+Q9BxBul2S/aw/22et4Reayj6VDpnUToPVwpfKjrPAZhiHFFmIYqf8Vb3pO80kDkJ/7TM5YkAYw4sa3611gZ/PTAQhz//Lg0wJqFQlseeijwecr0eM0mkpBHiNPvClYUPwwWHQ== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(136003)(39850400004)(396003)(346002)(366004)(26005)(2906002)(66476007)(83380400001)(66556008)(38100700002)(8676002)(38350700002)(66946007)(5660300002)(4326008)(54906003)(52116002)(7416002)(1076003)(110136005)(6506007)(316002)(86362001)(44832011)(478600001)(2616005)(956004)(6486002)(8936002)(36756003)(186003)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: V/GhGtKI/XqBIRElFImNzCIkjfdH3OmFNL4KODW2rA/oQDj1gl7PiTVv3cMlm6hPDtV4MjVdGZ6k0yLQJniRHvjMeO17bt6kU9kEFWrQ0aRBatsRMP5sz7bHwnPCvbFen3HalZmPkWu3E7/ElbLCX5p3/wcznWpH8KfcdidELk2f4rp35Z0I2lyPuFAJQ02u24F0vGh/bLTqWl4rFrJCqNHt2s5Cw/2v/fht2BkE1ITcpwPU3GXJZgUdS1StytYQ3/x3LclJCiBgNR8DpVQdI5REgWvGWiLEmVzuovfVqxiCd7MQ31uQHefbLSYNapEcmdGwKMKzJxHQIrYb7AcsGkieYXPyURByG2wz1cjy0/J2N4bceoC85w4YM6dFNdEb36kyRr3tAA5xXNmE3+hUa5wGegKNzGoOjavp+/w/c163fomFc7zFV5FNrDYtnGwrQrjI6IgZB6Ey7DrHjE+c4AMgrbZqz9/h2MpHevdFS0IR8GB4xuyLpJ5MaX2bpzayPql+e6Rh0Ik7bw52azEoKMi6dBc8bDDbY/epCWKiSsv35FSQ62MSrjI6c8LG9cvhBqke8rx8ZroLJ0KFyS4DvjPM092f3979QAXd+DP+gQ6q1/VW0oNYyvcqPbuThGEgkvF2F0Hotx4OcGh5E1v8McnwmrGui07adzv6xOPurApsphV00vX//fdipBHguh9SoIXND3LSQ+AZD5CMC7Xuy6rz/GLna535mYC4UG0594Ctuk16PnoawuwMcpSYFHyY5PU/f2zIh1zaBP4cb/VN4Vrku6Ih4DZX0uAiwvdfeHvFG6Vu2x0XTR7Zk6ARdXrViDsjywdhpFxZ7RrU9FEBaZWOnX8LQyXxKtD+HK7T5BhW8VWFkxTYhsfA5k3BuHKdyGv8N8dsg6Frnu7DL4vnMvRHjzNJqM67ymw1Di1/8FROWATspjtdoMYPf+y0mz67sXHTEaWRw5KBvgG7i5+E5q3kRnltRWEHuxKA2E3NlHzXd/eT3ayn0+kkEJr+6RY2ptnT0go+fK5owpaZ8eASRGXnWsImjWASvK8OtAtzP8+buQ3JhMiWNZCBEO71PMyLXaRfv6lUxM2WZ57tI6UnuiWGPJUKSvkMTaPSdwJkSakAhCh2tXP6MPCHrm8ssEyA86gBEUIHT+6RLkOObCgxaBDih9adGmuAmGu8IVLiRdiviMn9VNX5J0lnJbsF/CXcknW7Xrb5ZRFmoqv5DULxKWNqzTzMSVhStqoyp4t5W76sMMOSY9D/9CugbLCjML2CSo0DQUzf1TPGG7esdrxff3D/A7svKdGGoa6sSbg8x0cn+qsMbnE/yp5hwxcEBR4q X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 58689837-165d-4f26-89d8-08d94548de61 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2021 15:22:32.2150 (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: Uzk3Xc/AHD71IbOWT39cIb12VLAFiKAruwnwNC49RZODaslZX4Qy24FbgF9G+3wMuH4k4uNYeFzgTZ7wTPEywg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6271 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In preparation of making br_vlan_replay() be called automatically for every switchdev driver, we need to drop the extra argument to the blocking notifier block so it becomes a less bureaucratic process, and just emit the replayed events on the public chain. Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/mscc/ocelot_net.c | 3 +-- include/linux/if_bridge.h | 6 ++--- net/bridge/br_vlan.c | 32 ++++++++------------------ net/dsa/dsa_priv.h | 1 - net/dsa/port.c | 6 ++--- net/dsa/slave.c | 2 +- 6 files changed, 16 insertions(+), 34 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot_net.c b/drivers/net/ethernet/mscc/ocelot_net.c index 863437990f92..981adbf21200 100644 --- a/drivers/net/ethernet/mscc/ocelot_net.c +++ b/drivers/net/ethernet/mscc/ocelot_net.c @@ -1179,8 +1179,7 @@ static int ocelot_switchdev_sync(struct ocelot *ocelot, int port, if (err && err != -EOPNOTSUPP) return err; - err = br_vlan_replay(bridge_dev, brport_dev, priv, true, - &ocelot_switchdev_blocking_nb, extack); + err = br_vlan_replay(bridge_dev, brport_dev, priv, true, extack); if (err && err != -EOPNOTSUPP) return err; diff --git a/include/linux/if_bridge.h b/include/linux/if_bridge.h index c7ed22b22256..58624f393248 100644 --- a/include/linux/if_bridge.h +++ b/include/linux/if_bridge.h @@ -119,8 +119,7 @@ int br_vlan_get_proto(const struct net_device *dev, u16 *p_proto); int br_vlan_get_info(const struct net_device *dev, u16 vid, struct bridge_vlan_info *p_vinfo); int br_vlan_replay(struct net_device *br_dev, struct net_device *dev, - const void *ctx, bool adding, struct notifier_block *nb, - struct netlink_ext_ack *extack); + const void *ctx, bool adding, struct netlink_ext_ack *extack); #else static inline bool br_vlan_enabled(const struct net_device *dev) { @@ -150,8 +149,7 @@ static inline int br_vlan_get_info(const struct net_device *dev, u16 vid, static inline int br_vlan_replay(struct net_device *br_dev, struct net_device *dev, const void *ctx, - bool adding, struct notifier_block *nb, - struct netlink_ext_ack *extack) + bool adding, struct netlink_ext_ack *extack) { return -EOPNOTSUPP; } diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index 14f10203d121..ad2d1e56c6e4 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -1807,35 +1807,28 @@ void br_vlan_notify(const struct net_bridge *br, kfree_skb(skb); } -static int br_vlan_replay_one(struct notifier_block *nb, - struct net_device *dev, +static int br_vlan_replay_one(struct net_device *dev, struct switchdev_obj_port_vlan *vlan, - const void *ctx, unsigned long action, + const void *ctx, bool adding, struct netlink_ext_ack *extack) { - struct switchdev_notifier_port_obj_info obj_info = { - .info = { - .dev = dev, - .extack = extack, - .ctx = ctx, - }, - .obj = &vlan->obj, - }; int err; - err = nb->notifier_call(nb, action, &obj_info); - return notifier_to_errno(err); + if (adding) + err = switchdev_port_obj_add(dev, &vlan->obj, ctx, extack); + else + err = switchdev_port_obj_del(dev, &vlan->obj, ctx); + + return err; } int br_vlan_replay(struct net_device *br_dev, struct net_device *dev, - const void *ctx, bool adding, struct notifier_block *nb, - struct netlink_ext_ack *extack) + const void *ctx, bool adding, struct netlink_ext_ack *extack) { struct net_bridge_vlan_group *vg; struct net_bridge_vlan *v; struct net_bridge_port *p; struct net_bridge *br; - unsigned long action; int err = 0; u16 pvid; @@ -1862,11 +1855,6 @@ int br_vlan_replay(struct net_device *br_dev, struct net_device *dev, if (!vg) return 0; - if (adding) - action = SWITCHDEV_PORT_OBJ_ADD; - else - action = SWITCHDEV_PORT_OBJ_DEL; - pvid = br_get_pvid(vg); list_for_each_entry(v, &vg->vlan_list, vlist) { @@ -1880,7 +1868,7 @@ int br_vlan_replay(struct net_device *br_dev, struct net_device *dev, if (!br_vlan_should_use(v)) continue; - err = br_vlan_replay_one(nb, dev, &vlan, ctx, action, extack); + err = br_vlan_replay_one(dev, &vlan, ctx, adding, extack); if (err) return err; } diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index 20003512d8f8..3b51aaa26760 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -285,7 +285,6 @@ static inline bool dsa_tree_offloads_bridge_port(struct dsa_switch_tree *dst, /* slave.c */ extern const struct dsa_device_ops notag_netdev_ops; -extern struct notifier_block dsa_slave_switchdev_blocking_notifier; void dsa_slave_mii_bus_init(struct dsa_switch *ds); int dsa_slave_create(struct dsa_port *dp); diff --git a/net/dsa/port.c b/net/dsa/port.c index c86121e9d87d..63a244858e2b 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -208,8 +208,7 @@ static int dsa_port_switchdev_sync(struct dsa_port *dp, if (err && err != -EOPNOTSUPP) return err; - err = br_vlan_replay(br, brport_dev, dp, true, - &dsa_slave_switchdev_blocking_notifier, extack); + err = br_vlan_replay(br, brport_dev, dp, true, extack); if (err && err != -EOPNOTSUPP) return err; @@ -238,8 +237,7 @@ static int dsa_port_switchdev_unsync_objs(struct dsa_port *dp, if (err && err != -EOPNOTSUPP) return err; - err = br_vlan_replay(br, brport_dev, dp, false, - &dsa_slave_switchdev_blocking_notifier, extack); + err = br_vlan_replay(br, brport_dev, dp, false, extack); if (err && err != -EOPNOTSUPP) return err; diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 461c80bc066a..f8f06756c6a3 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -2521,7 +2521,7 @@ static struct notifier_block dsa_slave_switchdev_notifier = { .notifier_call = dsa_slave_switchdev_event, }; -struct notifier_block dsa_slave_switchdev_blocking_notifier = { +static struct notifier_block dsa_slave_switchdev_blocking_notifier = { .notifier_call = dsa_slave_switchdev_blocking_event, }; From patchwork Mon Jul 12 15:21:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 473332 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB463C07E99 for ; Mon, 12 Jul 2021 15:23:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D30E461004 for ; Mon, 12 Jul 2021 15:23:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235633AbhGLPZ4 (ORCPT ); Mon, 12 Jul 2021 11:25:56 -0400 Received: from mail-am6eur05on2085.outbound.protection.outlook.com ([40.107.22.85]:46304 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235514AbhGLPZi (ORCPT ); Mon, 12 Jul 2021 11:25:38 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CpI3R5VnU4XIxozFEs2HP5/hLpSlAAJvgHapAfiw7RMXciFKmaKJuGB3raMnNsvQ51yq0TXauofcLLx7ZwsQ+yLgleZvFCvLL7kvcPvsot7ZUpfTixjrkTInRRM2ZmAY2Pl7Fu/P522aQ6VyW1TA6gimPk3D52RcqTFZl+Kf1oC9ZS2V4yLjGzXUgnwKnrrI3sBKKiWN7oglNv4L+UbELbgJyHmqsHN9eO0EZQ5xmo0F1DAe2Nmog4YvOeDzh5tACC3EJjGrxzgUt9URacITBn7WnHvOrR3pb63QAwr06pwoWHnsqBN73TQtpCIcs8lNnHstLLiJpKyfxuhYRy/+4w== 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-SenderADCheck; bh=/+KVIVbzF/qsJO5Fqwixkq4iaulIzPKoUTb3Hy7E3rE=; b=WaTK7WuVW3qRZSkGlB6LIuLKLL+bJAUQHE9fzuSZdltaJ4L4gatEpMXAnTX52Pcn1Ty6o3QdVTXcGv/QD9xIqgYRBabkkdOf7NSoTJNdtiBg8PvUgcy8Ul/ReXNy5FfVKPGVHZOnUAAcu0Np7bolUF5jD2k7U3628hSFMMKur23SUR1fQbZvM3iAdPAfdZuF97fNgZvQyFdG0js3C62GhIOoHUAZyIQ8ZfdhKhY/L8jvMu0k7jkJtM9N/6aYL2fihDyg04sMF2I6B6TvgSMkS+zurcGOm6GAKaMOtGLPBQKSwWTUrY+5Oan+KXlLrxubgSX4s05xKzmfgf4y6GgRVA== 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=/+KVIVbzF/qsJO5Fqwixkq4iaulIzPKoUTb3Hy7E3rE=; b=rxxjx85DkbYYDMKFiqHMiAgYud85HrCaV5qVRJT1iSXl4LhIsXr2+RYKBk/j49gEYPA21Y4LWx1IpV5472323pd9xz7GieJJTxFOOt9luXyFNSsZQrYecGZQLvcgpAhE0THvGd/3KGr/guQo0zbUgPkUjVXMsgBLo1EMBsUfvZ8= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR04MB6271.eurprd04.prod.outlook.com (2603:10a6:803:f7::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20; Mon, 12 Jul 2021 15:22:38 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab%7]) with mapi id 15.20.4308.026; Mon, 12 Jul 2021 15:22:38 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Jiri Pirko , Ido Schimmel , Tobias Waldekranz , Roopa Prabhu , Nikolay Aleksandrov , Stephen Hemminger , bridge@lists.linux-foundation.org, Grygorii Strashko Subject: [RFC PATCH v3 net-next 22/24] net: dsa: add support for bridge TX forwarding offload Date: Mon, 12 Jul 2021 18:21:40 +0300 Message-Id: <20210712152142.800651-23-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712152142.800651-1-vladimir.oltean@nxp.com> References: <20210712152142.800651-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20 via Frontend Transport; Mon, 12 Jul 2021 15:22:36 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dd9a0eda-1a4c-4201-bf5f-08d94548e1e5 X-MS-TrafficTypeDiagnostic: VI1PR04MB6271: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FkRnMQMEl+sw5Wfg51onHJixVfuOwOyxnr5FbqqviCW6y6DKflFETRn6Xnh1LXxk6uGtMS/riD0FE0GB+cenFM8UBp5U7ZtBNPvoIYeObpl8edb/yaa+mz8g5pS26MpyMzYHTFJqzREKsRyuYH5RZAQlRK1ky22+dsT5RyVfCFRwUG5uTuxl6w9gnxU+wjOlXpJowtcAZFPu16Y09U/knX3wr83gQxPP8kVrPsjXJ4ElIkNQmjjWfsCBOjCUbH2XIgw7SjX891d/fIQMGXLhBunCy210PllLtoCeQxbjSLzacGK8WqtW0cXJAAd0H7HX4XKx2fg+O2XO7kcCfzEz4k2uuJMzCYFLpnnJE9f52ALPdtwHinpFrsPCA5eFO2J1Va6Esw36yLPBkg3O+Gu4UM4qzmVqLfipf/oVlcciLaHQWZYgtSfb8PNYDPk/HkoMeFOUcT6F1rpYCHT/TRaf7Fa4AKdJ9LDJb7eboTqcq8aQ+2UZSvUE9MHaf3BdiN8Tg6V+cMispmT2l/C3TOrV1HZXIcIfPyzxkfxgpU5oJxW+1gIwoimU41EmsxX2a38ANzMJjgXfKmkJ6S8GUI4sZG1WjLaaALUtHmBWmqnoIUM75ra5dUQKKJcVQFDd1IiaoVS0r76Zy6mFEsJ7Cck+zN+ICbyOwdnr8VI27l3jOcO4lXD6+jUOaqO/ikZ2MCWY X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(136003)(39850400004)(396003)(346002)(366004)(26005)(2906002)(66476007)(6666004)(83380400001)(66556008)(38100700002)(8676002)(30864003)(38350700002)(66946007)(5660300002)(4326008)(54906003)(52116002)(7416002)(1076003)(110136005)(6506007)(316002)(86362001)(44832011)(478600001)(2616005)(956004)(6486002)(8936002)(36756003)(186003)(6512007); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qMn+upSYZ+I/iV/Y8lMMgles+x4ItzTt99qyUDfjha3dvoVG73voyaZNCgS7cbWFrwb85h9G+Lw9bpkPPOYtduxyOstnDECcEJPUXROJ2tOD/7ZjWAqIuke2mXMhr+J2uDfxwdq8PLRfBthv1ey5eHDpHhO2aWPjksnti9fr9iPyfjEGUjl5wjvVNZgNxII5wtqJhJpbH02ZJ92z1lj8TMLa1Q25ijlLgQR5RysCXlJarmq3kj1Gmg1k9ESFvEgXL0eoI2qvLqv053RJux0iIZKWYm/Dt+9qJUlwLEs3/G0atRNjv2fDXh3sUqp4uHbqDQBLdL88n2ZlOp/R75qzLv2UKeCNuwULNqkYDPW9ZvS5FjXPCfsL88lXOjQmzwY7Sa58kuGDhGwUraN4GiqJU8OKDBHT9JpAp6P9gBLu6sER3hSeOAU70a9lkoIiUQdQbKzX0x1uanrKnK+CvLq73otHA41KSqifRkdoUi8kzLJgGV4ldIBTWn6Kj5pmJTlDpixnMcP6HImFDHvbSWqa6l4tkv49XLxKR5P1tz3byeG8b3ky37bRe4tHHP/hQeIdWGZpMkObl1FOA4hZOmSX6ES1Li0O86ZRyvFx1YYpi7zMNyX/RSFwPrfKH2PN75lsqH16dXamdQ5DN8HX8ZWzcF8YF9w7DwU49Nhvk5/VQ4pnnanjwtH4fgk4hQV3W9KD8diZB0T3IzZuBlPXIaO09Uqgh2+as5om3Fk1vcUAlWbSAk6kCc7wExLteSxOECwS+cK6i+1nEr1ievReNLSa/xMBqoa/LBhnXJEK4cnxwyHazNQWYNL916JrxEZ4P2ej+HGTnzl4SVguHOHzNWzAV6SH2cLNnrOZ0QtiJqpQuF1sO9TsuJFvgqQBfLxOQiW8GXzdz8Bp7JL5RU7UrOewkW4HZw7MFDXDe7F3qdahuZty+Hlg1MovNF/E79kPBmK8xSFoH0YNNa1D24zv2Pfk4b0yPCPymm9iDK+a8WF2AIE9h7A6l8saXgGNI9LrxPwl5XTHcHZJCPgVDH2Vfe9Wty+MztbVQ9GQeNGx4YIXKZIkbBwaRCVcqlL6YMArLx/LmfnyLdgWcJmWcRXNYIKcSVoNs5J31reDT4Bx1BL5GPBI55jfaZJo2HPBnzVNXWr+BnuFy4oXYf3LnC7LITNAb8mx7vnkwaZRfLK6/m8XYekTRAIi5JMwq/UB/Ui1eDjDzN3gAh+uzERGS7E8y2245g9YqbR1LX2B8aK2PlyP84hAXeoPlmBhy0Iio0TBc6L7EFLqMMT5FOUAd9gpIv2WW9zYBWDAHNqR3Io88+3mYDiYn898AcLBnbXi63yMz3Mf X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: dd9a0eda-1a4c-4201-bf5f-08d94548e1e5 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2021 15:22:38.1586 (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: efxtqv3q11+T6cB90Dt0sOSY9HWyyAqT/1RKYWHf8U2fdr/MtmGD18njbsuUsy2apzZZMYa+7PdNsvrBXUVLrw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB6271 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org For a DSA switch, to offload the forwarding process of a bridge device means to send the packets coming from the software bridge as data plane packets. This is contrary to everything that DSA has done so far, because the current taggers only know to send control packets (ones that target a specific destination port), whereas data plane packets are supposed to be forwarded according to the FDB lookup, much like packets ingressing on any regular ingress port. If the FDB lookup process returns multiple destination ports (flooding, multicast), then replication is also handled by the switch hardware - the bridge only sends a single packet and avoids the skb_clone(). DSA plays a substantial role in backing the forwarding offload, and leaves relatively few things up to the switch driver. In particular, DSA keeps for each bridge port a zero-based index (the number of the bridge). Multiple ports enslaved to the same bridge have a pointer to the same accel_priv structure. The tagger can check if the packet that is being transmitted on has skb->offload_fwd_mark = true or not. If it does, it can be sure that the packet belongs to the data plane of a bridge, further information about which can be obtained based on dp->bridge_dev and dp->bridge_num. It can then compose a DSA tag for injecting a data plane packet into that bridge number. For the switch driver side, we offer two new dsa_switch_ops methods, called .port_bridge_fwd_offload_{add,del}, which are modeled after .port_bridge_{join,leave}. These methods are provided in case the driver needs to configure the hardware to treat packets coming from that bridge software interface as data plane packets. The switchdev <-> bridge interaction happens during the netdev_master_upper_dev_link() call, so to switch drivers, the effect is that the .port_bridge_fwd_offload_add() method is called immediately after .port_bridge_join(). If the bridge number exceeds the number of bridges for which the switch driver can offload the TX data plane (and this includes the case where the driver can offload none), DSA falls back to simply returning tx_fwd_offload = false in the switchdev_bridge_port_offload() call. Signed-off-by: Vladimir Oltean --- include/net/dsa.h | 19 ++++++++- net/dsa/dsa2.c | 1 + net/dsa/dsa_priv.h | 6 +++ net/dsa/port.c | 100 ++++++++++++++++++++++++++++++++++++++++++++- net/dsa/slave.c | 13 +++++- 5 files changed, 136 insertions(+), 3 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index 89626eab92b9..99b4e23b003b 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -162,6 +162,9 @@ struct dsa_switch_tree { /* Track the largest switch index within a tree */ unsigned int last_switch; + + /* Track the bridges with forwarding offload enabled */ + unsigned long fwd_offloading_bridges; }; #define dsa_lags_foreach_id(_id, _dst) \ @@ -224,7 +227,6 @@ struct dsa_mall_tc_entry { }; }; - struct dsa_port { /* A CPU port is physically connected to a master device. * A user port exposed to userspace has a slave device. @@ -262,6 +264,7 @@ struct dsa_port { bool vlan_filtering; u8 stp_state; struct net_device *bridge_dev; + int bridge_num; struct devlink_port devlink_port; bool devlink_port_setup; struct phylink *pl; @@ -410,6 +413,12 @@ struct dsa_switch { */ unsigned int num_lag_ids; + /* Drivers that support bridge forwarding offload should set this to + * the maximum number of bridges spanning the same switch tree that can + * be offloaded. + */ + unsigned int num_fwd_offloading_bridges; + size_t num_ports; }; @@ -693,6 +702,14 @@ struct dsa_switch_ops { struct net_device *bridge); void (*port_bridge_leave)(struct dsa_switch *ds, int port, struct net_device *bridge); + /* Called right after .port_bridge_join() */ + int (*port_bridge_fwd_offload_add)(struct dsa_switch *ds, int port, + struct net_device *bridge, + int bridge_num); + /* Called right before .port_bridge_leave() */ + void (*port_bridge_fwd_offload_del)(struct dsa_switch *ds, int port, + struct net_device *bridge, + int bridge_num); void (*port_stp_state_set)(struct dsa_switch *ds, int port, u8 state); void (*port_fast_age)(struct dsa_switch *ds, int port); diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index de5e93ba2a9d..c7fa85fb3086 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -1044,6 +1044,7 @@ static struct dsa_port *dsa_port_touch(struct dsa_switch *ds, int index) dp->ds = ds; dp->index = index; + dp->bridge_num = -1; INIT_LIST_HEAD(&dp->list); list_add_tail(&dp->list, &dst->ports); diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index 3b51aaa26760..ff70e5afe3f2 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -14,6 +14,8 @@ #include #include +#define DSA_MAX_NUM_OFFLOADING_BRIDGES BITS_PER_LONG + enum { DSA_NOTIFIER_AGEING_TIME, DSA_NOTIFIER_BRIDGE_JOIN, @@ -197,6 +199,10 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br, int dsa_port_pre_bridge_leave(struct dsa_port *dp, struct net_device *br, struct netlink_ext_ack *extack); void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br); +int dsa_port_bridge_fwd_offload_add(struct dsa_port *dp, + struct net_device *br, int bridge_num); +void dsa_port_bridge_fwd_offload_del(struct dsa_port *dp, + struct net_device *br, int bridge_num); int dsa_port_lag_change(struct dsa_port *dp, struct netdev_lag_lower_state_info *linfo); int dsa_port_lag_join(struct dsa_port *dp, struct net_device *lag_dev, diff --git a/net/dsa/port.c b/net/dsa/port.c index fce02db6a845..283726f5121b 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -230,6 +230,75 @@ static void dsa_port_switchdev_unsync_attrs(struct dsa_port *dp) */ } +static int dsa_tree_find_bridge_num(struct dsa_switch_tree *dst, + struct net_device *bridge_dev) +{ + struct dsa_port *dp; + + list_for_each_entry(dp, &dst->ports, list) + if (dp->bridge_dev == bridge_dev) + return dp->bridge_num; + + return -1; +} + +static void dsa_port_bridge_tx_fwd_unprepare(struct dsa_port *dp, + struct net_device *bridge_dev) +{ + struct dsa_switch *ds = dp->ds; + struct dsa_switch_tree *dst; + int bridge_num; + + dst = ds->dst; + + bridge_num = dp->bridge_num; + + dp->bridge_num = -1; + + /* bridge no longer in use, time to clean it up */ + if (!dsa_tree_find_bridge_num(dst, bridge_dev)) + clear_bit(bridge_num, &dst->fwd_offloading_bridges); + + /* Notify the chips only once the offload has been deactivated, so + * that they can update their configuration accordingly. + */ + dsa_port_bridge_fwd_offload_del(dp, bridge_dev, bridge_num); +} + +static bool dsa_port_bridge_tx_fwd_prepare(struct dsa_port *dp, + struct net_device *bridge_dev) +{ + struct dsa_switch *ds = dp->ds; + struct dsa_switch_tree *dst; + int bridge_num, err; + + dst = ds->dst; + + bridge_num = dsa_tree_find_bridge_num(dst, bridge_dev); + if (bridge_num < 0) { + /* First port that offloads TX forwarding for this bridge */ + int bridge_num; + + bridge_num = find_first_zero_bit(&dst->fwd_offloading_bridges, + DSA_MAX_NUM_OFFLOADING_BRIDGES); + if (bridge_num >= ds->num_fwd_offloading_bridges) + return false; + + set_bit(bridge_num, &dst->fwd_offloading_bridges); + } + + dp->bridge_num = bridge_num; + + /* Notify the driver */ + err = dsa_port_bridge_fwd_offload_add(dp, bridge_dev, bridge_num); + if (err) { + dsa_port_bridge_tx_fwd_unprepare(dp, bridge_dev); + return false; + } + + return true; +} + int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br, struct netlink_ext_ack *extack) { @@ -241,6 +310,7 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br, }; struct net_device *dev = dp->slave; struct net_device *brport_dev; + bool tx_fwd_offload; int err; /* Here the interface is already bridged. Reflect the current @@ -254,7 +324,10 @@ int dsa_port_bridge_join(struct dsa_port *dp, struct net_device *br, if (err) goto out_rollback; - err = switchdev_bridge_port_offload(brport_dev, dev, dp, false, extack); + tx_fwd_offload = dsa_port_bridge_tx_fwd_prepare(dp, br); + + err = switchdev_bridge_port_offload(brport_dev, dev, dp, tx_fwd_offload, + extack); if (err) goto out_rollback_unbridge; @@ -279,6 +352,8 @@ int dsa_port_pre_bridge_leave(struct dsa_port *dp, struct net_device *br, struct net_device *brport_dev = dsa_port_to_bridge_port(dp); struct net_device *dev = dp->slave; + dsa_port_bridge_tx_fwd_prepare(dp, br); + return switchdev_bridge_port_unoffload(brport_dev, dev, dp, extack); } @@ -304,6 +379,29 @@ void dsa_port_bridge_leave(struct dsa_port *dp, struct net_device *br) dsa_port_switchdev_unsync_attrs(dp); } +int dsa_port_bridge_fwd_offload_add(struct dsa_port *dp, + struct net_device *br, int bridge_num) +{ + struct dsa_switch *ds = dp->ds; + + if (!ds->ops->port_bridge_fwd_offload_add) + return -EOPNOTSUPP; + + return ds->ops->port_bridge_fwd_offload_add(ds, dp->index, br, + bridge_num); +} + +void dsa_port_bridge_fwd_offload_del(struct dsa_port *dp, + struct net_device *br, int bridge_num) +{ + struct dsa_switch *ds = dp->ds; + + if (!ds->ops->port_bridge_fwd_offload_del) + return; + + ds->ops->port_bridge_fwd_offload_del(ds, dp->index, br, bridge_num); +} + int dsa_port_lag_change(struct dsa_port *dp, struct netdev_lag_lower_state_info *linfo) { diff --git a/net/dsa/slave.c b/net/dsa/slave.c index f8f06756c6a3..4eff63b4ef2a 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -1877,10 +1877,21 @@ int dsa_slave_create(struct dsa_port *port) slave_dev = alloc_netdev_mqs(sizeof(struct dsa_slave_priv), name, NET_NAME_UNKNOWN, ether_setup, - ds->num_tx_queues, 1); + ds->num_tx_queues + 1, 1); if (slave_dev == NULL) return -ENOMEM; + /* To avoid changing the number of TX queues at runtime depending on + * whether the tagging protocol in use supports bridge forwarding + * offload or not, just assume that all tagging protocols do, and + * unconditionally register one extra TX queue to back that offload. + * Then set num_real_tx_queues such that it will never be selected by + * netdev_pick_tx(), just by ourselves. + */ + ret = netif_set_real_num_tx_queues(slave_dev, ds->num_tx_queues); + if (ret) + goto out_free; + slave_dev->features = master->vlan_features | NETIF_F_HW_TC; if (ds->ops->port_vlan_add && ds->ops->port_vlan_del) slave_dev->features |= NETIF_F_HW_VLAN_CTAG_FILTER; From patchwork Mon Jul 12 15:21:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 473334 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8E52C07E9A for ; Mon, 12 Jul 2021 15:22:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9E6E161008 for ; Mon, 12 Jul 2021 15:22:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235605AbhGLPZp (ORCPT ); Mon, 12 Jul 2021 11:25:45 -0400 Received: from mail-eopbgr50084.outbound.protection.outlook.com ([40.107.5.84]:23552 "EHLO EUR03-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235535AbhGLPZa (ORCPT ); Mon, 12 Jul 2021 11:25:30 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TeskMXhhYvBxGuiQZSAruAjdGNikYwJw1FVi21LdYUDr0Kok+QueklILbX+xufbFOaCvTM7Mi7Q218pujiJR1iYKyuXohLVOvCvg8kILRtqQyVkgqvjIYzkwaXPK3BcI6ytnerI04v5Uj57BSzfX6ckhAn/iPxJ+1IOFE5SeUZNKh6pgSKnH1ScsoMzvAcqe/YIbGLybdkAdHf7tMZuJgnNMUcZ2uvnXzbj4/6H+Fw9xb86S+5LM6maCj+rC/UGIMZhrbiqKiVueiZx2wVhClkymyXJcs3dsqc9crT+fri38M8kz2ztOoSM144y9uyfBfujImukIai+oXc8MKyrcfA== 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-SenderADCheck; bh=0upUWCaw89Y/tpgL57V14pBNZVHaTEDlb60A0JoBUYE=; b=UHM8q/7FBb3ZO4IM+xXrLRQDueXbzFtCHpsbZ0m98UbHtLHDu3269vn2G9wMO3jKiqsP+krc5Ch6Y3GJUOEdvnM6rKmf7jkjUEe6BY5tUC9REgzzBAIiYy27qYaDLB7TimjRXgH/AVjo/UgG0v/jT7GsMpTAvGLZhT8r25hH+6IiFyjyoEJ9oEh3jO9kBLyWhBOAWWzt4RyOk48JIhIQkXDp0YCP8VnszGmViEB19sVEjZDIANVCJ3Avw8ORw+cp/kE1IPRLOrzCaHQiDWmKCe4qS0LwdYj/Psyp2AJkpOTVIWszgddjw1pdRC4Bc6v6Ku9DC9aOHe24Oyfi7/MVTg== 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=0upUWCaw89Y/tpgL57V14pBNZVHaTEDlb60A0JoBUYE=; b=j67h4TYtbuC2olWn/M+fwz65xE954Nf8lX2q0qiovsCPLbNsWMQalTHnRQ2fMqpOsvDRjH79pls+FoluAbtLc7w9ITHLQ8LuET4r044SXrAJDxtdAnTB3Q7gNWq5wm+4NLokLy3OLkMzMheOapeRs2eClblMqgNjxelfJthhRn8= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR0402MB2798.eurprd04.prod.outlook.com (2603:10a6:800:ae::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.23; Mon, 12 Jul 2021 15:22:39 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab%7]) with mapi id 15.20.4308.026; Mon, 12 Jul 2021 15:22:39 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Jiri Pirko , Ido Schimmel , Tobias Waldekranz , Roopa Prabhu , Nikolay Aleksandrov , Stephen Hemminger , bridge@lists.linux-foundation.org, Grygorii Strashko Subject: [RFC PATCH v3 net-next 23/24] net: dsa: mv88e6xxx: map virtual bridges with forwarding offload in the PVT Date: Mon, 12 Jul 2021 18:21:41 +0300 Message-Id: <20210712152142.800651-24-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712152142.800651-1-vladimir.oltean@nxp.com> References: <20210712152142.800651-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20 via Frontend Transport; Mon, 12 Jul 2021 15:22:38 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 0ffc0977-79d6-4d03-e3f5-08d94548e2c0 X-MS-TrafficTypeDiagnostic: VI1PR0402MB2798: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: APn4LA7YBP7HnWnVu0M+OohAaROhDANi19NBxYLTT39rZwlFZ5DdtPnpYo05RbXPv4AAUuoiXHPbCuKlg6ZpUEg0El7qI7d7pfgAo45VhJaYQDesLa8vX4+MYV6ljJktMqVS8iZKPNuVL0aZCl4y7Ay2sIfO7+Fx9jILyS1JyiQ2CUtE7V6YcRCGEziYqjcf1ExfKN+k2umXdrLrWFH1FkLyoFcxc7dG/57Kt8jb5Gg9hfC2kzRvnkm2EZWGdD+a4b60KH3huzkCYnldflJhyJafoTaxPqooDt6kLzM7+Q30Iaz6dv9IEVERJKsLi5SmXq5DiOBR2YsWrLBG4Y1SfvSeer1NhitCd1YTNsauDGGloATEYnc/hfEsihzHxDCDwI4Szx9CGnCV2FjG0mn7cSiM9cAmwbVqpBXGUIPGxdDFX9oaNuIv0ILpTm5x5ZinOrQJgj9gc8PymH+I2ZaHGn//s1lbT6f17xerrA3sDb0OIacmm1nX0gvfgKbUckWdwQe3laur+roJKzqSnOCpOVOSslTeNiNGgXKwKFP2v4PEQjXW71syFb9C9wyz6nzGpsHvG7GR8+YaVjSNmMKyTj70OAl1/yyj6L036hpXcfuTycttRVCSs+/S57P2bvlsQT8Z/zb3u6mVDKUg8ZbcUkAFYovt3ZVL9Id7UwV65T0OMBMbP3tKTS0OLClO5m4t X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(39860400002)(376002)(346002)(396003)(136003)(366004)(83380400001)(66946007)(4326008)(110136005)(2906002)(52116002)(6506007)(54906003)(38350700002)(956004)(2616005)(186003)(8936002)(44832011)(316002)(1076003)(38100700002)(6666004)(478600001)(5660300002)(36756003)(6512007)(26005)(66476007)(6486002)(7416002)(8676002)(86362001)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: sbaB3xUgWLtmM4tYTbIEtsB5e/G40YBoVwh8dcNHzNvfF54qi1ps9ZyPAKLrliT7OVMZ8fH+PInHqQP92itczfstFEoiojgKhLMLBZodv2RDyE72e/POEBE76/q4Ifdk/oGWz0bNbEIOWcBIS2XSvz3t/RT2LIv9ZuZLqrCexJe3WmnzaztTH4b3nXyfvoNKqjQnrB5o+Ozt586CcbAKmi2v55II2SedqKZaVShqTz5Z0yH4cs/HqXpAfVsEM3YnLqsCTxxR8DWoJLyOasygNh6EI6alH8vTEkq3mihU4A8zjV+62WM0twYjSZ14JUsJBmcTpsdnkH+4iKyUKagML1gYGR2z9L23uvrXAgFWSrkHE/uyUHaqfv4WRc8r/Q9INwUC4Y9bWmUEQL8eVrwQ+KcKPQUyzS9xW8hYeVWj9wiVpDZs5UnDfehAmTmDcy3irF9rl7P2cAq0mYdG6IZYs+tZPbRxmKcFsJNvZE062IMmpfgm1HYZFg9Q3hNLAmE7o7PhEFwtNePeWMSc8JSKd0IkjP2WGWMvEfXUrmpUfukk0ZSog05xhfK9ioli4ewypQ6LzAylROU54H/yYFyoZqSL6HLaA7CNFd8LfWkFnOa9G6NoRoi42ekQNpKYEN8pjWbVA10ewQYKCm+lwRjOdOI+1PNvTTBG4X2IqQUtrOJa4DhGeOIBNdOpq2u+4Ia66y81jAVES9oc+XmWRROV/nlEGSei4Z6ja5cnrMxAz2oK5gbrCVFlmRJeA6Vxm313FGdvf25mkjL9HJSA/gzRVcK50slWAwaJoVfEnBwQrG3EupHX2Jj7fyz34k1xYMHZi2+4vhyJJ88aXDxRvqSnWqcVS3GoOLdumejcK5DD3UotdP+FZSMDeNMB8pjO7ffERCFQLqtCbe1LQpLPuCjYT5wSBMXFtuifYrA3/c4BlCWKVzg3BLjCxja5eK3VOTRKW0wJQ4Kq+Sc2ASaW3XXoDPG7XerjszBoCLWwpK/V0WrZh8avqJpSyQFZs9bkwiBrq1AvJ1hvOmC4e+vVQf+3vPMmfkcVM+e1wvmXl3Qy67pil5hwkdacHjVG4JLdoR3Dx4rPNgSO9o6+sB8DmJvVGeNBLol57sY+Y1MX7q52JubphRvGtd7dbleJnWPNmdaBawU5Md3ZEfCcLYZikMgWBGSIQT/1WjoqcfShujYB/fn3kPGs0OmAfL2juW+yOE1zY0ZAXZOVvEtuDJlMvQpgWXgZk6ZJrMb8FKz5GnSbt6FivVYnCQvKE1aRqjFLrpdnRdkyzzOHZtnWaD5LcBplo2Qib4HQ0836N0SbsRV9mc/WZ1saEnAZ0zE7gPkYC4O9 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0ffc0977-79d6-4d03-e3f5-08d94548e2c0 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2021 15:22:39.5189 (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: wGTpC48TNOXBOsaLBtr+udCokDj92dgPKvh+3mTA972bNJr2i2neIAyAn4CTTybjwuAW13zIsEAPjD5t7FJz9g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB2798 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The mv88e6xxx switches have the ability to receive FORWARD (data plane) frames from the CPU port and route them according to the FDB. We can use this to offload the forwarding process of packets sent by the software bridge. Because DSA supports bridge domain isolation between user ports, just sending FORWARD frames is not enough, as they might leak the intended broadcast domain of the bridge on behalf of which the packets are sent. It should be noted that FORWARD frames are also (and typically) used to forward data plane packets on DSA links in cross-chip topologies. The FORWARD frame header contains the source port and switch ID, and switches receiving this frame header forward the packet according to their cross-chip port-based VLAN table (PVT). To address the bridging domain isolation in the context of offloading the forwarding on TX, the idea is that we can reuse the parts of the PVT that don't have any physical switch mapped to them, one entry for each software bridge. The switches will therefore think that behind their upstream port lie many switches, all in fact backed up by software bridges through tag_dsa.c, which constructs FORWARD packets with the right switch ID corresponding to each bridge. The mapping we use is absolutely trivial: DSA gives us a unique bridge number, and we add the number of the physical switches in the DSA switch tree to that, to obtain a unique virtual bridge device number to use in the PVT. Co-developed-by: Tobias Waldekranz Signed-off-by: Tobias Waldekranz Signed-off-by: Vladimir Oltean --- drivers/net/dsa/mv88e6xxx/chip.c | 78 ++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 4 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index beb41572d04e..061271480e8a 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -1221,14 +1221,36 @@ static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port) bool found = false; u16 pvlan; - list_for_each_entry(dp, &dst->ports, list) { - if (dp->ds->index == dev && dp->index == port) { + /* dev is a physical switch */ + if (dev <= dst->last_switch) { + list_for_each_entry(dp, &dst->ports, list) { + if (dp->ds->index == dev && dp->index == port) { + /* dp might be a DSA link or a user port, so it + * might or might not have a bridge_dev + * pointer. Use the "found" variable for both + * cases. + */ + br = dp->bridge_dev; + found = true; + break; + } + } + /* dev is a virtual bridge */ + } else { + list_for_each_entry(dp, &dst->ports, list) { + if (dp->bridge_num < 0) + continue; + + if (dp->bridge_num + 1 + dst->last_switch != dev) + continue; + + br = dp->bridge_dev; found = true; break; } } - /* Prevent frames from unknown switch or port */ + /* Prevent frames from unknown switch or virtual bridge */ if (!found) return 0; @@ -1236,7 +1258,6 @@ static u16 mv88e6xxx_port_vlan(struct mv88e6xxx_chip *chip, int dev, int port) if (dp->type == DSA_PORT_TYPE_CPU || dp->type == DSA_PORT_TYPE_DSA) return mv88e6xxx_port_mask(chip); - br = dp->bridge_dev; pvlan = 0; /* Frames from user ports can egress any local DSA links and CPU ports, @@ -2422,6 +2443,44 @@ static void mv88e6xxx_crosschip_bridge_leave(struct dsa_switch *ds, mv88e6xxx_reg_unlock(chip); } +/* Treat the software bridge as a virtual single-port switch behind the + * CPU and map in the PVT. First dst->last_switch elements are taken by + * physical switches, so start from beyond that range. + */ +static int mv88e6xxx_map_virtual_bridge_to_pvt(struct dsa_switch *ds, + int bridge_num) +{ + u8 dev = bridge_num + ds->dst->last_switch + 1; + struct mv88e6xxx_chip *chip = ds->priv; + int err; + + mv88e6xxx_reg_lock(chip); + err = mv88e6xxx_pvt_map(chip, dev, 0); + mv88e6xxx_reg_unlock(chip); + + return err; +} + +static int mv88e6xxx_bridge_fwd_offload_add(struct dsa_switch *ds, int port, + struct net_device *br, + int bridge_num) +{ + return mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num); +} + +static void mv88e6xxx_bridge_fwd_offload_del(struct dsa_switch *ds, int port, + struct net_device *br, + int bridge_num) +{ + int err; + + err = mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num); + if (err) { + dev_err(ds->dev, "failed to remap cross-chip Port VLAN: %pe\n", + ERR_PTR(err)); + } +} + static int mv88e6xxx_software_reset(struct mv88e6xxx_chip *chip) { if (chip->info->ops->reset) @@ -3025,6 +3084,15 @@ static int mv88e6xxx_setup(struct dsa_switch *ds) chip->ds = ds; ds->slave_mii_bus = mv88e6xxx_default_mdio_bus(chip); + /* Since virtual bridges are mapped in the PVT, the number we support + * depends on the physical switch topology. We need to let DSA figure + * that out and therefore we cannot set this at dsa_register_switch() + * time. + */ + if (mv88e6xxx_has_pvt(chip)) + ds->num_fwd_offloading_bridges = MV88E6XXX_MAX_PVT_SWITCHES - + ds->dst->last_switch - 1; + mv88e6xxx_reg_lock(chip); if (chip->info->ops->setup_errata) { @@ -6128,6 +6196,8 @@ static const struct dsa_switch_ops mv88e6xxx_switch_ops = { .crosschip_lag_change = mv88e6xxx_crosschip_lag_change, .crosschip_lag_join = mv88e6xxx_crosschip_lag_join, .crosschip_lag_leave = mv88e6xxx_crosschip_lag_leave, + .port_bridge_fwd_offload_add = mv88e6xxx_bridge_fwd_offload_add, + .port_bridge_fwd_offload_del = mv88e6xxx_bridge_fwd_offload_del, }; static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip) From patchwork Mon Jul 12 15:21:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 473333 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 05E5DC07E99 for ; Mon, 12 Jul 2021 15:23:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E465861004 for ; Mon, 12 Jul 2021 15:23:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235615AbhGLPZu (ORCPT ); Mon, 12 Jul 2021 11:25:50 -0400 Received: from mail-eopbgr50084.outbound.protection.outlook.com ([40.107.5.84]:23552 "EHLO EUR03-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235550AbhGLPZb (ORCPT ); Mon, 12 Jul 2021 11:25:31 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BmobA9Uakx/LG/BsWclT58QmEx/kj8LDV2PJlE1gosr290FRUg1eqlILE+7t29TgPzPUIGv5DHzf9hB8E7OOs7v2VSU95RV8qgApODvE27zob/wc+2GXg57UdyDnHcrP8WoQNU9hdvYa7kIfSLbhQpmbwKmN9rV0zc6S1lB01Fgj/xkK0I6SkYMcxmR10kmMC3rUgZ5J5CfxCdd/nzgkHma6+WenvlAAKYHdrbunwxbh1lDfopQB1cjantGAy7vhjxT8zTg6+7cYu+DyIYBs/scvmEJdG1jrvBUJZUb58Y8rbenIcCFzCOt/h+2QA1VPW3LaTJ3tS376arj1KRQnMg== 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-SenderADCheck; bh=PhRJZfuWSZ6soOzr0n7BBsWXwa+g+/chbcyOA+nDW4s=; b=Eu35toHCgLGdIDTSul1NnySSVfSRFyXSgFP+Lavm7G2upX7s0dJquX9xgWEZ+zzCoEDKwP1os8IiPkNsjEi0N00d/TTOtQi9+Y2FxDDu+GG25KrPcULyb+8qifjEF43pltLfdI5MKCZSgMSYjshSc34J3jCsTMKwKJEzK999Nu3YX0oGtWAGmBkfeoqVZX9HsnSuYgIsHtQQAx9TlszntHmT3vsbHW/DGfUe3FyL2zlTE+fl7Nz8WdI36mxulvaTFlsiUYNFF+zam0jfAi8AHvpekt1AflXaD/kzbEZmB9x7B1nB7sh9CdxgNdg2gCAVHrBXPeFwbwz++RJ9SyeRBA== 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=PhRJZfuWSZ6soOzr0n7BBsWXwa+g+/chbcyOA+nDW4s=; b=Vx4KCH/+UXcrZWokHMxlRqTfsIvcyGLIw69eEZcUzDvaFQkwKb8mroXWLFbbejhN8eUL/IWkCbPS5+mAapqK0cGaN4F0xtrgARXfoOKVBef4bjAwVM/nSJF2H3feGDN/GE9Me186gGFenfq8gKAvuOFJIlS4j1JjBW/E3q7qEM4= Authentication-Results: vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by VI1PR0402MB2798.eurprd04.prod.outlook.com (2603:10a6:800:ae::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.23; Mon, 12 Jul 2021 15:22:41 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::b1a0:d654:a578:53ab%7]) with mapi id 15.20.4308.026; Mon, 12 Jul 2021 15:22:40 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot , Jiri Pirko , Ido Schimmel , Tobias Waldekranz , Roopa Prabhu , Nikolay Aleksandrov , Stephen Hemminger , bridge@lists.linux-foundation.org, Grygorii Strashko Subject: [RFC PATCH v3 net-next 24/24] net: dsa: tag_dsa: offload the bridge forwarding process Date: Mon, 12 Jul 2021 18:21:42 +0300 Message-Id: <20210712152142.800651-25-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210712152142.800651-1-vladimir.oltean@nxp.com> References: <20210712152142.800651-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by AM4PR0101CA0058.eurprd01.prod.exchangelabs.com (2603:10a6:200:41::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4308.20 via Frontend Transport; Mon, 12 Jul 2021 15:22:39 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 55b34e6a-5bb0-4fe2-273a-08d94548e397 X-MS-TrafficTypeDiagnostic: VI1PR0402MB2798: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MzEkkI+MXb8sWZfPez9F1rPoYmuP/+C3xQKeO3iG+xdhO4I0zMTzD9lYWzWa54oOsV4hUHijobJpH92h50a7DcoVmffqALL5bRhCHxLA5nXq8gs26DcHBA37iIWYZvGnAx4lAsWk7R0B1d9I0E0JlAP5bDrFNKjpkfHgSu3gOXr3mr/535pObAq5r5wdGpVjBTEBjXEFqLQVu9oi7iP31Oum3qyGxoFQWTdgniGlPgaUW/+GA/Bv8yE7Bn0UcFvvJIAA9dvc3LLq/cUSKSqmevAnr5+V+TucpiWJLEI3tXGPLize56wg3E4HsSqjPAfLDi/qdMUBOG+tuDHiHPJ3wrCAoDNcDZ0mnwy/ldE4rpjFly4umzXvWn/Gq8Rz+SRIYIjtA6zyzy+9spGSvr77bjUXSd9Y0+zAfD7vLqyY6bdZ694OwkeaPCd+N0sME6/IGPGkVsSFU/0RaPasCLhKEeP2gEPDnEhWBfgf7XKEORzHV0NhW2ATrCgIn3muihSoyl6/5Cs9gkVl6MO3Kkp34UPmldegrXUx8NegKLUWjCAsv55tigjBCbBP6GYx4wiv3YXrFt0nH9egrBkzeOAVoDqGzL/oGLf241EIpMMqNYOb3eQc39jnvBUSZMVbYTn6K4EIA+1UWgbrd6PHS59Ij55knkWhoP2SN4sC6ueTZ7lilBmimXFhR1ytlZWYP5mSFLZh8EYOUXq+dGRvRnf0Lw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(39860400002)(376002)(346002)(396003)(136003)(366004)(83380400001)(66946007)(4326008)(110136005)(2906002)(52116002)(6506007)(54906003)(38350700002)(956004)(2616005)(186003)(8936002)(44832011)(316002)(1076003)(38100700002)(6666004)(478600001)(5660300002)(36756003)(6512007)(26005)(66476007)(6486002)(7416002)(8676002)(86362001)(66556008); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ftcUt3gq4ciC+etsyVWzZb9PZd4cfI0ZlvtMSvyWZx8IkdYrw+0zM6fETY4Wxf8tFNR48Xf1UkRYdZdgIvmrCvLcJPvm3Fg1HPLOAeceIS5BaHpTzLFKwSgaljmnnLZfgorssMu3jLVp7YKaH0afsbbgRBbiqD63pEAeu+5m69ddhxuJOXhK5sv7sM/GBK2QHmL+jfRVgnE1nfXvttv2R+oGzMMhxDIDrjrjRKDseryYd86mm4K4K0nT7xan3V6AOLf7SV/ZNUenz5VyOytYaElA7Bn5Q0TEvbMreDtZS8Adxj+EuOoIHH5GUNWDz3HESCqxVHho3dBGMlvAeUceHyJttM2LkKi4n378QUmy/64rFUcBEOIWNQQNBmFj/OCTd2IsEfHn3VP0jRj1uKTef4UEoxXevQx8IOL+uH9nTQCpfUEUr7jZ4QTgzbXF8OXGfVcOg01CODmjLPDGset9rCVHAD63eRMrrEmEVsQ5kbwyIgWiqCcAQT/RHM2JnvgR7JCvL+efYH1Yhwzjpx39xvZI9laZPSyrejKUPoVud6TPeMLcUrteHUC6LPMqa81hLfuvif8LK1TNrtAoUb29WzrgLfttEyl/aTjqaHmuir46vvmSdo1ujTEDxspLhTvss1o6CnFlhEERYWd6uxMpGDWCN9cRY+OmoKrquowTA0q1G5c+BU4OH6lfwwUxJzdMHrOK/jqEcNyzfzBKjLM3UyzlwX8JyoIt4zbGQC27NxFSyyB/hetmhE4FUKNoqwhRLF2LWBoSl/vtj7irFxpJepzMdaGDrvrMyintdHKOHHvMqJP1yXJl/fabEIinW0dUdX0a8EjbiuhKGjUaFTEyOu0bmiQzvcmp4pFxPIspCeYvzWcArZB2WFUR+VLkrMMZxg4C/mLhFw34A3bZHo4sjMgNPy1eg5MjBIAjYO6JSNhx4Zwax0v1klAcWK6yMSY9uByK/T7ct3o2VSU8BkfEHJTasUzITP8vjepQk56RDvC/By0CVcMmnM7VFiXhCZw6wRIHf4L8dnHo2eTBSr5V8jiEIr3q6CFK6A6BpaTilQHWl1RC3zEgM8jbwh5nHnJqUp2PxD11rsOWvjTGxPR8peN4Nkvj6YFA5+q7VpDIouvpE+OsUF5dsqCyeHp4hQlDO2/yzBKoteW689/EXeCkLTgy58K3PeliB9FkrAOQ7xIDm66ZJVUFwm/rakPuXlYjW0aVQ0Ec6LZdD0EJVKqvkp/uj5u8y1V26XL2h6vTXq5bDE56GHFoQ6MBfhQSBM7j0Zx0B43PUl+Qd0IOcYyYeVTwA5zrUi4nhz3B0g9YUFuRK3Udl61+DmiK0y2OMlqo X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 55b34e6a-5bb0-4fe2-273a-08d94548e397 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 12 Jul 2021 15:22:40.9630 (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: Bdjvc9XgQ39Wn7S2wahLQ46QUvDMQb5e7xkTzLS4K4UANRNrQOPohStw+H0V5jEJSIzIcd6tsiCKCRBJQym+Wg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB2798 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Tobias Waldekranz Allow the DSA tagger to generate FORWARD frames for offloaded skbs sent from a bridge that we offload, allowing the switch to handle any frame replication that may be required. This also means that source address learning takes place on packets sent from the CPU, meaning that return traffic no longer needs to be flooded as unknown unicast. Signed-off-by: Tobias Waldekranz Signed-off-by: Vladimir Oltean --- net/dsa/tag_dsa.c | 52 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 8 deletions(-) diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c index a822355afc90..0f258218c8cf 100644 --- a/net/dsa/tag_dsa.c +++ b/net/dsa/tag_dsa.c @@ -126,7 +126,42 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev, u8 extra) { struct dsa_port *dp = dsa_slave_to_port(dev); + u8 tag_dev, tag_port; + enum dsa_cmd cmd; u8 *dsa_header; + u16 pvid = 0; + int err; + + if (skb->offload_fwd_mark) { + struct dsa_switch_tree *dst = dp->ds->dst; + struct net_device *br = dp->bridge_dev; + + cmd = DSA_CMD_FORWARD; + + /* When offloading forwarding for a bridge, inject FORWARD + * packets on behalf of a virtual switch device with an index + * past the physical switches. + */ + tag_dev = dst->last_switch + 1 + dp->bridge_num; + tag_port = 0; + + /* If we are offloading forwarding for a VLAN-unaware bridge, + * inject packets to hardware using the bridge's pvid, since + * that's where the packets ingressed from. + */ + if (!br_vlan_enabled(br)) { + /* Safe because __dev_queue_xmit() runs under + * rcu_read_lock_bh() + */ + err = br_vlan_get_pvid_rcu(br, &pvid); + if (err) + return NULL; + } + } else { + cmd = DSA_CMD_FROM_CPU; + tag_dev = dp->ds->index; + tag_port = dp->index; + } if (skb->protocol == htons(ETH_P_8021Q)) { if (extra) { @@ -134,10 +169,10 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev, memmove(skb->data, skb->data + extra, 2 * ETH_ALEN); } - /* Construct tagged FROM_CPU DSA tag from 802.1Q tag. */ + /* Construct tagged DSA tag from 802.1Q tag. */ dsa_header = skb->data + 2 * ETH_ALEN + extra; - dsa_header[0] = (DSA_CMD_FROM_CPU << 6) | 0x20 | dp->ds->index; - dsa_header[1] = dp->index << 3; + dsa_header[0] = (cmd << 6) | 0x20 | tag_dev; + dsa_header[1] = tag_port << 3; /* Move CFI field from byte 2 to byte 1. */ if (dsa_header[2] & 0x10) { @@ -148,12 +183,13 @@ static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev, skb_push(skb, DSA_HLEN + extra); memmove(skb->data, skb->data + DSA_HLEN + extra, 2 * ETH_ALEN); - /* Construct untagged FROM_CPU DSA tag. */ + /* Construct untagged DSA tag. */ dsa_header = skb->data + 2 * ETH_ALEN + extra; - dsa_header[0] = (DSA_CMD_FROM_CPU << 6) | dp->ds->index; - dsa_header[1] = dp->index << 3; - dsa_header[2] = 0x00; - dsa_header[3] = 0x00; + + dsa_header[0] = (cmd << 6) | tag_dev; + dsa_header[1] = tag_port << 3; + dsa_header[2] = pvid >> 8; + dsa_header[3] = pvid & 0xff; } return skb;