From patchwork Fri Mar 11 21:15:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12778622 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F389C433F5 for ; Fri, 11 Mar 2022 22:50:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229763AbiCKWvg (ORCPT ); Fri, 11 Mar 2022 17:51:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40302 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229812AbiCKWvZ (ORCPT ); Fri, 11 Mar 2022 17:51:25 -0500 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2041.outbound.protection.outlook.com [40.107.22.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AA082C14BE for ; Fri, 11 Mar 2022 14:25:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ko9wiZHAXOKGHIYKbkCxCm3bBAUY/20/eztN/gdIwYTLSA/2ccY5FEdW7Ai55SPlF0PpArX+V8WNfOpvREPRqP+bmZHh7FAiel3OA1PfXMjdjq8kMGUV4nFyUUMkVmM5uLtG05lhrRnDhof3t04Ktixr2s2/eq6cu050Iit6U+NCFG3GtNQ60cj0B4cAt0P0pOSek8FTsXec94zlNqiHJgt6VwgldPZ6NCYr8T+Az9m0+XrGghbZB9rA6kvekVPH2NC7bA0Ml4IXHRrzK3cfl5pJnh0TsNncx6Wp6e7rI4ec1wL9Sze0SiBBV6UAQ3quP0bGPiKxBoFF4LFPoZR8CA== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=H5jXbu9hoHifto8sFEiSK27vHwvo/QzmmF01KpLD/Z4=; b=Fsy6mCTiNTZXxMwqzUlUz+1IDNLx03rHdVj7rfwbUq0LddVVPaI91IlAXl8TwI4Ehpcw+IzLHpN1KgxQkhk0pX78BKGxDC29dK5xWHPIeAI8bodIBfPpPf1+tqAwFjGvZnQqR3f7XWJuBMhYRZY1jkGRmSTPI99wpAFj1NpM+WAmILBaN0IK7PeyG4tc6lrxJLZOIB87bJX2Gw5+BOfzJSsrqf3gd1ohuXFOnKluxMegCEBszqRpF7i86XV5ZjC+JNt5rL+5rwZ6X79J7Kl4M6IsjNfIbo+Zw5Avts00Mu3Y+WhoNFt45ANxXoO6FIo8UjxxxJpGKZRULGrPrdAgnQ== 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=H5jXbu9hoHifto8sFEiSK27vHwvo/QzmmF01KpLD/Z4=; b=QtR2CKGheyd+njMOrUQrlGVfeiWrqdxr301mKb0LEYEmk3YFGoMRNG3jOKM1j+N1EqaJ+E/ZwOzlktm6YEaOvWksSuIiieoTjf9dalKa7KhkpYQ92+em3LJXoT9G8PgcQsLPwmbt/v8P3UhFFBFlB86AIfn8LeTDMqJI+GbFhOg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by DU2PR04MB8934.eurprd04.prod.outlook.com (2603:10a6:10:2e1::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22; Fri, 11 Mar 2022 21:15:31 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::ac0c:d5d:aaa9:36]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::ac0c:d5d:aaa9:36%5]) with mapi id 15.20.5038.027; Fri, 11 Mar 2022 21:15:31 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Jakub Kicinski , "David S. Miller" , Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Petr Machata Subject: [PATCH net-next 1/3] net: dsa: report and change port default priority using dcbnl Date: Fri, 11 Mar 2022 23:15:18 +0200 Message-Id: <20220311211520.2543260-2-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220311211520.2543260-1-vladimir.oltean@nxp.com> References: <20220311211520.2543260-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AS8PR04CA0188.eurprd04.prod.outlook.com (2603:10a6:20b:2f3::13) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 37208d90-4252-4849-64ee-08da03a4461b X-MS-TrafficTypeDiagnostic: DU2PR04MB8934:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: MpvhwpHqlcPOgqwyjjd26uiZWIOBehCky68ZPlwAzGDmsobiPTNWoaFQMGiFOIT4YZc6A6Ui9o3vSpdGlYkvKXlpi3p7vkiVI9zorHYRj2GE3ewfoClq01P60GrB2J3mm1p7oSftAEAK7kjnmCz9IUaoEbTbD53/nqRu55aC7sg9XIgUAwoos+1W+oAsYg/XQLG7WHJOk0dtcPWmvkCV9ZVrbDNXbxUn7MJB0PUAzHcNJGKYKYSP07HMvsrLtcP6aLPV01t78AHz0zjz0nNvVznO+ugeFRsTOz+EagLfuQZ4+tXTGyAHZY4AVUNkZox4oND42q+dl8qxGOFipmYFOzXZrXup7diBrTvad262OERQQQQa0+YuUW6egOxWu8F4zA6IvF6crnYN98BYtLlDNm+nsTwzNAlNySHAKiqHdpRBIwCDsA4tPQPFi/RNbSVkiqhR94DqqsQufVYzLgqMKj+42Hpd586viu4rP1hy2bNxDNbgSWkw64mKkijeopXPtHU3M89yusGQYdiXh9oriWclieCex/PImA9Pn2aXvAxNxh/iHwDgzffSP9pSUTRLqyEOMB/3cvd3AD4deLlqf1xv3Oe4TI1PcapQVSLZmSKLiPq3g12jJjojQkWPm+VCMm8AbHeYVON3x8S8kp6ZmQ1vPtxLspcyjd1A0+CqJom7+G0qwZpdMxYppkjw3OuNrt4GPT8XvDIx+FZ7MjFl4Nuar79LqpeJgmRyUSKvCpDtHer0DDDZ9ZHbEHaNslK1l03RYJlb3DXp33YVMf6CdgwTnQQDRbrfxO6kEe0SireSjUPxMyoMq9IpsOUCR8Lu 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:(13230001)(4636009)(366004)(6916009)(36756003)(38350700002)(1076003)(54906003)(38100700002)(316002)(66476007)(6512007)(83380400001)(86362001)(508600001)(2616005)(2906002)(8936002)(66556008)(7416002)(6666004)(26005)(6506007)(6486002)(4326008)(8676002)(66946007)(5660300002)(966005)(44832011)(186003)(52116002)(17423001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: FCzV39fT2iq8X+MVrJ67O6p1WwdgOT2I4Bv9IR/FJQlrvXubvSEyn3NmmCEqC07mOpLTPLQCFymvzu6dLlwMpjhm/SGPCC54hOVD4X3oKx2eWxng/VI5ggMOuSccXLVbJ/LVHoeT3OkR/dmel9PcyvxIXDU3eXaRHa8/RqxQZGnDK6X8CyPD5kjfRz/eajzO9ZkayfjaIn/X6kq8XrL4IZOL418dbC+LT57iVP/0nNgdwHVn61DPu3xxVQN16GyZnGO+xcm1jLDnpaRN/4BUmkHnwt8OBc1LodJHTWUt5Ppydt9F7i/v15DhwKwCAB+Jgl9FQiA1c6fBevdpIlSkCZxhVFdcDdb+JPHzMrn182XFy8N7cDJtOJ7tcH2XPbLVwSGWI/uJAsQcOwr7pib+3QuprFkgwQb0M3YwuPPakLDmf+8ZpEqH0yRysvnzMp4EjT4WVudCQdT2I6QQpMrYLCDjJLOkze7YaSCBlsLOvD7Q9bchEDMqP3RgSi7Xq7t704KKV8ZPTj8yp9M3jo9oPw6RbsGV54POr17+af+PSPk+QsXgm82WzYs+je02rBeodCUEZ6Eb/84ZtlQUnw+OXOp1PZY9bkPzU/dvw31Nt6pArjbNa1zmzXy7rIoqLxfQJKod4YHBBM7vBxGf6rql1tMVBCY0abA6zoB3WxKLAa+RPYXBicuuu42PonqkUSEb0RYcnlAFVG1Ul8zf/8LmbK1bN4cokhmMvqq9Zz70aMFTK0RMhGDeB+JbCSpT2FQ3xJunL9gPDjxv13dbj/wRAn4E7TJskpwZ9N9ZIYQScsvKZb69asKBUOaLhD+SHDZAoK+RaG0MN2EyQK2GbVVBJRHLihCZIw062qemKJqfASlKUAC1nuwQ+MkZWDbhx31fAzFVU61+IEqlbscP4l9lUo8II0HW0tBZeZNySNZyGWcHMXVYSul2Bsv98av7dgb96L3zsuZSCx0HSWC+WX6Obav8WetAYNLUOKeuJiu5acLD8WYe3V4BvnzjubOzhZzmuf8jYXEdjN5OF7Rab738861HQvQCmxtDo7rvfqOtTuEKdYhEtuic/UXKxmrd9KhhlmnJ5ymQaSVXHWItfWj4447oJw8Gia4kltW41ax58Ps3zjvDzABdTo8gtWxuX/WbeT2RIwaYBdL5EeW+LaYiqv0a281cO/959REVeDzlIqtAmYk9HPc2k1EgPeImO6P3XJCzSvHr5HVltHzHlrRCZAt4x8Qe/TMEhjWcbbZcjNBwiWYD58ZDiTXC5+hK/qUY3WknLeVUz1l5GOo19M1OGpbItF9bso+niPClqZiYlTZwRB5a6PFMSiMghWfZei3um8YK52AIbE70/vuDXqjibDxR3TVPp7VlK6ackNvpNygpfEh2sm20Gpx1pAFvoYEwRM7G19MlTTcn5MrGb1N+/PoEavruKzINeAUj2l6OSmFPwyybTslH03aTQ7FifJPGE6x6kP8xdDk+ZIOwwLZU3w== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 37208d90-4252-4849-64ee-08da03a4461b X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 21:15:31.4410 (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: nVvzdpltwmn47g/4zwFEtvF55IjlDFzcx4TeKeGDyymlWD6jVzNSmfJNjpAsZoFkI4ZP1QElHhcgVFuNfdLjCw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8934 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org The port-based default QoS class is assigned to packets that lack a VLAN PCP (or the port is configured to not trust the VLAN PCP), an IP DSCP (or the port is configured to not trust IP DSCP), and packets on which no tc-skbedit action has matched. Similar to other drivers, this can be exposed to user space using the DCB Application Priority Table. IEEE 802.1Q-2018 specifies in Table D-8 - Sel field values that when the Selector is 1, the Protocol ID value of 0 denotes the "Default application priority. For use when application priority is not otherwise specified." The way in which the dcbnl integration in DSA has been designed has to do with its requirements. Andrew Lunn explains that SOHO switches are expected to come with some sort of pre-configured QoS profile, and that it is desirable for this to come pre-loaded into the DSA slave interfaces' DCB application priority table. In the dcbnl design, this is possible because calls to dcb_ieee_setapp() can be initiated by anyone including being self-initiated by this device driver. However, what makes this challenging to implement in DSA is that the DSA core manages the net_devices (effectively hiding them from drivers), while drivers manage the hardware. The DSA core has no knowledge of what individual drivers' QoS policies are. DSA could export to drivers a wrapper over dcb_ieee_setapp() and these could call that function to pre-populate the app priority table, however drivers don't have a good moment in time to do this. The dsa_switch_ops :: setup() method gets called before the net_devices are created (dsa_slave_create), and so is dsa_switch_ops :: port_setup(). What remains is dsa_switch_ops :: port_enable(), but this gets called upon each ndo_open. If we add app table entries on every open, we'd need to remove them on close, to avoid duplicate entry errors. But if we delete app priority entries on close, what we delete may not be the initial, driver pre-populated entries, but rather user-added entries. So it is clear that letting drivers choose the timing of the dcb_ieee_setapp() call is inappropriate. The alternative which was chosen is to introduce hardware-specific ops in dsa_switch_ops, and effectively hide dcbnl details from drivers as well. For pre-populating the application table, dsa_slave_dcbnl_init() will call ds->ops->port_get_default_prio() which is supposed to read from hardware. If the operation succeeds, DSA creates a default-prio app table entry. The method is called as soon as the slave_dev is registered, but before we release the rtnl_mutex. This is done such that user space sees the app table entries as soon as it sees the interface being registered. The fact that we populate slave_dev->dcbnl_ops with a non-NULL pointer changes behavior in dcb_doit() from net/dcb/dcbnl.c, which used to return -EOPNOTSUPP for any dcbnl operation where netdev->dcbnl_ops is NULL. Because there are still dcbnl-unaware DSA drivers even if they have dcbnl_ops populated, the way to restore the behavior is to make all dcbnl_ops return -EOPNOTSUPP on absence of the hardware-specific dsa_switch_ops method. The dcbnl framework absurdly allows there to be more than one app table entry for the same selector and protocol (in other words, more than one port-based default priority). In the iproute2 dcb program, there is a "replace" syntactical sugar command which performs an "add" and a "del" to hide this away. But we choose the largest configured priority when we call ds->ops->port_set_default_prio(), using __fls(). When there is no default-prio app table entry left, the port-default priority is restored to 0. Link: https://patchwork.kernel.org/project/netdevbpf/patch/20210113154139.1803705-2-olteanv@gmail.com/ Signed-off-by: Vladimir Oltean --- I dislike having "#if IS_ENABLED(CONFIG_DCB)" in C code, so I minimized this pattern as much as possible, replacing it with __maybe_unused. Let's see how this goes with build testing... include/net/dsa.h | 7 +++ net/dsa/slave.c | 137 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) diff --git a/include/net/dsa.h b/include/net/dsa.h index 9d16505fc0e2..1220af73151b 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -892,6 +892,13 @@ struct dsa_switch_ops { int (*get_ts_info)(struct dsa_switch *ds, int port, struct ethtool_ts_info *ts); + /* + * DCB ops + */ + int (*port_get_default_prio)(struct dsa_switch *ds, int port); + int (*port_set_default_prio)(struct dsa_switch *ds, int port, + u8 prio); + /* * Suspend and resume */ diff --git a/net/dsa/slave.c b/net/dsa/slave.c index a61a7c54af20..97f5da81fe68 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "dsa_priv.h" @@ -1852,6 +1853,123 @@ int dsa_slave_change_mtu(struct net_device *dev, int new_mtu) return err; } +static int __maybe_unused +dsa_slave_dcbnl_set_default_prio(struct net_device *dev, struct dcb_app *app) +{ + struct dsa_port *dp = dsa_slave_to_port(dev); + struct dsa_switch *ds = dp->ds; + unsigned long mask, new_prio; + int err, port = dp->index; + + if (!ds->ops->port_set_default_prio) + return -EOPNOTSUPP; + + err = dcb_ieee_setapp(dev, app); + if (err) + return err; + + mask = dcb_ieee_getapp_mask(dev, app); + new_prio = __fls(mask); + + err = ds->ops->port_set_default_prio(ds, port, new_prio); + if (err) { + dcb_ieee_delapp(dev, app); + return err; + } + + return 0; +} + +static int __maybe_unused dsa_slave_dcbnl_ieee_setapp(struct net_device *dev, + struct dcb_app *app) +{ + switch (app->selector) { + case IEEE_8021QAZ_APP_SEL_ETHERTYPE: + switch (app->protocol) { + case 0: + return dsa_slave_dcbnl_set_default_prio(dev, app); + default: + return -EOPNOTSUPP; + } + break; + default: + return -EOPNOTSUPP; + } +} + +static int __maybe_unused +dsa_slave_dcbnl_del_default_prio(struct net_device *dev, struct dcb_app *app) +{ + struct dsa_port *dp = dsa_slave_to_port(dev); + struct dsa_switch *ds = dp->ds; + unsigned long mask, new_prio; + int err, port = dp->index; + + if (!ds->ops->port_set_default_prio) + return -EOPNOTSUPP; + + err = dcb_ieee_delapp(dev, app); + if (err) + return err; + + mask = dcb_ieee_getapp_mask(dev, app); + new_prio = mask ? __fls(mask) : 0; + + err = ds->ops->port_set_default_prio(ds, port, new_prio); + if (err) { + dcb_ieee_setapp(dev, app); + return err; + } + + return 0; +} + +static int __maybe_unused dsa_slave_dcbnl_ieee_delapp(struct net_device *dev, + struct dcb_app *app) +{ + switch (app->selector) { + case IEEE_8021QAZ_APP_SEL_ETHERTYPE: + switch (app->protocol) { + case 0: + return dsa_slave_dcbnl_del_default_prio(dev, app); + default: + return -EOPNOTSUPP; + } + break; + default: + return -EOPNOTSUPP; + } +} + +/* Pre-populate the DCB application priority table with the priorities + * configured during switch setup, which we read from hardware here. + */ +static int dsa_slave_dcbnl_init(struct net_device *dev) +{ + struct dsa_port *dp = dsa_slave_to_port(dev); + struct dsa_switch *ds = dp->ds; + int port = dp->index; + int err; + + if (ds->ops->port_get_default_prio) { + int prio = ds->ops->port_get_default_prio(ds, port); + struct dcb_app app = { + .selector = IEEE_8021QAZ_APP_SEL_ETHERTYPE, + .protocol = 0, + .priority = prio, + }; + + if (prio < 0) + return prio; + + err = dcb_ieee_setapp(dev, &app); + if (err) + return err; + } + + return 0; +} + static const struct ethtool_ops dsa_slave_ethtool_ops = { .get_drvinfo = dsa_slave_get_drvinfo, .get_regs_len = dsa_slave_get_regs_len, @@ -1881,6 +1999,11 @@ static const struct ethtool_ops dsa_slave_ethtool_ops = { .self_test = dsa_slave_net_selftest, }; +static const struct dcbnl_rtnl_ops __maybe_unused dsa_slave_dcbnl_ops = { + .ieee_setapp = dsa_slave_dcbnl_ieee_setapp, + .ieee_delapp = dsa_slave_dcbnl_ieee_delapp, +}; + static struct devlink_port *dsa_slave_get_devlink_port(struct net_device *dev) { struct dsa_port *dp = dsa_slave_to_port(dev); @@ -2105,6 +2228,9 @@ int dsa_slave_create(struct dsa_port *port) return -ENOMEM; slave_dev->ethtool_ops = &dsa_slave_ethtool_ops; +#if IS_ENABLED(CONFIG_DCB) + slave_dev->dcbnl_ops = &dsa_slave_dcbnl_ops; +#endif if (!is_zero_ether_addr(port->mac)) eth_hw_addr_set(slave_dev, port->mac); else @@ -2162,6 +2288,17 @@ int dsa_slave_create(struct dsa_port *port) goto out_phy; } + if (IS_ENABLED(CONFIG_DCB)) { + ret = dsa_slave_dcbnl_init(slave_dev); + if (ret) { + netdev_err(slave_dev, + "failed to initialize DCB: %pe\n", + ERR_PTR(ret)); + rtnl_unlock(); + goto out_unregister; + } + } + ret = netdev_upper_dev_link(master, slave_dev, NULL); rtnl_unlock(); From patchwork Fri Mar 11 21:15:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12778623 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6C542C433F5 for ; Fri, 11 Mar 2022 22:50:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229705AbiCKWvk (ORCPT ); Fri, 11 Mar 2022 17:51:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229911AbiCKWv0 (ORCPT ); Fri, 11 Mar 2022 17:51:26 -0500 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2041.outbound.protection.outlook.com [40.107.22.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7F367C621F for ; Fri, 11 Mar 2022 14:25:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CN575QcGfqpMmgUHX7YL4Cl0cv/An+M6sgqbvP0v+adL2qxdihrNCadyJeOfUzGg7o89qdvAADs8iV+9XUFPtleGqgcR4ITMJOrZp069FGmgBQTxG5pO0bZ0oEjWwLNMT4kIBQvg4zMsNGw/92pE7dukcijpCKj02NQd9H7sIJ+jVxt9/jPQ1IFN4KgREr+0e1keU9SBuDjeCyv2yuGVv9Ws+Gfbb2d2Jf7hUSjqRYAx5URMquz+WaGkVeSuExK05/9EwciWR8mukgg6HzICfvV5dW3k3DgG+Q2P+TWMrhEEUAb4uPwmw77ykD89BQzA1hR5HY64Lpk+Fbw9wI+QQQ== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=x7mtbvztN10iuto0I2csKpxH9NCE9XBtw1uY3uhXO/E=; b=V9xhDhmkMWN2BLuOQMA8BD2kIoGD+PRD77MSmK4r1RrivRHFLnjJGxIaF/51HHLexeW3KoVRi0kh89O1hlsbeIbeNma2jFr2JiIYyw4FnEl5QnuN0T3TXLE3IDADohxanmDWuec6b9Qj70hRgw0OQa9ZG23KSobx8G04aEzTrUQKKQD6DmHlEVh9HwS+MeimreGYBrRXvouw8sKql2BdUSTRYDyAuogqIllGgLbSfRP6geUpWM7w6/k/dXCwy9nXOFYnG7S6fPe6llQYAxYjErDY8+xmX4XMghBJudhzKO2gEWRglBVtozv4Kh3SpAz/2muIJI1jpb2ON0tUQYZMoA== 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=x7mtbvztN10iuto0I2csKpxH9NCE9XBtw1uY3uhXO/E=; b=P5so67ih6Uy+vDNuBbSQv4l5Rtp7nvw7JIQbrIVQhpCUlxvsFPwrOwFEDnHiBIJfFuyClzR/Cxn5bekR/9tthhNtxdAdKxTaS5Yk7PCLpam63zvEFL50GqiX1UH9hesYyPj2sVwh7Xk/cISEmfzAPaxpDRgAWCimDAvI9mfEqIE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by DU2PR04MB8934.eurprd04.prod.outlook.com (2603:10a6:10:2e1::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22; Fri, 11 Mar 2022 21:15:32 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::ac0c:d5d:aaa9:36]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::ac0c:d5d:aaa9:36%5]) with mapi id 15.20.5038.027; Fri, 11 Mar 2022 21:15:32 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Jakub Kicinski , "David S. Miller" , Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Petr Machata Subject: [PATCH net-next 2/3] net: dsa: report and change port dscp priority using dcbnl Date: Fri, 11 Mar 2022 23:15:19 +0200 Message-Id: <20220311211520.2543260-3-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220311211520.2543260-1-vladimir.oltean@nxp.com> References: <20220311211520.2543260-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AS8PR04CA0188.eurprd04.prod.outlook.com (2603:10a6:20b:2f3::13) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: de51fb9d-cfb1-46e2-1d6a-08da03a446da X-MS-TrafficTypeDiagnostic: DU2PR04MB8934:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UtkpK2sNRfgvs0f/b7NaN0izmJ7yCvMoihwtuDhsdxvhndHnlPTN6EDbvpMC6WzMDmMnlcVXvp6SHCJWiadEURLzdXB049+89Rg0s+o4Uk2szQ4PMzcYn/gxSeLBRc2gWJBN+hvSdrypWoOsPgjgOQTKEgclwkvlzsPMPafCcPvky6rNo1aUJkzHchRuvG51suh65MIm0wf9T7iPOYaTvNVodw0lU4vZtY3a67MVsSiXWFuOaY6kGR0SY8+TtIEkhJl4IBeABSEdrD8kS+Y5Qk836XZE94xtrE4OeEogHpQBXhnnOleyn+179+pY4myS75quFbTik1UKAGG4B+XJB0cjt2epofO1kwwFFfFqKsmNF0v3sgr6PSxXWmqKUv8vMBvB9MAPNcJGJP39o0Et6G9MT06mfkIXzDNTonZYjLJKEt9lh7UJefFBB7ZiKFK8fZTi2qHAzkqrXLjvGgWMFC2aO7jcs9OgPRaijvwig1vP8AcxHKhN95tF6QJOZhOjOYPPJUbTTtqRk+EHwJW3T+uo6AMLoWI9nm09/aaEAs1uGa4shHKHwqRIVafVH1BK2vTxC0lVt/UsEodyG4n20MPT1KcIru8PMoe4FgDOIxqhSmAv1Gc5t1AfYGmwE9LlfO/+q0NeoQJfIgTyD3502PEhC3VNXL5BSlkX6mMQeT8BLW4KSlVAxTUzI7j0Ee43dCnFmwov5B06j13lcUjhmjhxUJdGxJZpoXvRDBqbi1U= 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:(13230001)(4636009)(366004)(6916009)(36756003)(38350700002)(1076003)(54906003)(38100700002)(316002)(66476007)(6512007)(83380400001)(86362001)(508600001)(2616005)(2906002)(8936002)(66556008)(7416002)(6666004)(26005)(6506007)(6486002)(4326008)(8676002)(66946007)(5660300002)(44832011)(186003)(52116002)(17423001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UJmXy0R/jYK1dlSkRzRELmcr2MY6Yfhv9n+GDiuXystcVGRR3AxaUI79O3aerAI97wIviC1YC/t1h3ulwozqOou8jUYNyQAJUV6poMnfGAbZYQXZzYc57EN+xbprkno97FXa/whnIBOg7HrxPr1hrx1PK6nYW/V0W0e8R/XOCtzMkeOJy9vuALm3yhDVpKF7o8soYvRJDg5bC3VbMOi6ojidNjxs4Vk940MnLEo+eoj29g1MdbXhSpbB2+5OmOoU1gHhAFMfsL0QPEdQVu8c7UY+L7INIrKHvv/qQwQ2ZEdGEUHXVZBt0mQGy7PLIxwVM0LKvR3LQDsQ1n3Xb56Po8P/G3TTwG+7HzR6zFu37++25uCB2NDDaIiboX6QXsQjv3v4RubQM4aUKyN9TGkPlJRPai4ruFshkki9iRTGBZ1j8YgaNGuHCDvfh5IdZzxQvDePDtoGoVTBxzBSCNnAMjE9IENIpkmtlD0kyiPUCL8xw0se1ypCd3rfAcbISl3isTfjRa4xpkSShmoAfjR3bA2MnMZqgOMBgbYhLrwDFUqS5fnMSvq1x1KGycD+IONNhWFqyf5UdOSQqDYufl2m0Lxwdx2W8cMWh8iaXx0wzSILqlaYk+hEgrwuwKKcvft/xVpdmlt+MHK3Qo4tv8pm6SgylJOmTjUEoNmrvs/aEdRixxkV6zQpOaR2kVU10+sbyJDF6cqhv77PJmflpKu+9r5OEp0tve08vgzM+abXWFZ6pXlcD4d4XIIeuf2wG4Ur8HAyxe/xBlYT4Quhb3kETn1ANmfVBT8PbTxz/rQMwZxFK7LuXU+7wZQzVqkRSt/q3fk8m1EgdHpG9+mx+x5GuszffOqnc13Ze+2Nu1Y78X8BdBjhbA9NJwwLZVb4jDq7YVMuC0CLKMiC4REBKee280KF1nRukXKtVIVETzvu75jbmM1bPL1MHKSJJp3d/+0xrmoLs83etR8v4uky9JNs6+Hd7vjkdF/Uze11qnmHIfCTYGT4qaL72lN6193v8mmdtKSFzZsLqDlk+sbEB/JJctbrPwHHphBsU4p74kPXHblFEk66YfnI1qkXqGbpZRgOO/HwMZtaD9XBwStAtHNQaFxuDSvJ5xRFtKa8WZbNcNZZARKkjsvv58COsfpXxdrBm1I5sWJMtYj8XGpOWzseU7Fa7oPfvUBPqJSz5sdGjM/0Tu9AUBW2qfB+4XbFPJMdMGU69TPEOGu5Et5NhbzCcpuJZzIz5IOdpSZdLP+kRc7HwwbFB/e7isTh6krjRPsjMrC+d7Myv9yXhoEc9WK105iTjflJOvIQxaHVw3uRsmYIhwKwskIRL0PE2nrpV42QduGXbAY8mc2qUKLDJSIooK0CA5BrhlVnXYoqW5dgBKvQCKeGoPh+ax8ntwSUmap6mQjr+4eJeqD29uFnaWcCW+XUKbqH2SiKZhKVquMBt2OUUAxnURTpf4mALxCi7NJ1r5lv273fFukYqwdGxjSIgw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: de51fb9d-cfb1-46e2-1d6a-08da03a446da X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 21:15:32.6128 (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: wmxvaW7GZ6M48z1DJHolRM7HABzOhPNIABCnKEGCl8mYjGStBkbDm13Xiphy9AuHawiUB6Ea7b+Xl8GHm69LUQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8934 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Similar to the port-based default priority, IEEE 802.1Q-2018 allows the Application Priority Table to define QoS classes (0 to 7) per IP DSCP value (0 to 63). In the absence of an app table entry for a packet with DSCP value X, QoS classification for that packet falls back to other methods (VLAN PCP or port-based default). The presence of an app table for DSCP value X with priority Y makes the hardware classify the packet to QoS class Y. As opposed to the default-prio where DSA exposes only a "set" in dsa_switch_ops (because the port-based default is the fallback, it always exists, either implicitly or explicitly), for DSCP priorities we expose an "add" and a "del". The addition of a DSCP entry means trusting that DSCP priority, the deletion means ignoring it. Drivers that already trust (at least some) DSCP values can describe their configuration in dsa_switch_ops :: port_get_dscp_prio(), which is called for each DSCP value from 0 to 63. Again, there can be more than one dcbnl app table entry for the same DSCP value, DSA chooses the one with the largest configured priority. Signed-off-by: Vladimir Oltean --- include/net/dsa.h | 5 +++ net/dsa/slave.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) diff --git a/include/net/dsa.h b/include/net/dsa.h index 1220af73151b..9bfe984fcdbf 100644 --- a/include/net/dsa.h +++ b/include/net/dsa.h @@ -898,6 +898,11 @@ struct dsa_switch_ops { int (*port_get_default_prio)(struct dsa_switch *ds, int port); int (*port_set_default_prio)(struct dsa_switch *ds, int port, u8 prio); + int (*port_get_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp); + int (*port_add_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp, + u8 prio); + int (*port_del_dscp_prio)(struct dsa_switch *ds, int port, u8 dscp, + u8 prio); /* * Suspend and resume diff --git a/net/dsa/slave.c b/net/dsa/slave.c index 97f5da81fe68..f9cecda791d5 100644 --- a/net/dsa/slave.c +++ b/net/dsa/slave.c @@ -1880,6 +1880,40 @@ dsa_slave_dcbnl_set_default_prio(struct net_device *dev, struct dcb_app *app) return 0; } +static int __maybe_unused +dsa_slave_dcbnl_add_dscp_prio(struct net_device *dev, struct dcb_app *app) +{ + struct dsa_port *dp = dsa_slave_to_port(dev); + struct dsa_switch *ds = dp->ds; + unsigned long mask, new_prio; + int err, port = dp->index; + u8 dscp = app->protocol; + + if (!ds->ops->port_add_dscp_prio) + return -EOPNOTSUPP; + + if (dscp >= 64) { + netdev_err(dev, "DSCP APP entry with protocol value %u is invalid\n", + dscp); + return -EINVAL; + } + + err = dcb_ieee_setapp(dev, app); + if (err) + return err; + + mask = dcb_ieee_getapp_mask(dev, app); + new_prio = __fls(mask); + + err = ds->ops->port_add_dscp_prio(ds, port, dscp, new_prio); + if (err) { + dcb_ieee_delapp(dev, app); + return err; + } + + return 0; +} + static int __maybe_unused dsa_slave_dcbnl_ieee_setapp(struct net_device *dev, struct dcb_app *app) { @@ -1892,6 +1926,8 @@ static int __maybe_unused dsa_slave_dcbnl_ieee_setapp(struct net_device *dev, return -EOPNOTSUPP; } break; + case IEEE_8021QAZ_APP_SEL_DSCP: + return dsa_slave_dcbnl_add_dscp_prio(dev, app); default: return -EOPNOTSUPP; } @@ -1924,6 +1960,30 @@ dsa_slave_dcbnl_del_default_prio(struct net_device *dev, struct dcb_app *app) return 0; } +static int __maybe_unused +dsa_slave_dcbnl_del_dscp_prio(struct net_device *dev, struct dcb_app *app) +{ + struct dsa_port *dp = dsa_slave_to_port(dev); + struct dsa_switch *ds = dp->ds; + int err, port = dp->index; + u8 dscp = app->protocol; + + if (!ds->ops->port_del_dscp_prio) + return -EOPNOTSUPP; + + err = dcb_ieee_delapp(dev, app); + if (err) + return err; + + err = ds->ops->port_del_dscp_prio(ds, port, dscp, app->priority); + if (err) { + dcb_ieee_setapp(dev, app); + return err; + } + + return 0; +} + static int __maybe_unused dsa_slave_dcbnl_ieee_delapp(struct net_device *dev, struct dcb_app *app) { @@ -1936,6 +1996,8 @@ static int __maybe_unused dsa_slave_dcbnl_ieee_delapp(struct net_device *dev, return -EOPNOTSUPP; } break; + case IEEE_8021QAZ_APP_SEL_DSCP: + return dsa_slave_dcbnl_del_dscp_prio(dev, app); default: return -EOPNOTSUPP; } @@ -1967,6 +2029,30 @@ static int dsa_slave_dcbnl_init(struct net_device *dev) return err; } + if (ds->ops->port_get_dscp_prio) { + int protocol; + + for (protocol = 0; protocol < 64; protocol++) { + struct dcb_app app = { + .selector = IEEE_8021QAZ_APP_SEL_DSCP, + .protocol = protocol, + }; + int prio; + + prio = ds->ops->port_get_dscp_prio(ds, port, protocol); + if (prio == -EOPNOTSUPP) + continue; + if (prio < 0) + return prio; + + app.priority = prio; + + err = dcb_ieee_setapp(dev, &app); + if (err) + return err; + } + } + return 0; } From patchwork Fri Mar 11 21:15:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vladimir Oltean X-Patchwork-Id: 12778624 X-Patchwork-Delegate: kuba@kernel.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 536C2C433F5 for ; Fri, 11 Mar 2022 22:50:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229882AbiCKWvw (ORCPT ); Fri, 11 Mar 2022 17:51:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229846AbiCKWvd (ORCPT ); Fri, 11 Mar 2022 17:51:33 -0500 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2041.outbound.protection.outlook.com [40.107.22.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 813272D34B7 for ; Fri, 11 Mar 2022 14:25:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MEM0ewJeqqzGU9Ngx8hOzZcwun2YJdW7B678MmXMxCQqyPafNDlrLguTIbLGazmx0MAc6rvymYN+s7pGhz7xRoi0FLOlQ1xUjp6+3iHhV512cVU1yVzZ89hHUnJxATLsvSHqO+SoqZF60FO2ZdbTR2wXzqS3hAOaVg/9Hziu3CoVOn6Cm78ibcFopmJRfE4yNQCTcfY3O5oVZblu1i7UVD7idIt8hbXdAJDTtOSnSzU9j6pDj1g0PU0wjm2cFm8IjZULS+EE31W+aFP0mTmwrETeNIdP4280LIqLh0B/HnIJca0XVdFYKPuOqesXVFyjp7I+FbwNUN5mBjuUkmA76A== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=4Vwt9FtCvYzEhXgxr1gv2K9Sv+YQbLtoObEzHClRLIY=; b=DN6PtrRMQYSj1ZM8D580rLd4OGZ7FkuFqcGVnnnsUVIgUk7NYH2Nfl+1Pn0nXV0wL+sfgnK0tN24A73D7+vajov7RK+z3ind2LxRpttqqLHNc0Rt7S6z6zvaf9x397/LSbJS+ZjkBkTg0tRRHqJCl/fYoLELs2bk3ihvoEyjWd9Q1ZymHtbdC8lzDxdO2TerldaFgarop5apc/NZVPALDxpSQIKSXQKCiD3ZU0jJ0hFNoB699ogf2w7F4sF5dOqXykNVMpUMUj9wOiknLUpsXDbT3WW2yQflGsGGNweSlapsTiiA8+uON/kI7r/7YcX6CxmzPhYxxucGXTHqArZNTg== 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=4Vwt9FtCvYzEhXgxr1gv2K9Sv+YQbLtoObEzHClRLIY=; b=OwheHpl4H0FbjtY0j9k8BR3T2WMZcXRuCCFBdHy08pXkzX6ayZdVzbInEW/GKo16GVf8drUpZeTpLUbkBTMbA5LujDwMCZeTyFIDk4v75XNxXOm8CND1wJv1QpGoJG6t4FnbTKkQ4KH2YYw1iamJ3qNJub/I+jY6C993eD0wuC4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) by DU2PR04MB8934.eurprd04.prod.outlook.com (2603:10a6:10:2e1::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5061.22; Fri, 11 Mar 2022 21:15:33 +0000 Received: from VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::ac0c:d5d:aaa9:36]) by VI1PR04MB5136.eurprd04.prod.outlook.com ([fe80::ac0c:d5d:aaa9:36%5]) with mapi id 15.20.5038.027; Fri, 11 Mar 2022 21:15:33 +0000 From: Vladimir Oltean To: netdev@vger.kernel.org Cc: Jakub Kicinski , "David S. Miller" , Florian Fainelli , Andrew Lunn , Vivien Didelot , Vladimir Oltean , Claudiu Manoil , Alexandre Belloni , UNGLinuxDriver@microchip.com, Petr Machata Subject: [PATCH net-next 3/3] net: dsa: felix: configure default-prio and dscp priorities Date: Fri, 11 Mar 2022 23:15:20 +0200 Message-Id: <20220311211520.2543260-4-vladimir.oltean@nxp.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220311211520.2543260-1-vladimir.oltean@nxp.com> References: <20220311211520.2543260-1-vladimir.oltean@nxp.com> X-ClientProxiedBy: AS8PR04CA0188.eurprd04.prod.outlook.com (2603:10a6:20b:2f3::13) To VI1PR04MB5136.eurprd04.prod.outlook.com (2603:10a6:803:55::19) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8a701860-1373-430a-8821-08da03a4478a X-MS-TrafficTypeDiagnostic: DU2PR04MB8934:EE_ X-Microsoft-Antispam-PRVS: X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UM970Vb2itfZc94imhf1rnrSPpPg1bMwuK16jp11I2EK2t0W2mHOXOOKN3xWGBsz7Kq9wqrG8XVuI6kySL91kTMnYg6y84Ya3ikbKHwjogrOQABk+4kZ9aiw0oqHs47io9XX+K2keePV35gSx6TJX3gHfcAPm1SsHY3G4pBsXpiJOnbqeU3EaH72rxO4TUpcn9B07J0Y+rplI+wsHrQ/UyZSex/Xy1/WOrXyfkwRpaH4WFsnOcid1GemWJc2hrLWTaljHvcujXs+l7Jg0YCavxJ/kZDt5IcxY5EsO8fE6rYkfw1a4IDWVrpWSENzSgh/pah01C7J98cUxk1XU7R8U2FthUHcRW7jOMtvrXyrfjyt9gHkM6xKqPwGBMnloktVeUT/aD3yUuNi9prUN/z/QUoKcCrSZHXOGJjXtOxbLJlx3eIjUZHOeHjX6o7WbDr4TpifxAmBRJ3gMTgip+96fPOKOCXXnjAlvtzMJwjFLdsB/0HA/Eugg9OstP8KGSitLMmJ1QCQovXUQOfrmZy2Wv2d+x/nnOU+ngrxBBosXaCjk5eG0qxZ8I28ytdyJ4P2yRR4yLZUo9GpqOCJVG3+U0nnd+iz0oIs5LoBkUxa7ICaxtBEHypTHODU3ASOf0wp/cNt68yg3aH8Fof0q0LuRdYS5jG4ObOxBVC4amtGntZVafMrPZkMQcylL3DojDJeSusjpKmrSGAaIoLqd7FbVA== 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:(13230001)(4636009)(366004)(6916009)(36756003)(38350700002)(1076003)(54906003)(38100700002)(316002)(66476007)(6512007)(83380400001)(86362001)(508600001)(2616005)(2906002)(8936002)(66556008)(7416002)(6666004)(26005)(6506007)(6486002)(4326008)(8676002)(66946007)(5660300002)(44832011)(186003)(52116002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 35k6Cynxma5b4t0eBzpNy2TrSbSsaVb/r0j+4lt34+D9srbuUVW6ewXYcnLj6iKCPRpIIAFfJU9kgNEiXDhDRfSHjjVUv5m1TGJrx3whGTvtUSYzrx9KIyYfzrBmsBi0v6O2KIb6zrfOxxQZJx95KWDVAlzOQ4TWzReVD7wgjw2CIoU7cdQ3hoDXWbC7ThWjkTrgRwlYoS0AovKFdb5Ux6I2ypCNn5ubLighfsXVOzPBpjuDT6zP1hANC4xw2/KmFi3G8uQabQyOntU+g8a7hWS57LEP8oG9pJ46wkfe3dQtR6H1L5mp9LiBSbDO17qwa/wCTlaSfgzYWEZwyNta/9id+F9+nj/nEsDHWCkyVsF61WZJkKyKhhWZ/fCILk/Lr7RzeJplNzonCGgcInZGe5qoP8iDpeFhSQdZASDf0ErsD9XflHjuZb1P5EwjN/9weu7uC92v7bvTcDz7UnO1nHixYq0hnuOrBw8Uygq1g7MJaUQVmHACWEUyCPEprXlHj96O8hVMGh3xNiABj02qxQbnXZmG9M2flDPqEM0aI4Ir9KfVH7muh1BPO0Vq7K3A6zdantDBOeqTlEjT6bfzc7DhK4cZUkC7VvtLChPiIB0PJdWpCjKM4uTxhaoZUr6YjrqVintfBS9wu8d50Yh32mZ5UDOTWkUOarpDi8nPNCs8IJWzaqwUnR2/SZFdKORbAuxxRrCanYUQWvRG7prw4z8jSNyD68CPodgVRw2gnniI0n++QXRdhc/ZHrazNrSAl2zmzzfyWwo3uo7p7/km2SxpI6EPVCRbJGXtYbhmG1PMaF3p5bOMOs6g4Y39VlmVidtMCezVWU1MJVozQ9KSZwOpfcVN+SJhblVcRIgPygN3pVTYOuPAoOsTpw5sInqrXIsY+trPu+FQgBzY6hqa47lLyGknj58yd6uKJj3/FeKq0hATOIF8+XEJQGNfqWwNOB9Lz5SwDqukMmm0KRtNExA6FOog0hYrzQwoWw+E3lzTkexXoUf2XSpwM2RofFPk0NmeRXejQqKTEJQOIoRpKQCiaArnux1gepfTDN8rEQBTbZjjYmcKhJ+WzrTbJ/hfsV01rxQPV4STeTO1UskQOFn08i3N6TRk6tmidXNas+SRPGH4Xw9H/jj8DrKO/gCgC07XJ3GfppGMzpEEZBtualXq4Innfn3ZOb34QZYZ0kfhepIzIrx1nS6BttvM1/tsba6KyWK7Ki1REXa+5hC6f/wHQSZxcKjyA0wmg0Bx6E22w5tbRgNksYEzCaKBEOVLWaaNp/11Y7d+JpGxsLb3nRLQSp66kTqHH0+n3E7XPI+t/NK2VUma4swg8HG5QqD1WTPs5ZQfMzqrkBaxiRV5E4fUxcum+WSiHHjZux+6aSN9veD1+Rnvo0iGwHZ4B4ljhUmKTCYbf6Mqe3SVD7wlb9zV2rrCFXjmtKvick861SQJL5PvEqTcgWQ/LZOjnyfNaNIhLrckysMGTlqhgotCrg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8a701860-1373-430a-8821-08da03a4478a X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5136.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 11 Mar 2022 21:15:33.8002 (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: NeP8SF5lEbmsmLCJOgvYbLIrpJ6v465A9DAMTBND4Ybev8VwE4apHcRhl0S1ofQzNbgqVQyeDNcqcd2JNOveXA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8934 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Follow the established programming model for this driver and provide shims in the felix DSA driver which call the implementations from the ocelot switch lib. The ocelot switchdev driver wasn't integrated with dcbnl due to lack of hardware availability. The switch doesn't have any fancy QoS classification enabled by default. The provided getters will create a default-prio app table entry of 0, and no dscp entry. However, the getters have been made to actually retrieve the hardware configuration rather than static values, to be future proof in case DSA will need this information from more call paths. For default-prio, there is a single field per port, in ANA_PORT_QOS_CFG, called QOS_DEFAULT_VAL. DSCP classification is enabled per-port, again via ANA_PORT_QOS_CFG (field QOS_DSCP_ENA), and individual DSCP values are configured as trusted or not through register ANA_DSCP_CFG (replicated 64 times). An untrusted DSCP value falls back to other QoS classification methods. If trusted, the selected ANA_DSCP_CFG register also holds the QoS class in the QOS_DSCP_VAL field. The hardware also supports DSCP remapping (DSCP value X is translated to DSCP value Y before the QoS class is determined based on the app table entry for Y) and DSCP packet rewriting. The dcbnl framework, for being so flexible in other useless areas, doesn't appear to support this. So this functionality has been left out. Signed-off-by: Vladimir Oltean --- drivers/net/dsa/ocelot/felix.c | 43 +++++++++++ drivers/net/ethernet/mscc/ocelot.c | 116 +++++++++++++++++++++++++++++ include/soc/mscc/ocelot.h | 5 ++ 3 files changed, 164 insertions(+) diff --git a/drivers/net/dsa/ocelot/felix.c b/drivers/net/dsa/ocelot/felix.c index 35b436a491e1..13d6b178777c 100644 --- a/drivers/net/dsa/ocelot/felix.c +++ b/drivers/net/dsa/ocelot/felix.c @@ -1799,6 +1799,44 @@ felix_mrp_del_ring_role(struct dsa_switch *ds, int port, return ocelot_mrp_del_ring_role(ocelot, port, mrp); } +static int felix_port_get_default_prio(struct dsa_switch *ds, int port) +{ + struct ocelot *ocelot = ds->priv; + + return ocelot_port_get_default_prio(ocelot, port); +} + +static int felix_port_set_default_prio(struct dsa_switch *ds, int port, + u8 prio) +{ + struct ocelot *ocelot = ds->priv; + + return ocelot_port_set_default_prio(ocelot, port, prio); +} + +static int felix_port_get_dscp_prio(struct dsa_switch *ds, int port, u8 dscp) +{ + struct ocelot *ocelot = ds->priv; + + return ocelot_port_get_dscp_prio(ocelot, port, dscp); +} + +static int felix_port_add_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, + u8 prio) +{ + struct ocelot *ocelot = ds->priv; + + return ocelot_port_add_dscp_prio(ocelot, port, dscp, prio); +} + +static int felix_port_del_dscp_prio(struct dsa_switch *ds, int port, u8 dscp, + u8 prio) +{ + struct ocelot *ocelot = ds->priv; + + return ocelot_port_del_dscp_prio(ocelot, port, dscp, prio); +} + const struct dsa_switch_ops felix_switch_ops = { .get_tag_protocol = felix_get_tag_protocol, .change_tag_protocol = felix_change_tag_protocol, @@ -1862,6 +1900,11 @@ const struct dsa_switch_ops felix_switch_ops = { .port_mrp_del_ring_role = felix_mrp_del_ring_role, .tag_8021q_vlan_add = felix_tag_8021q_vlan_add, .tag_8021q_vlan_del = felix_tag_8021q_vlan_del, + .port_get_default_prio = felix_port_get_default_prio, + .port_set_default_prio = felix_port_set_default_prio, + .port_get_dscp_prio = felix_port_get_dscp_prio, + .port_add_dscp_prio = felix_port_add_dscp_prio, + .port_del_dscp_prio = felix_port_del_dscp_prio, }; struct net_device *felix_port_to_netdev(struct ocelot *ocelot, int port) diff --git a/drivers/net/ethernet/mscc/ocelot.c b/drivers/net/ethernet/mscc/ocelot.c index 21134125a6e4..41dbb1e326c4 100644 --- a/drivers/net/ethernet/mscc/ocelot.c +++ b/drivers/net/ethernet/mscc/ocelot.c @@ -2907,6 +2907,122 @@ void ocelot_port_bridge_flags(struct ocelot *ocelot, int port, } EXPORT_SYMBOL(ocelot_port_bridge_flags); +int ocelot_port_get_default_prio(struct ocelot *ocelot, int port) +{ + int val = ocelot_read_gix(ocelot, ANA_PORT_QOS_CFG, port); + + return ANA_PORT_QOS_CFG_QOS_DEFAULT_VAL_X(val); +} +EXPORT_SYMBOL_GPL(ocelot_port_get_default_prio); + +int ocelot_port_set_default_prio(struct ocelot *ocelot, int port, u8 prio) +{ + if (prio >= IEEE_8021QAZ_MAX_TCS) + return -ERANGE; + + ocelot_rmw_gix(ocelot, + ANA_PORT_QOS_CFG_QOS_DEFAULT_VAL(prio), + ANA_PORT_QOS_CFG_QOS_DEFAULT_VAL_M, + ANA_PORT_QOS_CFG, + port); + + return 0; +} +EXPORT_SYMBOL_GPL(ocelot_port_set_default_prio); + +int ocelot_port_get_dscp_prio(struct ocelot *ocelot, int port, u8 dscp) +{ + int qos_cfg = ocelot_read_gix(ocelot, ANA_PORT_QOS_CFG, port); + int dscp_cfg = ocelot_read_rix(ocelot, ANA_DSCP_CFG, dscp); + + /* Return error if DSCP prioritization isn't enabled */ + if (!(qos_cfg & ANA_PORT_QOS_CFG_QOS_DSCP_ENA)) + return -EOPNOTSUPP; + + if (qos_cfg & ANA_PORT_QOS_CFG_DSCP_TRANSLATE_ENA) { + dscp = ANA_DSCP_CFG_DSCP_TRANSLATE_VAL_X(dscp_cfg); + /* Re-read ANA_DSCP_CFG for the translated DSCP */ + dscp_cfg = ocelot_read_rix(ocelot, ANA_DSCP_CFG, dscp); + } + + /* If the DSCP value is not trusted, the QoS classification falls back + * to VLAN PCP or port-based default. + */ + if (!(dscp_cfg & ANA_DSCP_CFG_DSCP_TRUST_ENA)) + return -EOPNOTSUPP; + + return ANA_DSCP_CFG_QOS_DSCP_VAL_X(dscp_cfg); +} +EXPORT_SYMBOL_GPL(ocelot_port_get_dscp_prio); + +int ocelot_port_add_dscp_prio(struct ocelot *ocelot, int port, u8 dscp, u8 prio) +{ + int mask, val; + + if (prio >= IEEE_8021QAZ_MAX_TCS) + return -ERANGE; + + /* There is at least one app table priority (this one), so we need to + * make sure DSCP prioritization is enabled on the port. + * Also make sure DSCP translation is disabled + * (dcbnl doesn't support it). + */ + mask = ANA_PORT_QOS_CFG_QOS_DSCP_ENA | + ANA_PORT_QOS_CFG_DSCP_TRANSLATE_ENA; + + ocelot_rmw_gix(ocelot, ANA_PORT_QOS_CFG_QOS_DSCP_ENA, mask, + ANA_PORT_QOS_CFG, port); + + /* Trust this DSCP value and map it to the given QoS class */ + val = ANA_DSCP_CFG_DSCP_TRUST_ENA | ANA_DSCP_CFG_QOS_DSCP_VAL(prio); + + ocelot_write_rix(ocelot, val, ANA_DSCP_CFG, dscp); + + return 0; +} +EXPORT_SYMBOL_GPL(ocelot_port_add_dscp_prio); + +int ocelot_port_del_dscp_prio(struct ocelot *ocelot, int port, u8 dscp, u8 prio) +{ + int dscp_cfg = ocelot_read_rix(ocelot, ANA_DSCP_CFG, dscp); + int mask, i; + + /* During a "dcb app replace" command, the new app table entry will be + * added first, then the old one will be deleted. But the hardware only + * supports one QoS class per DSCP value (duh), so if we blindly delete + * the app table entry for this DSCP value, we end up deleting the + * entry with the new priority. Avoid that by checking whether user + * space wants to delete the priority which is currently configured, or + * something else which is no longer current. + */ + if (ANA_DSCP_CFG_QOS_DSCP_VAL_X(dscp_cfg) != prio) + return 0; + + /* Untrust this DSCP value */ + ocelot_write_rix(ocelot, 0, ANA_DSCP_CFG, dscp); + + for (i = 0; i < 64; i++) { + int dscp_cfg = ocelot_read_rix(ocelot, ANA_DSCP_CFG, i); + + /* There are still app table entries on the port, so we need to + * keep DSCP enabled, nothing to do. + */ + if (dscp_cfg & ANA_DSCP_CFG_DSCP_TRUST_ENA) + return 0; + } + + /* Disable DSCP QoS classification if there isn't any trusted + * DSCP value left. + */ + mask = ANA_PORT_QOS_CFG_QOS_DSCP_ENA | + ANA_PORT_QOS_CFG_DSCP_TRANSLATE_ENA; + + ocelot_rmw_gix(ocelot, 0, mask, ANA_PORT_QOS_CFG, port); + + return 0; +} +EXPORT_SYMBOL_GPL(ocelot_port_del_dscp_prio); + void ocelot_init_port(struct ocelot *ocelot, int port) { struct ocelot_port *ocelot_port = ocelot->ports[port]; diff --git a/include/soc/mscc/ocelot.h b/include/soc/mscc/ocelot.h index ee3c59639d70..4d51e2a7120f 100644 --- a/include/soc/mscc/ocelot.h +++ b/include/soc/mscc/ocelot.h @@ -869,6 +869,11 @@ int ocelot_port_pre_bridge_flags(struct ocelot *ocelot, int port, struct switchdev_brport_flags val); void ocelot_port_bridge_flags(struct ocelot *ocelot, int port, struct switchdev_brport_flags val); +int ocelot_port_get_default_prio(struct ocelot *ocelot, int port); +int ocelot_port_set_default_prio(struct ocelot *ocelot, int port, u8 prio); +int ocelot_port_get_dscp_prio(struct ocelot *ocelot, int port, u8 dscp); +int ocelot_port_add_dscp_prio(struct ocelot *ocelot, int port, u8 dscp, u8 prio); +int ocelot_port_del_dscp_prio(struct ocelot *ocelot, int port, u8 dscp, u8 prio); int ocelot_port_bridge_join(struct ocelot *ocelot, int port, struct net_device *bridge, int bridge_num, struct netlink_ext_ack *extack);