From patchwork Tue Aug 10 16:14:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 494770 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, 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 62909C4338F for ; Tue, 10 Aug 2021 16:18:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3D023610A7 for ; Tue, 10 Aug 2021 16:18:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234323AbhHJQSX (ORCPT ); Tue, 10 Aug 2021 12:18:23 -0400 Received: from mail-am6eur05on2081.outbound.protection.outlook.com ([40.107.22.81]:23521 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234454AbhHJQPg (ORCPT ); Tue, 10 Aug 2021 12:15:36 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SwK5Ao3t2GVnjKIBqNFG6SJzroOzjVIOymphggIkuc/XEibt3m1tukecQFXB+7F3ziYv5P9iaIWZIcvNpDjuIcZqEqv0rYNlGYHy0hRbF9Sqqh4FHtdFCO9ICG7h0OmLaCsxdgigqMWsQg3zWARCtAlfmZvav8e2D3/SFmyWg9djug1OEcsjaGrtKXyM+YTM0jRvz4tME+FYBIg2RjYJr/rCFfS0yBXaPXnWAV4cp+u3IJsCEJit8VGzuFBmsje77DSEHNuYkxaBf245GMTEqsDPClV7aEr8NIy+K3d9fQvXXeLxA1cBJECjsuLfvZGu2QGmSfLE4jex4Y4+ursjBA== 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=ru/8YH3stzTQLi2rtfduBlt9tQMb0Nd9jRA34V3Cl3o=; b=BpaOv1etpRgTjo+hiadiXJ+xQg0r7NGbuSPWLdRQu/24rLPerYMRdz2ZmiJ5cd3m2vmWz5GZHbl/gPW3teLpyPPzsLJZ+DpfPkHgoBIwKvlsFSzw9SbeJFdV7ABrj6zLhgyo1tHcCMWbEExGWH8SiTI7MXrQDOXRHkiN3Fwsa4dxnHI7jbRGTWN9hMt0GHxVLkJQEVhxLjXFRvo2mEvF39YIZlC2+K6qnFzLP6iRv2XnNINyzluMc9ZvonCqJOBVSkotPKxXn+cO3knxCRkrzdiAd07Jg9MxKc202cyvuOz2RU5eLdvK7PNeB3drqdEiGfBICeP3YuzdQaMMUpx79g== 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=ru/8YH3stzTQLi2rtfduBlt9tQMb0Nd9jRA34V3Cl3o=; b=nyCWH/Fmjt+r1eQMbzxk0AM8A2tj75Vl5SmoAtjLfwP4o5Mmb8CkI1fVDShUrzRJU/wiSrHplaEKnl4yHSnQcrMCfFu9WNYHWZJFAG0GAWhF5LFtKhUDTV2ACMpmL9JmHaSBC19/vn4W8EiGtcXDK6ynLrHuuy99F4V30Xg63Bo= 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 VI1PR0402MB2800.eurprd04.prod.outlook.com (2603:10a6:800:b8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.19; Tue, 10 Aug 2021 16:15:04 +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; Tue, 10 Aug 2021 16:15:04 +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 v2 net-next 1/8] net: dsa: introduce a dsa_port_is_unused helper Date: Tue, 10 Aug 2021 19:14:41 +0300 Message-Id: <20210810161448.1879192-2-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210810161448.1879192-1-vladimir.oltean@nxp.com> References: <20210810161448.1879192-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM4PR05CA0031.eurprd05.prod.outlook.com (2603:10a6:205::44) 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 AM4PR05CA0031.eurprd05.prod.outlook.com (2603:10a6:205::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.15 via Frontend Transport; Tue, 10 Aug 2021 16:15:03 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c475e9f8-cc42-4aac-81a1-08d95c1a032b X-MS-TrafficTypeDiagnostic: VI1PR0402MB2800: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2201; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: fDtLQ25Dn8X0bIogEsRlBH2Tol1gUukL4aeEfkPeDgOUNNZzLP3nk/0OrD7bLgSt9y4NLUtPz/rotRjr3NMJn/9zTTMQlFyVzj1QSsTXPYd7DCv9Lc4lAv6taVazJnL/EHgoG8GYak/eV2c8I53fwueRgi4WMMieRr/qrj6rEhuiabBUlG73V4chy/FTSaAa97Ye3u53EPoQHhZe4Z5+sVmH4d3wYKDAkrNgORyv6SNZVcGyE8jDv6imUY+pS2MPWtS3ql/qWYXqoFsFu5xIyqbU5PKzcHh4gr7AMysHzbE47X6xzsJttogFutsL2loNEyuAr/tVliMY10A32Cckuv1EbWhUfhpFZa1P4Trc0INGWpR/QxnCnYan4nlnLOaqcE+MKaaVrqxSfVQA4dCSdDoxbEgUmw1KOsldCaoiM3C7G2QydkEN4AeuyZBPV/BwwyCEuNY/jMKrBCpHfaMsY7Dfc2hEI2ouCFLULVmeISJI5zSQWnpPiobTe9H4KGQRcAxttAoE3Iq69jSUFmgP59VJi2XOdanVuKwK9h/VAIEnI+EfUdN0yCb0GMvkjiu5oCDD6aR0PW25aZPVFC2qt9+PwZxsU9xhecQFNUGkZlgmGR5UOsgxKAXN7mf2k7TK5bhu4EY2Up4mv4lotLNzDVU2SrMyiABlMDjk+ro5tw7qs5cihR48FQE/MaNmjTK5rJTt6pfuLUCjm8F+tpyIWw== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(346002)(136003)(396003)(39850400004)(366004)(6506007)(52116002)(6512007)(86362001)(110136005)(478600001)(8676002)(2906002)(956004)(54906003)(26005)(1076003)(8936002)(6486002)(316002)(36756003)(4744005)(7416002)(186003)(66946007)(5660300002)(66556008)(66476007)(44832011)(2616005)(6666004)(4326008)(38100700002)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1w8FqfFUr6CNPyxV8/jLS6AdRgsY9UlGljqqKSvGgnnd48PCE1iQKrq7xkBUM+Ilm5ABXLqTUVu4icOOoqHZbEBt60bUE1zgfibhxynTBn+XTFNXw+Jp/sofxm+snOtrHmpcmLilSNR02eI2g7Z7IX5CRj6900Ma2P0ReoNwRYV9iDT/A5u4pQMbfPwSZlQwK28W+xwzQ9yR53AvvZ3EkC43B8wYQWqyCfzOH2phjAmVpl1CA3pphoIT2WBMPw0PuYtFhE2uLST753ANh9EV8Vlaj+DbTlDKYf6BTqjFmUkFMHxkLYezHCDwkE/esmy7qpenscl5koBNFQDXcCl2hipxgv03QtqPt4YAfjRS8Ny0uADaOx2dG0kpesYUujbKMMqx0OuYkWANj2SKDSUkUHgMcHqngPgxiwoVdTBn5zzUVJ7Os+A5sLVvZ0ycNv9MWmJGDOjLWcpgw1V9TJeuhExI/ta8hWxsRRs5nrim1ehN5pULl/f+cp956sazZAxWlfk76OjSEVjzGS80xY/0FIAh3Y8/cHvL+PGJDJDKfQX2Iq7/Q797Ybz+rYi8u1THcLbz4yNESSiA89/KlsMscIllaTdTk0VM0h7uY+HkXX/8+rUJ2mqZ2+vBMHkE+E2pkUlTfALudzo+F8Iy4GIQfRUKrgRs6OGFnnM/zvSmkj+jHu+hGeMjwr0A9vIFg6rFzcIx7jt/2M6GFNPk1X2Gtp7dqX+k6uZy9xzYpD5sckCsNlJi7PUYhVJRraex2ED800CwkgDlynd5vkq7Zq6xBqdE+eLJW3ndxgxNoetZEBTVkoEpe1uttMYtSwXuraX26rLAbNpznbwV0+wqOFGnkCYf43+lPjLdo8PnRav7A3bi+MR87h29vGF19Hr7+uanpH3uW8N5Isu/JDpoEqwZmNxk9OtVHP7N1bV0V6t4ckkkbAY/LTXbWgG8vxEK5Ux4D/aBbu39KeA0WEixVql0y3rpwr64P3uIy2tolNELYonD2Qt/jXjX2NEeKq0+Qd2E1+UzN/mkjMnQ6xaWvxB1jUsauYOZi+12RirUFXqIG0dK5AjSsBVx7Msuw496aC4RUpjcF4bAXvCrB3EY/7dmFiYK9ONkYNrqYyhWgzfXoyPnJL69ixZTSZjlNok4/6vhY+Xb38zaYX53QJ+A9CQrfi3GeW4nUC41RT0Vfg55LcYOz2+XEuEIzAnusexo6O86cVukInl2mpx/dxYliiEu7lwVBtwjzRrwiW4OZ1j7bdgGm6m09sTEGu2NaCnAK5OzReYTRQ2bvEqfkbEithcVPTTZ9dtw38fHBsNNQsbUrrhQl0dh+2ihvoNMGJHGFI3y X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c475e9f8-cc42-4aac-81a1-08d95c1a032b X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2021 16:15:04.3442 (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: w9E4ufuvcIkwLB3fb3++yOp5dhLyDOcjm6m/MAKId65J6jlkK0ZTo+/bOQZwxm/wuGihE6oS7xP2cAwK9+fX9Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB2800 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Similar to the existing dsa_port_is_{cpu,user,dsa} helpers which operate directly on a struct dsa_port *dp, let's introduce the equivalent of dsa_is_unused_port. We will use this to create a more efficient iterator over the available ports of a switch. Signed-off-by: Vladimir Oltean Reviewed-by: Florian Fainelli --- v1->v2: none include/net/dsa.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/include/net/dsa.h b/include/net/dsa.h index cd7dc74d0d4c..d05c71a92715 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -431,6 +431,11 @@ static inline struct dsa_port *dsa_to_port(struct dsa_switch *ds, int p) return NULL; } +static inline bool dsa_port_is_unused(struct dsa_port *port) +{ + return port->type == DSA_PORT_TYPE_UNUSED; +} + static inline bool dsa_port_is_dsa(struct dsa_port *port) { return port->type == DSA_PORT_TYPE_DSA; From patchwork Tue Aug 10 16:14:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 494769 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, 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 8E8CBC43214 for ; Tue, 10 Aug 2021 16:18:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D5FB610A8 for ; Tue, 10 Aug 2021 16:18:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235943AbhHJQS2 (ORCPT ); Tue, 10 Aug 2021 12:18:28 -0400 Received: from mail-am6eur05on2080.outbound.protection.outlook.com ([40.107.22.80]:16133 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234553AbhHJQPr (ORCPT ); Tue, 10 Aug 2021 12:15:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Y5Zn38u1TZT2iYuCU34fE807tIc/9KwGQ/VvSL1fcFaekNcV02kf7TEqs72GgFTr7inMo9w3Ot9qwOEpSoAi9AvEKOew/ctpN82AJXS3rqqV65L8I5+RquD65NIgdVCBxC8i/gwV1Eh7fRrXt06wxf4mIv9rKDtGXNRpUuLxG2En1wpPQaJysTUJqNEHErHiU7Bks3SZtC+/D24OiMl8cLNWUdtrWnToZB5WdB6j+SbNs6XNtqIgd91TEw0BpDmBC5XlRtewWHbq+1/99K/rAL780p4s0HfHtQ8GT2w2VjfqvlgiEp/ARb/6b6WangQqEpuA4d0y27XkV0na1zIsKA== 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=QZfLfrwcf/2oOaww7/aUkUxIRwkO7Xa/ENl5e/NIB7Y=; b=WFrlBVQJXfoRX+yS5+7AzHUHNfGUHxohK5lZqeOCuyklzfxszEUJTrvgKWSJneef7URSxPOjvjnY+FnWnyFw4NIaBUoU1tUyWlSSAscBo+Cnfv3OdE7NgjCcxrH38b9WRZBxDJrpX1JyKcb+bVhf2WskOqb1vIOQO2B2GCbBlv8c0ioeba9B+tmtvLzie0Yek+diVBevgvihoD3W82XM12xchNvrqv25FgrvPLGWtEQRTojHEwYDvU+umtTrFUbf9XY/3jtTxYxLdi+IkzIqVQ7Osga6Dv/Ey+Ox2QQx7U25oJWDevfoc6HTLktQVk+eyV2qEq6U/nup8dxJu1Hxdw== 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=QZfLfrwcf/2oOaww7/aUkUxIRwkO7Xa/ENl5e/NIB7Y=; b=lnzY8ANyXHyPrvEgi6VXtTHLEUgxHdBcGuxlC1DPbDZG8NeLlZg53LuYXDFBsr9wRDCnrReSV+hmQ8NfMm2LhFz+82gNn2KyVJafS6W3CUeHr8mii9LpQ4m6WsIoPXgj7odXzwJve029wD0wfD1MoY6UxfZN9Cc2XqGuWDLSo6M= 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 VI1PR0402MB2800.eurprd04.prod.outlook.com (2603:10a6:800:b8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.19; Tue, 10 Aug 2021 16:15: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.4394.023; Tue, 10 Aug 2021 16:15:06 +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 v2 net-next 2/8] net: dsa: remove the "dsa_to_port in a loop" antipattern from the core Date: Tue, 10 Aug 2021 19:14:42 +0300 Message-Id: <20210810161448.1879192-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210810161448.1879192-1-vladimir.oltean@nxp.com> References: <20210810161448.1879192-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM4PR05CA0031.eurprd05.prod.outlook.com (2603:10a6:205::44) 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 AM4PR05CA0031.eurprd05.prod.outlook.com (2603:10a6:205::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.15 via Frontend Transport; Tue, 10 Aug 2021 16:15:04 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 985c3726-836a-4816-ee8a-08d95c1a041a X-MS-TrafficTypeDiagnostic: VI1PR0402MB2800: X-MS-Exchange-Transport-Forked: True 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: 8RQAxRzBhHI0VDilRLxiRdudRhD5jlrP39IwKFyGZ0PhJuUoKsUBJqnYGClKSol2cQ4wprfm96hnwhu3xGOBzCnuhgvHfVnrtXPrLFrpMrn7XXPv4hZypFohdHgRC/XDAc1zBe976v+bnTY9wi5eaAjD6Wp4qcqnj++icjiqPV6vRcuICs7yzljKFFLTFsowTX2ogFdU6FQaS7kHNLIyHMdCVujJNcDbCZsGmWrJywIW2qSA8eEYRjVyq7HYWClUmThUWSYbCl87nKCIIAZ6E0HLZxheLoJkfOj39K1/nVJoFO+ZYZNXXtjG0EzCWLrPDEUy/xNNQsAToUZ0zjHk4UDsD+oj/IT+I3ABfbVji/eESRixu5pxMxIuNevFk3m41SDz+k+x/c9QUcXuKLHAWu7w4lx9DnptAdrMtw3vl+STxsqwIIEBXeRHThvqS2JtXySKUUFPP4zalzq7zCNTsiPDPii6iU/8D1Xpmw5jBwAjpt+wQgmmGSUsFSbFYpezbzImzro83ccu19vbCpy/IjXRcdiSWwH5Ur8u6LY5rQ2+Mty67hq8VbsrP5DG1m6uSu7v/P/7x6d5d1TVOzcS9FhVQ4yW8+GE8qWI/Qlgd8FNhULYqg/LIIEcd3zMwTJ+Ywo/AdZYu7JF5YR42L2unKC+5huwLbjLgcfNRixZUJwLE0eDhetUINRUnam+hzL1 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(346002)(136003)(396003)(39850400004)(366004)(6506007)(52116002)(6512007)(86362001)(110136005)(478600001)(8676002)(2906002)(956004)(83380400001)(54906003)(26005)(1076003)(8936002)(6486002)(316002)(36756003)(7416002)(30864003)(186003)(66946007)(5660300002)(66556008)(66476007)(44832011)(2616005)(6666004)(4326008)(38100700002)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BH0Xf9iC/2Tmqm4EnF7gx1RXBjrQo7EZjouRN343huRxz0F2PBEADBnQ5gG9tQtCTJeDB5GE2ZS9pxdcHJSVVqogEQx1RQEPkmSawpdEeGBtTTIyrIjCMareIqWeUPhjTJDCxbV7q+jShten2BikG/BBZysD+/JLHgy7ujkXXF20MlVvViTiCEhNuGbTcXhecCLXb21FWJlpRL7YpdRthDtmZbzhdErg4XhPWDMCySHs+JoOVAUB9mZ9YReUWohibu+fSWKBVsivXcE0Dr/MyMKL8MoG2zjguyVd8DX1H57FzJp2hzKW9HFhPku3hpZFvlu55HhDGUR9oB8Gq44EsrLqT6hJw38/qF4r9qEwuZYtJXwIDyv+TWbr2Un6m5JYTGtMYYDFXpLAN6DdrM/bzTzEWp20EazH+3VRDhpHVDqFjbRR2E/Dw3qdSDDbTbywxJwDkviJDJQEuCzfumY6ZVujjwrDETeqJ/id4MD3jILMyWotJLP5cahnP99wpZr7HMlVUXvvNlvz3MTvU4yZ4hgiItH7a7honDrIospSaV0mNZbTlRFx9e7i0O8Slk1pvYbmHbdv8lMLSwUy2CfpeluECZoi0Qp9ecjwufBHWcZlz/4cLjsp+qXDQIQOTulJbGLRoQ7ZbKvm6YNvDAgX9l3YAU+naurEFrvUeUs3M9U8fCPwuqc5LiWZ7wEjj+95DX0zi+qSqpWdG9h++NcCqcX1WGU0sTUnLBTrByJcvNVQKwbxmoGEb/rZg2xuIPiCdrppKGOfVFTy2+lflu/erO2SBgrn2rPCTCD3Ijd9efI1bnEbr+bslNbKlmsm2W1of7KpO25xFeqetMWvz1Z4n+2n/7LrFY5VYMrVGwH0K9MrOijv5PePiUcC34nXx9mZ2Popjq+9ldfUzyp+eT6xoqghRdqa3Vog4zCbKgQQMkK4kODO4MZNwvYE3y9hdOJsfEM4oRSw2Tb+EPgnVsUprAzv0QNDIn+DbGTQl4SuWvG3sENUhVVWLVoJUR2hi6Q9HkTeCIy1toDS+jv+UOGgrNKvIADzmXbhsihRltFWRHilElzNxTUpNtFYoG7LXFx+M2OnO+hZ7CRY6dAjBB+1qC7v+Ggempb9Q/lf6HbXRBr3+nurlqYBJw/reCQmoKuFwAdmsJ6d0GqRcdX+gV+2C7ch3CIta44QFCDpaf7/Y45q+Y6ksQtAXv9gZuK90tJjeCs0vcGE6mmh3eOgpx544VH3QXvajk1j1GJI4ZOEDGBhKkrIfS8op0vBntyHh7dSCJ5RkokYvqJe77k9YeZCafv+SkBPf0iufNxzzym08dmqOfy5o3Xnkdb5vjkRinme X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 985c3726-836a-4816-ee8a-08d95c1a041a X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2021 16:15:05.9543 (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: hjwlAP4ccWbARUk1GmMw3LTai79e52d/Vn+NiYV9eHxFM9qjSJ3MjDO4Rgguj1lt1lp6DZ7NF7YwHMCgYwsnEA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB2800 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 Reviewed-by: Florian Fainelli --- v1->v2: two more conversions of dsa_port_is_user include/net/dsa.h | 19 +++++++++++++++---- net/dsa/dsa.c | 22 +++++++++++----------- net/dsa/dsa2.c | 13 ++++++------- net/dsa/port.c | 7 ++++--- net/dsa/slave.c | 2 +- net/dsa/switch.c | 41 ++++++++++++++++++----------------------- net/dsa/tag_8021q.c | 29 +++++++++++++---------------- 7 files changed, 68 insertions(+), 65 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..cf9810d55611 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)); @@ -1040,7 +1039,7 @@ int dsa_tree_change_tag_proto(struct dsa_switch_tree *dst, goto out_unlock; list_for_each_entry(dp, &dst->ports, list) { - if (!dsa_is_user_port(dp->ds, dp->index)) + if (!dsa_port_is_user(dp)) continue; if (dp->slave->flags & IFF_UP) 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/slave.c b/net/dsa/slave.c index 7674f788d563..2f6a2e7d24c0 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -2266,7 +2266,7 @@ static int dsa_slave_netdevice_event(struct notifier_block *nb, dst = cpu_dp->ds->dst; list_for_each_entry(dp, &dst->ports, list) { - if (!dsa_is_user_port(dp->ds, dp->index)) + if (!dsa_port_is_user(dp)) continue; list_add(&dp->slave->close_list, &close_list); 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 */ From patchwork Tue Aug 10 16:14:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 494768 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, 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 4D7F2C41537 for ; Tue, 10 Aug 2021 16:18:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 42E6A60ED8 for ; Tue, 10 Aug 2021 16:18:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236033AbhHJQSa (ORCPT ); Tue, 10 Aug 2021 12:18:30 -0400 Received: from mail-am6eur05on2080.outbound.protection.outlook.com ([40.107.22.80]:16133 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234710AbhHJQQd (ORCPT ); Tue, 10 Aug 2021 12:16:33 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mT60ozXEDgHkQzKS86kSiCcpAPTJrOO3u5lYJ/n/gwaQSOZbF418NLW4jJMNqmbBgaH0PViwMt3njKtmrofQ8RF1sM133yjTzU+fA4pPlOndxUHmKzUgxjiE/x4kBbHdy0C2hpp5PLSd7txsQl7I4+nBFHgqrary4zQZgCipTdl/YJIRqo4nzKRmNhfbk40TImShhTRQrm8GHCTkTGU2mEs6txRias7BwVnqA1dV5GN1DbCzuNANfsIRFRBmlYR26IMk3eMJF1frWUKKhGcCACz14uBIhX/94frEU083JVIKC4O2zcJruwqGPXItLY0Gjbfuj+QQRZKRF2oHPcnsew== 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=0B5MPayK7zm5Cf1VeRaoaVSBEJUGaDDyG1ikrG15070=; b=JsGYac+eGgWUBpGaXWV2mn9FZm/620Akii8/IrhcbmIjcinPzJDEPNIsSWUjcIP1LFIvhclyAA5ACdt+Gqhqe+OnhYXndmStWHl5XoWyo2QCtEgUzLglXJsCVRZm3uwhmO/3Oen0+mqoVCjOoQNPb6o36ZBjhs8+98jNjnoKIrP3nkDMQ5KB3w/FSpdN+YYEfC+jY9nkHt/FPFGUh2bjJTXjXba8WjkD/xgWDoYZfKvkwuaHTe4gpycpkrN3qeWFNtOUiJJ+SYcEkYiMIhfoxF+rgDraTevl0GiHsEgl3j1aLgWFhTiCqOfwY9URCCqFTZEO1r5T89QwGa4bY3uKLQ== 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=0B5MPayK7zm5Cf1VeRaoaVSBEJUGaDDyG1ikrG15070=; b=MPEPc8vxQhlJ06yHm9cBWVFdaFNscNGqtD6NlOpX0Oiw2pTdFVgPKPVBSX+s2/QOgGLzUO+U03zaMdIpqBo9kmorjqdjE3Bvj3O5yHjodoPl5BCBrCNNMrGQDS2hQkrKy07EKGqWNDGZaTzBQ0apmGd8v7mWVqHWEdj+P6JcIwE= 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 VI1PR0402MB2800.eurprd04.prod.outlook.com (2603:10a6:800:b8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.19; Tue, 10 Aug 2021 16:15:07 +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; Tue, 10 Aug 2021 16:15:07 +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 v2 net-next 3/8] net: dsa: remove the "dsa_to_port in a loop" antipattern from drivers Date: Tue, 10 Aug 2021 19:14:43 +0300 Message-Id: <20210810161448.1879192-4-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210810161448.1879192-1-vladimir.oltean@nxp.com> References: <20210810161448.1879192-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM4PR05CA0031.eurprd05.prod.outlook.com (2603:10a6:205::44) 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 AM4PR05CA0031.eurprd05.prod.outlook.com (2603:10a6:205::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.15 via Frontend Transport; Tue, 10 Aug 2021 16:15:06 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f2038e72-d12a-419b-e5b3-08d95c1a0512 X-MS-TrafficTypeDiagnostic: VI1PR0402MB2800: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:8882; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: C6iClVXkWphZ6IGniZ7SBu8fb7ODEYZDFk6wNRsV6jxsqaEmiAvzzthvs4WMCm1qLkDwLk5IrXw6POyTLftqTe2yVgkPGvH1Sjt59ZgUaQi8m5yq80N4nlxVm8DO1PMUBQ7sBlZaLWCkcTLKsuP3xhiZlunHrSBOc21+3QsJwjAlSTQmPtrTMyXLNWs9KlElJW7YxptTdtG5OGD1x/xXoQZIXrXuK9Oi0CPK7OXJ5B5+vpfWhWKDGtu/CBUOQAFUNBASyFZdke2fLiLULAb8yRNlmwebUkGCqFAYbv2ERCC6hHQDO6+nDfABkKWOuRBDex1TaJqxM044DDwHAu6QK5qSe+w1YPicrTrIDhtPj72qr8p5S0+dssVOK0u88SLhwXQVqRmbrM3l5vvXNRCYd3xHq0mkd+cVz2O1k7+hduqcaX032VCnTeVRJewafTRKLCfaNfbyy8OYAY+xZP5JyckWz1JBff4b6oPfPpj3lSNLsCOpXIdWzVltMOYfaFrKJja7CXz3I68f0Hajzapf8CGBuPoS/+vrRFpxacc6ziAwmWxYO7dDAlb1mNpm81EOQaPafRPr5pdlPuDa16VJahIVn+yml21JNLQO/KL7Ka2hHWaIC/Z4XEF8lwvgNjdOr2+E/wIGmGOwILyEA2Xbd04FCuN8DXXs2csCGnW1BARBpCE082V2EZ+k/zFLzzMM X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(346002)(136003)(396003)(39850400004)(366004)(6506007)(52116002)(6512007)(86362001)(110136005)(478600001)(8676002)(2906002)(956004)(83380400001)(54906003)(26005)(1076003)(8936002)(6486002)(316002)(36756003)(7416002)(30864003)(186003)(66946007)(5660300002)(66556008)(66476007)(44832011)(2616005)(6666004)(4326008)(38100700002)(38350700002)(559001)(579004); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: j7leQYM065pml/xavHh/82/Uvd10xberScRgu+N1aEnSkypiT0F5w47hELsjB1jwq4WWkPiv0XXYgOHfQmFcLECIxB3gjeTcy9J0kVnBgzCNmbtzlELLHg4Ahpki17IUmyEtZsyx0QZ34558L4U4gw1KAhVYk0VVURPLbbIoba8iBukf1PfYwHgCS2R6raPFwPO6n0RPiOJzPyDzpubGHFaIdcC9qCZvTaoHD4sgSo7w1DRuM9gnrOXx52PRuKgM2Vw/QXzerBN++hsX95r+imtCiSEPl8I/5eSYRVq30GnGUonI3EgM0Czg7efhnIWLuWdqZQJmzuueR0b9yISt7hj767EEEn0U8qcl+jBWuvP747DHsMUss4LjAdkD5w/bMgXEAvOvfLcfkLd9CvSr9cGEZ1ppGaYA0muWeulX5ZC1dLdW/tOSpyVYn+t+8TN5A1mus58QrZz5Ioa36JbrW4PQfmKTMzB7GW5+FHaqhiyaicW52hnzokPOxSWsM+CGT4heblnPJDe6W75atKXkTwkBoyB34qeDvf6yigxDkFf2eUawL7ZnKE3AZKRIKQb7Gg8tOWP4lqEnoZXF3v85/O1dXmPQebpkFw04sNyilOybQpqYrFzbKbYeENzFIl5EI9AA4YVPzga1wS2eeb6Q2H30C2z7CjJj7b4s9guTHjSfVMMntP1tuj0tKKFy1bAE4bsWE079b6rBidsILbWFTs6vQyUd1pVbRql4Jm2qbgg3Z450hbP6YmjOvCFL/CcYtUHkaEyaY6n//+ysUMhxK5yfO+aVWE73W9zgbUeagPsbRW+SNZqeqm22StpgckUakkAWGbYAZwXFaSMFMWDjCbhnQfS9mhuuLYrdrhrJZZ2O7kbqoPk0vDP6GsiLJdOEW5rKSBdYJJOObUA0kkjIv+JXNq0y0o//gTgEP/lP7WiK9embkuOup5o6SYTcXgcEDkRdIz+2fujjhb3XYct1oCXEq5jAy1++awVfwgbsVAT9oIkyYPTQpoijadhshwOyUvAuhN9tgB1rHBFOAz4Ej6TZxhJOIJuM+QSPp5irF7zSFH2NhBsPpYtiKwaDQxPfVZogeUYNtBf6a06BqXSLOv46vxgXJDX6rzdvxruxp6YLjLQIzR2EMnsXqosh6Uc7KHDUg00ZmggE1/7/QXWuktgw2W0pwXXJQVFwGE35HOI/wGAjc18XbD+Bc8iW6p4VnlQ01Nkoz42OU2PAvTwJ0YC3miICkvZOfcYKbfVmo9N2LJxUOFZ+18jq3LWFCNOr+/Dk3LKZSMiEc2pUVcLPJHHPs8lbC1GpzuE4I430I0kkP4twloMfDwH9fKe4cort X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f2038e72-d12a-419b-e5b3-08d95c1a0512 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2021 16:15:07.5994 (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: G5XY02orrjjGuy04TzbSVo/2wULUtxPKjsjsmszPT8uRuwZFtJUwyqOF/87B8jizSp+lGh3orM8bvEJPYe+r6Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB2800 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Since the DSA conversion from the ds->ports array into the dst->ports list, the DSA API has encouraged driver writers to write inefficient code. Currently, switch drivers which want to filter by a specific type of port when iterating, like {!unused, user, cpu, dsa}, use the dsa_is_*_port helper. Under the hood, this uses dsa_to_port which iterates again through dst->ports. But the driver iterates through the port list already, so the complexity is quadratic for the typical case of a single-switch tree. Many drivers also call dsa_to_port many times while iterating and do not even cache the result, probably unaware of the hidden complexity of this function. When drivers need to iterate between pairs of {to, from} ports, and use any of the functions above, the complexity is even higher. Use the newly introduced DSA port iterators, and also introduce some more which are not directly needed by the DSA core. Note that the b53_br_{join,leave} functions have been converted to use the dp-based iterators, but to preserve the original behavior, the dev->enabled_ports check from b53_for_each_port has been split out and open-coded. This will be addressed in the next patch. Signed-off-by: Vladimir Oltean --- v1->v2: remove an unused "int port" variable in felix_vsc9959.c drivers/net/dsa/b53/b53_common.c | 22 ++- drivers/net/dsa/bcm_sf2.c | 8 +- drivers/net/dsa/hirschmann/hellcreek.c | 27 +-- .../net/dsa/hirschmann/hellcreek_hwtstamp.c | 19 +- drivers/net/dsa/microchip/ksz9477.c | 19 +- drivers/net/dsa/microchip/ksz_common.c | 19 +- drivers/net/dsa/mt7530.c | 58 +++--- drivers/net/dsa/mv88e6xxx/chip.c | 37 ++-- drivers/net/dsa/mv88e6xxx/hwtstamp.c | 10 +- drivers/net/dsa/mv88e6xxx/port.c | 12 +- drivers/net/dsa/ocelot/felix.c | 79 +++----- drivers/net/dsa/ocelot/felix_vsc9959.c | 11 +- drivers/net/dsa/ocelot/seville_vsc9953.c | 14 +- drivers/net/dsa/qca8k.c | 32 ++-- drivers/net/dsa/sja1105/sja1105_main.c | 176 ++++++++---------- drivers/net/dsa/sja1105/sja1105_mdio.c | 12 +- drivers/net/dsa/xrs700x/xrs700x.c | 37 ++-- include/net/dsa.h | 19 ++ 18 files changed, 284 insertions(+), 327 deletions(-) diff --git a/drivers/net/dsa/b53/b53_common.c b/drivers/net/dsa/b53/b53_common.c index bd1417a66cbf..ccd93147d994 100644 --- a/drivers/net/dsa/b53/b53_common.c +++ b/drivers/net/dsa/b53/b53_common.c @@ -1851,6 +1851,7 @@ int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br) { struct b53_device *dev = ds->priv; s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index; + struct dsa_port *dp; u16 pvlan, reg; unsigned int i; @@ -1873,8 +1874,13 @@ int b53_br_join(struct dsa_switch *ds, int port, struct net_device *br) b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); - b53_for_each_port(dev, i) { - if (dsa_to_port(ds, i)->bridge_dev != br) + dsa_switch_for_each_port(dp, ds) { + i = dp->index; + + if (!(dev->enabled_ports & BIT(i))) + continue; + + if (dp->bridge_dev != br) continue; /* Add this local port to the remote port VLAN control @@ -1903,14 +1909,20 @@ void b53_br_leave(struct dsa_switch *ds, int port, struct net_device *br) struct b53_device *dev = ds->priv; struct b53_vlan *vl = &dev->vlans[0]; s8 cpu_port = dsa_to_port(ds, port)->cpu_dp->index; - unsigned int i; u16 pvlan, reg, pvid; + struct dsa_port *dp; + unsigned int i; b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(port), &pvlan); - b53_for_each_port(dev, i) { + dsa_switch_for_each_port(dp, ds) { + i = dp->index; + + if (!(dev->enabled_ports & BIT(i))) + continue; + /* Don't touch the remaining ports */ - if (dsa_to_port(ds, i)->bridge_dev != br) + if (dp->bridge_dev != br) continue; b53_read16(dev, B53_PVLAN_PAGE, B53_PVLAN_PORT_MASK(i), ®); diff --git a/drivers/net/dsa/bcm_sf2.c b/drivers/net/dsa/bcm_sf2.c index 6ce9ec1283e0..2f78fb88ed9e 100644 --- a/drivers/net/dsa/bcm_sf2.c +++ b/drivers/net/dsa/bcm_sf2.c @@ -913,7 +913,7 @@ static void bcm_sf2_enable_acb(struct dsa_switch *ds) static int bcm_sf2_sw_suspend(struct dsa_switch *ds) { struct bcm_sf2_priv *priv = bcm_sf2_to_priv(ds); - unsigned int port; + struct dsa_port *dp; bcm_sf2_intr_disable(priv); @@ -921,10 +921,8 @@ static int bcm_sf2_sw_suspend(struct dsa_switch *ds) * port, the other ones have already been disabled during * bcm_sf2_sw_setup */ - for (port = 0; port < ds->num_ports; port++) { - if (dsa_is_user_port(ds, port) || dsa_is_cpu_port(ds, port)) - bcm_sf2_port_disable(ds, port); - } + dsa_switch_for_each_available_port(dp, ds) + bcm_sf2_port_disable(ds, dp->index); if (!priv->wol_ports_mask) clk_disable_unprepare(priv->clk); diff --git a/drivers/net/dsa/hirschmann/hellcreek.c b/drivers/net/dsa/hirschmann/hellcreek.c index 5c54ae1be62c..c439c4b09211 100644 --- a/drivers/net/dsa/hirschmann/hellcreek.c +++ b/drivers/net/dsa/hirschmann/hellcreek.c @@ -345,7 +345,7 @@ static int hellcreek_vlan_prepare(struct dsa_switch *ds, int port, struct netlink_ext_ack *extack) { struct hellcreek *hellcreek = ds->priv; - int i; + struct dsa_port *dp; dev_dbg(hellcreek->dev, "VLAN prepare for port %d\n", port); @@ -353,11 +353,8 @@ static int hellcreek_vlan_prepare(struct dsa_switch *ds, int port, * VLANs are internally used by the driver to ensure port * separation. Thus, they cannot be used by someone else. */ - for (i = 0; i < hellcreek->pdata->num_ports; ++i) { - const u16 restricted_vid = hellcreek_private_vid(i); - - if (!dsa_is_user_port(ds, i)) - continue; + dsa_switch_for_each_user_port(dp, ds) { + const u16 restricted_vid = hellcreek_private_vid(dp->index); if (vlan->vid == restricted_vid) { NL_SET_ERR_MSG_MOD(extack, "VID restricted by driver"); @@ -1304,8 +1301,9 @@ static void hellcreek_teardown_devlink_regions(struct dsa_switch *ds) static int hellcreek_setup(struct dsa_switch *ds) { struct hellcreek *hellcreek = ds->priv; + struct dsa_port *dp; u16 swcfg = 0; - int ret, i; + int ret; dev_dbg(hellcreek->dev, "Set up the switch\n"); @@ -1331,12 +1329,8 @@ static int hellcreek_setup(struct dsa_switch *ds) hellcreek_write(hellcreek, swcfg, HR_SWCFG); /* Initial vlan membership to reflect port separation */ - for (i = 0; i < ds->num_ports; ++i) { - if (!dsa_is_user_port(ds, i)) - continue; - - hellcreek_setup_vlan_membership(ds, i, true); - } + dsa_switch_for_each_user_port(dp, ds) + hellcreek_setup_vlan_membership(ds, dp->index, true); /* Configure PCP <-> TC mapping */ hellcreek_setup_tc_identity_mapping(hellcreek); @@ -1413,10 +1407,10 @@ hellcreek_port_prechangeupper(struct dsa_switch *ds, int port, struct netdev_notifier_changeupper_info *info) { struct hellcreek *hellcreek = ds->priv; + struct dsa_port *dp; bool used = true; int ret = -EBUSY; u16 vid; - int i; dev_dbg(hellcreek->dev, "Pre change upper for port %d\n", port); @@ -1435,9 +1429,8 @@ hellcreek_port_prechangeupper(struct dsa_switch *ds, int port, /* For all ports, check bitmaps */ mutex_lock(&hellcreek->vlan_lock); - for (i = 0; i < hellcreek->pdata->num_ports; ++i) { - if (!dsa_is_user_port(ds, i)) - continue; + dsa_switch_for_each_user_port(dp, ds) { + int i = dp->index; if (port == i) continue; diff --git a/drivers/net/dsa/hirschmann/hellcreek_hwtstamp.c b/drivers/net/dsa/hirschmann/hellcreek_hwtstamp.c index 40b41c794dfa..1cbae1654dfe 100644 --- a/drivers/net/dsa/hirschmann/hellcreek_hwtstamp.c +++ b/drivers/net/dsa/hirschmann/hellcreek_hwtstamp.c @@ -354,13 +354,12 @@ long hellcreek_hwtstamp_work(struct ptp_clock_info *ptp) { struct hellcreek *hellcreek = ptp_to_hellcreek(ptp); struct dsa_switch *ds = hellcreek->ds; - int i, restart = 0; + struct dsa_port *dp; + int restart = 0; - for (i = 0; i < ds->num_ports; i++) { + dsa_switch_for_each_user_port(dp, ds) { struct hellcreek_port_hwtstamp *ps; - - if (!dsa_is_user_port(ds, i)) - continue; + int i = dp->index; ps = &hellcreek->ports[i].port_hwtstamp; @@ -459,15 +458,11 @@ static void hellcreek_hwtstamp_port_setup(struct hellcreek *hellcreek, int port) int hellcreek_hwtstamp_setup(struct hellcreek *hellcreek) { struct dsa_switch *ds = hellcreek->ds; - int i; + struct dsa_port *dp; /* Initialize timestamping ports. */ - for (i = 0; i < ds->num_ports; ++i) { - if (!dsa_is_user_port(ds, i)) - continue; - - hellcreek_hwtstamp_port_setup(hellcreek, i); - } + dsa_switch_for_each_user_port(dp, ds) + hellcreek_hwtstamp_port_setup(hellcreek, dp->index); /* Select the synchronized clock as the source timekeeper for the * timestamps and enable inline timestamping. diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c index 854e25f43fa7..a7435c581e49 100644 --- a/drivers/net/dsa/microchip/ksz9477.c +++ b/drivers/net/dsa/microchip/ksz9477.c @@ -1266,11 +1266,14 @@ static void ksz9477_port_setup(struct ksz_device *dev, int port, bool cpu_port) static void ksz9477_config_cpu_port(struct dsa_switch *ds) { struct ksz_device *dev = ds->priv; + struct dsa_port *dp; struct ksz_port *p; int i; - for (i = 0; i < dev->port_cnt; i++) { - if (dsa_is_cpu_port(ds, i) && (dev->cpu_ports & (1 << i))) { + dsa_switch_for_each_port(dp, ds) { + i = dp->index; + + if (dsa_port_is_cpu(dp) && (dev->cpu_ports & (1 << i))) { phy_interface_t interface; const char *prev_msg; const char *prev_mode; @@ -1609,18 +1612,22 @@ static const struct ksz_dev_ops ksz9477_dev_ops = { int ksz9477_switch_register(struct ksz_device *dev) { - int ret, i; struct phy_device *phydev; + struct dsa_switch *ds; + struct dsa_port *dp; + int ret; ret = ksz_switch_register(dev, &ksz9477_dev_ops); if (ret) return ret; - for (i = 0; i < dev->phy_port_cnt; ++i) { - if (!dsa_is_user_port(dev->ds, i)) + ds = dev->ds; + + dsa_switch_for_each_user_port(dp, ds) { + if (dp->index >= dev->phy_port_cnt) continue; - phydev = dsa_to_port(dev->ds, i)->slave->phydev; + phydev = dp->slave->phydev; /* The MAC actually cannot run in 1000 half-duplex mode. */ phy_remove_link_mode(phydev, diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c index 1542bfb8b5e5..2b188f998115 100644 --- a/drivers/net/dsa/microchip/ksz_common.c +++ b/drivers/net/dsa/microchip/ksz_common.c @@ -68,28 +68,23 @@ static void ksz_mib_read_work(struct work_struct *work) { struct ksz_device *dev = container_of(work, struct ksz_device, mib_read.work); + struct dsa_switch *ds = dev->ds; struct ksz_port_mib *mib; + struct dsa_port *dp; struct ksz_port *p; - int i; - - for (i = 0; i < dev->port_cnt; i++) { - if (dsa_is_unused_port(dev->ds, i)) - continue; - p = &dev->ports[i]; + dsa_switch_for_each_available_port(dp, ds) { + p = &dev->ports[dp->index]; mib = &p->mib; mutex_lock(&mib->cnt_mutex); /* Only read MIB counters when the port is told to do. * If not, read only dropped counters when link is not up. */ - if (!p->read) { - const struct dsa_port *dp = dsa_to_port(dev->ds, i); + if (!p->read && !netif_carrier_ok(dp->slave)) + mib->cnt_ptr = dev->reg_mib_cnt; - if (!netif_carrier_ok(dp->slave)) - mib->cnt_ptr = dev->reg_mib_cnt; - } - port_r_cnt(dev, i); + port_r_cnt(dev, dp->index); p->read = false; mutex_unlock(&mib->cnt_mutex); } diff --git a/drivers/net/dsa/mt7530.c b/drivers/net/dsa/mt7530.c index 53e6150e95b6..010d4bb7794f 100644 --- a/drivers/net/dsa/mt7530.c +++ b/drivers/net/dsa/mt7530.c @@ -1195,25 +1195,27 @@ mt7530_port_bridge_join(struct dsa_switch *ds, int port, { struct mt7530_priv *priv = ds->priv; u32 port_bitmap = BIT(MT7530_CPU_PORT); - int i; + struct dsa_port *dp; mutex_lock(&priv->reg_mutex); - for (i = 0; i < MT7530_NUM_PORTS; i++) { + dsa_switch_for_each_user_port(dp, ds) { + if (dp->index == port) + continue; + + if (dp->bridge_dev != bridge) + continue; + /* Add this port to the port matrix of the other ports in the * same bridge. If the port is disabled, port matrix is kept * and not being setup until the port becomes enabled. */ - if (dsa_is_user_port(ds, i) && i != port) { - if (dsa_to_port(ds, i)->bridge_dev != bridge) - continue; - if (priv->ports[i].enable) - mt7530_set(priv, MT7530_PCR_P(i), - PCR_MATRIX(BIT(port))); - priv->ports[i].pm |= PCR_MATRIX(BIT(port)); + if (priv->ports[dp->index].enable) + mt7530_set(priv, MT7530_PCR_P(dp->index), + PCR_MATRIX(BIT(port))); + priv->ports[dp->index].pm |= PCR_MATRIX(BIT(port)); - port_bitmap |= BIT(i); - } + port_bitmap |= BIT(dp->index); } /* Add the all other ports to this port matrix. */ @@ -1236,7 +1238,7 @@ mt7530_port_set_vlan_unaware(struct dsa_switch *ds, int port) { struct mt7530_priv *priv = ds->priv; bool all_user_ports_removed = true; - int i; + struct dsa_port *dp; /* This is called after .port_bridge_leave when leaving a VLAN-aware * bridge. Don't set standalone ports to fallback mode. @@ -1255,9 +1257,8 @@ mt7530_port_set_vlan_unaware(struct dsa_switch *ds, int port) mt7530_rmw(priv, MT7530_PPBV1_P(port), G0_PORT_VID_MASK, G0_PORT_VID_DEF); - for (i = 0; i < MT7530_NUM_PORTS; i++) { - if (dsa_is_user_port(ds, i) && - dsa_port_is_vlan_filtering(dsa_to_port(ds, i))) { + dsa_switch_for_each_user_port(dp, ds) { + if (dsa_port_is_vlan_filtering(dp)) { all_user_ports_removed = false; break; } @@ -1307,26 +1308,31 @@ mt7530_port_bridge_leave(struct dsa_switch *ds, int port, struct net_device *bridge) { struct mt7530_priv *priv = ds->priv; - int i; + struct dsa_port *dp; mutex_lock(&priv->reg_mutex); - for (i = 0; i < MT7530_NUM_PORTS; i++) { + dsa_switch_for_each_user_port(dp, ds) { /* Remove this port from the port matrix of the other ports * in the same bridge. If the port is disabled, port matrix * is kept and not being setup until the port becomes enabled. * And the other port's port matrix cannot be broken when the * other port is still a VLAN-aware port. */ - if (dsa_is_user_port(ds, i) && i != port && - !dsa_port_is_vlan_filtering(dsa_to_port(ds, i))) { - if (dsa_to_port(ds, i)->bridge_dev != bridge) - continue; - if (priv->ports[i].enable) - mt7530_clear(priv, MT7530_PCR_P(i), - PCR_MATRIX(BIT(port))); - priv->ports[i].pm &= ~PCR_MATRIX(BIT(port)); - } + if (dp->index == port) + continue; + + if (dsa_port_is_vlan_filtering(dp)) + continue; + + if (dp->bridge_dev != bridge) + continue; + + if (priv->ports[dp->index].enable) + mt7530_clear(priv, MT7530_PCR_P(dp->index), + PCR_MATRIX(BIT(port))); + + priv->ports[dp->index].pm &= ~PCR_MATRIX(BIT(port)); } /* Set the cpu port to be the only one in the port matrix of diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index c45ca2473743..1525415aca46 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -1635,9 +1635,11 @@ static int mv88e6xxx_atu_new(struct mv88e6xxx_chip *chip, u16 *fid) static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port, u16 vid) { + struct dsa_port *dp = dsa_to_port(ds, port); struct mv88e6xxx_chip *chip = ds->priv; struct mv88e6xxx_vtu_entry vlan; - int i, err; + struct dsa_port *other_dp; + int err; /* DSA and CPU ports have to be members of multiple vlans */ if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port)) @@ -1650,27 +1652,20 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port, if (!vlan.valid) return 0; - for (i = 0; i < mv88e6xxx_num_ports(chip); ++i) { - if (dsa_is_dsa_port(ds, i) || dsa_is_cpu_port(ds, i)) - continue; - - if (!dsa_to_port(ds, i)->slave) - continue; - - if (vlan.member[i] == + dsa_switch_for_each_user_port(other_dp, ds) { + if (vlan.member[other_dp->index] == MV88E6XXX_G1_VTU_DATA_MEMBER_TAG_NON_MEMBER) continue; - if (dsa_to_port(ds, i)->bridge_dev == - dsa_to_port(ds, port)->bridge_dev) + if (other_dp->bridge_dev == dp->bridge_dev) break; /* same bridge, check next VLAN */ - if (!dsa_to_port(ds, i)->bridge_dev) + if (!other_dp->bridge_dev) continue; dev_err(ds->dev, "p%d: hw VLAN %d already used by port %d in %s\n", - port, vlan.vid, i, - netdev_name(dsa_to_port(ds, i)->bridge_dev)); + port, vlan.vid, other_dp->index, + netdev_name(other_dp->bridge_dev)); return -EOPNOTSUPP; } @@ -1996,16 +1991,14 @@ static int mv88e6xxx_port_add_broadcast(struct mv88e6xxx_chip *chip, int port, static int mv88e6xxx_broadcast_setup(struct mv88e6xxx_chip *chip, u16 vid) { + struct dsa_switch *ds = chip->ds; + struct dsa_port *dp; int port; int err; - for (port = 0; port < mv88e6xxx_num_ports(chip); port++) { - struct dsa_port *dp = dsa_to_port(chip->ds, port); + dsa_switch_for_each_available_port(dp, ds) { struct net_device *brport; - if (dsa_is_unused_port(chip->ds, port)) - continue; - brport = dsa_port_to_bridge_port(dp); if (brport && !br_port_flag_is_set(brport, BR_BCAST_FLOOD)) /* Skip bridged user ports where broadcast @@ -3077,6 +3070,7 @@ static void mv88e6xxx_teardown(struct dsa_switch *ds) static int mv88e6xxx_setup(struct dsa_switch *ds) { struct mv88e6xxx_chip *chip = ds->priv; + struct dsa_port *dp; u8 cmode; int err; int i; @@ -3113,9 +3107,8 @@ static int mv88e6xxx_setup(struct dsa_switch *ds) } /* Setup Switch Port Registers */ - for (i = 0; i < mv88e6xxx_num_ports(chip); i++) { - if (dsa_is_unused_port(ds, i)) - continue; + dsa_switch_for_each_available_port(dp, ds) { + i = dp->index; /* Prevent the use of an invalid port. */ if (mv88e6xxx_is_invalid_port(chip, i)) { diff --git a/drivers/net/dsa/mv88e6xxx/hwtstamp.c b/drivers/net/dsa/mv88e6xxx/hwtstamp.c index 8f74ffc7a279..73153249b4c0 100644 --- a/drivers/net/dsa/mv88e6xxx/hwtstamp.c +++ b/drivers/net/dsa/mv88e6xxx/hwtstamp.c @@ -452,13 +452,11 @@ long mv88e6xxx_hwtstamp_work(struct ptp_clock_info *ptp) struct mv88e6xxx_chip *chip = ptp_to_chip(ptp); struct dsa_switch *ds = chip->ds; struct mv88e6xxx_port_hwtstamp *ps; - int i, restart = 0; + struct dsa_port *dp; + int restart = 0; - for (i = 0; i < ds->num_ports; i++) { - if (!dsa_is_user_port(ds, i)) - continue; - - ps = &chip->port_hwtstamp[i]; + dsa_switch_for_each_user_port(dp, ds) { + ps = &chip->port_hwtstamp[dp->index]; if (test_bit(MV88E6XXX_HWTSTAMP_TX_IN_PROGRESS, &ps->state)) restart |= mv88e6xxx_txtstamp_work(chip, ps); diff --git a/drivers/net/dsa/mv88e6xxx/port.c b/drivers/net/dsa/mv88e6xxx/port.c index f77e2ee64a60..2c300ab70002 100644 --- a/drivers/net/dsa/mv88e6xxx/port.c +++ b/drivers/net/dsa/mv88e6xxx/port.c @@ -1381,13 +1381,13 @@ static int mv88e6393x_port_policy_write(struct mv88e6xxx_chip *chip, int port, static int mv88e6393x_port_policy_write_all(struct mv88e6xxx_chip *chip, u16 pointer, u8 data) { - int err, port; - - for (port = 0; port < mv88e6xxx_num_ports(chip); port++) { - if (dsa_is_unused_port(chip->ds, port)) - continue; + struct dsa_switch *ds = chip->ds; + struct dsa_port *dp; + int err; - err = mv88e6393x_port_policy_write(chip, port, pointer, data); + dsa_switch_for_each_available_port(dp, ds) { + err = mv88e6393x_port_policy_write(chip, dp->index, pointer, + data); if (err) return err; } diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c index 9505f9b3ac90..f4bd43545f04 100644 --- a/drivers/net/dsa/ocelot/felix.c +++ b/drivers/net/dsa/ocelot/felix.c @@ -266,12 +266,12 @@ static void felix_8021q_cpu_port_deinit(struct ocelot *ocelot, int port) */ static int felix_setup_mmio_filtering(struct felix *felix) { - unsigned long user_ports = 0, cpu_ports = 0; + unsigned long user_ports = dsa_user_ports(felix->ds); + unsigned long cpu_ports = dsa_cpu_ports(felix->ds); struct ocelot_vcap_filter *redirect_rule; struct ocelot_vcap_filter *tagging_rule; struct ocelot *ocelot = &felix->ocelot; - struct dsa_switch *ds = felix->ds; - int port, ret; + int ret; tagging_rule = kzalloc(sizeof(struct ocelot_vcap_filter), GFP_KERNEL); if (!tagging_rule) @@ -283,13 +283,6 @@ static int felix_setup_mmio_filtering(struct felix *felix) return -ENOMEM; } - for (port = 0; port < ocelot->num_phys_ports; port++) { - if (dsa_is_user_port(ds, port)) - user_ports |= BIT(port); - if (dsa_is_cpu_port(ds, port)) - cpu_ports |= BIT(port); - } - tagging_rule->key_type = OCELOT_VCAP_KEY_ETYPE; *(__be16 *)tagging_rule->key.etype.etype.value = htons(ETH_P_1588); *(__be16 *)tagging_rule->key.etype.etype.mask = htons(0xffff); @@ -388,14 +381,12 @@ static int felix_setup_tag_8021q(struct dsa_switch *ds, int cpu) struct ocelot *ocelot = ds->priv; struct felix *felix = ocelot_to_felix(ocelot); unsigned long cpu_flood; - int port, err; + struct dsa_port *dp; + int err; felix_8021q_cpu_port_init(ocelot, cpu); - for (port = 0; port < ds->num_ports; port++) { - if (dsa_is_unused_port(ds, port)) - continue; - + dsa_switch_for_each_available_port(dp, ds) { /* This overwrites ocelot_init(): * Do not forward BPDU frames to the CPU port module, * for 2 reasons: @@ -408,7 +399,7 @@ static int felix_setup_tag_8021q(struct dsa_switch *ds, int cpu) */ ocelot_write_gix(ocelot, ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0), - ANA_PORT_CPU_FWD_BPDU_CFG, port); + ANA_PORT_CPU_FWD_BPDU_CFG, dp->index); } /* In tag_8021q mode, the CPU port module is unused, except for PTP @@ -439,7 +430,8 @@ static void felix_teardown_tag_8021q(struct dsa_switch *ds, int cpu) { struct ocelot *ocelot = ds->priv; struct felix *felix = ocelot_to_felix(ocelot); - int err, port; + struct dsa_port *dp; + int err; err = felix_teardown_mmio_filtering(felix); if (err) @@ -448,17 +440,14 @@ static void felix_teardown_tag_8021q(struct dsa_switch *ds, int cpu) dsa_tag_8021q_unregister(ds); - for (port = 0; port < ds->num_ports; port++) { - if (dsa_is_unused_port(ds, port)) - continue; - + dsa_switch_for_each_available_port(dp, ds) { /* Restore the logic from ocelot_init: * do not forward BPDU frames to the front ports. */ ocelot_write_gix(ocelot, ANA_PORT_CPU_FWD_BPDU_CFG_BPDU_REDIR_ENA(0xffff), ANA_PORT_CPU_FWD_BPDU_CFG, - port); + dp->index); } felix_8021q_cpu_port_deinit(ocelot, cpu); @@ -1178,7 +1167,8 @@ static int felix_setup(struct dsa_switch *ds) { struct ocelot *ocelot = ds->priv; struct felix *felix = ocelot_to_felix(ocelot); - int port, err; + struct dsa_port *dp; + int err; err = felix_init_structs(felix, ds->num_ports); if (err) @@ -1197,31 +1187,24 @@ static int felix_setup(struct dsa_switch *ds) } } - for (port = 0; port < ds->num_ports; port++) { - if (dsa_is_unused_port(ds, port)) - continue; - - ocelot_init_port(ocelot, port); + dsa_switch_for_each_available_port(dp, ds) { + ocelot_init_port(ocelot, dp->index); /* Set the default QoS Classification based on PCP and DEI * bits of vlan tag. */ - felix_port_qos_map_init(ocelot, port); + felix_port_qos_map_init(ocelot, dp->index); } err = ocelot_devlink_sb_register(ocelot); if (err) goto out_deinit_ports; - for (port = 0; port < ds->num_ports; port++) { - if (!dsa_is_cpu_port(ds, port)) - continue; - + dsa_switch_for_each_cpu_port(dp, ds) /* The initial tag protocol is NPI which always returns 0, so * there's no real point in checking for errors. */ - felix_set_tag_protocol(ds, port, felix->tag_proto); - } + felix_set_tag_protocol(ds, dp->index, felix->tag_proto); ds->mtu_enforcement_ingress = true; ds->assisted_learning_on_cpu_port = true; @@ -1229,12 +1212,8 @@ static int felix_setup(struct dsa_switch *ds) return 0; out_deinit_ports: - for (port = 0; port < ocelot->num_phys_ports; port++) { - if (dsa_is_unused_port(ds, port)) - continue; - - ocelot_deinit_port(ocelot, port); - } + dsa_switch_for_each_available_port(dp, ds) + ocelot_deinit_port(ocelot, dp->index); ocelot_deinit_timestamp(ocelot); ocelot_deinit(ocelot); @@ -1250,25 +1229,17 @@ static void felix_teardown(struct dsa_switch *ds) { struct ocelot *ocelot = ds->priv; struct felix *felix = ocelot_to_felix(ocelot); - int port; - - for (port = 0; port < ds->num_ports; port++) { - if (!dsa_is_cpu_port(ds, port)) - continue; + struct dsa_port *dp; - felix_del_tag_protocol(ds, port, felix->tag_proto); - } + dsa_switch_for_each_cpu_port(dp, ds) + felix_del_tag_protocol(ds, dp->index, felix->tag_proto); ocelot_devlink_sb_unregister(ocelot); ocelot_deinit_timestamp(ocelot); ocelot_deinit(ocelot); - for (port = 0; port < ocelot->num_phys_ports; port++) { - if (dsa_is_unused_port(ds, port)) - continue; - - ocelot_deinit_port(ocelot, port); - } + dsa_switch_for_each_available_port(dp, ds) + ocelot_deinit_port(ocelot, dp->index); if (felix->info->mdio_bus_free) felix->info->mdio_bus_free(ocelot); diff --git a/drivers/net/dsa/ocelot/felix_vsc9959.c b/drivers/net/dsa/ocelot/felix_vsc9959.c index f966a253d1c7..493ffa40ee40 100644 --- a/drivers/net/dsa/ocelot/felix_vsc9959.c +++ b/drivers/net/dsa/ocelot/felix_vsc9959.c @@ -1034,13 +1034,14 @@ static const struct ocelot_ops vsc9959_ops = { static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot) { struct felix *felix = ocelot_to_felix(ocelot); + struct dsa_switch *ds = felix->ds; struct enetc_mdio_priv *mdio_priv; struct device *dev = ocelot->dev; void __iomem *imdio_regs; struct resource res; struct enetc_hw *hw; struct mii_bus *bus; - int port; + struct dsa_port *dp; int rc; felix->pcs = devm_kcalloc(dev, felix->info->num_ports, @@ -1091,13 +1092,11 @@ static int vsc9959_mdio_bus_alloc(struct ocelot *ocelot) felix->imdio = bus; - for (port = 0; port < felix->info->num_ports; port++) { - struct ocelot_port *ocelot_port = ocelot->ports[port]; + dsa_switch_for_each_available_port(dp, ds) { + struct ocelot_port *ocelot_port = ocelot->ports[dp->index]; struct mdio_device *pcs; struct lynx_pcs *lynx; - - if (dsa_is_unused_port(felix->ds, port)) - continue; + int port = dp->index; if (ocelot_port->phy_mode == PHY_INTERFACE_MODE_INTERNAL) continue; diff --git a/drivers/net/dsa/ocelot/seville_vsc9953.c b/drivers/net/dsa/ocelot/seville_vsc9953.c index deae923c8b7a..fe7828c402bd 100644 --- a/drivers/net/dsa/ocelot/seville_vsc9953.c +++ b/drivers/net/dsa/ocelot/seville_vsc9953.c @@ -1085,9 +1085,10 @@ static const struct ocelot_ops vsc9953_ops = { static int vsc9953_mdio_bus_alloc(struct ocelot *ocelot) { struct felix *felix = ocelot_to_felix(ocelot); + struct dsa_switch *ds = felix->ds; struct device *dev = ocelot->dev; + struct dsa_port *dp; struct mii_bus *bus; - int port; int rc; felix->pcs = devm_kcalloc(dev, felix->info->num_ports, @@ -1118,15 +1119,12 @@ static int vsc9953_mdio_bus_alloc(struct ocelot *ocelot) felix->imdio = bus; - for (port = 0; port < felix->info->num_ports; port++) { - struct ocelot_port *ocelot_port = ocelot->ports[port]; - int addr = port + 4; + dsa_switch_for_each_available_port(dp, ds) { + struct ocelot_port *ocelot_port = ocelot->ports[dp->index]; + int addr = dp->index + 4; struct mdio_device *pcs; struct lynx_pcs *lynx; - if (dsa_is_unused_port(felix->ds, port)) - continue; - if (ocelot_port->phy_mode == PHY_INTERFACE_MODE_INTERNAL) continue; @@ -1140,7 +1138,7 @@ static int vsc9953_mdio_bus_alloc(struct ocelot *ocelot) continue; } - felix->pcs[port] = lynx; + felix->pcs[dp->index] = lynx; dev_info(dev, "Found PCS at internal MDIO address %d\n", addr); } diff --git a/drivers/net/dsa/qca8k.c b/drivers/net/dsa/qca8k.c index 1f63f50f73f1..f2c1369c2bff 100644 --- a/drivers/net/dsa/qca8k.c +++ b/drivers/net/dsa/qca8k.c @@ -940,6 +940,7 @@ static int qca8k_setup(struct dsa_switch *ds) { struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; + struct dsa_port *dp; int ret, i; u32 mask; @@ -1009,9 +1010,11 @@ qca8k_setup(struct dsa_switch *ds) return ret; /* Setup connection between CPU port & user ports */ - for (i = 0; i < QCA8K_NUM_PORTS; i++) { + dsa_switch_for_each_port(dp, ds) { + i = dp->index; + /* CPU port gets connected to all user ports of the switch */ - if (dsa_is_cpu_port(ds, i)) { + if (dsa_port_is_cpu(dp)) { ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(QCA8K_CPU_PORT), QCA8K_PORT_LOOKUP_MEMBER, dsa_user_ports(ds)); if (ret) @@ -1019,7 +1022,7 @@ qca8k_setup(struct dsa_switch *ds) } /* Individual user ports get connected to CPU port only */ - if (dsa_is_user_port(ds, i)) { + if (dsa_port_is_user(dp)) { int shift = 16 * (i % 2); ret = qca8k_rmw(priv, QCA8K_PORT_LOOKUP_CTRL(i), @@ -1509,21 +1512,23 @@ qca8k_port_bridge_join(struct dsa_switch *ds, int port, struct net_device *br) { struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; int port_mask = BIT(QCA8K_CPU_PORT); - int i, ret; + struct dsa_port *dp; + int ret; - for (i = 1; i < QCA8K_NUM_PORTS; i++) { - if (dsa_to_port(ds, i)->bridge_dev != br) + dsa_switch_for_each_port(dp, ds) { + if (dp->bridge_dev != br) continue; + /* Add this port to the portvlan mask of the other ports * in the bridge */ ret = qca8k_reg_set(priv, - QCA8K_PORT_LOOKUP_CTRL(i), + QCA8K_PORT_LOOKUP_CTRL(dp->index), BIT(port)); if (ret) return ret; - if (i != port) - port_mask |= BIT(i); + if (dp->index != port) + port_mask |= BIT(dp->index); } /* Add all other ports to this ports portvlan mask */ @@ -1537,16 +1542,17 @@ static void qca8k_port_bridge_leave(struct dsa_switch *ds, int port, struct net_device *br) { struct qca8k_priv *priv = (struct qca8k_priv *)ds->priv; - int i; + struct dsa_port *dp; - for (i = 1; i < QCA8K_NUM_PORTS; i++) { - if (dsa_to_port(ds, i)->bridge_dev != br) + dsa_switch_for_each_port(dp, ds) { + if (dp->bridge_dev != br) continue; + /* Remove this port to the portvlan mask of the other ports * in the bridge */ qca8k_reg_clear(priv, - QCA8K_PORT_LOOKUP_CTRL(i), + QCA8K_PORT_LOOKUP_CTRL(dp->index), BIT(port)); } diff --git a/drivers/net/dsa/sja1105/sja1105_main.c b/drivers/net/dsa/sja1105/sja1105_main.c index f7219bca45e9..cd6e3f40d474 100644 --- a/drivers/net/dsa/sja1105/sja1105_main.c +++ b/drivers/net/dsa/sja1105/sja1105_main.c @@ -207,10 +207,7 @@ static int sja1105_init_mac_settings(struct sja1105_private *priv) mac = table->entries; - list_for_each_entry(dp, &ds->dst->ports, list) { - if (dp->ds != ds) - continue; - + dsa_switch_for_each_available_port(dp, ds) { mac[dp->index] = default_mac; /* Let sja1105_bridge_stp_state_set() keep address learning @@ -239,7 +236,7 @@ static int sja1105_init_mii_settings(struct sja1105_private *priv) struct sja1105_xmii_params_entry *mii; struct dsa_switch *ds = priv->ds; struct sja1105_table *table; - int i; + struct dsa_port *dp; table = &priv->static_config.tables[BLK_IDX_XMII_PARAMS]; @@ -259,11 +256,9 @@ static int sja1105_init_mii_settings(struct sja1105_private *priv) mii = table->entries; - for (i = 0; i < ds->num_ports; i++) { + dsa_switch_for_each_available_port(dp, ds) { sja1105_mii_role_t role = XMII_MAC; - - if (dsa_is_unused_port(priv->ds, i)) - continue; + int i = dp->index; switch (priv->phy_mode[i]) { case PHY_INTERFACE_MODE_INTERNAL: @@ -331,8 +326,9 @@ static int sja1105_init_mii_settings(struct sja1105_private *priv) static int sja1105_init_static_fdb(struct sja1105_private *priv) { struct sja1105_l2_lookup_entry *l2_lookup; + struct dsa_switch *ds = priv->ds; struct sja1105_table *table; - int port; + struct dsa_port *dp; table = &priv->static_config.tables[BLK_IDX_L2_LOOKUP]; @@ -363,9 +359,8 @@ static int sja1105_init_static_fdb(struct sja1105_private *priv) l2_lookup[0].index = SJA1105_MAX_L2_LOOKUP_COUNT - 1; /* Flood multicast to every port by default */ - for (port = 0; port < priv->ds->num_ports; port++) - if (!dsa_is_unused_port(priv->ds, port)) - l2_lookup[0].destports |= BIT(port); + dsa_switch_for_each_available_port(dp, ds) + l2_lookup[0].destports |= BIT(dp->index); return 0; } @@ -405,20 +400,16 @@ static int sja1105_init_l2_lookup_params(struct sja1105_private *priv) struct dsa_switch *ds = priv->ds; int port, num_used_ports = 0; struct sja1105_table *table; + struct dsa_port *dp; u64 max_fdb_entries; - for (port = 0; port < ds->num_ports; port++) - if (!dsa_is_unused_port(ds, port)) - num_used_ports++; + dsa_switch_for_each_available_port(dp, ds) + num_used_ports++; max_fdb_entries = SJA1105_MAX_L2_LOOKUP_COUNT / num_used_ports; - for (port = 0; port < ds->num_ports; port++) { - if (dsa_is_unused_port(ds, port)) - continue; - + dsa_switch_for_each_available_port(dp, ds) default_l2_lookup_params.maxaddrp[port] = max_fdb_entries; - } table = &priv->static_config.tables[BLK_IDX_L2_LOOKUP_PARAMS]; @@ -461,7 +452,7 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv) .vlanid = SJA1105_DEFAULT_VLAN, }; struct dsa_switch *ds = priv->ds; - int port; + struct dsa_port *dp; table = &priv->static_config.tables[BLK_IDX_VLAN_LOOKUP]; @@ -477,15 +468,14 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv) table->entry_count = 1; - for (port = 0; port < ds->num_ports; port++) { - if (dsa_is_unused_port(ds, port)) - continue; + dsa_switch_for_each_available_port(dp, ds) { + int port = dp->index; pvid.vmemb_port |= BIT(port); pvid.vlan_bc |= BIT(port); pvid.tag_port &= ~BIT(port); - if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) { + if (dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp)) { priv->tag_8021q_pvid[port] = SJA1105_DEFAULT_VLAN; priv->bridge_pvid[port] = SJA1105_DEFAULT_VLAN; } @@ -498,12 +488,12 @@ static int sja1105_init_static_vlan(struct sja1105_private *priv) static int sja1105_init_l2_forwarding(struct sja1105_private *priv) { struct sja1105_l2_forwarding_entry *l2fwd; + struct dsa_port *dp, *from_dp, *to_dp; struct dsa_switch *ds = priv->ds; struct dsa_switch_tree *dst; struct sja1105_table *table; struct dsa_link *dl; - int port, tc; - int from, to; + int tc; table = &priv->static_config.tables[BLK_IDX_L2_FORWARDING]; @@ -525,24 +515,21 @@ static int sja1105_init_l2_forwarding(struct sja1105_private *priv) * rules and the VLAN PCP to ingress queue mapping. * Set up the ingress queue mapping first. */ - for (port = 0; port < ds->num_ports; port++) { - if (dsa_is_unused_port(ds, port)) - continue; - + dsa_switch_for_each_available_port(dp, ds) for (tc = 0; tc < SJA1105_NUM_TC; tc++) - l2fwd[port].vlan_pmap[tc] = tc; - } + l2fwd[dp->index].vlan_pmap[tc] = tc; /* Then manage the forwarding domain for user ports. These can forward * only to the always-on domain (CPU port and DSA links) */ - for (from = 0; from < ds->num_ports; from++) { - if (!dsa_is_user_port(ds, from)) - continue; + dsa_switch_for_each_user_port(from_dp, ds) { + int from = from_dp->index; - for (to = 0; to < ds->num_ports; to++) { - if (!dsa_is_cpu_port(ds, to) && - !dsa_is_dsa_port(ds, to)) + dsa_switch_for_each_port(to_dp, ds) { + int to = to_dp->index; + + if (!dsa_port_is_cpu(to_dp) && + !dsa_port_is_dsa(to_dp)) continue; l2fwd[from].bc_domain |= BIT(to); @@ -556,13 +543,14 @@ static int sja1105_init_l2_forwarding(struct sja1105_private *priv) * always-on domain). These can send packets to any enabled port except * themselves. */ - for (from = 0; from < ds->num_ports; from++) { - if (!dsa_is_cpu_port(ds, from) && !dsa_is_dsa_port(ds, from)) + dsa_switch_for_each_port(from_dp, ds) { + int from = from_dp->index; + + if (!dsa_port_is_cpu(from_dp) && !dsa_port_is_dsa(from_dp)) continue; - for (to = 0; to < ds->num_ports; to++) { - if (dsa_is_unused_port(ds, to)) - continue; + dsa_switch_for_each_available_port(to_dp, ds) { + int to = to_dp->index; if (from == to) continue; @@ -585,6 +573,8 @@ static int sja1105_init_l2_forwarding(struct sja1105_private *priv) dst = ds->dst; list_for_each_entry(dl, &dst->rtable, list) { + int from, to; + if (dl->dp->ds != ds || dl->link_dp->cpu_dp == dl->dp->cpu_dp) continue; @@ -604,24 +594,17 @@ static int sja1105_init_l2_forwarding(struct sja1105_private *priv) /* Finally, manage the egress flooding domain. All ports start up with * flooding enabled, including the CPU port and DSA links. */ - for (port = 0; port < ds->num_ports; port++) { - if (dsa_is_unused_port(ds, port)) - continue; - - priv->ucast_egress_floods |= BIT(port); - priv->bcast_egress_floods |= BIT(port); + dsa_switch_for_each_available_port(dp, ds) { + priv->ucast_egress_floods |= BIT(dp->index); + priv->bcast_egress_floods |= BIT(dp->index); } /* Next 8 entries define VLAN PCP mapping from ingress to egress. * Create a one-to-one mapping. */ for (tc = 0; tc < SJA1105_NUM_TC; tc++) { - for (port = 0; port < ds->num_ports; port++) { - if (dsa_is_unused_port(ds, port)) - continue; - - l2fwd[ds->num_ports + tc].vlan_pmap[port] = tc; - } + dsa_switch_for_each_available_port(dp, ds) + l2fwd[ds->num_ports + tc].vlan_pmap[dp->index] = tc; l2fwd[ds->num_ports + tc].type_egrpcp2outputq = true; } @@ -634,7 +617,8 @@ static int sja1110_init_pcp_remapping(struct sja1105_private *priv) struct sja1110_pcp_remapping_entry *pcp_remap; struct dsa_switch *ds = priv->ds; struct sja1105_table *table; - int port, tc; + struct dsa_port *dp; + int tc; table = &priv->static_config.tables[BLK_IDX_PCP_REMAPPING]; @@ -657,13 +641,9 @@ static int sja1110_init_pcp_remapping(struct sja1105_private *priv) pcp_remap = table->entries; /* Repeat the configuration done for vlan_pmap */ - for (port = 0; port < ds->num_ports; port++) { - if (dsa_is_unused_port(ds, port)) - continue; - + dsa_switch_for_each_available_port(dp, ds) for (tc = 0; tc < SJA1105_NUM_TC; tc++) - pcp_remap[port].egrpcp[tc] = tc; - } + pcp_remap[dp->index].egrpcp[tc] = tc; return 0; } @@ -999,7 +979,8 @@ static int sja1105_init_l2_policing(struct sja1105_private *priv) struct sja1105_l2_policing_entry *policing; struct dsa_switch *ds = priv->ds; struct sja1105_table *table; - int port, tc; + struct dsa_port *dp; + int tc; table = &priv->static_config.tables[BLK_IDX_L2_POLICING]; @@ -1019,9 +1000,10 @@ static int sja1105_init_l2_policing(struct sja1105_private *priv) policing = table->entries; /* Setup shared indices for the matchall policers */ - for (port = 0; port < ds->num_ports; port++) { - int mcast = (ds->num_ports * (SJA1105_NUM_TC + 1)) + port; - int bcast = (ds->num_ports * SJA1105_NUM_TC) + port; + dsa_switch_for_each_available_port(dp, ds) { + int mcast = (ds->num_ports * (SJA1105_NUM_TC + 1)) + dp->index; + int bcast = (ds->num_ports * SJA1105_NUM_TC) + dp->index; + int port = dp->index; for (tc = 0; tc < SJA1105_NUM_TC; tc++) policing[port * SJA1105_NUM_TC + tc].sharindx = port; @@ -1033,10 +1015,11 @@ static int sja1105_init_l2_policing(struct sja1105_private *priv) } /* Setup the matchall policer parameters */ - for (port = 0; port < ds->num_ports; port++) { + dsa_switch_for_each_available_port(dp, ds) { int mtu = VLAN_ETH_FRAME_LEN + ETH_FCS_LEN; + int port = dp->index; - if (dsa_is_cpu_port(ds, port) || dsa_is_dsa_port(ds, port)) + if (dsa_port_is_cpu(dp) || dsa_port_is_dsa(dp)) mtu += VLAN_HLEN; policing[port].smax = 65535; /* Burst size in bytes */ @@ -1996,16 +1979,17 @@ static int sja1105_bridge_member(struct dsa_switch *ds, int port, { struct sja1105_l2_forwarding_entry *l2_fwd; struct sja1105_private *priv = ds->priv; - int i, rc; + struct dsa_port *dp; + int rc; l2_fwd = priv->static_config.tables[BLK_IDX_L2_FORWARDING].entries; - for (i = 0; i < ds->num_ports; i++) { - /* Add this port to the forwarding matrix of the - * other ports in the same bridge, and viceversa. - */ - if (!dsa_is_user_port(ds, i)) - continue; + /* Add this port to the forwarding matrix of the + * other ports in the same bridge, and viceversa. + */ + dsa_switch_for_each_user_port(dp, ds) { + int i = dp->index; + /* For the ports already under the bridge, only one thing needs * to be done, and that is to add this port to their * reachability domain. So we can perform the SPI write for @@ -2017,8 +2001,10 @@ static int sja1105_bridge_member(struct dsa_switch *ds, int port, */ if (i == port) continue; - if (dsa_to_port(ds, i)->bridge_dev != br) + + if (dp->bridge_dev != br) continue; + sja1105_port_allow_traffic(l2_fwd, i, port, member); sja1105_port_allow_traffic(l2_fwd, port, i, member); @@ -2366,6 +2352,7 @@ int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled, struct sja1105_private *priv = ds->priv; struct sja1105_table *table; struct sja1105_rule *rule; + struct dsa_port *dp; u16 tpid, tpid2; int rc; @@ -2435,11 +2422,8 @@ int sja1105_vlan_filtering(struct dsa_switch *ds, int port, bool enabled, l2_lookup_params = table->entries; l2_lookup_params->shared_learn = !priv->vlan_aware; - for (port = 0; port < ds->num_ports; port++) { - if (dsa_is_unused_port(ds, port)) - continue; - - rc = sja1105_commit_pvid(ds, port); + dsa_switch_for_each_available_port(dp, ds) { + rc = sja1105_commit_pvid(ds, dp->index); if (rc) return rc; } @@ -2753,17 +2737,14 @@ static int sja1105_setup(struct dsa_switch *ds) static void sja1105_teardown(struct dsa_switch *ds) { struct sja1105_private *priv = ds->priv; - int port; + struct dsa_port *dp; rtnl_lock(); dsa_tag_8021q_unregister(ds); rtnl_unlock(); - for (port = 0; port < ds->num_ports; port++) { - struct sja1105_port *sp = &priv->ports[port]; - - if (!dsa_is_user_port(ds, port)) - continue; + dsa_switch_for_each_user_port(dp, ds) { + struct sja1105_port *sp = &priv->ports[dp->index]; if (sp->xmit_worker) kthread_destroy_worker(sp->xmit_worker); @@ -3284,7 +3265,8 @@ static int sja1105_probe(struct spi_device *spi) struct sja1105_private *priv; size_t max_xfer, max_msg; struct dsa_switch *ds; - int rc, port; + struct dsa_port *dp; + int rc; if (!dev->of_node) { dev_err(dev, "No DTS bindings for SJA1105 driver\n"); @@ -3389,14 +3371,10 @@ static int sja1105_probe(struct spi_device *spi) } /* Connections between dsa_port and sja1105_port */ - for (port = 0; port < ds->num_ports; port++) { - struct sja1105_port *sp = &priv->ports[port]; - struct dsa_port *dp = dsa_to_port(ds, port); + dsa_switch_for_each_user_port(dp, ds) { + struct sja1105_port *sp = &priv->ports[dp->index]; struct net_device *slave; - if (!dsa_is_user_port(ds, port)) - continue; - dp->priv = sp; sp->dp = dp; sp->data = tagger_data; @@ -3418,10 +3396,10 @@ static int sja1105_probe(struct spi_device *spi) return 0; out_destroy_workers: - while (port-- > 0) { - struct sja1105_port *sp = &priv->ports[port]; + dsa_switch_for_each_port_continue_reverse(dp, ds) { + struct sja1105_port *sp = &priv->ports[dp->index]; - if (!dsa_is_user_port(ds, port)) + if (!dsa_port_is_user(dp)) continue; kthread_destroy_worker(sp->xmit_worker); diff --git a/drivers/net/dsa/sja1105/sja1105_mdio.c b/drivers/net/dsa/sja1105/sja1105_mdio.c index 19aea8fb76f6..6f8d20a5bc37 100644 --- a/drivers/net/dsa/sja1105/sja1105_mdio.c +++ b/drivers/net/dsa/sja1105/sja1105_mdio.c @@ -390,9 +390,9 @@ static int sja1105_mdiobus_pcs_register(struct sja1105_private *priv) { struct sja1105_mdio_private *mdio_priv; struct dsa_switch *ds = priv->ds; + struct dsa_port *dp; struct mii_bus *bus; int rc = 0; - int port; if (!priv->info->pcs_mdio_read || !priv->info->pcs_mdio_write) return 0; @@ -420,12 +420,10 @@ static int sja1105_mdiobus_pcs_register(struct sja1105_private *priv) return rc; } - for (port = 0; port < ds->num_ports; port++) { + dsa_switch_for_each_available_port(dp, ds) { struct mdio_device *mdiodev; struct dw_xpcs *xpcs; - - if (dsa_is_unused_port(ds, port)) - continue; + int port = dp->index; if (priv->phy_mode[port] != PHY_INTERFACE_MODE_SGMII && priv->phy_mode[port] != PHY_INTERFACE_MODE_2500BASEX) @@ -451,7 +449,9 @@ static int sja1105_mdiobus_pcs_register(struct sja1105_private *priv) return 0; out_pcs_free: - for (port = 0; port < ds->num_ports; port++) { + dsa_switch_for_each_port_continue_reverse(dp, ds) { + int port = dp->index; + if (!priv->xpcs[port]) continue; diff --git a/drivers/net/dsa/xrs700x/xrs700x.c b/drivers/net/dsa/xrs700x/xrs700x.c index 130abb0f1438..7465be144cc9 100644 --- a/drivers/net/dsa/xrs700x/xrs700x.c +++ b/drivers/net/dsa/xrs700x/xrs700x.c @@ -297,7 +297,6 @@ static void xrs700x_port_stp_state_set(struct dsa_switch *ds, int port, static int xrs700x_port_add_bpdu_ipf(struct dsa_switch *ds, int port) { struct xrs700x *priv = ds->priv; - unsigned int val = 0; int i = 0; int ret; @@ -316,12 +315,8 @@ static int xrs700x_port_add_bpdu_ipf(struct dsa_switch *ds, int port) } /* Mirror BPDU to CPU port */ - for (i = 0; i < ds->num_ports; i++) { - if (dsa_is_cpu_port(ds, i)) - val |= BIT(i); - } - - ret = regmap_write(priv->regmap, XRS_ETH_ADDR_FWD_MIRROR(port, 0), val); + ret = regmap_write(priv->regmap, XRS_ETH_ADDR_FWD_MIRROR(port, 0), + dsa_cpu_ports(ds)); if (ret) return ret; @@ -340,8 +335,8 @@ static int xrs700x_port_add_bpdu_ipf(struct dsa_switch *ds, int port) static int xrs700x_port_add_hsrsup_ipf(struct dsa_switch *ds, int port, int fwdport) { + unsigned int val = dsa_cpu_ports(ds); struct xrs700x *priv = ds->priv; - unsigned int val = 0; int i = 0; int ret; @@ -360,11 +355,6 @@ static int xrs700x_port_add_hsrsup_ipf(struct dsa_switch *ds, int port, } /* Mirror HSR/PRP supervision to CPU port */ - for (i = 0; i < ds->num_ports; i++) { - if (dsa_is_cpu_port(ds, i)) - val |= BIT(i); - } - ret = regmap_write(priv->regmap, XRS_ETH_ADDR_FWD_MIRROR(port, 1), val); if (ret) return ret; @@ -505,28 +495,27 @@ static void xrs700x_mac_link_up(struct dsa_switch *ds, int port, static int xrs700x_bridge_common(struct dsa_switch *ds, int port, struct net_device *bridge, bool join) { - unsigned int i, cpu_mask = 0, mask = 0; + unsigned int cpu_mask = 0, mask = 0; struct xrs700x *priv = ds->priv; + struct dsa_port *dp; int ret; - for (i = 0; i < ds->num_ports; i++) { - if (dsa_is_cpu_port(ds, i)) - continue; - - cpu_mask |= BIT(i); + dsa_switch_for_each_user_port(dp, ds) { + cpu_mask |= BIT(dp->index); - if (dsa_to_port(ds, i)->bridge_dev == bridge) + if (dp->bridge_dev == bridge) continue; - mask |= BIT(i); + mask |= BIT(dp->index); } - for (i = 0; i < ds->num_ports; i++) { - if (dsa_to_port(ds, i)->bridge_dev != bridge) + dsa_switch_for_each_port(dp, ds) { + if (dp->bridge_dev != bridge) continue; /* 1 = Disable forwarding to the port */ - ret = regmap_write(priv->regmap, XRS_PORT_FWD_MASK(i), mask); + ret = regmap_write(priv->regmap, XRS_PORT_FWD_MASK(dp->index), + mask); if (ret) return ret; } diff --git a/include/net/dsa.h b/include/net/dsa.h index 4639a82bab66..379ad8183639 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -475,6 +475,14 @@ static inline bool dsa_is_user_port(struct dsa_switch *ds, int p) list_for_each_entry((_dp), &(_ds)->dst->ports, list) \ if ((_dp)->ds == (_ds)) +#define dsa_switch_for_each_port_continue_reverse(_dp, _ds) \ + list_for_each_entry_continue_reverse((_dp), &(_ds)->dst->ports, list) \ + if ((_dp)->ds == (_ds)) + +#define dsa_switch_for_each_available_port(_dp, _ds) \ + dsa_switch_for_each_port((_dp), (_ds)) \ + if (!dsa_port_is_unused((_dp))) + #define dsa_switch_for_each_user_port(_dp, _ds) \ dsa_switch_for_each_port((_dp), (_ds)) \ if (dsa_port_is_user((_dp))) @@ -494,6 +502,17 @@ static inline u32 dsa_user_ports(struct dsa_switch *ds) return mask; } +static inline u32 dsa_cpu_ports(struct dsa_switch *ds) +{ + struct dsa_port *dp; + u32 mask = 0; + + dsa_switch_for_each_cpu_port(dp, ds) + mask |= BIT(dp->index); + + return mask; +} + /* Return the local port used to reach an arbitrary switch device */ static inline unsigned int dsa_routing_port(struct dsa_switch *ds, int device) { From patchwork Tue Aug 10 16: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: 494767 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, 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 52096C432BE for ; Tue, 10 Aug 2021 16:18:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E754A610A8 for ; Tue, 10 Aug 2021 16:18:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235657AbhHJQSl (ORCPT ); Tue, 10 Aug 2021 12:18:41 -0400 Received: from mail-am6eur05on2081.outbound.protection.outlook.com ([40.107.22.81]:23521 "EHLO EUR05-AM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S234936AbhHJQQh (ORCPT ); Tue, 10 Aug 2021 12:16:37 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fx+m1FevHisCyzlM/DusyWbr+gkrGmOfkwK2fswalf4kSh96SY6hgfH2oRuVF3ou8kOGUb1tLJqUYYyj+leQF6KYuWdNFgmitekMfMeD1omglM/dr0D9n/5gnV9zPvqqdICarn149eQBICcWLS02VHhqiBeq/+a68Tk4YTm5zwS6OPSri+T8hf4XSCsQs1vCX8EeUx4gXVdRFgWi6aecegRPXjU5TG+lfWIBTsonuEYraECp113NfXWSSvLUqowOTvjp3SGCLxUoNDRw3dq0hfUYoVxKkHjjkYg3cTFxEDI6/AK6zYLH+Y5p0aQajc9ww3GBXPhd2C/LRIU8NPYmAw== 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=yVQ+QwfFN8J4dK05om740vkFljwYVXOzBExFmow+Mag=; b=SGtEtLwPmTppGz8lIeHZ8DHgLqhQ0RXijTSOYfi6U7UTzyhCkHHg3++aMglEBpTHVyNsoceL1A7xSV/beBXft1Pw/PN6tYbgl7zc/bIgG4YUGBFbHKLK6+O5mebxALVTBtDEWNicY2yp6d98+r4w/MHf7N8cFhyW4VxDteCxF2gpV+y95XRh8Xvsh2MH0z0tg8G8J+enwIqATZM0JvnDmp+6sMdrIWmyxSgucDMeMd1TOHqA1FrYKcg5P4MpslT3X2+juYPjfKfxzmQ915MB/31W9166AarS/ZbildfUovc0+jhNAq44ILXhCHYAX/P69dMWtZZUYMEJj333LjLo9g== 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=yVQ+QwfFN8J4dK05om740vkFljwYVXOzBExFmow+Mag=; b=ClH8uKZjds6kvwB/I/T6B6HiGb94F7ZbAXkLY1wGQ/e85HmoP19j9WlRn3C1c7sGz6h80kgj3wwD4ZSVMoRth1LDd9SAL8HpYbNFu6jcMMQ00ENayH/DKNAWbEdUHm+DQg2HJ89EoFcAKpjXHhrcJO1ExPjBfmRPtFTS8R0Seeg= 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 VI1PR0402MB2800.eurprd04.prod.outlook.com (2603:10a6:800:b8::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.19; Tue, 10 Aug 2021 16:15:12 +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; Tue, 10 Aug 2021 16:15:12 +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 v2 net-next 6/8] net: dsa: remove gratuitous use of dsa_is_{user, dsa, cpu}_port Date: Tue, 10 Aug 2021 19:14:46 +0300 Message-Id: <20210810161448.1879192-7-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210810161448.1879192-1-vladimir.oltean@nxp.com> References: <20210810161448.1879192-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AM4PR05CA0031.eurprd05.prod.outlook.com (2603:10a6:205::44) 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 AM4PR05CA0031.eurprd05.prod.outlook.com (2603:10a6:205::44) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4394.15 via Frontend Transport; Tue, 10 Aug 2021 16:15:11 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: aa4c96e7-46ac-445d-0d15-08d95c1a07ef X-MS-TrafficTypeDiagnostic: VI1PR0402MB2800: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:6430; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: YqLmJMydxwXTAGyjEQUImk2mWbmD/QuapEXtWKfg3ivLjKyuiwH+QQQ5GAYGM45Rp7Tp5A194Ta2Kueo1CdloEg83LQpVl+Sqdxmg/tFkNomEZqNEmKlT8kbay4HN9dCKVO6iqj3LQb3p7nbtDBsH6/spM/xaf7SICLisshuo7WMrcTHnyrYeGpP47MTErrPqS5MkEqP3+1iOecrKZOeqsQTDle+0QP1pkZP5z5lFCaveL8CaMQ9GhcT1ukHwOMralMxJEXmUharF+3kpz5bPvuyxBWKU0LD4L+I3uUgj9sLtnlFw7hnJwPGE1pa8GxpZqzQQaXCmJyIvOmxK42hiWV0Mi9JvLcdAshmYrTQZusk8EViAHpGQnRad0V34yO0JNYxzcNC+IjAZXrLYowmF5h2eaubi8E7X+mNKbohFknbAMa66LzHYma27viz56NCJ/RcQ/a8hlM5DC3Dp1cgNT1Pov2M3vdmgKQjcFcVPQ7L8QZN4NroRR6HnlcIk0t8dLweZZbectCGrhKmpYNdXfLGDWHHiQi49KLyX0GvEIqRMAK6pYwYdtYjSUt+XgL72cxywM6UhPO2m47Lq2uuPYEGAJcWBVqJEGZ1AQpiC77a1hV7eG8cIZ58MKAObR9ci2Tts3H/MnYhyjfUnpmUDRVoVCs9Ba+CxBjBcNjk9kfI71gE8rjcGb90+fHzgd/m X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(376002)(346002)(136003)(396003)(39850400004)(366004)(6506007)(52116002)(6512007)(86362001)(110136005)(478600001)(8676002)(2906002)(956004)(83380400001)(54906003)(26005)(1076003)(8936002)(6486002)(316002)(36756003)(7416002)(186003)(66946007)(5660300002)(66556008)(66476007)(44832011)(2616005)(6666004)(4326008)(38100700002)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BcSOyLqmIIi2W3j4rM/KDT1gOzAbuQJ4EpL3jlS89qRWoTLsxEkS7ctfJlQblLgEmSrYyMmAAQNYjKGhtX05KNokNrXZ+Z2lwCJk6ljOm/DVooQPz+UNDRGUHw8i+OvoyHQ0G/nncLbote/MEH15XIVHyH+dkPxPyOZPk8mrY97NkT8RydVqXL/jwh2zdd+3lA2nZzNA4cq8P7/m/PYQmqQsO9G7k/IpH+aS2M66xchCw9qXLk/oaPb5sWw/BtlDiBVvK16nzVIkPm7A4QeAaPKu/vRtOqdfcazXMxeZUMrr68i5YocDBhpm98RZuAjFM7xoZjxQsY4C600PQ9hnKBgd92N7VW/9Tj5dsD0er/zXMD89LYUoaJIMZ6DJ+j1vXz5ZNVjZXNkwfW6kq9NapPw3O2eUnZLROG3Tx/XwycWJeQlzKrag+DcS9blAY+5ERknu7VGYlKExM37+jyJQYW9rYN+a+CiGBE93ERvDd6RC1gH4zVQszPbljmJSzeRas4+JIgxX1yWviRrDr3DDJ6gK9+Pv5/7lhSNPddgpvB61ZudVV29iO1IlULzp7BKr5rfGQnmLKZHH4BOfUUTFuGs1esG2FRjN7eosrPI11z+7RomJbCojeoKzCyRMOiImVHXsvigtzc+KI7tVMpuSH6xzp49o+rFOr36E1CfPMd67Z0ut/IdxI9uAUCefwUUJRMBjaigeP0CvzeB639PLiYE6y/rk26vif68cuRhERgQqCio7WP14jaLxnpZQM9cazrMVKjcSwEug7u7R1BoLwHrZugteQlhtscD0Mi3DnrbsIhXPv//yGCpkdAJ1hCJm7RQF+SV8JCt0eRqK7uRpLT3g6nrkm9gZPwuUBQYNF7UpXBNnIBtITqI6hRioxhp0vBAXKTxvjrlAcX7bwQSD+Lyx0l2fOm4j0d5tlSc2fjete/UXBmtR96UDi5fkXkAFMAAI77d6Yo3N4yHRKJ3lPU5KQnteV7HsgnFN8ehrO3CCrgnkPROI++zxpnnuT/U2Dpl0YuYliyl3lM6+fnOrRySgD7qyl49HBkALGFbAg379kSncwQTrgJPkmEaB45XB0Ki9a6ofU8i8SfjoW0OIjkbEjiM5mRw8G4j9Y82O+W9OXS6+revaIiYlh3b6EyOEZ6TxpXQ1JW1blmKx/HtfL3/3AVHF/H47F9EMnwnM7k1ih+JfSk5hp0fdc0EA+TZ44K7LcxfQIrygO8byBqoQs2YVYSkGU+Q3e9ItLDInQNy+2GfoIOftut99B2/FN32t1cJM4u/wbj8+rVbJEjB7g00JnSWHYsGl1tpzpD+RzbafSbdbziqAcqRx/cg289lc X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: aa4c96e7-46ac-445d-0d15-08d95c1a07ef X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 10 Aug 2021 16:15:12.3197 (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: z08Jmklnr0N7vh6tkviq/kO9RPHJIQmbp7VgpEqYC6cjPdcm4J99VdT1bmQVyVPmXLWA/NTddusA8IUEk+OXVA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR0402MB2800 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Find the occurrences of dsa_is_{user,dsa,cpu}_port where a struct dsa_port *dp was already available in the function scope, and replace them with the dsa_port_is_{user,dsa,cpu} equivalent function which uses that dp directly and does not perform another hidden dsa_to_port(). Signed-off-by: Vladimir Oltean --- v1->v2: patch is new drivers/net/dsa/mv88e6xxx/chip.c | 2 +- net/dsa/port.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/net/dsa/mv88e6xxx/chip.c b/drivers/net/dsa/mv88e6xxx/chip.c index 5ce3c9129307..edd8eaa22bc7 100644 --- a/drivers/net/dsa/mv88e6xxx/chip.c +++ b/drivers/net/dsa/mv88e6xxx/chip.c @@ -1641,7 +1641,7 @@ static int mv88e6xxx_port_check_hw_vlan(struct dsa_switch *ds, int port, int err; /* DSA and CPU ports have to be members of multiple vlans */ - if (dsa_is_dsa_port(ds, port) || dsa_is_cpu_port(ds, port)) + if (dsa_port_is_dsa(dp) || dsa_port_is_cpu(dp)) return 0; err = mv88e6xxx_vtu_get(chip, vid, &vlan); diff --git a/net/dsa/port.c b/net/dsa/port.c index 05b902d69863..e035650a30ab 100644 --- a/net/dsa/port.c +++ b/net/dsa/port.c @@ -548,7 +548,7 @@ static bool dsa_port_can_apply_vlan_filtering(struct dsa_port *dp, * enter an inconsistent state: deny changing the VLAN awareness state * as long as we have 8021q uppers. */ - if (vlan_filtering && dsa_is_user_port(ds, dp->index)) { + if (vlan_filtering && dsa_port_is_user(dp)) { struct net_device *upper_dev, *slave = dp->slave; struct net_device *br = dp->bridge_dev; struct list_head *iter; @@ -1046,7 +1046,7 @@ static void dsa_port_phylink_mac_link_down(struct phylink_config *config, struct phy_device *phydev = NULL; struct dsa_switch *ds = dp->ds; - if (dsa_is_user_port(ds, dp->index)) + if (dsa_port_is_user(dp)) phydev = dp->slave->phydev; if (!ds->ops->phylink_mac_link_down) {