From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id AFCFF43E06; Fri, 5 Apr 2024 16:47:34 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 641F14069D; Fri, 5 Apr 2024 16:47:30 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id EABB140633 for ; Fri, 5 Apr 2024 16:47:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712328448; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HexOe9efAcg94Cfh+kb/JlltZ/Z3WEk7QUM13Nh1WIM=; b=RdBPG36xqGiRmqP64EBFVIks0g07YBfntmQRdMdMlBvqA8cbDni1EUw/k3lP7iGymAPaT9 yFqE1zQ+9k6I8Fs1a6wOFEVq3Jw6b/SsvSKCuZIP9ZIVtJzbEY9t+oKAMTtHF2giIrFdPm VlmRcnVvDOrjjQQuMNY5aTNvdZRxOwc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-504-O9E8e2pzP-eK0sHJaiSjuw-1; Fri, 05 Apr 2024 10:47:25 -0400 X-MC-Unique: O9E8e2pzP-eK0sHJaiSjuw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 04D2B85A5B7; Fri, 5 Apr 2024 14:47:24 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.225.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id A968E1121337; Fri, 5 Apr 2024 14:47:22 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, ferruh.yigit@amd.com, Aman Singh , Yuying Zhang , Jie Hai , Yisen Zhuang Subject: [PATCH v2 8/8] net: clear outer UDP checksum in Intel prepare helper Date: Fri, 5 Apr 2024 16:46:02 +0200 Message-ID: <20240405144604.906695-9-david.marchand@redhat.com> In-Reply-To: <20240405144604.906695-1-david.marchand@redhat.com> References: <20240405125039.897933-1-david.marchand@redhat.com> <20240405144604.906695-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org If requesting an inner (L3/L4 checksum or L4 segmentation) offload, when the hardware does not support recomputing outer UDP checksum, automatically disable it in the common helper. Signed-off-by: David Marchand --- app/test-pmd/csumonly.c | 10 ++----- doc/guides/prog_guide/mbuf_lib.rst | 8 +++--- drivers/net/hns3/hns3_rxtx.c | 44 ------------------------------ lib/net/rte_net.h | 22 +++++++++++---- 4 files changed, 22 insertions(+), 62 deletions(-) diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c index 71add6ca47..2246c22e8e 100644 --- a/app/test-pmd/csumonly.c +++ b/app/test-pmd/csumonly.c @@ -612,19 +612,13 @@ process_outer_cksums(void *outer_l3_hdr, struct testpmd_offload_info *info, return ol_flags; } - /* outer UDP checksum is done in software. In the other side, for - * UDP tunneling, like VXLAN or Geneve, outer UDP checksum can be - * set to zero. + /* Outer UDP checksum is done in software. * * If a packet will be TSOed into small packets by NIC, we cannot * set/calculate a non-zero checksum, because it will be a wrong * value after the packet be split into several small packets. */ - if (tso_enabled) - udp_hdr->dgram_cksum = 0; - - /* do not recalculate udp cksum if it was 0 */ - if (udp_hdr->dgram_cksum != 0) { + if (!tso_enabled && udp_hdr->dgram_cksum != 0) { udp_hdr->dgram_cksum = 0; udp_hdr->dgram_cksum = get_udptcp_checksum(m, outer_l3_hdr, info->outer_l2_len + info->outer_l3_len, diff --git a/doc/guides/prog_guide/mbuf_lib.rst b/doc/guides/prog_guide/mbuf_lib.rst index 4e285c0aab..35f7fffbc7 100644 --- a/doc/guides/prog_guide/mbuf_lib.rst +++ b/doc/guides/prog_guide/mbuf_lib.rst @@ -158,7 +158,7 @@ a vxlan-encapsulated tcp packet: This is similar to case 1), but l2_len is different. It is supported on hardware advertising RTE_ETH_TX_OFFLOAD_IPV4_CKSUM. - Note that it can only work if outer L4 checksum is 0. + Note that some driver may set outer L4 checksum to 0. - calculate checksum of in_ip and in_tcp:: @@ -169,7 +169,7 @@ a vxlan-encapsulated tcp packet: This is similar to case 2), but l2_len is different. It is supported on hardware advertising RTE_ETH_TX_OFFLOAD_IPV4_CKSUM and RTE_ETH_TX_OFFLOAD_TCP_CKSUM. - Note that it can only work if outer L4 checksum is 0. + Note that some driver may set outer L4 checksum to 0. - segment inner TCP:: @@ -180,7 +180,7 @@ a vxlan-encapsulated tcp packet: RTE_MBUF_F_TX_TCP_SEG; This is supported on hardware advertising RTE_ETH_TX_OFFLOAD_TCP_TSO. - Note that it can only work if outer L4 checksum is 0. + Note that some driver may set outer L4 checksum to 0. - calculate checksum of out_ip, in_ip, in_tcp:: @@ -193,7 +193,7 @@ a vxlan-encapsulated tcp packet: This is supported on hardware advertising RTE_ETH_TX_OFFLOAD_IPV4_CKSUM, RTE_ETH_TX_OFFLOAD_UDP_CKSUM and RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM. - Note that it can only work if outer L4 checksum is 0. + Note that some driver may set outer L4 checksum to 0. The list of flags and their precise meaning is described in the mbuf API documentation (rte_mbuf.h). Also refer to the testpmd source code diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c index 03fc919fd7..b5436c51e7 100644 --- a/drivers/net/hns3/hns3_rxtx.c +++ b/drivers/net/hns3/hns3_rxtx.c @@ -3616,47 +3616,6 @@ hns3_pkt_need_linearized(struct rte_mbuf *tx_pkts, uint32_t bd_num, return false; } -static void -hns3_outer_header_cksum_prepare(struct rte_mbuf *m) -{ - uint64_t ol_flags = m->ol_flags; - uint32_t paylen, hdr_len, l4_proto; - struct rte_udp_hdr *udp_hdr; - - if (!(ol_flags & (RTE_MBUF_F_TX_OUTER_IPV4 | RTE_MBUF_F_TX_OUTER_IPV6)) && - ((ol_flags & RTE_MBUF_F_TX_OUTER_UDP_CKSUM) || - !(ol_flags & RTE_MBUF_F_TX_TCP_SEG))) - return; - - if (ol_flags & RTE_MBUF_F_TX_OUTER_IPV4) { - struct rte_ipv4_hdr *ipv4_hdr; - - ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *, - m->outer_l2_len); - l4_proto = ipv4_hdr->next_proto_id; - } else { - struct rte_ipv6_hdr *ipv6_hdr; - - ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv6_hdr *, - m->outer_l2_len); - l4_proto = ipv6_hdr->proto; - } - - if (l4_proto != IPPROTO_UDP) - return; - - /* driver should ensure the outer udp cksum is 0 for TUNNEL TSO */ - hdr_len = m->l2_len + m->l3_len + m->l4_len; - hdr_len += m->outer_l2_len + m->outer_l3_len; - paylen = m->pkt_len - hdr_len; - if (paylen <= m->tso_segsz) - return; - udp_hdr = rte_pktmbuf_mtod_offset(m, struct rte_udp_hdr *, - m->outer_l2_len + - m->outer_l3_len); - udp_hdr->dgram_cksum = 0; -} - static int hns3_check_tso_pkt_valid(struct rte_mbuf *m) { @@ -3834,7 +3793,6 @@ hns3_prep_pkt_proc(struct hns3_tx_queue *tx_queue, struct rte_mbuf *m) * checksum of packets that need TSO, so network driver * software not need to recalculate it. */ - hns3_outer_header_cksum_prepare(m); return 0; } } @@ -3848,8 +3806,6 @@ hns3_prep_pkt_proc(struct hns3_tx_queue *tx_queue, struct rte_mbuf *m) if (!hns3_validate_tunnel_cksum(tx_queue, m)) return 0; - hns3_outer_header_cksum_prepare(m); - return 0; } diff --git a/lib/net/rte_net.h b/lib/net/rte_net.h index efd9d5f5ee..79e969464b 100644 --- a/lib/net/rte_net.h +++ b/lib/net/rte_net.h @@ -109,6 +109,10 @@ static inline int rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags) { /* Initialise ipv4_hdr to avoid false positive compiler warnings. */ + const uint64_t inner_requests = RTE_MBUF_F_TX_IP_CKSUM | RTE_MBUF_F_TX_L4_MASK | + RTE_MBUF_F_TX_TCP_SEG | RTE_MBUF_F_TX_UDP_SEG; + const uint64_t outer_requests = RTE_MBUF_F_TX_OUTER_IP_CKSUM | + RTE_MBUF_F_TX_OUTER_UDP_CKSUM; struct rte_ipv4_hdr *ipv4_hdr = NULL; struct rte_ipv6_hdr *ipv6_hdr; struct rte_tcp_hdr *tcp_hdr; @@ -120,9 +124,7 @@ rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags) * Mainly it is required to avoid fragmented headers check if * no offloads are requested. */ - if (!(ol_flags & (RTE_MBUF_F_TX_IP_CKSUM | RTE_MBUF_F_TX_L4_MASK | RTE_MBUF_F_TX_TCP_SEG | - RTE_MBUF_F_TX_UDP_SEG | RTE_MBUF_F_TX_OUTER_IP_CKSUM | - RTE_MBUF_F_TX_OUTER_UDP_CKSUM))) + if (!(ol_flags & (inner_requests | outer_requests))) return 0; if (ol_flags & (RTE_MBUF_F_TX_OUTER_IPV4 | RTE_MBUF_F_TX_OUTER_IPV6)) { @@ -136,19 +138,27 @@ rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags) struct rte_ipv4_hdr *, m->outer_l2_len); ipv4_hdr->hdr_checksum = 0; } - if (ol_flags & RTE_MBUF_F_TX_OUTER_UDP_CKSUM) { + if (ol_flags & RTE_MBUF_F_TX_OUTER_UDP_CKSUM || ol_flags & inner_requests) { if (ol_flags & RTE_MBUF_F_TX_OUTER_IPV4) { ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *, m->outer_l2_len); udp_hdr = (struct rte_udp_hdr *)((char *)ipv4_hdr + m->outer_l3_len); - udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr, m->ol_flags); + if (ol_flags & RTE_MBUF_F_TX_OUTER_UDP_CKSUM) + udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr, + m->ol_flags); + else + udp_hdr->dgram_cksum = 0; } else { ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv6_hdr *, m->outer_l2_len); udp_hdr = rte_pktmbuf_mtod_offset(m, struct rte_udp_hdr *, m->outer_l2_len + m->outer_l3_len); - udp_hdr->dgram_cksum = rte_ipv6_phdr_cksum(ipv6_hdr, m->ol_flags); + if (ol_flags & RTE_MBUF_F_TX_OUTER_UDP_CKSUM) + udp_hdr->dgram_cksum = rte_ipv6_phdr_cksum(ipv6_hdr, + m->ol_flags); + else + udp_hdr->dgram_cksum = 0; } } } -- 2.44.0