From patchwork Fri Oct 27 12:27:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13438589 X-Patchwork-Delegate: kuba@kernel.org Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net [23.128.96.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E5A11A705 for ; Fri, 27 Oct 2023 12:28:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="IvTdM9LP" Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2051.outbound.protection.outlook.com [40.107.243.51]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86993128 for ; Fri, 27 Oct 2023 05:28:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gY79ne3jt8ofRUUVoH4LZpvGm5oHOsqQZQrFnsWC4d2UvvDXk66uxFGrEx2SPoRL83DA0aI2KdAFfrH+1WybSC39IoNPO1Z+SevkCy2iibXvsEz/TlxSOzwvp8VmNqmUjl9Q8/Hk0ogtnfujgtQt8lnTQBOrwzrSsVfmSa+iOgi0313OrzYYjgcRKHHC0SrpgnamRJnhB9rw3gbYXr4gVtJRKiqxFmLSFSu+9kpZWXz0+o5bJLO3Q86TcDCtAErnqbrrQB6+NTBL/FXLo82Rx2Oo0NzDSCEJ8eDNLkElRpIvlKwlmYB5WAxsu2xysbFQPZ+qF8GDozoUuBL1K+dzMA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=fycy3vBtE3gfS6VdLkQICJcUegKYjQt8l0YIgLGyRtk=; b=fRmdWl5yrAojqhk3pzQWiiSt5unAalWNCR4AhDEqvZX7/dUvnecRpaOgaJ3eScQRuEaHNlB/LuCX5tHTTTYcLpP8OjMFbc1pSvjDaFapSAjJuLPCVeuigtbFWaRBGmS7dcyrQuSA0VzPeBN86Os7wUt2sIEVII/mo0RLBXlifNzWGt3BhwQiXaRmgty+fkB8cWekuYzFnm9xj9W1o2LdWHH7MRchH7QuXYO/wS4Hci2fLF9Zmr1kqsrINMbDFDk3OKgrjr9vWGj/JnyuZ/z25ywveIXDDfzoMS1KQOT3PPw/gEfHRuFVMoRJ7GXtsm64dy+IFFOec70AAuFffilXQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; 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=fycy3vBtE3gfS6VdLkQICJcUegKYjQt8l0YIgLGyRtk=; b=IvTdM9LPg3g6qYKD8yvnsLNzHkLLHOK14CSWWxmz1Loeoc1i4txoRMeHvSyf36zfhN4vgY//rYnri/7n35Bunuu4nZX8zIjyfGG7445V6dXjJmjqLoYZz1rDmK4179QTjz4UAKe3FghDg4KqbYrLHG8AHqfG183KgvbijiNyQ1Lg3qiH4BijqAlHiUwvEZW2MPT2+ic/jnpwvbaKHpJ8EbgOric2sdRA/R55yqM3kp+w1jm2nSo86lSALKG6yv+0mgEX61fD7KQz+Jm8u5GD7ixKJ+R3YEsJhzP9vsobMmPEcF/h6YGsSDOPqb3vPYwpJ3Mtbu1B37spZmK7OxSmTQ== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from SJ1PR12MB6075.namprd12.prod.outlook.com (2603:10b6:a03:45e::8) by PH7PR12MB7378.namprd12.prod.outlook.com (2603:10b6:510:20d::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6907.33; Fri, 27 Oct 2023 12:28:12 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::42b4:7f1:b049:39b2]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::42b4:7f1:b049:39b2%7]) with mapi id 15.20.6933.024; Fri, 27 Oct 2023 12:28:11 +0000 From: Aurelien Aptel To: linux-nvme@lists.infradead.org, netdev@vger.kernel.org, sagi@grimberg.me, hch@lst.de, kbusch@kernel.org, axboe@fb.com, chaitanyak@nvidia.com, davem@davemloft.net, kuba@kernel.org Cc: Aurelien Aptel , aurelien.aptel@gmail.com, smalin@nvidia.com, malin1024@gmail.com, ogerlitz@nvidia.com, yorayz@nvidia.com, borisp@nvidia.com, galshalom@nvidia.com, mgurtovoy@nvidia.com, edumazet@google.com, pabeni@redhat.com, imagedong@tencent.com Subject: [PATCH v18 02/20] netlink: add new family to manage ULP_DDP enablement and stats Date: Fri, 27 Oct 2023 12:27:37 +0000 Message-Id: <20231027122755.205334-3-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231027122755.205334-1-aaptel@nvidia.com> References: <20231027122755.205334-1-aaptel@nvidia.com> X-ClientProxiedBy: FR4P281CA0420.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:d0::17) To SJ1PR12MB6075.namprd12.prod.outlook.com (2603:10b6:a03:45e::8) Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SJ1PR12MB6075:EE_|PH7PR12MB7378:EE_ X-MS-Office365-Filtering-Correlation-Id: 33f08ce2-e442-4966-00ee-08dbd6e82f39 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: NY+vUfI7TJudL40zuOlyuQe5Tzguq+uyw7X55Ks2uGccnN/iTV23qHAOv5ojmpN7uMJiTKYwWP+7JhIHZbTanWE1ksU6yot/y3I537BTzhC9IFSshtGtlCL/ivU5lSUOxX/Xk6N6yIxyjN3noIqjpq6Rd4TGxIxfX/UXDxzCJKc7UJe9KWLVaUYyYRnW9a5XdvN/RGOjwHpdOjysqX5P3fi9p1BpzbTX8l6z9ik7wACars3l0mZVdNpPhZEUgN8rkLGZciV4/I8+mnShWO0YEUQhWf/R54nX0vCLdmhYz58W/Z/EvIU69gscX5C6egJOSahXHCcMMO+TDeGdddrbH/KxBMH+eIB4iuXxYqKMnyiTQ/Lbq92lTfDf6ED1ta3mk7lGpVuURkeOef81NGPbfD2a5iuWpN9wyAvMzhbOvBTGxs2jIPIMZJLMEnSY3q0ADSEY1UhKt86tYSNiL06jQG7QF5w634dRNC19KLyg8BW4W0+trIAABRA2fDY+OV90I1ueUklyY4SFgo455mJejCV/rgbEUiWkUKVfh7e4Epzpv2T3s+hjsOeZntGQHme1DP9pA4dm2eSS/P8GTjgXB6eh9vp71VAeK5YEsUJElco= X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:SJ1PR12MB6075.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(376002)(136003)(366004)(39860400002)(346002)(230922051799003)(64100799003)(451199024)(186009)(1800799009)(1076003)(83380400001)(26005)(2616005)(6512007)(6506007)(6666004)(38100700002)(478600001)(2906002)(30864003)(7416002)(6486002)(4326008)(41300700001)(8676002)(8936002)(66556008)(66946007)(316002)(66476007)(36756003)(86362001)(5660300002)(309714004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: BQG0UBkdDX+0kHP24S9DpP4hDTm+Fl/+CijSgc+d9Ur7+8QrLPfJTW/sZq5Tj6KW/R5S73ySWQbkXBgy/yoDXpwFiLcJcPBRvqEPdnyfw7dgAPqaCt3G9jjbm7qJOrBGOYUmJsbu+rgy5NPG2PTVfajisOfAxqO1mkLp1hKK/cc38PPLUIeDhXL2G6vinqbqZQwO3mXPV9k+qgyvWcTXK2LAURZNqEW+iHmLE+Wt1vGCNny4M1WKuq/VFB8T8jIvtKgBVI7Lk9BeKJLkkSD65jbodDhkSwqbm3XH0A/d2nUN4g3LRz3gSomC250MvihoKt7hwTUEq++xx4gv6WwY5OU/8r2WrO7LVnndfAAnoCNDNATeVs45h+K55R76egD+/v/oRkDoaNNYxc/OJ0B5tkGZRzuLc8gXpAEwX3j3h8DamGlhcAQloRhb4g62c5O/0zeupbIjWPvwbtXl/X9qWNwBnWvykMyePlXbE41h1Di3QKVaCDl3eNaPV58bQOO1hyn9p96JeGyEc8H8gJKgBBINJnexop/6sKiW7yeorYdMNpFbG/cheSm3Ogt/5vgKA7KpkvHuLjoEgh9yWInkTPqvC/reIO82W7PcriySWQKfKe6a7Pg9f11lxG7edMj+tVfLQap2rsA95BkVRIgJrqTdxM1KAkEAE8dug3MUyKQxKJ1v4BYJTqojAYJyI3AM5c55A2gklWEdx3f/LD1bB/aHgRe9qXfiHoRsUBORF4DdK/70Ld5FPPAmgRwbDZQzEiNDwCDbAW5xgXdC/9NfLZcGYmIL1NnKvWbJsbxkgwyd9DXeqPtvIHqhCWTX8lPKms8RvVmEXCv9jBUy4xeOMTDBUfeAFSn3Z5t9EG4F81jfBpVW3AXfo9P1c5kOT1WyJ7Pt6ckMbafzA8rlt54oEUBvBGLwVXzChWt0APpdeQPM/9Z2qnncP9OB8hUGozXaPzoi5hG6j5kvmicbrLHYwLVnQbwrb7/6jA33rD1LRPP+86KOmuv2Z8SZwP4KFh/Sf0gomoaClO+17u/ASrYdf0dlMyvDAEhIbTiAwYrhkWWeEEhKIgcMyUq1E9fekdEb99oh+Gjr6bkTJeIczNfO1JyvhDZpNHxEBYeLc1eOvJjUdnrzdJ/Q1DDpoJTK0q3SZMKCWmRtNJ8Ql6jEQNNvvapopxEwrYNXobj933fu1Z6Mk9/Sq6If8sbQSM+XUlvPjXFh6DCEB5vSUy7/LUUG0BjHiic3dq/9QCAJ6o71L5AWuSIuc0TyqGw4/HKWjjp8DfTdUQ5gVLeGL6sqXdGaSWj9ggChYYmyeSFmyHu4uxKRVwESZ/E1jaAhG+HfUqeksWsDhDbkp/lH/5TApJyPRHi+K6GLEwtd8ELXcH3ODTyBOnnp4kvFYrMGtDALHEA26+soCJKBh1U5dUuEwU5k4lOqa90oBBwqNvhBdwN7pUi3JjkaFZSm7WwOnWeHYM9ddqWQo8GL2EB/OclAF//ZzOgHyPZSzjSz1CbWjyDMF1GXdf/W6zehTtTEOxfh/NiF+qOlL0IxF66HGGdcS0TjtwyExmrHBddvoD2Wvtvpg3ASTNRlsgYmci83smuAg4Pu X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 33f08ce2-e442-4966-00ee-08dbd6e82f39 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Oct 2023 12:28:11.8811 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: xlRmFv8Xh956CTJSOO6lifUJ9MsEDsGExP/uzRjufMBYa9HKdwjzpGd/Z07PVXw6ybQWQpNgGJ0Pf2I9zn34Pg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PH7PR12MB7378 X-Patchwork-Delegate: kuba@kernel.org Add a new netlink family to get/set ULP DDP capabilities on a network device and to retrieve statistics. The messages use the genetlink infrastructure and are specified in a YAML file which was used to generate some of the files in this commit: ./tools/net/ynl/ynl-gen-c.py --mode kernel \ --spec ./Documentation/netlink/specs/ulp_ddp.yaml --header \ -o net/core/ulp_ddp_gen_nl.h ./tools/net/ynl/ynl-gen-c.py --mode kernel \ --spec ./Documentation/netlink/specs/ulp_ddp.yaml --source \ -o net/core/ulp_ddp_gen_nl.c ./tools/net/ynl/ynl-gen-c.py --mode uapi \ --spec ./Documentation/netlink/specs/ulp_ddp.yaml --header \ > include/uapi/linux/ulp_ddp.h Signed-off-by: Shai Malin Signed-off-by: Aurelien Aptel --- Documentation/netlink/specs/ulp_ddp.yaml | 172 ++++++++++++ include/net/ulp_ddp.h | 3 +- include/uapi/linux/ulp_ddp.h | 61 +++++ net/core/Makefile | 2 +- net/core/ulp_ddp_gen_nl.c | 75 +++++ net/core/ulp_ddp_gen_nl.h | 30 ++ net/core/ulp_ddp_nl.c | 335 +++++++++++++++++++++++ 7 files changed, 676 insertions(+), 2 deletions(-) create mode 100644 Documentation/netlink/specs/ulp_ddp.yaml create mode 100644 include/uapi/linux/ulp_ddp.h create mode 100644 net/core/ulp_ddp_gen_nl.c create mode 100644 net/core/ulp_ddp_gen_nl.h create mode 100644 net/core/ulp_ddp_nl.c diff --git a/Documentation/netlink/specs/ulp_ddp.yaml b/Documentation/netlink/specs/ulp_ddp.yaml new file mode 100644 index 000000000000..7822aa60ae29 --- /dev/null +++ b/Documentation/netlink/specs/ulp_ddp.yaml @@ -0,0 +1,172 @@ +# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) +# +# Author: Aurelien Aptel +# +# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# + +name: ulp_ddp + +protocol: genetlink + +doc: Netlink protocol to manage ULP DPP on network devices. + +definitions: + - + type: enum + name: cap + render-max: true + entries: + - nvme-tcp + - nvme-tcp-ddgst-rx + +attribute-sets: + - + name: stats + attributes: + - + name: ifindex + doc: interface index of the net device. + type: u32 + - + name: rx-nvme-tcp-sk-add + doc: Sockets successfully configured for NVMeTCP offloading. + type: uint + - + name: rx-nvme-tcp-sk-add-fail + doc: Sockets failed to be configured for NVMeTCP offloading. + type: uint + - + name: rx-nvme-tcp-sk-del + doc: Sockets with NVMeTCP offloading configuration removed. + type: uint + - + name: rx-nvme-tcp-setup + doc: NVMe-TCP IOs successfully configured for Rx Direct Data Placement. + type: uint + - + name: rx-nvme-tcp-setup-fail + doc: NVMe-TCP IOs failed to be configured for Rx Direct Data Placement. + type: uint + - + name: rx-nvme-tcp-teardown + doc: NVMe-TCP IOs with Rx Direct Data Placement configuration removed. + type: uint + - + name: rx-nvme-tcp-drop + doc: Packets failed the NVMeTCP offload validation. + type: uint + - + name: rx-nvme-tcp-resync + doc: > + NVMe-TCP resync operations were processed due to Rx TCP packets + re-ordering. + type: uint + - + name: rx-nvme-tcp-packets + doc: TCP packets successfully processed by the NVMeTCP offload. + type: uint + - + name: rx-nvme-tcp-bytes + doc: Bytes were successfully processed by the NVMeTCP offload. + type: uint + - + name: caps + attributes: + - + name: ifindex + doc: interface index of the net device. + type: u32 + - + name: hw + doc: bitmask of the capabilities supported by the device. + type: uint + enum: cap + enum-as-flags: true + - + name: active + doc: bitmask of the capabilities currently enabled on the device. + type: uint + enum: cap + enum-as-flags: true + - + name: wanted + doc: > + new active bit values of the capabilities we want to set on the + device. + type: uint + enum: cap + enum-as-flags: true + - + name: wanted_mask + doc: bitmask of the meaningful bits in the wanted field. + type: uint + enum: cap + enum-as-flags: true + +operations: + list: + - + name: caps-get + doc: Get ULP DDP capabilities. + attribute-set: caps + do: + request: + attributes: + - ifindex + reply: + attributes: + - ifindex + - hw + - active + pre: ulp_ddp_get_netdev + post: ulp_ddp_put_netdev + - + name: stats-get + doc: Get ULP DDP stats. + attribute-set: stats + do: + request: + attributes: + - ifindex + reply: + attributes: + - ifindex + - rx-nvme-tcp-sk-add + - rx-nvme-tcp-sk-add-fail + - rx-nvme-tcp-sk-del + - rx-nvme-tcp-setup + - rx-nvme-tcp-setup-fail + - rx-nvme-tcp-teardown + - rx-nvme-tcp-drop + - rx-nvme-tcp-resync + - rx-nvme-tcp-packets + - rx-nvme-tcp-bytes + pre: ulp_ddp_get_netdev + post: ulp_ddp_put_netdev + - + name: caps-set + doc: Set ULP DDP capabilities. + attribute-set: caps + do: + request: + attributes: + - ifindex + - wanted + - wanted_mask + reply: + attributes: + - ifindex + - hw + - active + pre: ulp_ddp_get_netdev + post: ulp_ddp_put_netdev + - + name: caps-set-ntf + doc: Notification for change in ULP DDP capabilities. + notify: caps-get + +mcast-groups: + list: + - + name: mgmt diff --git a/include/net/ulp_ddp.h b/include/net/ulp_ddp.h index 972d22537385..89abc3047068 100644 --- a/include/net/ulp_ddp.h +++ b/include/net/ulp_ddp.h @@ -10,6 +10,7 @@ #include #include #include +#include enum ulp_ddp_type { ULP_DDP_NVME = 1, @@ -128,7 +129,7 @@ struct ulp_ddp_stats { */ }; -#define ULP_DDP_CAP_COUNT 1 +#define ULP_DDP_CAP_COUNT (ULP_DDP_CAP_MAX + 1) struct ulp_ddp_dev_caps { DECLARE_BITMAP(active, ULP_DDP_CAP_COUNT); diff --git a/include/uapi/linux/ulp_ddp.h b/include/uapi/linux/ulp_ddp.h new file mode 100644 index 000000000000..dbf6399d3aef --- /dev/null +++ b/include/uapi/linux/ulp_ddp.h @@ -0,0 +1,61 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/ulp_ddp.yaml */ +/* YNL-GEN uapi header */ + +#ifndef _UAPI_LINUX_ULP_DDP_H +#define _UAPI_LINUX_ULP_DDP_H + +#define ULP_DDP_FAMILY_NAME "ulp_ddp" +#define ULP_DDP_FAMILY_VERSION 1 + +enum ulp_ddp_cap { + ULP_DDP_CAP_NVME_TCP, + ULP_DDP_CAP_NVME_TCP_DDGST_RX, + + /* private: */ + __ULP_DDP_CAP_MAX, + ULP_DDP_CAP_MAX = (__ULP_DDP_CAP_MAX - 1) +}; + +enum { + ULP_DDP_A_STATS_IFINDEX = 1, + ULP_DDP_A_STATS_RX_NVME_TCP_SK_ADD, + ULP_DDP_A_STATS_RX_NVME_TCP_SK_ADD_FAIL, + ULP_DDP_A_STATS_RX_NVME_TCP_SK_DEL, + ULP_DDP_A_STATS_RX_NVME_TCP_SETUP, + ULP_DDP_A_STATS_RX_NVME_TCP_SETUP_FAIL, + ULP_DDP_A_STATS_RX_NVME_TCP_TEARDOWN, + ULP_DDP_A_STATS_RX_NVME_TCP_DROP, + ULP_DDP_A_STATS_RX_NVME_TCP_RESYNC, + ULP_DDP_A_STATS_RX_NVME_TCP_PACKETS, + ULP_DDP_A_STATS_RX_NVME_TCP_BYTES, + + __ULP_DDP_A_STATS_MAX, + ULP_DDP_A_STATS_MAX = (__ULP_DDP_A_STATS_MAX - 1) +}; + +enum { + ULP_DDP_A_CAPS_IFINDEX = 1, + ULP_DDP_A_CAPS_HW, + ULP_DDP_A_CAPS_ACTIVE, + ULP_DDP_A_CAPS_WANTED, + ULP_DDP_A_CAPS_WANTED_MASK, + + __ULP_DDP_A_CAPS_MAX, + ULP_DDP_A_CAPS_MAX = (__ULP_DDP_A_CAPS_MAX - 1) +}; + +enum { + ULP_DDP_CMD_CAPS_GET = 1, + ULP_DDP_CMD_STATS_GET, + ULP_DDP_CMD_CAPS_SET, + ULP_DDP_CMD_CAPS_SET_NTF, + + __ULP_DDP_CMD_MAX, + ULP_DDP_CMD_MAX = (__ULP_DDP_CMD_MAX - 1) +}; + +#define ULP_DDP_MCGRP_MGMT "mgmt" + +#endif /* _UAPI_LINUX_ULP_DDP_H */ diff --git a/net/core/Makefile b/net/core/Makefile index b6a16e7c955a..1aff91f0fce0 100644 --- a/net/core/Makefile +++ b/net/core/Makefile @@ -18,7 +18,7 @@ obj-y += dev.o dev_addr_lists.o dst.o netevent.o \ obj-$(CONFIG_NETDEV_ADDR_LIST_TEST) += dev_addr_lists_test.o obj-y += net-sysfs.o -obj-$(CONFIG_ULP_DDP) += ulp_ddp.o +obj-$(CONFIG_ULP_DDP) += ulp_ddp.o ulp_ddp_nl.o ulp_ddp_gen_nl.o obj-$(CONFIG_PAGE_POOL) += page_pool.o obj-$(CONFIG_PROC_FS) += net-procfs.o obj-$(CONFIG_NET_PKTGEN) += pktgen.o diff --git a/net/core/ulp_ddp_gen_nl.c b/net/core/ulp_ddp_gen_nl.c new file mode 100644 index 000000000000..5675193ad8ca --- /dev/null +++ b/net/core/ulp_ddp_gen_nl.c @@ -0,0 +1,75 @@ +// SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/ulp_ddp.yaml */ +/* YNL-GEN kernel source */ + +#include +#include + +#include "ulp_ddp_gen_nl.h" + +#include + +/* ULP_DDP_CMD_CAPS_GET - do */ +static const struct nla_policy ulp_ddp_caps_get_nl_policy[ULP_DDP_A_CAPS_IFINDEX + 1] = { + [ULP_DDP_A_CAPS_IFINDEX] = { .type = NLA_U32, }, +}; + +/* ULP_DDP_CMD_STATS_GET - do */ +static const struct nla_policy ulp_ddp_stats_get_nl_policy[ULP_DDP_A_STATS_IFINDEX + 1] = { + [ULP_DDP_A_STATS_IFINDEX] = { .type = NLA_U32, }, +}; + +/* ULP_DDP_CMD_CAPS_SET - do */ +static const struct nla_policy ulp_ddp_caps_set_nl_policy[ULP_DDP_A_CAPS_WANTED_MASK + 1] = { + [ULP_DDP_A_CAPS_IFINDEX] = { .type = NLA_U32, }, + [ULP_DDP_A_CAPS_WANTED] = NLA_POLICY_MASK(NLA_UINT, 0x3), + [ULP_DDP_A_CAPS_WANTED_MASK] = NLA_POLICY_MASK(NLA_UINT, 0x3), +}; + +/* Ops table for ulp_ddp */ +static const struct genl_split_ops ulp_ddp_nl_ops[] = { + { + .cmd = ULP_DDP_CMD_CAPS_GET, + .pre_doit = ulp_ddp_get_netdev, + .doit = ulp_ddp_nl_caps_get_doit, + .post_doit = ulp_ddp_put_netdev, + .policy = ulp_ddp_caps_get_nl_policy, + .maxattr = ULP_DDP_A_CAPS_IFINDEX, + .flags = GENL_CMD_CAP_DO, + }, + { + .cmd = ULP_DDP_CMD_STATS_GET, + .pre_doit = ulp_ddp_get_netdev, + .doit = ulp_ddp_nl_stats_get_doit, + .post_doit = ulp_ddp_put_netdev, + .policy = ulp_ddp_stats_get_nl_policy, + .maxattr = ULP_DDP_A_STATS_IFINDEX, + .flags = GENL_CMD_CAP_DO, + }, + { + .cmd = ULP_DDP_CMD_CAPS_SET, + .pre_doit = ulp_ddp_get_netdev, + .doit = ulp_ddp_nl_caps_set_doit, + .post_doit = ulp_ddp_put_netdev, + .policy = ulp_ddp_caps_set_nl_policy, + .maxattr = ULP_DDP_A_CAPS_WANTED_MASK, + .flags = GENL_CMD_CAP_DO, + }, +}; + +static const struct genl_multicast_group ulp_ddp_nl_mcgrps[] = { + [ULP_DDP_NLGRP_MGMT] = { "mgmt", }, +}; + +struct genl_family ulp_ddp_nl_family __ro_after_init = { + .name = ULP_DDP_FAMILY_NAME, + .version = ULP_DDP_FAMILY_VERSION, + .netnsok = true, + .parallel_ops = true, + .module = THIS_MODULE, + .split_ops = ulp_ddp_nl_ops, + .n_split_ops = ARRAY_SIZE(ulp_ddp_nl_ops), + .mcgrps = ulp_ddp_nl_mcgrps, + .n_mcgrps = ARRAY_SIZE(ulp_ddp_nl_mcgrps), +}; diff --git a/net/core/ulp_ddp_gen_nl.h b/net/core/ulp_ddp_gen_nl.h new file mode 100644 index 000000000000..368433cfa867 --- /dev/null +++ b/net/core/ulp_ddp_gen_nl.h @@ -0,0 +1,30 @@ +/* SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) */ +/* Do not edit directly, auto-generated from: */ +/* Documentation/netlink/specs/ulp_ddp.yaml */ +/* YNL-GEN kernel header */ + +#ifndef _LINUX_ULP_DDP_GEN_H +#define _LINUX_ULP_DDP_GEN_H + +#include +#include + +#include + +int ulp_ddp_get_netdev(const struct genl_split_ops *ops, struct sk_buff *skb, + struct genl_info *info); +void +ulp_ddp_put_netdev(const struct genl_split_ops *ops, struct sk_buff *skb, + struct genl_info *info); + +int ulp_ddp_nl_caps_get_doit(struct sk_buff *skb, struct genl_info *info); +int ulp_ddp_nl_stats_get_doit(struct sk_buff *skb, struct genl_info *info); +int ulp_ddp_nl_caps_set_doit(struct sk_buff *skb, struct genl_info *info); + +enum { + ULP_DDP_NLGRP_MGMT, +}; + +extern struct genl_family ulp_ddp_nl_family; + +#endif /* _LINUX_ULP_DDP_GEN_H */ diff --git a/net/core/ulp_ddp_nl.c b/net/core/ulp_ddp_nl.c new file mode 100644 index 000000000000..4e8b210f6734 --- /dev/null +++ b/net/core/ulp_ddp_nl.c @@ -0,0 +1,335 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * ulp_ddp_nl.c + * Author: Aurelien Aptel + * Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + */ +#include +#include "ulp_ddp_gen_nl.h" + +#define ULP_DDP_STATS_CNT (sizeof(struct ulp_ddp_stats) / sizeof(u64)) + +struct ulp_ddp_reply_context { + struct net_device *dev; + netdevice_tracker tracker; + void *hdr; + u32 ifindex; + struct ulp_ddp_dev_caps caps; + struct ulp_ddp_stats stats; +}; + +static size_t ulp_ddp_reply_size(int cmd) +{ + size_t len = 0; + + BUILD_BUG_ON(ULP_DDP_CAP_COUNT > 64); + + /* ifindex */ + len += nla_total_size(sizeof(u32)); + + switch (cmd) { + case ULP_DDP_CMD_CAPS_GET: + case ULP_DDP_CMD_CAPS_SET: + case ULP_DDP_CMD_CAPS_SET_NTF: + /* hw */ + len += nla_total_size_64bit(sizeof(u64)); + + /* active */ + len += nla_total_size_64bit(sizeof(u64)); + break; + case ULP_DDP_CMD_STATS_GET: + /* stats */ + len += nla_total_size_64bit(sizeof(u64)) * ULP_DDP_STATS_CNT; + break; + } + + return len; +} + +/* pre_doit */ +int ulp_ddp_get_netdev(const struct genl_split_ops *ops, + struct sk_buff *skb, struct genl_info *info) +{ + struct ulp_ddp_reply_context *ctx; + + if (GENL_REQ_ATTR_CHECK(info, ULP_DDP_A_CAPS_IFINDEX)) + return -EINVAL; + + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + ctx->ifindex = nla_get_u32(info->attrs[ULP_DDP_A_CAPS_IFINDEX]); + ctx->dev = netdev_get_by_index(genl_info_net(info), + ctx->ifindex, + &ctx->tracker, + GFP_KERNEL); + if (!ctx->dev) { + kfree(ctx); + NL_SET_ERR_MSG_ATTR(info->extack, + info->attrs[ULP_DDP_A_CAPS_IFINDEX], + "Network interface does not exist"); + return -ENODEV; + } + + if (!ctx->dev->netdev_ops->ulp_ddp_ops) { + netdev_put(ctx->dev, &ctx->tracker); + kfree(ctx); + NL_SET_ERR_MSG_ATTR(info->extack, + info->attrs[ULP_DDP_A_CAPS_IFINDEX], + "Network interface does not support ULP DDP"); + return -EOPNOTSUPP; + } + + info->user_ptr[0] = ctx; + return 0; +} + +/* post_doit */ +void ulp_ddp_put_netdev(const struct genl_split_ops *ops, struct sk_buff *skb, + struct genl_info *info) +{ + struct ulp_ddp_reply_context *ctx = info->user_ptr[0]; + + netdev_put(ctx->dev, &ctx->tracker); + kfree(ctx); +} + +static int ulp_ddp_prepare_context(struct ulp_ddp_reply_context *ctx, int cmd) +{ + const struct ulp_ddp_dev_ops *ops = ctx->dev->netdev_ops->ulp_ddp_ops; + + switch (cmd) { + case ULP_DDP_CMD_CAPS_GET: + case ULP_DDP_CMD_CAPS_SET: + case ULP_DDP_CMD_CAPS_SET_NTF: + ops->get_caps(ctx->dev, &ctx->caps); + break; + case ULP_DDP_CMD_STATS_GET: + ops->get_stats(ctx->dev, &ctx->stats); + break; + } + + return 0; +} + +static int ulp_ddp_write_reply(struct sk_buff *rsp, + struct ulp_ddp_reply_context *ctx, + int cmd, + const struct genl_info *info) +{ + ctx->hdr = genlmsg_iput(rsp, info); + if (!ctx->hdr) + return -EMSGSIZE; + + switch (cmd) { + case ULP_DDP_CMD_CAPS_GET: + case ULP_DDP_CMD_CAPS_SET: + case ULP_DDP_CMD_CAPS_SET_NTF: + if (nla_put_u32(rsp, ULP_DDP_A_CAPS_IFINDEX, ctx->ifindex) || + nla_put_uint(rsp, ULP_DDP_A_CAPS_HW, ctx->caps.hw[0]) || + nla_put_uint(rsp, ULP_DDP_A_CAPS_ACTIVE, + ctx->caps.active[0])) + goto err_cancel_msg; + break; + case ULP_DDP_CMD_STATS_GET: + if (nla_put_u32(rsp, ULP_DDP_A_STATS_IFINDEX, ctx->ifindex) || + nla_put_uint(rsp, + ULP_DDP_A_STATS_RX_NVME_TCP_SK_ADD, + ctx->stats.rx_nvmeotcp_sk_add) || + nla_put_uint(rsp, + ULP_DDP_A_STATS_RX_NVME_TCP_SK_ADD_FAIL, + ctx->stats.rx_nvmeotcp_sk_add_fail) || + nla_put_uint(rsp, + ULP_DDP_A_STATS_RX_NVME_TCP_SK_DEL, + ctx->stats.rx_nvmeotcp_sk_del) || + nla_put_uint(rsp, + ULP_DDP_A_STATS_RX_NVME_TCP_SETUP, + ctx->stats.rx_nvmeotcp_ddp_setup) || + nla_put_uint(rsp, + ULP_DDP_A_STATS_RX_NVME_TCP_SETUP_FAIL, + ctx->stats.rx_nvmeotcp_ddp_setup_fail) || + nla_put_uint(rsp, + ULP_DDP_A_STATS_RX_NVME_TCP_TEARDOWN, + ctx->stats.rx_nvmeotcp_ddp_teardown) || + nla_put_uint(rsp, + ULP_DDP_A_STATS_RX_NVME_TCP_DROP, + ctx->stats.rx_nvmeotcp_drop) || + nla_put_uint(rsp, + ULP_DDP_A_STATS_RX_NVME_TCP_RESYNC, + ctx->stats.rx_nvmeotcp_resync) || + nla_put_uint(rsp, + ULP_DDP_A_STATS_RX_NVME_TCP_PACKETS, + ctx->stats.rx_nvmeotcp_packets) || + nla_put_uint(rsp, + ULP_DDP_A_STATS_RX_NVME_TCP_BYTES, + ctx->stats.rx_nvmeotcp_bytes)) + goto err_cancel_msg; + } + genlmsg_end(rsp, ctx->hdr); + + return 0; + +err_cancel_msg: + genlmsg_cancel(rsp, ctx->hdr); + + return -EMSGSIZE; +} + +int ulp_ddp_nl_caps_get_doit(struct sk_buff *req, struct genl_info *info) +{ + struct ulp_ddp_reply_context *ctx = info->user_ptr[0]; + struct sk_buff *rsp; + int ret = 0; + + ret = ulp_ddp_prepare_context(ctx, ULP_DDP_CMD_CAPS_GET); + if (ret) + return ret; + + rsp = genlmsg_new(ulp_ddp_reply_size(ULP_DDP_CMD_CAPS_GET), GFP_KERNEL); + if (!rsp) + return -EMSGSIZE; + + ret = ulp_ddp_write_reply(rsp, ctx, ULP_DDP_CMD_CAPS_GET, info); + if (ret < 0) + goto err_rsp; + + return genlmsg_reply(rsp, info); + +err_rsp: + nlmsg_free(rsp); + return ret; +} + +static void ulp_ddp_nl_notify_dev(struct ulp_ddp_reply_context *ctx) +{ + struct genl_info info; + struct sk_buff *ntf; + + if (!genl_has_listeners(&ulp_ddp_nl_family, dev_net(ctx->dev), + ULP_DDP_NLGRP_MGMT)) + return; + + genl_info_init_ntf(&info, &ulp_ddp_nl_family, ULP_DDP_CMD_CAPS_SET_NTF); + ntf = genlmsg_new(ulp_ddp_reply_size(ULP_DDP_CMD_CAPS_GET), GFP_KERNEL); + if (!ntf) + return; + + if (ulp_ddp_write_reply(ntf, ctx, ULP_DDP_CMD_CAPS_SET_NTF, &info)) { + nlmsg_free(ntf); + return; + } + + genlmsg_multicast_netns(&ulp_ddp_nl_family, dev_net(ctx->dev), ntf, + 0, ULP_DDP_NLGRP_MGMT, GFP_KERNEL); +} + +static int ulp_ddp_apply_bits(struct ulp_ddp_reply_context *ctx, + unsigned long *req_wanted, + unsigned long *req_mask, + struct genl_info *info) +{ + DECLARE_BITMAP(old_active, ULP_DDP_CAP_COUNT); + DECLARE_BITMAP(new_active, ULP_DDP_CAP_COUNT); + const struct ulp_ddp_dev_ops *ops; + struct ulp_ddp_dev_caps caps; + int ret; + + ops = ctx->dev->netdev_ops->ulp_ddp_ops; + ops->get_caps(ctx->dev, &caps); + + /* new_active = (old_active & ~req_mask) | (wanted & req_mask) + * new_active &= caps_hw + */ + bitmap_copy(old_active, caps.active, ULP_DDP_CAP_COUNT); + bitmap_and(req_wanted, req_wanted, req_mask, ULP_DDP_CAP_COUNT); + bitmap_andnot(new_active, old_active, req_mask, ULP_DDP_CAP_COUNT); + bitmap_or(new_active, new_active, req_wanted, ULP_DDP_CAP_COUNT); + bitmap_and(new_active, new_active, caps.hw, ULP_DDP_CAP_COUNT); + if (!bitmap_equal(old_active, new_active, ULP_DDP_CAP_COUNT)) { + ret = ops->set_caps(ctx->dev, new_active, info->extack); + if (ret < 0) + return ret; + ops->get_caps(ctx->dev, &caps); + bitmap_copy(new_active, caps.active, ULP_DDP_CAP_COUNT); + } + + /* return 1 to notify */ + return !bitmap_equal(old_active, new_active, ULP_DDP_CAP_COUNT); +} + +int ulp_ddp_nl_caps_set_doit(struct sk_buff *skb, struct genl_info *info) +{ + struct ulp_ddp_reply_context *ctx = info->user_ptr[0]; + unsigned long wanted, wanted_mask; + struct sk_buff *rsp; + bool notify; + int ret; + + if (GENL_REQ_ATTR_CHECK(info, ULP_DDP_A_CAPS_WANTED) || + GENL_REQ_ATTR_CHECK(info, ULP_DDP_A_CAPS_WANTED_MASK)) + return -EINVAL; + + rsp = genlmsg_new(ulp_ddp_reply_size(ULP_DDP_CMD_STATS_GET), GFP_KERNEL); + if (!rsp) + return -EMSGSIZE; + + wanted = nla_get_u64(info->attrs[ULP_DDP_A_CAPS_WANTED]); + wanted_mask = nla_get_u64(info->attrs[ULP_DDP_A_CAPS_WANTED_MASK]); + + ret = ulp_ddp_apply_bits(ctx, &wanted, &wanted_mask, info); + if (ret < 0) + goto err_rsp; + + notify = !!ret; + ret = ulp_ddp_prepare_context(ctx, ULP_DDP_CMD_CAPS_SET); + if (ret) + goto err_rsp; + + ret = ulp_ddp_write_reply(rsp, ctx, ULP_DDP_CMD_CAPS_SET, info); + if (ret < 0) + goto err_rsp; + + ret = genlmsg_reply(rsp, info); + if (notify) + ulp_ddp_nl_notify_dev(ctx); + + return ret; + +err_rsp: + nlmsg_free(rsp); + + return ret; +} + +int ulp_ddp_nl_stats_get_doit(struct sk_buff *skb, struct genl_info *info) +{ + struct ulp_ddp_reply_context *ctx = info->user_ptr[0]; + struct sk_buff *rsp; + int ret = 0; + + ret = ulp_ddp_prepare_context(ctx, ULP_DDP_CMD_STATS_GET); + if (ret) + return ret; + + rsp = genlmsg_new(ulp_ddp_reply_size(ULP_DDP_CMD_STATS_GET), GFP_KERNEL); + if (!rsp) + return -EMSGSIZE; + + ret = ulp_ddp_write_reply(rsp, ctx, ULP_DDP_CMD_STATS_GET, info); + if (ret < 0) + goto err_rsp; + + return genlmsg_reply(rsp, info); + +err_rsp: + nlmsg_free(rsp); + return ret; +} + +static int __init ulp_ddp_init(void) +{ + return genl_register_family(&ulp_ddp_nl_family); +} + +subsys_initcall(ulp_ddp_init);