From patchwork Wed Apr 21 15:52:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 425755 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,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 5C850C433ED for ; Wed, 21 Apr 2021 15:53:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 235D061445 for ; Wed, 21 Apr 2021 15:53:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244103AbhDUPx6 (ORCPT ); Wed, 21 Apr 2021 11:53:58 -0400 Received: from mail-bn8nam12on2041.outbound.protection.outlook.com ([40.107.237.41]:36320 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S243720AbhDUPxt (ORCPT ); Wed, 21 Apr 2021 11:53:49 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TRg0dqZtL+y6neqiaUj8jxHlNi1XXqehENK1GixHEo/XX4eQmRnean5m2kYg31y17zfs8p5gpsx3Lof3AUUtWaHkPMhgkaFxF7pH5/z8og6Ex7HlxPKavQR+tU9HeknAeVOwTXlZR4qzWP0fOXqVFsbByGFUxQ40mm48oJgVBvjxF9W2QovhzrYlT7mgqfdioMWvrn+Z2f0NpPb4whzBg283GWbxoh7mIQOm1r1Jfis5BPe5eYTMknKiK149FCApgQCl7xES52YqrJInoPCr6ewX0nSpOaUHDamVSbds/5nuPr6iZXE6qFzUMfS8rhO9DqkX2rvfMOcgOhi9/GsbJw== 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=uRR3KKHr4sWyA9SIvxQ0UvsB1Ur5N2+g2WqlGIxyohI=; b=N98D9l/xsxz2S7up5aOIle9q6b83dma1TyP5Gkv2ihdxsMXeYVgAw8hDh+FZ8sci+hrJ+65wjSG/w5FhawrwbdUVfzYbniyLOvV+8I4jm77uMzh7rvlMDLOA2ofX95w8+bbMEZXp6bkslYhpJmc80LYmGOYrLy9nLEsEZbiU6I4IYHRipht5c9pkfUFPKU+HTJ/t1f4hdAgP3+/smuQzu5fokAAOG8obbiJPgCoLOkTwMzJHZ2htlb+JjidjSJOF8S+eyc74hOGhMxsXMhlpNtXe1CpB+0ZEsmPK3ouG3Q5qp/PZjXy4fOs9CA/3hcZ9laWlEKO9CKMk8zjW5nOeAA== 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=uRR3KKHr4sWyA9SIvxQ0UvsB1Ur5N2+g2WqlGIxyohI=; b=ASS2bvIf4uFTfYITdNMR5TPZIpOjNPAMnGxSF3aL8/Zf1hCSv7i0Gohv7XIDyVoaJcAdonDMUspxxneM29usNga8gF9FJt5JLlUabAYqcauHCDGKWVi2J/0pylZ0rO+nlKKY01pLxuAYLttStAc18FtEFsxrhSa2xGJ5SrptOxZ/cYNu/t8h2gIl5B7f5GJMG2SnRDSBgOQKA/SLoYHoNyiAOSDCrfNrT9al0Ymy8UhG7W+dVpzA5dx8LPxlgwwainIFztooAjvctQti+rHbrTvS894o5IiUl3xGNIqoy+vxr+RXFxSeH/j7YD9EehVCX508JHz0uXZWAVRA/TwlGA== Received: from BN6PR1401CA0015.namprd14.prod.outlook.com (2603:10b6:405:4b::25) by BN6PR12MB1172.namprd12.prod.outlook.com (2603:10b6:404:1f::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.20; Wed, 21 Apr 2021 15:53:14 +0000 Received: from BN8NAM11FT063.eop-nam11.prod.protection.outlook.com (2603:10b6:405:4b:cafe::fa) by BN6PR1401CA0015.outlook.office365.com (2603:10b6:405:4b::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.20 via Frontend Transport; Wed, 21 Apr 2021 15:53:14 +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 BN8NAM11FT063.mail.protection.outlook.com (10.13.177.110) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4065.21 via Frontend Transport; Wed, 21 Apr 2021 15:53:14 +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, 21 Apr 2021 15:53:13 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.12) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 21 Apr 2021 15:53:11 +0000 From: To: CC: , , , , , , Dmytro Linkin Subject: [PATCH RESEND-2 RFC net-next 02/18] netdevsim: Disable VFs on nsim_dev_reload_destroy() call Date: Wed, 21 Apr 2021 18:52:49 +0300 Message-ID: <1619020385-20220-3-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1619020385-20220-1-git-send-email-dlinkin@nvidia.com> References: <1619020385-20220-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 34f48a0c-650f-4cce-9c19-08d904dd92bc X-MS-TrafficTypeDiagnostic: BN6PR12MB1172: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:469; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TbAs9DcgGklHZZlvTetZ/cfjLHGbEtg2Rokd4KNW3m02zr2bdysWSH1UtWJRqx+JmxjEkVNZJq6BpurkG0v+b4x4tU/1Z8mqb6BMQCSwP4EMCl30iSS2w8/mLqhpj+8k9FnwsM2E7B9fO5s75DVJFrep6C1wGZAFsIsuH1mrvVTiKrSw6LkBrZXduWAj/JJyJQDhvzjxmpg7VlDHFI5qmxD9NkcqqQAEAZAxFQJjK1Gcj/FWul1j7dvle5zAI8vPISoultaK4cf4QhvrrO8EkBnhpv0jizB/bqGK5Q6CQWckyC0s+uuRQn3AB84YQJBhjecTwShV0+9RJtRSoct1+IVnnF7kAfhFjTCL97bBattXrHFZHl6jXH2haXNeo4MhFxgvd072EjK0HJ4zc4nAkcVW5b998LrPRsk9hR/8w8q2KtetfY+wyFXZlsCycvi8Mct5XwyPDWq8VGUL4uzMubiaYQyt1Yu7tBLZHdFDfdKd4tr7Es3Nv5skj6D9j1fZa7PdQEafr8zPWvOpAJAoazKv5rSrTMed7DMEQypDIjPANhjai6iy87OIBBp/I/MLopZDXoQaCpRSwRJvwDv1No2y+NyBe4Udi3ZmFNBbgNjvC/qpBR7/eNlk/vOt0RjOd5uD5ExeHMoIFHmwZK4IOHkSzJodgAjs0FpM2b1RBAg= 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)(396003)(136003)(346002)(39860400002)(376002)(36840700001)(46966006)(2616005)(6666004)(107886003)(426003)(316002)(4326008)(36756003)(2876002)(70586007)(2906002)(26005)(186003)(8936002)(82740400003)(7636003)(86362001)(70206006)(36906005)(82310400003)(336012)(36860700001)(83380400001)(356005)(47076005)(5660300002)(54906003)(478600001)(8676002)(6916009)(7696005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2021 15:53:14.3754 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 34f48a0c-650f-4cce-9c19-08d904dd92bc 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: BN8NAM11FT063.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1172 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Dmytro Linkin Move VFs disabling from device release() to nsim_dev_reload_destroy() to make VFs disabling and ports removal simultaneous. This is a requirement for VFs ports implemented in next patches. Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- drivers/net/netdevsim/bus.c | 5 +---- drivers/net/netdevsim/dev.c | 6 ++++++ drivers/net/netdevsim/netdevsim.h | 1 + 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/net/netdevsim/bus.c b/drivers/net/netdevsim/bus.c index 4bd7ef3c..d5c547c 100644 --- a/drivers/net/netdevsim/bus.c +++ b/drivers/net/netdevsim/bus.c @@ -37,7 +37,7 @@ static int nsim_bus_dev_vfs_enable(struct nsim_bus_dev *nsim_bus_dev, return 0; } -static void nsim_bus_dev_vfs_disable(struct nsim_bus_dev *nsim_bus_dev) +void nsim_bus_dev_vfs_disable(struct nsim_bus_dev *nsim_bus_dev) { nsim_bus_dev->num_vfs = 0; } @@ -233,9 +233,6 @@ ssize_t nsim_bus_dev_max_vfs_write(struct file *file, static void nsim_bus_dev_release(struct device *dev) { - struct nsim_bus_dev *nsim_bus_dev = to_nsim_bus_dev(dev); - - nsim_bus_dev_vfs_disable(nsim_bus_dev); } static struct device_type nsim_bus_dev_type = { diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 12df93a..cd50c05 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -1182,6 +1182,12 @@ static void nsim_dev_reload_destroy(struct nsim_dev *nsim_dev) if (devlink_is_reload_failed(devlink)) return; debugfs_remove(nsim_dev->take_snapshot); + + mutex_lock(&nsim_dev->nsim_bus_dev->vfs_lock); + if (nsim_dev->nsim_bus_dev->num_vfs) + nsim_bus_dev_vfs_disable(nsim_dev->nsim_bus_dev); + mutex_unlock(&nsim_dev->nsim_bus_dev->vfs_lock); + nsim_dev_port_del_all(nsim_dev); nsim_dev_psample_exit(nsim_dev); nsim_dev_health_exit(nsim_dev); diff --git a/drivers/net/netdevsim/netdevsim.h b/drivers/net/netdevsim/netdevsim.h index 12f56f2..a1b49c8 100644 --- a/drivers/net/netdevsim/netdevsim.h +++ b/drivers/net/netdevsim/netdevsim.h @@ -276,6 +276,7 @@ ssize_t nsim_bus_dev_max_vfs_read(struct file *file, ssize_t nsim_bus_dev_max_vfs_write(struct file *file, const char __user *data, size_t count, loff_t *ppos); +void nsim_bus_dev_vfs_disable(struct nsim_bus_dev *nsim_bus_dev); #if IS_ENABLED(CONFIG_XFRM_OFFLOAD) void nsim_ipsec_init(struct netdevsim *ns); From patchwork Wed Apr 21 15:52:51 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 425747 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,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 7648EC433B4 for ; Wed, 21 Apr 2021 15:54:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4AB446144B for ; Wed, 21 Apr 2021 15:54:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244158AbhDUPyy (ORCPT ); Wed, 21 Apr 2021 11:54:54 -0400 Received: from mail-eopbgr770051.outbound.protection.outlook.com ([40.107.77.51]:19818 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S236609AbhDUPxx (ORCPT ); Wed, 21 Apr 2021 11:53:53 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JAU11JJanzQxDiqln2PPMF01wMtBn9pToToERUcb5Yp6C7f8RXXaZk8lhYiB+Vdi2UGJTNWe4VcG2uQv9pmg2cm9wEDCDehbcUzKq+8Yb0qvkVX+2eJuSNKdXWznHW1E59PI8oi/nQwdTjoqzxbTvLMX2qQ5wDH+jBcetfuQ1ZMgkSnDwMb3b8caAqYEt53B+WMIG2gMX28Ov2rQRfkttOr1pq6ZuQeLY57MCpWLlORLw7Rpo5yurjD17um3aPZx1ky2yGuWAL8CKE73Qe2SjcTNZL5Wh8rQTVLq8Xs78xZ/ftwrfq33WWhzO0AM4lD6eVKP0fgQYvqSgR6iTQ57AQ== 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=Pb5rOyXCWA4y7OrW2JBMT1Cbso6REtZqTl3fzfq51BM=; b=aImosJ7mPjAGhDaWVaRbfN8GNl0JHndgDhQzrhp2X/Rt71+agdx7xty3osNU2EXh+ePDIjOUDM9pD1KqBLTz/OXbTSJp6FcMP6094Yypj4mUaoYg1S8f9PKzVQ4LcG4b0bWh9vNsupTzXdD0RuYjjgVI0KayJbLI4+OlYxk8VaYbA3RvQmFUtxwFHOLtW31yrGo5iqUv4TnjEflKv58sOzxvcLZcOCgF0vgDJoM1Sgago+pDrhNeNBi6ydUEbaIA4Iy7lnlNvj/q1Y1MXw4hv2+WybVVWO4iixvZCg5n2pzHtLo33C7A17SPILW5aYW2v43cO1LP7nDAYbkoXSnWAg== 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=Pb5rOyXCWA4y7OrW2JBMT1Cbso6REtZqTl3fzfq51BM=; b=oVwQ0yi3X1N02Gl1Fq/p/o66YMxnIOvsXgtt1FJ90KHmiHx4Wqn6majGP+IiqviDOpX+ivjM8mFhy7YUN1jWse4wlu6qvfZkrtDoUwPEY2oAsQf6kXpfIDFV2cvAGdNzaPOUpoTyyahfLHIYouPxaF0szpek7hYSEsBMBnj7RSqmVXJFzFvf/NOw63lXTc8XcJwXF7/gqdJcvlqoDrwXKhjrh9bfYL4yRTiXQ8+yyCNtE8OL+n/qiNsHkUGaBccZA+O4OHTasVfDX1sVhY/MdMEdsY9ewPvpqw4XwswLd6DAZq4HbHniEdKN1fnH7eExkgFS4s7ChStbIkfVgWpgsg== Received: from CO1PR15CA0070.namprd15.prod.outlook.com (2603:10b6:101:20::14) by BL0PR12MB2467.namprd12.prod.outlook.com (2603:10b6:207:4c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.20; Wed, 21 Apr 2021 15:53:19 +0000 Received: from CO1NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:101:20:cafe::b9) by CO1PR15CA0070.outlook.office365.com (2603:10b6:101:20::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.20 via Frontend Transport; Wed, 21 Apr 2021 15:53:19 +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 CO1NAM11FT009.mail.protection.outlook.com (10.13.175.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4065.21 via Frontend Transport; Wed, 21 Apr 2021 15:53:18 +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, 21 Apr 2021 08:53:18 -0700 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.12) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 21 Apr 2021 15:53:16 +0000 From: To: CC: , , , , , , Dmytro Linkin Subject: [PATCH RESEND-2 RFC net-next 04/18] netdevsim: Implement VFs Date: Wed, 21 Apr 2021 18:52:51 +0300 Message-ID: <1619020385-20220-5-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1619020385-20220-1-git-send-email-dlinkin@nvidia.com> References: <1619020385-20220-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ecf76293-3432-4a8f-f997-08d904dd957f X-MS-TrafficTypeDiagnostic: BL0PR12MB2467: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:2512; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /R5JUhqzfCgGUtOOyz2uXKdgi1YMrudoTX5yHm8uzhyHQy9WxJnkBi23QPDWWsM7woewTM8T4es9Ld0jLp4Y8BhSumD307Pdp7dmX8Z6mb4ZTDZO0qSjVn92/WBk52/uwdZuJ8THCBBe8kE73II+Hi7xsaDjNJJlzadcT8F/eqmHQF2cggp4N6Qvr88pEnq3tpPhoDF7MfSHBrzv4k60e2nHxJ6pNDaMYFX7njXEIIVwwO9pxXqskRQQlbD5OSw0pX0J2U/njGPPcrLemIdM8wT4ztDhJHiqkiyyT8ja5bcsNPXZ4wVIjqtDpzUJGGqdItAQqM7ys62NCz64AJxq9icyrnkVOJm45QlChUkcCEdpQ7xm25w+kia2BkuPKWH4G7IjRZg/Fn2kf3Ku3NIP1oHx20qjbOTvc1SrbXWP5JlnvgojoNSe7Uzmwv3AdmRSJ3sKelkdb8ljspFyKTOblzQQU09p5gYVTSIe5fqNeAIkSggGjHvdc65AqhqgErw9UTjFxyE2uaOhlx3olzt0FgVuNmWnZMZxFfiKYx26XTvLMzkaeXb/2kh7HnoA0/KkGV9JLbHu25/9wk/vuHdHw4iRjVXwPesAJDX3D1fMpYRjsWjxhjnI5HCoF9AU1djKU24uw3dyiLSPU88imfghDw== 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)(376002)(346002)(136003)(396003)(46966006)(36840700001)(2876002)(6666004)(26005)(316002)(2906002)(186003)(478600001)(54906003)(356005)(8936002)(82310400003)(7696005)(82740400003)(5660300002)(2616005)(107886003)(70206006)(4326008)(70586007)(8676002)(6916009)(36860700001)(7636003)(86362001)(83380400001)(426003)(336012)(36756003)(47076005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2021 15:53:18.9802 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ecf76293-3432-4a8f-f997-08d904dd957f 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: CO1NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB2467 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Dmytro Linkin Allow creation of netdevsim ports for VFs along with allocations of corresponding net devices and devlink ports. Add enums and helpers to distinguish PFs' ports from VFs' ports. Ports creation/deletion debugfs API intended to be used with physical ports only. VFs instantiation will be done in one of the next patches. Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- drivers/net/netdevsim/dev.c | 14 ++++++- drivers/net/netdevsim/netdev.c | 90 ++++++++++++++++++++++++++++++------------ 2 files changed, 77 insertions(+), 27 deletions(-) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 93d6f3d..8bd7654 100644 --- a/drivers/net/netdevsim/dev.c +++ b/drivers/net/netdevsim/dev.c @@ -945,11 +945,15 @@ static int nsim_dev_devlink_trap_init(struct devlink *devlink, static int __nsim_dev_port_add(struct nsim_dev *nsim_dev, enum nsim_dev_port_type type, unsigned int port_index) { + struct nsim_bus_dev *nsim_bus_dev = nsim_dev->nsim_bus_dev; struct devlink_port_attrs attrs = {}; struct nsim_dev_port *nsim_dev_port; struct devlink_port *devlink_port; int err; + if (type == NSIM_DEV_PORT_TYPE_VF && !nsim_bus_dev->num_vfs) + return -EINVAL; + nsim_dev_port = kzalloc(sizeof(*nsim_dev_port), GFP_KERNEL); if (!nsim_dev_port) return -ENOMEM; @@ -957,8 +961,14 @@ static int __nsim_dev_port_add(struct nsim_dev *nsim_dev, enum nsim_dev_port_typ nsim_dev_port->port_type = type; devlink_port = &nsim_dev_port->devlink_port; - attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL; - attrs.phys.port_number = port_index + 1; + if (nsim_dev_port_is_pf(nsim_dev_port)) { + attrs.flavour = DEVLINK_PORT_FLAVOUR_PHYSICAL; + attrs.phys.port_number = port_index + 1; + } else { + attrs.flavour = DEVLINK_PORT_FLAVOUR_PCI_VF; + attrs.pci_vf.pf = 0; + attrs.pci_vf.vf = port_index; + } memcpy(attrs.switch_id.id, nsim_dev->switch_id.id, nsim_dev->switch_id.id_len); attrs.switch_id.id_len = nsim_dev->switch_id.id_len; devlink_port_attrs_set(devlink_port, &attrs); diff --git a/drivers/net/netdevsim/netdev.c b/drivers/net/netdevsim/netdev.c index 659d3dc..9352e18 100644 --- a/drivers/net/netdevsim/netdev.c +++ b/drivers/net/netdevsim/netdev.c @@ -261,6 +261,18 @@ static struct devlink_port *nsim_get_devlink_port(struct net_device *dev) .ndo_get_devlink_port = nsim_get_devlink_port, }; +static const struct net_device_ops nsim_vf_netdev_ops = { + .ndo_start_xmit = nsim_start_xmit, + .ndo_set_rx_mode = nsim_set_rx_mode, + .ndo_set_mac_address = eth_mac_addr, + .ndo_validate_addr = eth_validate_addr, + .ndo_change_mtu = nsim_change_mtu, + .ndo_get_stats64 = nsim_get_stats64, + .ndo_setup_tc = nsim_setup_tc, + .ndo_set_features = nsim_set_features, + .ndo_get_devlink_port = nsim_get_devlink_port, +}; + static void nsim_setup(struct net_device *dev) { ether_setup(dev); @@ -280,6 +292,49 @@ static void nsim_setup(struct net_device *dev) dev->max_mtu = ETH_MAX_MTU; } +static int nsim_init_netdevsim(struct netdevsim *ns) +{ + int err; + + ns->netdev->netdev_ops = &nsim_netdev_ops; + + err = nsim_udp_tunnels_info_create(ns->nsim_dev, ns->netdev); + if (err) + return err; + + rtnl_lock(); + err = nsim_bpf_init(ns); + if (err) + goto err_utn_destroy; + + nsim_ipsec_init(ns); + + err = register_netdevice(ns->netdev); + if (err) + goto err_ipsec_teardown; + rtnl_unlock(); + return 0; + +err_ipsec_teardown: + nsim_ipsec_teardown(ns); + nsim_bpf_uninit(ns); +err_utn_destroy: + rtnl_unlock(); + nsim_udp_tunnels_info_destroy(ns->netdev); + return err; +} + +static int nsim_init_netdevsim_vf(struct netdevsim *ns) +{ + int err; + + ns->netdev->netdev_ops = &nsim_vf_netdev_ops; + rtnl_lock(); + err = register_netdevice(ns->netdev); + rtnl_unlock(); + return err; +} + struct netdevsim * nsim_create(struct nsim_dev *nsim_dev, struct nsim_dev_port *nsim_dev_port) { @@ -299,33 +354,15 @@ struct netdevsim * ns->nsim_dev_port = nsim_dev_port; ns->nsim_bus_dev = nsim_dev->nsim_bus_dev; SET_NETDEV_DEV(dev, &ns->nsim_bus_dev->dev); - dev->netdev_ops = &nsim_netdev_ops; nsim_ethtool_init(ns); - - err = nsim_udp_tunnels_info_create(nsim_dev, dev); + if (nsim_dev_port_is_pf(nsim_dev_port)) + err = nsim_init_netdevsim(ns); + else + err = nsim_init_netdevsim_vf(ns); if (err) goto err_free_netdev; - - rtnl_lock(); - err = nsim_bpf_init(ns); - if (err) - goto err_utn_destroy; - - nsim_ipsec_init(ns); - - err = register_netdevice(dev); - if (err) - goto err_ipsec_teardown; - rtnl_unlock(); - return ns; -err_ipsec_teardown: - nsim_ipsec_teardown(ns); - nsim_bpf_uninit(ns); -err_utn_destroy: - rtnl_unlock(); - nsim_udp_tunnels_info_destroy(dev); err_free_netdev: free_netdev(dev); return ERR_PTR(err); @@ -337,10 +374,13 @@ void nsim_destroy(struct netdevsim *ns) rtnl_lock(); unregister_netdevice(dev); - nsim_ipsec_teardown(ns); - nsim_bpf_uninit(ns); + if (nsim_dev_port_is_pf(ns->nsim_dev_port)) { + nsim_ipsec_teardown(ns); + nsim_bpf_uninit(ns); + } rtnl_unlock(); - nsim_udp_tunnels_info_destroy(dev); + if (nsim_dev_port_is_pf(ns->nsim_dev_port)) + nsim_udp_tunnels_info_destroy(dev); free_netdev(dev); } From patchwork Wed Apr 21 15:52:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 425754 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,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 89948C433B4 for ; Wed, 21 Apr 2021 15:53:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5211461445 for ; Wed, 21 Apr 2021 15:53:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244130AbhDUPyB (ORCPT ); Wed, 21 Apr 2021 11:54:01 -0400 Received: from mail-bn8nam12on2041.outbound.protection.outlook.com ([40.107.237.41]:12800 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244111AbhDUPx7 (ORCPT ); Wed, 21 Apr 2021 11:53:59 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nR2asrnB6CP3DAyvEXuWYwugYn67E4sXuy/6KdS6hLhx9vkMoGegZj0x0qVP4eS0PE698w+uGG1UEoca/pu/QFAcbGVn7qhKIyC5cTYg1uW6trVQkoRwGmTq/idYOb5dXM9IoGXTVEh2ZxKOBHJKNDOCT/c73jl3hzLV5CkoaGwQw7HIrEBNx1WHy5XahLNwsijiX6dnUFz9wAxbQSAaLF7IId4hpq3DOYk4nL27XTG6j6dCCkfo5l5DQ2jCXxppf/57i380gpTdJzkV3EIKxaTSypnLt4DmAGcl3+7LO0/FJwpEaIWt0S5UJLjUI5NBnwGY0N09hUB/8yhATz1Xeg== 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=cxf/Ruo3phGxv21QJu1bW1lxlJsd4h35TWhdPsMgtFs=; b=QvdZnjIUldCiUQA0JqbKBFvLs4y66968Cf7p6qAfrEA2aE6CJCs/494YSlHN+W41Ao1pHOmsG9gNuuwe9soabRlgjlgZqb0JKc82XOBvKNbiHRc20x33SlbMP7VooBUljqEdosgfOCBDBIPq4O1UfgwM0oFjonUCXAdrXxx3oShx0yNTfQ2s1pfUmNz9b/uZTQwyAV+4LCmTkyqmotxGLbBwXV8a9cSJa/mvd/t1MQBB+pGjNMjVtcUXIBv8WRFQ8/oa6UWxsPbaBDlbGrR002fdT8h56Y1JGq8nopptQ//X/NaQ2ntHUXmEG8iUIzZwwmlrXpbJ92jAiX5sWkt3cg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) 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=cxf/Ruo3phGxv21QJu1bW1lxlJsd4h35TWhdPsMgtFs=; b=mP3r73hL0erIv9Hd0Al+fR32H0AFNWcUG8NQM0Q18zdhfySLVZcGcn0Mo5BurQTh1ODWYN0t1oUxLgUQ13mSqcxDLDzqoHGH0YRS8FvVxQg6WkA6OcL6NsTDpC4Ill4SvSJSlerJ+nZYgkKYtuGopWhYiDO2lknQf3R56ztCOWRlTbZnfr1LDIu8T4E1ELOeYuGetMBbNeSpnaf62cnLWj+No/20RmcPsmPW+7EkJKAkAYl0XxNDXbjoXcXrlACfKD8FfA2Znd3AfrCnpmp4GqQpSlldHHasgw1jhlPvv/B1JkU5wS718KbZhEm3gOV9dKhedzRMzGudDPF8q6eKWw== Received: from BN0PR04CA0093.namprd04.prod.outlook.com (2603:10b6:408:ec::8) by CY4PR12MB1702.namprd12.prod.outlook.com (2603:10b6:903:11f::23) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.24; Wed, 21 Apr 2021 15:53:25 +0000 Received: from BN8NAM11FT009.eop-nam11.prod.protection.outlook.com (2603:10b6:408:ec:cafe::f3) by BN0PR04CA0093.outlook.office365.com (2603:10b6:408:ec::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.22 via Frontend Transport; Wed, 21 Apr 2021 15:53:24 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) 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.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT009.mail.protection.outlook.com (10.13.176.65) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4065.21 via Frontend Transport; Wed, 21 Apr 2021 15:53:24 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 21 Apr 2021 15:53:23 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 21 Apr 2021 15:53:23 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.12) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 21 Apr 2021 15:53:21 +0000 From: To: CC: , , , , , , Dmytro Linkin Subject: [PATCH RESEND-2 RFC net-next 06/18] devlink: Introduce rate object Date: Wed, 21 Apr 2021 18:52:53 +0300 Message-ID: <1619020385-20220-7-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1619020385-20220-1-git-send-email-dlinkin@nvidia.com> References: <1619020385-20220-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 013f4dbe-4722-4e97-2bee-08d904dd98c1 X-MS-TrafficTypeDiagnostic: CY4PR12MB1702: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:883; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: aFgzPXPn++KIUchPWbYI2RzR9niV3WX6/W6rt80ZoiFKAWBMKqi5Edeu9X3FM/aJWEchPIi/i9ekOSxnz1OlhCjKEdz690esY3WyfvDGGnyO3Cfn1xgENx3UG7gLcinD7xqJOCQCoeaJOjR+ZASfz8NK9SJW8S1a0q2G2oG7LupOAnx7SkT2+hzQEY9v5b1/OS3Q4U9mVHWflcU4TWln6tzgNQSin0b19tA1D89d4IG+dTwK+Te7DqZ/c76UZ3mtqgz5kRr28DO3wLxk3m28zEAGjcN4nO2wAKhQu2IC0lr4WaAAbxssx7q8uaAkiqg6hfZ/K051AkG22gRQXnFH+TLw3XP7lGs8ztNhHRMBfRbhHa2WrLwVBZBAhfAwECrtyF5Nm6//BX9mBPEF4NNV3SjBSCFgTau7t8xJCHGYeS/FRX857O5B0pODFGmzKPOWL851X/P+k3qemKOtidXv8ZGmQn6poMc052LLnPo8UwzBu6q5Hy8aMsJKfYtRBfYCm6D7QsWO+sr8v3wuilVN14aJy9ggrvi9OMo9Sy1WhzQ/BuXuRggP0n3HPX+B9LyD7dALuOlEpH8v5G+1kWysV3pHyg/AEnSZpo4+CfvWq8axz+0WMHa9tDPqNh9j/ePJhT0j7mnbNuChJpsbu0vL/Jpxe5Hv0xjgurcCyj2ntyDY52nj8i3aWwO/jthxsz3s X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(346002)(39860400002)(396003)(376002)(136003)(46966006)(36840700001)(7636003)(82310400003)(83380400001)(36906005)(6916009)(2616005)(8676002)(26005)(82740400003)(4326008)(54906003)(478600001)(2906002)(186003)(30864003)(5660300002)(36756003)(8936002)(356005)(316002)(86362001)(2876002)(7696005)(107886003)(70586007)(36860700001)(336012)(426003)(47076005)(70206006)(6666004)(461764006); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2021 15:53:24.4327 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 013f4dbe-4722-4e97-2bee-08d904dd98c1 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.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT009.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: CY4PR12MB1702 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 func 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 --- include/net/devlink.h | 14 +++ include/uapi/linux/devlink.h | 11 +++ net/core/devlink.c | 222 ++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 246 insertions(+), 1 deletion(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index 853420d..073bc66 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; @@ -131,6 +132,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; @@ -150,6 +160,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 { @@ -1509,6 +1521,8 @@ void devlink_port_attrs_pci_vf_set(struct devlink_port *devlink_port, u32 contro u16 pf, u16 vf, bool external); void devlink_port_attrs_pci_sf_set(struct devlink_port *devlink_port, u32 controller, u16 pf, u32 sf); +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 737b61c..7acff15 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); @@ -8618,6 +8783,61 @@ 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. + */ +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 + */ +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 Apr 21 15:52:55 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 425753 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,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 A4265C43461 for ; Wed, 21 Apr 2021 15:53:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4DA816144C for ; Wed, 21 Apr 2021 15:53:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244147AbhDUPyI (ORCPT ); Wed, 21 Apr 2021 11:54:08 -0400 Received: from mail-dm3nam07on2069.outbound.protection.outlook.com ([40.107.95.69]:54913 "EHLO NAM02-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244134AbhDUPyE (ORCPT ); Wed, 21 Apr 2021 11:54:04 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OxGqmakFfTAcbbBJvt6tZHVXYu9R3pNRqNUlcwBh2+EKGO6xR/02cAn3ukYCY/qgnRiaWwRBd/TEh1uXeI8hXtooaoCtA25gqnsVVHq+uf8rZWrlXiuMqwGRP5TlDWuRzcqYK6bx5ad2eJA7e77lt63Y6B7AUPAt/sUWS+fNZUQSQYnIUxJImlKg0wLbGKXDHxlpZZk1LjzKRUOYvF/ExikqBCiJSZ/dIb4lmQIRg7DH5IVyydmtlkZzaTF2jZew3xo97hrOQdKrV3BsrP7t5EwZYHITXjGhJnGhmQ4gz5oACVPaIVDd2KGvnAoYYImE7uzbZEv7wyOFA0/Nj7v9bQ== 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=866KIhVVVGAYUdDcI2Q2dthtOXmCKME3XEBqri+730Q=; b=FsHjQlKOykrwn+UnSC4VejNJpM4pH/YEod2v++lVw5beM3ZBhJMmnbH3dUwxJMNVHkYHLxvxd9jitXj9ffT0LpwqiEj7ETLBvMZnabw/ttARx0VA5B54OuY9icBh7E9HlbTd7ABo96S3UKiGMOLcc1MRgeyIi1JD2F2sTtw/bb4M6dg/ePKm8h2bGJ4DNgHCKFQkCARwY2hYFbyydgwqJf5U6sYJDH+QmPpF1ToNeffWcfhi83X4CJgF5GAwmzJThE83LAcL4FKrXISnAP+hpnWVWyCxg6FkoAV9hU5NbKnDgm0z1Lf6JFFWSR2LgSS/m9K+Wrxt9tl6tPt+Uh9OSQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) 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=866KIhVVVGAYUdDcI2Q2dthtOXmCKME3XEBqri+730Q=; b=li1OIifZP/Q9x0hEQckyESAPJvBQSfdHRug5FkRgYGWTWpD/3fkKcYfOp+BJL7zLptaylR/vLs0/Px3DrX3LL1QHKK9+MGFns/g7ayA9s3rHD0pq8Z7EjZzZsG470fTU+g2kjzrJ0p6cVlKH8PjY0xpYVdFTgw7SBEbOIUImd3yjRuNqRspN/zVm4iXzRuTilWDYks42a/b9yiSA47V3b+fLhRp//CFg00jTLlpv77jwvbn3ZOP5woSp0IpdVbjrBW6usNz0rbDHrzvAY3Bi6v/qEjOirF5nWMs/U5oxyPVTN/7kgzhMtt0ch05eA7udm8orNDUOXFKW4LkrO8cIIQ== Received: from BN6PR2001CA0004.namprd20.prod.outlook.com (2603:10b6:404:b4::14) by MN2PR12MB3965.namprd12.prod.outlook.com (2603:10b6:208:168::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.21; Wed, 21 Apr 2021 15:53:29 +0000 Received: from BN8NAM11FT008.eop-nam11.prod.protection.outlook.com (2603:10b6:404:b4:cafe::7) by BN6PR2001CA0004.outlook.office365.com (2603:10b6:404:b4::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.22 via Frontend Transport; Wed, 21 Apr 2021 15:53:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) 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.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT008.mail.protection.outlook.com (10.13.177.95) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4065.21 via Frontend Transport; Wed, 21 Apr 2021 15:53:29 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 21 Apr 2021 15:53:28 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.12) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 21 Apr 2021 15:53:26 +0000 From: To: CC: , , , , , , Dmytro Linkin Subject: [PATCH RESEND-2 RFC net-next 08/18] selftest: netdevsim: Add devlink rate test Date: Wed, 21 Apr 2021 18:52:55 +0300 Message-ID: <1619020385-20220-9-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1619020385-20220-1-git-send-email-dlinkin@nvidia.com> References: <1619020385-20220-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: be928286-1e2e-4d2d-0a54-08d904dd9b85 X-MS-TrafficTypeDiagnostic: MN2PR12MB3965: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:612; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: hJy2vYfzhjucYIke7fJHRrp/RyruM4ZIpr/fZgGAAvEcIPeRrPPB9t48eg7Ufmf92dXO60dsMC7qp2vm1h+pBEpSmJGjKcTIOeOIboYfxyqX/n2IuErMOH2y0ndGgL/cv3GhbwgrPkro+wt9ObNTd9LvW7YctCLMj5hamnh5wKHuWdDIqdmu0NvQx+k/FfmcwZr2Tx5kPlVIqTk//qmJlS9AWkZ6fUGByTOfrFdXhTKw6gLUQkqpCLuEUJLDgTdkjkFRcHcVrXwogOWl6V5FP10uEEPtyjFq3gC2tj3CD/bF0+JekVHfD2Ys7hQHg9pv4Wdeu5A7xmEILWhWipBEViSYxscblFn/bLX1BlvW0U0aaedleUAZ2uR9/2iPtjZTspZ9/9sWGVLniDk3NBFden1M0cNbkyizmpAhVeuUWIpewE0YJwj8cSOvr5JPwBXkqa0TvBulmCOuQVT4riUVT4ZFr34KETEYoNnlFQshZhV5K2DbKLlkozatS3Zpg1jLA2iWuEMiDg/u9fO/EOW9j7ETjCreZgaVXMV7qVyXtcZaqamFRjdt1QHNA6s7VEW4iODZWbvJu2wsD8JVeITKsUABdPdYiZLndDe1Tdmcqljw2VwDckx1w6+bUQ+D40h4dbvM9mXuIJNszQCFIq/+rg== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(136003)(376002)(39860400002)(346002)(396003)(36840700001)(46966006)(8676002)(186003)(83380400001)(47076005)(336012)(7696005)(82310400003)(36756003)(356005)(36860700001)(70206006)(8936002)(107886003)(5660300002)(478600001)(6666004)(82740400003)(2906002)(86362001)(426003)(2876002)(70586007)(316002)(36906005)(6916009)(2616005)(54906003)(4326008)(7636003)(26005); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2021 15:53:29.1247 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: be928286-1e2e-4d2d-0a54-08d904dd9b85 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.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT008.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MN2PR12MB3965 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 --- .../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..b8b0990 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 func 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 Apr 21 15:52:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 425752 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,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 2002DC433ED for ; Wed, 21 Apr 2021 15:54:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D8C076144B for ; Wed, 21 Apr 2021 15:54:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244152AbhDUPyb (ORCPT ); Wed, 21 Apr 2021 11:54:31 -0400 Received: from mail-dm3nam07on2064.outbound.protection.outlook.com ([40.107.95.64]:21377 "EHLO NAM02-DM3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244150AbhDUPyJ (ORCPT ); Wed, 21 Apr 2021 11:54:09 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=iGzMwRPJQdqtiYUezkPWy+/uFchIMoEDksmFxlmQD8GTVVvYA1P///4qCGNI1VRCT8oQuOqucVyJRElxrK1+4egIMFHqcsXCfLmzMUxba7hA3z3eyYkQ7Xzt9L9g7UFWxCjpAEhRuNMOhxLNJZb+q56mUI6ZQnvVZIzWRY16ss/JLqFRaLhSNKdk4rHNzoVMqa3EpbCXs88URZlU9VGRV1+hKqT9qCNOJrAQr0A7s1QgiOsQT1HW4WR5IDwddmYVw6O4EeSIhyLPu8sU3/DEnJZ+Da0nIojYy7pmYN0wW0/nPi9aPXzPLa5NTwrzEIQsqIEf27tiJ5vDOmLWSLBNXA== 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=G+0AKlKMFkcBr6wS14xi5JBTHdfBtvmB4W6wM08MndY=; b=f0Os9TmSZEMydOA6ji0zdyEr4voc/mPrrX+mn3bL3D5ihovGLw78r1gnxmMtX55SqKR5IVTqqX9Gy74yv0+8S0r+LzozSCpD7dy7/gGHT0PwJ++JjfmA6fLu9M9EMAOmFy+DNr00h9tCas6ZQRF1dGxtgI+c1C9Jm9j767aMhDMi82dKsWAM2h8QiEpUk4U5YjaDr/lb3SFF/vBDhEEkaZvz0aKY5sQHqSJSTQzRiT1abhYJG8hxtLL8aB4jE/AOvNtn9/ulr3ev7wV+ZwSbi7vPzlhuLncjHDrUEHWQ8TYZqpxZjTyrX5A89FZ7S+7LcB/D4fw9h3mU4igCwgpRqQ== 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=G+0AKlKMFkcBr6wS14xi5JBTHdfBtvmB4W6wM08MndY=; b=F+Sw4lRofdLZR81gGs0XJ1DKsTpJBgSXpOWXkjIIWL3qJb13WHfHxI38bdTvEK04qSqxpCvk1cRsGt4SAi3XZuydXdntthijDXrdK51v44RfzJamMOGsRXLjpVW6GNkmE70mi0Sqgha8ZNQkNjYumUcFfjkN+lCIIOV6EBleSe1EWNt7aQRzAM8lckxu23HWHJUH/YMiuJaa0CxseSbWoRs3pRHN6TcFYZfDONT1dgurbpbSWxEVM3kA2Q/PixP4kGzTgmy6F7u94GBXdJND8lXFVfJ1BN0XsDDALqvKXYNOp31HgPIMbFytiGjhJ+rvPA+ca6EIAYy2bVED+ysV/w== Received: from MWHPR1701CA0016.namprd17.prod.outlook.com (2603:10b6:301:14::26) by BN6PR12MB1330.namprd12.prod.outlook.com (2603:10b6:404:1e::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16; Wed, 21 Apr 2021 15:53:34 +0000 Received: from CO1NAM11FT036.eop-nam11.prod.protection.outlook.com (2603:10b6:301:14:cafe::1) by MWHPR1701CA0016.outlook.office365.com (2603:10b6:301:14::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.22 via Frontend Transport; Wed, 21 Apr 2021 15:53:34 +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 CO1NAM11FT036.mail.protection.outlook.com (10.13.174.124) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4065.21 via Frontend Transport; Wed, 21 Apr 2021 15:53:33 +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, 21 Apr 2021 08:53:33 -0700 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.12) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 21 Apr 2021 15:53:31 +0000 From: To: CC: , , , , , , Dmytro Linkin Subject: [PATCH RESEND-2 RFC net-next 10/18] netdevsim: Implement devlink rate leafs tx rate support Date: Wed, 21 Apr 2021 18:52:57 +0300 Message-ID: <1619020385-20220-11-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1619020385-20220-1-git-send-email-dlinkin@nvidia.com> References: <1619020385-20220-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: ac8102b0-736c-40d2-856a-08d904dd9e40 X-MS-TrafficTypeDiagnostic: BN6PR12MB1330: 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: jmy/HHO3IJ8x36j6d64Z52V+/TvrhGTR/o4VrzaSEVpde4Fo0WGbtbXu6dIOAVLKbn8OjUmZeh80Hd19gMJSG1OYSJYtV0XthhgJzD3dLqs84p+uMnexNUxJ4ckYw8S6eG5vpn5jtlFD0WDXfgHvdR6gYhaZP+DDMDo16vNUN9tJ9B0gRaEw+ElC9k0iYzMDka6i/8cm2f3aE1/nmvVT9X6ANTISQRaKamjry0UdNTJO45Pes6m4W0FV0G14JcKVDvUEI5YRKFREpXe3Z0Lk20bIODNDEy3IjYnEszB7rMof6sc4Z+GXAHYxElpgMh6goxRQrcNZUNGrAhiuYSUttSIC2U0n83nmGOGVA3uwN+Nc7ejSNYPoX+AKMbIqQ9NwNlOhkOYvS6EoY5+gbkk1S5A245AkcQddZOcNyEdH7XDfJlv6a5e5Bg7EKXAI5JwItGejQg6xyb6OqDq1apBFO8NTTqQ0LYDxyHx4ygdPmU/Vjud4wND2afA9QVmULV659YMnDiw8kvhMML2x+lBEkMC8vFcHGrezkD1SW4jMgLqDNr9hXhuzIUAlu9VRe193EFMgWETTcEmcg/S4doi+fmUngeHBKodbZhPzZ0f++mba0UVUk0QSFKAdm/dg+z9VntJ5J4OWXMmNyjb3XaE5cS/St6SlR3ilUHvF0xYTkdg= 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)(136003)(376002)(396003)(36840700001)(46966006)(70206006)(478600001)(6666004)(316002)(83380400001)(2876002)(82310400003)(7696005)(36756003)(2906002)(54906003)(36860700001)(426003)(107886003)(8676002)(26005)(186003)(5660300002)(4326008)(7636003)(356005)(336012)(2616005)(47076005)(82740400003)(8936002)(6916009)(86362001)(70586007); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2021 15:53:33.7778 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: ac8102b0-736c-40d2-856a-08d904dd9e40 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: CO1NAM11FT036.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR12MB1330 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 | 77 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 74 insertions(+), 3 deletions(-) diff --git a/drivers/net/netdevsim/dev.c b/drivers/net/netdevsim/dev.c index 356287a..a6dfa6b6 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,66 @@ 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 = *rate; + + if (val % NSIM_LINK_SPEED_UNIT) { + pr_err("%s rate value %lluBps not in link speed units of 1Mbps.\n", + name, val); + NL_SET_ERR_MSG_MOD(extack, "TX rate value not in link speed units of 1Mbps."); + return -EINVAL; + } + + val = div_u64(val, NSIM_LINK_SPEED_UNIT); + 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 +1074,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 Apr 21 15:52:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 425751 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,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 317F5C43460 for ; Wed, 21 Apr 2021 15:54:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B821E61249 for ; Wed, 21 Apr 2021 15:54:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244165AbhDUPyg (ORCPT ); Wed, 21 Apr 2021 11:54:36 -0400 Received: from mail-eopbgr760075.outbound.protection.outlook.com ([40.107.76.75]:52742 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244184AbhDUPyQ (ORCPT ); Wed, 21 Apr 2021 11:54:16 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jFFaW5ni1naFEid9dSJqq/JHj0vAxmFfDfkQZKOvMqYD88fptdkr/GhtsLiqlIJ/2ug0G62OmFtp/qVQDCuW6/3j0oS9JQEZ79s4RfyrwZ73wsoYtrvLmenxrGjRFuXxO8y5ALiPqoH80y/GWokiVtPwu3lolG2CeDgwHZKGXexwSyrEGjagc3oh3Nm/k/ZVphV0gfivAlrbi4RMOcQu1NK+6hcr9qwsJNWP9oQb5DrISEiqKJB/iHiiTQWPJmAMQYMHXd/nm+6iAG5eb0w72gGXnAlgvcEBQPxLbzbTeKxef7tKZdBtdVMq+MNN2qvNJoNkBE8pRgt03h4Baum2Pw== 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=93jjrhHXHtXcVMNp7PN6VQJ06ZTPf8ilufDbbNa7UMs=; b=LHE/FNqOjph4+F4G+8zKEPTvo/nmsqyE6TO3QXDVR+wVQFbMeQZm7GKU0XHaqBj8s42598Ru7OH21C/DjNqpRdzcrnv9msLHH6hON0cSipFNuL/i+zQyLMIAPWT0Q9knS5RT6k/l1QOvV+AJcJQWw+OJ0tZDXvdiwG5QAA/Ga1vQJbB3xzajort1xkSq5/gIS6LhxuCkJdomSaA23xILviVxWaOVKqRsNH3cmxYWHmIRiYxhb8ZfSRy/7x1Uk/W+96ey5hh8pcbboFO/Rjiw1bf/59lHDDAUZRPqC8NeglK4GDviSO6o3ftC7Mxa31G/FTz1wNppagN71O7ido2fRA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.35) 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=93jjrhHXHtXcVMNp7PN6VQJ06ZTPf8ilufDbbNa7UMs=; b=JCg1opfyoBnyfRM2sOgEgYZwh3nSmIJvYaRA3dJ2YfTeV4E8IeA6ZcdG/qbnUbV/9JIow9grF4/EAR05yfatMkbg7SQ7O4GTNuqgLPx+3icmFmuag5piDhjnHb7Sz12PGp5nsjd070ihHlJXSFSEtnJvT8qC840eDAWR8av9i0qto67Qj2QMosScdTxLTG4ivbbus/3wtk9IKUnruJamGYkDEO225n0qKSimemj3fNsy1351pYY4mF/dMtwRLCiB0vwGCo6AETIlCnmYbPrcNMOfGQFw2f8v4/uAyhZF0ErdNAAGnB3lfMCU6gfzhPUcwaxJRgAPJPNHOpGKECm7ZQ== Received: from BN6PR20CA0058.namprd20.prod.outlook.com (2603:10b6:404:151::20) by DM5PR12MB2358.namprd12.prod.outlook.com (2603:10b6:4:b3::34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.18; Wed, 21 Apr 2021 15:53:41 +0000 Received: from BN8NAM11FT046.eop-nam11.prod.protection.outlook.com (2603:10b6:404:151:cafe::aa) by BN6PR20CA0058.outlook.office365.com (2603:10b6:404:151::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21 via Frontend Transport; Wed, 21 Apr 2021 15:53:40 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.35) 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.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 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.4065.21 via Frontend Transport; Wed, 21 Apr 2021 15:53:40 +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, 21 Apr 2021 15:53:38 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL105.nvidia.com (172.20.187.12) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 21 Apr 2021 15:53:38 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.12) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 21 Apr 2021 15:53:36 +0000 From: To: CC: , , , , , , Dmytro Linkin Subject: [PATCH RESEND-2 RFC net-next 12/18] devlink: Introduce rate nodes Date: Wed, 21 Apr 2021 18:52:59 +0300 Message-ID: <1619020385-20220-13-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1619020385-20220-1-git-send-email-dlinkin@nvidia.com> References: <1619020385-20220-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 74917d65-0c82-4d91-0dc8-08d904dda273 X-MS-TrafficTypeDiagnostic: DM5PR12MB2358: X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:5797; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ku3cay2uK6maFOG/56MlIsFJZ8ewru3tv6wZ6eGCyBIvYxhWQOvK0nug6woiVjsYdJkIWCfi5Ty6quLdHmbraK6oMh8GqHVrPCNFwlKG6/+NMMCGA9VVSj0BpDuKANonT/nIQtc3wK2yOdOWI3qvjHrK39z+CUwG5tzFatWHRcKFkq/JcsIPDM1tDn+1rKCQ6/HlW3it16sg5dKBYARTPrv1eZ4PRpVYeFWq3QScd2aYQw3ULyEOVPJvMWRa+61aTYXnMRzLj/mLcvyEI5iylf7AmEoGTlryn1x9WnNUnRRX7T4doi9fFmoz/INqGqWEvSet7QKMav/6prMV7d4iCyTYoy42B1OGR8Z0LkFVIj+jKw7QKt8I9fQVRM11F5HpBHNRGnwVGNIRjxu9kRkq6dxKX1KdHzGOVBpB3s7O2TDKqTJ47bupPuP1eRid/ZU4OCthiE50+Dl1IdarShkPcVLj1iSzA78AdGK/7rtCZEW4NTYrXffxWxMqhYhW0/j3bmg4DicxvYqqRgFUmU9xfwNpspu5wkPcsPpbk3wBGEkLPfjnX4MXinS76FATfhikeOyKG5uIXxJmFrxiOF0ZjYdfiabUA1GqRBWqLfVXmPKGvB98xZf7xAc4TUF19XAOqnoflO6uenpDWJ6BAVmZQaA4RVHk9+0txIvDF0Ghjjo= 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)(39860400002)(396003)(136003)(376002)(346002)(46966006)(36840700001)(7636003)(54906003)(2616005)(478600001)(2876002)(316002)(5660300002)(70206006)(82740400003)(36860700001)(2906002)(8676002)(26005)(356005)(36906005)(82310400003)(336012)(7696005)(4326008)(36756003)(107886003)(6916009)(47076005)(86362001)(70586007)(8936002)(186003)(6666004)(83380400001)(30864003)(426003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2021 15:53:40.7699 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 74917d65-0c82-4d91-0dc8-08d904dda273 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: BN8NAM11FT046.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR12MB2358 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. Disallow moving device from switchdev to legacy mode if any node exist on that device. Example: $ devlink port func rate add netdevsim/netdevsim10/group1 $ devlink port func rate set netdevsim/netdevsim10/group1 \ tx_share 10mbit tx_max 100mbit Add + set command can be combined: $ devlink port func rate add netdevsim/netdevsim10/group1 \ tx_share 10mbit tx_max 100mbit $ devlink port func rate show netdevsim/netdevsim10/group1 netdevsim/netdevsim10/group1: type node tx_share 10mbit tx_max 100mbit $ devlink port func rate del netdevsim/netdevsim10/group1 Co-developed-by: Vlad Buslov Signed-off-by: Vlad Buslov Signed-off-by: Dmytro Linkin Reviewed-by: Jiri Pirko --- include/net/devlink.h | 13 ++- include/uapi/linux/devlink.h | 3 + net/core/devlink.c | 209 +++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 218 insertions(+), 7 deletions(-) diff --git a/include/net/devlink.h b/include/net/devlink.h index cbfa456..ac0b5eb 100644 --- a/include/net/devlink.h +++ b/include/net/devlink.h @@ -140,7 +140,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 { @@ -1473,6 +1476,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) 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 4f0412e..eca3f28 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, @@ -1513,8 +1582,12 @@ static int devlink_nl_rate_set(struct devlink_rate *devlink_rate, 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, From patchwork Wed Apr 21 15:53:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmytro Linkin X-Patchwork-Id: 425750 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,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 C82A9C433B4 for ; Wed, 21 Apr 2021 15:54:05 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 981D06144B for ; Wed, 21 Apr 2021 15:54:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244182AbhDUPyi (ORCPT ); Wed, 21 Apr 2021 11:54:38 -0400 Received: from mail-mw2nam12on2088.outbound.protection.outlook.com ([40.107.244.88]:17462 "EHLO NAM12-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244206AbhDUPyU (ORCPT ); Wed, 21 Apr 2021 11:54:20 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IctnVNJVEJIUt9IBdmSum9Dq1wd+qrAsMKCKsd6auxBJR4StbdzX/2v7BPGXlXYNTqG/O7uF1BnKpriyg/+tnxshfZ/e7Fo/ee9S1w0OMcVR2gBBbl1pKKJw1PJRtM2Jfn+csw/A2iKsn4wLgOPjMkoJbZgGhKtNY1tDwmQx+5Ma2jLzTsXMzXa/JRIR6ZIrHQe8a0MasbLkuO8lb3qxSEEYtPrrJohln0MvHj3cTEw7SD8XStKjGiGNgpU0sFL5/RkhTMgANM9ox4CTHV1xE3k1a2WqgGWs22jx82cBJmqEPqY633HXinRB7M+GWzJshEWPCG+AYez+3WWa3UqVyw== 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=838VzIoMdMnnBo6U2RbgamxAH1bw27AhKWkJWZtx57o=; b=g6o7HWcyK2B3xtzO0dr7EV3cHmuon3HvKo39vJ1ioDt2rvLSoBH7pYIK0meYqgjvDcVJTC+PQJiucpPjv/M8jhY9/3G9RDtf5YT8ZTMzgVRPYp7e4G3JAOm7CixDSFb7PkA4aymKIxldeSwuAO0Gw5CPJWtHLk9/jnGntk17ZNjHx3ZBwVUObvCD0rrzUyc5CGHQkY46il5r4/r+HaFB/L0uj/Tre0Vunbq3MEuHRgFgyeyk0COtLHhIHYa98k2hP06WtLjosIA9t6ohzmxFE+LqxFYfLcYXHD031FbnxBfM6xdkOyZCZGgrmKyZTcqM7pXWOMhjp90DhJ6ulERv1Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) 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=838VzIoMdMnnBo6U2RbgamxAH1bw27AhKWkJWZtx57o=; b=lDMoEVTIMnJre7WC813aMkAewDHaWPxuj30JyL2o4MsG0ERJyq2RT/LPNYrIAnIH5bWJXGf605A5HyI91++RthrH9Y4hrfXJJROP73Sa14hwqBRqDYFDTuv4yAtzsGyODMELMnu+4K8DsPy4Ehw2I9BpezVloh10hYXNwqDCb3KM6MLHTEL8QTUiyj66InT9xeGvQfvWNMNaI+j0gDeUeWLSTnggpj++z9OUyeQA6d2HDbf8ij9NmP9iU8FquJJ4vesCelvmeWTIXK4p6sZL8TQ5NU75QqB9IjszoS1gOCO/EjJTktNz2ocNocOa/Hm2A/kx204rluW1Qfr6tM4ZWA== Received: from BN6PR14CA0025.namprd14.prod.outlook.com (2603:10b6:404:13f::11) by BN6PR1201MB0164.namprd12.prod.outlook.com (2603:10b6:405:4e::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.16; Wed, 21 Apr 2021 15:53:44 +0000 Received: from BN8NAM11FT052.eop-nam11.prod.protection.outlook.com (2603:10b6:404:13f:cafe::a3) by BN6PR14CA0025.outlook.office365.com (2603:10b6:404:13f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.20 via Frontend Transport; Wed, 21 Apr 2021 15:53:44 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) 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.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT052.mail.protection.outlook.com (10.13.177.210) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4065.21 via Frontend Transport; Wed, 21 Apr 2021 15:53:44 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 21 Apr 2021 15:53:43 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.12) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 21 Apr 2021 15:53:40 +0000 From: To: CC: , , , , , , Dmytro Linkin Subject: [PATCH RESEND-2 RFC net-next 14/18] selftest: netdevsim: Add devlink rate nodes test Date: Wed, 21 Apr 2021 18:53:01 +0300 Message-ID: <1619020385-20220-15-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1619020385-20220-1-git-send-email-dlinkin@nvidia.com> References: <1619020385-20220-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: adcc37d7-0141-4304-007d-08d904dda4ad X-MS-TrafficTypeDiagnostic: BN6PR1201MB0164: 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: avoJJfJPY5e2ZvL/hsGodJDIvitJhNeelVom5ZdsNIiEeRo2ZHRO8DD/j8yOURVkelPM6lf7g6z/SCzFTHIWPqcgTXZDqHKDN1D8XeejUCPM1c5KGCGDhfTiSGJnRIKeOvHXykpfaO2hK+b61QOWeDgQZLI+TB/Ht4LBOIBhzwkbcn5bFzzU2c9CFLVvjCtCbCz7FpR6YY41XoIDUM3vUifVbz+6r7zvgDnkAWGd/PbDezseImgPJpc1ASUT935N6KF7mouVfoMFx43AGgqeTDRBi2rprHjGXL9WlXxSpj2eUMMmtmvrbE1JOPWhQXWLEpgxfnmh/VefPouLjIAszMyAh7E6Bat3jBjFqdU9dZPhaK89xeAGVo90X92cwFA0nBuE+LxPv3SjyS7j4727Uy2r0GOPx0d5kOryzpG12/z+/8QNroxS9q8jloOyLBrJSWo1C4ELf4EtAc+TGaTPeOtKRU83/RNsMZNFi6E0VTwH+chGECkjwzCFF975AfONkh7JwjM/LoYZulP5nSpHChnllBQkBEAl3LjTBm5V6sVWT4OuGMGwiLBnLl4PWW69IFAwaimj/GGp8j0twA7JKQSdzIvqzEiRs8x9kCziSIebs08ukKuJKaPDRMnmS6qJIZ3beD1O2p4L4tDP21Qvcw== X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(39860400002)(136003)(376002)(346002)(396003)(46966006)(36840700001)(54906003)(4326008)(6916009)(70206006)(70586007)(82740400003)(2906002)(8936002)(426003)(36860700001)(8676002)(47076005)(82310400003)(36756003)(478600001)(186003)(356005)(7696005)(26005)(86362001)(36906005)(336012)(2876002)(6666004)(5660300002)(2616005)(83380400001)(316002)(107886003)(7636003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2021 15:53:44.4252 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: adcc37d7-0141-4304-007d-08d904dda4ad 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.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT052.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR1201MB0164 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 --- .../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 c4be343..7c6ecf2 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 func 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 func rate add $handle +} + +rate_node_del() +{ + local handle=$1 + + devlink port func 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 Apr 21 15:53: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: 425749 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.0 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 73C3BC433B4 for ; Wed, 21 Apr 2021 15:54:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 338A26144B for ; Wed, 21 Apr 2021 15:54:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244186AbhDUPym (ORCPT ); Wed, 21 Apr 2021 11:54:42 -0400 Received: from mail-bn7nam10on2078.outbound.protection.outlook.com ([40.107.92.78]:37984 "EHLO NAM10-BN7-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244218AbhDUPyY (ORCPT ); Wed, 21 Apr 2021 11:54:24 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=msyA6dLn7cp57wQVC9t7z/a/AY7REneImo26USfuo0yqKVk0gIgFRCHCVHAyWRR5hUuQvfcw3MQdnqeyyaoD0bTcwIpQTANpVDOiESKrytpT/gnFtjN9NeAv3VG2zNlIApHwcZNXJXZjqYBwhDIxSWZ5ms4fq9mQPPkVKr6AhrZvkz0VzJh5twtAOR9IvAGZpX3JcldJOf2UuEgs1+6WkJOEwpteXoZbq+YvKBCwurj7kaiXxd5W86on68hgCwMEI6X+5yGf/SGzSCVAePqW/s65pYVmnytHwI0n8sQUmlsCYS437pcFqjgbwPmAXBnF+txmkseswTAO10ggLEA0Fg== 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=bap1HI+o+6GKH57AXZk8EaqK6K+XpH9o5t8BYypoYRs=; b=OnA5Nt9j8QvYTg+8O1Wzo8hxZXVveSZjbwNmn7sKUfstuA6G9PqRTUeGIMgFaru7S8012jdXiDrRGIkUyYDOZjKolLR7/ukCxujZlRGoG7ENsLBFwYxGlLb+T+ZOTS/isXe2BWSQ/W/mw/cwwU3ESPZPdI/nX5zHZubLKyqJqWo9pBhYWZ2Fy+VfQQE2KyDURpTxUX1R9CUaSX3pCBAGivQMQOWjk5vQNOxHaUV1BochkEQAeioZ7x8Jx/BdyNniR3MjXOjTxv9EWW/PSWZDA0jLgrU7ysTskboOt9YdyB+MNwXXsza5vKSmSpF/rXZZ7kL9Kh/8/K5r5q9U10zwkg== 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=bap1HI+o+6GKH57AXZk8EaqK6K+XpH9o5t8BYypoYRs=; b=eR1+LfslqwhZ6W1BJXijCf7nZLxetwFe/XtATyOgrkpzHl3eRah/WRlzgyETF7GIBb0mMN2fEw9FURuzQvhoXzDeZ68ex7OcoBu6Oh1jQPzKzYqD/paB1EaRq8tqVtP6IaQWxEjpqEuTylqTxMNF7hJdv/kLkYCGrcn5QEjYihpezqdZq3mXwUIqSS5bZ7H4jB5D4NcovJnwaPRbn+y9YtjLVB7hswm+/fmxSkfxS031/a8YKuImEwMS6oLJvqMUABCTyOhwfv1hxOsgqum4B0rqo8WPllFxZ6TSj/5ZLJyREBFumLq/kBzYuO52z91TiYYEtnFgxPS1zDw8Zq8hnQ== Received: from BN6PR20CA0049.namprd20.prod.outlook.com (2603:10b6:404:151::11) by DM6PR12MB3433.namprd12.prod.outlook.com (2603:10b6:5:38::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.24; Wed, 21 Apr 2021 15:53:49 +0000 Received: from BN8NAM11FT046.eop-nam11.prod.protection.outlook.com (2603:10b6:404:151:cafe::5f) by BN6PR20CA0049.outlook.office365.com (2603:10b6:404:151::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4065.21 via Frontend Transport; Wed, 21 Apr 2021 15:53:48 +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 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.4065.21 via Frontend Transport; Wed, 21 Apr 2021 15:53:48 +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, 21 Apr 2021 15:53:48 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.12) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 21 Apr 2021 15:53:45 +0000 From: To: CC: , , , , , , Dmytro Linkin Subject: [PATCH RESEND-2 RFC net-next 16/18] netdevsim: Allow setting parent node of rate objects Date: Wed, 21 Apr 2021 18:53:03 +0300 Message-ID: <1619020385-20220-17-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1619020385-20220-1-git-send-email-dlinkin@nvidia.com> References: <1619020385-20220-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 4d7b6677-473a-4f8b-32d3-08d904dda72e X-MS-TrafficTypeDiagnostic: DM6PR12MB3433: 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: bo7pASKEffhWzNTh6mIrD8ZynCQ3TF9aAt+Ajng8xnQxBWUwEEkNuo+yHAgAyHPX4a+cazAwc73Dpy+mdg9fOyZNbTR8C0K/8OjgvA+wQgqgbqhJio04fYtRcZ1LmTCkQOsveRLvyFFxHA82xQGgO7D6OKO82OeRa1eH89JMh0EbHErycWpmSOpsuJUF+Z/cGr30XHW+af3+jUV/ml3YhpZy047qvxDYTam4juUH9omaR9XhzikIQ9iVcXulMpIf0lwx0bazNBjmn7cGEQcO4DwzyA6xQTEbjcDssmvPGiUHMy2/fby7sjg/Ruzese53xl7pvOAoMMnt2aPUBtZweXxaRLneLU7sb8i3XQMmjgF+IErcaubDu52dMI/wbt1usgzZf6HcehEwSWE279J0Xadj2SsuQJhf1yWy+IRgwLEtgJl7z1SiGeR/UvtopbpP2nyDwuJTxovAwYf7qnoooZw8iT/z8CYsikPVHroRl05MlWm2qbfjqg0tzN8DWKtZZdPSbHVb1PGWDsSUmDyOijY5+XhSoWiRnn5mDpIwhEF24AAw8RUdIOp/KxvNrrFn59An+h/0FT63vNJdhcOABCYmDhG3Gl1fMmiiJxIjUylLkXzKeEvoc7rVId2TAJCyTT6S5SGTLDrOluCL7uH2LA== 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)(39860400002)(346002)(136003)(396003)(46966006)(36840700001)(86362001)(107886003)(47076005)(8936002)(36906005)(2876002)(6666004)(82740400003)(7636003)(186003)(336012)(54906003)(82310400003)(5660300002)(2906002)(26005)(4326008)(36860700001)(478600001)(356005)(6916009)(2616005)(83380400001)(70206006)(7696005)(8676002)(70586007)(316002)(426003)(36756003); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2021 15:53:48.6903 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 4d7b6677-473a-4f8b-32d3-08d904dda72e 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: BN8NAM11FT046.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR12MB3433 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 febc1b5..959d9a7 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); @@ -1065,6 +1099,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; }; @@ -1102,6 +1138,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."); @@ -1114,13 +1151,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, @@ -1128,11 +1180,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, @@ -1154,6 +1235,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 Apr 21 15:53: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: 425748 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,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 8CCFBC433B4 for ; Wed, 21 Apr 2021 15:54:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4B2396144B for ; Wed, 21 Apr 2021 15:54:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244199AbhDUPyr (ORCPT ); Wed, 21 Apr 2021 11:54:47 -0400 Received: from mail-mw2nam08on2059.outbound.protection.outlook.com ([40.107.101.59]:9697 "EHLO NAM04-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S244158AbhDUPy2 (ORCPT ); Wed, 21 Apr 2021 11:54:28 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dfbypZRJB8FFqYIyEw5JjwSY7sVrlMStKSFqMF8v87veHq6aKMkCCROZpX/inUqyBoCD9JZ9RFzdsCff4bLwm0HSsWGXpV9aumEtE4nZjpKuWiSSFYmP+x1ER6bIZc5UNAeePn9/SxNgydWJCs9dd6cepwKT3DPQ201qqiBFVytsQaJ4bDr28oTIrt5wVnqXxVT87VVr/CD//b5y4QTjcKW4Y2bkbybf36F9sPihTaPKl1YzCzt+52hdA7WnTl4Y4klGE1KVWJUU9meCeeUiIejard0F+5Syzx8Uw3D+2bu7kkNlw8pI51RgJagfAJdkcoFSGD6qoYQ3u18GAipjSw== 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=RIYHD16GjASpgUYImN9eeBkgnVPBzmDO/oiY3Sw3Mu7I2ElluLTyevy77BBkfflYXvn2rzAU3QqVAwwo1/KQxokGDnxZobl/roRcGtoxi1F6rvqyjDMTJUDOO0XAARaSoLJXMYs0W5iimcReYhKWsucskb3XXHruodyRDM2dXMT8iviYXYjwr5xa6JA7GYzy2eSWhli4qvmjWF6h11U0pfBC5f327UYQbNpO3nbNmM/IJpC4KdGik5HHXya8BClph2vw2Zu+6c4ZZew266HTZaz08mAQ2Nz6d8g1/2zDQaN8SGfTBpZsae/sAl1s0KH8lKjaBaHsDorr1H6OUbJ57w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 216.228.112.34) 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=QA59NZ+NnUtsOa1ld8ipNDBJTIzAV3x7XGJpM81icClxYnVVu73BBwolySzj6pHGShMcURw7s4ExwiQFhSqnusXaglrN02nwsMQdMdAkfFlcsi/51zj9tIu0yfkUMPpgmt0mZ/gk8vZpfXTLvHYm66lkzD1Cme/Xt8rdeKSMzua18KA/VrsrxVDzvtmr5G+qCu6zY9rdNGxCs8WvKfR/xr/cjkYkZIS+RwnVK48vSyTzTN83jq2yOFvgjTwODT0Lbl1Ckajs5N/nklCWsmMvbOb/0hmtWmf0qwUvyPQtAIU/m9681fXiGF06XXIzRK3qDcAG4MWpO/wcVbZjsc9SZQ== Received: from BN9PR03CA0566.namprd03.prod.outlook.com (2603:10b6:408:138::31) by DM4PR12MB5264.namprd12.prod.outlook.com (2603:10b6:5:39c::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.19; Wed, 21 Apr 2021 15:53:54 +0000 Received: from BN8NAM11FT027.eop-nam11.prod.protection.outlook.com (2603:10b6:408:138:cafe::24) by BN9PR03CA0566.outlook.office365.com (2603:10b6:408:138::31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4042.19 via Frontend Transport; Wed, 21 Apr 2021 15:53:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 216.228.112.34) 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.34 as permitted sender) receiver=protection.outlook.com; client-ip=216.228.112.34; helo=mail.nvidia.com; Received: from mail.nvidia.com (216.228.112.34) by BN8NAM11FT027.mail.protection.outlook.com (10.13.177.96) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.20.4065.21 via Frontend Transport; Wed, 21 Apr 2021 15:53:53 +0000 Received: from HQMAIL105.nvidia.com (172.20.187.12) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 21 Apr 2021 15:53:52 +0000 Received: from vdi.nvidia.com (172.20.145.6) by mail.nvidia.com (172.20.187.12) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Wed, 21 Apr 2021 15:53:50 +0000 From: To: CC: , , , , , , Dmytro Linkin Subject: [PATCH RESEND-2 RFC net-next 18/18] Documentation: devlink rate objects Date: Wed, 21 Apr 2021 18:53:05 +0300 Message-ID: <1619020385-20220-19-git-send-email-dlinkin@nvidia.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1619020385-20220-1-git-send-email-dlinkin@nvidia.com> References: <1619020385-20220-1-git-send-email-dlinkin@nvidia.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 6a5ab0ff-b7a4-4d92-5017-08d904ddaa39 X-MS-TrafficTypeDiagnostic: DM4PR12MB5264: 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: 3ulDCNg2Hkc9zoi0eSyI5WWovIiUaI/1OzabSsUekv5rZyoyP8USDnEF1AcmYO54rqjtMeazfcoZABpoBnLsWAvRGId1b7fAXvofKJX7xodHhCv/HeyYEhqafSn9FSZ20KMRA/JkpLrZrYo/WXS65uC9/voluo2+X3DY3ykNIdnt+tFjUnG8iB3E6KOyejxw+Dxr+ebR3hAx1N0KbpEry5/C/pnOXjprEZspGtUFYbGYAmJoa4SMMaUm8RA9vQiKxgCxsas9Y47DOwGRzFRwFZ2TGYy7L3BK6Vr+VFbRSukWFmgHmliQfqPHq0Ri55oOhQkJ5CzRIYbNlv+7ljSNfIXeTMdpNlAFr8abByXwbrSW4hp7IHYq9Q5RJJGVY+EFQE/teRr3FNYuLnFFnDDEi8USLBbzUaYz8tNPbYNJ0pNVs2ESuCORK6q/ui/1r8A2GMd+8ogijQXuPunIFXMUDls3m943pztbp+0uZmODdUse+EabQ/njFoAS8+y9rZX+GMdtCJyyfMb5eFwY4KGkOlEB831tmY9k4ezGD+EWqMv6uCbcZz9ulW4vhZAQ4R93DrKwnSKQOqTbHU6Cd6LcjiJg0fefnw5OPmAp4bwiOMOWOT6AFfS464jEgcYb50RhqDtNBfU+3NLqcv1E1rHUcgiD0/UHj7pdUrRFd0bAmcE= X-Forefront-Antispam-Report: CIP:216.228.112.34; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:mail.nvidia.com; PTR:schybrid03.nvidia.com; CAT:NONE; SFS:(4636009)(136003)(346002)(39860400002)(396003)(376002)(46966006)(36840700001)(356005)(26005)(336012)(86362001)(426003)(7696005)(2906002)(2616005)(107886003)(7636003)(83380400001)(6666004)(54906003)(8676002)(82310400003)(186003)(478600001)(316002)(70206006)(70586007)(2876002)(47076005)(8936002)(36756003)(4326008)(36860700001)(82740400003)(36906005)(5660300002)(6916009); DIR:OUT; SFP:1101; X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Apr 2021 15:53:53.7823 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 6a5ab0ff-b7a4-4d92-5017-08d904ddaa39 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.34]; Helo=[mail.nvidia.com] X-MS-Exchange-CrossTenant-AuthSource: BN8NAM11FT027.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR12MB5264 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 =====================