From patchwork Mon Jul 19 17:14:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 480305 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.7 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 4099CC07E9D for ; Mon, 19 Jul 2021 17:19:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2675261009 for ; Mon, 19 Jul 2021 17:19:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352901AbhGSQi2 (ORCPT ); Mon, 19 Jul 2021 12:38:28 -0400 Received: from mail-eopbgr60064.outbound.protection.outlook.com ([40.107.6.64]:32129 "EHLO EUR04-DB3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1354997AbhGSQfl (ORCPT ); Mon, 19 Jul 2021 12:35:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G6WJaxU/dLVdNDnMuosofMrzNN9FdVmjlt91s5l2EtxeohknaLxg6knfq7GLAjfkjb0howl/KaCGhKIQ5lfBgYgDzfmlUZNtt0IJrklFDcrwGR1agYsFIhGfS6oenVoZODuqy46vWNJMldrsRzzZTROAT5lGSxedjAhthHpkswA2GQIK5iToSApT5723SWvLu5qiNnzlMiszz9n6IymLhdv4CJI/VnNXrxHwUYfp4jO8fKVCPrvOHSKKg342Hx25GiSMqr3uun50djYiB73pI7wirEzgwkAiP4GyiaCSDznimMhddX1lmXef544W9sQuz8t/fx9hg87+GNe2oSe2Jg== 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=wZf5EERXBllj8RqL2dAYh7jEHNvw08hODIGkcIw+Uic=; b=fOJ/xRpcs9PTOvh4KHcO9diaBQjPHY4Efgk2GwX+XTXnm8jxIjkyoLry96Q4Zo5VfS2861dodTjHsOpw4l/SKugSTytkddTQAO5i5kMkfig+sySHbGAqPISlqMkEuSJ8rd9eR7nctFtQzUHQC9tkpPGHFP9Mk3YjAp1SzDGXeizCFxKkeR1PZcA3v0rMZhjL6OHlBeY2Vfv/jZXlum1TuADSb2XzKYU88vH+g6o/ZoXTFnJdQ3D/sU/WuP2uYqzwFC9pSon/6XcRkh7541ILVTEV/Dksd9o0HazjOthsfO6UWqLBp+ID6GJNzBGABh/+lnuEjUM6RZdihqZfo+Iy5Q== 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=wZf5EERXBllj8RqL2dAYh7jEHNvw08hODIGkcIw+Uic=; b=QtPbeahh37gcWNpOcGjtitEewYU3Rpedjfvyl0DZnx6bs17thVHB9qY9USLd/lW2WVyUMM0AB/3xcEYUU7LNCFnaupaJRqII7jmO6OND2AscuhqV14SxNJymU5w6GgV9ERDAsB8jWCcI1SI8N3oEU4mwb7qS5C8TecervZXIL+I= 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 VI1PR0402MB3407.eurprd04.prod.outlook.com (2603:10a6:803:5::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Mon, 19 Jul 2021 17:16:06 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0%2]) with mapi id 15.20.4331.032; Mon, 19 Jul 2021 17:16:06 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot Subject: [PATCH net-next 03/11] net: dsa: tag_8021q: use symbolic error names Date: Mon, 19 Jul 2021 20:14:44 +0300 Message-Id: <20210719171452.463775-4-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210719171452.463775-1-vladimir.oltean@nxp.com> References: <20210719171452.463775-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR10CA0038.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::18) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by AM0PR10CA0038.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Mon, 19 Jul 2021 17:16:05 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 93efa179-bc95-4e94-c70d-08d94ad8e4de X-MS-TrafficTypeDiagnostic: VI1PR0402MB3407: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4502; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: B6qw9E/wxqzH8Qbri8d6rAORyhKQ7HMXpBVCm+b0etQ/vve0AwVYdrIdKSkTNqXSZ8spIFG32O3lNExoH1MQ7Na4Gl/9T40AO9VuuvZUMXPFx/4SCGKiYYP79Gp3NaIsll6JNAl5LbW2iArT4/ihoy0v//XNFBObPISYrtfRXPsnNq7fG+soIMnMKSjb/2bONzugg/Z5Etz2dOp7nYauKQ/VFONWsp1QetepChwLpyO3K+LwAWCwFtVtqc4bxLzd92nqRctnBAaNWemTm4uUJ4W6pkqpDZ6OVOSZ98llkkSTyR1yKQRqS0i1Eq++Ve1txHB1gAalQ14psaoLv4y4Yi+Az7QbawqsoOpaMNx00B3RnUbG1OwDAxKE8Vy5KKumnnoZ3Klu+p8qE9w/XXsmJRULjwezd70LW4w/hcBk3eELnZ80LSm2Omy/byQ5ncHIJT0yBUruJne4GliKLt4W/xAxa6v7aim5ZESvUBVa7n1md5R/i/RZIr+LdBe2QLCV07LQk/ParOAJCwhoLtzae3fvZn/h+mEsbbqq5xIvxmHn2AVyrPlQgaq3U5rrTxFz8edtjUdIbH0UCgjMZgM+qHUCzdUJYebTCO1sq4J1onKF3z+6VUC/PB1LX1LjVc/zPY0nqqP5UfxVuC5NqTSqm77gcNyq9eNzU62XZn81pJQFSff530I7CyKQC04ZfLRaNp7nUKpkE4pt+DBPB85S4Q== 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)(39850400004)(396003)(366004)(136003)(346002)(376002)(6666004)(6512007)(86362001)(36756003)(52116002)(8676002)(8936002)(6506007)(83380400001)(316002)(5660300002)(66476007)(4326008)(66946007)(66556008)(110136005)(2616005)(956004)(1076003)(6486002)(54906003)(38350700002)(478600001)(38100700002)(186003)(44832011)(2906002)(26005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: IUsZ8l9YBhkW8mSfK2BZ4SZHV/t2EtVGztbNorvFR5qRBt6Hpz/D5fuRGhm4bpFeT5u6gJLvgCllD9Y3jtRGbzinNihGb9QEJWE0Y7fwoXVyujkAn6RqhNwqHLK+H5H/0YNFz00I8AUL+eHvfNLUtC/s7lmdHNkA2bjoER+aqqVz4QVwlkqwy5syacO7ZjhBmMQbQuY544d/y25vF5LN1n+WDbj2KZB4+q9+VfobDRdbxtB/biluU5RJ5CkqGk5HZjEMH+CenRD5BFTUu69c7N9FzIcuQNlCE5qh3Z/Vuyfs3oQAUT1vEnISXCim8mrivYHnkH4oC4xn0nC9pH39zsK3ZQWMvF3praPscRa5Ja9vYyuRIorPNZJt/1ww8iXKKVc356XBsVqx4pMh1Z/Uj2rmKDfNBFvJiGBkwfbjhpEenMJa0ymxuW4+7Wd8+NH/apHY/P/71DZiuGiaSCXOPao7aTjep9+j5KVgyK/ZQzMsntPkV/tX2dzP3wBD5NrvdXuExu3tmanpG74j0nqK/U09ljJFsmwSwIpXmdBw2++dvnjp0JCji2WP0RABGbxsypYWjBLio+F+Rowf1ouu0SzWzY0oo1QmZNk9FK9P+LzGgPs2RioDMvn98oC6DErSdOZ3qpKPV6XcEVTHE9EJXi3oQ22NrkNVnOWMqHGkBUzHPHkqtnE8qsMjdUeDHojPJdg2lwGnNdR5qS2O2eMcdLrXx6v3jOFtL7U6/NHoLlPZrwBVzRtk1OLWwa4QfOp6N2CsfryXwZhp/HH0vJbxeCklxvGEepCs7rk3yEHB0JP/zHUD7oqTeC83sPE3uQVVG0EyCBaQ8EsrQ2APe3C4l3zgn7KzlyVoZzvgL6piwnuDot5lC62pymVnTDGBmzDDYcS5KXzo5L53DPEpOA7qTqO3EyKYHITetg2LSlHQGsqINoz3/5ghu0sVOwItGpW10bHvRAXhRhvtzTFWSwtKSNm6wjFwzrAJ3rJpGfbPuXvr2H9JzNqfKtVfGYFs0o3rAcz+wC42rRZah6SiuJjMZVfVKCxa+H955s3WJw+exKeW80YsEALkwT9PFYfbEL2O/ss0Ghv5zJz1xH0B3aJP85gmX3dXCgJ6K7RSvUuTQdl1HC5Fofz72+7sO21VY6iraH1SW5pKfL0beydW8lndlSsBu2HSDEAyDmrNjXpro2cWKqH7AYj2NluljRThm/LJQGtTSMHTI79XYg63vPALvKG8Bz4ZhXPt7QQYSQqDUNr/PV6r255StYfgJ1T6cX0HqxBKz1v7gNPj15SH0WnX8ElPnigpN+mMrULv15PKqIiVlusiucKc3V8BkvYzKeyM X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 93efa179-bc95-4e94-c70d-08d94ad8e4de X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2021 17:16:06.4411 (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: 0g36G4poRLfF1+r1ggNfK5/ZE/HQJkXpQD1niG3J59nOC+X93Ps+s3bcfij6ak+Tc7GV+Z9Owdc2Sp/2tkl44g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3407 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Use %pe to give the user a string holding the error code instead of just a number. Signed-off-by: Vladimir Oltean --- net/dsa/tag_8021q.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index 1c5a32019773..3a25b7b1ba50 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -214,8 +214,8 @@ static int dsa_8021q_setup_port(struct dsa_8021q_context *ctx, int port, err = dsa_8021q_vid_apply(ctx, i, rx_vid, flags, enabled); if (err) { dev_err(ctx->ds->dev, - "Failed to apply RX VID %d to port %d: %d\n", - rx_vid, port, err); + "Failed to apply RX VID %d to port %d: %pe\n", + rx_vid, port, ERR_PTR(err)); return err; } } @@ -226,8 +226,8 @@ static int dsa_8021q_setup_port(struct dsa_8021q_context *ctx, int port, err = dsa_8021q_vid_apply(ctx, upstream, rx_vid, 0, enabled); if (err) { dev_err(ctx->ds->dev, - "Failed to apply RX VID %d to port %d: %d\n", - rx_vid, port, err); + "Failed to apply RX VID %d to port %d: %pe\n", + rx_vid, port, ERR_PTR(err)); return err; } @@ -242,15 +242,15 @@ static int dsa_8021q_setup_port(struct dsa_8021q_context *ctx, int port, enabled); if (err) { dev_err(ctx->ds->dev, - "Failed to apply TX VID %d on port %d: %d\n", - tx_vid, port, err); + "Failed to apply TX VID %d on port %d: %pe\n", + tx_vid, port, ERR_PTR(err)); return err; } err = dsa_8021q_vid_apply(ctx, upstream, tx_vid, 0, enabled); if (err) { dev_err(ctx->ds->dev, - "Failed to apply TX VID %d on port %d: %d\n", - tx_vid, upstream, err); + "Failed to apply TX VID %d on port %d: %pe\n", + tx_vid, upstream, ERR_PTR(err)); return err; } @@ -267,8 +267,8 @@ int dsa_8021q_setup(struct dsa_8021q_context *ctx, bool enabled) err = dsa_8021q_setup_port(ctx, port, enabled); if (err < 0) { dev_err(ctx->ds->dev, - "Failed to setup VLAN tagging for port %d: %d\n", - port, err); + "Failed to setup VLAN tagging for port %d: %pe\n", + port, ERR_PTR(err)); return err; } } From patchwork Mon Jul 19 17:14:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 480304 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.7 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 B3C76C07E95 for ; Mon, 19 Jul 2021 17:19:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9CC7160FED for ; Mon, 19 Jul 2021 17:19:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352122AbhGSQil (ORCPT ); Mon, 19 Jul 2021 12:38:41 -0400 Received: from mail-eopbgr60064.outbound.protection.outlook.com ([40.107.6.64]:32129 "EHLO EUR04-DB3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1355063AbhGSQfp (ORCPT ); Mon, 19 Jul 2021 12:35:45 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XMbRIC4O6vK71P825DzFt9O6iGDWjPJoJp0y+gWlUuEw5uJKxOp2SzTA50VezZmvDezXxakPLjGPixema34o9M5Z4oGgQ7+yE6IyVsKP/oOWAD3uGnHnajCFS2EFtxTQovXq/94NQU6eto/CLIX8XKIsWRW2NQhl1HVU8MXhGwIVoYjKvOP52IxouQbRAO1mD5PlgvUhBeK+ds12RmFwrmZBIvCp75R7sctN6SButxCYXh62Gg391xgSd0ISi/05apQ+kpJRva+vdaoqdb8fX3wj9sLlivQK+KtaLm7A08cZMGaxVsdak+UaqftlofXcUpLL8pCyPMCALmkwkH2ZLg== 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=m5jDFvkiH3psSH6wXcLGZrGruROKURyJyZEFsje7DjY=; b=CGm+UeGKB7EN1Xr7hb1fo0JUU77nk28bwPMIyJYPz4/ncfsZyA7cqPORfkOqd3zJpT57jVozyR7+sKRMSumwj8jVeq5k88nX7G4p0Wa0GRROIyOBWameAcuibs6+VHCHsMG5bKL+JjROLjwwymd2UdIjGis1eXmajuVJLDa+JihC0LCeHjsfxVJBGZkj0lahtWvAxgOmtX+KVDv6saIV4yAUakQlwsDUq2XN5oI1dOlNrK0i8/8JJg3OLct0RDnZWGkwR/UCzxE/k6np1rifnkdDsEDXla5mynhnXM93hTpMybMVlHneGqWlC6SWxso3nW6fZJ/waVxWHmnBBOGCeA== 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=m5jDFvkiH3psSH6wXcLGZrGruROKURyJyZEFsje7DjY=; b=MAiNwvKvjmlHKLdQPUGReVnXGunI5pj9Wz1N3NoulXY6MgVN+Z0hWR5evhXtFYq0RU2lFSF45sHseU5CQ1tfGIM9xkuDC6O1Vzzlh9CEJ4alFj6jRrA99fwXslq8t7Ve2GQmpliVVbrDs/P94dDgjwZHrw3XY/q4Ak5yuGqKE+g= 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 VI1PR0402MB3407.eurprd04.prod.outlook.com (2603:10a6:803:5::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Mon, 19 Jul 2021 17:16:08 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0%2]) with mapi id 15.20.4331.032; Mon, 19 Jul 2021 17:16:08 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot Subject: [PATCH net-next 05/11] net: dsa: tag_8021q: create dsa_tag_8021q_{register, unregister} helpers Date: Mon, 19 Jul 2021 20:14:46 +0300 Message-Id: <20210719171452.463775-6-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210719171452.463775-1-vladimir.oltean@nxp.com> References: <20210719171452.463775-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR10CA0038.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::18) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by AM0PR10CA0038.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Mon, 19 Jul 2021 17:16:07 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 20f459c5-90f4-4344-316f-08d94ad8e5fb X-MS-TrafficTypeDiagnostic: VI1PR0402MB3407: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:3276; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: iiNWNTHfAvWjNbTXac4uqb1uQtSRI981ktxLrH82RAnGA/yEM/IwuyW80cXXOpvad7M45zz1vsPt0Lmv7kNvvCXNQDTBd45nRLRMLSAUE4oGdtdssi++JBTWjmMotAgc0Y+snmtkaySlG5uW4Si1hRf6XTOTGaO6pRLT1yh3KGqr2cP3JZSXRxCRMq0myRhhIfnUTxKBl9diuNq+SwPmXx8FZUJw1MGnOyi5paICxaQ8Sa861ZqfQfcQLHzC3tTuqaXaEOrncKap2bY96GfBdKypZq0r4S13mQT7JLyUjPa7Yy68rsE5tsXGywaz8N0lBRCviUnCIffR9voGTcSik7uFhCe9ang34EW4m4FyrPpIY6dw+pBI/HgDvN1buIrG9r2IE1AReJfHJkBWFqac75R/kAp1vsvBG12pknYWfgNejLF4621HH2JaLMYbMKSPmMGDsbf91nVeMAPOuXp1TkD9yxaKzOi3kKtPLVYjt93eFZeSUqIflY3rlPkfivYn0Q9nHrZ6t3VasCNumEVidtWML2P5D7YVyNqIJvAw0AEr8i30nyOSWQGTr4BY33zMBkxkUN1eeR+67Ly2cRVGA5zAT/zF38GrIMbvBFzfC1Uj+DgkcEcSohXMmn4tThC2GObdMzNZvgfDp03z1S+z+B1bLDwZCfcpY/OHx/HRrO9ql7fmvaUvAMM4TCpZFDYwtJHi6mD8YKH7VazuG7YZ+Q== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(39850400004)(396003)(366004)(136003)(346002)(376002)(6666004)(6512007)(86362001)(36756003)(52116002)(8676002)(8936002)(6506007)(83380400001)(316002)(5660300002)(66476007)(4326008)(66946007)(66556008)(110136005)(2616005)(956004)(1076003)(6486002)(54906003)(38350700002)(478600001)(38100700002)(186003)(44832011)(2906002)(26005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gMpmlbh+kSsJEFqBpzpTjLYoAyfx7UdPZXoSlRPEdXt0dI4nx6lHDoP/kVnUGSEvVheWkr7uLek8I0et5060QDLgJcOCXFZFULytv4j9Lg9XlAQtAO+MRUacqP2jLqIEbqaTsitX5k1EOkvsvPFyIZz7DnXC83u+6ZnH2SgNOGsUjHiUj/70XAYqUw7dwdm6dZK/GufCCvyfbYRpPnXR0JW1rc1D5eGofX3bPaaejDwQmbr2Glf9iJNviv6U/THYKMlnenZAUV71so4T9VXaUgvpK7rRVgPsSLTOjbXAJ35i3xl/OjomKDlNYVvmtghj6V/0V2Q7uYrlDnQnEfQedtLWbvZDZ9zHzKe/0TM38/mARSACCkbQAAj43aFSLXLQlafI5yX96cX1tWtqBZDhi4cUH7NyEhPmdAYMhV1dtE8Cbu5ClmmBBLf5uwt88aYSURaDikqMb/l1If0210slvEmRk5vdflXjllU2+f9vTQIH+u9+Tg5LHG6iYaINikyDJT6vSFIK9k9BhJaB5dpqiqD36D+l0s1R0WnxenKe43WRwi3PLXFXahHcTbhwWfHga+7ndCfQF24K+ds+FN/LHNjjPoGrdGZbEU7kzH7OwsvGmrhP3HlgOPha4SQJpWNByL/2BCTCTYF80R10WnWMH2cgW7+ZLdpVrGJF1YzbUZ/DQHxuTa/L4wGc9MxTJj37wKAd0Y/J/LVcYqLFC7weaz6aQxA2yfEdGAMADVZzXEY3HqYecfnF5if4bsegsis1sgxtYZEku0aoUOnQuHuQWYDJD0q3hZYoTX+xZjDjgm44i4YgETS7ayxDjmbQUFmpzONTHhRv9hX+fzZFyrEooYVFtAU8H/ERKaDDDVNUdDamTaSsBlNnc8dKSUVdlFcf/cCIfrWZ+Ev7bSffWMOlAHmJEMnr0H5T2xEiNPkEmf3ZR5HnhkofK21eFZUm+aIwKgrAIu+L+NqEUYXsRrK7HvE6Ad5WHt3Ux77tZC9CJ8XMhmgRmYiiWnAb/ZQY0mlFW7DaWHHCkjhPpd4NfqP9nUlvUeg0EhbIMfyJqx/KJsMavZh5cUO+v7/LGu/6EtNBzBNrtZMR6KmOlAxsBJvS0h0GufZFuFRv1fgcaWSar2YHxSjLtQocAE9z0B4iVK4RGnVu4d6/LhJnC7uo+4ip32zy6Pp90gHGHRMKz8bbZE+SksmWH9wUz7sJFs271XawNBcfB0Kh5ZGRSlf024ykoPbKyOU8ijWAC2Vj82PohkOWg7a0/TeANsSf6aD985vG8NvNPnQQAZvnCSXN7EI2oKqQEbuOrYZsKDWF7YoUk71A8bXo9uYzAbg8FGTOWxRD X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 20f459c5-90f4-4344-316f-08d94ad8e5fb X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2021 17:16:08.2921 (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: WaZAWdqsUjHptNd3r5VSKB0z/S0Xi+9oRwQziZRtU5P5JRgL/Csvuym4HdxgY2qTUEOz4hX5BdNOe0cM/U/Gpw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3407 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org In preparation of moving tag_8021q to core DSA, move all initialization and teardown related to tag_8021q which is currently done by drivers in 2 functions called "register" and "unregister". These will gather more functionality in future patches, which will better justify the chosen naming scheme. Signed-off-by: Vladimir Oltean --- drivers/net/dsa/ocelot/felix.c | 12 ++++------ drivers/net/dsa/sja1105/sja1105_main.c | 18 +++++++------- include/linux/dsa/8021q.h | 6 +++++ net/dsa/tag_8021q.c | 33 ++++++++++++++++++++++++++ 4 files changed, 52 insertions(+), 17 deletions(-) diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c index a2a15919b960..b52cc381cdc1 100644 --- a/drivers/net/dsa/ocelot/felix.c +++ b/drivers/net/dsa/ocelot/felix.c @@ -425,15 +425,11 @@ static int felix_setup_tag_8021q(struct dsa_switch *ds, int cpu) ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_MC); ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_BC); - felix->dsa_8021q_ctx = kzalloc(sizeof(*felix->dsa_8021q_ctx), - GFP_KERNEL); + felix->dsa_8021q_ctx = dsa_tag_8021q_register(ds, &felix_tag_8021q_ops, + htons(ETH_P_8021AD)); if (!felix->dsa_8021q_ctx) return -ENOMEM; - felix->dsa_8021q_ctx->ops = &felix_tag_8021q_ops; - felix->dsa_8021q_ctx->proto = htons(ETH_P_8021AD); - felix->dsa_8021q_ctx->ds = ds; - err = dsa_8021q_setup(felix->dsa_8021q_ctx, true); if (err) goto out_free_dsa_8021_ctx; @@ -447,7 +443,7 @@ static int felix_setup_tag_8021q(struct dsa_switch *ds, int cpu) out_teardown_dsa_8021q: dsa_8021q_setup(felix->dsa_8021q_ctx, false); out_free_dsa_8021_ctx: - kfree(felix->dsa_8021q_ctx); + dsa_tag_8021q_unregister(felix->dsa_8021q_ctx); return err; } @@ -466,7 +462,7 @@ static void felix_teardown_tag_8021q(struct dsa_switch *ds, int cpu) if (err) dev_err(ds->dev, "dsa_8021q_setup returned %d", err); - kfree(felix->dsa_8021q_ctx); + dsa_tag_8021q_unregister(felix->dsa_8021q_ctx); for (port = 0; port < ds->num_ports; port++) { if (dsa_is_unused_port(ds, port)) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index 4514ac468cc8..689f46797d1c 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -3306,16 +3306,11 @@ static int sja1105_probe(struct spi_device *spi) mutex_init(&priv->ptp_data.lock); mutex_init(&priv->mgmt_lock); - priv->dsa_8021q_ctx = devm_kzalloc(dev, sizeof(*priv->dsa_8021q_ctx), - GFP_KERNEL); + priv->dsa_8021q_ctx = dsa_tag_8021q_register(ds, &sja1105_dsa_8021q_ops, + htons(ETH_P_8021Q)); if (!priv->dsa_8021q_ctx) return -ENOMEM; - priv->dsa_8021q_ctx->ops = &sja1105_dsa_8021q_ops; - priv->dsa_8021q_ctx->proto = htons(ETH_P_8021Q); - priv->dsa_8021q_ctx->ds = ds; - - INIT_LIST_HEAD(&priv->dsa_8021q_ctx->crosschip_links); INIT_LIST_HEAD(&priv->bridge_vlans); INIT_LIST_HEAD(&priv->dsa_8021q_vlans); @@ -3324,7 +3319,7 @@ static int sja1105_probe(struct spi_device *spi) rc = dsa_register_switch(priv->ds); if (rc) - return rc; + goto out_tag_8021q_unregister; if (IS_ENABLED(CONFIG_NET_SCH_CBS)) { priv->cbs = devm_kcalloc(dev, priv->info->num_cbs_shapers, @@ -3377,6 +3372,8 @@ static int sja1105_probe(struct spi_device *spi) out_unregister_switch: dsa_unregister_switch(ds); +out_tag_8021q_unregister: + dsa_tag_8021q_unregister(priv->dsa_8021q_ctx); return rc; } @@ -3384,8 +3381,11 @@ static int sja1105_probe(struct spi_device *spi) static int sja1105_remove(struct spi_device *spi) { struct sja1105_private *priv = spi_get_drvdata(spi); + struct dsa_switch *ds = priv->ds; + + dsa_unregister_switch(ds); + dsa_tag_8021q_unregister(priv->dsa_8021q_ctx); - dsa_unregister_switch(priv->ds); return 0; } diff --git a/include/linux/dsa/8021q.h b/include/linux/dsa/8021q.h index 5f01dea7d5b6..9945898a90c3 100644 --- a/include/linux/dsa/8021q.h +++ b/include/linux/dsa/8021q.h @@ -34,6 +34,12 @@ struct dsa_8021q_context { __be16 proto; }; +struct dsa_8021q_context *dsa_tag_8021q_register(struct dsa_switch *ds, + const struct dsa_8021q_ops *ops, + __be16 proto); + +void dsa_tag_8021q_unregister(struct dsa_8021q_context *ctx); + int dsa_8021q_setup(struct dsa_8021q_context *ctx, bool enabled); int dsa_8021q_crosschip_bridge_join(struct dsa_8021q_context *ctx, int port, diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index 3a25b7b1ba50..73966ca23ac3 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -410,6 +410,39 @@ int dsa_8021q_crosschip_bridge_leave(struct dsa_8021q_context *ctx, int port, } EXPORT_SYMBOL_GPL(dsa_8021q_crosschip_bridge_leave); +struct dsa_8021q_context *dsa_tag_8021q_register(struct dsa_switch *ds, + const struct dsa_8021q_ops *ops, + __be16 proto) +{ + struct dsa_8021q_context *ctx; + + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return NULL; + + ctx->ops = ops; + ctx->proto = proto; + ctx->ds = ds; + + INIT_LIST_HEAD(&ctx->crosschip_links); + + return ctx; +} +EXPORT_SYMBOL_GPL(dsa_tag_8021q_register); + +void dsa_tag_8021q_unregister(struct dsa_8021q_context *ctx) +{ + struct dsa_8021q_crosschip_link *c, *n; + + list_for_each_entry_safe(c, n, &ctx->crosschip_links, list) { + list_del(&c->list); + kfree(c); + } + + kfree(ctx); +} +EXPORT_SYMBOL_GPL(dsa_tag_8021q_unregister); + struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev, u16 tpid, u16 tci) { From patchwork Mon Jul 19 17:14:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 480303 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.7 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 BBD58C07E9B for ; Mon, 19 Jul 2021 17:19:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A082B6108B for ; Mon, 19 Jul 2021 17:19:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1352485AbhGSQi6 (ORCPT ); Mon, 19 Jul 2021 12:38:58 -0400 Received: from mail-eopbgr60064.outbound.protection.outlook.com ([40.107.6.64]:32129 "EHLO EUR04-DB3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1355136AbhGSQf5 (ORCPT ); Mon, 19 Jul 2021 12:35:57 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Tyy2I6ABVmzdhfyPfHwWo2NJt9HUB4E16CddNsKHXonl0jiPoINkkiwpEQGhLhyZ++M8Pe2fhvsbz8e8eEaaPQtxymwyqSg/ZF1nExRRkQC/eJp8oC/G63sOkZqzSS0aKXTfD0iPlKhH4CmVW5qAii92B0YD0mS/r4vOqVLAAsEFw7gdLxeTRWBduilU/U8gbuafVZI4DF2GZqphqUjjjJhIw81KMxoOFaB4acRM4sGdFu6HGkSxJpm0f6KhkdS9y2+tgWvTsyStkTPQvJ3CXZzhjV4NSjT2BccvabrgTdUErMBZT7aQPuNTZa3EzWoxVJNPcAbD85+aEuhPNLNvnw== 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=GzuwfDPv4elBY0Kph0lYxhhu39nN1bvzevVZdm0Oi4s=; b=UE3f+XVzR3r+T5PrFYWy/SBQDAt+YnqrNXTxlklItSnwc2IENTivZYcRX6APMoahLwdgRDiriy70gaCWfMHRf2V0lXIXTrUCo/AoYzGVh6GTdnp6Z7HxzfEImX8elYOCTxKH7gpZALBgov6J6HG2NA9Xc2DdhM6okohdW3BQfawdjvaLzCivekRqQ1qqg1Ug9aQpYdBNTvsh8y//WUSvfMkNRteLqReXnjQaR1ipey30jwEaoI+r6x60knNy8xhr8I701p5hmCLv0TUX+VX/3azelnwAXLRRAZMtpwg43HAX6w6nAMaH5QXPyeweHqfPISuLJR6X9YkNs+D59fs1Hw== 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=GzuwfDPv4elBY0Kph0lYxhhu39nN1bvzevVZdm0Oi4s=; b=Svrtb9EF6a5aH17FdncH2WN3F4KdqzlDWMRJs/7pxL9GCz79BoIXrNNKeTBReN+n+Snz2iWkj97KvyaKH/bsYjPCDmsV0qnlm1qpkik7xZ/2XeorJigWgiuCEsbTfQ7hLxVUZtd4cwNvb32U1M0aPZq2gbW/dwKpmpbMb/ofQ5g= 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 VI1PR0402MB3407.eurprd04.prod.outlook.com (2603:10a6:803:5::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Mon, 19 Jul 2021 17:16:10 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0%2]) with mapi id 15.20.4331.032; Mon, 19 Jul 2021 17:16:10 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot Subject: [PATCH net-next 07/11] net: dsa: let the core manage the tag_8021q context Date: Mon, 19 Jul 2021 20:14:48 +0300 Message-Id: <20210719171452.463775-8-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210719171452.463775-1-vladimir.oltean@nxp.com> References: <20210719171452.463775-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR10CA0038.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::18) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by AM0PR10CA0038.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Mon, 19 Jul 2021 17:16:09 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 57fb65ce-7f8b-477b-4fbd-08d94ad8e739 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3407: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1824; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YoJueF6A/PeI4C4rMDyWMYnNYKQb/GJ9c6qJnp4UvrYAlL4QkkbnCOJtlBLXeejypAs8j2Q0vO+Dxs8ah266uUibBN+wvjgqrVq+pd8JXQyuhTrkzDgfJspXzqfUJdz652ucD/l0iJcyPG3oNgsfG51Cr6fWVYeJlh1NQAdyLMsVX7OaVE5q1K3Lf87NjXYcpKhiXzv8EJ4+jf7Cf7TsjmA5Q5lL638z5mBsx9+fLJu16z9eDj22awjS7N5Iao5qwydBtoWBtDwS2aD4dCJl2rHEcGX/ixfHq24wrcq2bUEwoClpe3E2sG5z6yQsU1tB2SW2SFssj/6eA2GXJI6ySm763KyH02Nhrb5hmfg1uLxg4u4+yOl+A3rEEEQYw2krIozVhPQdUelrbvoZpzDlkI/o0qVLMRq9TvqPRJfITyiTZSwy+yvKlRNoq83aY8ggjf4DSTv5ahUWExGlDj/RBPgZKUhcPYUR9nkLgIFTrAOIOG1guYTUfHz2THZ7gDaDVRyWFqIVYOAq5EA/5MFnKIxp54ZBwZjLJnKDij6GQwzcHntyUQc8ITvCXxAy/z5EtUgB6FeZDI/bkj9KEQgjGV6X34rbYp27QhAcQHisc8nHxgjI7zmp1ctRu5uYYzfDiUyDTtbo46z4OiwUHETrteGfDVHPrGaLxGCjBVfAKSymHMutsze2fKYR7NWhbeGkNHxbgb3a/tbtpR7Ax9T9BQ== 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)(39850400004)(396003)(366004)(136003)(346002)(376002)(6666004)(6512007)(86362001)(36756003)(52116002)(30864003)(8676002)(8936002)(6506007)(83380400001)(316002)(5660300002)(66476007)(4326008)(66946007)(66556008)(110136005)(2616005)(956004)(1076003)(6486002)(54906003)(38350700002)(478600001)(38100700002)(186003)(44832011)(2906002)(26005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: v6uHvSYIq0nv0zv56OSOymTCqtQEvm7FJpMQXYuSXcQTeMBFDjZdcOiO2d3FDIGcuOJzaFNfpnbU/Naj0ib/P5FIBuv6GoaasZjtjMlj7+Xw85b4y4cxtUaN9br74tP92CFWiK6/fCurCVPOSw0xqbyQSmCYvZAs9DjJ/a+fKPKsa6PFdVrb1LLniY+ubQqZA01O+k+UZR9alknf/B3LhEjO3n8qzd9oojRz4HGVnkwlBLkcMI9J4OszA2eD47/zmDW6h23VgXqclC9SJf8pjYzU0zJhXiMWtG7PCekPG9bWydYejwoQfiMQ8ghBo+BlUzWDigYcAdmc/U2i84UOp8DJXx7UGYwja3Meo+n/0YKNympfFFcbR5hZ0Kwy0e11MUyeMDZ575oR3lNqz3XBtMlGuoMYlMrJhR0qgEz9FF48yc/h8bUq9S1+LvD6jybU6G0oEZ5sMcLrwz3Pzgd7wtEUA9g6O4xmUmpj331uciOGu7ic/3aTmeyWqfKlV7pFGyTTLPWw1C1l0A3hKhtqcer+snmHz5dC0JjY7tbuDw+QcAqgrrdQ7yn0HZFkKnECkMmuLqjdBFKEWWw3+sazO0ILEfbpZr3VRqEij8NfyNKyQ9zfKv/JQvQ8BBXafzrKudTNPBKLjDy0loIYo4MVRsY7NH6ZBc8GImmlppHQRSfjUDkP8fF4VYkEfBLh88Mgexnh+steOhM5Ew7qzBczcxJSw2VGwVi7r34lGg08/ZgiIEyqYAtp9xJb7xj6Mz4PXoDvS0rY9YU3+HFhdl8xwpPI2mFmoxMHpHKLj5wuY7irMWS9ajwFhCvUBzzSctv7sn1Wx7UzCsGaM8pPcJRpzwD9gXcHMEqmND7ZCWsNlq28WWMOrr98+vVEI9UWXLOllvfZuDMQU8PopHHoanQeghq8/MhDWIuVFCNjVrYweH0zv8QE0yjzNJBz20+0d5YqTQSZQcT9Z2QMtyzIdJLLeE/zg4HGQwYYlYPyXmqVYp94s1p9rPhOww9kHSC9vH/+Dos9M47LsxvT+3JYkXWAEkaVyKM360jQtCBs9tkYjb16M08cwZVqh2vTCVFNKRgS3NMdCbz+80fxBJ2Liw77ZZ7bUIRD1XmV3iRd1xyKtL2eEohjcAweN4EOo1PydPuxZMlYYizGOHLm6eO2yWc0VSqQbIL5W6YLKFtLCEHJdjoRcVGu3cBxBNWdvSRGIP9QcEoR1Gj57XrVC7XnNs8xaE9Jbu4Jrwlc1Skd/B8ikAZRzivWo6FyTFxKfTt5LI6uTvAh+FpzzuKgeNiXq+oolWPrhR54fzw+LKZ24hZbWS3Q1VwjrutXpA8ARwRE6qQk X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 57fb65ce-7f8b-477b-4fbd-08d94ad8e739 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2021 17:16:10.4878 (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: 4ekCyi10HwafQUzBjl1rPCFfFpX5Xq9SEUjYtRQpZg31PM+HA12BRl6So9vRrLz3C1Bq66/HlIyN4HkRCw17Ig== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3407 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The basic problem description is as follows: Be there 3 switches in a daisy chain topology: | sw0p0 sw0p1 sw0p2 sw0p3 sw0p4 [ user ] [ user ] [ user ] [ dsa ] [ cpu ] | +---------+ | sw1p0 sw1p1 sw1p2 sw1p3 sw1p4 [ user ] [ user ] [ user ] [ dsa ] [ dsa ] | +---------+ | sw2p0 sw2p1 sw2p2 sw2p3 sw2p4 [ user ] [ user ] [ user ] [ user ] [ dsa ] The CPU will not be able to ping through the user ports of the bottom-most switch (like for example sw2p0), simply because tag_8021q was not coded up for this scenario - it has always assumed DSA switch trees with a single switch. To add support for the topology above, we must admit that the RX VLAN of sw2p0 must be added on some ports of switches 0 and 1 as well. This is in fact a textbook example of thing that can use the cross-chip notifier framework that DSA has set up in switch.c. There is only one problem: core DSA (switch.c) is not able right now to make the connection between a struct dsa_switch *ds and a struct dsa_8021q_context *ctx. Right now, it is drivers who call into tag_8021q.c and always provide a struct dsa_8021q_context *ctx pointer, and tag_8021q.c calls them back with the .tag_8021q_vlan_{add,del} methods. But with cross-chip notifiers, it is possible for tag_8021q to call drivers without drivers having ever asked for anything. A good example is right above: when sw2p0 wants to set itself up for tag_8021q, the .tag_8021q_vlan_add method needs to be called for switches 1 and 0, so that they transport sw2p0's VLANs towards the CPU without dropping them. So instead of letting drivers manage the tag_8021q context, add a tag_8021q_ctx pointer inside of struct dsa_switch, which will be populated when dsa_tag_8021q_register() returns success. The patch is fairly long-winded because we are partly reverting commit 5899ee367ab3 ("net: dsa: tag_8021q: add a context structure") which made the driver-facing tag_8021q API use "ctx" instead of "ds". Now that we can access "ctx" directly from "ds", this is no longer needed. Signed-off-by: Vladimir Oltean --- drivers/net/dsa/ocelot/felix.c | 22 ++--- drivers/net/dsa/ocelot/felix.h | 1 - drivers/net/dsa/sja1105/sja1105.h | 1 - drivers/net/dsa/sja1105/sja1105_main.c | 40 ++++----- include/linux/dsa/8021q.h | 18 ++-- include/net/dsa.h | 3 + net/dsa/tag_8021q.c | 114 +++++++++++++------------ 7 files changed, 99 insertions(+), 100 deletions(-) diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c index b52cc381cdc1..9e4ae15aa4fb 100644 --- a/drivers/net/dsa/ocelot/felix.c +++ b/drivers/net/dsa/ocelot/felix.c @@ -425,14 +425,14 @@ static int felix_setup_tag_8021q(struct dsa_switch *ds, int cpu) ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_MC); ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_BC); - felix->dsa_8021q_ctx = dsa_tag_8021q_register(ds, &felix_tag_8021q_ops, - htons(ETH_P_8021AD)); - if (!felix->dsa_8021q_ctx) - return -ENOMEM; + err = dsa_tag_8021q_register(ds, &felix_tag_8021q_ops, + htons(ETH_P_8021AD)); + if (err) + return err; - err = dsa_8021q_setup(felix->dsa_8021q_ctx, true); + err = dsa_8021q_setup(ds, true); if (err) - goto out_free_dsa_8021_ctx; + goto out_tag_8021q_unregister; err = felix_setup_mmio_filtering(felix); if (err) @@ -441,9 +441,9 @@ static int felix_setup_tag_8021q(struct dsa_switch *ds, int cpu) return 0; out_teardown_dsa_8021q: - dsa_8021q_setup(felix->dsa_8021q_ctx, false); -out_free_dsa_8021_ctx: - dsa_tag_8021q_unregister(felix->dsa_8021q_ctx); + dsa_8021q_setup(ds, false); +out_tag_8021q_unregister: + dsa_tag_8021q_unregister(ds); return err; } @@ -458,11 +458,11 @@ static void felix_teardown_tag_8021q(struct dsa_switch *ds, int cpu) dev_err(ds->dev, "felix_teardown_mmio_filtering returned %d", err); - err = dsa_8021q_setup(felix->dsa_8021q_ctx, false); + err = dsa_8021q_setup(ds, false); if (err) dev_err(ds->dev, "dsa_8021q_setup returned %d", err); - dsa_tag_8021q_unregister(felix->dsa_8021q_ctx); + dsa_tag_8021q_unregister(ds); for (port = 0; port < ds->num_ports; port++) { if (dsa_is_unused_port(ds, port)) diff --git a/drivers/net/dsa/ocelot/felix.h b/drivers/net/dsa/ocelot/felix.h index 4d96cad815d5..9da3c6a94c6e 100644 --- a/drivers/net/dsa/ocelot/felix.h +++ b/drivers/net/dsa/ocelot/felix.h @@ -60,7 +60,6 @@ struct felix { struct lynx_pcs **pcs; resource_size_t switch_base; resource_size_t imdio_base; - struct dsa_8021q_context *dsa_8021q_ctx; enum dsa_tag_protocol tag_proto; }; diff --git a/drivers/net/dsa/sja1105/sja1105.h b/drivers/net/dsa/sja1105/sja1105.h index 869b19c08fc0..068be8afd322 100644 --- a/drivers/net/dsa/sja1105/sja1105.h +++ b/drivers/net/dsa/sja1105/sja1105.h @@ -257,7 +257,6 @@ struct sja1105_private { * the switch doesn't confuse them with one another. */ struct mutex mgmt_lock; - struct dsa_8021q_context *dsa_8021q_ctx; struct devlink_region **regions; struct sja1105_cbs_entry *cbs; struct mii_bus *mdio_base_t1; diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index 689f46797d1c..ac4254690a8d 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -1995,8 +1995,6 @@ static int sja1105_crosschip_bridge_join(struct dsa_switch *ds, int other_port, struct net_device *br) { struct dsa_switch *other_ds = dsa_switch_find(tree_index, sw_index); - struct sja1105_private *other_priv = other_ds->priv; - struct sja1105_private *priv = ds->priv; int port, rc; if (other_ds->ops != &sja1105_switch_ops) @@ -2008,17 +2006,13 @@ static int sja1105_crosschip_bridge_join(struct dsa_switch *ds, if (dsa_to_port(ds, port)->bridge_dev != br) continue; - rc = dsa_8021q_crosschip_bridge_join(priv->dsa_8021q_ctx, - port, - other_priv->dsa_8021q_ctx, + rc = dsa_8021q_crosschip_bridge_join(ds, port, other_ds, other_port); if (rc) return rc; - rc = dsa_8021q_crosschip_bridge_join(other_priv->dsa_8021q_ctx, - other_port, - priv->dsa_8021q_ctx, - port); + rc = dsa_8021q_crosschip_bridge_join(other_ds, other_port, + ds, port); if (rc) return rc; } @@ -2032,8 +2026,6 @@ static void sja1105_crosschip_bridge_leave(struct dsa_switch *ds, struct net_device *br) { struct dsa_switch *other_ds = dsa_switch_find(tree_index, sw_index); - struct sja1105_private *other_priv = other_ds->priv; - struct sja1105_private *priv = ds->priv; int port; if (other_ds->ops != &sja1105_switch_ops) @@ -2045,22 +2037,19 @@ static void sja1105_crosschip_bridge_leave(struct dsa_switch *ds, if (dsa_to_port(ds, port)->bridge_dev != br) continue; - dsa_8021q_crosschip_bridge_leave(priv->dsa_8021q_ctx, port, - other_priv->dsa_8021q_ctx, + dsa_8021q_crosschip_bridge_leave(ds, port, other_ds, other_port); - dsa_8021q_crosschip_bridge_leave(other_priv->dsa_8021q_ctx, - other_port, - priv->dsa_8021q_ctx, port); + dsa_8021q_crosschip_bridge_leave(other_ds, other_port, + ds, port); } } static int sja1105_setup_8021q_tagging(struct dsa_switch *ds, bool enabled) { - struct sja1105_private *priv = ds->priv; int rc; - rc = dsa_8021q_setup(priv->dsa_8021q_ctx, enabled); + rc = dsa_8021q_setup(ds, enabled); if (rc) return rc; @@ -2233,6 +2222,7 @@ static int sja1105_build_vlan_table(struct sja1105_private *priv, bool notify); static int sja1105_notify_crosschip_switches(struct sja1105_private *priv) { + struct dsa_8021q_context *ctx = priv->ds->tag_8021q_ctx; struct sja1105_crosschip_switch *s, *pos; struct list_head crosschip_switches; struct dsa_8021q_crosschip_link *c; @@ -2240,7 +2230,7 @@ static int sja1105_notify_crosschip_switches(struct sja1105_private *priv) INIT_LIST_HEAD(&crosschip_switches); - list_for_each_entry(c, &priv->dsa_8021q_ctx->crosschip_links, list) { + list_for_each_entry(c, &ctx->crosschip_links, list) { bool already_added = false; list_for_each_entry(s, &crosschip_switches, list) { @@ -3306,10 +3296,10 @@ static int sja1105_probe(struct spi_device *spi) mutex_init(&priv->ptp_data.lock); mutex_init(&priv->mgmt_lock); - priv->dsa_8021q_ctx = dsa_tag_8021q_register(ds, &sja1105_dsa_8021q_ops, - htons(ETH_P_8021Q)); - if (!priv->dsa_8021q_ctx) - return -ENOMEM; + rc = dsa_tag_8021q_register(ds, &sja1105_dsa_8021q_ops, + htons(ETH_P_8021Q)); + if (rc) + return rc; INIT_LIST_HEAD(&priv->bridge_vlans); INIT_LIST_HEAD(&priv->dsa_8021q_vlans); @@ -3373,7 +3363,7 @@ static int sja1105_probe(struct spi_device *spi) out_unregister_switch: dsa_unregister_switch(ds); out_tag_8021q_unregister: - dsa_tag_8021q_unregister(priv->dsa_8021q_ctx); + dsa_tag_8021q_unregister(ds); return rc; } @@ -3384,7 +3374,7 @@ static int sja1105_remove(struct spi_device *spi) struct dsa_switch *ds = priv->ds; dsa_unregister_switch(ds); - dsa_tag_8021q_unregister(priv->dsa_8021q_ctx); + dsa_tag_8021q_unregister(ds); return 0; } diff --git a/include/linux/dsa/8021q.h b/include/linux/dsa/8021q.h index 9945898a90c3..77939c0c8dd5 100644 --- a/include/linux/dsa/8021q.h +++ b/include/linux/dsa/8021q.h @@ -34,20 +34,20 @@ struct dsa_8021q_context { __be16 proto; }; -struct dsa_8021q_context *dsa_tag_8021q_register(struct dsa_switch *ds, - const struct dsa_8021q_ops *ops, - __be16 proto); +int dsa_tag_8021q_register(struct dsa_switch *ds, + const struct dsa_8021q_ops *ops, + __be16 proto); -void dsa_tag_8021q_unregister(struct dsa_8021q_context *ctx); +void dsa_tag_8021q_unregister(struct dsa_switch *ds); -int dsa_8021q_setup(struct dsa_8021q_context *ctx, bool enabled); +int dsa_8021q_setup(struct dsa_switch *ds, bool enabled); -int dsa_8021q_crosschip_bridge_join(struct dsa_8021q_context *ctx, int port, - struct dsa_8021q_context *other_ctx, +int dsa_8021q_crosschip_bridge_join(struct dsa_switch *ds, int port, + struct dsa_switch *other_ds, int other_port); -int dsa_8021q_crosschip_bridge_leave(struct dsa_8021q_context *ctx, int port, - struct dsa_8021q_context *other_ctx, +int dsa_8021q_crosschip_bridge_leave(struct dsa_switch *ds, int port, + struct dsa_switch *other_ds, int other_port); struct sk_buff *dsa_8021q_xmit(struct sk_buff *skb, struct net_device *netdev, diff --git a/include/net/dsa.h b/include/net/dsa.h index 33f40c1ec379..e213572f6341 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -352,6 +352,9 @@ struct dsa_switch { unsigned int ageing_time_min; unsigned int ageing_time_max; + /* Storage for drivers using tag_8021q */ + struct dsa_8021q_context *tag_8021q_ctx; + /* devlink used to represent this switch device */ struct devlink *devlink; diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index 16eb2c7bcc8d..de46a551a486 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -113,10 +113,11 @@ EXPORT_SYMBOL_GPL(vid_is_dsa_8021q); * user explicitly configured this @vid through the bridge core, then the @vid * is installed again, but this time with the flags from the bridge layer. */ -static int dsa_8021q_vid_apply(struct dsa_8021q_context *ctx, int port, u16 vid, +static int dsa_8021q_vid_apply(struct dsa_switch *ds, int port, u16 vid, u16 flags, bool enabled) { - struct dsa_port *dp = dsa_to_port(ctx->ds, port); + struct dsa_8021q_context *ctx = ds->tag_8021q_ctx; + struct dsa_port *dp = dsa_to_port(ds, port); if (enabled) return ctx->ops->vlan_add(ctx->ds, dp->index, vid, flags); @@ -176,29 +177,29 @@ static int dsa_8021q_vid_apply(struct dsa_8021q_context *ctx, int port, u16 vid, * +-+-----+-+-----+-+-----+-+-----+-+ +-+-----+-+-----+-+-----+-+-----+-+ * swp0 swp1 swp2 swp3 swp0 swp1 swp2 swp3 */ -static int dsa_8021q_setup_port(struct dsa_8021q_context *ctx, int port, - bool enabled) +static int dsa_8021q_setup_port(struct dsa_switch *ds, int port, bool enabled) { - int upstream = dsa_upstream_port(ctx->ds, port); - u16 rx_vid = dsa_8021q_rx_vid(ctx->ds, port); - u16 tx_vid = dsa_8021q_tx_vid(ctx->ds, port); + struct dsa_8021q_context *ctx = ds->tag_8021q_ctx; + int upstream = dsa_upstream_port(ds, port); + u16 rx_vid = dsa_8021q_rx_vid(ds, port); + u16 tx_vid = dsa_8021q_tx_vid(ds, port); struct net_device *master; int i, err; /* The CPU port is implicitly configured by * configuring the front-panel ports */ - if (!dsa_is_user_port(ctx->ds, port)) + if (!dsa_is_user_port(ds, port)) return 0; - master = dsa_to_port(ctx->ds, port)->cpu_dp->master; + master = dsa_to_port(ds, port)->cpu_dp->master; /* Add this user port's RX VID to the membership list of all others * (including itself). This is so that bridging will not be hindered. * L2 forwarding rules still take precedence when there are no VLAN * restrictions, so there are no concerns about leaking traffic. */ - for (i = 0; i < ctx->ds->num_ports; i++) { + for (i = 0; i < ds->num_ports; i++) { u16 flags; if (i == upstream) @@ -211,9 +212,9 @@ static int dsa_8021q_setup_port(struct dsa_8021q_context *ctx, int port, /* The RX VID is a regular VLAN on all others */ flags = BRIDGE_VLAN_INFO_UNTAGGED; - err = dsa_8021q_vid_apply(ctx, i, rx_vid, flags, enabled); + err = dsa_8021q_vid_apply(ds, i, rx_vid, flags, enabled); if (err) { - dev_err(ctx->ds->dev, + dev_err(ds->dev, "Failed to apply RX VID %d to port %d: %pe\n", rx_vid, port, ERR_PTR(err)); return err; @@ -223,9 +224,9 @@ static int dsa_8021q_setup_port(struct dsa_8021q_context *ctx, int port, /* CPU port needs to see this port's RX VID * as tagged egress. */ - err = dsa_8021q_vid_apply(ctx, upstream, rx_vid, 0, enabled); + err = dsa_8021q_vid_apply(ds, upstream, rx_vid, 0, enabled); if (err) { - dev_err(ctx->ds->dev, + dev_err(ds->dev, "Failed to apply RX VID %d to port %d: %pe\n", rx_vid, port, ERR_PTR(err)); return err; @@ -238,17 +239,17 @@ static int dsa_8021q_setup_port(struct dsa_8021q_context *ctx, int port, vlan_vid_del(master, ctx->proto, rx_vid); /* Finally apply the TX VID on this port and on the CPU port */ - err = dsa_8021q_vid_apply(ctx, port, tx_vid, BRIDGE_VLAN_INFO_UNTAGGED, + err = dsa_8021q_vid_apply(ds, port, tx_vid, BRIDGE_VLAN_INFO_UNTAGGED, enabled); if (err) { - dev_err(ctx->ds->dev, + dev_err(ds->dev, "Failed to apply TX VID %d on port %d: %pe\n", tx_vid, port, ERR_PTR(err)); return err; } - err = dsa_8021q_vid_apply(ctx, upstream, tx_vid, 0, enabled); + err = dsa_8021q_vid_apply(ds, upstream, tx_vid, 0, enabled); if (err) { - dev_err(ctx->ds->dev, + dev_err(ds->dev, "Failed to apply TX VID %d on port %d: %pe\n", tx_vid, upstream, ERR_PTR(err)); return err; @@ -257,16 +258,16 @@ static int dsa_8021q_setup_port(struct dsa_8021q_context *ctx, int port, return err; } -int dsa_8021q_setup(struct dsa_8021q_context *ctx, bool enabled) +int dsa_8021q_setup(struct dsa_switch *ds, bool enabled) { int err, port; ASSERT_RTNL(); - for (port = 0; port < ctx->ds->num_ports; port++) { - err = dsa_8021q_setup_port(ctx, port, enabled); + for (port = 0; port < ds->num_ports; port++) { + err = dsa_8021q_setup_port(ds, port, enabled); if (err < 0) { - dev_err(ctx->ds->dev, + dev_err(ds->dev, "Failed to setup VLAN tagging for port %d: %pe\n", port, ERR_PTR(err)); return err; @@ -277,24 +278,25 @@ int dsa_8021q_setup(struct dsa_8021q_context *ctx, bool enabled) } EXPORT_SYMBOL_GPL(dsa_8021q_setup); -static int dsa_8021q_crosschip_link_apply(struct dsa_8021q_context *ctx, - int port, - struct dsa_8021q_context *other_ctx, +static int dsa_8021q_crosschip_link_apply(struct dsa_switch *ds, int port, + struct dsa_switch *other_ds, int other_port, bool enabled) { - u16 rx_vid = dsa_8021q_rx_vid(ctx->ds, port); + u16 rx_vid = dsa_8021q_rx_vid(ds, port); /* @rx_vid of local @ds port @port goes to @other_port of * @other_ds */ - return dsa_8021q_vid_apply(other_ctx, other_port, rx_vid, + return dsa_8021q_vid_apply(other_ds, other_port, rx_vid, BRIDGE_VLAN_INFO_UNTAGGED, enabled); } -static int dsa_8021q_crosschip_link_add(struct dsa_8021q_context *ctx, int port, - struct dsa_8021q_context *other_ctx, +static int dsa_8021q_crosschip_link_add(struct dsa_switch *ds, int port, + struct dsa_switch *other_ds, int other_port) { + struct dsa_8021q_context *other_ctx = other_ds->tag_8021q_ctx; + struct dsa_8021q_context *ctx = ds->tag_8021q_ctx; struct dsa_8021q_crosschip_link *c; list_for_each_entry(c, &ctx->crosschip_links, list) { @@ -305,9 +307,9 @@ static int dsa_8021q_crosschip_link_add(struct dsa_8021q_context *ctx, int port, } } - dev_dbg(ctx->ds->dev, + dev_dbg(ds->dev, "adding crosschip link from port %d to %s port %d\n", - port, dev_name(other_ctx->ds->dev), other_port); + port, dev_name(other_ds->dev), other_port); c = kzalloc(sizeof(*c), GFP_KERNEL); if (!c) @@ -323,7 +325,7 @@ static int dsa_8021q_crosschip_link_add(struct dsa_8021q_context *ctx, int port, return 0; } -static void dsa_8021q_crosschip_link_del(struct dsa_8021q_context *ctx, +static void dsa_8021q_crosschip_link_del(struct dsa_switch *ds, struct dsa_8021q_crosschip_link *c, bool *keep) { @@ -332,7 +334,7 @@ static void dsa_8021q_crosschip_link_del(struct dsa_8021q_context *ctx, if (*keep) return; - dev_dbg(ctx->ds->dev, + dev_dbg(ds->dev, "deleting crosschip link from port %d to %s port %d\n", c->port, dev_name(c->other_ctx->ds->dev), c->other_port); @@ -347,8 +349,8 @@ static void dsa_8021q_crosschip_link_del(struct dsa_8021q_context *ctx, * or untagged: it doesn't matter, since it should never egress a frame having * our @rx_vid. */ -int dsa_8021q_crosschip_bridge_join(struct dsa_8021q_context *ctx, int port, - struct dsa_8021q_context *other_ctx, +int dsa_8021q_crosschip_bridge_join(struct dsa_switch *ds, int port, + struct dsa_switch *other_ds, int other_port) { /* @other_upstream is how @other_ds reaches us. If we are part @@ -356,49 +358,50 @@ int dsa_8021q_crosschip_bridge_join(struct dsa_8021q_context *ctx, int port, * our CPU ports. If we're part of the same tree though, we should * probably use dsa_towards_port. */ - int other_upstream = dsa_upstream_port(other_ctx->ds, other_port); + int other_upstream = dsa_upstream_port(other_ds, other_port); int err; - err = dsa_8021q_crosschip_link_add(ctx, port, other_ctx, other_port); + err = dsa_8021q_crosschip_link_add(ds, port, other_ds, other_port); if (err) return err; - err = dsa_8021q_crosschip_link_apply(ctx, port, other_ctx, + err = dsa_8021q_crosschip_link_apply(ds, port, other_ds, other_port, true); if (err) return err; - err = dsa_8021q_crosschip_link_add(ctx, port, other_ctx, other_upstream); + err = dsa_8021q_crosschip_link_add(ds, port, other_ds, other_upstream); if (err) return err; - return dsa_8021q_crosschip_link_apply(ctx, port, other_ctx, + return dsa_8021q_crosschip_link_apply(ds, port, other_ds, other_upstream, true); } EXPORT_SYMBOL_GPL(dsa_8021q_crosschip_bridge_join); -int dsa_8021q_crosschip_bridge_leave(struct dsa_8021q_context *ctx, int port, - struct dsa_8021q_context *other_ctx, +int dsa_8021q_crosschip_bridge_leave(struct dsa_switch *ds, int port, + struct dsa_switch *other_ds, int other_port) { - int other_upstream = dsa_upstream_port(other_ctx->ds, other_port); + struct dsa_8021q_context *other_ctx = other_ds->tag_8021q_ctx; + int other_upstream = dsa_upstream_port(other_ds, other_port); + struct dsa_8021q_context *ctx = ds->tag_8021q_ctx; struct dsa_8021q_crosschip_link *c, *n; list_for_each_entry_safe(c, n, &ctx->crosschip_links, list) { if (c->port == port && c->other_ctx == other_ctx && (c->other_port == other_port || c->other_port == other_upstream)) { - struct dsa_8021q_context *other_ctx = c->other_ctx; int other_port = c->other_port; bool keep; int err; - dsa_8021q_crosschip_link_del(ctx, c, &keep); + dsa_8021q_crosschip_link_del(ds, c, &keep); if (keep) continue; - err = dsa_8021q_crosschip_link_apply(ctx, port, - other_ctx, + err = dsa_8021q_crosschip_link_apply(ds, port, + other_ds, other_port, false); if (err) @@ -410,15 +413,15 @@ int dsa_8021q_crosschip_bridge_leave(struct dsa_8021q_context *ctx, int port, } EXPORT_SYMBOL_GPL(dsa_8021q_crosschip_bridge_leave); -struct dsa_8021q_context *dsa_tag_8021q_register(struct dsa_switch *ds, - const struct dsa_8021q_ops *ops, - __be16 proto) +int dsa_tag_8021q_register(struct dsa_switch *ds, + const struct dsa_8021q_ops *ops, + __be16 proto) { struct dsa_8021q_context *ctx; ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); if (!ctx) - return NULL; + return -ENOMEM; ctx->ops = ops; ctx->proto = proto; @@ -426,12 +429,15 @@ struct dsa_8021q_context *dsa_tag_8021q_register(struct dsa_switch *ds, INIT_LIST_HEAD(&ctx->crosschip_links); - return ctx; + ds->tag_8021q_ctx = ctx; + + return 0; } EXPORT_SYMBOL_GPL(dsa_tag_8021q_register); -void dsa_tag_8021q_unregister(struct dsa_8021q_context *ctx) +void dsa_tag_8021q_unregister(struct dsa_switch *ds) { + struct dsa_8021q_context *ctx = ds->tag_8021q_ctx; struct dsa_8021q_crosschip_link *c, *n; list_for_each_entry_safe(c, n, &ctx->crosschip_links, list) { @@ -439,6 +445,8 @@ void dsa_tag_8021q_unregister(struct dsa_8021q_context *ctx) kfree(c); } + ds->tag_8021q_ctx = NULL; + kfree(ctx); } EXPORT_SYMBOL_GPL(dsa_tag_8021q_unregister); From patchwork Mon Jul 19 17:14:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 480293 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.7 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 3416EC07E9D for ; Mon, 19 Jul 2021 17:24:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 16D376112D for ; Mon, 19 Jul 2021 17:24:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351616AbhGSQn0 (ORCPT ); Mon, 19 Jul 2021 12:43:26 -0400 Received: from mail-eopbgr70082.outbound.protection.outlook.com ([40.107.7.82]:25006 "EHLO EUR04-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1355146AbhGSQf6 (ORCPT ); Mon, 19 Jul 2021 12:35:58 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=oLr0fvE/hUh6p0WioyqbKdI0SUWykbuNy0xioJOYBJJR9hDEN+ePNGboS20FAxmkcgcfm73T75pX+Utt4TwGR2pIwmBosLfIiiM1SQQar9re31vdBNfJ6+LVR2XhjvTRsBOj/U8O/94qED623Oesj0hXrqprJA5ZH0ZZL0kVfof79MYzLfKEZae4K/63PIX9CSyeA6tSCvk9ZfwpwlCxl7FwOkbHzoUtJfBUUKIhCiJamPddwMiluqc/znmMsSsb0+0B/cz5SVDt9bCGG4wl47/DATNS6e/T+je/yc+ZpXEYJvXvTC2U0TJZl6KTX+zk0SnCNbootb1nQFD8ZKX15g== 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=qHYBsBCAgaiqdp7W5U2hsYTA+jRd5AgSicDx22hEKMI=; b=OqsaLlS9fmZYdtfFF0z/bM5udfuOE+wTfzk6xmGv2+UCTIV1XKdiZdUdluRA0Dv71eMJayUmNo6EszVzJ5UAREDzggbXB33qSsUHICKOD9aufHSbGLzB8lFqO+wavrZCJA4YveOGqwWzA1pq8sgrAt3hyyF3PLja/D0E/Hry+JWUWMtraRRPAFmRv6LuoQ7uEhg4UVDneug9BfwhaITaJFGNyIgHQ9eIBn+2lSUXJ6EugrRfLk8LDTgui5kyGfshbZXx5Q9i40MA0rjgSb98mhNmw1WRUJeKA9U+2dSSb55yg8lB0ultvYdRta+BN4MUZ9izlixCgm/rpS7UUyyEIA== 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=qHYBsBCAgaiqdp7W5U2hsYTA+jRd5AgSicDx22hEKMI=; b=MKOu33dEhpuJB0lgWzZQVQS/nJ30SGTFS/YeJI6CxBikREDX+7fVse+E9WboTWnPMGoX6fBRodirFXimK4HC6Z5LwfL2ofQY1wZ4ih+Kj2ydvQPyZwD5v05OsCk5Ajm4WLgJcQZVjdUHLb/8+KOkk7DgwWwmuxQqtrhpzFlTGmM= 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 VI1PR0402MB3407.eurprd04.prod.outlook.com (2603:10a6:803:5::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Mon, 19 Jul 2021 17:16:11 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0%2]) with mapi id 15.20.4331.032; Mon, 19 Jul 2021 17:16:11 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot Subject: [PATCH net-next 08/11] net: dsa: make tag_8021q operations part of the core Date: Mon, 19 Jul 2021 20:14:49 +0300 Message-Id: <20210719171452.463775-9-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210719171452.463775-1-vladimir.oltean@nxp.com> References: <20210719171452.463775-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR10CA0038.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::18) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by AM0PR10CA0038.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Mon, 19 Jul 2021 17:16:10 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 43b2d8d1-e544-4e22-b412-08d94ad8e7ef X-MS-TrafficTypeDiagnostic: VI1PR0402MB3407: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: k5bN5Vwzi3/7FbnLZuh8SOcyzgGzR3yCay6su+31Cr3Eb7sAeTit/SgCYZtrjuy6RyunD7kod0TC5hbawqkaEU+J3dwOhReEJ/WNF6viY8YfvUfQh/3TUTz/VSogDrYD4oZlL+KIF/9MAePgg0VCtolLcoD2bmcJF8q4Q6epHCD8hl2s7tx2SBuYmq2xnGi+CQhqZcvZbg5INzJskflDWf7bxVy/7B7vc4YYeInrZGkRjGfqFlUU+QQn8N/SagVOgHq5s2N+W0dTBIQc8CId+dZudfIEcsxA9A+LdYN5mIvW+dk7f0ycj+3hD+yPupLNIQTZapNc6k6lFYJS2zbgehafos17rP3l7P+pyCVSKs4ZV493e8zZTtbUtX9lYpDRzJjc+ioBFmBW0CxlsaT+MxiYF8RfLij2v1024AL8hXOEVwFpAaPqaEXpMneIr9OXYyTu0skKol23lJ21QKNxtANV2IPCzXWppi1PY9JouknGUwMHL2CftwJhTjiz5PYOoVOmc5mKl+i6FFjneBxVtRCg9ntl/knbjznVyviEDX39nWGrUaEyNmjM1K7ATNxLnrZGoWq2RxfjYAWyCC+WDg2L0C6UqtQ02/lsLrlK+YxdvGZPjKYKjjw03+287m0uQEeyOg8yCC/5yNrYSJaK6CY017J+TRzEtJK8PLpS8IpwlY7nQ5PfHebkRYX5ej7qKNbnFfhrSxy1Yv4LEovAqw== 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)(39850400004)(396003)(366004)(136003)(346002)(376002)(6666004)(6512007)(86362001)(36756003)(52116002)(8676002)(8936002)(6506007)(83380400001)(316002)(5660300002)(66476007)(4326008)(66946007)(66556008)(110136005)(2616005)(956004)(1076003)(6486002)(54906003)(38350700002)(478600001)(38100700002)(186003)(44832011)(2906002)(26005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: XCLZkgMWZi/AgSioLsvf+gxXdUWrg2QLbiy5/fD8JEISMk85BX4btUwPIJYOwOMPqvSlpCSgaBFBhL2CFf99iEBFSZBNJTTEJ1YyGhF6RNsSOXvByja9Z+dC0iU8ZjANLuTUjnWxUUcU/wnaDvHFO4RmYs/UUgXciUi/+4//N/DHg/r5XfKBuv/pz+nAYEv1Dtqql6m+DCaHvmYBfPVqwdiGuO8IOco9tYY+61LuBJGh61fOWSMFUpfO9ZAiC5SJatB97djqt4X7qCoKVzp2GWf1oG4sKLFO7IwDe+ODiomqGZJuY8Dy9fkGEiA3hVhAnlVqsaFspy820pqowE2nfQtyd4UqHgcdKukkYd7T7Cubuw7MDxDC4hY3Pq1/XA+4KS3uPkGHjZ5Z/QodTkW3jxC2DMBQt8xMnLL0RmN45KEJ0YASEaXSahfxtSRSL5NI62Bagtjx8OiKvgk8DGoIC/dnsve+F7J5Z1gKzQw5t0n4n/l3GOpeRv7ar52Nqt/tkzM0ukc78Hs3ssQHB40R65aS6j3GG4UE3/CQX5yY4yEXjGV3D5vV9ZmZcKQO5MdS6M1zIP2mkMDve7CNkM6Xdr72I1Nm3RnxDPm7NF9E/Yh6w9zWU7/+VGXz0aQ9QbrsAaGMNy6GOCiJxcGyxhc+ahaIB1xhDyeaoId+c8iyAPqhe8JFRpgTAuQoOUIRszAdmVYUcO6DEvQaEyUCJeMvLYMf0k7vKO66gJWrEZ53G/d1prhpbRwk7lfzwPoqxeqkLwxVCsFkx/p8b3dwgwU6b01EcllM3j78D4wvUc/t8HoAwJNso68JijOMNGc/kNG9m0JrAZANGVGkcSXL27tlFXO9ImNd0W1yfevUKmRq+aTi7ox2pkgn1OIiygL/GlKuUy1+wOqqmN3oj9lWV7JCJU/+mvZK8Bw3pxhb8ldEs7Y5bJhGpc5Wlv5wNbiPvXfXNq4CLP5SXScK8IQk77ZZtws6NLQ/FePpvcDqyzDwzvhPMnm02nQ6BvsiMMODl3mveiMdJ3YpO6hEywwlh0Sdh1xFd/lpNXuDsn2N1WA+PG0lP2Mzx1vIMZ9BZhOj4RTx7e5niuvwnPc101iMKKSlD3mg2Jt0CEdAPR1GnhnLZMjfGtvTRoQ4tds+9WYzvgZwtZ5cTOdrNrcXMUnxZ1lkCvNWXh1FOz+PRcefu6h/hvAJU9s5zBrBjQDsVGWHT8Map09a/ZLkQpS3L2XafLoIOhpLIRziQMq4VEMVV5XAxTuna/yiErE6nRDJ9WfDhzFHvVjM11V8SkJMaBK4Id5bJiKv82c81t3O+9XxYwQeDrY7Z7SepTZMZXgkp836nLdE X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 43b2d8d1-e544-4e22-b412-08d94ad8e7ef X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2021 17:16:11.6102 (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: 4nPQCjC+PS2rr5Ka7YgEkkUS96Ft59ayh5dxPX1YAcdyQaT2QqmbIgdEd3FHYIewatZ239flTo9vz83pbuJ00w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3407 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Make tag_8021q a more central element of DSA and move the 2 driver specific operations outside of struct dsa_8021q_context (which is supposed to hold dynamic data and not really constant function pointers). Signed-off-by: Vladimir Oltean --- drivers/net/dsa/ocelot/felix.c | 10 +++------- drivers/net/dsa/sja1105/sja1105_main.c | 10 +++------- include/linux/dsa/8021q.h | 10 +--------- include/net/dsa.h | 7 +++++++ net/dsa/tag_8021q.c | 10 +++------- 5 files changed, 17 insertions(+), 30 deletions(-) diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c index 9e4ae15aa4fb..b6ab28d2f155 100644 --- a/drivers/net/dsa/ocelot/felix.c +++ b/drivers/net/dsa/ocelot/felix.c @@ -231,11 +231,6 @@ static int felix_tag_8021q_vlan_del(struct dsa_switch *ds, int port, u16 vid) return 0; } -static const struct dsa_8021q_ops felix_tag_8021q_ops = { - .vlan_add = felix_tag_8021q_vlan_add, - .vlan_del = felix_tag_8021q_vlan_del, -}; - /* Alternatively to using the NPI functionality, that same hardware MAC * connected internally to the enetc or fman DSA master can be configured to * use the software-defined tag_8021q frame format. As far as the hardware is @@ -425,8 +420,7 @@ static int felix_setup_tag_8021q(struct dsa_switch *ds, int cpu) ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_MC); ocelot_rmw_rix(ocelot, 0, cpu_flood, ANA_PGID_PGID, PGID_BC); - err = dsa_tag_8021q_register(ds, &felix_tag_8021q_ops, - htons(ETH_P_8021AD)); + err = dsa_tag_8021q_register(ds, htons(ETH_P_8021AD)); if (err) return err; @@ -1675,6 +1669,8 @@ const struct dsa_switch_ops felix_switch_ops = { .port_mrp_del = felix_mrp_del, .port_mrp_add_ring_role = felix_mrp_add_ring_role, .port_mrp_del_ring_role = felix_mrp_del_ring_role, + .tag_8021q_vlan_add = felix_tag_8021q_vlan_add, + .tag_8021q_vlan_del = felix_tag_8021q_vlan_del, }; struct net_device *felix_port_to_netdev(struct ocelot *ocelot, int port) diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index ac4254690a8d..0c04f6caccdf 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -2543,11 +2543,6 @@ static int sja1105_dsa_8021q_vlan_del(struct dsa_switch *ds, int port, u16 vid) return sja1105_build_vlan_table(priv, true); } -static const struct dsa_8021q_ops sja1105_dsa_8021q_ops = { - .vlan_add = sja1105_dsa_8021q_vlan_add, - .vlan_del = sja1105_dsa_8021q_vlan_del, -}; - /* The programming model for the SJA1105 switch is "all-at-once" via static * configuration tables. Some of these can be dynamically modified at runtime, * but not the xMII mode parameters table. @@ -3153,6 +3148,8 @@ static const struct dsa_switch_ops sja1105_switch_ops = { .crosschip_bridge_join = sja1105_crosschip_bridge_join, .crosschip_bridge_leave = sja1105_crosschip_bridge_leave, .devlink_info_get = sja1105_devlink_info_get, + .tag_8021q_vlan_add = sja1105_dsa_8021q_vlan_add, + .tag_8021q_vlan_del = sja1105_dsa_8021q_vlan_del, }; static const struct of_device_id sja1105_dt_ids[]; @@ -3296,8 +3293,7 @@ static int sja1105_probe(struct spi_device *spi) mutex_init(&priv->ptp_data.lock); mutex_init(&priv->mgmt_lock); - rc = dsa_tag_8021q_register(ds, &sja1105_dsa_8021q_ops, - htons(ETH_P_8021Q)); + rc = dsa_tag_8021q_register(ds, htons(ETH_P_8021Q)); if (rc) return rc; diff --git a/include/linux/dsa/8021q.h b/include/linux/dsa/8021q.h index 77939c0c8dd5..0bda08fb2f16 100644 --- a/include/linux/dsa/8021q.h +++ b/include/linux/dsa/8021q.h @@ -21,22 +21,14 @@ struct dsa_8021q_crosschip_link { refcount_t refcount; }; -struct dsa_8021q_ops { - int (*vlan_add)(struct dsa_switch *ds, int port, u16 vid, u16 flags); - int (*vlan_del)(struct dsa_switch *ds, int port, u16 vid); -}; - struct dsa_8021q_context { - const struct dsa_8021q_ops *ops; struct dsa_switch *ds; struct list_head crosschip_links; /* EtherType of RX VID, used for filtering on master interface */ __be16 proto; }; -int dsa_tag_8021q_register(struct dsa_switch *ds, - const struct dsa_8021q_ops *ops, - __be16 proto); +int dsa_tag_8021q_register(struct dsa_switch *ds, __be16 proto); void dsa_tag_8021q_unregister(struct dsa_switch *ds); diff --git a/include/net/dsa.h b/include/net/dsa.h index e213572f6341..9e5593885357 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -872,6 +872,13 @@ struct dsa_switch_ops { const struct switchdev_obj_ring_role_mrp *mrp); int (*port_mrp_del_ring_role)(struct dsa_switch *ds, int port, const struct switchdev_obj_ring_role_mrp *mrp); + + /* + * tag_8021q operations + */ + int (*tag_8021q_vlan_add)(struct dsa_switch *ds, int port, u16 vid, + u16 flags); + int (*tag_8021q_vlan_del)(struct dsa_switch *ds, int port, u16 vid); }; #define DSA_DEVLINK_PARAM_DRIVER(_id, _name, _type, _cmodes) \ diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index de46a551a486..4a11c5004783 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -116,13 +116,12 @@ EXPORT_SYMBOL_GPL(vid_is_dsa_8021q); static int dsa_8021q_vid_apply(struct dsa_switch *ds, int port, u16 vid, u16 flags, bool enabled) { - struct dsa_8021q_context *ctx = ds->tag_8021q_ctx; struct dsa_port *dp = dsa_to_port(ds, port); if (enabled) - return ctx->ops->vlan_add(ctx->ds, dp->index, vid, flags); + return ds->ops->tag_8021q_vlan_add(ds, dp->index, vid, flags); - return ctx->ops->vlan_del(ctx->ds, dp->index, vid); + return ds->ops->tag_8021q_vlan_del(ds, dp->index, vid); } /* RX VLAN tagging (left) and TX VLAN tagging (right) setup shown for a single @@ -413,9 +412,7 @@ int dsa_8021q_crosschip_bridge_leave(struct dsa_switch *ds, int port, } EXPORT_SYMBOL_GPL(dsa_8021q_crosschip_bridge_leave); -int dsa_tag_8021q_register(struct dsa_switch *ds, - const struct dsa_8021q_ops *ops, - __be16 proto) +int dsa_tag_8021q_register(struct dsa_switch *ds, __be16 proto) { struct dsa_8021q_context *ctx; @@ -423,7 +420,6 @@ int dsa_tag_8021q_register(struct dsa_switch *ds, if (!ctx) return -ENOMEM; - ctx->ops = ops; ctx->proto = proto; ctx->ds = ds; From patchwork Mon Jul 19 17:14:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 480294 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.7 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 125A1C6499D for ; Mon, 19 Jul 2021 17:22:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EEEA56108B for ; Mon, 19 Jul 2021 17:22:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1351676AbhGSQlz (ORCPT ); Mon, 19 Jul 2021 12:41:55 -0400 Received: from mail-eopbgr70082.outbound.protection.outlook.com ([40.107.7.82]:25006 "EHLO EUR04-HE1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1355210AbhGSQgH (ORCPT ); Mon, 19 Jul 2021 12:36:07 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IhHeqeOoT4ForMjr+ySiX0W6IQtDXqGymxC/AT6vy7WJ2tA0E8yQEBKpeWeaq28UmUzu8H2BaTSmn06S+GdrgETFBCGpFQVJY7jF2ppPyS3huDjBZfeoTzc+8253ogopfA52ID/40vUTzmt49vpXyLi2NbUzWSfkHDT5ur0ylJTZVPrM/NBW2PqsdHPmJv79tc9CcLaCnepq5GfLjajiQfUjiXGm1zvQOS4Y8fVTKL5Jg1iQ7l/CmMBUYleiPpbAesxKtQE15DWPTCm/c6i/xZHfsblnENEDlJAKGydZGK21vwm14gkKw8cXLSXoeDHjLdszE+oBTdVP5mwtpCdm/g== 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=Y4MYLY7D0KitytZZulKcckN7CIJ5cnYG2d/lPjXl2Ms=; b=KSZwc6tFsVNjeb85YFfj9W4oQLoJxsIUV2yjHbcQChIwdJ6vOv9BPS1IzB2BIzeGMIte6/xQlJXQFDDoz10y9xLRXR9hwRJSPIc5g4wTWm4eyoQ3J5qqUBXa540C9oiD1G4TvDGvSs64S3745j9wDhdtJtdQnlvug8Ko7JDbPk6kOx0zf9CyIxZ6CLAQJM9tEJJ3Ztc+xEuRY6M+efgAfo5/tXcHTFrXDW5OPZwyXlBo/fIrfKXPcfOgSRpYgEQwEQZ48caKlGnUrUwSlvDAeZsBC+Sps1Rh3zE1IZBOWwsJqtfOwQ5TL0pJ5metCQoLgwXKVKhA4YD4aM60H/xEXw== 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=Y4MYLY7D0KitytZZulKcckN7CIJ5cnYG2d/lPjXl2Ms=; b=S2HwJIDW8XCJMLlrBXa8GtAlxpZ/zoajQAGoBkHbHHN0IHLwJ5etxYhZYjx5Xw6ymMXkVa2+bMtD2QFh31iT2Gob6O3vqJ3KLU1MLc4p66IVYEcSk7DFpFGoPsjUR2PEqJbI3Wb4stgswHNEn7aGCiRiZBMEUwZ9R5E2RpR/FNc= 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 VI1PR0402MB3407.eurprd04.prod.outlook.com (2603:10a6:803:5::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21; Mon, 19 Jul 2021 17:16:13 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::109:1995:3e6b:5bd0%2]) with mapi id 15.20.4331.032; Mon, 19 Jul 2021 17:16:13 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Andrew Lunn , Florian Fainelli , Vivien Didelot Subject: [PATCH net-next 10/11] net: dsa: tag_8021q: manage RX VLANs dynamically at bridge join/leave time Date: Mon, 19 Jul 2021 20:14:51 +0300 Message-Id: <20210719171452.463775-11-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210719171452.463775-1-vladimir.oltean@nxp.com> References: <20210719171452.463775-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR10CA0038.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::18) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from localhost.localdomain (82.76.66.29) by AM0PR10CA0038.EURPRD10.PROD.OUTLOOK.COM (2603:10a6:20b:150::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4331.21 via Frontend Transport; Mon, 19 Jul 2021 17:16:12 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 83820bdf-113d-4d0a-9fc1-08d94ad8e918 X-MS-TrafficTypeDiagnostic: VI1PR0402MB3407: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:10000; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3WuZ1O2jGF4U4lFytKvB9PNYFFa+M/KTfcNvaZrS35rjvOKxfzyguI4YPUnKbEkjuZtURA8Eje8mVUdMoq7C6d0Tm4/d0YpyNyT0Ny6s5mMp/1BQNIArb9hTINZJm3HSFv0QotJtK42gltqClVNvzr5G/9VbQV5JPr9RQTdZcLZkpAcLgEvB1Y9sDVU5QZtYENGDC8NgWUnv17DS194OT+s8+nn08Gy7iB80p3RFFI4vtfKhz0NS7gPXTOs3oVBFL3iFX5ORqLikfoCZvxwHDC/AvGoXqKTSQTIyuYQRWCaGz0v99nx5Qx9WcCwEKbpfFi40lsmQdaN514edtmfQKl6NkIKOXJ1r+feHkrXyctB4N2KjiOkNEGTKkmJ6sKlObRHP5NS2szxA/o/oI9JW3clm+QcbAGMZmSkrgQ+s7mD35XT6x+lOMBfZzWAA2wb7RpzqmZpU/qoCnr2DSAxWv//WYlgnPJyL97gcV1mozwaQQM++1/b9tDXTxR+BPJmMMOBnAb1Yr8VXChNgLMmsIsdEaYtbGqy2q5U7cMV7jec8X7Z19ROGKMSl6xYt3W1UA+yd7YKJZ9i5IGKGNgVCU97w1ZnrbFtOCkDEhAr3mK4zhBTUSBhHPdXXTg+fZJ0yZM9Wl1J5gug8oggfJS8qiw== 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)(39850400004)(396003)(366004)(136003)(346002)(376002)(6666004)(6512007)(86362001)(36756003)(52116002)(30864003)(8676002)(8936002)(6506007)(83380400001)(316002)(5660300002)(66476007)(4326008)(66946007)(66556008)(110136005)(2616005)(956004)(1076003)(6486002)(54906003)(38350700002)(478600001)(38100700002)(186003)(44832011)(2906002)(26005)(966005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NBKF8p12u9NhWQlBhZucN74MaHvqN28IwnEKOCAnCrl3dS3Ll8x1vZ+0vpSIC6BSxlfiBma8JKELAi2f511NelB0L5TDWVmXwZg5lYZcfn7AKSUsZY8LXMYWPB1ULpG0phhuMcOAE40tWB511g5fuHfRLexKn1xsAvJGgZnTUtZtczA042lPqXHWS4hOPJMgHHa+Pkk/UKz7FDTT11iXMIF9fRg/MyE3WTBxGEy/J3uRsIl/4vqVP92apBmGXelQHbkrSTII+v8hprBxd4tjqKVNYPw/WkbWakNg/EVHvJbRxdC204m/cMi0npipNDqKx6PFGKl7OefC0bXO53ph3ptI1rOpPJZCjP0Fkgu0Q7ryGBh+4yDX26ipQocM404fZY2sAzLbEcW8Rye/Cp0xr8khH7KbeIZxn15/F7Cds1CE8oJxi0ci4jdA3H9peu3FR2+7Ks/ManGU8ONRFghWatXMmRH+2qsFaVVpUArCowWAFHI25EQwoj8MipIn/vZHAamvchOt6QRQ2bDwn1e28Zs6W2i1n2ZcsRHFqwTxqj1iInrwQRPS6t3kK/JiL6WXPMx7qjdC77Erq61SUrqhF0nxIY5UpCQaILEmjqiOctcCAfmM6rCN+YTSMOHCnyY/k/sAz3YK/POfxJvUv/TwCrNm32KeHrttXi6HcdljTboZfBf9T9JVnKW/2reJ7bc7TqRsKRKp1GMCcgTx6v6BvsxqVHfJkg+xB3G0qD1+8xhhytsavect7iodM11o0GX6AXzKY86m1wmnjp/OoW9l2Sb8qjz4lkOXOOtLhFaeam1qfB0ByWYxnweRdpohLdHFgC1GJYdrFiY6S+j4LSc1Exfi0RNHVtuw6iQXgA4stfoDU3ntNajKpXTNf3VkCJkMXVkEDmnljVjLPlUEJSGFnoGACmmoA2b5dsg26DgV/oN7YVVYtzNHbdA7prKHPU37VllKBTQ2+tmr8jHWjdYYY4zvJBQHF/jTebqlv02swOd4kT6gedOjsgwmbKrVDG1DlcTt6VNI0vpd0+HQso2LH9nH8B8tp9vCfZMLS5RAvUyNJbq1yUYIPZz85pAxwFlhLWozKIFuQv4cVB4rEUSNSzEk0iGTbbV4uFj8FrAICH5d5GngUwTA6UPenZ/CWAk2e4tY6MYio8gdA7rmT4t3aEhflu3CejN8UwpT1yp665lsd0es7CeSVL0gRLUJZb2udBefPDJC1r7ZeW4c0+dwrXQHQj1tYLIs9OP+pTk5F72Q4DqELHd7aRLVBZm+PjWy/8qyfvlUEeND8BC/1GyYe28yhTZPLvy7Ay8PVTjAAyPIzD7fZqh8yS+naQBOEwml X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 83820bdf-113d-4d0a-9fc1-08d94ad8e918 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 19 Jul 2021 17:16:13.5561 (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: +Ic1cmQLb5/RvwcAiS8b/wnvvta9dncz3EO2NE9dFk6WQHwx1J1CC+eBlywbDTuRzk6z8ToSMG6BDzOuQjkwJA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB3407 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org There has been at least one wasted opportunity for tag_8021q to be used by a driver: https://patchwork.ozlabs.org/project/netdev/patch/20200710113611.3398-3-kurt@linutronix.de/#2484272 because of a design decision: the declared purpose of tag_8021q is to offer source port/switch identification for a tagging driver for packets coming from a switch with no hardware DSA tagging support. It is not intended to provide VLAN-based port isolation, because its first user, sja1105, had another mechanism for bridging domain isolation, the L2 Forwarding Table. So even if 2 ports are in the same VLAN but they are separated via the L2 Forwarding Table, they will not communicate with one another. The L2 Forwarding Table is managed by the sja1105_bridge_join() and sja1105_bridge_leave() methods. As a consequence, today tag_8021q does not bother too much with hooking into .port_bridge_join() and .port_bridge_leave() because that would introduce yet another degree of freedom, it just iterates statically through all ports of a switch and adds the RX VLAN of one port to all the others. In this way, whenever .port_bridge_join() is called, bridging will magically work because the RX VLANs are already installed everywhere they need to be. This is not to say that the reason for the change in this patch is to satisfy the hellcreek and similar use cases, that is merely a nice side effect. Instead it is to make sja1105 cross-chip links work properly over a DSA link. For context, sja1105 today supports a degenerate form of cross-chip bridging, where the switches are interconnected through their CPU ports ("disjoint trees" topology). There is some code which has been generalized into dsa_8021q_crosschip_link_{add,del}, but it is not enough, and frankly it is impossible to build upon that. Real multi-switch DSA trees, like daisy chains or H trees, which have actual DSA links, do not work. The problem is that sja1105 is unlike mv88e6xxx, and does not have a PVT for cross-chip bridging, which is a table by which the local switch can select the forwarding domain for packets from a certain ingress switch ID and source port. The sja1105 switches cannot parse their own DSA tags, because, well, they don't really have support for DSA tags, it's all VLANs. So to make something like cross-chip bridging between sw0p0 and sw1p0 to work over the sw0p3/sw1p3 DSA link to work with sja1105 in the topology below: | | sw0p0 sw0p1 sw0p2 sw0p3 sw1p3 sw1p2 sw1p1 sw1p0 [ user ] [ user ] [ cpu ] [ dsa ] ---- [ dsa ] [ cpu ] [ user ] [ user ] we need to ask ourselves 2 questions: (1) how should the L2 Forwarding Table be managed? (2) how should the VLAN Lookup Table be managed? i.e. what should prevent packets from going to unwanted ports? Since as mentioned, there is no PVT, the L2 Forwarding Table only contains forwarding rules for local ports. So we can say "all user ports are allowed to forward to all CPU ports and all DSA links". If we allow forwarding to DSA links unconditionally, this means we must prevent forwarding using the VLAN Lookup Table. This is in fact asymmetric with what we do for tag_8021q on ports local to the same switch, and it matters because now that we are making tag_8021q a core DSA feature, we need to hook into .crosschip_bridge_join() to add/remove the tag_8021q VLANs. So for symmetry it makes sense to manage the VLANs for local forwarding in the same way as cross-chip forwarding. Note that there is a very precise reason why tag_8021q hooks into dsa_switch_bridge_join() which acts at the cross-chip notifier level, and not at a higher level such as dsa_port_bridge_join(). We need to install the RX VLAN of the newly joining port into the VLAN table of all the existing ports across the tree that are part of the same bridge, and the notifier already does the iteration through the switches for us. Signed-off-by: Vladimir Oltean --- net/dsa/dsa_priv.h | 6 ++ net/dsa/switch.c | 24 +++++--- net/dsa/tag_8021q.c | 134 ++++++++++++++++++++++++++++++++++---------- 3 files changed, 126 insertions(+), 38 deletions(-) diff --git a/net/dsa/dsa_priv.h b/net/dsa/dsa_priv.h index f201c33980bf..28c4d1107b6d 100644 --- a/net/dsa/dsa_priv.h +++ b/net/dsa/dsa_priv.h @@ -386,6 +386,12 @@ int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst, const struct dsa_device_ops *tag_ops, const struct dsa_device_ops *old_tag_ops); +/* tag_8021q.c */ +int dsa_tag_8021q_bridge_join(struct dsa_switch *ds, + struct dsa_notifier_bridge_info *info); +int dsa_tag_8021q_bridge_leave(struct dsa_switch *ds, + struct dsa_notifier_bridge_info *info); + extern struct list_head dsa_tree_list; #endif diff --git a/net/dsa/switch.c b/net/dsa/switch.c index 5ece05dfd8f2..38560de99b80 100644 --- a/net/dsa/switch.c +++ b/net/dsa/switch.c @@ -90,18 +90,25 @@ static int dsa_switch_bridge_join(struct dsa_switch *ds, struct dsa_notifier_bridge_info *info) { struct dsa_switch_tree *dst = ds->dst; + int err; if (dst->index == info->tree_index && ds->index == info->sw_index && - ds->ops->port_bridge_join) - return ds->ops->port_bridge_join(ds, info->port, info->br); + ds->ops->port_bridge_join) { + err = ds->ops->port_bridge_join(ds, info->port, info->br); + if (err) + return err; + } if ((dst->index != info->tree_index || ds->index != info->sw_index) && - ds->ops->crosschip_bridge_join) - return ds->ops->crosschip_bridge_join(ds, info->tree_index, - info->sw_index, - info->port, info->br); + ds->ops->crosschip_bridge_join) { + err = ds->ops->crosschip_bridge_join(ds, info->tree_index, + info->sw_index, + info->port, info->br); + if (err) + return err; + } - return 0; + return dsa_tag_8021q_bridge_join(ds, info); } static int dsa_switch_bridge_leave(struct dsa_switch *ds, @@ -151,7 +158,8 @@ static int dsa_switch_bridge_leave(struct dsa_switch *ds, if (err && err != EOPNOTSUPP) return err; } - return 0; + + return dsa_tag_8021q_bridge_leave(ds, info); } /* Matches for all upstream-facing ports (the CPU port and all upstream-facing diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index 9785c8497039..0946169033a5 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -137,12 +137,6 @@ static int dsa_8021q_vid_apply(struct dsa_switch *ds, int port, u16 vid, * force all switched traffic to pass through the CPU. So we must also make * the other front-panel ports members of this VID we're adding, albeit * we're not making it their PVID (they'll still have their own). - * By the way - just because we're installing the same VID in multiple - * switch ports doesn't mean that they'll start to talk to one another, even - * while not bridged: the final forwarding decision is still an AND between - * the L2 forwarding information (which is limiting forwarding in this case) - * and the VLAN-based restrictions (of which there are none in this case, - * since all ports are members). * - On TX (ingress from CPU and towards network) we are faced with a problem. * If we were to tag traffic (from within DSA) with the port's pvid, all * would be well, assuming the switch ports were standalone. Frames would @@ -156,9 +150,10 @@ static int dsa_8021q_vid_apply(struct dsa_switch *ds, int port, u16 vid, * a member of the VID we're tagging the traffic with - the desired one. * * So at the end, each front-panel port will have one RX VID (also the PVID), - * the RX VID of all other front-panel ports, and one TX VID. Whereas the CPU - * port will have the RX and TX VIDs of all front-panel ports, and on top of - * that, is also tagged-input and tagged-output (VLAN trunk). + * the RX VID of all other front-panel ports that are in the same bridge, and + * one TX VID. Whereas the CPU port will have the RX and TX VIDs of all + * front-panel ports, and on top of that, is also tagged-input and + * tagged-output (VLAN trunk). * * CPU port CPU port * +-------------+-----+-------------+ +-------------+-----+-------------+ @@ -176,6 +171,98 @@ static int dsa_8021q_vid_apply(struct dsa_switch *ds, int port, u16 vid, * +-+-----+-+-----+-+-----+-+-----+-+ +-+-----+-+-----+-+-----+-+-----+-+ * swp0 swp1 swp2 swp3 swp0 swp1 swp2 swp3 */ +static bool dsa_tag_8021q_bridge_match(struct dsa_switch *ds, int port, + struct dsa_notifier_bridge_info *info) +{ + struct dsa_port *dp = dsa_to_port(ds, port); + + /* Don't match on self */ + if (ds->dst->index == info->tree_index && + ds->index == info->sw_index && + port == info->port) + return false; + + if (dsa_port_is_user(dp)) + return dp->bridge_dev == info->br; + + return false; +} + +int dsa_tag_8021q_bridge_join(struct dsa_switch *ds, + struct dsa_notifier_bridge_info *info) +{ + struct dsa_switch *targeted_ds; + u16 targeted_rx_vid; + int err, port; + + if (!ds->tag_8021q_ctx) + return 0; + + targeted_ds = dsa_switch_find(info->tree_index, info->sw_index); + targeted_rx_vid = dsa_8021q_rx_vid(targeted_ds, info->port); + + for (port = 0; port < ds->num_ports; port++) { + u16 rx_vid = dsa_8021q_rx_vid(ds, port); + + if (!dsa_tag_8021q_bridge_match(ds, port, info)) + continue; + + /* Install the RX VID of the targeted port in our VLAN table */ + err = dsa_8021q_vid_apply(ds, port, targeted_rx_vid, + BRIDGE_VLAN_INFO_UNTAGGED, true); + if (err) + return err; + + /* Install our RX VID into the targeted port's VLAN table */ + err = dsa_8021q_vid_apply(targeted_ds, info->port, rx_vid, + BRIDGE_VLAN_INFO_UNTAGGED, true); + if (err) + return err; + } + + return 0; +} + +int dsa_tag_8021q_bridge_leave(struct dsa_switch *ds, + struct dsa_notifier_bridge_info *info) +{ + struct dsa_switch *targeted_ds; + u16 targeted_rx_vid; + int err, port; + + if (!ds->tag_8021q_ctx) + return 0; + + targeted_ds = dsa_switch_find(info->tree_index, info->sw_index); + targeted_rx_vid = dsa_8021q_rx_vid(targeted_ds, info->port); + + for (port = 0; port < ds->num_ports; port++) { + u16 rx_vid = dsa_8021q_rx_vid(ds, port); + + if (!dsa_tag_8021q_bridge_match(ds, port, info)) + continue; + + /* Remove the RX VID of the targeted port from our VLAN table */ + err = dsa_8021q_vid_apply(ds, port, targeted_rx_vid, + BRIDGE_VLAN_INFO_UNTAGGED, false); + if (err) + dev_err(ds->dev, + "port %d failed to delete tag_8021q VLAN: %pe\n", + port, ERR_PTR(err)); + + /* Remove our RX VID from the targeted port's VLAN table */ + err = dsa_8021q_vid_apply(targeted_ds, info->port, rx_vid, + BRIDGE_VLAN_INFO_UNTAGGED, false); + if (err) + dev_err(targeted_ds->dev, + "port %d failed to delete tag_8021q VLAN: %pe\n", + info->port, ERR_PTR(err)); + } + + return 0; +} + +/* Set up a port's tag_8021q RX and TX VLAN for standalone mode operation */ static int dsa_8021q_setup_port(struct dsa_switch *ds, int port, bool enabled) { struct dsa_8021q_context *ctx = ds->tag_8021q_ctx; @@ -183,7 +270,7 @@ static int dsa_8021q_setup_port(struct dsa_switch *ds, int port, bool enabled) u16 rx_vid = dsa_8021q_rx_vid(ds, port); u16 tx_vid = dsa_8021q_tx_vid(ds, port); struct net_device *master; - int i, err; + int err; /* The CPU port is implicitly configured by * configuring the front-panel ports @@ -198,26 +285,13 @@ static int dsa_8021q_setup_port(struct dsa_switch *ds, int port, bool enabled) * L2 forwarding rules still take precedence when there are no VLAN * restrictions, so there are no concerns about leaking traffic. */ - for (i = 0; i < ds->num_ports; i++) { - u16 flags; - - if (i == upstream) - continue; - else if (i == port) - /* The RX VID is pvid on this port */ - flags = BRIDGE_VLAN_INFO_UNTAGGED | - BRIDGE_VLAN_INFO_PVID; - else - /* The RX VID is a regular VLAN on all others */ - flags = BRIDGE_VLAN_INFO_UNTAGGED; - - err = dsa_8021q_vid_apply(ds, i, rx_vid, flags, enabled); - if (err) { - dev_err(ds->dev, - "Failed to apply RX VID %d to port %d: %pe\n", - rx_vid, port, ERR_PTR(err)); - return err; - } + err = dsa_8021q_vid_apply(ds, port, rx_vid, BRIDGE_VLAN_INFO_UNTAGGED | + BRIDGE_VLAN_INFO_PVID, enabled); + if (err) { + dev_err(ds->dev, + "Failed to apply RX VID %d to port %d: %pe\n", + rx_vid, port, ERR_PTR(err)); + return err; } /* CPU port needs to see this port's RX VID