From patchwork Sat Jul 3 11:56:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12356965 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F3F4C07E97 for ; Sat, 3 Jul 2021 11:58:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4362861926 for ; Sat, 3 Jul 2021 11:58:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230244AbhGCMBI (ORCPT ); Sat, 3 Jul 2021 08:01:08 -0400 Received: from mail-eopbgr20072.outbound.protection.outlook.com ([40.107.2.72]:8275 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230209AbhGCMBD (ORCPT ); Sat, 3 Jul 2021 08:01:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NBFnAbBR5m2AmAz0MN9ofObTOrkFzvTlFdbL8g02MXZhar+soDdOUMY1eEHhHG3CRFxTXnUmAcBZlVLzY9Tf1wXOrEYKR7dfcoDk9XhTHRszzwIa1GKzT9UGFBwfq5y/inPddD0EePBg70+jQlX6O6EFIkP3NpWxTIyFjfzg7MAeeD9ocPL7gafvgX/Bw4FuD4ltDuMEmyZdJ3vnUWK8Wj1wKuSarNtmLgr0Bo/00LfNIj7+hOgtCpmOIakv2cukUZneB0gT0uE/7J+8BVWUY1FCEHJT5CZJH0ZUrrpg8SVcWv60rICxCDuhme4i9oMCCGFruL/ciz3OfdJMMuek3A== 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=/8ARGCbzXYmxoVhI/W45fy7wsub+EkJDR8//ZmjXIV0=; b=XM4w9UjhvbXRwMvuZQlQSBLfChaquFWZMuvMk/Jr/MK47bPTYIT6NWD1twJv3XZz5ukJdEwjI/38z3l+LBAUkxEdMBsjyhjFrB9idP+WixBSXi2X1di5mhz/kysfhuSdMCfOONdTOR17R/JxBVcovLHKRf2Kt5X0V3rZ/ji1Y6zsNlRL6SM2jPQp7qRWvWezG8HPF3vjcIUUIVAWizVtSgaudXKchTwJYOtIps3FVUXJhDG71S0nOabatEVDzzNbOc2G63H3aOp3lqo7hGa7cNfB/M2ZIL83h0JWt8VXmVtLCuw60bVBcwoSoJ9Z2WP5tKaxGvTlZRTWmC/RlxUTvQ== 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=/8ARGCbzXYmxoVhI/W45fy7wsub+EkJDR8//ZmjXIV0=; b=UdldaYw4PcFuEjx+U3FA+s70+P9JWLeP7uPnZYH/3YA8Kfxiq4vdgSWVbDvpIApj+WYejlfqc1G9kEOj9NU6RrFUL8wuFl+0xtn1TOUQyo+05vOYnbA4vWUM5bQhTTwbn6QsYxsDY74SZ6I0WWz6IhPwmFl6e77CfcxD04IY+bk= 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 VI1PR0401MB2509.eurprd04.prod.outlook.com (2603:10a6:800:56::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.22; Sat, 3 Jul 2021 11:58:27 +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.4287.031; Sat, 3 Jul 2021 11:58:27 +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, Alexander Duyck Subject: [RFC PATCH v2 net-next 01/10] net: dfwd: constrain existing users to macvlan subordinates Date: Sat, 3 Jul 2021 14:56:56 +0300 Message-Id: <20210703115705.1034112-2-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210703115705.1034112-1-vladimir.oltean@nxp.com> References: <20210703115705.1034112-1-vladimir.oltean@nxp.com> X-Originating-IP: [188.26.224.68] X-ClientProxiedBy: PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::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 (188.26.224.68) by PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.23 via Frontend Transport; Sat, 3 Jul 2021 11:58:26 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 008a85f0-f965-4ed1-b8fe-08d93e19de40 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2509: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6790; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: y7AKiONQfHFmIheJfwdHIedL9rkavL2MlqgZ0fwDNzvugVmwGVXWYXYdCx8/krG/l0ScKmlWrtZNddCiycLDrU0HR6h8yxI8t9+hirbkRWMy7vtupw/7pK4JxOjNW2ZNXlTpRNJXFfXWL1JUYKvFloKqFJavpIVWnNsEnkWKuQ6xQ/c246VyF/ILxfWWdTR7dGwYzS2ZLZkgU5Ar4q5C8PiXEXHscWY5OZzeiAxE9WH1/YM/VJnLcrbX4EXqrz9/s0y2tznoS0mXqdH4UmXYTFW5a81GRj3d6CfciL8pnPSv0hDurlWVQif+KyuI2MVcDJieL9zptacARie1bqp7DLono+OINmGeAA6gr4DzkeerA/3+EbvmnJuviQ4QUStz1vBQL7C/hPtp0pb3uF7L/Hs1YcfZitb/ld0hVOc2BSJPgUZEnSghWwQHRx585JPiwQskQZmEL/r0PN2UJ86UmQ2ydd3eIvUy85Tc/Hvs/RljQQpaaoB6+uc2KYXWF7kdIhn9BOlTvw4mQy19bVx3TprTeCjfnt9QnUNBM8HRwIg5N6wRTR7MfS1ZVQxpgdAZ3RgPDnSnHVK8oUdmk/GSna9WQuA1erAoELfXQO4SuUpiyKZhNlWbPdGF9bPhh021EfBtmCGW6rfE4QtPN8g+6K/VcuffX8xVuSSu8jNJm82JEYP+COT2cAaS3wTlPwdlH56MyaNuQcGEe4eKbeTZkrsW7fNTFnmlfVD2dpzmzPkv5qY69TrRFOz8DOV45HLI 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)(376002)(366004)(346002)(136003)(39850400004)(6506007)(2906002)(4326008)(36756003)(2616005)(44832011)(956004)(6666004)(478600001)(7416002)(5660300002)(110136005)(66946007)(26005)(52116002)(1076003)(8676002)(8936002)(316002)(54906003)(66476007)(66556008)(6486002)(38100700002)(16526019)(38350700002)(186003)(83380400001)(86362001)(6512007)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bhAVE4AAj6zIn5zXBD32TxDIseNtbCOUam94Z2dhpG0CRXwQ+uCQ5k+O7erhanDQCoaASU30hcUJeExzZ6FLWR8tPWJqNPIwcOCPpGvnUqncXvZbuQe/UA3Lf4IngTgx3aHOXmZe7NloPqw1sFgSB4H2cVZDKfGQ8bgfDqezT20FRZ95aAXreeEm0T3AplmO/9lluGuMw+1M4pD9OUXRFEL2pklcMIfJbqMwrSkjNeBehQEMDkZrPRE/CfAX8MF3tGq8q/ItOxAUOv/wk2qrysrQpGmJSApnl3oQgmikGOPFeB+Q0TO+NoPULayoMcGfRJXa1lBCzpG9aPyGdNDOgdtsZ1lFDYEBn1l63lwvD2wUTGExx4UAXubF6sFlTsMWr6FPz4Waf4OhatOtPNhrIyPwME1PgnGSAAquxPW8gce6aOjltHI9q+i3XHWk1LPowxT0CixU4CuP2FqbU1vUa24+4FpogGPkV76tmZqhZJ8aFlPC5Zfy/bnoYFKL54tGKTmHHOVq5NrY0S8oPYSnOkN6uzCE5TTl8b9DQe0mo7PdRn+7+KItauqFvGqlD4vc1mLFd6db8RruxCKz6a1IXoIh4Zh0Jt9CluinKBW2krxVt83APru9omFPUCLuy1XfV5SqRMVs3hr9MG6fGZW3YspMWxpu31UXADMuNGYCwNstvAKG4LDHCiQUTBeEuXvzmUU9+weEXAMB6B3nXMSE+rHa+S9LIb6K6xQbnvJBtUfkIvaFWoRN3gEv5eMIz+Hj78vV5hNi1x9FutljfTJSEvpLZxaI3goTqWEE9f0dU1+mURQg0SgoNqdYiU3Akfw6LZvOsk0IwgrhKBQjc2cHvszLbnLo5ArGbWSSf9HEBPa+6X630+95fCfVAZRzEWfmRX3cWnJnjTqSfeksLAvEybti02RwgdEvaMZMEz6oI5zn7MLgvbuDQax04STUJwuMtjA9tc6FDZBrTpcBGmquCICV1ni5Z214Juw1/ONvXO/etRahMVRNyXOGtQaB07IGRI4Fdu28I6gURzSXziMWNLTowjTlPs6jKcn/azQxE8zEeQWL8TSekrpcCvBsdGIsQ1iFOm5jDEwC9/d3PzXR+Oi0bEhBeX+u+Jfbf8sw3QoxfeQ8zL+0zOpFm0RDfbzDcewezEBM6z2cbjoVS1Oxx6hMkV0bJzBXP/D4WuXIrVya3R8zScoJ7ttbUbNSqjTLk66zAh5NsT1qJ2QeTTb0BnNL5B+lNwGZJmVjYXeY5cmqaEYEmloYm7V7yDGbGFdnfR5vckdHTBnBHdk9XdddjKAYDv7NDkEsC8ixgtYm0pGixhbtXqP10akAmCLThWXz X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 008a85f0-f965-4ed1-b8fe-08d93e19de40 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2021 11:58:27.7531 (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: 5hkSIc9L6k+wKEYSFrVtaGkMl3IuCTEY2DO9/tZEyTi95MieXHhLweetRjM6756n9UO5I6oLLHzym4Lv2pAJWQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2509 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Tobias Waldekranz The dfwd_add/del_station NDOs are currently only used by the macvlan subsystem to request L2 forwarding offload from lower devices. In order add support for other types of devices (like bridges), we constrain the current users to make sure that the subordinate requesting the offload is in fact a macvlan. Signed-off-by: Tobias Waldekranz Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/intel/fm10k/fm10k_netdev.c | 3 +++ drivers/net/ethernet/intel/i40e/i40e_main.c | 3 +++ drivers/net/ethernet/intel/ixgbe/ixgbe_main.c | 3 +++ 3 files changed, 9 insertions(+) diff --git a/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c b/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c index 2fb52bd6fc0e..4dba6e6a282d 100644 --- a/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c +++ b/drivers/net/ethernet/intel/fm10k/fm10k_netdev.c @@ -1352,6 +1352,9 @@ static void *fm10k_dfwd_add_station(struct net_device *dev, int size, i; u16 vid, glort; + if (!netif_is_macvlan(sdev)) + return ERR_PTR(-EOPNOTSUPP); + /* The hardware supported by fm10k only filters on the destination MAC * address. In order to avoid issues we only support offloading modes * where the hardware can actually provide the functionality. diff --git a/drivers/net/ethernet/intel/i40e/i40e_main.c b/drivers/net/ethernet/intel/i40e/i40e_main.c index 861e59a350bd..812ad241a049 100644 --- a/drivers/net/ethernet/intel/i40e/i40e_main.c +++ b/drivers/net/ethernet/intel/i40e/i40e_main.c @@ -7629,6 +7629,9 @@ static void *i40e_fwd_add(struct net_device *netdev, struct net_device *vdev) struct i40e_fwd_adapter *fwd; int avail_macvlan, ret; + if (!netif_is_macvlan(vdev)) + return ERR_PTR(-EOPNOTSUPP); + if ((pf->flags & I40E_FLAG_DCB_ENABLED)) { netdev_info(netdev, "Macvlans are not supported when DCB is enabled\n"); return ERR_PTR(-EINVAL); diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c index ffff69efd78a..1ecdb7dc9534 100644 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_main.c @@ -9938,6 +9938,9 @@ static void *ixgbe_fwd_add(struct net_device *pdev, struct net_device *vdev) int tcs = adapter->hw_tcs ? : 1; int pool, err; + if (!netif_is_macvlan(vdev)) + return ERR_PTR(-EOPNOTSUPP); + if (adapter->xdp_prog) { e_warn(probe, "L2FW offload is not supported with XDP\n"); return ERR_PTR(-EINVAL); From patchwork Sat Jul 3 11:56:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12356967 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E8C9C07E99 for ; Sat, 3 Jul 2021 11:58:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4FAB761922 for ; Sat, 3 Jul 2021 11:58:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230258AbhGCMBJ (ORCPT ); Sat, 3 Jul 2021 08:01:09 -0400 Received: from mail-eopbgr20063.outbound.protection.outlook.com ([40.107.2.63]:47491 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230231AbhGCMBE (ORCPT ); Sat, 3 Jul 2021 08:01:04 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=R6JTPvUN5dXa8u+zrlj1g9QCRP8AC7VZtmy51DnYPZCR1x1X0XzJWr53kv8z+ssm92Wn1VS98aGieK/pGDr9jnviwJEXfEs4lqIguOJIH7Cg8vrqKi07ddmvYaQ5J0wRn3PnZwb/noWO8ROdbfTUOw0TsNtER/cugY3Fb5tvH+NjalADzv7Tx7U5sLmN3NvT+Zq+ibou8FY09y3BKpiViETTFme0bxqtuw96sSDq9X1RErj1X6Of3JRY//ZyV9aOngpkP1v+Timtk916Ga0svrgAazF8q+9FT6eNrc7nwKOux0pIHxso+FfLZ3BYylqKOnr3i7rTmOfwDrtjJK8ylw== 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=vzrmRMFH55T/ycNRCVZN7/f2Fva2SypalG7KrtWnBFU=; b=fdaTGJxC8niX9GqP+MZB8CZNzDE2OSq4886xUaEii8LfUY9h+W7phsAyU+pv1gnsSVrdAoIY+LSvyGICjDF8NlpHhFRhy1vwr6kdd1cQHAfRet/CuU2JbMzz1i1tW/5d61D9ggvsO4wzUznufPrdZRmhJpbgrkB8bcfFJQLDYR8AtwRloe0KGfF4+xMX35wKPYBq3ImYvg2TZnCNkTFsJsV/IJOqc6MXFCv8MuKsZjWn+8AJbxI863ZjoLGMFPF1JYyoV9BSrZPSKr5zWk1vmflZBDMIKFaZsLDG5B2TGT+8qehWvLexXIS8R+eMr4UXJ6LPkio8r1fiWJ6fKUFIxw== 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=vzrmRMFH55T/ycNRCVZN7/f2Fva2SypalG7KrtWnBFU=; b=cYzWzvG/+SxMcWL0LzviySjZGnuVQT6Ujw3Idz/4jzNDpiR/PniZBvRlQdnDwgR20XhbU9HqDXkBT5QaxoN0m2lWYE9O5oa0h6P1/aESoa2IAh7PbkHJb2w24DdsHqsmAqezpuyYgaTZlyuJvYueBjch6cACoVP6vObxG+ZIhYk= 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 VI1PR0401MB2509.eurprd04.prod.outlook.com (2603:10a6:800:56::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.22; Sat, 3 Jul 2021 11:58: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.4287.031; Sat, 3 Jul 2021 11:58: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, Alexander Duyck Subject: [RFC PATCH v2 net-next 02/10] net: bridge: disambiguate offload_fwd_mark Date: Sat, 3 Jul 2021 14:56:57 +0300 Message-Id: <20210703115705.1034112-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210703115705.1034112-1-vladimir.oltean@nxp.com> References: <20210703115705.1034112-1-vladimir.oltean@nxp.com> X-Originating-IP: [188.26.224.68] X-ClientProxiedBy: PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::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 (188.26.224.68) by PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.23 via Frontend Transport; Sat, 3 Jul 2021 11:58:28 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: fd94ad1a-8d80-4fd9-6a62-08d93e19df3d X-MS-TrafficTypeDiagnostic: VI1PR0401MB2509: 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: muXEHepXIYwlyG9ezU3q9FLXHVUyVwZojR0r1QPwa5BdZUha3tsQShwx6Rudk3b6QeTFrsY9f3dBSkPXYe7RrBUCa/Z7EzJeqMdsZd6g/4aDs3xuXmCRhmNr64aZ4dImoSyLu5dLteejk9IyZ+mRMMjy9/Y6cC+q8DUY1Bf/Hz9O5m71oJpZn2dktWtwFseVtuoyHwIal9vZrX2VQ08my3tN61YrpNSw2vgHgozju5VLaVendgkHhw9if2/v+QWwx2BalOpkzj1vD/4vFf9OPpNYdjoI4EWN5AQbD8Uh9OI9pfSRx6C67RlX4FdUjbB9p3ll819N9ylxLlDBW89TirKX5MdT0YDxkUvxZgB/BSARVlOJ/ry8epWz+OYcPsVpHfeerVuQtnWQ6s3qxj+n90Jqfy3UXsWoJQYMzpft135Py372/NfJY3XitJqwcesmlZtQttSfXkhwE7QU1yxDVFs2AMpqfc/iDHNr/yDcQns8Zu/CgiBOnurXSq0llgiihcmioPtr8BsLImiPKzJ9ExzxBijkEUHxsDBxp+l0cKqLVHu7N7xzepi/+O/tQu9Szm3jVxfq2zCJJIfPaFr6mVJmAywKx9YvTl6UfrHlVn3Hbg8vT4PMgslB/P3BE/vO1WrxZ5iBXO1/tEYe6jAVwpqVbwutyhJ5+AzTsxRPksBp2OOmNvXxnE6n8F+w8MPM1banpPcbEVkHPsH8/b/LbV3rtTw9KI2yNq2U49/6k0AjgAQRLV8ZP3buQuStZ88q 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)(376002)(366004)(346002)(136003)(39850400004)(6506007)(2906002)(4326008)(36756003)(2616005)(44832011)(956004)(6666004)(478600001)(7416002)(5660300002)(110136005)(66946007)(26005)(52116002)(1076003)(8676002)(8936002)(316002)(54906003)(66476007)(66556008)(6486002)(38100700002)(16526019)(38350700002)(186003)(83380400001)(86362001)(6512007)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3BQtmk++LXB+tPdvwaNSllpkn5gAXq1IFp3HGVvJFCnD6KCnVPfDb9Ul4ZD9BYLXr16Um7xhTf6QXsa6duwWmbP3oAkEYGqV6X4awpaa3HdTFdwhQMxsWpITYuB65+4j7mtw95aCpve+yAiIOOEndP1AUivO4NNj+gaNuHHzd59rMEVUK06VSxeqpn7YKGyCoYX9nzx5Zr6adDa+wuG0PgPj4uNfA0jWBSOz1cuQ2bkW71r8h9rrlGd0N2k18+CowgTPOqug+a2ta7T7ObuOBDn7CkYqlWegQlDGrAEF2Xch+FhKh3IO0USEztiIMKOQCKKYNXXiIrkaxVVv+jdSSJQahf4/T7waGRehgbEi/QAPGBzL/UrV2AtMNHx/u/bpV/8x+dbRYFkYoJlA79tndsg/qmSmGL76D6JdtTacrLA98KVeEkMgygQpxdSg/kdkONQ+mzEyKfXaPvwkFtzH1avoW513DKCqXb2tVReMHLkH3AMWpdE33gbKnmZqCDHWfwQiWcZ9OGAPVaP+samrIW8C3g2IixYCH3JfADi4Hn+Nm4fa7AfQJ2VOsxb6n2xyfoLTOPkkSJ8uOlIsSmT1RHnlyTTnfkdIhRSZlVoZ8JOit6wSCgy8HKiAgiOpcZHUmHc3nrydp58BfQxtSuGoYPRPMBoU6hBK11RqX8ZouxO+gLYoeam0HYmOKisPw/K+7C2rDNq5rt2GOsWCAcNQ/AUdY94qcDJbrVaVbZMtcvW7JKEV8nvI9QfhC4/q6zqPFilPLubwm0a2FxmWMFPHKIrDqCxMxCK4RBaRuE0oPIvkx1mlDo+2rtYVmvqMB+6yZI9Jf2OvhfkqMzUh1k90LgEoQGmDVMUxqMJuBVby2NvCyOuppmYsQ2+ACAuyMSxPKijMGvsFYUBNTnsuWE72bwKHWmsDfU+SkkdNVA41LKQChF3ZzMlDNqg9p2utYEvzdEomrPimidZNd2N7OYfKRBYfnOT3Rduuc6i3baXg9MKIlb8gKRBIPS4D/CQtV8Hv3rhLTkyQeIDWPimPCwWDjpwQqHubxJzu7aqR1XGL0S/XUA/4ggfQWawikQAU7vNPtX42B0W+B/ql18LGhlbkq2tIlTkaDt7PzJvjiiqu2HatefjyDZ+fNiYrscE0m4RhyfTAUKrPtiwjexEevLQVkdw7++EQ9hDaAmz74a485JvDom4rymz8ygbHRsq5OjfeKfuOBlnLUh0BdqZD+yKh8GVoZyIYtwwkBVsNwvoXzJRFJVJkmOdHDK97aiuuKAa96GTCFVCCWmlWK01TrVjt0fiGSwjBY8OykaHhWaVvyfbD1QPaaT8AJXWknbGYDEmm X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fd94ad1a-8d80-4fd9-6a62-08d93e19df3d X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2021 11:58:29.2113 (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: 3s9s9h5HeK2iK2AuyyviKUEjhBoL3chspdpdXM4H1Qcs9mvefGyL70HUBhibGFbajFSPI8TVmwoges+xlXdnyQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2509 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Tobias Waldekranz Before this change, four related - but distinct - concepts where named offload_fwd_mark: - skb->offload_fwd_mark: Set by the switchdev driver if the underlying hardware has already forwarded this frame to the other ports in the same hardware domain. - nbp->offload_fwd_mark: An idetifier used to group ports that share the same hardware forwarding domain. - br->offload_fwd_mark: Counter used to make sure that unique IDs are used in cases where a bridge contains ports from multiple hardware domains. - skb->cb->offload_fwd_mark: The hardware domain on which the frame ingressed and was forwarded. Introduce the term "hardware forwarding domain" ("hwdom") in the bridge to denote a set of ports with the following property: If an skb with skb->offload_fwd_mark set, is received on a port belonging to hwdom N, that frame has already been forwarded to all other ports in hwdom N. By decoupling the name from "offload_fwd_mark", we can extend the term's definition in the future - e.g. to add constraints that describe expected egress behavior - without overloading the meaning of "offload_fwd_mark". - nbp->offload_fwd_mark thus becomes nbp->hwdom. - br->offload_fwd_mark becomes br->last_hwdom. - skb->cb->offload_fwd_mark becomes skb->cb->src_hwdom. The slight change in naming here mandates a slight change in behavior of the nbp_switchdev_frame_mark() function. Previously, it only set this value in skb->cb for packets with skb->offload_fwd_mark true (ones which were forwarded in hardware). Whereas now we always track the incoming hwdom for all packets coming from a switchdev (even for the packets which weren't forwarded in hardware, such as STP BPDUs, IGMP reports etc). As all uses of skb->cb->offload_fwd_mark were already gated behind checks of skb->offload_fwd_mark, this will not introduce any functional change, but it paves the way for future changes where the ingressing hwdom must be known for frames coming from a switchdev regardless of whether they were forwarded in hardware or not (basically, if the skb comes from a switchdev, skb->cb->src_hwdom now always tracks which one). A typical example where this is relevant: the switchdev has a fixed configuration to trap STP BPDUs, but STP is not running on the bridge and the group_fwd_mask allows them to be forwarded. Say we have this setup: br0 / | \ / | \ swp0 swp1 swp2 A BPDU comes in on swp0 and is trapped to the CPU; the driver does not set skb->offload_fwd_mark. The bridge determines that the frame should be forwarded to swp{1,2}. It is imperative that forward offloading is _not_ allowed in this case, as the source hwdom is already "poisoned". Recording the source hwdom allows this case to be handled properly. Signed-off-by: Tobias Waldekranz Signed-off-by: Vladimir Oltean Reviewed-by: Grygorii Strashko --- net/bridge/br_if.c | 2 +- net/bridge/br_private.h | 10 +++++----- net/bridge/br_switchdev.c | 16 ++++++++-------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/net/bridge/br_if.c b/net/bridge/br_if.c index f7d2f472ae24..73fa703f8df5 100644 --- a/net/bridge/br_if.c +++ b/net/bridge/br_if.c @@ -643,7 +643,7 @@ int br_add_if(struct net_bridge *br, struct net_device *dev, if (err) goto err5; - err = nbp_switchdev_mark_set(p); + err = nbp_switchdev_hwdom_set(p); if (err) goto err6; diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 2b48b204205e..e16879caaaf3 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -329,7 +329,7 @@ struct net_bridge_port { struct netpoll *np; #endif #ifdef CONFIG_NET_SWITCHDEV - int offload_fwd_mark; + int hwdom; #endif u16 group_fwd_mask; u16 backup_redirected_cnt; @@ -476,7 +476,7 @@ struct net_bridge { u32 auto_cnt; #ifdef CONFIG_NET_SWITCHDEV - int offload_fwd_mark; + int last_hwdom; #endif struct hlist_head fdb_list; @@ -506,7 +506,7 @@ struct br_input_skb_cb { #endif #ifdef CONFIG_NET_SWITCHDEV - int offload_fwd_mark; + int src_hwdom; #endif }; @@ -1645,7 +1645,7 @@ static inline void br_sysfs_delbr(struct net_device *dev) { return; } /* br_switchdev.c */ #ifdef CONFIG_NET_SWITCHDEV -int nbp_switchdev_mark_set(struct net_bridge_port *p); +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, @@ -1665,7 +1665,7 @@ static inline void br_switchdev_frame_unmark(struct sk_buff *skb) skb->offload_fwd_mark = 0; } #else -static inline int nbp_switchdev_mark_set(struct net_bridge_port *p) +static inline int nbp_switchdev_hwdom_set(struct net_bridge_port *p) { return 0; } diff --git a/net/bridge/br_switchdev.c b/net/bridge/br_switchdev.c index d3adee0f91f9..833fd30482c2 100644 --- a/net/bridge/br_switchdev.c +++ b/net/bridge/br_switchdev.c @@ -8,20 +8,20 @@ #include "br_private.h" -static int br_switchdev_mark_get(struct net_bridge *br, struct net_device *dev) +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->offload_fwd_mark; + return p->hwdom; } - return ++br->offload_fwd_mark; + return ++br->last_hwdom; } -int nbp_switchdev_mark_set(struct net_bridge_port *p) +int nbp_switchdev_hwdom_set(struct net_bridge_port *p) { struct netdev_phys_item_id ppid = { }; int err; @@ -35,7 +35,7 @@ int nbp_switchdev_mark_set(struct net_bridge_port *p) return err; } - p->offload_fwd_mark = br_switchdev_mark_get(p->br, p->dev); + p->hwdom = br_switchdev_hwdom_get(p->br, p->dev); return 0; } @@ -43,15 +43,15 @@ int nbp_switchdev_mark_set(struct net_bridge_port *p) void nbp_switchdev_frame_mark(const struct net_bridge_port *p, struct sk_buff *skb) { - if (skb->offload_fwd_mark && !WARN_ON_ONCE(!p->offload_fwd_mark)) - BR_INPUT_SKB_CB(skb)->offload_fwd_mark = p->offload_fwd_mark; + if (p->hwdom) + BR_INPUT_SKB_CB(skb)->src_hwdom = p->hwdom; } bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p, const struct sk_buff *skb) { return !skb->offload_fwd_mark || - BR_INPUT_SKB_CB(skb)->offload_fwd_mark != p->offload_fwd_mark; + BR_INPUT_SKB_CB(skb)->src_hwdom != p->hwdom; } /* Flags that can be offloaded to hardware */ From patchwork Sat Jul 3 11:56:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12356969 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2710BC07E98 for ; Sat, 3 Jul 2021 11:58:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 06CB6617ED for ; Sat, 3 Jul 2021 11:58:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230289AbhGCMBP (ORCPT ); Sat, 3 Jul 2021 08:01:15 -0400 Received: from mail-eopbgr20063.outbound.protection.outlook.com ([40.107.2.63]:47491 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230232AbhGCMBG (ORCPT ); Sat, 3 Jul 2021 08:01:06 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZKKHAdX5qSR+Cfti61G8iaUXb9bG5kSmtMYwK7Q4zhJpW36fSA6dyQH+nql/QC8Y6GU4Do+wIzxb/GNWuM+DL7jOkV+enmNiYvPtA4mg3cVLsv5bHdJG1+pO1HD7+DX5m1me3Dp9l+acGTKKoaDojAbpsgreD/YOlktkBjRoKXfmX+3b9ieNbzNyklhN6+P49ehcJgOLR9fS+nuMnGbqa1+1zNHNE/MITSjpZaUxdfMMKIqhqRrI+e4URC2hdXYLHcfiraIApqhilT3CsOi9twxPHDq5JSqaDA5d4NZTnzyhTJiqt6DXwKbeOqvBNFMMB42krsVs22BEE0dplbxb4A== 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=23nRG5Gwg8ZyF9G2b15V4G3AQDjXOyi4pS+pH4O6H6E=; b=dlhcrAkOo4UfH3PnT5NJTGcKFjOO3ig+j7rjvy4f6qdjKx8NSqgcG9lTGRfYabRcAOEB/la8Mj8g7keR6qksR3mn9twk6eQSCTgcfDgx5fSNSek452fERlDfHodWsGVKwYO+mZOW+l4AKHG4OGLOU7dW7mqYrtRRq7ODcb/uJBN3qJUeI67/KYhoGY6JmAKByMmcqvC8P4N2pYNesGpKiw836wIPSLCfvhQUV82SrmVCyeImmY4hQN2py42iepvSY37ZwsQHIAMrKA7nsLucjq1pha88GM0C2cb/D62G5TuisobhlasBY80+J9/WP18UaOryBAMiLESQxlai6fnVaw== 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=23nRG5Gwg8ZyF9G2b15V4G3AQDjXOyi4pS+pH4O6H6E=; b=DmYtY+M7ZwocFWW/DUxJ2SBfX5CcqwBERzUvGUlAuYSqbR3lSjyAJVyb26bJ3r8a0eYTBC2ktsuDIfoikBzD2bGxWhF1FUeOCVmfOclwqHhmZGGN9TLDzvz2JdVwQMCa6QDVYWiQSTSQx1O0PVa8jNlPtLwO6oniYhfqcWKzElA= 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 VI1PR0401MB2509.eurprd04.prod.outlook.com (2603:10a6:800:56::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.22; Sat, 3 Jul 2021 11:58:30 +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.4287.031; Sat, 3 Jul 2021 11:58:30 +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, Alexander Duyck Subject: [RFC PATCH v2 net-next 03/10] net: bridge: switchdev: recycle unused hwdoms Date: Sat, 3 Jul 2021 14:56:58 +0300 Message-Id: <20210703115705.1034112-4-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210703115705.1034112-1-vladimir.oltean@nxp.com> References: <20210703115705.1034112-1-vladimir.oltean@nxp.com> X-Originating-IP: [188.26.224.68] X-ClientProxiedBy: PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::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 (188.26.224.68) by PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.23 via Frontend Transport; Sat, 3 Jul 2021 11:58:29 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 790bd6b0-0a43-4201-e9d4-08d93e19e01b X-MS-TrafficTypeDiagnostic: VI1PR0401MB2509: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: n08rB0HripkAh3Kf5EzN344txaHa85WmLevWHsMkX0AHskZOJNssOJuup0bqYUpvnLm8Q7P6JfV5H/wbBOIHmwDAQSpOA7zi2hYQZSEQLbUWcYnJ9OSH8Opp03Cj10be89VU/32px6SeRH63NU7Y12KGrhuJVkor2YUtJwOLJig4398VK+hQJP/0rUxx+ujWSNc1PXGIaBLJk/RtozUawOqSdSSdxylFNA4yX8Y9Jr0f9WfJfUX5MQntNWLqjDUCL9oEOTjhatta9DlkDtEyTT5ft8bXyrET2B8dGHKeMzyM2byyldbTDR4BjeGwMgKu1vOdWHH5n8KuwUHjnvJfvfAuA8AqtGD5pBSN2xy01fzBYb3gl2lGJsvbf4OFx1gmVQhhaw4c9OuIJckmorlwdcY4KNcw+31LBBusFmP/9WuPSvePJq073TfM2lFOCW6ru9w+EeuT7wwYEVLHl7E82lUlMcNAPPyAF8+Crpbkfib04sL0knpgFeX6PIJO1JP4l6ZwqcsmkmSgATP/7qp3uu89pjdHIC3pBJoKvTEW9Jnhx/3zIb4IOixHB4gfW2GNaCluFRbtdTFtu9qkLiHrH1A3GkrEQcYF6Au1mS7oroWt5G4ZIC71wckOUSulDNOG/wzEMWd3imZIvwcDe85Pno8B4/b9TPvi39WM7xDOIEyc5gW7qGO2brOUmZtENyx0wKg5mMr7MXZ8DYtaRNVUTV+nZoP1Q10SJSPhyS9KoNna3pGFXXtdPCLWDRhxX6ZC 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)(376002)(366004)(346002)(136003)(39850400004)(6506007)(2906002)(4326008)(36756003)(2616005)(44832011)(956004)(6666004)(478600001)(7416002)(5660300002)(110136005)(66946007)(26005)(52116002)(1076003)(8676002)(8936002)(316002)(54906003)(66476007)(66556008)(6486002)(38100700002)(16526019)(38350700002)(186003)(83380400001)(86362001)(6512007)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: g8scRTQ32Y7plqkznipE2H+PzmYNtMc/8BFW1E7GAgWUoFB2C2Nzl3gYWaZ0/2rTYkG5KC/FC5UUvj30pQENkpv92yuPnSmDO0gxfU2/U07r5Z5igBP8YmiTXB5UPjWq4iBP7ZzX+afzYN3ZTfr9eb6Xrad876t1O2Km3gBlsBkP0RQvCZdluGTMdqfW8l15GNc+kz8/Z36gxHpPPKrEnfOxqCcVogIIr7734JCm6O7z2BwxLDRj61tTxIPjCflwmRxHm6Q4ssjLHucRqArDEfmWZ2/Qe1+4Ww/OUkR56cUwU5zSVqwGvu5dkZxFEQaUPLpcfPVyIFYSbDMQYzdmJ/2qJX5d44AfUDyt2GndOuV5ttNaZ8zrthDMstBPRXtlApuPYxArb6/TU7soHw1EjVt25lElxNyDFh3PXvWqSdXL/aACPsW3vCBTiu6LyW93qplftO470kBg6WQKPVWEilvF4oseGaMgRrHv/Z2ClxrLNW3A7TEaGmCyNv8z3ZgaLFW0F5FR0allV0ybzzJc5tTSSwkYArcfidkbRTcfd8JvzbYLHaUZ+gRzSbCWu9awKQBDNUVmzrw+mmTfZOAbbz0vjvo1ZAi9XV3MKIhrPIdVDS6moS7GM3M5h6Tzy9SRoK9C4D6v0UStKqn2z3dlnQ/QartoVEJC57zwu4GRYJ7p3u1p/UezSss+MWf3lme5RHFzLC+4dQJqp24rqDxZmS3ZW7AFwWf75pLwC7Dv7fahEsY2QqNSm0/80fyVNRnKvPQGN7fXkQRv9Pdb/ha6EL5jGPW8fDTdi0s8KLAFIY1QehXROWZyeQa+bupc33ABGe2hrZ+B4pbQSNa9Aoj6ExP6PgWHgQQUi89X48k21/Q+db992wNXQm4U9P/VAPcAvBHXZnQHd51h/oTb/egfjrcUlN2+7BpawyuOXv2uETwL+tXcyMbtmsxMoGElQw8vlhvf0lMFuaDXQCo+LppuBTI/pLfXexzhQF/rRgyju7YL4g8ACSFUGJB+l0TBg+kf+wvplWXIc8wntvy5EF/pVlco9y5SBU6dbQzMBPmvLJvz+UDK7FORzLvtUIzcBSDLwbd8bVMmWBu9mcacxmLJMKP5h9bqU4kPkHCGO8YVNnimV4L783hDpFM0+UtGhaaCrUcyowv05LYSaJkr8aI0qivIUINtAMhjgggyF8/5WTrs9/ASJ35lhMqauOSYFMEP3wr79CO+3GAzsdy+/Mq8n1vt1uAOwzjrlADFEz9BiSLXiiy/Ir9sbk7hCVgDrySqV6Xa7Oovs1nm4MG8OdCObe/nlpvkco8Otyo0J8wocLmCsMRmuV7ecH2Juz5eKpqH X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 790bd6b0-0a43-4201-e9d4-08d93e19e01b X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2021 11:58:30.6614 (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: 8z3ZtuOH5SfhweurBe7ZcSdETxDILZe3EtJTFoPiZrQL4almii6OYeIJddwU44P3QqZpTRhpN/sCTBGLpW7sZA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2509 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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, 85 insertions(+), 40 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 e16879caaaf3..9ff09a32e3f8 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 */ @@ -476,7 +478,7 @@ struct net_bridge { u32 auto_cnt; #ifdef CONFIG_NET_SWITCHDEV - int last_hwdom; + unsigned long busy_hwdoms; #endif struct hlist_head fdb_list; @@ -1645,7 +1647,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, @@ -1659,17 +1660,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) { @@ -1710,6 +1709,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 Sat Jul 3 11:56:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12356971 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8222FC07E9A for ; Sat, 3 Jul 2021 11:58:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 62EC361416 for ; Sat, 3 Jul 2021 11:58:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230312AbhGCMBR (ORCPT ); Sat, 3 Jul 2021 08:01:17 -0400 Received: from mail-eopbgr20063.outbound.protection.outlook.com ([40.107.2.63]:47491 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230209AbhGCMBJ (ORCPT ); Sat, 3 Jul 2021 08:01:09 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BylWH2M228AT4o1jP/Dsr1S3JyNW3PDQ7t852Lk2501PvyWzFy7x19d1hVtvbmoqaN0gZVyd9+8kJVqoT6yPUlIieY7B1S+Ww9pKP0+JWTUjzni4X8wc4V76OoJoiOo+04ePJm7VDvu4kWhpsgaaMC07n/Q2Ls6xbg+YO4Qheud8zf0FwPihGTYPNJOmVN41n6z+IraK4bCMAuOz+LMf6EaC42EwE4IMq/oxWiOox2oZJUmYYnoM9syLW5HPvCZcw1lgpZVESJrya7+KxFkugb3gIT0BEWnTCHTXv6DWDuKWcqsAj3VuqSZstdAVuF6biTRXIADlUaIfb0oWNxzfVw== 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=jgxR7hFYSoTBWSHzj5ZUbxnFm+s0uIOxEOzE3rEZmOI=; b=M+NqLnguW5tg2o2snbBhveyKuBwO59INcnVnisJVgwAMAZcFwoFXhWVUozKIGOD9KjaQxjc7aVY/ETiIX7vDRYtHF2FkN9lBXwERjeBERHCe07I4ZOGrKYhz87XNf0Dk9iQffCtGRlC1ij/0Hx3m3MXAxMYnJB+iQInwHBF2UklIr7MnLHKAnb5XRKQf9xzYdVkdgSv0OVTnnQ6O1WjdujrT2xsIlLkLWlSscv8LzvpXsh07bwecfXNHjoxA+oU90MjyOVbvtoPzvYZf6nTyETKcxsCc4tzQLuxHp9H43I0tBD3c/8+i0xVDwQr/UIx57VS9ieXcEzEuKeMNcEG83w== 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=jgxR7hFYSoTBWSHzj5ZUbxnFm+s0uIOxEOzE3rEZmOI=; b=WTrlWR3zS10EVS3swB3BcwzODRW1GdUzHXdroYIfxLI+DoLmhcRqGHEgCRKyGDPZFWhtkLseWAyVp8ppTbV5tM3QktgVfZXQ1UesGhRu1G2Wt9kHjkIsfU2Q+J1JF0LIoOFIljiQF3yxx9nTYhaf429xEA2GMejyIlnf4z4UkpM= 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 VI1PR0401MB2509.eurprd04.prod.outlook.com (2603:10a6:800:56::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.22; Sat, 3 Jul 2021 11:58: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.4287.031; Sat, 3 Jul 2021 11:58: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, Alexander Duyck Subject: [RFC PATCH v2 net-next 04/10] net: bridge: switchdev: allow the data plane forwarding to be offloaded Date: Sat, 3 Jul 2021 14:56:59 +0300 Message-Id: <20210703115705.1034112-5-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210703115705.1034112-1-vladimir.oltean@nxp.com> References: <20210703115705.1034112-1-vladimir.oltean@nxp.com> X-Originating-IP: [188.26.224.68] X-ClientProxiedBy: PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::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 (188.26.224.68) by PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.23 via Frontend Transport; Sat, 3 Jul 2021 11:58:30 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 37ecffac-50f9-4918-5c88-08d93e19e0f7 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2509: 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: ltV4ISAyUXvQStrowe9Gfveuu2ZS6VMU6iyWRmhLbd/WSb1HL2uIagx+WPf9EAlCeY9EY1RQfC3rVN7f/6Iv0VTwpPv9oFwcHP4GY4GYebEPZxeO1oaux3UlNVZwb2jMOeqJWW3PJfXi20psvGtYS8xK2KX14bAadIxs3urE9tFwRE2IYg7ElKuNFAqat8w5Dv/Wam5GUBHs867rsWpbQa7DiFm4zbJmfb7PqtpWMTomK6g07myvndb9JBSPksT9hPXMWrERzrfF+3Z8E73EVMpBSBgpav+V21T3B/RSUS1hG9RGo2tiMstuVvL3Y2xkU/eaucdBxQgnCo6MUi2CzRtTJDx9YHxGp+Jl0rdu6RnCHPmk1aggvYRQ+/M8PGXXf9PN/vjClZ0Q5PFRtQ4OXbNMsP5mMRwuwPf/wt8Jfd6XLxo58g7RWAGmPGXzpRAqYsFKqi9iHZBX+psI+89L1oZrHTJZ8Ey65B6WKi3Bklz4shR7CtmImZ52mngtIg1hNbvScSF4tShmZyEahwqm37bXwRRoHUlMHyRFpUbmNxS4cUzRNRhyN29hg5P1o3eikw9BG2LVFp/X1KEUz0Bb5xsZsnIhv5MjYQZF8VFf0b/3ol6/MYaFFjQEKb8skJrXwDAGcFhmQUtvdKVh1dznogVC7XCCAi2JTnMAut993RAVpQCfTQzaPsx1GCWERJ+P5YI67gLApocSToISiiFIBDlZSU+aLC3tBLiNeQY9CXifc/OoJGp9MQxoIqSkElMA 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)(376002)(366004)(346002)(136003)(39850400004)(6506007)(2906002)(4326008)(36756003)(2616005)(44832011)(956004)(6666004)(478600001)(7416002)(5660300002)(110136005)(66946007)(26005)(52116002)(1076003)(8676002)(8936002)(316002)(54906003)(66476007)(66556008)(6486002)(38100700002)(16526019)(38350700002)(186003)(83380400001)(86362001)(6512007)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HFtd5ZjtlSgO9fNP5RxABZwzh/JdlzFqx9AXkjLTjB57qsmWKS8ffCXi6DpZ07o95g+oL0xDHiggMIHVCqMXIsSiNzxvxExC/MWiQXZu9jsGydKaHYcwiY1HMhuNHeYoduzTpgPTWpOMGXXs15F7X61F2QM2RLxk10dN5RwDV2T8RjM8LUPORWqd1HsTye7Et9DspAjZZe0ry86DPqXNh+bbHP7pfrpewthZb7jQbzJp64uLgUNa5h3xm7WEVe+oYMHpUNoEjFEN4ye2wqVlzpKE41kTIHbm349rr/64eV4JiCr7rLMPe+9b6HmXlGha2WTY4Qi3f14m+u56Xv946ar+Zr/v67POOMt/Rmso5YEUTr+35maMUjlsl7AjUJgaRlIPx0/uIVyAk503zEU0y4EL87zvZzvj9cAV1NK2d+4ez7RKYQZ/chym6wvHT7b+8sa2ZGXu+zcTHDkrcVjBEvduWKuy5qth3tDIC7LonBt4U1xVDUTMAWOTCRWjbNACvjjvBhnkVs9hFqGkZD1/gOmAcyJ1bQTO8qKCyDeuNRfFXTg/H/npOFNEnXrFnJj7JLBe4F04JeJ7sJMeXpB0A05cH+cXhKeOOfMDMZhUb31AGIohpFKMGxrs0X9FKRQldXS1qRhq0z0K0OFG9FwThpmbLRwPXykon4EUQUIr2/M/FiVYzopQQ+aLBF/pE6HB+Jy4A0Zr7R4vHuIrmEUTuu+U7oOL2EYuq/65NwUnVylXvre5q8EX2DGSqNllYZk+RvzuwiGP3pGvgKeepIRJRSGU8pdRTceRemwhgJKrautuHY4mPz2yOF9JaqCHdj+cXMp6FKm6bl7u2IPptvT4THumMJfgdEdkpFS8dubT3eHv+EXX0eFLjAFPF0RBiKGZDH1Mo5VyMs+YQQ2b8tKqKJ/wdAH7u0UeNkTHHd3UOqlSI8BBuQsM5wW1JQiM3hZ7YzLZq37Ncds5W4ufFqr2xOMiKK898lnTMGzrQQ7P4XJ/UJOzm5/jX4I8WzLOyaGvGQ6hvthVBPsE0vXjI+CTX4uj5JsQwCNCKRhO+U4fdk5Cq4AaZt13/UWr84IWWDAf4eTKtdTJf5xKI4sj1PTgldfo9/e/+IP+B3/dau+y3t6rI0kaL230mUtiqkJISmpz4yIhPgqzOGEXdOXJZuTKLmWjlYr4oca7UsGCIjHh86ZPqS0MRE8/FmI8VJySg2q0EcEhDyx40NA2oNjTisasApQ/SJ/lb/Cj8gFnKdO1izN9i7rFzSAdkiSTVBqnnu+hN1vDTkjljVCEa74LLLdSTBgf4GIvUQE7Y71Y4rgwDtTlO2pprzY4Pi5g7FDYdfEG X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 37ecffac-50f9-4918-5c88-08d93e19e0f7 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2021 11:58:32.1086 (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: 3QflPcdBNFKH7saApw93e9E9rmRaEcZrkbHr4W5AdLeS7D2ec5sRAg1Jqv6JHJaCczyrYpJ8RMNWa6T4BQ8mFg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2509 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC From: Tobias Waldekranz Allow switchdevs to forward frames from the CPU in accordance with the bridge configuration in the same way as is done between bridge ports. This means that the bridge will only send a single skb towards one of the ports under the switchdev's control, and expects the driver to deliver the packet to all eligible ports in its domain. Primarily this improves the performance of multicast flows with multiple subscribers, as it allows the hardware to perform the frame replication. The basic flow between the driver and the bridge is as follows: - The switchdev accepts the offload by returning a non-null pointer from .ndo_dfwd_add_station when the port is added to the bridge. - The bridge sends offloadable skbs to one of the ports under the switchdev's control using dev_queue_xmit_accel. - The switchdev notices the offload by checking for a non-NULL "sb_dev" in the core's call to .ndo_select_queue. v1->v2: - convert br_input_skb_cb::fwd_hwdoms to a plain unsigned long - introduce a static key "br_switchdev_fwd_offload_used" to minimize the impact of the newly introduced feature on all the setups which don't have hardware that can make use of it - introduce a check for nbp->flags & BR_FWD_OFFLOAD to optimize cache line access - reorder nbp_switchdev_frame_mark_accel() and br_handle_vlan() in __br_forward() - do not strip VLAN on egress if forwarding offload on VLAN-aware bridge is being used - propagate errors from .ndo_dfwd_add_station() if not EOPNOTSUPP Signed-off-by: Tobias Waldekranz Signed-off-by: Vladimir Oltean --- include/linux/if_bridge.h | 1 + net/bridge/br_forward.c | 18 +++++++- net/bridge/br_private.h | 24 +++++++++++ net/bridge/br_switchdev.c | 87 +++++++++++++++++++++++++++++++++++++-- net/bridge/br_vlan.c | 10 ++++- 5 files changed, 135 insertions(+), 5 deletions(-) diff --git a/include/linux/if_bridge.h b/include/linux/if_bridge.h index b651c5e32a28..a47b86ab7f96 100644 --- a/include/linux/if_bridge.h +++ b/include/linux/if_bridge.h @@ -57,6 +57,7 @@ struct br_ip_list { #define BR_MRP_AWARE BIT(17) #define BR_MRP_LOST_CONT BIT(18) #define BR_MRP_LOST_IN_CONT BIT(19) +#define BR_FWD_OFFLOAD BIT(20) #define BR_DEFAULT_AGEING_TIME (300 * HZ) diff --git a/net/bridge/br_forward.c b/net/bridge/br_forward.c index 07856362538f..919246a2c7eb 100644 --- a/net/bridge/br_forward.c +++ b/net/bridge/br_forward.c @@ -32,6 +32,8 @@ static inline int should_deliver(const struct net_bridge_port *p, int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb) { + struct net_device *sb_dev = NULL; + skb_push(skb, ETH_HLEN); if (!is_skb_forwardable(skb->dev, skb)) goto drop; @@ -48,7 +50,14 @@ int br_dev_queue_push_xmit(struct net *net, struct sock *sk, struct sk_buff *skb skb_set_network_header(skb, depth); } - dev_queue_xmit(skb); + if (br_switchdev_accels_skb(skb)) { + sb_dev = BR_INPUT_SKB_CB(skb)->brdev; + + WARN_ON_ONCE(br_vlan_enabled(sb_dev) && + !skb_vlan_tag_present(skb)); + } + + dev_queue_xmit_accel(skb, sb_dev); return 0; @@ -76,6 +85,11 @@ static void __br_forward(const struct net_bridge_port *to, struct net *net; int br_hook; + /* Mark the skb for forwarding offload early so that br_handle_vlan() + * can know whether to pop the VLAN header on egress or keep it. + */ + nbp_switchdev_frame_mark_accel(to, skb); + vg = nbp_vlan_group_rcu(to); skb = br_handle_vlan(to->br, to, vg, skb); if (!skb) @@ -174,6 +188,8 @@ static struct net_bridge_port *maybe_deliver( if (!should_deliver(p, skb)) return prev; + nbp_switchdev_frame_mark_fwd(p, skb); + if (!prev) goto out; diff --git a/net/bridge/br_private.h b/net/bridge/br_private.h index 9ff09a32e3f8..655212df57f7 100644 --- a/net/bridge/br_private.h +++ b/net/bridge/br_private.h @@ -332,6 +332,7 @@ struct net_bridge_port { #endif #ifdef CONFIG_NET_SWITCHDEV int hwdom; + void *accel_priv; #endif u16 group_fwd_mask; u16 backup_redirected_cnt; @@ -508,7 +509,9 @@ struct br_input_skb_cb { #endif #ifdef CONFIG_NET_SWITCHDEV + u8 fwd_accel:1; int src_hwdom; + unsigned long fwd_hwdoms; #endif }; @@ -1647,6 +1650,12 @@ static inline void br_sysfs_delbr(struct net_device *dev) { return; } /* br_switchdev.c */ #ifdef CONFIG_NET_SWITCHDEV +bool br_switchdev_accels_skb(struct sk_buff *skb); + +void nbp_switchdev_frame_mark_accel(const struct net_bridge_port *p, + struct sk_buff *skb); +void nbp_switchdev_frame_mark_fwd(const struct net_bridge_port *p, + struct sk_buff *skb); 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, @@ -1669,6 +1678,21 @@ static inline void br_switchdev_frame_unmark(struct sk_buff *skb) skb->offload_fwd_mark = 0; } #else +static inline bool br_switchdev_accels_skb(struct sk_buff *skb) +{ + return false; +} + +static inline void nbp_switchdev_frame_mark_accel(const struct net_bridge_port *p, + struct sk_buff *skb) +{ +} + +static inline void nbp_switchdev_frame_mark_fwd(const struct net_bridge_port *p, + struct sk_buff *skb) +{ +} + static inline void nbp_switchdev_frame_mark(const struct net_bridge_port *p, struct sk_buff *skb) { diff --git a/net/bridge/br_switchdev.c b/net/bridge/br_switchdev.c index f3120f13c293..8653d9a540a1 100644 --- a/net/bridge/br_switchdev.c +++ b/net/bridge/br_switchdev.c @@ -8,6 +8,40 @@ #include "br_private.h" +static struct static_key_false br_switchdev_fwd_offload_used; + +static bool nbp_switchdev_can_accel(const struct net_bridge_port *p, + const struct sk_buff *skb) +{ + if (!static_branch_unlikely(&br_switchdev_fwd_offload_used)) + return false; + + return (p->flags & BR_FWD_OFFLOAD) && + (p->hwdom != BR_INPUT_SKB_CB(skb)->src_hwdom); +} + +bool br_switchdev_accels_skb(struct sk_buff *skb) +{ + if (!static_branch_unlikely(&br_switchdev_fwd_offload_used)) + return false; + + return BR_INPUT_SKB_CB(skb)->fwd_accel; +} + +void nbp_switchdev_frame_mark_accel(const struct net_bridge_port *p, + struct sk_buff *skb) +{ + if (nbp_switchdev_can_accel(p, skb)) + BR_INPUT_SKB_CB(skb)->fwd_accel = true; +} + +void nbp_switchdev_frame_mark_fwd(const struct net_bridge_port *p, + struct sk_buff *skb) +{ + if (nbp_switchdev_can_accel(p, skb)) + set_bit(p->hwdom, &BR_INPUT_SKB_CB(skb)->fwd_hwdoms); +} + void nbp_switchdev_frame_mark(const struct net_bridge_port *p, struct sk_buff *skb) { @@ -18,8 +52,10 @@ void nbp_switchdev_frame_mark(const struct net_bridge_port *p, bool nbp_switchdev_allowed_egress(const struct net_bridge_port *p, const struct sk_buff *skb) { - return !skb->offload_fwd_mark || - BR_INPUT_SKB_CB(skb)->src_hwdom != p->hwdom; + struct br_input_skb_cb *cb = BR_INPUT_SKB_CB(skb); + + return !test_bit(p->hwdom, &cb->fwd_hwdoms) && + (!skb->offload_fwd_mark || cb->src_hwdom != p->hwdom); } /* Flags that can be offloaded to hardware */ @@ -125,6 +161,39 @@ int br_switchdev_port_vlan_del(struct net_device *dev, u16 vid) return switchdev_port_obj_del(dev, &v.obj); } +static int nbp_switchdev_fwd_offload_add(struct net_bridge_port *p) +{ + void *priv; + + if (!(p->dev->features & NETIF_F_HW_L2FW_DOFFLOAD)) + return 0; + + priv = p->dev->netdev_ops->ndo_dfwd_add_station(p->dev, p->br->dev); + if (IS_ERR(priv)) { + int err = PTR_ERR(priv); + + return err == -EOPNOTSUPP ? 0 : err; + } + + p->accel_priv = priv; + p->flags |= BR_FWD_OFFLOAD; + static_branch_inc(&br_switchdev_fwd_offload_used); + + return 0; +} + +static void nbp_switchdev_fwd_offload_del(struct net_bridge_port *p) +{ + if (!p->accel_priv) + return; + + p->dev->netdev_ops->ndo_dfwd_del_station(p->dev, p->accel_priv); + + p->accel_priv = NULL; + p->flags &= ~BR_FWD_OFFLOAD; + static_branch_dec(&br_switchdev_fwd_offload_used); +} + static int nbp_switchdev_hwdom_set(struct net_bridge_port *joining) { struct net_bridge *br = joining->br; @@ -176,13 +245,25 @@ int nbp_switchdev_add(struct net_bridge_port *p) return err; } - return nbp_switchdev_hwdom_set(p); + err = nbp_switchdev_hwdom_set(p); + if (err) + return err; + + if (p->hwdom) { + err = nbp_switchdev_fwd_offload_add(p); + if (err) + return err; + } + + return 0; } void nbp_switchdev_del(struct net_bridge_port *p) { ASSERT_RTNL(); + nbp_switchdev_fwd_offload_del(p); + if (p->hwdom) nbp_switchdev_hwdom_put(p); } diff --git a/net/bridge/br_vlan.c b/net/bridge/br_vlan.c index a08e9f193009..bf014efa5851 100644 --- a/net/bridge/br_vlan.c +++ b/net/bridge/br_vlan.c @@ -457,7 +457,15 @@ struct sk_buff *br_handle_vlan(struct net_bridge *br, u64_stats_update_end(&stats->syncp); } - if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED) + /* If the skb will be sent using forwarding offload, the assumption is + * that the switchdev will inject the packet into hardware together + * with the bridge VLAN, so that it can be forwarded according to that + * VLAN. The switchdev should deal with popping the VLAN header in + * hardware on each egress port as appropriate. So only strip the VLAN + * header if forwarding offload is not being used. + */ + if (v->flags & BRIDGE_VLAN_INFO_UNTAGGED && + !br_switchdev_accels_skb(skb)) __vlan_hwaccel_clear_tag(skb); if (p && (p->flags & BR_VLAN_TUNNEL) && From patchwork Sat Jul 3 11:57:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12356973 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 42B7AC07E97 for ; Sat, 3 Jul 2021 11:58:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 25B4561922 for ; Sat, 3 Jul 2021 11:58:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230265AbhGCMBS (ORCPT ); Sat, 3 Jul 2021 08:01:18 -0400 Received: from mail-eopbgr20063.outbound.protection.outlook.com ([40.107.2.63]:47491 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230257AbhGCMBK (ORCPT ); Sat, 3 Jul 2021 08:01:10 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Pjj69hrcgj87/Mh5yJsgomjKQho/d26HOtv/jav43H1H7nNZsculf9tpreVs9A21UyoHyuPWxidFGiU/T277z3uhTu+HWvUrNV1SRTT/rRrehmzXXdtB3nFA6nBZAQ+/K5TxsYzspt4Kcb5FUl2zmJkFOJivHQdQucArekizCIlSgw+wO2XwgjGcFtOkoRtdubnjbOemDRqZ8nmC0E96WerUb8cgxuEe3EqY8+PouiCq7ZK/HNvxe4PnUJeLJhpO7jDkOQ9AOnc+gbP21/tOh+wzyrwfpZfOUni0JNcFlyhezYciYC+vi17yQVJNZcvDLXrIupg5IiWjE/PQo3QfMA== 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=tdrmZRU0Q37EP78FtXBrjURVRoxh9R2XUtsYeAyE8XM=; b=JkHiXBI173Dsp1+sDWXDLr2rXVvljYc7YWqCyG/Zi3appSTClhxpIgm2V/x4IDuTNNtH0cc6FT92GLEqf4+A6ytSZX9YQM5/BBXxVGR/TU3dC0PyDBC7r6JpHnfJBmmteRUyCvXYO5bpXQJgC4ZCdQQt3pfniJIkjp5eqY2SWwONHrdpz9fVWdJCaBBEtMNkEsEcjI1UeFquP9hv2HdgeNST7wXltDIPYJUmZyd0aKaONthGvPTx8B+9veq8v9Zp0lSPFcYPBfFzzp8UFA+26T/Lt2JpuU/m98gfbpo775ZkSOTHOfLMjVDq3MYKRLfBDmVdF/6PIQvgMFUgwfK+uQ== 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=tdrmZRU0Q37EP78FtXBrjURVRoxh9R2XUtsYeAyE8XM=; b=UGHdQghISd2IvCvLLHDKUWCf3tq/Op8H+TK3twnw+TjCwHBEYlwa+Y835DSieZFT2m9dWJ5Cqdqhq5yY00/MXJ+ntU5dx5KJbEyfyxLJ0AjCGIOGmQeBOWK3WJfjb9GM034hBS8y3SUhCQkBjnw1S8jfpZ5Qt7spnTM137Dc6rk= 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 VI1PR0401MB2509.eurprd04.prod.outlook.com (2603:10a6:800:56::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.22; Sat, 3 Jul 2021 11:58:33 +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.4287.031; Sat, 3 Jul 2021 11:58:33 +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, Alexander Duyck Subject: [RFC PATCH v2 net-next 05/10] net: extract helpers for binding a subordinate device to TX queues Date: Sat, 3 Jul 2021 14:57:00 +0300 Message-Id: <20210703115705.1034112-6-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210703115705.1034112-1-vladimir.oltean@nxp.com> References: <20210703115705.1034112-1-vladimir.oltean@nxp.com> X-Originating-IP: [188.26.224.68] X-ClientProxiedBy: PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::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 (188.26.224.68) by PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.23 via Frontend Transport; Sat, 3 Jul 2021 11:58:32 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 68f8265a-71c0-4113-ed45-08d93e19e1d6 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2509: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Wh44hv8aDm2gMTn5HpRk7BwmbhudMOsUrH9Yhx6Q/tq9Vs4h7TNaklRkjJdWs3JMHUaSUor2WuNS6p+MiE7GrGeuj+H0V3MRCOXgb6+cZD5Q/m0Xu5seexKVfr/6JFgOVAhpxO8WnrviqUSu4ccmS13vcyJyHZ84PfvY56v2BtGd8B1eHYKycU7p3y0deEWg79KnYbFtXEpUZTq9mdOorUA+mgFzTARaO3WZruuK6wamvLyuimoo9GKOPN5ypSOSoKdNtYrzATyHxxr5j4sspmmenFbBYN7fqlkOPzZ5kyIwOnAb36YzfMdFm2vUhv7XYEJkwOuqao9niGFoM1MD6sm5XxO7FSAgER+rFIbqkhizQgN+HnUgXqJri6O78ubr3FiUmG8kPxc5/l/MPCNlbNQoPgnJ4SfqWk78J28Hh8trdvkiWAY8w3EQc4hYRibiuZqHY6TkpRPQHk6nsvHdr176jwBDaDscVjEzZYVWZrNkfsmt9XpvjqQFjboZiyoR8i3W+ZUxlbKT/0q12Fe4hRkH56Jyq1u/gctuPTZqCr9dKKlmSxz9iTlEhg7Zw5Fzre6NZyoaCdzO6Qraz2UKktwogrs7stSrlGXvtZkYjBIh4auJhCbWksIrT3tWV+lnpv0r5L8AcU5cHa/qKvC1QivbpWttnR0HH1bhMsLXuWXWbgo8KZEZiedBNxrT5Ejiq+Go2QKCev/BypobXtV4DZq5D4Ux3iyyH5MokYaKaow6hdhYZpC2M/WgXHoJ9FWG 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)(376002)(366004)(346002)(136003)(39850400004)(6506007)(2906002)(4326008)(36756003)(2616005)(44832011)(956004)(6666004)(478600001)(7416002)(5660300002)(110136005)(66946007)(26005)(52116002)(1076003)(8676002)(8936002)(316002)(54906003)(66476007)(66556008)(6486002)(38100700002)(16526019)(38350700002)(186003)(83380400001)(86362001)(6512007)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 38GSF9kvT0iL88mkp0qzoWe7slaIGte2RLozogRF8EFBaf4+54FdIzOWoUNegGN+N/+rupuguRTC/yqFFvA4frr1JVGse78+iHrP9kVrEVroJy3hJNeozMh6LatAYD9QoZUAiCmdNbBh8wmIGpmgnfy96DncmhU43MfxKP9z+EA6wh6x5LTcV2y7ZbX1qjeeaBXLj98+NBdgsn0Pke5XMClAXeIRdMkov90dUzxBdhJSMWd2MRP1Xe27zgtdVVBYOwnCQ0pUxFEDOFmY0rmaADi7FPDwvccmdoQ/cKJxh9cURcw08cL0kpRDyGcisV2y4WCfdSKySATYX2m+iDRVMcCMQPRHe9BSed/EKzcTmpQrM0Ta2pq+uLwGWfIukIiCpLJIxEXq9W96/eJ5//96Xt1E6ePGwgD1JU27KUE8LgQB1/F8oV464BmwhQu76Cv5K8g1vP6cl1zOwXjT2Vu8zA3aV4HORtDh7uzhJ59rkunZEX994jCbi3pKytPuqrRY9WE/7FW8RSf5Ao1ysByoqN4rP7eO7INiOcmPfpxULaALUdScEBDtDBkvOJfKVcECSgPPKL5T+yWcr+gORuudRvJRjdxR+4bZ2EzzxkiYMP+NtkVX5bL8XD9L4tx8rPtDLHuMEQXxIe3scV66Lx5yrHZ8/tW17ye1xPH79nP6DUzMsPO6+jx2laGYQGJdt6hcT4vdcSsQLa/eIuOSw8TKez0suVCPpSFkAihqFcj3OWh/u9rt7tiTXfrhcQpcE4mo3L7TjQOjPP3xPvKUI9doH1kXeDgE9Iztj7CR1bizqbIfX1K/NGHsU7AMG7zXZOEJVWtU3djjgTA8KeUIjIU421G9vipyX/pjsBYMTv2xdn1LNOTHQGeJBn4Ya/hO724T4incLUUXMPdHo+G/NuJsYvg0D9JAxGi1e0aaLgi0VIqJ+o05vWSJBTKxUjIjYUbAp9QXWJeK7xdmScEWU1yjUM5rD1hHqY3imjo/3AQXdLU7cnsYd2b80nErTd+PpB3R5fVxtoyxiKcpaHtqpH6IWj4jhN9IT2eIlnNcrKIOTfpP4MuCaVIJ9XkYugMP6o01CJbqSKSdMD964Gtzj2y/900WhsBzrDTA3slAzWVDpty6ksBw+34+5zX5NGdhMYCk67yHwoC6t+B77r5y4C9s3KlxnA6ZAFXQUSf9CDgE8iDGC5RuJ1PRTptbMiqMEbXLj7JGLaChl1HKJev7VXTCFPplfmyEKD3sPyGWkPRrQlfoBMC03k4tD7M1dj+jd1M37kUcl5TevjmEmbjWyWTFic9RZKmpdP61DgRqezKtlqDQXoTK/nf4VZJsSCVy5J76 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 68f8265a-71c0-4113-ed45-08d93e19e1d6 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2021 11:58:33.5438 (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: IYvNMaogPc+CwWUm2VD6OqhyheNUw2cFuJPHKfWy+JXT6wFQje5werwFelDc9ukgWtL0Xw1LZ18HEH0wurWeXw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2509 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC Currently, the acceleration scheme for offloading the data plane of upper devices to hardware is geared towards a single topology: that of macvlan interfaces, where there is a lower interface with many uppers. We would like to use the same acceleration framework for the bridge data plane, but there we have a single upper interface with many lowers. This matters because commit ffcfe25bb50f ("net: Add support for subordinate device traffic classes") has pulled some logic out of ixgbe_select_queue() and moved it into net/core/dev.c as if it was generic enough to do so. In particular, it created a scheme where: - ixgbe calls netdev_set_sb_channel() on the macvlan interface, which changes the macvlan's dev->num_tc to a negative value (-channel). The value itself is not used anywhere in any relevant manner, it only matters that it's negative, because: - when ixgbe calls netdev_bind_sb_channel_queue(), the macvlan is checked for being configured as a subordinate channel (its num_tc must be smaller than zero) and its tc_to_txq guts are being scavenged to hold what ixgbe puts in it (for each traffic class, a mapping is recorded towards an ixgbe TX ring dedicated to that macvlan). This is safe because "we can pretty much guarantee that the tc_to_txq mappings and XPS maps for the upper device are unused". - when a packet is to be transmitted on the ixgbe interface on behalf of a macvlan upper and a TX queue is to be selected, netdev_pick_tx() -> skb_tx_hash() looks at the tc_to_txq array of the macvlan sb_dev, which was populated by ixgbe. The packet reaches the dedicated TX ring. Fun, but netdev hierarchies with one upper and many lowers cannot do this, because if multiple lowers tried to lay their eggs into the same tc_to_txq array of the same upper, they would have to coordinate somehow. So it doesn't quite work. But nonetheless, to make sure of the subordinate device concept, we need access to the sb_dev in the ndo_start_xmit() method, and the only place we can retrieve it from is: netdev_get_tx_queue(dev, skb_get_queue_mapping(skb))->sb_dev So we need that pointer populated and not much else. Refactor the code which assigns the subordinate device pointer per lower interface TX queue into a dedicated set of helpers and export it. Signed-off-by: Vladimir Oltean --- include/linux/netdevice.h | 7 +++++++ net/core/dev.c | 31 +++++++++++++++++++++++-------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index eaf5bb008aa9..16c88e416693 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -2301,6 +2301,13 @@ static inline void net_prefetchw(void *p) #endif } +void netdev_bind_tx_queues_to_sb_dev(struct net_device *dev, + struct net_device *sb_dev, + u16 count, u16 offset); + +void netdev_unbind_tx_queues_from_sb_dev(struct net_device *dev, + struct net_device *sb_dev); + void netdev_unbind_sb_channel(struct net_device *dev, struct net_device *sb_dev); int netdev_bind_sb_channel_queue(struct net_device *dev, diff --git a/net/core/dev.c b/net/core/dev.c index c253c2aafe97..02e3a6941381 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -2957,21 +2957,37 @@ int netdev_set_num_tc(struct net_device *dev, u8 num_tc) } EXPORT_SYMBOL(netdev_set_num_tc); -void netdev_unbind_sb_channel(struct net_device *dev, - struct net_device *sb_dev) +void netdev_bind_tx_queues_to_sb_dev(struct net_device *dev, + struct net_device *sb_dev, + u16 count, u16 offset) +{ + while (count--) + netdev_get_tx_queue(dev, count + offset)->sb_dev = sb_dev; +} +EXPORT_SYMBOL_GPL(netdev_bind_tx_queues_to_sb_dev); + +void netdev_unbind_tx_queues_from_sb_dev(struct net_device *dev, + struct net_device *sb_dev) { struct netdev_queue *txq = &dev->_tx[dev->num_tx_queues]; + while (txq-- != &dev->_tx[0]) { + if (txq->sb_dev == sb_dev) + txq->sb_dev = NULL; + } +} +EXPORT_SYMBOL_GPL(netdev_unbind_tx_queues_from_sb_dev); + +void netdev_unbind_sb_channel(struct net_device *dev, + struct net_device *sb_dev) +{ #ifdef CONFIG_XPS netif_reset_xps_queues_gt(sb_dev, 0); #endif memset(sb_dev->tc_to_txq, 0, sizeof(sb_dev->tc_to_txq)); memset(sb_dev->prio_tc_map, 0, sizeof(sb_dev->prio_tc_map)); - while (txq-- != &dev->_tx[0]) { - if (txq->sb_dev == sb_dev) - txq->sb_dev = NULL; - } + netdev_unbind_tx_queues_from_sb_dev(dev, sb_dev); } EXPORT_SYMBOL(netdev_unbind_sb_channel); @@ -2994,8 +3010,7 @@ int netdev_bind_sb_channel_queue(struct net_device *dev, /* Provide a way for Tx queue to find the tc_to_txq map or * XPS map for itself. */ - while (count--) - netdev_get_tx_queue(dev, count + offset)->sb_dev = sb_dev; + netdev_bind_tx_queues_to_sb_dev(dev, sb_dev, count, offset); return 0; } From patchwork Sat Jul 3 11:57:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12356975 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B60A4C07E99 for ; Sat, 3 Jul 2021 11:58:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C2BA61922 for ; Sat, 3 Jul 2021 11:58:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230330AbhGCMBT (ORCPT ); Sat, 3 Jul 2021 08:01:19 -0400 Received: from mail-eopbgr20063.outbound.protection.outlook.com ([40.107.2.63]:47491 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230259AbhGCMBL (ORCPT ); Sat, 3 Jul 2021 08:01:11 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=U6de2vP6yirytl024TVOVRTiSIripxEEeLveGmdrQX4ikEUKwgEJaZaxhZZGz4P7/kuiJicKYfOoXMhZh4OJp+xqdduzJQI46qQSJKGiqQ75iCsjhnMXUDXK6cQZ48WQniHJXi1WtjC0wdbHyhIwBreIYx3KYfLPhszA95ZVhe6/At7Q5ESCyEyZtbiMeYN6BhsbHO2Qy7jKkLlLsPl7GTsuvdXV8Bcn7YE1ztrrhKRbCPdFW423t59xKN/rX3BWQIyeHbn7N4wE1TkjaMoW83mawHlDDb0f8tskv4XG5zr3pFlhHDt27mGDHrdNRVBbq0e1xJ3PfenhTS1sLrX2qA== 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=sm1suUrRTUxN1sONyMB0D5Ren6HKrOyLt+PgKB8cvag=; b=lRt6TQmNFMa7HgD1PqgFeuR3O+XvRs7r5ziukwRaN6ky2m4S4fBHUdmsrChtCA0QJGZ+VNRGnFFbRfefFAvYtdpkOp24Qnzx4pJJSZ2swtSI3KWVspdD7pC0GmpvhHMk17UUGgaHU5p19bCmk4/YufmAgu4itakbZLUrCEstgkqFWInVHerUNA5M4e9rw8eLeQfR2Bt9+ttgpiHTjK4itz6i7E/xKYaRl2yeMO4+L7Gpbdvv/SAvDy2/PEiDDZ5iWqGTwgrGU+bpo+D4QoGC6YfHk4I2N+WKlp8iUURm0kc0af1wZfDIjLzHVT6A1VIdYCKncM9Rehf2wcEv0AeLkQ== 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=sm1suUrRTUxN1sONyMB0D5Ren6HKrOyLt+PgKB8cvag=; b=ciUe7vBXnBuXNX8XgFbFxdjeVRn5EwFa8aMZ/9nJP5+6PuMWIIreDUbjgB9kC3Rm/5StM0r/Eyb9y97v5uFbR9n9e/DvomSQvqBl9QmH/6KUB+rp0OSEQ34ZSheftnTchmS3DhRMqwN604bH8h41KXAedfDPhuMYh6w/qpMpOYE= 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 VI1PR0401MB2509.eurprd04.prod.outlook.com (2603:10a6:800:56::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.22; Sat, 3 Jul 2021 11:58:35 +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.4287.031; Sat, 3 Jul 2021 11:58:35 +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, Alexander Duyck Subject: [RFC PATCH v2 net-next 06/10] net: allow ndo_select_queue to go beyond dev->num_real_tx_queues Date: Sat, 3 Jul 2021 14:57:01 +0300 Message-Id: <20210703115705.1034112-7-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210703115705.1034112-1-vladimir.oltean@nxp.com> References: <20210703115705.1034112-1-vladimir.oltean@nxp.com> X-Originating-IP: [188.26.224.68] X-ClientProxiedBy: PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::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 (188.26.224.68) by PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.23 via Frontend Transport; Sat, 3 Jul 2021 11:58:33 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 701a467f-8dd5-493b-827b-08d93e19e2b4 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2509: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5516; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oqFYBV7Wr43rpuidzpq1oRXOtqlkHEpMt3PRXtGN1VQWZ4Hek4naAPJKQP7yNchoepWZ5mDkVGnaXve8jn6b9oexpO9HZkUFh0npwety7EtpAjs401+Zdand3Hbzifq4ptMSLta3ZGYKf54GsYYzbKRK7bo+YiRR2q02zWNt7nnHC1AZ4LluHBJF0Mo2M+3F71xlNx1KtWIZwNRT5DIvla7GgSoV4tbJHl9sqTJFCmEvOvPPxirvh29mb1oGx3xmpHC/P99vNvS4A6ypirU4W9l8CIe+4LKI2fqV4o9oiyfoGsGBxZiBdZbGF2ZJaX3T8XAdtBnuOfEpi1UeIaC7W8R7VtmoQTA+IYpaVnPSMQoY6vZHph4qZGxrKDKYAVj69hFrShkK08wkVtdaA3cAkmiF9guCIGXvcv7ec7NPAKUmFkrI8iFzJoNp/tmDDGS4fDK/rdxS/VjLKubJAY+/4mpDXGU+axkyLQPdaoRJN1s7fkEb/MePNoxgVb6MeAZMxlNdYSD8p/aJtdjQlr37zFMLXkm+Pa5iPi2tFQWVGnL4PU998ngIy9wxlsBeRHkblGYJT/6yOrUR7MBj4TIFelZknj2SApcYwkRFA0Bs6IaTPY0Vp1D/klTm0L+HZmE76gJ4VW+ObKdoY+PfmUJn6gLfZomM37lEzmjyaHW2ZE1x2hyiwifVAbArpKTcZ4fSMSfhHNlhX0Mk2x+PP0ZINSdTlVqgme3ZyxvTxJggsGWDbAnUtHahuhl30+2YF5td 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)(376002)(366004)(346002)(136003)(39850400004)(6506007)(2906002)(4326008)(36756003)(2616005)(44832011)(956004)(6666004)(478600001)(7416002)(5660300002)(110136005)(66946007)(26005)(52116002)(1076003)(8676002)(8936002)(316002)(54906003)(66476007)(66556008)(6486002)(38100700002)(16526019)(38350700002)(186003)(83380400001)(86362001)(6512007)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1FMVbIKn6hAwdxzHvOOQaRv0zS6rcFdIcyCu3wwWfTtqHofIVCz27/ogizRYm/ivS7fjC1kGaCCG1sFtRGM9mSXbOzsHpN3XJ2j7LiVATizA/hoGnNUFs5gQwtTamg6XcxVkYmq/+fdwqSN5h/OEZ3lLI71O3su/IGWh16dId8lvDQwlt1WN6paVpi2GbsBOUeLyYxgCBeRK1bsoCO7huGbLV69/JOC8Uur/KaG6hocq1I0Hmj/GZKFX49ZhdDtZXQRzsYvjMyRFysU+X3oyMIoXYRzV4nfUxdt9t8aM5hoT6XzvBAjSPkaOZNUer2CFOpZzFNMbjqPXRWcEqqEh2Dm8IHbr3p8XkWWJQ6CUhgBWRO30Wfd1jhaiGlgVGcNqzvPmd47DwB5o2hfJo6+3xrtKKtsHVPqTq+v2rTWg58NEMe1WNGSUgEbFtktGbMQ+Lw/2yicvUWuv7Eilt7RMi24+FhtiYm8h8XJ2BKU+rNCWPAUszfDggO74EMMqdaMJEYQjYXD2kZnmLP9SUQ7/fsHMuljcr4YU1hGda/Okgjekpa0iJbLpLCzr18OgyHDq7iC/5Hki2AWIQfcB5IO8x9NDh6HYFcGPoMuG5apukcvM/jeH9LEdG3PrDcFUgWUfFS9sl6HG1C9qcAylxpNPFpusJPjKTAL4R7168478Nq9N7sE3bUuX3h1MTSP9Y2/GiZcJzq62C7DIPaWmylBodchc9/sL6YP7p6AhjXrC2dduVHcGF4oaPBE3RHnf7+5gBAyscBEKcPstiIANP4Toz3eYehqcf+sxJey3qk8CD9xLk6bWD2YSdIx5a6Av2TOutxyUB/BrSCY8ak53o16v2vPOA4XsfxaXWimqmsofCzGS/rBPGe0WpbHUFX7yrUeTDEGk6YZUUsdmjgaBe+jha+/4JRZ/dhUejsBnJ4CjVcbGmdtfGwST4JCeRBjVuYsJtoqxFGd1rCHtgEtQpx59QrJi89I4Qn7rc5EPcfQpwIoHKyPg1GFaomwaMgnVrlvFMht1Ctbb/NgH8bFAi92UZZW9jcx7CFG2E2l8cqqGvGdTLjNMau3rMgLUx7LLmIbg2BhYNLkwu34uLh6dRivWV54IwWV5A2Vs/IsrVJ/hU63z6M95nlQizCHXMB+aAHVocQDVvPkmj6y4iMGiaaLsy/qHMQE2H0NvZA76xQHL+gWAfzEcikxKXVP4kEvtSqgVc6a2vNjRAd0eX1tCgHU+9ia+DqPpP345hVJb6NtOpYuDpJ9X4Wm72zqJy33vBp5VjfSvOPI4V8UreWvZl1TO+TQHJVvG5NJ7CtULfX36K6DfR7IJ844rRFuljhul8olY X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 701a467f-8dd5-493b-827b-08d93e19e2b4 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2021 11:58:35.0419 (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: CltoVNiseAva5MfMv5GhTTDkoENMfiwV6ou8FLf4097JITjcY7FTkThwV1OlLb1gWuvgcf4IExAPtfml+swQ3g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2509 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC When using a bridge upper as a subordinate device, switchdev interfaces must allocate a TX queue for it, in order to have the information needed in .ndo_start_xmit() whether the skb comes from the bridge or not. The dedicated TX queue has the ->sb_dev pointer pointing to the bridge device, and the only assumption that can be made is that any skb on that queue must be coming from the bridge. So no other skbs can be sent on that. The default netdev_pick_tx() -> skb_tx_hash() policy hashes between TX queues of the same priority. To make the scheme work, switchdev drivers offloading a bridge need to implement their own .ndo_select_queue() which selects the dedicated TX queue for packets coming from the sb_dev, and lets netdev_pick_tx() choose from the rest of the TX queues for the rest. The implication is that the dedicated TX queue for the sb_dev must be outside of the dev->num_real_tx_queues range, because otherwise, netdev_pick_tx() might choose that TX queue for packets which aren't actually coming from our sb_dev and therefore the assumption made in the driver's .ndo_start_xmit() would be wrong. This patch lifts the restriction in netdev_core_pick_tx() which says that the dedicated TX queue for the sb_dev cannot be larger than the num_real_tx_queues. With this, netdev_pick_tx() can safely pick between the non-dedicated TX queues. Signed-off-by: Vladimir Oltean --- include/linux/netdevice.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 16c88e416693..d43f6ddd12a1 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3697,10 +3697,10 @@ static inline void netdev_reset_queue(struct net_device *dev_queue) */ static inline u16 netdev_cap_txqueue(struct net_device *dev, u16 queue_index) { - if (unlikely(queue_index >= dev->real_num_tx_queues)) { - net_warn_ratelimited("%s selects TX queue %d, but real number of TX queues is %d\n", + if (unlikely(queue_index >= dev->num_tx_queues)) { + net_warn_ratelimited("%s selects TX queue %d, but number of TX queues is %d\n", dev->name, queue_index, - dev->real_num_tx_queues); + dev->num_tx_queues); return 0; } From patchwork Sat Jul 3 11:57:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12356977 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91DB0C07E98 for ; Sat, 3 Jul 2021 11:58:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7CA1F61922 for ; Sat, 3 Jul 2021 11:58:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230344AbhGCMBU (ORCPT ); Sat, 3 Jul 2021 08:01:20 -0400 Received: from mail-eopbgr20063.outbound.protection.outlook.com ([40.107.2.63]:47491 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230266AbhGCMBM (ORCPT ); Sat, 3 Jul 2021 08:01:12 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PkpQZpCZR0z+ipHKxL60nv5krq25SMuT/S+kh0RV0RayH9D2Qf3l2mPj2O6q7WPdwM70F5b+pwaRTsoKd+m79ATTg+7QAdvFcS3+v3UJguW/3rXLhDR/HUvFz2HYde9p4yTy28pTfShb3aFyBGe8eKIKnoYOhMdIVJcaZcryx15fHSM9rRejt++85uE91Eag60plUhSA9sp1fToPdW8bB70N3JC+SjCo/bd6MVlVoCd1LugHBTatwXplE7irI2EraivjVgx3jMD6P/2LEl3j1kzw/u7zCEe27G+FMpruzuGpP15zdDok7u+BVCizddVa0kne16JO2B/OUE6ZOh3CIw== 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=YcXpR57JCcAMQ9q/jdIeT5Ev/nTHUqZD/rJq1Q8j8q4=; b=azy0ccum6fhBGBPV1ammHjcuP5FFDs6bK7CN+eoHv+TLdKgJDNNVndbHxnbnLyOt85HR95BAtbKf3+/95Ay4UCgO2+IAlbs5xio5N0nxT27tFPeD1wWTOcApGNRhd1Ik4jeFwXTFLNM46H1lz5AnL/DDAh+EoBTHCmFnuwUdbrrlNs86J0JEJ02kmL7QDxdAJcm+0Wfiqu2PrI+HKvc7MjyfT3FhkfGNrTVJ3ub8cLACwEOJdZEnmLOJ5dJpyGwKWyVqJrtwpOLEqSbAF6kL9F2P9vFkb+qQeveDgMmkiw6EKsjQH2/njSohBPwCExUv/2VhsS4yLV6M88weyAZI0Q== 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=YcXpR57JCcAMQ9q/jdIeT5Ev/nTHUqZD/rJq1Q8j8q4=; b=XCRHziJTV6C4CGUooEYbkpDGkLegU80mRJYA0pwF8df78TIh/UkpjaVzTbJYeM9rP6F2MODRmMvpl+2N5wnLT1fQsqBc+kbl//P4eu36f8VE7GsYdl4WIDL53lTaALHG81cSJnb2QM+OGNrh8kr1KXsdUKUb1UUG8UHmYVsz0j0= 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 VI1PR0401MB2509.eurprd04.prod.outlook.com (2603:10a6:800:56::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.22; Sat, 3 Jul 2021 11:58:36 +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.4287.031; Sat, 3 Jul 2021 11:58:36 +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, Alexander Duyck Subject: [RFC PATCH v2 net-next 07/10] net: dsa: track the number of switches in a tree Date: Sat, 3 Jul 2021 14:57:02 +0300 Message-Id: <20210703115705.1034112-8-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210703115705.1034112-1-vladimir.oltean@nxp.com> References: <20210703115705.1034112-1-vladimir.oltean@nxp.com> X-Originating-IP: [188.26.224.68] X-ClientProxiedBy: PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::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 (188.26.224.68) by PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.23 via Frontend Transport; Sat, 3 Jul 2021 11:58:35 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f897eaae-f91c-4fe3-fd81-08d93e19e394 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2509: 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: TDqJ8j0J44HJZUgWvPaiVNCG/prgbniCzl78r5sUovlQgfVwolp5pwGnDSHPbVkGpdm3pMLDETl9oEC1j52pZI7n0qjKw8rFJkKZK4Lwbf729QYBri/s6QpIHPxGIjaKahXhX3hdmaE9FwjmFhNHuBzv76onJ4nF3Wm3dwtjSjGH11cYxZfg9xnxsZQVJmLiL2UAovrthvpvFuDoK3FwMCR0Xw2qkLxS/IencfRtEQanULh6CR6sm+eGjQb1qc/vhAJZTgw9Z2DNs2vtAWVit/DOjbnbPI39zjHi4hXkdXFRehJrdvKP8GmNHymF0PsVHRFYRQjyW/OgMfdjLHxFRrnReHSSxhpfIc2MKv4lhRHFdMhyb2ftgQcxnUFcJ6ScAScF6bDDIYO1K8Nk4K9avthI3DNxOXH0hPXrrk46cWSKx2wuLkSpeypoEKqGItBJ21d1a1q3wcf2xE/EskT+q2pw9NVtLDcijUx9Vi0rf2f99Tsgd+y4ZvR76dhbAlIWDBpHr73+Dcn9EA3Jr4nmu49gFV0zpisj5GaCkKudGP46+PnyW4OP16nVu1rqGmmrjK/Qi6AzcCmQLYC1MBo0hBmSGbzPVAbqsJrX5jWFkMKaXgWMbBlR4iW3ntIquGORIPuHFBSae8d4PRn6SHWzCa7/z1X6gqeCjAFFSUNyaz5XvgWJFo04Hs3LaCskhzOfCjtjme9/ugSVC72Laal7UvOmKS0Vd+fht92W8bGwqf9dsPtuBFGk4Y+iDLXFeD32 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)(376002)(366004)(346002)(136003)(39850400004)(6506007)(2906002)(4326008)(36756003)(2616005)(44832011)(956004)(6666004)(478600001)(7416002)(5660300002)(110136005)(66946007)(26005)(52116002)(1076003)(8676002)(8936002)(316002)(54906003)(66476007)(66556008)(6486002)(38100700002)(16526019)(38350700002)(186003)(86362001)(6512007)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 8DZtsF5x8gTQ6dQd6F3pokVcNI11ln//0hpzIW7NMfVD4Rsa/FSKAGGtfdu1ECpu1v1f0iS3mKrE2V2qcfSzNn02HEQzQW2VwThU4tbfFi9UzuR4smkug17sLNFY8+ffcdDHuTAZD5B6Ri2DyE5JMUnvvgJAaEDhNc3kYIOk6ftNzCpqYQ9Dl7boWzmfdRhqWvTuvy6KuVSfgLmDLY4NMnuGuBtpBSvtXryO4GuXg0oA5YQTg9/S5lenx3ItBGXRSjqiFnSzdoWHwutJeorM9WFit6GkcLpBX4180KM7hBsNz+FzvXK29atr6ajXFpd3VbUtN2WH8Zr4Di7BFsTh5HZhAXeLN13RZ5PWQdkenXh9QOq2MNzKa94VyjESOY3N+IPpcuXN2SYmcTmMXfo5799GQI9NvL4ViuqhC/FG5ZOqIfdTooFSODQqrDWNDd4XHwwQVfva5VLPSPYLiFQqhlFM7v4NgOKyCbw/YikOCZlH4Zy7B1X68MBvf2hAkW9nKxaCGAdbEFPb/dARSCFHXVVSkbSA7MMISBa9DB2iHD9AMM8Nu6aawfk6HRPpck+PYH0AYNEZZsL3wEWdqsYme+/5yPI/KuM6Yapsfmarr7yxuiQ7CLG/q8cK6+hfooeDi9xndB6MBhodN0AQHi0qKrr/m1HxU0+ycHDZMuSGU1bOjflnsvljXIR1vgcFIhQaSeVHGTQPHIeMHahr2HXPwzUkfTTZgTxTYeXoIaYUIuFmsjwOGgxWOVOz9uyMXYm0v1RiKj65EsN4+FFagSD1Mo1cNLNRRVwky0yDHzSXirg92pDxQ04rMnzHL97OhhoH+VFZcXEookePC/3Ve1bs96Xe/k7KgWpnTFqePR+9UL4H2ETdZMPOtyAdR5WxyveerSczVJYPbKgMeBvLtx0ISkmoS5XOMWPQpV7Jdt8KoxPJEklKxV82fHfb8HoSdAjNptqFyF6aZsApyxM54B5OLtjzu5k6xTFXFZv9SfXLwaDqqSydQWeAVolbXCeSIXi/Ywas7195SeKckgpMxqKTvsiWi7uPP6BpBMNrAScw6T3kCVVj/K6fADhJhTD9LTLH7qUs4a3sQ6DCeQtALUgHEqOhehzcqcCSCGBvDiWy0Uogy3R0pGYRopBgyyooExwsxBy2j2jafJBpDg4Cc80AN5+vWfVRLSCRVUiLVO6nRCedg2XyQZaLYpZ0EsLIWYrq/QajcL5kdenwLHLWxx4NhWMAWiM2/INCqnN+TyKZ7ONU3U3AqoKZl0ovYH+RVOPGYxG5MIqc4NWxyk72YgLLEZb55Qr4emaFqw0S6SDEBeBTY46OUpm5dG0dwNM3JvI3 X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f897eaae-f91c-4fe3-fd81-08d93e19e394 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2021 11:58:36.4671 (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: qK6WUS2u1q10xnmoq8MffBGP8E/nrm6NdqK1E5beCMbFFSDITTVojIsnGrxo75wQUKHHTchKfFZpHUorT8lbJA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2509 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC In preparation of supporting data plane forwarding on behalf of a software bridge, some drivers might need to view bridges as virtual switches behind the CPU port in a cross-chip topology. Give them some help and let them know how many physical switches there are in the tree, so that they can count the virtual switches starting from that number on. Note that the first dsa_switch_ops method where this information is reliably available is .setup(). This is because of how DSA works: in a tree with 3 switches, each calling dsa_register_switch(), the first 2 will advance until dsa_tree_setup() -> dsa_tree_setup_routing_table() and exit with error code 0 because the topology is not complete. Since probing is parallel at this point, one switch does not know about the existence of the other. Then the third switch comes, and for it, dsa_tree_setup_routing_table() returns complete = true. This switch goes ahead and calls dsa_tree_setup_switches() for everybody else, calling their .setup() methods too. This acts as the synchronization point. Signed-off-by: Vladimir Oltean --- include/net/dsa.h | 3 +++ net/dsa/dsa2.c | 3 +++ 2 files changed, 6 insertions(+) diff --git a/include/net/dsa.h b/include/net/dsa.h index 33f40c1ec379..89626eab92b9 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -159,6 +159,9 @@ struct dsa_switch_tree { */ struct net_device **lags; unsigned int lags_len; + + /* Track the largest switch index within a tree */ + unsigned int last_switch; }; #define dsa_lags_foreach_id(_id, _dst) \ diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index 185629f27f80..de5e93ba2a9d 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -1265,6 +1265,9 @@ static int dsa_switch_parse_member_of(struct dsa_switch *ds, return -EEXIST; } + if (ds->dst->last_switch < ds->index) + ds->dst->last_switch = ds->index; + return 0; } From patchwork Sat Jul 3 11:57:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12356979 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E692FC07E99 for ; Sat, 3 Jul 2021 11:58:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BBECD61416 for ; Sat, 3 Jul 2021 11:58:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230358AbhGCMBW (ORCPT ); Sat, 3 Jul 2021 08:01:22 -0400 Received: from mail-eopbgr20063.outbound.protection.outlook.com ([40.107.2.63]:47491 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230273AbhGCMBN (ORCPT ); Sat, 3 Jul 2021 08:01:13 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZpD7iM5t4QYaQyshxieUk8GwW1fu7f8va2FRgwn+RTpx6L9SMFHphFdMaNrYpKHegB+3NDLplt5L2ovCRJwOEnYw23bWeSLSiGafMfzS8U75pTxMuoSxYkAp2accGU/HDiCyGdB2xIyuq0Jh+HPFePzXeAL86eHuC9SbKOpWe/qrnmGCkRzIIyw/mwrY6t9b73pEbxpuXs1JOQV+7CGnnR9oO7Ug4i6m13O2r5Vj/xTO0jzrYDqilogT9yUbmox652Yn7HE5Z4fyE6CPaNrJHsAIY7VFEkZtVgOBk4hcYOsiLHPjveBzIDuKGEoiar72Bh4bZPK7PB+O94rHJsGrVg== 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=vD52k5CHDZVcs9/FaEqP8gNttkNWEcNmP7+01jQIHwc=; b=fIzuiFRvS3WBbvLbZsgB9SA/CoDMLepIZe5tozZ49MHQMjFS40rjlsd+jpAdNhyyPKyMIJgzqSvuMO9eSoPIGH/vU8X4bBMShumy/mlacGdj9zVziC1FCHmf7ZuFYjGo33zvPKW5j3+T0fN6qK3J36IipWwsnkgIiexjhFWM2FFnNthIO7J7zU9rETm3jSos7XvZGYzZb7QiYZQwD1Tw6rNT1tFXqJrg3gBaiTIKqT1osQbKe/MvEJZ2hGYqrBjL69MzfRNznrGuKo1gsB8xsCJ61f8T9PoL1xwSkhoydevYA2iwIl4B9SDrN8lFjHfiBwiLv1YT6uDVAVVecC+e5g== 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=vD52k5CHDZVcs9/FaEqP8gNttkNWEcNmP7+01jQIHwc=; b=K6Kop54/Dk4OjO5y5Cb+b7/cFxyIBJ59AQ1SxrpfWPIlGpEr8zlssfwyjwqmN8rJCpAzJDs7xi4PvWayH1CvOLamcO8AvY5Fd6FVKBrvGAIWq0UJsqmsfUsyTfEiShSzOqPw/p2aZy/VwUvLIbdudjiGMGt2nmzjhMWSF7BhBoI= 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 VI1PR0401MB2509.eurprd04.prod.outlook.com (2603:10a6:800:56::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.22; Sat, 3 Jul 2021 11:58: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.4287.031; Sat, 3 Jul 2021 11:58: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, Alexander Duyck Subject: [RFC PATCH v2 net-next 08/10] net: dsa: add support for bridge forwarding offload Date: Sat, 3 Jul 2021 14:57:03 +0300 Message-Id: <20210703115705.1034112-9-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210703115705.1034112-1-vladimir.oltean@nxp.com> References: <20210703115705.1034112-1-vladimir.oltean@nxp.com> X-Originating-IP: [188.26.224.68] X-ClientProxiedBy: PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::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 (188.26.224.68) by PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.23 via Frontend Transport; Sat, 3 Jul 2021 11:58:36 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f975c4e0-1a0a-4f94-8a62-08d93e19e46d X-MS-TrafficTypeDiagnostic: VI1PR0401MB2509: 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: SEIkZ2uw4ZYva3Huy9W8hnasd4Eeiq8r8zV4UHK333Sv+8SBaBHViEVd1SCQckJS7TA/Rx1l4e1D9HlNRUYmArtxqb1XQZX411Tj8o2wn9/fjjKYxWxP+d7oTUo8GD5JNtI6of521NMZgizT3bg8lCzI89wiFCfhQOiRUhxvmIDESx51XTe1Qhagf+JJfnCDo7UgBO5KK38nBbuxlQIEgz9tdU4ohWFFRl0r1Ofd2Fn8W9N+XinoHd/DnihMGbjWTe7+jJiKHaHZ+HxQ//OCGoLXIC4wYGKH4WtGBNJeySpLCdRFzuZvj1jRi4CqWmWTP/BoiyFMMGJEAjfbvu/zY0KXFQOimQ+uSnqXCdEdWEzcMAsUoNqZDZQKD/YBB4YuQdX04d7uI5KanUEUYYx7hM34nK2iaUqb6Riw0sUpKHNTMO/T6X5cTVB51T6Y1DjT0JBzPvjYr0GB3mi3R3qul8GrSB2moaGNIvRp9g0KcHVUAKeeGTP8+ai2kdWNBkMqPv2OcIit0m3nk9MjCa+yTOUeelNosVYc5GlfXEZorsEYbm1Dc7b/2JnxlNCAJBnSufKseNxBalzBcoob6MMeZ8SR9fW28hW3IA6DcqM+C+CQq80HinED04fF3eVKhQhVUotY0YME+grRXzTNly3TnVwjqsHu35vtFQm8TqhISQcDJHn9A3R/i3pw1HIc/EQaaBazsYlonZCrIfNa+MaZw59pkFu4MaiBh2C6Iu8A70E= 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)(376002)(366004)(346002)(136003)(39850400004)(6506007)(30864003)(2906002)(4326008)(36756003)(2616005)(44832011)(956004)(6666004)(478600001)(7416002)(5660300002)(110136005)(66946007)(26005)(52116002)(1076003)(8676002)(8936002)(316002)(54906003)(66476007)(66556008)(6486002)(38100700002)(16526019)(38350700002)(186003)(83380400001)(86362001)(6512007)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Zme0V0vmVQnjVQMrTI4GuLgBuc6XEKUuNvquCWGEtbdY99ZYh7/B5WgcMs8SGm/QwuXLbwwEIlmL7mx0zHnBY7ql2ZkJ266RL6SFPyl2L03dEP2b/ehQ2b9TTkWqhSOAgzdpBad7pgbjI4oyQ8OdyM/AMWCMsQCd/A32bfRoNyRKwU0lG9W5YHyhhKTdVAs86I/+XhJ/ZFz3JppPmDSd4jWgxVnjkh7xWVWGse4zzYR5why4inCXr5mrI/AifPyTnQ9RsLMQsk7uJ66b+2RwSmXWl0d+pfOQCs+XiTn7rPgNq2z8uyd702+Mh3x0ABQQjYl6OgL8HK8GAe5QB1DYmxZbE4i+Ns14pJ2bebvWrkw+VOX6Z/lWDQ+eDU4/xUnR86s4okgAGk+AV6yhOhx/qQqaE9N24bKRlzxXPfQ/Prj3w5UNmAY5MJHbihhndWxFKEUA2p+afGpLTTfM+TgXedh1Pe6hGqk6AQKL1036klT/8iUgsvFlPSlt3IcDJDHKrhozbMxL7wxJ++9QqquXFtKXrLYK5gp5kX5ceyG2wV47YcwxM0pn+imV6YnQKKEOwgeuX716QvhXhvKzwCk5n55NUCam+KF1wP9Op2D+tfSpSlP+vb+f72qy5PtabM6vaP0ZfdAZkHKKRpvWDJf9t/zLscsz1E3AdXk6p127GlvwstAnyIwEJ2l3quVJCn1gsRMlCRNYkMI18KlNUQBTyvrs7UjIxNxdan8hv29fRmIll0WrEAzNjIZ9v5PCV3Lyt3rS6fce4LjzoMQqNSN8B/twSO6nskQ05D4Lp0IPXMtRCeLuvg8qSSwonGtHUbohAEkIDdSTSphIoSXEyTBrGWPvE824QgMw5DFw5b8/YsacRWFhDTTky0ZF1N8VqEuthsKJtLaP8mOTwohbhVEsJGszFT6g5cPm9O0Qfp3tyYKSQOCWEOVqKLFvkzrCOZz3xnDetdik11rsuA+ckRsivmMMjr3J/mV6WuBgjPuaMMeJ4g6Rw+AdWrIhcxA8dvJbiqrkZXeQD4ahrhYJLDXi4xmET+hE7O2sGuMWvB4SSCCjAVEC1+Wvgs8ye10+/B37ZwFib4oZuWdMlisX6yI3JOBQfLK4Qcms8gdxWfdD03j6dmhW4H310zdRdvoCOe+v5i1ZMwcSq9kqhwmGzD34PFnmay7slfPgv8v1AH3MIHeC4Z13wETnTAUFAO+CGbRPY73d27bJ7GIndOBp2fK/AQVbiFVOL8fc3RYXuKjgL0UtbjVcWjFqGZgfGEvdwaT6sJSMRFHNifluxKMuxcZnmtfwp1JbTfYVIQDI5K85NTjjRqNpcxwu9WtJrCkCrxOF X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f975c4e0-1a0a-4f94-8a62-08d93e19e46d X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2021 11:58:37.9103 (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: jOokrtfQu4nZGIfcrjP6Jon5fErnoLvlLfw12s48Kl8WpHyPJF29nwFkn7xQ/WNRZFmNxy3aFlSmQuNvUWozUQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2509 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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 creates an accel_priv structure per port associated with each possible bridge upper, and for each bridge it keeps 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 way this offloading scheme (borrowed from macvlan offloading on Intel hardware) works is that lower interfaces are supposed to reserve a netdev TX queue corresponding to each offloadable upper ("subordinate") interface. DSA reserves a single TX queue per port, a queue outside the num_real_tx_queues range. That special TX queue has a ->sb_dev pointer, which is the reason why we use it in the first place (to have access to the sb_dev from .ndo_start_xmit). DSA then implements a custom .ndo_select_queue to direct packets on behalf of the bridge to that special queue, and leaves netdev_pick_tx to pick among the num_real_tx_queues (excluding the sb_dev queue) using the default policies. It is assumed that both the tagger must support forwarding offload (it must search for the subordinate device - the bridge), and must therefore set the ".bridge_fwd_offload = true" capability, as well as the switch driver (this must set in ds->num_fwd_offloading_bridges the maximum number of bridges for which it can offload forwarding). The tagger can check if the TX queue that the skb is being transmitted on has a subordinate device (sb_dev) associated with it or not. If it does, it can be sure that the subordinate device is a bridge, and it can use the dp->accel_priv to get further information about that bridge, such as the bridge number. 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 pair of dsa_switch_ops methods which are modeled after .port_bridge_{join,leave} and .crosschip_bridge_{join,leave}. These are .port_bridge_fwd_offload_{add,del} and the cross-chip equivalents. 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 bridge calls our .ndo_dfwd_add_station immediately after netdev_master_upper_dev_link(), so to switch drivers, the effect is that the .port_bridge_fwd_offload_add() method is called immediately after .port_bridge_join(). Signed-off-by: Vladimir Oltean --- include/net/dsa.h | 34 ++++++++++++ net/dsa/dsa_priv.h | 17 ++++++ net/dsa/port.c | 35 ++++++++++++ net/dsa/slave.c | 134 ++++++++++++++++++++++++++++++++++++++++++++- net/dsa/switch.c | 58 ++++++++++++++++++++ 5 files changed, 277 insertions(+), 1 deletion(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index 89626eab92b9..5d111cc2e403 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -103,6 +103,7 @@ struct dsa_device_ops { * its RX filter. */ bool promisc_on_master; + bool bridge_fwd_offload; }; /* This structure defines the control interfaces that are overlayed by the @@ -162,6 +163,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,6 +228,10 @@ struct dsa_mall_tc_entry { }; }; +struct dsa_bridge_fwd_accel_priv { + struct net_device *sb_dev; + int bridge_num; +}; struct dsa_port { /* A CPU port is physically connected to a master device. @@ -294,6 +302,8 @@ struct dsa_port { struct list_head fdbs; struct list_head mdbs; + struct dsa_bridge_fwd_accel_priv *accel_priv; + bool setup; }; @@ -410,6 +420,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 +709,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); @@ -777,6 +801,16 @@ struct dsa_switch_ops { struct netdev_lag_upper_info *info); int (*crosschip_lag_leave)(struct dsa_switch *ds, int sw_index, int port, struct net_device *lag); + int (*crosschip_bridge_fwd_offload_add)(struct dsa_switch *ds, + int tree_index, + int sw_index, int port, + struct net_device *br, + int bridge_num); + void (*crosschip_bridge_fwd_offload_del)(struct dsa_switch *ds, + int tree_index, + int sw_index, int port, + struct net_device *br, + int bridge_num); /* * PTP functionality diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index f201c33980bf..c577338b5bb7 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -14,10 +14,14 @@ #include #include +#define DSA_MAX_NUM_OFFLOADING_BRIDGES BITS_PER_LONG + enum { DSA_NOTIFIER_AGEING_TIME, DSA_NOTIFIER_BRIDGE_JOIN, DSA_NOTIFIER_BRIDGE_LEAVE, + DSA_NOTIFIER_BRIDGE_FWD_OFFLOAD_ADD, + DSA_NOTIFIER_BRIDGE_FWD_OFFLOAD_DEL, DSA_NOTIFIER_FDB_ADD, DSA_NOTIFIER_FDB_DEL, DSA_NOTIFIER_HOST_FDB_ADD, @@ -54,6 +58,15 @@ struct dsa_notifier_bridge_info { int port; }; +/* DSA_NOTIFIER_BRIDGE_FWD_OFFLOAD_* */ +struct dsa_notifier_bridge_fwd_offload_info { + struct net_device *br; + int tree_index; + int sw_index; + int port; + int bridge_num; +}; + /* DSA_NOTIFIER_FDB_* */ struct dsa_notifier_fdb_info { int sw_index; @@ -197,6 +210,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 28b45b7e66df..3c268d00908c 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -344,6 +344,41 @@ 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_notifier_bridge_fwd_offload_info info = { + .tree_index = dp->ds->dst->index, + .sw_index = dp->ds->index, + .port = dp->index, + .br = br, + .bridge_num = bridge_num, + }; + + return dsa_port_notify(dp, DSA_NOTIFIER_BRIDGE_FWD_OFFLOAD_ADD, + &info); +} + +void dsa_port_bridge_fwd_offload_del(struct dsa_port *dp, + struct net_device *br, int bridge_num) +{ + struct dsa_notifier_bridge_fwd_offload_info info = { + .tree_index = dp->ds->dst->index, + .sw_index = dp->ds->index, + .port = dp->index, + .br = br, + .bridge_num = bridge_num, + }; + struct net_device *dev = dp->slave; + int err; + + err = dsa_port_notify(dp, DSA_NOTIFIER_BRIDGE_FWD_OFFLOAD_DEL, + &info); + if (err) + netdev_err(dev, "failed to notify fwd offload del: %pe\n", + ERR_PTR(err)); +} + 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 ffbba1e71551..003f3bb9c51a 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -1679,6 +1679,119 @@ static int dsa_slave_fill_forward_path(struct net_device_path_ctx *ctx, return 0; } +/* Direct packets coming from the data plane of the bridge to a dedicated TX + * queue, and let the generic netdev_pick_tx() handle the rest via hashing + * among TX queues of the same priority. + */ +static u16 dsa_slave_select_queue(struct net_device *dev, struct sk_buff *skb, + struct net_device *sb_dev) +{ + struct dsa_port *dp = dsa_slave_to_port(dev); + struct dsa_switch *ds = dp->ds; + + if (unlikely(sb_dev)) + return ds->num_tx_queues; + + return netdev_pick_tx(dev, skb, sb_dev); +} + +static struct dsa_bridge_fwd_accel_priv * +dsa_find_accel_priv_by_sb_dev(struct dsa_switch_tree *dst, + struct net_device *sb_dev) +{ + struct dsa_port *dp; + + list_for_each_entry(dp, &dst->ports, list) + if (dp->accel_priv && dp->accel_priv->sb_dev == sb_dev) + return dp->accel_priv; + + return NULL; +} + +static void dsa_slave_fwd_offload_del(struct net_device *dev, void *sb_dev) +{ + struct dsa_bridge_fwd_accel_priv *accel_priv; + struct dsa_port *dp = dsa_slave_to_port(dev); + struct dsa_switch *ds = dp->ds; + struct dsa_switch_tree *dst; + int bridge_num; + + if (!netif_is_bridge_master(sb_dev)) + return; + + dst = ds->dst; + + accel_priv = dp->accel_priv; + bridge_num = accel_priv->bridge_num; + + dp->accel_priv = NULL; + + /* accel_priv no longer in use, time to clean it up */ + if (!dsa_find_accel_priv_by_sb_dev(dst, sb_dev)) { + clear_bit(accel_priv->bridge_num, &dst->fwd_offloading_bridges); + kfree(accel_priv); + } + + netdev_unbind_tx_queues_from_sb_dev(dev, sb_dev); + + /* 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, sb_dev, bridge_num); +} + +static void *dsa_slave_fwd_offload_add(struct net_device *dev, + struct net_device *sb_dev) +{ + struct dsa_bridge_fwd_accel_priv *accel_priv; + struct dsa_port *dp = dsa_slave_to_port(dev); + struct dsa_switch *ds = dp->ds; + struct dsa_switch_tree *dst; + int err; + + if (!netif_is_bridge_master(sb_dev)) + return ERR_PTR(-EOPNOTSUPP); + + dst = ds->dst; + + accel_priv = dsa_find_accel_priv_by_sb_dev(dst, sb_dev); + if (!accel_priv) { + /* First port that offloads 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 ERR_PTR(-EOPNOTSUPP); + + accel_priv = kzalloc(sizeof(*accel_priv), GFP_KERNEL); + if (!accel_priv) + return ERR_PTR(-ENOMEM); + + accel_priv->sb_dev = sb_dev; + accel_priv->bridge_num = bridge_num; + + set_bit(bridge_num, &dst->fwd_offloading_bridges); + } + + dp->accel_priv = accel_priv; + + /* There can be only one master upper interface for each port in the + * case of bridge forwarding offload, so just bind a single TX queue to + * that subordinate device, the last one. + */ + netdev_bind_tx_queues_to_sb_dev(dev, sb_dev, 1, ds->num_tx_queues); + + err = dsa_port_bridge_fwd_offload_add(dp, sb_dev, + accel_priv->bridge_num); + if (err) { + dsa_slave_fwd_offload_del(dev, sb_dev); + return ERR_PTR(err); + } + + return accel_priv; +} + static const struct net_device_ops dsa_slave_netdev_ops = { .ndo_open = dsa_slave_open, .ndo_stop = dsa_slave_close, @@ -1703,6 +1816,9 @@ static const struct net_device_ops dsa_slave_netdev_ops = { .ndo_get_devlink_port = dsa_slave_get_devlink_port, .ndo_change_mtu = dsa_slave_change_mtu, .ndo_fill_forward_path = dsa_slave_fill_forward_path, + .ndo_dfwd_add_station = dsa_slave_fwd_offload_add, + .ndo_dfwd_del_station = dsa_slave_fwd_offload_del, + .ndo_select_queue = dsa_slave_select_queue, }; static struct device_type dsa_type = { @@ -1819,6 +1935,11 @@ void dsa_slave_setup_tagger(struct net_device *slave) slave->needed_tailroom += master->needed_tailroom; p->xmit = cpu_dp->tag_ops->xmit; + + if (cpu_dp->tag_ops->bridge_fwd_offload) + slave->features |= NETIF_F_HW_L2FW_DOFFLOAD; + else + slave->features &= ~NETIF_F_HW_L2FW_DOFFLOAD; } static struct lock_class_key dsa_slave_netdev_xmit_lock_key; @@ -1877,10 +1998,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; diff --git a/net/dsa/switch.c b/net/dsa/switch.c index 248455145982..f0033906f36b 100644 --- a/net/dsa/switch.c +++ b/net/dsa/switch.c @@ -154,6 +154,58 @@ static int dsa_switch_bridge_leave(struct dsa_switch *ds, return 0; } +static int +dsa_switch_bridge_fwd_offload_add(struct dsa_switch *ds, + struct dsa_notifier_bridge_fwd_offload_info *info) +{ + struct dsa_switch_tree *dst = ds->dst; + int tree_index = info->tree_index; + int bridge_num = info->bridge_num; + struct net_device *br = info->br; + int sw_index = info->sw_index; + int port = info->port; + + if (dst->index == tree_index && ds->index == sw_index && + ds->ops->port_bridge_fwd_offload_add) + return ds->ops->port_bridge_fwd_offload_add(ds, port, br, + bridge_num); + + if ((dst->index != tree_index || ds->index != sw_index) && + ds->ops->crosschip_bridge_fwd_offload_add) + return ds->ops->crosschip_bridge_fwd_offload_add(ds, + tree_index, + sw_index, + port, br, + bridge_num); + + return -EOPNOTSUPP; +} + +static int +dsa_switch_bridge_fwd_offload_del(struct dsa_switch *ds, + struct dsa_notifier_bridge_fwd_offload_info *info) +{ + struct dsa_switch_tree *dst = ds->dst; + int tree_index = info->tree_index; + int bridge_num = info->bridge_num; + struct net_device *br = info->br; + int sw_index = info->sw_index; + int port = info->port; + + if (dst->index == tree_index && ds->index == sw_index && + ds->ops->port_bridge_fwd_offload_del) + ds->ops->port_bridge_fwd_offload_del(ds, port, br, + bridge_num); + + if ((dst->index != info->tree_index || ds->index != info->sw_index) && + ds->ops->crosschip_bridge_fwd_offload_del) + ds->ops->crosschip_bridge_fwd_offload_del(ds, tree_index, + sw_index, port, br, + bridge_num); + + return 0; +} + /* Matches for all upstream-facing ports (the CPU port and all upstream-facing * DSA links) that sit between the targeted port on which the notifier was * emitted and its dedicated CPU port. @@ -663,6 +715,12 @@ static int dsa_switch_event(struct notifier_block *nb, case DSA_NOTIFIER_BRIDGE_LEAVE: err = dsa_switch_bridge_leave(ds, info); break; + case DSA_NOTIFIER_BRIDGE_FWD_OFFLOAD_ADD: + err = dsa_switch_bridge_fwd_offload_add(ds, info); + break; + case DSA_NOTIFIER_BRIDGE_FWD_OFFLOAD_DEL: + err = dsa_switch_bridge_fwd_offload_del(ds, info); + break; case DSA_NOTIFIER_FDB_ADD: err = dsa_switch_fdb_add(ds, info); break; From patchwork Sat Jul 3 11:57:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12356981 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C6A3C07E97 for ; Sat, 3 Jul 2021 11:58:51 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5661861922 for ; Sat, 3 Jul 2021 11:58:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230375AbhGCMBX (ORCPT ); Sat, 3 Jul 2021 08:01:23 -0400 Received: from mail-eopbgr20063.outbound.protection.outlook.com ([40.107.2.63]:47491 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230282AbhGCMBO (ORCPT ); Sat, 3 Jul 2021 08:01:14 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MRTAQzcgqv0r9LmKhAdiXyRsC1Sjbf3BFjVPnkvLtIuYM57qWAz2jz/ryANOyNCaPR8tMrzkARSyh5pofriio0DQuGjZXuzJedW8+Jmy5/PpxZavP20TWh5czbMoTc/3S/1hfKt9kTc06oEgTIUJ4/Qdih//Zo/URo9+uYJW04fA3WRPJf/uBxFSp95c2yvNylxOgV8NLwD3EMpVN/ZNLO01VA4FOunE0YUrT0QFZMWYSjI0RTdtV0k9g+8tkouPe7t1iOT7oChjhDLRYHqmLgluozocN2mAhmXfvSxsEJpi0M4gziGSOhgT7ppxbYu3awkIMOrU/0maf0+OZOnVfg== 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=Eu1sAgg7D4fTGIJBx5Bv/Zf9lqtWFAqVWzacPFz9uYA=; b=nAmhLdMhBWoOUULxXIaGhBgsaL+K8x+gRIHXghftAh8dgwRtn4iPlGCXnDQ7rBfcLus29QfSdMThOyJ7U39eVjN19p0FVbu+dmkC8Xx0vebl+FRzVVxbBEYyK9/3n+EACNIVpdh/5k77akJs2xYqYczpZLKUbkoUx8JQC3i55QT3+zhgkMIK1yfm3nBNGKSTWSRQP+cCKAUUYBm+ixEOOgsY6dLMxFHjg/84w2FMF/O8QGcAeZ1cjHhzsNbuVLFhH6v7dHKvuUDISOB9b0T6wmS/OZ/BA1Ok+y5LzPa4IGFGmOBmnirVbmnCkFZzZZR5eHPDZ0Rt/kFZ+YFe72k8rg== 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=Eu1sAgg7D4fTGIJBx5Bv/Zf9lqtWFAqVWzacPFz9uYA=; b=aHY2jehM9D4WnS4ZsbTT9gVwbKrz+TX5aQCqyZsdKPLnEc3yp2JvEpE0fPDKxdQfdgn1cXFsYoP59ISuKhqf0vfshRDa5ygGaWJBUEi128oLZk4T+NHb2TmIpnkNZTVPznKrPhSqdJczDirAj70kh+xNyCa8Q7VRWJuhO8VUaZ8= 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 VI1PR0401MB2509.eurprd04.prod.outlook.com (2603:10a6:800:56::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.22; Sat, 3 Jul 2021 11:58: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.4287.031; Sat, 3 Jul 2021 11:58: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, Alexander Duyck Subject: [RFC PATCH v2 net-next 09/10] net: dsa: mv88e6xxx: map virtual bridges with forwarding offload in the PVT Date: Sat, 3 Jul 2021 14:57:04 +0300 Message-Id: <20210703115705.1034112-10-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210703115705.1034112-1-vladimir.oltean@nxp.com> References: <20210703115705.1034112-1-vladimir.oltean@nxp.com> X-Originating-IP: [188.26.224.68] X-ClientProxiedBy: PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::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 (188.26.224.68) by PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.23 via Frontend Transport; Sat, 3 Jul 2021 11:58:38 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: df13e2e0-937d-41fd-655d-08d93e19e546 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2509: 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: CdrUMt056Rkb/gr2HAo9z9pm8NJMZp+8pnGi5ijEYlNkDUdNk+g6l5oSA/JAE2v66EPzK2h6A6K3V4zHnkwuehXE0Gnex4x4/fBcS9H890x0AGWMdkdeKhjR5l6K9U+bWuALmSWMbj5KhfPs5fGpYm0gXiObC12wm3odmWknM0DXdrzmxCbh8+MKVkbZtTBVlLqIsEy7wsYLIazHGctumOoVoDofCb2LObVsK9h8sNR5CjcuwylSmydL9ePB7c/8qneJXdOJG2a+n0+/xJrEm1KRY4c+vGshEE0LA5+6jOmBarexniWW+5vlzu8w4jk+3CQXqhydM5lv35du8qJ1yre0XZUwNJp9JwTXn7n8+0RvB9HePa7oa+JgQlyqOJQub9dge/507nI0i+z49fKtNkr/1JnVUS1+yFr63Y+wsFQcSPjVh16xeW8YHQCAXFKYVWpDaEXaCspiqk024icTG4/AqJ9FdZpABQZJo5gZE4LTsmOHRlMTlbLQDsAkwaZD17jNeE9+Ywgf1Y258qDKbrBVx3L1e0HucGKQQMaRsPit/zkb3yfvkx+6r82Ij6i+LlOHsij98lFP88kVsyLTdgfuBHXxx1NBEx3xdqGKSWJ+OhvBTKi1us5b2Y2f7+mOyxIMlqjlYg7AY1fKdcb1KE3K0TCzRPDRkZWW7jCS2bKa8ZNX1BqIaKomQO2xDwWE+/9EXe4iMLnckstfIQi3OfChew7U1dpCEMYjL6mYE7U= 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)(376002)(366004)(346002)(136003)(39850400004)(6506007)(2906002)(4326008)(36756003)(2616005)(44832011)(956004)(6666004)(478600001)(7416002)(5660300002)(110136005)(66946007)(26005)(52116002)(1076003)(8676002)(8936002)(316002)(54906003)(66476007)(66556008)(6486002)(38100700002)(16526019)(38350700002)(186003)(83380400001)(86362001)(6512007)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1yjdB7kTRnvl6GjynrOxDXVonsbkdRXSg+nJe4CThXtf30tNDeMm8f1gcJccSobD2oAe9FJKGPs/WhS8z2F2FodNfH794tV1NiUd6tm/zhPuqCb8W9LRYaE6JGvuLS3/UbuBbXGMEF9YVmeEEr9Zh/7rBiZHHI42P+jt/6lznUP5LcDE1vzZwzwuS/kQh4VLr6Vi9gnXwWxLRIy2MctxG761dVAjTB/jK2oDLMzJrppdL+P269ha+v2ZiwJVTdCfo2N+bvRAfd0KDhXUTwufYL6AYpVoOU65cPB9/PcmTWEZU3Dt3iaQU9zZ6caGGlFfsEsGUL2wz5SZfnqpFekDCVVyxYmBwyxmTaQ50w+jc3vQHfv098iqPinWUsPfNkkeWSJP5vFaSwLuvIJnoI5VaMDh1Em2SQEkDT0GQKd6sIRFiDGmrucxyg+BCrQQAWa12hU4zj3HklS04EMFcc23N2pYbD0NiJw531TnEqQxqBkAcCf4YlkBYWzpvBd/UXBZZ55mj3TOPY1lM2SblIC/7Ut8KlV2CycSDzbv5Bc+WaJ5Hk1pSr/u5oxREkKn94khAGpGb0MyytOqXsKwmGIOF4reXjsoNoHlRbHvqY3iQbI4hDwXDgiDNTaz/Ra+7f1uQs6EaRBHIMhcGIUGxc9+ApKrOcWrDa89tHcv0v5dQshLkG03UsrNEWBSpUs1hKvI5aimwqRhJryvHtGeSPIIeD/FKz0VNkXICZtfiwRIVu7ri87mGO/WTp2l4xexqOUeBVESwfGXRhBpL2NnbEuXFkG58exm1VqxxuP9RRJ0MACDH2ZeP3Gfd09OmVxdLR38CAc1H942hf5T6RZaf7tPxY0flHFGmbna2+1Ymn3RyIAKSNAyx8WvPLVuTWRbmobg7PXf8Ar/NkcbCkU7CRGktlhApviLyK1mBXnWuhU9Nr+mlIdrze/uvVDsexLLc16DQf/qEmrC1tQnUI9MOtqQ4ip3hjokMeEAMQa1GFQyDNT7rm1mBdsEoo93JtgBukNhS+0U/tgqTquflwoDRalTQCVbORHO8wRI6uUIQzvQ0sZYLBa+scf9dG84PcCJUA94N3WkqGJ6+LzgwSBcZSuVy7CcV+vQi9kxhJNwH+e9kNQcPyzDRfXwniPRW/1ZqyDQf0S1yJvDPmnHeFlpNdnrYoBnHCXl1Gi0eeFkEg71f616uts+/KMS2kHfhd1Zj7kGMjvkBWqfULUCeSlCDLpCY7HYn+2ZoD2fq3Ixs1l0LP4eEpRvTR+XjkHl7joJeE1GiYsNMOmI6/u1Jp/WlEUzh+amlMxs7qp2k32mPntyypKzNc0DmNdlSg5Isu1GEbSu X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: df13e2e0-937d-41fd-655d-08d93e19e546 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2021 11:58:39.3355 (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: JWdhviW9iqyxeijEDgornZjVyS+wae6MuStNbJfRxBSC3V36MFWc24ZoOrZy3+WvbSFxKZPJzWegDtYTg7foNQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2509 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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 | 106 +++++++++++++++++++++++++++++-- 1 file changed, 102 insertions(+), 4 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index beb41572d04e..6b9c1a77d874 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -1221,14 +1221,38 @@ 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) { + struct dsa_bridge_fwd_accel_priv *accel_priv = dp->accel_priv; + + if (!accel_priv) + continue; + + if (accel_priv->bridge_num + 1 + dst->last_switch != dev) + continue; + + br = accel_priv->sb_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 +1260,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 +2445,68 @@ 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_crosschip_bridge_fwd_offload_add(struct dsa_switch *ds, + int tree_index, int sw_index, + int port, struct net_device *br, + int bridge_num) +{ + return mv88e6xxx_map_virtual_bridge_to_pvt(ds, bridge_num); +} + +static void +mv88e6xxx_crosschip_bridge_fwd_offload_del(struct dsa_switch *ds, + int tree_index, int sw_index, + 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 +3110,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 +6222,10 @@ 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, + .crosschip_bridge_fwd_offload_add = mv88e6xxx_crosschip_bridge_fwd_offload_add, + .crosschip_bridge_fwd_offload_del = mv88e6xxx_crosschip_bridge_fwd_offload_del, }; static int mv88e6xxx_register_switch(struct mv88e6xxx_chip *chip) From patchwork Sat Jul 3 11:57:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12356983 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,MSGID_FROM_MTA_HEADER,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77000C07E97 for ; Sat, 3 Jul 2021 11:58:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 627EA61416 for ; Sat, 3 Jul 2021 11:58:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230320AbhGCMB1 (ORCPT ); Sat, 3 Jul 2021 08:01:27 -0400 Received: from mail-eopbgr20063.outbound.protection.outlook.com ([40.107.2.63]:47491 "EHLO EUR02-VE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230209AbhGCMBS (ORCPT ); Sat, 3 Jul 2021 08:01:18 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=l+nRUFLnzWBjzeQaLOz6r0OACAuZ9qYjiZIkUZCGb/Veb67+dhKoxeX2WeXnqOJBNzeLPepZCeqOLo/cobUVr4JF2Zlg9S+HTq7pkruV8i6kFOREGB8vp4hNrjmo7Fvy2I6THgBqd5vPFPbexalxzT60mQXZVdWcm5LhCFU4zmbXqq8uoA2W9npuMEEsJ3x4HVkjnapwA7IPQsMgxW3J2GhcWQgjzsAHeSDQ0BMl0w7Q5yl3rmQJCXQi3xGItEf0q41C5FgasOhzdQYfSOkzQrxSYpmPqWoObL+NCplIkXUzzzEzeGYSO6DUBx8Avy8WC7amAgKV19Qd7Wo4r/OCnA== 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=DduN+q9h+tIBuMlP1SW0pq2bUKwwt+2igei15Vdqnek=; b=LjhiR5l6lqayj/MaPkqQaPOTuAmzpcpivFQkwCyIG4Y4sP0Wi+RXki5M4WCj6twJsxMDuOKMSy9tyQsb7/gURik0IeXVe/lWmNzB5/jTGP/h4vvDFBac5tj10SLRCNmAA/CZyzxURDCK5qLDkyFq5apCPEAbrUWKM6OCztyfEJwB+fP19dTEQdKIzdFC27HRbUjFVrbN6TJxyJvvO4BQ8FBAA6IRulW3cxWN8h7ewO35/Z2VOzrAJfq6aCROZloND1we/w7qTT8MljoyEGnh4JSWPw7EPvBFcV9VYwjBpf758jGavYa4JQjb4EZ1ynLFlCJF3WBBDRvKXUYifwBgmQ== 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=DduN+q9h+tIBuMlP1SW0pq2bUKwwt+2igei15Vdqnek=; b=h1R8WAbjiWvWq25/oggMOeUnCjqHWODUSRzmUj2aS7Pwk0PDOiTwzdc4bL27Mcsy09WBLtnoRHLDf3uF5pYHtMr8GusObDT21jeh7Up21r1RMQxt2svnZxp7DHtKUuvmYXc1buS1IARGL53Sghl5VCxO2qIqXN6ZKIhRiZB7qL4= 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 VI1PR0401MB2509.eurprd04.prod.outlook.com (2603:10a6:800:56::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.22; Sat, 3 Jul 2021 11:58:40 +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.4287.031; Sat, 3 Jul 2021 11:58: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, Alexander Duyck Subject: [RFC PATCH v2 net-next 10/10] net: dsa: tag_dsa: offload the bridge forwarding process Date: Sat, 3 Jul 2021 14:57:05 +0300 Message-Id: <20210703115705.1034112-11-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210703115705.1034112-1-vladimir.oltean@nxp.com> References: <20210703115705.1034112-1-vladimir.oltean@nxp.com> X-Originating-IP: [188.26.224.68] X-ClientProxiedBy: PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::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 (188.26.224.68) by PR3P189CA0081.EURP189.PROD.OUTLOOK.COM (2603:10a6:102:b4::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4287.23 via Frontend Transport; Sat, 3 Jul 2021 11:58:39 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5cd5d110-5c19-4662-0763-08d93e19e627 X-MS-TrafficTypeDiagnostic: VI1PR0401MB2509: 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: oxsFHy9I+zX5H/aZhuo6AD18Jtb+Pz0oV/H4kEAME5PQ5mrLcnI0DGGqjfr2WfJtGWvQIzfLVnV81Dm3eqX+e8LqRUORCod6gLi0CFia3DqdKRFmqujLn1zCB0tYHsRZ1IigEXVoK3vqZivHxWqeP3R+rpQjiegn2vr730/QoQPHT5ENqzxbBYsJNR1XBQehZEOjoosEkzlL5O5pH8qQXLPGv8AfAkcgOLjgqGBDqEbbEqdDk8e+f8COyFNFVb5AVEbzZbpR5X0zPr0Zv/XMmNvnF7rE/+sfG7CSm+F2XK3JyTkjLUw45BF/ZmlfrlOHX1rMNACHs88TttGmxVPtRDBGuAb1Q5o9D+CtY4SB4DfqdOy3nyci0v5m5FgLs8h3d6H+iVIgJQNV9utLGF/yEiRUOYrVVAb+F0b+/NmYJRfdeRvWrfsDW/p/vP/tIsEgnUrVOB/WjSC2rNmovGkTry265toQ/zP3Xf/CCLd/knYubaRF+ucyCimcw10lrRZtFRVpYm7sd8AwiBlHeeN1CCENELSOIQf1q2BhQshNwH/iuSrUq966yRh1w/cm16kYO7R75fEJVkGN3z7Nk3O02G3xhB7Gd+mZBNMqS12HtZyHBtNnMx+HQUsJrFM16aG4Jxo9rkWJEqGv5q+waKNy7t/tKajrPAPJdokE4TWgwwU/MVmilf1MfM1Nay/AFTomkLDe9VG2g8z1g40hIBglGX5Qjl1Q8Fknt5sdfCKcDHK3QGpyEgljUrhpBO+hoO4O 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)(376002)(366004)(346002)(136003)(39850400004)(6506007)(2906002)(4326008)(36756003)(2616005)(44832011)(956004)(6666004)(478600001)(7416002)(5660300002)(110136005)(66946007)(26005)(52116002)(1076003)(8676002)(8936002)(316002)(54906003)(66476007)(66556008)(6486002)(38100700002)(16526019)(38350700002)(186003)(83380400001)(86362001)(6512007)(69590400013);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: X09kkgn7HcJI1Q3EPd6fkVEM+Gr6zhppT7MuDfQkUKE52VoyHriev0UIz1fFuD842OwK9TF0x97FBz/Ef4kn2KSYpgtcIDnS0b5NCwXdU9dubuWD5u3V1J4EeApYTz0vXlS7CyaynDqQKqIQP25/0FFYzf3aYPwNcO8DNqeyz4JniNVa+OCc0+2Cat1uMseXDZmfeMT1hyG2HetvhN6ExxkJrVOri6KTSeHqspk/aAgyiZZJ9LcvLxMmJFBjqVZSg/9kPQ6xB83ulCIKMqrphTNoHzLXzzQeDiXZ1m2GuQ/WAVSQEOyaq/xI4mHCmnVaVae45YfOG68++c497FLhyZ9PsfdEgvC+7EWDc90sWsLyrcjosP5UgSp1Pf/EXMdmtEBmomPVXYvxtaAW+TKNrntSl6CAtH2pRbERzSR5L77DaghyDBgllKKmwZf4xEX8S68K8+TOVEwbxJJhagNAkGdJspfZ5/OYdHZ4NYCcLqsOkEpsVgOxEQIPKm8bOkgcUGgmC4BxQ86d1uFtcIg7Wg5kb9HAxy8ptHDYAi9qsqcR+kCTLSvtB5/w+pQaLze5vonxGuGsRTuEMCeIcGH5/W1MzF0vXuMb8Iut3nvsOUQeBobVV2xwMh7M8iWl3jw5/ijm3H6yBkQUTrP960fsdmDUdPRpP40V4HRiSl0F228iRe3r9OHfFOsF8Ly3L4J/M9jJBwgaVjHoJfKb+h5ZkQ2amIay6Cd2xYa+CjMPfg2MTInxcGhgw7En6PYHChMop9jIRvpRcLW2SJAlH1zfG7Z3q5nAWFZQdYiRPXP5FgENyxqLfnwo9gEt/FlAKw3ofdSibm/kYdm5/3oVta0xwuiT/PXBKTg8y/CSRAyCWAlOxrMQTg75Ic+NiFMM3D5YwBFV/wMyFWFkF0QnHlRK0eYjySofNeVlZ1cKR/TJPUvr9KBlmYMWr+BOXb8oQg97aFCQAtsO21/74D5yiUxvbwrgDvH6o6gZTPROHmpsmAoBJqLG1NY0g/g3ZbSczqzcxsbGs08ONX641jHzNGBXyZ6ESaI5rTMcRHn3Ys8rq7jmP3tYplYT3FdrX3QkMFXKmfo1sif1+2CN5FX7jEmITtLMME5Uxe+a87gUnyrV6r34vmzrMcaa3p2TdzS6wBRB/csowt2OKPmPnEvaa6Wg1ri/zm+LlD9kb0DlufqcRPTWonQ6tXoyxeeUvfIK07hDLDXaJFoVgdCe6w+pZBeTAEr2n1oDP0O8Kz2zRNDamWcXePbqGS1XnzcgUJxo0RbmiWXeTpb9vyuni/f3JYW/6HydTdmP9iC3fqn1PrTC9Zvlla3tVO6WWjYpykD9SBcE X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5cd5d110-5c19-4662-0763-08d93e19e627 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Jul 2021 11:58:40.7906 (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: evVRshzTH5E4BID7UqPv0Aq7Cb8ry+Kvb566lAnCINi/K53WC/wb1psEG9YYkF95t8QVyVZ0CsSKxmrkmhZ3YA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0401MB2509 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org X-Patchwork-State: RFC 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/dsa_priv.h | 11 +++++++++ net/dsa/tag_dsa.c | 60 +++++++++++++++++++++++++++++++++++++++------- 2 files changed, 63 insertions(+), 8 deletions(-) diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index c577338b5bb7..c070157cd967 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -389,6 +389,17 @@ static inline struct sk_buff *dsa_untag_bridge_pvid(struct sk_buff *skb) return skb; } +static inline struct net_device * +dsa_slave_get_sb_dev(const struct net_device *dev, struct sk_buff *skb) +{ + u16 queue_mapping = skb_get_queue_mapping(skb); + struct netdev_queue *txq; + + txq = netdev_get_tx_queue(dev, queue_mapping); + + return txq->sb_dev; +} + /* switch.c */ int dsa_switch_register_notifier(struct dsa_switch *ds); void dsa_switch_unregister_notifier(struct dsa_switch *ds); diff --git a/net/dsa/tag_dsa.c b/net/dsa/tag_dsa.c index a822355afc90..9151ed141b3e 100644 --- a/net/dsa/tag_dsa.c +++ b/net/dsa/tag_dsa.c @@ -125,8 +125,49 @@ enum dsa_code { static struct sk_buff *dsa_xmit_ll(struct sk_buff *skb, struct net_device *dev, u8 extra) { + struct net_device *sb_dev = dsa_slave_get_sb_dev(dev, skb); 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 (sb_dev) { + /* Don't bother finding the accel_priv corresponding with this + * subordinate device, we know it's the bridge becase we can't + * offload anything else, so just search for it under the port, + * we know it's the same. + */ + struct dsa_bridge_fwd_accel_priv *accel_priv = dp->accel_priv; + struct dsa_switch_tree *dst = dp->ds->dst; + + 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 + accel_priv->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(sb_dev)) { + /* Safe because __dev_queue_xmit() runs under + * rcu_read_lock_bh() + */ + err = br_vlan_get_pvid_rcu(sb_dev, &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 +175,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 +189,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; @@ -304,6 +346,7 @@ static const struct dsa_device_ops dsa_netdev_ops = { .xmit = dsa_xmit, .rcv = dsa_rcv, .needed_headroom = DSA_HLEN, + .bridge_fwd_offload = true, }; DSA_TAG_DRIVER(dsa_netdev_ops); @@ -347,6 +390,7 @@ static const struct dsa_device_ops edsa_netdev_ops = { .xmit = edsa_xmit, .rcv = edsa_rcv, .needed_headroom = EDSA_HLEN, + .bridge_fwd_offload = true, }; DSA_TAG_DRIVER(edsa_netdev_ops);