From patchwork Wed Aug 18 12:01:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 500292 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 5FD46C4338F for ; Wed, 18 Aug 2021 12:04:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3FF6561058 for ; Wed, 18 Aug 2021 12:04:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236646AbhHRMEk (ORCPT ); Wed, 18 Aug 2021 08:04:40 -0400 Received: from mail-vi1eur05on2074.outbound.protection.outlook.com ([40.107.21.74]:54881 "EHLO EUR05-VI1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236394AbhHRMEO (ORCPT ); Wed, 18 Aug 2021 08:04:14 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cl+/V1hSsgff6Jmnn1FfO3K7/A8ZBlkXxlQge+mwFCdZlMQBq313b5V4efTvD8y44WmRqZ53uR9y7MaTi9vcJ3X2in8b8j4lDt0pbfAmMZhnO0reuS6c/fAZbFx5bu4aYGK2wMdunRFuUxvVsXFIaSjWDEnTSV5zj9p4jjZc5fSvK5y/xcTiVZ7xzZURULv+ggcqx5lEejVekU2wOsfVt4AVGNUUxxDemynEG24eIHyTYdNaSl2iUaUSiqB+ODeXaLpDe76WMwdtmM7sryOMh3wOY8Jr8yulC2B3CCxToNYXxzRZ3B3//5I4zE1v/81BdAm/k0XOJdVrQCJUzjKL6Q== 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=zhImt1syFqdWJrYlFm96xbsLOURwpTwXQrNslGfzI0M=; b=OWKXfKVaUkzfARlUAPfW9xmVksqmQsqfQIIPgt95X+8Li1yjngnQ5TbXtzNlO9eAXcm5Hn390XIZi36hEq+rS7RMzQjOn496igPe+fB4Zx2o3ibRptLBX+ffwWuNnC49TLhCNpfT0//k4EMhZEgTjBuuRW32CTC51satUwEEVCHzF+Hqbr3annSZ3iwqKZFwXVBDQW6SY38+Q6CkMBva6ylsOzTnkZQ2afKedwPSK9zMsLvergKba/gu7b766pdT4iZg9aiEUP1P+vrw1XjmAmzGjpR9LhFfKGfo9cbKkSBLjekuC/6DdseTrNeMsUe5i/0/VqWwI2v9sTCjFsn9Sg== 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=zhImt1syFqdWJrYlFm96xbsLOURwpTwXQrNslGfzI0M=; b=HpNSFZTLFdEQtRrsQ7BECWwhbSK//zeGzwscmt8LOdXyUAbhGTMFtUyRD2F3LVk4pIc7hhnnDj12fEPhhcsO/qU3T9hQfYf6RGjxwCGGQHV3xwFk15vRWFu6bS0LUKYLVY1PdDlYnMZXE85zPSX+2JKPaJNEBZzX4GmoEcXgAb4= 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 VI1PR04MB4222.eurprd04.prod.outlook.com (2603:10a6:803:46::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4415.18; Wed, 18 Aug 2021 12:03:17 +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.4415.024; Wed, 18 Aug 2021 12:03:17 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org, Jakub Kicinski , "David S. Miller" Cc: Roopa Prabhu , Nikolay Aleksandrov , Andrew Lunn , Florian Fainelli , Vivien Didelot , Vladimir Oltean , Vadym Kochan , Taras Chornyi , Jiri Pirko , Ido Schimmel , UNGLinuxDriver@microchip.com, Grygorii Strashko , Marek Behun , DENG Qingfang , Kurt Kanzenbach , Hauke Mehrtens , Woojung Huh , Sean Wang , Landen Chao , Claudiu Manoil , Alexandre Belloni , George McCollister , Ioana Ciornei , Saeed Mahameed , Leon Romanovsky , Lars Povlsen , Steen Hegelund , Julian Wiedmann , Karsten Graul , Heiko Carstens , Vasily Gorbik , Christian Borntraeger , Ivan Vecera , Vlad Buslov , Jianbo Liu , Mark Bloch , Roi Dayan , Tobias Waldekranz , Vignesh Raghavendra , Jesse Brandeburg , Peter Ujfalusi Subject: [RFC PATCH net-next 19/20] net: mscc: ocelot: use helpers for port VLAN membership Date: Wed, 18 Aug 2021 15:01:49 +0300 Message-Id: <20210818120150.892647-20-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210818120150.892647-1-vladimir.oltean@nxp.com> References: <20210818120150.892647-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: VI1PR08CA0134.eurprd08.prod.outlook.com (2603:10a6:800:d5::12) 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 VI1PR08CA0134.eurprd08.prod.outlook.com (2603:10a6:800:d5::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4436.19 via Frontend Transport; Wed, 18 Aug 2021 12:03:15 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4f765e2f-5379-4342-f04a-08d9624029ce X-MS-TrafficTypeDiagnostic: VI1PR04MB4222: 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: lGfJWDnifx8XooR3gBBdD5dSLz3UkZ5cxisbJSmhaQKk1es9daN9n1SKkr3I8Fve1q+iK929vnSlxN70zzV+X9GiWti0MhzZCILww6tV2E5FyxaH6MR1LIVVOjn26dFUT0e23l0Qx9uBzYNigmrm1y1q7t9NhOnvJHiUTjymP9hkZ0spFGpmphvnhDd4b/sh3+E4EbQLS+lCL2A02wXxGsm12D+dJOq11KRv+yGexooiNUGOn+zrAGTa/257BH77hLZIw+n1BzAF+YR1Q5GjnXM51ONr+INsx2uQWi2J2cgqXxleEfv0MEgj5mHIa0oeiiPyoQ7KdSGMOE9lQ4ss2EFqLsIMJtxvEGo68bWXeVzU9fM4RvwITqjYHecvFXjyYTqI7ERfdOw4mypGkiRtkFKOUPZOvdgJ3nkvnIl8icT0RdtIqn+jUYsRgNT94WSOp0m7kNw9HlgBSAq25hqMneUmQOV1pxVThIOhphXkSE61G/z5aGSIzitoVMZXI14NVr45DtwvKUGGfuZiPz0MezrUmIuME4pjKdvbyH7ygfEhDd9nI9f3MQf67ukatLap X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:VI1PR04MB5136.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(346002)(396003)(136003)(39860400002)(366004)(376002)(6486002)(52116002)(2616005)(44832011)(4326008)(5660300002)(26005)(1076003)(6666004)(54906003)(956004)(6512007)(6506007)(186003)(38350700002)(38100700002)(86362001)(36756003)(110136005)(316002)(83380400001)(8936002)(478600001)(8676002)(66476007)(7416002)(7406005)(66946007)(66556008)(2906002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: o8LSPcHDKtnEnxG/Iv28xKRPBD0xqQpCAuZH1BTQAqBzm9iGJ5UN1h0Iaipn8ggxP1faCK7+FQEEfBlAcPrckJMaLcbz5hobRjMlADJK+OP9V0EQga7rd8cpD2aNDMHEl4Q01q8CQ1IXsOdd6TQPjvhPtwDwWzRC4DCk9rGp9uPlsllsAzU2YBM4reVyMe4aAyDTpUL3XPjV8Gd3qfrpDTty/WGBulhkAj9InKnk/6JVvFhOrkwq1s7ZVf3PVGeKSGzKHkzFG18ki2rwic+4tpcG++IAObYbW154aKd8CdCS46ATobI3+sImgmlRwx+Zob20oi9vW5a9xfA3e7HmugHmNCUJBwxtaKURQ7jjvJGoMEdJ9EeQHOWQE6mwvCrw+qQDqsNon5+K+qX0fv0xdi1N3Yf65Or0IN20aTVLRSCl0RSU2lTMQQPxBYemYfsITtZkj8QCFNcRH+Im1gzfQnAq+sXpkiLfG/fXRf12d448QJxACkr3JvRo+vmFlOtYTaYFTZBbtOiMI0FgBl9cPZyJ2S3QVproy3z3Q9p6gpzLOHBOTcxHNt9/YwKeExzbws0BmbJWiX250ipLHhKJ6nnzrZrvU8hPHUu6Ro/9hbBPdct9xuaiTHwnzvQfngzc/TR1oPkTcbuBKWJInYY/o2aCbQsiUUR/RpcOL18LoGI6BdZjUmulTTOckz6H+Az5c5YOeMRx5+SVvhax8030QStDDIR94CT9Shyu0iV3iBPrF+gKNwXcy6vBANLAM2O/Xz/0vAStCSqBMTZq5NONXrw755wuUtPLCnEYiNmytZthGHj2BwipssgagWf7xtbSlEtBDMD8ypKGiTm/xCL41Gn12JMo8WGip80gu7eJxElFPr5d8IAZrkiOGU0vQR8QNG05G8Y+7eDfJqeu1h30MoUi8hdvBVVb+Lo7SYVS2HKQ1TD3t74Mg+HVXMN31LmsNjTrwIqdHnnAZBW9o3zOH20PumSjYHJgDQgj336rbwUGOTYCChoHBGkTKqXqHwzCkqf4zpyDC0751UaT7MTscjpZACSaCaT1rzg6z7ZAGxQ1EzPjLNphXzwrlP49bhgMyE8WkBN2CANtOMM6m1fEXk0XMu0MfwV3RDwQdyYT8n9WoIRDqyROYg5MBOjNqATGI4olIKgvjeI91f9pbpaNKIfNKPRqhfb/2nZl8Vpl+Z5oHyf8fMVbALH5zQL9LOeVAV0mHpFelZd73UFJ6bTYzSIItOOtXWq/yGZ7H3Ux90eLOu3DS6HE2djU4aUxQkPHilXFkHakhMOL4S8UZvXAJTOSRWO0DKbe6+DqrpgsXtmC/TbjJSfgZGrZeyjLE0An X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4f765e2f-5379-4342-f04a-08d9624029ce X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Aug 2021 12:03:17.0681 (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: zZVHarSzFubO0ibHVvEo5pApl/AaVx0+sFsx5UdJugUOM2817u8TJAx9YM2JCrCMC7yg0WNkIgvHJiYLHY75BA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VI1PR04MB4222 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org This is a mostly cosmetic patch that creates some helpers for accessing the VLAN table. These helpers are also a bit more careful in that they do not modify the ocelot->vlan_mask unless the hardware operation succeeded. Not all callers check the return value (the init code doesn't), but anyway. Signed-off-by: Vladimir Oltean --- drivers/net/ethernet/mscc/ocelot.c | 60 ++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index e848e0379b5a..c581b955efb3 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -222,6 +222,33 @@ static void ocelot_port_set_pvid(struct ocelot *ocelot, int port, ANA_PORT_DROP_CFG, port); } +static int ocelot_vlan_member_set(struct ocelot *ocelot, u32 vlan_mask, u16 vid) +{ + int err; + + err = ocelot_vlant_set_mask(ocelot, vid, vlan_mask); + if (err) + return err; + + ocelot->vlan_mask[vid] = vlan_mask; + + return 0; +} + +static int ocelot_vlan_member_add(struct ocelot *ocelot, int port, u16 vid) +{ + return ocelot_vlan_member_set(ocelot, + ocelot->vlan_mask[vid] | BIT(port), + vid); +} + +static int ocelot_vlan_member_del(struct ocelot *ocelot, int port, u16 vid) +{ + return ocelot_vlan_member_set(ocelot, + ocelot->vlan_mask[vid] & ~BIT(port), + vid); +} + int ocelot_port_vlan_filtering(struct ocelot *ocelot, int port, bool vlan_aware, struct netlink_ext_ack *extack) { @@ -278,13 +305,11 @@ EXPORT_SYMBOL(ocelot_vlan_prepare); int ocelot_vlan_add(struct ocelot *ocelot, int port, u16 vid, bool pvid, bool untagged) { - int ret; + int err; - /* Make the port a member of the VLAN */ - ocelot->vlan_mask[vid] |= BIT(port); - ret = ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]); - if (ret) - return ret; + err = ocelot_vlan_member_add(ocelot, port, vid); + if (err) + return err; /* Default ingress vlan classification */ if (pvid) { @@ -311,13 +336,11 @@ EXPORT_SYMBOL(ocelot_vlan_add); int ocelot_vlan_del(struct ocelot *ocelot, int port, u16 vid) { struct ocelot_port *ocelot_port = ocelot->ports[port]; - int ret; + int err; - /* Stop the port from being a member of the vlan */ - ocelot->vlan_mask[vid] &= ~BIT(port); - ret = ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]); - if (ret) - return ret; + err = ocelot_vlan_member_del(ocelot, port, vid); + if (err) + return err; /* Ingress */ if (ocelot_port->pvid_vlan.vid == vid) { @@ -339,6 +362,7 @@ EXPORT_SYMBOL(ocelot_vlan_del); static void ocelot_vlan_init(struct ocelot *ocelot) { + unsigned long all_ports = GENMASK(ocelot->num_phys_ports - 1, 0); u16 port, vid; /* Clear VLAN table, by default all ports are members of all VLANs */ @@ -347,23 +371,19 @@ static void ocelot_vlan_init(struct ocelot *ocelot) ocelot_vlant_wait_for_completion(ocelot); /* Configure the port VLAN memberships */ - for (vid = 1; vid < VLAN_N_VID; vid++) { - ocelot->vlan_mask[vid] = 0; - ocelot_vlant_set_mask(ocelot, vid, ocelot->vlan_mask[vid]); - } + for (vid = 1; vid < VLAN_N_VID; vid++) + ocelot_vlan_member_set(ocelot, 0, vid); /* Because VLAN filtering is enabled, we need VID 0 to get untagged * traffic. It is added automatically if 8021q module is loaded, but * we can't rely on it since module may be not loaded. */ - ocelot->vlan_mask[0] = GENMASK(ocelot->num_phys_ports - 1, 0); - ocelot_vlant_set_mask(ocelot, 0, ocelot->vlan_mask[0]); + ocelot_vlan_member_set(ocelot, all_ports, 0); /* Set vlan ingress filter mask to all ports but the CPU port by * default. */ - ocelot_write(ocelot, GENMASK(ocelot->num_phys_ports - 1, 0), - ANA_VLANMASK); + ocelot_write(ocelot, all_ports, ANA_VLANMASK); for (port = 0; port < ocelot->num_phys_ports; port++) { ocelot_write_gix(ocelot, 0, REW_PORT_VLAN_CFG, port);