From patchwork Wed Feb 28 12:57:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575442 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2060.outbound.protection.outlook.com [40.107.96.60]) (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 B1BFA149001 for ; Wed, 28 Feb 2024 12:58:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125084; cv=fail; b=tvg3CqlrIRv86waXaXFRFGJil1uUm1hYZaH9frM3tibL1DrimM3OnPyMf9XAW9meQVoFM/id0IBdiQWBKEtUNv+4lWTdMpi8pHH1g7KgL9g9xl/EAP+PYLNo/2UWXxFuGrcspIMyeWBVlaWmufTJQJbk6EcoVn+U0ZZph2hDhRA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125084; c=relaxed/simple; bh=NFz7NFqWrcUANk7ldX4tMYsUwzrTCVjZrHBMalAOyLA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=aS9T1JyBe5S5XJmeDlGqma4+T0O516IoqMRpC5y1Jrp4+wT9JExrx45fxv/xF8f5gohEIHyx9CEcAMLAZPPCd4jOSqAhcOfxjSJW+jViaQ/PebAsH+8S2Axc0uWsxJphEzikT7AZWPqi/8VEPxOjDc0668fGufJl6ZI9RZYAmrc= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=UKPfWv/K; arc=fail smtp.client-ip=40.107.96.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="UKPfWv/K" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NW3GYhctfHh58OXbvbR6uj5T7Qz7wLWk7DzgcDZOSXDgyE15oaVSLIxEOU6921Aw1Ho2a3JYsoeAZDmaUQohPlt7y3Ln0DfuUgUMorms6rPCK1iFbQDM0FqLb+uC7s2tVYpx46K/XuHJ+rZjKESKI/DbdLVaDTJMFYQsdO/3gnM9fvXoG8JOIBS8yS5ZLuwcb+Dr7afqqUe27r5gjuX2PdIYpGXKFjlSLzRzjFsVN5D6a6BpnYDkx0BJliXnQkCO+zDiaIotm40czuq1aQZV8qvS42OxWWeTrghmcnj8QNPdF1soExI2Ouf+cY7s8Eg5ecFaw/cOZW8yiFcg1icUrw== 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=cMxtiLrmjf1oiGBnupVrNp1rHrg/HEIlqBcOpJrmS1s=; b=B41QSI8L2+RfEmAxls8Mz8N8mv0t+SIyHXXlp7u9RFrDGNq5R4QNLoa+a/pjN1gnP59TdSzjcHJfCw/Mh2w5NcqcJCrpwpXkD9ICC7nIMP84Qr0BqAeu5oQolFy6wT/AgOi/aLSqJwVyuOj5JyxAYu0E05FROG2fEb14faJ/lMb72tI+I4kN+MLUsCRzWffWFdjG/l9nfGoX8ev2yrnpk+DndA5JyW1RC4vemMqKpMnDA34Wii3GWp9thFOujI4nga75wdWK6ieM7DPkhTOGa1Q8OaQhu9uKyp8WgEua/a6DMLgM+JSNyzYi2TiJCQGJyDbpdOrMg3fo1tpsUhAZeQ== 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=cMxtiLrmjf1oiGBnupVrNp1rHrg/HEIlqBcOpJrmS1s=; b=UKPfWv/KaADRH4YgtPW4CW+vJjLFBZ9NnhKYmuRMT0w3kFTJYjFDw7TJYjxlgrYQw0ocQ/zqWSalL0JnhxXEWmohN4YV66uTtpNO/ZzVy8Gx58cN1y3RT/ifegjQU73HVWeVGzhAxWLNVlE86VvxmFuL5nveIeBX13/b9paBTaHfbHVlJs/wKxAB+3lOhlDEBPeW1Lt7qhiJgTRlsUAr4XmG6HH+XqSAmgBXgwjc4/aUb0wp3I8eZgBy4dOV4FA5f8m/znVDZcdKLWBAatbZQNpVJPMmGlZUJoCSnzRClia0tc5pn7KHKMdTPNcj+3pB3xef+p3IkuTai3fx7DRjMA== 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 SA1PR12MB8841.namprd12.prod.outlook.com (2603:10b6:806:376::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Wed, 28 Feb 2024 12:57:57 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:57:57 +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: Boris Pismenny , aaptel@nvidia.com, aurelien.aptel@gmail.com, smalin@nvidia.com, malin1024@gmail.com, ogerlitz@nvidia.com, yorayz@nvidia.com, galshalom@nvidia.com, mgurtovoy@nvidia.com, edumazet@google.com, pabeni@redhat.com, dsahern@kernel.org, ast@kernel.org, jacob.e.keller@intel.com Subject: [PATCH v23 01/20] net: Introduce direct data placement tcp offload Date: Wed, 28 Feb 2024 12:57:14 +0000 Message-Id: <20240228125733.299384-2-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FR4P281CA0264.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:e8::18) 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_|SA1PR12MB8841:EE_ X-MS-Office365-Filtering-Correlation-Id: 83cd5ff9-7968-4b58-fc5a-08dc385ce2af X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ECna/DghPCALhEp7YGogtAf+fKu46Vm8Ee3X1+twRqrTbsG+/21O7Cm38YidfTfJP6rAm4v0Cg3QfmjrCppHQXktaylt1xGHg39Bb0xE2NBntBHynRow/TDgIyVWmkPYPJrCZllYcaESmQFOFDHE8AwaRTs7EBD8vynL4MwuUXS40boXyaBc8KT36CWFEp2SVu3+VpVioY60M8ZZ3GdJ5Dfb6n61GZcCzi+BYMub3hm0deRMbl2Wt81efTh8Vop0hifD1CaQ/C246d6z9oRFcUVnnwJVoRBgq9AJtARePDocpzALd+AyA+BtambAZXDuXO/MCRILbcdP+3g53xCjBYE6qd5LjxYcNWfmLPDWmax3KSFKdakRLEOSMrPL458jd+tX0Q2NrPnD0D6sNVj84s39sw9oMLetvUCCPfZ8+Gx5/gWABs0i11XbzMWV/ctajT0/8I6J2QylMm3q7Vst3KOxdknHvT0j8AuU3EYesdUjoEPI3RncmwaFGMutOZ+4uT7bgugZcmKdxhYkq4BlXuEbfHPUyFQOPEUH+sGy8wxuPrAfE3LEo0cK1vlBPoNacr1dUFoUaV1iOyEvxfyAU8kcfPb6mIdOGD20ya5ZCzDVAJkEIn2EX11IQ6U2lC3Z 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 75vWRmNNrw5mBdGOTTc4s9siorkR7z5r1iuWSZfjnK7xas2ajdjcG7D3Zrz4oQFlepX6X7k+g9xa6sOAIZPgCRoqnVCYqAHcUT7Z7Ubrmv+0EQJTeCQlI8ePddJ/3Im+TX02JxSXcXzHz5TEW+7q+ZP7TTIMGs29/jDcaYSkA3+VjYriMfJfwkV/DGgDWFf9Z+15h5ObcPau4GBzwE7f7ATa4WBd+QrJZHRVK2KQP5ScH3joaGoCAae/DJ17cWuZYqcwu/NHE0zBpfSzrWlcUieLRlAw1bzSAWKetCJeZij2X2KUHen27hxxHHIQY7sSjYyqwAvNZkbXojxebmU25jNoRihpSrKQhOkgXBGanJEf1WdG1lkACJvNSE3F4IDH7E5KZICreSurDYYMrsYcLkTVcZaZHgkzsE/qsW1TLbNGiWUwv+0xS7XIssp3s4CQIDjWdh3n/W6/zd99m4oQDb7ggvTAh9uD4AHdIdcyVkMoBZlj476eVl7byN5/q4DUTNIi54/Z0rhsoBX4F6wfdevsb8C8vBgI/EIg8cqeY0zX7QuovqBhIg1vFBLkIGnNXDoNTJ2ROoca/3lH2TFc9sdIWNkFhfpGcGp2TCiOdO8uFUNYfuDQCzzymlk4QVK1VzXV2v3nMJw9xPU44hB313OIHnEUVo7a2261b6qT/IEs2ZrC6Q81E41pvMEFgRf+1cEru0JsF9cnQZ0VvFng8qH22FKJK44DWm8eCefBDu4ZGRAUx9yAUdbZyR0qae3XyIym6IYgW6CaSOh9Z6DJCq3mAACbjsBLz7UmEaXUvT3DviydXkigVB6MDaYb8C4UWdj6QdADucPSdTWp/UpNLvKum/ZcVskhaWt0opPqM6XnD0oyGRoIo8f4R2tt+gExAxLXBWsHsmEG7xKaps5MZWBmt8YiiIqumQu6HHuPPUIiWUjwRvGHwnRRh+BifHdWDBgQkzSJ39X6Y9CWmz9jz+MepbQk91vwVH79R89RJjpH6ldacxDPqvnxyurBd9PPlp72twiWP4lFiZzBmwD5koiD5QBpwWsXJVEx8AHp0prZmtGWwiKp6J2SNoHyvRpO2gWdLbTdL0jXA4zIvL6DQ+9ZLMHphsnn8w2wYTLGKbh4d5eAeJD0VKr8hnrxFmqblauWiFZfPJPSrSxUNx87fKND7b9Cr+uqwbzbqKAzTb4gRdAwCO14Syj/kydwDtKswBOzsPlfO6+3FVNpCL1Z/tJsF7psJ6hG1psbqORjbWplCLs5+W1Au3mu+b9k46pr8dsbSFwcCLKjizPBq/hBtD2QFU30Tx2MjRuoDHgl7xHIUVsa77CQmlbCd5DVDspmqDDyVY2/QSzlqfQt9SChu0o2kBFPXFkrwm3T9ZniWtdHf/1GcvpoahHuGsw3XuTp+iFC9IOrVQGL/zT6ZaJ8nOGJR3wOqXIjI2Nqmb4ZqEKnmhMOhQMXBgct/BEpOz9jnjNnzCucxPGoEeHRhawmEwh46DJCesPa2vsyU7WO/p61tYBJ2+ZMdotZtIU49NEtMOrkLrKhGkba1pMEwabjj2PduQ1fu0Ej5fTJsCuZH5kcJjmgXHg1jkyumWghz49w X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 83cd5ff9-7968-4b58-fc5a-08dc385ce2af X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:57:57.3917 (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: MRHTi3MkAhd4EvGykqAuelUuKV8HKsHIN93cPqH+9e4SmZTcygO+XbnB2rMGfVc+gOflVckfCDPOMrqPAv94fg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8841 X-Patchwork-Delegate: kuba@kernel.org From: Boris Pismenny This commit introduces direct data placement (DDP) offload for TCP. The motivation is saving compute resources/cycles that are spent to copy data from SKBs to the block layer buffers and CRC calculation/verification for received PDUs (Protocol Data Units). The DDP capability is accompanied by new net_device operations that configure hardware contexts. There is a context per socket, and a context per DDP operation. Additionally, a resynchronization routine is used to assist hardware handle TCP OOO, and continue the offload. Furthermore, we let the offloading driver advertise what is the max hw sectors/segments. The interface includes the following net-device ddp operations: 1. sk_add - add offload for the queue represented by socket+config pair 2. sk_del - remove the offload for the socket/queue 3. ddp_setup - request copy offload for buffers associated with an IO 4. ddp_teardown - release offload resources for that IO 5. limits - query NIC driver for quirks and limitations (e.g. max number of scatter gather entries per IO) 6. set_caps - request ULP DDP capabilities enablement 7. get_caps - request current ULP DDP capabilities 8. get_stats - query NIC driver for ULP DDP stats Using this interface, the NIC hardware will scatter TCP payload directly to the BIO pages according to the command_id. To maintain the correctness of the network stack, the driver is expected to construct SKBs that point to the BIO pages. The SKB passed to the network stack from the driver represents data as it is on the wire, while it is pointing directly to data in destination buffers. As a result, data from page frags should not be copied out to the linear part. To avoid needless copies, such as when using skb_condense, we mark the skb->no_condense bit. In addition, the skb->ulp_crc will be used by the upper layers to determine if CRC re-calculation is required. The two separated skb indications are needed to avoid false positives GRO flushing events. Follow-up patches will use this interface for DDP in NVMe-TCP. Capability bits stored in net_device allow drivers to report which ULP DDP capabilities a device supports. Control over these capabilities will be exposed to userspace in later patches. Signed-off-by: Boris Pismenny Signed-off-by: Ben Ben-Ishay Signed-off-by: Or Gerlitz Signed-off-by: Yoray Zack Signed-off-by: Shai Malin Signed-off-by: Aurelien Aptel --- include/linux/netdevice.h | 5 + include/linux/skbuff.h | 25 ++- include/net/inet_connection_sock.h | 6 + include/net/ulp_ddp.h | 322 +++++++++++++++++++++++++++++ net/Kconfig | 20 ++ net/core/Makefile | 1 + net/core/skbuff.c | 3 +- net/core/ulp_ddp.c | 52 +++++ net/ipv4/tcp_input.c | 13 +- net/ipv4/tcp_ipv4.c | 3 + net/ipv4/tcp_offload.c | 3 + 11 files changed, 450 insertions(+), 3 deletions(-) create mode 100644 include/net/ulp_ddp.h create mode 100644 net/core/ulp_ddp.c diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index f07c8374f29c..610d0530c9f9 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1435,6 +1435,8 @@ struct netdev_net_notifier { * struct kernel_hwtstamp_config *kernel_config, * struct netlink_ext_ack *extack); * Change the hardware timestamping parameters for NIC device. + * struct ulp_ddp_dev_ops *ulp_ddp_ops; + * ULP DDP operations (see include/net/ulp_ddp.h) */ struct net_device_ops { int (*ndo_init)(struct net_device *dev); @@ -1679,6 +1681,9 @@ struct net_device_ops { int (*ndo_hwtstamp_set)(struct net_device *dev, struct kernel_hwtstamp_config *kernel_config, struct netlink_ext_ack *extack); +#if IS_ENABLED(CONFIG_ULP_DDP) + const struct ulp_ddp_dev_ops *ulp_ddp_ops; +#endif }; /** diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h index 696e7680656f..3695697cc6e5 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -820,6 +820,8 @@ typedef unsigned char *sk_buff_data_t; * delivery_time in mono clock base (i.e. EDT). Otherwise, the * skb->tstamp has the (rcv) timestamp at ingress and * delivery_time at egress. + * @no_condense: When set, don't condense fragments (DDP offloaded) + * @ulp_crc: CRC offloaded * @napi_id: id of the NAPI struct this skb came from * @sender_cpu: (aka @napi_id) source CPU in XPS * @alloc_cpu: CPU which did the skb allocation. @@ -999,7 +1001,10 @@ struct sk_buff { #if IS_ENABLED(CONFIG_IP_SCTP) __u8 csum_not_inet:1; #endif - +#ifdef CONFIG_ULP_DDP + __u8 no_condense:1; + __u8 ulp_crc:1; +#endif #if defined(CONFIG_NET_SCHED) || defined(CONFIG_NET_XGRESS) __u16 tc_index; /* traffic control index */ #endif @@ -5084,5 +5089,23 @@ static inline void skb_mark_for_recycle(struct sk_buff *skb) ssize_t skb_splice_from_iter(struct sk_buff *skb, struct iov_iter *iter, ssize_t maxsize, gfp_t gfp); +static inline bool skb_is_no_condense(const struct sk_buff *skb) +{ +#ifdef CONFIG_ULP_DDP + return skb->no_condense; +#else + return 0; +#endif +} + +static inline bool skb_is_ulp_crc(const struct sk_buff *skb) +{ +#ifdef CONFIG_ULP_DDP + return skb->ulp_crc; +#else + return 0; +#endif +} + #endif /* __KERNEL__ */ #endif /* _LINUX_SKBUFF_H */ diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h index 9ab4bf704e86..0ce01192e985 100644 --- a/include/net/inet_connection_sock.h +++ b/include/net/inet_connection_sock.h @@ -67,6 +67,8 @@ struct inet_connection_sock_af_ops { * @icsk_ulp_ops Pluggable ULP control hook * @icsk_ulp_data ULP private data * @icsk_clean_acked Clean acked data hook + * @icsk_ulp_ddp_ops Pluggable ULP direct data placement control hook + * @icsk_ulp_ddp_data ULP direct data placement private data * @icsk_ca_state: Congestion control state * @icsk_retransmits: Number of unrecovered [RTO] timeouts * @icsk_pending: Scheduled timer event @@ -97,6 +99,10 @@ struct inet_connection_sock { const struct tcp_ulp_ops *icsk_ulp_ops; void __rcu *icsk_ulp_data; void (*icsk_clean_acked)(struct sock *sk, u32 acked_seq); +#ifdef CONFIG_ULP_DDP + const struct ulp_ddp_ulp_ops *icsk_ulp_ddp_ops; + void __rcu *icsk_ulp_ddp_data; +#endif unsigned int (*icsk_sync_mss)(struct sock *sk, u32 pmtu); __u8 icsk_ca_state:5, icsk_ca_initialized:1, diff --git a/include/net/ulp_ddp.h b/include/net/ulp_ddp.h new file mode 100644 index 000000000000..5be527332799 --- /dev/null +++ b/include/net/ulp_ddp.h @@ -0,0 +1,322 @@ +/* SPDX-License-Identifier: GPL-2.0 + * + * ulp_ddp.h + * Author: Boris Pismenny + * Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + */ +#ifndef _ULP_DDP_H +#define _ULP_DDP_H + +#include +#include +#include + +enum ulp_ddp_type { + ULP_DDP_NVME = 1, +}; + +/** + * struct nvme_tcp_ddp_limits - nvme tcp driver limitations + * + * @full_ccid_range: true if the driver supports the full CID range + */ +struct nvme_tcp_ddp_limits { + bool full_ccid_range; +}; + +/** + * struct ulp_ddp_limits - Generic ulp ddp limits: tcp ddp + * protocol limits. + * Add new instances of ulp_ddp_limits in the union below (nvme-tcp, etc.). + * + * @type: type of this limits struct + * @max_ddp_sgl_len: maximum sgl size supported (zero means no limit) + * @io_threshold: minimum payload size required to offload + * @tls: support for ULP over TLS + * @nvmeotcp: NVMe-TCP specific limits + */ +struct ulp_ddp_limits { + enum ulp_ddp_type type; + int max_ddp_sgl_len; + int io_threshold; + bool tls:1; + union { + struct nvme_tcp_ddp_limits nvmeotcp; + }; +}; + +/** + * struct nvme_tcp_ddp_config - nvme tcp ddp configuration for an IO queue + * + * @pfv: pdu version (e.g., NVME_TCP_PFV_1_0) + * @cpda: controller pdu data alignment (dwords, 0's based) + * @dgst: digest types enabled (header or data, see + * enum nvme_tcp_digest_option). + * The netdev will offload crc if it is supported. + * @queue_size: number of nvme-tcp IO queue elements + * @queue_id: queue identifier + */ +struct nvme_tcp_ddp_config { + u16 pfv; + u8 cpda; + u8 dgst; + int queue_size; + int queue_id; +}; + +/** + * struct ulp_ddp_config - Generic ulp ddp configuration + * Add new instances of ulp_ddp_config in the union below (nvme-tcp, etc.). + * + * @type: type of this config struct + * @nvmeotcp: NVMe-TCP specific config + * @io_cpu: cpu core running the IO thread for this socket + */ +struct ulp_ddp_config { + enum ulp_ddp_type type; + int io_cpu; + union { + struct nvme_tcp_ddp_config nvmeotcp; + }; +}; + +/** + * struct ulp_ddp_io - ulp ddp configuration for an IO request. + * + * @command_id: identifier on the wire associated with these buffers + * @nents: number of entries in the sg_table + * @sg_table: describing the buffers for this IO request + * @first_sgl: first SGL in sg_table + */ +struct ulp_ddp_io { + u32 command_id; + int nents; + struct sg_table sg_table; + struct scatterlist first_sgl[SG_CHUNK_SIZE]; +}; + +/** + * struct ulp_ddp_stats - ULP DDP offload statistics + * @rx_nvmeotcp_sk_add: number of sockets successfully prepared for offloading. + * @rx_nvmeotcp_sk_add_fail: number of sockets that failed to be prepared + * for offloading. + * @rx_nvmeotcp_sk_del: number of sockets where offloading has been removed. + * @rx_nvmeotcp_ddp_setup: number of NVMeTCP PDU successfully prepared for + * Direct Data Placement. + * @rx_nvmeotcp_ddp_setup_fail: number of PDUs that failed DDP preparation. + * @rx_nvmeotcp_ddp_teardown: number of PDUs done with DDP. + * @rx_nvmeotcp_drop: number of PDUs dropped. + * @rx_nvmeotcp_resync: number of resync. + * @rx_nvmeotcp_packets: number of offloaded PDUs. + * @rx_nvmeotcp_bytes: number of offloaded bytes. + */ +struct ulp_ddp_stats { + u64 rx_nvmeotcp_sk_add; + u64 rx_nvmeotcp_sk_add_fail; + u64 rx_nvmeotcp_sk_del; + u64 rx_nvmeotcp_ddp_setup; + u64 rx_nvmeotcp_ddp_setup_fail; + u64 rx_nvmeotcp_ddp_teardown; + u64 rx_nvmeotcp_drop; + u64 rx_nvmeotcp_resync; + u64 rx_nvmeotcp_packets; + u64 rx_nvmeotcp_bytes; + + /* + * add new stats at the end and keep in sync with + * Documentation/netlink/specs/ulp_ddp.yaml + */ +}; + +#define ULP_DDP_CAP_COUNT 1 + +struct ulp_ddp_dev_caps { + DECLARE_BITMAP(active, ULP_DDP_CAP_COUNT); + DECLARE_BITMAP(hw, ULP_DDP_CAP_COUNT); +}; + +struct netlink_ext_ack; + +/** + * struct ulp_ddp_dev_ops - operations used by an upper layer protocol + * to configure ddp offload + * + * @limits: query ulp driver limitations and quirks. + * @sk_add: add offload for the queue represented by socket+config + * pair. this function is used to configure either copy, crc + * or both offloads. + * @sk_del: remove offload from the socket, and release any device + * related resources. + * @setup: request copy offload for buffers associated with a + * command_id in ulp_ddp_io. + * @teardown: release offload resources association between buffers + * and command_id in ulp_ddp_io. + * @resync: respond to the driver's resync_request. Called only if + * resync is successful. + * @set_caps: set device ULP DDP capabilities. + * returns a negative error code or zero. + * @get_caps: get device ULP DDP capabilities. + * @get_stats: query ULP DDP statistics. + */ +struct ulp_ddp_dev_ops { + int (*limits)(struct net_device *netdev, + struct ulp_ddp_limits *limits); + int (*sk_add)(struct net_device *netdev, + struct sock *sk, + struct ulp_ddp_config *config); + void (*sk_del)(struct net_device *netdev, + struct sock *sk); + int (*setup)(struct net_device *netdev, + struct sock *sk, + struct ulp_ddp_io *io); + void (*teardown)(struct net_device *netdev, + struct sock *sk, + struct ulp_ddp_io *io, + void *ddp_ctx); + void (*resync)(struct net_device *netdev, + struct sock *sk, u32 seq); + int (*set_caps)(struct net_device *dev, unsigned long *bits, + struct netlink_ext_ack *extack); + void (*get_caps)(struct net_device *dev, + struct ulp_ddp_dev_caps *caps); + int (*get_stats)(struct net_device *dev, + struct ulp_ddp_stats *stats); +}; + +#define ULP_DDP_RESYNC_PENDING BIT(0) + +/** + * struct ulp_ddp_ulp_ops - Interface to register upper layer + * Direct Data Placement (DDP) TCP offload. + * @resync_request: NIC requests ulp to indicate if @seq is the start + * of a message. + * @ddp_teardown_done: NIC driver informs the ulp that teardown is done, + * used for async completions. + */ +struct ulp_ddp_ulp_ops { + bool (*resync_request)(struct sock *sk, u32 seq, u32 flags); + void (*ddp_teardown_done)(void *ddp_ctx); +}; + +/** + * struct ulp_ddp_ctx - Generic ulp ddp context + * + * @type: type of this context struct + * @buf: protocol-specific context struct + */ +struct ulp_ddp_ctx { + enum ulp_ddp_type type; + unsigned char buf[]; +}; + +static inline struct ulp_ddp_ctx *ulp_ddp_get_ctx(const struct sock *sk) +{ +#ifdef CONFIG_ULP_DDP + struct inet_connection_sock *icsk = inet_csk(sk); + + return (__force struct ulp_ddp_ctx *)icsk->icsk_ulp_ddp_data; +#else + return NULL; +#endif +} + +static inline void ulp_ddp_set_ctx(struct sock *sk, void *ctx) +{ +#ifdef CONFIG_ULP_DDP + struct inet_connection_sock *icsk = inet_csk(sk); + + rcu_assign_pointer(icsk->icsk_ulp_ddp_data, ctx); +#endif +} + +static inline int ulp_ddp_setup(struct net_device *netdev, + struct sock *sk, + struct ulp_ddp_io *io) +{ +#ifdef CONFIG_ULP_DDP + return netdev->netdev_ops->ulp_ddp_ops->setup(netdev, sk, io); +#else + return -EOPNOTSUPP; +#endif +} + +static inline void ulp_ddp_teardown(struct net_device *netdev, + struct sock *sk, + struct ulp_ddp_io *io, + void *ddp_ctx) +{ +#ifdef CONFIG_ULP_DDP + netdev->netdev_ops->ulp_ddp_ops->teardown(netdev, sk, io, ddp_ctx); +#endif +} + +static inline void ulp_ddp_resync(struct net_device *netdev, + struct sock *sk, + u32 seq) +{ +#ifdef CONFIG_ULP_DDP + netdev->netdev_ops->ulp_ddp_ops->resync(netdev, sk, seq); +#endif +} + +static inline int ulp_ddp_get_limits(struct net_device *netdev, + struct ulp_ddp_limits *limits, + enum ulp_ddp_type type) +{ +#ifdef CONFIG_ULP_DDP + limits->type = type; + return netdev->netdev_ops->ulp_ddp_ops->limits(netdev, limits); +#else + return -EOPNOTSUPP; +#endif +} + +static inline bool ulp_ddp_cap_turned_on(unsigned long *old, + unsigned long *new, + int bit_nr) +{ + return !test_bit(bit_nr, old) && test_bit(bit_nr, new); +} + +static inline bool ulp_ddp_cap_turned_off(unsigned long *old, + unsigned long *new, + int bit_nr) +{ + return test_bit(bit_nr, old) && !test_bit(bit_nr, new); +} + +#ifdef CONFIG_ULP_DDP + +int ulp_ddp_sk_add(struct net_device *netdev, + struct sock *sk, + struct ulp_ddp_config *config, + const struct ulp_ddp_ulp_ops *ops); + +void ulp_ddp_sk_del(struct net_device *netdev, + struct sock *sk); + +bool ulp_ddp_is_cap_active(struct net_device *netdev, int cap_bit_nr); + +#else + +static inline int ulp_ddp_sk_add(struct net_device *netdev, + struct sock *sk, + struct ulp_ddp_config *config, + const struct ulp_ddp_ulp_ops *ops) +{ + return -EOPNOTSUPP; +} + +static inline void ulp_ddp_sk_del(struct net_device *netdev, + struct sock *sk) +{} + +static inline bool ulp_ddp_is_cap_active(struct net_device *netdev, + int cap_bit_nr) +{ + return false; +} + +#endif + +#endif /* _ULP_DDP_H */ diff --git a/net/Kconfig b/net/Kconfig index 4adc47d0c9c2..858987ee2c65 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -515,4 +515,24 @@ config NET_TEST If unsure, say N. +config ULP_DDP + bool "ULP direct data placement offload" + help + This feature provides a generic infrastructure for Direct + Data Placement (DDP) offload for Upper Layer Protocols (ULP, + such as NVMe-TCP). + + If the ULP and NIC driver supports it, the ULP code can + request the NIC to place ULP response data directly + into application memory, avoiding a costly copy. + + This infrastructure also allows for offloading the ULP data + integrity checks (e.g. data digest) that would otherwise + require another costly pass on the data we managed to avoid + copying. + + For more information, see + . + + endif # if NET diff --git a/net/core/Makefile b/net/core/Makefile index 821aec06abf1..c135195005f5 100644 --- a/net/core/Makefile +++ b/net/core/Makefile @@ -18,6 +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_PAGE_POOL) += page_pool.o page_pool_user.o obj-$(CONFIG_PROC_FS) += net-procfs.o obj-$(CONFIG_NET_PKTGEN) += pktgen.o diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 0d9a489e6ae1..c57a505bef4b 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -76,6 +76,7 @@ #include #include #include +#include #include #include @@ -6762,7 +6763,7 @@ void skb_condense(struct sk_buff *skb) { if (skb->data_len) { if (skb->data_len > skb->end - skb->tail || - skb_cloned(skb)) + skb_cloned(skb) || skb_is_no_condense(skb)) return; /* Nice, we can free page frag(s) right now */ diff --git a/net/core/ulp_ddp.c b/net/core/ulp_ddp.c new file mode 100644 index 000000000000..658e67620c0f --- /dev/null +++ b/net/core/ulp_ddp.c @@ -0,0 +1,52 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * + * ulp_ddp.c + * Author: Aurelien Aptel + * Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. + */ + +#include + +int ulp_ddp_sk_add(struct net_device *netdev, + struct sock *sk, + struct ulp_ddp_config *config, + const struct ulp_ddp_ulp_ops *ops) +{ + int ret; + + /* put in ulp_ddp_sk_del() */ + dev_hold(netdev); + + config->io_cpu = sk->sk_incoming_cpu; + ret = netdev->netdev_ops->ulp_ddp_ops->sk_add(netdev, sk, config); + if (ret) { + dev_put(netdev); + return ret; + } + + inet_csk(sk)->icsk_ulp_ddp_ops = ops; + + return 0; +} +EXPORT_SYMBOL_GPL(ulp_ddp_sk_add); + +void ulp_ddp_sk_del(struct net_device *netdev, + struct sock *sk) +{ + netdev->netdev_ops->ulp_ddp_ops->sk_del(netdev, sk); + inet_csk(sk)->icsk_ulp_ddp_ops = NULL; + dev_put(netdev); +} +EXPORT_SYMBOL_GPL(ulp_ddp_sk_del); + +bool ulp_ddp_is_cap_active(struct net_device *netdev, int cap_bit_nr) +{ + struct ulp_ddp_dev_caps caps; + + if (!netdev->netdev_ops->ulp_ddp_ops->get_caps) + return false; + netdev->netdev_ops->ulp_ddp_ops->get_caps(netdev, &caps); + return test_bit(cap_bit_nr, caps.active); +} +EXPORT_SYMBOL_GPL(ulp_ddp_is_cap_active); diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c index b1c4462a0798..ad2a1dd5af6e 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -4807,7 +4807,10 @@ static bool tcp_try_coalesce(struct sock *sk, if (from->decrypted != to->decrypted) return false; #endif - +#ifdef CONFIG_ULP_DDP + if (skb_is_ulp_crc(from) != skb_is_ulp_crc(to)) + return false; +#endif if (!skb_try_coalesce(to, from, fragstolen, &delta)) return false; @@ -5377,6 +5380,10 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root, memcpy(nskb->cb, skb->cb, sizeof(skb->cb)); #ifdef CONFIG_TLS_DEVICE nskb->decrypted = skb->decrypted; +#endif +#ifdef CONFIG_ULP_DDP + nskb->no_condense = skb->no_condense; + nskb->ulp_crc = skb->ulp_crc; #endif TCP_SKB_CB(nskb)->seq = TCP_SKB_CB(nskb)->end_seq = start; if (list) @@ -5410,6 +5417,10 @@ tcp_collapse(struct sock *sk, struct sk_buff_head *list, struct rb_root *root, #ifdef CONFIG_TLS_DEVICE if (skb->decrypted != nskb->decrypted) goto end; +#endif +#ifdef CONFIG_ULP_DDP + if (skb_is_ulp_crc(skb) != skb_is_ulp_crc(nskb)) + goto end; #endif } } diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 0c50c5a32b84..cec2eb5b68f6 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -2048,6 +2048,9 @@ bool tcp_add_backlog(struct sock *sk, struct sk_buff *skb, tail->decrypted != skb->decrypted || #endif !mptcp_skb_can_collapse(tail, skb) || +#ifdef CONFIG_ULP_DDP + skb_is_ulp_crc(tail) != skb_is_ulp_crc(skb) || +#endif thtail->doff != th->doff || memcmp(thtail + 1, th + 1, hdrlen - sizeof(*th))) goto no_coalesce; diff --git a/net/ipv4/tcp_offload.c b/net/ipv4/tcp_offload.c index 8311c38267b5..56705fbe6ce4 100644 --- a/net/ipv4/tcp_offload.c +++ b/net/ipv4/tcp_offload.c @@ -268,6 +268,9 @@ struct sk_buff *tcp_gro_receive(struct list_head *head, struct sk_buff *skb) #ifdef CONFIG_TLS_DEVICE flush |= p->decrypted ^ skb->decrypted; #endif +#ifdef CONFIG_ULP_DDP + flush |= skb_is_ulp_crc(p) ^ skb_is_ulp_crc(skb); +#endif if (flush || skb_gro_receive(p, skb)) { mss = 1; From patchwork Wed Feb 28 12:57:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575443 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2087.outbound.protection.outlook.com [40.107.96.87]) (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 D3FF8149000 for ; Wed, 28 Feb 2024 12:58:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.87 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125088; cv=fail; b=D3Z3lCPcbyXLLh0WRUDQWJPyLa+s25aBLflmKf2numaNK1/fm0KIkb6+/GpT6ZSPfusTM81cFjWM4/kgroznx3qfSudavXiDdLNGMDpuDHZb3qCo1PZPmoch3BxPRiiBOlw80I5knIu8vibHQS8GXDbts6kMmn1uV3aeRPy0I6s= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125088; c=relaxed/simple; bh=rWwDTMYyh4huFbmr43usIcSnJIbiEun/qxZVk90fjzo=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=A6kfhCIKsBeb6DVMF/zZfrrEl1LI52OnCgAZLtzlUKcUjwvqrqqE4J/g3DV5IGll/DUPiJIu5OGgDykFYdqaUFVIa1PkOdUolP+WuejOrB90b4VajsrBO46shlQ1gHblEaf87A9C1JJYTLht/HINEaRZve7x3KZ57ettzxXxdpU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=UThVP9o1; arc=fail smtp.client-ip=40.107.96.87 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="UThVP9o1" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PG1gnNmDeYlF8xFSUayx/qKASboJ90+ajoLHTAkjjJgY4PItuKhQZV4YC2U8aSQi7f28fP9zWRwNq2+Vm43tqwxqdmb1ydMn6imQquufNw/p4690pxuWPWGVhCnOS58c48YhPNPhDF29HFvq0P8XqSlMbVi2T+eZU8AdCQKGE4brBY27r5dil4t6R7kHxBJbGaEOG65KA5nTfmqyNViSwxq6tsM8NCFyHnlrBLw0LRRZelsCRXA7v6aVv9HP0QE5RfSDR2gszV3I80D8fq8m/DeC58BqIWbgGrsGjpJi3DovtfzJlIcaQQ9+UYo6qJqAOB+IBX94pL7OXVI3GgRjCQ== 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=M7fZE2qbrp3EUBu91S7bpGcXKHVPboj8VaZpFKEdGBM=; b=HfVTLiKqb3ZZFpUAEKqwCmsbgWX9xHA0fl4G8G/DZbaifFoGOlTcMNmqrmDTb/IAknlQ785GFBtPUduB3y+iXlkTGILMj7LFfpfhEkRZMMOc3Q5iv5CC1SsdDKJ0HYUjKn7Qlb3EZy39Gib7/tzoIdW5ncEPKB/+owMLdin45/oJmAE0PpMrPRG46/tBGOvuImdcVk09avWJ4aaSdO3v4cfwGWtSX42R5MR9I8p3zaFW7OHlrZhJxzCzZUryaBPR75dOeJrG+YHprngj65l52iG8qCxjDRXNw9J0cwK4VWXonUaENfsQPpp074fz80BEbZaaxGax8sU6DTojMiJxFA== 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=M7fZE2qbrp3EUBu91S7bpGcXKHVPboj8VaZpFKEdGBM=; b=UThVP9o1nuXuBkTDWb1yjLfqblSzo7wnAu92SucbxEfDE2d6eDck92ZMCGojhfSdhX+7c0GBWiopbB+ra6HTiRcrN/DsmLqJ9DEcWhSl5FZAPKzUD1Uy1O2uf5Y4g1EzY/fPbjjQksVJXlhJYE8HajRIydCmzebSDgxEfpcII2ihZ1ic29cydUjkgLSyMGF/CjV9QEj+cmKe+fXyHJA1sMKyZWfticHJkGWYsBg24FHpzwcMDa0PFqL1lEVrwAhOCbUUVpKcYxRZ5yZyxcjnDYo96PuY6W0vwjlDPtlYvetBdgNtP1oPS38nU7SVyq7bSQvXHdSgbeNsoIsrIXbWTA== 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 SA1PR12MB8841.namprd12.prod.outlook.com (2603:10b6:806:376::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Wed, 28 Feb 2024 12:58:02 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:58:02 +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 Subject: [PATCH v23 02/20] netlink: add new family to manage ULP_DDP enablement and stats Date: Wed, 28 Feb 2024 12:57:15 +0000 Message-Id: <20240228125733.299384-3-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FR4P281CA0443.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:c6::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_|SA1PR12MB8841:EE_ X-MS-Office365-Filtering-Correlation-Id: 338824b2-2b37-45eb-faf6-08dc385ce5b2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: RjMg/qGKOcv6uyf6t2cVCxM/TTNMqNPIiMqdckhsRrwhwdjxwhOgIM4l0IcIrVNzLqWmlgBECSsq8xwnebK7f5gjEuyaBu5VwGZUJG3WPf/zxDqYTZnNmsMWPpYqIZldlrn839f9xsccCHnb703DQmpsSDyv/8n9SZW29dQ/LdDMhxB9+uyLnXRloOvUZ8/bhjZdVtq76l9Tie7t2TaszCQUT9KjpIEyvvL64tSBkAeTQ+0HGqxb1G8JfRH2NrYi5wIMmIVDDO2gYivVdKYQjbrkKw+ts2s01r9lbW8FOPN/g6SpCWd9lbTRGaIhIApypr0/ffx7hX4DMwR/2hF9Vq/EibDedp1Ey8KEZRV7MNmBD5B0oL+UoB0+KP3Up8WpqMMTcZoj7RTu22rj1BXSk1NOvYtana0zZfLtuVWa1Hw5ap0sIryQLnEKRieM2rTrSL/fqom5bJJEfRJ8rZZLXY0pbynhYFKtJVq5C0ZaLMqMZUCma1XBCOo4iZJkm5pWmw8TvGbut0Er/8vfDdXNKfw8r0khPKFywHTxLkwaQA9+48h2Q/+qZxX2HlXv+hJoYWXQj2rfwrIWORyCEbbOIxTwQf3E3mFu6HCk/hoFbyDEUN8NHxHMnGi6ST+qZNat 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NE/xpLvHTVB7GrcM/HDlCcNsacg0NmqZUQdBHvDK3ooxCcdg8kSSST6Zzu08M1iT7Yh3TJmn9LPkUC1UEEL1YETHOoruhJiQDk14ToCXx6DSSytca7+n8i77XAKH8NjsljDQNEBLNnLCUq2tVRE/wzCJJ+LoxMR/IWeWQs7T9m1+/OsLW3xfQEpjk9BtT35CuSj8QoBIJ815ID7Vs6w6LbTOpCXSTVld8PbF81HNSYjm2PmbPn/GzreI0XrM5wFZ+/C5aEEalqkmGmwRJrNz0gwK7uevPzi7bHlQRAELFOl7ko6uuBsvDdLRKqzdUgnHiBMHxICJ9um2raGEADzO+LdgDIn47wni62mwlFWoju0BvzWUJbEbiEtGAfRm3TgLsez942hExBjcGWb/tG0vM2lxjBOCQYl7Xsukz8Inm9NYBAB/HuOoO5zGvVqJW33cLQtfjn8BlybdQ9h4gsAclAxI0+O7SiDBJmPWCoiJI+BYWYQX1zxe/NHj9/dyZ6SXF4lRyxo8mfSaPtE8NnPMf4kCdN9RWCiwq+77D8xrgv1yN/rivEUlIAwMBCXButoCS72UOr6AbPZfPwmqMzuBRYXU/2jRJC0QuBHlUnOUSyXanAEjtlrcMBUifut7FSyxFWRL7vdGtUYcn7hHYZrMjUsMQDMJZ79FobaLHYFMK7cN8nfl+vNxy+R3HKCyGJQu37anf23v/u75jasRVzNPaWtmCQ/l5JoAulLA7nKxZjeZBnUW/NCj2duLAKqjmlh6oqrqZC9/bzX6o3OuSsms9crOhxl4DGJTUtiBffFUlEtXKZwBOmMQKujtOcHrm5nbalpE0jDpTZDWjpiAVm2wcSMwoZmnUUmdztBR+Ce3wRkInYFg/56ohNGsQ08BfxG/iR/g2EzrRg0Z8JCLL7f19RwGGEMns2LKCbmEnr37DrjRq1+yjUd0E4si1WnXVsHHirJ16kAolEX8WnQVFViOySfjmIq+BXigHHGCJMN4lolp8UiC6Oaqa0526ZnNBR262TbkuC6mRLXHukz9JVqj8aUji8H8E0CJUUhK9WgngrSmTaRX+elJ+svUu8VAJPX2CYDKQ+gdsHSnByS3fakUrVgFEAPXJSGjvNn3LWOjXzkwYYnqpsOTmodsA0ng2vIJX3P97EWPy5Lbc6CTA/bxePuKcEHCz9zz9fHfYWg4uzsfEG9c/S5xewXqY7/CEqKzLs0MajCu033HEYyxqKWXuStUSYSg3czjDqulVMHtCix2dzWKRCoznV9rK2FEcB0neCiX6Zl3XPvgEHKxw9HvLNQpa/TOz4OYe9PimBekbOUfscD4SlOab9s8r2qJfxqykADVRUwa7T95RVkPGhyWKaoSvjT74QUlgPnRpRmfWyHDe70ajFJkpYL1V77VZKe1URRReph3sGXpO0UG9JErPA+0PfN3S34qANsLtKNJdvEeNlq+1/Cp1hqaik9u25NGLk/gOXY0Flx0zPLHbfTDT4NHJzggYsfGkPW5E/1U85P1q4aw0h5zKIURsHjMS82aT6nQ1L2pKD1zsr6MVAu9oO8L6XrY6u6QS45fAa4Gnvi3yHmfb6jpaCDANXa3YPr/ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 338824b2-2b37-45eb-faf6-08dc385ce5b2 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:58:02.4293 (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: DVDN9zdqvUlTSbFdbBzGusnqXWGd/0CB+l0FlBTu6PEw/Dl22JsWMQCPey2ZF/xekxrMMyAT/U1dGRs7eMGNHw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8841 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 | 344 +++++++++++++++++++++++ 7 files changed, 685 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..27a0b905ec28 --- /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 5be527332799..ce333e28e089 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 c135195005f5..da381587a161 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 page_pool_user.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..04feefce23c2 --- /dev/null +++ b/net/core/ulp_ddp_nl.c @@ -0,0 +1,344 @@ +// 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; + 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; + u32 ifindex; + + if (GENL_REQ_ATTR_CHECK(info, ULP_DDP_A_CAPS_IFINDEX)) + return -EINVAL; + + ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); + if (!ctx) + return -ENOMEM; + + ifindex = nla_get_u32(info->attrs[ULP_DDP_A_CAPS_IFINDEX]); + ctx->dev = netdev_get_by_index(genl_info_net(info), + 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) +{ + void *hdr; + + hdr = genlmsg_iput(rsp, info); + if (!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->dev->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->dev->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, hdr); + + return 0; + +err_cancel_msg: + genlmsg_cancel(rsp, 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) + 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; + int ret; + + 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_SET_NTF), GFP_KERNEL); + if (!ntf) + return; + + ret = ulp_ddp_write_reply(ntf, ctx, ULP_DDP_CMD_CAPS_SET_NTF, &info); + if (ret) { + 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, + bool *notify) +{ + 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) + return ret; + ops->get_caps(ctx->dev, &caps); + bitmap_copy(new_active, caps.active, ULP_DDP_CAP_COUNT); + } + + /* notify if capabilities were changed */ + *notify = !bitmap_equal(old_active, new_active, ULP_DDP_CAP_COUNT); + + return 0; +} + +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 = false; + 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_CAPS_SET), GFP_KERNEL); + if (!rsp) + return -EMSGSIZE; + + wanted = nla_get_uint(info->attrs[ULP_DDP_A_CAPS_WANTED]); + wanted_mask = nla_get_uint(info->attrs[ULP_DDP_A_CAPS_WANTED_MASK]); + + rtnl_lock(); + ret = ulp_ddp_apply_bits(ctx, &wanted, &wanted_mask, info, ¬ify); + rtnl_unlock(); + if (ret) + goto err_rsp; + + 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) + 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) + 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); From patchwork Wed Feb 28 12:57:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575444 Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2084.outbound.protection.outlook.com [40.107.223.84]) (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 015E01487DC for ; Wed, 28 Feb 2024 12:58:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.84 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125091; cv=fail; b=ipQ5HBOJRtDQaTxVMK/61TJXZjbG13liM5m9Xu5ErNfUOc132XpafybZx7dzLOg/4eufcM8wOOU3k+C5tmOKi7Ppa7MmKNuOLpkdCycB9PJFdn3xNKkgDuEdVWI89Xv7fDCtn8w4lt1oXxikG/DCi1VxciDvfyslrBFGjGTKFlQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125091; c=relaxed/simple; bh=WPG1WdFQCgWH205L4cyQIMK+IArbMBwXIAxOB8WErX0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=Y9OCTvrWkzh3jkIBJzUZNiSUHv2kOzHNSiAkb0n0E/gnne4xUvX5a5e2sTVHFcvBlCfEJ+h8rwqQVYpkzoBOl4Zm2oXuCtxZVujyzOWh5TLPmjeHmvnY6KTfDL8CNAV3MefQ7t+N060BUHHq37V6n5t+HMW1rjgWzhwLLSEM/oo= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=HsSCRp0G; arc=fail smtp.client-ip=40.107.223.84 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="HsSCRp0G" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ov4JbDkp+YQ9g8rrZzip3uq5mpazAHIQFExjEJpXGZkx9G0Nc3QBpkAdQpw5OBegtVAAZ/8IdUOjN3phuaemdkRZDxJ2SwtDEWuOMQiLd917+zyz8d2fygEbMoteNq+Ir3q4ZLaDztMVIqD14Rs2+1ukZHwNQNs4PMyAAlo20cS60kbhCf+38VsHFlEf7ERUAGIbA7yG+yComFO21aavLpcbQUAfC5I53h+sLLVks3s5LHufZ2uM8szt8UxNl+VrblPyHvfDISs+F+9JVxebLhlwYoWyT1FddyKCQYcFq7vq3Wl1A9eiFjZYjTSIHgJ1Bq8ipBRtBFA1k4T7zyvrHg== 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=0sLApczNqqtZPZpFTMVngzXYhp8Tp26lWbudrMCYYF0=; b=muB59ZrFCiqQiKrZtRqsExjjHErdVXxrlE34MrzP424d7ljRvNN6/cra4HvVJlB3NxWdC9rRXKVT73GjV9q2NfARhoRNngH7cM3KlfoplHaI280fOmtZmO5xFkMeYfg5WgqybqjwacsEHI3D/PdQQBaLT1vmWHdF56RcY/t3XEzM6JAROEVhjAEkyfdjt+EZi5o72HYbztCfH1sIu9AgvQhKjcwlNqo7BUT/NSeND0D9VYLz2axOCyCdSJW1TPtb7jYzK1FBUM89LGSe5OrKh4YXXHo8nXv0zMOJlOyy956qxXg/lo/3/VCsXmycnO2KKrisSYSc5/GElZ9RTb1I9Q== 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=0sLApczNqqtZPZpFTMVngzXYhp8Tp26lWbudrMCYYF0=; b=HsSCRp0GC1TsPw4W5A7ThpP6yn9ModCdR9mzI3ttZAAYlorecDYPttGLrfc9kR0NUJjb4gWUOcmDKfN6P3PYKbvxk7SURgL1QjlgqWSN45rYprHJBsyjZz5yxp5SGIVEQNpsmRmr4hGmSIk9v9L7XttqVLtxHCQpsyBLZEYyCrjp/DM6iP6IfflgZpNAa8+48PlwTwhf425HDimgXjq10iIEdwIE6EFcGVYkNO1Sq1r0sxUKnnJtS2RoCwQQ9MDxJ/6MKS1j71qCZLDxpDzpCtgccN3vkAAt5tdvCZKDiDor4eY4UIvzs0q8XO+lOK3gjS015OMh+a7CuRngFjqDCA== 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 SA1PR12MB8841.namprd12.prod.outlook.com (2603:10b6:806:376::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Wed, 28 Feb 2024 12:58:07 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:58:07 +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: aaptel@nvidia.com, 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, viro@zeniv.linux.org.uk Subject: [PATCH v23 03/20] iov_iter: skip copy if src == dst for direct data placement Date: Wed, 28 Feb 2024 12:57:16 +0000 Message-Id: <20240228125733.299384-4-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FR4P281CA0322.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:eb::15) 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_|SA1PR12MB8841:EE_ X-MS-Office365-Filtering-Correlation-Id: 3af79acd-b958-4ad9-a0ed-08dc385ce89b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 7FMyLqTE8cHJBNiNK3jOFwML4ld4GL6bka6eyAiqm+X8JUCnE9W3HjfOQjQiorLjih+PDy3PH+n0I0MpDIus1e3L2Y3QOB2wjgPEs6+wUCmkD/If5rZrFJBMJ3oCmz2ZLtaOugpOdx4SyZzCCFSOavMClpZgasc4IbXTjeIrosCr04Z0mPwKQAGR1/qtrnvMH69+PzFYyjO6TzR9fELvnuDPpUa5A00U5nyr3VVctHLqT7c76waelo9POfrpA6+hBUqgOUqbfI70PJJODC/UX6z/OPwoI8QWMnSYHuR16OEWowD5M7MZngto+OV7iMKMjmJhtUgMX+NCJu7ANlWSCjPRewmJRDV+i8PCpNiRJ/DBv0/Wwc+JGjppAMfrTA7I+MCEG+GBgNMsjypX5YgxSvYMc0u0zsDFjmLmlbFie4QF8IOOQx/xJ+eNwXq8IrSaHnPAoxsX8nl4zRKDau0jHVcxg0GHpV52jOcl3I6YxYsq8tT8IPNJSEJpetonMQOjes4RBHCQNp/4HeU/P5gAYW2UkHaT3kh+jDwwoTFTlZULmz4/IqDqZdiKuwO05K8Cu+h7wDl3DFp1JmltGmSH1XcaH4AmWTOT+rDqswr3AlwZVftC4Co/RJ1p0MDKng3saDbpsxRLjuYk+/0vqkOupA== 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SoIPPANPyVYB4HgkrX63ee0NQJAbBQRv1e9oVPq2nDRncZaDVSDaz5iaoLMJDG40OefsbonW1cShemRGgWbnduW0optqXpD/JJEpNS7+mdYhyi1SeyBrN6Pk4UY/zitbm8zQqAxAHpSYCVnMxPyZl+pH2p1xC/IJsO2Gn8gLhvadY1ZxMfTaGBeA6rdIQI1DZeABEHyXUNdWiWOqkwy/SngIrzlL8MsEKpgQ4QUAw2jlAnDLgLjkc073M6EeZnQ2is9ZMv2dykFV9NZo2d57xDOWy7eDfIYRfjODRGtzyfvri5Snz/yZPON3AnQFuMTihHk+fH+rtACpdvUXw9jIGaX/RheRjEV0vNboLaOUWRclu9I+xbVexZNRu0jLIO2J6c3ELchmCWKAOoc3dM/qN7OLRWqp5hX0qeEP6ITkK2CuKkK3tKSKqiQwG+y7cIVqwol8YLUg3XP6f9o0qP8xqmH3O6uAKzZIXc72rs7ylmTnWoWV+//Mpr8MjbaNsl/WLTApGsrNlTgr38unzuDi45ZVNbm6PLr27UAxw8pT2oizY9goQzgy3gfB4bNOX8AANjnpmLJ12pJjNYWcF0Wba2/EBf4FD8O7f7pHJUNbwoJuQvRSR3gnsR+ZPHCX59rwcsxJ/FslqE15HfAuqWF7HfuTSwskHIQq78kjWFjheGncnBtZtidwl8yS7YADwr8UOEzLVx23WGtM13RoZeDNkfGQ2ySDgXhhSdu0UBSSrN9F2xXHSIyagMwcxqplakIsT38Q+3l0rtJP3OCZwEJLYMFGf0Ejz8PEUi0sWzCnbtJYng6i8D2W7ZVRJeDlYNmfARI2O9droljzuQ6Cc+ufDYDpGWLtZ0758D77LT4u0y0Tu3dzIeDvxRBl9M9MbpgXPqLoWA9th2QR8qIkoAkUSA5d3ACQe+aF0yIO/yyj36jss0HGBHHu5TrrIbomyWjRdxffPsGDW18EytJqVoQzCIe9FhIPpFAQ1I+6lMDaFGo38teEjzLaipj/F55/nWhnXLQ1icphOq1BcpNF97sQcwytEmiRX2TIOPaM+PXjrlH3Pf3y8uqv0F/6tCU6IA4oNakDJ7IcTbueqQupJy98HH233wD3LbBOMxlCZJ6PoWyzwaHqld5Ej26Ov/hxob6+B0NOPy+jHwRclkEFB8Y/mBE4AzkM8J+6f8RQz5WSCMt362zRAy+GHzkv1YWztef+NmnVoOLpQSV4SV59fs4o1nVrtPJrjGriUGG5W1H1qnlGWZ/oRRZHYJXMA9KJ0hitZ06XyS0M+rV3JxTiVCPyDOUi/fhsIVu7UM91DDOgC3/CCiPzN+ltg5fcejKbTtZc5b0NEAvHBjlJudPBdvLvxabkfIa75IVYWpd5+TNlJLRE3dypiII1GXndPK81RwdRK6x9tJP1lYv/UuPnDtabcw51iDp87HXEXS5H0xKoYQbtnovsvLCXfdCtg9lB8fCtS+xVIXzn0JCo614XGyH9CjOj49971GPbwZVla54Iq6cNop1ck23IwuRt8pLJvQ6in2Q7zQXqmRbmhJHgJL4NCWJxzJJqOstF5SucZDu4OnWBrdcttjg5++Ui9oyOkE2c X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3af79acd-b958-4ad9-a0ed-08dc385ce89b X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:58:07.1515 (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: Buv+32eCTWfKM1RMjlDrlzIbNiabnRS3ygkFwunPB5EVRqNwTTvhW0TIc0qBZXoduckZ4kcXFNx50N9ZHKWLJg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8841 From: Ben Ben-Ishay When using direct data placement (DDP) the NIC could write the payload directly into the destination buffer and constructs SKBs such that they point to this data. To skip copies when SKB data already resides in the destination buffer we check if (src == dst), and skip the copy when it's true. Signed-off-by: Ben Ben-Ishay Signed-off-by: Boris Pismenny Signed-off-by: Or Gerlitz Signed-off-by: Yoray Zack Signed-off-by: Shai Malin Signed-off-by: Aurelien Aptel Reviewed-by: Chaitanya Kulkarni --- lib/iov_iter.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/iov_iter.c b/lib/iov_iter.c index e0aa6b440ca5..feceffab1de5 100644 --- a/lib/iov_iter.c +++ b/lib/iov_iter.c @@ -62,7 +62,14 @@ static __always_inline size_t memcpy_to_iter(void *iter_to, size_t progress, size_t len, void *from, void *priv2) { - memcpy(iter_to, from + progress, len); + /* + * When using direct data placement (DDP) the hardware writes + * data directly to the destination buffer, and constructs + * IOVs such that they point to this data. + * Thus, when the src == dst we skip the memcpy. + */ + if (iter_to != from + progress) + memcpy(iter_to, from + progress, len); return 0; } From patchwork Wed Feb 28 12:57:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575445 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2067.outbound.protection.outlook.com [40.107.223.67]) (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 10763149DE1 for ; Wed, 28 Feb 2024 12:58:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.223.67 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125095; cv=fail; b=NFf0tXuwTdxBN2/m1qBoZ+vyRLVhbkF/7KItASI/dwkmvhNJoSdHCRFndwnbrC5ZviIf1iNhqcXxeC83eSN2xsOOeJOle/oi/VRCHGkqQUdGyBb3DsfzbPM5D9mvdnSRo/da50yu2W6a8ve67UEePqNZO0a4Is1dSi18FCj35A0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125095; c=relaxed/simple; bh=x+ojbMqS+nBq3Ig5KQM98i56xaJzbLwn+0iLQIi4/4Y=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=fvQVnvWEpI/ZFE6jl3vg9pcHuNzb5bNAwvQSHa8RkTed/4+BGAOiuaW+1m+CQ8sgbfshfDbpQWUcVmsv5TXmXhuzs7VeDaGPaJGc1HbedMuzz5MjTx/2K+MXw5/Wx+7CNAWNuXHE9VgKAhYoOcv7gfuZEH9E4UDIPnNzYNOCXug= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=bp1WI+cD; arc=fail smtp.client-ip=40.107.223.67 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="bp1WI+cD" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=lVDsl/oHpNKSc00C3i8cZuegZxSWR9etI3H9WZyJLG9468vOZjXu0+g4PY1QKbqLBYA1doW+u79Enu7Z36KQY4O5oSXjetAuRMb6Dp2uKDMw7gQXVVVs0uYkv3yj2gtZNlYEMm4i5B/hAeLmq36Mqag8ZQIpWzzNCzCpb1/+0jUTrxcWJXjunJKzJz1rTEou1Jbw1LLzEDVyFGoIZmAbfaEUHzfcBNiYHfb0DNNOsCy93JOCwx+OCod32v9Qy4jA3wuTvcX9OCgvHP0T5NF18g+M/yxFrpERtMsCoIfHlGJJNqJtCsQ1lntuvn1stbYEoz5ZcFNaS3aFhLlbFGKSdA== 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=TfqBOtuDeJTu7qfzs8wYEaS66yZiic1CbmyP5u2Ot2I=; b=aiOJ3bK5mDXk2zmv+ZyEBiaQLqhyxvIpn3odftntbzaWM828kpiiyJYyySH/QrkoLeq12E4IkZvKVlY6y3KDW2rJe6bVTjsW2X2n+P9mvArgZ0sw0RIpVgFS9XvkJZWMNpAlaMcytENMlW67TEn1KUZDTqUryuFBP9McimrWbmCIW6oHYEppCw+Mo6yCdWIOuKbNNqcW1p3nXpQYFiW6F3FVzYpExbXwDeyShT6/Q8WGoh4OmvRZq4vKZAB8EOZk2/tlBX0yFaaDJLXY582P9ZnnbCgQpje+wmxRFhSYV08D1NB6OlLrgiTjBKi8cZUpGanSZ24oOGKZuxNpoqghaw== 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=TfqBOtuDeJTu7qfzs8wYEaS66yZiic1CbmyP5u2Ot2I=; b=bp1WI+cDvetio2hbE7NpARMBXij7Kp4ys7h1OI+D55s026pox/+S9bcHpXEQTwTKU2zK/sdyuULDA/z4HuCyzIjriP/ENICXJdvjcYT12hNUH9WX+az00p2YqkyLai376LP0XBTuoq1FSF5SCnKAFelpR/EaRNLYV6n5PNI8J9LsfKN/joo3AfGqd/BWVy0vw5UqvD8Dl1XdIUgVgebF4H94TeOCYNyY2NFtH78RgIkOaKFCUyONe1GwzclrmedYDeE0IUrcZnyM8Xvj1cJ48pSGyvZvT1A0uRaRGyUEeqbQsJqIK4c8XkqQS2WWHVvZ/TOC/KNAgKRCdvCiS+NqSg== 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 SA1PR12MB8841.namprd12.prod.outlook.com (2603:10b6:806:376::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Wed, 28 Feb 2024 12:58:11 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:58: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, john.fastabend@gmail.com, daniel@iogearbox.net Subject: [PATCH v23 04/20] net/tls,core: export get_netdev_for_sock Date: Wed, 28 Feb 2024 12:57:17 +0000 Message-Id: <20240228125733.299384-5-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FRYP281CA0015.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::25) 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_|SA1PR12MB8841:EE_ X-MS-Office365-Filtering-Correlation-Id: 6b38e6fa-bb97-4577-b4e7-08dc385ceb33 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JcC8eJf2+UC5aKlxay2+FbLAmBpUF5IY4TzFAqEg4rTwSPsyxgLVBuPDMqtGafmNdP8xuHhqLz1jBsKi3Z74uzVt+ARfgY9cgyn0xW2rKOH+3J6A4TwS2JBQU/qXJ40ApR4KsXNMgWJBe+55VDc5hzzCPNUxk3lXNDmy7cAkbjC0wZJ1zP4NuDGkUGBEXYNK4bbh/as2tSr94UBp5panNX45xwCbAZMyyyX5NhEAkUGbTNGIjTu3hmsnreM0imFuMLek0Z8wDFqHxxLfuB5Ha2KiaTRHxikZ8qkeXZPOY2kgSTYD/BD1p/JdqnNQFYVtRZ4LM+tjOoRD3uegxvuXlIaS98OiYvkAfsRWlFnW8gjVXPZIa0plaA/+GvACPwxxk28PdNMFXQxj330gLCuUId3qWMbJovhoSQALvvjpGRrii9fNvoAdt+BUoM811gUnDyALhfckrqzdg9Vej5NvOIkSHgSHjNTFldkAEX/s20jZcLmQdn3JvBmM5QV86+hTVbicdmvbEuTRCRcsCk+7xhwA915j7EQ8fJvzQiF019JyFnow3sKvKOU7tz3iWv8/RSSrUsazi8qotiu7mp+Vg9ujuRpIWW9i2npgcCac9LbxE/IzxYBoUrwzB4brV2s3 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wZvsRlCTXyC+U8zjAhrhOXi/tr7dsXH/USQkbywkRednvEsNbM6KhNKpPNsfmS4VjzGkuBV5+EalDxGfOmAFPEqoLudyymk5fkwAsInwMln8ElGpPNbhFXTZw0LVRfxeqz3okabiduvTSjN0YGaUDng/UGVBovYo5yl5LVs2XT6+KdlantL28UjwbP1EtOKu+R4Ce+O9fhcg3wIIUBd8eTHVFVL7MqZr2uboV//8ZnCEj+DFbWVXkQkGlxnSJrG8cDJ0q7oIDpG3D8kqJnzP6bI5v5qaIQ4RjpqT0TVSVc/PH2vTlqjNcoWOxb5vNoiq92VJzQfyP0s9yjmIIRXcLVUQwxcaGRCJT6mKfduMVIm6TgLA473WwX5fPfEoqQ9hjCm40RAoCAPth+Qj4MGVlS6niyeU58+ircSZlXuNhPW5EfcJWig49gcqzAv4PBueKvq/f1pTIG0o7PPQ54BecIudgV9WDouQELIL7qo8ARy2ul9PVtmw1lDcfgKYrqe729HHjcTiL2hrbVL+bf+1r5OH0Moi5p6aa5R01o60veIby+6AwC67v7oK6CinvQ1j/X3Gg2sFvmbp9ftKjmmBKnuvZwcmoPyTmw6+Bx2eqQZungU66QPbLwnGANcYUxnvxt2a2wvu3NZHTkjBvbUDeTAJD4c1fR8gkuRP1HN4DfFYEd+RKp+/BKUa568kSlPMqsHMRAW/2DXxinMJoO+03OG/iJsFxJTJs+vVa0Qy2kIpm2FPmv/bUELtGfz0zhe34LsTPyw1C7N+C0ZcTMa+TvOaCbVYe+0ZPReWKY5QuEJwWTNx14KvuqKeSxiJY4XXDi3lOzCLw8Q0KbANhan5xdwt3XLiWZjHzNxT9ZCRF0i3NjqoTksMqD9/13NGQoZZYPjSFHiJ7R6txkv+LqIL9Y5KUY9axFmDkG6gh7+w4EOmsnN/mlcm3lP9e1lGwjKtjac+TO6jn+cwjFGjb61n5NqTcUqjf3SqNyZSOH1Nd2leWyUKzS98Q3itObKiMRbLQwm53Y4pJ1aV/m7RfjbaIWj+QVqrrmi9qIP0I9wafGtVJ89zw5wfWzDkt9P4lag3hrOeGNlvk1e5om+/XIAG58JTraqf650Emnp0M++o+Uk2CvLW6/PZRjGFCNNshOV7SetCBicHOF/6rKZAMoAmmZZqirq65iyHNIaiqo4K205fMAvXfuwHbTpUGp1Zk0/HQaQ6aY/8s37AkKUzYRB9xQD1SMaxNNlowPAKAY4GEKrU8FV0tUn0GKiSDTd9OnTAHS6QGkIhInLgHbC2DgZUGVypPz02TJOqgEcZg0WX5WTicHeG5xXskYYDkr7GvL8OGYsrM0sgVGJTvEsjn6kcIhhqtfUDWcveHqEZEPMVUhGHT9vWSx5QqsKy/2m5wweMSYLWkzw3kkysht39rb1tziL9uWqiZdcxyqCB1wpX48ienfOBgUhhMS6fLJ8flzTM6EWwMhVZ9sWRZjwtxH5RER6UHmHvAOtvn03X5hyhaf51aimRzJzc57oIgErYkLIFwCaCmuYz/9TDVBXK7Q+fcpEFGTvhMcOuuJIFWPqZt1Nxl/H2qvPEBEtqOrpuA/7f X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6b38e6fa-bb97-4577-b4e7-08dc385ceb33 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:58:11.5109 (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: QOq6FamHOlqI8URcARgOzzLgESA3fnrbKHjYT0ffUHdqKorchV66+SurrX/fhETrX2Jom06//ako6ABS06cSeg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8841 X-Patchwork-Delegate: kuba@kernel.org * remove netdev_sk_get_lowest_dev() from net/core * move get_netdev_for_sock() from net/tls to net/core * update exising users in net/tls/tls_device.c get_netdev_for_sock() is a utility that is used to obtain the net_device structure from a connected socket. Later patches will use this for nvme-tcp DDP and DDP DDGST offloads. Suggested-by: Christoph Hellwig Signed-off-by: Ben Ben-Ishay Signed-off-by: Shai Malin Signed-off-by: Aurelien Aptel --- include/linux/netdevice.h | 5 +++-- net/core/dev.c | 30 +++++++++++++++++------------- net/tls/tls_device.c | 31 +++++++++---------------------- 3 files changed, 29 insertions(+), 37 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index 610d0530c9f9..9dda1a5f3dbb 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3209,8 +3209,9 @@ void init_dummy_netdev(struct net_device *dev); struct net_device *netdev_get_xmit_slave(struct net_device *dev, struct sk_buff *skb, bool all_slaves); -struct net_device *netdev_sk_get_lowest_dev(struct net_device *dev, - struct sock *sk); +struct net_device *get_netdev_for_sock(struct sock *sk, + netdevice_tracker *tracker, + gfp_t gfp); struct net_device *dev_get_by_index(struct net *net, int ifindex); struct net_device *__dev_get_by_index(struct net *net, int ifindex); struct net_device *netdev_get_by_index(struct net *net, int ifindex, diff --git a/net/core/dev.c b/net/core/dev.c index cc9c2eda65ac..e839a6b4fdf3 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -8315,27 +8315,31 @@ static struct net_device *netdev_sk_get_lower_dev(struct net_device *dev, } /** - * netdev_sk_get_lowest_dev - Get the lowest device in chain given device and socket - * @dev: device + * get_netdev_for_sock - Get the lowest device in socket * @sk: the socket + * @tracker: tracking object for the acquired reference + * @gfp: allocation flags for the tracker * - * %NULL is returned if no lower device is found. + * Assumes that the socket is already connected. + * Returns the lower device or %NULL if no lower device is found. */ - -struct net_device *netdev_sk_get_lowest_dev(struct net_device *dev, - struct sock *sk) +struct net_device *get_netdev_for_sock(struct sock *sk, + netdevice_tracker *tracker, + gfp_t gfp) { - struct net_device *lower; + struct dst_entry *dst = sk_dst_get(sk); + struct net_device *dev, *lower; - lower = netdev_sk_get_lower_dev(dev, sk); - while (lower) { + if (unlikely(!dst)) + return NULL; + dev = dst->dev; + while ((lower = netdev_sk_get_lower_dev(dev, sk))) dev = lower; - lower = netdev_sk_get_lower_dev(dev, sk); - } - + netdev_hold(dev, tracker, gfp); + dst_release(dst); return dev; } -EXPORT_SYMBOL(netdev_sk_get_lowest_dev); +EXPORT_SYMBOL_GPL(get_netdev_for_sock); static void netdev_adjacent_add_links(struct net_device *dev) { diff --git a/net/tls/tls_device.c b/net/tls/tls_device.c index bf8ed36b1ad6..5868daf36ae2 100644 --- a/net/tls/tls_device.c +++ b/net/tls/tls_device.c @@ -119,22 +119,6 @@ static void tls_device_queue_ctx_destruction(struct tls_context *ctx) tls_device_free_ctx(ctx); } -/* We assume that the socket is already connected */ -static struct net_device *get_netdev_for_sock(struct sock *sk) -{ - struct dst_entry *dst = sk_dst_get(sk); - struct net_device *netdev = NULL; - - if (likely(dst)) { - netdev = netdev_sk_get_lowest_dev(dst->dev, sk); - dev_hold(netdev); - } - - dst_release(dst); - - return netdev; -} - static void destroy_record(struct tls_record_info *record) { int i; @@ -1063,6 +1047,7 @@ int tls_set_device_offload(struct sock *sk) struct tls_offload_context_tx *offload_ctx; const struct tls_cipher_desc *cipher_desc; struct tls_crypto_info *crypto_info; + netdevice_tracker netdev_tracker; struct tls_prot_info *prot; struct net_device *netdev; struct tls_context *ctx; @@ -1076,7 +1061,7 @@ int tls_set_device_offload(struct sock *sk) if (ctx->priv_ctx_tx) return -EEXIST; - netdev = get_netdev_for_sock(sk); + netdev = get_netdev_for_sock(sk, &netdev_tracker, GFP_KERNEL); if (!netdev) { pr_err_ratelimited("%s: netdev not found\n", __func__); return -EINVAL; @@ -1172,7 +1157,7 @@ int tls_set_device_offload(struct sock *sk) * by the netdev's xmit function. */ smp_store_release(&sk->sk_validate_xmit_skb, tls_validate_xmit_skb); - dev_put(netdev); + netdev_put(netdev, &netdev_tracker); return 0; @@ -1186,7 +1171,7 @@ int tls_set_device_offload(struct sock *sk) free_marker_record: kfree(start_marker_record); release_netdev: - dev_put(netdev); + netdev_put(netdev, &netdev_tracker); return rc; } @@ -1194,13 +1179,15 @@ int tls_set_device_offload_rx(struct sock *sk, struct tls_context *ctx) { struct tls12_crypto_info_aes_gcm_128 *info; struct tls_offload_context_rx *context; + netdevice_tracker netdev_tracker; struct net_device *netdev; + int rc = 0; if (ctx->crypto_recv.info.version != TLS_1_2_VERSION) return -EOPNOTSUPP; - netdev = get_netdev_for_sock(sk); + netdev = get_netdev_for_sock(sk, &netdev_tracker, GFP_KERNEL); if (!netdev) { pr_err_ratelimited("%s: netdev not found\n", __func__); return -EINVAL; @@ -1249,7 +1236,7 @@ int tls_set_device_offload_rx(struct sock *sk, struct tls_context *ctx) tls_device_attach(ctx, sk, netdev); up_read(&device_offload_lock); - dev_put(netdev); + netdev_put(netdev, &netdev_tracker); return 0; @@ -1262,7 +1249,7 @@ int tls_set_device_offload_rx(struct sock *sk, struct tls_context *ctx) release_lock: up_read(&device_offload_lock); release_netdev: - dev_put(netdev); + netdev_put(netdev, &netdev_tracker); return rc; } From patchwork Wed Feb 28 12:57:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575446 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2041.outbound.protection.outlook.com [40.107.96.41]) (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 ED3F3149E01 for ; Wed, 28 Feb 2024 12:58:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125100; cv=fail; b=KXq4HwWw4AnokeBZM6hTkvMnAD6l9iDZwbXY8TyEW75wTcw9pTj7+ZZRvfL7PQJPqqKx7KQBSW0Z7eHKDNs/shoDGDp3wx9ygaJU5zMWPP3KWoErEtLx6Fu3qjsYMXhYZNvoA6h/fzWqpk3sVbMXCcvQZxVOYwvGrcWY801GH30= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125100; c=relaxed/simple; bh=9tGU8X+JkvhbkTP/biDJU8ya130vLcLhUtCuKWpXGTI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=IAtzkAYIhKyyp30wfNZVe7MmKl09ON8j/ZwLhhe6BmfBkjvpmM+v9slvFq88WRGBdSMSL3beGHrNeSi46yySlHAZP3R4V3485rvcfvXfP6+z6xSyEFyUrTBDbqIurgtzGxOJDn5j481uz26sy0oswgg68qVWVU1fpK/9W57N5Ns= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=VrCDCPMe; arc=fail smtp.client-ip=40.107.96.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="VrCDCPMe" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=EvoQRN+NjFD8sBvjA6zSeKKrUjrmdy7ckve3PDYLD9vOih/MoQFRZeQYD0MBTnX3Tv3ko96AjJo0TLMff9RmRbbQMN9pPXlOCBJWtMrBDP24vcvQvLy5TOywfG26Erza0zFpXZ5DpuasifcWrqQbFMEEt2e5ddeZTClm6ZBBxd7wEdAkuHoGaMURJ/xNMSbg5tq3tubAOjJbcZ+WUq8lTaZXpJlfipiyJWyZoCbNDliQiyOhvOKscD21exOErgZZI0lB2DyPNi22MlThBMudq2vnfQyqknfVkQwOuhaC3P62KtEwatKK4yuuSB+e0mFoBDxNzVSjnEs2j38+K5Ivvg== 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=qRaE5L8tLG0Ght7+qSojeQ7SJQ7+295gvVxa5bX21Jg=; b=BhFaaqNULG31LPjikMiEWR7Kx6Ct/A5/VVyK3a3sRx1zusGy0U6ZHdH9SdKa/tQ/WQi87dqc7FgBrAKjJhVw4Huli1p/+GXDg2qT+qRKCFYvAz4aaHJf3xbf0AvqCA8H8QgbAdd1hsoTebFJKD/s9OoR0gkX0Gw7sHVcPCEjAkoJKD1/StHU34s/gN9QDSGW5elxs70l6CSft+pWlMh92aQ7UeKeBLJoOoCJgNLLMrli9UYlQTJsTUaFnacR+aYFUUaByx0oM9vA3T58/deY/pfzxEUHlRKpKbz7ehWJX1acSLjDe1QzfvrmDfbWGtw1QKhZaPaSVle6UnYljhxm6g== 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=qRaE5L8tLG0Ght7+qSojeQ7SJQ7+295gvVxa5bX21Jg=; b=VrCDCPMegUZKVhdcjk/Ndne24UF/HYJp+T8m+zYHG/Rv7fF3xNb369eYPmsyt+VgXhmtLXMqLFV2xgBOYkWi37j7IwgQIx2g5bjUV9uw+xxg+A9usN3egfVKAUiR77wdDOBAkixYW+/Q+qGZPi7d0UZUoTf2rDKv56nqf1x/lOCZ0gfb9cdV4TKj3flpDtZLHhOcoQjvslAnJ0mEVit6tE2pQ1VQ1z7CCDtBgPq3G6Q39N95OOp9cYrk3uX8ZLasb6MGxS0fY+pqCbEZGCcXsnle8nkx8KlynxXxjr+YWWNvjaF7o88+6Q1itfYx5aEiKd3LXeITFn85wxv0x1lIwg== 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 SA1PR12MB8841.namprd12.prod.outlook.com (2603:10b6:806:376::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Wed, 28 Feb 2024 12:58:16 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:58:16 +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: Boris Pismenny , aaptel@nvidia.com, aurelien.aptel@gmail.com, smalin@nvidia.com, malin1024@gmail.com, ogerlitz@nvidia.com, yorayz@nvidia.com, galshalom@nvidia.com, mgurtovoy@nvidia.com, brauner@kernel.org Subject: [PATCH v23 05/20] nvme-tcp: Add DDP offload control path Date: Wed, 28 Feb 2024 12:57:18 +0000 Message-Id: <20240228125733.299384-6-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FR4P281CA0439.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:c6::20) 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_|SA1PR12MB8841:EE_ X-MS-Office365-Filtering-Correlation-Id: 21f61243-30dc-4c08-ad5c-08dc385cedde X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 4JrKQzUtCZlwBNFSO1/4shYOalrP2mRDyU7NZZNoVbSY9p9k+r1o+/yats3jtlYCScLZ7GrvYjpPKBFXg6HaXOE+0eYqlScn595hqf+TL5XptpY7PMHMAmxqwF/YgSePpmABj+5Fi0OqrmN1ERTHx4c5rhOm4BPAq/RtZ1NDwlwpe/lbbF+s0vOGlYrbgA0UhQfT3Ht6DgHmpMItDF1MgykQlkFaOfAf8qGzv2C8Oe9wg6+La4U3R1Oif5Y21JZsUW0VR7qYqc87RmDYz9MWefDlIcB39/GFe4KPS8jF8fojFU8cGLEea3Xase0R1uJWWE68pV1EOAwIlqfQ9wQGct3MKsy/dtmb+LoBY1yR28NpPjs+NsSaMvUDEkCIoFnv0lON0QlEWaHfmh2W5BVzRHCOMYDJAUEzZ2X0hAvLks83l0dSAA26r1186Vpt/Rfe0wFcJOhwpB8ZoXfhx2MpbQSOR5Boc9j9nB6fFQvdbmGAfumAWbb4bYIubqIVpAf4leZ242leV8M6Ttgbo3ZJODTn1fLbWHl6whtOvNv9IfLGd572JeX7XirKgXbGz0aV/DvCuvOe3B7x6q0i6v3ooehEoMDmyb1IYRfwg6w6geqP4qJPYhP73WVU36XU2Cn0L1IzvhjQp+1QebNnTn47KA== 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: zTOe68JPl0bcLYhOQuqs6VA0wL21wE4kRsk9ktnBFW6YEH8spt00QFLluauiNqkdU78Cb75qAfFpFbE3h35h3v/Xuiijctn1vLXXE5XNLIH2XU9A1KI5rHA2RL8uF9fv4kEzC/TwEBKp8pK183GVPzlom9tEK1tXiJjViAYv/1vDWexEbfqr0hGL7e8Cl7XVv0KI+59SE9BBJHsrVNY1+e9mBrezAEQbmabZZMrK+tBw64GKyKMgx+Hz4NYib0hb4/6yrjuzM+nARpI+Mkxac50zJfqCClzlmRDGwEKWtuXrb+yxQSmtOF2tPz9W0fEUEk7RnWhNblOt4yRi/oKKckSc6NZdDZkxkZJQf2CptiTVtA0pxvvi/DgIvn+lSvMFlA9tFYqVRz2SMDtld2uDe43Y57E0XO2ywtSvJr7HhQQR2cKiGiONoAtZvyk8cWB+EqlWehtZ9Y6djurjfXfd+aC8JG2w7CerKAw0sLyYZGQiWQWO/LIptwbSx1OARVA65FS+aJxdi9j+QdSBwHX/9yAQGxEl7IRiTNtx2IWxxQ2qpN8TeHS2V37i+WjItFrGZVmsh5Wcbv/zYjW2lHjs0oOkd3wumOEng7PhKA2OrTXfECVnreu9mNPla1UA98607iM5jPR161JUEaJrO8DumZygysNdm9r7v8bXY/sjb4e5O4jgUQEx+nyz1nIS8yPDc/EkKnZqseny+35TpoTsZKBxv/A34jx6rlqh8pwHVPAeHI4F3Vj0H5yi1a8XiEVQtn3K2raCCrMOXDBQwk16HbFI09lKJoRq94vxZWQlImq57vH09E3jZSra3Zgo6W+CMUsjO9G8l0CHte2NLHO4U6OH2xs+FOuZICuBEsrUdqNW3aRWI/t163PuKC5qV/tByQCPNMWVHLIuxTIcfzysa64OT0wfnujSP+2oaLXWscJ/RSpAmM3EludEGSuKyaUJ6hptpNS5Fp/NumTEUVYI0bWUCrM0BBUEoKfGxPJ0oM4d6scf7pw0R1YK3kFllBxjSM+zzrxx0JEO7EhE6U8n+wNpWu0h0Ws4WWsOSOEB0Ou8sAh2VkamKOgw4EP58GOG5NTMUr8Mb0w9tjYEC0Z9jVcIL0lwOOhCRV55TSEj7OFWOVb7bkimdbBy8bfOwZzswa2Y4ibl/rz7DLNcNX3L8X0A/Lfy3/HmaSLT3BCDrUA3l9hz0Id8NHsq/U7rXMTnPlZr3JD4PZNjukK4OgpQHBZiOperp63rt25kLz9UdW2peyDrMt4K9PleJewDsHXYQtHGLKYA5wZ8/bIXzwPvAdSF7jYlE6Jg5pQqatxWvyg/AOpMA6ntAQyv6ydvhyNdyaBKmiIkiqCPa8p0MPmN6LrsHwh0tGWhv4xcixG3HwgloWoXnDr8wjQRdqgrzIQCNMN5jOdFhOGQJQGsw7UMeiFC1ZvIn6SXUu+xLhBTm/iqm9QmVTF37vkXiJjd5krMK/kJUJRQZEvwdzSEs4x+4lP5MsdGJ7r8drGiVpwJHoy7ByqSN2UgntBp6IzAf2fTMGR/apXUAofFWK6nTdhtf66Xh9XEVeIMsKDiKATVMUD+XoLEWNoyhH3ZEU9HUKFn X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21f61243-30dc-4c08-ad5c-08dc385cedde X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:58:15.9796 (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: xIwwfXIuQL+Oa9Xw/lDivLuZ0tvQiIYNtfdGwBz9kv6+hkbuijUcdGDXdwqpEhKVx9e1z2m1tthZgjPUAv2NsA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8841 From: Boris Pismenny This commit introduces direct data placement offload to NVME TCP. There is a context per queue, which is established after the handshake using the sk_add/del NDOs. Additionally, a resynchronization routine is used to assist hardware recovery from TCP OOO, and continue the offload. Resynchronization operates as follows: 1. TCP OOO causes the NIC HW to stop the offload 2. NIC HW identifies a PDU header at some TCP sequence number, and asks NVMe-TCP to confirm it. This request is delivered from the NIC driver to NVMe-TCP by first finding the socket for the packet that triggered the request, and then finding the nvme_tcp_queue that is used by this routine. Finally, the request is recorded in the nvme_tcp_queue. 3. When NVMe-TCP observes the requested TCP sequence, it will compare it with the PDU header TCP sequence, and report the result to the NIC driver (resync), which will update the HW, and resume offload when all is successful. Some HW implementation such as ConnectX-7 assume linear CCID (0...N-1 for queue of size N) where the linux nvme driver uses part of the 16 bit CCID for generation counter. To address that, we use the existing quirk in the nvme layer when the HW driver advertises if the device is not supports the full 16 bit CCID range. Furthermore, we let the offloading driver advertise what is the max hw sectors/segments via ulp_ddp_limits. A follow-up patch introduces the data-path changes required for this offload. Socket operations need a netdev reference. This reference is dropped on NETDEV_GOING_DOWN events to allow the device to go down in a follow-up patch. Signed-off-by: Boris Pismenny Signed-off-by: Ben Ben-Ishay Signed-off-by: Or Gerlitz Signed-off-by: Yoray Zack Signed-off-by: Shai Malin Signed-off-by: Aurelien Aptel Signed-off-by: Max Gurtovoy Reviewed-by: Chaitanya Kulkarni Reviewed-by: Max Gurtovoy --- drivers/nvme/host/tcp.c | 265 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 252 insertions(+), 13 deletions(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index a6d596e05602..86a9ad9f679b 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -21,6 +21,10 @@ #include #include +#ifdef CONFIG_ULP_DDP +#include +#endif + #include "nvme.h" #include "fabrics.h" @@ -46,6 +50,16 @@ MODULE_PARM_DESC(tls_handshake_timeout, "nvme TLS handshake timeout in seconds (default 10)"); #endif +#ifdef CONFIG_ULP_DDP +/* NVMeTCP direct data placement and data digest offload will not + * happen if this parameter false (default), regardless of what the + * underlying netdev capabilities are. + */ +static bool ddp_offload; +module_param(ddp_offload, bool, 0644); +MODULE_PARM_DESC(ddp_offload, "Enable or disable NVMeTCP direct data placement support"); +#endif + #ifdef CONFIG_DEBUG_LOCK_ALLOC /* lockdep can detect a circular dependency of the form * sk_lock -> mmap_lock (page fault) -> fs locks -> sk_lock @@ -119,6 +133,7 @@ enum nvme_tcp_queue_flags { NVME_TCP_Q_ALLOCATED = 0, NVME_TCP_Q_LIVE = 1, NVME_TCP_Q_POLLING = 2, + NVME_TCP_Q_OFF_DDP = 3, }; enum nvme_tcp_recv_state { @@ -146,6 +161,18 @@ struct nvme_tcp_queue { size_t ddgst_remaining; unsigned int nr_cqe; +#ifdef CONFIG_ULP_DDP + /* + * resync_tcp_seq is a speculative PDU header tcp seq number (with + * an additional flag in the lower 32 bits) that the HW send to + * the SW, for the SW to verify. + * - The 32 high bits store the seq number + * - The 32 low bits are used as a flag to know if a request + * is pending (ULP_DDP_RESYNC_PENDING). + */ + atomic64_t resync_tcp_seq; +#endif + /* send state */ struct nvme_tcp_request *request; @@ -186,6 +213,13 @@ struct nvme_tcp_ctrl { struct delayed_work connect_work; struct nvme_tcp_request async_req; u32 io_queues[HCTX_MAX_TYPES]; + + struct net_device *ddp_netdev; + netdevice_tracker netdev_tracker; + u32 ddp_threshold; +#ifdef CONFIG_ULP_DDP + struct ulp_ddp_limits ddp_limits; +#endif }; static LIST_HEAD(nvme_tcp_ctrl_list); @@ -297,6 +331,171 @@ static inline size_t nvme_tcp_pdu_last_send(struct nvme_tcp_request *req, return nvme_tcp_pdu_data_left(req) <= len; } +#ifdef CONFIG_ULP_DDP + +static struct net_device * +nvme_tcp_get_ddp_netdev_with_limits(struct nvme_tcp_ctrl *ctrl) +{ + struct net_device *netdev; + int ret; + + if (!ddp_offload) + return NULL; + + /* netdev ref is put in nvme_tcp_stop_admin_queue() */ + netdev = get_netdev_for_sock(ctrl->queues[0].sock->sk, &ctrl->netdev_tracker, GFP_KERNEL); + if (!netdev) { + dev_dbg(ctrl->ctrl.device, "netdev not found\n"); + return NULL; + } + + if (!ulp_ddp_is_cap_active(netdev, ULP_DDP_CAP_NVME_TCP)) + goto err; + + ret = ulp_ddp_get_limits(netdev, &ctrl->ddp_limits, ULP_DDP_NVME); + if (ret) + goto err; + + if (ctrl->ctrl.opts->tls && !ctrl->ddp_limits.tls) + goto err; + + return netdev; +err: + netdev_put(netdev, &ctrl->netdev_tracker); + return NULL; +} + +static bool nvme_tcp_resync_request(struct sock *sk, u32 seq, u32 flags); +static const struct ulp_ddp_ulp_ops nvme_tcp_ddp_ulp_ops = { + .resync_request = nvme_tcp_resync_request, +}; + +static int nvme_tcp_offload_socket(struct nvme_tcp_queue *queue) +{ + struct ulp_ddp_config config = {.type = ULP_DDP_NVME}; + int ret; + + config.nvmeotcp.pfv = NVME_TCP_PFV_1_0; + config.nvmeotcp.cpda = 0; + config.nvmeotcp.dgst = + queue->hdr_digest ? NVME_TCP_HDR_DIGEST_ENABLE : 0; + config.nvmeotcp.dgst |= + queue->data_digest ? NVME_TCP_DATA_DIGEST_ENABLE : 0; + config.nvmeotcp.queue_size = queue->ctrl->ctrl.sqsize + 1; + config.nvmeotcp.queue_id = nvme_tcp_queue_id(queue); + + ret = ulp_ddp_sk_add(queue->ctrl->ddp_netdev, + queue->sock->sk, + &config, + &nvme_tcp_ddp_ulp_ops); + if (ret) + return ret; + + set_bit(NVME_TCP_Q_OFF_DDP, &queue->flags); + + return 0; +} + +static void nvme_tcp_unoffload_socket(struct nvme_tcp_queue *queue) +{ + clear_bit(NVME_TCP_Q_OFF_DDP, &queue->flags); + ulp_ddp_sk_del(queue->ctrl->ddp_netdev, queue->sock->sk); +} + +static void nvme_tcp_ddp_apply_limits(struct nvme_tcp_ctrl *ctrl) +{ + ctrl->ctrl.max_segments = ctrl->ddp_limits.max_ddp_sgl_len; + ctrl->ctrl.max_hw_sectors = + ctrl->ddp_limits.max_ddp_sgl_len << (ilog2(SZ_4K) - SECTOR_SHIFT); + ctrl->ddp_threshold = ctrl->ddp_limits.io_threshold; + + /* offloading HW doesn't support full ccid range, apply the quirk */ + ctrl->ctrl.quirks |= + ctrl->ddp_limits.nvmeotcp.full_ccid_range ? 0 : NVME_QUIRK_SKIP_CID_GEN; +} + +/* In presence of packet drops or network packet reordering, the device may lose + * synchronization between the TCP stream and the L5P framing, and require a + * resync with the kernel's TCP stack. + * + * - NIC HW identifies a PDU header at some TCP sequence number, + * and asks NVMe-TCP to confirm it. + * - When NVMe-TCP observes the requested TCP sequence, it will compare + * it with the PDU header TCP sequence, and report the result to the + * NIC driver + */ +static void nvme_tcp_resync_response(struct nvme_tcp_queue *queue, + struct sk_buff *skb, unsigned int offset) +{ + u64 pdu_seq = TCP_SKB_CB(skb)->seq + offset - queue->pdu_offset; + struct net_device *netdev = queue->ctrl->ddp_netdev; + u64 pdu_val = (pdu_seq << 32) | ULP_DDP_RESYNC_PENDING; + u64 resync_val; + u32 resync_seq; + + resync_val = atomic64_read(&queue->resync_tcp_seq); + /* Lower 32 bit flags. Check validity of the request */ + if ((resync_val & ULP_DDP_RESYNC_PENDING) == 0) + return; + + /* + * Obtain and check requested sequence number: is this PDU header + * before the request? + */ + resync_seq = resync_val >> 32; + if (before(pdu_seq, resync_seq)) + return; + + /* + * The atomic operation guarantees that we don't miss any NIC driver + * resync requests submitted after the above checks. + */ + if (atomic64_cmpxchg(&queue->resync_tcp_seq, pdu_val, + pdu_val & ~ULP_DDP_RESYNC_PENDING) != + atomic64_read(&queue->resync_tcp_seq)) + ulp_ddp_resync(netdev, queue->sock->sk, pdu_seq); +} + +static bool nvme_tcp_resync_request(struct sock *sk, u32 seq, u32 flags) +{ + struct nvme_tcp_queue *queue = sk->sk_user_data; + + /* + * "seq" (TCP seq number) is what the HW assumes is the + * beginning of a PDU. The nvme-tcp layer needs to store the + * number along with the "flags" (ULP_DDP_RESYNC_PENDING) to + * indicate that a request is pending. + */ + atomic64_set(&queue->resync_tcp_seq, (((uint64_t)seq << 32) | flags)); + + return true; +} + +#else + +static struct net_device * +nvme_tcp_get_ddp_netdev_with_limits(struct nvme_tcp_ctrl *ctrl) +{ + return NULL; +} + +static void nvme_tcp_ddp_apply_limits(struct nvme_tcp_ctrl *ctrl) +{} + +static int nvme_tcp_offload_socket(struct nvme_tcp_queue *queue) +{ + return 0; +} + +static void nvme_tcp_unoffload_socket(struct nvme_tcp_queue *queue) +{} + +static void nvme_tcp_resync_response(struct nvme_tcp_queue *queue, + struct sk_buff *skb, unsigned int offset) +{} + +#endif + static void nvme_tcp_init_iter(struct nvme_tcp_request *req, unsigned int dir) { @@ -739,6 +938,9 @@ static int nvme_tcp_recv_pdu(struct nvme_tcp_queue *queue, struct sk_buff *skb, size_t rcv_len = min_t(size_t, *len, queue->pdu_remaining); int ret; + if (test_bit(NVME_TCP_Q_OFF_DDP, &queue->flags)) + nvme_tcp_resync_response(queue, skb, *offset); + ret = skb_copy_bits(skb, *offset, &pdu[queue->pdu_offset], rcv_len); if (unlikely(ret)) @@ -1804,6 +2006,8 @@ static void __nvme_tcp_stop_queue(struct nvme_tcp_queue *queue) kernel_sock_shutdown(queue->sock, SHUT_RDWR); nvme_tcp_restore_sock_ops(queue); cancel_work_sync(&queue->io_work); + if (test_bit(NVME_TCP_Q_OFF_DDP, &queue->flags)) + nvme_tcp_unoffload_socket(queue); } static void nvme_tcp_stop_queue(struct nvme_ctrl *nctrl, int qid) @@ -1820,6 +2024,20 @@ static void nvme_tcp_stop_queue(struct nvme_ctrl *nctrl, int qid) mutex_unlock(&queue->queue_lock); } +static void nvme_tcp_stop_admin_queue(struct nvme_ctrl *nctrl) +{ + struct nvme_tcp_ctrl *ctrl = to_tcp_ctrl(nctrl); + + nvme_tcp_stop_queue(nctrl, 0); + + /* + * We are called twice by nvme_tcp_teardown_admin_queue() + * Set ddp_netdev to NULL to avoid putting it twice + */ + netdev_put(ctrl->ddp_netdev, &ctrl->netdev_tracker); + ctrl->ddp_netdev = NULL; +} + static void nvme_tcp_setup_sock_ops(struct nvme_tcp_queue *queue) { write_lock_bh(&queue->sock->sk->sk_callback_lock); @@ -1846,19 +2064,37 @@ static int nvme_tcp_start_queue(struct nvme_ctrl *nctrl, int idx) nvme_tcp_init_recv_ctx(queue); nvme_tcp_setup_sock_ops(queue); - if (idx) + if (idx) { ret = nvmf_connect_io_queue(nctrl, idx); - else + if (ret) + goto err; + + if (ctrl->ddp_netdev) { + ret = nvme_tcp_offload_socket(queue); + if (ret) { + dev_info(nctrl->device, + "failed to setup offload on queue %d ret=%d\n", + idx, ret); + } + } + } else { ret = nvmf_connect_admin_queue(nctrl); + if (ret) + goto err; + + ctrl->ddp_netdev = nvme_tcp_get_ddp_netdev_with_limits(ctrl); + if (ctrl->ddp_netdev) + nvme_tcp_ddp_apply_limits(ctrl); - if (!ret) { - set_bit(NVME_TCP_Q_LIVE, &queue->flags); - } else { - if (test_bit(NVME_TCP_Q_ALLOCATED, &queue->flags)) - __nvme_tcp_stop_queue(queue); - dev_err(nctrl->device, - "failed to connect queue: %d ret=%d\n", idx, ret); } + + set_bit(NVME_TCP_Q_LIVE, &queue->flags); + return 0; +err: + if (test_bit(NVME_TCP_Q_ALLOCATED, &queue->flags)) + __nvme_tcp_stop_queue(queue); + dev_err(nctrl->device, + "failed to connect queue: %d ret=%d\n", idx, ret); return ret; } @@ -2069,7 +2305,7 @@ static int nvme_tcp_configure_io_queues(struct nvme_ctrl *ctrl, bool new) static void nvme_tcp_destroy_admin_queue(struct nvme_ctrl *ctrl, bool remove) { - nvme_tcp_stop_queue(ctrl, 0); + nvme_tcp_stop_admin_queue(ctrl); if (remove) nvme_remove_admin_tag_set(ctrl); nvme_tcp_free_admin_queue(ctrl); @@ -2112,7 +2348,7 @@ static int nvme_tcp_configure_admin_queue(struct nvme_ctrl *ctrl, bool new) nvme_quiesce_admin_queue(ctrl); blk_sync_queue(ctrl->admin_q); out_stop_queue: - nvme_tcp_stop_queue(ctrl, 0); + nvme_tcp_stop_admin_queue(ctrl); nvme_cancel_admin_tagset(ctrl); out_cleanup_tagset: if (new) @@ -2127,7 +2363,7 @@ static void nvme_tcp_teardown_admin_queue(struct nvme_ctrl *ctrl, { nvme_quiesce_admin_queue(ctrl); blk_sync_queue(ctrl->admin_q); - nvme_tcp_stop_queue(ctrl, 0); + nvme_tcp_stop_admin_queue(ctrl); nvme_cancel_admin_tagset(ctrl); if (remove) nvme_unquiesce_admin_queue(ctrl); @@ -2419,7 +2655,10 @@ static void nvme_tcp_complete_timed_out(struct request *rq) struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq); struct nvme_ctrl *ctrl = &req->queue->ctrl->ctrl; - nvme_tcp_stop_queue(ctrl, nvme_tcp_queue_id(req->queue)); + if (nvme_tcp_admin_queue(req->queue)) + nvme_tcp_stop_admin_queue(ctrl); + else + nvme_tcp_stop_queue(ctrl, nvme_tcp_queue_id(req->queue)); nvmf_complete_timed_out_request(rq); } From patchwork Wed Feb 28 12:57:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575447 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2085.outbound.protection.outlook.com [40.107.96.85]) (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 F017414831E for ; Wed, 28 Feb 2024 12:58:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.85 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125104; cv=fail; b=jUHVanRgda9wFDkHi7Z+1ZDHBC796xtVG/xkY6FfRN9SExLgy7Zv5yN2edRXQJ5rNEPfS3w3kzimkqmzUzRt7qlySdIvtdcPTLuwoCs18g0EmhkQiXb/WADmIRPQEUqETCNZYBui1ZZoPTSMxlExqopFSMJHpLuDbAu8fww0yfw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125104; c=relaxed/simple; bh=ptyiAxTp40aWmX7G0+W96ImxZAoDnZqHWpMMS1Nb1+M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=fJqTCcCLLyD9Sn/2ppof7GdEYbnzccWr2aGrFUcpMhwmUbXrJfcS9ya3SyHZg9MPL1mHKorI7QH8uPOgofsYGHdxkR0SbQbcfFwnU0WhkZxYusc1TGimGKOFYm7wxndsLj4fjuSMcqbPqhknNMz7UZprfaM+E8ifMIz3W6TeQlI= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=CKvw7jdY; arc=fail smtp.client-ip=40.107.96.85 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="CKvw7jdY" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m/qf8qqcXub4RLn8ksSxVRn8BKaIaN4fGULAMjUlF1ylt2nyYzLafr0FZ9LAhirFEMojCCAdmldqE4c24TlWbI8d5vVFeQ3uLfp/+jAeN9JT3fk1T1Pbz4KXoO6DUgJZv/A9qBo4Mgk0upzaJRojA1Fu5O6gzrjF+dMlyBwTNHamuEorlcDRRgQu7sjxSdjRHjQHLboxr/SztcrJa/aIeJikBXRgLEoiFyroHIvnj5845Pj5XnMS37NrQ2COzxe+bCcq/lTarTHPR2wpAIgbBIWKBgySjoYwh4ZXTdB4XlxMe4BhmmqbtzMOXhezLyUHzFDnR1XCpWW4T38yZEp+aw== 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=Ph4u3VPfStZG2Hoxuob/umOC9c4fCOgcYeVo8bJ7QTI=; b=UCEW9cfWufsO2QUqYk4f/UDGLYbCFUgVeVL5CPSEU4T9O6Sge14SAWpCNfuw3yLo6TZwu2T+BY5r1JZjpDM8PyUMi2lE8RxRWNLwLri+Add62/tc6F/EDXyF/9l12PFBzCka0mE/fuN0+jHqJXL2U+vvJNoYItMeaxEbg83DMKqrZaT0QdzOzXbSqIBRXkyMGf8L6Z2/61MZWH2qJ7TblTGpwVLMbtLRVjGpSeL8zhXwpPQbu3W3AStTGVuEafdj226FJhzkq3EQtbgNhr/MrRD+xzM2rhKB8vJ3XieUeg/yDAqEwvEmZPOe8/9EIksJdl3Tw+D8/CIx65AuekVNig== 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=Ph4u3VPfStZG2Hoxuob/umOC9c4fCOgcYeVo8bJ7QTI=; b=CKvw7jdYSTKwPVdwUUTYSQgpKgytpahXdpy9TP3SMWPJYcaxz5bAjYXp9hPbYLdcXbk76RBHoLjzgK7CJElJgLJwH4ohnZEBPCeOlnHiW0KK5tUyXcLjoEps6VhBkQICYcrGb6u27FP7k92FaYbc+kU3/T2kxt0+b8Ix0ez2EhW6bt8B3RIYGvaoKJ/1CXKkgz2Qr+FcolH9xybMmBOY41GVvM2m6iVtu+2ViS9ZUuvyXoN5FWSXJkA11hj4wKTPgvBwDOV2M8Rp5inY9FSjaS69d15JhKwf7xtX1sAMxohOtumFHgzAikTx6FW1TRUPrN8Bl/wLBH4fe5TyIIOPwA== 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 SA1PR12MB8841.namprd12.prod.outlook.com (2603:10b6:806:376::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Wed, 28 Feb 2024 12:58:20 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:58:20 +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: Boris Pismenny , aaptel@nvidia.com, aurelien.aptel@gmail.com, smalin@nvidia.com, malin1024@gmail.com, ogerlitz@nvidia.com, yorayz@nvidia.com, galshalom@nvidia.com, mgurtovoy@nvidia.com Subject: [PATCH v23 06/20] nvme-tcp: Add DDP data-path Date: Wed, 28 Feb 2024 12:57:19 +0000 Message-Id: <20240228125733.299384-7-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FR4P281CA0327.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:eb::11) 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_|SA1PR12MB8841:EE_ X-MS-Office365-Filtering-Correlation-Id: 400e71a1-cb66-427f-e010-08dc385cf05d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9B7iDORmyCUHM4MbZt2x2XqNsAqfbbRCpyQ74PcEptYj6as4NdzKenv7jU4RGqMfQl3e47aIQ3ig81T8xlbIiFT4h74hLwpAtcoW1NOpwZNr67teytSlvQlQ7X+AE7KfBQ+ADcZowcxiVPAOSKeAvHtxkc0d83BsmpfkayI/zFSIFaNHSQM9X+BeQduVrYCsBTM5B84n1tqpjvSdUFG1OVJGOATfnlufenGYdtk1vmZsXoiPQIW+s4MZjPrFVSrTaIkr9zoliLe1G+YsAO4J4Z1bmumBY36sOXFyeT4BYa2Nysj4rqQEHr0OCzNjb74jrAnFaY75JfvBWsaI3SebO5e2Kda2LKMp+lMBz9kPM9v3mwuYr2S0O+2QFqcfQ+XB5Eo2XZiUvk4PkUObQXqi2Z9DPzMUq2x6N3g68p6jch48GUdlHZkVPtVpunYeQqPlIQm7L2C+ZRPLsLUuqJYfpN/TMYbLAQqSso4k+ezCBloBIIxBoTZZ3CTqE/Di9JyBeFwdXqbrU4i7ZvRsUGxtxRmL3hVU2eU3zKCmX+GvaVQ2AXlg0u3prj9hePxq707S7pkC97HQ8OnGMYSDxCFkgMa/L+XdltsUP3Na3eJ6VgcU8d3At8d7pDKuYCQkRzig 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: +RwkT2koFUktHL8Eo1TplB/6/AB3iPZqHDxv36aPUXYy22Em6tRcBv8TetTGZxEPFjKtL2BiMuECS0wolCJMfiJyVlSc7GegzjSVQRHmm6lDO3fl8zEkmvAb5DlMkxgrZingijPHAFoABV/TVgLiwdb/MQ9JpQz/q74GVtqJAXEzVEHlPfWVXLegCzoTKQh9yIjD3k8BZra26O3+3lMLPU7Jg1HSweLhqIMoYJv785/F2fDHVBcIqGqr7y9/+M77U7fCrzvi9GYINNHoogc3PncrKoxqj0IXszmSOyeMiu6X2OVCOhPJiGcwrguvMAUe3YwFBKy5pwhDzDmlY5VyOiO4p6SL2HxYCucqCU7jcOV7BY/U3K0pYx3RzSR2I8c++W/W2CsYJoW3+j4GfAhLcONYjyuTZ0tzxb3eCRARSiwoG8fKxZKtTh0aKGNx3hILP3LuAv2U01Vd/ZGC4N2+Br48ZiUpSnnDSG7DT1rLlqVOr52QnwKrKDyHwhusL7MN7e2kdLg1mpcQotQa3sjraCCUjVbvJjfqujg9AjnU9UiBorn5EO73nMImuqcZTlRU9LJBLUAtVvJwcw28W/SsCf6i1S4V3AaWTiGPM+zHOu4K0PLFvbivAz9lPh0UhVX16ADIWglM4K66Q524HC+79ELS+3Ghj83v3TZhPnntH/B4GlGqGm8wXHmTMh32j9kCNlocHSrs+opDWtUVOzNI3sZmamysZ8CrRAwPkVH1SfkRNK6HkTu1BYOUgYp4XUY/ZXGLdP3pye6eoSjaaUfo7vyXqFS6O3f78CqWwAGBl8AjgNgGD3YHfM2tlVPZfhVJNDsHLsy53uJRZn/8kU7FjatMVlyUkKoTtijanb/b+N0/O6RpprEYkBH8kBdbYkfftOivu529VTnNbz+e7H7Dldr5w3IO0JSsffP8iMm5Ci8WoHndr5MLikYLiGBnhaGImevndjlS1syr1WcNEU6lW6DWv0UvTfMU2GMdef5WiEfrnB1VNXiOOoUdQRBCcKd3pw6nQ0i9IV4b6trA18ChJDVTGbasvkM+ikun8WX82RO9QJIFWDJjvz8RALyuRgW42k3quGIg37AdGfo6wGYq1HIvVzPPDIOaWdPSV3uy1s6biUo4rKPPIcNOUwCt/a4VbU+TkWGGxl8rZYaUJYiQmTQ/Z59OqBnDg4O7prxLfna0RneguIyNDH2TlbemAC4s/gQtk7/fiHsUZ5GTe0uaubrsEpsCQkBLzgraPmzuAvzodngvEwGr0tAvLQNqp+0pIytFRGWLikcf3aWKithO9mo+TDVd0OtrlvEnVgr1Yd0nJdmp5z9ehKfP9JnReFefqfAPqZSIStG0h7DV6ltI3QdO3fswXGamgHzcyhCErJFR1IL8DkvrYHf7Xec6L42RaG4nIQg+kFGXyiVE2pwMOK89HG9zz8otEVv4SihqhsbkkZOK0X5kJ+iTn9ZgKpLpJqEmmHaMsbzLERLADyguH56Ypf3nsGipmha8v3Ao/rmk2O+hTC7jmCr+FvhvpOiCzHMll03hAANmrlGXKYs/eqtxZ6xQjnBONUOwCIMnH9Legk7Qfa3Dy8ZEvR/LpF0g X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 400e71a1-cb66-427f-e010-08dc385cf05d X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:58:20.1751 (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: 07caNy38IqZ+r2b+B5E9GT/vgCZmj2wJ/OKNu/F7DSP4W77vQ3+qYDrstL08scTnVcoyD6M+8AniTfcs4p0SrA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8841 From: Boris Pismenny Introduce the NVMe-TCP DDP data-path offload. Using this interface, the NIC hardware will scatter TCP payload directly to the BIO pages according to the command_id in the PDU. To maintain the correctness of the network stack, the driver is expected to construct SKBs that point to the BIO pages. The data-path interface contains two routines: setup/teardown. The setup provides the mapping from command_id to the request buffers, while the teardown removes this mapping. For efficiency, we introduce an asynchronous nvme completion, which is split between NVMe-TCP and the NIC driver as follows: NVMe-TCP performs the specific completion, while NIC driver performs the generic mq_blk completion. Signed-off-by: Boris Pismenny Signed-off-by: Ben Ben-Ishay Signed-off-by: Or Gerlitz Signed-off-by: Yoray Zack Signed-off-by: Shai Malin Signed-off-by: Aurelien Aptel Reviewed-by: Chaitanya Kulkarni Reviewed-by: Max Gurtovoy --- drivers/nvme/host/tcp.c | 135 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 130 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 86a9ad9f679b..b7cfe14661d6 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -120,6 +120,10 @@ struct nvme_tcp_request { struct llist_node lentry; __le32 ddgst; + /* ddp async completion */ + __le16 nvme_status; + union nvme_result result; + struct bio *curr_bio; struct iov_iter iter; @@ -127,6 +131,11 @@ struct nvme_tcp_request { size_t offset; size_t data_sent; enum nvme_tcp_send_state state; + +#ifdef CONFIG_ULP_DDP + bool offloaded; + struct ulp_ddp_io ddp; +#endif }; enum nvme_tcp_queue_flags { @@ -333,6 +342,25 @@ static inline size_t nvme_tcp_pdu_last_send(struct nvme_tcp_request *req, #ifdef CONFIG_ULP_DDP +static bool nvme_tcp_is_ddp_offloaded(const struct nvme_tcp_request *req) +{ + return req->offloaded; +} + +static int nvme_tcp_ddp_alloc_sgl(struct nvme_tcp_request *req, struct request *rq) +{ + int ret; + + req->ddp.sg_table.sgl = req->ddp.first_sgl; + ret = sg_alloc_table_chained(&req->ddp.sg_table, + blk_rq_nr_phys_segments(rq), + req->ddp.sg_table.sgl, SG_CHUNK_SIZE); + if (ret) + return -ENOMEM; + req->ddp.nents = blk_rq_map_sg(rq->q, rq, req->ddp.sg_table.sgl); + return 0; +} + static struct net_device * nvme_tcp_get_ddp_netdev_with_limits(struct nvme_tcp_ctrl *ctrl) { @@ -366,10 +394,68 @@ nvme_tcp_get_ddp_netdev_with_limits(struct nvme_tcp_ctrl *ctrl) } static bool nvme_tcp_resync_request(struct sock *sk, u32 seq, u32 flags); +static void nvme_tcp_ddp_teardown_done(void *ddp_ctx); static const struct ulp_ddp_ulp_ops nvme_tcp_ddp_ulp_ops = { .resync_request = nvme_tcp_resync_request, + .ddp_teardown_done = nvme_tcp_ddp_teardown_done, }; +static void nvme_tcp_teardown_ddp(struct nvme_tcp_queue *queue, + struct request *rq) +{ + struct net_device *netdev = queue->ctrl->ddp_netdev; + struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq); + + ulp_ddp_teardown(netdev, queue->sock->sk, &req->ddp, rq); + sg_free_table_chained(&req->ddp.sg_table, SG_CHUNK_SIZE); +} + +static void nvme_tcp_ddp_teardown_done(void *ddp_ctx) +{ + struct request *rq = ddp_ctx; + struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq); + + if (!nvme_try_complete_req(rq, req->nvme_status, req->result)) + nvme_complete_rq(rq); +} + +static void nvme_tcp_setup_ddp(struct nvme_tcp_queue *queue, + struct request *rq) +{ + struct net_device *netdev = queue->ctrl->ddp_netdev; + struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq); + int ret; + + if (rq_data_dir(rq) != READ || + queue->ctrl->ddp_threshold > blk_rq_payload_bytes(rq)) + return; + + /* + * DDP offload is best-effort, errors are ignored. + */ + + req->ddp.command_id = nvme_cid(rq); + ret = nvme_tcp_ddp_alloc_sgl(req, rq); + if (ret) + goto err; + + ret = ulp_ddp_setup(netdev, queue->sock->sk, &req->ddp); + if (ret) { + sg_free_table_chained(&req->ddp.sg_table, SG_CHUNK_SIZE); + goto err; + } + + /* if successful, sg table is freed in nvme_tcp_teardown_ddp() */ + req->offloaded = true; + + return; +err: + WARN_ONCE(ret, "ddp setup failed (queue 0x%x, cid 0x%x, ret=%d)", + nvme_tcp_queue_id(queue), + nvme_cid(rq), + ret); +} + static int nvme_tcp_offload_socket(struct nvme_tcp_queue *queue) { struct ulp_ddp_config config = {.type = ULP_DDP_NVME}; @@ -473,6 +559,11 @@ static bool nvme_tcp_resync_request(struct sock *sk, u32 seq, u32 flags) #else +static bool nvme_tcp_is_ddp_offloaded(const struct nvme_tcp_request *req) +{ + return false; +} + static struct net_device * nvme_tcp_get_ddp_netdev_with_limits(struct nvme_tcp_ctrl *ctrl) { @@ -490,6 +581,14 @@ static int nvme_tcp_offload_socket(struct nvme_tcp_queue *queue) static void nvme_tcp_unoffload_socket(struct nvme_tcp_queue *queue) {} +static void nvme_tcp_setup_ddp(struct nvme_tcp_queue *queue, + struct request *rq) +{} + +static void nvme_tcp_teardown_ddp(struct nvme_tcp_queue *queue, + struct request *rq) +{} + static void nvme_tcp_resync_response(struct nvme_tcp_queue *queue, struct sk_buff *skb, unsigned int offset) {} @@ -765,6 +864,24 @@ static void nvme_tcp_error_recovery(struct nvme_ctrl *ctrl) queue_work(nvme_reset_wq, &to_tcp_ctrl(ctrl)->err_work); } +static void nvme_tcp_complete_request(struct request *rq, + __le16 status, + union nvme_result result, + __u16 command_id) +{ + struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq); + + if (nvme_tcp_is_ddp_offloaded(req)) { + req->nvme_status = status; + req->result = result; + nvme_tcp_teardown_ddp(req->queue, rq); + return; + } + + if (!nvme_try_complete_req(rq, status, result)) + nvme_complete_rq(rq); +} + static int nvme_tcp_process_nvme_cqe(struct nvme_tcp_queue *queue, struct nvme_completion *cqe) { @@ -784,10 +901,9 @@ static int nvme_tcp_process_nvme_cqe(struct nvme_tcp_queue *queue, if (req->status == cpu_to_le16(NVME_SC_SUCCESS)) req->status = cqe->status; - if (!nvme_try_complete_req(rq, req->status, cqe->result)) - nvme_complete_rq(rq); + nvme_tcp_complete_request(rq, req->status, cqe->result, + cqe->command_id); queue->nr_cqe++; - return 0; } @@ -985,10 +1101,13 @@ static int nvme_tcp_recv_pdu(struct nvme_tcp_queue *queue, struct sk_buff *skb, static inline void nvme_tcp_end_request(struct request *rq, u16 status) { + struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq); + struct nvme_tcp_queue *queue = req->queue; + struct nvme_tcp_data_pdu *pdu = (void *)queue->pdu; union nvme_result res = {}; - if (!nvme_try_complete_req(rq, cpu_to_le16(status << 1), res)) - nvme_complete_rq(rq); + nvme_tcp_complete_request(rq, cpu_to_le16(status << 1), res, + pdu->command_id); } static int nvme_tcp_recv_data(struct nvme_tcp_queue *queue, struct sk_buff *skb, @@ -2734,6 +2853,9 @@ static blk_status_t nvme_tcp_setup_cmd_pdu(struct nvme_ns *ns, if (ret) return ret; +#ifdef CONFIG_ULP_DDP + req->offloaded = false; +#endif req->state = NVME_TCP_SEND_CMD_PDU; req->status = cpu_to_le16(NVME_SC_SUCCESS); req->offset = 0; @@ -2772,6 +2894,9 @@ static blk_status_t nvme_tcp_setup_cmd_pdu(struct nvme_ns *ns, return ret; } + if (test_bit(NVME_TCP_Q_OFF_DDP, &queue->flags)) + nvme_tcp_setup_ddp(queue, rq); + return 0; } From patchwork Wed Feb 28 12:57:20 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575448 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2077.outbound.protection.outlook.com [40.107.96.77]) (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 3BA0C149DEC for ; Wed, 28 Feb 2024 12:58:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125112; cv=fail; b=Esf1IHJVqKDKpzYnaqkB2dX7z3r0OMb0TJybu5Nj7wUXOjluc8W6oS/6yRqDpTZMKhgFD4xQv83W3ug+SXQY54FoyT1O/MVmGzMiWM9PF5R9stbdroZFpZGB4V/5C0+TboDvtpx6MRco4kp0bdvrFJjV/BUM0lAhBxoK2wm0U+Q= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125112; c=relaxed/simple; bh=PsLyU4x7dsXA6pVaXwccjfcPAqyvroMDtK+Aqj+iV3M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=YJqmNnrDO1dJUjstS9u6gHYocLRE14L8lK2sReynd81L0k06TC20oUDpOFgFlcC/VwDbKtpFDaf2Rop4tAYbmUQoF6A2eiuJU89vJOcpRKCBKoluRfAoEl7IS12YvjE2gJDGLF46hBRqFFVXCVu4aHbZ0iziu0/I4OESO8fGUes= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=C69d6aPF; arc=fail smtp.client-ip=40.107.96.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="C69d6aPF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cGTkXSlQTpTdWcy+sWnJX5CdyS363n7Toqn1c3pja6T3Cnd0aBVYwD5pLXnaqhuhTjx1x42wYkMI+doDv1bfW+cwDIOKkSbVYSK5QbWKC0gn/yVjUZ+Mt5hmlSKasWk4UqlbDxiwPEglM5nU4rLwqiDIxWBL2wmmJeD0gvT90s29xAa60bQjCuxn6yv36ecwlj/AgM8qIprTgGsk/8jaF44eoBIS/CVmQmKPeBlftXh7CrmPVcwGbJhVvu8w5h720qFx/aBPbZQz2vIBlEBrZsnbPNiSzbBQfk+iue6yC3yklo5BkrHnURaaqnB7+MBN0+cN0lDY0Z/w17u+RndFbg== 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=GbZy5ypvOMWfXq+TYtOLM9WnQXjn/iQB/XiSZBGluoA=; b=Sn6VTHJkpEfVioaoqwfFWlZaSZgvZwCrQiSU5Bl8wGyyhxv6mj5qUW/B69s230i8cfb7AA9/P6bmBVzpg4SlX4GGxRhSGatdY/skAliPzXzIhGdvG77oHd54UmNFrWbTSgByU9dpa7pI1LsXiaeKH8v2heQvY1cau/ROEd3tbRXIo8pOnhnzXNzazYyi8lTReH/jfKN7MHBwukR7y3Ztd08A82mN2IDQDJ4XcX84OAusRY3lPGVJLvObxVaJ5rD+YQ4Ax/vwbn9dfpNcVUhVEujmeyoy9FTCuilAq7Tm/y7A6y/d7fAvVD8BwMWIYTyohtbnlsGAjSNQtLPvZrF8ZA== 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=GbZy5ypvOMWfXq+TYtOLM9WnQXjn/iQB/XiSZBGluoA=; b=C69d6aPF7edPuQJpWr+pj5pDjHEUzPrJRbCRPgiP9KYveSy7grCjeJI23nuXAri447t2M0Jgg2f6v/qCRrcMXz4MdU8pHvjKRAvHVubxfPuvDShmz5JHDzW8shFQBGQogQW9wl+LacUaSzRf1hLYBidyFEv+vI1gKo4Bqt/i8dkaxzgGuNqRfGNPpMlACt+crq+diOKP8rZrRuvEMK2w1xbxnze60bKxzIj0McywadM6/jroIFEtddRg/a1qA4+3g6KLFqmubczG8QbEP44+gvrF/MGxolf8ATlcR8BZNG9z7diRn0+LME6m1ripaeFaix8hiROl/aMGq2AUwjGyDw== 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 SA1PR12MB8841.namprd12.prod.outlook.com (2603:10b6:806:376::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Wed, 28 Feb 2024 12:58:25 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:58:25 +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: Yoray Zack , aaptel@nvidia.com, aurelien.aptel@gmail.com, smalin@nvidia.com, malin1024@gmail.com, ogerlitz@nvidia.com, borisp@nvidia.com, galshalom@nvidia.com, mgurtovoy@nvidia.com Subject: [PATCH v23 07/20] nvme-tcp: RX DDGST offload Date: Wed, 28 Feb 2024 12:57:20 +0000 Message-Id: <20240228125733.299384-8-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FR4P281CA0046.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:cc::9) 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_|SA1PR12MB8841:EE_ X-MS-Office365-Filtering-Correlation-Id: 26b64482-5bf9-45db-90d1-08dc385cf369 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /3wvx+eqvawXDDLTYMyYEn6Lf5VpUEt2nGMsynCVphLyhqGDIh3ZCiw0J7WhX81XZGNq/4bC1nFZmuzeXshmHSDmGWW/VbIsbeHbZGrDri8FS5e4jxmzA87khx0V0Xov6S41OR0myCyGlrZlCqd9GFbLKcpSbt86NzTkgAYsGISwChl+XN1qSVxVzRlLe5ddpB01z/VkSsL3vDsS5AJzGDgHV4/SdG4oD1LwWcF7DwlBEzwanE4UfAc3J3dY+McnrDL5/eBVIm8Q5p/y/pBMoBEpCP8buxgJmtHmzWxu+7u84J9FzbsbtDX6zRENTUhWASJa8bDgQMNHiat9KWemjzV7DGkT4rjQwBk66KyP+gqrUPM12OVIPK1kTCz3PamaFcp0KvsmWanLni1d//+eGa/1vpINfjJpv/qouEMiAgSdaEhbSTUM2qmWcss+1aB+JEvYLf0htAh3otB9A9WOIoxWH6xt3owG1QvY8/IF2ED3mW9Fb4nPc613qK3A8/rv+Sev5n5mBk13NDdXgsBrbAmvKis+pJiL5gNA9eycuimzFD7PQDKhNGSHfcrdbAKF/BY0H/7T9GhJ1PPlGnXy7c36HBDnx2+shS6FUEubEkAQNIBCuwCtZ4y/OSFOzJg4iLqH+KFri1aFyhQMe0WEkA== 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ediq95VLpXvjVdQpxgZJUyRd9QqRKux1tX3vbjULbRpUQynIl9B0ZWn+Ob0VcLRafffZb2vJcLZR3bAQ3q3nYdPQLN/r66p1a5T4sA2zyDOTVVXLpf2khTRK20MDaz73zJ2m9VKxdf+hxO/vqnNqCZcjP0tyr7Z44w01pxA9c3Ytt96YuNcs7fL3XISc3l3oPQi8vLlUTenV+es0lUN/iRz9QGZxtVo0y1dWWTsxLEhtu22VGEJ9gH9S/xechTENUCQ+P9qmCGsNwGwpgH5NyiaSimCIVSahQYQxFwpDbc9sp4uGXJndzg9tBmWhXZE497+w6PLlgNVjgubvX07hNwzmmH7KWWaj8Xj4JOIWCn25+xo8TXk1Z9vlRNGGaVIHo09bQmsJUnVAIm/73aIMctayaIc9NuJiK1gB0JzXRySH0JPELcPY+fqyml1FzNp8Ijqri/CrYmJfiMCKDeS7r00cKB8Q2UDR5mP2ctX5u2vljCzQqBZDM5oVL+ZzNRgKx/OE7tQhtVYcnQMgvvwzQHhqTdJhxLVizGGBVdMoLiCK3UZOYMA5Y/dDl1cqPq0mJTRu3PwAznN5nH3UQg03y7/+7MWey55zIBhC8jhzEiRteqcat+Rj3g03LWqY/IGRrUxTeLHoxq4V5O489fEPjkiTUO83E7OES3Ut5rF+dFznlr7LZfSZ0Obb+OfGLdxF2ScQcl3RNPdd6jSbU9R0oEkTW7F68u+9j+l0zUjh+DyXt8da0VNLsnIqCjSliguEffwlm+vv7eNEzC1FtX2t6oHZW+RzfHTldWo+Pte+N9ow+w2EdUNpo0qL/MQHDAQWszFfnvZuA5RCMJ/o22SOb1gTUZVPPbZmLmfFQ/tcr7ka8RHQdGEgP4TAbGYeXX6R1ouutS3rjtawDqmEYmYDDqhu2szBbx+nOM53EPWPas52x0T1705eyIbnnjPrNT8wT4UOT4RXemEChFPRbw7sWMX0mM7CbJ/KJP5rzdGyfaWrQQJXw55prnRDMBamnU3I+ekNvR8eFbLE3ruy8fmqSrh7CjHTDYheZxAhO5+PUmMZyDQbUp0Tc/N0BmsGES95Y2ZmT8A5LDLhR7kzouF/XxQO5oZ5W95THJt8MZQFkHCZ/GRGlMNGNKs1AKJprMBc4bdVk61GsStplTgOJPT2E2NQfge9BnwvYDSnNvsPMRmT0SG9m1Z1Xo39dtJmonacuhkBBlyY8/7Hdo9nu36xqykAuInfRtcVuI/NkbEF54JNt5PgQWiGxmfQ3hM5/0xbn6m8TVWy14xjvOKZJ6Ey7EUUwQDZAVfQRJYokahN7Rmmo4C5cExgk/LmJc/SzwCCoGCUQCjZTP7H/gk3hx4bpU+o73qp+SOOt1n5aTj5DCA6Hu4iDC2Ng12ljA9/NeLNvfdgc7XhVuQ5fB5MOPCHeczCAHwVkruldB8wa35fkIWf41pikn1rf4/dMhLwxqOvI1uVE6lu/znyFJ3IBr2H6cwAtERNhcBE0Us2wbjQZr/TpIxVU+Pp3eGYKEKSB/HsukKoaRLT/ZQlqTZ1wjJqVnD8e0OU0FU/hEVZJesZiJnif9CM5TQMZMWaQQ/Al07j X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 26b64482-5bf9-45db-90d1-08dc385cf369 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:58:25.3263 (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: rt391SguxA2g79OLQTld6c9VhY2HCeSiD+lNdxWzrorlMn0LcKj58YHV7V00ESzfeanvx+Lieso2jj5nM6QvLg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8841 From: Yoray Zack Enable rx side of DDGST offload when supported. At the end of the capsule, check if all the skb bits are on, and if not recalculate the DDGST in SW and check it. Signed-off-by: Yoray Zack Signed-off-by: Boris Pismenny Signed-off-by: Ben Ben-Ishay Signed-off-by: Or Gerlitz Signed-off-by: Shai Malin Signed-off-by: Aurelien Aptel Reviewed-by: Chaitanya Kulkarni Reviewed-by: Max Gurtovoy Reviewed-by: Sagi Grimberg --- drivers/nvme/host/tcp.c | 96 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 91 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index b7cfe14661d6..2eebd9d2aee5 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -143,6 +143,7 @@ enum nvme_tcp_queue_flags { NVME_TCP_Q_LIVE = 1, NVME_TCP_Q_POLLING = 2, NVME_TCP_Q_OFF_DDP = 3, + NVME_TCP_Q_OFF_DDGST_RX = 4, }; enum nvme_tcp_recv_state { @@ -180,6 +181,7 @@ struct nvme_tcp_queue { * is pending (ULP_DDP_RESYNC_PENDING). */ atomic64_t resync_tcp_seq; + bool ddp_ddgst_valid; #endif /* send state */ @@ -393,6 +395,46 @@ nvme_tcp_get_ddp_netdev_with_limits(struct nvme_tcp_ctrl *ctrl) return NULL; } +static inline bool nvme_tcp_ddp_ddgst_ok(struct nvme_tcp_queue *queue) +{ + return queue->ddp_ddgst_valid; +} + +static inline void nvme_tcp_ddp_ddgst_update(struct nvme_tcp_queue *queue, + struct sk_buff *skb) +{ + if (queue->ddp_ddgst_valid) + queue->ddp_ddgst_valid = skb_is_ulp_crc(skb); +} + +static void nvme_tcp_ddp_ddgst_recalc(struct ahash_request *hash, + struct request *rq, + __le32 *ddgst) +{ + struct nvme_tcp_request *req; + + req = blk_mq_rq_to_pdu(rq); + if (!req->offloaded) { + /* if we have DDGST_RX offload but DDP was skipped + * because it's under the min IO threshold then the + * request won't have an SGL, so we need to make it + * here + */ + if (nvme_tcp_ddp_alloc_sgl(req, rq)) + return; + } + + ahash_request_set_crypt(hash, req->ddp.sg_table.sgl, (u8 *)ddgst, + req->data_len); + crypto_ahash_digest(hash); + if (!req->offloaded) { + /* without DDP, ddp_teardown() won't be called, so + * free the table here + */ + sg_free_table_chained(&req->ddp.sg_table, SG_CHUNK_SIZE); + } +} + static bool nvme_tcp_resync_request(struct sock *sk, u32 seq, u32 flags); static void nvme_tcp_ddp_teardown_done(void *ddp_ctx); static const struct ulp_ddp_ulp_ops nvme_tcp_ddp_ulp_ops = { @@ -478,6 +520,10 @@ static int nvme_tcp_offload_socket(struct nvme_tcp_queue *queue) return ret; set_bit(NVME_TCP_Q_OFF_DDP, &queue->flags); + if (queue->data_digest && + ulp_ddp_is_cap_active(queue->ctrl->ddp_netdev, + ULP_DDP_CAP_NVME_TCP_DDGST_RX)) + set_bit(NVME_TCP_Q_OFF_DDGST_RX, &queue->flags); return 0; } @@ -485,6 +531,7 @@ static int nvme_tcp_offload_socket(struct nvme_tcp_queue *queue) static void nvme_tcp_unoffload_socket(struct nvme_tcp_queue *queue) { clear_bit(NVME_TCP_Q_OFF_DDP, &queue->flags); + clear_bit(NVME_TCP_Q_OFF_DDGST_RX, &queue->flags); ulp_ddp_sk_del(queue->ctrl->ddp_netdev, queue->sock->sk); } @@ -593,6 +640,20 @@ static void nvme_tcp_resync_response(struct nvme_tcp_queue *queue, struct sk_buff *skb, unsigned int offset) {} +static inline bool nvme_tcp_ddp_ddgst_ok(struct nvme_tcp_queue *queue) +{ + return false; +} + +static inline void nvme_tcp_ddp_ddgst_update(struct nvme_tcp_queue *queue, + struct sk_buff *skb) +{} + +static void nvme_tcp_ddp_ddgst_recalc(struct ahash_request *hash, + struct request *rq, + __le32 *ddgst) +{} + #endif static void nvme_tcp_init_iter(struct nvme_tcp_request *req, @@ -853,6 +914,9 @@ static void nvme_tcp_init_recv_ctx(struct nvme_tcp_queue *queue) queue->pdu_offset = 0; queue->data_remaining = -1; queue->ddgst_remaining = 0; +#ifdef CONFIG_ULP_DDP + queue->ddp_ddgst_valid = true; +#endif } static void nvme_tcp_error_recovery(struct nvme_ctrl *ctrl) @@ -1118,6 +1182,9 @@ static int nvme_tcp_recv_data(struct nvme_tcp_queue *queue, struct sk_buff *skb, nvme_cid_to_rq(nvme_tcp_tagset(queue), pdu->command_id); struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq); + if (test_bit(NVME_TCP_Q_OFF_DDGST_RX, &queue->flags)) + nvme_tcp_ddp_ddgst_update(queue, skb); + while (true) { int recv_len, ret; @@ -1146,7 +1213,8 @@ static int nvme_tcp_recv_data(struct nvme_tcp_queue *queue, struct sk_buff *skb, recv_len = min_t(size_t, recv_len, iov_iter_count(&req->iter)); - if (queue->data_digest) + if (queue->data_digest && + !test_bit(NVME_TCP_Q_OFF_DDGST_RX, &queue->flags)) ret = skb_copy_and_hash_datagram_iter(skb, *offset, &req->iter, recv_len, queue->rcv_hash); else @@ -1188,8 +1256,11 @@ static int nvme_tcp_recv_ddgst(struct nvme_tcp_queue *queue, char *ddgst = (char *)&queue->recv_ddgst; size_t recv_len = min_t(size_t, *len, queue->ddgst_remaining); off_t off = NVME_TCP_DIGEST_LENGTH - queue->ddgst_remaining; + struct request *rq; int ret; + if (test_bit(NVME_TCP_Q_OFF_DDGST_RX, &queue->flags)) + nvme_tcp_ddp_ddgst_update(queue, skb); ret = skb_copy_bits(skb, *offset, &ddgst[off], recv_len); if (unlikely(ret)) return ret; @@ -1200,9 +1271,25 @@ static int nvme_tcp_recv_ddgst(struct nvme_tcp_queue *queue, if (queue->ddgst_remaining) return 0; + rq = nvme_cid_to_rq(nvme_tcp_tagset(queue), + pdu->command_id); + + if (test_bit(NVME_TCP_Q_OFF_DDGST_RX, &queue->flags)) { + /* + * If HW successfully offloaded the digest + * verification, we can skip it + */ + if (nvme_tcp_ddp_ddgst_ok(queue)) + goto out; + /* + * Otherwise we have to recalculate and verify the + * digest with the software-fallback + */ + nvme_tcp_ddp_ddgst_recalc(queue->rcv_hash, rq, + &queue->exp_ddgst); + } + if (queue->recv_ddgst != queue->exp_ddgst) { - struct request *rq = nvme_cid_to_rq(nvme_tcp_tagset(queue), - pdu->command_id); struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq); req->status = cpu_to_le16(NVME_SC_DATA_XFER_ERROR); @@ -1213,9 +1300,8 @@ static int nvme_tcp_recv_ddgst(struct nvme_tcp_queue *queue, le32_to_cpu(queue->exp_ddgst)); } +out: if (pdu->hdr.flags & NVME_TCP_F_DATA_SUCCESS) { - struct request *rq = nvme_cid_to_rq(nvme_tcp_tagset(queue), - pdu->command_id); struct nvme_tcp_request *req = blk_mq_rq_to_pdu(rq); nvme_tcp_end_request(rq, le16_to_cpu(req->status)); From patchwork Wed Feb 28 12:57:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575449 Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on2077.outbound.protection.outlook.com [40.107.96.77]) (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 DBB2814AD07 for ; Wed, 28 Feb 2024 12:58:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.96.77 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125114; cv=fail; b=rTzFUCje7mb0TrSSdv6tnlslCSnn3B44rupvuaN1XDuzSw5Usghw2mWn9wS6NX6LwrGtZRCpETssnbMQaPgOm8fVgC3x/2aSbtiXz2UWCl6hstB5Ow2jvsHKuM+X5SRLmF5VbBnjDGSyx4OVl8fax5bzcHTqrkHKXnkQ35L1QQw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125114; c=relaxed/simple; bh=UIhyrw0Jhxy1VMiqqHbkQPD36zev1eOqTuR9cVQLXic=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=lqAMl79SP0Iq9vzKi/4rm3DVoDssSR1tVrS5DiwIjUBOzOwckSuImbKCw0lh9cRhZsMAXQuyrW3YxRRcuFZUL2iae3RwpV/L/Xy4Eals9MiLAHCQUz0gf+My73IpigyzowvNHT52ZEAe0LOxhPjHqCDARfbLCHoA+TVdkDeLePw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=QuxvakRZ; arc=fail smtp.client-ip=40.107.96.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="QuxvakRZ" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cqYKJemmbTDJ3qd2McFuiNNJQNJC6KYPhELp4iRcnY1EPdcwdy/Cid4ZkqstVjNFH1siYvaeuRkiALubU2x48CRyterwoiYUGut92/+cOpZMvsFY6SSoSmcPr598kNuHJeLiGrUn1LCojL7jAlAC+iJqHQ/jPL+XyyCWFi3jHh7Rq++NVEasZ6dp7Z7pkb+Hz3Dcd1MnGGpSNurzICxKofSeiK+9i3FFU1Cd/NvCXDR7ac4T7n4vkIxQkISFyPXXhG6AkznwPw2kRRhTXe9Bw1sxFPp1FVehQCi1FAjOS3eM37qALyFgg8BUo0e+Pi1TsNqZ5gvcmmfpBAruKHXKGg== 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=qOyesJ4qaII7YLOMCFPJsgmod+GLx8e/QcK9Ea0HJdI=; b=eURK8PUn/eTZGSYQc1+XXo61hJHfCjlD6vLcJ8tORZfIC6vlrbL2PtSvQnuY45xQDw8gSi/zGDGslJuDo2uVTlFM7wlW4XqCq+h73RT4nsG/A0grWfY6NrPXEG1QREqCUe1rGFrVDUySwuVnaYvrUg/Ni+YKevnAEYOB34hJNuluMDHD97UC4oAbqMj8a0M94ICrGk7z7eQ14Y7NCm7G6WwROglUAHPIWidf9flsSHzATDmFqxITa2GNJAE7FHmqO0Ieb6itjAYBicuOkPa01fzSL2O2f5XU1qX8k+LH92SkNguu0Nx23v3L/BVegQ8xdXauc2QW4FGn2VwUXnpydg== 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=qOyesJ4qaII7YLOMCFPJsgmod+GLx8e/QcK9Ea0HJdI=; b=QuxvakRZKudeZv5dkDau8YkmXvE12GCJ72H2Kyb9vHtT/HPN+gckvpVwkthF9As2kxycvhk0jWlx1jz0PprfFmkq2oBYJ0KrG5PIOsC6XVTtsMSkimyILSX683rRLLDCxpKyPIX+5m3TWsAVkFp319La9EfqvHc/Bve/CYxfoDBI+zrTf20JWohy0OLDEdWFr1zeAu2GyUZPxaP4aamJF2yhonHyeOhUqTDupqPn8INqlJazMTeO8plfjMMWhm6g6INKxYVi/Qwdw7IoKxAkKUzVliKOod+uCy9jSc9NOv6RIb2W5MXmQdFSgqLkwk4lRjgGFhyNshV0xjp+YMqxlQ== 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 SA1PR12MB8841.namprd12.prod.outlook.com (2603:10b6:806:376::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.34; Wed, 28 Feb 2024 12:58:30 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:58:30 +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: Or Gerlitz , aaptel@nvidia.com, aurelien.aptel@gmail.com, smalin@nvidia.com, malin1024@gmail.com, yorayz@nvidia.com, borisp@nvidia.com, galshalom@nvidia.com, mgurtovoy@nvidia.com Subject: [PATCH v23 08/20] nvme-tcp: Deal with netdevice DOWN events Date: Wed, 28 Feb 2024 12:57:21 +0000 Message-Id: <20240228125733.299384-9-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FRYP281CA0008.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10::18) 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_|SA1PR12MB8841:EE_ X-MS-Office365-Filtering-Correlation-Id: 395f646a-66ea-4388-1961-08dc385cf62b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Ig+HhKvonF+4OM8m6uLuuA6NiM7UL/F0UoIrX8Tq9YEtYqCEppT9e8Zbj2CZu8vg1biO9Fowgn9GkeqZzBCoIeYirSKLLEdPOg03TvW88o28Rb3lcdCP+Ah6ODbo2EpgLt6C6cr3K7R/dcBbA6YWAHjeKZqeIr0cC9hvEbOhEYlL1lv0rCLAlA++9ohpuORruScSPv9B4aB/6r3ihdFMc/lpaUUJ4IQwEuQlxoy/5ySBOifUcTL8ohWc9kvKUUJRROhwbShUgm3J7GTM5IrLkuPdlWh9IxYyj+u6SDXn6Je3vzNa1iQP7T2M3b3uzjjVCIz7L3rb2uLubalbm+flQAtskNlAuVDa4k25mUGwfZWu4p+TxsBeosBHfw3mrfzyB/vBe46YJpvuJWdAv3MJEokSZzyoIphoSzSgfduuTsiVOMv3TKJ4UKnVaAvBA5tGuY4noLmbXSvOssYZPDzmkMdYP7ij8ezhzsinCji4wbQy6nFV7BJP8t5KBNPSTUkzAj46X3LPXB2kB8YVToRks1JD78gIkN3c0GoRchpMrfcP40CGXBfgQllDcTxVSIvebgNUOQO6mP5+VUaryJL0oueeawMCZ3qbz0F/6dQthPwwT4i9S0RM1851BHkUaTpt 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: siPwP3EYUmPg8Jtho8DB4f/B8/AWe7xV8RADRotXk1gnkrsiSQm+zbSpbjZp+LYuO63IB4x+J1XIpE0KMz5oy3/T+7G7oHWHdcGNEtbR+re2l7sDPmamWVC8+MOfwFu2evrJpF6JOVNYoF1rOe80cBnouo79QQOrOWFKegcPFmwUXgltrF0fHbXBQ3f4dCjCXpfeikqX2c2TJ8J2ytmetvUB3N0w0J/VGwPGI2t73lzOggbQT6IMJANS/oPKQzqnyQfnepy9znBWkAZ3OmoB4V43jOlX4AlkujmgDneTT+2hdHmIbI7plp5EfNwYHiXxoBIyk2EpChPrYIZrk0sE+k40VAiin6YWU58DuyxREfzULrqlohYQDrA3IaX2Gy4da/ryNmTsdZ5OtKRys+Hql5jmc7mExW9yKK4p538t7YB/IAeE2YlOzPujsiBm4NPk4P614SZx1BWDgFTxtCslW4Y2+mnXxIVDBPT88aimpH6W18cSbIPJXJfpd16Ra/NyH3WTgRGqyVmMiU8hj32rjads4yPXx9m+Rmj9fTrL2KCsmyPwClSDqTBkyzaqAumtvUX3WRkfjGfHdj935HM4vTiMZduWZQ0I0q1EqXgKc+5tmJjSlKfUoS67Ejc0ZnIyKnB6e/4QLO5J9v4ZhE+SlzpeCl6NHucRTFCiLrUtw2TFHrFpx/uWhNP5DC4QFcx+yccoKxfiliptPFWinZ/AbMowb533s9VnerrZ728aOqYllej4gtrx0RiewppW1X3EeKFDYRTXqoQyAVYpYN2zcdY4MriipFwhqw2eAFwWNZEOZwj3AprcbNWChxBwJ6F1lrLwC+HAbkOxmSkcl+QjN8vxbXD0T/GNBU7WbzASGyUvXpzdEE2Ke6CBvZ2keVpqtF7dXByggTV76fK2Xm3ltgZX9ziIOEiiDn8CSeBmbpC7F6NxJU2EaD6raKLDx0cRFOL1yXDYJ25g+aLWzQ/CpMSx4nNUb7u77UFy/zl6PRwhvqczaR37Dt6nqcNk9yFZca1ZdM0NNr+nGs2OlSU/X7Pzz1XJYMQ/mkHUGKrOBEBAiqlBd6RCRi5KvWoYlx2bd9lChF3zb6v6pnyCv4/NsgK/FLybi6IxLLYT9ogxBT21cS1sSXSXAL//Y3m7Wx0kxvkD+BxxVH4fWIzx/QGvTqJzmo99HjhFXwH2Upg7PwmLPlER0Q1gGy+KthH2/tdLvUCJLC1MYD20Q3DOlmVfzp6saaA/J8iVrq2aEl4lroFURi3MvVqAzVu4oRhWsAGjvkCIM7UotBlC4fkwWYMT7B/tnzGe9ke+r94QSx8koCIS5WJYQJ7qrqgzFnSz2zbRq3zP6dYXc/TAvGe/dKBJ1kc1DfTtb8D3GleX3+sbHBntPA9rB8Uag7ZB+jW6JxaU9488QR10uiooysSSbluPbjfE9LJRj67b70PjkbqrdXdfdqcEaVJfAmmhE9s1j/eu6nB+QZD3OEjnLT6bobEX9+VNWUcxlWN4cW0wlXCqqxhUHRBCPkagZEE/495enkF/3CQ3a3Y/P5IFtMgxhkq1sNkvSX/2m08n9BaQyJU9nRh/4AJNvgLKR9E4F7TnLiNE X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 395f646a-66ea-4388-1961-08dc385cf62b X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:58:29.9075 (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: yNfreosOBuFwqPSuKqMiDGFxC/3SYXNdHJqAlzOaWaveB55E+7SEfk97+VjRw2fAYZIKj9pP4yLXX6HeqVFA8w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA1PR12MB8841 From: Or Gerlitz For ddp setup/teardown and resync, the offloading logic uses HW resources at the NIC driver such as SQ and CQ. These resources are destroyed when the netdevice does down and hence we must stop using them before the NIC driver destroys them. Use netdevice notifier for that matter -- offloaded connections are stopped before the stack continues to call the NIC driver close ndo. We use the existing recovery flow which has the advantage of resuming the offload once the connection is re-set. This also buys us proper handling for the UNREGISTER event b/c our offloading starts in the UP state, and down is always there between up to unregister. Signed-off-by: Or Gerlitz Signed-off-by: Boris Pismenny Signed-off-by: Ben Ben-Ishay Signed-off-by: Yoray Zack Signed-off-by: Shai Malin Signed-off-by: Aurelien Aptel Reviewed-by: Chaitanya Kulkarni Reviewed-by: Sagi Grimberg --- drivers/nvme/host/tcp.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 2eebd9d2aee5..115c14398c2c 100644 --- a/drivers/nvme/host/tcp.c +++ b/drivers/nvme/host/tcp.c @@ -235,6 +235,7 @@ struct nvme_tcp_ctrl { static LIST_HEAD(nvme_tcp_ctrl_list); static DEFINE_MUTEX(nvme_tcp_ctrl_mutex); +static struct notifier_block nvme_tcp_netdevice_nb; static struct workqueue_struct *nvme_tcp_wq; static const struct blk_mq_ops nvme_tcp_mq_ops; static const struct blk_mq_ops nvme_tcp_admin_mq_ops; @@ -3225,6 +3226,32 @@ static struct nvme_ctrl *nvme_tcp_create_ctrl(struct device *dev, return ERR_PTR(ret); } +static int nvme_tcp_netdev_event(struct notifier_block *this, + unsigned long event, void *ptr) +{ +#ifdef CONFIG_ULP_DDP + struct net_device *ndev = netdev_notifier_info_to_dev(ptr); + struct nvme_tcp_ctrl *ctrl; + + if (event != NETDEV_GOING_DOWN) + return NOTIFY_DONE; + + mutex_lock(&nvme_tcp_ctrl_mutex); + list_for_each_entry(ctrl, &nvme_tcp_ctrl_list, list) { + if (ndev == ctrl->ddp_netdev) + nvme_tcp_error_recovery(&ctrl->ctrl); + } + mutex_unlock(&nvme_tcp_ctrl_mutex); + flush_workqueue(nvme_reset_wq); + /* + * The associated controllers teardown has completed, + * ddp contexts were also torn down so we should be + * safe to continue... + */ +#endif + return NOTIFY_DONE; +} + static struct nvmf_transport_ops nvme_tcp_transport = { .name = "tcp", .module = THIS_MODULE, @@ -3240,6 +3267,8 @@ static struct nvmf_transport_ops nvme_tcp_transport = { static int __init nvme_tcp_init_module(void) { + int ret; + BUILD_BUG_ON(sizeof(struct nvme_tcp_hdr) != 8); BUILD_BUG_ON(sizeof(struct nvme_tcp_cmd_pdu) != 72); BUILD_BUG_ON(sizeof(struct nvme_tcp_data_pdu) != 24); @@ -3254,8 +3283,19 @@ static int __init nvme_tcp_init_module(void) if (!nvme_tcp_wq) return -ENOMEM; + nvme_tcp_netdevice_nb.notifier_call = nvme_tcp_netdev_event; + ret = register_netdevice_notifier(&nvme_tcp_netdevice_nb); + if (ret) { + pr_err("failed to register netdev notifier\n"); + goto out_free_workqueue; + } + nvmf_register_transport(&nvme_tcp_transport); return 0; + +out_free_workqueue: + destroy_workqueue(nvme_tcp_wq); + return ret; } static void __exit nvme_tcp_cleanup_module(void) @@ -3263,6 +3303,7 @@ static void __exit nvme_tcp_cleanup_module(void) struct nvme_tcp_ctrl *ctrl; nvmf_unregister_transport(&nvme_tcp_transport); + unregister_netdevice_notifier(&nvme_tcp_netdevice_nb); mutex_lock(&nvme_tcp_ctrl_mutex); list_for_each_entry(ctrl, &nvme_tcp_ctrl_list, list) From patchwork Wed Feb 28 12:57:22 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575450 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) (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 789E51487DF; Wed, 28 Feb 2024 12:58:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125121; cv=fail; b=OSmBC2FfnNx2zT1fW1n9IekyJhyHezITzc7LioA2fDyDj9j7nyM8eTKd2B+E/rkAtJSC6iTHAsznqaASuswAhBPNbBH6SJY2eTknqHtdx8jb4ir45vNEfl90y4JOoXIsTDRvUmlhycg/+Mxqqgb+igNjRtyuGDsqDZXcUKQSuHg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125121; c=relaxed/simple; bh=+LdNGKODjidhFjD67+8mjNg4ZNr4FKVUUvgwOOjxnjQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=RctdNFSkWJZ/BfXN212el73fYGDL5yuDEYe+K61NijtQ8gUd2dEv1wXRefF9iuq6OFcVVvWnVLQKd42rPm7QYsAfWKxdvgZGQ1Byy1eZDnRNQV2hY8w5sO7ZvIYAN3aK8Ixn9I7sjWyGDDg15PoXadwN5T0B9dWNNpyoejNwcuk= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=bLysYCAm; arc=fail smtp.client-ip=40.107.236.40 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="bLysYCAm" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jkPpBQlgEeUlDs9Hdrb6s0hQwXxj4nUMY4eJapZ0/GCHYZHhyR6HLzLax8pv/SakeOzDXA+RHTf4K/bs+T4jssWiCn6VpW50Ddu5P6qPOTSfkKTRUEbP+DPw/WXrNcCyl1jggdO8D2O0gjlh/51bRuMGtnlsa8aeFzTdUf4RIqlApAs+KYjRqYqmLMs0mIODiYRPCb7nVmlfaR7HVpC4avLNF4moTPmzDhjR7tJNDx+msX+rlKsVsb4/y9y6ehRlGMqpOQq5PSvdlyHpzXden4NUOq8U2KP2j1iJ/Y7ynM+Flr0B/IAYe3gXrfukNVjpc7YCnh4dikx8NUeJwLmzPg== 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=km8O+Bbqp5VjRWGtVFWspLxJHyuMM46DH/4xj/EyMyQ=; b=j6HCtJvJIRhWl9EjTfomabWd5mFKLAPl6XNUuJHDpXFcKVNJzKbxLBzzE9A/+MljFi+m2OV+4+j0xBcQph59k3QIRHNsMPMVwUigibC69Ys/dZc0OZ3W4+6FWorYDKB6saOyWs7YkzbOniygkwHEhrYXskNmIzBqK/hgRhlyZTJOiogjqcI4S5jg825an3OALiD8jfIKK0PEjUb//nfNOtj/dsnhSL5Dkws6EnIWpHacEt0npHrAgBsC1v3dnkjSy3PbE89Lz+cXDWxyy2HaoF365pOuvSTvxCExouskmDlvvYiRZB1GSTnB4I9tAhSsGMf2VMKKajqMV9s2aMOpBg== 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=km8O+Bbqp5VjRWGtVFWspLxJHyuMM46DH/4xj/EyMyQ=; b=bLysYCAmU6Fli+1SaXxk6Y6GB+lL8O315Kcgcq9eCKgtZDZm/ny2w5msFVYyuleDazSKqHs2W1MBmG8VcjRI7w8eHOtYDHTkBCDtEBqLjxZGwn1S13zwEtUBhQcsj1ISXfXgpWeTq8VcQfw6+vb5u/QBh1h+WAoib4fZqLdiDGRvk909AgoqEX8rngRcMhzQE5f3BQM9EjZv9MA/b6y91IX1fBrojaJEmQ3l9utE09sm0KGs/3HFiwjwMRNIPqVHn4Uq9KQVpiBWdi/bS24a1bjESeQG9Uz3QJffIhjd+SPMZdpYJPNn4Q3gkT0L3vpA5vsG1BTqmgzbdOvqSbEBgw== 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 CH3PR12MB9218.namprd12.prod.outlook.com (2603:10b6:610:19f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.36; Wed, 28 Feb 2024 12:58:35 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:58:35 +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: Yoray Zack , aaptel@nvidia.com, aurelien.aptel@gmail.com, smalin@nvidia.com, malin1024@gmail.com, ogerlitz@nvidia.com, borisp@nvidia.com, galshalom@nvidia.com, mgurtovoy@nvidia.com, linux-doc@vger.kernel.org, edumazet@google.com, pabeni@redhat.com, corbet@lwn.net Subject: [PATCH v23 09/20] Documentation: add ULP DDP offload documentation Date: Wed, 28 Feb 2024 12:57:22 +0000 Message-Id: <20240228125733.299384-10-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FR4P281CA0419.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:d0::18) 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_|CH3PR12MB9218:EE_ X-MS-Office365-Filtering-Correlation-Id: f8503666-677a-4f19-03d0-08dc385cf91d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QgY8NyGdQMxhh7RAd311bcjYBPcwKKKrgGCtUnsOuneBk+wUGsbPI/YR+mMO6/TNIP6LjYHuRA9JZV/2eIsl4J5EA3r1NtUQcXO5r3cBAmDTx67CjVAyYVQWcG6u+V/hJBTzatIKb69NPDP15SMwmsl1VRNrXVJijeGCpVBtb7kBuqMJ6sQCUsbVIY8Xu1BiH8L+VcChJY5ONPwsa26mveX78VkNZ/6VEBxIt7pqwmqtJSStSXbPezxy2EzerJkZKMWZCqTgHUWEGnnHoGqPgQpg9cyGt8EbYjtu5gYGCrfI2iC+FwuvST1ck0oywXCWISy/ePqbpsD0Fy4BW5R7+kugYmCp8nk7u9IiGzVVHUkltMEFJPcihWYASJ/yjZ+cWRFjdtzlTPaWCQJfxcofngcjmStVDkp+77BY0dmbyyO9R8MIpTTgLXOwHWBxwb4qsDVKSScG6A7/9BR8vJfIxqp37Oe4qbOFUX62+fUR78UQTe9aYp/QYWLywpZi0wHEsoURnFuF8VcI+uwHY6ZWQB+WQWBnxPuLIJ5R7foZgw8+yEDaP0GScic4UYx/gwzjbwcVG+bcRlMHEjK8IMX1yRQit4dHdOJSyeDlDLyF6y3AJ3Xr85UATk5ZomxRNNHMd6JCa6JMtKYi1ryxAchdlA== 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: iW84r4eorqia6YK0HHRVTOHwB9jQZCzpeUbcbsNU2+Z6iqsTyWjVsbh8zidKHSx5/UeiljRmCeBDPgfFnpt4dfw5rHeTcPBmKE5O1V0ONI4tonn6SUFIIUqtT+LZQrF7dh56EHr7GH5fTPZDNCOyeoMh6tk3mxnWdpmSfTTE3sIshb7uJ6K9fCPlLwNfh0WE3jf7bkdfEky1Ykd+xxd8HFdOTnn8ZLUgwyqxqzSY42yqDNJd6K12RGymwOBLMnrvkhEu+sqBVUZNL825HR6m5HrwMU/XlDsF1vzX9o5bXowEbDgueJnyqwUdma/am+k45dxC7OjUSUGAY5MCLjiPrIjq9mXP7qeW1eOIMOwQ5mAVQ6gRU7K0P6Saxq/XRXjD7pDn23ax/VJ+8vJzemDBi78g+0M19h8UA+4di3JD7zgmgsx4oEV5XGUXjmw7/FA1mZESKbDMNEKY7D/tuGD6FfF7f3KA+G6qLSYGeKxKDmRtwe/EMJeqopxDp+9TMiEwPssiSe4qn6LLxJwBTAyBRbHzWbPRUcsoSVx/UZ6DFSQYQd2OrLfbndvaUcokPzBL5r7gyg5CLdZm3syfWxIO254i8DGXxOQ2SawVKNdOhjEiYlD1U+h1kFDSWuzypwDuZAChDLak5XtfhdFVeNWVm1qk2digN4BOjkFtGPNl78KRm8OCzqZZio+XEw33PzEiQZJV5dN7ql9RcdSC1EQG0jUfV4rntE7VFgRsY7hElVQEMnJe0DtJ5Q3R/b50jSFR8RR62NlmeO6PDI7MW0BRDsmyqIDRxcpFmOd9P5ME2/EsCKWpZvVYnzJoPwVrOiig1S4nvaxERq3QQYcnUh6szFH5x/AIVMvD+CVvbDceUKa0bpiFPEmsJECZcs2MqiE0gGEK6ThFg3i8KPhh7bj9hWY4WeacuNr7Q6vuDfq+0a8fD73NjFaK8YiBd6/a8aBjHDLgjIA1Sn35IDrZvlPz4RsxTKiuxsrpZXcjcP8hdzRk0QN43XeSFv1QaE+PkqrpKYiQ6VvxXb6Hj1kVTeYoJExCYS6WhWlhyii4AGa2RIWy8QQRNE9dYHr9C58Vb2neRtzp8sUTNh4wFT6/gtpMZe5gJnOqzgPgIf9QRI3oCygiDxxVhfJsmApmbaUIUsJgCp1LI94dcYScirkVaYY9BkOo3PJBYfGahq5SEo2WpbIgyubwJe38hmQSzsrBuVHk64n4P8E1O4e2uZqm+c52wYqA2Vfuvzd34WZRs+iPnC2jodvH4lH7UphrtRExgUxUddm4iGGX8HwuYOTw5e4AWmJQrA7teq5xybHUNK1DsAqvQ/Trto+CsEoysokJR6lpz0C3miw+PN0Lm0v43N2B0rIWVs0Yg6OCd7rGkHwhKSuq7PrNTlXsij0gMqNnSGhd1En2Uj2VzQNEdm1boqzN27AboufNhiVlp2wi6FbO25HhHZjEeScEVp8gHUifcUW8Q4J6YQqtMttvTGHgpI58swJD/nKF9fs8xwVbjynwEitZL3SvwBH3Hb6BkMEbIt2+JuJI0saWqqGXdaY6wt2Yk+xFK/LBPWE9ArnpKli2UOzlxbB3lCMf4xFcLA1CfL7Z X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f8503666-677a-4f19-03d0-08dc385cf91d X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:58:35.0144 (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: 0jS9uxQLKUq/oLX7x4uMcjYGLzoGMuOXo9POQREK0WLhA/t1KqIw3HMTUAqG4D/9i8Kj8IAbunEKvVylC1yhNA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9218 X-Patchwork-Delegate: kuba@kernel.org From: Yoray Zack Document the new ULP DDP API and add it under "networking". Use NVMe-TCP implementation as an example. Signed-off-by: Boris Pismenny Signed-off-by: Ben Ben-Ishay Signed-off-by: Or Gerlitz Signed-off-by: Yoray Zack Signed-off-by: Shai Malin Signed-off-by: Aurelien Aptel --- Documentation/networking/index.rst | 1 + Documentation/networking/ulp-ddp-offload.rst | 374 +++++++++++++++++++ 2 files changed, 375 insertions(+) create mode 100644 Documentation/networking/ulp-ddp-offload.rst diff --git a/Documentation/networking/index.rst b/Documentation/networking/index.rst index 69f3d6dcd9fd..2b96da09269f 100644 --- a/Documentation/networking/index.rst +++ b/Documentation/networking/index.rst @@ -110,6 +110,7 @@ Contents: tc-queue-filters tcp_ao tcp-thin + ulp-ddp-offload team timestamping tipc diff --git a/Documentation/networking/ulp-ddp-offload.rst b/Documentation/networking/ulp-ddp-offload.rst new file mode 100644 index 000000000000..438f060e9af4 --- /dev/null +++ b/Documentation/networking/ulp-ddp-offload.rst @@ -0,0 +1,374 @@ +.. SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) + +================================= +ULP direct data placement offload +================================= + +Overview +======== + +The Linux kernel ULP direct data placement (DDP) offload infrastructure +provides tagged request-response protocols, such as NVMe-TCP, the ability to +place response data directly in pre-registered buffers according to header +tags. DDP is particularly useful for data-intensive pipelined protocols whose +responses may be reordered. + +For example, in NVMe-TCP numerous read requests are sent together and each +request is tagged using the PDU header CID field. Receiving servers process +requests as fast as possible and sometimes responses for smaller requests +bypasses responses to larger requests, e.g., 4KB reads bypass 1GB reads. +Thereafter, clients correlate responses to requests using PDU header CID tags. +The processing of each response requires copying data from SKBs to read +request destination buffers; The offload avoids this copy. The offload is +oblivious to destination buffers which can reside either in userspace +(O_DIRECT) or in kernel pagecache. + +Request TCP byte-stream: + +.. parsed-literal:: + + +---------------+-------+---------------+-------+---------------+-------+ + | PDU hdr CID=1 | Req 1 | PDU hdr CID=2 | Req 2 | PDU hdr CID=3 | Req 3 | + +---------------+-------+---------------+-------+---------------+-------+ + +Response TCP byte-stream: + +.. parsed-literal:: + + +---------------+--------+---------------+--------+---------------+--------+ + | PDU hdr CID=2 | Resp 2 | PDU hdr CID=3 | Resp 3 | PDU hdr CID=1 | Resp 1 | + +---------------+--------+---------------+--------+---------------+--------+ + +The driver builds SKB page fragments that point to destination buffers. +Consequently, SKBs represent the original data on the wire, which enables +*transparent* inter-operation with the network stack. To avoid copies between +SKBs and destination buffers, the layer-5 protocol (L5P) will check +``if (src == dst)`` for SKB page fragments, success indicates that data is +already placed there by NIC hardware and copy should be skipped. + +In addition, L5P might have DDGST which ensures data integrity over +the network. If not offloaded, ULP DDP might not be efficient as L5P +will need to go over the data and calculate it by itself, cancelling +out the benefits of the DDP copy skip. ULP DDP has support for Rx/Tx +DDGST offload. On the received side the NIC will verify DDGST for +received PDUs and update SKB->ulp_ddp and SKB->ulp_crc bits. If all the SKBs +making up a L5P PDU have crc on, L5P will skip on calculating and +verifying the DDGST for the corresponding PDU. On the Tx side, the NIC +will be responsible for calculating and filling the DDGST fields in +the sent PDUs. + +Offloading does require NIC hardware to track L5P protocol framing, similarly +to RX TLS offload (see Documentation/networking/tls-offload.rst). NIC hardware +will parse PDU headers, extract fields such as operation type, length, tag +identifier, etc. and only offload segments that correspond to tags registered +with the NIC, see the :ref:`buf_reg` section. + +Device configuration +==================== + +During driver initialization the driver sets the ULP DDP operations +for the :c:type:`struct net_device ` via +`netdev->netdev_ops->ulp_ddp_ops`. + +The :c:member:`get_caps` operation returns the ULP DDP capabilities +enabled and/or supported by the device to the caller. The current list +of capabilities is represented as a bitset: + +.. code-block:: c + + enum ulp_ddp_cap { + ULP_DDP_CAP_NVME_TCP, + ULP_DDP_CAP_NVME_TCP_DDGST, + }; + +The enablement of capabilities can be controlled via the +:c:member:`set_caps` operation. This operation is exposed to userspace +via netlink. See Documentation/netlink/specs/ulp_ddp.yaml for more +details. + +Later, after the L5P completes its handshake, the L5P queries the +driver for its runtime limitations via the :c:member:`limits` operation: + +.. code-block:: c + + int (*limits)(struct net_device *netdev, + struct ulp_ddp_limits *lim); + + +All L5P share a common set of limits and parameters (:c:type:`struct ulp_ddp_limits `): + +.. code-block:: c + + /** + * struct ulp_ddp_limits - Generic ulp ddp limits: tcp ddp + * protocol limits. + * Add new instances of ulp_ddp_limits in the union below (nvme-tcp, etc.). + * + * @type: type of this limits struct + * @max_ddp_sgl_len: maximum sgl size supported (zero means no limit) + * @io_threshold: minimum payload size required to offload + * @tls: support for ULP over TLS + * @nvmeotcp: NVMe-TCP specific limits + */ + struct ulp_ddp_limits { + enum ulp_ddp_type type; + int max_ddp_sgl_len; + int io_threshold; + bool tls:1; + union { + /* ... protocol-specific limits ... */ + struct nvme_tcp_ddp_limits nvmeotcp; + }; + }; + +But each L5P can also add protocol-specific limits e.g.: + +.. code-block:: c + + /** + * struct nvme_tcp_ddp_limits - nvme tcp driver limitations + * + * @full_ccid_range: true if the driver supports the full CID range + */ + struct nvme_tcp_ddp_limits { + bool full_ccid_range; + }; + +Once the L5P has made sure the device is supported the offload +operations are installed on the socket. + +If offload installation fails, then the connection is handled by software as if +offload was not attempted. + +To request offload for a socket `sk`, the L5P calls :c:member:`sk_add`: + +.. code-block:: c + + int (*sk_add)(struct net_device *netdev, + struct sock *sk, + struct ulp_ddp_config *config); + +The function return 0 for success. In case of failure, L5P software should +fallback to normal non-offloaded operations. The `config` parameter indicates +the L5P type and any metadata relevant for that protocol. For example, in +NVMe-TCP the following config is used: + +.. code-block:: c + + /** + * struct nvme_tcp_ddp_config - nvme tcp ddp configuration for an IO queue + * + * @pfv: pdu version (e.g., NVME_TCP_PFV_1_0) + * @cpda: controller pdu data alignment (dwords, 0's based) + * @dgst: digest types enabled. + * The netdev will offload crc if L5P data digest is supported. + * @queue_size: number of nvme-tcp IO queue elements + * @queue_id: queue identifier + */ + struct nvme_tcp_ddp_config { + u16 pfv; + u8 cpda; + u8 dgst; + int queue_size; + int queue_id; + }; + +When offload is not needed anymore, e.g. when the socket is being released, the L5P +calls :c:member:`sk_del` to release device contexts: + +.. code-block:: c + + void (*sk_del)(struct net_device *netdev, + struct sock *sk); + +Normal operation +================ + +At the very least, the device maintains the following state for each connection: + + * 5-tuple + * expected TCP sequence number + * mapping between tags and corresponding buffers + * current offset within PDU, PDU length, current PDU tag + +NICs should not assume any correlation between PDUs and TCP packets. +If TCP packets arrive in-order, offload will place PDU payloads +directly inside corresponding registered buffers. NIC offload should +not delay packets. If offload is not possible, than the packet is +passed as-is to software. To perform offload on incoming packets +without buffering packets in the NIC, the NIC stores some inter-packet +state, such as partial PDU headers. + +RX data-path +------------ + +After the device validates TCP checksums, it can perform DDP offload. The +packet is steered to the DDP offload context according to the 5-tuple. +Thereafter, the expected TCP sequence number is checked against the packet +TCP sequence number. If there is a match, offload is performed: the PDU payload +is DMA written to the corresponding destination buffer according to the PDU header +tag. The data should be DMAed only once, and the NIC receive ring will only +store the remaining TCP and PDU headers. + +We remark that a single TCP packet may have numerous PDUs embedded inside. NICs +can choose to offload one or more of these PDUs according to various +trade-offs. Possibly, offloading such small PDUs is of little value, and it is +better to leave it to software. + +Upon receiving a DDP offloaded packet, the driver reconstructs the original SKB +using page frags, while pointing to the destination buffers whenever possible. +This method enables seamless integration with the network stack, which can +inspect and modify packet fields transparently to the offload. + +.. _buf_reg: + +Destination buffer registration +------------------------------- + +To register the mapping between tags and destination buffers for a socket +`sk`, the L5P calls :c:member:`setup` of :c:type:`struct ulp_ddp_dev_ops +`: + +.. code-block:: c + + int (*setup)(struct net_device *netdev, + struct sock *sk, + struct ulp_ddp_io *io); + + +The `io` provides the buffer via scatter-gather list (`sg_table`) and +corresponding tag (`command_id`): + +.. code-block:: c + + /** + * struct ulp_ddp_io - tcp ddp configuration for an IO request. + * + * @command_id: identifier on the wire associated with these buffers + * @nents: number of entries in the sg_table + * @sg_table: describing the buffers for this IO request + * @first_sgl: first SGL in sg_table + */ + struct ulp_ddp_io { + u32 command_id; + int nents; + struct sg_table sg_table; + struct scatterlist first_sgl[SG_CHUNK_SIZE]; + }; + +After the buffers have been consumed by the L5P, to release the NIC mapping of +buffers the L5P calls :c:member:`teardown` of :c:type:`struct +ulp_ddp_dev_ops `: + +.. code-block:: c + + void (*teardown)(struct net_device *netdev, + struct sock *sk, + struct ulp_ddp_io *io, + void *ddp_ctx); + +`teardown` receives the same `io` context and an additional opaque +`ddp_ctx` that is used for asynchronous teardown, see the :ref:`async_release` +section. + +.. _async_release: + +Asynchronous teardown +--------------------- + +To teardown the association between tags and buffers and allow tag reuse NIC HW +is called by the NIC driver during `teardown`. This operation may be +performed either synchronously or asynchronously. In asynchronous teardown, +`teardown` returns immediately without unmapping NIC HW buffers. Later, +when the unmapping completes by NIC HW, the NIC driver will call up to L5P +using :c:member:`ddp_teardown_done` of :c:type:`struct ulp_ddp_ulp_ops `: + +.. code-block:: c + + void (*ddp_teardown_done)(void *ddp_ctx); + +The `ddp_ctx` parameter passed in `ddp_teardown_done` is the same on provided +in `teardown` and it is used to carry some context about the buffers +and tags that are released. + +Resync handling +=============== + +RX +-- +In presence of packet drops or network packet reordering, the device may lose +synchronization between the TCP stream and the L5P framing, and require a +resync with the kernel's TCP stack. When the device is out of sync, no offload +takes place, and packets are passed as-is to software. Resync is very similar +to TLS offload (see documentation at Documentation/networking/tls-offload.rst) + +If only packets with L5P data are lost or reordered, then resynchronization may +be avoided by NIC HW that keeps tracking PDU headers. If, however, PDU headers +are reordered, then resynchronization is necessary. + +To resynchronize hardware during traffic, we use a handshake between hardware +and software. The NIC HW searches for a sequence of bytes that identifies L5P +headers (i.e., magic pattern). For example, in NVMe-TCP, the PDU operation +type can be used for this purpose. Using the PDU header length field, the NIC +HW will continue to find and match magic patterns in subsequent PDU headers. If +the pattern is missing in an expected position, then searching for the pattern +starts anew. + +The NIC will not resume offload when the magic pattern is first identified. +Instead, it will request L5P software to confirm that indeed this is a PDU +header. To request confirmation the NIC driver calls up to L5P using +:c:member:`resync_request` of :c:type:`struct ulp_ddp_ulp_ops `: + +.. code-block:: c + + bool (*resync_request)(struct sock *sk, u32 seq, u32 flags); + +The `seq` parameter contains the TCP sequence of the last byte in the PDU header. +The `flags` parameter contains a flag (`ULP_DDP_RESYNC_PENDING`) indicating whether +a request is pending or not. +L5P software will respond to this request after observing the packet containing +TCP sequence `seq` in-order. If the PDU header is indeed there, then L5P +software calls the NIC driver using the :c:member:`resync` function of +the :c:type:`struct ulp_ddp_dev_ops ` inside the :c:type:`struct +net_device ` while passing the same `seq` to confirm it is a PDU +header. + +.. code-block:: c + + void (*resync)(struct net_device *netdev, + struct sock *sk, u32 seq); + +Statistics +========== + +Per L5P protocol, the NIC driver must report statistics for the above +netdevice operations and packets processed by offload. +These statistics are per-device and can be retrieved from userspace +via netlink (see Documentation/netlink/specs/ulp_ddp.yaml). + +For example, NVMe-TCP offload reports: + + * ``rx_nvme_tcp_sk_add`` - number of NVMe-TCP Rx offload contexts created. + * ``rx_nvme_tcp_sk_add_fail`` - number of NVMe-TCP Rx offload context creation + failures. + * ``rx_nvme_tcp_sk_del`` - number of NVMe-TCP Rx offload contexts destroyed. + * ``rx_nvme_tcp_setup`` - number of DDP buffers mapped. + * ``rx_nvme_tcp_setup_fail`` - number of DDP buffers mapping that failed. + * ``rx_nvme_tcp_teardown`` - number of DDP buffers unmapped. + * ``rx_nvme_tcp_drop`` - number of packets dropped in the driver due to fatal + errors. + * ``rx_nvme_tcp_resync`` - number of packets with resync requests. + * ``rx_nvme_tcp_packets`` - number of packets that used offload. + * ``rx_nvme_tcp_bytes`` - number of bytes placed in DDP buffers. + +NIC requirements +================ + +NIC hardware should meet the following requirements to provide this offload: + + * Offload must never buffer TCP packets. + * Offload must never modify TCP packet headers. + * Offload must never reorder TCP packets within a flow. + * Offload must never drop TCP packets. + * Offload must not depend on any TCP fields beyond the + 5-tuple and TCP sequence number. From patchwork Wed Feb 28 12:57:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575451 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2040.outbound.protection.outlook.com [40.107.236.40]) (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 DAF16149E17 for ; Wed, 28 Feb 2024 12:58:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125123; cv=fail; b=jjQGb1xcS9YUerwQpTKgTe9fnbLsa77oPHMY6O4WSU2VdDjBg7kxP3NweGDWjMGmFEQHjScdcUwDiEQ4zBTr97jJnJ2JhO1U/dzPgujZFpodCumkN3EBgb5UEFt7ct/np2HpyWzVnyzTiul4dzmW9fkoOROnt1qH6SMSfRwSZOw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125123; c=relaxed/simple; bh=HWsrRfFSw+O25JmAtf6AJxXRitiIdg1eCpxSO53fGgE=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=hDiEo9i0MrIbfKhqYU7Wn8RPmO5VxYTbUESIRQvarlZ2QLgMdIQj2crwOPR4p4SgB48WSFETCYalYF/Blf8kNLx2mvTigOpfLxM1Q2Co5CjtRPHnG5CGfsjJ0RLxRC8hZ7p/P0WRd7yYTYhjevZcjQqljdrR/pdRFcXWbLqaaas= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=gIgEPtYl; arc=fail smtp.client-ip=40.107.236.40 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="gIgEPtYl" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eVmIKIsrQ9rjFEhGaFsHRWwPUiIZGivzlXNhrZu9x7RUchbOU+JBUPyyHdRWXGimhQUIlUM9G1SFMQvUs9sIOg5QEyZ1HohVXlfn7dq1lKT4uAYYXMiMTBIExo+TqrrOCKH74HcdQpbMuJHs0lOEy9dXiNVoIEdDYz8X4SjyrTJz7iqVROHbbaGs8Jl4/u0UEV+DFu/AjGIOzF5eOsGWqqubRNBLYYD2+NQIPS2iLiKV46PwBTyoHZ5VMJK1bdTmiTuZa6DaPMjyNYHL4Ut2EdA8R7qR1GRd8YLqvfOP4YEzE9YNRERtWVCQtGsZ3qiaGAK5i4/17Ri2q0SFEHduUw== 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=t0CdfFmFpaF06xm9NXysyjJuk4VcskPNDYfY1S9YtAc=; b=O0emzP6p+L3zwajA2IpuJlf23tfqCuFnJLVGlAVmi1+8xSfafNsF1fiHNbOItyMRUTvA+qXzHlEeAMzgvPv3HY6OTGFhvWcnvi2G3WQ23hJHcNQAjr6zZUs82R7VLeyTVuFh8hXicYEDYNzg+sG6vUu0p+6tuDADH4Qp9t9hKXWa0LRyGrI/puHmsA6Irf1R/hUHKgJ2uMwUuqTwTITz2Qwy/rO4E6H9BYRBJwmUWviPWqHBHbd6fSczPJ38dWIatXxnRy/uugtuz4SR/ab8vgRwXePs9XCR9HYGrrd5VgXKMBUCRRq3RdJf7pbd0Dhks/xE1b2Y9WL6740xLrvIHg== 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=t0CdfFmFpaF06xm9NXysyjJuk4VcskPNDYfY1S9YtAc=; b=gIgEPtYlIe6xtZAANvsvkGIJVrL5CeAkbvS+6fYNGAydX1AU1bGCzG5meMUrs7or08pSZ35j3/y8aC06hWjmHlB3WAR0CfXLK2NfJMUSmSX1LhMDnIHbN8zl5oEszmSYuupakzwMLmVW8DA3Ltdy3wMd6PSkuXRdMWEvm9HqAXNN3zdu2Fqa1uWlJw/ouagfkkpEeJnJNKu1Wdnhj8EX+bNiQhBOF0Q88TzvqvRsxZyyYQ0EI4/slZLCgY4Ug1pN1dI9RKrSyECtbNQ71HXIunUnAZZ1HYiZg13gUcRwH2wuT/z/nuWkQ2dgsinZ1HaqvMEqF58jSxKi8JnO2a/NWQ== 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 CH3PR12MB9218.namprd12.prod.outlook.com (2603:10b6:610:19f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.36; Wed, 28 Feb 2024 12:58:39 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:58:39 +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: Or Gerlitz , aaptel@nvidia.com, aurelien.aptel@gmail.com, smalin@nvidia.com, malin1024@gmail.com, yorayz@nvidia.com, borisp@nvidia.com, galshalom@nvidia.com, mgurtovoy@nvidia.com Subject: [PATCH v23 10/20] net/mlx5e: Rename from tls to transport static params Date: Wed, 28 Feb 2024 12:57:23 +0000 Message-Id: <20240228125733.299384-11-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FR4P281CA0151.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:ba::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_|CH3PR12MB9218:EE_ X-MS-Office365-Filtering-Correlation-Id: 52d373cd-4f1e-4a3c-19fa-08dc385cfbb3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DM4kI0l7QYnzKeTQZEAOtJHNuxdt8xKSab+FGqMqRPQRsldbMQHtPU+vSMTjqOz3ro2S5VuQmOryXeiP+Ac8wPxLwvcD/A5M74s4RA1BUfP2WO6Ate/RE0LcqZu6xD7OsNVwJEu1m5wkm6Yrw3CxnsnzqIqavpG29kKUtzHEeyZsBqccnz0YPw/we0v6qQUlO36xeh8EZXqZMspKD0hyH+YyLcWrt8iycL0JW5G52jPJAruU5lF0iUayirjma0TfresEvTAn8ITdN+9Q9tqpI1fxuYEoCPMefuUuEGZtNae5I5pjg7gAUXnQ0w6CC1j52JDKPpU5NJXOSq0qYa/82Jd4QCgT9qwlb6BL/e4BFOXyLtnOciR4hRHbAc4T2rf8ic6iA05dfkwv09U1y6kWxI3LMi89+EMlND42MVK/6iybJZT27i5YamzIZW5KPHZlHY3/rD+Mq9lLqpGzDvZVnPHtB2BYHPCGlZklEc1/flYm7vdtgryZYP/AiQEb0HTAH/Q7s8Qh6Bs9BluFfzWTwHpLQmokqLwaGON5KCeXZMj4uViBBNkgO/FQvBSVGYvmeIGBqHUploiBVsaGtrwfNGvXoP+lvW673VI/MoazsD/6GTEX7Yhxx/iCwGVnAtuW 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2xs8LkbYvmcWxMwimH6h2DX6c32FGXZiMyehLWF5BLEXzc0C6SSNNCNcMovkWRvj7/MKyczMQ2CR/fj5MUvwJGHoGQ+wPPN2m5vxUZpSftMPdRlYVNzwUXEYznBMbx6k8C7CNtNabX0n3hNr6uBW4qyiecKttm6qcETYaz5X4tOM1510HO/tkMG8ftJ8sxbbPYEMx7BdiFJRSWeFa7cITOU4afAgCHf0xfJrIifPcQVTU4zJjOwckc/sbMUzZRW3zKdaJ4a0WrWm1cTxIqNNWzvdrmwf9Nl5ClQvazFs3YqHGK71ZJXKMF5TPsXWNZN4ZjnLhvNIGWV2PjhWozQuME5O+Nch0mwoqjLFZmTsDtD8N+wZn6UqNpKwpaxVZMq3lfetv5fHzUtUWINK/bB38EgGDi3SSWgVZqiKl79qhu+ki/U3QL/fyfEuNiKlaJXiTm7ibwXFSC2oMBOCifEd7kxdWYh9k/hPUukxdXHt7WgY7qm900JE9vQwXpJXSanKVJ/Rh8nhTrUXb6FnreJmasAo8AhHH8fswhFzJ7WTJ59h07ak5tLTr+Qe34CDUh1SDaYleFHnfW52MqV/5CM5WtA1eSwtGB6GsCpmcGyEzlIZfB6hANZnSSygGzPd0n2VTHy1xwOfATt3hcLdDmfZE0ByxzsA4a6yiYFf9/DyAegKKZVOkV0XnMsGxEipbpu2Z4L9sGlOCXX9vPYt3itCpjtpcb9Xolz1KMflxjOT/ZW5Sm4x0x6A/bqieNbVc0QulZ43IbvQLtWtsU4bWLf82VA7fUfJ2GYQLxSWX7Ga6eVZw3HCoG15my46CZAchtcoapIzt4UuI2ol/u1BntZVh+8zvLTVldAsVMi1SVsd7KJIMp5mo45pB0ku/m5OhmNjn/u2EktNJSQdSd4KjyaDhLK7iY5Ya4KHUWXnaVtxSGOHRpMFVqP8UZWLGD7qr0oe/qQxyXZbymgqTkTWf5OmF38WTlbWdQ6X/KTX20iOSSWZm+Dp8qHBmO6rzwoG5rigmnt+4QNVoSSfJ1WnwTpJMxueJgyYVOHuh1byF4YLD6I7fshtcgjJIAZtH0CNfF7FuGI43O6NTF8Phe48H264HYnK/WAvovpW3tVWD0fNOZXHBWVgbtjA2NgPACAzo08BQepFHLfF1azf8ltY867B5EHy+D3t4/cksyUVuW/0mP8CHRtUp0HTlQp46p8riiwz1LLcuWdeAlSmd5GSls8laFIqFCC6IFvvBxtaFrjjYmQa0yCufg+WHH5e85/Js2NJNqLLxnhtuyqLUzcbihNG/4U8hjfJx3rPzYFkEPImmIBkkcLCDCTJo6xaaghgJwClEiAjbKoveTWYdAxB7oZTj+6Hy3Y2GCDn2tp+tZbC2B+cfocEQxmlAkMpnaJk7qIF8vi4akIHJ+pEA+TdymUTbah/FN7NHqHifcyShTIAjAJAoCNhhazYshu4ecVQBilUZqAq/TuMLgeLcnYPj/rOl43ZBIRFL2jFzts9VeHqbee0t/9rdzdyujO3i/EGlobBK8AOdkeJTmLmIAnIHWLImhGc4RIb2gNnJFx4CastESmis1hTqHryTYO0LD/Rp9AM X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 52d373cd-4f1e-4a3c-19fa-08dc385cfbb3 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:58:39.3176 (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: eXr1fHlQEJTQGXKhkGFMcnG5OgwxfyBCv6+QAyugvXJBW5F+Ia4iktai0YSbOvDwZ+fdwiRVGomnTUavx7QQvQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9218 X-Patchwork-Delegate: kuba@kernel.org From: Or Gerlitz The static params structure is used in TLS but also in other transports we're offloading like nvmeotcp: - Rename the relevant structures/fields - Create common file for appropriate transports - Apply changes in the TLS code No functional change here. Signed-off-by: Or Gerlitz Signed-off-by: Ben Ben-Ishay Signed-off-by: Aurelien Aptel Reviewed-by: Tariq Toukan --- .../mlx5/core/en_accel/common_utils.h | 32 +++++++++++++++++ .../mellanox/mlx5/core/en_accel/ktls.c | 2 +- .../mellanox/mlx5/core/en_accel/ktls_rx.c | 6 ++-- .../mellanox/mlx5/core/en_accel/ktls_tx.c | 8 ++--- .../mellanox/mlx5/core/en_accel/ktls_txrx.c | 36 ++++++++----------- .../mellanox/mlx5/core/en_accel/ktls_utils.h | 17 ++------- include/linux/mlx5/device.h | 8 ++--- include/linux/mlx5/mlx5_ifc.h | 8 +++-- 8 files changed, 67 insertions(+), 50 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/common_utils.h diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/common_utils.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/common_utils.h new file mode 100644 index 000000000000..efdf48125848 --- /dev/null +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/common_utils.h @@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ +/* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. */ +#ifndef __MLX5E_COMMON_UTILS_H__ +#define __MLX5E_COMMON_UTILS_H__ + +#include "en.h" + +struct mlx5e_set_transport_static_params_wqe { + struct mlx5_wqe_ctrl_seg ctrl; + struct mlx5_wqe_umr_ctrl_seg uctrl; + struct mlx5_mkey_seg mkc; + struct mlx5_wqe_transport_static_params_seg params; +}; + +/* macros for transport_static_params handling */ +#define MLX5E_TRANSPORT_SET_STATIC_PARAMS_WQEBBS \ + (DIV_ROUND_UP(sizeof(struct mlx5e_set_transport_static_params_wqe), MLX5_SEND_WQE_BB)) + +#define MLX5E_TRANSPORT_FETCH_SET_STATIC_PARAMS_WQE(sq, pi) \ + ((struct mlx5e_set_transport_static_params_wqe *)\ + mlx5e_fetch_wqe(&(sq)->wq, pi, sizeof(struct mlx5e_set_transport_static_params_wqe))) + +#define MLX5E_TRANSPORT_STATIC_PARAMS_WQE_SZ \ + (sizeof(struct mlx5e_set_transport_static_params_wqe)) + +#define MLX5E_TRANSPORT_STATIC_PARAMS_DS_CNT \ + (DIV_ROUND_UP(MLX5E_TRANSPORT_STATIC_PARAMS_WQE_SZ, MLX5_SEND_WQE_DS)) + +#define MLX5E_TRANSPORT_STATIC_PARAMS_OCTWORD_SIZE \ + (MLX5_ST_SZ_BYTES(transport_static_params) / MLX5_SEND_WQE_DS) + +#endif /* __MLX5E_COMMON_UTILS_H__ */ diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c index 984fa04bd331..bab9b0c59491 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls.c @@ -100,7 +100,7 @@ bool mlx5e_is_ktls_rx(struct mlx5_core_dev *mdev) return false; /* Check the possibility to post the required ICOSQ WQEs. */ - if (WARN_ON_ONCE(max_sq_wqebbs < MLX5E_TLS_SET_STATIC_PARAMS_WQEBBS)) + if (WARN_ON_ONCE(max_sq_wqebbs < MLX5E_TRANSPORT_SET_STATIC_PARAMS_WQEBBS)) return false; if (WARN_ON_ONCE(max_sq_wqebbs < MLX5E_TLS_SET_PROGRESS_PARAMS_WQEBBS)) return false; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_rx.c index 9b597cb24598..20994773056c 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_rx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_rx.c @@ -136,16 +136,16 @@ static struct mlx5_wqe_ctrl_seg * post_static_params(struct mlx5e_icosq *sq, struct mlx5e_ktls_offload_context_rx *priv_rx) { - struct mlx5e_set_tls_static_params_wqe *wqe; + struct mlx5e_set_transport_static_params_wqe *wqe; struct mlx5e_icosq_wqe_info wi; u16 pi, num_wqebbs; - num_wqebbs = MLX5E_TLS_SET_STATIC_PARAMS_WQEBBS; + num_wqebbs = MLX5E_TRANSPORT_SET_STATIC_PARAMS_WQEBBS; if (unlikely(!mlx5e_icosq_can_post_wqe(sq, num_wqebbs))) return ERR_PTR(-ENOSPC); pi = mlx5e_icosq_get_next_pi(sq, num_wqebbs); - wqe = MLX5E_TLS_FETCH_SET_STATIC_PARAMS_WQE(sq, pi); + wqe = MLX5E_TRANSPORT_FETCH_SET_STATIC_PARAMS_WQE(sq, pi); mlx5e_ktls_build_static_params(wqe, sq->pc, sq->sqn, &priv_rx->crypto_info, mlx5e_tir_get_tirn(&priv_rx->tir), mlx5_crypto_dek_get_id(priv_rx->dek), diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c index d61be26a4df1..0691995470e2 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_tx.c @@ -33,7 +33,7 @@ u16 mlx5e_ktls_get_stop_room(struct mlx5_core_dev *mdev, struct mlx5e_params *pa num_dumps = mlx5e_ktls_dumps_num_wqes(params, MAX_SKB_FRAGS, TLS_MAX_PAYLOAD_SIZE); - stop_room += mlx5e_stop_room_for_wqe(mdev, MLX5E_TLS_SET_STATIC_PARAMS_WQEBBS); + stop_room += mlx5e_stop_room_for_wqe(mdev, MLX5E_TRANSPORT_SET_STATIC_PARAMS_WQEBBS); stop_room += mlx5e_stop_room_for_wqe(mdev, MLX5E_TLS_SET_PROGRESS_PARAMS_WQEBBS); stop_room += num_dumps * mlx5e_stop_room_for_wqe(mdev, MLX5E_KTLS_DUMP_WQEBBS); stop_room += 1; /* fence nop */ @@ -550,12 +550,12 @@ post_static_params(struct mlx5e_txqsq *sq, struct mlx5e_ktls_offload_context_tx *priv_tx, bool fence) { - struct mlx5e_set_tls_static_params_wqe *wqe; + struct mlx5e_set_transport_static_params_wqe *wqe; u16 pi, num_wqebbs; - num_wqebbs = MLX5E_TLS_SET_STATIC_PARAMS_WQEBBS; + num_wqebbs = MLX5E_TRANSPORT_SET_STATIC_PARAMS_WQEBBS; pi = mlx5e_txqsq_get_next_pi(sq, num_wqebbs); - wqe = MLX5E_TLS_FETCH_SET_STATIC_PARAMS_WQE(sq, pi); + wqe = MLX5E_TRANSPORT_FETCH_SET_STATIC_PARAMS_WQE(sq, pi); mlx5e_ktls_build_static_params(wqe, sq->pc, sq->sqn, &priv_tx->crypto_info, priv_tx->tisn, mlx5_crypto_dek_get_id(priv_tx->dek), diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_txrx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_txrx.c index 570a912dd6fa..8abea6fe6cd9 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_txrx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_txrx.c @@ -8,10 +8,6 @@ enum { MLX5E_STATIC_PARAMS_CONTEXT_TLS_1_2 = 0x2, }; -enum { - MLX5E_ENCRYPTION_STANDARD_TLS = 0x1, -}; - #define EXTRACT_INFO_FIELDS do { \ salt = info->salt; \ rec_seq = info->rec_seq; \ @@ -20,7 +16,7 @@ enum { } while (0) static void -fill_static_params(struct mlx5_wqe_tls_static_params_seg *params, +fill_static_params(struct mlx5_wqe_transport_static_params_seg *params, union mlx5e_crypto_info *crypto_info, u32 key_id, u32 resync_tcp_sn) { @@ -53,25 +49,25 @@ fill_static_params(struct mlx5_wqe_tls_static_params_seg *params, return; } - gcm_iv = MLX5_ADDR_OF(tls_static_params, ctx, gcm_iv); - initial_rn = MLX5_ADDR_OF(tls_static_params, ctx, initial_record_number); + gcm_iv = MLX5_ADDR_OF(transport_static_params, ctx, gcm_iv); + initial_rn = MLX5_ADDR_OF(transport_static_params, ctx, initial_record_number); memcpy(gcm_iv, salt, salt_sz); memcpy(initial_rn, rec_seq, rec_seq_sz); tls_version = MLX5E_STATIC_PARAMS_CONTEXT_TLS_1_2; - MLX5_SET(tls_static_params, ctx, tls_version, tls_version); - MLX5_SET(tls_static_params, ctx, const_1, 1); - MLX5_SET(tls_static_params, ctx, const_2, 2); - MLX5_SET(tls_static_params, ctx, encryption_standard, - MLX5E_ENCRYPTION_STANDARD_TLS); - MLX5_SET(tls_static_params, ctx, resync_tcp_sn, resync_tcp_sn); - MLX5_SET(tls_static_params, ctx, dek_index, key_id); + MLX5_SET(transport_static_params, ctx, tls_version, tls_version); + MLX5_SET(transport_static_params, ctx, const_1, 1); + MLX5_SET(transport_static_params, ctx, const_2, 2); + MLX5_SET(transport_static_params, ctx, acc_type, + MLX5_TRANSPORT_STATIC_PARAMS_ACC_TYPE_TLS); + MLX5_SET(transport_static_params, ctx, resync_tcp_sn, resync_tcp_sn); + MLX5_SET(transport_static_params, ctx, dek_index, key_id); } void -mlx5e_ktls_build_static_params(struct mlx5e_set_tls_static_params_wqe *wqe, +mlx5e_ktls_build_static_params(struct mlx5e_set_transport_static_params_wqe *wqe, u16 pc, u32 sqn, union mlx5e_crypto_info *crypto_info, u32 tis_tir_num, u32 key_id, u32 resync_tcp_sn, @@ -80,19 +76,17 @@ mlx5e_ktls_build_static_params(struct mlx5e_set_tls_static_params_wqe *wqe, struct mlx5_wqe_umr_ctrl_seg *ucseg = &wqe->uctrl; struct mlx5_wqe_ctrl_seg *cseg = &wqe->ctrl; u8 opmod = direction == TLS_OFFLOAD_CTX_DIR_TX ? - MLX5_OPC_MOD_TLS_TIS_STATIC_PARAMS : - MLX5_OPC_MOD_TLS_TIR_STATIC_PARAMS; - -#define STATIC_PARAMS_DS_CNT DIV_ROUND_UP(sizeof(*wqe), MLX5_SEND_WQE_DS) + MLX5_OPC_MOD_TRANSPORT_TIS_STATIC_PARAMS : + MLX5_OPC_MOD_TRANSPORT_TIR_STATIC_PARAMS; cseg->opmod_idx_opcode = cpu_to_be32((pc << 8) | MLX5_OPCODE_UMR | (opmod << 24)); cseg->qpn_ds = cpu_to_be32((sqn << MLX5_WQE_CTRL_QPN_SHIFT) | - STATIC_PARAMS_DS_CNT); + MLX5E_TRANSPORT_STATIC_PARAMS_DS_CNT); cseg->fm_ce_se = fence ? MLX5_FENCE_MODE_INITIATOR_SMALL : 0; cseg->tis_tir_num = cpu_to_be32(tis_tir_num << 8); ucseg->flags = MLX5_UMR_INLINE; - ucseg->bsf_octowords = cpu_to_be16(MLX5_ST_SZ_BYTES(tls_static_params) / 16); + ucseg->bsf_octowords = cpu_to_be16(MLX5E_TRANSPORT_STATIC_PARAMS_OCTWORD_SIZE); fill_static_params(&wqe->params, crypto_info, key_id, resync_tcp_sn); } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_utils.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_utils.h index 3d79cd379890..5e2d186778aa 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_utils.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_utils.h @@ -6,6 +6,7 @@ #include #include "en.h" +#include "en_accel/common_utils.h" enum { MLX5E_TLS_PROGRESS_PARAMS_AUTH_STATE_NO_OFFLOAD = 0, @@ -33,13 +34,6 @@ union mlx5e_crypto_info { struct tls12_crypto_info_aes_gcm_256 crypto_info_256; }; -struct mlx5e_set_tls_static_params_wqe { - struct mlx5_wqe_ctrl_seg ctrl; - struct mlx5_wqe_umr_ctrl_seg uctrl; - struct mlx5_mkey_seg mkc; - struct mlx5_wqe_tls_static_params_seg params; -}; - struct mlx5e_set_tls_progress_params_wqe { struct mlx5_wqe_ctrl_seg ctrl; struct mlx5_wqe_tls_progress_params_seg params; @@ -50,19 +44,12 @@ struct mlx5e_get_tls_progress_params_wqe { struct mlx5_seg_get_psv psv; }; -#define MLX5E_TLS_SET_STATIC_PARAMS_WQEBBS \ - (DIV_ROUND_UP(sizeof(struct mlx5e_set_tls_static_params_wqe), MLX5_SEND_WQE_BB)) - #define MLX5E_TLS_SET_PROGRESS_PARAMS_WQEBBS \ (DIV_ROUND_UP(sizeof(struct mlx5e_set_tls_progress_params_wqe), MLX5_SEND_WQE_BB)) #define MLX5E_KTLS_GET_PROGRESS_WQEBBS \ (DIV_ROUND_UP(sizeof(struct mlx5e_get_tls_progress_params_wqe), MLX5_SEND_WQE_BB)) -#define MLX5E_TLS_FETCH_SET_STATIC_PARAMS_WQE(sq, pi) \ - ((struct mlx5e_set_tls_static_params_wqe *)\ - mlx5e_fetch_wqe(&(sq)->wq, pi, sizeof(struct mlx5e_set_tls_static_params_wqe))) - #define MLX5E_TLS_FETCH_SET_PROGRESS_PARAMS_WQE(sq, pi) \ ((struct mlx5e_set_tls_progress_params_wqe *)\ mlx5e_fetch_wqe(&(sq)->wq, pi, sizeof(struct mlx5e_set_tls_progress_params_wqe))) @@ -76,7 +63,7 @@ struct mlx5e_get_tls_progress_params_wqe { mlx5e_fetch_wqe(&(sq)->wq, pi, sizeof(struct mlx5e_dump_wqe))) void -mlx5e_ktls_build_static_params(struct mlx5e_set_tls_static_params_wqe *wqe, +mlx5e_ktls_build_static_params(struct mlx5e_set_transport_static_params_wqe *wqe, u16 pc, u32 sqn, union mlx5e_crypto_info *crypto_info, u32 tis_tir_num, u32 key_id, u32 resync_tcp_sn, diff --git a/include/linux/mlx5/device.h b/include/linux/mlx5/device.h index 01275c6e8468..66783d63ab97 100644 --- a/include/linux/mlx5/device.h +++ b/include/linux/mlx5/device.h @@ -454,8 +454,8 @@ enum { }; enum { - MLX5_OPC_MOD_TLS_TIS_STATIC_PARAMS = 0x1, - MLX5_OPC_MOD_TLS_TIR_STATIC_PARAMS = 0x2, + MLX5_OPC_MOD_TRANSPORT_TIS_STATIC_PARAMS = 0x1, + MLX5_OPC_MOD_TRANSPORT_TIR_STATIC_PARAMS = 0x2, }; enum { @@ -463,8 +463,8 @@ enum { MLX5_OPC_MOD_TLS_TIR_PROGRESS_PARAMS = 0x2, }; -struct mlx5_wqe_tls_static_params_seg { - u8 ctx[MLX5_ST_SZ_BYTES(tls_static_params)]; +struct mlx5_wqe_transport_static_params_seg { + u8 ctx[MLX5_ST_SZ_BYTES(transport_static_params)]; }; struct mlx5_wqe_tls_progress_params_seg { diff --git a/include/linux/mlx5/mlx5_ifc.h b/include/linux/mlx5/mlx5_ifc.h index 7f5e846eb46d..3ae272948dda 100644 --- a/include/linux/mlx5/mlx5_ifc.h +++ b/include/linux/mlx5/mlx5_ifc.h @@ -12409,12 +12409,16 @@ enum { MLX5_GENERAL_OBJECT_TYPE_ENCRYPTION_KEY_PURPOSE_MACSEC = 0x4, }; -struct mlx5_ifc_tls_static_params_bits { +enum { + MLX5_TRANSPORT_STATIC_PARAMS_ACC_TYPE_TLS = 0x1, +}; + +struct mlx5_ifc_transport_static_params_bits { u8 const_2[0x2]; u8 tls_version[0x4]; u8 const_1[0x2]; u8 reserved_at_8[0x14]; - u8 encryption_standard[0x4]; + u8 acc_type[0x4]; u8 reserved_at_20[0x20]; From patchwork Wed Feb 28 12:57:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575452 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2064.outbound.protection.outlook.com [40.107.243.64]) (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 8425814A081 for ; Wed, 28 Feb 2024 12:58:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.64 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125129; cv=fail; b=nbIb63QPoih0/Vzs0FW1vZgCoyaePpPk7hPAgu/stIKtPO0ibRND4VsZt3ZBCtZ6kv7Lu92MC4CRjzGQXbvEOX/n/7PyEnvMFnLS/f2gxwXVozDfyY+6uKjW7PFXXNDmVlmf+xy9EpxH407dOg7igY9P8S/O5EwmSbzzMbhlkI8= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125129; c=relaxed/simple; bh=G4tg3p0PhmlQGKSKIsiKfoQ6Qi/0TG8zc84ii8dgLS4=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=JkcVa8lZg1XefNmxlMmjuZHBR5237PSqHUSHpcY+nyLE0RDth6ZEpV5ijuPiuCMqcmZJb3jSFrCsG8hjk2oNIyTXkqh7bBzF1mKdsdfH8KfeqC+1lXHtljfOde+RBFjPRiOcDL1CH2PId3KGCMRN2yzU6alolTpIh9aH8aEy27c= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=Z/culZm1; arc=fail smtp.client-ip=40.107.243.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Z/culZm1" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eQbwHXB/NOFCLE3u11i4LBlGUQoxVNVEcRaCxfoTrOOjyno/41UoqdHaKRpBkjJvhWfOVl+nkgseAu0woJX2GaUW6qIkoqmatZx4ujbGPrMt/W0e5+UechZq/sQIkdaNz62PHPNNddDoDLe5cmJS6VvmJzXclh2Y3anDdiJ73z4lTCIH6+38urjDYA/lfXQtgeFqg3QJPA4XU115BYA007JTg2/UAMz3Q3QX6i9jYIf6Jbgqz8Kw2SqZ7yBB/4veZXLO1lm8jwiuGXJNx/krNuqfvhzU3Jequub6eOptFkmBJKUhDBmuVl75pFrCzVFnLIgwJq1UusFyrI8GwjzjoQ== 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=OuGh3Cu/0s5UODkQpuU5t6sxs9SmT8bXd3q3YxzoiVU=; b=ZDkp+Ssvzj87w6cT+hMGkersyMV+Uv0lM4cYvLtBMSAlJ0kayRczYSJeOWy+6k4TBx3oQJIRMReXVfrXqW2Gv/FU0cDAs53ia4utB7dGNzfC4IJUrU4ppaY0fBFXog7SsvF8MtaxZOZjyZ4dUT1ie8287cdbuh6vwAJMt1lTASnTb8REzI0FjBNjqChLG/V/WpXf7T4hxU0S4buBfro8tYqvfAeVoGc0ePQ9Es+33FI/RG8liIlZnwmJQXT5NXt8vPrX2Vib1lSuJYEe/B6jIUZXfMVwH764NuN50FlL1IS9+1/7ZMhJM4NNGKZVENdDNxDh9UIY9nsMRltfuLVECw== 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=OuGh3Cu/0s5UODkQpuU5t6sxs9SmT8bXd3q3YxzoiVU=; b=Z/culZm1gP5D/p0HhOzwO/eNCH2tykbcvVJKdcWBqy7carwJEMGJMciqonBc9AKRYhyh/om072aYjYNYijFFuny0kExxhXSUmSzbG6VP44Z1QgKMbSZAih7b7RPAlXopSDELy5HWzkkKw4YdKMDETwO8+yMq+9IP6xIJW7mbjFcz6p0tHnQnfm8f1grNV6L2eCdV1Dm45N+VTGCBC50emOFUDxKujl3m4/uIM60ugeONrVCCPqGTynO50QQUcXCzJ8t+AQ0O4XiYjn1Ne2l6u1CFhfdK5chxzyQjSaNRQyA8t/eU7eo7/KcA9yFvpSc1i2i0zpI8P4pet68Oh1/WNA== 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 SA3PR12MB7859.namprd12.prod.outlook.com (2603:10b6:806:305::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.39; Wed, 28 Feb 2024 12:58:44 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:58:44 +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: Or Gerlitz , aaptel@nvidia.com, aurelien.aptel@gmail.com, smalin@nvidia.com, malin1024@gmail.com, yorayz@nvidia.com, borisp@nvidia.com, galshalom@nvidia.com, mgurtovoy@nvidia.com Subject: [PATCH v23 11/20] net/mlx5e: Refactor ico sq polling to get budget Date: Wed, 28 Feb 2024 12:57:24 +0000 Message-Id: <20240228125733.299384-12-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FR4P281CA0321.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:eb::13) 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_|SA3PR12MB7859:EE_ X-MS-Office365-Filtering-Correlation-Id: 88648672-15f2-4f7d-6b13-08dc385cfeb6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Phm6Dm038yWq95i1kIo8oVhqdXiGFi186+99yrwf4qYKo+7dDaoSPtu9XNPnt3Vn1CMuRV3nwk4CkVyJOgJPt9wVtXAna0ky0kHSu1NdKqWD5O1b4yrEqITyFYmyCeTsNBMjLL3gm6Sz5AnLqDZ9hp5HXyIgTcmCLkeinBi0ssBbnh0TolhoazcZJWZwBb61LTPMAe2Vdk/cKCuhvPRx06Q4oc4mp2Z6sFoNu3HG4buVDjLBY6YQn4EpKurItloAyLMEXdfBU1WOh5PPqZvDClWx2evBXGwRxj2DCOJXyQ/LUCZb1nS3IGts9sqiEC9IbibkXFFVsTgbdshaD/oyCYD96mnbkN6yjilPg3veumUQOyradQEI7E06fkRG/+Ogx8dQ4a2+IMi1YU9EQcCx3CnVWQ3q9iXPDf92yTVnIafkEYoEEpjxWuABsIH1AIW2tGJm/AYhxDlG24PZfkgZrxV6NcoTcwgnu0kr/ETy0KnZnjU3tggAiS97wkkVzXDWw9kmU7/HxU1cl3KIpRYfSR3m+/EvhMyhdVlNlNCSFr6DmN7dderjxXY+jA8Tssy5VfMmwIzSf09uHwqi36AnwDqOl3panZFaFWrkCSrmDwWDC1PRJnRberL9A2v+EfUDL0XblScr4bVNZOZJ4dQqYg== 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UMcMlUfr43g/x+Oc8OgsN4Ckrz9pU2LbJ5qx35NCrAPPFo0mPq6n8ycgLNotGKvYJmE2tfHVTdzH1fuWEED6y9z6EfaUlUvPYn5UovseVo0m40ahnwjqIfpfBNgYtId8yzptAuHELfOhaRydTTQY1p5r/5DXoQXrVsDuRVL0FiQRbDwFPd8iHHHfpUas0XcQZeD5wlEjJq3txQLdHsEaUw4hTS1iHD2tmYOSEXZ0KcQue8Fn83W/QZ54Em0+EmMCUJ714CCau7nS5GOthlROXeJyhsSbxvHkMhgOrpHx04x+LeZsQ+A3supqzbjxy+tKHEM2VyXP0l8rimCz7pdaD4kHs/dzq3d8g5jxyZ2qyeOiBD//v97OV3abhmOFu3gf1v+qypToSgDnrnAtUPOtlNEX1TumdM9FcUOaqNEScHwSDCW0skHkRx/rjHuSHMzB3whwVuhp/YvZgeCzsYJFMzj/bf2NL8VkpYHJyprttW1H/KFddPJPoSgjqxR+1nBoThzBsYOXW6njCIYWK5+VaJtpcCvsb5HZdjBXH6oGwN1BVd2hwWGjbA+A2DQOTcGLKHa3GfyAWW61aJJF53oQyQDgTOqlKfbEPHsKJt7zxxvxkgAwzp/8HCpWuEzAzuc7gvrw+j+R+hlyxJ2MaaelLT7nNbUeBhu4wbG5ZMTYWfaZNErN4RueJIT9ENnSf+L83i72JdjvmGD0CvWqON2ET2mHtLRfuh5/s6SzutyLnz8KzxTs2yHlsL+oL7uE2F9cqAosM5Dxqey7rZeT9Weua75zQitodjvG16PGbxPp0fLmbn8Dml7nmd6EfakrYJragwO87fSpfWRLt+nsGGXAqT7iwaOWYm6t8sosfkO0OSGsUU8AZpOj3R+HhtKCXOQI4p4+QarGTrch8KIzfkge2nyAyHhPvVxZBAW9seAzB4lh98vnRl77KoVJEoMtEDWgwrA7hMYrBdwvLjpG2LX73aP9zLcL7MuL42K2npzzzEvyST6CIaLmuuSlzUIUwlcDb/cU6MCRxmmQX++01uw/JRKsuPYexS+Ywns3Wji3VabbtwKSNMF0KU9kLlrI0PpEt8HbKutUVsqKlDjCPhYoKOoYfQfAIiy9cMXrCZJGEd82PM9m/ukxJx6ZuNjImth+ZBvBBRDu5md2IaX6Ma1nw+XPJ47uUcBOvn16PHW38iKDOx6XqTWRMyXWA/3NIqErspI4usH7pzYXaZhDZwCstJmN0ERT06Q6Smya/hXDQcKB0cP2xKAtWVJRQ/DMFOq4cCM2mUWdY4n5fvxpKcGgV9i170xBbeUllSCZz0kxs0vKpw6MPLci/6FGxx+/EG14+Bhy3WEQOmgdByTqOGe3uSeBgU2uP79Nc6KqiXmmcWHUfYDF8YAM0+uLUVbej2fzAVSY+gZUPB3UsWbV4T11bCWbWRC2aLBR2CdTva++tOlXhqOvpeAV5X8ia/f4sjyATpiZ2TBTGmIECKs81n6dXn1FhgqTko83r244K7ZL6wzQk9+Creydp9S6kwhIHyNsj05bKdDIhidvaDnCCE8MIaxgUJZE/HFpjGIWAQQSDK8ane+Vnidui346CXTc3TNE X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 88648672-15f2-4f7d-6b13-08dc385cfeb6 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:58:44.2310 (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: Q1v3Izde5kTqJW4m2rvHEKzcTrSH6OZ0EvEIx+Cs8bsO21w/dcDNGtOzNCDJBZQpy5kzAiUmPXT9sqP7aZrJeQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7859 X-Patchwork-Delegate: kuba@kernel.org From: Or Gerlitz The mlx5e driver uses ICO SQs for internal control operations which are not visible to the network stack, such as UMR mapping for striding RQ (MPWQ) and etc more cases. The upcoming nvmeotcp offload uses ico sq for umr mapping as part of the offload. As a pre-step for nvmeotcp ico sqs which have their own napi and need to comply with budget, add the budget as parameter to the polling of cqs related to ico sqs. The polling already stops after a limit is reached, so just have the caller to provide this limit as the budget. Additionnaly, we move the mdev pointer directly on the icosq structure. This provides better separation between channels to ICO SQs for use-cases where they are not tightly coupled (such as the upcoming nvmeotcp code). No functional change here. Signed-off-by: Or Gerlitz Signed-off-by: Aurelien Aptel Reviewed-by: Tariq Toukan --- drivers/net/ethernet/mellanox/mlx5/core/en.h | 1 + drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c | 4 ++-- drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h | 2 +- drivers/net/ethernet/mellanox/mlx5/core/en_main.c | 5 ++--- drivers/net/ethernet/mellanox/mlx5/core/en_rx.c | 4 ++-- drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c | 4 ++-- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h index 55c6ace0acd5..714af3a451fd 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h @@ -556,6 +556,7 @@ struct mlx5e_icosq { /* control path */ struct mlx5_wq_ctrl wq_ctrl; struct mlx5e_channel *channel; + struct mlx5_core_dev *mdev; struct work_struct recover_work; } ____cacheline_aligned_in_smp; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c index 4358798d6ce1..9cde6ce17992 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/reporter_rx.c @@ -46,7 +46,7 @@ static int mlx5e_query_rq_state(struct mlx5_core_dev *dev, u32 rqn, u8 *state) static int mlx5e_wait_for_icosq_flush(struct mlx5e_icosq *icosq) { - struct mlx5_core_dev *dev = icosq->channel->mdev; + struct mlx5_core_dev *dev = icosq->mdev; unsigned long exp_time; exp_time = jiffies + msecs_to_jiffies(mlx5_tout_ms(dev, FLUSH_ON_ERROR)); @@ -91,7 +91,7 @@ static int mlx5e_rx_reporter_err_icosq_cqe_recover(void *ctx) rq = &icosq->channel->rq; if (test_bit(MLX5E_RQ_STATE_ENABLED, &icosq->channel->xskrq.state)) xskrq = &icosq->channel->xskrq; - mdev = icosq->channel->mdev; + mdev = icosq->mdev; dev = icosq->channel->netdev; err = mlx5_core_query_sq_state(mdev, icosq->sqn, &state); if (err) { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h b/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h index 879d698b6119..cdd7fbf218ae 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h @@ -62,7 +62,7 @@ void mlx5e_trigger_irq(struct mlx5e_icosq *sq); void mlx5e_completion_event(struct mlx5_core_cq *mcq, struct mlx5_eqe *eqe); void mlx5e_cq_error_event(struct mlx5_core_cq *mcq, enum mlx5_event event); int mlx5e_napi_poll(struct napi_struct *napi, int budget); -int mlx5e_poll_ico_cq(struct mlx5e_cq *cq); +int mlx5e_poll_ico_cq(struct mlx5e_cq *cq, int budget); /* RX */ INDIRECT_CALLABLE_DECLARE(bool mlx5e_post_rx_wqes(struct mlx5e_rq *rq)); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index be809556b2e1..039fe9252c4d 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -1512,6 +1512,7 @@ static int mlx5e_alloc_icosq(struct mlx5e_channel *c, int err; sq->channel = c; + sq->mdev = mdev; sq->uar_map = mdev->mlx5e_res.hw_objs.bfreg.map; sq->reserved_room = param->stop_room; @@ -1912,11 +1913,9 @@ void mlx5e_deactivate_icosq(struct mlx5e_icosq *icosq) static void mlx5e_close_icosq(struct mlx5e_icosq *sq) { - struct mlx5e_channel *c = sq->channel; - if (sq->ktls_resync) mlx5e_ktls_rx_resync_destroy_resp_list(sq->ktls_resync); - mlx5e_destroy_sq(c->mdev, sq->sqn); + mlx5e_destroy_sq(sq->mdev, sq->sqn); mlx5e_free_icosq_descs(sq); mlx5e_free_icosq(sq); } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c index d601b5faaed5..780902f63823 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c @@ -993,7 +993,7 @@ static void mlx5e_handle_shampo_hd_umr(struct mlx5e_shampo_umr umr, shampo->ci = (shampo->ci + umr.len) & (shampo->hd_per_wq - 1); } -int mlx5e_poll_ico_cq(struct mlx5e_cq *cq) +int mlx5e_poll_ico_cq(struct mlx5e_cq *cq, int budget) { struct mlx5e_icosq *sq = container_of(cq, struct mlx5e_icosq, cq); struct mlx5_cqe64 *cqe; @@ -1068,7 +1068,7 @@ int mlx5e_poll_ico_cq(struct mlx5e_cq *cq) wi->wqe_type); } } while (!last_wqe); - } while ((++i < MLX5E_TX_CQ_POLL_BUDGET) && (cqe = mlx5_cqwq_get_cqe(&cq->wq))); + } while ((++i < budget) && (cqe = mlx5_cqwq_get_cqe(&cq->wq))); sq->cc = sqcc; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c index a7d9b7cb4297..fd52311aada9 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_txrx.c @@ -178,8 +178,8 @@ int mlx5e_napi_poll(struct napi_struct *napi, int budget) busy |= work_done == budget; - mlx5e_poll_ico_cq(&c->icosq.cq); - if (mlx5e_poll_ico_cq(&c->async_icosq.cq)) + mlx5e_poll_ico_cq(&c->icosq.cq, MLX5E_TX_CQ_POLL_BUDGET); + if (mlx5e_poll_ico_cq(&c->async_icosq.cq, MLX5E_TX_CQ_POLL_BUDGET)) /* Don't clear the flag if nothing was polled to prevent * queueing more WQEs and overflowing the async ICOSQ. */ From patchwork Wed Feb 28 12:57:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575453 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2055.outbound.protection.outlook.com [40.107.243.55]) (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 2621614A081 for ; Wed, 28 Feb 2024 12:58:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.55 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125132; cv=fail; b=lDNlWNHod+p7lRMxKk17pwXDEOKFtSZLlzPpgdq3jqQrrJ17Aacsr9r2oWU7Jq24mPukqeZ5q+xR+gKMfWTYBdUsDWqMAhDgFIg4qXeiWoTI+DA/VSCzMfpJtWGFmMyuTHOUKF4K/I0WmidgxxkN5kxucxLWkxurrn4b7XqVTa4= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125132; c=relaxed/simple; bh=IL4i6JcLJiu6TWhrhd2SBUo058JpWg4uPOHsqcbTp98=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=mP82nAstIMn9VUCtLN9ASLoYj0+LcGIFVPan3Wxv0jfCwb8Y9WOGGgFrOOnA2uVaI2l1xw463eF1TL654f2QgQ8GXsFla/zyyCRStBkXS2Nw4ACb9Nhn6qRSHA/KSbtdN7Eo+QwP+uCg4qsdaMwL2jGSOVI1OMo/pyS3Iq39Lug= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=eEjcKXaF; arc=fail smtp.client-ip=40.107.243.55 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="eEjcKXaF" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TMm2j/tSl4TgTwa5BaXs4kni3BRmP66JWE8UBOz/NmJdqtIMTp3eyCqwCmgTxok9BpCaluDmphMPRE49iUclGGbXa2rxUr8o6hKjXBvluFka2l6eySKcnvCoAK1tinDmCBfWoaUAsygTBw7+r0GUS+Yi6VhYmFmeKQ7lPzPgVt+d26Qx2EdCMeVOUOMRHtZZq1uqbt3YpxO4p4JaSVDuRvq9svrY5AwEzBUK0fTwf98LsCUZnsNt/QQhwQzKmVg8kcoatlr7j03vKXlqP3gyINaEv6D1CcnS56oaLMYItD5bCgVNf7Xgx5nDxq38+XzxMb8kofOoWPf99TD3eKrPiA== 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=UBkrPrG8UItm1RjlenMy2WAYh6IiSxPhUc4LOLGGj0Q=; b=K6Vu7vqS0akhx48Ej1xFKNB985L9dzqga+vKQEBY9WWUdIcOvVQ3p5byL9A2KjGmMKk8r42gFWifENqIyfiuRY6WzItKR/W+uAPjQ+6FHr/I/Y+EX1UiVdddOjjxAT/wetC0NgPWj3jFRcYRdChCqmaH9XsAkk3WcxOF6zJfbzVDNzhbmYuNeNg2Wvl9Kkkp9OgaQIXwCkZ8JQI7l9sJDKnkfCKRsck7A3JU3X/FhDf0+MQV9aJLaNaukPldqXXbFhap+tvKizOcwPoR3H9+epjHSfpvtCcuH6fk0Pfy1n54vsUqNklwTPvc9rhIEdYGdys2fQYa+IMSzflo2Br34Q== 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=UBkrPrG8UItm1RjlenMy2WAYh6IiSxPhUc4LOLGGj0Q=; b=eEjcKXaFT+1qRZ9S04038EdtapWVCavGtLdebbnf+vwki42elZI0Jnnex7m9gsHowz3ty4TChwYpvm2bjhCRgOlaNU9dFPNu53wNCKdemOXI12+L7Y5vHPW8dartELty6Cr3ana2UTOB3fhhYo7De2FjAFydR6jwQEZ32sQNRA9fWBDaBBW2dM2/pgE0p/x1WfIyD4zy/+aj7CrXJIUTMXazdUdeWMXCSIpIxNJtssTuqSZzG96av2eF2Ew6rTWmcd342xVFBhH+jmKpK0phBnWEuu/zMMw5BBQBJvDh6fWPrQO17QIp81Y4DzT9daQM1Lni7H5eGiYD3j5/VKjOVA== 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 SA3PR12MB7859.namprd12.prod.outlook.com (2603:10b6:806:305::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.39; Wed, 28 Feb 2024 12:58:48 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:58:48 +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: aaptel@nvidia.com, 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 Subject: [PATCH v23 12/20] net/mlx5: Add NVMEoTCP caps, HW bits, 128B CQE and enumerations Date: Wed, 28 Feb 2024 12:57:25 +0000 Message-Id: <20240228125733.299384-13-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FR4P281CA0082.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:cd::12) 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_|SA3PR12MB7859:EE_ X-MS-Office365-Filtering-Correlation-Id: be6504f5-15ab-41f2-4423-08dc385d0120 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: eV0F7lpFlbhBG8TUkftpNPvgVqttrOligHleZvTnBDjmh79ukslLhGbh1t5Tw63wydQODIHRtX2KGilCCTGID/S/GXwE42qAvaL0+/QhRVKKf1rG+mPRgK7U1D8gTaftCv9AgW4pqo52qxgDZVjLLJEqEugmgy7dRko86r8nl1PfGlzESaRJT/VBDHVTAzVP21fLE/3/Sn7oMD5kbn0YdWdnQBsUxRJWKkgtjZC1yZvRLExfEzDtz1O2Wix4QtU1Plle7n7mCfmkCX5UkfL1Yef41XCRhw78q9WNf5EKhPWN2lmv54IV0RzIRMXflfIe4zAK692SbatknUtvlhn5dWZxKQeYpm4AChHtzNqMD2WoYbAavFcHFgStzlO77Gq8eHZ3iI5bTaCfzEGY5bMpo+qiMB+XIJ/snblNQxIm+C0k6K3LgrVVe4A9XKGTz4d2JjLY9FHeZg5virLt5leAYeSKMyrHTielXsW7jX1WKUA7hUfj7s5wXcrqMT3oPzRX07deGSnSPtz1OoBJfSDRJXJEow0L2PUpePosQBFKcOHuE1QKkXh/HNNbCfajQUlkqKz7yt1U8ki4JBO+1KvpcElzgz4IzYFSTM4IzHPNCYbot7Y1pgVbf1QhOc3kq40n 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PcrCQVgNL0ykNBb9WpzWYLg3FOzbv007HbrBOmd3ZSkMxkYzLxdMgATnLCGkNOflLAfxzPsITMQ/xpm18XDUKupAxfku24UJNzYt4UrGCXgcoDBSsGzrj6p+EiJIycRJ+xDrvqRcMTLczNxO+nZifQBOjdlMuEUh5WtIL4yEJr6F87Cg3YHbvfhOl0v4PAosoy3c5fgEJ43XguerF7If5ZiON9fXmfhraySXsb+8py24YsH6pljRXpUp3QMwduPOYTV4FvIJX3nvNczeSRjIyZo0S6ihrVVCTZKdiSmMAKBkzIo65TK/AQr/Jsr7NfdeG52sbFgOJYrVDBoltNRYIdGY1gkDxj4hnrDrIuLpS73nXQ+F7CWl+wqfc4g5R1WWcbdgCSkdGp0rGepGYZ5c0T2WyPjhsBxpb0Jx7DyjOab/VVm2xEiSfJsVYfVjAy1AX5ranWuHIs0t/TRK6apxEKUz8z3kfZHraf9lDf9vyjLY0msN8RF3461/Wl+q47+0ksX8jM+vB/1bVrnSNDdyQFhK1BC1k16pXGvbuRuB30z7csFKbSqBu7GFFCtRDdGUl/5xENqS0sBVnmkhohuddr6B+PMD/IR4S65lMfNYHe/8cyYvwRHPlMjs19B+XqohtUraei8KDENqd3O+WV89WBDrMRwEWXM4OYX7HRAxu7gbKsgFS0M5y0I75MhY0pxvuy0Hf3LRH6lnNNdvAJjSXhdWdJLIsHU61/IqMS30Hu981XJ1skViEmp9VD3pHo5oOJDkBPCrq/A8yFRRUGbwe5PdVbDOvMc3Xo45MQFWIPUXrRipdvR3WUVo+UcSjz4QPVhMBnQNwOwIjrV4rXLZK/ZuC/6qgMV9u8T9C4PoYUVI/rWWXrdva7VNVMzN+w0cUVU1CXNRKq2XUnoU7NHShRY6b/Q7fr74QzpMh8ESRJNi/UBcfbHQo0l4e2pgJ7VZZTuamrUVo+3ymWFFQ+QI1/WenxLA7KbPjJheaf5I85hiwe62BiI4QfuasiasEiot7Vaem+EWrKQqD4pwgX9vmPewnMBt92zZKpi2shq6rRiFkywAAURY2GHzfkedPC7kiX4kLuxK0QtDXUZUeFqhWtmyTFb1PfhGOBbaBBtAtXCy60Vnp9Ds59O/e1mzRPEzMHR+opEqZrR0+k5u/Mumm2v1wqKr9QZToH9pUV+9tgC0/qOTluGALnbxlKwRbNl7pNZDFGsiHj0daQQMEJPduRylhDFlUS24cTYcz3g897RGK0M1Ked5zLaP3TCCgqwHKIInitIDmObhNsTVw2g75Ah4I7TwO2A1GdIL7lTuX31boIIhgk3Ps+U7WdzAD3KWvnTAPqaaPh8+umt0/7bBcACE1BbQddT2Tx9lmMwPT/EEAFVGiK9IYFtke5hVGu0ZPiAeHOkfy8u5Yqr9L3yH7pcmBy48TQ7NInk+aDl+eGGkLlwaE5Hr8zqrnTgWce1XerEEEBjSXRKMj+aIxVozh5n6Xpk61Ul4YQJBzKwCZ+gvmCb30wyzXghsMXbOYw6Vqz6eloYni/ALac7UNWeSniTpuME595qdml4VoBvM3tLm/CC1edhFWL8VxtKcoL8a X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: be6504f5-15ab-41f2-4423-08dc385d0120 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:58:48.2865 (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: HJOFfa6s2KvM1Gc1iU3YsTMfAjCIJJTxml84Fu+BOfHzDhU+OjWm64DiVPqYgYf6HDC8ugMeU1ugAVqHdx/h8A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7859 X-Patchwork-Delegate: kuba@kernel.org From: Ben Ben-Ishay Add the necessary infrastructure for NVMEoTCP offload: - Create mlx5_cqe128 structure for NVMEoTCP offload. The new structure consist from the regular mlx5_cqe64 + NVMEoTCP data information for offloaded packets. - Add nvmetcp field to mlx5_cqe64, this field define the type of the data that the additional NVMEoTCP part represents. - Add nvmeotcp_zero_copy_en + nvmeotcp_crc_en bit to the TIR, for identify NVMEoTCP offload flow and tag_buffer_id that will be used by the connected nvmeotcp_queues. - Add new capability to HCA_CAP that represents the NVMEoTCP offload ability. Signed-off-by: Ben Ben-Ishay Signed-off-by: Or Gerlitz Signed-off-by: Aurelien Aptel Reviewed-by: Tariq Toukan --- drivers/net/ethernet/mellanox/mlx5/core/fw.c | 6 ++ include/linux/mlx5/device.h | 51 ++++++++++++- include/linux/mlx5/mlx5_ifc.h | 75 ++++++++++++++++++-- include/linux/mlx5/qp.h | 1 + 4 files changed, 128 insertions(+), 5 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/fw.c b/drivers/net/ethernet/mellanox/mlx5/core/fw.c index e7faf7e73ca4..b76aafa679f6 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/fw.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/fw.c @@ -280,6 +280,12 @@ int mlx5_query_hca_caps(struct mlx5_core_dev *dev) return err; } + if (MLX5_CAP_GEN(dev, nvmeotcp)) { + err = mlx5_core_get_caps(dev, MLX5_CAP_DEV_NVMEOTCP); + if (err) + return err; + } + return 0; } diff --git a/include/linux/mlx5/device.h b/include/linux/mlx5/device.h index 66783d63ab97..99cea3707bbc 100644 --- a/include/linux/mlx5/device.h +++ b/include/linux/mlx5/device.h @@ -264,6 +264,7 @@ enum { enum { MLX5_MKEY_MASK_LEN = 1ull << 0, MLX5_MKEY_MASK_PAGE_SIZE = 1ull << 1, + MLX5_MKEY_MASK_XLT_OCT_SIZE = 1ull << 2, MLX5_MKEY_MASK_START_ADDR = 1ull << 6, MLX5_MKEY_MASK_PD = 1ull << 7, MLX5_MKEY_MASK_EN_RINVAL = 1ull << 8, @@ -798,7 +799,11 @@ struct mlx5_err_cqe { struct mlx5_cqe64 { u8 tls_outer_l3_tunneled; - u8 rsvd0; + u8 rsvd16bit:4; + u8 nvmeotcp_zc:1; + u8 nvmeotcp_ddgst:1; + u8 nvmeotcp_resync:1; + u8 rsvd23bit:1; __be16 wqe_id; union { struct { @@ -847,6 +852,19 @@ struct mlx5_cqe64 { u8 op_own; }; +struct mlx5e_cqe128 { + __be16 cclen; + __be16 hlen; + union { + __be32 resync_tcp_sn; + __be32 ccoff; + }; + __be16 ccid; + __be16 rsvd8; + u8 rsvd12[52]; + struct mlx5_cqe64 cqe64; +}; + struct mlx5_mini_cqe8 { union { __be32 rx_hash_result; @@ -882,6 +900,28 @@ enum { #define MLX5_MINI_CQE_ARRAY_SIZE 8 +static inline bool cqe_is_nvmeotcp_resync(struct mlx5_cqe64 *cqe) +{ + return cqe->nvmeotcp_resync; +} + +static inline bool cqe_is_nvmeotcp_crcvalid(struct mlx5_cqe64 *cqe) +{ + return cqe->nvmeotcp_ddgst; +} + +static inline bool cqe_is_nvmeotcp_zc(struct mlx5_cqe64 *cqe) +{ + return cqe->nvmeotcp_zc; +} + +/* check if cqe is zc or crc or resync */ +static inline bool cqe_is_nvmeotcp(struct mlx5_cqe64 *cqe) +{ + return cqe_is_nvmeotcp_zc(cqe) || cqe_is_nvmeotcp_crcvalid(cqe) || + cqe_is_nvmeotcp_resync(cqe); +} + static inline u8 mlx5_get_cqe_format(struct mlx5_cqe64 *cqe) { return (cqe->op_own >> 2) & 0x3; @@ -1222,6 +1262,7 @@ enum mlx5_cap_type { MLX5_CAP_VDPA_EMULATION = 0x13, MLX5_CAP_DEV_EVENT = 0x14, MLX5_CAP_IPSEC, + MLX5_CAP_DEV_NVMEOTCP = 0x19, MLX5_CAP_CRYPTO = 0x1a, MLX5_CAP_MACSEC = 0x1f, MLX5_CAP_GENERAL_2 = 0x20, @@ -1429,6 +1470,14 @@ enum mlx5_qcam_feature_groups { #define MLX5_CAP_MACSEC(mdev, cap)\ MLX5_GET(macsec_cap, (mdev)->caps.hca[MLX5_CAP_MACSEC]->cur, cap) +#define MLX5_CAP_DEV_NVMEOTCP(mdev, cap)\ + MLX5_GET(nvmeotcp_cap, \ + (mdev)->caps.hca[MLX5_CAP_DEV_NVMEOTCP]->cur, cap) + +#define MLX5_CAP64_DEV_NVMEOTCP(mdev, cap)\ + MLX5_GET64(nvmeotcp_cap, \ + (mdev)->caps.hca[MLX5_CAP_DEV_NVMEOTCP]->cur, cap) + enum { MLX5_CMD_STAT_OK = 0x0, MLX5_CMD_STAT_INT_ERR = 0x1, diff --git a/include/linux/mlx5/mlx5_ifc.h b/include/linux/mlx5/mlx5_ifc.h index 3ae272948dda..193e56ee9265 100644 --- a/include/linux/mlx5/mlx5_ifc.h +++ b/include/linux/mlx5/mlx5_ifc.h @@ -1468,6 +1468,20 @@ enum { MLX5_STEERING_FORMAT_CONNECTX_7 = 2, }; +struct mlx5_ifc_nvmeotcp_cap_bits { + u8 zerocopy[0x1]; + u8 crc_rx[0x1]; + u8 crc_tx[0x1]; + u8 reserved_at_3[0x15]; + u8 version[0x8]; + + u8 reserved_at_20[0x13]; + u8 log_max_nvmeotcp_tag_buffer_table[0x5]; + u8 reserved_at_38[0x3]; + u8 log_max_nvmeotcp_tag_buffer_size[0x5]; + u8 reserved_at_40[0x7c0]; +}; + struct mlx5_ifc_cmd_hca_cap_bits { u8 reserved_at_0[0x10]; u8 shared_object_to_user_object_allowed[0x1]; @@ -1492,7 +1506,9 @@ struct mlx5_ifc_cmd_hca_cap_bits { u8 event_cap[0x1]; u8 reserved_at_91[0x2]; u8 isolate_vl_tc_new[0x1]; - u8 reserved_at_94[0x4]; + u8 reserved_at_94[0x2]; + u8 nvmeotcp[0x1]; + u8 reserved_at_97[0x1]; u8 prio_tag_required[0x1]; u8 reserved_at_99[0x2]; u8 log_max_qp[0x5]; @@ -3494,6 +3510,7 @@ union mlx5_ifc_hca_cap_union_bits { struct mlx5_ifc_macsec_cap_bits macsec_cap; struct mlx5_ifc_crypto_cap_bits crypto_cap; struct mlx5_ifc_ipsec_cap_bits ipsec_cap; + struct mlx5_ifc_nvmeotcp_cap_bits nvmeotcp_cap; u8 reserved_at_0[0x8000]; }; @@ -3746,7 +3763,9 @@ struct mlx5_ifc_tirc_bits { u8 disp_type[0x4]; u8 tls_en[0x1]; - u8 reserved_at_25[0x1b]; + u8 nvmeotcp_zero_copy_en[0x1]; + u8 nvmeotcp_crc_en[0x1]; + u8 reserved_at_27[0x19]; u8 reserved_at_40[0x40]; @@ -3777,7 +3796,8 @@ struct mlx5_ifc_tirc_bits { struct mlx5_ifc_rx_hash_field_select_bits rx_hash_field_selector_inner; - u8 reserved_at_2c0[0x4c0]; + u8 nvmeotcp_tag_buffer_table_id[0x20]; + u8 reserved_at_2e0[0x4a0]; }; enum { @@ -12018,6 +12038,7 @@ enum { MLX5_HCA_CAP_GENERAL_OBJECT_TYPES_ENCRYPTION_KEY = BIT_ULL(0xc), MLX5_HCA_CAP_GENERAL_OBJECT_TYPES_IPSEC = BIT_ULL(0x13), MLX5_HCA_CAP_GENERAL_OBJECT_TYPES_SAMPLER = BIT_ULL(0x20), + MLX5_HCA_CAP_GENERAL_OBJECT_TYPES_NVMEOTCP_TAG_BUFFER_TABLE = BIT_ULL(0x21), MLX5_HCA_CAP_GENERAL_OBJECT_TYPES_FLOW_METER_ASO = BIT_ULL(0x24), }; @@ -12025,6 +12046,7 @@ enum { MLX5_GENERAL_OBJECT_TYPES_ENCRYPTION_KEY = 0xc, MLX5_GENERAL_OBJECT_TYPES_IPSEC = 0x13, MLX5_GENERAL_OBJECT_TYPES_SAMPLER = 0x20, + MLX5_GENERAL_OBJECT_TYPES_NVMEOTCP_TAG_BUFFER_TABLE = 0x21, MLX5_GENERAL_OBJECT_TYPES_FLOW_METER_ASO = 0x24, MLX5_GENERAL_OBJECT_TYPES_MACSEC = 0x27, MLX5_GENERAL_OBJECT_TYPES_INT_KEK = 0x47, @@ -12398,6 +12420,20 @@ struct mlx5_ifc_query_sampler_obj_out_bits { struct mlx5_ifc_sampler_obj_bits sampler_object; }; +struct mlx5_ifc_nvmeotcp_tag_buf_table_obj_bits { + u8 modify_field_select[0x40]; + + u8 reserved_at_40[0x20]; + + u8 reserved_at_60[0x1b]; + u8 log_tag_buffer_table_size[0x5]; +}; + +struct mlx5_ifc_create_nvmeotcp_tag_buf_table_in_bits { + struct mlx5_ifc_general_obj_in_cmd_hdr_bits general_obj_in_cmd_hdr; + struct mlx5_ifc_nvmeotcp_tag_buf_table_obj_bits nvmeotcp_tag_buf_table_obj; +}; + enum { MLX5_GENERAL_OBJECT_TYPE_ENCRYPTION_KEY_KEY_SIZE_128 = 0x0, MLX5_GENERAL_OBJECT_TYPE_ENCRYPTION_KEY_KEY_SIZE_256 = 0x1, @@ -12411,6 +12447,13 @@ enum { enum { MLX5_TRANSPORT_STATIC_PARAMS_ACC_TYPE_TLS = 0x1, + MLX5_TRANSPORT_STATIC_PARAMS_ACC_TYPE_NVMETCP = 0x2, + MLX5_TRANSPORT_STATIC_PARAMS_ACC_TYPE_NVMETCP_WITH_TLS = 0x3, +}; + +enum { + MLX5_TRANSPORT_STATIC_PARAMS_TI_INITIATOR = 0x0, + MLX5_TRANSPORT_STATIC_PARAMS_TI_TARGET = 0x1, }; struct mlx5_ifc_transport_static_params_bits { @@ -12433,7 +12476,20 @@ struct mlx5_ifc_transport_static_params_bits { u8 reserved_at_100[0x8]; u8 dek_index[0x18]; - u8 reserved_at_120[0xe0]; + u8 reserved_at_120[0x14]; + + u8 cccid_ttag[0x1]; + u8 ti[0x1]; + u8 zero_copy_en[0x1]; + u8 ddgst_offload_en[0x1]; + u8 hdgst_offload_en[0x1]; + u8 ddgst_en[0x1]; + u8 hddgst_en[0x1]; + u8 pda[0x5]; + + u8 nvme_resync_tcp_sn[0x20]; + + u8 reserved_at_160[0xa0]; }; struct mlx5_ifc_tls_progress_params_bits { @@ -12740,4 +12796,15 @@ struct mlx5_ifc_msees_reg_bits { u8 reserved_at_80[0x180]; }; +struct mlx5_ifc_nvmeotcp_progress_params_bits { + u8 next_pdu_tcp_sn[0x20]; + + u8 hw_resync_tcp_sn[0x20]; + + u8 pdu_tracker_state[0x2]; + u8 offloading_state[0x2]; + u8 reserved_at_44[0xc]; + u8 cccid_ttag[0x10]; +}; + #endif /* MLX5_IFC_H */ diff --git a/include/linux/mlx5/qp.h b/include/linux/mlx5/qp.h index bd53cf4be7bd..b72f08efe6de 100644 --- a/include/linux/mlx5/qp.h +++ b/include/linux/mlx5/qp.h @@ -227,6 +227,7 @@ struct mlx5_wqe_ctrl_seg { #define MLX5_WQE_CTRL_OPCODE_MASK 0xff #define MLX5_WQE_CTRL_WQE_INDEX_MASK 0x00ffff00 #define MLX5_WQE_CTRL_WQE_INDEX_SHIFT 8 +#define MLX5_WQE_CTRL_TIR_TIS_INDEX_SHIFT 8 enum { MLX5_ETH_WQE_L3_INNER_CSUM = 1 << 4, From patchwork Wed Feb 28 12:57:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575454 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2082.outbound.protection.outlook.com [40.107.243.82]) (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 658D3149DE2 for ; Wed, 28 Feb 2024 12:58:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125139; cv=fail; b=UBX2thNX9zQKRNnK9McgYMZ7HY5+EhuVbzQiEuLQtitAzpXs5PDUOtyN4Lw+RoHeCdJjS4cdv4kiaYvjrdRYZFf0a0GA6NQWjnPCjDQ/LE7NTklOG6gghEyioVG+CxVXROBpzKwKbfce2nOEAx49qvhRk0Of77RJSxdSILSeB/0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125139; c=relaxed/simple; bh=NdQOHDi7TalU1bDg9eymVZJujrb+Dq7dylqzqrLkJrY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=D2joPm7Vo6q0/nBZuDMUnvonM1Xox1MVty47+FQThil/tznhfnCu69f4MoBCtx6RBCgD00Ubsa7th8x4nDazsEzvMozFO4OfvboG/j6JEAp8VCKPG9mKulVhP11NahANNDByiuaeHLMy0AJqOaKYL8N+s6v8ygOcIUYep26xGoM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=WWilmX6o; arc=fail smtp.client-ip=40.107.243.82 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="WWilmX6o" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=nXm90todOgPvOGUBYA8TeCeZxmA/nATbNaNzjCfGwBWC3iXO2gAZMbPGiSi4bQGs8Cw1m85an47BfUdJVR431k4thGILmQaTRTB2GJbrOw5vAMvA9M9uLWHzUAfNA8Z6WaWl06qBZ4jQVEu2fYEyDzPmZY1yZQ5Ti1mWFTxpr7eZBcB3Pkl7+ZUJ8RMKWUWz7JdBlojF2Ru+Dq7A50nb2hSFTKbD8J5NgScb8gYoEotoqvDpSAgDlIVPd2fMIiw4I7Kb2CTtSGodSfLetFip/r1QzXX1d47nE00FZf8LtU2JtT+rqO65PhGdh0iow0KGTaGkLr0NoxWiRh5akHNT6A== 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=i4PjmerQef5w2bVOck4ferdBePbU4xCjfZ118/HSApE=; b=JkMsuZgqOVyrGV5MVt87Lz+KkjrAKetmRYsuGCFTsLMoFuBqf217aWV548ugZmfcTF5HikAjt5NcANlHXXiPj1c/FWDmglfCk1xKnNU4GtIIfEq6YAOaO5cXB8MoKOuNnpYxQt9ZdbkgL79GNweyobzDH2U90/qwDmtOKjny4vECibR32sC8lfUltMrcNQOfbyyZDVX1NShLpaoU8+PeAwT16e88gtyoYp6/qak3VHEW/iNvFYsV+cpbIDNpJsA4jkKelCZwCNO3Z9vmADOQ+un03lqWdxXe4Z/WNjwpNXN8xs+YXnnKUKd4CEMh5lPnl+KBO0lb+1Ndg7jnr0c29A== 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=i4PjmerQef5w2bVOck4ferdBePbU4xCjfZ118/HSApE=; b=WWilmX6o9Rxy6N4V5s2AzBlb1s8iaHuWJSCmJcKWcAlsbgXNPCsIUfbw3QhLp2oRMfRtQimjq14OeNEFDAMK39zfxQyF7Lt5M8gGBf/gMoH1BGI4OCpOFySP34DOh50OPYZgDyyofTIjLDYOX+VRo7/WtyusuK0oyFBuO4QFrcYM57X1Hbv8sJv6dV/1o5ocTGEvgc8zGOwhBSbzBEk70n/5fK+KM+dH+n7WtXwtmZiPCZir5cTxGFPi+V3c7Lyb3HPkO0MRv+ZUjQvgSO7drmjlsplGsDZvmcxC4SU0KAB2Jy5fMArlghmE4ujGsZkxJ5YNBx2wKb5sXf+ZaIPCUg== 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 SA3PR12MB7859.namprd12.prod.outlook.com (2603:10b6:806:305::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.39; Wed, 28 Feb 2024 12:58:53 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:58:53 +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: aaptel@nvidia.com, 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 Subject: [PATCH v23 13/20] net/mlx5e: NVMEoTCP, offload initialization Date: Wed, 28 Feb 2024 12:57:26 +0000 Message-Id: <20240228125733.299384-14-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FR2P281CA0115.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:9d::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_|SA3PR12MB7859:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e9b2ecf-878d-41c0-6969-08dc385d0438 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: /JISgw4AEb3PeFid6wACqR57HxQ/9SkHUjc2RE2b2HrTK5naOM/nYow560SAA4g256R0VkJLWLmUiiFEMBBAeW0wxeNVa3oUE3IOZo2s/FULWsj4KEP9FMNZCN83+txrTXx1kcVo2iBARglt9Z30kDBwH+ozkhV7PNoTE3VYDySwCBhhWpquRuUkyS0J6ItlwmFVDpL0Dvq9rQx+ZW/pXovt/wAYlmeUFe+0pJ9EgDqZxpLfWv6pGH/hJSUGXulx7m1yYOpFH8LQQjub6/rti6HkxA0RGimdqLgHogJlddn2myEGGU47VYk7DC7SsFIXX6z90Yy+kMogoMSdPZ8usEpCnHgWlzzl3bD69z7a7N0BFEFU9t08E/AyHNed5QCpWe34x3+G/gyj4U0qC0u3dWqQ7LjRu98H1kZIIEvyw0cXED9LuZw28U2ITGqJx5NyTVuxd8ry9NLKwhmbe+ZaJ0JGgC0zsuaiVPXp8Xwpupve9AvW6/9JJg4Q8fvX+kT1RSCXn0fyLAr/O8t6vZp+v+UlRl31uxZSgLmEV0M+Z1mAZFY/J2JrTcF0+z5dRuoecnu4u/OSEGYnXr76TVYp4YzEsS1uy/loYZ+a33HUoAeDHyLNBDiIthebeTI53Stm8JkAiB4ijLuRlbB8QTXg0w== 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: eUE5ICU0jEHAtgdTh+EfiqzMEVDWPf+moLltgH/CIYD2N+kS65jhqfuicKSTpqFN8WKKhnBmOzsv+MLD5+rx/LdivkoWipVAqm2q7ScubnohmnU0nRvboEdpPVxulSfaTcYo9Ro4YOoTRnJjWyl0TP+k6lZI1e4lkn2QQ8JU19xC0zPPcPD0MbYrHgXP7kpyiTZxDkNeoS2OyK74O8g/0cPjszl1QnHAiXHxFUd//gKWpQ73w2YKmSga+atoFQilo+L3W1ZhHUb7gSprKLdckRtCaomo+DnivcaIpvx+KHQWoHejjCtVLew+qaf8tqarq/ZxTEs1v93/WtyylkOJ1qH3cyhxsGWfkNUj3oeJahgsvrPoyygoc+B24I5PtqFIuJoinxipaNv3K3g59vSKNR8FkZBmf32fMyHBIK25eDmWliZumuJiqrHCqpkpSHjR1SJuxvSf2Nwf5IciF7IMBQHaTIBdz1Tvuz9yhXo0diarugIlD6OPBXi1NFS3F0HN7NWvAJRzFNQNa6XevU7OsVw3+juudS+bKY7X3/8Q9X7qTANwCUvAj7jyzseGA451b47wGd0k8RVVGihPyznqiM4aSn+8B48m0hKpLZ3kIYqY96ew3BBkv3oV9T0w5XkUEXddkMzh+R/pSQCVxDcDDzZzMOaHv7P8ZKF8yZILslXphDKivZHeTCSXeKkuTc70wmGz7AuUq6yvXzkNuo+sX1Vr1Q26bUXbxMYQII3TfmmRsY/4k1jp83mAoxz6pMPsAQUBgs93WOoSjqYgHQxWcFoQJBN7x3xriNNYk2XqN6vcFB9rLMnLNHGogfMJUM4ZN7JrWP4IglCdhcKIFVg+h0i8IV684K/xbT5/z7t8fVY443lHuv7RR2ZFIg0LAXswRjcEWKoKFgmKaopZZsYC1xsKg9jbnX2b1txf/+hPnwHWCf0Uz/S8GUp1u+LLTU/RC8U30jmGBf15nrq3DdLMO+uBHDUB109X7jKgwZp0hYSDygk12qVSlCHTHGlVwqlVXla2OmVuQIfhRb/3rVOxytVX3NFNV/tnCE95DZekM5IDyL+smxLZj6RQ34qB9IGWu89pJ2OemyDMtqDVf6+oj4dcMCaivVtbmZfVxMx15Czek5MBoc0WEZp/KZPIrI3FRmhDX7iEFFZSI02jTQ/0FS36TBCtnw+oZ81z3hr0arspf9XKXlOKmOk2E3VY3rAbNFJmivt66QJimh8IBehrXAfwmp7YGq2xEc/J/bQBKYrwPuJ0XCA6MxanJrJ4SD5NbBEAWNHBM7wHSg5nw7QSTkJYgE5GTyM/WONgb/Lm2Uo4zuTulW3c1TGxY/1BfoXNPKDLVPWY8R28gFwjhzPgYCUKcN/58YvFjIHGI3gAvUq9GQPpY5WFwctb/CuaQkKDDqXGByDxzjhwGwCAQuIo4YlsMzV5lLSII7eAscFe6FZEYWfxz7gpLJNuCYxKIImYcke7HYK5zoSEOxFwPHvGYvbHkC28MtUYorMGJhbSlIOEY04muntTOpTpZ1AOkotCluqre1boRcesz4v3IruwgMub+E3wTewmfvzbczmDvhtjQ5ZQYSeFvf88vIlDEVbr X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e9b2ecf-878d-41c0-6969-08dc385d0438 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:58:53.6311 (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: W9uHIZCN9ya9cCvbSIpgXziuegWFq2Jqn8eticpByy2pBCoGcSrF9OMNqauiqrKk8B4DSwixMcD2pZiYF+clfA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7859 X-Patchwork-Delegate: kuba@kernel.org From: Ben Ben-Ishay This commit introduces the driver structures and initialization blocks for NVMEoTCP offload. The mlx5 nvmeotcp structures are: - queue (mlx5e_nvmeotcp_queue) - pairs 1:1 with nvmeotcp driver queues and deals with the offloading parts. The mlx5e queue is accessed in the ddp ops: initialized on sk_add, used in ddp setup,teardown,resync and in the fast path when dealing with packets, destroyed in the sk_del op. - queue entry (nvmeotcp_queue_entry) - pairs 1:1 with offloaded IO from that queue. Keeps pointers to the SG elements describing the buffers used for the IO and the ddp context of it. - queue handler (mlx5e_nvmeotcp_queue_handler) - we use icosq per NVME-TCP queue for UMR mapping as part of the ddp offload. Those dedicated SQs are unique in the sense that they are driven directly by the NVME-TCP layer to submit and invalidate ddp requests. Since the life-cycle of these icosqs is not tied to the channels, we create dedicated napi contexts for polling them such that channels can be re-created during offloading. The queue handler has pointer to the cq associated with the queue's sq and napi context. - main offload context (mlx5e_nvmeotcp) - has ida and hash table instances. Each offloaded queue gets an ID from the ida instance and the pairs are kept in the hash table. The id is programmed as flow tag to be set by HW on the completion (cqe) of all packets related to this queue (by 5-tuple steering). The fast path which deals with packets uses the flow tag to access the hash table and retrieve the queue for the processing. We query nvmeotcp capabilities to see if the offload can be supported and use 128B CQEs when this happens. By default, the offload is off but can be enabled with `ethtool --ulp-ddp nvme-tcp-ddp on`. Signed-off-by: Ben Ben-Ishay Signed-off-by: Boris Pismenny Signed-off-by: Or Gerlitz Signed-off-by: Yoray Zack Signed-off-by: Shai Malin Signed-off-by: Aurelien Aptel Reviewed-by: Tariq Toukan --- .../net/ethernet/mellanox/mlx5/core/Kconfig | 11 + .../net/ethernet/mellanox/mlx5/core/Makefile | 2 + drivers/net/ethernet/mellanox/mlx5/core/en.h | 4 + .../net/ethernet/mellanox/mlx5/core/en/fs.h | 4 +- .../ethernet/mellanox/mlx5/core/en/params.c | 12 +- .../ethernet/mellanox/mlx5/core/en/params.h | 3 + .../mellanox/mlx5/core/en_accel/en_accel.h | 3 + .../mellanox/mlx5/core/en_accel/fs_tcp.h | 2 +- .../mellanox/mlx5/core/en_accel/nvmeotcp.c | 217 ++++++++++++++++++ .../mellanox/mlx5/core/en_accel/nvmeotcp.h | 120 ++++++++++ .../ethernet/mellanox/mlx5/core/en_ethtool.c | 6 + .../net/ethernet/mellanox/mlx5/core/en_fs.c | 4 +- .../net/ethernet/mellanox/mlx5/core/en_main.c | 16 ++ .../net/ethernet/mellanox/mlx5/core/main.c | 1 + 14 files changed, 396 insertions(+), 9 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.h diff --git a/drivers/net/ethernet/mellanox/mlx5/core/Kconfig b/drivers/net/ethernet/mellanox/mlx5/core/Kconfig index 685335832a93..5935c2cdefec 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/Kconfig +++ b/drivers/net/ethernet/mellanox/mlx5/core/Kconfig @@ -164,6 +164,17 @@ config MLX5_EN_TLS help Build support for TLS cryptography-offload acceleration in the NIC. +config MLX5_EN_NVMEOTCP + bool "NVMEoTCP acceleration" + depends on ULP_DDP + depends on MLX5_CORE_EN + default y + help + Build support for NVMEoTCP acceleration in the NIC. + This includes Direct Data Placement and CRC offload. + Note: Support for hardware with this capability needs to be selected + for this option to become available. + config MLX5_SW_STEERING bool "Mellanox Technologies software-managed steering" depends on MLX5_CORE_EN && MLX5_ESWITCH diff --git a/drivers/net/ethernet/mellanox/mlx5/core/Makefile b/drivers/net/ethernet/mellanox/mlx5/core/Makefile index c44870b175f9..f397e2eb0cdc 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/Makefile +++ b/drivers/net/ethernet/mellanox/mlx5/core/Makefile @@ -109,6 +109,8 @@ mlx5_core-$(CONFIG_MLX5_EN_TLS) += en_accel/ktls_stats.o \ en_accel/fs_tcp.o en_accel/ktls.o en_accel/ktls_txrx.o \ en_accel/ktls_tx.o en_accel/ktls_rx.o +mlx5_core-$(CONFIG_MLX5_EN_NVMEOTCP) += en_accel/fs_tcp.o en_accel/nvmeotcp.o + mlx5_core-$(CONFIG_MLX5_SW_STEERING) += steering/dr_domain.o steering/dr_table.o \ steering/dr_matcher.o steering/dr_rule.o \ steering/dr_icm_pool.o steering/dr_buddy.o \ diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h index 714af3a451fd..e837ffbebe3e 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h @@ -326,6 +326,7 @@ struct mlx5e_params { int hard_mtu; bool ptp_rx; __be32 terminate_lkey_be; + bool nvmeotcp; }; static inline u8 mlx5e_get_dcb_num_tc(struct mlx5e_params *params) @@ -935,6 +936,9 @@ struct mlx5e_priv { #endif #ifdef CONFIG_MLX5_EN_TLS struct mlx5e_tls *tls; +#endif +#ifdef CONFIG_MLX5_EN_NVMEOTCP + struct mlx5e_nvmeotcp *nvmeotcp; #endif struct devlink_health_reporter *tx_reporter; struct devlink_health_reporter *rx_reporter; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h b/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h index 4d6225e0eec7..780e8b5ae8e0 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/fs.h @@ -77,7 +77,7 @@ enum { MLX5E_INNER_TTC_FT_LEVEL, MLX5E_FS_TT_UDP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1, MLX5E_FS_TT_ANY_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1, -#ifdef CONFIG_MLX5_EN_TLS +#if defined(CONFIG_MLX5_EN_TLS) || defined(CONFIG_MLX5_EN_NVMEOTCP) MLX5E_ACCEL_FS_TCP_FT_LEVEL = MLX5E_INNER_TTC_FT_LEVEL + 1, #endif #ifdef CONFIG_MLX5_EN_ARFS @@ -169,7 +169,7 @@ struct mlx5e_fs_any *mlx5e_fs_get_any(struct mlx5e_flow_steering *fs); void mlx5e_fs_set_any(struct mlx5e_flow_steering *fs, struct mlx5e_fs_any *any); struct mlx5e_fs_udp *mlx5e_fs_get_udp(struct mlx5e_flow_steering *fs); void mlx5e_fs_set_udp(struct mlx5e_flow_steering *fs, struct mlx5e_fs_udp *udp); -#ifdef CONFIG_MLX5_EN_TLS +#if defined(CONFIG_MLX5_EN_TLS) || defined(CONFIG_MLX5_EN_NVMEOTCP) struct mlx5e_accel_fs_tcp *mlx5e_fs_get_accel_tcp(struct mlx5e_flow_steering *fs); void mlx5e_fs_set_accel_tcp(struct mlx5e_flow_steering *fs, struct mlx5e_accel_fs_tcp *accel_tcp); #endif diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/params.c b/drivers/net/ethernet/mellanox/mlx5/core/en/params.c index 5757f4f10c12..ed4923a21d8b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/params.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/params.c @@ -889,7 +889,8 @@ static void mlx5e_build_common_cq_param(struct mlx5_core_dev *mdev, void *cqc = param->cqc; MLX5_SET(cqc, cqc, uar_page, mdev->priv.uar->index); - if (MLX5_CAP_GEN(mdev, cqe_128_always) && cache_line_size() >= 128) + if (MLX5_CAP_GEN(mdev, cqe_128_always) && + (cache_line_size() >= 128 || param->force_cqe128)) MLX5_SET(cqc, cqc, cqe_sz, CQE_STRIDE_128_PAD); } @@ -919,6 +920,9 @@ static void mlx5e_build_rx_cq_param(struct mlx5_core_dev *mdev, void *cqc = param->cqc; u8 log_cq_size; + /* nvme-tcp offload mandates 128 byte cqes */ + param->force_cqe128 |= IS_ENABLED(CONFIG_MLX5_EN_NVMEOTCP) && params->nvmeotcp; + switch (params->rq_wq_type) { case MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ: hw_stridx = MLX5_CAP_GEN(mdev, mini_cqe_resp_stride_index); @@ -1258,9 +1262,9 @@ static u8 mlx5e_build_async_icosq_log_wq_sz(struct mlx5_core_dev *mdev) return MLX5E_PARAMS_MINIMUM_LOG_SQ_SIZE; } -static void mlx5e_build_icosq_param(struct mlx5_core_dev *mdev, - u8 log_wq_size, - struct mlx5e_sq_param *param) +void mlx5e_build_icosq_param(struct mlx5_core_dev *mdev, + u8 log_wq_size, + struct mlx5e_sq_param *param) { void *sqc = param->sqc; void *wq = MLX5_ADDR_OF(sqc, sqc, wq); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/params.h b/drivers/net/ethernet/mellanox/mlx5/core/en/params.h index 6800949dafbc..f5a4d6f5d5bf 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/params.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/params.h @@ -17,6 +17,7 @@ struct mlx5e_cq_param { struct mlx5_wq_param wq; u16 eq_ix; u8 cq_period_mode; + bool force_cqe128; }; struct mlx5e_rq_param { @@ -147,6 +148,8 @@ void mlx5e_build_xdpsq_param(struct mlx5_core_dev *mdev, struct mlx5e_params *params, struct mlx5e_xsk_param *xsk, struct mlx5e_sq_param *param); +void mlx5e_build_icosq_param(struct mlx5_core_dev *mdev, + u8 log_wq_size, struct mlx5e_sq_param *param); int mlx5e_build_channel_param(struct mlx5_core_dev *mdev, struct mlx5e_params *params, u16 q_counter, diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h index caa34b9c161e..070dabb03bd4 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/en_accel.h @@ -40,6 +40,7 @@ #include "en_accel/ktls.h" #include "en_accel/ktls_txrx.h" #include +#include "en_accel/nvmeotcp.h" #include "en.h" #include "en/txrx.h" @@ -202,11 +203,13 @@ static inline void mlx5e_accel_tx_finish(struct mlx5e_txqsq *sq, static inline int mlx5e_accel_init_rx(struct mlx5e_priv *priv) { + mlx5e_nvmeotcp_init_rx(priv); return mlx5e_ktls_init_rx(priv); } static inline void mlx5e_accel_cleanup_rx(struct mlx5e_priv *priv) { + mlx5e_nvmeotcp_cleanup_rx(priv); mlx5e_ktls_cleanup_rx(priv); } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/fs_tcp.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/fs_tcp.h index a032bff482a6..d907e352ffae 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/fs_tcp.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/fs_tcp.h @@ -6,7 +6,7 @@ #include "en/fs.h" -#ifdef CONFIG_MLX5_EN_TLS +#if defined(CONFIG_MLX5_EN_TLS) || defined(CONFIG_MLX5_EN_NVMEOTCP) int mlx5e_accel_fs_tcp_create(struct mlx5e_flow_steering *fs); void mlx5e_accel_fs_tcp_destroy(struct mlx5e_flow_steering *fs); struct mlx5_flow_handle *mlx5e_accel_fs_add_sk(struct mlx5e_flow_steering *fs, diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c new file mode 100644 index 000000000000..8f99534430f0 --- /dev/null +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c @@ -0,0 +1,217 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB +// Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. + +#include +#include +#include "en_accel/nvmeotcp.h" +#include "en_accel/fs_tcp.h" +#include "en/txrx.h" + +#define MAX_NUM_NVMEOTCP_QUEUES (4000) +#define MIN_NUM_NVMEOTCP_QUEUES (1) + +static const struct rhashtable_params rhash_queues = { + .key_len = sizeof(int), + .key_offset = offsetof(struct mlx5e_nvmeotcp_queue, id), + .head_offset = offsetof(struct mlx5e_nvmeotcp_queue, hash), + .automatic_shrinking = true, + .min_size = MIN_NUM_NVMEOTCP_QUEUES, + .max_size = MAX_NUM_NVMEOTCP_QUEUES, +}; + +static int +mlx5e_nvmeotcp_offload_limits(struct net_device *netdev, + struct ulp_ddp_limits *limits) +{ + return 0; +} + +static int +mlx5e_nvmeotcp_queue_init(struct net_device *netdev, + struct sock *sk, + struct ulp_ddp_config *tconfig) +{ + return 0; +} + +static void +mlx5e_nvmeotcp_queue_teardown(struct net_device *netdev, + struct sock *sk) +{ +} + +static int +mlx5e_nvmeotcp_ddp_setup(struct net_device *netdev, + struct sock *sk, + struct ulp_ddp_io *ddp) +{ + return 0; +} + +static void +mlx5e_nvmeotcp_ddp_teardown(struct net_device *netdev, + struct sock *sk, + struct ulp_ddp_io *ddp, + void *ddp_ctx) +{ +} + +static void +mlx5e_nvmeotcp_ddp_resync(struct net_device *netdev, + struct sock *sk, u32 seq) +{ +} + +int set_ulp_ddp_nvme_tcp(struct net_device *netdev, bool enable) +{ + struct mlx5e_priv *priv = netdev_priv(netdev); + struct mlx5e_params new_params; + int err = 0; + + /* There may be offloaded queues when an netlink callback to disable the feature is made. + * Hence, we can't destroy the tcp flow-table since it may be referenced by the offload + * related flows and we'll keep the 128B CQEs on the channel RQs. Also, since we don't + * deref/destroy the fs tcp table when the feature is disabled, we don't ref it again + * if the feature is enabled multiple times. + */ + if (!enable || priv->nvmeotcp->enabled) + return 0; + + err = mlx5e_accel_fs_tcp_create(priv->fs); + if (err) + return err; + + new_params = priv->channels.params; + new_params.nvmeotcp = enable; + err = mlx5e_safe_switch_params(priv, &new_params, NULL, NULL, true); + if (err) + goto fs_tcp_destroy; + + priv->nvmeotcp->enabled = true; + return 0; + +fs_tcp_destroy: + mlx5e_accel_fs_tcp_destroy(priv->fs); + return err; +} + +static int mlx5e_ulp_ddp_set_caps(struct net_device *netdev, unsigned long *new_caps, + struct netlink_ext_ack *extack) +{ + struct mlx5e_priv *priv = netdev_priv(netdev); + DECLARE_BITMAP(old_caps, ULP_DDP_CAP_COUNT); + struct mlx5e_params *params; + int ret = 0; + int nvme = -1; + + mutex_lock(&priv->state_lock); + params = &priv->channels.params; + bitmap_copy(old_caps, priv->nvmeotcp->ddp_caps.active, ULP_DDP_CAP_COUNT); + + /* always handle nvme-tcp-ddp and nvme-tcp-ddgst-rx together (all or nothing) */ + + if (ulp_ddp_cap_turned_on(old_caps, new_caps, ULP_DDP_CAP_NVME_TCP) && + ulp_ddp_cap_turned_on(old_caps, new_caps, ULP_DDP_CAP_NVME_TCP_DDGST_RX)) { + if (MLX5E_GET_PFLAG(params, MLX5E_PFLAG_RX_CQE_COMPRESS)) { + NL_SET_ERR_MSG_MOD(extack, + "NVMe-TCP offload not supported when CQE compress is active. Disable rx_cqe_compress ethtool private flag first\n"); + goto out; + } + + if (netdev->features & (NETIF_F_LRO | NETIF_F_GRO_HW)) { + NL_SET_ERR_MSG_MOD(extack, + "NVMe-TCP offload not supported when HW_GRO/LRO is active. Disable rx-gro-hw ethtool feature first\n"); + goto out; + } + nvme = 1; + } else if (ulp_ddp_cap_turned_off(old_caps, new_caps, ULP_DDP_CAP_NVME_TCP) && + ulp_ddp_cap_turned_off(old_caps, new_caps, ULP_DDP_CAP_NVME_TCP_DDGST_RX)) { + nvme = 0; + } + + if (nvme >= 0) { + ret = set_ulp_ddp_nvme_tcp(netdev, nvme); + if (ret) + goto out; + change_bit(ULP_DDP_CAP_NVME_TCP, priv->nvmeotcp->ddp_caps.active); + change_bit(ULP_DDP_CAP_NVME_TCP_DDGST_RX, priv->nvmeotcp->ddp_caps.active); + } + +out: + mutex_unlock(&priv->state_lock); + return ret; +} + +static void mlx5e_ulp_ddp_get_caps(struct net_device *dev, + struct ulp_ddp_dev_caps *caps) +{ + struct mlx5e_priv *priv = netdev_priv(dev); + + mutex_lock(&priv->state_lock); + memcpy(caps, &priv->nvmeotcp->ddp_caps, sizeof(*caps)); + mutex_unlock(&priv->state_lock); +} + +const struct ulp_ddp_dev_ops mlx5e_nvmeotcp_ops = { + .limits = mlx5e_nvmeotcp_offload_limits, + .sk_add = mlx5e_nvmeotcp_queue_init, + .sk_del = mlx5e_nvmeotcp_queue_teardown, + .setup = mlx5e_nvmeotcp_ddp_setup, + .teardown = mlx5e_nvmeotcp_ddp_teardown, + .resync = mlx5e_nvmeotcp_ddp_resync, + .set_caps = mlx5e_ulp_ddp_set_caps, + .get_caps = mlx5e_ulp_ddp_get_caps, +}; + +void mlx5e_nvmeotcp_cleanup_rx(struct mlx5e_priv *priv) +{ + if (priv->nvmeotcp && priv->nvmeotcp->enabled) + mlx5e_accel_fs_tcp_destroy(priv->fs); +} + +int mlx5e_nvmeotcp_init(struct mlx5e_priv *priv) +{ + struct mlx5e_nvmeotcp *nvmeotcp = NULL; + int ret = 0; + + if (!(MLX5_CAP_GEN(priv->mdev, nvmeotcp) && + MLX5_CAP_DEV_NVMEOTCP(priv->mdev, zerocopy) && + MLX5_CAP_DEV_NVMEOTCP(priv->mdev, crc_rx) && + MLX5_CAP_GEN(priv->mdev, cqe_128_always))) + return 0; + + nvmeotcp = kzalloc(sizeof(*nvmeotcp), GFP_KERNEL); + + if (!nvmeotcp) + return -ENOMEM; + + ida_init(&nvmeotcp->queue_ids); + ret = rhashtable_init(&nvmeotcp->queue_hash, &rhash_queues); + if (ret) + goto err_ida; + + /* report ULP DPP as supported, but don't enable it by default */ + set_bit(ULP_DDP_CAP_NVME_TCP, nvmeotcp->ddp_caps.hw); + set_bit(ULP_DDP_CAP_NVME_TCP_DDGST_RX, nvmeotcp->ddp_caps.hw); + nvmeotcp->enabled = false; + priv->nvmeotcp = nvmeotcp; + return 0; + +err_ida: + ida_destroy(&nvmeotcp->queue_ids); + kfree(nvmeotcp); + return ret; +} + +void mlx5e_nvmeotcp_cleanup(struct mlx5e_priv *priv) +{ + struct mlx5e_nvmeotcp *nvmeotcp = priv->nvmeotcp; + + if (!nvmeotcp) + return; + + rhashtable_destroy(&nvmeotcp->queue_hash); + ida_destroy(&nvmeotcp->queue_ids); + kfree(nvmeotcp); + priv->nvmeotcp = NULL; +} diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.h new file mode 100644 index 000000000000..29546992791f --- /dev/null +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.h @@ -0,0 +1,120 @@ +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ +/* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. */ +#ifndef __MLX5E_NVMEOTCP_H__ +#define __MLX5E_NVMEOTCP_H__ + +#ifdef CONFIG_MLX5_EN_NVMEOTCP + +#include +#include "en.h" +#include "en/params.h" + +struct mlx5e_nvmeotcp_queue_entry { + struct mlx5e_nvmeotcp_queue *queue; + u32 sgl_length; + u32 klm_mkey; + struct scatterlist *sgl; + u32 ccid_gen; + u64 size; + + /* for the ddp invalidate done callback */ + void *ddp_ctx; + struct ulp_ddp_io *ddp; +}; + +struct mlx5e_nvmeotcp_queue_handler { + struct napi_struct napi; + struct mlx5e_cq *cq; +}; + +/** + * struct mlx5e_nvmeotcp_queue - mlx5 metadata for NVMEoTCP queue + * @ulp_ddp_ctx: Generic ulp ddp context + * @tir: Destination TIR created for NVMEoTCP offload + * @fh: Flow handle representing the 5-tuple steering for this flow + * @id: Flow tag ID used to identify this queue + * @size: NVMEoTCP queue depth + * @ccid_gen: Generation ID for the CCID, used to avoid conflicts in DDP + * @max_klms_per_wqe: Number of KLMs per DDP operation + * @hash: Hash table of queues mapped by @id + * @pda: Padding alignment + * @tag_buf_table_id: Tag buffer table for CCIDs + * @dgst: Digest supported (header and/or data) + * @sq: Send queue used for posting umrs + * @ref_count: Reference count for this structure + * @after_resync_cqe: Indicate if resync occurred + * @ccid_table: Table holding metadata for each CC (Command Capsule) + * @ccid: ID of the current CC + * @ccsglidx: Index within the scatter-gather list (SGL) of the current CC + * @ccoff: Offset within the current CC + * @ccoff_inner: Current offset within the @ccsglidx element + * @channel_ix: Channel IX for this nvmeotcp_queue + * @sk: The socket used by the NVMe-TCP queue + * @crc_rx: CRC Rx offload indication for this queue + * @priv: mlx5e netdev priv + * @static_params_done: Async completion structure for the initial umr mapping + * synchronization + * @sq_lock: Spin lock for the icosq + * @qh: Completion queue handler for processing umr completions + */ +struct mlx5e_nvmeotcp_queue { + struct ulp_ddp_ctx ulp_ddp_ctx; + struct mlx5e_tir tir; + struct mlx5_flow_handle *fh; + int id; + u32 size; + /* needed when the upper layer immediately reuses CCID + some packet loss happens */ + u32 ccid_gen; + u32 max_klms_per_wqe; + struct rhash_head hash; + int pda; + u32 tag_buf_table_id; + u8 dgst; + struct mlx5e_icosq sq; + + /* data-path section cache aligned */ + refcount_t ref_count; + /* for MASK HW resync cqe */ + bool after_resync_cqe; + struct mlx5e_nvmeotcp_queue_entry *ccid_table; + /* current ccid fields */ + int ccid; + int ccsglidx; + off_t ccoff; + int ccoff_inner; + + u32 channel_ix; + struct sock *sk; + u8 crc_rx:1; + /* for ddp invalidate flow */ + struct mlx5e_priv *priv; + /* end of data-path section */ + + struct completion static_params_done; + /* spin lock for the ico sq, ULP can issue requests from multiple contexts */ + spinlock_t sq_lock; + struct mlx5e_nvmeotcp_queue_handler qh; +}; + +struct mlx5e_nvmeotcp { + struct ida queue_ids; + struct rhashtable queue_hash; + struct ulp_ddp_dev_caps ddp_caps; + bool enabled; +}; + +int mlx5e_nvmeotcp_init(struct mlx5e_priv *priv); +int set_ulp_ddp_nvme_tcp(struct net_device *netdev, bool enable); +void mlx5e_nvmeotcp_cleanup(struct mlx5e_priv *priv); +static inline void mlx5e_nvmeotcp_init_rx(struct mlx5e_priv *priv) {} +void mlx5e_nvmeotcp_cleanup_rx(struct mlx5e_priv *priv); +extern const struct ulp_ddp_dev_ops mlx5e_nvmeotcp_ops; +#else + +static inline int mlx5e_nvmeotcp_init(struct mlx5e_priv *priv) { return 0; } +static inline void mlx5e_nvmeotcp_cleanup(struct mlx5e_priv *priv) {} +static inline int set_ulp_ddp_nvme_tcp(struct net_device *dev, bool en) { return -EOPNOTSUPP; } +static inline void mlx5e_nvmeotcp_init_rx(struct mlx5e_priv *priv) {} +static inline void mlx5e_nvmeotcp_cleanup_rx(struct mlx5e_priv *priv) {} +#endif +#endif /* __MLX5E_NVMEOTCP_H__ */ diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c index cc51ce16df14..fddadc896c26 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_ethtool.c @@ -38,6 +38,7 @@ #include "en/ptp.h" #include "lib/clock.h" #include "en/fs_ethtool.h" +#include "en_accel/nvmeotcp.h" void mlx5e_ethtool_get_drvinfo(struct mlx5e_priv *priv, struct ethtool_drvinfo *drvinfo) @@ -1918,6 +1919,11 @@ int mlx5e_modify_rx_cqe_compression_locked(struct mlx5e_priv *priv, bool new_val return -EINVAL; } + if (priv->channels.params.nvmeotcp) { + netdev_warn(priv->netdev, "Can't set CQE compression after ULP DDP NVMe-TCP offload\n"); + return -EINVAL; + } + new_params = priv->channels.params; MLX5E_SET_PFLAG(&new_params, MLX5E_PFLAG_RX_CQE_COMPRESS, new_val); if (rx_filter) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_fs.c b/drivers/net/ethernet/mellanox/mlx5/core/en_fs.c index 777d311d44ef..853e30f221c8 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_fs.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_fs.c @@ -62,7 +62,7 @@ struct mlx5e_flow_steering { #ifdef CONFIG_MLX5_EN_ARFS struct mlx5e_arfs_tables *arfs; #endif -#ifdef CONFIG_MLX5_EN_TLS +#if defined(CONFIG_MLX5_EN_TLS) || defined(CONFIG_MLX5_EN_NVMEOTCP) struct mlx5e_accel_fs_tcp *accel_tcp; #endif struct mlx5e_fs_udp *udp; @@ -1557,7 +1557,7 @@ void mlx5e_fs_set_any(struct mlx5e_flow_steering *fs, struct mlx5e_fs_any *any) fs->any = any; } -#ifdef CONFIG_MLX5_EN_TLS +#if defined(CONFIG_MLX5_EN_TLS) || defined(CONFIG_MLX5_EN_NVMEOTCP) struct mlx5e_accel_fs_tcp *mlx5e_fs_get_accel_tcp(struct mlx5e_flow_steering *fs) { return fs->accel_tcp; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index 039fe9252c4d..433df982400e 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -50,6 +50,7 @@ #include "en_accel/macsec.h" #include "en_accel/en_accel.h" #include "en_accel/ktls.h" +#include "en_accel/nvmeotcp.h" #include "lib/vxlan.h" #include "lib/clock.h" #include "en/port.h" @@ -4233,6 +4234,13 @@ static netdev_features_t mlx5e_fix_features(struct net_device *netdev, features &= ~NETIF_F_NETNS_LOCAL; } + if (features & (NETIF_F_LRO | NETIF_F_GRO_HW)) { + if (params->nvmeotcp) { + netdev_warn(netdev, "Disabling HW-GRO/LRO, not supported after ULP DDP NVMe-TCP offload\n"); + features &= ~(NETIF_F_LRO | NETIF_F_GRO_HW); + } + } + mutex_unlock(&priv->state_lock); return features; @@ -4994,6 +5002,9 @@ const struct net_device_ops mlx5e_netdev_ops = { .ndo_has_offload_stats = mlx5e_has_offload_stats, .ndo_get_offload_stats = mlx5e_get_offload_stats, #endif +#ifdef CONFIG_MLX5_EN_NVMEOTCP + .ulp_ddp_ops = &mlx5e_nvmeotcp_ops, +#endif }; static u32 mlx5e_choose_lro_timeout(struct mlx5_core_dev *mdev, u32 wanted_timeout) @@ -5334,6 +5345,10 @@ static int mlx5e_nic_init(struct mlx5_core_dev *mdev, if (err) mlx5_core_err(mdev, "TLS initialization failed, %d\n", err); + err = mlx5e_nvmeotcp_init(priv); + if (err) + mlx5_core_err(mdev, "NVMEoTCP initialization failed, %d\n", err); + mlx5e_health_create_reporters(priv); /* If netdev is already registered (e.g. move from uplink to nic profile), @@ -5354,6 +5369,7 @@ static int mlx5e_nic_init(struct mlx5_core_dev *mdev, static void mlx5e_nic_cleanup(struct mlx5e_priv *priv) { mlx5e_health_destroy_reporters(priv); + mlx5e_nvmeotcp_cleanup(priv); mlx5e_ktls_cleanup(priv); mlx5e_fs_cleanup(priv->fs); debugfs_remove_recursive(priv->dfs_root); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/main.c b/drivers/net/ethernet/mellanox/mlx5/core/main.c index c2593625c09a..2578482f9afa 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/main.c @@ -1744,6 +1744,7 @@ static const int types[] = { MLX5_CAP_MACSEC, MLX5_CAP_ADV_VIRTUALIZATION, MLX5_CAP_CRYPTO, + MLX5_CAP_DEV_NVMEOTCP, }; static void mlx5_hca_caps_free(struct mlx5_core_dev *dev) From patchwork Wed Feb 28 12:57:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575455 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2040.outbound.protection.outlook.com [40.107.243.40]) (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 EFA5614C582 for ; Wed, 28 Feb 2024 12:59:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125142; cv=fail; b=tzSV/Um2jseg68F3aZICOxl5uXIKMrq3k2tCwmobJWEAbJ36ws0pRZeu7EmD1OY3fGF4nTcsWAOqXxx3XZXirUqkKq3JNd2MG9g2KNrtWlG4+i0hYTnfd8TNIgfT4yNsUL8x2HZjPopueLeuizM/BvlUD9N8GsMQ0vjh0dhwnic= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125142; c=relaxed/simple; bh=L+fATSu7wju+xIXEvIlWuzH8g12yUZNew/Psv7Lz+Nk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=NbVBP9kQscJ4WinePeAWZNcsr4/D1Wuwo+V6bHuq+r381ZmJk/D0kcGF0obFJIhZ6UVKjvm4IUcFQwwxfMgkYACPLr52WqoOHU2mLd5dXK8j1TgzjcbQ/KLTcqqPKnV7I/72ji1si6yzieCcMr58jAM0CEPfSbmwqU3t97XoNbU= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=Cvcic3Ro; arc=fail smtp.client-ip=40.107.243.40 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Cvcic3Ro" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NG4nSZBCbljCgMiPKLojJzAjGd/QXR92ugWnokJV9MmEmMYi7SAtziJdShJGvNc3s51o1LO6WDxjp9o56wKObXinCSraPAcBHlV+5Y5FUCurMPl0k9Cncjdb8rvLTipNiQ6ebTmLQLovpXDUFja5JqNfEnBnIyN/NGonGs+8fAlJ9GXzkbafOlDHWCTOftx9zOTuw5c/cM9u5hb1QzNHV4L4sy0AXakTCfPiTtQitY/WhIjnbPtiNwo+vPCwwQUfToxYkNSyMR8Kf5a0bzCLza6ILa5KGKk4G3nnah8Q/U4L8REivBYcxl2iUeHQ6FU+Y/eBiBEHzyE23w+qY7EOMw== 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=pa3K+d+tGObk4y9Zv/bhOSlIarCrDmSWoYqxxmm8F3I=; b=MrvTT+AXs7H4kkAwmK2l14Vc0yYfg7WC5Gd4HTDqjlLw0PMEZLZZc3U7FPARM5iagBdih+SYUu1dJAS7xzYELBWoT+sJanQI7rhZNCbdlWdUXvtNg4M738B4drwNVPZMj9WF8fzBxYPhW0gaa8QJYXvXyMX1+u+MBlpb6oS8Dz9cnjY+E7jJwhRHcifQ1i5Jr1/ksnA3uHsy1Qji3x/h52J0624a19rjb5RWwaIuwzcwEoLCv0km0hZAI9RK0kCowCq4j2EIyCB6g0UTs/owV2ch596p5lyX8gc6IpDNyrUI/f0idEg91hL1kBrs6wj+sej6o6/V4T4eHnx2Xw6TnQ== 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=pa3K+d+tGObk4y9Zv/bhOSlIarCrDmSWoYqxxmm8F3I=; b=Cvcic3RoJ+F/8wkJLfrdYas93vbFnOdwJe++8EXHIIt8PNl3cOOd8dgucXuBcATeo4TZGFoas/5qDeAzbCxdvcLkDy+QRSQoQZF04Y46JZuGueQg8b6PklSP1pLxAuvu+u+aZQD3QeopX/6Fjd45c+BWaSesBJtRX4G/P2hgnDfo3AhZDb6NLaB1vRP7uddZ8QbHI6vJ6irLVFrstJXCUoaIqO/R2Rb/PqSj7A6iCNRr1gpezZW0x6aR3bgaJVrVTmTkWzXRIjr/N8Bph9xZBgGmgq+kwpzU7NYLZLK4Zv0M0TEFENswAXZ7taj2ISVj6+FA2ONdfwWMctYGY/1R9w== 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 SA3PR12MB7859.namprd12.prod.outlook.com (2603:10b6:806:305::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.39; Wed, 28 Feb 2024 12:58:58 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:58:58 +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: Boris Pismenny , aaptel@nvidia.com, aurelien.aptel@gmail.com, smalin@nvidia.com, malin1024@gmail.com, ogerlitz@nvidia.com, yorayz@nvidia.com, galshalom@nvidia.com, mgurtovoy@nvidia.com Subject: [PATCH v23 14/20] net/mlx5e: TCP flow steering for nvme-tcp acceleration Date: Wed, 28 Feb 2024 12:57:27 +0000 Message-Id: <20240228125733.299384-15-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FR4P281CA0114.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:bb::15) 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_|SA3PR12MB7859:EE_ X-MS-Office365-Filtering-Correlation-Id: d65152a0-a5b2-4d1d-1ce0-08dc385d06f2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dj0U3VWJmXrj9MKzjfDuD7++qEUkcbsVISZL5bIR/HuXhzd4QbVk4tgrkn3k8c1RG/HF6+JrCgpIoaZScJ0e2/L05c+UgL9uxT8X8bYPS19+AoeejxAJc8oMqFbWhPKX3mM6mm79JFOI+Zfpd2SXSvIxjnSXVfy6Z2+1mmQblgORpZp6QaF5cgFhsKewoMl4WMWhyZ/LIpHfI3uv91jdY6ETO6KZl4xz+9hoGJQpfVPOyACkOIYRX9jp8+NQ0hhcq7etGl0wiAbRFsYPNBTjVLYDndk0MZzAfjRYzHpcy2aDW0Uvr4UJ8YlxfsVUOmPDU1UTQ/XdBqp+klF9qBHvpahYTMSgNhEq3qmN7dGkr7nx5xu3mZNhLgkxsF91A9tlJfDUmLdXtnZy52b5tmqhUXdV7ZZRVJbelf1r2x2wIBO7+IZpyPJcimQ7UbDxIDZFW828gmq15I/8hG8jayfmUn64ZbSS2nIdsQfGTUCa9Oe5IpgPVDVFBjs9JWQptMfyEMaE+KFTvTLBQrut/YNGNtc5yz8WGyLNZjeh7s6QmTnwWkhh1p0w3zyvD/YNGwbpkd9gbkuJxTSjrFfFNOa8/cExH1+DhU2t3xML7GqhRNJnJQ8zt5hF3n4+BhwHgZcMFb2K27Zd2zcm8Sk83r4cNw== 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HOUlhbjtvt4x8inq3mGg96XvPeeMN+VBCeHBtcdPoaidf4s1FuSZ7Kb9kWT6dpZjlqWtepEOhXxI4Vr+bWBdEASmF1qI3M8PrYOrFgEFQ0dEdJ8AYDJEwzGKqlSIH436lY+LzY/nOVyHYnLP41W8E5erdfbzkBmm3cMDsumktlKSNNUAW9qVVRpB4pk0yzgj29IP4GCP1GMP70uLEs679FHLODH0bRyaRCQgdBBzLCgPTPWxHJnASH+ARrRaSy7r3hxH9WM5L3xiXEWixCmpB01M2O4otkmBgJlLQmD2WEeeNcIm6jjPYYOzj+W1nUs4fwAvtpxNzOiASZISTtQyQhDFq4KEThvToCtmP0EeUlQrN5xG8DHQGc90U8xqgZapORiImwXqIEbP60bKZzB9CijMWynyXds/d51lepdTNpTfrW2Sp4EF3D3WX/M6kcH/FON8kHcoTJ9ykv5Zup5EkKk+2BUKw3NYiBWsa3qUEEgP6D+yDEi8yFQoeoXAstsUP+ntbd+ZhbLb/rNpxJyBz6EC8KWdlOVFAdilmdBBo7IoWAFITzdUsH/t0kfkvlypVkOTyGjJ6jnY8mZ/UdMB+WBff7C2R25yW4IHI4UrYHGA1XraDmd+XTUXvLeiuiOQ46U48MNCM3T5cw+DRfnh/bqNF9lyGlHiC5JcsHUsooMRg69og1shsNGTtw3kKQOxHr5ZxDPEq9dOL9thVNZXP6sffzcLcVrD3SSy2J0Z/yA87LfTQswDgzJcPUDNvPsrI2jxYV41EmJwG45IF6+hsQnpq0iEa2847/ZyjluQVHYT7xcwu0KgYEs/G5xMD6V7H2FlZX7S5afChg6lvS9TzIRWf07xC1Ex12WBuayH4R7Kz/cN1nHBu0Pa4ReEtPrcOD+TddiI8biutXC+AtAgRjp/wdZb/mb32IN7TjiOtwRm5btB9SIr2nbWGTv4FKVV0bL2tsMCzDh/NKwjgoGQLVaBzOlNzwNPBeY3Q3Zsy/AMYqRwE8ksI+tUku5fi5T6wq3vyvGHk6xXbY0r7GZuTHDQ/KpsqynVfHOqzTYzbFXF4VKCTDVypcEdVotsxR6XGdD/pN0Iw7jKvuoaQesUBkPjzckS+Ugtx8QgXcJE99PayFw90TLb8bWM71/kBs9tvAaT0G61N6uDcXj2vUGTUL2f5ltPF8LlMD/cjoOalSsl6jsbM912IzYeHCTZoqvezFN/v8G5jQCqPf+gGzx4n+/hONFkYyn9Cwfw/4eiiSNO+g92Nk3X0j5qsCBvpZ2w0zia11wWY80/9NncR1dVdbw2ndLy5K44hgB9dTO+i9q1WJjT00LW/ZBtQTs90666MelWqTpWKvpnteTeYpt9KdCfAmW+bJjVuRxmpXPBBF3YiFArBtoDRxLSG58DAw76dGpU9uSjIlldQNnP8PqX8a7Ml7RAfpR3WWWzPnsDM9Kgj18TFQ0q+BXtBp9bF/PswJ0+iwCea4hCgG3noiqVrKHzCpZXt4Ryzt3Uk7nJBube7D2ZcbOy8DByiTqnN0/KR6n5LU2bXbffVLkxar94Wh+6ZhWct0/GEOi2JWkvRaxFpzArOO8u4ySDLo/DUZBd X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d65152a0-a5b2-4d1d-1ce0-08dc385d06f2 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:58:58.0358 (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: 1NsrVELk/UHqNUrZB+DhTMKn+jX6MpmjuLwH3Xc3CeCRNMAmC9pU+9H8A60Qf8aNjCWpMXYTivmcoXkiOBPGPw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7859 X-Patchwork-Delegate: kuba@kernel.org From: Boris Pismenny Both nvme-tcp and tls acceleration require tcp flow steering. Add reference counter to share TCP flow steering structure. Signed-off-by: Boris Pismenny Signed-off-by: Ben Ben-Ishay Signed-off-by: Or Gerlitz Signed-off-by: Yoray Zack Signed-off-by: Aurelien Aptel Reviewed-by: Tariq Toukan --- .../ethernet/mellanox/mlx5/core/en_accel/fs_tcp.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/fs_tcp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/fs_tcp.c index c7d191f66ad1..82a9e2a4f58b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/fs_tcp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/fs_tcp.c @@ -14,6 +14,7 @@ enum accel_fs_tcp_type { struct mlx5e_accel_fs_tcp { struct mlx5e_flow_table tables[ACCEL_FS_TCP_NUM_TYPES]; struct mlx5_flow_handle *default_rules[ACCEL_FS_TCP_NUM_TYPES]; + refcount_t user_count; }; static enum mlx5_traffic_types fs_accel2tt(enum accel_fs_tcp_type i) @@ -361,6 +362,9 @@ void mlx5e_accel_fs_tcp_destroy(struct mlx5e_flow_steering *fs) if (!accel_tcp) return; + if (!refcount_dec_and_test(&accel_tcp->user_count)) + return; + accel_fs_tcp_disable(fs); for (i = 0; i < ACCEL_FS_TCP_NUM_TYPES; i++) @@ -372,12 +376,17 @@ void mlx5e_accel_fs_tcp_destroy(struct mlx5e_flow_steering *fs) int mlx5e_accel_fs_tcp_create(struct mlx5e_flow_steering *fs) { - struct mlx5e_accel_fs_tcp *accel_tcp; + struct mlx5e_accel_fs_tcp *accel_tcp = mlx5e_fs_get_accel_tcp(fs); int i, err; if (!MLX5_CAP_FLOWTABLE_NIC_RX(mlx5e_fs_get_mdev(fs), ft_field_support.outer_ip_version)) return -EOPNOTSUPP; + if (accel_tcp) { + refcount_inc(&accel_tcp->user_count); + return 0; + } + accel_tcp = kzalloc(sizeof(*accel_tcp), GFP_KERNEL); if (!accel_tcp) return -ENOMEM; @@ -393,6 +402,7 @@ int mlx5e_accel_fs_tcp_create(struct mlx5e_flow_steering *fs) if (err) goto err_destroy_tables; + refcount_set(&accel_tcp->user_count, 1); return 0; err_destroy_tables: From patchwork Wed Feb 28 12:57:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575458 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2082.outbound.protection.outlook.com [40.107.243.82]) (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 7EED514C582 for ; Wed, 28 Feb 2024 12:59:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125147; cv=fail; b=Jg17B5Y32FsA+svGcewCQCoDwffA3uQDJoaif/dLnV7E5XY6GLBlq60YuqzSW5+yX1V7zBQhwP7yhZXCo+2XNFwIJAL/mIVSmlcnOYmwTHnnReCUHfobmexaosjLYrS3sszYBNqAzsQQEft6u32f3zoKgugwiNhwrRV0tpTJ0n0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125147; c=relaxed/simple; bh=UbuMSkfuehEgiCZ9Z0NquzvRHU/9lpW/wuvIH8yNlpA=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=r5FG86+65nwezG6ao8kDqa0JGeQCwuDVLtWy8Q5J5+sfQ2O1hioDhvuKNgHlhQqDhgoEnBVoITmQJ1iyLLyjEtm5g0Ta8yQe1pGcDlKhTWtwtXf2PPudctixYPZAOyOJVh9AgT4jIlXp+MKQvOj6zlgdlULwEcRmoqgGC+Eb7ZY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=lDvklN/I; arc=fail smtp.client-ip=40.107.243.82 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="lDvklN/I" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ear+io0J6JCbpg+/BN7lNuDLfzkrG01SYAgcHf607LYbciRm+nif25HHz18fo8Iwn+rzg2G9HQYolyCme+NTmBRxZA9nfeoHeI1gGfnWWokuobPwTuFzG3gm8Pd6MJes427CzbnfxuWG3mVoMPA67UQ9I3XXJLD/8WETFyKrTvSFg+GJGSxvT4cVBer37xzmhW8gER4gbbX/lTiSwhKvflc8PGUce8Wh2XOcruksILdjvxwKeiE55G5Ms9PNjyETKBk0V8tKd+UaK4AvL45ub133ArYPfRJyhYYg8lwm3xhGJvV0rfc9MsPl5x+SVrOr1k+NgJ3YpUM1RLpWgLlddg== 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=D7gG2+nSmQ4j+/cg6MJGtX5WqvxLjWmgRwM9wwAH0gY=; b=fVNvGI12EeRc1UmQ6YlNeBFke4aiNBV8KA85MmgSHlPs3AYy/KeAFgfEe3d2VCgQuFvdCoRk5sMt1sw5ZC6w/LIdYuZfnEEqqzpY12IfokVVtjmM7vI+RxDCnESuZpn0rZGkTzfWjR3D6oU8SIdUzsJetCn9RDho/M92KX6UQH/iAiCfN6kb3vkjHkcZtegNiSfuvYd9GSybRgx+/XBABvf9XvsNhFTjYrVCpzfIhVKgPjpbWs49E97XzgPvd5PQqE2QIqoaHSsAmTMp9RatZ6nW0VW3M754qTGN513eMLaK6T2zWLyLKNYLVEFTrzgBKyaTzzCDaNmQVhqrRIXDBw== 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=D7gG2+nSmQ4j+/cg6MJGtX5WqvxLjWmgRwM9wwAH0gY=; b=lDvklN/IUgcHSBcMjZSd5NY1Vf5Mq6jNp8NgQB7youlEpi349YRFwAV7uo1RAmJxjH4D6nDIo+3Xwrw9J45fnCasBUtOMR5+iKNySzazvpJ1Pk2zhQP6GdBnQ82vcEt1cDtDghxs//+YN14Xb4UWGZg30UjPYulcfAqG0D3dzneTx5hSlaecuqSS9y/NdQH3s7dCwKGQBr3jr4tiBQNfoVDZALboNmGUKpLRRb9fopXQ4nbbEI9hJ8lSNIuAxzy1ECbnqE99uzmsVWU00bTL70czdyd1tZQ+ClbTzTNB2fjRyO4/CE6n9i6BmkYjAaiT7hvOZ9D8zdTVWuSORxZRpA== 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 SA3PR12MB7859.namprd12.prod.outlook.com (2603:10b6:806:305::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.39; Wed, 28 Feb 2024 12:59:02 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:59:02 +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: aaptel@nvidia.com, 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 Subject: [PATCH v23 15/20] net/mlx5e: NVMEoTCP, use KLM UMRs for buffer registration Date: Wed, 28 Feb 2024 12:57:28 +0000 Message-Id: <20240228125733.299384-16-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FR2P281CA0041.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:92::12) 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_|SA3PR12MB7859:EE_ X-MS-Office365-Filtering-Correlation-Id: 2f6451e5-070c-4c97-6970-08dc385d097d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: PzDnjdYEl0msPyncYkCJldkvgAIHg3HDRH0LhMdaopLc37yThqrZ0SL8OfyJ0et5PSkXSs1y9glCrbIinBI2BD+V/Jmf91IKTD8D16c5TcAX2P/nX06P/h1SQs5sDIXnjWICcj3FZ5vd2RB/ACEczQsfE4evkKMkfdEafc7HuDiJODjj7r8gX0VuHpj4KmT6st5jLsOhlmqvPr9cuvetCZ3lzQNUw+d6iz1O91dL9MwUOXcxuoPhNJgt2xfjjOtAvHjbtWracXHn1ctSDQGqDKWD/pLKaL1SKXQwsaZ18HIA9icIyk8A0MHc/JU+MSsZVt0kqUl1mQzAdP1vmlbaA8yXKOwm02HgoBGUyTFTX2c7elDI4n6hB6GSIWq589uxOTiEAyBWbqZdRuDZsioJIcyzFPNuaKLrnT/rqyGCfBsrpOmUq4PwdARV7dVur6CKFaihq18vHIyGVmg4wbConFs24WfoJJVNl3IfTIfPupGbIJtl79LKDNGNk1UzTZ+uKN0CVeztIUUX8H6dHNaPlZX81I0Ez3jtBeM5Jlf6XEfIU5XlztHQcR+zydxuz+FftS921ur5ZTdw7ZOVlG0uoWU0Eb1WpOnJR68Tfm7GIuKw3PAHz74jAsKSm/yKTHyf3kwDHDMEosMUVGm/AHSA+w== 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 7wSLW7OxqZFunfM5AffjmklE7mebR3LWQ7xaDbFd4MwnmlJO+0hz9N71yuF2W9lYxoYBm068zYlwNVKXRtaN0DOgoCuN7y/R2kXIIwomHCO14tPjsy8J4vtwBsB/YrfIfsA4sJzlw9P0StwsW0SG9/Q5fc6sTj85oCa+y5HmJZSClBfuYuk29e8R+jtxrtmGjQU3hIUJFoehsO71TBvwe0mK0zUsUSLoXmYv+1BuYo4IR5DufP/QufIq+lZ4Qnh+RcYDgsWSHedoa/Kr0fsdrGgP/j8KeFmzTR3+tsRKMqe4uj+APLQsKvAsDHR55+16rMt6RK6v4JP2vrTmPEf1KPuzNqUrhMapvayjOT7JK4aKL3LlFQ8iVaardrICrNticeaWHuHjg2rq1KKoIbt2ATgWpVQl9M2Tku0z5dx7WC+IJ9Ms5U2/C5BNqiwzSiwkHLUDi+IePE3a9Xwubv00Aq7jpA8ENtUiT0+hgjSEKZv0hByv25VNcufWH5dU9ZpmGnulemYGPCnqUm/8SbvzlX7zFLpqZTbJR8svdoo2xtBmn/RWp3yrj+m3cyryjwUY3IRffLGmhSPzJ9GRNtXaOkntD2LHbxfHsj3d4yNQlZbTDKUAKOK4H1x/xT1sZmnWbb+24pWiNt331MsLemqUeZB22kHM4EgsGKeNzMNSC0c60NGnoOJuU3IAdEgb1JpEDkBxJurrfXV35oLoK2VBToZK72Pp6k85jmEIMPdMn7dCdEDB3XiypbAMsfe+rTdWem+hrqt3lH8OJFD4L/MoIrSnnd+urt43Iv3RAlRpw3taMsnirofQfX/3ri266byWUdQPf5y2zqhCHEf8BtgObdNOQhFwZbOELIoa89Q4SF3dwwitzMXUp1wD63oT1pLEiQ1tpRWr2GvjiioK/EwOPyVRX9S3wshJB0Av7RaHS4HkDNpb8WI5ClwUhPNw0uKZpdf3NhJxf3DM9yaE10FM8DOO5dSeJhjdaEuMKc9w9CxmWYnYlmNjiAcpfA8TxNcPw20opihvNE73Ud+9MS35ESfPL+KFjzUk2BnlBRNh19TSIUzEy3wLtyBc7ILi5cZLAiTSmG7fZE7+44fLsFjBjqwcrjWZ6qCx6IfsCoCfhlDGGc3CoC9KCGFpqIgmVs3ylPwKawzVa+dcO+ZY1oLCbcFOSuO9CPfhPsxWc5NZZLtHdj6CyT3dEbrfBJmJBRnWdiyOtD367nTGCWWo6jTPp3cs44aqem1N14EyWMKKCg/o6f5v51+bmirRx33hvTOhSN2XdrzT0fbeM86k9gpQ/Smk2YBJfN4h1+jGVcEqXwsN8jqyHa9ywzH69XEmPSHfFuPhe0r7JlhLrHq6V7tZ3JLRlB1A1tDVKBS1NwvXAP/+W8psn4lvZiGREDy2KG7GH9OeGfajbwqA2fQhkFXPA4qeUrFh10PQAcTbKaXISnGleV6cr/9/ZokRr7GTgtxkWc1mgvXC1+IP7w6wwJSAjSvdVPVYuwttwzSntdChuyRqSJLSq1sGLVFleb791gQPbb/MRXtx/hgTjuWomPW3vAH5KJyggSDii+hvxVup0wPHW/aAn2pVYr38sMODhWLE X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2f6451e5-070c-4c97-6970-08dc385d097d X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:59:02.3677 (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: s3bCPnJdHDrY+dQpbOFQtU0iPmWaDGwFBAvHCUHySN0iTaSB0xnCMkAb97ui8003mw1DmknvuSZ5/ky6xp4sXw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7859 X-Patchwork-Delegate: kuba@kernel.org From: Ben Ben-Ishay NVMEoTCP offload uses buffer registration for ddp operation. Every request comprises from SG list that might consist from elements with multiple combination sizes, thus the appropriate way to perform buffer registration is with KLM UMRs. UMR stands for user-mode memory registration, it is a mechanism to alter address translation properties of MKEY by posting WorkQueueElement aka WQE on send queue. MKEY stands for memory key, MKEY are used to describe a region in memory that can be later used by HW. KLM stands for {Key, Length, MemVa}, KLM_MKEY is indirect MKEY that enables to map multiple memory spaces with different sizes in unified MKEY. KLM UMR is a UMR that use to update a KLM_MKEY. Nothing needs to be done on memory registration completion and this notification is expensive so we add a wrapper to be able to ring the doorbell without generating any. Signed-off-by: Ben Ben-Ishay Signed-off-by: Boris Pismenny Signed-off-by: Or Gerlitz Signed-off-by: Yoray Zack Signed-off-by: Aurelien Aptel Reviewed-by: Tariq Toukan --- .../net/ethernet/mellanox/mlx5/core/en/txrx.h | 16 ++- .../mellanox/mlx5/core/en_accel/nvmeotcp.c | 123 ++++++++++++++++++ .../mlx5/core/en_accel/nvmeotcp_utils.h | 25 ++++ .../net/ethernet/mellanox/mlx5/core/en_rx.c | 4 + 4 files changed, 165 insertions(+), 3 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_utils.h diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h b/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h index cdd7fbf218ae..294fdcdb0f6c 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h @@ -50,6 +50,9 @@ enum mlx5e_icosq_wqe_type { MLX5E_ICOSQ_WQE_SET_PSV_TLS, MLX5E_ICOSQ_WQE_GET_PSV_TLS, #endif +#ifdef CONFIG_MLX5_EN_NVMEOTCP + MLX5E_ICOSQ_WQE_UMR_NVMEOTCP, +#endif }; /* General */ @@ -256,10 +259,10 @@ static inline u16 mlx5e_icosq_get_next_pi(struct mlx5e_icosq *sq, u16 size) } static inline void -mlx5e_notify_hw(struct mlx5_wq_cyc *wq, u16 pc, void __iomem *uar_map, - struct mlx5_wqe_ctrl_seg *ctrl) +__mlx5e_notify_hw(struct mlx5_wq_cyc *wq, u16 pc, void __iomem *uar_map, + struct mlx5_wqe_ctrl_seg *ctrl, u8 cq_update) { - ctrl->fm_ce_se |= MLX5_WQE_CTRL_CQ_UPDATE; + ctrl->fm_ce_se |= cq_update; /* ensure wqe is visible to device before updating doorbell record */ dma_wmb(); @@ -273,6 +276,13 @@ mlx5e_notify_hw(struct mlx5_wq_cyc *wq, u16 pc, void __iomem *uar_map, mlx5_write64((__be32 *)ctrl, uar_map); } +static inline void +mlx5e_notify_hw(struct mlx5_wq_cyc *wq, u16 pc, void __iomem *uar_map, + struct mlx5_wqe_ctrl_seg *ctrl) +{ + __mlx5e_notify_hw(wq, pc, uar_map, ctrl, MLX5_WQE_CTRL_CQ_UPDATE); +} + static inline void mlx5e_cq_arm(struct mlx5e_cq *cq) { struct mlx5_core_cq *mcq; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c index 8f99534430f0..a9392f88bef5 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c @@ -4,6 +4,7 @@ #include #include #include "en_accel/nvmeotcp.h" +#include "en_accel/nvmeotcp_utils.h" #include "en_accel/fs_tcp.h" #include "en/txrx.h" @@ -19,6 +20,120 @@ static const struct rhashtable_params rhash_queues = { .max_size = MAX_NUM_NVMEOTCP_QUEUES, }; +static void +fill_nvmeotcp_klm_wqe(struct mlx5e_nvmeotcp_queue *queue, struct mlx5e_umr_wqe *wqe, u16 ccid, + u32 klm_entries, u16 klm_offset) +{ + struct scatterlist *sgl_mkey; + u32 lkey, i; + + lkey = queue->priv->mdev->mlx5e_res.hw_objs.mkey; + for (i = 0; i < klm_entries; i++) { + sgl_mkey = &queue->ccid_table[ccid].sgl[i + klm_offset]; + wqe->inline_klms[i].bcount = cpu_to_be32(sg_dma_len(sgl_mkey)); + wqe->inline_klms[i].key = cpu_to_be32(lkey); + wqe->inline_klms[i].va = cpu_to_be64(sgl_mkey->dma_address); + } + + for (; i < ALIGN(klm_entries, MLX5_UMR_KLM_NUM_ENTRIES_ALIGNMENT); i++) { + wqe->inline_klms[i].bcount = 0; + wqe->inline_klms[i].key = 0; + wqe->inline_klms[i].va = 0; + } +} + +static void +build_nvmeotcp_klm_umr(struct mlx5e_nvmeotcp_queue *queue, struct mlx5e_umr_wqe *wqe, + u16 ccid, int klm_entries, u32 klm_offset, u32 len, + enum wqe_type klm_type) +{ + u32 id = (klm_type == KLM_UMR) ? queue->ccid_table[ccid].klm_mkey : + (mlx5e_tir_get_tirn(&queue->tir) << MLX5_WQE_CTRL_TIR_TIS_INDEX_SHIFT); + u8 opc_mod = (klm_type == KLM_UMR) ? MLX5_CTRL_SEGMENT_OPC_MOD_UMR_UMR : + MLX5_OPC_MOD_TRANSPORT_TIR_STATIC_PARAMS; + u32 ds_cnt = MLX5E_KLM_UMR_DS_CNT(ALIGN(klm_entries, MLX5_UMR_KLM_NUM_ENTRIES_ALIGNMENT)); + struct mlx5_wqe_umr_ctrl_seg *ucseg = &wqe->uctrl; + struct mlx5_wqe_ctrl_seg *cseg = &wqe->ctrl; + struct mlx5_mkey_seg *mkc = &wqe->mkc; + u32 sqn = queue->sq.sqn; + u16 pc = queue->sq.pc; + + cseg->opmod_idx_opcode = cpu_to_be32((pc << MLX5_WQE_CTRL_WQE_INDEX_SHIFT) | + MLX5_OPCODE_UMR | (opc_mod) << 24); + cseg->qpn_ds = cpu_to_be32((sqn << MLX5_WQE_CTRL_QPN_SHIFT) | ds_cnt); + cseg->general_id = cpu_to_be32(id); + + if (klm_type == KLM_UMR && !klm_offset) { + ucseg->mkey_mask = cpu_to_be64(MLX5_MKEY_MASK_XLT_OCT_SIZE | + MLX5_MKEY_MASK_LEN | MLX5_MKEY_MASK_FREE); + mkc->xlt_oct_size = cpu_to_be32(ALIGN(len, MLX5_UMR_KLM_NUM_ENTRIES_ALIGNMENT)); + mkc->len = cpu_to_be64(queue->ccid_table[ccid].size); + } + + ucseg->flags = MLX5_UMR_INLINE | MLX5_UMR_TRANSLATION_OFFSET_EN; + ucseg->xlt_octowords = cpu_to_be16(ALIGN(klm_entries, MLX5_UMR_KLM_NUM_ENTRIES_ALIGNMENT)); + ucseg->xlt_offset = cpu_to_be16(klm_offset); + fill_nvmeotcp_klm_wqe(queue, wqe, ccid, klm_entries, klm_offset); +} + +static void +mlx5e_nvmeotcp_fill_wi(struct mlx5e_icosq *sq, u32 wqebbs, u16 pi) +{ + struct mlx5e_icosq_wqe_info *wi = &sq->db.wqe_info[pi]; + + memset(wi, 0, sizeof(*wi)); + + wi->num_wqebbs = wqebbs; + wi->wqe_type = MLX5E_ICOSQ_WQE_UMR_NVMEOTCP; +} + +static u32 +post_klm_wqe(struct mlx5e_nvmeotcp_queue *queue, + enum wqe_type wqe_type, + u16 ccid, + u32 klm_length, + u32 klm_offset) +{ + struct mlx5e_icosq *sq = &queue->sq; + u32 wqebbs, cur_klm_entries; + struct mlx5e_umr_wqe *wqe; + u16 pi, wqe_sz; + + cur_klm_entries = min_t(int, queue->max_klms_per_wqe, klm_length - klm_offset); + wqe_sz = MLX5E_KLM_UMR_WQE_SZ(ALIGN(cur_klm_entries, MLX5_UMR_KLM_NUM_ENTRIES_ALIGNMENT)); + wqebbs = DIV_ROUND_UP(wqe_sz, MLX5_SEND_WQE_BB); + pi = mlx5e_icosq_get_next_pi(sq, wqebbs); + wqe = MLX5E_NVMEOTCP_FETCH_KLM_WQE(sq, pi); + mlx5e_nvmeotcp_fill_wi(sq, wqebbs, pi); + build_nvmeotcp_klm_umr(queue, wqe, ccid, cur_klm_entries, klm_offset, + klm_length, wqe_type); + sq->pc += wqebbs; + sq->doorbell_cseg = &wqe->ctrl; + return cur_klm_entries; +} + +static void +mlx5e_nvmeotcp_post_klm_wqe(struct mlx5e_nvmeotcp_queue *queue, enum wqe_type wqe_type, + u16 ccid, u32 klm_length) +{ + struct mlx5e_icosq *sq = &queue->sq; + u32 klm_offset = 0, wqes, i; + + wqes = DIV_ROUND_UP(klm_length, queue->max_klms_per_wqe); + + spin_lock_bh(&queue->sq_lock); + + for (i = 0; i < wqes; i++) + klm_offset += post_klm_wqe(queue, wqe_type, ccid, klm_length, klm_offset); + + if (wqe_type == KLM_UMR) /* not asking for completion on ddp_setup UMRs */ + __mlx5e_notify_hw(&sq->wq, sq->pc, sq->uar_map, sq->doorbell_cseg, 0); + else + mlx5e_notify_hw(&sq->wq, sq->pc, sq->uar_map, sq->doorbell_cseg); + + spin_unlock_bh(&queue->sq_lock); +} + static int mlx5e_nvmeotcp_offload_limits(struct net_device *netdev, struct ulp_ddp_limits *limits) @@ -45,6 +160,14 @@ mlx5e_nvmeotcp_ddp_setup(struct net_device *netdev, struct sock *sk, struct ulp_ddp_io *ddp) { + struct mlx5e_nvmeotcp_queue *queue; + + queue = container_of(ulp_ddp_get_ctx(sk), + struct mlx5e_nvmeotcp_queue, ulp_ddp_ctx); + + /* Placeholder - map_sg and initializing the count */ + + mlx5e_nvmeotcp_post_klm_wqe(queue, KLM_UMR, ddp->command_id, 0); return 0; } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_utils.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_utils.h new file mode 100644 index 000000000000..6ef92679c5d0 --- /dev/null +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_utils.h @@ -0,0 +1,25 @@ +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ +/* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. */ +#ifndef __MLX5E_NVMEOTCP_UTILS_H__ +#define __MLX5E_NVMEOTCP_UTILS_H__ + +#include "en.h" + +#define MLX5E_NVMEOTCP_FETCH_KLM_WQE(sq, pi) \ + ((struct mlx5e_umr_wqe *)\ + mlx5e_fetch_wqe(&(sq)->wq, pi, sizeof(struct mlx5e_umr_wqe))) + +#define MLX5_CTRL_SEGMENT_OPC_MOD_UMR_NVMEOTCP_TIR_PROGRESS_PARAMS 0x4 + +#define MLX5_CTRL_SEGMENT_OPC_MOD_UMR_TIR_PARAMS 0x2 +#define MLX5_CTRL_SEGMENT_OPC_MOD_UMR_UMR 0x0 + +enum wqe_type { + KLM_UMR, + BSF_KLM_UMR, + SET_PSV_UMR, + BSF_UMR, + KLM_INV_UMR, +}; + +#endif /* __MLX5E_NVMEOTCP_UTILS_H__ */ diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c index 780902f63823..ff8b648534db 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c @@ -1061,6 +1061,10 @@ int mlx5e_poll_ico_cq(struct mlx5e_cq *cq, int budget) case MLX5E_ICOSQ_WQE_GET_PSV_TLS: mlx5e_ktls_handle_get_psv_completion(wi, sq); break; +#endif +#ifdef CONFIG_MLX5_EN_NVMEOTCP + case MLX5E_ICOSQ_WQE_UMR_NVMEOTCP: + break; #endif default: netdev_WARN_ONCE(cq->netdev, From patchwork Wed Feb 28 12:57:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575459 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2060.outbound.protection.outlook.com [40.107.243.60]) (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 10E7C149000 for ; Wed, 28 Feb 2024 12:59:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125155; cv=fail; b=MP0pSKULwn4NMtQZkPClzaXS2pHsXQyjjuZVnu5Yu81i6kDQozrZFw08OfABeMlu3kS5NPsPnijeQO3RGBbVzWG+mWROIrbHL/SsiE34muZ6crfpqnmFZt7GJ6knDg7nBYcyNUW8HaN4vd0c+/7mVPccbAaeIUiWSHJq9A+zdro= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125155; c=relaxed/simple; bh=XcjXEdhoVx47z1Y6f6QEKxjtKe2N3Q8w1nG2GTPi2uk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=tQ0wieZYRGAsDaDisMqHq1M3nFF2JJceic6LCIHL3oHBHNDpukPxgQcOC9ziuncqrV9TbLyNhIncqC1F+imk8JMjfb+Bwah2keg2Kl/yxbu+5T5R755XWYhA1ouPqyi7j1VzOeZx/U6whrmZDGiPjPyzpLzVRyRbn7Zuk27qZtQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=Zo17v+A7; arc=fail smtp.client-ip=40.107.243.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="Zo17v+A7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QXo3k7YgLU/8aQk3cnuGhYRTglmEkz81xQ6Ed3ad5cacXpQPGTS1+wizVdrQ+lrpMC2qJ95C8Uk70JRIdALBo0MUJgmBFdwhbu26/t/xu2jCzmhgC1VKyt0fkBeMu5KwM7ArcE1xgTwxh5Nsb+uiJePt+bYtFpTVtw986m/hPVNgOYr+ibHhG/tq4YZKIJZrYiirBELNc8llmtnECAshDbPwQQ4xlKvvuxB+KmOzM+CaHw/zWCXZtFVLvIPvA8R3PuNfMgel3tGsVcVfdb4D6GR/V3dt+Wl65SuDJbg5iHSUHX6kmve8qbB4TJKTmEp9wxlFk5gNwlAWyOsVuDWsrA== 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=NqHtfgpm4iF3e/Ga01X7RT8N3AYF4wddZpUTbGaRQVk=; b=YSJfY9gqXQcO/wcL963mRZGgQx9XXD0CiPOW9lE+m5nYFyZYwUB4aXqBqPTmZzWMrRNEj0tv/9RHm+h/lBUmvUETtUIMbbLVAhTQDSQPOVIyKLwdVL7u+cXt/rGZro/rBrriBD1XgNvWMyUiqVatd8kvK6ZFEX65ciqhp5nWWKIKNnRlUAGdp6tPKA5p+B0H/qb+WFA1QSjmWviTmIGJOtORWd/Ns3LQo5D93IvUOLLCZ0KL2cRuzjh2B7xVmPVS0aM+wADYLYKHd4gd262aaG/B10kz1ZPy6SXrbG09Y/Ahvg0a/k2wXq/+2c2hEufvKxd/DrO4eKcee1PBTmTWMg== 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=NqHtfgpm4iF3e/Ga01X7RT8N3AYF4wddZpUTbGaRQVk=; b=Zo17v+A74EZ9Grv9iV3kdRkj20F7wBnUsfGfZhvMEHKmji60pgtIpA5oTC2gZMocBwhxqQ669lMQzZ0aE1sEbUZUCHUEue9jodFDP9W9UXQBNP8J1pHBe4F4g7lxFu4EkIQZR+SpwDq9EJ9j2rMSONN2xj+JSdWnSdflzN4LmtrSbZyTXseAexHDoKz8EarSmXOvp6rzbz4yMbZK+lQv2B23dQ4OPmco0YXRH4yasYKIXOKfqklMDss7mVcd8ZY0C1iYaiAqYA9gd+jufhbppFQPdvjjuB8+XI8xss1TrJMoqkVha8LfjjFGGGsqE0+oy0gtrHg4aPNM9F9uJ9gC6Q== 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 SA3PR12MB7859.namprd12.prod.outlook.com (2603:10b6:806:305::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.39; Wed, 28 Feb 2024 12:59:07 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:59:07 +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: aaptel@nvidia.com, 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 Subject: [PATCH v23 16/20] net/mlx5e: NVMEoTCP, queue init/teardown Date: Wed, 28 Feb 2024 12:57:29 +0000 Message-Id: <20240228125733.299384-17-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FR2P281CA0072.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:9a::11) 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_|SA3PR12MB7859:EE_ X-MS-Office365-Filtering-Correlation-Id: bc1eda7f-e1c1-4cca-b18b-08dc385d0c4c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sXPqKj99q3zAntUAR6V9zoN1Ad+Hx+/kDJ2AmWksRjqzu4KRhxuEtWJMxRfAohLaRCdoVqxERS+eSz7uVsnAgxAh2Ls0skiXQBzq5LAlYhgP5Z7GXY2ly1ABeisxkijUXVswRvvxUyj9rrm9Up9nruWxgMSfI1Kp8IAGibCNlOKKWFoWdKBRfVHAjTIPYkSiiKEkeKX30CdcfGtVVlh9ED6z23yJkWHM66u8lxvLLd8KDbCxWKu4I3z+rUam3goH9j7Xz9bT0x8W+CyCTpFzEgSd+ZrOppCUgqZ3t23wxX+4ceb/5hjvyDSx4St+1lXlk3gMu9LBQ7oG255uOGToKaZrjiRPS2tpsTkuyshPy90rYMTyUHaI//qCzlO4IDQX2Z3M5LxKO67Ogz6rrZzXLlib7+40/kOCbld+LZPn+2O7SUxgWuXouPEIkYDPs2c0dZhdzpjdl/d44OokzpSi62AeJNrPH08s9tlhzZWxBXCAQjPe8bEnOpxpeFk2X9rvMEhA3TRBV7UeLNCmr2Jq1K8tubk3j3M/9iufRDLoHRtx+0hadKp8MgOfP1I8BSskujy9XC6AsNVign2xB1iil2t2V6idzU9nhUCvXNM0lWXsCJ/jZYRRx/7uNDLkt41+ 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QTEACJv3rB0SU01wZ4jc4nK0uOQzw1WxB5ARcElke6dv1qS3oHOAOavxIEe4CSte8+r30IXgJ/3CtyJU6kkeaZCyWb9Sr0Z5KUNxXOG+JUN7DxYTw467ZemQB1NCWmXxsLyECA5l8UGlDVBoO6fsXcU0bFYEUJbJLplVNkl5EYTEspORi51kDGIDMH+7IrGr4EJ9aiL+wp1VQfV6h4l/O9FSVopvEkvvA/yejshn5TOGJJeknDcEDFFnsGSLo4N9E1uOjuW64paSCSnxTdQPBg5hwBGjCZhzVxQHuX8AIMoVXbWWgKl6SHhDO1upGWOV4kN7NAM/hzkruzKNxFkHQVDdIyrCmi+n21+VNCq/rej2dSE6M/08RLRBR6FGLLxDSy8dJ2/GVCtYBZ4LZEDdVJua2EBqarqZ663ybwhT1Pq315OeFb8X/LW5uN5WgnEeNBwnPGHE8HHEJd7jborO3cvaP4yXIc95iMorW+KnP+CALuu3syta/FnP3PugQoqGmmtrZmyHN3H8jkWtosPhJ/2tsl+j9O+sfIUQDQ9OpozPnYNXHRBBoWjGPcZKfSDeXQUproweKA1iWJsviIftbkP5bGRSBypQMIWHpEFcT3m9aQqcsOUl1qe4nTVTeDjIG44bAlg0U45mpVchBv857vvUtCtM/TgCUmyfchauqhL0lgmXHiN9grwimQAF0+mDZerdPYwk+2Sxw/8Hy4RCPKRkDBIArVFiWyb101cYmOG/iOEfNog4Lju4LovrJ4ASGNami3l7XqG3mCmP24Tg0EZEH33XS8ufPPBPbkxPNSiQvBkb5KI9uFO8a1PTATNPCmciPcZj/Y1rUE8KA4pHqqOwyDNXrcMBtzbA1uBu4bQ/ZJGQ1rBAt3/mk8aXWZiJ2VJ+SMElESFS0PQfNXnqi4L0NlKPomGwkoqxmof/wrk3KCeOqLUoSGHnsoC5Qy1RgKUYTD2+fee0VJN3oyYtBVfmoXeZB7wbIr0i0tfqRXiE8qOx/ASgiryaIBqn72WGep7+8IKRJzO2Oobngs8On6OXOEsdSotOdvNWkPWNQ5Rdxg/e/ENbjD+xODaBFuhWb/qSiMkxCqofW/nqAXGQalLSmpW229WeC2EAzVf4YKdW4uth4xlkbRfamKH9NwxfAaXW+U1SUurmqWuePwUb1CPj/v0cU8CiXqNkwhplkgM884C8Ozv9eLBdzOkw7ROVdSF3WFPJ2nB9AaxmQ3l1ZimDl0Brku2onFyksb3WaLP7jAyxvjqKkI7QRFJwwOo0pWUr8wmpr4GFjCgwPl5sYuIcK2lXswQjx6T7g+M79Uj8SCPaX/731VyClUvy4CHHiNWyktn5bgzwjZft136eBH1ptqeA0ic3gCULGQsYsbxWtU7WBG0d7vcOk+PyU2qNOkqMc27g0hMUC6e8ZFuleZlkaJFaSJip+GBr0jkBCuh2un7RrWiBMPZ381SrjbZEc+3v+vC+wt1aKJdTeYYoCSVuRtOAe/iE1WFvBG4h6rbkbIOdYLEcZqcXYfj0eUedap5i8h3Yt+ziAPbgxc2FouffnLFVyUVxHYOEucvKK6VbYqd0efV+qZEwAV2En53f X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: bc1eda7f-e1c1-4cca-b18b-08dc385d0c4c X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:59:07.2411 (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: Au6nzTmaa2Ys/HzpS/0uSz50JwLkbkJjWxMlePziT4mSenMK+ucoKh/VBctqlghpTma1/V4ngK8s1Nt0Wcx8RQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7859 X-Patchwork-Delegate: kuba@kernel.org From: Ben Ben-Ishay Adds the ddp ops of sk_add, sk_del and offload limits. When nvme-tcp establishes new queue/connection, the sk_add op is called. We allocate a hardware context to offload operations for this queue: - use a steering rule based on the connection 5-tuple to mark packets of this queue/connection with a flow-tag in their completion (cqe) - use a dedicated TIR to identify the queue and maintain the HW context - use a dedicated ICOSQ to maintain the HW context by UMR postings - use a dedicated tag buffer for buffer registration - maintain static and progress HW contexts by posting the proper WQEs. When nvme-tcp teardowns a queue/connection, the sk_del op is called. We teardown the queue and free the corresponding contexts. The offload limits we advertise deal with the max SG supported. [Re-enabled calling open/close icosq out of en_main.c] Signed-off-by: Ben Ben-Ishay Signed-off-by: Boris Pismenny Signed-off-by: Or Gerlitz Signed-off-by: Yoray Zack Signed-off-by: Aurelien Aptel Reviewed-by: Tariq Toukan --- drivers/net/ethernet/mellanox/mlx5/core/en.h | 4 + .../ethernet/mellanox/mlx5/core/en/rx_res.c | 28 + .../ethernet/mellanox/mlx5/core/en/rx_res.h | 4 + .../net/ethernet/mellanox/mlx5/core/en/tir.c | 15 + .../net/ethernet/mellanox/mlx5/core/en/tir.h | 2 + .../net/ethernet/mellanox/mlx5/core/en/txrx.h | 6 + .../mellanox/mlx5/core/en_accel/nvmeotcp.c | 566 +++++++++++++++++- .../mellanox/mlx5/core/en_accel/nvmeotcp.h | 4 + .../mlx5/core/en_accel/nvmeotcp_utils.h | 41 ++ .../net/ethernet/mellanox/mlx5/core/en_main.c | 8 +- .../net/ethernet/mellanox/mlx5/core/en_rx.c | 15 +- 11 files changed, 682 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h index e837ffbebe3e..14f16154c709 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h @@ -1043,6 +1043,10 @@ int mlx5e_create_rq(struct mlx5e_rq *rq, struct mlx5e_rq_param *param); void mlx5e_destroy_rq(struct mlx5e_rq *rq); struct mlx5e_sq_param; +int mlx5e_open_icosq(struct mlx5e_channel *c, struct mlx5e_params *params, + struct mlx5e_sq_param *param, struct mlx5e_icosq *sq, + work_func_t recover_work_func); +void mlx5e_close_icosq(struct mlx5e_icosq *sq); int mlx5e_open_xdpsq(struct mlx5e_channel *c, struct mlx5e_params *params, struct mlx5e_sq_param *param, struct xsk_buff_pool *xsk_pool, struct mlx5e_xdpsq *sq, bool is_redirect); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c b/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c index b23e224e3763..1bafde64130d 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.c @@ -643,6 +643,34 @@ struct mlx5e_rss_params_hash mlx5e_rx_res_get_current_hash(struct mlx5e_rx_res * return mlx5e_rss_get_hash(res->rss[0]); } +int mlx5e_rx_res_nvmeotcp_tir_create(struct mlx5e_rx_res *res, unsigned int rxq, bool crc_rx, + u32 tag_buf_id, struct mlx5e_tir *tir) +{ + bool inner_ft_support = res->features & MLX5E_RX_RES_FEATURE_INNER_FT; + struct mlx5e_tir_builder *builder; + u32 rqtn; + int err; + + builder = mlx5e_tir_builder_alloc(false); + if (!builder) + return -ENOMEM; + + rqtn = mlx5e_rx_res_get_rqtn_direct(res, rxq); + + mlx5e_tir_builder_build_rqt(builder, res->mdev->mlx5e_res.hw_objs.td.tdn, rqtn, + inner_ft_support); + mlx5e_tir_builder_build_direct(builder); + mlx5e_tir_builder_build_nvmeotcp(builder, crc_rx, tag_buf_id); + down_read(&res->pkt_merge_param_sem); + mlx5e_tir_builder_build_packet_merge(builder, &res->pkt_merge_param); + err = mlx5e_tir_init(tir, builder, res->mdev, false); + up_read(&res->pkt_merge_param_sem); + + mlx5e_tir_builder_free(builder); + + return err; +} + int mlx5e_rx_res_tls_tir_create(struct mlx5e_rx_res *res, unsigned int rxq, struct mlx5e_tir *tir) { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.h b/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.h index 82aaba8a82b3..30e9c03a559f 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/rx_res.h @@ -67,4 +67,8 @@ struct mlx5e_rss_params_hash mlx5e_rx_res_get_current_hash(struct mlx5e_rx_res * /* Accel TIRs */ int mlx5e_rx_res_tls_tir_create(struct mlx5e_rx_res *res, unsigned int rxq, struct mlx5e_tir *tir); + +int mlx5e_rx_res_nvmeotcp_tir_create(struct mlx5e_rx_res *res, unsigned int rxq, bool crc_rx, + u32 tag_buf_id, struct mlx5e_tir *tir); + #endif /* __MLX5_EN_RX_RES_H__ */ diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tir.c b/drivers/net/ethernet/mellanox/mlx5/core/en/tir.c index d4239e3b3c88..8bdf74cbd8cd 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tir.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tir.c @@ -143,6 +143,21 @@ void mlx5e_tir_builder_build_direct(struct mlx5e_tir_builder *builder) MLX5_SET(tirc, tirc, rx_hash_fn, MLX5_RX_HASH_FN_INVERTED_XOR8); } +void mlx5e_tir_builder_build_nvmeotcp(struct mlx5e_tir_builder *builder, bool crc_rx, + u32 tag_buf_id) +{ + void *tirc = mlx5e_tir_builder_get_tirc(builder); + + WARN_ON(builder->modify); + + MLX5_SET(tirc, tirc, nvmeotcp_zero_copy_en, 1); + MLX5_SET(tirc, tirc, nvmeotcp_tag_buffer_table_id, tag_buf_id); + MLX5_SET(tirc, tirc, nvmeotcp_crc_en, !!crc_rx); + MLX5_SET(tirc, tirc, self_lb_block, + MLX5_TIRC_SELF_LB_BLOCK_BLOCK_UNICAST | + MLX5_TIRC_SELF_LB_BLOCK_BLOCK_MULTICAST); +} + void mlx5e_tir_builder_build_tls(struct mlx5e_tir_builder *builder) { void *tirc = mlx5e_tir_builder_get_tirc(builder); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/tir.h b/drivers/net/ethernet/mellanox/mlx5/core/en/tir.h index 857a84bcd53a..bdec6931444b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/tir.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/tir.h @@ -35,6 +35,8 @@ void mlx5e_tir_builder_build_rss(struct mlx5e_tir_builder *builder, bool inner); void mlx5e_tir_builder_build_direct(struct mlx5e_tir_builder *builder); void mlx5e_tir_builder_build_tls(struct mlx5e_tir_builder *builder); +void mlx5e_tir_builder_build_nvmeotcp(struct mlx5e_tir_builder *builder, bool crc_rx, + u32 tag_buf_id); struct mlx5_core_dev; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h b/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h index 294fdcdb0f6c..c87dca17d5c8 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h @@ -52,6 +52,7 @@ enum mlx5e_icosq_wqe_type { #endif #ifdef CONFIG_MLX5_EN_NVMEOTCP MLX5E_ICOSQ_WQE_UMR_NVMEOTCP, + MLX5E_ICOSQ_WQE_SET_PSV_NVMEOTCP, #endif }; @@ -224,6 +225,11 @@ struct mlx5e_icosq_wqe_info { struct { struct mlx5e_ktls_rx_resync_buf *buf; } tls_get_params; +#endif +#ifdef CONFIG_MLX5_EN_NVMEOTCP + struct { + struct mlx5e_nvmeotcp_queue *queue; + } nvmeotcp_q; #endif }; }; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c index a9392f88bef5..38d87a3e2931 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c @@ -3,6 +3,7 @@ #include #include +#include #include "en_accel/nvmeotcp.h" #include "en_accel/nvmeotcp_utils.h" #include "en_accel/fs_tcp.h" @@ -11,6 +12,11 @@ #define MAX_NUM_NVMEOTCP_QUEUES (4000) #define MIN_NUM_NVMEOTCP_QUEUES (1) +/* Max PDU data will be 512K */ +#define MLX5E_NVMEOTCP_MAX_SEGMENTS (128) +#define MLX5E_NVMEOTCP_IO_THRESHOLD (32 * 1024) +#define MLX5E_NVMEOTCP_FULL_CCID_RANGE (0) + static const struct rhashtable_params rhash_queues = { .key_len = sizeof(int), .key_offset = offsetof(struct mlx5e_nvmeotcp_queue, id), @@ -20,6 +26,95 @@ static const struct rhashtable_params rhash_queues = { .max_size = MAX_NUM_NVMEOTCP_QUEUES, }; +static u32 mlx5e_get_max_sgl(struct mlx5_core_dev *mdev) +{ + return min_t(u32, + MLX5E_NVMEOTCP_MAX_SEGMENTS, + 1 << MLX5_CAP_GEN(mdev, log_max_klm_list_size)); +} + +static u32 +mlx5e_get_channel_ix_from_io_cpu(struct mlx5e_params *params, u32 io_cpu) +{ + int num_channels = params->num_channels; + u32 channel_ix = io_cpu; + + if (channel_ix >= num_channels) + channel_ix = channel_ix % num_channels; + + return channel_ix; +} + +static +int mlx5e_create_nvmeotcp_tag_buf_table(struct mlx5_core_dev *mdev, + struct mlx5e_nvmeotcp_queue *queue, + u8 log_table_size) +{ + u32 in[MLX5_ST_SZ_DW(create_nvmeotcp_tag_buf_table_in)] = {}; + u32 out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)]; + u64 general_obj_types; + void *obj; + int err; + + obj = MLX5_ADDR_OF(create_nvmeotcp_tag_buf_table_in, in, + nvmeotcp_tag_buf_table_obj); + + general_obj_types = MLX5_CAP_GEN_64(mdev, general_obj_types); + if (!(general_obj_types & + MLX5_HCA_CAP_GENERAL_OBJECT_TYPES_NVMEOTCP_TAG_BUFFER_TABLE)) + return -EINVAL; + + MLX5_SET(general_obj_in_cmd_hdr, in, opcode, + MLX5_CMD_OP_CREATE_GENERAL_OBJECT); + MLX5_SET(general_obj_in_cmd_hdr, in, obj_type, + MLX5_GENERAL_OBJECT_TYPES_NVMEOTCP_TAG_BUFFER_TABLE); + MLX5_SET(nvmeotcp_tag_buf_table_obj, obj, + log_tag_buffer_table_size, log_table_size); + + err = mlx5_cmd_exec(mdev, in, sizeof(in), out, sizeof(out)); + if (!err) + queue->tag_buf_table_id = MLX5_GET(general_obj_out_cmd_hdr, + out, obj_id); + return err; +} + +static +void mlx5_destroy_nvmeotcp_tag_buf_table(struct mlx5_core_dev *mdev, u32 uid) +{ + u32 in[MLX5_ST_SZ_DW(general_obj_in_cmd_hdr)] = {}; + u32 out[MLX5_ST_SZ_DW(general_obj_out_cmd_hdr)]; + + MLX5_SET(general_obj_in_cmd_hdr, in, opcode, + MLX5_CMD_OP_DESTROY_GENERAL_OBJECT); + MLX5_SET(general_obj_in_cmd_hdr, in, obj_type, + MLX5_GENERAL_OBJECT_TYPES_NVMEOTCP_TAG_BUFFER_TABLE); + MLX5_SET(general_obj_in_cmd_hdr, in, obj_id, uid); + + mlx5_cmd_exec(mdev, in, sizeof(in), out, sizeof(out)); +} + +static void +fill_nvmeotcp_bsf_klm_wqe(struct mlx5e_nvmeotcp_queue *queue, struct mlx5e_umr_wqe *wqe, + u16 ccid, u32 klm_entries, u16 klm_offset) +{ + u32 i; + + /* BSF_KLM_UMR is used to update the tag_buffer. To spare the + * need to update both mkc.length and tag_buffer[i].len in two + * different UMRs we initialize the tag_buffer[*].len to the + * maximum size of an entry so the HW check will pass and the + * validity of the MKEY len will be checked against the + * updated mkey context field. + */ + for (i = 0; i < klm_entries; i++) { + u32 lkey = queue->ccid_table[i + klm_offset].klm_mkey; + + wqe->inline_klms[i].bcount = cpu_to_be32(U32_MAX); + wqe->inline_klms[i].key = cpu_to_be32(lkey); + wqe->inline_klms[i].va = 0; + } +} + static void fill_nvmeotcp_klm_wqe(struct mlx5e_nvmeotcp_queue *queue, struct mlx5e_umr_wqe *wqe, u16 ccid, u32 klm_entries, u16 klm_offset) @@ -73,18 +168,149 @@ build_nvmeotcp_klm_umr(struct mlx5e_nvmeotcp_queue *queue, struct mlx5e_umr_wqe ucseg->flags = MLX5_UMR_INLINE | MLX5_UMR_TRANSLATION_OFFSET_EN; ucseg->xlt_octowords = cpu_to_be16(ALIGN(klm_entries, MLX5_UMR_KLM_NUM_ENTRIES_ALIGNMENT)); ucseg->xlt_offset = cpu_to_be16(klm_offset); - fill_nvmeotcp_klm_wqe(queue, wqe, ccid, klm_entries, klm_offset); + if (klm_type == BSF_KLM_UMR) + fill_nvmeotcp_bsf_klm_wqe(queue, wqe, ccid, klm_entries, klm_offset); + else + fill_nvmeotcp_klm_wqe(queue, wqe, ccid, klm_entries, klm_offset); +} + +static void +fill_nvmeotcp_progress_params(struct mlx5e_nvmeotcp_queue *queue, + struct mlx5_seg_nvmeotcp_progress_params *params, + u32 seq) +{ + void *ctx = params->ctx; + + params->tir_num = cpu_to_be32(mlx5e_tir_get_tirn(&queue->tir)); + + MLX5_SET(nvmeotcp_progress_params, ctx, next_pdu_tcp_sn, seq); + MLX5_SET(nvmeotcp_progress_params, ctx, pdu_tracker_state, + MLX5E_NVMEOTCP_PROGRESS_PARAMS_PDU_TRACKER_STATE_START); +} + +void +build_nvmeotcp_progress_params(struct mlx5e_nvmeotcp_queue *queue, + struct mlx5e_set_nvmeotcp_progress_params_wqe *wqe, + u32 seq) +{ + struct mlx5_wqe_ctrl_seg *cseg = &wqe->ctrl; + u32 sqn = queue->sq.sqn; + u16 pc = queue->sq.pc; + u8 opc_mod; + + memset(wqe, 0, MLX5E_NVMEOTCP_PROGRESS_PARAMS_WQE_SZ); + opc_mod = MLX5_CTRL_SEGMENT_OPC_MOD_UMR_NVMEOTCP_TIR_PROGRESS_PARAMS; + cseg->opmod_idx_opcode = cpu_to_be32((pc << MLX5_WQE_CTRL_WQE_INDEX_SHIFT) | + MLX5_OPCODE_SET_PSV | (opc_mod << 24)); + cseg->qpn_ds = cpu_to_be32((sqn << MLX5_WQE_CTRL_QPN_SHIFT) | + PROGRESS_PARAMS_DS_CNT); + fill_nvmeotcp_progress_params(queue, &wqe->params, seq); +} + +static void +fill_nvmeotcp_static_params(struct mlx5e_nvmeotcp_queue *queue, + struct mlx5_wqe_transport_static_params_seg *params, + u32 resync_seq, bool ddgst_offload_en) +{ + void *ctx = params->ctx; + + MLX5_SET(transport_static_params, ctx, const_1, 1); + MLX5_SET(transport_static_params, ctx, const_2, 2); + MLX5_SET(transport_static_params, ctx, acc_type, + MLX5_TRANSPORT_STATIC_PARAMS_ACC_TYPE_NVMETCP); + MLX5_SET(transport_static_params, ctx, nvme_resync_tcp_sn, resync_seq); + MLX5_SET(transport_static_params, ctx, pda, queue->pda); + MLX5_SET(transport_static_params, ctx, ddgst_en, + !!(queue->dgst & NVME_TCP_DATA_DIGEST_ENABLE)); + MLX5_SET(transport_static_params, ctx, ddgst_offload_en, ddgst_offload_en); + MLX5_SET(transport_static_params, ctx, hddgst_en, + !!(queue->dgst & NVME_TCP_HDR_DIGEST_ENABLE)); + MLX5_SET(transport_static_params, ctx, hdgst_offload_en, 0); + MLX5_SET(transport_static_params, ctx, ti, + MLX5_TRANSPORT_STATIC_PARAMS_TI_INITIATOR); + MLX5_SET(transport_static_params, ctx, cccid_ttag, 1); + MLX5_SET(transport_static_params, ctx, zero_copy_en, 1); +} + +void +build_nvmeotcp_static_params(struct mlx5e_nvmeotcp_queue *queue, + struct mlx5e_set_transport_static_params_wqe *wqe, + u32 resync_seq, bool crc_rx) +{ + u8 opc_mod = MLX5_OPC_MOD_TRANSPORT_TIR_STATIC_PARAMS; + struct mlx5_wqe_umr_ctrl_seg *ucseg = &wqe->uctrl; + struct mlx5_wqe_ctrl_seg *cseg = &wqe->ctrl; + u32 sqn = queue->sq.sqn; + u16 pc = queue->sq.pc; + + memset(wqe, 0, MLX5E_TRANSPORT_STATIC_PARAMS_WQE_SZ); + + cseg->opmod_idx_opcode = cpu_to_be32((pc << MLX5_WQE_CTRL_WQE_INDEX_SHIFT) | + MLX5_OPCODE_UMR | (opc_mod) << 24); + cseg->qpn_ds = cpu_to_be32((sqn << MLX5_WQE_CTRL_QPN_SHIFT) | + MLX5E_TRANSPORT_STATIC_PARAMS_DS_CNT); + cseg->imm = cpu_to_be32(mlx5e_tir_get_tirn(&queue->tir) + << MLX5_WQE_CTRL_TIR_TIS_INDEX_SHIFT); + + ucseg->flags = MLX5_UMR_INLINE; + ucseg->bsf_octowords = cpu_to_be16(MLX5E_TRANSPORT_STATIC_PARAMS_OCTWORD_SIZE); + fill_nvmeotcp_static_params(queue, &wqe->params, resync_seq, crc_rx); } static void -mlx5e_nvmeotcp_fill_wi(struct mlx5e_icosq *sq, u32 wqebbs, u16 pi) +mlx5e_nvmeotcp_fill_wi(struct mlx5e_nvmeotcp_queue *nvmeotcp_queue, + struct mlx5e_icosq *sq, u32 wqebbs, u16 pi, + enum wqe_type type) { struct mlx5e_icosq_wqe_info *wi = &sq->db.wqe_info[pi]; memset(wi, 0, sizeof(*wi)); wi->num_wqebbs = wqebbs; - wi->wqe_type = MLX5E_ICOSQ_WQE_UMR_NVMEOTCP; + switch (type) { + case SET_PSV_UMR: + wi->wqe_type = MLX5E_ICOSQ_WQE_SET_PSV_NVMEOTCP; + wi->nvmeotcp_q.queue = nvmeotcp_queue; + break; + default: + /* cases where no further action is required upon completion, such as ddp setup */ + wi->wqe_type = MLX5E_ICOSQ_WQE_UMR_NVMEOTCP; + break; + } +} + +static void +mlx5e_nvmeotcp_rx_post_static_params_wqe(struct mlx5e_nvmeotcp_queue *queue, u32 resync_seq) +{ + struct mlx5e_set_transport_static_params_wqe *wqe; + struct mlx5e_icosq *sq = &queue->sq; + u16 pi, wqebbs; + + spin_lock_bh(&queue->sq_lock); + wqebbs = MLX5E_TRANSPORT_SET_STATIC_PARAMS_WQEBBS; + pi = mlx5e_icosq_get_next_pi(sq, wqebbs); + wqe = MLX5E_TRANSPORT_FETCH_SET_STATIC_PARAMS_WQE(sq, pi); + mlx5e_nvmeotcp_fill_wi(NULL, sq, wqebbs, pi, BSF_UMR); + build_nvmeotcp_static_params(queue, wqe, resync_seq, queue->crc_rx); + sq->pc += wqebbs; + mlx5e_notify_hw(&sq->wq, sq->pc, sq->uar_map, &wqe->ctrl); + spin_unlock_bh(&queue->sq_lock); +} + +static void +mlx5e_nvmeotcp_rx_post_progress_params_wqe(struct mlx5e_nvmeotcp_queue *queue, u32 seq) +{ + struct mlx5e_set_nvmeotcp_progress_params_wqe *wqe; + struct mlx5e_icosq *sq = &queue->sq; + u16 pi, wqebbs; + + wqebbs = MLX5E_NVMEOTCP_PROGRESS_PARAMS_WQEBBS; + pi = mlx5e_icosq_get_next_pi(sq, wqebbs); + wqe = MLX5E_NVMEOTCP_FETCH_PROGRESS_PARAMS_WQE(sq, pi); + mlx5e_nvmeotcp_fill_wi(queue, sq, wqebbs, pi, SET_PSV_UMR); + build_nvmeotcp_progress_params(queue, wqe, seq); + sq->pc += wqebbs; + mlx5e_notify_hw(&sq->wq, sq->pc, sq->uar_map, &wqe->ctrl); } static u32 @@ -104,7 +330,7 @@ post_klm_wqe(struct mlx5e_nvmeotcp_queue *queue, wqebbs = DIV_ROUND_UP(wqe_sz, MLX5_SEND_WQE_BB); pi = mlx5e_icosq_get_next_pi(sq, wqebbs); wqe = MLX5E_NVMEOTCP_FETCH_KLM_WQE(sq, pi); - mlx5e_nvmeotcp_fill_wi(sq, wqebbs, pi); + mlx5e_nvmeotcp_fill_wi(queue, sq, wqebbs, pi, wqe_type); build_nvmeotcp_klm_umr(queue, wqe, ccid, cur_klm_entries, klm_offset, klm_length, wqe_type); sq->pc += wqebbs; @@ -134,25 +360,328 @@ mlx5e_nvmeotcp_post_klm_wqe(struct mlx5e_nvmeotcp_queue *queue, enum wqe_type wq spin_unlock_bh(&queue->sq_lock); } +static int mlx5e_create_nvmeotcp_mkey(struct mlx5_core_dev *mdev, u8 access_mode, + u32 translation_octword_size, u32 *mkey) +{ + int inlen = MLX5_ST_SZ_BYTES(create_mkey_in); + void *mkc; + u32 *in; + int err; + + in = kvzalloc(inlen, GFP_KERNEL); + if (!in) + return -ENOMEM; + + mkc = MLX5_ADDR_OF(create_mkey_in, in, memory_key_mkey_entry); + MLX5_SET(mkc, mkc, free, 1); + MLX5_SET(mkc, mkc, translations_octword_size, translation_octword_size); + MLX5_SET(mkc, mkc, umr_en, 1); + MLX5_SET(mkc, mkc, lw, 1); + MLX5_SET(mkc, mkc, lr, 1); + MLX5_SET(mkc, mkc, access_mode_1_0, access_mode); + + MLX5_SET(mkc, mkc, qpn, 0xffffff); + MLX5_SET(mkc, mkc, pd, mdev->mlx5e_res.hw_objs.pdn); + + err = mlx5_core_create_mkey(mdev, mkey, in, inlen); + + kvfree(in); + return err; +} + static int mlx5e_nvmeotcp_offload_limits(struct net_device *netdev, struct ulp_ddp_limits *limits) { + struct mlx5e_priv *priv = netdev_priv(netdev); + struct mlx5_core_dev *mdev = priv->mdev; + + if (limits->type != ULP_DDP_NVME) + return -EOPNOTSUPP; + + limits->max_ddp_sgl_len = mlx5e_get_max_sgl(mdev); + limits->io_threshold = MLX5E_NVMEOTCP_IO_THRESHOLD; + limits->tls = false; + limits->nvmeotcp.full_ccid_range = MLX5E_NVMEOTCP_FULL_CCID_RANGE; return 0; } +static int mlx5e_nvmeotcp_queue_handler_poll(struct napi_struct *napi, int budget) +{ + struct mlx5e_nvmeotcp_queue_handler *qh; + int work_done; + + qh = container_of(napi, struct mlx5e_nvmeotcp_queue_handler, napi); + + work_done = mlx5e_poll_ico_cq(qh->cq, budget); + + if (work_done == budget || !napi_complete_done(napi, work_done)) + goto out; + + mlx5e_cq_arm(qh->cq); + +out: + return work_done; +} + +static void +mlx5e_nvmeotcp_destroy_icosq(struct mlx5e_icosq *sq) +{ + mlx5e_close_icosq(sq); + mlx5e_close_cq(&sq->cq); +} + +static void mlx5e_nvmeotcp_icosq_err_cqe_work(struct work_struct *recover_work) +{ + struct mlx5e_icosq *sq = container_of(recover_work, struct mlx5e_icosq, recover_work); + + /* Not implemented yet. */ + + netdev_warn(sq->channel->netdev, "nvmeotcp icosq recovery is not implemented\n"); +} + +static int +mlx5e_nvmeotcp_build_icosq(struct mlx5e_nvmeotcp_queue *queue, struct mlx5e_priv *priv, int io_cpu) +{ + u16 max_sgl, max_klm_per_wqe, max_umr_per_ccid, sgl_rest, wqebbs_rest; + struct mlx5e_channel *c = priv->channels.c[queue->channel_ix]; + struct mlx5e_sq_param icosq_param = {}; + struct mlx5e_create_cq_param ccp = {}; + struct dim_cq_moder icocq_moder = {}; + struct mlx5e_icosq *icosq; + int err = -ENOMEM; + u16 log_icosq_sz; + u32 max_wqebbs; + + icosq = &queue->sq; + max_sgl = mlx5e_get_max_sgl(priv->mdev); + max_klm_per_wqe = queue->max_klms_per_wqe; + max_umr_per_ccid = max_sgl / max_klm_per_wqe; + sgl_rest = max_sgl % max_klm_per_wqe; + wqebbs_rest = sgl_rest ? MLX5E_KLM_UMR_WQEBBS(sgl_rest) : 0; + max_wqebbs = (MLX5E_KLM_UMR_WQEBBS(max_klm_per_wqe) * + max_umr_per_ccid + wqebbs_rest) * queue->size; + log_icosq_sz = order_base_2(max_wqebbs); + + mlx5e_build_icosq_param(priv->mdev, log_icosq_sz, &icosq_param); + ccp.napi = &queue->qh.napi; + ccp.ch_stats = &priv->channel_stats[queue->channel_ix]->ch; + ccp.node = cpu_to_node(io_cpu); + ccp.ix = queue->channel_ix; + + err = mlx5e_open_cq(priv->mdev, icocq_moder, &icosq_param.cqp, &ccp, &icosq->cq); + if (err) + goto err_nvmeotcp_sq; + err = mlx5e_open_icosq(c, &priv->channels.params, &icosq_param, icosq, + mlx5e_nvmeotcp_icosq_err_cqe_work); + if (err) + goto close_cq; + + spin_lock_init(&queue->sq_lock); + return 0; + +close_cq: + mlx5e_close_cq(&icosq->cq); +err_nvmeotcp_sq: + return err; +} + +static void +mlx5e_nvmeotcp_destroy_rx(struct mlx5e_priv *priv, struct mlx5e_nvmeotcp_queue *queue, + struct mlx5_core_dev *mdev) +{ + int i; + + mlx5e_accel_fs_del_sk(queue->fh); + + for (i = 0; i < queue->size; i++) + mlx5_core_destroy_mkey(mdev, queue->ccid_table[i].klm_mkey); + + mlx5e_tir_destroy(&queue->tir); + mlx5_destroy_nvmeotcp_tag_buf_table(mdev, queue->tag_buf_table_id); + + mlx5e_deactivate_icosq(&queue->sq); + napi_disable(&queue->qh.napi); + mlx5e_nvmeotcp_destroy_icosq(&queue->sq); + netif_napi_del(&queue->qh.napi); +} + +static int +mlx5e_nvmeotcp_queue_rx_init(struct mlx5e_nvmeotcp_queue *queue, + struct ulp_ddp_config *config, + struct net_device *netdev) +{ + struct nvme_tcp_ddp_config *nvme_config = &config->nvmeotcp; + u8 log_queue_size = order_base_2(nvme_config->queue_size); + struct mlx5e_priv *priv = netdev_priv(netdev); + struct mlx5_core_dev *mdev = priv->mdev; + struct sock *sk = queue->sk; + int err, max_sgls, i; + + if (nvme_config->queue_size > + BIT(MLX5_CAP_DEV_NVMEOTCP(mdev, log_max_nvmeotcp_tag_buffer_size))) + return -EINVAL; + + err = mlx5e_create_nvmeotcp_tag_buf_table(mdev, queue, log_queue_size); + if (err) + return err; + + queue->qh.cq = &queue->sq.cq; + netif_napi_add(priv->netdev, &queue->qh.napi, mlx5e_nvmeotcp_queue_handler_poll); + + mutex_lock(&priv->state_lock); + err = mlx5e_nvmeotcp_build_icosq(queue, priv, config->io_cpu); + mutex_unlock(&priv->state_lock); + if (err) + goto del_napi; + + napi_enable(&queue->qh.napi); + mlx5e_activate_icosq(&queue->sq); + + /* initializes queue->tir */ + err = mlx5e_rx_res_nvmeotcp_tir_create(priv->rx_res, queue->channel_ix, queue->crc_rx, + queue->tag_buf_table_id, &queue->tir); + if (err) + goto destroy_icosq; + + mlx5e_nvmeotcp_rx_post_static_params_wqe(queue, 0); + mlx5e_nvmeotcp_rx_post_progress_params_wqe(queue, tcp_sk(sk)->copied_seq); + + queue->ccid_table = kcalloc(queue->size, sizeof(struct mlx5e_nvmeotcp_queue_entry), + GFP_KERNEL); + if (!queue->ccid_table) { + err = -ENOMEM; + goto destroy_tir; + } + + max_sgls = mlx5e_get_max_sgl(mdev); + for (i = 0; i < queue->size; i++) { + err = mlx5e_create_nvmeotcp_mkey(mdev, MLX5_MKC_ACCESS_MODE_KLMS, max_sgls, + &queue->ccid_table[i].klm_mkey); + if (err) + goto free_ccid_table; + } + + mlx5e_nvmeotcp_post_klm_wqe(queue, BSF_KLM_UMR, 0, queue->size); + + if (!(WARN_ON(!wait_for_completion_timeout(&queue->static_params_done, + msecs_to_jiffies(3000))))) + queue->fh = mlx5e_accel_fs_add_sk(priv->fs, sk, mlx5e_tir_get_tirn(&queue->tir), + queue->id); + + if (IS_ERR_OR_NULL(queue->fh)) { + err = -EINVAL; + goto destroy_mkeys; + } + + return 0; + +destroy_mkeys: + while ((i--)) + mlx5_core_destroy_mkey(mdev, queue->ccid_table[i].klm_mkey); +free_ccid_table: + kfree(queue->ccid_table); +destroy_tir: + mlx5e_tir_destroy(&queue->tir); +destroy_icosq: + mlx5e_deactivate_icosq(&queue->sq); + napi_disable(&queue->qh.napi); + mlx5e_nvmeotcp_destroy_icosq(&queue->sq); +del_napi: + netif_napi_del(&queue->qh.napi); + mlx5_destroy_nvmeotcp_tag_buf_table(mdev, queue->tag_buf_table_id); + + return err; +} + static int mlx5e_nvmeotcp_queue_init(struct net_device *netdev, struct sock *sk, - struct ulp_ddp_config *tconfig) + struct ulp_ddp_config *config) { + struct nvme_tcp_ddp_config *nvme_config = &config->nvmeotcp; + struct mlx5e_priv *priv = netdev_priv(netdev); + struct mlx5_core_dev *mdev = priv->mdev; + struct mlx5e_nvmeotcp_queue *queue; + int queue_id, err; + + if (config->type != ULP_DDP_NVME) { + err = -EOPNOTSUPP; + goto out; + } + + queue = kzalloc(sizeof(*queue), GFP_KERNEL); + if (!queue) { + err = -ENOMEM; + goto out; + } + + queue_id = ida_simple_get(&priv->nvmeotcp->queue_ids, + MIN_NUM_NVMEOTCP_QUEUES, MAX_NUM_NVMEOTCP_QUEUES, + GFP_KERNEL); + if (queue_id < 0) { + err = -ENOSPC; + goto free_queue; + } + + queue->crc_rx = !!(nvme_config->dgst & NVME_TCP_DATA_DIGEST_ENABLE); + queue->ulp_ddp_ctx.type = ULP_DDP_NVME; + queue->sk = sk; + queue->id = queue_id; + queue->dgst = nvme_config->dgst; + queue->pda = nvme_config->cpda; + queue->channel_ix = mlx5e_get_channel_ix_from_io_cpu(&priv->channels.params, + config->io_cpu); + queue->size = nvme_config->queue_size; + queue->max_klms_per_wqe = MLX5E_MAX_KLM_PER_WQE(mdev); + queue->priv = priv; + init_completion(&queue->static_params_done); + + err = mlx5e_nvmeotcp_queue_rx_init(queue, config, netdev); + if (err) + goto remove_queue_id; + + err = rhashtable_insert_fast(&priv->nvmeotcp->queue_hash, &queue->hash, + rhash_queues); + if (err) + goto destroy_rx; + + write_lock_bh(&sk->sk_callback_lock); + ulp_ddp_set_ctx(sk, queue); + write_unlock_bh(&sk->sk_callback_lock); + refcount_set(&queue->ref_count, 1); return 0; + +destroy_rx: + mlx5e_nvmeotcp_destroy_rx(priv, queue, mdev); +remove_queue_id: + ida_simple_remove(&priv->nvmeotcp->queue_ids, queue_id); +free_queue: + kfree(queue); +out: + return err; } static void mlx5e_nvmeotcp_queue_teardown(struct net_device *netdev, struct sock *sk) { + struct mlx5e_priv *priv = netdev_priv(netdev); + struct mlx5_core_dev *mdev = priv->mdev; + struct mlx5e_nvmeotcp_queue *queue; + + queue = container_of(ulp_ddp_get_ctx(sk), struct mlx5e_nvmeotcp_queue, ulp_ddp_ctx); + + WARN_ON(refcount_read(&queue->ref_count) != 1); + mlx5e_nvmeotcp_destroy_rx(priv, queue, mdev); + + rhashtable_remove_fast(&priv->nvmeotcp->queue_hash, &queue->hash, + rhash_queues); + ida_simple_remove(&priv->nvmeotcp->queue_ids, queue->id); + write_lock_bh(&sk->sk_callback_lock); + ulp_ddp_set_ctx(sk, NULL); + write_unlock_bh(&sk->sk_callback_lock); + mlx5e_nvmeotcp_put_queue(queue); } static int @@ -171,6 +700,13 @@ mlx5e_nvmeotcp_ddp_setup(struct net_device *netdev, return 0; } +void mlx5e_nvmeotcp_ctx_complete(struct mlx5e_icosq_wqe_info *wi) +{ + struct mlx5e_nvmeotcp_queue *queue = wi->nvmeotcp_q.queue; + + complete(&queue->static_params_done); +} + static void mlx5e_nvmeotcp_ddp_teardown(struct net_device *netdev, struct sock *sk, @@ -185,6 +721,26 @@ mlx5e_nvmeotcp_ddp_resync(struct net_device *netdev, { } +struct mlx5e_nvmeotcp_queue * +mlx5e_nvmeotcp_get_queue(struct mlx5e_nvmeotcp *nvmeotcp, int id) +{ + struct mlx5e_nvmeotcp_queue *queue; + + queue = rhashtable_lookup_fast(&nvmeotcp->queue_hash, + &id, rhash_queues); + if (!IS_ERR_OR_NULL(queue)) + refcount_inc(&queue->ref_count); + return queue; +} + +void mlx5e_nvmeotcp_put_queue(struct mlx5e_nvmeotcp_queue *queue) +{ + if (refcount_dec_and_test(&queue->ref_count)) { + kfree(queue->ccid_table); + kfree(queue); + } +} + int set_ulp_ddp_nvme_tcp(struct net_device *netdev, bool enable) { struct mlx5e_priv *priv = netdev_priv(netdev); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.h index 29546992791f..8b29f3fde7f2 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.h @@ -106,6 +106,10 @@ struct mlx5e_nvmeotcp { int mlx5e_nvmeotcp_init(struct mlx5e_priv *priv); int set_ulp_ddp_nvme_tcp(struct net_device *netdev, bool enable); void mlx5e_nvmeotcp_cleanup(struct mlx5e_priv *priv); +struct mlx5e_nvmeotcp_queue * +mlx5e_nvmeotcp_get_queue(struct mlx5e_nvmeotcp *nvmeotcp, int id); +void mlx5e_nvmeotcp_put_queue(struct mlx5e_nvmeotcp_queue *queue); +void mlx5e_nvmeotcp_ctx_complete(struct mlx5e_icosq_wqe_info *wi); static inline void mlx5e_nvmeotcp_init_rx(struct mlx5e_priv *priv) {} void mlx5e_nvmeotcp_cleanup_rx(struct mlx5e_priv *priv); extern const struct ulp_ddp_dev_ops mlx5e_nvmeotcp_ops; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_utils.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_utils.h index 6ef92679c5d0..fdb194c30e3b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_utils.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_utils.h @@ -4,6 +4,35 @@ #define __MLX5E_NVMEOTCP_UTILS_H__ #include "en.h" +#include "en_accel/nvmeotcp.h" +#include "en_accel/common_utils.h" + +enum { + MLX5E_NVMEOTCP_PROGRESS_PARAMS_PDU_TRACKER_STATE_START = 0, + MLX5E_NVMEOTCP_PROGRESS_PARAMS_PDU_TRACKER_STATE_TRACKING = 1, + MLX5E_NVMEOTCP_PROGRESS_PARAMS_PDU_TRACKER_STATE_SEARCHING = 2, +}; + +struct mlx5_seg_nvmeotcp_progress_params { + __be32 tir_num; + u8 ctx[MLX5_ST_SZ_BYTES(nvmeotcp_progress_params)]; +}; + +struct mlx5e_set_nvmeotcp_progress_params_wqe { + struct mlx5_wqe_ctrl_seg ctrl; + struct mlx5_seg_nvmeotcp_progress_params params; +}; + +/* macros for wqe handling */ +#define MLX5E_NVMEOTCP_PROGRESS_PARAMS_WQE_SZ \ + (sizeof(struct mlx5e_set_nvmeotcp_progress_params_wqe)) + +#define MLX5E_NVMEOTCP_PROGRESS_PARAMS_WQEBBS \ + (DIV_ROUND_UP(MLX5E_NVMEOTCP_PROGRESS_PARAMS_WQE_SZ, MLX5_SEND_WQE_BB)) + +#define MLX5E_NVMEOTCP_FETCH_PROGRESS_PARAMS_WQE(sq, pi) \ + ((struct mlx5e_set_nvmeotcp_progress_params_wqe *)\ + mlx5e_fetch_wqe(&(sq)->wq, pi, sizeof(struct mlx5e_set_nvmeotcp_progress_params_wqe))) #define MLX5E_NVMEOTCP_FETCH_KLM_WQE(sq, pi) \ ((struct mlx5e_umr_wqe *)\ @@ -14,6 +43,9 @@ #define MLX5_CTRL_SEGMENT_OPC_MOD_UMR_TIR_PARAMS 0x2 #define MLX5_CTRL_SEGMENT_OPC_MOD_UMR_UMR 0x0 +#define PROGRESS_PARAMS_DS_CNT \ + DIV_ROUND_UP(MLX5E_NVMEOTCP_PROGRESS_PARAMS_WQE_SZ, MLX5_SEND_WQE_DS) + enum wqe_type { KLM_UMR, BSF_KLM_UMR, @@ -22,4 +54,13 @@ enum wqe_type { KLM_INV_UMR, }; +void +build_nvmeotcp_progress_params(struct mlx5e_nvmeotcp_queue *queue, + struct mlx5e_set_nvmeotcp_progress_params_wqe *wqe, u32 seq); + +void +build_nvmeotcp_static_params(struct mlx5e_nvmeotcp_queue *queue, + struct mlx5e_set_transport_static_params_wqe *wqe, + u32 resync_seq, bool crc_rx); + #endif /* __MLX5E_NVMEOTCP_UTILS_H__ */ diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index 433df982400e..fa73e671c848 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -1866,9 +1866,9 @@ void mlx5e_tx_err_cqe_work(struct work_struct *recover_work) mlx5e_reporter_tx_err_cqe(sq); } -static int mlx5e_open_icosq(struct mlx5e_channel *c, struct mlx5e_params *params, - struct mlx5e_sq_param *param, struct mlx5e_icosq *sq, - work_func_t recover_work_func) +int mlx5e_open_icosq(struct mlx5e_channel *c, struct mlx5e_params *params, + struct mlx5e_sq_param *param, struct mlx5e_icosq *sq, + work_func_t recover_work_func) { struct mlx5e_create_sq_param csp = {}; int err; @@ -1912,7 +1912,7 @@ void mlx5e_deactivate_icosq(struct mlx5e_icosq *icosq) synchronize_net(); /* Sync with NAPI. */ } -static void mlx5e_close_icosq(struct mlx5e_icosq *sq) +void mlx5e_close_icosq(struct mlx5e_icosq *sq) { if (sq->ktls_resync) mlx5e_ktls_rx_resync_destroy_resp_list(sq->ktls_resync); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c index ff8b648534db..c88c4972f708 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c @@ -53,6 +53,7 @@ #include "en_accel/macsec.h" #include "en_accel/ipsec_rxtx.h" #include "en_accel/ktls_txrx.h" +#include "en_accel/nvmeotcp.h" #include "en/xdp.h" #include "en/xsk/rx.h" #include "en/health.h" @@ -957,16 +958,23 @@ void mlx5e_free_icosq_descs(struct mlx5e_icosq *sq) ci = mlx5_wq_cyc_ctr2ix(&sq->wq, sqcc); wi = &sq->db.wqe_info[ci]; sqcc += wi->num_wqebbs; -#ifdef CONFIG_MLX5_EN_TLS switch (wi->wqe_type) { +#ifdef CONFIG_MLX5_EN_TLS case MLX5E_ICOSQ_WQE_SET_PSV_TLS: mlx5e_ktls_handle_ctx_completion(wi); break; case MLX5E_ICOSQ_WQE_GET_PSV_TLS: mlx5e_ktls_handle_get_psv_completion(wi, sq); break; - } #endif +#ifdef CONFIG_MLX5_EN_NVMEOTCP + case MLX5E_ICOSQ_WQE_SET_PSV_NVMEOTCP: + mlx5e_nvmeotcp_ctx_complete(wi); + break; +#endif + default: + break; + } } sq->cc = sqcc; } @@ -1065,6 +1073,9 @@ int mlx5e_poll_ico_cq(struct mlx5e_cq *cq, int budget) #ifdef CONFIG_MLX5_EN_NVMEOTCP case MLX5E_ICOSQ_WQE_UMR_NVMEOTCP: break; + case MLX5E_ICOSQ_WQE_SET_PSV_NVMEOTCP: + mlx5e_nvmeotcp_ctx_complete(wi); + break; #endif default: netdev_WARN_ONCE(cq->netdev, From patchwork Wed Feb 28 12:57:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575460 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2060.outbound.protection.outlook.com [40.107.243.60]) (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 BAF05149E17 for ; Wed, 28 Feb 2024 12:59:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.60 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125157; cv=fail; b=rM1ZYWkNQiXRIoimxVL39RuXppbsS8S0V9WEWU+lVNgBmsM9qV/GypoAWIiF54B9kaG5JGSUBfwel7YCn5UEailOzNx7ZayHn6RyC96yzJdHLy0ymA9ZsOG6XaAlfpVUz5M0R+FY7NhXbdy3xMsxKSkQtyavdpm4AuPOXAKWCN0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125157; c=relaxed/simple; bh=qVD0FGVsThgqxwZjJDC8AQxlHxjXdXvBVp1BopLP+xw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=fv3jDS2d2PZyU/Q7tQaqxLvJDHVFA/WshX4+8pq3zWZoQD/fOnGC1N9IUFxltSbINz2yPkNVkhAMkX4CVs5SJrbPVxI8kPfGMGypZSpP6tdERXTW8eilkJtambNplhKNIt1WOdry5orMXRvCuyCriivxq5TIwsozLc7wfKiP5sE= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=RFfKvQEC; arc=fail smtp.client-ip=40.107.243.60 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="RFfKvQEC" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fhoZQhOkSdW6SseIyLh91B1B/UQ3LWf/SOn4DwqU1xOQjLHLeDreo9qnb0zeqzaKpsU97Sn+E12P0+r9FTkPtIZQdWB+e0iFNmBrqfSEgrfna2QE4HyEed6nUNefdYM7EKUHLkzk2dOaZJzNar/v5eVXTD54mvVdd4E5wxWi4rG9bEQF2anOWrGq5wCKRmA5Muvn+xzNXpnMbJsGmKJtEGrFoXkCpLPpSPBTmdVbBPGcDUeqoKInE/VE5Cdvai3MP+NrLcFp3bChYGDEcXeheEzX4XTkb8cMCVckfzO6koA9B6wonkIgi0rUinpf46AbjN8M2F1NYT++0fjoEVScRw== 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=aBC8ZaRFywYPFjYCo1zZdOWucFVJu46ZFINHRhoYfrA=; b=AgEWG7v4kFi0gAn14AaTZDz8vi7n1+J4fcIQcLosRllbDKSEzOM5lzFovzcwMaz+Vp6sKWuIKn3I14SO8FnP3kuJRvS+Ihxj01rAfWIMhwqczzPHXv1EYY8JKw8wF7PIE4NN9+Myg5XZYgTyb/hT7bt3PZQW7yF1S9EfzP83Q6g38fJpR7l+arKiEANaBwY7KEyaWu2mdpY3CZghxYB8UQM3VAIcoPy7QTKKhWTNI1LPZENlL93QwciL2Hx9rhy30DNxjMWzHqtihXaRCplftEGB7wxMfOrHHAgOQj0GFpKHzMZcgW7tJjz0npfG+LYAHyT780i/HAC4DNoUxOr+6Q== 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=aBC8ZaRFywYPFjYCo1zZdOWucFVJu46ZFINHRhoYfrA=; b=RFfKvQECUrbsZlktNX+cYUyu4kw3xDpwOY0oshWixVEAZfDIOgmy5eTy7f16GV0r+MX6ueHm1GPR2x74V7NDH+nN3zkaJFmL1uSrMhqwvwkahVHjl0VSeVWFH69BcFFcYICK0usUMjD9iOD6KCUABPwotbVpMMbZipNCQeSE2u4a3JInMxuqEJvI11hG4qdtZV8hVi1Au9QcMwd1ALMfwWNyNHkesfAYCx1rQGdFD3J5pFlt4+GAec6TVw+q0EqRboLzFyOZDSeDLxpUf8hNNK0CAPl1Q3qelVlF98VsMvzxRpYshkJMPNtquFwqvEgxrB0R8/WCaWln8Y0rFcnvDw== 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 SA3PR12MB7859.namprd12.prod.outlook.com (2603:10b6:806:305::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.39; Wed, 28 Feb 2024 12:59:12 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:59:12 +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: aaptel@nvidia.com, 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 Subject: [PATCH v23 17/20] net/mlx5e: NVMEoTCP, ddp setup and resync Date: Wed, 28 Feb 2024 12:57:30 +0000 Message-Id: <20240228125733.299384-18-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FR4P281CA0398.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:cf::16) 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_|SA3PR12MB7859:EE_ X-MS-Office365-Filtering-Correlation-Id: 669e4728-3754-4670-6159-08dc385d0f39 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sSUqU4mN0IiTxUP7di5vT9qRRyVkYnPDx07uLEvYJxTm7NKku1oESJaZCK3HFM6r5mF5CKW0Dg0ANMhaz35YAukoJb/bwXCYJeb1aryK9w2SOS4HvoMOz1belZ/CEHdKCsclS010TXsdEWpdzjdsT1nPtq8Fmmcq1O9ZCOM/87UxfofrShLJ15E/Ck+85UmVz5uK71BLPIxH7cnrn1lznOmQBv9rU22W2c1+ybSZIApvKNXadI4mTc6Xf2WTpKZIwaL3OIM5b2RJz9cnzg4zW37JfObFNHAcNa2CGknObLumIXSnpPbNSnc3fSsT1t2I0w05uzjfYjtiOdG0KDlf88ISQXcwXIQRXdwVaSqqAt34ExHjoGn6vSXtZHH0lnDX5Jkda1ABMuN3q6vz1UDMKvF2u3RGYjQBQbgCvWCpq1TpmyaiZ1nSN826sYuYnh8b5MXFCwB6HSwHLRZxKs1Q6Jl0hpbPkb7PC1BvENjcDLNWv2iWjMm9LIMUveiGk33YB1fZKOGKr9Xn53zIfUucjtWcuBwzHFvvjNwSlw2BUJpZb8vfpzNQ9gKGleicPKL124EDy37OWFJjof0ihSzoEiGwzG6rUGbA61KTtfMyhFLduOr9SRarXgsxMTzT60Bb 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DBahtDjPnC7Vat/JydQ2RSGOPp8b7yBxH0cXmR8mURXhIsiRlElMDVVzm+wR0O2ws0m3npZpT6WV0wmYqPKXzPds1egRUdqGGBFvLX9clvLNfS2wsDO5avhQ5jfcnMTFDB/OSFsjbh8LqRSDAsMY8Zz5WQ7OFjEJzA5Qp2YfhMIHcLGyJ9phIcEKDSIU1LncS3/un38LwVmblg0Ae5ZnYgI8eMbvEiFXu8hKvEBrkaGhYneOkLJLby8St33bz7vuMUp5G2LcyuawK+RXoaK4I6GaYlavtkfu1JZw5Pc0uP00lZ7GMtQHK2tYwde5SPqq1uRlVB63g54QuoXUC3xmOkTOJi/+FqpdZFALN0GIriz8i0LBsFGGawrdWo7jkQAa2PlAHB+1CylEx/BpHDRasVPZD0qEHGihtXSyQhR8L0+BIv8gADanldh7W0Ik63IeM1WNKKEWVV2xya4A9wyTDTOea5Ol3S2D/xNDfLB0RjTbMXMuqE9o7mOcVl1wiHPzr7AlUqqRhkan+3CPuMN8r+Sem6koejJKN7MwZQb5bWbfTPUU8dVuAryrc+TQxk9MmwsyfkRfvFj1lOeL7TbpdvpNPdd3N0IjTjmJ9O9rndbapcLp01eZkSO09QOS6qtrJbcRW0kxoedkXF9O9zG5JlmDq2ZQ62OWFAmoUhMJle2EeH+aDzw3yxmKjA+00xf8cyAr17EBYw5VCXY0nH2WFAh5hVPAW1CgZ+OaYD/h9drrcRC23Iy8mO0VdaSITNsl0vPYkjIf6WWgdRVaFCUIioSbIDfVhQDUoOk871PNcgdzLHXG9xGLvYs4KttcfFLv4j5IFiqjn16yXgqjl2y6EkMkrs+BtDO02usWBtu96b2IyI+YkV9sREsI3hboGdJKZCdr6+Q7JFPkKrzEoOZ6GbCGuiKa30B5TwvqGW5JQeNKYXEqmF0ZG4mMwjl9D/7g2YfYG2/s2e3jWCIP+JIBnG8p3jiwgHzH9Lkb3oyj4ltc7Qj4PiFZ+nMjHe6H11DodtT7A+ZFQUNCDdAEME2GznS4aDnr5B+5HopemTJgkXs04tyLbQuWuQX2cjiovvr26agfclmZ8/EJO6YlFjWmQEsTiV4vZI9EdaacOLHp/YQjLIH1kPJa7rJ2OactGolXGTVjOXzJiMPOr3L4/OF/Abpbdw1AsDpYji4nBgpJ1ZXXHOM4wXhN72C4ei4u6QbQC119gRo5H3+3bVdXkBN/bgRV+4xv+qqZhDIPfwE/UXtyFSReQUkIuTWMsV8LtAXeyw6OLQURLkMyrqsySZrzo7nOJuR5qy8VP+SOZaMnaqSzRT3nATH94MFXbVh/juSSVYEe50y47FVTC6NnykxsXIK5jVzjLYEal70nzc4fpd+7umHw26a15Miq2OFQzr/rFViU2xga7bV9HmayCsqFd8vO1Z2QtDgsAkezMo2w+2Nm8X6qaJxa2EujlaFVUiIJGziFEjSqZt64zRR3eMN2Ahmx66g8y9P/BDMHAQ4DiPfYF+XtfspUegY0pKG3SzdkkmbYHFVKw3IyU9+29MGGdwu5wneQBvF1R5uDBWWfVUgW5WmKwHXLrauN5pi2zW15 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 669e4728-3754-4670-6159-08dc385d0f39 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:59:11.9495 (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: Mu1Qx81F0td34bsQGJ5rsZJ/dOK1SOyf+roSNj7clRKYvGVHZHH+i3pyK14Jb+kqZXiSEUeNjhMZGCmVDJf5Vw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7859 X-Patchwork-Delegate: kuba@kernel.org From: Ben Ben-Ishay NVMEoTCP offload uses buffer registration for every NVME request to perform direct data placement. This is achieved by creating a NIC HW mapping between the CCID (command capsule ID) to the set of buffers that compose the request. The registration is implemented via MKEY for which we do fast/async mapping using KLM UMR WQE. The buffer registration takes place when the ULP calls the ddp_setup op which is done before they send their corresponding request to the other side (e.g nvmf target). We don't wait for the completion of the registration before returning back to the ulp. The reason being that the HW mapping should be in place fast enough vs the RTT it would take for the request to be responded. If this doesn't happen, some IO may not be ddp-offloaded, but that doesn't stop the overall offloading session. When the offloading HW gets out of sync with the protocol session, a hardware/software handshake takes place to resync. The ddp_resync op is the part of the handshake where the SW confirms to the HW that a indeed they identified correctly a PDU header at a certain TCP sequence number. This allows the HW to resume the offload. The 1st part of the handshake is when the HW identifies such sequence number in an arriving packet. A special mark is made on the completion (cqe) and then the mlx5 driver invokes the ddp resync_request callback advertised by the ULP in the ddp context - this is in downstream patch. Signed-off-by: Ben Ben-Ishay Signed-off-by: Boris Pismenny Signed-off-by: Or Gerlitz Signed-off-by: Yoray Zack Signed-off-by: Aurelien Aptel Reviewed-by: Tariq Toukan --- .../mellanox/mlx5/core/en_accel/nvmeotcp.c | 146 +++++++++++++++++- 1 file changed, 144 insertions(+), 2 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c index 38d87a3e2931..dd9c28d60fd3 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c @@ -684,19 +684,156 @@ mlx5e_nvmeotcp_queue_teardown(struct net_device *netdev, mlx5e_nvmeotcp_put_queue(queue); } +static bool +mlx5e_nvmeotcp_validate_small_sgl_suffix(struct scatterlist *sg, int sg_len, int mtu) +{ + int i, hole_size, hole_len, chunk_size = 0; + + for (i = 1; i < sg_len; i++) + chunk_size += sg_dma_len(&sg[i]); + + if (chunk_size >= mtu) + return true; + + hole_size = mtu - chunk_size - 1; + hole_len = DIV_ROUND_UP(hole_size, PAGE_SIZE); + + if (sg_len + hole_len > MAX_SKB_FRAGS) + return false; + + return true; +} + +static bool +mlx5e_nvmeotcp_validate_big_sgl_suffix(struct scatterlist *sg, int sg_len, int mtu) +{ + int i, j, last_elem, window_idx, window_size = MAX_SKB_FRAGS - 1; + int chunk_size = 0; + + last_elem = sg_len - window_size; + window_idx = window_size; + + for (j = 1; j < window_size; j++) + chunk_size += sg_dma_len(&sg[j]); + + for (i = 1; i <= last_elem; i++, window_idx++) { + chunk_size += sg_dma_len(&sg[window_idx]); + if (chunk_size < mtu - 1) + return false; + + chunk_size -= sg_dma_len(&sg[i]); + } + + return true; +} + +/* This function makes sure that the middle/suffix of a PDU SGL meets the + * restriction of MAX_SKB_FRAGS. There are two cases here: + * 1. sg_len < MAX_SKB_FRAGS - the extreme case here is a packet that consists + * of one byte from the first SG element + the rest of the SGL and the remaining + * space of the packet will be scattered to the WQE and will be pointed by + * SKB frags. + * 2. sg_len => MAX_SKB_FRAGS - the extreme case here is a packet that consists + * of one byte from middle SG element + 15 continuous SG elements + one byte + * from a sequential SG element or the rest of the packet. + */ +static bool +mlx5e_nvmeotcp_validate_sgl_suffix(struct scatterlist *sg, int sg_len, int mtu) +{ + int ret; + + if (sg_len < MAX_SKB_FRAGS) + ret = mlx5e_nvmeotcp_validate_small_sgl_suffix(sg, sg_len, mtu); + else + ret = mlx5e_nvmeotcp_validate_big_sgl_suffix(sg, sg_len, mtu); + + return ret; +} + +static bool +mlx5e_nvmeotcp_validate_sgl_prefix(struct scatterlist *sg, int sg_len, int mtu) +{ + int i, hole_size, hole_len, tmp_len, chunk_size = 0; + + tmp_len = min_t(int, sg_len, MAX_SKB_FRAGS); + + for (i = 0; i < tmp_len; i++) + chunk_size += sg_dma_len(&sg[i]); + + if (chunk_size >= mtu) + return true; + + hole_size = mtu - chunk_size; + hole_len = DIV_ROUND_UP(hole_size, PAGE_SIZE); + + if (tmp_len + hole_len > MAX_SKB_FRAGS) + return false; + + return true; +} + +/* This function is responsible to ensure that a PDU could be offloaded. + * PDU is offloaded by building a non-linear SKB such that each SGL element is + * placed in frag, thus this function should ensure that all packets that + * represent part of the PDU won't exaggerate from MAX_SKB_FRAGS SGL. + * In addition NVMEoTCP offload has one PDU offload for packet restriction. + * Packet could start with a new PDU and then we should check that the prefix + * of the PDU meets the requirement or a packet can start in the middle of SG + * element and then we should check that the suffix of PDU meets the requirement. + */ +static bool +mlx5e_nvmeotcp_validate_sgl(struct scatterlist *sg, int sg_len, int mtu) +{ + int max_hole_frags; + + max_hole_frags = DIV_ROUND_UP(mtu, PAGE_SIZE); + if (sg_len + max_hole_frags <= MAX_SKB_FRAGS) + return true; + + if (!mlx5e_nvmeotcp_validate_sgl_prefix(sg, sg_len, mtu) || + !mlx5e_nvmeotcp_validate_sgl_suffix(sg, sg_len, mtu)) + return false; + + return true; +} + static int mlx5e_nvmeotcp_ddp_setup(struct net_device *netdev, struct sock *sk, struct ulp_ddp_io *ddp) { + struct scatterlist *sg = ddp->sg_table.sgl; + struct mlx5e_nvmeotcp_queue_entry *nvqt; struct mlx5e_nvmeotcp_queue *queue; + struct mlx5_core_dev *mdev; + int i, size = 0, count = 0; queue = container_of(ulp_ddp_get_ctx(sk), struct mlx5e_nvmeotcp_queue, ulp_ddp_ctx); + mdev = queue->priv->mdev; + count = dma_map_sg(mdev->device, ddp->sg_table.sgl, ddp->nents, + DMA_FROM_DEVICE); + + if (count <= 0) + return -EINVAL; - /* Placeholder - map_sg and initializing the count */ + if (WARN_ON(count > mlx5e_get_max_sgl(mdev))) + return -ENOSPC; + + if (!mlx5e_nvmeotcp_validate_sgl(sg, count, READ_ONCE(netdev->mtu))) + return -EOPNOTSUPP; + + for (i = 0; i < count; i++) + size += sg_dma_len(&sg[i]); + + nvqt = &queue->ccid_table[ddp->command_id]; + nvqt->size = size; + nvqt->ddp = ddp; + nvqt->sgl = sg; + nvqt->ccid_gen++; + nvqt->sgl_length = count; + mlx5e_nvmeotcp_post_klm_wqe(queue, KLM_UMR, ddp->command_id, count); - mlx5e_nvmeotcp_post_klm_wqe(queue, KLM_UMR, ddp->command_id, 0); return 0; } @@ -719,6 +856,11 @@ static void mlx5e_nvmeotcp_ddp_resync(struct net_device *netdev, struct sock *sk, u32 seq) { + struct mlx5e_nvmeotcp_queue *queue = + container_of(ulp_ddp_get_ctx(sk), struct mlx5e_nvmeotcp_queue, ulp_ddp_ctx); + + queue->after_resync_cqe = 1; + mlx5e_nvmeotcp_rx_post_static_params_wqe(queue, seq); } struct mlx5e_nvmeotcp_queue * From patchwork Wed Feb 28 12:57:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575461 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12on2043.outbound.protection.outlook.com [40.107.243.43]) (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 2666B149E17 for ; Wed, 28 Feb 2024 12:59:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.243.43 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125160; cv=fail; b=Gc/+B+WifHsCT8uGmuvkI7GUYkE7HaOzMUDeKQigpehIBWU+Tf+1VRk36249g7cU3Qvfy8L97JLZegKk4vnsYxa7yuTFyem7H+0C/nc8960TUoiWYb5iBZbkac9AkYQwnHJHSZbonSG7Xnta7lk7x1YwemPBxARCrXG+uYweJzc= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125160; c=relaxed/simple; bh=qZgBFZaJ8lXYfH3s4azqv4srfrt9C8DsTp2lotkhSVY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=u7vC52Nc0WSl85//9oMciss4QMZU/cHpFN2Yibmc6/Rbv5NTP9E8nn5x7qOhaxLp5aLLYo9r5Ppnqu5tfCjSfa1tBnkKbdJVzvZordMnxr7m97sBNtuqxvFdZf3751dYVYKon6N1JcYqxHZLEIc/EU7YulKFsLqAE889qrIYH54= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=VwhVrIhj; arc=fail smtp.client-ip=40.107.243.43 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="VwhVrIhj" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=grLwieOyyW9PHQymPGN6zyXBNrWjqFCXVEYrf9E3vYQP0Q1IPXrdtnmV2noNzZ7EIRr4JBDawxNvoEQNhrwdKC9UrR6aR9sIoWrgoop/FivhwnTGa0opKM3VpE84/4Lo4fnOe3NDHBxUiagksrojlTonZnKzqgm5ESUPLLFyws7mtm1042lScTW1NK1HGot8RgytiAmETnujcGXQR/iFzbvNhiwzuwAzklmd75U7VdunL42eRYDPlmT803YMVfNKaxCKpBr2+MXGosAXcvhSyYracRGyEicGnJUuIM/qae4aDm8EzPWtkcWondwUrVuzQRWWxdIHs0n9uQ+fri2u3Q== 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=Qu8AqpFXgApXcdBsqxSHt4Z39ZB/TOeP1spLQWTT/Yg=; b=GuEBTvqGKNjWTlAqoEqd8GS2ZpcUgYnuH68A288pPRLZ2jkg0YMUFdLm1A6RiDArRo0GJtj1HVt5NXd65ohXPqJqBlIYjBSEERLCV+d+xW28Rey8bm529p4RF0ItinxRUtguz/vAuxX1VWzkx4tLH/+zE95Cqr/P31R8FWn9yxtyOYmTxE9O7vSex/O4145EBBUBQNG9lGlU1HD0HjN4gNvTee08RobHFUeRqJFBGQQRb19+6ktzckNxB1Ys1DGV+RBwpkDtK8qkvL11QIHxbsOh43AZz41184XPnOgW9BWGr6TmSe3a/kCNP9QWYK0DfJGeRhGdcaV8qG0NTDuYZQ== 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=Qu8AqpFXgApXcdBsqxSHt4Z39ZB/TOeP1spLQWTT/Yg=; b=VwhVrIhjdVp3reeLWPq7Ib+LxTZLGkUC70l/NKa4qXNgxhulWjkAQrRcA5mH5IcubRNKnHfw2IR1z/I74m4ZvDy+mzKwfsqwTNb2G/Xk37qWpLqzPIT+//y1vdBuOWTwtXeR9zKMZsE8JKjzPMF1TUf82Nc95NC02l6whyJbgghAnDJNfwc9+w3I4YF5NPRs9xSqx+l5p5Ulnc8XLwhzbQ7X58mFb7CwmhFhqoKIS6ym7vQNADEE71zGTzTjCf6uz6Ein87raZlQkPnpSdYlIvZyFafeXehoj6RtKNSKfQGkyb83z9PRxy+YKdNJKg1UuIjtD1O6ifnSP3lYf2cglg== 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 SA3PR12MB7859.namprd12.prod.outlook.com (2603:10b6:806:305::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.39; Wed, 28 Feb 2024 12:59:16 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:59:16 +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: aaptel@nvidia.com, 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 Subject: [PATCH v23 18/20] net/mlx5e: NVMEoTCP, async ddp invalidation Date: Wed, 28 Feb 2024 12:57:31 +0000 Message-Id: <20240228125733.299384-19-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FR4P281CA0206.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:e5::10) 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_|SA3PR12MB7859:EE_ X-MS-Office365-Filtering-Correlation-Id: de112f0f-a4dd-47fb-e7e7-08dc385d11d8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: obYixjtmpRxFekdHm/0DcA6+abw9HucQwT0JEeuGXBOvfQ8in+UpdgkNxMnF1Gc3miygCbX/7BLzz3swNa3XH9SxTnVhQoKkqkT2jemr60riykeCyzR2Jgj1fxDf+YJqkxyaVFIgBOiV+NqVMwVy7OEV6m21q+DKBvTtQ/i2yHi8iYslI63kTs6v+ZGp8ww6gSlsioRZdf+qgOigLK/SOPB9lBZotaflennyjcVGgKaTmVKH74EsOL/8Mb+b996nuux2cAjj+2qMKGAMmSuIEjq6DyR+6AUsGwZ/qp54+cb1FSZq1HqstnCtTvMXoQSHgTDfE2QjAPCxMKg6KDqjXREFJi6uKG8MbzJktYZnJ9MeHdkC+4Yc/fwCXkxvY8nZI2K0u7oO6JMx30/VxyJYZMhBBcce9rtnksNxUqeG1AA5OhUB9tziydZhYxh+E3SoS01AEtzpJvuWcxfmB4zh2uWrt8YzHGBcwwcZYNVhDV+b/7Gj2axRhepnXfbzZ0j/V0e++3+RovU8YpfMqT4QhR6IjoS2ppE5R3DLzg8xWtL6fR/14gX7fSAh+/mWBn5xt1XwRLyIJNDhE+Q4jfYffniQrh94XDQlAWAFUeI3hkohMIJFMC3Og90OGJ7VXMKdccROWgqZ7yZYI6nuHMhlSA== 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tlxcJ51mo3KvAjyFAj3msIPZaFiS6dioFtTBCcM1tm6FSoSBKPEnoE2gNtoKfnENYTMIix0RNHjlELjxb6d5LDUHeK7w9jZlU2q/yVdhKikuiKPdkVTPJ7Zi5PFJwOUi+e5gY0Ig7MBqUKjkT5nPkPxDLkPLLkhvFdWqfVl0UeFt9f+0P/dfzTHLXKtERvq2eM92/DXdFwmSoXMDtjyL4ZMg1LRgk5TJWdAJ2EEr08lOy6xWxlEoCSUjlz7g8en90rLqoaon79HtubHmT0G1Zb2TZCy49ZXITyeYzaDKxWK09a5PELG78OZEQPTO+y20zZaAoWM5o+rModCdtUXxa+xVMLc81mQSE8qiTm0QIvP+xuHsbbd/VUbLTMz2bW7qBa55e2ZMKOP7UrSc94YwN7P6xxY9aiy72SaoNZ/kgzdxp//a/Dabq7eklwUNbNj+GAvarljatQ5i1JOKF9B0OVV3zXY/d/wIcrTHTgVyHmXUVlHYLzlv/0o3VS5cXE7Gj9gZ/rrdgFVbxwmI1kmgyP0zkUrYu2KwJEIyczbIm1Dg5ydwyxPne0vM1Q4ClVPaNwWaZV1dDN5sxioj37x3LdRNz1qZANkevhBo2xIrIGV1W36sQnHFAElkok1LI5PO/321medbpf8MK9zre7/RGVkMTFidkGgxUCFgUhg8V7lvUFcpCpX5nZeOVjDCcJndIk0eXBjpgAlfWIRap0ayssvbU8OcbXB0O3dJJEHelLqg7JRjiieDfBGqYSOcQOuTEiC/cir9EccW3n9GkzuQBa05oKf0yEXb0KGXgLV5l6i8Dp7bGrR+J6tkoEMI2YZLwQpMBiSKUGC/r+YRKa6lqxILzWt1Z+uDA09JLju4+vYqWeKKrZzxZwSyUuREKDJsoPKTZ8lOF6mjX7lPs3GPj4sGWVU1X1GtcAXs4x8zH6i7u6cP983DBeVIsVKrqC3ci/olkTFkdJejCWQNVHNpgPIzFtAjDriHJ+Ii6sgMBr5yp+tRi9OgE81/OPaMpmpp4joWP5hSlQd0/MdmRCGIi0JlXbqrM8fnxtIg0wj8MB1WJb4l7GtFHFX9fZYUk6HoxYe2t7hxZLefTOZ7rAUESO+nHV8F93SIUAJRwwHG0QgcxzJfDYxyGDmKpkSkXdN7x6PPsO9Iq5a14C+Xucg2uh01BcL3OpzOq9AB+iDZNHylmiipWnqJly91PmNps2sKmfEkh2PN8LG1dztd8WjloxE5wZrrpghfAsWwkYEn16/wk5uW1E9thnXjqILjanAbWx2gbopkkzE/VqfBkuTsOz4GjaYmxg8d9XDY77IQPEPh/oBzCHMZ1LeErcJit+awr+n8EjJitZEQDYBxHXtJHyO6fGq6emiiwayBWmMi87TpcrrOAyAuET7fpRbxltItsGdIGVklXVLdbR08HCaj1Yn3qvwuZI3Mpmo8hDyq7DQj2od1ox2xWn7CrsRWfgjec4M5n42xmBuUkmpgWujaCwwAfPAvSvLHbwrHzjFTJ/l0FHyih1SA8UuU5pHc1fwq0F/l/+scYyBTly0z3poOVqjFt1XWXYkzYow/hZJrb1BSbmf0W3wlmDDFeq0yZGvr X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: de112f0f-a4dd-47fb-e7e7-08dc385d11d8 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:59:16.3491 (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: zQ2uM8w0U2MgM+md4xKyj7H3zBCEQtc4eUy8uNU6TrVUITXMdT2z9nYJga5nyAYxa1FmfVU6b91zrf7ZrUbuhg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA3PR12MB7859 X-Patchwork-Delegate: kuba@kernel.org From: Ben Ben-Ishay After the ULP consumed the buffers of the offloaded request, it calls the ddp_teardown op to release the NIC mapping for them and allow the NIC to reuse the HW contexts associated with offloading this IO. We do a fast/async un-mapping via UMR WQE. In this case, the ULP does holds off with completing the request towards the upper/application layers until the HW unmapping is done. When the corresponding CQE is received, a notification is done via the the teardown_done ddp callback advertised by the ULP in the ddp context. Signed-off-by: Ben Ben-Ishay Signed-off-by: Boris Pismenny Signed-off-by: Or Gerlitz Signed-off-by: Yoray Zack Signed-off-by: Aurelien Aptel Reviewed-by: Tariq Toukan --- .../net/ethernet/mellanox/mlx5/core/en/txrx.h | 4 ++ .../mellanox/mlx5/core/en_accel/nvmeotcp.c | 66 ++++++++++++++++--- .../mellanox/mlx5/core/en_accel/nvmeotcp.h | 1 + .../net/ethernet/mellanox/mlx5/core/en_rx.c | 6 ++ 4 files changed, 67 insertions(+), 10 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h b/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h index c87dca17d5c8..3c124f708afc 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h @@ -52,6 +52,7 @@ enum mlx5e_icosq_wqe_type { #endif #ifdef CONFIG_MLX5_EN_NVMEOTCP MLX5E_ICOSQ_WQE_UMR_NVMEOTCP, + MLX5E_ICOSQ_WQE_UMR_NVMEOTCP_INVALIDATE, MLX5E_ICOSQ_WQE_SET_PSV_NVMEOTCP, #endif }; @@ -230,6 +231,9 @@ struct mlx5e_icosq_wqe_info { struct { struct mlx5e_nvmeotcp_queue *queue; } nvmeotcp_q; + struct { + struct mlx5e_nvmeotcp_queue_entry *entry; + } nvmeotcp_qe; #endif }; }; diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c index dd9c28d60fd3..4c49ff9a7999 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c @@ -142,10 +142,11 @@ build_nvmeotcp_klm_umr(struct mlx5e_nvmeotcp_queue *queue, struct mlx5e_umr_wqe u16 ccid, int klm_entries, u32 klm_offset, u32 len, enum wqe_type klm_type) { - u32 id = (klm_type == KLM_UMR) ? queue->ccid_table[ccid].klm_mkey : - (mlx5e_tir_get_tirn(&queue->tir) << MLX5_WQE_CTRL_TIR_TIS_INDEX_SHIFT); - u8 opc_mod = (klm_type == KLM_UMR) ? MLX5_CTRL_SEGMENT_OPC_MOD_UMR_UMR : - MLX5_OPC_MOD_TRANSPORT_TIR_STATIC_PARAMS; + u32 id = (klm_type == BSF_KLM_UMR) ? + (mlx5e_tir_get_tirn(&queue->tir) << MLX5_WQE_CTRL_TIR_TIS_INDEX_SHIFT) : + queue->ccid_table[ccid].klm_mkey; + u8 opc_mod = (klm_type == BSF_KLM_UMR) ? MLX5_OPC_MOD_TRANSPORT_TIR_STATIC_PARAMS : + MLX5_CTRL_SEGMENT_OPC_MOD_UMR_UMR; u32 ds_cnt = MLX5E_KLM_UMR_DS_CNT(ALIGN(klm_entries, MLX5_UMR_KLM_NUM_ENTRIES_ALIGNMENT)); struct mlx5_wqe_umr_ctrl_seg *ucseg = &wqe->uctrl; struct mlx5_wqe_ctrl_seg *cseg = &wqe->ctrl; @@ -158,6 +159,13 @@ build_nvmeotcp_klm_umr(struct mlx5e_nvmeotcp_queue *queue, struct mlx5e_umr_wqe cseg->qpn_ds = cpu_to_be32((sqn << MLX5_WQE_CTRL_QPN_SHIFT) | ds_cnt); cseg->general_id = cpu_to_be32(id); + if (!klm_entries) { /* this is invalidate */ + ucseg->mkey_mask = cpu_to_be64(MLX5_MKEY_MASK_FREE); + ucseg->flags = MLX5_UMR_INLINE; + mkc->status = MLX5_MKEY_STATUS_FREE; + return; + } + if (klm_type == KLM_UMR && !klm_offset) { ucseg->mkey_mask = cpu_to_be64(MLX5_MKEY_MASK_XLT_OCT_SIZE | MLX5_MKEY_MASK_LEN | MLX5_MKEY_MASK_FREE); @@ -259,8 +267,8 @@ build_nvmeotcp_static_params(struct mlx5e_nvmeotcp_queue *queue, static void mlx5e_nvmeotcp_fill_wi(struct mlx5e_nvmeotcp_queue *nvmeotcp_queue, - struct mlx5e_icosq *sq, u32 wqebbs, u16 pi, - enum wqe_type type) + struct mlx5e_icosq *sq, u32 wqebbs, + u16 pi, u16 ccid, enum wqe_type type) { struct mlx5e_icosq_wqe_info *wi = &sq->db.wqe_info[pi]; @@ -272,6 +280,10 @@ mlx5e_nvmeotcp_fill_wi(struct mlx5e_nvmeotcp_queue *nvmeotcp_queue, wi->wqe_type = MLX5E_ICOSQ_WQE_SET_PSV_NVMEOTCP; wi->nvmeotcp_q.queue = nvmeotcp_queue; break; + case KLM_INV_UMR: + wi->wqe_type = MLX5E_ICOSQ_WQE_UMR_NVMEOTCP_INVALIDATE; + wi->nvmeotcp_qe.entry = &nvmeotcp_queue->ccid_table[ccid]; + break; default: /* cases where no further action is required upon completion, such as ddp setup */ wi->wqe_type = MLX5E_ICOSQ_WQE_UMR_NVMEOTCP; @@ -290,7 +302,7 @@ mlx5e_nvmeotcp_rx_post_static_params_wqe(struct mlx5e_nvmeotcp_queue *queue, u32 wqebbs = MLX5E_TRANSPORT_SET_STATIC_PARAMS_WQEBBS; pi = mlx5e_icosq_get_next_pi(sq, wqebbs); wqe = MLX5E_TRANSPORT_FETCH_SET_STATIC_PARAMS_WQE(sq, pi); - mlx5e_nvmeotcp_fill_wi(NULL, sq, wqebbs, pi, BSF_UMR); + mlx5e_nvmeotcp_fill_wi(NULL, sq, wqebbs, pi, 0, BSF_UMR); build_nvmeotcp_static_params(queue, wqe, resync_seq, queue->crc_rx); sq->pc += wqebbs; mlx5e_notify_hw(&sq->wq, sq->pc, sq->uar_map, &wqe->ctrl); @@ -307,7 +319,7 @@ mlx5e_nvmeotcp_rx_post_progress_params_wqe(struct mlx5e_nvmeotcp_queue *queue, u wqebbs = MLX5E_NVMEOTCP_PROGRESS_PARAMS_WQEBBS; pi = mlx5e_icosq_get_next_pi(sq, wqebbs); wqe = MLX5E_NVMEOTCP_FETCH_PROGRESS_PARAMS_WQE(sq, pi); - mlx5e_nvmeotcp_fill_wi(queue, sq, wqebbs, pi, SET_PSV_UMR); + mlx5e_nvmeotcp_fill_wi(queue, sq, wqebbs, pi, 0, SET_PSV_UMR); build_nvmeotcp_progress_params(queue, wqe, seq); sq->pc += wqebbs; mlx5e_notify_hw(&sq->wq, sq->pc, sq->uar_map, &wqe->ctrl); @@ -330,7 +342,7 @@ post_klm_wqe(struct mlx5e_nvmeotcp_queue *queue, wqebbs = DIV_ROUND_UP(wqe_sz, MLX5_SEND_WQE_BB); pi = mlx5e_icosq_get_next_pi(sq, wqebbs); wqe = MLX5E_NVMEOTCP_FETCH_KLM_WQE(sq, pi); - mlx5e_nvmeotcp_fill_wi(queue, sq, wqebbs, pi, wqe_type); + mlx5e_nvmeotcp_fill_wi(queue, sq, wqebbs, pi, ccid, wqe_type); build_nvmeotcp_klm_umr(queue, wqe, ccid, cur_klm_entries, klm_offset, klm_length, wqe_type); sq->pc += wqebbs; @@ -345,7 +357,10 @@ mlx5e_nvmeotcp_post_klm_wqe(struct mlx5e_nvmeotcp_queue *queue, enum wqe_type wq struct mlx5e_icosq *sq = &queue->sq; u32 klm_offset = 0, wqes, i; - wqes = DIV_ROUND_UP(klm_length, queue->max_klms_per_wqe); + if (wqe_type == KLM_INV_UMR) + wqes = 1; + else + wqes = DIV_ROUND_UP(klm_length, queue->max_klms_per_wqe); spin_lock_bh(&queue->sq_lock); @@ -844,12 +859,43 @@ void mlx5e_nvmeotcp_ctx_complete(struct mlx5e_icosq_wqe_info *wi) complete(&queue->static_params_done); } +void mlx5e_nvmeotcp_ddp_inv_done(struct mlx5e_icosq_wqe_info *wi) +{ + struct mlx5e_nvmeotcp_queue_entry *q_entry = wi->nvmeotcp_qe.entry; + struct mlx5e_nvmeotcp_queue *queue = q_entry->queue; + struct mlx5_core_dev *mdev = queue->priv->mdev; + struct ulp_ddp_io *ddp = q_entry->ddp; + const struct ulp_ddp_ulp_ops *ulp_ops; + + dma_unmap_sg(mdev->device, ddp->sg_table.sgl, + q_entry->sgl_length, DMA_FROM_DEVICE); + + q_entry->sgl_length = 0; + + ulp_ops = inet_csk(queue->sk)->icsk_ulp_ddp_ops; + if (ulp_ops && ulp_ops->ddp_teardown_done) + ulp_ops->ddp_teardown_done(q_entry->ddp_ctx); +} + static void mlx5e_nvmeotcp_ddp_teardown(struct net_device *netdev, struct sock *sk, struct ulp_ddp_io *ddp, void *ddp_ctx) { + struct mlx5e_nvmeotcp_queue_entry *q_entry; + struct mlx5e_nvmeotcp_queue *queue; + + queue = container_of(ulp_ddp_get_ctx(sk), struct mlx5e_nvmeotcp_queue, ulp_ddp_ctx); + q_entry = &queue->ccid_table[ddp->command_id]; + WARN_ONCE(q_entry->sgl_length == 0, + "Invalidation of empty sgl (CID 0x%x, queue 0x%x)\n", + ddp->command_id, queue->id); + + q_entry->ddp_ctx = ddp_ctx; + q_entry->queue = queue; + + mlx5e_nvmeotcp_post_klm_wqe(queue, KLM_INV_UMR, ddp->command_id, 0); } static void diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.h index 8b29f3fde7f2..13817d8a0aae 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.h @@ -109,6 +109,7 @@ void mlx5e_nvmeotcp_cleanup(struct mlx5e_priv *priv); struct mlx5e_nvmeotcp_queue * mlx5e_nvmeotcp_get_queue(struct mlx5e_nvmeotcp *nvmeotcp, int id); void mlx5e_nvmeotcp_put_queue(struct mlx5e_nvmeotcp_queue *queue); +void mlx5e_nvmeotcp_ddp_inv_done(struct mlx5e_icosq_wqe_info *wi); void mlx5e_nvmeotcp_ctx_complete(struct mlx5e_icosq_wqe_info *wi); static inline void mlx5e_nvmeotcp_init_rx(struct mlx5e_priv *priv) {} void mlx5e_nvmeotcp_cleanup_rx(struct mlx5e_priv *priv); diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c index c88c4972f708..89ef317bdd2f 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c @@ -968,6 +968,9 @@ void mlx5e_free_icosq_descs(struct mlx5e_icosq *sq) break; #endif #ifdef CONFIG_MLX5_EN_NVMEOTCP + case MLX5E_ICOSQ_WQE_UMR_NVMEOTCP_INVALIDATE: + mlx5e_nvmeotcp_ddp_inv_done(wi); + break; case MLX5E_ICOSQ_WQE_SET_PSV_NVMEOTCP: mlx5e_nvmeotcp_ctx_complete(wi); break; @@ -1073,6 +1076,9 @@ int mlx5e_poll_ico_cq(struct mlx5e_cq *cq, int budget) #ifdef CONFIG_MLX5_EN_NVMEOTCP case MLX5E_ICOSQ_WQE_UMR_NVMEOTCP: break; + case MLX5E_ICOSQ_WQE_UMR_NVMEOTCP_INVALIDATE: + mlx5e_nvmeotcp_ddp_inv_done(wi); + break; case MLX5E_ICOSQ_WQE_SET_PSV_NVMEOTCP: mlx5e_nvmeotcp_ctx_complete(wi); break; From patchwork Wed Feb 28 12:57:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575462 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) (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 6470A14900E for ; Wed, 28 Feb 2024 12:59:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125167; cv=fail; b=FXoYyTY1LUwnpV8haPa0ufO44pzYfr8fSSpojOzJ983ufGQgZIAL1/kiqeapRgR8jjK5v2H3zbJVq+BV12+K1j+vLxK0QcqK8Jdp9L2MYZKlRORtt8f+89A6409IQVkgoRpM5FHgPbz69dD0Q475g/ZXRUKQcIVrnWJNFT81LMA= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125167; c=relaxed/simple; bh=LnjNBTLvIdVHJwIwbvvSw78gm7LZd4b2SShFlAgYPOY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=F6hKv/Gwib5pMr+1NFIEgyaixy2FZ3n3hJMJLDK/Wy3JrPl1ekthFs2RuzzpJSOi6x4SELvuYUvTGa4nFPUXJOdr7dRPqyV9s0BpRsF8pQKhDR2F9zKZjOtGYCRSjRvagBplmwYxetFV/5bu3ksZHvu7/UoypakkvHy3hnHg//Q= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=bcX/7mMz; arc=fail smtp.client-ip=40.107.236.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="bcX/7mMz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=C1Q8DnXF8MqrZvneY/N699vACnFcw+KLbeKtCdQ1WmhdnZQKuao11CqnL37hlDPgIKBOp9l4X6z7xUo76s6Y3JbL27bagwRl4vKgQtj4cI4DKHdkmk28ySW0p6oUT/Ftq0Qis/zk5rAeVHzIYvN+ggCIc4qsfNmSZnst0783jnVbWBe2h3L65603YMvhNQzJ04kCBqWXjrnfKEG33nwdyebXoXU71+d9wCxG5JsN71gUjsOZ2G82H9wwv3HZmn/siLeCzy0emGnRm9q54LzIwHz/a7GsMDZl7qeH0xVEDz86ApD3J73I8F5uiCQSXg1lSI5RXLvfAyG5MTu7KhQEew== 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=T9Lu4MiKfu8rJ5irWeGURpUvOF6lyqp1XHPnMcGD6f4=; b=L9OVJR50U2VsnUNAK+7fSaT3RGQK6ovVZYIfTFHnev80zrWj3wIVnSWjULN/J21d17OFtnzA4MyxIbN01K3Qv9iM54W2mRwx6rVMwvsEJ7M51UxRFd+CEeN/jtnfGK5aIvfYfoyunSLCju4j8R1DhW2saybis8DuwHPKO4hyp6emMLVwrHMu7QVBZn4k5pke74YPFlAtEmXkjwRNmonohC/I+ZSS1bnjsNr2AytnDLNccGi3Zm8RJbwi4fdOmxfzmdlR3Xzd1mlwPIAX+9OgSijQsbC0ZFOcUTNJ/CL3DGkHMMaW5TQO47D1d9ojDn8X8cown3zVvL75bE28QYqQVQ== 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=T9Lu4MiKfu8rJ5irWeGURpUvOF6lyqp1XHPnMcGD6f4=; b=bcX/7mMzvrC9r+XYrvT2riaAnyOtckW3rzj56a8wxLHznwaPfPstSr0fOhBjsWljS2CwddBFdNYrYGOqxeTPE+lXESW5afLK2d9zixrkEIQm9b8e3u/3crqNNUwQ/i+buVW5A11qDOgskZD2/egKyNuw2PlwFKYAgJbow+CYbEHW7Q5KBhNMgGwIsTrNZ7wFZK/m9B1KQk8UxauOUvKCwLSsqOk+OBEs0ODiSMTKcYzU0H8rs3nswjERfeCdCF+CmnbAX2S8L9D9ug4R9yjkjgWplqdOTr0v8uGBC1QkCBLZUSS/gdR8zVuqFVFrP08NVsts0BnzCdOX/T1jqf64bw== 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 CH3PR12MB9218.namprd12.prod.outlook.com (2603:10b6:610:19f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.36; Wed, 28 Feb 2024 12:59:21 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:59:21 +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: aaptel@nvidia.com, 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 Subject: [PATCH v23 19/20] net/mlx5e: NVMEoTCP, data-path for DDP+DDGST offload Date: Wed, 28 Feb 2024 12:57:32 +0000 Message-Id: <20240228125733.299384-20-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FR4P281CA0086.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:cd::13) 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_|CH3PR12MB9218:EE_ X-MS-Office365-Filtering-Correlation-Id: c262a873-a6a2-4eab-9572-08dc385d14e9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: amzLuyaRnOitR0uj5xW7wPy1KEotClG0e/f+BlZszmlIdOnCHUYgAfcHiF/8tzUZYeqTegp0Xuj5MYxtH5LyLPjrhV3eM4nT0vPrWctfxcF6mMdGv9m7GmrDVk7ct+BDbz6JzSJ5XSfwrOhE5nakPq+wTXTwcDVG1U029JA1nPwAJsG/O5b17ZVnXxg+ld0zK4GezlIX2iUq9ne4lH4VWwstqeraPBS88C6pZ4PriB3vcVUS+mBJwRPiBcQIeOmLnsHJH4EmyoVi2k1y+bS6fnBJlWeESUq1KRyx0UTtHgLc5fXN1H/Tk7+mtsIyPN9gv7XHDdm67/zM6HiQ1BxcPZyfvZT8CvH2RnLTpIOw/bBDdD/coY+Qif+8WsVYx3TCW7q0y/SUe3Let+tBwXeB70weZfeZo82u1riuixMAbs/EzyZOVdk0yv6zoITr0eNom1imkWkt48w04V1bEZxLOJhGC2Y6NR2JXjZhHanfdpuPvDiT4pcA5Cm6eyJVXzG6BX5xCs2eItaYrTl2BJ+5dKc0TSll+P/XJ6ASk9XHB9S3LzotwAMeWze8ty4J3LWLBdfLCOuIbQ9BzWCOxi1ocKhIQvBPv82gJtFfYi965t2lRdZ/kQoSe+JBoR3VYLaYWPeYQ23UGD7zkzQhThqIvg== 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MtR+SMV+IcResWOPvyXA1GGZrbfnk+ANhUCgQzjAyB1EBthEDjPlS4pjc7QMisiB14FzxxI4ETfxOjEcKb6y8A7UExjG6iK9C7Mnx0mH4em61xhdfBfswqwhEEu9CBXGd0UvGMZDGcjl7VpR49iB9upAuWQT3ScNscIuDK+xGCThoMcGlNQQKkfd7mEa28OjwhFlYEOUbksroN3oyKF129FTAn27c5F2RqlvzH3CoKs2phpe1zENABaEWLuBceRMxxmmKgXwVTSBHhER1mX1gto634R7vtihVIy4vZgHj72XmRBViqFRGjoAWSbmOw1Ncs+oVugWeqfk/Ao97sxX2k75KHWlwVSAvfVDdTMVdOMIGtMoRMvAh4k59jxT6I5BtNvasMAVHRZCcQpTicermT3aKxBKhHYZSvhZIwGMCT5Bed/gRWOU4zr2S44DgoeXtr9GtF+c7/RReU940JYGt2DkzA0nWB57SLPLhkZ1MsQAD5FPg8M5TR4zeLt+P6vNKQtzQBJlNR/5R/EJ5Kgn0P0v1oi+DS3RswKnn6tDfHs2RZfFLpaIvwx4XtQJxhpctyYyouzkeKdGRseTziqkCDdKIqiYHe9HeyxpFEbcRkc9iGeczkY4zOAUS7Ofr5CnreqmydMYYEWEOWk652RTESMwUco5q13QT+UtO36kjbCzLH9VQSmFnzWdO1x/7Y1jTIqk3qn1GyhDpUD7SGSDLAAgtUu6u7UNx9PDdn0NcvLBBCB1mJ15dw92ab69Xpy9WN/hE4VxKYFcamraO4VAXfDKUgOSkDb049gdzuK6CX/hlqW7T1vnGQZJx8Y08024iAH8sVsWQzsMunSsENj9JoTDaDXhPbrj1/qy7DNtCHVu93XvK+kZFU3IF/erf3v774uf14QDPKc076woyM5ZWPlDioHXUubIi56r1Q8Y7nRFBwSy1VrCmgM5bMeTX7eJrOMLe0ZB6YnngK+I5Tr3xd/f+9L9nVAHRPPZ1mNiqxQvFVbaPEzmmTiLFlxZGIcqeWQMOG4naUVrRdz7iG26GLYUm2X/TCvgMIdxa88or6tQXLmZtLJPVWqEZB8rLjT+og6AgVck5CO+Swm8vYhnfyprt7xKUAA2i3BxImIhN0doSx096Cw6fA4XDhzmJ/ImGQgE5mJkRz9u5ziMWBlG7wfX1h74Pv7nekWTxI8gI80370x0aI6kjMWsnrY+XBu/k/HyXd5P8BRz4pqecH7oe8suCJUG5xmG1uRO0oxc1WVilYL87rVJWBzxPMzNLjj/OU+0GwNjI3g8TdnNC9I4xM95WYPvwl5M8liZa9MFiyoAg7d+U8uwHba0MThIT7cNOS0ukAgMJYjKDsLwBKL1I/1qDlXWRIeFUToh7C+n8gK+Oa5P1HNaljT2OwCeyWuYCOT5wPh8O8c1hcxGm1Jwv/dXetl+wA6tbbxRUmlZ79zyHz1wKta8zR51RlzRZD6MIn8QhmW6Suyye0BhDiTYKtQoaH8iEcK559W9svADLiFz6ghmbp72QahGWwTtBeisDIkzFFpF4hYGV+Ly4nkwTbDyH3ghgI+h3Ui7CBRUAydSSy2IJ2Gq+GTv2GAN7HzE X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: c262a873-a6a2-4eab-9572-08dc385d14e9 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:59:21.4934 (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: Oax+xSu8zYIvs+0Ej3OfcB8EtLyMkYEYOoQykSV5j71taFKGU3LnZzT3R+uyOYVzd/ygelc+BDwVct458NCnSQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9218 X-Patchwork-Delegate: kuba@kernel.org From: Ben Ben-Ishay This patch implements the data-path for direct data placement (DDP) and DDGST offloads. NVMEoTCP DDP constructs an SKB from each CQE, while pointing at NVME destination buffers. In turn, this enables the offload, as the NVMe-TCP layer will skip the copy when src == dst. Additionally, this patch adds support for DDGST (CRC32) offload. HW will report DDGST offload only if it has not encountered an error in the received packet. We pass this indication in skb->ulp_crc up the stack to NVMe-TCP to skip computing the DDGST if all corresponding SKBs were verified by HW. This patch also handles context resynchronization requests made by NIC HW. The resync request is passed to the NVMe-TCP layer to be handled at a later point in time. Finally, we also use the skb->no_condense bit to avoid skb_condense. This is critical as every SKB that uses DDP has a hole that fits perfectly with skb_condense's policy, but filling this hole is counter-productive as the data there already resides in its destination buffer. Signed-off-by: Ben Ben-Ishay Signed-off-by: Boris Pismenny Signed-off-by: Or Gerlitz Signed-off-by: Yoray Zack Signed-off-by: Aurelien Aptel Reviewed-by: Tariq Toukan --- .../net/ethernet/mellanox/mlx5/core/Makefile | 2 +- .../net/ethernet/mellanox/mlx5/core/en/txrx.h | 6 + .../mlx5/core/en_accel/nvmeotcp_rxtx.c | 345 ++++++++++++++++++ .../mlx5/core/en_accel/nvmeotcp_rxtx.h | 37 ++ .../net/ethernet/mellanox/mlx5/core/en_rx.c | 44 ++- 5 files changed, 419 insertions(+), 15 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_rxtx.c create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_rxtx.h diff --git a/drivers/net/ethernet/mellanox/mlx5/core/Makefile b/drivers/net/ethernet/mellanox/mlx5/core/Makefile index f397e2eb0cdc..2db0bd83d517 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/Makefile +++ b/drivers/net/ethernet/mellanox/mlx5/core/Makefile @@ -109,7 +109,7 @@ mlx5_core-$(CONFIG_MLX5_EN_TLS) += en_accel/ktls_stats.o \ en_accel/fs_tcp.o en_accel/ktls.o en_accel/ktls_txrx.o \ en_accel/ktls_tx.o en_accel/ktls_rx.o -mlx5_core-$(CONFIG_MLX5_EN_NVMEOTCP) += en_accel/fs_tcp.o en_accel/nvmeotcp.o +mlx5_core-$(CONFIG_MLX5_EN_NVMEOTCP) += en_accel/fs_tcp.o en_accel/nvmeotcp.o en_accel/nvmeotcp_rxtx.o mlx5_core-$(CONFIG_MLX5_SW_STEERING) += steering/dr_domain.o steering/dr_table.o \ steering/dr_matcher.o steering/dr_rule.o \ diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h b/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h index 3c124f708afc..516054e480d9 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/txrx.h @@ -526,4 +526,10 @@ static inline struct mlx5e_mpw_info *mlx5e_get_mpw_info(struct mlx5e_rq *rq, int return (struct mlx5e_mpw_info *)((char *)rq->mpwqe.info + array_size(i, isz)); } + +static inline struct mlx5e_wqe_frag_info *get_frag(struct mlx5e_rq *rq, u16 ix) +{ + return &rq->wqe.frags[ix << rq->wqe.info.log_num_frags]; +} + #endif diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_rxtx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_rxtx.c new file mode 100644 index 000000000000..269d8075f3c2 --- /dev/null +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_rxtx.c @@ -0,0 +1,345 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB +// Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. + +#include "en_accel/nvmeotcp_rxtx.h" +#include +#include "en/txrx.h" + +#define MLX5E_TC_FLOW_ID_MASK 0x00ffffff + +static struct mlx5e_frag_page *mlx5e_get_frag(struct mlx5e_rq *rq, + struct mlx5_cqe64 *cqe) +{ + struct mlx5e_frag_page *fp; + + if (rq->wq_type == MLX5_WQ_TYPE_LINKED_LIST_STRIDING_RQ) { + u16 wqe_id = be16_to_cpu(cqe->wqe_id); + u16 stride_ix = mpwrq_get_cqe_stride_index(cqe); + u32 wqe_offset = stride_ix << rq->mpwqe.log_stride_sz; + u32 page_idx = wqe_offset >> rq->mpwqe.page_shift; + struct mlx5e_mpw_info *wi = mlx5e_get_mpw_info(rq, wqe_id); + union mlx5e_alloc_units *au = &wi->alloc_units; + + fp = &au->frag_pages[page_idx]; + } else { + /* Legacy */ + struct mlx5_wq_cyc *wq = &rq->wqe.wq; + u16 ci = mlx5_wq_cyc_ctr2ix(wq, be16_to_cpu(cqe->wqe_counter)); + struct mlx5e_wqe_frag_info *wi = get_frag(rq, ci); + + fp = wi->frag_page; + } + + return fp; +} + +static void nvmeotcp_update_resync(struct mlx5e_nvmeotcp_queue *queue, + struct mlx5e_cqe128 *cqe128) +{ + const struct ulp_ddp_ulp_ops *ulp_ops; + u32 seq; + + seq = be32_to_cpu(cqe128->resync_tcp_sn); + ulp_ops = inet_csk(queue->sk)->icsk_ulp_ddp_ops; + if (ulp_ops && ulp_ops->resync_request) + ulp_ops->resync_request(queue->sk, seq, ULP_DDP_RESYNC_PENDING); +} + +static void mlx5e_nvmeotcp_advance_sgl_iter(struct mlx5e_nvmeotcp_queue *queue) +{ + struct mlx5e_nvmeotcp_queue_entry *nqe = &queue->ccid_table[queue->ccid]; + + queue->ccoff += nqe->sgl[queue->ccsglidx].length; + queue->ccoff_inner = 0; + queue->ccsglidx++; +} + +static inline void +mlx5e_nvmeotcp_add_skb_frag(struct net_device *netdev, struct sk_buff *skb, + struct mlx5e_nvmeotcp_queue *queue, + struct mlx5e_nvmeotcp_queue_entry *nqe, u32 fragsz) +{ + dma_sync_single_for_cpu(&netdev->dev, + nqe->sgl[queue->ccsglidx].offset + queue->ccoff_inner, + fragsz, DMA_FROM_DEVICE); + + page_ref_inc(compound_head(sg_page(&nqe->sgl[queue->ccsglidx]))); + + skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, + sg_page(&nqe->sgl[queue->ccsglidx]), + nqe->sgl[queue->ccsglidx].offset + queue->ccoff_inner, + fragsz, + fragsz); +} + +static inline void +mlx5_nvmeotcp_add_tail_nonlinear(struct sk_buff *skb, skb_frag_t *org_frags, + int org_nr_frags, int frag_index) +{ + while (org_nr_frags != frag_index) { + skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, + skb_frag_page(&org_frags[frag_index]), + skb_frag_off(&org_frags[frag_index]), + skb_frag_size(&org_frags[frag_index]), + skb_frag_size(&org_frags[frag_index])); + frag_index++; + } +} + +static void +mlx5_nvmeotcp_add_tail(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe, + struct mlx5e_nvmeotcp_queue *queue, struct sk_buff *skb, + int offset, int len) +{ + struct mlx5e_frag_page *frag_page = mlx5e_get_frag(rq, cqe); + + frag_page->frags++; + skb_add_rx_frag(skb, skb_shinfo(skb)->nr_frags, + virt_to_page(skb->data), offset, len, len); +} + +static void mlx5_nvmeotcp_trim_nonlinear(struct sk_buff *skb, skb_frag_t *org_frags, + int *frag_index, int remaining) +{ + unsigned int frag_size; + int nr_frags; + + /* skip @remaining bytes in frags */ + *frag_index = 0; + while (remaining) { + frag_size = skb_frag_size(&skb_shinfo(skb)->frags[*frag_index]); + if (frag_size > remaining) { + skb_frag_off_add(&skb_shinfo(skb)->frags[*frag_index], + remaining); + skb_frag_size_sub(&skb_shinfo(skb)->frags[*frag_index], + remaining); + remaining = 0; + } else { + remaining -= frag_size; + skb_frag_unref(skb, *frag_index); + *frag_index += 1; + } + } + + /* save original frags for the tail and unref */ + nr_frags = skb_shinfo(skb)->nr_frags; + memcpy(&org_frags[*frag_index], &skb_shinfo(skb)->frags[*frag_index], + (nr_frags - *frag_index) * sizeof(skb_frag_t)); + + /* remove frags from skb */ + skb_shinfo(skb)->nr_frags = 0; + skb->len -= skb->data_len; + skb->truesize -= skb->data_len; + skb->data_len = 0; +} + +static bool +mlx5e_nvmeotcp_rebuild_rx_skb_nonlinear(struct mlx5e_rq *rq, struct sk_buff *skb, + struct mlx5_cqe64 *cqe, u32 cqe_bcnt) +{ + int ccoff, cclen, hlen, ccid, remaining, fragsz, to_copy = 0; + struct net_device *netdev = rq->netdev; + struct mlx5e_priv *priv = netdev_priv(netdev); + struct mlx5e_nvmeotcp_queue_entry *nqe; + skb_frag_t org_frags[MAX_SKB_FRAGS]; + struct mlx5e_nvmeotcp_queue *queue; + int org_nr_frags, frag_index; + struct mlx5e_cqe128 *cqe128; + u32 queue_id; + + queue_id = (be32_to_cpu(cqe->sop_drop_qpn) & MLX5E_TC_FLOW_ID_MASK); + queue = mlx5e_nvmeotcp_get_queue(priv->nvmeotcp, queue_id); + if (unlikely(!queue)) { + dev_kfree_skb_any(skb); + return false; + } + + cqe128 = container_of(cqe, struct mlx5e_cqe128, cqe64); + if (cqe_is_nvmeotcp_resync(cqe)) { + nvmeotcp_update_resync(queue, cqe128); + mlx5e_nvmeotcp_put_queue(queue); + return true; + } + + /* If a resync occurred in the previous cqe, + * the current cqe.crcvalid bit may not be valid, + * so we will treat it as 0 + */ + if (unlikely(queue->after_resync_cqe) && cqe_is_nvmeotcp_crcvalid(cqe)) { + skb->ulp_crc = 0; + queue->after_resync_cqe = 0; + } else { + if (queue->crc_rx) + skb->ulp_crc = cqe_is_nvmeotcp_crcvalid(cqe); + } + + skb->no_condense = cqe_is_nvmeotcp_zc(cqe); + if (!cqe_is_nvmeotcp_zc(cqe)) { + mlx5e_nvmeotcp_put_queue(queue); + return true; + } + + /* cc ddp from cqe */ + ccid = be16_to_cpu(cqe128->ccid); + ccoff = be32_to_cpu(cqe128->ccoff); + cclen = be16_to_cpu(cqe128->cclen); + hlen = be16_to_cpu(cqe128->hlen); + + /* carve a hole in the skb for DDP data */ + org_nr_frags = skb_shinfo(skb)->nr_frags; + mlx5_nvmeotcp_trim_nonlinear(skb, org_frags, &frag_index, cclen); + nqe = &queue->ccid_table[ccid]; + + /* packet starts new ccid? */ + if (queue->ccid != ccid || queue->ccid_gen != nqe->ccid_gen) { + queue->ccid = ccid; + queue->ccoff = 0; + queue->ccoff_inner = 0; + queue->ccsglidx = 0; + queue->ccid_gen = nqe->ccid_gen; + } + + /* skip inside cc until the ccoff in the cqe */ + while (queue->ccoff + queue->ccoff_inner < ccoff) { + remaining = nqe->sgl[queue->ccsglidx].length - queue->ccoff_inner; + fragsz = min_t(off_t, remaining, + ccoff - (queue->ccoff + queue->ccoff_inner)); + + if (fragsz == remaining) + mlx5e_nvmeotcp_advance_sgl_iter(queue); + else + queue->ccoff_inner += fragsz; + } + + /* adjust the skb according to the cqe cc */ + while (to_copy < cclen) { + remaining = nqe->sgl[queue->ccsglidx].length - queue->ccoff_inner; + fragsz = min_t(int, remaining, cclen - to_copy); + + mlx5e_nvmeotcp_add_skb_frag(netdev, skb, queue, nqe, fragsz); + to_copy += fragsz; + if (fragsz == remaining) + mlx5e_nvmeotcp_advance_sgl_iter(queue); + else + queue->ccoff_inner += fragsz; + } + + if (cqe_bcnt > hlen + cclen) { + remaining = cqe_bcnt - hlen - cclen; + mlx5_nvmeotcp_add_tail_nonlinear(skb, org_frags, + org_nr_frags, + frag_index); + } + + mlx5e_nvmeotcp_put_queue(queue); + return true; +} + +static bool +mlx5e_nvmeotcp_rebuild_rx_skb_linear(struct mlx5e_rq *rq, struct sk_buff *skb, + struct mlx5_cqe64 *cqe, u32 cqe_bcnt) +{ + int ccoff, cclen, hlen, ccid, remaining, fragsz, to_copy = 0; + struct net_device *netdev = rq->netdev; + struct mlx5e_priv *priv = netdev_priv(netdev); + struct mlx5e_nvmeotcp_queue_entry *nqe; + struct mlx5e_nvmeotcp_queue *queue; + struct mlx5e_cqe128 *cqe128; + u32 queue_id; + + queue_id = (be32_to_cpu(cqe->sop_drop_qpn) & MLX5E_TC_FLOW_ID_MASK); + queue = mlx5e_nvmeotcp_get_queue(priv->nvmeotcp, queue_id); + if (unlikely(!queue)) { + dev_kfree_skb_any(skb); + return false; + } + + cqe128 = container_of(cqe, struct mlx5e_cqe128, cqe64); + if (cqe_is_nvmeotcp_resync(cqe)) { + nvmeotcp_update_resync(queue, cqe128); + mlx5e_nvmeotcp_put_queue(queue); + return true; + } + + /* If a resync occurred in the previous cqe, + * the current cqe.crcvalid bit may not be valid, + * so we will treat it as 0 + */ + if (unlikely(queue->after_resync_cqe) && cqe_is_nvmeotcp_crcvalid(cqe)) { + skb->ulp_crc = 0; + queue->after_resync_cqe = 0; + } else { + if (queue->crc_rx) + skb->ulp_crc = cqe_is_nvmeotcp_crcvalid(cqe); + } + + skb->no_condense = cqe_is_nvmeotcp_zc(cqe); + if (!cqe_is_nvmeotcp_zc(cqe)) { + mlx5e_nvmeotcp_put_queue(queue); + return true; + } + + /* cc ddp from cqe */ + ccid = be16_to_cpu(cqe128->ccid); + ccoff = be32_to_cpu(cqe128->ccoff); + cclen = be16_to_cpu(cqe128->cclen); + hlen = be16_to_cpu(cqe128->hlen); + + /* carve a hole in the skb for DDP data */ + skb_trim(skb, hlen); + nqe = &queue->ccid_table[ccid]; + + /* packet starts new ccid? */ + if (queue->ccid != ccid || queue->ccid_gen != nqe->ccid_gen) { + queue->ccid = ccid; + queue->ccoff = 0; + queue->ccoff_inner = 0; + queue->ccsglidx = 0; + queue->ccid_gen = nqe->ccid_gen; + } + + /* skip inside cc until the ccoff in the cqe */ + while (queue->ccoff + queue->ccoff_inner < ccoff) { + remaining = nqe->sgl[queue->ccsglidx].length - queue->ccoff_inner; + fragsz = min_t(off_t, remaining, + ccoff - (queue->ccoff + queue->ccoff_inner)); + + if (fragsz == remaining) + mlx5e_nvmeotcp_advance_sgl_iter(queue); + else + queue->ccoff_inner += fragsz; + } + + /* adjust the skb according to the cqe cc */ + while (to_copy < cclen) { + remaining = nqe->sgl[queue->ccsglidx].length - queue->ccoff_inner; + fragsz = min_t(int, remaining, cclen - to_copy); + + mlx5e_nvmeotcp_add_skb_frag(netdev, skb, queue, nqe, fragsz); + to_copy += fragsz; + if (fragsz == remaining) + mlx5e_nvmeotcp_advance_sgl_iter(queue); + else + queue->ccoff_inner += fragsz; + } + + if (cqe_bcnt > hlen + cclen) { + remaining = cqe_bcnt - hlen - cclen; + mlx5_nvmeotcp_add_tail(rq, cqe, queue, skb, + offset_in_page(skb->data) + + hlen + cclen, remaining); + } + + mlx5e_nvmeotcp_put_queue(queue); + return true; +} + +bool +mlx5e_nvmeotcp_rebuild_rx_skb(struct mlx5e_rq *rq, struct sk_buff *skb, + struct mlx5_cqe64 *cqe, u32 cqe_bcnt) +{ + if (skb->data_len) + return mlx5e_nvmeotcp_rebuild_rx_skb_nonlinear(rq, skb, cqe, cqe_bcnt); + else + return mlx5e_nvmeotcp_rebuild_rx_skb_linear(rq, skb, cqe, cqe_bcnt); +} diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_rxtx.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_rxtx.h new file mode 100644 index 000000000000..a8ca8a53bac6 --- /dev/null +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_rxtx.h @@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB */ +/* Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. */ +#ifndef __MLX5E_NVMEOTCP_RXTX_H__ +#define __MLX5E_NVMEOTCP_RXTX_H__ + +#ifdef CONFIG_MLX5_EN_NVMEOTCP + +#include +#include "en_accel/nvmeotcp.h" + +bool +mlx5e_nvmeotcp_rebuild_rx_skb(struct mlx5e_rq *rq, struct sk_buff *skb, + struct mlx5_cqe64 *cqe, u32 cqe_bcnt); + +static inline int mlx5_nvmeotcp_get_headlen(struct mlx5_cqe64 *cqe, u32 cqe_bcnt) +{ + struct mlx5e_cqe128 *cqe128; + + if (!cqe_is_nvmeotcp_zc(cqe)) + return cqe_bcnt; + + cqe128 = container_of(cqe, struct mlx5e_cqe128, cqe64); + return be16_to_cpu(cqe128->hlen); +} + +#else + +static inline bool +mlx5e_nvmeotcp_rebuild_rx_skb(struct mlx5e_rq *rq, struct sk_buff *skb, + struct mlx5_cqe64 *cqe, u32 cqe_bcnt) +{ return true; } + +static inline int mlx5_nvmeotcp_get_headlen(struct mlx5_cqe64 *cqe, u32 cqe_bcnt) +{ return cqe_bcnt; } + +#endif /* CONFIG_MLX5_EN_NVMEOTCP */ +#endif /* __MLX5E_NVMEOTCP_RXTX_H__ */ diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c index 89ef317bdd2f..a319a1494b0a 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_rx.c @@ -53,7 +53,7 @@ #include "en_accel/macsec.h" #include "en_accel/ipsec_rxtx.h" #include "en_accel/ktls_txrx.h" -#include "en_accel/nvmeotcp.h" +#include "en_accel/nvmeotcp_rxtx.h" #include "en/xdp.h" #include "en/xsk/rx.h" #include "en/health.h" @@ -336,10 +336,6 @@ static inline void mlx5e_put_rx_frag(struct mlx5e_rq *rq, mlx5e_page_release_fragmented(rq, frag->frag_page); } -static inline struct mlx5e_wqe_frag_info *get_frag(struct mlx5e_rq *rq, u16 ix) -{ - return &rq->wqe.frags[ix << rq->wqe.info.log_num_frags]; -} static int mlx5e_alloc_rx_wqe(struct mlx5e_rq *rq, struct mlx5e_rx_wqe_cyc *wqe, u16 ix) @@ -1566,7 +1562,7 @@ static inline void mlx5e_handle_csum(struct net_device *netdev, #define MLX5E_CE_BIT_MASK 0x80 -static inline void mlx5e_build_rx_skb(struct mlx5_cqe64 *cqe, +static inline bool mlx5e_build_rx_skb(struct mlx5_cqe64 *cqe, u32 cqe_bcnt, struct mlx5e_rq *rq, struct sk_buff *skb) @@ -1577,6 +1573,13 @@ static inline void mlx5e_build_rx_skb(struct mlx5_cqe64 *cqe, skb->mac_len = ETH_HLEN; + if (IS_ENABLED(CONFIG_MLX5_EN_NVMEOTCP) && cqe_is_nvmeotcp(cqe)) { + bool ret = mlx5e_nvmeotcp_rebuild_rx_skb(rq, skb, cqe, cqe_bcnt); + + if (unlikely(!ret)) + return ret; + } + if (unlikely(get_cqe_tls_offload(cqe))) mlx5e_ktls_handle_rx_skb(rq, skb, cqe, &cqe_bcnt); @@ -1623,6 +1626,8 @@ static inline void mlx5e_build_rx_skb(struct mlx5_cqe64 *cqe, if (unlikely(mlx5e_skb_is_multicast(skb))) stats->mcast_packets++; + + return true; } static void mlx5e_shampo_complete_rx_cqe(struct mlx5e_rq *rq, @@ -1646,7 +1651,7 @@ static void mlx5e_shampo_complete_rx_cqe(struct mlx5e_rq *rq, } } -static inline void mlx5e_complete_rx_cqe(struct mlx5e_rq *rq, +static inline bool mlx5e_complete_rx_cqe(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe, u32 cqe_bcnt, struct sk_buff *skb) @@ -1655,7 +1660,7 @@ static inline void mlx5e_complete_rx_cqe(struct mlx5e_rq *rq, stats->packets++; stats->bytes += cqe_bcnt; - mlx5e_build_rx_skb(cqe, cqe_bcnt, rq, skb); + return mlx5e_build_rx_skb(cqe, cqe_bcnt, rq, skb); } static inline @@ -1869,7 +1874,8 @@ static void mlx5e_handle_rx_cqe(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe) goto wq_cyc_pop; } - mlx5e_complete_rx_cqe(rq, cqe, cqe_bcnt, skb); + if (unlikely(!mlx5e_complete_rx_cqe(rq, cqe, cqe_bcnt, skb))) + goto wq_cyc_pop; if (mlx5e_cqe_regb_chain(cqe)) if (!mlx5e_tc_update_skb_nic(cqe, skb)) { @@ -1916,7 +1922,8 @@ static void mlx5e_handle_rx_cqe_rep(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe) goto wq_cyc_pop; } - mlx5e_complete_rx_cqe(rq, cqe, cqe_bcnt, skb); + if (unlikely(!mlx5e_complete_rx_cqe(rq, cqe, cqe_bcnt, skb))) + goto wq_cyc_pop; if (rep->vlan && skb_vlan_tag_present(skb)) skb_vlan_pop(skb); @@ -1965,7 +1972,8 @@ static void mlx5e_handle_rx_cqe_mpwrq_rep(struct mlx5e_rq *rq, struct mlx5_cqe64 if (!skb) goto mpwrq_cqe_out; - mlx5e_complete_rx_cqe(rq, cqe, cqe_bcnt, skb); + if (unlikely(!mlx5e_complete_rx_cqe(rq, cqe, cqe_bcnt, skb))) + goto mpwrq_cqe_out; mlx5e_rep_tc_receive(cqe, rq, skb); @@ -2011,13 +2019,18 @@ mlx5e_fill_skb_data(struct sk_buff *skb, struct mlx5e_rq *rq, } } +static inline u16 mlx5e_get_headlen_hint(struct mlx5_cqe64 *cqe, u32 cqe_bcnt) +{ + return min_t(u32, MLX5E_RX_MAX_HEAD, mlx5_nvmeotcp_get_headlen(cqe, cqe_bcnt)); +} + static struct sk_buff * mlx5e_skb_from_cqe_mpwrq_nonlinear(struct mlx5e_rq *rq, struct mlx5e_mpw_info *wi, struct mlx5_cqe64 *cqe, u16 cqe_bcnt, u32 head_offset, u32 page_idx) { struct mlx5e_frag_page *frag_page = &wi->alloc_units.frag_pages[page_idx]; - u16 headlen = min_t(u16, MLX5E_RX_MAX_HEAD, cqe_bcnt); + u16 headlen = mlx5e_get_headlen_hint(cqe, cqe_bcnt); struct mlx5e_frag_page *head_page = frag_page; u32 frag_offset = head_offset; u32 byte_cnt = cqe_bcnt; @@ -2440,7 +2453,8 @@ static void mlx5e_handle_rx_cqe_mpwrq(struct mlx5e_rq *rq, struct mlx5_cqe64 *cq if (!skb) goto mpwrq_cqe_out; - mlx5e_complete_rx_cqe(rq, cqe, cqe_bcnt, skb); + if (unlikely(!mlx5e_complete_rx_cqe(rq, cqe, cqe_bcnt, skb))) + goto mpwrq_cqe_out; if (mlx5e_cqe_regb_chain(cqe)) if (!mlx5e_tc_update_skb_nic(cqe, skb)) { @@ -2773,7 +2787,9 @@ static void mlx5e_trap_handle_rx_cqe(struct mlx5e_rq *rq, struct mlx5_cqe64 *cqe if (!skb) goto wq_cyc_pop; - mlx5e_complete_rx_cqe(rq, cqe, cqe_bcnt, skb); + if (unlikely(!mlx5e_complete_rx_cqe(rq, cqe, cqe_bcnt, skb))) + goto wq_cyc_pop; + skb_push(skb, ETH_HLEN); mlx5_devlink_trap_report(rq->mdev, trap_id, skb, From patchwork Wed Feb 28 12:57:33 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13575463 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on2041.outbound.protection.outlook.com [40.107.236.41]) (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 F3607149DE0 for ; Wed, 28 Feb 2024 12:59:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.236.41 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125172; cv=fail; b=hb2RhluqNmW34YkAKbmvElVWkWi3zJU4TZ0DyYy4gar9ULpIFO5MATRx4jjbbMQ6IKjb47r/NrEQp2tgaAnhDFnAXTAub+FSLdDp0Mxsp11A7llzmEWZ6df3tJOd3nJ8BqHEDUfktjq8YreTvbzrV6HWbM5SqVRYg86k2E7xqWs= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709125172; c=relaxed/simple; bh=um3H+6mFJfNTRqDQGlZW5iGjeEESZNQPApZdKLjpORk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=VrP9Kb1a0Srcm8qyoDUx/B5sd0gJzGndG1Za4CsRjYeS+89PLWuZa5iOfd9tGcizxbymXcVZNw1sO3E57HP98jPnTStRQS3kyi8o0+VVMMmcIEQZLPGszz0pUpeQGiNJ9MA5Y7L3aM2F4CH3uLFVR9HQESAO3OmDV5UWZ2Waico= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com; spf=fail smtp.mailfrom=nvidia.com; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b=JrAPVVxg; arc=fail smtp.client-ip=40.107.236.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=nvidia.com Authentication-Results: smtp.subspace.kernel.org; spf=fail smtp.mailfrom=nvidia.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=Nvidia.com header.i=@Nvidia.com header.b="JrAPVVxg" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IfsA8yAz/PmaFJYC9Ln/8/9+a+khFP5OapBvFSEQ2WuPF+enO4UTl7gvV9sM0EEIz4JZKJ5oLzu6a+W2XZA1+/PbXDGe+/noVLinp0EYZxUFkFrmmQTJeGp4nh2zon2+9VvWzXX+TBmKxccNXLLqX4ziVWQeTV5YxMPGEoa5OwXba24ruzksebHOMuVxsWxHvSRSKH/66BkxpxeUeNRZPmYorAjTCDv1lH/X1ix9AFX9i6qbD4uw1j/EFWtqImhkfyOMTvqFrG/OBwuFDUvfAPlDGYQvDfPxf11llh2ThxhtFVuNFp0tnM3mgFDYLnwmvKC7NIh4vQnPW4SZrwMXhw== 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=W/cMAj4fCG8px+KutbWnaID12s/o9F0USET3ZHcJNfs=; b=YX1JFw256LRwRR0pj3ySo6O3of78QWUqZJCLjorFps5YmmbIMl7S5iguj2BD0syvzcZ0CzCAnPg8rciJ4Fa8kSfHTriCu0UNPcmDQCqlKAf92til7q2Z6SSOtavvMb2BuYdKdJWEEIiwo37d4s98VKdB+A/IyTX3NGo+qngMezLT4owUIKamYOLzHcDZQS//se2Al7dXNxgbGFv4kvWnXLb6a1lZAWdJmX+ajOUth3asqDJa+XderrDMHHXb6TYuG0Rd991xd1Vek8b2M19Hr0uf4TGSwf368YNW70JxkCePLOOUw4yVgEbm1kgSPna5wD1PtUsS0U1LEFGFQ/T62A== 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=W/cMAj4fCG8px+KutbWnaID12s/o9F0USET3ZHcJNfs=; b=JrAPVVxgWFnYedOWApXIGynmg/EGt57vy+uwRzrSI0/MBmz2ru+1uq6v6mCce1uUZjhBXwt/+C+5uBaUYMWNbVBRTnFIea8J5buuwM5sCqiBlC7whh6RhZAKGw7bTU4nTaqPfkrVJEEKg2VB/qreVrTcb6J3h652piUJ7PyDuRAJXkHfyNI3+vN1yckdf3YtcA6SAbsVCgppHCX8Y+F14q/gZ8ps2GEKcmF/TOK+I4gsa3UWWama3hfJoY1+xAhXx9aXqc0fTixJ2qrRWLsQARbWl6KcozyH6WoqdHScMXMbYbl1/m4f93iMwkKQcUqklYgxGoRxVLS1bzG6Qn0OJg== 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 CH3PR12MB9218.namprd12.prod.outlook.com (2603:10b6:610:19f::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7316.36; Wed, 28 Feb 2024 12:59:26 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::aa05:b8a0:7d5:b463%3]) with mapi id 15.20.7316.032; Wed, 28 Feb 2024 12:59:26 +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 Subject: [PATCH v23 20/20] net/mlx5e: NVMEoTCP, statistics Date: Wed, 28 Feb 2024 12:57:33 +0000 Message-Id: <20240228125733.299384-21-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240228125733.299384-1-aaptel@nvidia.com> References: <20240228125733.299384-1-aaptel@nvidia.com> X-ClientProxiedBy: FR2P281CA0144.DEUP281.PROD.OUTLOOK.COM (2603:10a6:d10:98::18) 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_|CH3PR12MB9218:EE_ X-MS-Office365-Filtering-Correlation-Id: f47e5f90-a5c0-4ef0-3175-08dc385d17ea X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ofV122dRqm0+vsKny5VId0qxr90SgVBI5yebeIKNqhyJLGTv8A25LpmpJK6qucbevj7gAb2O1fPc6u/DjudGO3aisTIGVT9F0OTZE3ybIiQ+b9dBcDjuToq+gkuwTbs9SBydQ271IM7ESt0v7SLxzgaARhZtU17va+eDtfCNGJZjUb0wmA7qwWbN+1l0F3yQlfFyzX2TaFpaJkbbQbfEV4K80xqRe45RnO1qtjx+rQjdpD67cqdGzQiTk6gDKZcdjQM+8MNl4blwYoh0kyJ1e8emy3/nrqrGFX57ubVaEuaN8Df/4zbRGlVQ3TGEVYvrlX6k57f87sKPxXBR83G1pJo3LSdZxuAm9pYHgB9hXGJLwS750lj37mQs0xdzuI+vuhXBY29H68yKcSRDq/Fk3xpGAwmUt74ynNOwo7O0BXn13RUyNV0hRj7N1DwhzJ/sjqumXqTlJUMYH9i0BzLSzq/RgqdsRNCiUKTku3bxQdtI9gsvonT1wLFglSnGlqYHYb6V5KSLGIJTDUx+Iu5/Zk8DFvDXmOSppx2EAsPvDj7PuNru5xwIGMLYBaLCkUv8fgktXbbkTOi4QbzziwpDT+L4QicExjWrtrYR2uujSKIXJFH7OnxYcfTZ6rtwPDv+nCYIvOiKvTd091T4/DdxFA== 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);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: NOyqYssilAFW7O6K+niTX8NQ40iYQahf9LaWXUfTb2aH6fDMZ9cznFfI4tS5b+NOoJU0VtZuzoXhqULx/Mkr0CliX42mGgEyurnvK0oRdE306/SH12c2SlVsnYEG0a8luajaT3Oj3K2X9tvUCAOm1+fEseAJfy1ZjHFbEUm3QIVbRK2sFxyxVcO6hKqYVB2w4IRe9P4b0sNssZ6i4GRfbLih/dOhbBce2bIAoKfuC29B+Z5p0O1hbg35v0uIIKOHzm4BxYIYLdtUcTVaqBT4kPcgm3vvmtFoiplsiJwR0482h1f8F3dYCpMsRGO/iX55naXW3lCBqTgvQK1DEZpANrspil5s5pVPI2ykmBCVB/GHU2+QVVQIXJy2ifPDgBNoqNwHUnUGtWOhfbzS7WTDC9WLB4erQmwJh8d034lcDu3mA4G5dXfHIt/bzXGp02KFACBDVpIZcUTVQoqZSJkhLZi9tTLukEkdxT6r3dhnyojNnaXTpEfQrN3/QViY/n8aJXo+tGyvKeFQUGOTr/4ry8IJWFQ48cbslMojz45NR8WVi6mAizitNkQ+35d47ofdPpiQ2XSGxehu3aB0Shj+dQEusO5M6fRShw+6XWDbIQ8TBmNqoNvkMkYGWJv8WhG/kagZPPiI7Jl8lOeN/M5nL0gw3Os2pvXrbXwJRxxvwd450V3thdzp3Vn3nlWt6DsttQCi9ofHiJxNKYFHa2J4B/HfeYFo4qcULyV1H0A522DMxxsyJhfXgE+XWW9EofGcFsYkrVnb9gOxvnYDmFE4NRKKOOr6Ijh2zHcXD1kdoopNKxT/xMWI3qNM0wYcQJBudTUY6uZT/aYSsDgjzs4eR/VHlBTPWzx2k7kRXy4wfSVg/By9DTSe3pFP6cYaMLyrT9As4KR481wYL7xZ0+HuuLnyWaLUh4pDaYxCTc5d3LQPbImyWka3b6NQMpRqqowIQ8dyOmOtWtUnkCSLDY9VMSmspnCTRb0IcQuOgrJ4sIDUAaLIXb6+WnHq7EpFVLXDTqxcNvy6GPoIUc/xAYgMu+2QNsN7Vf5H9UsHgPM5zeLFviMhde+Iqe9jiqZ05qhOhlpc12Io7E3YBW+R7IOTuOQIx45Wh+YeyLMJaQzPrRZjyEy7L3nrSki9AyJjUE2fCzorq1TvaK0h0F07ir1OqupHZS4KM2MvuP2wP/Fd680P4jPmMuPVSG5A4lQ67a7Uyng/EH2r3gt3ydnx1lXOgyr5YGn/aRdSm7U2vvXzvotxlYR9fAqGv/va0hZwWUksze8w88IkPqZd/wQqVfHux77Oc89vzyMnByXdPxgbO2FuqTAVlFpp/xsy/e7tAPC8LzjT7/P0SQ7FH9J/qLyNk22uJQnIqohvLWLLVPXv71uP0lmuL+bi3xDPepoO9NbcLrqm4ebFxXAibTc4Djyun21wSgxH1NLLhMuTnHVex5YxvAiDJfRM96f/w+oauQtXFx5C/ZWO62fEGOkKMmhXtgZi0AMK3NEaFcYRnrd38DL1gnRQvLLTOd+8aK4cn/Rk9qp8BoEaCoAz+DN/35jxwhMxFhAQjdZecxeaD9TxR3Rft32bDmpmt45+4sIIM5g7 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f47e5f90-a5c0-4ef0-3175-08dc385d17ea X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Feb 2024 12:59:26.6776 (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: ImlWKkrtts10gaunMNS7ym6CiLbzrU59Wh/Oul7pScA49wW73OKZo+cN015GIhpG3C66i4ptzMu4NDYMk/bn9w== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CH3PR12MB9218 X-Patchwork-Delegate: kuba@kernel.org NVMEoTCP offload statistics include both control and data path statistic: counters for the netdev ddp ops, offloaded packets/bytes, resync and dropped packets. Expose the statistics using ulp_ddp_ops->get_stats() instead of the regular statistics flow. Signed-off-by: Ben Ben-Ishay Signed-off-by: Boris Pismenny Signed-off-by: Or Gerlitz Signed-off-by: Yoray Zack Signed-off-by: Shai Malin Signed-off-by: Aurelien Aptel Reviewed-by: Tariq Toukan --- .../net/ethernet/mellanox/mlx5/core/Makefile | 3 +- .../mellanox/mlx5/core/en_accel/nvmeotcp.c | 52 ++++++++++++--- .../mellanox/mlx5/core/en_accel/nvmeotcp.h | 16 +++++ .../mlx5/core/en_accel/nvmeotcp_rxtx.c | 11 +++- .../mlx5/core/en_accel/nvmeotcp_stats.c | 66 +++++++++++++++++++ .../ethernet/mellanox/mlx5/core/en_stats.h | 8 +++ 6 files changed, 145 insertions(+), 11 deletions(-) create mode 100644 drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_stats.c diff --git a/drivers/net/ethernet/mellanox/mlx5/core/Makefile b/drivers/net/ethernet/mellanox/mlx5/core/Makefile index 2db0bd83d517..3c4e9a242131 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/Makefile +++ b/drivers/net/ethernet/mellanox/mlx5/core/Makefile @@ -109,7 +109,8 @@ mlx5_core-$(CONFIG_MLX5_EN_TLS) += en_accel/ktls_stats.o \ en_accel/fs_tcp.o en_accel/ktls.o en_accel/ktls_txrx.o \ en_accel/ktls_tx.o en_accel/ktls_rx.o -mlx5_core-$(CONFIG_MLX5_EN_NVMEOTCP) += en_accel/fs_tcp.o en_accel/nvmeotcp.o en_accel/nvmeotcp_rxtx.o +mlx5_core-$(CONFIG_MLX5_EN_NVMEOTCP) += en_accel/fs_tcp.o en_accel/nvmeotcp.o \ + en_accel/nvmeotcp_rxtx.o en_accel/nvmeotcp_stats.o mlx5_core-$(CONFIG_MLX5_SW_STEERING) += steering/dr_domain.o steering/dr_table.o \ steering/dr_matcher.o steering/dr_rule.o \ diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c index 4c49ff9a7999..4695993e128f 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.c @@ -616,9 +616,15 @@ mlx5e_nvmeotcp_queue_init(struct net_device *netdev, { struct nvme_tcp_ddp_config *nvme_config = &config->nvmeotcp; struct mlx5e_priv *priv = netdev_priv(netdev); + struct mlx5e_nvmeotcp_sw_stats *sw_stats; struct mlx5_core_dev *mdev = priv->mdev; struct mlx5e_nvmeotcp_queue *queue; int queue_id, err; + u32 channel_ix; + + channel_ix = mlx5e_get_channel_ix_from_io_cpu(&priv->channels.params, + config->io_cpu); + sw_stats = &priv->nvmeotcp->sw_stats; if (config->type != ULP_DDP_NVME) { err = -EOPNOTSUPP; @@ -645,11 +651,11 @@ mlx5e_nvmeotcp_queue_init(struct net_device *netdev, queue->id = queue_id; queue->dgst = nvme_config->dgst; queue->pda = nvme_config->cpda; - queue->channel_ix = mlx5e_get_channel_ix_from_io_cpu(&priv->channels.params, - config->io_cpu); + queue->channel_ix = channel_ix; queue->size = nvme_config->queue_size; queue->max_klms_per_wqe = MLX5E_MAX_KLM_PER_WQE(mdev); queue->priv = priv; + queue->sw_stats = sw_stats; init_completion(&queue->static_params_done); err = mlx5e_nvmeotcp_queue_rx_init(queue, config, netdev); @@ -661,6 +667,7 @@ mlx5e_nvmeotcp_queue_init(struct net_device *netdev, if (err) goto destroy_rx; + atomic64_inc(&sw_stats->rx_nvmeotcp_sk_add); write_lock_bh(&sk->sk_callback_lock); ulp_ddp_set_ctx(sk, queue); write_unlock_bh(&sk->sk_callback_lock); @@ -674,6 +681,7 @@ mlx5e_nvmeotcp_queue_init(struct net_device *netdev, free_queue: kfree(queue); out: + atomic64_inc(&sw_stats->rx_nvmeotcp_sk_add_fail); return err; } @@ -687,6 +695,8 @@ mlx5e_nvmeotcp_queue_teardown(struct net_device *netdev, queue = container_of(ulp_ddp_get_ctx(sk), struct mlx5e_nvmeotcp_queue, ulp_ddp_ctx); + atomic64_inc(&queue->sw_stats->rx_nvmeotcp_sk_del); + WARN_ON(refcount_read(&queue->ref_count) != 1); mlx5e_nvmeotcp_destroy_rx(priv, queue, mdev); @@ -818,25 +828,34 @@ mlx5e_nvmeotcp_ddp_setup(struct net_device *netdev, struct ulp_ddp_io *ddp) { struct scatterlist *sg = ddp->sg_table.sgl; + struct mlx5e_nvmeotcp_sw_stats *sw_stats; struct mlx5e_nvmeotcp_queue_entry *nvqt; struct mlx5e_nvmeotcp_queue *queue; struct mlx5_core_dev *mdev; int i, size = 0, count = 0; + int ret = 0; queue = container_of(ulp_ddp_get_ctx(sk), struct mlx5e_nvmeotcp_queue, ulp_ddp_ctx); + sw_stats = queue->sw_stats; mdev = queue->priv->mdev; count = dma_map_sg(mdev->device, ddp->sg_table.sgl, ddp->nents, DMA_FROM_DEVICE); - if (count <= 0) - return -EINVAL; + if (count <= 0) { + ret = -EINVAL; + goto ddp_setup_fail; + } - if (WARN_ON(count > mlx5e_get_max_sgl(mdev))) - return -ENOSPC; + if (WARN_ON(count > mlx5e_get_max_sgl(mdev))) { + ret = -ENOSPC; + goto ddp_setup_fail; + } - if (!mlx5e_nvmeotcp_validate_sgl(sg, count, READ_ONCE(netdev->mtu))) - return -EOPNOTSUPP; + if (!mlx5e_nvmeotcp_validate_sgl(sg, count, READ_ONCE(netdev->mtu))) { + ret = -EOPNOTSUPP; + goto ddp_setup_fail; + } for (i = 0; i < count; i++) size += sg_dma_len(&sg[i]); @@ -848,8 +867,13 @@ mlx5e_nvmeotcp_ddp_setup(struct net_device *netdev, nvqt->ccid_gen++; nvqt->sgl_length = count; mlx5e_nvmeotcp_post_klm_wqe(queue, KLM_UMR, ddp->command_id, count); - + atomic64_inc(&sw_stats->rx_nvmeotcp_ddp_setup); return 0; + +ddp_setup_fail: + dma_unmap_sg(mdev->device, ddp->sg_table.sgl, count, DMA_FROM_DEVICE); + atomic64_inc(&sw_stats->rx_nvmeotcp_ddp_setup_fail); + return ret; } void mlx5e_nvmeotcp_ctx_complete(struct mlx5e_icosq_wqe_info *wi) @@ -896,6 +920,7 @@ mlx5e_nvmeotcp_ddp_teardown(struct net_device *netdev, q_entry->queue = queue; mlx5e_nvmeotcp_post_klm_wqe(queue, KLM_INV_UMR, ddp->command_id, 0); + atomic64_inc(&queue->sw_stats->rx_nvmeotcp_ddp_teardown); } static void @@ -929,6 +954,14 @@ void mlx5e_nvmeotcp_put_queue(struct mlx5e_nvmeotcp_queue *queue) } } +static int mlx5e_ulp_ddp_get_stats(struct net_device *dev, + struct ulp_ddp_stats *stats) +{ + struct mlx5e_priv *priv = netdev_priv(dev); + + return mlx5e_nvmeotcp_get_stats(priv, stats); +} + int set_ulp_ddp_nvme_tcp(struct net_device *netdev, bool enable) { struct mlx5e_priv *priv = netdev_priv(netdev); @@ -1028,6 +1061,7 @@ const struct ulp_ddp_dev_ops mlx5e_nvmeotcp_ops = { .resync = mlx5e_nvmeotcp_ddp_resync, .set_caps = mlx5e_ulp_ddp_set_caps, .get_caps = mlx5e_ulp_ddp_get_caps, + .get_stats = mlx5e_ulp_ddp_get_stats, }; void mlx5e_nvmeotcp_cleanup_rx(struct mlx5e_priv *priv) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.h b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.h index 13817d8a0aae..41b5b304e598 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp.h @@ -9,6 +9,15 @@ #include "en.h" #include "en/params.h" +struct mlx5e_nvmeotcp_sw_stats { + atomic64_t rx_nvmeotcp_sk_add; + atomic64_t rx_nvmeotcp_sk_add_fail; + atomic64_t rx_nvmeotcp_sk_del; + atomic64_t rx_nvmeotcp_ddp_setup; + atomic64_t rx_nvmeotcp_ddp_setup_fail; + atomic64_t rx_nvmeotcp_ddp_teardown; +}; + struct mlx5e_nvmeotcp_queue_entry { struct mlx5e_nvmeotcp_queue *queue; u32 sgl_length; @@ -52,6 +61,7 @@ struct mlx5e_nvmeotcp_queue_handler { * @sk: The socket used by the NVMe-TCP queue * @crc_rx: CRC Rx offload indication for this queue * @priv: mlx5e netdev priv + * @sw_stats: Global software statistics for nvmeotcp offload * @static_params_done: Async completion structure for the initial umr mapping * synchronization * @sq_lock: Spin lock for the icosq @@ -88,6 +98,7 @@ struct mlx5e_nvmeotcp_queue { u8 crc_rx:1; /* for ddp invalidate flow */ struct mlx5e_priv *priv; + struct mlx5e_nvmeotcp_sw_stats *sw_stats; /* end of data-path section */ struct completion static_params_done; @@ -97,6 +108,7 @@ struct mlx5e_nvmeotcp_queue { }; struct mlx5e_nvmeotcp { + struct mlx5e_nvmeotcp_sw_stats sw_stats; struct ida queue_ids; struct rhashtable queue_hash; struct ulp_ddp_dev_caps ddp_caps; @@ -113,6 +125,7 @@ void mlx5e_nvmeotcp_ddp_inv_done(struct mlx5e_icosq_wqe_info *wi); void mlx5e_nvmeotcp_ctx_complete(struct mlx5e_icosq_wqe_info *wi); static inline void mlx5e_nvmeotcp_init_rx(struct mlx5e_priv *priv) {} void mlx5e_nvmeotcp_cleanup_rx(struct mlx5e_priv *priv); +int mlx5e_nvmeotcp_get_stats(struct mlx5e_priv *priv, struct ulp_ddp_stats *stats); extern const struct ulp_ddp_dev_ops mlx5e_nvmeotcp_ops; #else @@ -121,5 +134,8 @@ static inline void mlx5e_nvmeotcp_cleanup(struct mlx5e_priv *priv) {} static inline int set_ulp_ddp_nvme_tcp(struct net_device *dev, bool en) { return -EOPNOTSUPP; } static inline void mlx5e_nvmeotcp_init_rx(struct mlx5e_priv *priv) {} static inline void mlx5e_nvmeotcp_cleanup_rx(struct mlx5e_priv *priv) {} +static inline int mlx5e_nvmeotcp_get_stats(struct mlx5e_priv *priv, + struct ulp_ddp_stats *stats) +{ return 0; } #endif #endif /* __MLX5E_NVMEOTCP_H__ */ diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_rxtx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_rxtx.c index 269d8075f3c2..6ed9acdec376 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_rxtx.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_rxtx.c @@ -140,6 +140,7 @@ mlx5e_nvmeotcp_rebuild_rx_skb_nonlinear(struct mlx5e_rq *rq, struct sk_buff *skb int ccoff, cclen, hlen, ccid, remaining, fragsz, to_copy = 0; struct net_device *netdev = rq->netdev; struct mlx5e_priv *priv = netdev_priv(netdev); + struct mlx5e_rq_stats *stats = rq->stats; struct mlx5e_nvmeotcp_queue_entry *nqe; skb_frag_t org_frags[MAX_SKB_FRAGS]; struct mlx5e_nvmeotcp_queue *queue; @@ -151,12 +152,14 @@ mlx5e_nvmeotcp_rebuild_rx_skb_nonlinear(struct mlx5e_rq *rq, struct sk_buff *skb queue = mlx5e_nvmeotcp_get_queue(priv->nvmeotcp, queue_id); if (unlikely(!queue)) { dev_kfree_skb_any(skb); + stats->nvmeotcp_drop++; return false; } cqe128 = container_of(cqe, struct mlx5e_cqe128, cqe64); if (cqe_is_nvmeotcp_resync(cqe)) { nvmeotcp_update_resync(queue, cqe128); + stats->nvmeotcp_resync++; mlx5e_nvmeotcp_put_queue(queue); return true; } @@ -230,7 +233,8 @@ mlx5e_nvmeotcp_rebuild_rx_skb_nonlinear(struct mlx5e_rq *rq, struct sk_buff *skb org_nr_frags, frag_index); } - + stats->nvmeotcp_packets++; + stats->nvmeotcp_bytes += cclen; mlx5e_nvmeotcp_put_queue(queue); return true; } @@ -242,6 +246,7 @@ mlx5e_nvmeotcp_rebuild_rx_skb_linear(struct mlx5e_rq *rq, struct sk_buff *skb, int ccoff, cclen, hlen, ccid, remaining, fragsz, to_copy = 0; struct net_device *netdev = rq->netdev; struct mlx5e_priv *priv = netdev_priv(netdev); + struct mlx5e_rq_stats *stats = rq->stats; struct mlx5e_nvmeotcp_queue_entry *nqe; struct mlx5e_nvmeotcp_queue *queue; struct mlx5e_cqe128 *cqe128; @@ -251,12 +256,14 @@ mlx5e_nvmeotcp_rebuild_rx_skb_linear(struct mlx5e_rq *rq, struct sk_buff *skb, queue = mlx5e_nvmeotcp_get_queue(priv->nvmeotcp, queue_id); if (unlikely(!queue)) { dev_kfree_skb_any(skb); + stats->nvmeotcp_drop++; return false; } cqe128 = container_of(cqe, struct mlx5e_cqe128, cqe64); if (cqe_is_nvmeotcp_resync(cqe)) { nvmeotcp_update_resync(queue, cqe128); + stats->nvmeotcp_resync++; mlx5e_nvmeotcp_put_queue(queue); return true; } @@ -330,6 +337,8 @@ mlx5e_nvmeotcp_rebuild_rx_skb_linear(struct mlx5e_rq *rq, struct sk_buff *skb, hlen + cclen, remaining); } + stats->nvmeotcp_packets++; + stats->nvmeotcp_bytes += cclen; mlx5e_nvmeotcp_put_queue(queue); return true; } diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_stats.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_stats.c new file mode 100644 index 000000000000..af1838154bf8 --- /dev/null +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/nvmeotcp_stats.c @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0 OR Linux-OpenIB +// Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. + +#include "en_accel/nvmeotcp.h" + +struct ulp_ddp_counter_map { + size_t eth_offset; + size_t mlx_offset; +}; + +#define DECLARE_ULP_SW_STAT(fld) \ + { offsetof(struct ulp_ddp_stats, fld), \ + offsetof(struct mlx5e_nvmeotcp_sw_stats, fld) } + +#define DECLARE_ULP_RQ_STAT(fld) \ + { offsetof(struct ulp_ddp_stats, rx_ ## fld), \ + offsetof(struct mlx5e_rq_stats, fld) } + +#define READ_CTR_ATOMIC64(ptr, dsc, i) \ + atomic64_read((atomic64_t *)((char *)(ptr) + (dsc)[i].mlx_offset)) + +#define READ_CTR(ptr, desc, i) \ + (*((u64 *)((char *)(ptr) + (desc)[i].mlx_offset))) + +#define SET_ULP_STAT(ptr, desc, i, val) \ + (*(u64 *)((char *)(ptr) + (desc)[i].eth_offset) = (val)) + +/* Global counters */ +static const struct ulp_ddp_counter_map sw_stats_desc[] = { + DECLARE_ULP_SW_STAT(rx_nvmeotcp_sk_add), + DECLARE_ULP_SW_STAT(rx_nvmeotcp_sk_del), + DECLARE_ULP_SW_STAT(rx_nvmeotcp_ddp_setup), + DECLARE_ULP_SW_STAT(rx_nvmeotcp_ddp_setup_fail), + DECLARE_ULP_SW_STAT(rx_nvmeotcp_ddp_teardown), +}; + +/* Per-rx-queue counters */ +static const struct ulp_ddp_counter_map rq_stats_desc[] = { + DECLARE_ULP_RQ_STAT(nvmeotcp_drop), + DECLARE_ULP_RQ_STAT(nvmeotcp_resync), + DECLARE_ULP_RQ_STAT(nvmeotcp_packets), + DECLARE_ULP_RQ_STAT(nvmeotcp_bytes), +}; + +int mlx5e_nvmeotcp_get_stats(struct mlx5e_priv *priv, struct ulp_ddp_stats *stats) +{ + unsigned int i, ch, n = 0; + + if (!priv->nvmeotcp) + return 0; + + for (i = 0; i < ARRAY_SIZE(sw_stats_desc); i++, n++) + SET_ULP_STAT(stats, sw_stats_desc, i, + READ_CTR_ATOMIC64(&priv->nvmeotcp->sw_stats, sw_stats_desc, i)); + + for (i = 0; i < ARRAY_SIZE(rq_stats_desc); i++, n++) { + u64 sum = 0; + + for (ch = 0; ch < priv->stats_nch; ch++) + sum += READ_CTR(&priv->channel_stats[ch]->rq, rq_stats_desc, i); + + SET_ULP_STAT(stats, rq_stats_desc, i, sum); + } + + return n; +} diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_stats.h b/drivers/net/ethernet/mellanox/mlx5/core/en_stats.h index 12b3607afecd..929a0723812f 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_stats.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_stats.h @@ -128,6 +128,8 @@ void mlx5e_stats_rmon_get(struct mlx5e_priv *priv, const struct ethtool_rmon_hist_range **ranges); void mlx5e_get_link_ext_stats(struct net_device *dev, struct ethtool_link_ext_stats *stats); +struct ulp_ddp_stats; +void mlx5e_stats_ulp_ddp_get(struct mlx5e_priv *priv, struct ulp_ddp_stats *stats); /* Concrete NIC Stats */ @@ -396,6 +398,12 @@ struct mlx5e_rq_stats { u64 tls_resync_res_skip; u64 tls_err; #endif +#ifdef CONFIG_MLX5_EN_NVMEOTCP + u64 nvmeotcp_drop; + u64 nvmeotcp_resync; + u64 nvmeotcp_packets; + u64 nvmeotcp_bytes; +#endif }; struct mlx5e_sq_stats {