From patchwork Wed Jun 2 12:31:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 453057 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 81F1FC4708F for ; Wed, 2 Jun 2021 12:31:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6168C613BF for ; Wed, 2 Jun 2021 12:31:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229934AbhFBMdC (ORCPT ); Wed, 2 Jun 2021 08:33:02 -0400 Received: from mail-bn8nam12on2079.outbound.protection.outlook.com ([40.107.237.79]:33089 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229828AbhFBMc6 (ORCPT ); Wed, 2 Jun 2021 08:32:58 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=VSW3P9kRtpOclwTuaPXWvZqPBu1LNvKh2E0CirGtoHGrFYkH9793vTXIt6banyR7IsOni8ZRTpgmqGjLDj6mg+yacP5+1S9yzYGJsZg7j2QD4EcK+cfKJ1TCPF5ep9PthtP9a6Pntyerxq0wGVPJU4qb83eulSLKUK0l+amLCTk3mNmB61yO7/OYrCR8cvw+MjKsgKYkZ7X1sc97X96sep1VzCITOpgZN6Zxvi2IXQ7Rib863DGlGrAFWXu7JWudJd0BMXTmM9Nv9hLTeMNmJJNG4mZaNe9u3RUtTFCEypNDoXNqtJrwxJemAm93SgPJpAA0mO0rpiX+AT9xj8tBAw== 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=NE5B3qxn8XNStV8xoUvUEnaZxCtUjYEkqXMVWBfNNt8=; b=jCpupYG+a8O8Z7P4FtNFSFuesQQiv9Dg4re33fy5UYc8X8Cx7gDQU48zVmyygHsex+2+S4RuZO+525gsUBvEO7fbGDKnn/kwv3YsmgwGLxDvS4Z8Zc2U1eNba/SsgisPUR4bytLtcbkrPO3O8s/vxq5pZZXeROqfGbwq0LipAMfkPeyzWZOOtWyelVtQiULMAGTS9/XU4hXwRRQJnx+SMMVS0O8JiFoHtKkKxP/LTVg9ES9jqaxcPigZ08xNdaUfG1EV23n3Wm03V/KLNmHDJmyZDScVr/hHHEglV16gj/3uAFhH3JfCTO3tKk9MISVIZBlqeHIy2zrpKszbCkxKKA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=NE5B3qxn8XNStV8xoUvUEnaZxCtUjYEkqXMVWBfNNt8=; b=CGDv0cVf7YBSMnxmjIHgIZ3mjFyQI9Ki3hI0mSk9AMPFx/NYht2/Eye62lvMo1TdqMLQTSbnQyX513Fgk7z6OznTe+f7+QCiHAhuKocscklXOaqCa0SEVNb1NLm2tGg5KEEUw6ud6+QgLCBttjZr8T18LHp2CJ8Pc8+ThYc4RJ+0pc+EEjjuF78FaDva44pBPzxJWUyAWtZd+Dak6EUifXITe6Q8yByxrymj9mrtuBBI+gBblfk2Jums2VTOPCv5bo8+IDh31dRc/Y0hF4kPt3RQ2vtDR+1XdrR6gAVL5QoCM5G6bCQHIYD8u/3fOYKbW5ygo1L2VH7B/ph6OnwNcw== Received: from BN9PR03CA0577.namprd03.prod.outlook.com (2603:10b6:408:10d::12) by DM6PR12MB3084.namprd12.prod.outlook.com (2603:10b6:5:117::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.27; Wed, 2 Jun 2021 12:31:14 +0000 Received: from BN8NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:408:10d:cafe::ac) by BN9PR03CA0577.outlook.office365.com (2603:10b6:408:10d::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.15 via Frontend Transport; Wed, 2 Jun 2021 12:31:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; davemloft.net; dkim=none (message not signed) header.d=none; davemloft.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT015.mail.protection.outlook.com (10.13.176.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4150.30 via Frontend Transport; Wed, 2 Jun 2021 12:31:13 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 05:31:12 -0700 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 12:31:12 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.13) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Jun 2021 12:31:09 +0000 From: Dmytro Linkin To: CC: , , , , , , , , Subject: [PATCH RESEND iproute2 net-next 1/4] uapi: update devlink kernel header Date: Wed, 2 Jun 2021 15:31:02 +0300 Message-ID: <1622637065-30803-2-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622637065-30803-1-git-send-email-dlinkin@nvidia.com> References: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> <1622637065-30803-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6a24e73f-9be0-4f36-257a-08d925c24f5b X-MS-TrafficTypeDiagnostic: DM6PR12MB3084: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1169; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: HiR5kcSw9bMFQ06fOjMY1/rvYXblr01dKUMmCQ60XRR0apOCMbBOwOcPECZF0znRXyB9UE9CmhHlLxf3YkM0Jn1Rlya8ng7Rj+xJBVexOgCsEG6O9Ct9lRxpBVMTQ1+g0pX3xufNBQTeXp7lIy9hr9H98EY+L+02j+0EfgqLEGZo0VOP3/OxTcgza1n2Ov4m2jFWCiYgGLFF+tNB8F3E4rZEAOZRlS754ARWIYDRdNGDRdpAaod5bC1OOl7nW7seDPmscDKAnuTv65BGmUqHKcjQICfOYsmER9Rdsj+S6SsDGuqPLF/2vA+i2rIz9LVb7tiiLeyAL1Go00Uz7r4D4OLwMffFj0QbUt6T8ko3sFeFFEwC/+e9wLOmbltUm/FnSTTEKGnWI4KcT0z2+g86KdxsB4AW5xTFy1nkIE/EUeQqLEBf42/UWsW/2IrCn2QVLYJiZosZqS4AvnmhIJ4y3S2y+fkEzHpty4UOfjSZ7lVjpoKBCmQK1PEXSQDy8iZp/DnJrEXdXy8cAZcCi2Ahe2KVaGqmDYKgR7K7zI8l9fyn4IqPNEQqTZYrA5rITdmQQiZpR2ot+1SsSpofGtRu6pWgcYcSVabgz40QWNdVxxOgPqNvwgTLbozHVd3uW+7SdD6ob+dcy765+eMzzxv21Onj4Wa6/rhuBh6wqMFuRmE= X-Forefront-Antispam-Report: CIP:216.228.112.32; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid01.nvidia.com; CAT:NONE; SFS:(4636009)(346002)(376002)(396003)(39860400002)(136003)(46966006)(36840700001)(7696005)(2616005)(107886003)(8936002)(478600001)(316002)(82310400003)(6666004)(356005)(37006003)(5660300002)(54906003)(86362001)(15650500001)(82740400003)(70206006)(186003)(47076005)(36860700001)(6200100001)(70586007)(26005)(2906002)(7636003)(336012)(6862004)(83380400001)(426003)(8676002)(7049001)(4326008)(36756003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 12:31:13.3073 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6a24e73f-9be0-4f36-257a-08d925c24f5b X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.32]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3084 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Signed-off-by: Dmytro Linkin --- include/uapi/linux/devlink.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index a430775..6408b40 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -126,6 +126,11 @@ enum devlink_command { DEVLINK_CMD_HEALTH_REPORTER_TEST, + DEVLINK_CMD_RATE_GET, /* can dump */ + DEVLINK_CMD_RATE_SET, + DEVLINK_CMD_RATE_NEW, + DEVLINK_CMD_RATE_DEL, + /* add new commands above here */ __DEVLINK_CMD_MAX, DEVLINK_CMD_MAX = __DEVLINK_CMD_MAX - 1 @@ -206,6 +211,11 @@ enum devlink_port_flavour { */ }; +enum devlink_rate_type { + DEVLINK_RATE_TYPE_LEAF, + DEVLINK_RATE_TYPE_NODE, +}; + enum devlink_param_cmode { DEVLINK_PARAM_CMODE_RUNTIME, DEVLINK_PARAM_CMODE_DRIVERINIT, @@ -534,6 +544,13 @@ enum devlink_attr { DEVLINK_ATTR_RELOAD_ACTION_STATS, /* nested */ DEVLINK_ATTR_PORT_PCI_SF_NUMBER, /* u32 */ + + DEVLINK_ATTR_RATE_TYPE, /* u16 */ + DEVLINK_ATTR_RATE_TX_SHARE, /* u64 */ + DEVLINK_ATTR_RATE_TX_MAX, /* u64 */ + DEVLINK_ATTR_RATE_NODE_NAME, /* string */ + DEVLINK_ATTR_RATE_PARENT_NODE_NAME, /* string */ + /* add new attributes above here, update the policy in devlink.c */ __DEVLINK_ATTR_MAX, From patchwork Wed Jun 2 12:31:03 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 453918 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 B040BC47083 for ; Wed, 2 Jun 2021 12:31:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 92E8E613BA for ; Wed, 2 Jun 2021 12:31:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229822AbhFBMdN (ORCPT ); Wed, 2 Jun 2021 08:33:13 -0400 Received: from mail-bn8nam11on2062.outbound.protection.outlook.com ([40.107.236.62]:21473 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229844AbhFBMdD (ORCPT ); Wed, 2 Jun 2021 08:33:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bxVA1DQ8j3ugIzQ0ASWKrYGSQdCzq95pOs7X8usrzxiZTbzabuUzvNJsJc3tI4Bv6YohW2puD+CvtAc5O7lN/uc08I5NRRJs2pQ6clyjKoOTBpIAi6u6KkgEkxsYgwbhwOdJsSFqDTF+uVLslZ3N5w2tPaXwKWd3CSQ6etAtPgx92EhNu/iygnyBa8VIVhN9FC+bi0i9ALntV3INff1rESy3cKdbrNOs7TQ1qRE8xK9p9sj8kBlYOV7Y/oKN9NyI2FoETaMEFPFr/zMlNZJQIPSj5Y8JqPuI9jeJJAbrClR3fIMAPmPSsiWTcd9GTut7bkna1CD2CnBKktYOkhlMYA== 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=4yWZZkamS5pmvG7OQWTCd1O5esXpxib4sRwGtP6Y7kM=; b=SPE9OM/XeJKQg3TuMB8qotxN8yr0qBmlYvTpvq8xnsgBPzizTFowBlj2FURtUHpZU9GW4GJFmgTcCSvog+qxngXzKWKk9dLP1gONIvddmit59xlL+vwTPACAbLqYsdCQXeM2MRnlezy4q3HCZUf3Fi8Tc7L5Hqm2iw94A0ezbSAyKdcmd0duaBcSPgFNffOakY5pHBVVCiaI+fjvHXcyfN9ktcJClHB3zTlDB+tJGhFJiQo+at/I1UokdLO4sKRAzRUl9NcABGbpm+14SXksm9PJzF0OdHadVx0D9BNU9NHjpappg5JMB6wGucdRk+Hc9X5ylSaKUfLm2ynF33sd1A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=4yWZZkamS5pmvG7OQWTCd1O5esXpxib4sRwGtP6Y7kM=; b=O84D0N47IgjyWUGGXKCIsvjx1xe9LHYNr4svD/bikkTj0hY5eWv/PYsoxxDcay+hRtDHlrZeoZP62XwUb5l+eMatufk0Bw/p1/TdnWQ1nTDp3a/GAuQbIVxRenTkMiZWw+vKH20WLWdoJmjGg8aGnRHTriVsh31UnnP0LOPMCdVbIZ5/LW3hCo0y4uHpHJztosn4hh+2lIQO+uc5ZUxPmbGonG1hgo9IVI54HEB2dfIfa7tjK19/ROtSw1VbQDFyMkL9LnCUsViYrou4suzDQbNmRy4auYoO1z58O60fFED3iZns8iG68M4xY4UBjYYOMxNZ4dB2jtb5SqMEghhDkQ== Received: from CO2PR18CA0063.namprd18.prod.outlook.com (2603:10b6:104:2::31) by DM6PR12MB3148.namprd12.prod.outlook.com (2603:10b6:5:11c::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.26; Wed, 2 Jun 2021 12:31:18 +0000 Received: from CO1NAM11FT022.eop-nam11.prod.protection.outlook.com (2603:10b6:104:2:cafe::f6) by CO2PR18CA0063.outlook.office365.com (2603:10b6:104:2::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.15 via Frontend Transport; Wed, 2 Jun 2021 12:31:18 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; davemloft.net; dkim=none (message not signed) header.d=none; davemloft.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by CO1NAM11FT022.mail.protection.outlook.com (10.13.175.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4150.30 via Frontend Transport; Wed, 2 Jun 2021 12:31:18 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 12:31:15 +0000 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 12:31:15 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.13) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Jun 2021 12:31:12 +0000 From: Dmytro Linkin To: CC: , , , , , , , , Subject: [PATCH RESEND iproute2 net-next 2/4] devlink: Add helper function to validate object handler Date: Wed, 2 Jun 2021 15:31:03 +0300 Message-ID: <1622637065-30803-3-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622637065-30803-1-git-send-email-dlinkin@nvidia.com> References: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> <1622637065-30803-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 55b8d877-e7d0-480c-4972-08d925c2522e X-MS-TrafficTypeDiagnostic: DM6PR12MB3148: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1923; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3MW1pwQIBGj3ss4PPF+8X4fNrQRCrdR3q/RDIrx67MHOJNa40vnO3cKEds0xb2ovlFxUE02Z9RgdcUbr2OrhQUx2JdbxhWuu6tPyaSBrIlzOWWNUAPNgSdBfqjv33cHWF3R+J0R6+a0nY5M94xFN9nTUcWTe5AHd8gWrLiPkZFYHyl/P86p0H04dlBcxASAXaxhOpVNGnNars7Pw1k5IF9R5v7o7s42LTDErDeAI90twlUhfgQGU3gFcuhVXiblEbR1VSQF/QpU8d7er18NbFh+OMUE0giTD96v1QtMcxCOOxHvMHfYOvEqS9VldaWuUW51zfWa9O0MFt5F4B28RRvMsw9ODadcOk0kf84virudguO1dV0+I8zkiubTKWa/o98rXxdlB3pgrcGgfvUtBYNUr/H23ZC40X40HTj8/hJvHhyBpum+6VU9EHURWIKYdxrRzKDD0dA5kHZAeKPMLo0coSpOBT2YT/TQUdOITX3bspTFeU0dpFaiJAn3MKg+tAi7F+xXF4wId3AE1L363w9vDKUfRWH7eus/Df5D+542yH77CPpkAnYJvFRP5c+OaVaMVisd1AplNAQIVzXKgRY+sjzoMP1UKj0ZtwbKj23nvFowWnKuC4n9cllw8U3m92R/6sc1Dx+rlxkkYPE3QfClCJt4zo+p8NWNWhhBEe6c= X-Forefront-Antispam-Report: CIP:216.228.112.36; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid05.nvidia.com; CAT:NONE; SFS:(4636009)(136003)(346002)(396003)(39860400002)(376002)(46966006)(36840700001)(7636003)(8936002)(6200100001)(82740400003)(478600001)(6666004)(316002)(7696005)(6862004)(86362001)(426003)(2616005)(70586007)(37006003)(36906005)(186003)(107886003)(336012)(4326008)(54906003)(36756003)(83380400001)(36860700001)(26005)(5660300002)(15650500001)(47076005)(7049001)(8676002)(356005)(70206006)(2906002)(82310400003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 12:31:18.1064 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 55b8d877-e7d0-480c-4972-08d925c2522e X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.36]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT022.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3148 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Every handler argument validated in two steps, first of which, form checking, expects identifier is few words separated by slashes. For device and region handlers just checked if identifier have expected number of slashes. Add generic function to do that and make code cleaner & consistent. Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- devlink/devlink.c | 38 +++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index 16eca4f..f435fc8 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -915,6 +915,19 @@ static int strtobool(const char *str, bool *p_val) return 0; } +static int ident_str_validate(char *str, unsigned int expected) +{ + if (!str) + return -EINVAL; + + if (get_str_char_count(str, '/') != expected) { + pr_err("Wrong identification string format.\n"); + return -EINVAL; + } + + return 0; +} + static int __dl_argv_handle(char *str, char **p_bus_name, char **p_dev_name) { str_split_by_char(str, p_bus_name, p_dev_name, '/'); @@ -924,15 +937,12 @@ static int __dl_argv_handle(char *str, char **p_bus_name, char **p_dev_name) static int dl_argv_handle(struct dl *dl, char **p_bus_name, char **p_dev_name) { char *str = dl_argv_next(dl); + int err; - if (!str) { + err = ident_str_validate(str, 1); + if (err) { pr_err("Devlink identification (\"bus_name/dev_name\") expected\n"); - return -EINVAL; - } - if (get_str_char_count(str, '/') != 1) { - pr_err("Wrong devlink identification string format.\n"); - pr_err("Expected \"bus_name/dev_name\".\n"); - return -EINVAL; + return err; } return __dl_argv_handle(str, p_bus_name, p_dev_name); } @@ -1067,18 +1077,12 @@ static int dl_argv_handle_region(struct dl *dl, char **p_bus_name, char **p_dev_name, char **p_region) { char *str = dl_argv_next(dl); - unsigned int slash_count; + int err; - if (!str) { - pr_err("Expected \"bus_name/dev_name/region\" identification.\n"); - return -EINVAL; - } - - slash_count = get_str_char_count(str, '/'); - if (slash_count != 2) { - pr_err("Wrong region identification string format.\n"); + err = ident_str_validate(str, 2); + if (err) { pr_err("Expected \"bus_name/dev_name/region\" identification.\n"".\n"); - return -EINVAL; + return err; } return __dl_argv_handle_region(str, p_bus_name, p_dev_name, p_region); From patchwork Wed Jun 2 12:31:04 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 453056 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 06ECAC47083 for ; Wed, 2 Jun 2021 12:31:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DFE6B61396 for ; Wed, 2 Jun 2021 12:31:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229999AbhFBMdP (ORCPT ); Wed, 2 Jun 2021 08:33:15 -0400 Received: from mail-sn1anam02on2042.outbound.protection.outlook.com ([40.107.96.42]:38333 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229997AbhFBMdF (ORCPT ); Wed, 2 Jun 2021 08:33:05 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gQpQGspti8pAq6eijkT5J2PYhuXL35Xu30zJ33iD7ywgGg4bN3cS9pFyNFgGlBhne+yYeRahoi2NPgy7RylbIa/ecT/yinBnn6/QL4CaJCPsEFyqCONVVYGbt8DkTABuvDyIEiBBmDMIQieN1GG5sONUbMJgnGoCwjUhF3YoaDRTbz7DbXpCJchAIcHCvKl3PEfJWLnVaBZmv5mxVNk1UynSGgoZec0KFIkBYlaqooRzQW1bBP4f5A5Z6nUeiQ1yqV7FagKtuIekCenWbEaeZNQLn80ylCdXU5EpVn9TtOJIhGmoxeSAYkZtKH7uPrtNfRImbBtEleMmjorL936q6A== 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=9zlg1X8VBPoexoYaVB5/LsJD8LoNgru946AudvRJm0Q=; b=b2cP4gGHq6ACEyP+HDz7UHvds/RPFl+WIk6cLpvPriUKgdp0kS7ZMopzvnVdewYiREWIPiYTgMbfDr0yBGA11/Cuhvlpf6RkbrmH5kazyNjp4TuaCINk7t6xy4PpbFk6ztDL3n7MFVPfdOEWk5q7j0AgsnM6hSFOS4cdZXEZZ9a+ZSWPaguu9aPin7NnpvD/QTn867RQXHjPYn1kV7k84eM2NNS8xsX6k3+YqwECg6SjlLfsmwZ/jhLPLFE5GBduWSusQ1s0a5/6mCfyx6s/025gsKzF9NyftzdlCvqSldgIszSmMD2aup6lUV/Wd1BmxL1PaaZoVaCPKcPSsgrVNQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=9zlg1X8VBPoexoYaVB5/LsJD8LoNgru946AudvRJm0Q=; b=WCSN+aqhDcBJNza13IgA/KMM14yS8B22yv1mfAsUXW7A588joI1gjpH9VLI2Qw5PKDC9nMRbprTELU7bkcl0hAd0MREClC3aFvBippm9SGtdtQ99HIx+yWmKz3u4jfbPxDBKKqRcCXDbCyqOGNiNy5ebgN4TTN0zBNZiknPWW+jG3CiNtbtjAWZUCksefeZMdnhnIBeiMe8nhQuhB3+DMkjQapTf2Cw9anPNqLlDFGLBwf9Zn/iVCFMmF6NzXTuMjAqA7C9NxjyD+nCCpNEnGOpOfwTzIoRYgbecn2GVPnbyHE2R+fcXhHouxPHfJ6UjMO5Nrx47XLRR6apSWVp+LA== Received: from CO2PR18CA0054.namprd18.prod.outlook.com (2603:10b6:104:2::22) by MW2PR12MB2394.namprd12.prod.outlook.com (2603:10b6:907:f::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.29; Wed, 2 Jun 2021 12:31:19 +0000 Received: from CO1NAM11FT022.eop-nam11.prod.protection.outlook.com (2603:10b6:104:2:cafe::e5) by CO2PR18CA0054.outlook.office365.com (2603:10b6:104:2::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.15 via Frontend Transport; Wed, 2 Jun 2021 12:31:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by CO1NAM11FT022.mail.protection.outlook.com (10.13.175.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4150.30 via Frontend Transport; Wed, 2 Jun 2021 12:31:18 +0000 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 12:31:18 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.13) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Jun 2021 12:31:15 +0000 From: Dmytro Linkin To: CC: , , , , , , , , Subject: [PATCH RESEND iproute2 net-next 3/4] devlink: Add port func rate support Date: Wed, 2 Jun 2021 15:31:04 +0300 Message-ID: <1622637065-30803-4-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622637065-30803-1-git-send-email-dlinkin@nvidia.com> References: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> <1622637065-30803-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c76969c6-a50b-40ca-e670-08d925c2529f X-MS-TrafficTypeDiagnostic: MW2PR12MB2394: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2089; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /FPBxNp71MAPgU0fcEnJMoL2kajr93XyR3plgn+3Pzcgp9+TON8mbq+gl78ZelBPodxSRyF4CvzT/XfN8i9Z4I2MU7Nw1XPEgU3jtTUj1gF1JzN03IQmvuIuxlJIXs65Tyecrpn9oh1bnbOfMFfxxiLQzTp9/evEX5SAvAmSRK6kn1yWeLMLquYfZI6+masLeB1qUd9uw0fpH0hMrHx/TIeOkzvhP1UmP+qsIvPzjiB2/81dm852MQZG/g4sgNnYVIqBpFiLCKuSr8mBNT13uKHS9+v1RPNF7z4em5+0Eox91t2CJRcfehXqwgxezC+Wuvogyt6ZHS+MjguUUaLw0puJcsvGE0VJnJu3tCXPtS2a6p7V1l1dYvE6KpVsc+CstLduHMwpcMSz/xdk73i9AtXJRmCH5iTpcvu+e9OCkX5V0fsGMqsbBOumapOYtGQC01GyMeHDysw2YSIpwNbybkx3pFyDdlycujkeiv26oUAK7hNrRyA7ofh+4XfKIazvoW7oUl2Z0U7zuHRIgz3uYJYhht2L7QOusj6/DhyjwCL/BmHqxkALmvTgpymZRtCi0n+ePfvAY/i/jueF2toapcpJxCVwDNaZisdiQJksAiixSwuqqd2d1GIE74M8Ye7kGy0ivJgbnXiLi41eMk6NtA== X-Forefront-Antispam-Report: CIP:216.228.112.36; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid05.nvidia.com; CAT:NONE; SFS:(4636009)(39860400002)(346002)(136003)(376002)(396003)(36840700001)(46966006)(186003)(6862004)(36756003)(4326008)(30864003)(7636003)(107886003)(356005)(83380400001)(82740400003)(5660300002)(316002)(36906005)(7696005)(26005)(54906003)(70586007)(36860700001)(37006003)(47076005)(2906002)(70206006)(86362001)(6200100001)(336012)(478600001)(6666004)(8936002)(426003)(82310400003)(7049001)(2616005)(8676002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 12:31:18.8680 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c76969c6-a50b-40ca-e670-08d925c2529f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.36]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT022.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR12MB2394 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Implement user commands to manage devlink port func rate objects. List all rate commands: $ devlink port func rate help or just $ devlink port func rate To list all OR particular rate object: $ devlink port func rate show pci/0000:03:00.0/some_group: type node pci/0000:03:00.0/0: type leaf pci/0000:03:00.0/1: type leaf $ devlink prot func rate show pci/0000:03:00.0/1 pci/0000:03:00.0/0: type leaf $ devlink prot func rate show pci/0000:03:00.0/some_group pci/0000:03:00.0/some_group: type node Rate object of type "leaf" created by it's driver where name is the name of corresponding devlink port. Rate object of type "node" represents rate group created by the user using commands: $ devlink port func rate add pci/0000:03:00.0/some_group or with defining tx rate limits $ devlink port func rate add pci/0000:03:00.0/some_group \ tx_shara 10kbit tx_max 100mbit NOTE: node name cannot be a decimal value because it conflicts with devlink port indexes. To delete node object: $ devlink port func rate del pci/0000:03:00.0/some_group Set rate limits of existing rate object: $ devlink prot func rate set pci/0000:03:00.0/0 \ tx_share 5MBps tx_max 25GBps $ devlink prot func rate set pci/0000:03:00.0/some_group \ tx_share 0 Both SET and ADD commands accept any units of rates defined in IEC 60027-2 standard. NOTE: rate value 0 means that rate is unlimited. Such value is also ommited in show command output. NOTE: In SHOW command output rate values will be printed with suffixes as well, but in JSON output they are always units of Bps. Set or unset parent of existing rate object: $ devlink prot func rate set pci/0000:03:00.0/0 parent some_group $ devlink port func rate set pci/0000:03:00.0/0 noparent NOTE: Setting parent to empty ("") name due to kernel logic means unset parent and shouldn't be used to avoid unexpected parent unsets. Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- devlink/devlink.c | 489 ++++++++++++++++++++++++++++++++++++++++++++++-- man/man8/devlink-port.8 | 8 + man/man8/devlink-rate.8 | 256 +++++++++++++++++++++++++ 3 files changed, 738 insertions(+), 15 deletions(-) create mode 100644 man/man8/devlink-rate.8 diff --git a/devlink/devlink.c b/devlink/devlink.c index f435fc8..202359e 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -286,6 +286,11 @@ static void ifname_map_free(struct ifname_map *ifname_map) #define DL_OPT_PORT_PFNUMBER BIT(43) #define DL_OPT_PORT_SFNUMBER BIT(44) #define DL_OPT_PORT_FUNCTION_STATE BIT(45) +#define DL_OPT_PORT_FN_RATE_TYPE BIT(46) +#define DL_OPT_PORT_FN_RATE_TX_SHARE BIT(47) +#define DL_OPT_PORT_FN_RATE_TX_MAX BIT(48) +#define DL_OPT_PORT_FN_RATE_NODE_NAME BIT(49) +#define DL_OPT_PORT_FN_RATE_PARENT BIT(50) struct dl_opts { uint64_t present; /* flags of present items */ @@ -340,6 +345,11 @@ struct dl_opts { uint16_t port_flavour; uint16_t port_pfnumber; uint8_t port_fn_state; + uint16_t rate_type; + uint64_t rate_tx_share; + uint64_t rate_tx_max; + char *rate_node_name; + const char *rate_parent_node; }; struct dl { @@ -1054,38 +1064,103 @@ static int dl_argv_handle_both(struct dl *dl, char **p_bus_name, return 0; } -static int __dl_argv_handle_region(char *str, char **p_bus_name, - char **p_dev_name, char **p_region) +static int __dl_argv_handle_name(char *str, char **p_bus_name, + char **p_dev_name, char **p_name) { char *handlestr; int err; - err = str_split_by_char(str, &handlestr, p_region, '/'); - if (err) { - pr_err("Region identification \"%s\" is invalid\n", str); + err = str_split_by_char(str, &handlestr, p_name, '/'); + if (err) return err; - } - err = str_split_by_char(handlestr, p_bus_name, p_dev_name, '/'); - if (err) { - pr_err("Region identification \"%s\" is invalid\n", str); - return err; - } - return 0; + + return str_split_by_char(handlestr, p_bus_name, p_dev_name, '/'); } static int dl_argv_handle_region(struct dl *dl, char **p_bus_name, - char **p_dev_name, char **p_region) + char **p_dev_name, char **p_region) { char *str = dl_argv_next(dl); int err; err = ident_str_validate(str, 2); if (err) { - pr_err("Expected \"bus_name/dev_name/region\" identification.\n"".\n"); + pr_err("Expected \"bus_name/dev_name/region\" identification.\n"); return err; } - return __dl_argv_handle_region(str, p_bus_name, p_dev_name, p_region); + err = __dl_argv_handle_name(str, p_bus_name, p_dev_name, p_region); + if (err) + pr_err("Region identification \"%s\" is invalid\n", str); + return err; +} + + +static int dl_argv_handle_rate_node(struct dl *dl, char **p_bus_name, + char **p_dev_name, char **p_node) +{ + char *str = dl_argv_next(dl); + int err; + + err = ident_str_validate(str, 2); + if (err) { + pr_err("Expected \"bus_name/dev_name/node\" identification.\n"); + return err; + } + + err = __dl_argv_handle_name(str, p_bus_name, p_dev_name, p_node); + if (err) { + pr_err("Node identification \"%s\" is invalid\n", str); + return err; + } + + if (!**p_node || strspn(*p_node, "0123456789") == strlen(*p_node)) { + err = -EINVAL; + pr_err("Node name cannot be a devlink port index or empty.\n"); + } + + return err; +} + +static int dl_argv_handle_rate(struct dl *dl, char **p_bus_name, + char **p_dev_name, uint32_t *p_port_index, + char **p_node_name, uint64_t *p_handle_bit) +{ + char *str = dl_argv_next(dl); + char *identifier; + int err; + + err = ident_str_validate(str, 2); + if (err) { + pr_err("Expected \"bus_name/dev_name/node\" or " + "\"bus_name/dev_name/port_index\" identification.\n"); + return err; + } + + err = __dl_argv_handle_name(str, p_bus_name, p_dev_name, &identifier); + if (err) { + pr_err("Identification \"%s\" is invalid\n", str); + return err; + } + + if (!*identifier) { + pr_err("Identifier cannot be empty"); + return -EINVAL; + } + + if (strspn(identifier, "0123456789") == strlen(identifier)) { + err = strtouint32_t(identifier, p_port_index); + if (err) { + pr_err("Port index \"%s\" is not a number" + " or not within range\n", identifier); + return err; + } + *p_handle_bit = DL_OPT_HANDLEP; + } else { + *p_handle_bit = DL_OPT_PORT_FN_RATE_NODE_NAME; + *p_node_name = identifier; + } + return 0; } static int dl_argv_uint64_t(struct dl *dl, uint64_t *p_val) @@ -1397,6 +1472,36 @@ static int port_fn_state_parse(const char *statestr, uint8_t *state) return 0; } +static int port_fn_rate_type_get(const char *typestr, uint16_t *type) +{ + if (!strcmp(typestr, "leaf")) + *type = DEVLINK_RATE_TYPE_LEAF; + else if (!strcmp(typestr, "node")) + *type = DEVLINK_RATE_TYPE_NODE; + else + return -EINVAL; + return 0; +} + +static int port_fn_rate_value_get(struct dl *dl, uint64_t *rate) +{ + const char *ratestr; + __u64 rate64; + int err; + + err = dl_argv_str(dl, &ratestr); + if (err) + return err; + err = get_rate64(&rate64, ratestr); + if (err) { + pr_err("Invalid rate value: \"%s\"\n", ratestr); + return -EINVAL; + } + + *rate = rate64; + return 0; +} + struct dl_args_metadata { uint64_t o_flag; char err_msg[DL_ARGS_REQUIRED_MAX_ERR_LEN]; @@ -1469,6 +1574,19 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required, return err; o_required &= ~(DL_OPT_HANDLE | DL_OPT_HANDLEP) | handle_bit; o_found |= handle_bit; + } else if (o_required & DL_OPT_HANDLEP && + o_required & DL_OPT_PORT_FN_RATE_NODE_NAME) { + uint64_t handle_bit; + + err = dl_argv_handle_rate(dl, &opts->bus_name, &opts->dev_name, + &opts->port_index, + &opts->rate_node_name, + &handle_bit); + if (err) + return err; + o_required &= ~(DL_OPT_HANDLEP | DL_OPT_PORT_FN_RATE_NODE_NAME) | + handle_bit; + o_found |= handle_bit; } else if (o_required & DL_OPT_HANDLE) { err = dl_argv_handle(dl, &opts->bus_name, &opts->dev_name); if (err) @@ -1487,6 +1605,13 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required, if (err) return err; o_found |= DL_OPT_HANDLE_REGION; + } else if (o_required & DL_OPT_PORT_FN_RATE_NODE_NAME) { + err = dl_argv_handle_rate_node(dl, &opts->bus_name, + &opts->dev_name, + &opts->rate_node_name); + if (err) + return err; + o_found |= DL_OPT_PORT_FN_RATE_NODE_NAME; } while (dl_argc(dl)) { @@ -1884,6 +2009,44 @@ static int dl_argv_parse(struct dl *dl, uint64_t o_required, if (err) return err; o_found |= DL_OPT_PORT_SFNUMBER; + } else if (dl_argv_match(dl, "type") && + (o_all & DL_OPT_PORT_FN_RATE_TYPE)) { + const char *typestr; + + dl_arg_inc(dl); + err = dl_argv_str(dl, &typestr); + if (err) + return err; + err = port_fn_rate_type_get(typestr, &opts->rate_type); + if (err) + return err; + o_found |= DL_OPT_PORT_FN_RATE_TYPE; + } else if (dl_argv_match(dl, "tx_share") && + (o_all & DL_OPT_PORT_FN_RATE_TX_SHARE)) { + dl_arg_inc(dl); + err = port_fn_rate_value_get(dl, &opts->rate_tx_share); + if (err) + return err; + o_found |= DL_OPT_PORT_FN_RATE_TX_SHARE; + } else if (dl_argv_match(dl, "tx_max") && + (o_all & DL_OPT_PORT_FN_RATE_TX_MAX)) { + dl_arg_inc(dl); + err = port_fn_rate_value_get(dl, &opts->rate_tx_max); + if (err) + return err; + o_found |= DL_OPT_PORT_FN_RATE_TX_MAX; + } else if (dl_argv_match(dl, "parent") && + (o_all & DL_OPT_PORT_FN_RATE_PARENT)) { + dl_arg_inc(dl); + err = dl_argv_str(dl, &opts->rate_parent_node); + if (err) + return err; + o_found |= DL_OPT_PORT_FN_RATE_PARENT; + } else if (dl_argv_match(dl, "noparent") && + (o_all & DL_OPT_PORT_FN_RATE_PARENT)) { + dl_arg_inc(dl); + opts->rate_parent_node = ""; + o_found |= DL_OPT_PORT_FN_RATE_PARENT; } else { pr_err("Unknown option \"%s\"\n", dl_argv(dl)); return -EINVAL; @@ -1956,6 +2119,11 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl) mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, opts->dev_name); mnl_attr_put_strz(nlh, DEVLINK_ATTR_REGION_NAME, opts->region_name); + } else if (opts->present & DL_OPT_PORT_FN_RATE_NODE_NAME) { + mnl_attr_put_strz(nlh, DEVLINK_ATTR_BUS_NAME, opts->bus_name); + mnl_attr_put_strz(nlh, DEVLINK_ATTR_DEV_NAME, opts->dev_name); + mnl_attr_put_strz(nlh, DEVLINK_ATTR_RATE_NODE_NAME, + opts->rate_node_name); } if (opts->present & DL_OPT_PORT_TYPE) mnl_attr_put_u16(nlh, DEVLINK_ATTR_PORT_TYPE, @@ -2077,6 +2245,18 @@ static void dl_opts_put(struct nlmsghdr *nlh, struct dl *dl) mnl_attr_put_u16(nlh, DEVLINK_ATTR_PORT_PCI_PF_NUMBER, opts->port_pfnumber); if (opts->present & DL_OPT_PORT_SFNUMBER) mnl_attr_put_u32(nlh, DEVLINK_ATTR_PORT_PCI_SF_NUMBER, opts->port_sfnumber); + if (opts->present & DL_OPT_PORT_FN_RATE_TYPE) + mnl_attr_put_u16(nlh, DEVLINK_ATTR_RATE_TYPE, + opts->rate_type); + if (opts->present & DL_OPT_PORT_FN_RATE_TX_SHARE) + mnl_attr_put_u64(nlh, DEVLINK_ATTR_RATE_TX_SHARE, + opts->rate_tx_share); + if (opts->present & DL_OPT_PORT_FN_RATE_TX_MAX) + mnl_attr_put_u64(nlh, DEVLINK_ATTR_RATE_TX_MAX, + opts->rate_tx_max); + if (opts->present & DL_OPT_PORT_FN_RATE_PARENT) + mnl_attr_put_strz(nlh, DEVLINK_ATTR_RATE_PARENT_NODE_NAME, + opts->rate_parent_node); } static int dl_argv_parse_put(struct nlmsghdr *nlh, struct dl *dl, @@ -3790,6 +3970,7 @@ static void cmd_port_help(void) pr_err(" devlink port split DEV/PORT_INDEX count COUNT\n"); pr_err(" devlink port unsplit DEV/PORT_INDEX\n"); pr_err(" devlink port function set DEV/PORT_INDEX [ hw_addr ADDR ] [ state STATE ]\n"); + pr_err(" devlink port function rate { help | show | add | del | set }\n"); pr_err(" devlink port param set DEV/PORT_INDEX name PARAMETER value VALUE cmode { permanent | driverinit | runtime }\n"); pr_err(" devlink port param show [DEV/PORT_INDEX name PARAMETER]\n"); pr_err(" devlink port health show [ DEV/PORT_INDEX reporter REPORTER_NAME ]\n"); @@ -4083,6 +4264,7 @@ static int cmd_port_param_show(struct dl *dl) static void cmd_port_function_help(void) { pr_err("Usage: devlink port function set DEV/PORT_INDEX [ hw_addr ADDR ] [ state STATE ]\n"); + pr_err(" devlink port function rate { help | show | add | del | set }\n"); } static int cmd_port_function_set(struct dl *dl) @@ -4304,6 +4486,280 @@ static int cmd_port_param(struct dl *dl) return -ENOENT; } +static void +pr_out_port_rate_handle_start(struct dl *dl, struct nlattr **tb, bool try_nice) +{ + const char *bus_name; + const char *dev_name; + const char *node_name; + static char buf[64]; + + bus_name = mnl_attr_get_str(tb[DEVLINK_ATTR_BUS_NAME]); + dev_name = mnl_attr_get_str(tb[DEVLINK_ATTR_DEV_NAME]); + node_name = mnl_attr_get_str(tb[DEVLINK_ATTR_RATE_NODE_NAME]); + sprintf(buf, "%s/%s/%s", bus_name, dev_name, node_name); + if (dl->json_output) + open_json_object(buf); + else + pr_out("%s:", buf); +} + +static char *port_rate_type_name(uint16_t type) +{ + switch (type) { + case DEVLINK_RATE_TYPE_LEAF: + return "leaf"; + case DEVLINK_RATE_TYPE_NODE: + return "node"; + default: + return ""; + } +} + +static void pr_out_port_fn_rate(struct dl *dl, struct nlattr **tb) +{ + + if (!tb[DEVLINK_ATTR_RATE_NODE_NAME]) + pr_out_port_handle_start(dl, tb, false); + else + pr_out_port_rate_handle_start(dl, tb, false); + check_indent_newline(dl); + + if (tb[DEVLINK_ATTR_RATE_TYPE]) { + uint16_t type = + mnl_attr_get_u16(tb[DEVLINK_ATTR_RATE_TYPE]); + + print_string(PRINT_ANY, "type", "type %s", + port_rate_type_name(type)); + } + if (tb[DEVLINK_ATTR_RATE_TX_SHARE]) { + uint64_t rate = + mnl_attr_get_u64(tb[DEVLINK_ATTR_RATE_TX_SHARE]); + + if (rate) + print_rate(false, PRINT_ANY, "tx_share", + " tx_share %s", rate); + } + if (tb[DEVLINK_ATTR_RATE_TX_MAX]) { + uint64_t rate = + mnl_attr_get_u64(tb[DEVLINK_ATTR_RATE_TX_MAX]); + + if (rate) + print_rate(false, PRINT_ANY, "tx_max", + " tx_max %s", rate); + } + if (tb[DEVLINK_ATTR_RATE_PARENT_NODE_NAME]) { + const char *parent = + mnl_attr_get_str(tb[DEVLINK_ATTR_RATE_PARENT_NODE_NAME]); + + print_string(PRINT_ANY, "parent", " parent %s", parent); + } + + pr_out_port_handle_end(dl); +} + +static int cmd_port_fn_rate_show_cb(const struct nlmsghdr *nlh, void *data) +{ + struct dl *dl = data; + struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {}; + struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh); + + mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb); + if ((!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] || + !tb[DEVLINK_ATTR_PORT_INDEX]) && + !tb[DEVLINK_ATTR_RATE_NODE_NAME]) { + return MNL_CB_ERROR; + } + pr_out_port_fn_rate(dl, tb); + return MNL_CB_OK; +} + +static void cmd_port_fn_rate_help(void) +{ + pr_err("Usage: devlink port function rate help\n"); + pr_err(" devlink port function rate show [ DEV/{ PORT_INDEX | NODE_NAME } ]\n"); + pr_err(" devlink port function rate add DEV/NODE_NAME\n"); + pr_err(" [ tx_share VAL ][ tx_max VAL ][ { parent NODE_NAME | noparent } ]\n"); + pr_err(" devlink port function rate del DEV/NODE_NAME\n"); + pr_err(" devlink port function rate set DEV/{ PORT_INDEX | NODE_NAME }\n"); + pr_err(" [ tx_share VAL ][ tx_max VAL ][ { parent NODE_NAME | noparent } ]\n\n"); + pr_err(" VAL - float or integer value in units of bits or bytes per second (bit|bps)\n"); + pr_err(" and SI (k-, m-, g-, t-) or IEC (ki-, mi-, gi-, ti-) case-insensitive prefix.\n"); + pr_err(" Bare number, means bits per second, is possible.\n\n"); + pr_err(" For details refer to devlink-rate(8) man page.\n"); +} + +static int cmd_port_fn_rate_show(struct dl *dl) +{ + struct nlmsghdr *nlh; + uint16_t flags = NLM_F_REQUEST | NLM_F_ACK; + int err; + + if (dl_argc(dl) == 0) + flags |= NLM_F_DUMP; + + nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_RATE_GET, flags); + + if (dl_argc(dl) > 0) { + err = dl_argv_parse_put(nlh, dl, DL_OPT_HANDLEP | + DL_OPT_PORT_FN_RATE_NODE_NAME, 0); + if (err) + return err; + } + + pr_out_section_start(dl, "rate"); + err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, cmd_port_fn_rate_show_cb, dl); + pr_out_section_end(dl); + return err; +} + +static int port_fn_check_tx_rates(uint64_t min_rate, uint64_t max_rate) +{ + if (max_rate && min_rate > max_rate) { + pr_err("Invalid. Expected tx_share <= tx_max or tx_share == 0.\n"); + return -EINVAL; + } + return 0; +} + +static int port_fn_get_and_check_tx_rates(struct dl_opts *reply, + struct dl_opts *request) +{ + uint64_t min = reply->rate_tx_share; + uint64_t max = reply->rate_tx_max; + + if (request->present & DL_OPT_PORT_FN_RATE_TX_SHARE) + return port_fn_check_tx_rates(request->rate_tx_share, max); + return port_fn_check_tx_rates(min, request->rate_tx_max); +} + +static int cmd_port_fn_rate_add(struct dl *dl) +{ + struct nlmsghdr *nlh; + int err; + + nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_RATE_NEW, + NLM_F_REQUEST | NLM_F_ACK); + err = dl_argv_parse_put(nlh, dl, DL_OPT_PORT_FN_RATE_NODE_NAME, + DL_OPT_PORT_FN_RATE_TX_SHARE | + DL_OPT_PORT_FN_RATE_TX_MAX); + if (err) + return err; + + if ((dl->opts.present & DL_OPT_PORT_FN_RATE_TX_SHARE) && + (dl->opts.present & DL_OPT_PORT_FN_RATE_TX_MAX)) { + err = port_fn_check_tx_rates(dl->opts.rate_tx_share, + dl->opts.rate_tx_max); + if (err) + return err; + } + + return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL); +} + +static int cmd_port_fn_rate_del(struct dl *dl) +{ + struct nlmsghdr *nlh; + int err; + + nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_RATE_DEL, + NLM_F_REQUEST | NLM_F_ACK); + err = dl_argv_parse_put(nlh, dl, DL_OPT_PORT_FN_RATE_NODE_NAME, 0); + if (err) + return err; + + return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL); +} + +static int port_fn_get_rates_cb(const struct nlmsghdr *nlh, void *data) +{ + struct dl_opts *opts = data; + struct nlattr *tb[DEVLINK_ATTR_MAX + 1] = {}; + struct genlmsghdr *genl = mnl_nlmsg_get_payload(nlh); + + mnl_attr_parse(nlh, sizeof(*genl), attr_cb, tb); + if ((!tb[DEVLINK_ATTR_BUS_NAME] || !tb[DEVLINK_ATTR_DEV_NAME] || + !tb[DEVLINK_ATTR_PORT_INDEX]) && + !tb[DEVLINK_ATTR_RATE_NODE_NAME]) { + return MNL_CB_ERROR; + } + + if (tb[DEVLINK_ATTR_RATE_TX_SHARE]) + opts->rate_tx_share = + mnl_attr_get_u64(tb[DEVLINK_ATTR_RATE_TX_SHARE]); + if (tb[DEVLINK_ATTR_RATE_TX_MAX]) + opts->rate_tx_max = + mnl_attr_get_u64(tb[DEVLINK_ATTR_RATE_TX_MAX]); + return MNL_CB_OK; +} + +static int cmd_port_fn_rate_set(struct dl *dl) +{ + struct dl_opts tmp_opts = {0}; + struct nlmsghdr *nlh; + int err; + + err = dl_argv_parse(dl, DL_OPT_HANDLEP | + DL_OPT_PORT_FN_RATE_NODE_NAME, + DL_OPT_PORT_FN_RATE_TX_SHARE | + DL_OPT_PORT_FN_RATE_TX_MAX | + DL_OPT_PORT_FN_RATE_PARENT); + if (err) + return err; + + if ((dl->opts.present & DL_OPT_PORT_FN_RATE_TX_SHARE) && + (dl->opts.present & DL_OPT_PORT_FN_RATE_TX_MAX)) { + err = port_fn_check_tx_rates(dl->opts.rate_tx_share, + dl->opts.rate_tx_max); + if (err) + return err; + } else if (dl->opts.present & + (DL_OPT_PORT_FN_RATE_TX_SHARE | DL_OPT_PORT_FN_RATE_TX_MAX)) { + nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_RATE_GET, + NLM_F_REQUEST | NLM_F_ACK); + tmp_opts = dl->opts; + dl->opts.present &= ~(DL_OPT_PORT_FN_RATE_TX_SHARE | + DL_OPT_PORT_FN_RATE_TX_MAX | + DL_OPT_PORT_FN_RATE_PARENT); + dl_opts_put(nlh, dl); + err = mnlu_gen_socket_sndrcv(&dl->nlg, nlh, port_fn_get_rates_cb, + &dl->opts); + if (err) + return err; + err = port_fn_get_and_check_tx_rates(&dl->opts, &tmp_opts); + if (err) + return err; + dl->opts = tmp_opts; + } + + nlh = mnlu_gen_socket_cmd_prepare(&dl->nlg, DEVLINK_CMD_RATE_SET, + NLM_F_REQUEST | NLM_F_ACK); + dl_opts_put(nlh, dl); + return mnlu_gen_socket_sndrcv(&dl->nlg, nlh, NULL, NULL); +} + +static int cmd_port_function_rate(struct dl *dl) +{ + if (dl_argv_match(dl, "help")) { + cmd_port_fn_rate_help(); + return 0; + } else if (dl_argv_match(dl, "show") || dl_no_arg(dl)) { + dl_arg_inc(dl); + return cmd_port_fn_rate_show(dl); + } else if (dl_argv_match(dl, "add")) { + dl_arg_inc(dl); + return cmd_port_fn_rate_add(dl); + } else if (dl_argv_match(dl, "del")) { + dl_arg_inc(dl); + return cmd_port_fn_rate_del(dl); + } else if (dl_argv_match(dl, "set")) { + dl_arg_inc(dl); + return cmd_port_fn_rate_set(dl); + } + pr_err("Command \"%s\" not found\n", dl_argv(dl)); + return -ENOENT; +} + static int cmd_port_function(struct dl *dl) { if (dl_argv_match(dl, "help") || dl_no_arg(dl)) { @@ -4312,6 +4768,9 @@ static int cmd_port_function(struct dl *dl) } else if (dl_argv_match(dl, "set")) { dl_arg_inc(dl); return cmd_port_function_set(dl); + } else if (dl_argv_match(dl, "rate")) { + dl_arg_inc(dl); + return cmd_port_function_rate(dl); } pr_err("Command \"%s\" not found\n", dl_argv(dl)); return -ENOENT; diff --git a/man/man8/devlink-port.8 b/man/man8/devlink-port.8 index 563c583..616f094 100644 --- a/man/man8/devlink-port.8 +++ b/man/man8/devlink-port.8 @@ -71,6 +71,10 @@ devlink-port \- devlink port configuration .RI "STATE }" .ti -8 +.BR "devlink port function rate " +.RI "{ " show " | " set " | " add " | " del " | " help " }" + +.ti -8 .B devlink dev param set .I DEV/PORT_INDEX .B name @@ -240,6 +244,10 @@ Configuration mode in which the new value is set. Specify parameter name to show. If this argument, as well as port index, are omitted - all parameters supported by devlink device ports are listed. +.SS devlink port function rate - manage devlink rate objects +Is an alias for +.BR devlink-rate (8). + .SH "EXAMPLES" .PP devlink port show diff --git a/man/man8/devlink-rate.8 b/man/man8/devlink-rate.8 new file mode 100644 index 0000000..a6e28ac --- /dev/null +++ b/man/man8/devlink-rate.8 @@ -0,0 +1,256 @@ +.TH DEVLINK\-RATE 8 "12 Mar 2021" "iproute2" "Linux" +.SH NAME +devlink-rate \- devlink rate management +.SH SYNOPSIS +.sp +.ad l +.in +8 +.ti -8 +.B devlink +.RI "[ " OPTIONS " ]" +.B port function rate +.RI " { " COMMAND " | " +.BR help " }" +.sp + +.ti -8 +.IR OPTIONS " := { " +.BR -j [ \fIson "] | " -p [ \fIretty "] }" + +.ti -8 +.B devlink port function rate show +.RI "[ { " DEV/PORT_INDEX " | " DEV/NODE_NAME " } ]" + +.ti -8 +.B devlink port function rate set +.RI "{ " DEV/PORT_INDEX " | " DEV/NODE_NAME " } " +.RB [ " tx_share \fIVALUE " ] +.RB [ " tx_max \fIVALUE " ] +.RB "[ {" " parent \fINODE_NAME " | " noparent " "} ]" + +.ti -8 +.BI "devlink port function rate add " DEV/NODE_NAME +.RB [ " tx_share \fIVALUE " ] +.RB [ " tx_max \fIVALUE " ] +.RB "[ {" " parent \fINODE_NAME " | " noparent " "} ]" + +.ti -8 +.BI "devlink port function rate del " DEV/NODE_NAME + +.ti -8 +.B devlink port function rate help + +.SH "DESCRIPTION" + +.SS devlink port function rate show - display rate objects. +Displays specified rate object or, if not specified, all rate objects. Rate +object can be presented by one of the two types: +.TP 8 +.B leaf +Represents a single devlink port; created/destroyed by the driver and bound to +the devlink port. As example, some driver may create leaf rate object for every +devlink port associated with VF. Since leaf have 1to1 mapping to it's devlink +port, in user space it is referred as corresponding devlink port +\fIDEV/PORT_INDEX\fR; +.TP 8 +.B node +Represents a group of rate objects; created/deleted by the user (see command +below) and bound to the devlink device rather then to the devlink port. In +userspace it is referred as \fIDEV/NODE_NAME\fR, where node name can be any, +except decimal number, to avoid collisions with leafs. +.PP +Command output show rate object identifier, it's type and rate values along with +parent node name. Rate values printed in SI units which are more suitable to +represent specific value. JSON (\fB-j\fR) output always print rate values in +bytes per second. Zero rate values means "unlimited" rates and ommited in +output, as well as parent node name. + +.SS devlink port function rate set - set rate object parameters. +Allows set rate object's parameters. If any parameter specified multiple times +the last occurrence is used. +.PP +.I DEV/PORT_INDEX +- specifies devlink leaf rate object. +.br +.I DEV/NODE_NAME +- specifies devlink node rate object. +.PP +.BI tx_share " VALUE" +- specifies minimal tx rate value shared among all rate objects. If rate object +is a part of some rate group, then this value shared with rate objects of this +rate group. +.PP +.BI tx_max " VALUE" +- specifies maximum tx rate value. +.TP 8 +.I VALUE +These parameter accept a floating point number, possibly followed by either a +unit. +.RS +.TP +bit or a bare number +Bits per second +.TP +kbit +Kilobits per second +.TP +mbit +Megabits per second +.TP +gbit +Gigabits per second +.TP +tbit +Terabits per second +.TP +bps +Bytes per second +.TP +kbps +Kilobytes per second +.TP +mbps +Megabytes per second +.TP +gbps +Gigabytes per second +.TP +tbps +Terabytes per second +.RE +.PP +.BI parent " NODE_NAME \fR| " noparent +- set rate object parent to existing node with name \fINODE_NAME\fR or unset +parent. Rate limits of the parent node applied to all it's children. Actual +behaviour is details of driver's implementation. Setting parent to empty ("") +name due to the kernel logic threated as parent unset. + +.SS devlink port function rate add - create node rate object with specified parameters. +Creates rate object of type node and sets parameters. Parameters same as for the +"set" command. +.PP +.I DEV/NODE_NAME +- specifies the devlink node rate object to create. + +.SS devlink port function rate del - delete node rate object +Delete specified devlink node rate object. Node can't be deleted if there is any +child, user must explicitly unset the parent. +.PP +.I DEV/NODE_NAME +- specifies devlink node rate object to delete. + +.SS devlink port function rate help - display usage information +Display devlink rate usage information + +.SH "EXAMPLES" + +.PP +\fB*\fR Display all rate objects: +.RS 4 +.PP +# devlink port function rate show +.br +pci/0000:03:00.0/1 type leaf parent some_group +.br +pci/0000:03:00.0/2 type leaf tx_share 12Mbit +.br +pci/0000:03:00.0/some_group type node tx_share 1Gbps tx_max 5Gbps +.RE + +.PP +\fB*\fR Display leaf rate object bound to the 1st devlink port of the +pci/0000:03:00.0 device: +.RS 4 +.PP +# devlink port function rate show pci/0000:03:00.0/1 +.br +pci/0000:03:00.0/1 type leaf +.br +.RE + +.PP +\fB*\fR Display node rate object with name some_group of the pci/0000:03:00.0 device: +.RS 4 +.PP +# devlink port function rate show pci/0000:03:00.0/some_group +.br +pci/0000:03:00.0/some_group type node +.br +.RE + +.PP +\fB*\fR Display pci/0000:03:00.0/2 leaf rate object as pretty JSON output: +.RS 4 +.PP +# devlink -jp port function rate show pci/0000:03:00.0/2 +.br +{ +.br + "rate": { +.br + "pci/0000:03:00.0/2": { +.br + "type": "leaf", +.br + "tx_share": 1500000 +.br + } +.br + } +.br +} +.RE + +.PP +\fB*\fR Create node rate object with name "1st_group" on pci/0000:03:00.0 device: +.RS 4 +.PP +# devlink port function rate add pci/0000:03:00.0/1st_group +.RE + +.PP +\fB*\fR Create node rate object with specified parameters: +.RS 4 +.PP +# devlink port function rate add pci/0000:03:00.0/2nd_group \\ +.br + tx_share 10Mbit tx_max 30Mbit parent 1st_group +.RE + +.PP +\fB*\fR Set parameters to the specified leaf rate object: +.RS 4 +.PP +# devlink port function rate set pci/0000:03:00.0/1 \\ +.br + tx_share 2Mbit tx_max 10Mbit +.RE + +.PP +\fB*\fR Set leaf's parent to "1st_group": +.RS 4 +.PP +# devlink port function rate set pci/0000:03:00.0/1 parent 1st_group +.RE + +.PP +\fB*\fR Unset leaf's parent: +.RS 4 +.PP +# devlink port function rate set pci/0000:03:00.0/1 noparent +.RE + +.PP +\fB*\fR Delete node rate object: +.RS 4 +.PP +# devlink port function rate del pci/0000:03:00.0/2nd_group +.RE + +.SH SEE ALSO +.BR devlink (8), +.BR devlink-port (8) +.br + +.SH AUTHOR +Dmytro Linkin From patchwork Wed Jun 2 12:31:05 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 453917 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 796F6C47083 for ; Wed, 2 Jun 2021 12:31:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5FDF661396 for ; Wed, 2 Jun 2021 12:31:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229724AbhFBMdV (ORCPT ); Wed, 2 Jun 2021 08:33:21 -0400 Received: from mail-mw2nam10on2087.outbound.protection.outlook.com ([40.107.94.87]:37665 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230036AbhFBMdH (ORCPT ); Wed, 2 Jun 2021 08:33:07 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G5D4BfWCKr0cNzqDTFQUSx0VKe4yZbh6/NxIwKK3Aa6kTvP8jb2B3Uoh2c6iIGYgKVFKfaZbMovpHMyRhWzfCPe67lQl3D0J60BDKXGg2qjdz4UYj0WGnAw78mQJZrphubBSgO3MAqaaBVZZ7u7PSrDLp6e9dg3Uutv0l8uPx35FW1KLTrfUBN+MGOPbGFHWIyK7w5aAuT2HvJwV/HcxrGjG5fd5uYlM/QnnTwDzvkHIh7T+O644r6BfTD6reZwF8My0ND/NunLQlX8G4Buc3M/QxeZQhM+zdi7CC2s0yV3t+K0No8SocF+uCcIkE4aBYrXS0kz2CdCCm5SEBolRdg== 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=fCDmQqOIV8z4zUqk/o5vxPlq1Itwgnzcxh++1RPBlEU=; b=eyrSuQ14eD82p5XIVetjO7eF8TTAY5jDEVjzpDnCku/DOiP4G/JvWTSjLkeV9q8qA0/wkrgsCk5fKqapnyeZO/BVtsES/z3y1Awzzf5lL9E8GEQ7DzN6S7WbaGs64buoT7391YTNF2QNoYDldG62RHSeF+qHV/ruyFvNRztOROJEDAN3OQLNhsLuCg7iN9Ju1KDY0TTiUw25sefGkGS5OTBrdQRaWzV7yVryYb9U5UAc7HbC/cO7YE3yROV4gujEYSdQrG1e6gJVAvqSe/LCOF+KoOoZVke+7xNaHJ1gEheIQwtmvHlYKr2GSOp20MCG9Wcr6gPwW3JitLcQXwSPZA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=davemloft.net smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fCDmQqOIV8z4zUqk/o5vxPlq1Itwgnzcxh++1RPBlEU=; b=tTXcwpzO+8wG2sR7I7iVbqaNpmqbXuSBlJFU8gxxQLAp3m9hMVb/02FDa9r/bGYkqVmxS9UK7NHVYEAboSRWD8T9qF+x0vfG2MF12olHv4OBJczYgtHz9UiN00ClCYuTELMVxRttTcCWWh259ZzB3z0Ekd/HBLGQgE8rqMWqLpVtoqakIU7MP9tgmeaUkF4th2tnVUQjGix5pX0pySUDL6VfWCCv/7sTXe2f9t1seuLcsjztqSs6NXaGGh3J/XIF0T3ZWzGPhG2VbaPI4iqlCWNSPrW7uqqqSYF7iOvcSB4X0DR8j8lRduRPSl6/J6fqa5DcqpleaiAdUEJBZNqwnA== Received: from MW4PR03CA0292.namprd03.prod.outlook.com (2603:10b6:303:b5::27) by MN2PR12MB4606.namprd12.prod.outlook.com (2603:10b6:208:3f::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.21; Wed, 2 Jun 2021 12:31:22 +0000 Received: from CO1NAM11FT018.eop-nam11.prod.protection.outlook.com (2603:10b6:303:b5:cafe::53) by MW4PR03CA0292.outlook.office365.com (2603:10b6:303:b5::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.21 via Frontend Transport; Wed, 2 Jun 2021 12:31:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; davemloft.net; dkim=none (message not signed) header.d=none; davemloft.net; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by CO1NAM11FT018.mail.protection.outlook.com (10.13.175.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4150.30 via Frontend Transport; Wed, 2 Jun 2021 12:31:21 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 12:31:21 +0000 Received: from HQMAIL107.nvidia.com (172.20.187.13) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 12:31:20 +0000 Received: from vdi.nvidia.com (172.20.187.6) by mail.nvidia.com (172.20.187.13) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Jun 2021 12:31:18 +0000 From: Dmytro Linkin To: CC: , , , , , , , , Subject: [PATCH RESEND iproute2 net-next 4/4] devlink: Add ISO/IEC switch Date: Wed, 2 Jun 2021 15:31:05 +0300 Message-ID: <1622637065-30803-5-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622637065-30803-1-git-send-email-dlinkin@nvidia.com> References: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> <1622637065-30803-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1ba7fc85-5ee3-400e-4bf9-08d925c2547b X-MS-TrafficTypeDiagnostic: MN2PR12MB4606: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:626; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NP0VkLVpjtV60EYsBRAWXgVoL7OBD00moQ81DTLFYJkTj2RhR4xPr6HcHyUGW2uR9e52poBA7h0FM1uCEBxx8247oQ6cs0VbhTTav+SuF/fz4t97C++mbwat7SBu9vNICmPoQZZHhxL1ZPssrA3N3ruT/hzXaee7J6VTF3xKzQp04wp6n2HIcIHG9sTMauLcdmNgRD80oH5SgURqJujGGi/kPAPEpSjtbuIc1fOYAiUYqptKL4229pAd7ingn4trjlUk5ND1jlu107ND/vq473PUUDCiwTYbKy4hu11zLn94hmFQQYW8Lgm5tIjVUZg3pOluc4BbQ52n8hrHn8c6g3p2xtYvgCta/+xDjijbuqG4cuWqZPItIszgr8Uv3/hJZmTOgGN5amskOAn4Ew2Yv6d17lKoNhCznQslppleXZQdqiLCAGh0U6V4XTCrSzpmifEt8SlHpRmyduOuYn4I8XmPrnouWIVZKqNG0VpQpEpyRI/oWIo/N1oXkUj9118tnBCbN5h78EPtQ0l0eDWyXCUnR3GEUGUwI8ywS8JxE7SjWur7MD+cCzLR9SBjh72TyxcanTunE8Lru7iADcj7/APkDob8Nk5mBkgU59OQRqSWYjBMO1gzrEfXP0Dx9lEFNDaLaRRtqGv77L7l3qwH5caba3dWDdx4ZEQAAct3S5Q= X-Forefront-Antispam-Report: CIP:216.228.112.36; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid05.nvidia.com; CAT:NONE; SFS:(4636009)(136003)(346002)(376002)(39860400002)(396003)(46966006)(36840700001)(82310400003)(36906005)(8676002)(54906003)(7049001)(4326008)(8936002)(107886003)(5660300002)(6862004)(7636003)(356005)(6666004)(37006003)(82740400003)(478600001)(316002)(83380400001)(336012)(7696005)(2616005)(426003)(70586007)(26005)(70206006)(2906002)(47076005)(6200100001)(36860700001)(36756003)(86362001)(186003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 12:31:21.9816 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 1ba7fc85-5ee3-400e-4bf9-08d925c2547b X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.36]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT018.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4606 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org Add -i/--iec switch to print rate values using binary prefixes. Update devlink(8) and devlink-rate(8) pages. Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- devlink/devlink.c | 12 +++++++++--- man/man8/devlink-rate.8 | 24 +++++++++++++++++++----- man/man8/devlink.8 | 4 ++++ 3 files changed, 32 insertions(+), 8 deletions(-) diff --git a/devlink/devlink.c b/devlink/devlink.c index 202359e..0347ac8 100644 --- a/devlink/devlink.c +++ b/devlink/devlink.c @@ -71,6 +71,8 @@ static bool g_indent_newline; #define INDENT_STR_MAXLEN 32 static char g_indent_str[INDENT_STR_MAXLEN + 1] = ""; +static bool use_iec = false; + static void __attribute__((format(printf, 1, 2))) pr_err(const char *fmt, ...) { @@ -4537,7 +4539,7 @@ static void pr_out_port_fn_rate(struct dl *dl, struct nlattr **tb) mnl_attr_get_u64(tb[DEVLINK_ATTR_RATE_TX_SHARE]); if (rate) - print_rate(false, PRINT_ANY, "tx_share", + print_rate(use_iec, PRINT_ANY, "tx_share", " tx_share %s", rate); } if (tb[DEVLINK_ATTR_RATE_TX_MAX]) { @@ -4545,7 +4547,7 @@ static void pr_out_port_fn_rate(struct dl *dl, struct nlattr **tb) mnl_attr_get_u64(tb[DEVLINK_ATTR_RATE_TX_MAX]); if (rate) - print_rate(false, PRINT_ANY, "tx_max", + print_rate(use_iec, PRINT_ANY, "tx_max", " tx_max %s", rate); } if (tb[DEVLINK_ATTR_RATE_PARENT_NODE_NAME]) { @@ -9066,6 +9068,7 @@ int main(int argc, char **argv) { "verbose", no_argument, NULL, 'v' }, { "statistics", no_argument, NULL, 's' }, { "Netns", required_argument, NULL, 'N' }, + { "iec", no_argument, NULL, 'i' }, { NULL, 0, NULL, 0 } }; const char *batch_file = NULL; @@ -9081,7 +9084,7 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - while ((opt = getopt_long(argc, argv, "Vfb:njpvsN:", + while ((opt = getopt_long(argc, argv, "Vfb:njpvsN:i", long_options, NULL)) >= 0) { switch (opt) { @@ -9116,6 +9119,9 @@ int main(int argc, char **argv) goto dl_free; } break; + case 'i': + use_iec = true; + break; default: pr_err("Unknown option.\n"); help(); diff --git a/man/man8/devlink-rate.8 b/man/man8/devlink-rate.8 index a6e28ac..76c65a3 100644 --- a/man/man8/devlink-rate.8 +++ b/man/man8/devlink-rate.8 @@ -15,7 +15,7 @@ devlink-rate \- devlink rate management .ti -8 .IR OPTIONS " := { " -.BR -j [ \fIson "] | " -p [ \fIretty "] }" +.BR -j [ \fIson "] | " -p [ \fIretty "] | " -i [ \fIec "] }" .ti -8 .B devlink port function rate show @@ -61,9 +61,10 @@ except decimal number, to avoid collisions with leafs. .PP Command output show rate object identifier, it's type and rate values along with parent node name. Rate values printed in SI units which are more suitable to -represent specific value. JSON (\fB-j\fR) output always print rate values in -bytes per second. Zero rate values means "unlimited" rates and ommited in -output, as well as parent node name. +represent specific value. To print values in IEC units \fB-i\fR switch is +used. JSON (\fB-j\fR) output always print rate values in bytes per second. Zero +rate values means "unlimited" rates and ommited in output, as well as parent +node name. .SS devlink port function rate set - set rate object parameters. Allows set rate object's parameters. If any parameter specified multiple times @@ -85,7 +86,7 @@ rate group. .TP 8 .I VALUE These parameter accept a floating point number, possibly followed by either a -unit. +unit (both SI and IEC units supported). .RS .TP bit or a bare number @@ -117,6 +118,9 @@ Gigabytes per second .TP tbps Terabytes per second +.P +To specify in IEC units, replace the SI prefix (k-, m-, g-, t-) with IEC prefix +(ki-, mi-, gi- and ti-) respectively. Input is case-insensitive. .RE .PP .BI parent " NODE_NAME \fR| " noparent @@ -169,6 +173,16 @@ pci/0000:03:00.0/1 type leaf .RE .PP +\fB*\fR Display leaf rate object rate values using IEC units: +.RS 4 +.PP +# devlink -i port function rate show pci/0000:03:00.0/2 +.br +pci/0000:03:00.0/2 type leaf 11718Kibit +.br +.RE + +.PP \fB*\fR Display node rate object with name some_group of the pci/0000:03:00.0 device: .RS 4 .PP diff --git a/man/man8/devlink.8 b/man/man8/devlink.8 index 866fda5..840cf44 100644 --- a/man/man8/devlink.8 +++ b/man/man8/devlink.8 @@ -59,6 +59,10 @@ Output statistics. .BR "\-N", " \-Netns " Switches to the specified network namespace. +.TP +.BR "\-i", " --iec" +Print human readable rates in IEC units (e.g. 1Ki = 1024). + .SS .I OBJECT From patchwork Wed Jun 2 12:17:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 453066 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 4E8B4C4708F for ; Wed, 2 Jun 2021 12:18:00 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 384A6613D2 for ; Wed, 2 Jun 2021 12:18:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229957AbhFBMTm (ORCPT ); Wed, 2 Jun 2021 08:19:42 -0400 Received: from mail-sn1anam02on2068.outbound.protection.outlook.com ([40.107.96.68]:56050 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229938AbhFBMTg (ORCPT ); Wed, 2 Jun 2021 08:19:36 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BGjgvcrsSKat1ZmhFqVHX0RVS0vsZIJM8cl8z8Lg0TWoZAwN5BzYiZQbdwENlmRccFiIu9UenDACMbiQ/eLvyURo2bLyLCRf6WNv5+0JZUc/ma0w3C6UhpWzgmsCHnuJsMex0p7L+Z01SySQSHOpw22aMo8uRvkrsjFi9cZisVxhSRpyIvoVGJaunEJ5dj027GMK3KFF8tt4R3E+JlshsR9ownFOb0nV9a3HJwCdl6qM8+fXmYG1PR17BDpEaQFCPl/k7Ab1NbpzYTfiX/sjLcycbMj5w0lMTt0O2WBs68EsWUvSipnCao2WOPfE6yfLQlbAhOJyTsb89DUGxirPgg== 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=aracQJez9omuebwKabD6sX8pDMnJ89hOKSrs9KBu9yQ=; b=Przk5i+GbPlUWa36HVPfbmLRAF7LglW+FfXHEibMlVmIMDHgTwrATyXVaMmDZV2upnOSucw3cfCjGPPukbbrZDm4EMQ+GQgirDHljJOT8pAWnvTMX8sW453N65Zml1lWJ14uFsZLH09YhBQelRwJFL1RMz15Fg1d/rQCHCCS5FVfW2tioHXimpc3/MHQke3UmZeH8tm7lRNY9n+JD/5h7CHQPYrvwDkvvSRQ7DrPfBnU+uAp+zytirt4dVzExQd3Ys8IkR5qntVtwWEnToYNh7H97IFup+oAym1bPFv64QpmwaB3th11v4cnbCtPGSBT4asPu9TDbzXZ1SOWR1u7cQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=aracQJez9omuebwKabD6sX8pDMnJ89hOKSrs9KBu9yQ=; b=YD5TRMkl7eMX7Mea9sRdCyp+Ndg2geunCGyYYAvSLQtz/MAQTFvtnJFmCFVlYPfXQ8aexcmopimuOLMh9Cpjf0Ehds6C3TNWutpSCq4sHZA908HDfkRKl68hUCtn8PpAR9VU6xS6tnqh6esiBoYyxpI70DJAvOwWw6T6jJbrUGJgu7M+w/HNFBfD8yc821AoLcbFfbZ62K9lJaKnogTJ8PgyvSpSRqTQFHgTYEs6SgjbJGuWMC92ISF6nA/KCD1d8XioqkYPqEmF61OjOJlKLqaVUiQhqhQN6wrRVfPz33OXx5pGgcI3pPy6inRbLhtrMzVJ1eEKjfoNwY/nen8Eeg== Received: from CO2PR04CA0134.namprd04.prod.outlook.com (2603:10b6:104::12) by CY4PR12MB1445.namprd12.prod.outlook.com (2603:10b6:910:11::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.30; Wed, 2 Jun 2021 12:17:52 +0000 Received: from CO1NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:104:0:cafe::7f) by CO2PR04CA0134.outlook.office365.com (2603:10b6:104::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Wed, 2 Jun 2021 12:17:52 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by CO1NAM11FT015.mail.protection.outlook.com (10.13.175.130) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4150.30 via Frontend Transport; Wed, 2 Jun 2021 12:17:51 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 12:17:49 +0000 Received: from vdi.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Jun 2021 05:17:47 -0700 From: To: CC: , , , , , , , , Dmytro Linkin Subject: [PATCH RESEND net-next v3 05/18] netdevsim: Implement legacy/switchdev mode for VFs Date: Wed, 2 Jun 2021 15:17:18 +0300 Message-ID: <1622636251-29892-6-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> References: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 8c09d2de-c9c1-4c37-507c-08d925c07157 X-MS-TrafficTypeDiagnostic: CY4PR12MB1445: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1824; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: peC+RDooIZZa1YYY2DbX5h7Ft+xCUSXiMSxyHYyOt+YLoryeLv2KM8jdal0hQq1dAD5NeYrDc0+jWkoWi5q34IU6CwHqwYqPY3E8vAHCpg4dwFehUmOlNi39oQvVOrKO00h4ZlVUSA2ln5HsFTZqoVs8oXrfsL/ZlznWZx2E6kNtgWh9VsTuQL++WpuWz1hANxmEsxbQjmEWFCjp5fl4s2vrFGBPrTu7xzU25ksKDSbeYKh3Z4oKt/zxCoiBEeDO0sF47bFklO4iZjjZ7KOoQi2xtAf3fEaWGY60XxMGBYUyqWVM6jj0HPHwamC0x60jDesALhlcSCCBnes5xtbXrWhZ9tvj4ApM6I14SzrUpWBm1edl4xYvCh2vDWIAW7ATVjp4cg3PBgs0uJwsYPD2YMcxQjyV0koAIW8jgfYm32Gw2lmI2c+0Cul+jE3+YqFRXKsY8yJ/3DoSglI5PVPnsJj6LivfKpuillSS6IG/hZJqg6oJqfYyAuNeWe9RDIqvvmsNYu+uEuSQp/47CHgAqyweKlRWwWy/QYL01kSCI88q+CzBtGWP62VJ+xligRvP6tCYKnFSE3cz8XbU4Ld15ycp0Ei8nGTd4TeKzKvVK75tzN6FHsu+vkp4hESd8W5/JjZKTxE5pCehhPoVOmpy1wAJCx2xRjzzgOSJMzIYiKY= X-Forefront-Antispam-Report: CIP:216.228.112.36; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid05.nvidia.com; CAT:NONE; SFS:(4636009)(396003)(136003)(376002)(346002)(39860400002)(46966006)(36840700001)(2616005)(26005)(426003)(54906003)(7696005)(6916009)(5660300002)(2876002)(36906005)(478600001)(36860700001)(8936002)(336012)(82740400003)(356005)(70206006)(316002)(70586007)(82310400003)(186003)(36756003)(8676002)(47076005)(86362001)(7636003)(6666004)(83380400001)(107886003)(2906002)(4326008); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 12:17:51.3942 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 8c09d2de-c9c1-4c37-507c-08d925c07157 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.36]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1445 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Dmytro Linkin Implement callbacks to set/get eswitch mode value. Add helpers to check current mode. Instantiate VFs' net devices and devlink ports on switchdev enabling and remove them on legacy enabling. Changing number of VFs while in switchdev mode triggers VFs creation/deletion. Also disable NDO API callback to set VF rate, since it's legacy API. Switchdev API to set VF rate will be implemented in one of the next patches. Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- drivers/net/netdevsim/bus.c | 17 +++++++++- drivers/net/netdevsim/dev.c | 69 +++++++++++++++++++++++++++++++++++++++ drivers/net/netdevsim/netdev.c | 5 +++ drivers/net/netdevsim/netdevsim.h | 14 ++++++++ 4 files changed, 104 insertions(+), 1 deletion(-) diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c index e29146d..b56003d 100644 --- a/drivers/net/netdevsim/bus.c +++ b/drivers/net/netdevsim/bus.c @@ -27,6 +27,9 @@ static struct nsim_bus_dev *to_nsim_bus_dev(struct device *dev) static int nsim_bus_dev_vfs_enable(struct nsim_bus_dev *nsim_bus_dev, unsigned int num_vfs) { + struct nsim_dev *nsim_dev; + int err = 0; + if (nsim_bus_dev->max_vfs < num_vfs) return -ENOMEM; @@ -34,12 +37,24 @@ static int nsim_bus_dev_vfs_enable(struct nsim_bus_dev *nsim_bus_dev, return -ENOMEM; nsim_bus_dev->num_vfs = num_vfs; - return 0; + nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev); + if (nsim_esw_mode_is_switchdev(nsim_dev)) { + err = nsim_esw_switchdev_enable(nsim_dev, NULL); + if (err) + nsim_bus_dev->num_vfs = 0; + } + + return err; } void nsim_bus_dev_vfs_disable(struct nsim_bus_dev *nsim_bus_dev) { + struct nsim_dev *nsim_dev; + nsim_bus_dev->num_vfs = 0; + nsim_dev = dev_get_drvdata(&nsim_bus_dev->dev); + if (nsim_esw_mode_is_switchdev(nsim_dev)) + nsim_esw_legacy_enable(nsim_dev, NULL); } static ssize_t diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 8bd7654..ed9ce08 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -439,6 +439,72 @@ static void nsim_dev_dummy_region_exit(struct nsim_dev *nsim_dev) devlink_region_destroy(nsim_dev->dummy_region); } +static void __nsim_dev_port_del(struct nsim_dev_port *nsim_dev_port); +int nsim_esw_legacy_enable(struct nsim_dev *nsim_dev, struct netlink_ext_ack *extack) +{ + struct nsim_dev_port *nsim_dev_port, *tmp; + + mutex_lock(&nsim_dev->port_list_lock); + list_for_each_entry_safe(nsim_dev_port, tmp, &nsim_dev->port_list, list) + if (nsim_dev_port_is_vf(nsim_dev_port)) + __nsim_dev_port_del(nsim_dev_port); + mutex_unlock(&nsim_dev->port_list_lock); + nsim_dev->esw_mode = DEVLINK_ESWITCH_MODE_LEGACY; + return 0; +} + +int nsim_esw_switchdev_enable(struct nsim_dev *nsim_dev, struct netlink_ext_ack *extack) +{ + struct nsim_bus_dev *nsim_bus_dev = nsim_dev->nsim_bus_dev; + int i, err; + + for (i = 0; i < nsim_bus_dev->num_vfs; i++) { + err = nsim_dev_port_add(nsim_bus_dev, NSIM_DEV_PORT_TYPE_VF, i); + if (err) { + NL_SET_ERR_MSG_MOD(extack, "Failed to initialize VFs' netdevsim ports"); + pr_err("Failed to initialize VF id=%d. %d.\n", i, err); + goto err_port_add_vfs; + } + } + nsim_dev->esw_mode = DEVLINK_ESWITCH_MODE_SWITCHDEV; + return 0; + +err_port_add_vfs: + for (i--; i >= 0; i--) + nsim_dev_port_del(nsim_bus_dev, NSIM_DEV_PORT_TYPE_VF, i); + return err; +} + +static int nsim_devlink_eswitch_mode_set(struct devlink *devlink, u16 mode, + struct netlink_ext_ack *extack) +{ + struct nsim_dev *nsim_dev = devlink_priv(devlink); + int err = 0; + + mutex_lock(&nsim_dev->nsim_bus_dev->vfs_lock); + if (mode == nsim_dev->esw_mode) + goto unlock; + + if (mode == DEVLINK_ESWITCH_MODE_LEGACY) + err = nsim_esw_legacy_enable(nsim_dev, extack); + else if (mode == DEVLINK_ESWITCH_MODE_SWITCHDEV) + err = nsim_esw_switchdev_enable(nsim_dev, extack); + else + err = -EINVAL; + +unlock: + mutex_unlock(&nsim_dev->nsim_bus_dev->vfs_lock); + return err; +} + +static int nsim_devlink_eswitch_mode_get(struct devlink *devlink, u16 *mode) +{ + struct nsim_dev *nsim_dev = devlink_priv(devlink); + + *mode = nsim_dev->esw_mode; + return 0; +} + struct nsim_trap_item { void *trap_ctx; enum devlink_trap_action action; @@ -925,6 +991,8 @@ static int nsim_dev_devlink_trap_init(struct devlink *devlink, } static const struct devlink_ops nsim_dev_devlink_ops = { + .eswitch_mode_set = nsim_devlink_eswitch_mode_set, + .eswitch_mode_get = nsim_devlink_eswitch_mode_get, .supported_flash_update_params = DEVLINK_SUPPORT_FLASH_UPDATE_COMPONENT | DEVLINK_SUPPORT_FLASH_UPDATE_OVERWRITE_MASK, .reload_actions = BIT(DEVLINK_RELOAD_ACTION_DRIVER_REINIT), @@ -1177,6 +1245,7 @@ int nsim_dev_probe(struct nsim_bus_dev *nsim_bus_dev) devlink_params_publish(devlink); devlink_reload_enable(devlink); + nsim_dev->esw_mode = DEVLINK_ESWITCH_MODE_LEGACY; return 0; err_psample_exit: diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index 9352e18..c3aeb15 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -113,6 +113,11 @@ static int nsim_set_vf_rate(struct net_device *dev, int vf, int min, int max) struct netdevsim *ns = netdev_priv(dev); struct nsim_bus_dev *nsim_bus_dev = ns->nsim_bus_dev; + if (nsim_esw_mode_is_switchdev(ns->nsim_dev)) { + pr_err("Not supported in switchdev mode. Please use devlink API.\n"); + return -EOPNOTSUPP; + } + if (vf >= nsim_bus_dev->num_vfs) return -EINVAL; diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index e025c1b..13a0042 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -257,8 +257,22 @@ struct nsim_dev { u32 sleep; } udp_ports; struct nsim_dev_psample *psample; + u16 esw_mode; }; +int nsim_esw_legacy_enable(struct nsim_dev *nsim_dev, struct netlink_ext_ack *extack); +int nsim_esw_switchdev_enable(struct nsim_dev *nsim_dev, struct netlink_ext_ack *extack); + +static inline bool nsim_esw_mode_is_legacy(struct nsim_dev *nsim_dev) +{ + return nsim_dev->esw_mode == DEVLINK_ESWITCH_MODE_LEGACY; +} + +static inline bool nsim_esw_mode_is_switchdev(struct nsim_dev *nsim_dev) +{ + return nsim_dev->esw_mode == DEVLINK_ESWITCH_MODE_SWITCHDEV; +} + static inline struct net *nsim_dev_net(struct nsim_dev *nsim_dev) { return devlink_net(priv_to_devlink(nsim_dev)); From patchwork Wed Jun 2 12:17:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 453927 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 CA687C47083 for ; Wed, 2 Jun 2021 12:18:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA26F613B8 for ; Wed, 2 Jun 2021 12:18:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229831AbhFBMTn (ORCPT ); Wed, 2 Jun 2021 08:19:43 -0400 Received: from mail-mw2nam12on2065.outbound.protection.outlook.com ([40.107.244.65]:32480 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229967AbhFBMTi (ORCPT ); Wed, 2 Jun 2021 08:19:38 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WFHArQ19mtke86PUPJ7Dx0QV8OXooZewTs/ZEtFx4xc56BWOrf6mWzfiRcjQ1o9crVlWn0dn/uoqo9yPREDxhu09khhsZ+ZQr1eyfXY9wmfLU8zDezEYOG2MwDZs4exq1JCOEJXIsK+zcpvXUJc5JqB99wBBtdMzkvK15XnU5HK3ZtczQP73kk69+YecIHUmIQgkRM1TmGs/ON1O0uwNqgqgDe0YCf0Fshdp0Lm9LeFPYoT7dWYnsWYlRVRNuiiQBbAyZqwjIjL2ODtwFI64jajIu96v7tHDhbsicnYosANz6D7zBPER7Xtz7bS8z+f0VpQazLKt5tu6X8LN1H3+hg== 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=oI/vudcgjl4J/ikbfGkzBBKY6/Q7PLea29EEp5GMGVc=; b=WisZzhbCfbUE0GWQX7txmrsiccGb4S4nDondDBkMIVOGKJzlAj/3qIteeXzKYB0JqxKuFz0W6DODFFzX4XftnSOo/ys+7RUrS7qX5Fs29MmTM2H7QutNfXb6OhVRIikMtJ0PvUeWesw7TfjtFISyVT3+ktsXeghIy7rhPxekqMyWEcylQIcXAyNKNz/O+yeDTFboGT0er30xdNUq4zE6au+SV+Di+vPXlwfKi9xe0Ub/Sc1rQyq9UQXOxpqDrpqDvBr7/85fz6DlorvTVsK8pAJqoDpegFFL2SV/jzi+qbxQNxys+wYGlBZ/AsLRZSNIEzPsVC3p9tC4cEcZ6oG4EQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=oI/vudcgjl4J/ikbfGkzBBKY6/Q7PLea29EEp5GMGVc=; b=olonFcMYEEmZj8fN1NAj9psZ9odTRxHmPmjOy+IUl5CgJJIA/HiX73hqbREXbYE5KMzDscBcCtTAI/sg6NLsF04OPVBucwBrtlWl/OOKtoiJT3HXTDHhB2n5t5J0cquazkwiCbEYVIwoyAP9TkCoI2NpveKQJ42rH1dkXcYvOX6sbgeYVqKwhh5K+D8V2vCupBjDcCVEl8DndnVOmPwy4YChQOo8xzF5o42y9J0IuGpy+9bWrRzNyVlaI79XWnP5h3frb1dVhcO476TlLWPkO5hEfqT+S8UQDqAAxQ0COYe4v9B7jbOAinTgGhonejHLxizIOdmp5fWwcHtDpzBKyQ== Received: from BN0PR04CA0120.namprd04.prod.outlook.com (2603:10b6:408:ec::35) by DM6PR12MB3131.namprd12.prod.outlook.com (2603:10b6:5:11d::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.21; Wed, 2 Jun 2021 12:17:53 +0000 Received: from BN8NAM11FT015.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ec:cafe::48) by BN0PR04CA0120.outlook.office365.com (2603:10b6:408:ec::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.20 via Frontend Transport; Wed, 2 Jun 2021 12:17:53 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT015.mail.protection.outlook.com (10.13.176.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4150.30 via Frontend Transport; Wed, 2 Jun 2021 12:17:53 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 05:17:52 -0700 Received: from vdi.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Jun 2021 05:17:49 -0700 From: To: CC: , , , , , , , , Dmytro Linkin Subject: [PATCH RESEND net-next v3 06/18] devlink: Introduce rate object Date: Wed, 2 Jun 2021 15:17:19 +0300 Message-ID: <1622636251-29892-7-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> References: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 5768c383-f4d7-4fc5-7642-08d925c0728b X-MS-TrafficTypeDiagnostic: DM6PR12MB3131: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:127; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2jQG8HbAbstlhklYNEbuctKMUbWHW/BlEBnUUX3pctDjlU8qdwBytrJj9C6L1DajUs9gBUVInhAXti9NfMFzZfeoi4VteDcMKqlJ+K3xOc3lTpLSdSI/MUteSnNbHBJzoKWJ8+NlxR9o0F8XPJEQUewFfcYIevrQRkgTQMxOwQrkMSWy+ga5tdER9zHUuNaDFlRX4ECcomomB9Zbkz8pGM36oSPVFa3KFASjbufgQ126UF8RLjvG8LMQ8Nqzddb5bqGQUoF/X2aFVztMuEX1burbErSbn0+LNjKRI9TFIr62uprrZ7xDPicEllITBpjqZo+/2WiVHhBPycYush8cyC6krn0OZKxc8uh0nWIPzFpU7aqhHD/3vbzayfDqkJ3+hNzcpgYbr1QWSsfHu0GUf41aU/thEovOeA49ggISxYPrdubWy2/NwPhHmPEfIlOi99DuiWxky2IDc7QHobGZWQ0Ng4+q5YJDOf5M5IOpiAA94KbhuhWg9IJWQAXq3kfFtow+Sh5Pbml89raesrAX9JPdGziQVgWCUpygGsQdYBFFhGFGIGeJZJPjbJ8M8+4IjwUavKX6FCKomns0sgUvsz4/9QPhB7gzNWenZGJ67BvLvQhykVNNTiyTydwmjMY4rp8IDU5o2TxvJBwW6yaw4O2rG62utqAfRFHfsiBB9Ngv13dKkP08D1qaKJup8TyA X-Forefront-Antispam-Report: CIP:216.228.112.32; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid01.nvidia.com; CAT:NONE; SFS:(4636009)(396003)(39860400002)(376002)(346002)(136003)(46966006)(36840700001)(47076005)(26005)(356005)(6916009)(7696005)(7636003)(2616005)(5660300002)(82310400003)(86362001)(8676002)(2876002)(83380400001)(336012)(426003)(36860700001)(107886003)(186003)(30864003)(70586007)(8936002)(54906003)(6666004)(70206006)(478600001)(82740400003)(4326008)(2906002)(36756003)(316002)(461764006); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 12:17:53.2808 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 5768c383-f4d7-4fc5-7642-08d925c0728b X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.32]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT015.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3131 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Dmytro Linkin Allow registering rate object for devlink ports with dedicated devlink_rate_leaf_{create|destroy}() API. Implement new netlink DEVLINK_CMD_RATE_GET command that is used to retrieve rate object info. Add new DEVLINK_CMD_RATE_{NEW|DEL} commands that are used for notifications when creating/deleting leaf rate object. Rate API is intended to be used for rate limiting of individual devlink ports (leafs) and their aggregates (nodes). Example: $ devlink port show pci/0000:03:00.0/0 pci/0000:03:00.0/1 $ devlink port function rate show pci/0000:03:00.0/0: type leaf pci/0000:03:00.0/1: type leaf Co-developed-by: Vlad Buslov Signed-off-by: Vlad Buslov Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- Notes: v1->v2: - s/func/function/ in commit message - fixes kernel-doc for devlink_rate_leaf_{create|destroy}() include/net/devlink.h | 14 +++ include/uapi/linux/devlink.h | 11 +++ net/core/devlink.c | 229 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 253 insertions(+), 1 deletion(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index 7c984ca..2f5954d 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -34,6 +34,7 @@ struct devlink_dev_stats { struct devlink { struct list_head list; struct list_head port_list; + struct list_head rate_list; struct list_head sb_list; struct list_head dpipe_table_list; struct list_head resource_list; @@ -133,6 +134,15 @@ struct devlink_port_attrs { }; }; +struct devlink_rate { + struct list_head list; + enum devlink_rate_type type; + struct devlink *devlink; + void *priv; + + struct devlink_port *devlink_port; +}; + struct devlink_port { struct list_head list; struct list_head param_list; @@ -152,6 +162,8 @@ struct devlink_port { struct delayed_work type_warn_dw; struct list_head reporter_list; struct mutex reporters_lock; /* Protects reporter_list */ + + struct devlink_rate *devlink_rate; }; struct devlink_port_new_attrs { @@ -1512,6 +1524,8 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 contro void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, u32 controller, u16 pf, u32 sf, bool external); +int devlink_rate_leaf_create(struct devlink_port *port, void *priv); +void devlink_rate_leaf_destroy(struct devlink_port *devlink_port); int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, u32 size, u16 ingress_pools_count, u16 egress_pools_count, u16 ingress_tc_count, diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index f6008b2..0c27b45 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -126,6 +126,11 @@ enum devlink_command { DEVLINK_CMD_HEALTH_REPORTER_TEST, + DEVLINK_CMD_RATE_GET, /* can dump */ + DEVLINK_CMD_RATE_SET, + DEVLINK_CMD_RATE_NEW, + DEVLINK_CMD_RATE_DEL, + /* add new commands above here */ __DEVLINK_CMD_MAX, DEVLINK_CMD_MAX = __DEVLINK_CMD_MAX - 1 @@ -206,6 +211,10 @@ enum devlink_port_flavour { */ }; +enum devlink_rate_type { + DEVLINK_RATE_TYPE_LEAF, +}; + enum devlink_param_cmode { DEVLINK_PARAM_CMODE_RUNTIME, DEVLINK_PARAM_CMODE_DRIVERINIT, @@ -534,6 +543,8 @@ enum devlink_attr { DEVLINK_ATTR_RELOAD_ACTION_STATS, /* nested */ DEVLINK_ATTR_PORT_PCI_SF_NUMBER, /* u32 */ + + DEVLINK_ATTR_RATE_TYPE, /* u16 */ /* add new attributes above here, update the policy in devlink.c */ __DEVLINK_ATTR_MAX, diff --git a/net/core/devlink.c b/net/core/devlink.c index 4eb9695..28b2490 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -190,6 +190,25 @@ static struct devlink_port *devlink_port_get_from_info(struct devlink *devlink, return devlink_port_get_from_attrs(devlink, info->attrs); } +static inline bool +devlink_rate_is_leaf(struct devlink_rate *devlink_rate) +{ + return devlink_rate->type == DEVLINK_RATE_TYPE_LEAF; +} + +static struct devlink_rate * +devlink_rate_leaf_get_from_info(struct devlink *devlink, struct genl_info *info) +{ + struct devlink_rate *devlink_rate; + struct devlink_port *devlink_port; + + devlink_port = devlink_port_get_from_attrs(devlink, info->attrs); + if (IS_ERR(devlink_port)) + return ERR_CAST(devlink_port); + devlink_rate = devlink_port->devlink_rate; + return devlink_rate ?: ERR_PTR(-ENODEV); +} + struct devlink_sb { struct list_head list; unsigned int index; @@ -408,12 +427,13 @@ struct devlink_snapshot { #define DEVLINK_NL_FLAG_NEED_PORT BIT(0) #define DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT BIT(1) +#define DEVLINK_NL_FLAG_NEED_RATE BIT(2) /* The per devlink instance lock is taken by default in the pre-doit * operation, yet several commands do not require this. The global * devlink lock is taken and protects from disruption by user-calls. */ -#define DEVLINK_NL_FLAG_NO_LOCK BIT(2) +#define DEVLINK_NL_FLAG_NO_LOCK BIT(3) static int devlink_nl_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, struct genl_info *info) @@ -442,6 +462,15 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops, devlink_port = devlink_port_get_from_info(devlink, info); if (!IS_ERR(devlink_port)) info->user_ptr[1] = devlink_port; + } else if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_RATE) { + struct devlink_rate *devlink_rate; + + devlink_rate = devlink_rate_leaf_get_from_info(devlink, info); + if (IS_ERR(devlink_rate)) { + err = PTR_ERR(devlink_rate); + goto unlock; + } + info->user_ptr[1] = devlink_rate; } return 0; @@ -749,6 +778,39 @@ static int devlink_nl_port_attrs_put(struct sk_buff *msg, return 0; } +static int devlink_nl_rate_fill(struct sk_buff *msg, + struct devlink *devlink, + struct devlink_rate *devlink_rate, + enum devlink_command cmd, u32 portid, + u32 seq, int flags, + struct netlink_ext_ack *extack) +{ + void *hdr; + + hdr = genlmsg_put(msg, portid, seq, &devlink_nl_family, flags, cmd); + if (!hdr) + return -EMSGSIZE; + + if (devlink_nl_put_handle(msg, devlink)) + goto nla_put_failure; + + if (nla_put_u16(msg, DEVLINK_ATTR_RATE_TYPE, devlink_rate->type)) + goto nla_put_failure; + + if (devlink_rate_is_leaf(devlink_rate)) { + if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX, + devlink_rate->devlink_port->index)) + goto nla_put_failure; + } + + genlmsg_end(msg, hdr); + return 0; + +nla_put_failure: + genlmsg_cancel(msg, hdr); + return -EMSGSIZE; +} + static bool devlink_port_fn_state_valid(enum devlink_port_fn_state state) { @@ -920,6 +982,99 @@ static void devlink_port_notify(struct devlink_port *devlink_port, msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL); } +static void devlink_rate_notify(struct devlink_rate *devlink_rate, + enum devlink_command cmd) +{ + struct devlink *devlink = devlink_rate->devlink; + struct sk_buff *msg; + int err; + + WARN_ON(cmd != DEVLINK_CMD_RATE_NEW && + cmd != DEVLINK_CMD_RATE_DEL); + + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!msg) + return; + + err = devlink_nl_rate_fill(msg, devlink, devlink_rate, + cmd, 0, 0, 0, NULL); + if (err) { + nlmsg_free(msg); + return; + } + + genlmsg_multicast_netns(&devlink_nl_family, devlink_net(devlink), + msg, 0, DEVLINK_MCGRP_CONFIG, GFP_KERNEL); +} + +static int devlink_nl_cmd_rate_get_dumpit(struct sk_buff *msg, + struct netlink_callback *cb) +{ + struct devlink_rate *devlink_rate; + struct devlink *devlink; + int start = cb->args[0]; + int idx = 0; + int err = 0; + + mutex_lock(&devlink_mutex); + list_for_each_entry(devlink, &devlink_list, list) { + if (!net_eq(devlink_net(devlink), sock_net(msg->sk))) + continue; + mutex_lock(&devlink->lock); + list_for_each_entry(devlink_rate, &devlink->rate_list, list) { + enum devlink_command cmd = DEVLINK_CMD_RATE_NEW; + u32 id = NETLINK_CB(cb->skb).portid; + + if (idx < start) { + idx++; + continue; + } + err = devlink_nl_rate_fill(msg, devlink, + devlink_rate, + cmd, id, + cb->nlh->nlmsg_seq, + NLM_F_MULTI, NULL); + if (err) { + mutex_unlock(&devlink->lock); + goto out; + } + idx++; + } + mutex_unlock(&devlink->lock); + } +out: + mutex_unlock(&devlink_mutex); + if (err != -EMSGSIZE) + return err; + + cb->args[0] = idx; + return msg->len; +} + +static int devlink_nl_cmd_rate_get_doit(struct sk_buff *skb, + struct genl_info *info) +{ + struct devlink_rate *devlink_rate = info->user_ptr[1]; + struct devlink *devlink = devlink_rate->devlink; + struct sk_buff *msg; + int err; + + msg = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_KERNEL); + if (!msg) + return -ENOMEM; + + err = devlink_nl_rate_fill(msg, devlink, devlink_rate, + DEVLINK_CMD_RATE_NEW, + info->snd_portid, info->snd_seq, 0, + info->extack); + if (err) { + nlmsg_free(msg); + return err; + } + + return genlmsg_reply(msg, info); +} + static int devlink_nl_cmd_get_doit(struct sk_buff *skb, struct genl_info *info) { struct devlink *devlink = info->user_ptr[0]; @@ -7802,6 +7957,7 @@ static int devlink_nl_cmd_trap_policer_set_doit(struct sk_buff *skb, [DEVLINK_ATTR_PORT_PCI_PF_NUMBER] = { .type = NLA_U16 }, [DEVLINK_ATTR_PORT_PCI_SF_NUMBER] = { .type = NLA_U32 }, [DEVLINK_ATTR_PORT_CONTROLLER_NUMBER] = { .type = NLA_U32 }, + [DEVLINK_ATTR_RATE_TYPE] = { .type = NLA_U16 }, }; static const struct genl_small_ops devlink_nl_ops[] = { @@ -7828,6 +7984,13 @@ static int devlink_nl_cmd_trap_policer_set_doit(struct sk_buff *skb, .internal_flags = DEVLINK_NL_FLAG_NEED_PORT, }, { + .cmd = DEVLINK_CMD_RATE_GET, + .doit = devlink_nl_cmd_rate_get_doit, + .dumpit = devlink_nl_cmd_rate_get_dumpit, + .internal_flags = DEVLINK_NL_FLAG_NEED_RATE, + /* can be retrieved by unprivileged users */ + }, + { .cmd = DEVLINK_CMD_PORT_SPLIT, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = devlink_nl_cmd_port_split_doit, @@ -8202,6 +8365,7 @@ struct devlink *devlink_alloc(const struct devlink_ops *ops, size_t priv_size) xa_init_flags(&devlink->snapshot_ids, XA_FLAGS_ALLOC); __devlink_net_set(devlink, &init_net); INIT_LIST_HEAD(&devlink->port_list); + INIT_LIST_HEAD(&devlink->rate_list); INIT_LIST_HEAD(&devlink->sb_list); INIT_LIST_HEAD_RCU(&devlink->dpipe_table_list); INIT_LIST_HEAD(&devlink->resource_list); @@ -8304,6 +8468,7 @@ void devlink_free(struct devlink *devlink) WARN_ON(!list_empty(&devlink->resource_list)); WARN_ON(!list_empty(&devlink->dpipe_table_list)); WARN_ON(!list_empty(&devlink->sb_list)); + WARN_ON(!list_empty(&devlink->rate_list)); WARN_ON(!list_empty(&devlink->port_list)); xa_destroy(&devlink->snapshot_ids); @@ -8620,6 +8785,68 @@ void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, u32 contro } EXPORT_SYMBOL_GPL(devlink_port_attrs_pci_sf_set); +/** + * devlink_rate_leaf_create - create devlink rate leaf + * + * @devlink_port: devlink port object to create rate object on + * @priv: driver private data + * + * Create devlink rate object of type leaf on provided @devlink_port. + * Throws call trace if @devlink_port already has a devlink rate object. + * + * Context: Takes and release devlink->lock . + * + * Return: -ENOMEM if failed to allocate rate object, 0 otherwise. + */ +int +devlink_rate_leaf_create(struct devlink_port *devlink_port, void *priv) +{ + struct devlink *devlink = devlink_port->devlink; + struct devlink_rate *devlink_rate; + + devlink_rate = kzalloc(sizeof(*devlink_rate), GFP_KERNEL); + if (!devlink_rate) + return -ENOMEM; + + mutex_lock(&devlink->lock); + WARN_ON(devlink_port->devlink_rate); + devlink_rate->type = DEVLINK_RATE_TYPE_LEAF; + devlink_rate->devlink = devlink; + devlink_rate->devlink_port = devlink_port; + devlink_rate->priv = priv; + list_add_tail(&devlink_rate->list, &devlink->rate_list); + devlink_port->devlink_rate = devlink_rate; + devlink_rate_notify(devlink_rate, DEVLINK_CMD_RATE_NEW); + mutex_unlock(&devlink->lock); + + return 0; +} +EXPORT_SYMBOL_GPL(devlink_rate_leaf_create); + +/** + * devlink_rate_leaf_destroy - destroy devlink rate leaf + * + * @devlink_port: devlink port linked to the rate object + * + * Context: Takes and release devlink->lock . + */ +void devlink_rate_leaf_destroy(struct devlink_port *devlink_port) +{ + struct devlink_rate *devlink_rate = devlink_port->devlink_rate; + struct devlink *devlink = devlink_port->devlink; + + if (!devlink_rate) + return; + + mutex_lock(&devlink->lock); + devlink_rate_notify(devlink_rate, DEVLINK_CMD_RATE_DEL); + list_del(&devlink_rate->list); + devlink_port->devlink_rate = NULL; + mutex_unlock(&devlink->lock); + kfree(devlink_rate); +} +EXPORT_SYMBOL_GPL(devlink_rate_leaf_destroy); + static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port, char *name, size_t len) { From patchwork Wed Jun 2 12:17:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 453065 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 2C73DC47092 for ; Wed, 2 Jun 2021 12:18:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0E4B2613B8 for ; Wed, 2 Jun 2021 12:18:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229958AbhFBMTp (ORCPT ); Wed, 2 Jun 2021 08:19:45 -0400 Received: from mail-mw2nam10on2086.outbound.protection.outlook.com ([40.107.94.86]:37696 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229973AbhFBMTl (ORCPT ); Wed, 2 Jun 2021 08:19:41 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HQsiUA/ORHlZ8s6IU7gviZq1OlFPPMKnMTzrs97poUGzLJgoPwh01UE8ngZn2oXDREKdVNeejSIJfrE5lVsoNy/l5A3D+V8c8XkLUy94XQjZmiXmmKUNkyeL80z9FLOiXrSiHEYwz7cyC+mfXyqKvfM0BOUgqJEXgZQemIj0FMOoBEJw/ke4JjQOMFYzvxnNkIYNpUhdkNoOXetbEcNe+jo3acg17bAeQmYEc/5JK8KnBSVycq6jpAi9lql+/0eoVT6eIO9TbAJAJnjQCWg6jrDVnSGdRlfitp3zo55WQfTvs4A0qPdvz5Yf4RrWQwAlCT5G/ym9XEQAxObIgMijTg== 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=m8s2DaLPRJdS/d8/hCJX0xTYb5liTfDINCLFcO9y+cU=; b=MLdVxVd7Sc2QKLq9tGQo04PyXuSI5JhgNyEipxH2rumfsyvug1KBEb3k8mlYO0owB2UpUcIOumvhM6bvxtaNY/KfOrDVcmf3c4PVeTcCTklj4bJ/AMnHsbeRBsf4uPuDMpbo130Proa9FF/CeJxm4HyYXGX86jdUS9phR0i7IaDe2wHSHAEuc8KmbrKuMvE42UXtol09g2TSxu+8zcu48h5+9cY38BkerB88ShaP0350Ws6VXHPJUzAmF+qhYlu/18K4Y/4FJk6AYA8dDCxsWBXkXalJcsy6HQ+NIZd010JquRuo4E9mQeh1lCjIzbh8QT/N7lXSmdbG2z0N9x+e0w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=m8s2DaLPRJdS/d8/hCJX0xTYb5liTfDINCLFcO9y+cU=; b=uBKUFjuwTvgffS1YXH6+Y2hTrPvPMr3n8fahPvBXEr4mCrsXis6Gwi5iqUg/HDnr13+Diz0Bg3ov2nVVMn0/xBKOhOSFiD30bOoJW6gU3H3P2uv9U+DXDKxUsiW47a5SI2Tvj36ud2e73/aZpGzFbsbIY8f2bgQYonJrfyVOFwsSHbh8szc+WMqbIA9LkSG3v9A8ga0JvIESkaDwbnqdGVpF8f6hxMCwO/sC8KT7sjmgPBN3fKTO0kbOjCGypRjxLTe/T8+kD3GYVSbmMJ2JoNxMYNiJMhtjaP6B4+ynYGyxGL9bch/Q7QENIJMJ7mNI11enkIynoxI8vfDceqUDPA== Received: from MW2PR16CA0007.namprd16.prod.outlook.com (2603:10b6:907::20) by BY5PR12MB4275.namprd12.prod.outlook.com (2603:10b6:a03:20a::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.21; Wed, 2 Jun 2021 12:17:57 +0000 Received: from CO1NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:907:0:cafe::22) by MW2PR16CA0007.outlook.office365.com (2603:10b6:907::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.20 via Frontend Transport; Wed, 2 Jun 2021 12:17:57 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by CO1NAM11FT008.mail.protection.outlook.com (10.13.175.191) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4150.30 via Frontend Transport; Wed, 2 Jun 2021 12:17:56 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 12:17:55 +0000 Received: from vdi.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Jun 2021 05:17:52 -0700 From: To: CC: , , , , , , , , Dmytro Linkin Subject: [PATCH RESEND net-next v3 07/18] netdevsim: Register devlink rate leaf objects per VF Date: Wed, 2 Jun 2021 15:17:20 +0300 Message-ID: <1622636251-29892-8-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> References: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c97e2376-5311-4f04-6340-08d925c074ad X-MS-TrafficTypeDiagnostic: BY5PR12MB4275: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:31; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xgiq7SSPcVYwmPoblVkKkxJOIl3osn6qfOsUfzRbcwv8DipEiKGm0IiYfBTP0SMqAL5/o0SYa2M1E1kCPivy9SYJaICx++Xs/mvvW3QujJ3cIoQpawXG65GI0CEaLujSs+Fzxuaq9Zs1m5Z68lJtqvxSQ7SIn77odwP/1lnpvty+lx8ZZKJk85vgT8CFDC6xweTZu5ae1pSrvZwPoM7pkXiOthELuOEM7qYrpUpX9RsRpK09DMV/+SnDWKExNt0gSWHvMjIpXnWz6s2/OZ99DjHgkNYcyzgp4+D+sVSLdillkT9Wo/TNMgn+WG90G3gtKBAk9Bljhu5sGibLIU5l71AtFecNSldpVeye/cQWT+vwma0PyvjdrjUMVXGxP8vhG2NfvLE9dRUQilBCdXy1BQdpXiYtcTesXFy6WhK7ZB4V79Dkhd7BLwtwB2noMzpidvcW0A9qWygK6SCcXJpDj4QpJJ0PVMkjVjOMsBXwWc0DZbBD7+spgQgnxJJaKJ/W8iNR1mftZfIDPEVYSrplxvGIJG5h11HQaPsNIjc8zLHDmvosgrwrub+OX7/WBD6kXmo/DXzCtY9jHCmdjoYFBYTKcjJhomQShK7qytU0j2kgQtfs1ByV1D+gqfDHbt5Pfvcgluer+ANYMWoqgF/p9w== X-Forefront-Antispam-Report: CIP:216.228.112.36; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid05.nvidia.com; CAT:NONE; SFS:(4636009)(39860400002)(376002)(396003)(136003)(346002)(46966006)(36840700001)(36906005)(36860700001)(4326008)(2876002)(54906003)(82310400003)(2906002)(26005)(6666004)(47076005)(7636003)(478600001)(8676002)(2616005)(426003)(70206006)(336012)(82740400003)(6916009)(356005)(5660300002)(70586007)(8936002)(107886003)(86362001)(316002)(186003)(7696005)(36756003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 12:17:56.9995 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c97e2376-5311-4f04-6340-08d925c074ad X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.36]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY5PR12MB4275 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Dmytro Linkin Register devlink rate leaf objects per VF. Co-developed-by: Vlad Buslov Signed-off-by: Vlad Buslov Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- drivers/net/netdevsim/dev.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index ed9ce08..356287a 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -1055,11 +1055,20 @@ static int __nsim_dev_port_add(struct nsim_dev *nsim_dev, enum nsim_dev_port_typ goto err_port_debugfs_exit; } + if (nsim_dev_port_is_vf(nsim_dev_port)) { + err = devlink_rate_leaf_create(&nsim_dev_port->devlink_port, + nsim_dev_port); + if (err) + goto err_nsim_destroy; + } + devlink_port_type_eth_set(devlink_port, nsim_dev_port->ns->netdev); list_add(&nsim_dev_port->list, &nsim_dev->port_list); return 0; +err_nsim_destroy: + nsim_destroy(nsim_dev_port->ns); err_port_debugfs_exit: nsim_dev_port_debugfs_exit(nsim_dev_port); err_dl_port_unregister: @@ -1074,6 +1083,8 @@ static void __nsim_dev_port_del(struct nsim_dev_port *nsim_dev_port) struct devlink_port *devlink_port = &nsim_dev_port->devlink_port; list_del(&nsim_dev_port->list); + if (nsim_dev_port_is_vf(nsim_dev_port)) + devlink_rate_leaf_destroy(&nsim_dev_port->devlink_port); devlink_port_type_clear(devlink_port); nsim_destroy(nsim_dev_port->ns); nsim_dev_port_debugfs_exit(nsim_dev_port); From patchwork Wed Jun 2 12:17:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 453064 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 86EEFC47083 for ; Wed, 2 Jun 2021 12:18:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6D9B0613B8 for ; Wed, 2 Jun 2021 12:18:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229961AbhFBMTw (ORCPT ); Wed, 2 Jun 2021 08:19:52 -0400 Received: from mail-dm6nam10on2042.outbound.protection.outlook.com ([40.107.93.42]:51072 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229962AbhFBMTm (ORCPT ); Wed, 2 Jun 2021 08:19:42 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BaqjatNr79Yo8Lu6RN4WTqDTan5t/WHW/haMsC0N46sD/QGCD7JhUluIIRggqo5pFqz1eII40bWa/mQrBKH0f/Z3cUucrZFQ6Ao8Kf8fMI0Yitg4fPWGE1loB2PfIDH6CsRBwk+wMLYTzqlj4ANurZ3fS6EdV5wJiZIWlcpVpjQp0rQ/lZ7fvQ//6P71xn+Do3tpgqS6BrfhylTr0WVXGAKT9VlH95Fubn8TZufW0Ml1X3HbUZSjQlXZzm3vD0g+zAnWUrx4f0PldYX6nN/1j+xM6Qe/WiNd9Un3bE5yb0kl4PFnawE4chixKce1IFP1Nz54JGDjZSaV6C5TVbFz8A== 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=E+WSe9UwMbwu8YqblmRLM0HskzdUFtBQWHklUr2ts/Q=; b=Ifc3OxQjo4OzXdw4JDuPPisDog8luHvHddQI6i7jdo9Uf9moj4bH7Ucsn6gGgfkK+d2TpytF7ojsfr86dEY2RW22bzmdNjaOSh5mfLlxt4ZdJincln1HNFzYcN2/tibWhEp1cjeGzB5bm+H//hsB99CspWaaZZIOYdYHJt6UiyC4oPVEc2XCW0Hz7LiKenZ+7cC4N8mDL7PHhhOAJOkIGF7dxU8xu1Hj+1Au88T3XsEs/vcqn8phSeUhcn9Bc7/mhJqWlEiiJZrvC81a5EkuEGjZYouXk2UCIUp/l44XDCkPz2e+VkRYTMzxfQUm/eT/aS/+GKBOxHWs2I8xYBPhhg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=E+WSe9UwMbwu8YqblmRLM0HskzdUFtBQWHklUr2ts/Q=; b=G93hYVvfVj3Rk387bUvKvvZLFjMvGUL+rL6x4+Cr9XjDQiAKEMYOR8TsKh6bLaRYGU/LgYOiiYbJu2df+c4RRbE7d/pJwwa8d287+/tmL/qTo4qtodVFB4FZcWyRFuuImds8BNIaIUzh0lnC2Gl3Eysd81FsNyNLPqhizMni8KD9Ua+al54QsrjcLnjeICzdDWE66feHcJE6zWZkyz1IxX2LUQuB29CtNG6e3fD4n9kJJ8UPUyWXRkuKz/1bo+rU7LN6dNR24AXk2TM1KZ/SwiZphbhYyzQ+A80y9bq/4CMx8iB6XFTG0jdoLQ7HihzA/mOli6XlY+RZamt8IL9OcA== Received: from BN9PR03CA0107.namprd03.prod.outlook.com (2603:10b6:408:fd::22) by MN2PR12MB4335.namprd12.prod.outlook.com (2603:10b6:208:1d4::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20; Wed, 2 Jun 2021 12:17:58 +0000 Received: from BN8NAM11FT050.eop-nam11.prod.protection.outlook.com (2603:10b6:408:fd:cafe::a7) by BN9PR03CA0107.outlook.office365.com (2603:10b6:408:fd::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.15 via Frontend Transport; Wed, 2 Jun 2021 12:17:58 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT050.mail.protection.outlook.com (10.13.177.5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4150.30 via Frontend Transport; Wed, 2 Jun 2021 12:17:58 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 05:17:58 -0700 Received: from vdi.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Jun 2021 05:17:55 -0700 From: To: CC: , , , , , , , , Dmytro Linkin Subject: [PATCH RESEND net-next v3 08/18] selftest: netdevsim: Add devlink rate test Date: Wed, 2 Jun 2021 15:17:21 +0300 Message-ID: <1622636251-29892-9-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> References: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3593a8d1-6f67-4b61-6405-08d925c075a5 X-MS-TrafficTypeDiagnostic: MN2PR12MB4335: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2399; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 927RovtcTnopw6MylvuNDM3ZyF4JTeXDO1Y1LRY59AQ0KkX9EOv68t8XDCw0G4et5Z2+1OktZCfwaeE2y3GPqbXLh+mCTopSRuheozliYss7jOpv5AKkXSXZEk87iIyEmaWjS/VGuIRa+ecbh9QD/DJqE72IBJSKFL3vEVXCHFQee/nXp6pR8dwHdeczOs+seJBMOO6DWavw+RuMqlbEO2ZdN6+AUCnmoxjSf03xznSbV9H9iH2whiGYKucUb3MgZoTjCLxSrf/ZzREOr9AOuMAa+sLmzUpPIK1LnR4bV+f5wbTtzTb9+UNlVTJzNx6fzpTyp0+8nYTzbCOOfDSbau7EbN7PZN0N3TbUU/K/7i5Hzb/v1BA1GusNNDN8pSSCVu4+Ten7qzH6CeEKvzk+yGQFDk78ru9Llrb46KKGmhrx1UDpPSZ9CRtM/a4tj/3Dvq1Wjm8okakA/kQH7gOxGTgvnBbj+cb5XdJeesVUcvvAqY/zWdUMCl4RPEfEk33q7ZzEy0n9b8QPEo3Jc5tptGkkgnIRUu8rGlJIgmzJmMDTEcD+mJ8CT0kOzOf5YYw/lRX5wjdyjVG5dlfXLqSUY9yUond4gkf0/TqeSmrEdN4WGJFcPfX9zm5juraP0sVzf5NCSgEP/dqscz0rCP3Zbg== X-Forefront-Antispam-Report: CIP:216.228.112.32; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid01.nvidia.com; CAT:NONE; SFS:(4636009)(39860400002)(396003)(376002)(136003)(346002)(46966006)(36840700001)(7696005)(186003)(70206006)(356005)(7636003)(2616005)(83380400001)(426003)(6916009)(107886003)(36756003)(316002)(82310400003)(26005)(6666004)(36860700001)(2906002)(86362001)(82740400003)(54906003)(4326008)(5660300002)(478600001)(8936002)(70586007)(336012)(47076005)(2876002)(8676002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 12:17:58.5508 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3593a8d1-6f67-4b61-6405-08d925c075a5 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.32]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT050.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4335 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Dmytro Linkin Test verifies that all netdevsim VF ports have rate leaf object created by default. Co-developed-by: Vlad Buslov Signed-off-by: Vlad Buslov Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- Notes: v1->v2: - s/func/function in devlink command .../selftests/drivers/net/netdevsim/devlink.sh | 25 +++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh index 40909c2..c654be0 100755 --- a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh +++ b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh @@ -5,12 +5,13 @@ lib_dir=$(dirname $0)/../../../net/forwarding ALL_TESTS="fw_flash_test params_test regions_test reload_test \ netns_reload_test resource_test dev_info_test \ - empty_reporter_test dummy_reporter_test" + empty_reporter_test dummy_reporter_test rate_test" NUM_NETIFS=0 source $lib_dir/lib.sh BUS_ADDR=10 PORT_COUNT=4 +VF_COUNT=4 DEV_NAME=netdevsim$BUS_ADDR SYSFS_NET_DIR=/sys/bus/netdevsim/devices/$DEV_NAME/net/ DEBUGFS_DIR=/sys/kernel/debug/netdevsim/$DEV_NAME/ @@ -507,6 +508,28 @@ dummy_reporter_test() log_test "dummy reporter test" } +rate_leafs_get() +{ + local handle=$1 + + cmd_jq "devlink port function rate show -j" \ + '.[] | to_entries | .[] | select(.value.type == "leaf") | .key | select(contains("'$handle'"))' +} + +rate_test() +{ + RET=0 + + echo $VF_COUNT > /sys/bus/netdevsim/devices/$DEV_NAME/sriov_numvfs + devlink dev eswitch set $DL_HANDLE mode switchdev + local leafs=`rate_leafs_get $DL_HANDLE` + local num_leafs=`echo $leafs | wc -w` + [ "$num_leafs" == "$VF_COUNT" ] + check_err $? "Expected $VF_COUNT rate leafs but got $num_leafs" + + log_test "rate test" +} + setup_prepare() { modprobe netdevsim From patchwork Wed Jun 2 12:17:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 453926 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 5AC3DC4708F for ; Wed, 2 Jun 2021 12:18:12 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4264E60FDC for ; Wed, 2 Jun 2021 12:18:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230015AbhFBMTx (ORCPT ); Wed, 2 Jun 2021 08:19:53 -0400 Received: from mail-dm3nam07on2058.outbound.protection.outlook.com ([40.107.95.58]:11617 "EHLO NAM02-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229996AbhFBMTr (ORCPT ); Wed, 2 Jun 2021 08:19:47 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=G+R7Ai3ymiqa682baomdl5lgRBqMNjbuP8fHOdFB58RnFxu19jMtZXxLToWjsqjZrZTNiC34CY2c0v8QBypq9tqODPNJmoseuhox+pYKeKD/V8jvVQkaE5VOZ1UtZEod+yVUPWuIUrEvbsAVLwSCSe5lg3fbrgap2/UUe3eVjmc5bibdn9ITdNvuYD67/LrilH2yF0Ddd1iSpehMftMc4l0jBIzbB9/UZfAw5mxvKF7k4qMi656g8ISY3hPqixjBLayMnB9ZaBeNHHgw9n/HFMweFbrR4U683AeH+Hp1HwtfT20a3+ouV1dwJ426A0NBjsCSkv7n8lB03eC6dsF6ZQ== 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=cL3ZnTn3qGmr3iiNyXJS/cppuUvMhX78ihky9vnlb/w=; b=X5bidnka2pAsRX5ZjDyD8wQt6v7wWxnG6x6BnPR86B/ENTNqHM0WRvqQqZi8q4iZ6j8/QfrFDNiNVnx37f9BkjAt2HEircMD9FZleq9GNqN2Xx7Z/UHmz3Twc+xWVeRXxGbkZBr/EA6v3iwi2hYn2Tfb+/pF8/0fX10QJ/wHBk9rPjtJN2uTbg5UhJGeRc0j5Zq2vgvxnz75T4ym6eJpeHo7ZrH4ldz2eit6n7Z+ywMGimWwcBe53OYYy839rZJKgWkGCTkS+YtvzU2HyzDsVVKwlN69Yy6Q4lnedIQYaPAorUE7TnE7nHzdvvnOCyaAlBgQqRs/9vZs4KSSivyvRw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=cL3ZnTn3qGmr3iiNyXJS/cppuUvMhX78ihky9vnlb/w=; b=S1+czehs4WUb/i99zouKLFykrd+pjow/dwi/e2lGjAAbggyo8dLg39qFkfPnapo5mK8bAMX5/fXeJKcliXevJVSxXB9VwLbsKA5hw39WBTKmUISEPhJ4vykNzoPOsHGhW7kfbp/kCvw7MNPTXJWJpR7BwgF+UUrBgTCWMPE0KXitchCWF2cjOKXv3vLZhdDlTXXaVrvF1Q63NbrSKNlqv+HMsA09HLGcxA3FBGKtg0pTFw8Gu3R1z+Fif+m0iJubkDCFpm7BTsZFWTeAjI4ZgL3jadu1K2SFr88XDyacGVjfRx2dOy3F/LyA7bBDnt9N+oaFSFTa/xCg75Ugmvh4DA== Received: from BN7PR02CA0012.namprd02.prod.outlook.com (2603:10b6:408:20::25) by MN2PR12MB4125.namprd12.prod.outlook.com (2603:10b6:208:1d9::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20; Wed, 2 Jun 2021 12:18:03 +0000 Received: from BN8NAM11FT028.eop-nam11.prod.protection.outlook.com (2603:10b6:408:20:cafe::de) by BN7PR02CA0012.outlook.office365.com (2603:10b6:408:20::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.15 via Frontend Transport; Wed, 2 Jun 2021 12:18:03 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT028.mail.protection.outlook.com (10.13.176.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4150.30 via Frontend Transport; Wed, 2 Jun 2021 12:18:02 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 05:18:00 -0700 Received: from vdi.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Jun 2021 05:17:58 -0700 From: To: CC: , , , , , , , , Dmytro Linkin Subject: [PATCH RESEND net-next v3 09/18] devlink: Allow setting tx rate for devlink rate leaf objects Date: Wed, 2 Jun 2021 15:17:22 +0300 Message-ID: <1622636251-29892-10-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> References: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: dbf2fda0-06c7-4f25-6f9f-08d925c077c0 X-MS-TrafficTypeDiagnostic: MN2PR12MB4125: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:935; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9OBiGLhTgCDnQZR8zeb6O1ChgS6scdmbuvnp0p9COSulkMtvbYkjB+nCsWADvKXi38gwj2bHuRFgSOtuB1yOOekaLBI1BPGKEvbEOfl7GIIgYzhonew98JmPg3RPaHZ2K08E4ea1GtbztLRTAJriDxiaewJwi3rIfort73Vw5P+tBDvSc6a6ekBC5CT498HKV53PWqdDA/34l/lUOA9mC3sz8hP54m5vgz5vfLNZiC1ST2HlK+BLFFW64iUO24faPSnJE4a7eJZtj/OxDR36MQCGx8Ofn5jW3uUqobtgS2XltsfZr7RKa0eF9KPHwjjb1zjER0M5xLlQ7wFPgwQtsrjTrP5LBYpyasaLeknM3W8CeGoWtjzBB9HGr9AqXJVosf6B/EDJobKRG03zV6n27sP+ZcBNW1Vg8OqUHkarnUUK+7CWL1H8r5UE5wS6cUSfqU8jYTnD2XmTWoY0BFbyQOVqRXYPrJWDL8ktibza0l2dG1unlKK4Vwozl1bh2SLHh5txux9SgHbzL3sp3iDCYAc6BrRHAAACVWA+J1RjLvjp8ASwF73k8HG3ayqdf8dxkEBUbw0sCrPNoIeHsgNmvPFhozmprEpnhK825F3N+xZ1yiaYVyAMQtAGnhi0oTagSuIzFzmWwMDnA4YBozV1snvCc9K4ha1ESA+m/RyuPTg= X-Forefront-Antispam-Report: CIP:216.228.112.32; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid01.nvidia.com; CAT:NONE; SFS:(4636009)(136003)(376002)(396003)(346002)(39860400002)(46966006)(36840700001)(54906003)(70586007)(70206006)(8676002)(8936002)(356005)(7696005)(2876002)(82310400003)(336012)(2906002)(2616005)(86362001)(426003)(36860700001)(36756003)(107886003)(478600001)(6916009)(5660300002)(186003)(47076005)(26005)(82740400003)(6666004)(7636003)(316002)(4326008)(83380400001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 12:18:02.0945 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: dbf2fda0-06c7-4f25-6f9f-08d925c077c0 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.32]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT028.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB4125 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Dmytro Linkin Implement support for DEVLINK_CMD_RATE_SET command with new attributes DEVLINK_ATTR_RATE_TX_{SHARE|MAX} that are used to set devlink rate shared/max tx rate values. Extend devlink ops with new callbacks rate_leaf_tx_{share|max}_set() to allow supporting drivers to implement rate control through devlink. New attributes are optional. Driver implementations are allowed to support either or both of them. Shared rate example: $ devlink port function rate set netdevsim/netdevsim10/0 tx_share 10mbit $ devlink port function rate show netdevsim/netdevsim10/0 netdevsim/netdevsim10/0: type leaf tx_share 10mbit Max rate example: $ devlink port function rate set netdevsim/netdevsim10/0 tx_max 100mbit $ devlink port function rate show netdevsim/netdevsim10/0 netdevsim/netdevsim10/0: type leaf tx_max 100mbit Co-developed-by: Vlad Buslov Signed-off-by: Vlad Buslov Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- Notes: v1->v2: - s/func/function/ in devlink commands of commit message include/net/devlink.h | 10 ++++++ include/uapi/linux/devlink.h | 2 ++ net/core/devlink.c | 86 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+) diff --git a/include/net/devlink.h b/include/net/devlink.h index 2f5954d..46d5535 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -139,6 +139,8 @@ struct devlink_rate { enum devlink_rate_type type; struct devlink *devlink; void *priv; + u64 tx_share; + u64 tx_max; struct devlink_port *devlink_port; }; @@ -1465,6 +1467,14 @@ struct devlink_ops { struct devlink_port *port, enum devlink_port_fn_state state, struct netlink_ext_ack *extack); + + /** + * Rate control callbacks. + */ + int (*rate_leaf_tx_share_set)(struct devlink_rate *devlink_rate, void *priv, + u64 tx_share, struct netlink_ext_ack *extack); + int (*rate_leaf_tx_max_set)(struct devlink_rate *devlink_rate, void *priv, + u64 tx_max, struct netlink_ext_ack *extack); }; static inline void *devlink_priv(struct devlink *devlink) diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index 0c27b45..ae94cd2 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -545,6 +545,8 @@ enum devlink_attr { DEVLINK_ATTR_PORT_PCI_SF_NUMBER, /* u32 */ DEVLINK_ATTR_RATE_TYPE, /* u16 */ + DEVLINK_ATTR_RATE_TX_SHARE, /* u64 */ + DEVLINK_ATTR_RATE_TX_MAX, /* u64 */ /* add new attributes above here, update the policy in devlink.c */ __DEVLINK_ATTR_MAX, diff --git a/net/core/devlink.c b/net/core/devlink.c index 28b2490..eea1f88 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -803,6 +803,14 @@ static int devlink_nl_rate_fill(struct sk_buff *msg, goto nla_put_failure; } + if (nla_put_u64_64bit(msg, DEVLINK_ATTR_RATE_TX_SHARE, + devlink_rate->tx_share, DEVLINK_ATTR_PAD)) + goto nla_put_failure; + + if (nla_put_u64_64bit(msg, DEVLINK_ATTR_RATE_TX_MAX, + devlink_rate->tx_max, DEVLINK_ATTR_PAD)) + goto nla_put_failure; + genlmsg_end(msg, hdr); return 0; @@ -1495,6 +1503,76 @@ static int devlink_nl_cmd_port_del_doit(struct sk_buff *skb, return devlink->ops->port_del(devlink, port_index, extack); } +static int devlink_nl_rate_set(struct devlink_rate *devlink_rate, + const struct devlink_ops *ops, + struct genl_info *info) +{ + struct nlattr **attrs = info->attrs; + u64 rate; + int err; + + if (attrs[DEVLINK_ATTR_RATE_TX_SHARE]) { + rate = nla_get_u64(attrs[DEVLINK_ATTR_RATE_TX_SHARE]); + err = ops->rate_leaf_tx_share_set(devlink_rate, devlink_rate->priv, + rate, info->extack); + if (err) + return err; + devlink_rate->tx_share = rate; + } + + if (attrs[DEVLINK_ATTR_RATE_TX_MAX]) { + rate = nla_get_u64(attrs[DEVLINK_ATTR_RATE_TX_MAX]); + err = ops->rate_leaf_tx_max_set(devlink_rate, devlink_rate->priv, + rate, info->extack); + if (err) + return err; + devlink_rate->tx_max = rate; + } + + return 0; +} + +static bool devlink_rate_set_ops_supported(const struct devlink_ops *ops, + struct genl_info *info, + enum devlink_rate_type type) +{ + struct nlattr **attrs = info->attrs; + + if (type == DEVLINK_RATE_TYPE_LEAF) { + if (attrs[DEVLINK_ATTR_RATE_TX_SHARE] && !ops->rate_leaf_tx_share_set) { + NL_SET_ERR_MSG_MOD(info->extack, "TX share set isn't supported for the leafs"); + return false; + } + if (attrs[DEVLINK_ATTR_RATE_TX_MAX] && !ops->rate_leaf_tx_max_set) { + NL_SET_ERR_MSG_MOD(info->extack, "TX max set isn't supported for the leafs"); + return false; + } + } else { + WARN_ON("Unknown type of rate object"); + return false; + } + + return true; +} + +static int devlink_nl_cmd_rate_set_doit(struct sk_buff *skb, + struct genl_info *info) +{ + struct devlink_rate *devlink_rate = info->user_ptr[1]; + struct devlink *devlink = devlink_rate->devlink; + const struct devlink_ops *ops = devlink->ops; + int err; + + if (!ops || !devlink_rate_set_ops_supported(ops, info, devlink_rate->type)) + return -EOPNOTSUPP; + + err = devlink_nl_rate_set(devlink_rate, ops, info); + + if (!err) + devlink_rate_notify(devlink_rate, DEVLINK_CMD_RATE_NEW); + return err; +} + static int devlink_nl_sb_fill(struct sk_buff *msg, struct devlink *devlink, struct devlink_sb *devlink_sb, enum devlink_command cmd, u32 portid, @@ -7958,6 +8036,8 @@ static int devlink_nl_cmd_trap_policer_set_doit(struct sk_buff *skb, [DEVLINK_ATTR_PORT_PCI_SF_NUMBER] = { .type = NLA_U32 }, [DEVLINK_ATTR_PORT_CONTROLLER_NUMBER] = { .type = NLA_U32 }, [DEVLINK_ATTR_RATE_TYPE] = { .type = NLA_U16 }, + [DEVLINK_ATTR_RATE_TX_SHARE] = { .type = NLA_U64 }, + [DEVLINK_ATTR_RATE_TX_MAX] = { .type = NLA_U64 }, }; static const struct genl_small_ops devlink_nl_ops[] = { @@ -7991,6 +8071,12 @@ static int devlink_nl_cmd_trap_policer_set_doit(struct sk_buff *skb, /* can be retrieved by unprivileged users */ }, { + .cmd = DEVLINK_CMD_RATE_SET, + .doit = devlink_nl_cmd_rate_set_doit, + .flags = GENL_ADMIN_PERM, + .internal_flags = DEVLINK_NL_FLAG_NEED_RATE, + }, + { .cmd = DEVLINK_CMD_PORT_SPLIT, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = devlink_nl_cmd_port_split_doit, From patchwork Wed Jun 2 12:17:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 453925 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 A5C37C4708F for ; Wed, 2 Jun 2021 12:18:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9024D613BA for ; Wed, 2 Jun 2021 12:18:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230048AbhFBMTz (ORCPT ); Wed, 2 Jun 2021 08:19:55 -0400 Received: from mail-mw2nam12on2065.outbound.protection.outlook.com ([40.107.244.65]:27360 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230025AbhFBMTt (ORCPT ); Wed, 2 Jun 2021 08:19:49 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SS9prnkc2o7RGN2yEGSuCUteHHFNLmOOliUypUDrREQUjhvX2vv00habhcE12+9O/GZY4YUMKw79shKAu47CoI/qOBZhEMADRsbkA5XVDYvV2hOFuWEDebYkBvAjAGHBuOU/WG1OA39dR3Xcp75pQeI43pwLkqHFdjotu4Wu68Va7UdOssYdEZXw+rEPdTi59Fepb47tbpAMUESuNObRPQ8Y8Vwj/Rh6k2Of0ZFDs2nhB7gnTC7AWHdaKs7jWA9X83XJi2t7lZQscHBInw2AgIzDNrT5R3kLdXzAWd73+UUfRw3B2xV2MaCLLK92yKsSWFGx/I/7E/Jw3qkSXBTkKA== 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=Wt66aTPIoM3XVpKVU/8eW/w+SOJnPQe9QlO9+MlIB/Y=; b=OMuOEEFaEC+IDbp/qKSzwARjVI5RaZ7Px54kS7MtQ8uDyCGWF60x3YlS/khqLDf501MKZ2BDv1MZsESHOvo8QGiV58MlkgxKeESA7t1CPZOpwd91R5mQIEcK4oMe8w1OgJk8n2J1kb77wit15vIBGZIiBEgSHFL8bEVyIpXKuKQUL5qNLw5yy7oIt+gMMh1gZRJuATnRVNBrGw6to0Ns+KSA2EqgFSdjmG7DSd8+6Rj8s8fXDlVmJRUOJSUOSf8Fp/ySqgHHEmLFL3Qt/kzKGb3KSrvsX/k/IH5cTfpk2BN1zMuDm8T6dYsjIkyWN2cuDBAEls5pqAxQUbloua8H0A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Wt66aTPIoM3XVpKVU/8eW/w+SOJnPQe9QlO9+MlIB/Y=; b=MHfTtEwi/CCHR0sAg6F+loPll+G95eVG6HG5z8fMQfwKj1trlx/3R14YOuS/ws6n0ZII/wPOMf7a3EGKPLuZiTlf9cPzo3hpdHGDFerfA092xBG8fIRTtgnHKS4p5rKag8Icu7+T1TO/S6sS/6LwyajqffFZC8zNCyGIIQ15hfXc9kriIYzSek84qU+Rahp4IlNIpCb2OJvR3KgGylilurxpZKKeF6D/2XO0WDaWeRjZsnF+b0U6PcaMHuZufQ51gIXElDw1Drvr++gkCtqpWYTxS0iptsKt+mnZ37T4fzwOBnBH/3lD6FNC6tLV2jBiG17sI/31wtLQLUnNDltUdA== Received: from BN7PR02CA0004.namprd02.prod.outlook.com (2603:10b6:408:20::17) by BYAPR12MB4709.namprd12.prod.outlook.com (2603:10b6:a03:98::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.22; Wed, 2 Jun 2021 12:18:05 +0000 Received: from BN8NAM11FT028.eop-nam11.prod.protection.outlook.com (2603:10b6:408:20:cafe::36) by BN7PR02CA0004.outlook.office365.com (2603:10b6:408:20::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.20 via Frontend Transport; Wed, 2 Jun 2021 12:18:04 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT028.mail.protection.outlook.com (10.13.176.225) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4150.30 via Frontend Transport; Wed, 2 Jun 2021 12:18:04 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 05:18:03 -0700 Received: from vdi.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Jun 2021 05:18:01 -0700 From: To: CC: , , , , , , , , Dmytro Linkin Subject: [PATCH RESEND net-next v3 10/18] netdevsim: Implement devlink rate leafs tx rate support Date: Wed, 2 Jun 2021 15:17:23 +0300 Message-ID: <1622636251-29892-11-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> References: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c296f269-5591-4694-3985-08d925c07958 X-MS-TrafficTypeDiagnostic: BYAPR12MB4709: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:166; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: oyYL5vNelPv5DEcfAteEcD3LhhJyZHteK208toB7svqr92qq8OJi074qrD7MWKl0YAxQ586mmTEk4qKc8EsppqtewpBYwpRoZb+SzbEoLfFRH8UlA2od+9qnJH3qdELAfZfGDBZV1QBjeiB+IxiY+z+roR4VGZykhfpyAq8IiesgcNOzd75yxBHZrt5hgxxF5OlDSrkIG9djT5PX6zdenzMzlgb3pewuE7TXFfkCOEvy6StXDzQ/HAFQvtO1pIyABIgr5oZUNmFuZtR1jvbBlbVvR4r4dWjNkuwiAPPBc45TMMNyuNyyHI8kHXEiyY6uCT7bz9QiKGJBZpquQMfDLaU18ZmuBBYXnien1uj0E04Xvf2I5Qke39yZL8DCfc1MoE2dKqDA0kdQA7w/95ryhFvFl6zGXm7mirQqTViSNR4wXJIvfHpHXwyu5mDtxWv1A8T/qPW30adQNaDADA5NbPejNb0ARGNC+e0dykuMa/vdYqtqBpln3x3Ho0CeJQ3Nc491pvu/RJ9881eI5kE9SiildEydnwnusX6Ei18Iv9xjcRAz8zUVelXW0x7FXc6iuAuYsBHmjh+NCX6712g28Mn/FV3kUmfdCElWH1pZvnTxMjtzzoHCFC5p/J2X1JpeWVk8ivJU0V8yaXSwZ+KSC4jleCHeVut7zOojyc0tw9w= X-Forefront-Antispam-Report: CIP:216.228.112.32; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid01.nvidia.com; CAT:NONE; SFS:(4636009)(39860400002)(346002)(396003)(376002)(136003)(46966006)(36840700001)(83380400001)(82310400003)(478600001)(107886003)(336012)(5660300002)(8936002)(6916009)(4326008)(2616005)(426003)(2876002)(36756003)(186003)(6666004)(36860700001)(86362001)(54906003)(7696005)(316002)(2906002)(26005)(82740400003)(70586007)(7636003)(356005)(47076005)(8676002)(70206006); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 12:18:04.7550 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c296f269-5591-4694-3985-08d925c07958 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.32]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT028.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB4709 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Dmytro Linkin Implement new devlink ops that allow shared and max tx rate control for devlink port rate objects (leafs) through devlink API. Expose rate values of VF ports to netdevsim debugfs. Co-developed-by: Vlad Buslov Signed-off-by: Vlad Buslov Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- drivers/net/netdevsim/dev.c | 78 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 75 insertions(+), 3 deletions(-) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 356287a..5be6f7e 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -276,17 +276,26 @@ static void nsim_dev_debugfs_exit(struct nsim_dev *nsim_dev) static int nsim_dev_port_debugfs_init(struct nsim_dev *nsim_dev, struct nsim_dev_port *nsim_dev_port) { + struct nsim_bus_dev *nsim_bus_dev = nsim_dev->nsim_bus_dev; + unsigned int port_index = nsim_dev_port->port_index; char port_ddir_name[16]; char dev_link_name[32]; - sprintf(port_ddir_name, "%u", nsim_dev_port->port_index); + sprintf(port_ddir_name, "%u", port_index); nsim_dev_port->ddir = debugfs_create_dir(port_ddir_name, nsim_dev->ports_ddir); if (IS_ERR(nsim_dev_port->ddir)) return PTR_ERR(nsim_dev_port->ddir); - sprintf(dev_link_name, "../../../" DRV_NAME "%u", - nsim_dev->nsim_bus_dev->dev.id); + sprintf(dev_link_name, "../../../" DRV_NAME "%u", nsim_bus_dev->dev.id); + if (nsim_dev_port_is_vf(nsim_dev_port)) { + unsigned int vf_id = nsim_dev_port_index_to_vf_index(port_index); + + debugfs_create_u16("tx_share", 0400, nsim_dev_port->ddir, + &nsim_bus_dev->vfconfigs[vf_id].min_tx_rate); + debugfs_create_u16("tx_max", 0400, nsim_dev_port->ddir, + &nsim_bus_dev->vfconfigs[vf_id].max_tx_rate); + } debugfs_create_symlink("dev", nsim_dev_port->ddir, dev_link_name); return 0; @@ -990,6 +999,67 @@ static int nsim_dev_devlink_trap_init(struct devlink *devlink, return 0; } +#define NSIM_LINK_SPEED_MAX 5000 /* Mbps */ +#define NSIM_LINK_SPEED_UNIT 125000 /* 1 Mbps given in bytes/sec to avoid + * u64 overflow during conversion from + * bytes to bits. + */ + +static int nsim_rate_bytes_to_units(char *name, u64 *rate, struct netlink_ext_ack *extack) +{ + u64 val; + u32 rem; + + val = div_u64_rem(*rate, NSIM_LINK_SPEED_UNIT, &rem); + if (rem) { + pr_err("%s rate value %lluBps not in link speed units of 1Mbps.\n", + name, *rate); + NL_SET_ERR_MSG_MOD(extack, "TX rate value not in link speed units of 1Mbps."); + return -EINVAL; + } + + if (val > NSIM_LINK_SPEED_MAX) { + pr_err("%s rate value %lluMbps exceed link maximum speed 5000Mbps.\n", + name, val); + NL_SET_ERR_MSG_MOD(extack, "TX rate value exceed link maximum speed 5000Mbps."); + return -EINVAL; + } + *rate = val; + return 0; +} + +static int nsim_leaf_tx_share_set(struct devlink_rate *devlink_rate, void *priv, + u64 tx_share, struct netlink_ext_ack *extack) +{ + struct nsim_dev_port *nsim_dev_port = priv; + struct nsim_bus_dev *nsim_bus_dev = nsim_dev_port->ns->nsim_bus_dev; + int vf_id = nsim_dev_port_index_to_vf_index(nsim_dev_port->port_index); + int err; + + err = nsim_rate_bytes_to_units("tx_share", &tx_share, extack); + if (err) + return err; + + nsim_bus_dev->vfconfigs[vf_id].min_tx_rate = tx_share; + return 0; +} + +static int nsim_leaf_tx_max_set(struct devlink_rate *devlink_rate, void *priv, + u64 tx_max, struct netlink_ext_ack *extack) +{ + struct nsim_dev_port *nsim_dev_port = priv; + struct nsim_bus_dev *nsim_bus_dev = nsim_dev_port->ns->nsim_bus_dev; + int vf_id = nsim_dev_port_index_to_vf_index(nsim_dev_port->port_index); + int err; + + err = nsim_rate_bytes_to_units("tx_max", &tx_max, extack); + if (err) + return err; + + nsim_bus_dev->vfconfigs[vf_id].max_tx_rate = tx_max; + return 0; +} + static const struct devlink_ops nsim_dev_devlink_ops = { .eswitch_mode_set = nsim_devlink_eswitch_mode_set, .eswitch_mode_get = nsim_devlink_eswitch_mode_get, @@ -1005,6 +1075,8 @@ static int nsim_dev_devlink_trap_init(struct devlink *devlink, .trap_group_set = nsim_dev_devlink_trap_group_set, .trap_policer_set = nsim_dev_devlink_trap_policer_set, .trap_policer_counter_get = nsim_dev_devlink_trap_policer_counter_get, + .rate_leaf_tx_share_set = nsim_leaf_tx_share_set, + .rate_leaf_tx_max_set = nsim_leaf_tx_max_set, }; #define NSIM_DEV_MAX_MACS_DEFAULT 32 From patchwork Wed Jun 2 12:17:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 453063 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 0EA92C47083 for ; Wed, 2 Jun 2021 12:18:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E79A5613D6 for ; Wed, 2 Jun 2021 12:18:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230063AbhFBMUE (ORCPT ); Wed, 2 Jun 2021 08:20:04 -0400 Received: from mail-mw2nam10on2087.outbound.protection.outlook.com ([40.107.94.87]:41985 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229989AbhFBMTx (ORCPT ); Wed, 2 Jun 2021 08:19:53 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jmkUUL1C2bZp6ypUXcQK1Qkw8YE7TC32AuFS+jIXwdlRyexKyQNGHM8Eci1g9LzF8tMWA3xYXyvAUtEJsm6Z9t6U2OTzCv9U7MxzwLX1OX5UOGBTuVU+zcLav2mOLEI4olyk5ucEN2chqd5psf1B5OCFpFO8igTBuj+Qa/QExSFxmdvOWJAIhVRh2R3vKMHJ98FK/JZuG13RL3shLG3/jO71p76EcSO0MWvg1MnQeTUrjWMRbjHYoC8waAA+X09kDqN0IzAiesOZus7g8xN8UGbIy4CwvFSg/IM79Ts1PLWTFu6usPxifYTplbx82YAnY9N3XgT1njcX2I0zEyZ03A== 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=1JZM9C8cvD2UVV84x0mxd9HVJHTmhdrJcwzwdvwuD8w=; b=CYcViaRI20UTO3d37pbKlqcTr5uoJxrxWpcYjsPjfHmt0CEh20KPLNkzmC/8UzyB3lOfNjTEz+BV8K3bTrAZajzWzhBZWpO/jX6EPQhugjx7luN/S7QsiIZooxTvUz4J3vARrcoNslohRMH5dZ6dmK+oNUo20WzvZazZtkK0ZbPgAGY3j3LmSX0IGHe3OYAFlK2BA57QwtwlewS7s8m7DMmin2gdoqwgr244gEkWxHBjkZQHvzC/puQOu8GqGGgBj3Z8pUlAsPVHIDTgiXg3dWG4N3Gcpqt5gDgsRn8LRnz4l/dUFOoD2F0SvSAQeUw1zHWCNnEX9GgtQVXBJdgHvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1JZM9C8cvD2UVV84x0mxd9HVJHTmhdrJcwzwdvwuD8w=; b=oHPEuwS+Nt2B77oitWj2N7IHtwuG9jG3eYIdnJtKBkmPzgc/E/M+u6uQF1dNOHaFgngyA5gdwwJuDsaWdfYHjtKlSxT3sGB7iFLnikYAQPn20qKZFS5LPkz1tRmFIkN+z8qaTI9/jyKd7lzq6kQI2xwPDVWiu7EonjUFHZV7mtw6CfNm/9BDRCEhdy1LYhfwXEwub6mikhNxqkfQUav6V/tFT0OE8aIMx8dKItmkLcf5if4halXj8TR4WqX0Z1oa+uk46RkdEy+xPoqPEHGcorYvxHCB0RWeCctKhw/L2PeXoYjWy03mocs8OhhagIoN/WYyWbILufa0IlNM6jNFrA== Received: from MW4PR03CA0351.namprd03.prod.outlook.com (2603:10b6:303:dc::26) by MN2PR12MB3229.namprd12.prod.outlook.com (2603:10b6:208:102::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.22; Wed, 2 Jun 2021 12:18:07 +0000 Received: from CO1NAM11FT033.eop-nam11.prod.protection.outlook.com (2603:10b6:303:dc:cafe::ea) by MW4PR03CA0351.outlook.office365.com (2603:10b6:303:dc::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.22 via Frontend Transport; Wed, 2 Jun 2021 12:18:07 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by CO1NAM11FT033.mail.protection.outlook.com (10.13.174.247) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4150.30 via Frontend Transport; Wed, 2 Jun 2021 12:18:07 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 12:18:06 +0000 Received: from vdi.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Jun 2021 05:18:04 -0700 From: To: CC: , , , , , , , , Dmytro Linkin Subject: [PATCH RESEND net-next v3 11/18] selftest: netdevsim: Add devlink port shared/max tx rate test Date: Wed, 2 Jun 2021 15:17:24 +0300 Message-ID: <1622636251-29892-12-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> References: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: c849726b-5df9-46ad-26ce-08d925c07b01 X-MS-TrafficTypeDiagnostic: MN2PR12MB3229: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:4714; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Zvg0vH58v58xXtse/0gjik8UvmoMrjvEdelPAQKRgJdufZ3YHc2+g+ztV1OYc+KkQJmEvlmRIDr2+DN1srexMMjYKVcqweysHsYSBkqbiu7R+3uyxHN4mHv+C0xXI10xKt0b1aS2Ug8fnzCoTLPNggSSmyiTJflx3A7BkVRt8bfvaNX8Mh/4ykHI8vjjMkz+Jp64eT0QSgKwhtj98ftTHjBx11zrlIBNSqZ5jwGsBGjjToN5nITPK6xYRy+PR40dnA5VuaDaa8dl2gehplP7R4/a2DHSYWKYKQ6suZgDufL2IxxF8KwqHRBFD+exlJUrRbjP6IlFPcxSAstUIDiZ7A0sa69/NLizOrs8D1hUUlt63TxZWBddb52PyE226sOhcr83yGVmH4z/L8haIuK2RzpoxEO9stF48/R7IZQ3i2RCLOu1KPDEmld7cRjT4fObsgvlAJJPjO7bKAtpUvRewDXvC9klItbaHJ3pg3/8Nn8GyEBrBgOLj76qEsNcOOdciVBDFdMimrYKIieS0jykL96/VYrXbk/Uh3EGU94bvHsxnhW1oAO0GFUD0kXmbwQId8eaqYlg6cpiv3ZCjASNt0jwADzAErBO/tBVUrE8tREK1nIbYvnVLR2+JZW4QcYC/zlREu8GjiJWNyFUfwVscQ== X-Forefront-Antispam-Report: CIP:216.228.112.35; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid02.nvidia.com; CAT:NONE; SFS:(4636009)(396003)(136003)(39860400002)(346002)(376002)(46966006)(36840700001)(316002)(36906005)(5660300002)(54906003)(2906002)(478600001)(2876002)(2616005)(7696005)(36860700001)(4326008)(426003)(26005)(47076005)(8936002)(82310400003)(107886003)(356005)(7636003)(6916009)(6666004)(8676002)(82740400003)(70586007)(336012)(36756003)(70206006)(86362001)(186003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 12:18:07.6257 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: c849726b-5df9-46ad-26ce-08d925c07b01 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.35]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT033.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3229 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Dmytro Linkin Test verifies that netdevsim VFs can set and retrieve shared/max tx rate through new devlink API. Co-developed-by: Vlad Buslov Signed-off-by: Vlad Buslov Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- Notes: v1->v2: - s/func/function/ in devlink commands .../selftests/drivers/net/netdevsim/devlink.sh | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh index c654be0..05dcefc 100755 --- a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh +++ b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh @@ -516,6 +516,45 @@ rate_leafs_get() '.[] | to_entries | .[] | select(.value.type == "leaf") | .key | select(contains("'$handle'"))' } +rate_attr_set() +{ + local handle=$1 + local name=$2 + local value=$3 + local units=$4 + + devlink port function rate set $handle $name $value$units +} + +rate_attr_get() +{ + local handle=$1 + local name=$2 + + cmd_jq "devlink port function rate show $handle -j" '.[][].'$name +} + +rate_attr_tx_rate_check() +{ + local handle=$1 + local name=$2 + local rate=$3 + local debug_file=$4 + + rate_attr_set $handle $name $rate mbit + check_err $? "Failed to set $name value" + + local debug_value=$(cat $debug_file) + check_err $? "Failed to read $name value from debugfs" + [ "$debug_value" == "$rate" ] + check_err $? "Unexpected $name debug value $debug_value != $rate" + + local api_value=$(( $(rate_attr_get $handle $name) * 8 / 1000000 )) + check_err $? "Failed to get $name attr value" + [ "$api_value" == "$rate" ] + check_err $? "Unexpected $name attr value $api_value != $rate" +} + rate_test() { RET=0 @@ -527,6 +566,22 @@ rate_test() [ "$num_leafs" == "$VF_COUNT" ] check_err $? "Expected $VF_COUNT rate leafs but got $num_leafs" + rate=10 + for r_obj in $leafs + do + rate_attr_tx_rate_check $r_obj tx_share $rate \ + $DEBUGFS_DIR/ports/${r_obj##*/}/tx_share + rate=$(($rate+10)) + done + + rate=100 + for r_obj in $leafs + do + rate_attr_tx_rate_check $r_obj tx_max $rate \ + $DEBUGFS_DIR/ports/${r_obj##*/}/tx_max + rate=$(($rate+100)) + done + log_test "rate test" } From patchwork Wed Jun 2 12:17:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 453924 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 D01D6C4708F for ; Wed, 2 Jun 2021 12:18:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B8954613DE for ; Wed, 2 Jun 2021 12:18:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229626AbhFBMUL (ORCPT ); Wed, 2 Jun 2021 08:20:11 -0400 Received: from mail-dm6nam10on2077.outbound.protection.outlook.com ([40.107.93.77]:5088 "EHLO NAM10-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230046AbhFBMTz (ORCPT ); Wed, 2 Jun 2021 08:19:55 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HXk5RGvU6zt9g7QmWfhxnCo1TPbjxdQkdVtkcJWdCODDRJ0+baBVA0EuOjPQXgtKYmZs8HCl2WmxnX2KVgZXfcwQ66cKOLbAH6wRJDjMAb2TnHdgTJJYKjebs/ixfOpJ4gSCQwNVXzqMUgHWpDO9e9MnuQPySMwRTXKLfdY9XmP/jTY4bXTuZDhlfHFTC9vHZ1UINlDLLLtdIobJRHWYl+j1GB+aqoq8Q60UFci22zMH09oO/QVP8YtHGnTcvzWmL6UpZHoDBb6wBkKgiWgVPnKm+LaU5Fsb4Bs5UOPQxVwcfC0dWCZHRk3IKcJB14FbCrfey5xPr6XESHxsonYlog== 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=8GZVow037A9RI/Vs6/gtHQGW9Dr2Q9gdKBHu21DPjtg=; b=lIsksNJO4OhfC6VDFd/xQf+uzZOli5elhpE20ceQClXTVejjnpYMarHVKfIcp7K2CsAkDvaXCM9OrkD1h9CtAg4PpJ8fYpoKPBlBHj3APr/Q1c2fmVPvW+wTZ6N4DQLdAJqAMtzwtE0RL5AxUXjEnXy1tfiUvRD2OZ0NqeJGzpmHE42pg/HVu4a8CAS5w528Wi1sE2qlit2jQSBns9ibdRZXpxmCS+FqUstMlM+CBK3FUC3E5KuDficAhbzbKo0KIUpntbQjn1fXPPMpz4QAPBCUTd74MX0N4jynSYvawQb0AiNFK7UPqVS54IDZDPwoTrgz+0Uv0jOPPtOghlYCKQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.36) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=8GZVow037A9RI/Vs6/gtHQGW9Dr2Q9gdKBHu21DPjtg=; b=KkrtXNvS7TG8eFPGhdZfhcdhDhmFOdplzYoZtrItbsmXTowC/YHZIoBFp1ZTwiUgIGpbRqYkhqGNK6suXosokVu0Bs7eCp0r18sh/1xZi1mverTgVpC3kT1oALlXRgdnXxSzejyK0v3d15b5tuN8UYpsQJGM/NxQQ2sWXkAd0qtJA/B4p1kApvMLuJrqGNVxBay+QVdKqId0TThk7amToctd1Wavo8C4NLP6GE21EGvvbNPellxklYuDeq3q/liXJQaJeDNCxUiMJn+F2jC41mKn13k2MgEdCgWqD3msmsViw2QJr+kSGCFXewkNLACfyA4mmEH6Hud/1IWSkq9WFA== Received: from MWHPR04CA0033.namprd04.prod.outlook.com (2603:10b6:300:ee::19) by BN8PR12MB3249.namprd12.prod.outlook.com (2603:10b6:408:68::28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.26; Wed, 2 Jun 2021 12:18:11 +0000 Received: from CO1NAM11FT034.eop-nam11.prod.protection.outlook.com (2603:10b6:300:ee:cafe::d2) by MWHPR04CA0033.outlook.office365.com (2603:10b6:300:ee::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.22 via Frontend Transport; Wed, 2 Jun 2021 12:18:10 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.36) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.36 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.36; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.36) by CO1NAM11FT034.mail.protection.outlook.com (10.13.174.248) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4150.30 via Frontend Transport; Wed, 2 Jun 2021 12:18:10 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL101.nvidia.com (172.20.187.10) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 12:18:09 +0000 Received: from vdi.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Jun 2021 05:18:07 -0700 From: To: CC: , , , , , , , , Dmytro Linkin Subject: [PATCH RESEND net-next v3 12/18] devlink: Introduce rate nodes Date: Wed, 2 Jun 2021 15:17:25 +0300 Message-ID: <1622636251-29892-13-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> References: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f139c11d-f1c3-4796-314b-08d925c07cd2 X-MS-TrafficTypeDiagnostic: BN8PR12MB3249: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:62; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: kVCvyVwXMXuxl442GkTsM0qCipmE93p5YdIeioMKOTaktJrUGcELk/9SMZvP39Gesi3UNaOkoPU/Ut6EjGOYRdPwcDsD3OHMxtvnjo8SHA1vkPB/69zuFUZeOlzJq+ol3nH2jBd77ofH2MOvlTbjpeLZ90eUcxkrt3TRShMEJCuObpQq22I2bQe3ND1fs18CmANA9HaBkeuh87DVRrSbx3EhORP4lwCCwbulqNny3jvXQ9npEWC9+CRAfj5myGL0vDPhd7fKCXWfiPgbeow1MYIZQBCYhtBakHrMV1THUMfwVGZnzPNDBN5GCzL90HZ/7QUyT3XXnEwYtrh9BHGSfeNUIh5bbXy4cY0sjSdeTrh/xspyf0SYYbwK4hu6RJkEH03pxrxUYqqGr4LaYvVudapF/JUXKZ3WAcoLMP4cMfGo2wH6Brx88/8/K9+ZDJngRQ9fEIOa1IbbaDq8YF4Ei7jXKMw3nKAkGmfne22nwPGenbMgSHVKIetzN0/GTmzia1DEg/q2R+/7wguYaeuhrCujoeAhM53YAKDZWn1imzR670WObXZQ9DqfrYb+H97mJk4pPb9kef+yqU2fXZ0I0jqLEtQmr5Dz23jpsEi0BW7MEe7UkIXrMq9PTqaq92CYExUvnw78Qnfyq6IgRIeuKKJqkfQNFXtKEdJicOMXHZA= X-Forefront-Antispam-Report: CIP:216.228.112.36; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid05.nvidia.com; CAT:NONE; SFS:(4636009)(136003)(39860400002)(346002)(396003)(376002)(46966006)(36840700001)(478600001)(70586007)(4326008)(70206006)(86362001)(2906002)(36860700001)(82310400003)(36756003)(47076005)(54906003)(6916009)(36906005)(316002)(2616005)(356005)(336012)(5660300002)(2876002)(30864003)(426003)(6666004)(82740400003)(26005)(186003)(83380400001)(7636003)(107886003)(8936002)(7696005)(8676002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 12:18:10.6585 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f139c11d-f1c3-4796-314b-08d925c07cd2 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.36]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT034.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR12MB3249 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Dmytro Linkin Implement support for DEVLINK_CMD_RATE_{NEW|DEL} commands that are used to create and delete devlink rate nodes. Add new attribute DEVLINK_ATTR_RATE_NODE_NAME that specify node name string. The node name is an alphanumeric identifier. No valid node name can be a devlink port index, eg. decimal number. Extend devlink ops with new callbacks rate_node_{new|del}() and rate_node_tx_{share|max}_set() to allow supporting drivers to implement ports rate grouping and setting tx rate of rate nodes through devlink. Expose devlink_rate_nodes_destroy() function to allow vendor driver do proper cleanup of internally allocated resources for the nodes if the driver goes down or due to any other reasons which requires nodes to be destroyed. Disallow moving device from switchdev to legacy mode if any node exists on that device. User must explicitly delete nodes before switching mode. Example: $ devlink port function rate add netdevsim/netdevsim10/group1 $ devlink port function rate set netdevsim/netdevsim10/group1 \ tx_share 10mbit tx_max 100mbit Add + set command can be combined: $ devlink port function rate add netdevsim/netdevsim10/group1 \ tx_share 10mbit tx_max 100mbit $ devlink port function rate show netdevsim/netdevsim10/group1 netdevsim/netdevsim10/group1: type node tx_share 10mbit tx_max 100mbit $ devlink port function rate del netdevsim/netdevsim10/group1 Co-developed-by: Vlad Buslov Signed-off-by: Vlad Buslov Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- Notes: v1->v2: - s/func/function/ at commit message v2->v3: - added devlink_rate_nodes_destroy() include/net/devlink.h | 14 ++- include/uapi/linux/devlink.h | 3 + net/core/devlink.c | 238 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 247 insertions(+), 8 deletions(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index 46d5535..13162b5 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -142,7 +142,10 @@ struct devlink_rate { u64 tx_share; u64 tx_max; - struct devlink_port *devlink_port; + union { + struct devlink_port *devlink_port; + char *name; + }; }; struct devlink_port { @@ -1475,6 +1478,14 @@ struct devlink_ops { u64 tx_share, struct netlink_ext_ack *extack); int (*rate_leaf_tx_max_set)(struct devlink_rate *devlink_rate, void *priv, u64 tx_max, struct netlink_ext_ack *extack); + int (*rate_node_tx_share_set)(struct devlink_rate *devlink_rate, void *priv, + u64 tx_share, struct netlink_ext_ack *extack); + int (*rate_node_tx_max_set)(struct devlink_rate *devlink_rate, void *priv, + u64 tx_max, struct netlink_ext_ack *extack); + int (*rate_node_new)(struct devlink_rate *rate_node, void **priv, + struct netlink_ext_ack *extack); + int (*rate_node_del)(struct devlink_rate *rate_node, void *priv, + struct netlink_ext_ack *extack); }; static inline void *devlink_priv(struct devlink *devlink) @@ -1536,6 +1547,7 @@ void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, bool external); int devlink_rate_leaf_create(struct devlink_port *port, void *priv); void devlink_rate_leaf_destroy(struct devlink_port *devlink_port); +void devlink_rate_nodes_destroy(struct devlink *devlink); int devlink_sb_register(struct devlink *devlink, unsigned int sb_index, u32 size, u16 ingress_pools_count, u16 egress_pools_count, u16 ingress_tc_count, diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index ae94cd2..7e15853 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -213,6 +213,7 @@ enum devlink_port_flavour { enum devlink_rate_type { DEVLINK_RATE_TYPE_LEAF, + DEVLINK_RATE_TYPE_NODE, }; enum devlink_param_cmode { @@ -547,6 +548,8 @@ enum devlink_attr { DEVLINK_ATTR_RATE_TYPE, /* u16 */ DEVLINK_ATTR_RATE_TX_SHARE, /* u64 */ DEVLINK_ATTR_RATE_TX_MAX, /* u64 */ + DEVLINK_ATTR_RATE_NODE_NAME, /* string */ + /* add new attributes above here, update the policy in devlink.c */ __DEVLINK_ATTR_MAX, diff --git a/net/core/devlink.c b/net/core/devlink.c index eea1f88..d520fb5 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -196,6 +196,12 @@ static struct devlink_port *devlink_port_get_from_info(struct devlink *devlink, return devlink_rate->type == DEVLINK_RATE_TYPE_LEAF; } +static inline bool +devlink_rate_is_node(struct devlink_rate *devlink_rate) +{ + return devlink_rate->type == DEVLINK_RATE_TYPE_NODE; +} + static struct devlink_rate * devlink_rate_leaf_get_from_info(struct devlink *devlink, struct genl_info *info) { @@ -209,6 +215,55 @@ static struct devlink_port *devlink_port_get_from_info(struct devlink *devlink, return devlink_rate ?: ERR_PTR(-ENODEV); } +static struct devlink_rate * +devlink_rate_node_get_by_name(struct devlink *devlink, const char *node_name) +{ + static struct devlink_rate *devlink_rate; + + list_for_each_entry(devlink_rate, &devlink->rate_list, list) { + if (devlink_rate_is_node(devlink_rate) && + !strcmp(node_name, devlink_rate->name)) + return devlink_rate; + } + return ERR_PTR(-ENODEV); +} + +static struct devlink_rate * +devlink_rate_node_get_from_attrs(struct devlink *devlink, struct nlattr **attrs) +{ + const char *rate_node_name; + size_t len; + + if (!attrs[DEVLINK_ATTR_RATE_NODE_NAME]) + return ERR_PTR(-EINVAL); + rate_node_name = nla_data(attrs[DEVLINK_ATTR_RATE_NODE_NAME]); + len = strlen(rate_node_name); + /* Name cannot be empty or decimal number */ + if (!len || strspn(rate_node_name, "0123456789") == len) + return ERR_PTR(-EINVAL); + + return devlink_rate_node_get_by_name(devlink, rate_node_name); +} + +static struct devlink_rate * +devlink_rate_node_get_from_info(struct devlink *devlink, struct genl_info *info) +{ + return devlink_rate_node_get_from_attrs(devlink, info->attrs); +} + +static struct devlink_rate * +devlink_rate_get_from_info(struct devlink *devlink, struct genl_info *info) +{ + struct nlattr **attrs = info->attrs; + + if (attrs[DEVLINK_ATTR_PORT_INDEX]) + return devlink_rate_leaf_get_from_info(devlink, info); + else if (attrs[DEVLINK_ATTR_RATE_NODE_NAME]) + return devlink_rate_node_get_from_info(devlink, info); + else + return ERR_PTR(-EINVAL); +} + struct devlink_sb { struct list_head list; unsigned int index; @@ -428,12 +483,13 @@ struct devlink_snapshot { #define DEVLINK_NL_FLAG_NEED_PORT BIT(0) #define DEVLINK_NL_FLAG_NEED_DEVLINK_OR_PORT BIT(1) #define DEVLINK_NL_FLAG_NEED_RATE BIT(2) +#define DEVLINK_NL_FLAG_NEED_RATE_NODE BIT(3) /* The per devlink instance lock is taken by default in the pre-doit * operation, yet several commands do not require this. The global * devlink lock is taken and protects from disruption by user-calls. */ -#define DEVLINK_NL_FLAG_NO_LOCK BIT(3) +#define DEVLINK_NL_FLAG_NO_LOCK BIT(4) static int devlink_nl_pre_doit(const struct genl_ops *ops, struct sk_buff *skb, struct genl_info *info) @@ -465,12 +521,21 @@ static int devlink_nl_pre_doit(const struct genl_ops *ops, } else if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_RATE) { struct devlink_rate *devlink_rate; - devlink_rate = devlink_rate_leaf_get_from_info(devlink, info); + devlink_rate = devlink_rate_get_from_info(devlink, info); if (IS_ERR(devlink_rate)) { err = PTR_ERR(devlink_rate); goto unlock; } info->user_ptr[1] = devlink_rate; + } else if (ops->internal_flags & DEVLINK_NL_FLAG_NEED_RATE_NODE) { + struct devlink_rate *rate_node; + + rate_node = devlink_rate_node_get_from_info(devlink, info); + if (IS_ERR(rate_node)) { + err = PTR_ERR(rate_node); + goto unlock; + } + info->user_ptr[1] = rate_node; } return 0; @@ -801,6 +866,10 @@ static int devlink_nl_rate_fill(struct sk_buff *msg, if (nla_put_u32(msg, DEVLINK_ATTR_PORT_INDEX, devlink_rate->devlink_port->index)) goto nla_put_failure; + } else if (devlink_rate_is_node(devlink_rate)) { + if (nla_put_string(msg, DEVLINK_ATTR_RATE_NODE_NAME, + devlink_rate->name)) + goto nla_put_failure; } if (nla_put_u64_64bit(msg, DEVLINK_ATTR_RATE_TX_SHARE, @@ -1508,13 +1577,17 @@ static int devlink_nl_rate_set(struct devlink_rate *devlink_rate, struct genl_info *info) { struct nlattr **attrs = info->attrs; + int err = -EOPNOTSUPP; u64 rate; - int err; if (attrs[DEVLINK_ATTR_RATE_TX_SHARE]) { rate = nla_get_u64(attrs[DEVLINK_ATTR_RATE_TX_SHARE]); - err = ops->rate_leaf_tx_share_set(devlink_rate, devlink_rate->priv, - rate, info->extack); + if (devlink_rate_is_leaf(devlink_rate)) + err = ops->rate_leaf_tx_share_set(devlink_rate, devlink_rate->priv, + rate, info->extack); + else if (devlink_rate_is_node(devlink_rate)) + err = ops->rate_node_tx_share_set(devlink_rate, devlink_rate->priv, + rate, info->extack); if (err) return err; devlink_rate->tx_share = rate; @@ -1522,8 +1595,12 @@ static int devlink_nl_rate_set(struct devlink_rate *devlink_rate, if (attrs[DEVLINK_ATTR_RATE_TX_MAX]) { rate = nla_get_u64(attrs[DEVLINK_ATTR_RATE_TX_MAX]); - err = ops->rate_leaf_tx_max_set(devlink_rate, devlink_rate->priv, - rate, info->extack); + if (devlink_rate_is_leaf(devlink_rate)) + err = ops->rate_leaf_tx_max_set(devlink_rate, devlink_rate->priv, + rate, info->extack); + else if (devlink_rate_is_node(devlink_rate)) + err = ops->rate_node_tx_max_set(devlink_rate, devlink_rate->priv, + rate, info->extack); if (err) return err; devlink_rate->tx_max = rate; @@ -1547,6 +1624,15 @@ static bool devlink_rate_set_ops_supported(const struct devlink_ops *ops, NL_SET_ERR_MSG_MOD(info->extack, "TX max set isn't supported for the leafs"); return false; } + } else if (type == DEVLINK_RATE_TYPE_NODE) { + if (attrs[DEVLINK_ATTR_RATE_TX_SHARE] && !ops->rate_node_tx_share_set) { + NL_SET_ERR_MSG_MOD(info->extack, "TX share set isn't supported for the nodes"); + return false; + } + if (attrs[DEVLINK_ATTR_RATE_TX_MAX] && !ops->rate_node_tx_max_set) { + NL_SET_ERR_MSG_MOD(info->extack, "TX max set isn't supported for the nodes"); + return false; + } } else { WARN_ON("Unknown type of rate object"); return false; @@ -1573,6 +1659,78 @@ static int devlink_nl_cmd_rate_set_doit(struct sk_buff *skb, return err; } +static int devlink_nl_cmd_rate_new_doit(struct sk_buff *skb, + struct genl_info *info) +{ + struct devlink *devlink = info->user_ptr[0]; + struct devlink_rate *rate_node; + const struct devlink_ops *ops; + int err; + + ops = devlink->ops; + if (!ops || !ops->rate_node_new || !ops->rate_node_del) { + NL_SET_ERR_MSG_MOD(info->extack, "Rate nodes aren't supported"); + return -EOPNOTSUPP; + } + + if (!devlink_rate_set_ops_supported(ops, info, DEVLINK_RATE_TYPE_NODE)) + return -EOPNOTSUPP; + + rate_node = devlink_rate_node_get_from_attrs(devlink, info->attrs); + if (!IS_ERR(rate_node)) + return -EEXIST; + else if (rate_node == ERR_PTR(-EINVAL)) + return -EINVAL; + + rate_node = kzalloc(sizeof(*rate_node), GFP_KERNEL); + if (!rate_node) + return -ENOMEM; + + rate_node->devlink = devlink; + rate_node->type = DEVLINK_RATE_TYPE_NODE; + rate_node->name = nla_strdup(info->attrs[DEVLINK_ATTR_RATE_NODE_NAME], GFP_KERNEL); + if (!rate_node->name) { + err = -ENOMEM; + goto err_strdup; + } + + err = ops->rate_node_new(rate_node, &rate_node->priv, info->extack); + if (err) + goto err_node_new; + + err = devlink_nl_rate_set(rate_node, ops, info); + if (err) + goto err_rate_set; + + list_add(&rate_node->list, &devlink->rate_list); + devlink_rate_notify(rate_node, DEVLINK_CMD_RATE_NEW); + return 0; + +err_rate_set: + ops->rate_node_del(rate_node, rate_node->priv, info->extack); +err_node_new: + kfree(rate_node->name); +err_strdup: + kfree(rate_node); + return err; +} + +static int devlink_nl_cmd_rate_del_doit(struct sk_buff *skb, + struct genl_info *info) +{ + struct devlink_rate *rate_node = info->user_ptr[1]; + struct devlink *devlink = rate_node->devlink; + const struct devlink_ops *ops = devlink->ops; + int err; + + devlink_rate_notify(rate_node, DEVLINK_CMD_RATE_DEL); + err = ops->rate_node_del(rate_node, rate_node->priv, info->extack); + list_del(&rate_node->list); + kfree(rate_node->name); + kfree(rate_node); + return err; +} + static int devlink_nl_sb_fill(struct sk_buff *msg, struct devlink *devlink, struct devlink_sb *devlink_sb, enum devlink_command cmd, u32 portid, @@ -2441,6 +2599,30 @@ static int devlink_nl_cmd_eswitch_get_doit(struct sk_buff *skb, return genlmsg_reply(msg, info); } +static int devlink_rate_nodes_check(struct devlink *devlink, u16 mode, + struct netlink_ext_ack *extack) +{ + struct devlink_rate *devlink_rate; + u16 old_mode; + int err; + + if (!devlink->ops->eswitch_mode_get) + return -EOPNOTSUPP; + err = devlink->ops->eswitch_mode_get(devlink, &old_mode); + if (err) + return err; + + if (old_mode == mode) + return 0; + + list_for_each_entry(devlink_rate, &devlink->rate_list, list) + if (devlink_rate_is_node(devlink_rate)) { + NL_SET_ERR_MSG_MOD(extack, "Rate node(s) exists."); + return -EBUSY; + } + return 0; +} + static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb, struct genl_info *info) { @@ -2455,6 +2637,9 @@ static int devlink_nl_cmd_eswitch_set_doit(struct sk_buff *skb, if (!ops->eswitch_mode_set) return -EOPNOTSUPP; mode = nla_get_u16(info->attrs[DEVLINK_ATTR_ESWITCH_MODE]); + err = devlink_rate_nodes_check(devlink, mode, info->extack); + if (err) + return err; err = ops->eswitch_mode_set(devlink, mode, info->extack); if (err) return err; @@ -8038,6 +8223,7 @@ static int devlink_nl_cmd_trap_policer_set_doit(struct sk_buff *skb, [DEVLINK_ATTR_RATE_TYPE] = { .type = NLA_U16 }, [DEVLINK_ATTR_RATE_TX_SHARE] = { .type = NLA_U64 }, [DEVLINK_ATTR_RATE_TX_MAX] = { .type = NLA_U64 }, + [DEVLINK_ATTR_RATE_NODE_NAME] = { .type = NLA_NUL_STRING }, }; static const struct genl_small_ops devlink_nl_ops[] = { @@ -8077,6 +8263,17 @@ static int devlink_nl_cmd_trap_policer_set_doit(struct sk_buff *skb, .internal_flags = DEVLINK_NL_FLAG_NEED_RATE, }, { + .cmd = DEVLINK_CMD_RATE_NEW, + .doit = devlink_nl_cmd_rate_new_doit, + .flags = GENL_ADMIN_PERM, + }, + { + .cmd = DEVLINK_CMD_RATE_DEL, + .doit = devlink_nl_cmd_rate_del_doit, + .flags = GENL_ADMIN_PERM, + .internal_flags = DEVLINK_NL_FLAG_NEED_RATE_NODE, + }, + { .cmd = DEVLINK_CMD_PORT_SPLIT, .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP, .doit = devlink_nl_cmd_port_split_doit, @@ -8933,6 +9130,33 @@ void devlink_rate_leaf_destroy(struct devlink_port *devlink_port) } EXPORT_SYMBOL_GPL(devlink_rate_leaf_destroy); +/** + * devlink_rate_nodes_destroy - destroy all devlink rate nodes on device + * + * @devlink: devlink instance + * + * Destroy all rate nodes on specified device + * + * Context: Takes and release devlink->lock . + */ +void devlink_rate_nodes_destroy(struct devlink *devlink) +{ + static struct devlink_rate *devlink_rate, *tmp; + const struct devlink_ops *ops = devlink->ops; + + mutex_lock(&devlink->lock); + list_for_each_entry_safe(devlink_rate, tmp, &devlink->rate_list, list) { + if (devlink_rate_is_node(devlink_rate)) { + ops->rate_node_del(devlink_rate, devlink_rate->priv, NULL); + list_del(&devlink_rate->list); + kfree(devlink_rate->name); + kfree(devlink_rate); + } + } + mutex_unlock(&devlink->lock); +} +EXPORT_SYMBOL_GPL(devlink_rate_nodes_destroy); + static int __devlink_port_phys_port_name_get(struct devlink_port *devlink_port, char *name, size_t len) { From patchwork Wed Jun 2 12:17:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 453062 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 8C51AC4708F for ; Wed, 2 Jun 2021 12:18:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 65F3B613BA for ; Wed, 2 Jun 2021 12:18:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230029AbhFBMUM (ORCPT ); Wed, 2 Jun 2021 08:20:12 -0400 Received: from mail-bn8nam11on2049.outbound.protection.outlook.com ([40.107.236.49]:32993 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S230053AbhFBMT6 (ORCPT ); Wed, 2 Jun 2021 08:19:58 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=RW6Vk64kZkqnEa8PWm8DY7nHvH6WSxlq94FJ6otxG219fHc5AR76zjgDBnmASaEpGlbbP5czBnjIcUgodyRYHg15n9YuhiNOjNum0lGIZnrZVkxCvcSL+wkfa8XLP6BRzFuD3qejm6hXMEkp1gcpAT7u3rUYfap5nm+7D1TWkQbDL5OGc9PNpifapWtlYo7iVupIOdQoUG+WwDOcgMVO4gAHAhLxG6vyKgXlYNriiWo8VmCTRHEw08BiOqrM0nzQmHOFuSv2kOUPnCnN5YZQ83/ExqxYZg+JuTeLzggPCXew9ifh86RoUgmZA2LekfbEKZ54faz9lO6nRQCtjT/QvA== 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=jnnFqLUahqxi0XB2bKWKqZjExAF4o79lAwiKxxC8aoQ=; b=FWhmM7+Kz3w1bOA9hf1ULfXErqqhht6doYy+tQvHjkukGP929sh5oX3Z9e28VncVtJs5tcTzAxOjKz9p5z97x316VdMcOo1aEvjEZB9yVD1f2/2q8jpwd637NBLzt4q4s2q+in965dAS/sbA4Pd0k6mzzBZWf0bbLVE3WVKC5xLsMUzM7fKqmAyBq5aMQTyYRtmnXuk3xn+QorMuJeHyPVLowzVFNaHjeByqZf0HP9iZmfJsXQfHAXtFJV0rA8R6FfqU7tI887blTVgfAkQgTDZxXx4qJHioKXaoPAPwrhGmuEdjRwNilhoJlmL4JwmDoWyNSTAhK51+gJyKvYp4gA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jnnFqLUahqxi0XB2bKWKqZjExAF4o79lAwiKxxC8aoQ=; b=G823e3BFxy2mnqAKAxwMSsVtXGQcVN37ylHw1pAq9TybTYNQrO6ix+8AeC5I9aoMRddu1nIRmrE8WzyX5B9C5dPZ6SNwiccW4VGTdOLyac5CNTqf2bYMUAiEi3iQNHXSH8VUmwE1MXZclXIcUW1NjQKdcU2vxAlEbsNwh6LbNa4BaoKTnbKXvbGmmylKdc+Y5WFt/BKWQAcJ8PcHs7EZQQPRwOFzhVoF364bxXWxNzrt/1//3WWhSww8LzGm384UxLJ00VOpBkL9lxwV9fdGCJEifILcjF1aOgRZrKjHIgLKsHR7RQtH2ETIM7XHfzWDMcVeUWTTVdyGk8+18WxY1g== Received: from MWHPR03CA0023.namprd03.prod.outlook.com (2603:10b6:300:117::33) by BYAPR12MB2727.namprd12.prod.outlook.com (2603:10b6:a03:71::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.24; Wed, 2 Jun 2021 12:18:13 +0000 Received: from CO1NAM11FT018.eop-nam11.prod.protection.outlook.com (2603:10b6:300:117:cafe::28) by MWHPR03CA0023.outlook.office365.com (2603:10b6:300:117::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Wed, 2 Jun 2021 12:18:13 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by CO1NAM11FT018.mail.protection.outlook.com (10.13.175.16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4150.30 via Frontend Transport; Wed, 2 Jun 2021 12:18:13 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 12:18:12 +0000 Received: from vdi.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Jun 2021 05:18:09 -0700 From: To: CC: , , , , , , , , Dmytro Linkin Subject: [PATCH RESEND net-next v3 13/18] netdevsim: Implement support for devlink rate nodes Date: Wed, 2 Jun 2021 15:17:26 +0300 Message-ID: <1622636251-29892-14-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> References: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 2049d7b1-cf00-4300-7dff-08d925c07e45 X-MS-TrafficTypeDiagnostic: BYAPR12MB2727: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:326; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: AYvOwqfpPm+5qbiRuJKCoBeHOncbXJkvoMQ+2xkVdeM9aZsmjmLcY8+o39HJSNqCTgcl7UrERacYyWuZywY7ggOfkDwhewWAiJRaYMQviGrq5BEq0sxxhJQaqULxUtXzFXQKj7XnvDMxLYF/Lr+vMmNqoaGQFDwFu1Bdwic0B70PMcW0FAOmi/b/wmI4z5sCTuZnBYFCIWBUDufdB1ZXUJ+AAU/WEgGKD1dc7zREL7bRWSXIFq3IO7YBB7utjPHiQHbL7Lnq6MxJD0EMY8easlWVlrdvTVYAjL/xLwI5Ihr9xF6LWV47y886sWW5ALkYMrND0PrcQKp6C/7+iDAjQCyjW0K3/rjZuav3BApJq6JkDzlpEUqBu+bgpnvNBMg3aanbdFyDRZXj0JIJkEeaj+08As2NgjDPVTl0kMyPMDYQvbGd5siS617h3n00n6h4wISx8Lrc9dg6f3PifCck3LaiXTLK1SGqmpOiPsip8WhkguKHlUzYw0S8KQxBlI+yOh0zHOoYBVhaaF30sRmSH3bAvHoW9wM4lPwjZLmOwoXPPZ/bll8OVWh4boR4c2O0a5f9ZbqbxHI+E9HhLln00ERVa3AWVhMQwoOpM33CiE/ckELU47AzRdfF2so/7+1liMjoM6KhTM2qLNxK6+G+Zg== X-Forefront-Antispam-Report: CIP:216.228.112.35; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid02.nvidia.com; CAT:NONE; SFS:(4636009)(136003)(396003)(39860400002)(346002)(376002)(46966006)(36840700001)(2876002)(86362001)(26005)(47076005)(70586007)(83380400001)(6916009)(2906002)(186003)(70206006)(7636003)(82740400003)(36860700001)(2616005)(426003)(336012)(478600001)(8676002)(82310400003)(356005)(7696005)(8936002)(36756003)(5660300002)(54906003)(6666004)(4326008)(316002)(107886003)(36906005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 12:18:13.1118 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 2049d7b1-cf00-4300-7dff-08d925c07e45 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.35]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT018.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR12MB2727 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Dmytro Linkin Implement new devlink ops that allow creation, deletion and setting of shared/max tx rate of devlink rate nodes through devlink API. Expose rate node and it's tx rates to netdevsim debugfs. Co-developed-by: Vlad Buslov Signed-off-by: Vlad Buslov Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- Notes: v2->v3: - added devlink_rate_nodes_destroy() call drivers/net/netdevsim/dev.c | 80 +++++++++++++++++++++++++++++++++++++++ drivers/net/netdevsim/netdevsim.h | 1 + 2 files changed, 81 insertions(+) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 5be6f7e..9f01b6c 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -263,12 +263,16 @@ static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev) nsim_dev->ddir, nsim_dev->nsim_bus_dev, &nsim_dev_max_vfs_fops); + nsim_dev->nodes_ddir = debugfs_create_dir("rate_nodes", nsim_dev->ddir); + if (IS_ERR(nsim_dev->nodes_ddir)) + return PTR_ERR(nsim_dev->nodes_ddir); nsim_udp_tunnels_debugfs_create(nsim_dev); return 0; } static void nsim_dev_debugfs_exit(struct nsim_dev *nsim_dev) { + debugfs_remove_recursive(nsim_dev->nodes_ddir); debugfs_remove_recursive(nsim_dev->ports_ddir); debugfs_remove_recursive(nsim_dev->ddir); } @@ -451,8 +455,10 @@ static void nsim_dev_dummy_region_exit(struct nsim_dev *nsim_dev) static void __nsim_dev_port_del(struct nsim_dev_port *nsim_dev_port); int nsim_esw_legacy_enable(struct nsim_dev *nsim_dev, struct netlink_ext_ack *extack) { + struct devlink *devlink = priv_to_devlink(nsim_dev); struct nsim_dev_port *nsim_dev_port, *tmp; + devlink_rate_nodes_destroy(devlink); mutex_lock(&nsim_dev->port_list_lock); list_for_each_entry_safe(nsim_dev_port, tmp, &nsim_dev->port_list, list) if (nsim_dev_port_is_vf(nsim_dev_port)) @@ -1060,6 +1066,76 @@ static int nsim_leaf_tx_max_set(struct devlink_rate *devlink_rate, void *priv, return 0; } +struct nsim_rate_node { + struct dentry *ddir; + u16 tx_share; + u16 tx_max; +}; + +static int nsim_node_tx_share_set(struct devlink_rate *devlink_rate, void *priv, + u64 tx_share, struct netlink_ext_ack *extack) +{ + struct nsim_rate_node *nsim_node = priv; + int err; + + err = nsim_rate_bytes_to_units("tx_share", &tx_share, extack); + if (err) + return err; + + nsim_node->tx_share = tx_share; + return 0; +} + +static int nsim_node_tx_max_set(struct devlink_rate *devlink_rate, void *priv, + u64 tx_max, struct netlink_ext_ack *extack) +{ + struct nsim_rate_node *nsim_node = priv; + int err; + + err = nsim_rate_bytes_to_units("tx_max", &tx_max, extack); + if (err) + return err; + + nsim_node->tx_max = tx_max; + return 0; +} + +static int nsim_rate_node_new(struct devlink_rate *node, void **priv, + struct netlink_ext_ack *extack) +{ + struct nsim_dev *nsim_dev = devlink_priv(node->devlink); + struct nsim_rate_node *nsim_node; + + if (!nsim_esw_mode_is_switchdev(nsim_dev)) { + NL_SET_ERR_MSG_MOD(extack, "Node creation allowed only in switchdev mode."); + return -EOPNOTSUPP; + } + + nsim_node = kzalloc(sizeof(*nsim_node), GFP_KERNEL); + if (!nsim_node) + return -ENOMEM; + + nsim_node->ddir = debugfs_create_dir(node->name, nsim_dev->nodes_ddir); + if (!nsim_node->ddir) { + kfree(nsim_node); + return -ENOMEM; + } + debugfs_create_u16("tx_share", 0400, nsim_node->ddir, &nsim_node->tx_share); + debugfs_create_u16("tx_max", 0400, nsim_node->ddir, &nsim_node->tx_max); + *priv = nsim_node; + return 0; +} + +static int nsim_rate_node_del(struct devlink_rate *node, void *priv, + struct netlink_ext_ack *extack) +{ + struct nsim_rate_node *nsim_node = priv; + + debugfs_remove_recursive(nsim_node->ddir); + kfree(nsim_node); + return 0; +} + static const struct devlink_ops nsim_dev_devlink_ops = { .eswitch_mode_set = nsim_devlink_eswitch_mode_set, .eswitch_mode_get = nsim_devlink_eswitch_mode_get, @@ -1077,6 +1153,10 @@ static int nsim_leaf_tx_max_set(struct devlink_rate *devlink_rate, void *priv, .trap_policer_counter_get = nsim_dev_devlink_trap_policer_counter_get, .rate_leaf_tx_share_set = nsim_leaf_tx_share_set, .rate_leaf_tx_max_set = nsim_leaf_tx_max_set, + .rate_node_tx_share_set = nsim_node_tx_share_set, + .rate_node_tx_max_set = nsim_node_tx_max_set, + .rate_node_new = nsim_rate_node_new, + .rate_node_del = nsim_rate_node_del, }; #define NSIM_DEV_MAX_MACS_DEFAULT 32 diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 13a0042..d62a138 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -222,6 +222,7 @@ struct nsim_dev { struct dentry *ports_ddir; struct dentry *take_snapshot; struct dentry *max_vfs; + struct dentry *nodes_ddir; struct bpf_offload_dev *bpf_dev; bool bpf_bind_accept; bool bpf_bind_verifier_accept; From patchwork Wed Jun 2 12:17:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 453923 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 756F5C47083 for ; Wed, 2 Jun 2021 12:18:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F35C60FDC for ; Wed, 2 Jun 2021 12:18:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230116AbhFBMUY (ORCPT ); Wed, 2 Jun 2021 08:20:24 -0400 Received: from mail-dm6nam08on2066.outbound.protection.outlook.com ([40.107.102.66]:49027 "EHLO NAM04-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229745AbhFBMUA (ORCPT ); Wed, 2 Jun 2021 08:20:00 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QYtWy2MwGRc/Y16FLPMXuXcT37zlXw8d/AKjGGGfdYR6+u7aJ0RPzBXHr4agsMDC6odTmQPiYw29sKZ2CsbJeRFjtUa9xQLHPl3JEQf/CR87IBdwbz47TIV6eOA5Yr86quYX0ZanZ/IBvyeLyD/Wgc8DkZ+QL3qV8ctEOM1nCpPIgU/Tb6SnMnd06eHANU3M9bO8PLkLJ3rEC8zdXm6fPiL9yAZ1VPkcaHcKFDkGd5U2QYszqS/lyg20NIjuLxiyD/LhWn+lICxiNVkNAE9RAtN8iMfJqB7aW6GHToG2UBTa4bd7kTUghLFNarVrrxR/IimS+k/PhEQLQgziYM77zw== 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=yLD8T4pxHK7ogEKokyiWUTLies05D6B56tHXfxSNF8c=; b=KIq0sfxsQblCvIaDjzg8FpPv6MRNPKlokQ6456Zp+swI2mvtFwyQnuruAGTbdL8aq/4IRz3phLp7U01RF+vcvs/jr/1Xkmrp3emeh4P7glSLfEo4oYaxo3m2Osejdpn9fySH5BmXf7EQEHXJpKIIG7HqBGXOMNEkuM/BWU2fKt7LFltam5l3dluOOfRDxSSABsLeNoYDE5kBX7GdN9ZsWw7YON6L4HPufoKSHny+cgVXY1JHQ6imgu1vD1zjb47t7lhDThM0KjSnKxdqZdhTsNkZ7kX3xaYDP0LtC3dcQTALMFfyClr0SvupCZ3vNL6sNC+QWiuRtZI/lRQH70R4sA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yLD8T4pxHK7ogEKokyiWUTLies05D6B56tHXfxSNF8c=; b=poyowfzP56bvtJ1uT04E7oR5IfsruPxu4mjDRgHCItr19D75SwP78C0wT4yAAdkmmqVdyBI3b2WdbN+8DkMMBfRzjH1yhIu77qZ8dRWWoFCPo/JX9x4vQs+FjaJqdrp/6QLvbwvI/hDgnZoVf9rU17dD8ulOXlGwux9Q7ZNcpJEA1J4M8BxUMQ1XpaO7kaiMO32WetFgMIKnZNoPkW+uI3HJLe5fRZ0SdjyUH7EZsXN4BIn25gj6q5OU/3tuJ1fTlyds9C8UuisecldMNkEHn/V1hnU0Jm+0N6Hw1H5hAnofqUqqAxmzTyDN4G5UByuKYrKur4zmXtzXUJZ0yAcyUw== Received: from MWHPR02CA0001.namprd02.prod.outlook.com (2603:10b6:300:4b::11) by SN1PR12MB2479.namprd12.prod.outlook.com (2603:10b6:802:29::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.22; Wed, 2 Jun 2021 12:18:16 +0000 Received: from CO1NAM11FT054.eop-nam11.prod.protection.outlook.com (2603:10b6:300:4b:cafe::3a) by MWHPR02CA0001.outlook.office365.com (2603:10b6:300:4b::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.15 via Frontend Transport; Wed, 2 Jun 2021 12:18:16 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by CO1NAM11FT054.mail.protection.outlook.com (10.13.174.70) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4150.30 via Frontend Transport; Wed, 2 Jun 2021 12:18:16 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 12:18:15 +0000 Received: from vdi.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Jun 2021 05:18:12 -0700 From: To: CC: , , , , , , , , Dmytro Linkin Subject: [PATCH RESEND net-next v3 14/18] selftest: netdevsim: Add devlink rate nodes test Date: Wed, 2 Jun 2021 15:17:27 +0300 Message-ID: <1622636251-29892-15-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> References: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: aeec2335-f738-48ff-828e-08d925c08003 X-MS-TrafficTypeDiagnostic: SN1PR12MB2479: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TcfmgfkOt3BjOTc5nyLmPV4kyZmd5B0PMm3skMVhZm23jmp4Cr/bO1WtU0TfB/T8/nwaSudt1DQrI1ij78S8C8sUlw0nCvImxjNHk3CpgYhZfEKma7VHst6PKnzTzwaNF9XF1BYT3lJzCcyF8+V/btinUugGW4/GxKSUjxsRCDqaaqyY6SZJ6yAVLg5QTVLf8WIoeOe9gluaNx2uaxsEnO4ceP7yUa1oOO1QMeHKqpSi5qKfq1cY6RZqea3ErHfmrr839o6VsCaWSkP4YJII/bQa8H1kSVgBqcK+I+HG/rFPDxkBIZXKbKnErG7wDTXTRXzhtkjJuAOx5U3Saycb9CvpjR641YiAUbro4sKivfZ3CAnu1pAlzyC6yLZ4EsnWoXKv8QCIbr4Z6YNOrepubLVHgSoGM04kYqv5h4Y2BvyNkNtmbz+xrTZEDACUG/UIo6uj1aGAEfB0pVDa/INtSzrz1Ha5ZMcAfBHEmZBIfOtgjPInWua/fUupniszcvCnNHW+VxsA9E8vEinhqtfVwoSTv1aXN0g9h/eern/Xjdjh3x8ZhFRqVATi97NZwQdPsCWCY6pSZtcxOVna/mzsSWHwBPqKWlLSaPD/QuWyp2SH3PQBrfNGHZ9NNT5Z5Je1b3kLMgHEjhWUeuAzsdKELA== X-Forefront-Antispam-Report: CIP:216.228.112.35; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid02.nvidia.com; CAT:NONE; SFS:(4636009)(346002)(376002)(136003)(396003)(39860400002)(46966006)(36840700001)(6916009)(70586007)(26005)(54906003)(2906002)(8676002)(82310400003)(70206006)(478600001)(36906005)(2876002)(8936002)(186003)(83380400001)(82740400003)(6666004)(356005)(86362001)(107886003)(36860700001)(7696005)(2616005)(47076005)(5660300002)(36756003)(4326008)(336012)(426003)(7636003)(316002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 12:18:16.0188 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: aeec2335-f738-48ff-828e-08d925c08003 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.35]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT054.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1PR12MB2479 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Dmytro Linkin Test verifies that it is possible to create, delete and set min/max tx rate of devlink rate node on netdevsim VF. Co-developed-by: Vlad Buslov Signed-off-by: Vlad Buslov Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- Notes: v1->v2: - s/func/function/ in devlink commands .../selftests/drivers/net/netdevsim/devlink.sh | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh index 05dcefc..301d920 100755 --- a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh +++ b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh @@ -516,6 +516,14 @@ rate_leafs_get() '.[] | to_entries | .[] | select(.value.type == "leaf") | .key | select(contains("'$handle'"))' } +rate_nodes_get() +{ + local handle=$1 + + cmd_jq "devlink port function rate show -j" \ + '.[] | to_entries | .[] | select(.value.type == "node") | .key | select(contains("'$handle'"))' +} + rate_attr_set() { local handle=$1 @@ -555,6 +563,20 @@ rate_attr_tx_rate_check() check_err $? "Unexpected $name attr value $api_value != $rate" } +rate_node_add() +{ + local handle=$1 + + devlink port function rate add $handle +} + +rate_node_del() +{ + local handle=$1 + + devlink port function rate del $handle +} + rate_test() { RET=0 @@ -582,6 +604,29 @@ rate_test() rate=$(($rate+100)) done + local node1_name='group1' + local node1="$DL_HANDLE/$node1_name" + rate_node_add "$node1" + check_err $? "Failed to add node $node1" + + local num_nodes=`rate_nodes_get $DL_HANDLE | wc -w` + [ $num_nodes == 1 ] + check_err $? "Expected 1 rate node in output but got $num_nodes" + + local node_tx_share=10 + rate_attr_tx_rate_check $node1 tx_share $node_tx_share \ + $DEBUGFS_DIR/rate_nodes/${node1##*/}/tx_share + + local node_tx_max=100 + rate_attr_tx_rate_check $node1 tx_max $node_tx_max \ + $DEBUGFS_DIR/rate_nodes/${node1##*/}/tx_max + + rate_node_del "$node1" + check_err $? "Failed to delete node $node1" + local num_nodes=`rate_nodes_get $DL_HANDLE | wc -w` + [ $num_nodes == 0 ] + check_err $? "Expected 0 rate node but got $num_nodes" + log_test "rate test" } From patchwork Wed Jun 2 12:17:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 453061 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 800D2C47083 for ; Wed, 2 Jun 2021 12:18:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1F683613B8 for ; Wed, 2 Jun 2021 12:18:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230062AbhFBMUb (ORCPT ); Wed, 2 Jun 2021 08:20:31 -0400 Received: from mail-mw2nam10on2064.outbound.protection.outlook.com ([40.107.94.64]:59616 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229762AbhFBMUE (ORCPT ); Wed, 2 Jun 2021 08:20:04 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BhtYGLOGpPEytYiCeh3japh9EaJ9QH8r1ZvLHaY1O78M0WrFk5bC+gLTVPlHKz1jF2teRgZLCE+KqbbYLqWQfLq94T4ndgvl4t/tZkDAN3JkRieSItAh0WExHla5X7vHL2aLMMoTo9bRWAeUw7GclP/sj+n5jsFU+JPagQeXlQQdn/vIqg9+j5sHZxzn0XGkzWZOiYqkFMfVtlVkihEqlKAtHOnG5p3euSYagb/oRWH1kLp9gwNOhMNA8ziCaJ6rAZWoEhrxP0QOMAjmkqDmwEscm6mD1rKbUikGmI2u8pigQiE7TBXc6OrLVJqZyeg3Xa5u0lHKJ1rxya9VEcTTxw== 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=l38TADw6uTKrPt/uwljOd7X1kJKoyrfOyloFQ8G+6/4=; b=JDVdfpSJ4lKzqiz7UbUalA/uK4A1Hb4WM9nKMWLzSHpU68fEDt/nuOYItbwoS9+/fkXhyiZtEG7kNzAq+5tsqmm6j9teTBaAdcdQW0yg9dposeiE/65QpkVqyAAFwlO8ZjV0ccuYaTrtvHPFjX78kYGQ15aLJwXGSHvaxE9GyHDcs+MWHV2frg27m6CSc5WNE+YW15MqYfNaDQbFT/F+TeWXkzTA+EvXQ98WXCF7aOddDH18z5JEzYuYXMCzscbFIMzIPyM1s/gN4HVG9q/GZSRrOnnJx/cFfMc4IfkVSDQWqVkinf8XhhbJLmP+yDIqn2+EFpwp2tLzg2egdRxbIw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=l38TADw6uTKrPt/uwljOd7X1kJKoyrfOyloFQ8G+6/4=; b=pUnCz4yZNPIBtqiLZcULI/l7/kFKJrB+sPODENFOYT4ulh+g4bn4pXHG4RCxBPEAAJEPhjZGp6TAgsSJilDiFR9mhSfzEQCOVTQkzUgoOZwIpfdZsCXgYQ9z9WTU1VmCiP6b6ZYtKzoc66ggrU4OjYHyGo8UWr2uHqxWBcRh+dA6L18ySL9iTcz8r540a4ji3p0RB4ZRNa9d3I0jPJxMKTs9ZRW2d24qNUHkOeTanaP/SZ0PVTcTlcMvTZIDN5M/CKJDcUUmm0aQCoHvMwTJnNaALyX4DC5Uk+EsprrM4aMUQDt+bv4t/Bhhmt7TWFkwVfmLxOmOBZNMsmDfm1En9w== Received: from MWHPR18CA0070.namprd18.prod.outlook.com (2603:10b6:300:39::32) by MN2PR12MB3936.namprd12.prod.outlook.com (2603:10b6:208:16a::33) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.21; Wed, 2 Jun 2021 12:18:19 +0000 Received: from CO1NAM11FT004.eop-nam11.prod.protection.outlook.com (2603:10b6:300:39:cafe::2e) by MWHPR18CA0070.outlook.office365.com (2603:10b6:300:39::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Wed, 2 Jun 2021 12:18:19 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by CO1NAM11FT004.mail.protection.outlook.com (10.13.175.89) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4150.30 via Frontend Transport; Wed, 2 Jun 2021 12:18:18 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 12:18:18 +0000 Received: from vdi.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Jun 2021 05:18:15 -0700 From: To: CC: , , , , , , , , Dmytro Linkin Subject: [PATCH RESEND net-next v3 15/18] devlink: Allow setting parent node of rate objects Date: Wed, 2 Jun 2021 15:17:28 +0300 Message-ID: <1622636251-29892-16-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> References: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: b2f99019-9f49-4b13-e4c1-08d925c081be X-MS-TrafficTypeDiagnostic: MN2PR12MB3936: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:121; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 44D+HgEMs7VvEDi6AtEG16CtGMgR4Ao9PRP/ADw/E16zEB8ISWH7sKTm77fmKa3IwIiZcONlJP231HsvYdFW10qo2UaFv282UgBzXlDCwD4oMHiVAL6XV6UMArG2bs1wGR+x10XvlzrrqRP1jkxZo4qN+g9rkyVS1uhF74a6qSrCQ7tVoFLhYx1IXsV0PBA3THdJpHnt1LR2QXMPYWLAkvyh2bQdmndq01EHg7ybvo59RzePDSzyz7wU/Tc+VDUD1JmogmfJOSHyGI/dpk4DbkMrU03g9Ax+ONF1ZvZLNPL6pEu4mzYS0SPmHfON3uQ6lDIsN0Eq584Gt6Br95fjpXhE11Eb+oHwf3rNoLYvXjTIpcYD/yq8N6CsV71lbFmVii9N+v98vlhPGAN7IKxq2RJZydotro7Uq5w2SAzVsmaWUT7d82IbmW7Ik+SoCKM1CvnmKSjnqZ3aFrwGV2Yen5VgyMWiSUOj1voHWFY1dYc8X9qGg/RdWzyI95/awBt54xfmum7DdqnPZdFZgZLr7sDZ0LHi6BJLq93M+28BpdmYjiVyAgQe93GSgja7q3m9jM0Mpmn4WClgvwwyDGJj1kvq6uf1R16ktij9yuim7fCwUOdNI+CESFJ3r+s1zgH9sdr/WtvBvKVaGnHOUB4szT66vr4JS6E4n9KE8oVVMM0= X-Forefront-Antispam-Report: CIP:216.228.112.35; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid02.nvidia.com; CAT:NONE; SFS:(4636009)(396003)(346002)(39860400002)(376002)(136003)(46966006)(36840700001)(26005)(54906003)(7696005)(336012)(86362001)(36906005)(8936002)(82310400003)(5660300002)(7636003)(70206006)(186003)(36756003)(356005)(2616005)(36860700001)(83380400001)(4326008)(47076005)(6666004)(107886003)(6916009)(426003)(2906002)(82740400003)(70586007)(8676002)(316002)(478600001)(2876002); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 12:18:18.9056 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: b2f99019-9f49-4b13-e4c1-08d925c081be X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.35]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT004.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3936 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Dmytro Linkin Refactor DEVLINK_CMD_RATE_{GET|SET} command handlers to support setting a node as a parent for another rate object (leaf or node) by means of new attribute DEVLINK_ATTR_RATE_PARENT_NODE_NAME. Extend devlink ops with new callbacks rate_{leaf|node}_parent_set() to set node as a parent for rate object to allow supporting drivers to implement rate grouping through devlink. Driver implementations are allowed to support leafs or node children only. Invoking callback with NULL as parent should be threated by the driver as unset parent action. Extend rate object struct with reference counter to disallow deleting a node with any child pointing to it. User should unset parent for the child explicitly. Example: $ devlink port function rate add netdevsim/netdevsim10/group1 $ devlink port function rate add netdevsim/netdevsim10/group2 $ devlink port function rate set netdevsim/netdevsim10/group1 parent group2 $ devlink port function rate show netdevsim/netdevsim10/group1 netdevsim/netdevsim10/group1: type node parent group2 $ devlink port function rate set netdevsim/netdevsim10/group1 noparent Co-developed-by: Vlad Buslov Signed-off-by: Vlad Buslov Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- Notes: v1->v2: - s/func/function/ at commit message v2->v3: - unset parents for all rate objects at devlink_rate_nodes_destroy() include/net/devlink.h | 14 ++++- include/uapi/linux/devlink.h | 1 + net/core/devlink.c | 125 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 137 insertions(+), 3 deletions(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index 13162b5..eb045f1 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -142,9 +142,13 @@ struct devlink_rate { u64 tx_share; u64 tx_max; + struct devlink_rate *parent; union { struct devlink_port *devlink_port; - char *name; + struct { + char *name; + refcount_t refcnt; + }; }; }; @@ -1486,6 +1490,14 @@ struct devlink_ops { struct netlink_ext_ack *extack); int (*rate_node_del)(struct devlink_rate *rate_node, void *priv, struct netlink_ext_ack *extack); + int (*rate_leaf_parent_set)(struct devlink_rate *child, + struct devlink_rate *parent, + void *priv_child, void *priv_parent, + struct netlink_ext_ack *extack); + int (*rate_node_parent_set)(struct devlink_rate *child, + struct devlink_rate *parent, + void *priv_child, void *priv_parent, + struct netlink_ext_ack *extack); }; static inline void *devlink_priv(struct devlink *devlink) diff --git a/include/uapi/linux/devlink.h b/include/uapi/linux/devlink.h index 7e15853..32f53a00 100644 --- a/include/uapi/linux/devlink.h +++ b/include/uapi/linux/devlink.h @@ -549,6 +549,7 @@ enum devlink_attr { DEVLINK_ATTR_RATE_TX_SHARE, /* u64 */ DEVLINK_ATTR_RATE_TX_MAX, /* u64 */ DEVLINK_ATTR_RATE_NODE_NAME, /* string */ + DEVLINK_ATTR_RATE_PARENT_NODE_NAME, /* string */ /* add new attributes above here, update the policy in devlink.c */ diff --git a/net/core/devlink.c b/net/core/devlink.c index d520fb5..04cc5e5 100644 --- a/net/core/devlink.c +++ b/net/core/devlink.c @@ -880,6 +880,11 @@ static int devlink_nl_rate_fill(struct sk_buff *msg, devlink_rate->tx_max, DEVLINK_ATTR_PAD)) goto nla_put_failure; + if (devlink_rate->parent) + if (nla_put_string(msg, DEVLINK_ATTR_RATE_PARENT_NODE_NAME, + devlink_rate->parent->name)) + goto nla_put_failure; + genlmsg_end(msg, hdr); return 0; @@ -1152,6 +1157,18 @@ static int devlink_nl_cmd_rate_get_doit(struct sk_buff *skb, return genlmsg_reply(msg, info); } +static bool +devlink_rate_is_parent_node(struct devlink_rate *devlink_rate, + struct devlink_rate *parent) +{ + while (parent) { + if (parent == devlink_rate) + return true; + parent = parent->parent; + } + return false; +} + static int devlink_nl_cmd_get_doit(struct sk_buff *skb, struct genl_info *info) { struct devlink *devlink = info->user_ptr[0]; @@ -1572,11 +1589,75 @@ static int devlink_nl_cmd_port_del_doit(struct sk_buff *skb, return devlink->ops->port_del(devlink, port_index, extack); } +static int +devlink_nl_rate_parent_node_set(struct devlink_rate *devlink_rate, + struct genl_info *info, + struct nlattr *nla_parent) +{ + struct devlink *devlink = devlink_rate->devlink; + const char *parent_name = nla_data(nla_parent); + const struct devlink_ops *ops = devlink->ops; + size_t len = strlen(parent_name); + struct devlink_rate *parent; + int err = -EOPNOTSUPP; + + parent = devlink_rate->parent; + if (parent && len) { + NL_SET_ERR_MSG_MOD(info->extack, "Rate object already has parent."); + return -EBUSY; + } else if (parent && !len) { + if (devlink_rate_is_leaf(devlink_rate)) + err = ops->rate_leaf_parent_set(devlink_rate, NULL, + devlink_rate->priv, NULL, + info->extack); + else if (devlink_rate_is_node(devlink_rate)) + err = ops->rate_node_parent_set(devlink_rate, NULL, + devlink_rate->priv, NULL, + info->extack); + if (err) + return err; + + refcount_dec(&parent->refcnt); + devlink_rate->parent = NULL; + } else if (!parent && len) { + parent = devlink_rate_node_get_by_name(devlink, parent_name); + if (IS_ERR(parent)) + return -ENODEV; + + if (parent == devlink_rate) { + NL_SET_ERR_MSG_MOD(info->extack, "Parent to self is not allowed"); + return -EINVAL; + } + + if (devlink_rate_is_node(devlink_rate) && + devlink_rate_is_parent_node(devlink_rate, parent->parent)) { + NL_SET_ERR_MSG_MOD(info->extack, "Node is already a parent of parent node."); + return -EEXIST; + } + + if (devlink_rate_is_leaf(devlink_rate)) + err = ops->rate_leaf_parent_set(devlink_rate, parent, + devlink_rate->priv, parent->priv, + info->extack); + else if (devlink_rate_is_node(devlink_rate)) + err = ops->rate_node_parent_set(devlink_rate, parent, + devlink_rate->priv, parent->priv, + info->extack); + if (err) + return err; + + refcount_inc(&parent->refcnt); + devlink_rate->parent = parent; + } + + return 0; +} + static int devlink_nl_rate_set(struct devlink_rate *devlink_rate, const struct devlink_ops *ops, struct genl_info *info) { - struct nlattr **attrs = info->attrs; + struct nlattr *nla_parent, **attrs = info->attrs; int err = -EOPNOTSUPP; u64 rate; @@ -1606,6 +1687,14 @@ static int devlink_nl_rate_set(struct devlink_rate *devlink_rate, devlink_rate->tx_max = rate; } + nla_parent = attrs[DEVLINK_ATTR_RATE_PARENT_NODE_NAME]; + if (nla_parent) { + err = devlink_nl_rate_parent_node_set(devlink_rate, info, + nla_parent); + if (err) + return err; + } + return 0; } @@ -1624,6 +1713,11 @@ static bool devlink_rate_set_ops_supported(const struct devlink_ops *ops, NL_SET_ERR_MSG_MOD(info->extack, "TX max set isn't supported for the leafs"); return false; } + if (attrs[DEVLINK_ATTR_RATE_PARENT_NODE_NAME] && + !ops->rate_leaf_parent_set) { + NL_SET_ERR_MSG_MOD(info->extack, "Parent set isn't supported for the leafs"); + return false; + } } else if (type == DEVLINK_RATE_TYPE_NODE) { if (attrs[DEVLINK_ATTR_RATE_TX_SHARE] && !ops->rate_node_tx_share_set) { NL_SET_ERR_MSG_MOD(info->extack, "TX share set isn't supported for the nodes"); @@ -1633,6 +1727,11 @@ static bool devlink_rate_set_ops_supported(const struct devlink_ops *ops, NL_SET_ERR_MSG_MOD(info->extack, "TX max set isn't supported for the nodes"); return false; } + if (attrs[DEVLINK_ATTR_RATE_PARENT_NODE_NAME] && + !ops->rate_node_parent_set) { + NL_SET_ERR_MSG_MOD(info->extack, "Parent set isn't supported for the nodes"); + return false; + } } else { WARN_ON("Unknown type of rate object"); return false; @@ -1702,6 +1801,7 @@ static int devlink_nl_cmd_rate_new_doit(struct sk_buff *skb, if (err) goto err_rate_set; + refcount_set(&rate_node->refcnt, 1); list_add(&rate_node->list, &devlink->rate_list); devlink_rate_notify(rate_node, DEVLINK_CMD_RATE_NEW); return 0; @@ -1723,8 +1823,15 @@ static int devlink_nl_cmd_rate_del_doit(struct sk_buff *skb, const struct devlink_ops *ops = devlink->ops; int err; + if (refcount_read(&rate_node->refcnt) > 1) { + NL_SET_ERR_MSG_MOD(info->extack, "Node has children. Cannot delete node."); + return -EBUSY; + } + devlink_rate_notify(rate_node, DEVLINK_CMD_RATE_DEL); err = ops->rate_node_del(rate_node, rate_node->priv, info->extack); + if (rate_node->parent) + refcount_dec(&rate_node->parent->refcnt); list_del(&rate_node->list); kfree(rate_node->name); kfree(rate_node); @@ -8224,6 +8331,7 @@ static int devlink_nl_cmd_trap_policer_set_doit(struct sk_buff *skb, [DEVLINK_ATTR_RATE_TX_SHARE] = { .type = NLA_U64 }, [DEVLINK_ATTR_RATE_TX_MAX] = { .type = NLA_U64 }, [DEVLINK_ATTR_RATE_NODE_NAME] = { .type = NLA_NUL_STRING }, + [DEVLINK_ATTR_RATE_PARENT_NODE_NAME] = { .type = NLA_NUL_STRING }, }; static const struct genl_small_ops devlink_nl_ops[] = { @@ -9135,7 +9243,8 @@ void devlink_rate_leaf_destroy(struct devlink_port *devlink_port) * * @devlink: devlink instance * - * Destroy all rate nodes on specified device + * Unset parent for all rate objects and destroy all rate nodes + * on specified device. * * Context: Takes and release devlink->lock . */ @@ -9145,6 +9254,18 @@ void devlink_rate_nodes_destroy(struct devlink *devlink) const struct devlink_ops *ops = devlink->ops; mutex_lock(&devlink->lock); + list_for_each_entry(devlink_rate, &devlink->rate_list, list) { + if (!devlink_rate->parent) + continue; + + refcount_dec(&devlink_rate->parent->refcnt); + if (devlink_rate_is_leaf(devlink_rate)) + ops->rate_leaf_parent_set(devlink_rate, NULL, devlink_rate->priv, + NULL, NULL); + else if (devlink_rate_is_node(devlink_rate)) + ops->rate_node_parent_set(devlink_rate, NULL, devlink_rate->priv, + NULL, NULL); + } list_for_each_entry_safe(devlink_rate, tmp, &devlink->rate_list, list) { if (devlink_rate_is_node(devlink_rate)) { ops->rate_node_del(devlink_rate, devlink_rate->priv, NULL); From patchwork Wed Jun 2 12:17:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 453922 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=-16.3 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, UNWANTED_LANGUAGE_BODY,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 49627C4708F for ; Wed, 2 Jun 2021 12:18:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 272A4613D6 for ; Wed, 2 Jun 2021 12:18:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229774AbhFBMUc (ORCPT ); Wed, 2 Jun 2021 08:20:32 -0400 Received: from mail-bn8nam12on2074.outbound.protection.outlook.com ([40.107.237.74]:30145 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229932AbhFBMUG (ORCPT ); Wed, 2 Jun 2021 08:20:06 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hoz3XEwAE/KPJkn19rwkhopUG6hcHEjewgdkuVpEaWLHjvNnOIYB3Hl2knS+bGJ9WlrI1Zuxyn6CdxC5dx2zPBg/PrU3En9eS6NnAq50M90fVlgMWvanlcNiOrVD4DZzhBq6VxcXhdwtFdc4g78jD9BuBzVYztTl28ksAe+VW8OUKaArXPnMCYdyamYRMATKVX7VXBL2GfWImmodd3U1wXH/3g/7uRU9KP4/pppFeCGk6HaqmYlhjFODXz0D0C+23Z8OrCZ3ZhbUhXRf0yikrnIY588VTOM3P2ZuRiEZQuVagqBazODOQujGKzfaiwYgGGXquYzM1pb4Lt/F8yOKCg== 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=Yc4oij1qguvE2qTc64DTBA8PoMiHrA3p6D6Wziql+uE=; b=KkO71HIXWJCmH5TIDL1cCnd7utfE6QTTRwt2M6l4bYmXemkqKjTvX/8AD6aWAHnz225Pd10FnUAKCVEY1V0p3oBJtnQuhVKPY6xTM5P7Z/ByXTTr0zl2hWoU+btu01aze3s+YoBPVWDOS3qJGLGfmBjzoK7EemePwzgplq8tf3FBgIG6mHn6s6kj17Vq35pYPoVgxiXyzFd+awveeyPFTbCO0tIbASH/UwwdVDlWFpE9EXnPAjU28ikP3W3Ve/O7SAr5m4MynP8fsBOhsCIhVa5KlL4y6qNSUbtCwFahw9VU9VmtatFA23jey46CAoZsJbscdheSVw5IdOgzVZZRqQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=kernel.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Yc4oij1qguvE2qTc64DTBA8PoMiHrA3p6D6Wziql+uE=; b=eCd8cXpvjS/87mvPSElv2l8XjBVgKYeeoNuQEYbdxuqQ50QLF8aMwePpkftbs+HnJ0GYFhfw2HcKVd7giBF1J1B3/lIB1y4bFS3OSFug8iQ+m32lxgoZ1oUxcNRObo2JRWilxfpfkkv10ZZzLyEBEE65z3Irp+rKROfhiL5pEWDF6xmh8n5VIlU5N0750a0SrryCfGIxdX2EL4xdbU73V/zfI+qLLz2HsAqESwcN2rA3QrvMExj/a7qX4my6PT8V/SuJ0roaLTlexm5HMJay4y/RaxubnVBtvS0I/N4hs/PNiDmu6LUsmE4CL7SyPWEzKa+Im/knK0kfJCkI/r8F/g== Received: from MW4PR04CA0247.namprd04.prod.outlook.com (2603:10b6:303:88::12) by MW2PR12MB2395.namprd12.prod.outlook.com (2603:10b6:907:3::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20; Wed, 2 Jun 2021 12:18:22 +0000 Received: from CO1NAM11FT060.eop-nam11.prod.protection.outlook.com (2603:10b6:303:88:cafe::bd) by MW4PR04CA0247.outlook.office365.com (2603:10b6:303:88::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.21 via Frontend Transport; Wed, 2 Jun 2021 12:18:22 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; kernel.org; dkim=none (message not signed) header.d=none; kernel.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by CO1NAM11FT060.mail.protection.outlook.com (10.13.175.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4150.30 via Frontend Transport; Wed, 2 Jun 2021 12:18:22 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 12:18:21 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 12:18:21 +0000 Received: from vdi.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Jun 2021 05:18:18 -0700 From: To: CC: , , , , , , , , Dmytro Linkin Subject: [PATCH RESEND net-next v3 16/18] netdevsim: Allow setting parent node of rate objects Date: Wed, 2 Jun 2021 15:17:29 +0300 Message-ID: <1622636251-29892-17-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> References: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f2fe7d36-0c54-4f26-b6fe-08d925c0839f X-MS-TrafficTypeDiagnostic: MW2PR12MB2395: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:506; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: bs+96gkp2sccDZYP9aDyhKNBMGtQ/TQuVvGdkUTY2PSoMeS2lur3+oHxoo2kthfUferw0BvfldSMeVsL/5n6YwTcHGyztAGb5mbqGM6j4ctoKefZmWwnlV+cydDkwr7ts8DhE5h1AkHfBNXi3LpecmcmNnq6Ilt0Yq/Q/K0mnOw8ZRqZrDF64Y6S1be4BoVnUE6G4uggcaz7H4irBCfbfxCRq3Mv4IUqqhegSY9zF1/K1JqUIqsvWYnZfgGSz8cVUZvsOELBzAIQOy659MlbX190yY4qlti0KiIIIyrVS4w9Q4AqYaZtZQKHYrzjtDuBDcc6cnXLy52fcGeH9y/J80L7ewkAJXasU5KifmyqoHqtszQAycialx551UFFPuonIfaB80mMnLc5+RduDbcHPi6JbGKtp+hydOVB4AeewDKXscsEjRFtjdDgnk3C82zjPnhjmu7rP1XL3+6XMZhfGglUIDfGuTAgPoaZ8/7qC5Gwkju0MiBiG37nNCzNQL8pevyGeA5/yBHyteCei22AKHXceoRjxhHPwh/YsqQuL54mWgbc4UzmooBPQNaOeMOycQMh5XPN0UNA40egQsYBVWRi2n/VqV+0QNsEVsKPrDh53wNdh/KkDAIDaFVlViTDO16Y49/T3Cca8GeR508myg== X-Forefront-Antispam-Report: CIP:216.228.112.35; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid02.nvidia.com; CAT:NONE; SFS:(4636009)(376002)(136003)(396003)(39860400002)(346002)(36840700001)(46966006)(7696005)(36906005)(2616005)(26005)(5660300002)(36756003)(336012)(36860700001)(478600001)(426003)(47076005)(70206006)(83380400001)(4326008)(8676002)(82310400003)(2906002)(86362001)(82740400003)(2876002)(316002)(54906003)(186003)(6666004)(8936002)(356005)(6916009)(70586007)(107886003)(7636003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 12:18:22.0877 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: f2fe7d36-0c54-4f26-b6fe-08d925c0839f X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.35]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT060.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW2PR12MB2395 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Dmytro Linkin Implement new devlink ops that allow setting rate node as a parent for devlink port (leaf) or another devlink node through devlink API. Expose parent names to netdevsim debugfs in read only mode. Co-developed-by: Vlad Buslov Signed-off-by: Vlad Buslov Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- drivers/net/netdevsim/dev.c | 91 +++++++++++++++++++++++++++++++++++++-- drivers/net/netdevsim/netdevsim.h | 2 + 2 files changed, 89 insertions(+), 4 deletions(-) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 9f01b6c..527b019 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -222,6 +222,7 @@ static ssize_t nsim_dev_trap_fa_cookie_write(struct file *file, static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev) { char dev_ddir_name[sizeof(DRV_NAME) + 10]; + int err; sprintf(dev_ddir_name, DRV_NAME "%u", nsim_dev->nsim_bus_dev->dev.id); nsim_dev->ddir = debugfs_create_dir(dev_ddir_name, nsim_dev_ddir); @@ -264,10 +265,17 @@ static int nsim_dev_debugfs_init(struct nsim_dev *nsim_dev) nsim_dev->nsim_bus_dev, &nsim_dev_max_vfs_fops); nsim_dev->nodes_ddir = debugfs_create_dir("rate_nodes", nsim_dev->ddir); - if (IS_ERR(nsim_dev->nodes_ddir)) - return PTR_ERR(nsim_dev->nodes_ddir); + if (IS_ERR(nsim_dev->nodes_ddir)) { + err = PTR_ERR(nsim_dev->nodes_ddir); + goto err_out; + } nsim_udp_tunnels_debugfs_create(nsim_dev); return 0; + +err_out: + debugfs_remove_recursive(nsim_dev->ports_ddir); + debugfs_remove_recursive(nsim_dev->ddir); + return err; } static void nsim_dev_debugfs_exit(struct nsim_dev *nsim_dev) @@ -277,6 +285,27 @@ static void nsim_dev_debugfs_exit(struct nsim_dev *nsim_dev) debugfs_remove_recursive(nsim_dev->ddir); } +static ssize_t nsim_dev_rate_parent_read(struct file *file, + char __user *data, + size_t count, loff_t *ppos) +{ + char **name_ptr = file->private_data; + size_t len; + + if (!*name_ptr) + return 0; + + len = strlen(*name_ptr); + return simple_read_from_buffer(data, count, ppos, *name_ptr, len); +} + +static const struct file_operations nsim_dev_rate_parent_fops = { + .open = simple_open, + .read = nsim_dev_rate_parent_read, + .llseek = generic_file_llseek, + .owner = THIS_MODULE, +}; + static int nsim_dev_port_debugfs_init(struct nsim_dev *nsim_dev, struct nsim_dev_port *nsim_dev_port) { @@ -299,6 +328,11 @@ static int nsim_dev_port_debugfs_init(struct nsim_dev *nsim_dev, &nsim_bus_dev->vfconfigs[vf_id].min_tx_rate); debugfs_create_u16("tx_max", 0400, nsim_dev_port->ddir, &nsim_bus_dev->vfconfigs[vf_id].max_tx_rate); + nsim_dev_port->rate_parent = debugfs_create_file("rate_parent", + 0400, + nsim_dev_port->ddir, + &nsim_dev_port->parent_name, + &nsim_dev_rate_parent_fops); } debugfs_create_symlink("dev", nsim_dev_port->ddir, dev_link_name); @@ -1068,6 +1102,8 @@ static int nsim_leaf_tx_max_set(struct devlink_rate *devlink_rate, void *priv, struct nsim_rate_node { struct dentry *ddir; + struct dentry *rate_parent; + char *parent_name; u16 tx_share; u16 tx_max; }; @@ -1105,6 +1141,7 @@ static int nsim_rate_node_new(struct devlink_rate *node, void **priv, { struct nsim_dev *nsim_dev = devlink_priv(node->devlink); struct nsim_rate_node *nsim_node; + int err; if (!nsim_esw_mode_is_switchdev(nsim_dev)) { NL_SET_ERR_MSG_MOD(extack, "Node creation allowed only in switchdev mode."); @@ -1117,13 +1154,28 @@ static int nsim_rate_node_new(struct devlink_rate *node, void **priv, nsim_node->ddir = debugfs_create_dir(node->name, nsim_dev->nodes_ddir); if (!nsim_node->ddir) { - kfree(nsim_node); - return -ENOMEM; + err = -ENOMEM; + goto err_node; } debugfs_create_u16("tx_share", 0400, nsim_node->ddir, &nsim_node->tx_share); debugfs_create_u16("tx_max", 0400, nsim_node->ddir, &nsim_node->tx_max); + nsim_node->rate_parent = debugfs_create_file("rate_parent", 0400, + nsim_node->ddir, + &nsim_node->parent_name, + &nsim_dev_rate_parent_fops); + if (IS_ERR(nsim_node->rate_parent)) { + err = PTR_ERR(nsim_node->rate_parent); + goto err_ddir; + } + *priv = nsim_node; return 0; + +err_ddir: + debugfs_remove_recursive(nsim_node->ddir); +err_node: + kfree(nsim_node); + return err; } static int nsim_rate_node_del(struct devlink_rate *node, void *priv, @@ -1131,11 +1183,40 @@ static int nsim_rate_node_del(struct devlink_rate *node, void *priv, { struct nsim_rate_node *nsim_node = priv; + debugfs_remove(nsim_node->rate_parent); debugfs_remove_recursive(nsim_node->ddir); kfree(nsim_node); return 0; } +static int nsim_rate_leaf_parent_set(struct devlink_rate *child, + struct devlink_rate *parent, + void *priv_child, void *priv_parent, + struct netlink_ext_ack *extack) +{ + struct nsim_dev_port *nsim_dev_port = priv_child; + + if (parent) + nsim_dev_port->parent_name = parent->name; + else + nsim_dev_port->parent_name = NULL; + return 0; +} + +static int nsim_rate_node_parent_set(struct devlink_rate *child, + struct devlink_rate *parent, + void *priv_child, void *priv_parent, + struct netlink_ext_ack *extack) +{ + struct nsim_rate_node *nsim_node = priv_child; + + if (parent) + nsim_node->parent_name = parent->name; + else + nsim_node->parent_name = NULL; + return 0; +} + static const struct devlink_ops nsim_dev_devlink_ops = { .eswitch_mode_set = nsim_devlink_eswitch_mode_set, .eswitch_mode_get = nsim_devlink_eswitch_mode_get, @@ -1157,6 +1238,8 @@ static int nsim_rate_node_del(struct devlink_rate *node, void *priv, .rate_node_tx_max_set = nsim_node_tx_max_set, .rate_node_new = nsim_rate_node_new, .rate_node_del = nsim_rate_node_del, + .rate_leaf_parent_set = nsim_rate_leaf_parent_set, + .rate_node_parent_set = nsim_rate_node_parent_set, }; #define NSIM_DEV_MAX_MACS_DEFAULT 32 diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index d62a138..cdfdf2a 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -211,6 +211,8 @@ struct nsim_dev_port { unsigned int port_index; enum nsim_dev_port_type port_type; struct dentry *ddir; + struct dentry *rate_parent; + char *parent_name; struct netdevsim *ns; }; From patchwork Wed Jun 2 12:17:30 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 453060 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 F1073C47083 for ; Wed, 2 Jun 2021 12:18:56 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D5F79613DD for ; Wed, 2 Jun 2021 12:18:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230019AbhFBMUi (ORCPT ); Wed, 2 Jun 2021 08:20:38 -0400 Received: from mail-dm6nam11on2085.outbound.protection.outlook.com ([40.107.223.85]:51664 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229593AbhFBMUJ (ORCPT ); Wed, 2 Jun 2021 08:20:09 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cms1Zj+st1Lf8IBtCZIZlq4ZTTz0PaJ/oug2+YQUectOtQIqp7Vq8Wa2LYONLTBdbVOcxgD3Siba8+hvb8D9MCEDVNLMN7PmrZiO/PMTybsvuIfXcYIUKy4c4rSVkmWsD7Wr9JRgVO1n/IrE/iIR9/j0+MS4TjEm8JGfG24qfo8asUWXkHOg+8V2NliJeLO5gjHxHEjkHrGM45kdKhBcMfL/dwsa0Gdnir/A7Ovg91HGQ7dR9XQU7MsSan2/9XF2LsXR0b/TwY17DgVaFs0H4G/Pey/mH9WQhSUTWiDl5fEmGhDdGTlZGoDwnLvaFOh/SDjYWcY5HmVb3ymUSneV+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=A2LzdaZnx3savQDZ5ujq1YZvvNiCMxv3ZqPMRzXpoCs=; b=QJmznlxhCjeIyeJsfcY2kafShScOpMtrC2KprmRPsIXObeug6G1HVveyOz9/+4d3j1oNVF19gPek8YqEZaWU6XtTQnpbctcJGS8S1Y6p9vj9Ql9Bu/6Uin/9Jj/U8ILYM/6t+0g56kiWUrlGOEolDwXlxv6HwcKDXeuzbeMG4lcqB16AjTkYiQkI8BCUrydkN1Zt1Hac4u8bUJ+au7gIvLtO3DJp0015UhszJJHzvZSGxiCM2un9WWXqVv+iZhVpvcwvPqYE/BM1HgpRSmIy9FEkdb6ykXkfhHrPPjAM4IlNqK34UlAtYgvBu/GfbJSpjyXGPwpNYvFz2/iV9QGWuA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=A2LzdaZnx3savQDZ5ujq1YZvvNiCMxv3ZqPMRzXpoCs=; b=gk62X+TWD/gi86BIvOzY2JschDPkiPvPcZAA4bOX/ZBdnV/w+WAgNgOhItRJvjIE1pB+TGhip+tHCHN18ODrwv+0fPnbLfzSVA+JLtEFpDlSFzUvjgHFS0reCmgMmUmxklfoEjHdn3N8co+cApyof+a1Nath/QOB/eYs9fiVG7d90a4KcBXG9x0dcWebGmBOamHQnpR4rLwwyvxRAxLeR3MbqdHVuM0j4xNWOFIVwx8dXx5MVlRDzs3p6j73kZgZDiTvNhc4SwwItmcu9YeocdUeft7i7R4VT4hCgAmCifeY1HJEn9lKNXKkiS8r153AGIHyGxjx7PBeMgkSq1/jsA== Received: from MWHPR12CA0037.namprd12.prod.outlook.com (2603:10b6:301:2::23) by BL0PR12MB2353.namprd12.prod.outlook.com (2603:10b6:207:4c::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.26; Wed, 2 Jun 2021 12:18:25 +0000 Received: from CO1NAM11FT068.eop-nam11.prod.protection.outlook.com (2603:10b6:301:2:cafe::ff) by MWHPR12CA0037.outlook.office365.com (2603:10b6:301:2::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Wed, 2 Jun 2021 12:18:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.35 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.35; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.35) by CO1NAM11FT068.mail.protection.outlook.com (10.13.175.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4150.30 via Frontend Transport; Wed, 2 Jun 2021 12:18:24 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL111.nvidia.com (172.20.187.18) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 12:18:24 +0000 Received: from vdi.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Jun 2021 05:18:21 -0700 From: To: CC: , , , , , , , , Dmytro Linkin Subject: [PATCH RESEND net-next v3 17/18] selftest: netdevsim: Add devlink rate grouping test Date: Wed, 2 Jun 2021 15:17:30 +0300 Message-ID: <1622636251-29892-18-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> References: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 30bd918c-549f-48d0-df32-08d925c0852a X-MS-TrafficTypeDiagnostic: BL0PR12MB2353: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:1013; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: o1bA2Aq+xizA/Q6ghy7DG67WGQwrHinPpIeujGn5P+CfOH2nLb0b0Ni1w1x8L7zVNBUzYdaNR1So016A/HTHXGG3YvQPMD69fihqZwHbT++OzJ03wAzXv7Jla449JqxzXSIbP3cHEc6qiPpiIrES0qLADNZwOVejSNxjUPX3iRoxyfTkqlkFadXh1oRAzqseepjgB+QHZIWmRJDCvq8cu/AiQ3UeVnkd/4CFGKG+h6OSW1UsMAfxPZppfWaTdr1+k5nruVMKhaZD4OYJTSD2bJzND2Ny3bYjQFM5Qzcrr4UjO/479Tm6+qOlDUCawHaeIJx0aiap5Szrh3WFu04zuYuwXA33QrNsKIMKL5CJgBKQikhwb1Jmtk9TVfT25/y2Y7bo+mPu5B+udUU7AblJNRsYQLTxfsG9eCI3TWO5D1GD7FgXwTyxa+LSTsWW6/UzFMGZFkHlkaQftF/KD2ICz6egcP+ya9YeNQhrnP9Nx/2c+UfBgtIMtfHSIKI9CuOntF2IQITz2Jz4BlNvzEcyk+muSzCGBDjFhavl7wy4mg2RLMrPRkTu09tbkujM/7d4uFjJEEr5xNnF4I196uunaw0800h/bLmLU3Q0s6vVY830KP1rrrqV4Vkh37rxZuSk6ZBwkoc3TF9O0zEhm9rkmA== X-Forefront-Antispam-Report: CIP:216.228.112.35; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid04.nvidia.com; CAT:NONE; SFS:(4636009)(376002)(396003)(136003)(346002)(39860400002)(46966006)(36840700001)(86362001)(6666004)(8936002)(107886003)(356005)(8676002)(316002)(36906005)(7636003)(82310400003)(54906003)(2876002)(2616005)(7696005)(36756003)(36860700001)(5660300002)(426003)(70206006)(186003)(82740400003)(47076005)(4326008)(70586007)(83380400001)(2906002)(6916009)(26005)(336012)(478600001); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 12:18:24.6574 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 30bd918c-549f-48d0-df32-08d925c0852a X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.35]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: CO1NAM11FT068.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB2353 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Dmytro Linkin Test verifies that netdevsim correctly implements devlink ops callbacks that set node as a parent of devlink leaf or node rate object. Co-developed-by: Vlad Buslov Signed-off-by: Vlad Buslov Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- .../selftests/drivers/net/netdevsim/devlink.sh | 42 ++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh index 301d920..9de1d12 100755 --- a/tools/testing/selftests/drivers/net/netdevsim/devlink.sh +++ b/tools/testing/selftests/drivers/net/netdevsim/devlink.sh @@ -563,6 +563,26 @@ rate_attr_tx_rate_check() check_err $? "Unexpected $name attr value $api_value != $rate" } +rate_attr_parent_check() +{ + local handle=$1 + local parent=$2 + local debug_file=$3 + + rate_attr_set $handle parent $parent + check_err $? "Failed to set parent" + + debug_value=$(cat $debug_file) + check_err $? "Failed to get parent debugfs value" + [ "$debug_value" == "$parent" ] + check_err $? "Unexpected parent debug value $debug_value != $parent" + + api_value=$(rate_attr_get $r_obj parent) + check_err $? "Failed to get parent attr value" + [ "$api_value" == "$parent" ] + check_err $? "Unexpected parent attr value $api_value != $parent" +} + rate_node_add() { local handle=$1 @@ -627,6 +647,28 @@ rate_test() [ $num_nodes == 0 ] check_err $? "Expected 0 rate node but got $num_nodes" + local node1_name='group1' + local node1="$DL_HANDLE/$node1_name" + rate_node_add "$node1" + check_err $? "Failed to add node $node1" + + rate_attr_parent_check $r_obj $node1_name \ + $DEBUGFS_DIR/ports/${r_obj##*/}/rate_parent + + local node2_name='group2' + local node2="$DL_HANDLE/$node2_name" + rate_node_add "$node2" + check_err $? "Failed to add node $node2" + + rate_attr_parent_check $node2 $node1_name \ + $DEBUGFS_DIR/rate_nodes/$node2_name/rate_parent + rate_node_del "$node2" + check_err $? "Failed to delete node $node2" + rate_attr_set "$r_obj" noparent + check_err $? "Failed to unset $r_obj parent node" + rate_node_del "$node1" + check_err $? "Failed to delete node $node1" + log_test "rate test" } From patchwork Wed Jun 2 12:17:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 453921 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=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, 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 DA46BC4708F for ; Wed, 2 Jun 2021 12:18:58 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BDDC4613B8 for ; Wed, 2 Jun 2021 12:18:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229957AbhFBMUk (ORCPT ); Wed, 2 Jun 2021 08:20:40 -0400 Received: from mail-bn8nam11on2053.outbound.protection.outlook.com ([40.107.236.53]:24737 "EHLO NAM11-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S229999AbhFBMUM (ORCPT ); Wed, 2 Jun 2021 08:20:12 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TptjN9TbxGNtdipg9fbMqpaKBB9PHUzm6Zlde2rgGmUi5kFHVIdy988YUTxO22rconF5g0ikX3S5751ojlqj7BUiJ8HLHX1zF0/Umc04eLmanApdHJUwao3t61gQxMvd6wCgPuOXs3GDACrXWozbD1yckKj8IHndHxXdlWpGdD3req9adet+QPR7+fLOJN7YK36BZLra8H/vY72e3wcPKqdcKjZKEso0oVncy7A5c3JJeabdBLj4xK/GSG4IVz9P4zuo9UkVgEaZflQtKwNPvIkcYomTxuYvhv/KTvUIS37jDKkoCSia7ibmqb/Sia6+5nmfR0bLwcCG54lC0ZlSfQ== 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=tBPq8br7bzVSLj7j04iZjzzzb1UwrpqmKDdAubcS680=; b=fA4vTh/J3fdXq3LVhQkLYKIrJulp1gXSRrVWhlorJPlSHm2Nq3UYLcNBVJb2hfQWiC9yL3OvJLsnEXQdnb2NVjwsA2QMQK5PLttSmX9cFU2dcJ7CgHoBiz8s6QP66oZaj0S2GT5eE/YD53i6XeWUd22g/6B9FwbOF/R49PgXHfW8OPAt7JF1T2p2fyE1JXp7ZviKWBf+jo+vY10p43Wf61SNYryQrvlolbaOXZngtYKmpTGDi0Tz88Y9vmQvbCZtst34sOhcqSNe4dF4EkcsBLvbJllXA/Fbkd84a5GeJecGhb0PiBqgbJoZop5h9NdWRHYke7qZbblpaxG1qTMrBQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.32) smtp.rcpttodomain=networkplumber.org smtp.mailfrom=nvidia.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=nvidia.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=tBPq8br7bzVSLj7j04iZjzzzb1UwrpqmKDdAubcS680=; b=uH+Tks5yi/3HGnHtvgOZhU7nXNDBYue187GbuvwUopa7KhM12eIaSN+FshpPcRj/JQRwATUlKJFnaELDAc6xW/5GxlD7vHUwo4AMEVM9YKMXtAT2P2PL5M+NTTalO1aHXcz8cMK7oYo7PpoUnJZqLRpSZwurq0DDdRxC1jzMHJ4gjiSCR7mmCXJUxtJKUm238XFjxfJN1eNJr+EhaP5jTPxl0zqlW4TscU9Xe6eiqbIX1bm1hB2kS+o0UsR8tQwFtLcTgojfSuXEg0SPY1thWJNdERh+0FZ/z07GcCuDmn/Cn08GgxVII1hn25AK5cTuxOpnsV0yzumUP6wuvhviQg== Received: from BN0PR04CA0150.namprd04.prod.outlook.com (2603:10b6:408:ed::35) by BN6PR12MB1571.namprd12.prod.outlook.com (2603:10b6:405:4::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.20; Wed, 2 Jun 2021 12:18:28 +0000 Received: from BN8NAM11FT046.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ed:cafe::63) by BN0PR04CA0150.outlook.office365.com (2603:10b6:408:ed::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4195.15 via Frontend Transport; Wed, 2 Jun 2021 12:18:28 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.32) smtp.mailfrom=nvidia.com; networkplumber.org; dkim=none (message not signed) header.d=none;networkplumber.org; dmarc=pass action=none header.from=nvidia.com; Received-SPF: Pass (protection.outlook.com: domain of nvidia.com designates 216.228.112.32 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.32; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.32) by BN8NAM11FT046.mail.protection.outlook.com (10.13.177.127) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4150.30 via Frontend Transport; Wed, 2 Jun 2021 12:18:28 +0000 Received: from HQMAIL109.nvidia.com (172.20.187.15) by HQMAIL109.nvidia.com (172.20.187.15) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 2 Jun 2021 05:18:26 -0700 Received: from vdi.nvidia.com (172.20.187.5) by mail.nvidia.com (172.20.187.15) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 2 Jun 2021 05:18:24 -0700 From: To: CC: , , , , , , , , Dmytro Linkin Subject: [PATCH RESEND net-next v3 18/18] Documentation: devlink rate objects Date: Wed, 2 Jun 2021 15:17:31 +0300 Message-ID: <1622636251-29892-19-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> References: <1622636251-29892-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: d8d4e993-0839-4a0b-78ba-08d925c08743 X-MS-TrafficTypeDiagnostic: BN6PR12MB1571: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:9508; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TTuwHVAJSyYybTBQT+RZnsIgh6k1cwrw1uUlYibK5cU7Dl3cvjb7sViV0btwL3qFc/zezEEAcqjGnFdYBBhpCsxjrdQNXCjTY4DiMFsGLWvP1ImWl6yAG23Mj1V7l7hf/PxNhw8cuwfxOGHIk8wp7DTtRKJmfnUkxK9/XSnoi5QqMroL1yLJ+NXlEe8QDDERQBneP2dTQfejU+3itTb1h9C962YB2W7uIPD1qeOQ/KSySA+cAzHZLI7XewyDUA2Ex8FxvSk5pVWrkgrH/lKQvcUGYIOs5v7vlf083WYz8qTsGciVSfh7r9xglI0+eirtaZpASpMtBlmCvv/GT3BbCffaBR78Qe7Wu5NAqtdd+qzt2t5dGyxWY/m4BaKGcqMWVmTHjrH0Zn3p7VPefoy4qfQkuKvrrFRaN2Kmf26gp5ZJXttiEADvMEh64ieHfuvK+nBwsHtpZrWW2xKgm9IEVJfbantDB84gLr6tnuEYeh77XF06odmhD9/cBiE8mnZXnXgjX3wPDBReQ1BNY4wsFyd/0iCxRTqb1Q5n7LUH1HuzIRqMl9V4hV0yLs9GxcvJfgA6l2xkbLUtEUb0EmQa7QChM5Z4Jqo7gV2Lmqw6G2r57trwtYcgkcq2apeHIwUiFrTHkHm276Osa+jmNDN+Kv7D5VXGAd5yj48SBQG1QhE= X-Forefront-Antispam-Report: CIP:216.228.112.32; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid01.nvidia.com; CAT:NONE; SFS:(4636009)(346002)(39860400002)(376002)(396003)(136003)(46966006)(36840700001)(356005)(7636003)(478600001)(5660300002)(426003)(82740400003)(316002)(83380400001)(2616005)(107886003)(54906003)(70586007)(6666004)(26005)(186003)(70206006)(2876002)(36860700001)(82310400003)(336012)(47076005)(86362001)(4326008)(36756003)(8676002)(2906002)(8936002)(6916009)(7696005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Jun 2021 12:18:28.0231 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: d8d4e993-0839-4a0b-78ba-08d925c08743 X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=43083d15-7273-40c1-b7db-39efd9ccc17a; Ip=[216.228.112.32]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT046.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1571 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Dmytro Linkin Add devlink rate objects section at devlink port documentation. Add devlink rate support info at netdevsim devlink documentation. Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- Documentation/networking/devlink/devlink-port.rst | 35 +++++++++++++++++++++++ Documentation/networking/devlink/netdevsim.rst | 26 +++++++++++++++++ 2 files changed, 61 insertions(+) diff --git a/Documentation/networking/devlink/devlink-port.rst b/Documentation/networking/devlink/devlink-port.rst index ab790e7..7627b1d 100644 --- a/Documentation/networking/devlink/devlink-port.rst +++ b/Documentation/networking/devlink/devlink-port.rst @@ -164,6 +164,41 @@ device to instantiate the subfunction device on particular PCI function. A subfunction device is created on the :ref:`Documentation/driver-api/auxiliary_bus.rst `. At this point a matching subfunction driver binds to the subfunction's auxiliary device. +Rate object management +====================== + +Devlink provides API to manage tx rates of single devlink port or a group. +This is done through rate objects, which can be one of the two types: + +``leaf`` + Represents a single devlink port; created/destroyed by the driver. Since leaf + have 1to1 mapping to its devlink port, in user space it is referred as + ``pci//``; + +``node`` + Represents a group of rate objects (leafs and/or nodes); created/deleted by + request from the userspace; initially empty (no rate objects added). In + userspace it is referred as ``pci//``, where + ``node_name`` can be any identifier, except decimal number, to avoid + collisions with leafs. + +API allows to configure following rate object's parameters: + +``tx_share`` + Minimum TX rate value shared among all other rate objects, or rate objects + that parts of the parent group, if it is a part of the same group. + +``tx_max`` + Maximum TX rate value. + +``parent`` + Parent node name. Parent node rate limits are considered as additional limits + to all node children limits. ``tx_max`` is an upper limit for children. + ``tx_share`` is a total bandwidth distributed among children. + +Driver implementations are allowed to support both or either rate object types +and setting methods of their parameters. + Terms and Definitions ===================== diff --git a/Documentation/networking/devlink/netdevsim.rst b/Documentation/networking/devlink/netdevsim.rst index 02c2d20..8a292fb 100644 --- a/Documentation/networking/devlink/netdevsim.rst +++ b/Documentation/networking/devlink/netdevsim.rst @@ -57,6 +57,32 @@ entries, FIB rule entries and nexthops that the driver will allow. $ devlink resource set netdevsim/netdevsim0 path /nexthops size 16 $ devlink dev reload netdevsim/netdevsim0 +Rate objects +============ + +The ``netdevsim`` driver supports rate objects management, which includes: + +- registerging/unregistering leaf rate objects per VF devlink port; +- creation/deletion node rate objects; +- setting tx_share and tx_max rate values for any rate object type; +- setting parent node for any rate object type. + +Rate nodes and it's parameters are exposed in ``netdevsim`` debugfs in RO mode. +For example created rate node with name ``some_group``: + +.. code:: shell + + $ ls /sys/kernel/debug/netdevsim/netdevsim0/rate_groups/some_group + rate_parent tx_max tx_share + +Same parameters are exposed for leaf objects in corresponding ports directories. +For ex.: + +.. code:: shell + + $ ls /sys/kernel/debug/netdevsim/netdevsim0/ports/1 + dev ethtool rate_parent tx_max tx_share + Driver-specific Traps =====================