From patchwork Mon Aug 9 19:03:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 494846 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, MSGID_FROM_MTA_HEADER, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D701C432BE for ; Mon, 9 Aug 2021 19:03:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 21D5860EBD for ; Mon, 9 Aug 2021 19:03:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235937AbhHITEG (ORCPT ); Mon, 9 Aug 2021 15:04:06 -0400 Received: from mail-am6eur05on2069.outbound.protection.outlook.com ([40.107.22.69]:47936 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S235918AbhHITED (ORCPT ); Mon, 9 Aug 2021 15:04:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VaIZIE4abPLTCACxR4cUtU8CW0i5f+YunCtMRBSwDJcsp8y9DKONzRqkaIypkbcLl+5zIj6lk3wteNTl6VxVmD95dYoHMLUCV79mRgkCd+y/vonYhAQ9d4pl7SmFnVanwmziWUKsvug8pyovSPcYaiaH7iFITotaGyVrAxXdGX3chHSM6nrpTRqlHqka4kjrXR2MKYp13Oy4jWa/JjU8SuDuy082IE2QsGGs1zqrAnMqOV+10SZIKU+nhsk5g6pZHRoF1srr8hmNOzDOOO6xyx4tDZmRWLOis6+8DmwGIj+Lt2n19IVUh4QXK/Kjm3KxwP0KKR+C9jPRiEFydBO9aQ== 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=wKBsjeJT/luaHdgLZtLmt3nDc/Z5kIMo+OWL8trOMPA=; b=TLlOfzS0Pi3w6+ZhpKOMTGMiN0OthvRqhLauiN09IHfFl6cbbyq7hOxoOKxWXpOKIsP04m86QgWFWZ0i9inpOqwVUMOpBnrsHkVrnLtf6JB84i8hPNLiXEY2DfHLoDSqR4pvjEWtBUqrjl0+w/ZeJZxZq9iRYMN6dCOeZw10zpj/GHbHNmOpbJuOEfQZ5N7xqacluUD0fHcRGWhcdlDxW5jh8qsdQ/7U3PWt0WWJQwYj2r8cSrCQc8g5UtUfI0Cl1otWNhauTY0i6HY/xchi+jIW2Z5Q/oxE/NfiYoAtPaIGHMd2F6g8l2AYVjoYibfyARKICBILY1vHJRcVoEPsRQ== 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=wKBsjeJT/luaHdgLZtLmt3nDc/Z5kIMo+OWL8trOMPA=; b=BZ91XsIfkjt/8iuAT+bQXca0W1ypESLctzsDbb/RT1/xWwpfzqLnMmFNbgskOrWmaqeovGJfdvrwAiPYVtcOLBLp/AZGq42omH9c0i16Eljt7WsTEwD4O1b1AecrQaD/DqxFzp0GW1XakFETREF0sZ8aOevZGHpQrutMrLL/5Vc= 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 VI1PR04MB5501.eurprd04.prod.outlook.com (2603:10a6:803:d3::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.16; Mon, 9 Aug 2021 19:03:40 +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.4394.023; Mon, 9 Aug 2021 19:03:40 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean , Kurt Kanzenbach , Woojung Huh , UNGLinuxDriver@microchip.com, Sean Wang , Landen Chao , DENG Qingfang , Matthias Brugger , Claudiu Manoil , Alexandre Belloni , George McCollister Subject: [RFC PATCH net-next 2/4] net: dsa: remove the "dsa_to_port in a loop" antipattern from the core Date: Mon, 9 Aug 2021 22:03:18 +0300 Message-Id: <20210809190320.1058373-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210809190320.1058373-1-vladimir.oltean@nxp.com> References: <20210809190320.1058373-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM0PR04CA0057.eurprd04.prod.outlook.com (2603:10a6:208:1::34) 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.25.144.60) by AM0PR04CA0057.eurprd04.prod.outlook.com (2603:10a6:208:1::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.15 via Frontend Transport; Mon, 9 Aug 2021 19:03:39 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: caf0d3af-291b-4a2d-f2e4-08d95b686678 X-MS-TrafficTypeDiagnostic: VI1PR04MB5501: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qzn4UuFtaBgzc66wMIyILV2EmJ7XA3x4ccO9XWxWJEUQ3tAJLQXhZpobkAF9oPyskGA6N+x6wuzACgBtNHeZyJWJ/WX//dH9oIcOPM4X9+TyUbIc5TOl5PQOfAIOq99+EJO95+P03KGKKeBFfm/sp6DPaGpsPqN6IKwwcHKdIjTz4f5ldIiCRcYT4vcHuTYrO7Gex62isfvMxyMHktxI9ti0TSucBgi+qaxj7OmuZJv3bmjGm1NyJ7ivG6LeBracv6PohtUfamtTy8BOgVuYBJZesiD94M6hNdnyPobPwW3SVLzxv6/y37EHVkqgi1Ddoai4L8BbPWKr7S4nmfk/k1bE+hpTMPD64Gdw/MKpvmyn0EkeFLnsksSny0mhICvMR5k+9lSQ5kywZ20xo+wYtX/0D8nbfwM6MjBPvdqhKvJyFlTVPP+CPDpv/xQmvnmGzgukfJ+wyFFX+PvbJcF5fVusDJeXrEzuwMEh5fbpx63BWfTDkqpx+axn1UJksFanuYYWDJoeRXW0t01RDHjK4b6T4vu9EvLQ5UvcUJQnMcRB9SYKgcdLybL9GTa2q30HhreI6HHkZqjJuedeLCrtxsblnksIz0G7FTZyp5KGTiFMsDrJbInC/U5G49yka/hNvNOw4xKYF5gDb5BJizbkR0fjXHFOF/T0R6huIRUgsA/jeDPzxdm+oVtA+nqIY1kfYSPShPXOBN4NCK1RjA3fnQ== 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)(346002)(39850400004)(136003)(366004)(396003)(376002)(5660300002)(66946007)(66476007)(66556008)(7416002)(4326008)(6506007)(44832011)(54906003)(52116002)(6512007)(6486002)(38100700002)(2616005)(1076003)(956004)(110136005)(30864003)(6666004)(38350700002)(86362001)(186003)(36756003)(8676002)(83380400001)(8936002)(478600001)(26005)(2906002)(316002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: aimhS9Gvo36wTEN3+lwyROGUcbnu67NjiFljfopW455lCQ6NjyYHmxDavqzBwprAz5o4SsspQUqeP30dCm8oE2T0f2OwcX22aOE2pTlf6fuUDFqJbGDMlVyjqYVkpnNv2Vnhp0UAmVtCLPNbTNSRQ7jQEo+jzi5gQGhX4LzQe48eCz+gahosYA0Iyh2Eu6o1UectAAyyU3EPiOEXwOpiulp/Zxm7d2jfALe+NDKRKgsmbRDY9+6u0r2HLbvj+UkKi4m1iyjtok/QPKGuL0crNDclIMVLrMe74KtvKRZBCusmlC/UAO6l5Rdq3cnS97tKTEJtcg4W6y0dUDcVdTrpmg0zqPQpXDz3eL+MACLE2Y9OhuJlo73UUd9427nO4f067MRQcc8dmBSeU3/ap7xALYxuMOt2RMhXH+7JFHffg5DF1tPEO3LExoSocl0Uj5akbHC52SFeeTDcs7vzlzBfSsazJJ9euSUCCw/WtTGz4Zi6M1ze9oKumV/IaBd97x96qQ08aEJm4iX+WfiC7nc+JJPKvpppZgg+k0OV0iFiBKMpwgcIOhL0HPL4SpgwPk9W5yDNN3/4ahY0xTy8DkAC1DG3CXzWoZZIWFgFCzgfKhvEAACj1NLwvwQtcURkDA3VOWLpGtbI2Td2HpT1ooGj7SB+SsW0VIYm1sXwM4s2lKVp+6kO8dkeMnvm8w0aZCfSr01XZyGBKLO1L2dqltyWjVaoMZnNJ48YENVpCtpLB6rf1asvAWjvfoh/Wijfi8WxxTAAsBNNrjH1hTNGHvlJBGo0V5Ir0JIDGptjLMMYIvUDYroxrB54FSw10isdE8LkZUGZJE61MQgq0ULvY1gXNuKCX6ISyp9774hKHvl7OQUkm0s9nkJu4kisDkSvbEaHj/oDRSn3dUwuW/X5hKnXpVX9PlqOAIGdpeQgxHUTakKB3VIC+Tlj+x1pX3LGAg6zOQwcw6FCXiymQ2TNB8LebOcITm3aFuTmOejF/gKXBv0zrhp7/hHxsmZ9XrqEvXzxDrxsT0u6t99h+hFFU2hJklwrTkMcGjQMyKI+HGl3FcrYCfxFjnz0TmV2nlINjofmDDDYogeWJkkIhS+OlEgG1es1dMVD+cMxD41QUe1kcWC4v3nCE1wSevTdhAG7aETK2x39B4PshwNIXWrF/xRzg8N6loSgS+68YZQ7nreVsvkaCkXA2c8MgmuoRFIU3KLJ9WRGqhdXHA7j0BMZna+fdj07Wbx2iNzsa65tIg0NZutSpEMWe5PK5nfHS2QLxg2yc0XXh5TJc+FMJHnBzrtwIqkmN5kpYF5C+oBOyQQ2ZmT/Dbn63ALHcgl8ecpmEsSW X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: caf0d3af-291b-4a2d-f2e4-08d95b686678 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Aug 2021 19:03:40.5263 (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: WyJhFj52GTWi4ugtMunkZDjX89kxVN89Bn0enugQS39eJioJXut71L35DRC8+w0/tyinRPy3Owo5Xz3ExlQiJQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB5501 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Ever since Vivien's conversion of the ds->ports array into a dst->ports list, and the introduction of dsa_to_port, iterations through the ports of a switch became quadratic whenever dsa_to_port was needed. dsa_to_port can either be called directly, or indirectly through the dsa_is_{user,cpu,dsa,unused}_port helpers. Introduce a basic switch port iterator macro, dsa_switch_for_each_port, that works with the iterator variable being a struct dsa_port *dp directly, and not an int i. It is an expensive variable to go from i to dp, but cheap to go from dp to i. This macro iterates through the entire ds->dst->ports list and filters by the ports belonging just to the switch provided as argument. While at it, provide some more flavors of that macro which filter for specific types of ports: at the moment just user ports and CPU ports. Signed-off-by: Vladimir Oltean Signed-off-by: Vladimir Oltean --- include/net/dsa.h | 19 +++++++++++++++---- net/dsa/dsa.c | 22 +++++++++++----------- net/dsa/dsa2.c | 11 +++++------ net/dsa/port.c | 7 ++++--- net/dsa/switch.c | 41 ++++++++++++++++++----------------------- net/dsa/tag_8021q.c | 29 +++++++++++++---------------- 6 files changed, 66 insertions(+), 63 deletions(-) diff --git a/include/net/dsa.h b/include/net/dsa.h index d05c71a92715..4639a82bab66 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -471,14 +471,25 @@ static inline bool dsa_is_user_port(struct dsa_switch *ds, int p) return dsa_to_port(ds, p)->type == DSA_PORT_TYPE_USER; } +#define dsa_switch_for_each_port(_dp, _ds) \ + list_for_each_entry((_dp), &(_ds)->dst->ports, list) \ + if ((_dp)->ds == (_ds)) + +#define dsa_switch_for_each_user_port(_dp, _ds) \ + dsa_switch_for_each_port((_dp), (_ds)) \ + if (dsa_port_is_user((_dp))) + +#define dsa_switch_for_each_cpu_port(_dp, _ds) \ + dsa_switch_for_each_port((_dp), (_ds)) \ + if (dsa_port_is_cpu((_dp))) + static inline u32 dsa_user_ports(struct dsa_switch *ds) { + struct dsa_port *dp; u32 mask = 0; - int p; - for (p = 0; p < ds->num_ports; p++) - if (dsa_is_user_port(ds, p)) - mask |= BIT(p); + dsa_switch_for_each_user_port(dp, ds) + mask |= BIT(dp->index); return mask; } diff --git a/net/dsa/dsa.c b/net/dsa/dsa.c index 5e73332a9707..8104f2382988 100644 --- a/net/dsa/dsa.c +++ b/net/dsa/dsa.c @@ -280,23 +280,22 @@ static int dsa_switch_rcv(struct sk_buff *skb, struct net_device *dev, } #ifdef CONFIG_PM_SLEEP -static bool dsa_is_port_initialized(struct dsa_switch *ds, int p) +static bool dsa_port_is_initialized(const struct dsa_port *dp) { - const struct dsa_port *dp = dsa_to_port(ds, p); - return dp->type == DSA_PORT_TYPE_USER && dp->slave; } int dsa_switch_suspend(struct dsa_switch *ds) { - int i, ret = 0; + struct dsa_port *dp; + int ret = 0; /* Suspend slave network devices */ - for (i = 0; i < ds->num_ports; i++) { - if (!dsa_is_port_initialized(ds, i)) + dsa_switch_for_each_port(dp, ds) { + if (!dsa_port_is_initialized(dp)) continue; - ret = dsa_slave_suspend(dsa_to_port(ds, i)->slave); + ret = dsa_slave_suspend(dp->slave); if (ret) return ret; } @@ -310,7 +309,8 @@ EXPORT_SYMBOL_GPL(dsa_switch_suspend); int dsa_switch_resume(struct dsa_switch *ds) { - int i, ret = 0; + struct dsa_port *dp; + int ret = 0; if (ds->ops->resume) ret = ds->ops->resume(ds); @@ -319,11 +319,11 @@ int dsa_switch_resume(struct dsa_switch *ds) return ret; /* Resume slave network devices */ - for (i = 0; i < ds->num_ports; i++) { - if (!dsa_is_port_initialized(ds, i)) + dsa_switch_for_each_port(dp, ds) { + if (!dsa_port_is_initialized(dp)) continue; - ret = dsa_slave_resume(dsa_to_port(ds, i)->slave); + ret = dsa_slave_resume(dp->slave); if (ret) return ret; } diff --git a/net/dsa/dsa2.c b/net/dsa/dsa2.c index 8150e16aaa55..13794578a1d0 100644 --- a/net/dsa/dsa2.c +++ b/net/dsa/dsa2.c @@ -707,16 +707,15 @@ static int dsa_switch_setup_tag_protocol(struct dsa_switch *ds) { const struct dsa_device_ops *tag_ops = ds->dst->tag_ops; struct dsa_switch_tree *dst = ds->dst; - int port, err; + struct dsa_port *cpu_dp; + int err; if (tag_ops->proto == dst->default_proto) return 0; - for (port = 0; port < ds->num_ports; port++) { - if (!dsa_is_cpu_port(ds, port)) - continue; - - err = ds->ops->change_tag_protocol(ds, port, tag_ops->proto); + dsa_switch_for_each_cpu_port(cpu_dp, ds) { + err = ds->ops->change_tag_protocol(ds, cpu_dp->index, + tag_ops->proto); if (err) { dev_err(ds->dev, "Unable to use tag protocol \"%s\": %pe\n", tag_ops->name, ERR_PTR(err)); diff --git a/net/dsa/port.c b/net/dsa/port.c index eedd9881e1ba..05b902d69863 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -540,7 +540,8 @@ static bool dsa_port_can_apply_vlan_filtering(struct dsa_port *dp, struct netlink_ext_ack *extack) { struct dsa_switch *ds = dp->ds; - int err, i; + struct dsa_port *other_dp; + int err; /* VLAN awareness was off, so the question is "can we turn it on". * We may have had 8021q uppers, those need to go. Make sure we don't @@ -582,10 +583,10 @@ static bool dsa_port_can_apply_vlan_filtering(struct dsa_port *dp, * different ports of the same switch device and one of them has a * different setting than what is being requested. */ - for (i = 0; i < ds->num_ports; i++) { + dsa_switch_for_each_port(other_dp, ds) { struct net_device *other_bridge; - other_bridge = dsa_to_port(ds, i)->bridge_dev; + other_bridge = other_dp->bridge_dev; if (!other_bridge) continue; /* If it's the same bridge, it also has same diff --git a/net/dsa/switch.c b/net/dsa/switch.c index fd1a1c6bf9cf..5ddcf37ecfa5 100644 --- a/net/dsa/switch.c +++ b/net/dsa/switch.c @@ -17,14 +17,11 @@ static unsigned int dsa_switch_fastest_ageing_time(struct dsa_switch *ds, unsigned int ageing_time) { - int i; - - for (i = 0; i < ds->num_ports; ++i) { - struct dsa_port *dp = dsa_to_port(ds, i); + struct dsa_port *dp; + dsa_switch_for_each_port(dp, ds) if (dp->ageing_time && dp->ageing_time < ageing_time) ageing_time = dp->ageing_time; - } return ageing_time; } @@ -117,7 +114,8 @@ static int dsa_switch_bridge_leave(struct dsa_switch *ds, bool unset_vlan_filtering = br_vlan_enabled(info->br); struct dsa_switch_tree *dst = ds->dst; struct netlink_ext_ack extack = {0}; - int err, port; + struct dsa_port *dp; + int err; if (dst->index == info->tree_index && ds->index == info->sw_index && ds->ops->port_bridge_leave) @@ -138,10 +136,10 @@ static int dsa_switch_bridge_leave(struct dsa_switch *ds, * VLAN-aware bridge. */ if (unset_vlan_filtering && ds->vlan_filtering_is_global) { - for (port = 0; port < ds->num_ports; port++) { + dsa_switch_for_each_port(dp, ds) { struct net_device *bridge_dev; - bridge_dev = dsa_to_port(ds, port)->bridge_dev; + bridge_dev = dp->bridge_dev; if (bridge_dev && br_vlan_enabled(bridge_dev)) { unset_vlan_filtering = false; @@ -566,38 +564,35 @@ static int dsa_switch_change_tag_proto(struct dsa_switch *ds, struct dsa_notifier_tag_proto_info *info) { const struct dsa_device_ops *tag_ops = info->tag_ops; - int port, err; + struct dsa_port *dp, *cpu_dp; + int err; if (!ds->ops->change_tag_protocol) return -EOPNOTSUPP; ASSERT_RTNL(); - for (port = 0; port < ds->num_ports; port++) { - if (!dsa_is_cpu_port(ds, port)) - continue; - - err = ds->ops->change_tag_protocol(ds, port, tag_ops->proto); + dsa_switch_for_each_cpu_port(cpu_dp, ds) { + err = ds->ops->change_tag_protocol(ds, cpu_dp->index, + tag_ops->proto); if (err) return err; - dsa_port_set_tag_protocol(dsa_to_port(ds, port), tag_ops); + dsa_port_set_tag_protocol(cpu_dp, tag_ops); } /* Now that changing the tag protocol can no longer fail, let's update * the remaining bits which are "duplicated for faster access", and the * bits that depend on the tagger, such as the MTU. */ - for (port = 0; port < ds->num_ports; port++) { - if (dsa_is_user_port(ds, port)) { - struct net_device *slave; + dsa_switch_for_each_user_port(dp, ds) { + struct net_device *slave; - slave = dsa_to_port(ds, port)->slave; - dsa_slave_setup_tagger(slave); + slave = dp->slave; + dsa_slave_setup_tagger(slave); - /* rtnl_mutex is held in dsa_tree_change_tag_proto */ - dsa_slave_change_mtu(slave, slave->mtu); - } + /* rtnl_mutex is held in dsa_tree_change_tag_proto */ + dsa_slave_change_mtu(slave, slave->mtu); } return 0; diff --git a/net/dsa/tag_8021q.c b/net/dsa/tag_8021q.c index 654697ebb6f3..b29f4eb9aed1 100644 --- a/net/dsa/tag_8021q.c +++ b/net/dsa/tag_8021q.c @@ -322,15 +322,13 @@ int dsa_switch_tag_8021q_vlan_del(struct dsa_switch *ds, * +-+-----+-+-----+-+-----+-+-----+-+ +-+-----+-+-----+-+-----+-+-----+-+ * swp0 swp1 swp2 swp3 swp0 swp1 swp2 swp3 */ -static bool dsa_tag_8021q_bridge_match(struct dsa_switch *ds, int port, +static bool dsa_tag_8021q_bridge_match(struct dsa_port *dp, 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) + if (dp->ds->dst->index == info->tree_index && + dp->ds->index == info->sw_index && + dp->index == info->port) return false; if (dsa_port_is_user(dp)) @@ -344,8 +342,9 @@ int dsa_tag_8021q_bridge_join(struct dsa_switch *ds, { struct dsa_switch *targeted_ds; struct dsa_port *targeted_dp; + struct dsa_port *dp; u16 targeted_rx_vid; - int err, port; + int err; if (!ds->tag_8021q_ctx) return 0; @@ -354,11 +353,10 @@ int dsa_tag_8021q_bridge_join(struct dsa_switch *ds, targeted_dp = dsa_to_port(targeted_ds, info->port); targeted_rx_vid = dsa_8021q_rx_vid(targeted_ds, info->port); - for (port = 0; port < ds->num_ports; port++) { - struct dsa_port *dp = dsa_to_port(ds, port); - u16 rx_vid = dsa_8021q_rx_vid(ds, port); + dsa_switch_for_each_port(dp, ds) { + u16 rx_vid = dsa_8021q_rx_vid(ds, dp->index); - if (!dsa_tag_8021q_bridge_match(ds, port, info)) + if (!dsa_tag_8021q_bridge_match(dp, info)) continue; /* Install the RX VID of the targeted port in our VLAN table */ @@ -380,8 +378,8 @@ int dsa_tag_8021q_bridge_leave(struct dsa_switch *ds, { struct dsa_switch *targeted_ds; struct dsa_port *targeted_dp; + struct dsa_port *dp; u16 targeted_rx_vid; - int port; if (!ds->tag_8021q_ctx) return 0; @@ -390,11 +388,10 @@ int dsa_tag_8021q_bridge_leave(struct dsa_switch *ds, targeted_dp = dsa_to_port(targeted_ds, info->port); targeted_rx_vid = dsa_8021q_rx_vid(targeted_ds, info->port); - for (port = 0; port < ds->num_ports; port++) { - struct dsa_port *dp = dsa_to_port(ds, port); - u16 rx_vid = dsa_8021q_rx_vid(ds, port); + dsa_switch_for_each_port(dp, ds) { + u16 rx_vid = dsa_8021q_rx_vid(ds, dp->index); - if (!dsa_tag_8021q_bridge_match(ds, port, info)) + if (!dsa_tag_8021q_bridge_match(dp, info)) continue; /* Remove the RX VID of the targeted port from our VLAN table */