From patchwork Thu Dec 21 21:33:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502653 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2062.outbound.protection.outlook.com [40.107.237.62]) (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 6466176DD4 for ; Thu, 21 Dec 2023 21:34:15 +0000 (UTC) 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="lFZwpR65" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=FqrYQbTb+RFTmN5G2+al9CkozRekTS0yAblnjxu8Mit4qEPd+O0U38HNuj0tAMWOgG7goM3WXwtZvKDpr2EiRSWUXrrNrx7vEraMUP3DeeQ4X9jU3fIHQzNAd/LBflSdJ9lV0pDkFpYDzSaHAHd0nWeeZi0XdeejoYwkuav2axpXSUEJitmCAZTUPqvUxFtpk76q9ETGpk4h4v67pd1peinnEBGIubMBprt1/1f4WiOvVWrAnYUp3fz3whozAwRENAtxWWJSNMXMBlhzodUEdVal39e2WcoU5BtERyUKuMp4iPuFJK1C8oVbv8qnAO2EVOL38mbiZakbLhBDb5LpWw== 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=tpbITRh8Oo5kQw0fMIuj35fMfC/RlkDt/f+lNYtysg8=; b=IWrH6wbGv9qsA4FFiMVouRE237NSqoui1Cs2uf+tqpLY697UjLi+UdkB22CGB122LRS776qAua/nEnEFr5OYTwNonH8t+Riz9F+lVsdKyai6tRszGnkImQqlBZKXhXqQyaVcEpSQrdL6KuqRuu9ypt97WXIfvKOJJAJ1m5mO3Sy4RLkYvJvUqkYcdLMV0A7u7KMiQLdCmZaAdo0RCeQvrTsmk3R3dmHY/ze+vAuLgLaDGDITteklLB/uxXD3x24PUtVSEf5FKuTYpajFcJqyhekq2jL41nou5/1yF3z470mh9QHTeoWPOlG0yVZnXrbVTbQkh4RzJEwT8OmP9zNKAA== 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=tpbITRh8Oo5kQw0fMIuj35fMfC/RlkDt/f+lNYtysg8=; b=lFZwpR65N4XduE5eqicVmfdDEB/kJNSP+dDWfyVID7oF041sUgwmFwo1R0ow5s82Xlx+ddriWeC92EEVDNRlzoejJsZaMYlvOCPHsC9zFgiVsVciGCCp9nX+Qmo2AWi+Gvi9dT53+f9zLmwJxVJea+B7wME1FRYesYg5G+c4cNzw0LLA5lkP4/MutxRXsywq5bTCDeYKnCZOdFoAo5322B1dLuKwSIaJXtdzbel8snGWWWfUJ63M46DhSdN+s4rFSBRAqBzkg0+xzlRkgW1ZObpuVrgqYvfXU7e1+h7SzNgO/7zMK54RP8fvxkbU1cTjX5Zd7iJC+wh/TCPJ0RccWg== 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 IA0PR12MB8647.namprd12.prod.outlook.com (2603:10b6:208:480::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.18; Thu, 21 Dec 2023 21:34:11 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:34: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: 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 v22 01/20] net: Introduce direct data placement tcp offload Date: Thu, 21 Dec 2023 21:33:39 +0000 Message-Id: <20231221213358.105704-2-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO3P265CA0021.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:387::8) 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_|IA0PR12MB8647:EE_ X-MS-Office365-Filtering-Correlation-Id: 122943d0-514b-4501-60db-08dc026c91de X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Vi5v7yN33QPkff3jUEzHc9DmVu3fBRDD4en5trVN4yDuqFNS4tak+0IrIAGOeBMU4XXMGB21V0xYXBOdjvZOfbXMB56lhkhx8tsLRxqCBptprAK4Yn5fQps64/Nqgc4jW38KxPTGh/0hsd+zbUf4Z2j4kz/xqi0fWBIi6OeHXW5ItSBbbYgFKWEAE0EWuVQYrlj7ZSh7ePm820K3Z0pDUomN9op40d1jYShujYQv2klQktj/9/yqHrLiIW/J2W1pn2k1K1ZzKlzxqZSp7xdo6ggymy/OVu5rXDxqpt9fA2HoFhIMXsDj0KjK5rCyR1U0EaXH0j3wd6Iqa7ug+u/wWE3dd4hJavBt4+JraELTAJMbZkwOX3fO5C5Lf7LxP63vutLNZPY39Q4pxx0KMURnARvUyeUsOO7zUT6xrq1WULtpQTIuwJGTvJiiVSeIkBWzd/KBgBsQNWsG5hS2c1ozz9LXwUayms5VcNZ43uEbe8CK0D1s7iZuQwYONrumLPvH12ycmCSVVoPvmfb2Zh2KztX+9Vgl6a36GYrBWxLxJDWqj3gg/pYCQSpz1KrSk9cx 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)(376002)(136003)(366004)(39860400002)(396003)(346002)(230922051799003)(186009)(64100799003)(1800799012)(451199024)(6512007)(6506007)(478600001)(26005)(6486002)(2616005)(1076003)(41300700001)(66946007)(83380400001)(66556008)(66476007)(6666004)(316002)(86362001)(36756003)(8676002)(8936002)(38100700002)(2906002)(30864003)(7416002)(5660300002)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tC1S7Jpesix3p21abQzWelL4bsCTl5fVUxW4u+7vNglk+af14iUyIF5F0n32GpoI8nYMCAe+WM8DiphThMXx2e67xdXOLFiOWy6PtchJ2hRecS2PvXzYOW5COX7FVs2IxdAcj6XDAq7F3OQIl4HSGE16n+3iF42HmClZbpULcXUdB6KqKBzk+xGUJt35M/bgWCSmuoQjtz+IJxv5XhhEZYbADaVp2ysbiou0C6flOYayYXhr1+dSVt+PbxsDiKoMDNls1NiYsSFh3HqVT8E4+QNou9KC4SaKHSsCrs43yb0lJFK97MznIcQcR7VF7WKTTzBczZF7HKxpFmZ8DAJr65/X4FsJqmNJ7RnD3jhcso8ruKgnXWs1lPcaJGlye9N0qQ1k2Kw52L2ZOXTycxSAYPqSaYfhu/gP2Gyl9ozkC4qo+PBUQnLDGtuPvvwvMY40NijDhyFZvy8T97DbPYPwiG/d7JzbbOqZmaL8cJQdbRtaRoGLjT0BQxxe4Uv7JLnRm8KgPhEZvu1f5CYghjzxXjw4m0c5GjzduFpJFl8Vj4XQSx5fuemBOxqchD3qoyu7a95jqnx0rkV6Ot7gzGKgbFuxNsekRFWtWW6B4A+9dSHMsE1jnVF9Nnm7KCWzzVUWxX8KoR3BvoyIb5NRPV3q21Q6ZC/3PJpWVSmmvu3yzBcrvjsoR9YPagFvU9wdS+O0wlzdXzU7QrIM2DyD2QI0ERVT7Misyj7zygQVrcNmXkhSElaXs0uarYTned30jifAQOHma2oFEowStjswAWet8SwHo07aCyzEablpnbMYoOXAgf4VWEeyPhD5bLkLNc3+u6vyFgUwTY+z7SbfIiovYbe4ez5rnWyy8lVYWGLMWy/8KF0qc8Axw2SgGWFMTIhkUMi2KTM8oxwkPPbIhz934KzGSkXhiaWo61TI6BXGgT7oi5eQXh9fJWDX4+AfY6U8V/nWq1qFOadWQDhMdXjnENwb0sGO0TLU5+J15CD5PmzluIyJ5EvgrLP5j87lq+k9G0pwVIsCuA365oduE1kcBLraELbv+yexv/cKEftBuJzR5J/7TCABHPvirM2y11Q8BBa4/v2ehRqsckflWkKgHNg7lVPWNp1VSU2IKMTQryCbIGsyfh/hd7cB15HHnnpuL9bdb5JpULh+rLGxYKr07J9+BNZkiJQK9UkboY1ZpqYq0hKgTKWxBsmDwVYHfa2NGPATbHp3iibQws1pj5iLSa008lJQpnPM1TOnLXeKih+/sdJHnPlvABDXyEXAOrkp1hrl5RhyfH/tch6Pm2cvQsA0chYMDpwzhUqNfYs0aq4us4ySoydy4koDewwuUrYPZ/h04Gu94Zam4errcamulJ7zvgMI49LoXhvUCoMLZqk71QjhaLU024687ajVCEPIpUMFsW8lpOTfFPOdwhv6T7YYMrwvADFdg6S7MBiYyrvyhMvPsi3m/AePuD8/43+qXVUun8+uc2AwJ6mtSEJxAA68tzcQv+E9bSuCUxi/v15TC/PGKQNVBzri75DsdXlG2Mz8sb7j7CGHVQQwPwEK4/5dcn9zty5CWxwCdBRdV4u+gP9BCCQrehBC9Ht11KzW X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 122943d0-514b-4501-60db-08dc026c91de X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:34:10.9319 (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: UpTdLogPD/TAqWAG5jC4otko7BTHMhjhtMhfs6SP3rplb+Cf7J2U3yRwLxZV2w7ay+o4dNy4xmmIUUPklLLiJg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8647 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 1b935ee341b4..3ddabe42d8c8 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1432,6 +1432,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); @@ -1673,6 +1675,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 b370eb8d70f7..f3c8ffbcbf45 100644 --- a/include/linux/skbuff.h +++ b/include/linux/skbuff.h @@ -822,6 +822,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. @@ -1001,7 +1003,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 @@ -5078,5 +5083,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 d0a2f827d5f2..583b7272112f 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 3ec6bc98fa05..0ecb5c1fa942 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -517,4 +517,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 b157efea5dea..0b5561f2ef9e 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -76,6 +76,7 @@ #include #include #include +#include #include #include @@ -6606,7 +6607,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 7990f4939e8d..ff211976bb37 100644 --- a/net/ipv4/tcp_input.c +++ b/net/ipv4/tcp_input.c @@ -4789,7 +4789,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; @@ -5359,6 +5362,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) @@ -5392,6 +5399,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 4bac6e319aca..3c169094004f 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -2054,6 +2054,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 Thu Dec 21 21:33:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502654 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM11-DM6-obe.outbound.protection.outlook.com (mail-dm6nam11on2088.outbound.protection.outlook.com [40.107.223.88]) (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 934C776DAE for ; Thu, 21 Dec 2023 21:34:19 +0000 (UTC) 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="VRXi8oUl" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UAuJXD9hCCsz+hDXU2oJo9dkGuCjPUoqRsxIINjFRJFpXho7eup6JRbPvvNHfYfG3lLCoEpFrWgh80uVWmSGG7g96MB3wRpWsEhYoru4eZ45r74DE1nJPu4DRX+F53ym6NGm9Y8YbdvX9+TZ387191G8aHM+oupWhOgKy6MXcgijMG/LZM8rv6OFQdM2G8K5zg7zuq/DCfWvqIlb1jmo67g/4tvx6tvG84F/OidOkrQuleYURpbI2eFPuRRfCyliuFQJ76V840buyPNUEEytICamXHL4hBQzH+JJnxGEXzl850VSg+Uoe5YUBQFDFsgu0HtEIVN8O69xz6P8lIRykg== 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=cL1SxzXZu9C/qJk28P9uGfUGX/uprzp8paRG6aHJh9Q=; b=U255jLs/cxxAMVoamwSs1oFeZBsfb8ucpFopauysB653vFuhi+z/x+7sjvxCjl3L7/k0w3OCnxRuyjaoPXcWTHF4esYCIGyyk83iyuFXFkH8y1TD7Pm4lvLvILeQ59hdJ6rQ8zaXlEXdLBpUGNTfWZYpyWkKJDSQiBqaMfEn/+8o7IJrI6A8Xe2uVXsoJZYN5Ywo1cWXm8jwnNwQxZr6nHsT+MCvUSG2dRAkT22fDqp9s2aSm46wkl0cLfEat0nEaHuidNX5Nax6WfYJWRjpctf6RqbKBEOuS2lIapVWUNBbcs4tD7v88Xa+tR2sIIaa3tCyyeDY856kr+tumSQQww== 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=cL1SxzXZu9C/qJk28P9uGfUGX/uprzp8paRG6aHJh9Q=; b=VRXi8oUlFmOg/AnZbvff0FkKFozPx+o6A0KwY0TBvoQHK373XjydOQMHUsf+h3FoqPUMe7qlEaVZJqgqyiGAjR8GOX2wFcebZFhXkgzyzlkXOZ3njaZt1Vd5iZd1NmxLJH+6sqWWZLm0gEY8v36lAQVMZ5/1ZQWcfNAbywCdBxVLsxC3XgCxtO5WMaxLklWtVbfXy0nQlKsxzMcIZ+CNFU9IiitQLkKGRWD+KjBR6tZICiwcMMUZLdEfxwQ1Jp9kxdy+hKZaiF+ZjqKTyTbqLDGkaUJgSoB7ZCW03XYeBA9N/5p9L9KHKuMcm6Q2M41myu/VfK2PdqqYWTMvUC9eoA== 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 IA0PR12MB8647.namprd12.prod.outlook.com (2603:10b6:208:480::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.18; Thu, 21 Dec 2023 21:34:16 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:34: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: 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 v22 02/20] netlink: add new family to manage ULP_DDP enablement and stats Date: Thu, 21 Dec 2023 21:33:40 +0000 Message-Id: <20231221213358.105704-3-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO4P123CA0369.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:18e::14) 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_|IA0PR12MB8647:EE_ X-MS-Office365-Filtering-Correlation-Id: 122ed625-a6d7-4022-b520-08dc026c94db X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Q/joysjrDv41r9VZa6neKrEXE3GPl5lWtIRUkNroBISxwz36P7jOe47YfYWWi8wyiaG6I973y7L4YdtXF/dkuwCYY31EjtsYudtzcBuP1NLDA33/97AaPpK/4szF1wb8fuHZ/X46bbHQL7qxLQD59SjgBaZAMAYZrE6eEmJrKAmQ2N1OoW3RAuhOycdfIBcvpj4I8WOqow+8i33lj6CCXySOOnOjhT2Jgk/PF/b+Z+UohFDRQT3/675XgnfXoLBtloyq5x6ryjf/b8N8S/ALXPKnSkn7o2PJ55DaMiFjulhsl5BHMJbLsZYWA1OgqzMAv+xjoYE+El8HXmdSfbELmuvCXDRTp4iivktMzdNj9A2acrM+Uq7wBMY76Uu2I7DC6PInz6pUjErLzd2sxR9o8CJZMHnQspv4BnxIeefflIyLJU2GvdSK7Bi7Y6fkVJC3LZfAV+dvYDjSdhtV2DvP0RNR72u1Dx6qIu1a4CFjO75dDBNq3TDSF1nYCXQMogmal/1y9pO6lk2+BjuaygCaE3foZMlxFrgGfW5vcwryiI3RXm+OFWwbS5mPOY18GUjz 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)(376002)(136003)(366004)(39860400002)(396003)(346002)(230922051799003)(186009)(64100799003)(1800799012)(451199024)(6512007)(6506007)(478600001)(26005)(6486002)(2616005)(1076003)(41300700001)(66946007)(83380400001)(66556008)(66476007)(6666004)(316002)(86362001)(36756003)(8676002)(8936002)(38100700002)(2906002)(30864003)(7416002)(5660300002)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: iY4XYWxP63UYnLFbWSSH7bnoO4uLIIPIVYCaM/DEIfM947vbovgqKLPOMbn8tCjxH46NMMYs5BFksde+CERUMrYY5bXIKss7ymXBQNnkEgT7LkyB/8pIjY7J+cswClbHrjHTJ51kbqtKftRiubA7n42UniNoXm8Ku1MjnurLHAumQjKQBlKRlJR+q5DVqac8EnjLNg/bbcgfAJFMLJgV1prMxX5OXJNPbfmSZgrkawafzn50ZYhX87n47THNsg4nRnStBs+yM58v5FAq+G64rxxfuwEGa1LAUk6VOYxhvdiIr6SDeEaUEbPYz0neQtRxQe+6pRKH9kzhdJ53VAOZC6Zwv5UsbtQ6w2lQ8HTTD1yEB8YNF9ilgRan76kv99Txh38bfU993LQGE7peCFgk5wgoakwU3b9rtEE0lm+Dxbuj7nk88e3btCtiLVcSgIYg4jZu/B2ZrmTxhjWWeAPqxVdCbulkdlwrf+lT5MPBVmadaoOEPFp5j0SbYsE4ZI+K4lrZkWKotrIaKSB50WaNeRhqkVUivUdqed6F7XkpgA4LywkYqAvrPvZMW9Hhav0N2yJwyar+5oxawRxQz0khrxpmdp67VToI9SQNwWc6h0ywDF0A1uTE95MBjf/OYSaQD5meooHocsdwCl6qnI8scPgiKZcD2a4sdBHbJdL0NdbVqdNms/HPddGM1jTdLjdR0BNtNrH8RDatvgu6cQZd12sfUP+7JMbTM2OaSxzuT/z/bgTIJUNu6vEo0ABPW7J6Yu6gJXODWpMdyLYaRcEKEyuPD02sF+N1UOhdyGhjzkB/aIm/E797rE15o19eTc5XjiJ5YvLxdXNlsqCbep8KSqXXaWkFYegVNMJL2zatC7/snUzb/x2nJ2ZwFqTKRtKdZ+DtGXlT1Sx83exafopxpU+WLsC6JRbYBRky5rhQrByWmR2GnetA/IMBYpATwKidoir6JJTQ/wWSD1aPdvEV+UaRACy2H6mMLxcw8TYQGSBj7ZtZneRf5CfgB/uYDPrf2OH1ywtKFZdQz19hLO8TsumGrTG8GYwNpArXTz44EBTg8X36i96sSDiX7/mQo+MpDy5L2+MVKTGWs1usFgRvN/PYFq3HIdMnAvJxFrsnzfxzr1dMvtxVfmDim8miUIObXW7HYPv7BtgcCTgeHaSUhIrnSea6owJGuZ5tJ5bFolUff7Fs3D/8PgLUfX8cqrRQVsHBuyB89U2wWT9odmyhAgx4A09iww4vYkErx7itcfNKFruZqauSKTyF5J42wB+T6JmQbs7+HYRGaHmbi47IPIM9L5VAgAJXQmgAE2f4Vp4pCxTAwETCACBvOoDXQuKBXD5HOZ2RWLY+/CEbd5ffEA796ekEa5TYqWuq9peAesduxVgOtuUg8xMb3JP70cSUYfO05QXz5h+T/sw8hqA7iV13gTsnewrsDlUsqamuLhYeYieCpQHwdPBS+DYddNRrzyqATe5pnug0c1X+E4xB8V+J+oNw/U3rxO3YubWPnlceYnkN2Gxuay1lALGMiNSTUMi1jjVoTClZID08s41xnUiJ64qo5krZUW1W7CYqY8YLi/y55ZF4zL1MSndmwflY X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 122ed625-a6d7-4022-b520-08dc026c94db X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:34:15.9761 (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: FyUzR1VpFDHYpiV4xVHnWsf7VjY/tgE3QFk+XLD4Z71c8z/0qgiz746/8zJ3K2C1CGpRihIIRX8LW/5XB7HKfg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8647 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 Reviewed-by: Jiri Pirko --- 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 | 342 +++++++++++++++++++++++ 7 files changed, 683 insertions(+), 2 deletions(-) create mode 100644 Documentation/netlink/specs/ulp_ddp.yaml create mode 100644 include/uapi/linux/ulp_ddp.h create mode 100644 net/core/ulp_ddp_gen_nl.c create mode 100644 net/core/ulp_ddp_gen_nl.h create mode 100644 net/core/ulp_ddp_nl.c diff --git a/Documentation/netlink/specs/ulp_ddp.yaml b/Documentation/netlink/specs/ulp_ddp.yaml new file mode 100644 index 000000000000..7822aa60ae29 --- /dev/null +++ b/Documentation/netlink/specs/ulp_ddp.yaml @@ -0,0 +1,172 @@ +# SPDX-License-Identifier: ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) +# +# Author: Aurelien Aptel +# +# Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved. +# + +name: ulp_ddp + +protocol: genetlink + +doc: Netlink protocol to manage ULP DPP on network devices. + +definitions: + - + type: enum + name: cap + render-max: true + entries: + - nvme-tcp + - nvme-tcp-ddgst-rx + +attribute-sets: + - + name: stats + attributes: + - + name: ifindex + doc: interface index of the net device. + type: u32 + - + name: rx-nvme-tcp-sk-add + doc: Sockets successfully configured for NVMeTCP offloading. + type: uint + - + name: rx-nvme-tcp-sk-add-fail + doc: Sockets failed to be configured for NVMeTCP offloading. + type: uint + - + name: rx-nvme-tcp-sk-del + doc: Sockets with NVMeTCP offloading configuration removed. + type: uint + - + name: rx-nvme-tcp-setup + doc: NVMe-TCP IOs successfully configured for Rx Direct Data Placement. + type: uint + - + name: rx-nvme-tcp-setup-fail + doc: NVMe-TCP IOs failed to be configured for Rx Direct Data Placement. + type: uint + - + name: rx-nvme-tcp-teardown + doc: NVMe-TCP IOs with Rx Direct Data Placement configuration removed. + type: uint + - + name: rx-nvme-tcp-drop + doc: Packets failed the NVMeTCP offload validation. + type: uint + - + name: rx-nvme-tcp-resync + doc: > + NVMe-TCP resync operations were processed due to Rx TCP packets + re-ordering. + type: uint + - + name: rx-nvme-tcp-packets + doc: TCP packets successfully processed by the NVMeTCP offload. + type: uint + - + name: rx-nvme-tcp-bytes + doc: Bytes were successfully processed by the NVMeTCP offload. + type: uint + - + name: caps + attributes: + - + name: ifindex + doc: interface index of the net device. + type: u32 + - + name: hw + doc: bitmask of the capabilities supported by the device. + type: uint + enum: cap + enum-as-flags: true + - + name: active + doc: bitmask of the capabilities currently enabled on the device. + type: uint + enum: cap + enum-as-flags: true + - + name: wanted + doc: > + new active bit values of the capabilities we want to set on the + device. + type: uint + enum: cap + enum-as-flags: true + - + name: wanted_mask + doc: bitmask of the meaningful bits in the wanted field. + type: uint + enum: cap + enum-as-flags: true + +operations: + list: + - + name: caps-get + doc: Get ULP DDP capabilities. + attribute-set: caps + do: + request: + attributes: + - ifindex + reply: + attributes: + - ifindex + - hw + - active + pre: ulp_ddp_get_netdev + post: ulp_ddp_put_netdev + - + name: stats-get + doc: Get ULP DDP stats. + attribute-set: stats + do: + request: + attributes: + - ifindex + reply: + attributes: + - ifindex + - rx-nvme-tcp-sk-add + - rx-nvme-tcp-sk-add-fail + - rx-nvme-tcp-sk-del + - rx-nvme-tcp-setup + - rx-nvme-tcp-setup-fail + - rx-nvme-tcp-teardown + - rx-nvme-tcp-drop + - rx-nvme-tcp-resync + - rx-nvme-tcp-packets + - rx-nvme-tcp-bytes + pre: ulp_ddp_get_netdev + post: ulp_ddp_put_netdev + - + name: caps-set + doc: Set ULP DDP capabilities. + attribute-set: caps + do: + request: + attributes: + - ifindex + - wanted + - wanted_mask + reply: + attributes: + - ifindex + - hw + - active + pre: ulp_ddp_get_netdev + post: ulp_ddp_put_netdev + - + name: caps-set-ntf + doc: Notification for change in ULP DDP capabilities. + notify: caps-get + +mcast-groups: + list: + - + name: mgmt diff --git a/include/net/ulp_ddp.h b/include/net/ulp_ddp.h index 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..6f6e603fa2d4 --- /dev/null +++ b/net/core/ulp_ddp_nl.c @@ -0,0 +1,342 @@ +// 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]); + + ret = ulp_ddp_apply_bits(ctx, &wanted, &wanted_mask, info, ¬ify); + 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 Thu Dec 21 21:33:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502655 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2088.outbound.protection.outlook.com [40.107.237.88]) (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 AEEF076DAE for ; Thu, 21 Dec 2023 21:34:23 +0000 (UTC) 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="JAaJ7d71" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=g9aJe7xKvH9LBqwcs6lIMb4xbLVobkKdfIIKIMy7R1WyrDQoISGEtibJl3dWCLdUQKNCQjIQpp1lQ4e6nFYV3tohUP5eXNbTh3LslmY5MjhNHdGtGwjnocP98LN8CXEGztfP22c/BB/ONXT87OWoOqO2hEhiHtD/GNg4zr1K/y1tLL1rcBctx/7Kk+M0YP9IaY7wpFxiUyCA6InrJXuCRzOrEGZmPYyI+DDxme67Ursn2zMDAsdejdh4b+M6pUVCb8Hr3eObqwZAD+OCS8WQ/P0ZUzDbvWASoI2uK2hrEkOozhCynSGY9rJRFtjmWi3KG4jI9uPsf4AjiBKSRFotKA== 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=wYvVSRFTgY2wWY/42+MsPX2QgXrFds9afsSovT6ix2I=; b=FB+fgf+hPcRtiItNxVgUEQ/NqsDqQDi2SF1/peDcJ/j0DG35623YRLWvYpWC5uOR2zXReSUW/ilxznCmcCJfkAsUDhdzZOawOH0Gt3QGp/clCsoXo4eSBSWBkRN1a27Tefu9+W+7WRM2zXiH3Fh9NLPyQdXpFIq/bgWlcEXbF1nX/BEGpobVBBDIQG/AlqMNgBNm0J/MsZLh0TLovOEuhqA+KAGjgPk2VDvB28/3tt5f5sf5vwCYRsPPwCK29dXPF0xy+Ci53c/3O4bG7K311SObDA/ieQ2A+jW7WC1JnNPNUwIjNr7m0SPdIhJ/Xrj+zzwF2BWhPsocf3oqqzybsw== 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=wYvVSRFTgY2wWY/42+MsPX2QgXrFds9afsSovT6ix2I=; b=JAaJ7d71Qw7jpbkQAVmHYfOt/lWPycNnxzry9/aAl9/9L/VNzLORYM3St+XSv00m9JiZNRq2mAwEOvvlWjDfe8VE2o4WqvZ4N/Cjk1roS1XBjae2/kss6gBurqA061WsAM8VV6wE9jUUwIyap62ve8HfziJ/fQsalhijg5Kg9a1KHBP0qFE1nJwCg0A44mD07/gmfPjaL4mYRJg5oG31ZDNIRUB3ePAtRfk6T7DwVXT/xBn8ZkpyiUPINWAdEW06NBCO/qkCn/WZ1kBi0Sr+/MJNNsozVJ5teXQWFWBXwphDgFOq178iEYJtB5viyzL2WtQr87d7hNJtUwBfzQB9OA== 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 IA0PR12MB8647.namprd12.prod.outlook.com (2603:10b6:208:480::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.18; Thu, 21 Dec 2023 21:34:21 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:34: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: 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 v22 03/20] iov_iter: skip copy if src == dst for direct data placement Date: Thu, 21 Dec 2023 21:33:41 +0000 Message-Id: <20231221213358.105704-4-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO4P123CA0547.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:319::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_|IA0PR12MB8647:EE_ X-MS-Office365-Filtering-Correlation-Id: d43cc5f4-c20e-43b1-09c0-08dc026c97d9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: psqbbuHaxGMK+/nrinE8WvZyZrftU+cmttI0yIlBQ7q0VhyQpVH+warJleQDENwMS6nTN75fzIwyfWYzQGvWTsbeQWRkL03x/3LwlnPmpn9woNUYwqeCQ6CXFWJL2L7WBaAH7kZdeytXI2Mig0jcQhP/O7zQk70a6mgjkun0sAuOLb75AHCiT0DZJ9iK+gUtqIwEXxpcuCwWtbFLWwRSrGnMJYizB8jfejw6wZxKM7QFMfD1UuIOo7G3bbfvVJTgBihNzEQeBBVLdOjwRxJf+UT/m7nvUjm3aM2AD992ImFDE5fFsK+S+y8B1V/EIvVGpEgEXxFEhqCS+SZRFh+tIeI7wtmP/LK2s/wn8NNNvE5vleXArYljFEEGX24M0VBDC6V7tMNIpp2uxnfWCCfT8CzJrkyHUHCbCO8R87MJW16xQ/XeVJ1hcjoRfUK/3CQAc/Fqyj0ZuXmaZyQpNB/tydT9yf4m+GiUDxjvn0Nq+W/e+zs0PD1lYVFBLzAE4FYYeQznb/lsG9uFcGsN/ZAoh0J97uBI/h7unbR5b5jdy1D2XUzXW1GH/noQa55TA3op 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)(376002)(136003)(366004)(39860400002)(396003)(346002)(230922051799003)(186009)(64100799003)(1800799012)(451199024)(6512007)(6506007)(478600001)(26005)(6486002)(2616005)(1076003)(41300700001)(66946007)(83380400001)(66556008)(66476007)(6666004)(316002)(86362001)(36756003)(8676002)(8936002)(38100700002)(2906002)(7416002)(5660300002)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xLphsLqcMzftzi5pL57d9ztOBgDDG77/KeXJW+9TPePZPKclomk7Vqf7tvUEDftYu6pEqQHmgv1uu0Sq33W7OtkDRYcH3A876yPI/ZAFJ+HGrKiEj2XyaVd7BNV0GVR5is4b5t0vTUPEoxrfP88H+yuF8YLzP6GO//ZqssdgcCx1OWrW664btAMRIASreApFN1R85UoiV6C4o6pbsh20h4revFiscPfGqIQFUb3kQcSgskVUUj8Fq0p50tD+xQhDaOed5GhY2qn7t/CA4XCjkknF0o6u7hkW2/GfX+XirxeY8ywi3MjTCHdGMx9I2cILGRR037Pbu+MLhZwCbJ9HineEZdzICF7fF/rcESbnLHngAkEXxxP8eqFf4jnDbn+pX3GNETY/wtbPo/MfXaQBYS6GBYeECisMm8XvKSvfDk97kqHZLo9Rg0iem06My6HqRFxKWxjgPcKRh+ryuUyZtG0k51YbVP0s6yXcbMDg1bwMfDZG2f6h+zooVSLnNBc4kR+Tn/QBlDFdHIultPnmne7sXRtSPj74j2KYIEjruuGAJNwSwgcojAQwIWSnvWJr5bByZenCH2MfHzztu+7XOsJ0xOS99ubZroYxMi1q58P28pqgrk6mClSLFu9raHZdkmRYEou+k9TvfHO38xdBLBCAxCfqd7Zo3MFGktbmXbWGXPBX4nImZFzixpry+Na/wSqqb0XnHjR3Wnsm3gMyp2uIhH7yl+fxj3ncYDonJOsreCwR8E0tsOa2tE6fSwIHf5l9g+u4iVQuwkFdSmrkG/xcZn3Mnh7m1roLjWbMLrw9Axy5+m/x94tXcJQ1cGlgp7ufwdM38ODU0VzUDtlhqfSuG6/CGk+C1HNof8qa5YJX5LbKMG+VyBg6XRSzRRizxL11L36Ce8B9ltd8RhgxM5nCoWL1+OUwlERR3i+9aguhHED3ZfZhEM1/hzRcwpqOI0T2K9TiGvFk+UMWydoBoWOqUwSKbmwj7BBhE3aA+EjuIoJpeWN0GAJM/MTSzq71cJ2SravaYQvueCV+PZibLNSC36597/cdWBZYHhZuSDE8Xwl6zImHBKS7GYcwSHL+RpeZwWqsRtlcFX9BGAaVxXc4FEBtEkuQpob5yv6t5j8X6VoI8DdgQt0RemYVlYymPD3RAoq+cdF0ph2ntRf9R7vz+yg5pCSHa00h1nQHaN3ESLjXCr1sNruYOmJY7zWMHg5gtEJCm29TKMSFJEo9SRN2kQgEjS/EPtkAoCuRyi/RTr0n++w+sJ8P/qROA6vzCwfsF1nL+AzkOOE/YfkdTU8g8FynBzhF34o7Qlm2Tj7QdPnEtteyg6sfOyOZJAp5xDZIUALBjFDwFlJm0zvePcTHZ/7Os3SY7G82stEbFrkttUrKQnUqJaf7koPybB7WGptAe194NldqiOerjYUXgBZXjJ9xXi5btbCZYg2uDgxzMZXuF8UwE0rDkdwne9lqr1c3UKKIvJjSUZ9lmyLwF/xWr7iojh68yk8UYKVQfmF0KPpPnCmuTxSYlYNUG2pJy9+bbD6Zixd5Ic2VcYOez8w6D7tnpOw47sf3ZOz1M+jgmSpMWO/erN5fXki5XZj9 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: d43cc5f4-c20e-43b1-09c0-08dc026c97d9 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:34:20.8448 (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: B7NRc0U0uriVOc00H0872gjEgVeyvV7f1xUNvgaMG3K2qPvFF4zO+p6IPHuE8r+RFQPTVFRsW9+DhItL/tnV0Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8647 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 8ff6824a1005..b96d8b6f5818 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 Thu Dec 21 21:33:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502656 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2050.outbound.protection.outlook.com [40.107.237.50]) (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 367B276DAE for ; Thu, 21 Dec 2023 21:34:27 +0000 (UTC) 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="Qd42czAz" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cxtQt4zs0/cRCZuu49f08NIFjobZ8DAxt9T0TC6oRl8vjz9rCJ4alITQcG30PFeMKNhHrr+efkCUf8XZCSh2anjo++iLlBZpdmHX1vdaoYZf5ZVG4RRR/DCgaMvFcgNT7hjg1y03ZOuuLFs/sWpAZm40OINKSfCEgjexABhze16PK7EMiOPTzEAhiH8UimQk4P5hw7qQ0iKkFAjQs9RT7+dpJ/Sd3x2oE9muVnSIbGWmGTo8EqydrYS3QUPYmi7kIRa0KaQRI7aGqh0t6SbmypT1JdTAkz9w6u2ZZbx/X5EcCsNLS97Djy0B+HxdR2xZUApDKc7d8rawSkGkadk0Jw== 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=8rW4AhJ3LY/vB6IQX5dFyBUQfqTxa39/Olh+y8dPl3M=; b=csdcbAH05OTfcCZ048NWYrq59DX7WHD5OieUuRzEC8PW8BpeC1FoREwk8jEgF261FdAdazI37P9QwXxCHcPCwiMZjOTApk7MrMHwD2ctX5oVJSiKcvnKc9yjL560gUMJXa8HF6Hxpo21Q7YiP804jXt3CTSI4VP4JM33pT7fIQA+SQBa0nS6vcJ8Lkvy6Z595D24CCmmm0ii3Aug8ZH1EqLe4hBuslqjRXyIOzZl7AV2BSYiYrBWqgH5SkNlMHBDgVttdbGPp3CGedlQ+qHYGj6TY40bJrECivRoqCOBoJ1Ht98M7QcTDzcefB1/Oks1kyBDUVti0pGk1lKC+2SmHA== 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=8rW4AhJ3LY/vB6IQX5dFyBUQfqTxa39/Olh+y8dPl3M=; b=Qd42czAzTqqqp0askpSMoJTVGc5+M6RrZh+JuKUMRwhWsvX5mZIONsTAuiumsL4H7tQFbK45RIog3eEn1nXkNK5L+UTYCNnb2Jd2kzCQLBB0FH8eElsqLQ6fSvKWYFBeJZlqNpAWGBbURAggmOjLuu7v1tmpsklCQCrHc4g0N5mcYD4KYDNLa1Np/9h5WMcVt+q6IONhoc1VrLmG1j0WfgIguEtPyrbu1JcQHTumBHE9fAoGnhIpG1bAqvc+ef8C+vOGfQi5pIA4HRbT231I1XkCIwWRp/Knp3phku6vCDcb3zqWO8VIUqvRkrJTIYPX31gRRM9rUdrmJEfo/2XVkg== 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 IA0PR12MB8647.namprd12.prod.outlook.com (2603:10b6:208:480::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.18; Thu, 21 Dec 2023 21:34:25 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:34: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: 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 v22 04/20] net/tls,core: export get_netdev_for_sock Date: Thu, 21 Dec 2023 21:33:42 +0000 Message-Id: <20231221213358.105704-5-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO4P265CA0172.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:312::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_|IA0PR12MB8647:EE_ X-MS-Office365-Filtering-Correlation-Id: a0f21411-c541-4e63-1290-08dc026c9a8a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: J6FkhKfwQYuy8Qj0BwlAMNbIYdhMzYKgO1HVA2A4T1k74a1NoMCjuKa5g13585Q3KhkiVhuWPKhl5kCJAda4ZGfMoDkque5PkkIhvb+URFQtFARYqkcDowclTfHA1GRryM+lIxsECONVe3ZjkqnG4ghwbk3qiOcuxiOhvoG0pOUOhmMmoOxGQ9irQMEobBav5vkS4oabG2XKSnx/82FLWdknzxP8YzGGY8DfIoZLLzNOP8++p+3yrHepPS1lxIQK1QQNm7Rm8dFAXMTNWfVLJUK20wUlrXQm7y3wejEoKKuNU2IIk6/PWAiuI8dKfS813JYjd/FMjuq57NkHAfYydljDztEKcOxWNxnUU5ZfPk2dr9wZg8UjiEG6BwMt5EWIefPLmMOT4ONli1AeqVOrhfKxfEYLAMADmm3UMstSzfWnobLePwIskpTT+f9/zfCv9PskyPLhLmIzb/zGWbKMYJR4S16KWRB2Ey0FRQeilTAbuFs6ycNVeFCEv94aVpd+93vlUM0FZcJjYGl3GBsjivsZ830/Fua7U/4IVwy00sj9kBTLp8pri0FgTfun8lgo 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)(376002)(136003)(366004)(39860400002)(396003)(346002)(230922051799003)(186009)(64100799003)(1800799012)(451199024)(6512007)(6506007)(478600001)(26005)(6486002)(2616005)(1076003)(41300700001)(66946007)(83380400001)(66556008)(66476007)(6666004)(316002)(86362001)(36756003)(8676002)(8936002)(38100700002)(2906002)(7416002)(5660300002)(4326008);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PwiIjTkMz5d2dvNgT523UI+TQIJToXqbH4wtlKKR9TD7rTNFzzfpw0b80mOv3X83EcJ3x++1LOc2D6h3PONq17cb8Zo3M2aFdX4tVk3zc7aCZ1Av68Qdy5PJhOWYyGP6bV/TvqUycwq2/99kSodwZcSi36B7r8rtyoWhK/RFRQM7rbWDG7Z9NTfbIEu3fPxGDTOqYxNdEbeAP0N6WINedloEVTsYZGF2X1OmVIslgV3AUMfEz39G3qhU9oP5L27l5tEwLI6OVRdwa+hDclCtMOxBm6/EN8ZFKhumrH1C3V2cjkyKBurHPt9uOxLidKwDE1MOFfZojWT2McRyBGrqwcYYZB4eyyCEhNsvTmZYz6WfUmgz0ZXXx3WJ94z96pjYgzthkEhBRHZbVCK4QA+RmNwQTa1r02sISx2ZKjzMvyQB9jEJAxzIhxMmshGz1oG5co0Os8lAIoQ/2chQ37JwRwloJG3KzObLNs1ZdOjo4ZuHG/gATB5J8Fd58bLiSP8oY+hyrkhDwKA1Enq42aCa9fg5ZFfzisp3z2llCBK3W4Nkj/Yriz1QX3p2jJTmHvC7ZqOrN5W+TcmNdl1G+/ZhjX6UM0HAxRKV+pGt5/gQaAAruYR6KmlSEzABj5T1CAfjlgoF/sV+KlaL0+5zdvQBGu0evj5G5Q126zhOFfUgONQdLKLpUF/GHHs1h0dre4Stb/juHA3dUJe8FXRSec3BBbtgB2X3bgiAJvYx0N+HnOFZvGKObGd6IIoxhT66bCmj+W28fFmpMd9jm9LODRaO0QTerA1JHrzJllbkPxNMgU1a5svIP83CtGqXjW8mBSAH+H4Ox4npklPiRgM80DwYSvGekWuy0yZvB4SL6JFm6pIWM+3k3Z71Ya50zdYHIsy8B37aFzvVZA7DgOUa0AXsbYWw+QYmiX7zEQQ8nrGrz1zd9Qj4g5VmfFn6f3mgKNJFNTRYX5t0PU0Cu35Oku4Q49Beb4UC7HF98oT6PwqgKRDkVLEyy9UMXJjA40dpZX9LhJfYFIzS1xlAQp8WKowFKRl1SX174xjGLQKLIpvYEzv/6QLg9/832lwk1j8uzcT0A6O77IM0sDSQOOVpmEG+Z/uATV3Teg3n+HvnTNSzSyxB1ltspTQtvG+Kg/nKLCEUrJkm6hzeMRX6G1WX9/ptxvNXK5i/dew+WbzYbfxvCODFFi6m8jBqxlvjRiw994CdtygNG+7iWZ4GBrQbobwkWj3cS0VyC/Are1asZToNhE+GUzWVi0mAqmqIap7QzenDeKQGwGL+E9ZsqAch4PD7H5iRHzrGYPn5ge5b+NQgh2Sn7g/VtQxdhef1RRJA4yao5iOKY/5KOmM+elZTxmZu2jiRFd9i2jskujb9y9hA5Op6JQoL/sFkfe7cE7L1NbXcy35dVw0t51kYiHNURHN9sgFpiZLpssSsUcGgsYwTgilOcDJDOP/NG9EMardiMJOrLQwinqfdUsW8ifjQeja2uDnWNHBOa+DdjFot7WnJ91ci9v0gNWo2lKsHTY05Io5Z0syfwCujoGPBwn0JMdHPbALvQ4aA/oVfWCoQ3Zouz1K123pThTogDxmr0MGD+ClQ X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: a0f21411-c541-4e63-1290-08dc026c9a8a X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:34:25.3447 (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: IGXB6xpEOkRfeHcfRDoxcDULbHyoi0mL1bkRSLqLla5B6ybe+mmkddOELNjEZ4KuUit8bKkRUV37Apn6KvKd0A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: IA0PR12MB8647 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 3ddabe42d8c8..0359a1b58fa0 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -3202,8 +3202,9 @@ int 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 0432b04cf9b0..11a21e7d2217 100644 --- a/net/core/dev.c +++ b/net/core/dev.c @@ -8263,27 +8263,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 Thu Dec 21 21:33:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502657 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2086.outbound.protection.outlook.com [40.107.237.86]) (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 1923776DDD for ; Thu, 21 Dec 2023 21:34:32 +0000 (UTC) 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="cETjer0M" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LFimvF2NHFZZCl8EhFsTbTrQr2ClE71sdM5h3lt9VKjKeoRpfSeumnOVfjUmmkUm5U2sILQdgImQsAUWkd8gZBr+9nZiauIQ2TVDDMG798raRsvJ493NCtIyTLVC1y/TzZ7wifQtVJdvw4rJETlCbZf+3Wn+Br87kuAXHy1HBAx6v7ZP2kKAn/1YsroK62FJdUr2NbyNEBc2arJc5BlGaGgZx3vU4vnflADGUnbLHzXx7OOW9FNErUhzmTuHrWkFUZPIy3doOfBLP3i14ZaxJW2wd0OJfI2RQMh4r217Mhc941y1qKGrm6Fx5Iofc47aVgQa70HSPI37lb1gPfE3Ww== 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=TLRULv+AZz/683fU+45vIG6Kv7lGssqGnElW/dP1wjg=; b=d8pF4hjxvlG0uV36XHN3NJtJJ2AXbunDB3uhW+bLsycjnnkkhWpV2JX+yjwKeQhztwk6a7E+rBG8Af79ikwDQgAFf4Jg8uWDwLTHszt3Hfi4x2PKE2v8ZZIe4STZ5pdNRv04aAqM8U6iCoMuAN5nbuRzoqvbdm7Mhjrp0lws/v0IzWY9/EoW8ZePqHuFFQayqPbnPM4EWLexrzPl3laZ03eF0tBqUPV7BetM1cyEfll97vXzos2Mzy0TIpMQjOxjYJfw8kh19+Wp4TjfldJ4rmUbUWW48M+CLfUIgyMhU0v5hZ4sSPAvc94ChDXV750lJnUoG0AjhVSAfJVMONfx9g== 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=TLRULv+AZz/683fU+45vIG6Kv7lGssqGnElW/dP1wjg=; b=cETjer0M4tALQHmfk3bqoTnerzaD9O1joiE3pB6l69l0sH1UTMZT9jnPQuYJr9FehjqurYO8uJO7CCAlcbpl3a++e40ZkKVaA+BXAixLK+pA8GBkPQHENuCV2R3G5HfhJ2ot4putyBJXuxs52wCdEVDtzqNAENfPsMnhOLvpqX+j1P8v0e1gTvvqx7yIKQ5z1gMFExNXIxXr1+5d+3hSUu0+cqsQcUlFGszZOyqgcXaPwkQ3fdD59oXEMXaHbQw8+WAj/fj/7xPSU3NDYMvI9bER0ytH9FDhcbQrB9ADoVw4Fx3AtD5l4HAGudPZsfNURMmYOuLpyGhBzNHEB21Syw== 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 MW4PR12MB7481.namprd12.prod.outlook.com (2603:10b6:303:212::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.19; Thu, 21 Dec 2023 21:34:30 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:34:29 +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 v22 05/20] nvme-tcp: Add DDP offload control path Date: Thu, 21 Dec 2023 21:33:43 +0000 Message-Id: <20231221213358.105704-6-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO6P123CA0058.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:310::19) 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_|MW4PR12MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: 0ec20bf5-7461-469d-a7ce-08dc026c9d06 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 6shXqO9aphGryaPM+mvT5sT3MzFxq/8H8793hCygNcDZ8pgGAD+aPng1NhsSLifdURBncMIzRrvesuiO2UEIqK67gOwUVTCffaQLv9r4f0x3QWgToDPTOhk1/6ZF8ahG19UtXlj0uHf0VBrm4x+sXnzHL66Qn+ClsZ2ZJjAExh3FLN39zuEFUgtREatSKslm2nqfsQpzud68NGymjDX6TQTA16ehambgtFQ7Gt6w6VVAcI8ukTxYeXuVFWG6EacFDP4YRXXi9iOu47Q+yafohNvrANST0zcbLmtlnNBEdHp9YUj+KEBHbezqotlAdkvNCzCVMI6nhxMeXpYI4XmWB+bBPg9KUJsxhivY+hzGOX83oHQj/MACCiLiJ4Ab0AizNK3CuydGZUXODtn6Zt0H39fbQmYkqNFLiENd0WZ6DURnhJdfXXRs9V7uOXaYXymJVVmN9HRjHZYeLhnxlCx1mfIemUCnxBLDE86xGlkzHrCvSfsqF83Pb9De0G6orf+/7NM4Iv2SC43YUmwDh2Cmvs47AfAAZvEsse2KXxWQDF02RS5NsWIxOsHVZP7TZ6//jBR7rrh3H+6WrFdrI8lI7ob+mjgN2vHglhQp+vIVVIY= 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)(136003)(346002)(396003)(39860400002)(366004)(376002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(66946007)(8676002)(8936002)(66556008)(478600001)(66476007)(83380400001)(316002)(6666004)(30864003)(7416002)(4326008)(6506007)(6512007)(6486002)(2906002)(2616005)(26005)(1076003)(41300700001)(36756003)(5660300002)(86362001)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: CubYpY8y74PQMrDO2hTMyKfocHyZWXXFR7/fitnG++Luk3S5FKaZC44lStCTa97ISUliM3UR1176Qw+J3YBhL2ZhfbCN3sljG8CpHJ9ZGVrpY3hF29YphcXiIc+I15AIgNHQWPe479Hj1b0f2KnYAEXpGivtl679FyIuY1Q3rbDAtU3545Ge9+HJxGDzola1HmK3TLqRF8M3bGj1GaVbrTtddnCJ1oe4l1I6wDfC+tQmgEizCqNeOXN3cm2Wzqf8C57gqaDJIgikPLN/5tzVPb65jBOudbBp74s44fp+GOsARY1++vacSpjNeA4OIi6s7NAHaMY4rbw7CkPtBZwNnmeIcefg7EO5OtiIgbw3gLyNoIsltVuSzq/5jEg0ZBqNcLUAJUpTtVwWiRQ6UyyYAwFJSVb6x/si2GmaxyQosCuwVs91IhZcH9+dFi7ybykD2zjqQRbTWQhf8d1IEYcA7jrL0VPjeap3gHoQ4ShFGaBiTVwYUDp0XLZq0LSB1hPOFINmRWulckuvtd8iEFvMPOU/fszxdg8GQUNEzzSx46DhVWGIaWFuadL1wOTTHZASJvDXEoKl1YrWsmmlMLmz0AQTVGf77eH9we0UOFlGGKRZvocohGMG5A8x4qmPOnp4lAhjitKoYev9nX15lmvKme9/4LR3m5LBlBq88z/0xIgHoyWaQEdpGFfDWBGMGb0PHXL8A5O9WYyTIJgODAUpFGXQAM2EvGxXjdnhTSbqk0uM1uhiYreYY4hW1nHh9oVjaxQoBs/HtoUok4qE5r8DMJAcapvZwgHc6q1+mXKiY/DDYO5uvUAt9XiMbUcOz5zHK/yMjlZicPb1Fax1hBNizRHdmiVca22Q8azxhQlESQwcaXyoUQQD432Ia0GgjtOB5MGoXCqDRyOG5W6xz6rJyTAISqfHfO9HYW2yVaoZ5ZL1cENDIpVHBYcbEY6wQx3DpF0IDoouW0fA9Iu4D8i1gGTmVrayTOGGupj+38o5b73FgXc+ICxbrBJntWP05al5YypprLWoKPvWR7HR62pUjEU7yBVKomCvdcxYATc5bkn/hEn5/+VboRhglGDeH2Q6m+VlIAvqUz/gUVKTKTcZjW5q/guCaJX/UrblTJzQEImUm1Q/750beq7KYdeyGq7rolVRUvs1GjNypV4RVAjUssQqx5Vxqpnt8vOd6/QdQZKSEdfro8vVkyTE9tpGpYZ1Ipl4TNrOFRIIS2YTIfj80tOgrwiT0KeItlrqCHvOcQaNeO+KYhpLUfvdDEHW7pCIrxNL24C8jryQW615CAYAjozGXRsH3vrpWHpyiAIOZsAR9tqS4w01PyATs2Js9p04ms+ApXE2v3Z6ldGqiG7e5dvZiMviyNZpxgd+qWZB3CkYthTwMMIl2vWH796cIh+AaHZhwUBzLIeG7HX0O1Crer0w/pZfy01BQYsSyu1K7bMDNkD+GUx39gytg4fQPuCoR9YDo483IXusTUn07E6QQJWYkCo7GeYpmi1cO4Em/UEqGWnnfY9s/D5izTjOc+hIY7bfezBsJHSdO15qSsk0VTqRN0CIIDOTGtJGUSqZI+WF8ylvPTw6LLEeq6emwGvl X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0ec20bf5-7461-469d-a7ce-08dc026c9d06 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:34:29.5119 (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: BThqf/FEKzg4+/8KMuu+2AH5CrJiLtlW1tfcjWjxcPDhBy6vE6J48A2V2zlcDG7BDSy6xbYrSc6BkCZJ5+jJeg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7481 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 d79811cfa0ce..ddfc7cf6c83b 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; } @@ -2070,7 +2306,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); @@ -2113,7 +2349,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) @@ -2128,7 +2364,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); @@ -2413,7 +2649,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 Thu Dec 21 21:33:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502658 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2077.outbound.protection.outlook.com [40.107.237.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 855DC7762C for ; Thu, 21 Dec 2023 21:34:37 +0000 (UTC) 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="HwLzp6jr" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QO8SpIdbggvg+xAehpoh6rjm6lfLHJ8l9LeF9fCNevm70V6NbqYu4KWk2D7rUjGmr1PUotOrVsIF15xlcZWNgwCIKRfaaBuah92/fBXnCTDpPWcAKDRWY5ZSjd81fVcJVfZz8foczU8dSx/o1MNWY2U9FV/DKiiOyupazmdBTBn9tgu3G55mJhZHLc72JuCstQyfIR+Q1PDy4HP0xixr3waWgJFWya8h7M8lwtR/wbiQpEmHZ7cC3g9d9Hsd3delceLGaSq0gQvP4i8IXWYa7IEMGEORgejy4bnpZnO+5ccyxT8V8d0+yUsfsIkU/ndEj1Mxb3Nv985rkp37Bw7InQ== 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=9GOEd5v+KnrQZ2n36YinE8eqG1INtRsRCy5/N+TQmY4=; b=FLd/xftmiGwmb9yQXlZSjc5Up87Ljip4dD+iumNlUbjOLbyIJDmAuiNEpCbwQ2LQC/0JJwCCPHPM+uk4P53DUhFAXmiJWojKKdERR0hwRn5nki6Ua88P1pIb1uKQQ6OYH4AZQFqMTAZH+7RAVY8j5+YzBo3U8/X9fplnz4b0CDatTk3/a2HL/zg+sL61mVl0hKlYSRKq5umCDubhhelESjkQDKPKrRz95pEyIOZac+v7DYU4xYAoGrewlR9KwRm/PTnEQYobQ2MrrA1VfzmgujTpeB9e0ANeI7X6g5C9Zn2aDGeiprXQPfXK0SsB1l069AP9DDwAzTCmhavOqYzFDQ== 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=9GOEd5v+KnrQZ2n36YinE8eqG1INtRsRCy5/N+TQmY4=; b=HwLzp6jrZVGdq6yNcu8uab22Z32nGt9FiqE8vTEn1HPlGyXd+MDxv//SxR+jasMODUA2G2ee5iReeDSXu7/PbJpA/145xwgGlUYu1xj1EmSVhE4YdDgKQUE/YH5CH+OtSUychz5TiCiXTak+wfFdBMexGdB6Q22eUH98M3gQqF4zqhXs1r5hivu2Aizo1HfjJaankL726vKalxcRD0kFlIje/bov4rc75aeoS+eLL1Bflns0bHBW66ZSpyG9KhMV7J5Ixwvet6//AVUraQ4N8TR9qx0V32ryVhSX3FJ7DaVehtqLboNV0wivPpz5I1UgtdQgE4dXD8sjGhpbLcMqkg== 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 MW4PR12MB7481.namprd12.prod.outlook.com (2603:10b6:303:212::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.19; Thu, 21 Dec 2023 21:34:34 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:34:34 +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 v22 06/20] nvme-tcp: Add DDP data-path Date: Thu, 21 Dec 2023 21:33:44 +0000 Message-Id: <20231221213358.105704-7-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO2P265CA0107.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:c::23) 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_|MW4PR12MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: 21a5d352-c496-4f5e-d538-08dc026c9ffc X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tVWTLmwo2XJaLLTaN/q9r6lRK2e0m6NlFR1Od6nwL7nv+r9Nac8r6RNG+7JFJ7y4JeSMjBRgjyrbzGZ1SVrN3C968CalvljZrIPybA9RTGwoLIQ/IFArzY7X1t85vSc+LqLWri566zuvpl7javdGDBK2iZLk2HBr9tWkCiVswB5VcvrkYFIuxbTPLzBYEBaMyg31ocW/tnxVLDqzFhcoojPo5fIZ1V8XXgiH8l/KImgJqbgoCTmdFgIrv3kb0raASlPVDyXuXrZ/UB2EiKTB6ii5v88XdhSqqHI9UXB76W95lZxzaG83F4ZqxC2iSm66z7ldHb8wNsPdg1Rs9eLYo5112ttybBRnTl5mufgT08pDEYSk2kupK2HnRytnAGZvRi/gO8ZsY1O0UvuBeSDpnf7G0RfALbPL9QQnbk3RGllGhyeb0CU3SDA/c+lCJ1pXTwj8ytXDuz4UzlV41C7lQeS8trsO3IG9LR0xD31ev2zWl552IuLWPlRcweBxQpwZ8Aipaa5w1L8ugfhsY4a0871o7tf5ZFfV4x9k+HphdbY/+XXvA8K/013sA6tkHz3Av3Bh5+KFjFh2evTSPLyeOS6Lnr5tcyOjw+G3uLA70PQ= 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)(136003)(346002)(396003)(39860400002)(366004)(376002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(66946007)(8676002)(8936002)(66556008)(478600001)(66476007)(83380400001)(316002)(6666004)(7416002)(4326008)(6506007)(6512007)(6486002)(2906002)(2616005)(107886003)(26005)(1076003)(41300700001)(36756003)(5660300002)(86362001)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: wDB5svY6PN+xzJsXt+JLCfgWnMrfIw29mqQJzl2cT0JYUCu3+oClCsv/91h/Nmr+Og91K5edH+egHZ3GWP4ZtiqwPgpMozxM5ZPbpc6xL3H/daGCTg/RTROC7Xbf/wjAivylXGkdRHlGBq6KJmRnePfxdK1UlgzyTw0Tics+y76k1AfIsHM84W3n9k0EvgycTVpNsoHCj2UWc9vTvj0HHn5HAO2NVDjwKFTeait7BfsEFBO6PObM21Iad5D+YKkkQ/pZ1x4fuUygiKSRZmUrmQaxm18MR/AGjvJQcib0rHCodbrFYYad1u54tX+5A9+D/LykPpUwGxLTpSunI5bTvct9t3p9i56XWvZQ6GWtjuln/bbNWUvsFBWAKPzZf7HS2BON9FNsM4PKywBiQazAnQBEtF6UwhR8tY1ZYI/xmIM9jye2dtY69rspUqjPrbewo++jbT4/UdPGa10q1uNe8MDhIwV+iZZJrWkd8e0qfMZjym5QkJaGz2YkhgWqnG3aurvSIOGmfHuNnbeUTjHxxWlVig/QPavPKXVRisc0Qa1mvHlBdvu072LV6a8bJSOB8T4/a8t2LN9N5NoHol/O/32vnoghmsa5ALyIbKRkcycCrTV9yV9jvZI97LcNZgYB8NCeCJLs+V9imO4a//m8AJmcM7x4mp29JdNla0dJ6w5dvakQLXRU2eWVVEWRe76ZG2XNmDoaTIeGGGyOzo57aZIbiPzgcQeq38n6jpjfM9OAKVxk51rTkjPCyB/LAx7EZaqYWHbIwYi7DgXQgux3NRE/3eCZX9Gt6VWOgpquSF+I5ldai25ld5zJewUt3DPcVonaNvI40WeGlzHru5eVDK4cC02gz+w8JRb/G4xUpITHBXND1Ir/uHXKYUxcsiUNj4Rnm81pk0jC6q2fkqzFOg3ANM9xhVOfM4KCivQQnZAkLnH9ryEpX+yPezh+3ov/LPGc0PSgSjEVGBVDpYus71NHtqd4b8R9FFrejOPR5oUglVd2IoNRSO315tPZNpmg7eWDTlZbwiqBnh0lRpSSFwetoYv4v4bxR1Wk+YaYr6bn8pidP8QMkBohEjKeLiKKI/slv7jFxLaMX129nOPVOG1ohuDR+VPXa+yMEf5hIoNzypER+jceZkTwj8tLlIbdyWJzI06Ch8uGudpCGFkEEkeyqbzOiBlSakD6swHTeNMbcgOBWlkNB4eAIEMZHncRfYAchVAqNHePGUTvrJUdfHvLFFrl4BXjKKx7ZWDline1YkE4L+bJQ2rrw+++OKxMYuesm/3ZDpI5eVUMmpvAH+yG//p/S0R5kzPNj8Tj6ln2O09h9MjCmp5dJmwro2e1tuKKUYcj0lo8G+i9XkuNV6Qk1ldHYSndzRPI5mbOUJa9qVtroF/QH3GN7k42/xldT+yCrtuvEjDgzwOm2R6WsLNCZKAFhASQPA89ht/VukkB+Yl1XxuZ8ge+PXZ6zWXb/Sq1uj9gw9IDWkxMefAtebPlu++xubiaAssVcSoPD0LjT09K3gnpHWxHHfxyzl8xFgQnbvKpZj5F4jpbCkLz/5eBfBljLm11Dbj/3S+MBShBYtFAL6Q2f0gklPVSyAva X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21a5d352-c496-4f5e-d538-08dc026c9ffc X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:34:34.4767 (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: 14nk83ls47J+7JFI/0ILn83qCuC62xLsogXHzL1SRTjUnc0dvWgHCRuu4xB9V/SC+vsgtBLJRUfIB3vtw+gTFA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7481 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 | 125 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 120 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index ddfc7cf6c83b..420b8be309a4 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,11 @@ 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 struct net_device * nvme_tcp_get_ddp_netdev_with_limits(struct nvme_tcp_ctrl *ctrl) { @@ -366,10 +380,72 @@ 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); + 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) + goto err; + req->ddp.nents = blk_rq_map_sg(rq->q, rq, req->ddp.sg_table.sgl); + + 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 +549,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 +571,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 +854,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 +891,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 +1091,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, @@ -2728,6 +2837,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; @@ -2766,6 +2878,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 Thu Dec 21 21:33:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502659 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2082.outbound.protection.outlook.com [40.107.237.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 2EE9977620 for ; Thu, 21 Dec 2023 21:34:41 +0000 (UTC) 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="k8iZm4u4" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IEmILq1gn6DUmnPzC10Dt3enoynGAKwaXf14inMeZOOnafHtdNQwwpQ4cr2vGqGzvYA8wDoM4t4/qz9CW9ZKxz3HXupbh7oEvBS+yvBcrLKWSkY+l5SGacvwMAMd6vZPpo5OYhd11b7qBJE4drb8ITaD6afZvKKR6gB1Orj1GTbUfhQFGeYtcLIbNZiD7xhGW0n2gNEWzcerSmV7TItzyZaHpZrbgeD8wgFOzxcUhEPT+VuErQYb50UjQgSc+1K28i5MCQ/ZnBGqz6ec2QeLp0EUyGI6rwXkUP7AqDjUKC5v06MwHWDp1Rx8jrNMb8u7Jl+OSFsQKJZai/dltfYLcQ== 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=u9wEKH9HN/qmfDURE6Qw0cIJT1VVse0zXxf1ybIG2PM=; b=FwoVbRjF2oNv5mRJOEuXXfup4+uEabcGOyiIpGh0F5XyPR7pHMGfxtHU7BxcQHjF/RxQgvU9uTN9M3ekQwO/RER5EC2aYKtzIm+24AowqDFN2uUQEdXSmuDO6orT0moKkzByITNJxoVBb+zMwFMsABvCFv+jEZx8oj/4V19T122YayCjiWgWZyRUjPcdn1uv0lv5KWtxG1kdsM85Fj3+aWMXavDxHhJufrlv+lpFSkyQ6IMY9ZXSc1cN3mINTJgepvjuArFFvLZjAQBfepYeDe1sTMHMSUVr8f9wI/BxdxHa4gi6mbNen/zT/UqKniRAvAlYybXuPdAKac+G/MsgbQ== 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=u9wEKH9HN/qmfDURE6Qw0cIJT1VVse0zXxf1ybIG2PM=; b=k8iZm4u4SkB7ly16ynE/H77isg5e1utUOamHQ01Paikh9HdyluyBq66ZW8Jhp2TduT0JfSeLIqMEAfAMLNcCFc9OO3xcueQdOl9PDXAea87yxbXZ9DuCO3sWUO9TQrOQBlPyk/y8Q1akA5JtLkCf7R0u29+xoBjw7wUvxsxF4Xg0F2sYoQkDx+/onSeqCSH+XI41VzNFGag55c38nX7nKS9jn2fQON58Xcrg9e6eWBLCE3vjEuzyJXX3ZIJQn+kOsLHpa0jYbpq54FCAX3ch/EKHkr0D2BDQv2s4RZaziwfOvtXny8Pv9DLld3syaxCo/4wS15KlCEAGDJ3AI+qK3A== 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 MW4PR12MB7481.namprd12.prod.outlook.com (2603:10b6:303:212::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.19; Thu, 21 Dec 2023 21:34:39 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:34: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: 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 v22 07/20] nvme-tcp: RX DDGST offload Date: Thu, 21 Dec 2023 21:33:45 +0000 Message-Id: <20231221213358.105704-8-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LNXP265CA0019.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:5e::31) 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_|MW4PR12MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: 1b988af1-2fd9-4759-2af6-08dc026ca2db X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: QC9UBEn/5MtKsbUAuzXChh9KOfIPOTU6aDDIKHLewI7YlK0tzrkuGZlke3tSsu3ENvv/zgr2egXx3tsPwNiUKK6FUFiMeBr5pHYunVAAwuzLsCFAfdKc9jlCS0ZytHUwn7d7U3bSSNoyDGHHwLkUezWbkFPJiuk5Xu7oKiYUKXMER5nL4umA/iiNOXLPgIV+wX8+d/rXpfBv64rvwWHdjIAzlOMIrSSicApzTHUHV2AoTfru9rtOh/cRuXc4BvUJZuhuwxJ7uSJ1pxmBeNnxdEfl6q1YjquHDclmGz7giAc9wZ8vSLWWvT4i3VlgwUxBPF9/6UrRXIix8oS1zVYfv2XkA9QokTTzZkx/vHdKlOfawdpGPDTgTJhtCM55DK2mKtpYdPit72Dzjl2YjhQTS/5Z05O0UtsTYz9FMO3dMxxbqLx9mu+X0sqJOwYGAhw0aV+FbkcEp3h/w1KP8vEdQ0CnVxkf9GugdGyOjIlhxG91nvo/SXgP3juCvVGDAr1WgNBnGlh4N+lVZtvJ0qGOPk0mbD5fDS6h+3zU+pr+bhtis00/utLS59pkhRYhTLNYNNfWLeOMPYYCxu2n+ea+hH7g5+EkNJoKzpRSyYtoxNE= 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)(136003)(346002)(396003)(39860400002)(366004)(376002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(66946007)(8676002)(8936002)(66556008)(478600001)(66476007)(83380400001)(316002)(6666004)(7416002)(4326008)(6506007)(6512007)(6486002)(2906002)(2616005)(107886003)(26005)(1076003)(41300700001)(36756003)(5660300002)(86362001)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: VO1rTYwcWJiG7hByMXRMJ1hKv+ZW7ATUvOB7zJ5HfSrhTowaXrc2+N+6U671BLALih71gQ69xlD/6tT6eINYvnT1OP2aO99HFT62N1ruJy8P6cqcWcsGwQOAvuO4RQ3zdtXQiwr8//8bsPwnfh2W3aOS2C/QWpvT62axQRCTZyCGfYQRuUVwLb80uXdnXcPiZurDYP9yA2ljos4+14z3b8/c+BqSXkWSkbaB7lPOieS/aWl9pUvv2z88MkCOaxHCQc+7/3UKUktzQ4/3TxPui4D69kyR32V5cqzi6DWfaT1JhenysU9MLODPHWIJSCVzWi2uZluzx5P6qPQwJsyqN1Gov7VUlqaeq7wjuVdXSrvsEZ45Jdli7pcUfM+AyLHKhDUwty2ltv0aN4oKjUWv1bvPYsfG8O/f91X0HFFnRSaGjX2J32EYveTi9CA8obej24xs/Ap+woxl9JlJ8zcC/mPJNuEdVLnCk65o5b8GPGp55/WogcgF5tgMItX5FQ60RWRI90wZMOKla0kflfB6Z2zfhHxOMvzrIue20Gf7wc4xMUSUmz2NpKwkk4IK53bfkcYTke74cyWb7QzOyk0dbmf2AG5JTBmnqGRCx2INgg9yQBCVFKwZH+PxSiCEQNabiJZqv2hNr0cBxrtFAMqlHpd0V5lfZgVzrUvb+hei6TWwx/Oy5blAGxnmZboIHBoL1I7FSNBF3vILyLEl9a4fmlWbykr+Z2CVl5DJ6D5Y6sgK9zuvkhhJKsZw8eDvLPkO+JJsc54JcJGMFZKgCTwaH5tt3w9ZshIFyg0WrXmy3VVgOS/yxFTegEqU/9Vkj3oudeE5dn5KmHvBAX94x3yH5MD2MFbn5AhEAfcZNMAnPk9znJzMTuyCdQIEwoeQP5oICrUaMBHVQhHTexSIdGvknAM1XSutPQHI1J93UQk2bMikgidfedk9akkthSp0mdvXMNVS9995jCiUsOIMQJQgV0YJ4NRa8LfCoJd8eBFLSeeiDCCkPUW9MrDicplrA0W27dTt1oWegP1Y+8fdBDh8wgdZaejjG9KvxMv6+ZYgJWUfv5droMq+W9kCKY36MV6s0gHINPQzRzw4bmj/mY7CSyUYtBwOl+rA+D/M13C87ZvqCyqHYEnMa5QyjKePnK2FLfrvgtkXkkiFANNumwKJSwem0wxPM435otJWX8L/6/2rloVNJgOUD9yAPsicBKJ40BdyObHw/D1Cqcl+Rg1gBXWgcWXxVgl39J3z3UbLUABYVn7BNGD4Mm4VgkjlkJ3dC83FgAfy9Y0WvFIzbe3vTjzrJ2rXEyQVATikVu22W5hgccS05ZzwTDK/l8MZmb4jEGkok1Zr5pbUKDqJn8X3fRJQgXA3CNvSIkJKS7YkDfdjya9ZVDhkqPSPS8fbnV8zMgXGwdd30rCdSFhLaQ7051Iu24UwmkokufjQOjxWS7941Rp5Yktn2tRsLXt6CSOzktlrBz4Lqo8ckGxqVr+MtGpxWqqGsxrc3AyXzRC9JnYZONCK9wGnWmN62Zu2IFcRDKhsWQKpLcPjNLfnwisrpn0R33UNR56inBWyoJBzwEci9pbeaRkROjtOQpd11v3q X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1b988af1-2fd9-4759-2af6-08dc026ca2db X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:34:39.3069 (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: 87t+zdniny7nArJm1hVmiFXLYDD+Z0JtglXE78++W7G1VlLHr7Qgr0/66jHYVuLRgJLQUE2ohdJSA7/OewrsZg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7481 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 --- drivers/nvme/host/tcp.c | 80 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 5 deletions(-) diff --git a/drivers/nvme/host/tcp.c b/drivers/nvme/host/tcp.c index 420b8be309a4..6eed24b5f90c 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 */ @@ -379,6 +381,30 @@ 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); + ahash_request_set_crypt(hash, req->ddp.sg_table.sgl, (u8 *)ddgst, + req->data_len); + crypto_ahash_digest(hash); +} + 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 = { @@ -468,6 +494,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; } @@ -475,6 +505,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); } @@ -583,6 +614,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, @@ -843,6 +888,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) @@ -1108,6 +1156,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; @@ -1136,7 +1187,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 @@ -1178,8 +1230,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; @@ -1190,9 +1245,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); @@ -1203,9 +1274,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 Thu Dec 21 21:33:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502660 Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2049.outbound.protection.outlook.com [40.107.237.49]) (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 957B376DAE for ; Thu, 21 Dec 2023 21:34:46 +0000 (UTC) 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="KaznMSz8" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Eo/bN+d2jQD5h5A5sM3guPZ952MXcLv0wTTTTROW+VlsluJeQQJA3J7eca1A87tjYtR4/kT/vVVzy9dqn6VDenl+zXiiwXX0hzRsx1ZBLrHln4GUEbWePf0J2nii7DHLH3TP/1GT38lURVoJPVNOQGl4o8/WsZKUbiNoEV4/Cqy198sEVakNXw9/dxhrcu9+9ig4JhWigNZYDh1SRS0VHGlOAjz1ykNqyLNU1/FIL7T+xJ4gkBXRmx15gIlEHljyayotdCZ/PjHLKzcy7FyxrN1KyyjDtQ3qK7unoV892RGGRVM2V9moRrc2X2ba3upVa9fr7r20nb+sn1J3XHgFng== 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=U2LoW+wyJLGKqox2luchxX6ASlmSkahhXjlWSi1WRzk=; b=S0fN2yVDWvJTrzMcxMyQjdHOdXaOOxpNhDVpb7JqDd6hIltjq4D1OPziBQ/K8f2ekCNhVl5sXS1i/4rTBmVmVPtIP3O45/saToVbynmG+5NBBURKv93KJ0Mc5ZMDNYhmnbCc7xiWV7ZhrMskkRGfEER0O5PH6jMT8ZkJ4sUURp9CHuvw4mAiUvkZWswCbbF+WXgxNj1w7YxJf613TB8xQwEqIqoTN1li+Wn3VM2idlHhF1rvUiaYrDtMax8f7z83wtk0BMhJCgagrVVxkNW87uzbwAMbmUyb9PrEwa9DKIgajnAL93cUaSZAK9qeHfWH3AqipP3pDEMdYPi2dAT/oQ== 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=U2LoW+wyJLGKqox2luchxX6ASlmSkahhXjlWSi1WRzk=; b=KaznMSz8wrhgIBIRx1WzfR2MrgVHVBlv8xtOVp8QFyy5RrOgBDbLsSCoD3C8Ua6TzIqom9TDRJCg6sxZDakhzbnp/bGw+O4aUMSuSlLhHf4jFPkbdI2aeO61CZIsFyH4Vb7xAtoCJU6MEGLLAhkddFu4i7+I+BxA7+tP0mv5Sjv3/4RYWp/OJnYWdXDU04HXNZSndLWqqB52la7wHvFTji9bjmazpnM7g1d6JFf/gwG1NkXpovv1EAvbySfEh9mzqw4OKPnxsxsigi4R1vEJzy0P4d2EObwIIPtQSmqCYZQg4h1CqTb5v/QtqZuxFg5NeY0s5LDTGxocLg54qEdTYQ== 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 MW4PR12MB7481.namprd12.prod.outlook.com (2603:10b6:303:212::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.19; Thu, 21 Dec 2023 21:34:44 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:34: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 v22 08/20] nvme-tcp: Deal with netdevice DOWN events Date: Thu, 21 Dec 2023 21:33:46 +0000 Message-Id: <20231221213358.105704-9-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO4P123CA0398.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:189::7) 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_|MW4PR12MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: 3c4be56b-543c-4d08-d06b-08dc026ca5a8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Z96rIQ0PYQVOLHnTeLhgHB5Jqx5A/igBOCt/QMg/jEyn5Bcp0ySviGyzRnbe9ZR5cPj37FNRMu3YXuixOWeAHypBPlI3Pt52XFjXsqkZIAFwHfyOVCHOua/r5L04OYfMqLg2z9MIpSC99SZeOwrxsFEzDoPKd8E0QcJfAHnPMWtGMl9fo4d1IkgGsmAjWRSRslhsSlP0kW2XBxXopPXaQiMsfepvJyy1HyiAr0w0YvNQXZMXrmGDcpxjkSCPUVvcqrF1nxyw+zEkC2xlH1rzCKRdcQWINfmQLSFBHdlYJhxzF/0qbq1IFiZTUeL11pNRHIgRs5QbkbbkC2M83ATbr8Q+nGrj0cWXNe3UoSNj/c5wUsKBD9WHycaZdTNnoQEh5icUcv7gupZ54TSIY+EPzWAzD4cTchgcx+s/2jLt0OBN6M1r1FC+CkFzt9z6MQRj1A/pFkNnHvxhXEnqoVMXWfg+5a3dEpKdAEa3yd9U7xjZzeHz/NqGwRp9TNj03/plFvi8jNERgV48LMeYbxS0bfdI2u4VZ7I9uvBJ6l1b+CBxpazGd8Wup+OiYmeI7OVUeNTrPrbIleofq49ww2JDoAwV6aA10aJAA9Glu7MMRBE= 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)(136003)(346002)(396003)(39860400002)(366004)(376002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(66946007)(8676002)(8936002)(66556008)(478600001)(66476007)(83380400001)(316002)(7416002)(4326008)(6506007)(6512007)(6486002)(2906002)(2616005)(107886003)(26005)(1076003)(41300700001)(36756003)(5660300002)(86362001)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Z1MDaWZCLVn+pIDgy4OO4k0CIAxgsjvxSs9yrZhhM2hUXlVMgqOSCR1VlgxdeEB0t1LfYXvPoyGS0Z+BntZZbJLxsDPW2rvAbDX3hzilFTCf01SJDeyUjadl/Or6IOteDHlCble0eEGdk4th3eFpy8slXM1g7woxWmE8qpCAWFVUsr043zvoFdBN7PkDGdqQOVm7TEl8M1H1kiu7HJHr5azo7KiexdD5Bu391rEWtiiV6ZM4RP5tCT2dZJjQE1vSRggHtqH0n6ViVrBVHgrx5rN9wRXGtz24j74cy9UwBrniDbsfTEDeIGnIX5GHqzNOgfhID/+O5l4BlZihHTeSyZL+QFmzarOqiKd+QrmtIZAqqZXSSpAoN5ifKMkefKTqc2n6RpMcP67GbCZIPQU3ULr60QO2IjpsuxGSBygr8j+FvT4ItZxCCydTRDePtvqRYpbIqL7G+ShLTjqqH3aE9Q37d7RKrZ0zJWLGLGEfF2C8BfqEiZBQWk4B8kgLDrd71LBShYSo9GkrNy9njMXpdci5t1nLNZ7MFOUxp5EJWr5sKRexYA6Lyx00332U8X34emTR7mqH0uisdje42NVkHI+DRwv2BZSwKdPPbCrzKdtGHsFHE4orQ1HOa9l8K8uyeCEEiLwhUY4+iNveMd9tkrCZob+eNsS7pCYj0UXVx6/8TOU9V8lTz+X+cnX7R6CONJ7MoADLe3O8Rpop7EhCFuRjphKzNgFqJ5e1aMXkjWweNz/Y0O+uwL7HkMfH8wGic10eMEdrkNrZe06yVvAwWP70aCkKdgBsa1W68BM9jDqVe7C0OeFrBqv7GAEmgs5g2zwsfzcWSFG2mGiH5C1++wVOsOYLBIDaHzkOu2DHsZVyw1P2gKJUVX+7kn6WjPg/4RU67d4mvqg6G5UfTqTAfnJdbOKgrKfLn4LydxSob68tQ+xioBKFNN6fSGynqwuAiQ6hB77vDB4z2ffJHvJaCuVpq4F2VspBcoX27pXtJ4khkUmqyaHlRjtP/zMku5uOT38qjTA18ZH9iQuM7CIceZG3CBswIybgFFaazjsplPDlz7on/1fugnPYq9aTHHnkAxehrVc8HBVPYR5ZgFXfZnhM02SPkPrk0+yw6BKvgjYxzta2V9NHzYll3L8VW+D18aSje1PEsLmorutOZAzr+yGHQDcmQczlhqtp3iEW5RdnHy8F21PyeaC/RuJApKgoDwjkPDg540leD6O5xuP+3O1YNwm6zlkn8jvcPmfnnVN+vdcdseBxVxaXcMTUk98+DLUlYBzBMKkSHgXIgT5y/GoEGia6P1hOZl3YL7RV/S3G/IT3mqTG/5JYjd5T01SCqcGhZuCs8EYEOHj1gjNAkMCbzVaDrPc6kPtE7v8iiDK0SDYNJKAzKP+gOWwlUpfBSewXEPGhKij+Wa9IAOU8PKE3a42bwQzBVQ1tm/ycWdn7FZ3RS2ZOIXMmq1qPusrVbxn2kSmebZzfkq+FAU+A9kcKiVkQEuNro3oGpugWzBoM0Tz4idpHTDLV3U70RFelrl/CmykPe/g65ECZbQbythiYGZ6SJLezNK/2+YMvfp+tqPcPEXdE1zkfpJZzbl3z X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3c4be56b-543c-4d08-d06b-08dc026ca5a8 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:34:44.0023 (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: mqYQEnEHwUgs4jBRqWFVFwlY0e1DS6DDM8JzQlnAqRLSLRn0jzTmAMjeJREw0Rt1qIi5py/VBXrLS23ZGYfBsA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7481 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 6eed24b5f90c..00cb1c8404c4 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; @@ -3193,6 +3194,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; + + switch (event) { + case NETDEV_GOING_DOWN: + 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, @@ -3208,6 +3235,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); @@ -3222,8 +3251,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) @@ -3231,6 +3271,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 Thu Dec 21 21:33:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502661 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2042.outbound.protection.outlook.com [40.107.237.42]) (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 3FBEA76DAE; Thu, 21 Dec 2023 21:34:52 +0000 (UTC) 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="WA9LDtPo" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=h2k30LC907QX75Cj54LQ/ZJNRAy1xJO4W/VHLzgKcVxLVQdjCEiBXy8wOqeg+xEto0IQkpTXFGqYKvx22hwv0uSfLxvQivMRqvJHyTn2pJY1nHIXtMXP5VgXywjTfgLO+lsTEE9Znr0b7JRynyOWU/ScXvKXUpUjDMN5MCO9613r6hJ6ATFjPKK9/kXp2TCai4GyXqz6Ph2QFZz9lfelrTouLPueh1IQ/6F92psnYgMQhfYcuCnkF9Rjbx3u/x9CG3DfbUnxs6iDQQo1GA1dFFGAjKJMiDo/wXf6qrU2QMzhDve8ht2KUdsaiIOab1YPXLC5gr/JVY491BDLsj67fA== 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=Qew/daOmlwygAr7NIsvtRVh0DAAynsd3qFyosp6weXM=; b=k8gFgDBeJMxDrT2Q6EW2lD9Mn6lKGydPljYCzxjJJGvKEN1E9N8Sp408dekGODHfETmHkPbp8iprYCaF8UNO8P1QB8wt6kbpSqqf7brvS9nZTTNg/ocPAHmi6Gh+eAaXiM7qwN8P8xPkOCOf7kwkmcmvEIx7Duvh9/z6S0z6YocBQnyzomVjarkszbRaCNWw2mIsEjKdSOxsYEK/5Q7xQLSqW8iK7uozq+g4my1hL0I0+nhqg2y7QbK29elXr6ZWxwJPFuyl30tOfWMqI8vJ+o8LVuoobuwD2rv+2WYJqQvErfqGOQi+lGvTeiwguz4QV/elJyXQat5xKpnDqNi9EA== 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=Qew/daOmlwygAr7NIsvtRVh0DAAynsd3qFyosp6weXM=; b=WA9LDtPoxyiZtwIGc9xiZwN5EiA001LGuEjqZC5OnqX9mQB4f8SkLMB99GlCoy1KtFjCacvvNsIE0pvWLAshqtd5NPa9VLmb6qvBBI0keIPUz1SwTQOgXzLZYctNbs7LxFAfCWADi5ceF5niPmLFMCDHabSGcUooU1W9sZvqT0fpE/D8rpOpvNlrVkrsXKBse4WdrT40KFE1ufNWLztXm72ox4ciaGRpeg87Cl113eAMEH6J584Rci1B8lm7X2yySWcr5B7emlLotA+PXiRXh0/bqNENeIIw9JwuofygkArgYu2Yw7Gulx5wPsL5UCDIbvLG+a+Ur9CzVwP21g9bWg== 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 MW4PR12MB7481.namprd12.prod.outlook.com (2603:10b6:303:212::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.19; Thu, 21 Dec 2023 21:34:49 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:34:49 +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 v22 09/20] Documentation: add ULP DDP offload documentation Date: Thu, 21 Dec 2023 21:33:47 +0000 Message-Id: <20231221213358.105704-10-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO3P265CA0031.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:387::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_|MW4PR12MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: f72dc3d0-0f6c-4470-6000-08dc026ca8a1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: GssayZsPrut6TCH6ZoYICkuwR7SPiHgDpZgvRGDWAkCiPFp/GfaplD6H7+uZtsQY7eKxG/tKjgRhgxC2dQAg4zYgXnk7BHnosRe2nu0/4S5F+pSPtdC10DyxVJLMdzC6DSNje3AtkOzt6b0ygcGoTuWkRX+jYFwA5dqLKaLMPFNTEq+iMHmOX8vlQHm+8eIIkmwAyKwIMMzz+V5ZhEakGa/W+CL/rNV6lRlHq36ghPtCuZHvpMwNjG1h/CjcOYKO1EpCyuUFkx6pullTS0vT4Uvy1UHeOdmMcQKEuhl+fV5/PgIBFCaJzveKhjaVELfObopt5xZR1652iVr2FUm0ZcFYg6VZqW5hWO0DUtKd7JN7cgP3WsYV+ZdNx6KSVdTCwPg9dPCy+ESqraL+07efWCRzny9FRCLwqaak/qa7M2RD8gdt+U9YY7wJ6rfFvvQ6KZlSciwieoAJUIMKjuDSjfRgXF4ljaD5mVquA1Py10DgSbt3wz+/SreoVpRdrUuRyt5EwBtOBJaZIwq5BqZ3FDa3I/bLLr6F3TphPIoB9jPFhSykQw3/PtSeYe95HNyS1xPlKXD5NEjCCASh/cCfV8y/pKiYhuwEw9IHTsURoKw= 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)(136003)(346002)(396003)(39860400002)(366004)(376002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(66946007)(8676002)(8936002)(66556008)(478600001)(66476007)(83380400001)(316002)(30864003)(7416002)(4326008)(6506007)(6512007)(6486002)(2906002)(2616005)(26005)(1076003)(41300700001)(36756003)(5660300002)(86362001)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: xSZtJNm+FzUWU8juSULLw71HDLZwxrdxfEXj6uAcgEDjluS29dyUbXSmUjaUGqgCiSf8eKKL8L1V/5mz7A5oeYw5YYMD67n9ZSp17L2VqLDOfJpP6t2+CA64kD3SdvnvTFiblprCSk92E/BO9dvgMK/fUmvoJUv92P5zz7xS/X3puZt/EQwTXZYfZAk5zabqmDFMFff7msDK3FZcdJGvh1Xx91g+qmALxhLH3uOakbrxoDNG5saa9DixVqpGf/qgpcAmdOzvQLwclraqJUQ51WjYnqIftT2YuAW3SDLBr5O5E13uBnviPjKB6A5RfOFFp92IRlgjmjVWqlaHInZeIRGA+0zIRE5huk3+MyJ6Yb1mH6o7dDKiXuFPRbvqj2jcTqV2M4aqswSWhptDEZyC+6ZhQAPOT6jEelLUWecJBwCdplMdndOCbDHzHagj7sEOn+FxAkCL5v4FBiicJuFZdpS6L6UnLHQK04QQ6Rx/p2ACw81YJp/qJDSS1GVeTjqK/ZaluS+9bdGvyU633NcTXh7L/jTRIb3qe8Y0w/MhfOHYFHSiAX9AEzwKX3YKMTJ+jQXvrbhxI4bpn5+UjqxSNJHB1uqSUOCp5hRTENk53oQOpH2RKh6ZnAVejJHaOpWNVD+Jv8VjYb8RgYtUOi9ftlJYSywPXsooIk4qrZIDNa6A6x/Gid0rRqm91onumS6qXFe/gV/nK1vHjujRWnQR9mKyviUz0ogILIdATzvls/kp7U3mXCJ2YeP9yYqBicX1XAIe/JSQM9MGOh8l3rfR8pM7M7EeRKKpAxZoIL0zkohFG+qO0IuOkPK3fEIk50/fzM1jsdzsa2Uw4gtrPWj+DfePKflKUFBpaLQelu+n4C0YCND/SDZ0Sh39//Xh6+8NnFX84Ep9KbjnqWmg/z4uWM/YtI4eF6wOLWB7BQPcE//VMT5oTAy2ON3rJj0TWd7Xj9kxR1rGCl7bVuzEtOTZyG4EVhPNe91FAiD3rj+kiCmfQoRHp4BxBCmUyxMoLkntyEQjY15iDiumcZ0eB192JvOPMaOfK3jR1Z+tjFC3wn2l1ginqUiY0uAiWAZIHvON8y3DW3gjFvQV65jAzwXVqOhHnUvodUyYZY5dlF8iClDeVqd0YXjObXGGzXXoq1YJdk1Jlx9AooyrQ2NLvXDbqWzQf2xprf+dim/KrALQlEfa/SuPGZldY5UEYRbMng11bUdTwyXw1NgEwBi4h8zonPHnC32GRo4s+mAUJr0mKwlwqwYQXO+hSo2/JMpE50L0Re+hpPjkVGfp0KJQFYhR6AgffCLhHTLpPkadA4UqLROPJRkRE2nFvPib6aYkwIxYwx9DtuFYeb1tUnJEKeUI4lh0tXDixD7FnN6P/rldY8o+n2vvZ1QnFml9PzgZRfVY3XA0KfOmhk+gADaeCVY1kQlqPG1jZEiCVh2kCkNIGa/OTMeyCWk8TZQiJ42oknyBJzptCuCr80+CvKqkJObXgtlTXEVM9gYP5WMT+Me49oM35tyjioLa6RqYPXiRH94Fy9FSA87eRvQ3oh9FRi7AjtOpKT4fx+XpalFPCl7u8srHBpiK0W5Xed6xAq/PdF53 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f72dc3d0-0f6c-4470-6000-08dc026ca8a1 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:34:48.9829 (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: BmUFwqKvJik2LitKjwNTzvX+Dvt7WVa4LCCBLAweOd7PCB/9ZxXJxlSeqwimUkJhD+KVu1xrKr6Iip66GcSkmA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7481 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/netlink/specs/ulp_ddp.yaml | 12 +- Documentation/networking/index.rst | 1 + Documentation/networking/ulp-ddp-offload.rst | 374 +++++++++++++++++++ 3 files changed, 381 insertions(+), 6 deletions(-) create mode 100644 Documentation/networking/ulp-ddp-offload.rst diff --git a/Documentation/netlink/specs/ulp_ddp.yaml b/Documentation/netlink/specs/ulp_ddp.yaml index 7822aa60ae29..27a0b905ec28 100644 --- a/Documentation/netlink/specs/ulp_ddp.yaml +++ b/Documentation/netlink/specs/ulp_ddp.yaml @@ -26,7 +26,7 @@ attribute-sets: attributes: - name: ifindex - doc: interface index of the net device. + doc: Interface index of the net device. type: u32 - name: rx-nvme-tcp-sk-add @@ -75,31 +75,31 @@ attribute-sets: attributes: - name: ifindex - doc: interface index of the net device. + doc: Interface index of the net device. type: u32 - name: hw - doc: bitmask of the capabilities supported by the device. + 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. + 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 + 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. + doc: Bitmask of the meaningful bits in the wanted field. type: uint enum: cap enum-as-flags: true 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 Thu Dec 21 21:33:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502662 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2040.outbound.protection.outlook.com [40.107.237.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 70B1D76DDC for ; Thu, 21 Dec 2023 21:34:57 +0000 (UTC) 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="m4N0td5D" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Qd6INjYybMnhWK5DIEvWCT+DEuZJqTNmba0nTxolHcrUQB8r1wWaDm73/HO+g3+bt/dQbZlJwA4b/eVOIDp1lAlRWBB6JBSbe699O3qCUdF4XyqIkBjglnxNmBRvIDfonGRuc2dW7jNa66WJ8Mq3vMAQfpMluQSlNdB0JQPGIUGyX96u9x/judbR6xAjPRT4geFjM+F/ji8Mo51s9ktCmAmpJ3sbQ9TZODSIMCg9zVnUq/p9H1bXufqSzpVqycqloWDyvidh6xpxoZB7fv5VYSco/7Lc1jyz9pnxlyufaEikqzPPYyDrH5bve6iKaC1UZ/CudoAAcSoF04fqJbp7Sw== 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=9/tHnrHvLYAwRXyiGrR5BTXybg8Pj4BCVeXhZaRTll4=; b=S70OYFm6qYaYH3mLs/WS2SylgdLBX5p+qOjEg2bZHIfhyQyZhOCPn8t+FgW22FWeOs9eVJy1IQigDwkghIe7D3xUgRrv2CykTkusikEGVnEH+LkTLgqzlc+ClWLYX/1lWsvimhnpuHfHWgLEWee9wEOyJ2F8URukB4LJH+W/PTePYEo8kiqwh6/H1mKbg7c3c3BQHBijJJsNlL6acp1SHqrtlDvf2nSSl9z+78oImu+iTH81vjF728I6fyHLb2jcSXyOjLZFt5uMlQJ1l0W/ya/WJ/DOxTgpIwdftAwlgxoMGOp2/t/NnYbYJKpPpacKfBfrFE+0fA7gZjVmd2oZYA== 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=9/tHnrHvLYAwRXyiGrR5BTXybg8Pj4BCVeXhZaRTll4=; b=m4N0td5D0B6AhujllRrxgn6zKZw9iGj33ArsxM+X6i+4XcYN7yQREZ52LQmApK+zZsekBEhtnUj24SldI5x6DHWDfi2QyIx0OdMny1D5VCK98UmLn1AI7yqC24/ub7X3y/1Y2YP73WbQi13loMV+hzpi37IUss0h/fXRORHg0uIcxYx7JlBD320Koo+V1lpqwc0RA0a8gQWUDJWRg8mYsQ6DKiSxvAIaVCrRsTEul6wpk5hutFlGgReGRn4gfdYXCMza6WGXGXlUjMGa9+Q4n0HX92yeGeLbBGlr6YMCSs/mdxVEMNCVdJYuvNEG9D41kWPJGQm9zszEOmZEC7Segw== 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 MW4PR12MB7481.namprd12.prod.outlook.com (2603:10b6:303:212::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.19; Thu, 21 Dec 2023 21:34:54 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:34:54 +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 v22 10/20] net/mlx5e: Rename from tls to transport static params Date: Thu, 21 Dec 2023 21:33:48 +0000 Message-Id: <20231221213358.105704-11-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO2P265CA0256.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:8a::28) 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_|MW4PR12MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: bbd63385-0706-41a8-792b-08dc026caba3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: nlv7tKABnrXff1HUkWfgYs3X6J9iirr2G5PEhy5FGIB6TzteVCSYL36dC564oZBQHBiny4dqWl9Nsej5Y2QjFzkTyLpHYo81FrJDf0/rRBDZzo/umFbwkAtDUHRU05HhtZzVebZKrazlnhLEMxL0bzmyczZNZeGeBlS6Ppz5ph1eQZPc5cpOKY3IJsYzbV7nOt9xrBdc93XAg9ykEm0NEt6HpTQh7oxewl8Jpe1+BgX7StfZ1hAnNHCSB1PwauNjEWjZZz8607nYAuQQhgL1g5L//Aa21xUSNKC3QI4rN/IXQcKT+JQZCG2gvcI0yaQR2cykGW0OzxCuSPB8v/DeK0E1dgEXx0nHqwuTciJBneKp0Tc4Q8QsuLSxzyeyxkRBMmrauLE+LNyibTcxkSDxnUprV5gcB1XzND8zDYPmZTymK3Mo7mX3k7mysvlVbXYtU2VPiBCj46qrwfNd+15IZvjNIE4oQZt9diQrtKHinL4bmNlLibzVvOuN7CQ2ddmMado+BLHqRxiqT/jx3fgWfnvJs3Eo94grUZJsPMVkcQ8lHwif5Rc7b66PO8jZTiXnqKcqb+2iNP1DzI3wfzoP0lHWQ8gQuQva10NuLMk/ecI= 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)(136003)(346002)(396003)(39860400002)(366004)(376002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(66946007)(8676002)(8936002)(66556008)(478600001)(66476007)(83380400001)(316002)(6666004)(30864003)(7416002)(4326008)(6506007)(6512007)(6486002)(2906002)(2616005)(107886003)(26005)(1076003)(41300700001)(36756003)(5660300002)(86362001)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: F/7C3C/0dlWdClnsU7V1dgBu7qZXBIXjjulWanIt+RgvP8PwszuF3Bxa8m5z5fJSKI6soGK5jPnj0zoaoKhqanmgX5ANrGYuKL43ARoH5f998k4em8CbPZEIJktiYzIC3uEBOv9N+B9Yjo579HtSkat9Sxvduw3biza1F7ZjqqOkNS5B8tB3/9sQos8q0oHqY5m2346aYE/UQCuensPOBwG9s7mkyapA5JzVyMsXWTVQDUst+qQoHjKBQ0EOwal6M4vJBZDm86VuLEuFgmwuvgPG3K6NxG03b/KoNG8Iwie5+55uAM3G77sxP4QgitocBjyrDDyRHZ3T5lkAbYoHiRYC3DPvFPt4P/Mex5w+jhMfDXnYceDwrr334wn6mzmj4XK3u2ER1FVjcLmwsXpu9V30fTgFtCTwZXz4dQLi7px2CIaowEl5uc6glRvL2b5W7Ycg6Fb6mNEv1H7OMmICcOs6x+hr4wyT0LH7b95Uydy19wLM7S7Lj/5zKTyZs3/BHwoNROZqI5PPLWlhKwTn9YeWErdditpR2w6sy4KC7YfeqGobV1XKi5eGf95cUCUthq1LC72FSe09i6nf9A+7dQ2pXFauPaX/2BEi+BFJy+HMZU6DYJzpwNliZeXV9GonOfEUwgfzeZj2YVnvv0kSLamdKsIs2bNLveZ6KR+/deo4PniQhSM/SMgG1jhN3RReaI3koyLImumBEB4L0XfsNc0AjZsJN2GDtb4jqJMg4C0TNhmcheWziJr/rcMm7tXHNA4USfQyR8/kgx1/qs+mewNQomz5p6of2Km7W2i8m+fHScaXs4s5k3tAMk/ysC6WR2SWuCZkZJuSXVeoIKMixnBQ876u82m1PIqDJMKDonBtstQ39n56d365wJNWDvmIf0U7SxTp9rUtOX5IqRtCyCXTNhxXH+m8p5xmyfcbJDiaChvLKXWzvlCBp8Eo8tmVFJblQ5eUd/3ZE4+65a6mPgv1v9SPWfL+KUvr1F6q23LPUIYS8g1AKrMoHtZy6c2/VGHnCuoGQYheu/c5g9HURZOIuHeH+6uYd06iKz3qxOvtamDEi5Y9v/0VV+p+Vp83x9SOmasuHbMCJyGU+C5fjw2MpcYxiQ3Nhxymddl04wiHOnzLUmz8sguP7QGHuJiASIskgd5Nn23fZjsGTqJdzJeeqep+yLz5J2/OVWU27rJXGOO6aQ+D//VO/iJUUk++nwRlYzJoXpHYmo8EOmOYm6qY4uBw1R01G7R4LvjJcW87v+ylMGsLfY6z4msPeUY9KuMqSocra+23a2MxoOcoudfHjrYnsk9p2DzR7VTB5dalTZufjVZbmMrjYtpaMFiC1GZUEhvb6xcYgt5QLieQ/SGdhXvP4Bw9k2tigeb3glYv+t2Wrxoag2Kw5vw0kV05ixV6qgyIFPm9K1v8F53WlVAjDeP4yyFlkiAaQfHTBQZEgUcR5mOYc43CWOoCz7Xk3QAJEZXpbyd3hURPrIX45dZoCWkAz5v2MDHr1XK3g7nX8P+EAK6tGjt1I0ouqTUqlAjV9R0uIYG0vRwyHPRZlQjn5xzWj/gYbqPODa1nw2TdXE/nMNeN9mRU8BUvmr1G X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: bbd63385-0706-41a8-792b-08dc026caba3 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:34:54.1537 (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: lYBu88IoTg74t1rmp0Z9j045rmHNltgveSDJGyMLEwp89qWjVj35DxmgVVfMq2AOUfTNI43k+wNyzt6infcyGw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7481 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 820bca965fb6..f1dde3c6a3f3 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 ce2e71cd6d2a..7388410292ae 100644 --- a/include/linux/mlx5/mlx5_ifc.h +++ b/include/linux/mlx5/mlx5_ifc.h @@ -12358,12 +12358,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 Thu Dec 21 21:33:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502663 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2074.outbound.protection.outlook.com [40.107.237.74]) (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 7F13477628 for ; Thu, 21 Dec 2023 21:35:01 +0000 (UTC) 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="CumQ57Cx" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eH23HJtKb2n2we/cxDkA+Xix8SWk9YA5XJl/mcoEIrUYF0c0xXncF56qQoV8YqZSyi9wQLjSHlLpjZXkJSi943/YZo3zSr9XoNcPbcGv8XQd8pEYp/wtmZWeoG3TE6rVZQB3eOVrYZyjFHzFNq2sYeC6V00+JO1pmWIeEzmdfXCiIteESiBNfyuF5ipHxMTczf3BHgG/9mci4nr/CdlBfp4iumxmR3x95GN+1sfwc2z/DLRZlzleA6Jt+rPI8djbpT0wZLcOQegiSwSTTUeOpzzWOyhdYP0JWD35ZIP2aLcsKIPw2KbZx22vMyZqQMO8xow9eB192VCa/9qCb0DoQw== 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=R4vFytacI0akD5fbZ1CgExCmkcknh3sDQSfZMK1L8/M=; b=hVs/Cm4f0N/FeWE92V30SlaT7pk2f/cEsn9Woz6jkalzryIazBVLOX/kw5ttZQI5LTx/bG0R21sWGSundGRHDjxkTV+kkS40BSW2tF6Zou//OJaVBQuns8KWUdXnHhsiy1n37gWmH00g2xnK/5QARWrh3C0/hImfFH32O8sk7Xxot2PUM9Rfe7kyMfCHiLb3cVFG7tIy0a1zuy/cHRE17lQR5nfQ8hfkXgQvjVBWuMenj3G7y1PBe8cFl/o98F1nLhp2c0s/HQAWgFfIxyUn0y9D+xazbhNVvEeLZQopS93L02cU5Ku2UZC6pkdTtkz3wYAh452Dj+x6AfGa9op4aA== 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=R4vFytacI0akD5fbZ1CgExCmkcknh3sDQSfZMK1L8/M=; b=CumQ57Cxkzu+Cz3cBiEd79huEi1whUHV16UdV9KyiGA3zoqde0fmQvSpK33TN9HBV39gj4XZcMjtwdJ57Bd5tZtVAN0s2YKZrZ+WhNF7zoZnpMr67InrHHbvP6EoYDSVMPcbReYopoTWsDl9ZHD3ZcE04LVyRoGBnQBfqoBkgrO8yPcuyvOo2ZzZKMAfKtgZf2BpOYooVWY7DBoRBHkc6akT8EMkN+tq7K5XsAKk0ew2BrS4m0a5j45RRLPrYu9malVqJFJdg0Evf4fRXWZwRgtTRqeA2cqlL+qZ+z6NuWqsJ3LcE8U2HRSVd+hkmACw3AuBdYuvPSCs6JgvMjNUZQ== 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 MW4PR12MB7481.namprd12.prod.outlook.com (2603:10b6:303:212::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.19; Thu, 21 Dec 2023 21:34:58 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:34: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: 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 v22 11/20] net/mlx5e: Refactor ico sq polling to get budget Date: Thu, 21 Dec 2023 21:33:49 +0000 Message-Id: <20231221213358.105704-12-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO6P265CA0025.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2ff::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_|MW4PR12MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: 3d2c7f15-bafa-4d70-0ba5-08dc026cae5e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: tCC0H4x5c8PXqnmvc25CwAoXLQI7I8w4PgCbkXjjVPy7fuD+Nz2yCPaB1BrdLkmZ1H+aQEDc7eDjZLhX4c5Inhyd0m84pdA+IgDPBtZBaHdb6TFWBrVsCp6eqkP/uIT4IN1gnvp1de68PIkAxcT3U3I+7ptLQj11ORnTRlq+VDC6WVWoQmeTtVBJUPAiy8R5HNxAFEL9gYHsXE0IEjYCU2HYVVWXgLAABKPwPtni5bOMH/RbAkrjfg5EReaRwsPvZvAK/p8qZllocEYDxDbkZxx6WUymLBGwFEeR7aGOjL8Oa+tJggOkuw7iblgMDmYdN4hz+eKKScrZs3HAeYNmWwTQXpVh1p3Vf9DMxPqWX9QUNkF3ZnBIA//F3sBAyJRfozrqsVzpp8F+EUzul3vjCCs5Wv5GRUjCY1tjwWtS2OdiVyHEJlx4bsJ2vCHuDShazT+7hRcJUfarni1J8JcUkHP57WkQAnqxz0rfg71N1BG5PeNGJmXKUoATmmm0j9VCy/dRf7/I+0Xbgwr+WVNhwNKBQSSNX2K34wPy0RiqMd+OukDq+BhMf5i3GQWzkiHhKqtsVTXxSoVLM2SDylveFvz9T1J4bO6kri9sPCRUZP0= 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)(136003)(346002)(396003)(39860400002)(366004)(376002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(66946007)(8676002)(8936002)(66556008)(478600001)(66476007)(83380400001)(316002)(6666004)(7416002)(4326008)(6506007)(6512007)(6486002)(2906002)(2616005)(107886003)(26005)(1076003)(41300700001)(36756003)(5660300002)(86362001)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Qf+hu/G6BNpmuXORNTzajXXGL+FsIJ28RoQ2opaEYUGyOyHEyXnryEmMuEEjB1uJVlk7KQZNG3okUaDLSyR8icp+Ko5nRfhKoFnnf5ceXGkvdEm7Y/b20kHiqo6rCC5fQiHlBruAyF88Mu8lqWXFZd45GaMh31dn/67CNheEhAgJnj2h+SbxSLaUc7LdF9lvf5m9jHtf4/rV/uvhK/WCDqY6kT+yZpXPBtPqTYyOsh2/rx9a0xO0HZxdQ8UsWnJXCut7YjCGUEaZyrHtRbnRQkumk0G3tV4aJNiiSp+8e746WhZiO6G5fuy7jFkh64OB6gQKxtbWN9FO+xIYd1gE8PpoQse/1mxqf7WFZwZGWlyEbaZOStyLWtAFliEFepJZukxZr1vjVffgaxK7mXJD+XdVYAi+t0CBV9h8eCbUvSw7DklohI+i8YcQOgTDAI0UPkAr2HuhG9Ik8OzIaA6lOwCXZjGVypwcRVJ60218O3Q4RUhQQzghuhb6QWw4cAxxuh5cVUfVpyldRquGA/9tulcabq4Hp8f0Sx/CYRYrU4hZeacV160U1TpzFJkJNI6j7xYVif6YAq2WKEk8RVP2i2hLVfBmj/zsyevGUyP7ynPMdeYRdKDoRGYF4zzO16iA9//YSEjVMIsCQ/AMJvL2aQJXBatW4TUMim76/D+UOGd7Uo17wmk2R+vpH23r2BD4jgwnK23AsRG/pnbhCiB3oSfCqm0Ojh71lEkjPmJ1R+YCxc2HV4R+tHTfW3e6xR+27VwJLKK8Dz574D+zQEghnXDY+24fHiRPCMbBNZGUx5lMLdmL9yfXv0M9h7H9Tq80UxHNpSFB3h+rYBojGZtrlnkN5lReFM8O3Fs/p8tvxRr4qLbm3GjENGbehKuublzj9Tb2hs3xkOxYnvmjEI1Jm7Haox3HU6S1pOw7UVjl1kr7UdFDlyIxRZp0n+JbbwmV+Zybm3oRkRabYukkddd/wGhXSZoLDB1c+0AkrlOrCTA8U5Cwd4X2S7SH/sOEB/ZdJZayyrtAqZJvnO5+7U9mdM7WYKW5JV2IlWmfSmnS5msMumCvLwMOuLS4y/81EwRdr5yuwT6rB+qo0WAaR5SQuPVSkzuk4KBjL1jSehlbxuDy0U/MJtMwV6uudPUxznR1pgvLgAVJkYn5TpzCDthWSomd9E2KUzDdjE9gRgtzBLGVciL3Ev5SDSItBHri2m4J+GeUf5ewFamarDuTK/OoYIMx7POv1iqwJaULXu6fih6v3OLDxj7EedpB2iMCbE1CBBsjRDxGyBgA/Y5KIIef32SrpHqlbUdJ/pWhHNn3m7W3Ubzs6shxcmgAJzBm4QDnjQv2MpDZBBa/DqAX9PLcSrGitZDY/e/INuXL8ANfsB/cuaS4OgT8hQWZg/01UfFw5J7HtpseHQ3zianiW/hJNFFQqhZqK3htJgxNHcrDAO0wQDkDkaCylXEgW5AWjS9z1BVxQnL3t9oxJ/QedwIAyqVbCbuGHqTNSYcYa7vN14jAthTINukGQyENMzjBFXa4xf8N8hosj8/JOytjagv1qcpqIHYG7zsa3GhIKWbYPZ+5KBHhEenElS3tlFQpPv/3 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3d2c7f15-bafa-4d70-0ba5-08dc026cae5e X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:34:58.6688 (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: mXa+ZgVa3i7GRIc6UzqnWhzVIo7QbdDTtAtoyYTqYka8POFncrz3buNwd1ONOmm0uHL9F9v0HQ8qD19idKfGWg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7481 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_accel/ktls_rx.c | 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 ++-- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en.h b/drivers/net/ethernet/mellanox/mlx5/core/en.h index 43f027bf2da3..34be754f712c 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h @@ -557,6 +557,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_accel/ktls_rx.c b/drivers/net/ethernet/mellanox/mlx5/core/en_accel/ktls_rx.c index 20994773056c..3c6c5a4692a3 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 @@ -267,7 +267,7 @@ resync_post_get_progress_params(struct mlx5e_icosq *sq, goto err_out; } - pdev = mlx5_core_dma_dev(sq->channel->priv->mdev); + pdev = mlx5_core_dma_dev(sq->mdev); buf->dma_addr = dma_map_single(pdev, &buf->progress, PROGRESS_PARAMS_PADDED_SIZE, DMA_FROM_DEVICE); if (unlikely(dma_mapping_error(pdev, buf->dma_addr))) { diff --git a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c index 26a98cfb0a59..5740772a7b10 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -1501,6 +1501,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; @@ -1899,11 +1900,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 8d9743a5e42c..addf8905fc35 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 Thu Dec 21 21:33:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502664 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2069.outbound.protection.outlook.com [40.107.237.69]) (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 0DE8577F0F for ; Thu, 21 Dec 2023 21:35:05 +0000 (UTC) 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="QoqNKL0p" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CtUT/n+XMNbkVRsdKt+BkKkdVqcXoR50tApOJT/vCFRfhIA84bYc/d2Ns4uzFyAMJY6yRcfR/1hrZi1lICtQ5Xo+lcxYJx/6GurlytbZoF2extBzaihUUryPQ2OuoeqwWBLzT21Jy6xnsf0qAg3eo49ToCNwN+1ARuegubkol0AE1DXXMUsqDhu3m6blw7b6w7BdSWRHDDyEPm6dZCk85qc8q4PNYTdsixof9R6ZkrCwmIYai4mpmK22/ByDSfeFFpLV50oi/wRuoDAirZTHnywPNas/Aymqq0NyCCp140frmYztzrv8DjcwaOaD7xN9EEEmobumkQNb0odGK5Hf3A== 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=a2tSoZ3iT66rNXAP8OdSPtOyu6OiqwlCNJ8UQWUenAc=; b=fbuam2Fm3MFXaQKa+UlPm+V5V1gjzQ1YEddF2S6h2fwJcmUo9bl3c6GFAnETskqnzVbKmEWow8QPdRa9QBRhee7d6fwAXlksRBIekLIxGX3HcNvjwOapWIcs2p86E22NR1OcccQYy4qCxwbwlzSFfMxznfEb3owkN8R0Jua4Z0ZQzDCMloJUUTsLtC09O1fSqrhjnSnIH/rq2toXKmn5FBXdd4dja0ZPyXKl3kXLs2QAOWy7jPNUoKX/eqKXMMnps/PAoWdYnzZWXnoTl0soRNtsCvh9plXXJolJU1B8i5bmAUXKcHiaprRFwwwilOguyfFc/9f2zQlJhB+jtNEjmQ== 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=a2tSoZ3iT66rNXAP8OdSPtOyu6OiqwlCNJ8UQWUenAc=; b=QoqNKL0p2OzrSWJvKaPT5aaLzz8Ic9Bdnn3ZQn/T4nlBaCwpWNBzIMg2WeV6C0k/qo0lorqwV5iKFe9qvcYHRsdAzsm5h/CKvzPOn1saWbpISjtB/ovuOhHiTxH+3fd8veKojw6S0gbM8+sJ3Y1Ei/PodvKal/cluI33H7ZuP8bh1+0rbHwJK3JpOckniU+AC9mt8JNh03q3ufZzM7EwE0yXu1ZCa77xl1bwy8rzw/i0bt5RdfaL0sA/HVGwabXDEUowGZn+lEWr4ckmtWbc0zLLiouIq3XkNYqm9jj1Ipl7kO2UFomL3XNAl0YfJd4nYbiPNVN0Gx6Fz6QLdGu+1g== 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 MW4PR12MB7481.namprd12.prod.outlook.com (2603:10b6:303:212::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.19; Thu, 21 Dec 2023 21:35:03 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:35:03 +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 v22 12/20] net/mlx5: Add NVMEoTCP caps, HW bits, 128B CQE and enumerations Date: Thu, 21 Dec 2023 21:33:50 +0000 Message-Id: <20231221213358.105704-13-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO4P123CA0286.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:195::21) 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_|MW4PR12MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: 9449e9cb-259a-4ccd-5006-08dc026cb10a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: xTrsoFlSQvKoXYHeAghxMUS8RL6nYGWfOfCVts5OH0yFesNXQ9Sa1IxqnB/UUQ1GyDVf+DMF2jQIKjp2U0vaIM/fJfTsm7/BeoXL4ZjRR21QPKuTVFeHsVOEnV7eT6bMhfQSvsVuIZ0OAvdugun6y2UmS9sWnSlwBb6BDpetVySrQZ9pbHAJXfDPWXOd8FkSQjWTNjaj4dMCQ65ncBm5iLDL9NSZ0GojjDzcYpVbSfAKt36BXcDXvy3VAX0CKRXn5JQO2nqDb6cEgCci6GduRa/yWm44Eyaw2Axo3YN09Fluu2z1Z5v3/phpR5QiEdHZ80C8OcLWUm0kbywMrmlZQzhTc559zEuauyITAqVBRX6Y1btDY8JWssfxLYLKt9EFcHbCqNRO3jkP41EfJY4g6HEM5RzmPCFWfcOwU+Gkd6sYsl54grTg8Cdzx6FHWZjq7vQ62CjtLW+pojDLO7lO+Dgwko4aIThK9+YoFlkoVfBV2X1lEDjYB8eWP7RyWurJneJFqFnVNW6P87GqaCGHE0Oaib/w2rW2YuWrUbZ5CX9kHgALSitaBtvJyQoWGlT5zYjnkztw1J643wvaaKH8mVRtxMa47bSmdMyFtzvQk/g= 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)(136003)(346002)(396003)(39860400002)(366004)(376002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(66946007)(8676002)(8936002)(66556008)(478600001)(66476007)(83380400001)(316002)(6666004)(7416002)(4326008)(6506007)(6512007)(6486002)(2906002)(2616005)(107886003)(26005)(1076003)(41300700001)(36756003)(5660300002)(86362001)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: fFGCJKgU2fPhYi3txlgtfUYjbHS2l86Xmd1afClPEO0wr3laJVTKT7w/oZb9xU2mnzBG0lDj4KENB6gpGA915QkqTokXY5c/P+s25/KQa4L9XGDv6H3fbyQWtNe9iGAkoIFT0uJw3NDtJgDuTsPrbATtrH8EXy6Nnn4BGLlVDkXoGOGRjJzYvFr3wrqzh2kuw5iwfIn7o8S7oKlqBGftzs9saST3Z7ryRIpIePyYzMEF9M8TMOwN3bZRqltNbatQvKacuNSwIUrLgrPSi+McJYIrah0VO/fKHbfWycQGKUDNCbSRBGIeOMC12qf8izezOeGqQfOKn2NorimOOaafGeBPgpl8VUfYREmRq7FYiYhZcDxMeZ7o8wFrg0gDIboLfxaZpid+DsdPyT/2yu6/V+I3XlP8CmnfobJLZmRzPQasM6ykmf/fYYS71SOd5SS0+2qDZCErfw5OYz9xQLh6y3MtMr9J0iGKbD5KZsSxbHH6ACNDeldkot29oP5OwFzpUv4b0ZTpBn3Eeo5ONDeoHXZunOciie9O2JfGXSejZ7BRfgqwVRH/awjdQr1TUHo//YNu4ZJUYElY4kCN6A6YXnbW0Mcdtin3tcuOpR26lMY7K+b2JT9nwbSmYsfueNg10xf7/M880kdlUccPleMUv+RfCWivlQukBXAPEShuQs9b7GaX/OZURYoiLOgh8TygLybp8VgiSgMSwWjfTn9WE16s5mJRE72PkppIfnw1SHOb6jo/SGld28ytFVJF2E5l2BjYn2rq0CUXRPYA1i5rXD2uYaLNA8JRDIPrEXVesiTk9nRZgPC+II7et0AsA6sc3w3hoHeCy+Osn0uL/yIF8v9JqsymP/ZzbdVRrKJqBAUjdtSM1MOUWR596t94yFKasZMzJw6ZXnvS/YwkHiTnIAiJx7dP6cjNWg9wyRUsC6PD91/vraIAXYt2+gnlY1dYK+Gw9P2KFdThjPU+JBtrhwggU8R2g2ZXzCW15eo9rm/GH2G67t+drWvgCvckLA8SnvzRkhoDfVZOqapkbrAR1ggJKi+/QpLBIOB4mp+88UVsJ0cOnxvUfQ0mnUO7+05yseMMkqVGZv7giIoYL6yRWaQyoGDSr6XQWimqDiPlHktYGjt7L69Z2nEOhzmU5pzYaczDpuKj7rIug8gsD3FTXF9olk6e1XZ/9bnCO6gDk6K5yfpT14xol2pXSi2/XqDqCEQnLmcclHecXnMxfZ0JaCC/OJJXn7bjJJX34QI0ChIN7HsndK+C2Iao+3mSkzJQASpysPdEWWvOM/e4w53+hF3TakKQ8WL23zwF9Dd4wIf8ibhxMm0vKGphpZIt38Ne7A26eCrn94COxkAfiy50Mu5SKSdqnbh/xJMWVkMSP3UjjuzXjZmwizbvQ+sYlZEw9P72or++AEJqghMBwv03+GVcuP9a2eOxPlzw3XlBaGbxOkeVTcHX6+dyvOyxR5lC14QVXOp9eYnE7BLcBsAoP3KXtQeC6ssdJRiS48m5OcXb3F+5RsY2hpP/K/91w5dYnYPeyfovFIQrGLHAKEotC2QTXMKqQC1S4EPfpNbqJYcuFrWOFVUhCe7VzGz1+0o3 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 9449e9cb-259a-4ccd-5006-08dc026cb10a X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:35:03.0968 (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: HGDt3TkWHrq7jtLUJFyVwc055ZNpn5NOAmensI7WD3nf+H4hgihoXDekCVW5l8XC4iqjm1aqK62jiMJ/ngoHTA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7481 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 58f4c0d0fafa..f1745f69337b 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 f1dde3c6a3f3..6416a5e8a8e6 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 7388410292ae..ea321c96c1c2 100644 --- a/include/linux/mlx5/mlx5_ifc.h +++ b/include/linux/mlx5/mlx5_ifc.h @@ -1462,6 +1462,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]; @@ -1486,7 +1500,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]; @@ -3475,6 +3491,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]; }; @@ -3727,7 +3744,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]; @@ -3758,7 +3777,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 { @@ -11974,6 +11994,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), }; @@ -11981,6 +12002,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, @@ -12347,6 +12369,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, @@ -12360,6 +12396,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 { @@ -12382,7 +12425,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 { @@ -12681,4 +12737,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 Thu Dec 21 21:33:51 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502665 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2050.outbound.protection.outlook.com [40.107.237.50]) (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 A2E1CA5B for ; Thu, 21 Dec 2023 21:35:11 +0000 (UTC) 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="d7eEUcI7" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CaNObR5f/wpXWoA2hYN5pCcHyJqT/bY2HCTTlRrqAMiQ7NvMltH2Bq9ZFzlrlclvQFMiNRJdxiyOhH0MPzC8KGwmKBUfEcQy7RCEdFQnaVUFZs1iO7D2k1VANrLsd96xARIzlnzC418ztFe1/azz5bsv+z/bPjBUdkqza87oMuXhopoK5meV/4Uzo8B+H9Iy6iweoT9SAApke6iLAL1RBVcI/1u/qFzmRs2tw9K4Awv7juDHu5gZPpr7wo37+sQxV2lscaRzM8cC+6TkyTU5QsU3x/QGDh3MVHHiG8g/QQ/855kGnfAJe2+QBZxQjW8o7qqB+SwzZiMjAA02R7Jyog== 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=BqtZCLO4Y4zH4yfPX0F507i/zP5ywdVWLtna6KO07xQ=; b=U0tZL1RxvOKK/FiIJvF78aA8LvS6YMTOPd0sT4vfsqbK5ocMgl8+McrxH8zM5kAHS4uP2IZQe2w5VvysB0QgbFJz1lzoWAWcTnN7zQH6md7CjQ8PTe5GXfSP8eoe0dNbuZ1Ym/HqzYw9oFfvUgxYyXBF+y7RAwWrOnRUqfmFEW43iuVnsO6mjNnqq9DpHxsQTmGVkOCgfpbtxakirZDVvuK6TuWJqEibGugCWp9cWHfh2FI/2nEbSSSD6+ytprPi1BLRDNTZr7Wubn2KkDs4qYrJjhLNcR2iB4Wg5yI1ayeWLO0UenhjXS6hM3+xghxAoJMhR3c3TY6TXAQ1Mx6Esg== 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=BqtZCLO4Y4zH4yfPX0F507i/zP5ywdVWLtna6KO07xQ=; b=d7eEUcI7mp3cfJePkvXszvkbDO8/U4ingmUr1OQMHxyO/MFuXtWqraYftfqyDb2HB68EKA3BbXKhZEaVfwqdMxoxgxLo5wSK+FQ2vA/Mxi93iqMK1OrCRuFvpIqHIp9n1zhyR6UbPhPXklbDHjDm06h1owID9IraregClZv5Ojhmc0Vb9ZLHQbMbYjZ/hqdmL+ElMTk4E7JFiGVzzP8X5ZAAYTvltUYnPer2kc71G5rFh0vkrKbDbzeAAnFV1MZ7FJE5IBzna0QtR0+dzrk11NvniASWoilZ1mQ2/ZMVXMkSacEkgvXyo6MoElDl2Nd8kz2wfJ2ytZafcdzwqFQHeg== 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 MW4PR12MB7481.namprd12.prod.outlook.com (2603:10b6:303:212::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.19; Thu, 21 Dec 2023 21:35:08 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:35:08 +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 v22 13/20] net/mlx5e: NVMEoTCP, offload initialization Date: Thu, 21 Dec 2023 21:33:51 +0000 Message-Id: <20231221213358.105704-14-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO4P123CA0403.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:189::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_|MW4PR12MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: bdc35f4a-e6c7-43d6-7eee-08dc026cb3e1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: BNdoWra1X4mCj7agtt9mJwVvMGo8vvhZLcUxMpcG+tbtlL9ev3MeFVP7IOr7l9SJtU7VKFMLfpeVtdX45TfMXKSQZ/S5oVeLEON9gkqJcv/jwPxe0uSklMz64v4UTEtF3Ht7xt+oP8UyUZtLCQQAMOhFxbeP+TEpIBKdji3y2fK4heGYyV8+AGNgOdBn5VOzPPe8WsjICZW+uxvQqgHMZEyxT84nI7dScOdJLYFgGj42THK1wwQ/UdeIgraRS7SvRaeGVx0YxKrgZnFoXaCF3V0LMKJVik48Fe/PrfV8/jyvHdUty+tB72G3gAcYXz3EOyrsceYnBeluQ2sdNU8/sFy1or/8G0RwyXF7ZVmsp/HkcFTtCIh3Ns7uwGMdhESHGFLeJC2btPHa5x1P++9BdpT5blHZocqs2P68nK0TDfClFVtJU+SB6gCyHlo9DwJY8U51igjUiMRXBspwYZjrXclpZx/k2hDV0YV9bZJJgIk/+JaaWT9eajwDG/cY0/98+Uce5Uzwl7CXKW03otOnxlghgnEEppZu4UR/1aDMzEBV7FYf7UpE8V/CWfOAUDXst6+lJ3SwqCHqp99PCAY5bLjdNnjvV63B7y2gXK09CAc= 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)(136003)(346002)(396003)(39860400002)(366004)(376002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(66946007)(8676002)(8936002)(66556008)(478600001)(66476007)(83380400001)(316002)(6666004)(30864003)(7416002)(4326008)(6506007)(6512007)(6486002)(2906002)(66899024)(2616005)(107886003)(26005)(1076003)(41300700001)(36756003)(5660300002)(86362001)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Vi43DhR5SH0h9tcidp/l0DNJouhikoyK8g8EE1w4D2VrIscbGu6zvJ2BlPoEgYpN6nJEt5LOj2hN85quCOMLmeDxwBEPd/mvH/0zGpfuQCQ3IzIsQEL4lbdzyx9AqFrQCET1DFmgDSTLoXNr5sORn82uq3r2OFSeDUn9juygM0Dp5mElmCdDI3fnEFFSBE0eQNTb0FFAhHjvKiE/z0ecj1bDoxdwBsjncN994yAftl/e3qxgd7zin2eceYHNeLFKAf4m1cN+5T16hZYDCp1KXb+muBt1TZwdHM+REk7QZfumRbccHu0Lzw06SU6sea0DTQb3oW7xV558XCLyEs8ppPLpcyl1zc92sAN4sJw0Y3NKuUhN2fdNRn+4xIQyFrtWiaPDDAiIvc82Rbuk2Fc2i34d31tr/89O/w7aQRE5gMpQXh4bpgomamt9j2olnFUNm7PnoZ+gxw5RWLl8ykfSgbbDQmzzokQ2hcF4as2ZWY+v/FrqBX8uabVPatO3Q3UrRtc5qaBdAw8u1EApj0zEVtGWL2gAPcViaj8BTz8J6PlEQid97KTVOmpcQIuE27xAd720BgPfwUZfrDotjpS8pZs4cUa6KUdA1U8hoypeFhpttnmygR+1VHYv46y5EG/Zu0MtnmN7QuSDOkXJQ8U97y8rrjtPpInyCZGyoZp2N+1uh9w7fkFc64dzSdXE5fbStrQjTBAT875HfYUiebDXJQhwsh/0eIrfLAShCe5Eb/sM/bfonqF3sKap9R16wvcyOiovRKBsiVO2TnGFTqGJymxeqWuiulW3DWlYdtHyEZxn7jsZZlcCPXBzL6qGhM+cw4CIl3Hv0FOcPZScizHU0LE6d0Zw6Qw20kEGhq41EHpbcvU9VJCXdxT4oWiO6/lkg4jULjuZgqFWGWlBic6DI1LOdpwg3XAPKwXvYcNoWGForFTcmkdDqVywyCyVYqlIYzkF6YgisfvfHoXGMS7nWwVzdWSrs+7SQKrKvWyVbVbfmYfS8F7FSlhgzQc+EWc7aL5czBtYRm91U5OfrRGylosg75UD0v1GEFQNYbb8+EuwyDkzZeT/n3mLymWbUplUwOcfVTEzOd44ILPC6O+iohaROAmqRlJytAvkFgKgFs7EpgnPXyVCfHT555+o64kilrfguDUxrC8FvzOgKIA9N0i8I22UsNbumToPtyulr67uCIHn0tEzpUblKXRaDe/X+HU0qcrXgb7jIBfw8GQYEwTbg8kXuapog9VyT2Thj+7ePsJX5xlH7nt8OStu3ztbnuIVtyhV2Olo2fNSvTltxAaaxUQDASRjP39Whn3/KHdQXjyS903BdyWQkKShza7IruBg0zJKlne/G2FzrZw6PuiC86vGhT6IoLG4vkIgVHlFSP+vAWO7lQynKnkBibiteCEBjnTsXbgfHxLd44mB2x0PDdA/zp3V0mHWNbqDvPbVZUFKU7S2dzykLCp8lxgfxKEsGcUSYuaCPxRxM2nK0UFo7jcpnSosjDyPoouEEbgUQoC+7jNeyymrCCGzbb6cfZ+bytQJ1yfOeaa2Aw+tIQB2Bb2Tcmc5ntpgvO1PxS0TB9O0HozQ+Kow4kYoKqYL X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: bdc35f4a-e6c7-43d6-7eee-08dc026cb3e1 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:35:08.0228 (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: NbWvIs/5gYjx/BxGSS2mNd/eJZ0jbv7urcglT1UxQqJSl0lZMYKbwCYeOgzo5atSLH3gCVVdvAztQcLckmtA7g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7481 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 34be754f712c..577665af30c1 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h @@ -327,6 +327,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) @@ -936,6 +937,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 e097f336e1c4..21b7d8628dd3 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en/params.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en/params.c @@ -873,7 +873,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); } @@ -903,6 +904,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); @@ -1242,9 +1246,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 792a0ea544cd..fea15b4562c3 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) @@ -1934,6 +1935,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 5740772a7b10..1587ae90a893 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" @@ -4268,6 +4269,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; @@ -5021,6 +5029,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) @@ -5361,6 +5372,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), @@ -5381,6 +5396,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 bccf6e53556c..af3865578c8c 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 Thu Dec 21 21:33:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502666 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2050.outbound.protection.outlook.com [40.107.237.50]) (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 2768C77638 for ; Thu, 21 Dec 2023 21:35:15 +0000 (UTC) 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="ofIQQeZS" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=HmOeoZTmT1Xrm8HzeU4UZ2f+EzMFXx1DgilDftHon86d0IClRePqY28XorD8OcVsjW6Ut6S9Gfh2hx0TLLhR6t74NuUEiZt2UJj6Ze4MxrHQ+BwprucT4mq2M60fJbcuoZrHUeWO3d7E/0C5RCYz2EWhn4ZHRQC8azFsAJWbNvNONS+mUodY2tTItrIQ/uyWLssBs0XxhZ3u4DJ5n+rofWv9M07fRrazzdY1cBbkplcxBrJANj5liVYQvCks6ulBFLYR5OPhlLxzDxL1PdL+wilzJPW5V35Wu+czsPbS391JUrtBXHNpB/enNEgCsCpqfPcHo5EngC1vBX/y14ovsw== 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=QSlJKWtqu3nVNlF8gl88xZKOP7sI8eQm2zs2n0q1IXsH71SlfMEU3QcEfwD3zsWdevxl2cWBUwelxj0sIDFnmvKlsE7ca7ag7DtHCUsk379VBBA1xPyw0AND6ccsVGQZU3U3t+LEnnBZ1UsR8biZ3BmJ6YkyI/PBoTJoilvjiKaYygtRtTX+seb2u8AASW8J0to9EvEsdd3R5CoiS6DenQkGkRkz+pRZLvNL29zUdEZKo3k0skpVisP9aqf7nk6ZCRgVONMGPJYZtDs/97nUt4Y5IhVnGNdonjrUT82uFRs5N3zwd01HXFxDuBfqI2YuUKRtJ+k5edrO3dpLiIu5NQ== 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=ofIQQeZSyPIzMhEeG2hMbrrR/6fwJFWGTmFkxRY4kdjbhiZ3o/rI3bZvO8aUryid9RKWxSmrDMdIlGO210Y8EJRIeMuQQL7JD88d6ekp4naZTvNAnXA3SUelU2JC2IyYBkJH/zZlPrI7cq6fwNmsABexNaQx6JJI094aZpGAd6dyDtt1nFt3m8R48lsiMA9Jn4Y8JKySwDN5OrWUxyWpCi13tof24JVRyb3FOfJQVvcxUAe/2HerBUaclo4TY9ummTgmapvUkGDTpecZOEj6Y66/vmhD3lDvINazTmjXPglJQK0bWuVvnDBoisQgnE/ozKFLPkKd0wYfMPTFpn0JKw== 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 MW4PR12MB7481.namprd12.prod.outlook.com (2603:10b6:303:212::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.19; Thu, 21 Dec 2023 21:35:13 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:35:13 +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 v22 14/20] net/mlx5e: TCP flow steering for nvme-tcp acceleration Date: Thu, 21 Dec 2023 21:33:52 +0000 Message-Id: <20231221213358.105704-15-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO4P123CA0264.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:194::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_|MW4PR12MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: 890e73f4-4c5b-40ed-fa2f-08dc026cb6e5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: FCZk/HsMToerOpKAoiDzzkC8jQmZtmR81E0pUZeUwuPGQZxnLn0LUDd1CTYItJhphpIYZug5pRZagUlGJKKIFbFZMoK/kuu2ALf4YOgkdT0P22Z9VZOpggOxkfps4T3sDU4nGejnVsRVoEY/Eom20ytjYaNJc6a0xS+m4SnauSPU/JAct10cp/rnay7qK0WJERfP8pALN7roN4c0YtYX8NRmEN9nV1UdBgJ6AI1qG0lGAAHa2YirZYpzguG1owgmW1efHoVa0RRPRF8HtDwLaALU6FBNb4TbLPrGesLxedX61K9/cXZk2+TvQFbB7EuRAljZi27dVHB96PsF/uMCFN5xNXz1bZ0aNjjXB+qY4mxlB+MnD0RVTu1Pt20KEHPqVXW4noJ4XD52NMImnOsq6E9quyoL19OHbJnsb3075Tl5/QGTCTsY7+Og/JkA6yOVs/2DSbvy+WXYWH7Bm2DqflHJAGvTR3/HnFopjUFOAsKpUWLm9sc8F8RJYnfQVPntOrhy7Mi/pGmHQxa0fUdCF3pWdCc8LxmVO57vtj6f85scWdzLzkOxQaLc20KOU+KShsxMVG+FPXucVLzMJlQqKxZcFuvbuNzitLIJu/mG54U= 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)(136003)(346002)(396003)(39860400002)(366004)(376002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(66946007)(8676002)(8936002)(66556008)(478600001)(66476007)(83380400001)(316002)(6666004)(7416002)(4326008)(6506007)(6512007)(6486002)(2906002)(2616005)(107886003)(26005)(1076003)(41300700001)(36756003)(5660300002)(86362001)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Keh5Q+6sA+2UVd5bklJjaE7hKs1MngHj9XCqA8MZ6O4FOKbk54UvRDROIngnde06oc4kIA4If0tGohh/N4ndB2xaL/Am0zUQd9IvHmokDO1od1EbyjVdK31bCkEhqMgxFfvSq6X22KasIucAEF9XrP3TJHZKuvAcE5lSQl9Ba9fZrWJ+ZmoCLMjjVw7WayWWGhBuEcZv23HRbiK0uwGPtwuZwjyz2CIzvl1xWoLzgd9JejXj8y3VcWffgq3PaQ6hwq4uNKE/gY9fU2ETMxknQSh5aag5HRGRSlxWEMz1VJwWm8EI383RHyvQRbncrJyG181iHU3Y4p6N7OXkbrngyslWGmX8JK/u5vMJ6g5zgfimYRc+XCAJ+V53k2F8aQ1L6OJwQ0JZojs9u/wpOvOUZRU9Y25O/H2b1sL+pvFQHDR5zFPKfZov8JnEreXJ0/H2dEYng890n9KVe6wdXZqkDMsFA9oe37CcDCIKd7PNK2slRPN4LsNb86sCdqpVPnOEtrr620KyaR1TkyZjxT4QNcE6O0z+/fKDDezcgtd8WIKl7381xePhZ9XzD2uHbOyY5F4ZzjRRIuBOI3fummHUKcO+3DNXQDnynvkZUSClFKqec9CRWabzxHUfhmuCJANWR912kia4p7Qczokp0OsK7CrnjHcm0IoqMS69prXAwRXVRCgW0SjAUo8LBtUyYtYwOOYJB7+jeFmHRUQW5uh+rZ2al0c/1C7XODaJ/P05PGd4zGpNjjeiyK0MeqNQxJ1MEQLoAkjkq2ceGUiJm+5pDhdgFG13nUgXddI0I+8Kz3h5JA2EaREFNDDosoHGZmdi0H94kYabQKfR6twuGBhl+fYrB8doiwlWpFD6ZRUejjnGlo2X8CyETINs2F/Z6UDMr9GIPLOLkn2QYOOr1Lb9+PkKycjHwrPCPALM207ouWpLNEjIyW7ccvyNzZ1hC3zAH7aaZKQwEyfi0m2icDw56ZnqbJpf6A/kNIoKh5hV8ZxQ8Io1E7mI4eeP0XHunydsln05v3hCRj0xoczZx/yxR6JMQbWjP2SvKlWfm4dEKE63PMiGN2vFbvkiaGWJ9WpuvOW4iY7zSejhv8hxnnzClz5pzEgOl6uJAYZkYiHRwynf+KHLCKnK6Ra3itubD0tDemXpA7MmMAZ1145vmyLCsJkUEGjKYm5e3v2k1Uj18RK4MBwH6mwL2KkJELh948TcaK13rbqbSzjnl03VAP4qVjwqvgxlhEu18zzxgexcgkp+PbAY3P8i0cIl/AbmUDGmmmx2Gi3MRH23qLAcLhuSztmDvzVkeIuIGf71T7cd9ZiNyUUjkGt9i4cpY/dbeAPeDhvRn6FkkHwMROmxL9OCx+cviB45nlbHQYA5S/BR3w8e1oMpJTbJEKgYanY8lVrP8H9eJKZ6m2w6wWMdoly1Eo12MakeWvWLNA0v53kRXE6lLUnSF+ONS83GuSeoTdIHPm8SE3PBlFwBSD4idLilAdM9swCj8sKUdnOq1hi6TsDHLYcyMG7NJCT+l06SDH16q1r+mfx6MwIvO0T8PFNr8zBffUS7lkhVrkU29D/zz3ZTRzZwQK0f+KlwUZ0viFns X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 890e73f4-4c5b-40ed-fa2f-08dc026cb6e5 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:35:12.9348 (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: N3/EnIZhm/9ZWIWWwbLwlwhCMVcX9BgoBilrwIQPVcfASsooJZMgG8qtdVibWUk4W4ZApT1aFxD40asYlSOwwA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7481 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 Thu Dec 21 21:33:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502667 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2069.outbound.protection.outlook.com [40.107.237.69]) (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 D649B77653 for ; Thu, 21 Dec 2023 21:35:20 +0000 (UTC) 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="PwmRb+cj" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OuQZ2hS6i/eN5LKI3IZGW5eWMK2+nfMuTMEYZudr6gMtiwI5jmYuAxZ7BONzfKMBv4dZ5VikznUyZJWEZNy+Kg2/QnrUZ4RT8PFvoanFBP5YKyzcwy3gCVGbsKJD4rYE4aF1Vc94HgYbOvy3K5sUovWatm8T/4Nptaay+x35qzNF9MRT1LH9rH69Hl73f/MhNsvjKMQ+aHe8gYv3ZDzxiozhnAz7k3DJxRB6oBa3aA2UGNvqvNOGW2xr8izYsNqgULZufvSZFsASthIhP1e3AIlW08UuaX6M2OO/lnoJM7EOeDKBZOGvcmT/jqh6RCdLN4wBYsRY81mA8Pvhxvz6Vw== 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=9f9wo7q1N4LBRai4Nj2wbo6zIznzFZVgTLxXBbGDdbI=; b=VElQLViO3wJoUjJQOX3bARE+JKR2IMzjJHDpBvGBWBuDbbly8eIp+Q52XLZwCR3W3e3OVK6g6KPtFLVQ5MXo18vOEtyFJ2iTW3GkxGlZx4uI0B6vAnwVIlRk507C5rUqnZkq5gLlqDsrsUeA60ZQRBjBk3DVmcpm8CGR5FYG1Ja46lkNbPrWZhVSozVa8n/kJzAyd2w4xJvnDMSf0OeVZQtVnOGE5vqFy3S1XbPstwUlO4QZW/g1+6B9lwvja5G15ODUZ08/pNCMmtTTIaxCdp/p6U7LVZecE6KdoxRsLv3qMph5ucKcQuWHvWCZBhW2FkBzsVGlbtkjTXP30oqiaQ== 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=9f9wo7q1N4LBRai4Nj2wbo6zIznzFZVgTLxXBbGDdbI=; b=PwmRb+cjGXUE+2Paxrud4P8JRKHC/o+L2UHuH+eiyrbAKANEWHCrgm30fqLPEKEszmdfROIc8ansawnQ8ghzBkq6SCT7d8x4Nkaumfgah4WsOwkS6bRyTRnMMhVAY9xz+RJeW7YCDDWtnXkANL4UVG5g7OYGU/bo7ny+RQu/zgeAo9N0/KuxkgPA/EgHeGyyBo96z/SIbmS43u7315hXp7n7+coYwhDiXkXPOqemTZ+5ThFUD16kywyzMvcOTNEs3/Env83PXHKS4OTTAj6RojUG0d2s7uCjCy7XEiFtLkyqZSJ8dJygbap7Th5lUpIGjxVwWZdlQBxse2f8WyVwHw== 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 MW4PR12MB7481.namprd12.prod.outlook.com (2603:10b6:303:212::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.19; Thu, 21 Dec 2023 21:35:17 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:35:17 +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 v22 15/20] net/mlx5e: NVMEoTCP, use KLM UMRs for buffer registration Date: Thu, 21 Dec 2023 21:33:53 +0000 Message-Id: <20231221213358.105704-16-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO3P265CA0029.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:387::7) 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_|MW4PR12MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: ef126959-ba9d-44ca-9e33-08dc026cb9d2 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: OAmis2khyLakTgW6CKi5bgLzJNVshRzsGMrjTZwjdJoJJkQXaRXMNd3+hvcpORLDniLAEDWyqYqKREQBe7Rud1JNu/mYmKnCRS4MBg75NFbQRPIsqNtuBWvAwpaFKTCjYnDSHuZQB+uTSogcUSPPBxiXoDjjyNiorj0Q8ZHLHOjL8uOOu1mIiGJCMqie3EWyo2AOdAAgVMAViJ4ptbvKYFnLPaSFdbP785I0Fgeq4X75jKAW126wPZRlP9w9GH75Ps8hW1CSbHvLSK37ho9GMgvoHQtfFdjFCIeysxoMEvxK2cvmVPpYYthsVn+ZFFLJAbPRlEIEv0fIOwVArdK5Sjaf6SM1gg2OSdcvt0kruioOE9lDzgQnUp64+RbAqPq5Nx+D+yKIQzqAkpobQJdPmx06xi9vsfYlh/FXbxk5bm8MscnMFaDX2OhslN0keqKP10WRYyqft/OB/BP5+P3PjJlyPCCXvToTbev2IfocchPh8avVRrWnF+KXKOhBl4ofDWde78+THW2RguQAklDGVsEV7sWbzKMhtdc7dtG4MdcycjhhFAL10TrQCEbRWbIlEvkUUf2DXF7st0Wl4ZY1a56imyW79c8PshGb68jce9w= 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)(136003)(346002)(396003)(39860400002)(366004)(376002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(66946007)(8676002)(8936002)(66556008)(478600001)(66476007)(83380400001)(316002)(6666004)(7416002)(4326008)(6506007)(6512007)(6486002)(2906002)(2616005)(107886003)(26005)(1076003)(41300700001)(36756003)(5660300002)(86362001)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: hOe9z2x08Mz+LnWiUqdywrE8i8OI9qOVBobSRE9v/H6skyHQ4+i7Z7HyRAcHn/TKZ5MEocGQI3IBDf9Qr89ugSQyDCMF3JIBqMCEFcqlLldWBcfDCkJHPASdqpma+GE2tA35D4gBh1uJL1rDMr6A92QAdJsgx2y2jc9RxBYtkXI5WsSljUoeW/n35GRUTSvHLg2+JGOiTygmEbLQ6b7xJAINIh0MMv5QY755tyaDZr/Btd6/oZxgaOxHDTNYz+4ftHNkwGhg+JGA5xex45y4HLdApQtmp+khqrFcTGFgmIW8+bO5Q0xnyvzhP3YGnc6yX/DwfDX15zR1hIbooDo38qf7iPcmDM6PluxDxXZyWbjBrQVF9MffFxQWS56+rlmdY7v+B1XM6zuQpQM9ZZ3cPxiV8XBc4XL936LVGeuEmUotUtX7KGdc3NvrLaND2jNLKiNeo0iPYzpvOdte0mjQxtdFLRFDmXaI5+IK2RBFtXNMus93npXGdaYoOWHCjYkLFb84B4a0/YTVrC57KhqT2EuGmQCWshFCweuiHlk2C9GezYajMk5+8gyhxd8KJKbwiOvpEkV4teIGE8dwNQe7J6XxcJfzGVeUQ9IuZySibA+gGd5hLD4Wb8xvjKhSUwnkd5iTzIrztWbTNwmpJjM6GTezX3XywHoFfrPErYxceI5xVmXb1nQvPH8vMxOfCIvdATm7JKn/uswCtowR6/7ba6UF39F+Y9OrWPLCPf0W3EkYaA2tUk/tPF8ImajUo8m02tjzqIQ/vk0p9hQh7FQn5pES9XBrCHsyNVl1Ia/nUs7jGd+OUx6/G8c/sYI+4WHjIimn1z1bbYUOQ0OwTl9HaHjwkBMIsbaih2n83nWKsbnoLEodWuYSgVRyvWqyW25bjM0eaKcV/UHHJ8W2VRc1dNg/JrZqFQ/fSMtQggZGMSK1LmQ84oGCKXSsyso1/016io9FKrRuamIx5AN/djDVenILsxuBfU3hGs7rCKIEbZnPL+N3EG7NmZSVyokmdfJb7qIVtvZct5DW+ChOAtMw3kJTUvet8cytkJGAg4g2FLwv6h5URgxY1faWAFCfjIH8KXKFHflDqdWFFHQRQYv3WXFt4GpR3Z97FXC3BUxxs6T28p9We3u6EsP31ewk03g3PZExVw2X7pYUNM1W7fj3mEkaPwKPPFbMuMQkZiER4SCKKhphMGOH4qQcLJMAY8MzD9hIOhRojwNuK4K8Jdz+URSkKE90VAqqyGsxFGvMV51wOthsyqhe+EaoxjNsb4kFO7dXtO3dZqSlEbtLsRDirg70peW9bMw2E39n8SL8se8cQsv6BiXVii8Drekj4rdvhJzLw5CHXxCMxP1w7sraJ8f+1G+2W+qKqSPg4YlAie+RtOBGKRz6o9gQbyhxyx0sMXYT9GeTnDKP6ucX/GKwJvvPhmkAuQKZbb8AnrO2LM7clluIOURexMs8+UrWDBQl67rL1nwsu7AoutcgIrCNNCnyfqmm0E2yCvz6CsATPo9TKLbTAXSK5DKlrJWHHUsvihKjQ9qUnLVW5Yp9Ad1i++GQkm5MMMlB3X4QWCiJDukDRH4HBc0wrs4RA6dhO0go X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: ef126959-ba9d-44ca-9e33-08dc026cb9d2 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:35:17.8429 (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: FpNNi6c4myKI6mYXtoBX9fdYu4D0DYuRHV7bXwQwBETc2v9jw8btLHoFSUiCeJHN1+LN+43tolDP1fi6/0VcQg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7481 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 addf8905fc35..204a8137c1a0 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 Thu Dec 21 21:33:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502668 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2051.outbound.protection.outlook.com [40.107.237.51]) (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 0434376DCB for ; Thu, 21 Dec 2023 21:35:26 +0000 (UTC) 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="MQt6XdPa" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QIm7iAmgxIqdQWFQo2DJV4/8kXFKF2nRk+OYtF5MFCnX98h316rZg47zmcIpNZnAy1AlShbLn1U+SGAgx5SjQYzfQD+OoE+HUEj0Buv0TDSC8NuD1GwjYUTduUjsa93wE6qNIjhlbH6d6kBzMM6W8RDOhWQKz3QuMqK3O6BTMpSPl/fQxvepEGA8wiyNsoajYHVqN6ycKn5axzq68mZbc3XQefTnChME2CmAbS+vwVkIPP4MXOkZ14e9lIV1gcMHKNosB70go6y9tI7TbcXuU7vRdKmAwDyrxJvIDMrP1HdTaeO83vlizeELyhWgZl9rihDOVu4+uzB/OT7j/qq14w== 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=HugCKPtgXHLbH2/yncijtAP2xIBriP2zTFzxHGnuWHg=; b=gCmlIj31XGxyN0SsTjimPQrvA+/pNBCgnb79UiSO3mYCVX/CDgpMIAobH8u5k1FKgBhLCazZRdNnAEtJtRgmejxoYbCHinn/8OdXjFtl5GyEomoXiyfUl5/udvlyiQvExnU5ZmBI0QbyPPSJAWVFfwXzU+wGDzicutAo3xbrnxG5NT/so0ddLewGz7cwDGnI88I45NRJ7epN2ewx/5oWUx5ps5o7rGBdd1bKcNCX+R1C84Y8wrl2t+SoPEZ6Kb4NtrD4RWE5zIVxhss/FhKcj9bU+IF17oq2Dwl9+nhoWQBRe/hiugkvEG1gnV6BvaPy7adaSeuiC46YKlBvBL2HQw== 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=HugCKPtgXHLbH2/yncijtAP2xIBriP2zTFzxHGnuWHg=; b=MQt6XdPalIXCof7TlamM1UWWHlltFqDLVwthvIIYr0bsryNS4kUCJBvyW0DV2OYCqZiMQYw8G11Bt4y/WnLynY6CIdbqziIeltzNU+ec2aCfQIMHff8FyB7/syEWqk20PqPhVHjwm0slly1RgSVD50Pogvy+yBe1Rrnmt2abfZZbIW/RXrdZrrRx1Z7CqjreGNVlqpjHKytQcjgXM13Wn3VEBoz4cTuPvKyjDMXB6YLJajWUEvDVf+9lYvGoZQrVzkkzYLPa4rspB9mI3Pl3OPxpiNfjgyY2VLbxO4jVtc50hs/rmUsfgnYuiP4Thv9qcdEXchit/UqPKAFULY4TJQ== 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 MW4PR12MB7481.namprd12.prod.outlook.com (2603:10b6:303:212::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.19; Thu, 21 Dec 2023 21:35:23 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:35:23 +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 v22 16/20] net/mlx5e: NVMEoTCP, queue init/teardown Date: Thu, 21 Dec 2023 21:33:54 +0000 Message-Id: <20231221213358.105704-17-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO4P265CA0292.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:38f::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_|MW4PR12MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: f5455ea5-bf39-48b1-5269-08dc026cbd10 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 1Iybg+vFHI+htfxUbp+NQa/T42JMVgwsAaBcLPjpPs9m+oePfPQ8WttmBDmP/p5DQG5zCKcWf+/iLP5Xi3jFxnUjmpqMldjYobgsvsBoUvw4PB57hP/PcbD5gomFoQJz/kZ7NdXLpynGSXk7CkL0wkHxxi2QWZD6imWVolKfqs0+59Coq6S0Xi6pVTd0AjkXLSlZvtla98OCBlUgm8NZ/kYQIyvhV97g2oegieR0+DGJyoFd0j9QhlL49gjYkd6+B6Eawq/b61OsxLOeWFCjIosKGlC593W/kP2pt0bLR3qCazLPyE6voS3bC99aU49Q4XSQblUE8jtHp+kQ7K1GN8LA/uAs+qchbcQK1UI8hckjua4yXIpnCu6zaHkCRJLnNNrcV9Xi8zNuTHKUj7nxAx92SaGv4LNyEKAmY52TnPfKw9TSM7En6uksP55eB3ZjqJIQjXd+e/po8QWZ6DPj4KZLy+QdDcsqvuAXGpq1KIL4E1Q3bTBXnkIeyXAHAi0HbRqzwYex0H3gcUy1iWE4JRbqgokCQwab3QMAXJXEi5Y5yqj3Bn/aHUfmtITcWV2pF81El6DnP0IOxFgl7DHQDWtb6xmD/xx8AMzfut4aKjh09T1QwVrMT1EtJDBsEpHeVjrfM8+HBaqpheldsUF4anHouXlYjjTpqrzZseK/7pU= 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)(136003)(346002)(396003)(39860400002)(366004)(376002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(66946007)(8676002)(8936002)(66556008)(478600001)(66476007)(83380400001)(316002)(6666004)(30864003)(7416002)(4326008)(6506007)(6512007)(6486002)(2906002)(66899024)(2616005)(107886003)(26005)(1076003)(41300700001)(36756003)(5660300002)(86362001)(38100700002)(309714004);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 16CV96Cz8+IJhJDjjOjC7QvcN+zWXG64dUipTIRrZcdZ4ViJyYowwiAXd3FOcmK+cohFwFaHLsFoq3BRgMjwYT7aFy9jidiFOrFsjYSrS7JMmZ0mPBGjRFHukxJYJY+4ws0uykXYb458pj+3g9q+igMBSi4dfDxZrf1RW1TT5l0KVAKxT83olLMXZhwwtDDoV0iTZlzMPb6ZojYPhw9b7k/fe7LJpwGPchmsz/u0bTXwCPXzW0RxmMIjtCI6WaR3VpgT3G2bfS0OPyUBmyAbXohlUAD+TLLLJSWT9EgcAETazO8hhXApM6dHTozl/QD3J0qwqS2q0EqJDBJ8cXBo/0ozxG6coKMvAZTevGmgwqzcQYJXQwdGGc2ys9m4qbzw+oJ07uRBCYmiHpcxL5I3WF33itSuNe9fqwG9+oBw1N5IwuMwx7145nJYBWLXsqjVvPY5HiX4oXb/INZLVKc+pbbqLSDDfahYzo+pfbUMbTfybs6mbkC8vajyAX7p4AwIGVVfnyfR+lxLnHpEIghAWRVZ3W+g+0iM2e89t7kBbeaIfBqPRApnFp0mStu3zfLod7NjwxzPZp6GyKK2Ojq3PwFbg4QrOK8CHJT5ki7SShhJpm1jkwkU3bo0IXteJ67KId3sm26tFAJ92MtMvPw7mrMxNKygq7wAFPgxiyz131hgSpxfuLymhI+oAJ4kXeDTolzgChn3S4hfTMggcQGbIiD6mtPIxAsBtSgmBNXBHaZGZ1yQC5nsSfTmFr5A+RAhbWb3ogYSte/fTdjUsnLp2mWnFaFXA5f4WMC1DMDhrzd85C6tNZq144Zc0xpemyHjtUcce+tzikOM1UeFvRxo/Y1h1plMAioQxLMqkzt7SdwUh0rp5VROiXpeB/PSXP/atpHUeZYyUerYY2noDuFkRzdVr99R2aKoOBEtprov63BubS5CVyLt7p7YKNiYt05D+eQH9DUcRAERnMX9cugnwBE3lfn7KLD3xMlDkmRtOXRfalpDOKfM+zbmZIbY572LUdZzu5xfGZNHUk6cjyEBKY5CODxFAn2fY3q+ozH3iDJCYevq9IsXvAufPsA/oMm2YkVY73Y8IQ2CbO476lBrp/7+kOdFYb5XO3ohc0I8e3EVw5wwYPAHYeQ0lr0D/pUupcRyuFdyTAGQ8/gYBI+akZijRM1VLSw5IK4eC2BZgj8iBjzGzGkbsxOWuhDIYKY7odDNQ3/K4KBTxFavlcLEzKcmdO7mIU9UvpEn4Lix18L51jfpvJHD79K5+X+2sxQ/pUz8888lIExEZNE6Ni5EOA/dnoe7XptIGTWwzG6KsY5SctvgGNoyZmo0Uz+/gViUI/vW/2ADlVbQGrI2ILBb7+5zHWYpTo4C4HWVqNH2dRpaCc27CDMhcSnytAAeXcQtl3kWQF1dwq8GtAJujQsCrxsb5qwSrICtmVTSzpUZr6bSBG1VNhdVLWfHIy9BojU+E+FP0Y8La3hiMf49rtqtZeQWIPX4niWnZAZXV6Sm6pF6MjlSyFiBLL5diy2j0kjUUCAsMw/miSQSDE/lmLRDRGkIciaI0RdvNOZFtca3uMZM/Qit9JN15/tE6LxNzU0N X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f5455ea5-bf39-48b1-5269-08dc026cbd10 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:35:23.4960 (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: BXLts8l+D+DW9zwXDcV//e3eVC/5Glvtv6jDIdc/VLHe5jEpIOp6jN5HHdYTgioGT7uzcj0K0Ud+cwiNslD/bg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7481 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 577665af30c1..4ccb347eb35b 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en.h +++ b/drivers/net/ethernet/mellanox/mlx5/core/en.h @@ -1037,6 +1037,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..56969fe337e7 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, 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 1587ae90a893..31fbc1ed4a82 100644 --- a/drivers/net/ethernet/mellanox/mlx5/core/en_main.c +++ b/drivers/net/ethernet/mellanox/mlx5/core/en_main.c @@ -1853,9 +1853,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; @@ -1899,7 +1899,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 204a8137c1a0..1ed206b9d189 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 Thu Dec 21 21:33:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502669 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2056.outbound.protection.outlook.com [40.107.237.56]) (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 5D14D76DD6 for ; Thu, 21 Dec 2023 21:35:31 +0000 (UTC) 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="MfKkDqu6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PRTq9+MFgLgdDCFclVjrmnYTVaFoT94o2co9uH1GCUD3wJsms5/8JctQMSuHl852uh66/kTeM0RBTs96AVwciNdcPO8RZQ0nXGe+JcDG1ZGsPTdW+Swwols6NyLjo2vrMTX80CG8+STpm658R2EL7n6fA1ID08HDVbkeN8ryc9AM255msk+xUtTXOSS6sfTEGF2e/Wp+usBa5kN0BzsWfjaoDfB1ZKtvVl7Zi2918beYjzYvVFeL4ykwpbsvUIDwtF7UUPlnQbtgIWkxC9N1AaBCZeFvYw9qDJPEv1S3kGBtxyEmB5ztLbYo7Tv9szG5jXnAp5TlGNIMp02nMPSnLQ== 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=Pvb7MfjxhflAFlTyS3xrsn3CQoP0HBbIVNA+ozK2lQ8=; b=k/3aER4GmN2uEAsx7D3C9tirRxlZLv87m/xxL3se50YpI1BAtggow811OvwEa40Jy5zrfjcy0EpNvYDoda3ju6YuZnBS+mfvh0hhZA3HpZ425Ey5BmXx+raxfbfczyAzbzy5Yh0lPZbOYPJwhYiTnSMmOSszPqUhCAcmSB5ATy3vewPphIRwcsGJM3FT4FjICHv7ZuVKGuQLtfPjvIxmss3v1JX/sf2lnQAKel7MTO4DD3AdxjZLW3jk8p54RK16hqIybZoUtOb335PfynoqcPP2bXq9pLkZo0Ssd8K1rQtlFK2xHTAztLxo4lysv6WjfIUWhMCm6gfQYVR6G3wW3Q== 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=Pvb7MfjxhflAFlTyS3xrsn3CQoP0HBbIVNA+ozK2lQ8=; b=MfKkDqu6LEQdhxnXMpr5MmSM1BseM/v/HRY7K0NVfOA4w9Tn428wntI3aaQmmVJ7Jm1wInjPKI4lQUp36a0P8OkP+WnDkOZSkysRXOV/Wh6Ub33s7n+s3m2WvQm1syaTdUp9ENi/e57/CLm4vbxbDVf9Fz8KKgAGyTCgq5F2YKyf4kVskXtjczEUvo/MYVLrgcF/X6vvIzoLFK2J3ZHOkhWN3QrhErEkan36mtKdfi8VxLu4x0ytcEPkMXM1C2kc8WP2EoZDsJqJc7oBjimXERyyru9R3veNrgQqa+w5T3NCRcjNxFXYwy8HrgcNBX0hDYK3W9o08a32VDYqqQK7oA== 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 MW4PR12MB7481.namprd12.prod.outlook.com (2603:10b6:303:212::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.19; Thu, 21 Dec 2023 21:35:28 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:35:28 +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 v22 17/20] net/mlx5e: NVMEoTCP, ddp setup and resync Date: Thu, 21 Dec 2023 21:33:55 +0000 Message-Id: <20231221213358.105704-18-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO4P123CA0436.GBRP123.PROD.OUTLOOK.COM (2603:10a6:600:1a9::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_|MW4PR12MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: 618b3db9-b024-4e03-b99c-08dc026cc020 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2qhqM64FksVde2EQfUP0zC0N+8POCrXmORVi83Fbl3UyqktIBTN9TXq1vbuyghvtDkRgILZM+oGi0O0yMarDCf5ZNNf1xmg/Xg3yKeRfPdKXx4z9tquY/ZumO2WcvhbaAI0ZiwfBY4pGe/qk49jsPOrwWKDx+85rYAcpJ5fR99y85MNEuLHoYcNbBB2ssp9KRn659tZxcNR8jktvNq53frbMXWKolM/Sc6VxFwFWJNTI2kD7TAjjcTxcz9xxuVpnvmaCsedbC0U9uRT8288SB043rV2CWHxqG5DcsKEPc3B9OqW95pA35SDFIBRCoKvujE/QtpvZ3LCZGS3h7aGw4VoVj4e2XMnC8r8zs9wfSUPMmAvMSlRIHwe5JGvkjdv87gNCb3Yj4/exql65jLel9Ld2yXKtU6kzQmb5knIzNUfFacJ6G52LpXX2d9EbA2Eq70hotChFuOl+S7GJ3tbxJ4Y6r9OuLHI6Rol13LCyqIKcGhV721g8vNyEtAlcZmrFmQcayMMZxg3AmnpEQnDHzdq5bAMkr7Yy7wqJg3/lunnlFSCAaNSiV1fQO1wUeu6rE35NhnGSWrg/MmZoEbsVfgeAGDKBgZzVQcBY7CbYnOM= 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)(136003)(346002)(396003)(39860400002)(366004)(376002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(66946007)(8676002)(8936002)(66556008)(478600001)(66476007)(83380400001)(316002)(6666004)(7416002)(4326008)(6506007)(6512007)(6486002)(2906002)(2616005)(107886003)(26005)(1076003)(41300700001)(36756003)(5660300002)(86362001)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /sMPbQPzEs1xGgMwfDUgwCekpMgvlU3YEHy+wQvgX28/73efokqeZFc/lW/SeimU36fbKPpTElREHOBSXWFYqXyTwpXa3KGqQ0LrGioYvIIe0OIS0GoX5KGka/qIgOaKXr23DI1QxRZFH9eDMUxNsdGwBh8r1jBNIBp83Ww78dDs28yni/cm5PgAQwd3SjSdOpN9D4mqx4iKRdkN5l0NOdq1DfSU1WjuECtKMkHExjQNeIaqyz2r5cpg2DHiWk+oRhqMOixb7ymHRWgdi41nihR8SN7coKwyAcxP+82Ru6twCNxe15gveCPwg8x9DmSaPTJ06AoR230EDKTZu8uMxJfRlaBc4oaqNGflHdpKMnlxlS81UyBkg50V22MMYsELsHFtnsAh+tfy2y9h3i+EI8RVCabz9jS4rb3l+f+Tc2mo+q4Z55tm0Fn74jiiC/7kBzYVMvUyentfLVAWOYDKlbTtJH356hZopC8tOw+Sa11crr4Acwuzqfky2BuHEas8aGUxFnHwaag7g3kRInzzBWc9OCGy8Iyo05dRzbUSNbwYY1kqsc19rch4atITs/lMHYyVsO6bb8O16aExrq6LuFUo8qMisQCYk5imXaKThblxV+cj+H2/M7PcLmT805VyaVEc/nmkKD36odxg75FMBpK9Unhb4HlPcl/dRtuWK0TrpWNrT+3xoNyqPrPHOO0i0uTYvqq5t8H85ZlL2KdfLdUk7HfALZU7RrwDmx92DzyhM7hR39CFKe2iXa+WYK3gbnpbg6wJVQTNl7fZWI1tg5Zffk5nJrAH7FJeDAAH+yMg60Z1kTgzHbSCEXvUNb45OqQPkUiLiMI78wbXVtcnLmeGFPNzWcqohlJtEblsDgv2WI+b4CoU4NZB7i8l+Eu/nzhdW5KmdWv7Qld2UwVVbIqCkAbZPC34ZrsZFPVAHejspTqbZbe0Wu1nruhDdtMDTDbeebivjp2qLnTVZsyIDTn0d6DVJndE/isVKVPcifp+kYRLbAVZa4lueypvcV4blL0/BhmE6+z0Mbf2Joa2R2OkUjFkFUDzpMOxQivhEzk8Jtm3g7Btm2SmjrDMXlS/uiC/+64f/P3RiJIxQ/IZ2jOkbRvQeubvB8pxDAnUiEr0YKG/I97I7KxBIJUTNdn/0prjsRU+3x8xs9mMqIOW18Y91UyrMe/zdGuUObXtfs5z+Y9cKoXbDRS+ksQFYzHJlGNdY3fOjHbPMErPwuA6M6Z2x8X2YL5ThEqbYzF0oB/KT0nMA/+C3c6h6Ti2FUsxshX0u6pATKlB7oNWeAAttSpbbG+wib91BlmxL4jMvID4qq8DFL9jRd7As88glKpIHwnflcCbwW9XxjYqkDJYf4H6yXY4CZ2CneY5XYZG9Dgs++iDNGfnXUHcRPU+6cXf8LKoasU9wcVXfOPPtYSTDZ0a9tgScKB53g461pDGqtOzWjtTSMvkompdaKn2bceM+S8hbQ5d46MBXY1wBfHPKfBKVezMwn0MV2WcqSPQpJn6BEvIqqK3N6Vr8xtbAIWQ6i6+cTvDc67sqJkWmN9Hb1klswE/f3mpOxuZ3v4agxNRwJIDUYCg7dSBDgulQrex X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 618b3db9-b024-4e03-b99c-08dc026cc020 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:35:28.4853 (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: wit0tarhBKq9onkCt37zVnvS5G9OaDdQQ8EnBKsp1Arbv7218ClAuQG8uFChuoifk/UvbnlWOfuw9S9F8t3gjg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7481 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 56969fe337e7..8644021b8996 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 Thu Dec 21 21:33:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502670 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2074.outbound.protection.outlook.com [40.107.237.74]) (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 CD55463501 for ; Thu, 21 Dec 2023 21:35:36 +0000 (UTC) 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="bEiI4zNX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=e/6gqW4RghTQF/1dogyAiHeWeTP/+xGJqvCkxECmUJBv0Tv0mXLFLS4mwgSwzch4DL0V7jPmm4/gI+CtW6HGPch/qr2iGAHfdylZ6Jou8+dJ3e7FlZgC5sf5eIjXdH11WWBlBG2LCgPBSyGuUmK997sMrZqXmkKzLZRqI1ZQ2sgWoea4ADiWG8RGAhMC31E6Da9sDDRYo8Z7707Z2XLDCujWluiD5aC0xvdbz8dbhrbyf5lU3ObxC9qVDlAnLCRgeeIxLQ9YC94xhbsLzg+Y7KBF+FN0OT91f20tl9ehujC1b7kbntYztTa1rH3IQ0Ny5XNn2pjVTDILQKZEER46dQ== 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=QOlZDxSyHsLEZF97yXuUaM5RscokUivVILbVgtgH0yI=; b=gLiVPK2/YHr/YyUPvQAh3Lvnvf9chKbNNMLMkyCnn4KxCvqg7qrTHiiHY+LpM6LzPQH+PucJ0PspPTKUOsBAbvPq17j2UkfX823Lqaazj4DyqZDDEOQeWR9qsZ7QMkkAXcNonPBbuGl34bvBobixnbLvsxhx6/uvNtaMLugphEWY1XR84YP6TCV23OUHFHdPPkaYPxqLcVdttmdO+sTbrMTxGv/LVruOSq/eGIpqaPDSRFQLPAUj1FsXuHaDa76AbHSI95Y0HQKRqs41yVPMQ9F1qZ5w+1Osfj3zheyswoiSQV1bnQ2jiSBr4LgE9JK59/ZtLDudrHN3yJu4dprEXg== 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=QOlZDxSyHsLEZF97yXuUaM5RscokUivVILbVgtgH0yI=; b=bEiI4zNXPxCpWiBkRbWrUEnRWjTI2k3meziH1wwGQl7w6A+I+2SJluoSu/i/ne5BfrEVoyHtQv8tJ5CA+z8KX0QZL1K79mmXkDpvbJjlMiAG58NAHfxYsOeBqi1lqrjHDJ0zo3zs0cLOxP91p6+/BjFnwcma4bB/9ampr+mjzlYuPHe+B+TE/uhmAf10GJr26X0fvtUXAyc/P3z1HeivNqCcaTGVps9oNT9TldJCB5IijLm9cE3OpBLShLsyBGDZvkyzFFQge4EebWrrQ9ezQApFMPGp4FMTlcIvdgd3wqCFFDpSfG22Wla272hmL3Rb7psiHz7SwDVe3aZeyyf2dA== 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 MW4PR12MB7481.namprd12.prod.outlook.com (2603:10b6:303:212::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.19; Thu, 21 Dec 2023 21:35:34 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:35:33 +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 v22 18/20] net/mlx5e: NVMEoTCP, async ddp invalidation Date: Thu, 21 Dec 2023 21:33:56 +0000 Message-Id: <20231221213358.105704-19-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO4P265CA0151.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:2c7::6) 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_|MW4PR12MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: e0923194-4a7f-40aa-94c2-08dc026cc365 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: WvEyQYaRBjhx2/RdJRGTq6AM4PraLacGhUdJSCxp3ryxSsWDJpxukktwqrXFnyE6xrwLD00GUbcHk7DEfYg+9jQciySzIuV6Tl2GFrflSYthidXzUoqXaxGQQdUNpuXlXZXUWi1XhbFyyfiKVhNUbBQLOWm1JgoKuPJDosoPzIKlAMczzJikf5ukiNlIWBotPL2AWf48cYwNxnbXdgvNn4dThQdh9ulEw9d1QzeoTcqzHm9hlhT/RirCm+83I0/qvRcG45ut96XZM+QuIPdc/Orpn0WzxSaemYxEVSJfaiAVjLWB3Jszim+U1HW92Ib/3oCujuhthhZxgvOPJ6d1cO5vZ34lNuJC/LiXVlB6LcV2kw+1UZAK/x+BsRgQ/VuXzNmKy7o68PICMgTf3bVIxnRFWLXzW9v8svy/cppKDNIK+y8cIzgXr4w5qY7pOd1V5iiRUAUYhvX+s4+xVXxEQHPSTSeD7bKQ8CPrtBDevIbBUZIfoGwUtSDkm1FOedbu40qFidgpAF5iVTkZOqrWv2fl/bEQyG1BD5piK62U4Sh5aNkB+Y/YzE0/6U4/rIbTaGSjnUKFpvYQAeMLHSCYMFVyQ+bCrFiW+qxwZDtrzOM= 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)(136003)(346002)(396003)(39860400002)(366004)(376002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(66946007)(8676002)(8936002)(66556008)(478600001)(66476007)(83380400001)(316002)(6666004)(7416002)(4326008)(6506007)(6512007)(6486002)(2906002)(2616005)(107886003)(26005)(1076003)(41300700001)(36756003)(5660300002)(86362001)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: AnXNIA3w4NDsx2N9yb3m4Xn6WphX5ipaiUyzob2LEvGZl6fqk+WqIGCL75idd8H1yh7OCJs/bC7yWkD8VAisac1DoRHuEmiavnbmGHEPqOtVxRFRMvglHQF3xYQIvgZmcv48VOSYmUriEdjV0PpFVUKAVhxFDbQbSeelWZDDzOvpmOA/9V2nEc/Ir/4o9sDR6dR6hVfe/2qHEn4yATM7+i/Fv/7PWwDz7JXMWOj8oFikKU1U4LH7uNoQGc42WNcizb9gbvNDOEK5UZ8pB2xjItn6apWxChvk4kmG4nuO6LIbQF1Sq+bxJRXt6qizti8GkaOSxxJMgUAgRQH60YYCkzHJC2t1LNUxSU6yc5dzwH/EAStjvNedYrJ/gWWR+vCoCGkmOI2i1mC8pwYb+qSXkxKvDOfCSNB+la//loBoSkZAxAHQ/84vos3iYA28ez3QcSIw5BRKbEWW5UWKZzLQ1V1Q4D348pur36Yi0y48kEytdCUyf3QWAVLU4DKroXeiAslnuPn4c+yjVNaJdMD+RKrTWBVsl9P6Zfj5hBfQYOCUQ8XJLd+HOTBbTC2vQbmbFPfGepcLI+Gz5lU8NCKHapqgXU44Cju5ElQhZpBFW4SjcXosiz9WIfPxjKpfmvIvRb5mUcJm+igQRW3eqpTlJVwhY5JbzM9AikPuUB/bEcSGowGRG+dSKAkjs7KBzwZqnP5nynkq8ck4zZ+NuH30jPNVtW+JKvGiix1fcQ3NKulLD5x15sRf7mANF/mBV7fbAbZcxjjC3eJEeKThkn0oYn++A1C/Auqovze08AmXSsWHmPfNMFDm1bYiPF0vJ8xIhKPCMFrlvmQzTe3tejOY/EoYpGMqJJpx76cp+ugOw8ql+GgpsphhJIofbtoheSctuoKdvv8QYab1m9P7pSbxdS9hqGVhQL64uHHJmyTUhJ1TywWKeoXu/+560fHSmA0oOXRsTTDJOyjbjNYnsOyky3Fp1qkv7c5SkyGv94MZHqzpxJ9XkOQT0tIMTbLbbfR2blysXiGgSAbAmSj96XABbm9SuqM8cw7MXScxH1Y9TXhXEtk0L8c9koFs6mcvToDpETlPQ4jJe98mnoNV2TPYlXBndRq9FJthN3EKEeJI+PyNgCPvxd1qLsblHvsvWtKZ71wqN8iXcpuO4LgOJtP+UCq220Z3R2Ay2XMzwsEnn+AjYeRo59NZtVry6b7gIR4LUWG1rPxwa4ZSAiv3ylLBeHAlO7ll2VheoHxir0vl3BvLlcfW7Ux/Ye+cKREBOmA/E/AI5IygWBYzg5hZ0fRl70+9tfbcyBIZPnoPabOz6QBduPPLB4fRtS3IdZzF6VWw5wtd2FDv7UiMILU4bKJ5g4oJm3XnUXdoCaMoRIoji+xXY1n8ujvMAQxIMSOhQlZvwQvjYPg6eDNYBvISHLZd3/cw1vfnGl9rn7RKg7jD4gEzRz5InFioOU5dq9hmVutuoM1U7xywqF54y+hP+mM8iFKpZUBHql91u7rq1PvlmNSvsZ3uL7De5mPKyNkQoxW3uG+wIGp16YhtS6z/yXSOpHy2NPCdbg2zhlY/N/hqhKLgrBwiPnxnGXGU3QnQ+vo7 X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: e0923194-4a7f-40aa-94c2-08dc026cc365 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:35:33.8877 (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: 8pIWvsPn+WzqWjpf0FovaB1WyJ3nvD2fTmTVar8bIiuxMs2BCoH4YFsjT/UcL2eDy2Wix+o68dOn7d2JGxf2OQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7481 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 8644021b8996..462e0d97f82c 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 1ed206b9d189..b0dabb349b7b 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 Thu Dec 21 21:33:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502671 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2058.outbound.protection.outlook.com [40.107.237.58]) (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 2281F77F08 for ; Thu, 21 Dec 2023 21:35:40 +0000 (UTC) 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="RQwhUOnH" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CJ5WayZWblEwVu8hN2A3QBZcnXUHBHVXQvycxVMjQIUcBC4M010xOBCWDLrdejM80OYJoFq0gAuuTeJ1M2GhYZImdEFcJvVmS2qiXZ0vNjJP5cGveFh0QpTuNqM6rV1umoNLARoqybkZGWxW8b3A3OdBo7WEDvY99osQnelfbX20Tw6ArDe54IDVM9J0XRnvO1YhWVmqL9B077WhNQirRLpAmr5gnaeWNH+tJs2thDpet3VLmswdk/QiPW1OSBg9E5eho736ugqZajrpdY8hz2WeBT9A5NnRPyUUU1zHbQw5nwfSM3Qi32I7WcWQ1bEGHzA6kx8rM2Qfx3LOl22NFg== 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=OMNrKi2nhF/Q9ZopjVTPHnyykhTo2h0LSfNT4g9TsSw=; b=oZ0NxkokLgwhCMFGZTv+Lndua7puYO8jG4LgsISnpJVfyizvQPOIPVOsUbpLuXSDZWWYM1sx6K90zO5rVboejN4C4peSZ6NXey4kDLyj3hCk3LG1tx8BQURqAR6ujOvmE6nq3rPb3Jx8O/mg38gBuJLoNHPTHu0stcntzQ4Ij5GJ0Ad7wRhKSPkE8d2gmUlSAPeTwn5hNLgeS1ncxLCDRSgcoC91ILJslasym+eRtLdUaBBCXgZ+Z4o/KGsIwAQmvWkgUGbiZnW6p694WiFjUf9wcnzp8nsqQySSYaAsafPXlygrGLhCc0DItjKjd3aTDYznEO+Qas1+XG/41L1LQg== 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=OMNrKi2nhF/Q9ZopjVTPHnyykhTo2h0LSfNT4g9TsSw=; b=RQwhUOnHfgJSIF/1zY4N4knE+viDFdhFZc5tZWLaFzJy2xLpeM9FOH7epxi6kFewC9ECSFVNJKPUZQ0H/5ep1WrM15j3o8Ds5l6qGZXFlUTnUYiqTMm7nxylgptYEb6k1yyEMuyQ/KEas88tpdf421AmLJjhjjY8ptnTXLjMk2zj/UE9h3UMqQBlVCkcKJoHmVOoeR/IL562LXUkGLECO8sHS3Gi6fVOsr4PFMZO+Jfk6pwJFb1zJ3FqBze7YP4iHvNsW0ty3GcrGp02rgD0PiqaPFtWjJrjj16kA48G3o59/olSMxEEomIGyw1dQVQHLKX/MIkMyzUTRjs6buV35Q== 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 MW4PR12MB7481.namprd12.prod.outlook.com (2603:10b6:303:212::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.19; Thu, 21 Dec 2023 21:35:37 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:35:37 +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 v22 19/20] net/mlx5e: NVMEoTCP, data-path for DDP+DDGST offload Date: Thu, 21 Dec 2023 21:33:57 +0000 Message-Id: <20231221213358.105704-20-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO3P265CA0031.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:387::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_|MW4PR12MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: 2a5a4b30-6465-4ddc-ca60-08dc026cc5a1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DS8IEL0ObDkz69oXndLuIq+vKE/M/wVY5Zc67sOWVxwrj1vTbLWj+h4p7YL5PeS4psTRlnBkmIQhhLvwf7Kja6CJse65a+BdRxMD73Pp7k8Ms7Z8P2JaZ+sUGPyAESREHfUtEHY6pTB0y+AfEEinRgVbVyCLPFYBTEmBDYj1RQujWOe08Zqhn0PI6ruCvJ0csRBvHF4UGSgalNFrlcZMSon/OfDfh4uFYqrVPYO1oApV8h1NM5fIgL8ziY6AMTerKmRyVwabLiuCENQYdgNi605CmKaD7wQaODYRMMjlQLkIxI6pSxM51WgjTmjSbh0RrM0ArC392iQri06g20L4dmqAitQ9plfty1dT+LzOXGN+F0CBilb7qiolftyHNVXzIB88feh3MnTfLNo4Ot0YiUT2wcfNNZ4o7I3jA+JOXj0rEM0HyP+m77K5XgkaVm0OTNG3hyBv1zsgIRLqt0D5NdUk7+GCjn+TuRh4rPpP0O0CnzWbT4UvxMTM44hidSzYR2dOhz0kovXsb2K3DB9hj8kj3+xarVm3fha9V2GHqwb/T7E+VS9BbJ6YRRyvrjrpI73Pc+KmXofCcC4rOh0r86zVl/PatqNxSPyVV2cEO5g= 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)(136003)(346002)(396003)(39860400002)(366004)(376002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(66946007)(8676002)(8936002)(66556008)(478600001)(66476007)(83380400001)(316002)(6666004)(30864003)(7416002)(4326008)(6506007)(6512007)(6486002)(2906002)(2616005)(107886003)(26005)(1076003)(41300700001)(36756003)(5660300002)(86362001)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: /6wbCNibSBaqGPo/+YVPvUTAdzgZbIeT89IdIrtXSZFpSgPn3Nj9R4HNRaGiMcqZ9fDenYnXdxO9Z6ZzDK1QqQdDnnNSzDYCafM6E02XDiFvP0lNs9heXimJvXZ/Ux7sz0z6YxME7r4dPWslgMtwHyT5Ivkluc5AmdkzF2F6e4U6nDyH3IUQ63basthJFKm12vA/3wgA5VuS4tl6WnTWgMbTV5HCbwZ7AeSv4y1L1MKeUKyoQgq+QJ1VcvWvQ+Hgya9oqMV7SP0QW8j8kqfooUnYCxqNlPelb8FkOX/WX2dkBlHJO+mKNgAlUeL2aYws+KTMwYqHuRpZcAGUtGeWOvK7yAYo8T0piLM3qT7RoZs+lXxhLY3uLmP1WvDx406SSHGXfIksuz5gmLDghbFgEZNN9LXjHrTRzi5LhPNUZd5xy6MlKrSysDsSy1yccl2htvCMhfU42arEOE+a+SqJihserRG5iRJUkN7EXwlWE1cRDef/Dm3HsZGawgIdW2EUo6KkSHvkuWbuHf+jN6EuA3U/h9yR231Ya1teDQk6LZFgJULrt4S1xHtHfIo3ZdRmPlN3EnFg2wRucFORcTYyCEBHWtySWFNbxbR9W98mVwiAaUUv7GVvh+xCEuAoLCim+7RYmrNRiuJAZgipeZW7VngcL2WGx1isi1tQvfc0r1hLL0tlc7Tfz5wjFy20ubQqayz5YsVxMjxZx5vLXDuqFsJZvnrbszSE1ZjoO1Sd/zF4APr6rCj2BhFKU4zYn8FcXoj3pBKkL16Tnc+dzYQrcT8pjexB6PIS7BzsnU1VdgFA3ySfxqEs+PYI28beLVareSkeXtBG4E5CN6XYicg1fI9r6xj/iistdI7iAyPNDkWyVMCh2cGKg9l1v2ebCgGBTi3WrOFJfxR0TKt64DhHSdAYScBUqCJblJQpFJcPfaGYpRZ88I5iefWU+ofmV0lFTJExHKRSOsFE8Tt8C1alnhkQRnNmE2eDxSdeUgK9mv5h/LJso4Qqan74+7PwCz0bwV2NHfV538ZQOcsSoiF1/O75ojhtnV0qJAvOiyqANk9AdYbJtcfIHTmpumZt4ukbJvALYvIhXScxfR/oPiiLE5Rb1R2uQPDUTNeeJvZWLaTglrSO6sPr7rZQ8uvUUo+7dLif4RqeClN9mDkFXWAQ75podddz2QwP/2XFat/R8UEIPJODirqvo36LwnXWyEx2RIywT3HqGURo07UfFlpBdyGs01eZGMWrTeUxc42FhVxNhckfDG0jbkpDl/1l/zMr6llFVlaVTygLu6C/OyoQcXWtzZEJO0Hf0TECFQ2Kmw2j610ZoOaILrqVjJoj4oPJprTNf9Vujt3Izt4Et3cmkBO0XFikxo2Sro2vnzuxOvYs37ceTC/VLG6J6we0qFdFwr9zbwoyFoksggKFvr5LeYJa6OHNIIOMGF8MI4xaGo7Y7nB+kB+7dTuKSv0UyOXHpjuuBqIu3JzOryF0J6CyOs9/MMqFJvwspDexcXDMlt/h986z3CxGVeo2xq/fxy7MW2u10bnnE+KoRUba2yRG4HX65roC1H691q+9486cV3++AEQK+GOgYbjzmDTRgbWU X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 2a5a4b30-6465-4ddc-ca60-08dc026cc5a1 X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:35:37.7136 (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: vpTRf8hTGnTV2pNLYLCCCdOGXkG4Jf5G7qWLarYJh/UPLRyWoYxGjY8aAJp/zyiGrrbnep5LHSs/6nh8/BQhpA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7481 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 b0dabb349b7b..14dd03d2e402 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 Thu Dec 21 21:33:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aurelien Aptel X-Patchwork-Id: 13502672 X-Patchwork-Delegate: kuba@kernel.org Received: from NAM12-BN8-obe.outbound.protection.outlook.com (mail-bn8nam12on2088.outbound.protection.outlook.com [40.107.237.88]) (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 8AA6F77620 for ; Thu, 21 Dec 2023 21:35:45 +0000 (UTC) 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="DirNs8SB" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z5SBMfJiCRcbWlyHqs1TQPPoKmeLSWrwmLYU8zHzUVEJ7a275sf/qBonyVEhIn3DeTHe1Nwejx3jruyZlWbitygJfhE/2U+PopjfB9XltIOBf8pG4L1XUsbl1HN3WlPa3+ZgKPRu1C7fasQB9YookCypQ1/UW0uON3QHBljAj5F353NiMTPSK4se5oKMOyfKALiClT14BIg9RNtIMPz20Fk3riP3gBmE81vtOgdPuNHgbj2JviWq7PjSTFnQB6JPBXtrW/Mq6w4zXgBezfXtUszmiyiZaxlZsYqv1o/ZW+Zk2pxhjFDJG0g/FNzPo9kimJH4LFjpLS2nhoR4SaAR4A== 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=u5XQTBOL/L1JB7W8dkjc65TxCcZPV9Ju+395GeoUiyE=; b=UC0NqJZjvCtZC8g3LsD9z+sJz0YtoW9tcDSwhM2rGRL16npYtZgeQCP08MLUBk126o910PfY1LXtyy3v+yuIeun2FakADjNtghDxVAR4QQzJFQE8u4hZ9jQXhFDHRbFNLpimL+01jtTvG7a9H4/cwrUZxhqs8SiGJkrtFKncuI69y9RRGyjcd76fiHOBnxq0idYaxfpZMmIX4vLABv9zh7FxFqLxILgFE1ojlFVhAwa7yffLGri0zCg46O+uMEFNx+zfmeitteUxZH82S1uzIf5RaTK7VphqcdNhA0cbWSg4AlPHxbFG8Uruz2ndDgUCLn/NQeTR46I91NkGLiL5MA== 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=u5XQTBOL/L1JB7W8dkjc65TxCcZPV9Ju+395GeoUiyE=; b=DirNs8SBY6N6DvuBQeENcF4KqIOAjf5wH0ZH/BB0OlT1jrzyOGDRvUMC/AWqProM3/DZJiy+3tDbFachQCSmrrBkb6Vom4kRRD0XkCrqzuoFc6i/ZtkPi2F8+Y2iXVWHLd3CZOIWJ8YwfhMjMfHmVA+aXh5ir9IXwfx/P+dzjiUUvkhEn3Dk5bp/uu4GwxblNbSl/KVA231z5QiIyGXVA2Kx04/waAok9Wvb6Pea2PimOp5FoFjLlfmfH/sNPW9bpUoh5ebdQTvs6ITsycSsUbV0l/aF8Ht+qeELLjShS+0bcAsseByZT3yxOEjS5qgw4TDnb1Q7SuWmVmAVZmoXxQ== 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 MW4PR12MB7481.namprd12.prod.outlook.com (2603:10b6:303:212::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7113.19; Thu, 21 Dec 2023 21:35:42 +0000 Received: from SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e]) by SJ1PR12MB6075.namprd12.prod.outlook.com ([fe80::eb39:938e:7503:c21e%3]) with mapi id 15.20.7113.019; Thu, 21 Dec 2023 21:35:42 +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 v22 20/20] net/mlx5e: NVMEoTCP, statistics Date: Thu, 21 Dec 2023 21:33:58 +0000 Message-Id: <20231221213358.105704-21-aaptel@nvidia.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231221213358.105704-1-aaptel@nvidia.com> References: <20231221213358.105704-1-aaptel@nvidia.com> X-ClientProxiedBy: LO4P265CA0288.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:38f::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_|MW4PR12MB7481:EE_ X-MS-Office365-Filtering-Correlation-Id: 677d6aed-fc7a-4d93-aaff-08dc026cc86a X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: yHXAN5dT/N0nbUOALjsjWqRODpbsUvDU2qeb0LLRRCULmXfWIccl8c6b49vUr/DD1TZR/TnepcbXBoM40yptJWZ83U3W1Wa3JYivUCWUDBvGCX8MsEIx5qW1yBInrbT0wyj9+DrmnfssqxsXoRTjJ0xbdKmk7Q2jZ5kbjatp0AT+rcy3SWJamm7cYUbvBemhW4OFPRi5h45PKJT+F1DcKDZI5Y3JhFM7EC4eY95dGgyeZZLIA+djaOdswK7cFa/5FIsVp7vAwGAxPRZq6JsXq0uJ5nGAcxhLxMNeGNc5o27zzjyJhhaPKqu/fb7imP0k7u4inobS1yQS9T8K8SQU9bQYGgHv57cvGs2Ytt70uM15HaDVHvqYdOgKixrY04nceEW0h89gSGOBHe8jDKMQy7rARLZBIlAEwUJTTR9Sfpdt2luyqvwofooz5d9p2XGe5whhz04Ln4GdE3wN7L7n/RpPFxO/rUUsvdOiT56ns/63Yc04azE+kZRoTvE9Q3fT19ppKv5KOHIpMbvTuSgchRGv6C2CHdGy0AgnHsWYVSTKhl/fGXjNOyKW7XJHqY7bdlMztkPsrmEQJ2qko3PQ59oiGI8Il7732ADWEe2vxCM= 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)(136003)(346002)(396003)(39860400002)(366004)(376002)(230922051799003)(64100799003)(186009)(451199024)(1800799012)(66946007)(8676002)(8936002)(66556008)(478600001)(66476007)(83380400001)(316002)(6666004)(30864003)(7416002)(4326008)(6506007)(6512007)(6486002)(2906002)(2616005)(107886003)(26005)(1076003)(41300700001)(36756003)(5660300002)(86362001)(38100700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1eD45vSo6+tKrnS6UKiaizoNN0K2kYxIo95MQCI+Rhe1mLyE3SMPHtcc9ZnQ4NkLMUH7YHMFcNgjOuSz+7aeY5qAFD2bpUBVtv5cDwjvospEmKcJDWgv7Ny+1gqcOctMMExSNzhZYgBUoTM7qCQ2k0TEzBZEu4y4OLrN8Sl1c7FltouhTkCgZ41bKubVhZNHqj9fShW5ZHL43AxVfs/guHxgqil7zubu+/dHjwZ67aS7J5qRLgFto1ACuISDckF0K3zzlyISNSDH/QRHekkeJsHC2VnFd8eXsUYtuABXIF2oQ7j+9Y2vbQFE4I7HduyvTmqglOrpx4O9zj9bK/rcz/nsCnV/O7qhrWqtgNgt1sA3Fwrx46LZfIO18ff7dOcJMn0vqb+DYR9Vn9slj1ZYwrPi2vC/RRooX0uWVrma2nZn+SffdmwYrC7m5R9iNfhPlFhlGitS7pdRLFRs1rataYhxMrl/Ky6We5wJoO1PzWdbpgVAZGQNe5Ct90TsTuFAnSGzqojwutR/nmTAt7WWNL1S8ptDjqXo+DoWMNX/EjqwholXMBxWaH2kyKUpNGBB1AXGk6GotJvb+Mell4BOkSaGK2KhuncIkM+FF2wUMEqi2yI+xILPaoWvTLl+9T8jA7hk+4oTUNevhvbv/ZpiPH1ewe8cH75/PR/gre9XQE7ayu89vVRmCTmRbZkl0uiP64Ox5VA6AMczaFKoAwcoPR54FVHqPIJwr8ehAoeohMN72YynZkn2C46Tib88XKD3SvFHWB/zkuZ7oo4BUQRnuCwz+SDSt/haanQV1jsyllVf9fLtIB5szbhHfN2bKFjUtIwQ2FY12DVfbrTmK4CisTEB5oedj83y25RmHpDobjrKQCTaQjjYCdZDIGnXDWtYtEhDQXyGQa1Ww1B1liohKAsmYttlvY2mRU+yafGyPJTVsemdWvEP2Yd6kTFGWHggEwfjw5FQBiW3Wm8bCZz0EQ3VZoYJ0Hl3jQTCariRJDOZonog9NBHo15C4Rkg45aMbJj5g8M+2xgJs4gYm3pmyzYbDrALHejPTgaeTuJ1tRsNrcsRP0lONOCadFprz/GAIEyYOKpkUTJwz8tVIYcocOy5ZztPo1KTZyfguFm/Y4jUhjGV6rxrys/LDdaaeiFDlb1uqeFpdofvC6+Nz3dN7Ljq5t7twX3eCXG2K0KZXD/B4001Hhj8t/m0aIgc91OXafHyhM0COogbNgSw2Scd632mrWjTOCltyV2YP2BjB8pjDcE8RjmLk8ihyYwqwtbl9WAHub8qhuzIAjy6AX4RsMCnZ27PJUj59YU17l54V1/DWXFY3xArJeZAOuJe7wvppXInZ6nR7qzLSuKZzIk3JXg0tzLoDxInIOOP028IvD9zvHXzQKx/6E2T08fdSmVPiGUZptwZ76PILH+dTmkJN1bfZB0L+1um7KYOgys4kZmVboqC5+7KJS+zat5YAoOLEspsCm/p6FQFbZ4OI1g7KsHL5Ff8BQMa+4EGhAbMUB4RKWEHalea4njfcNa+3Apsjt8ETFe+JJwGHR0yHfYZuzpIU2q/MieM8eqK99/5R0BurZmAcQAN4LmmUIh/02mH X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: 677d6aed-fc7a-4d93-aaff-08dc026cc86a X-MS-Exchange-CrossTenant-AuthSource: SJ1PR12MB6075.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Dec 2023 21:35:42.4682 (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: LH1LfwysRicpFrYWUZXduQ655o42QrRD/KegIY2kG6owOzN7mH5BXMGIDqBWjr6Jy2V1BbTG9a7/S8wW+FffGg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR12MB7481 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 462e0d97f82c..371ab23292f5 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 {