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 A0F2843E06; Fri, 5 Apr 2024 16:47:07 +0200 (CEST) Received: from mails.dpdk.org (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 8D0254029C; Fri, 5 Apr 2024 16:47:07 +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 3CC064029C for ; Fri, 5 Apr 2024 16:47:05 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1712328424; 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=S4fn+TJKt47mpCqj01ODr31WxeLfKeRTOq4xZRua4Eo=; b=AGE5CWwawI56gJHV5iiCVFqnY/4kXauwrzbao5BYMNdQwPO+KBqQqA9ZbmhRlQnC6onSLf wwa/aIiEocFASrbWKDPipLvwrlh/VBndLMFYJXTCqIgXKolWsqyHt7qw8l1d25IqD8rllL m6wbua0vwa6BT4a5qYM15kAFIalWx1A= 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-694-imPPjYmYPly_FiAi5zKQfg-1; Fri, 05 Apr 2024 10:47:03 -0400 X-MC-Unique: imPPjYmYPly_FiAi5zKQfg-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (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 79DE5848A64; Fri, 5 Apr 2024 14:47:02 +0000 (UTC) Received: from dmarchan.redhat.com (unknown [10.45.225.49]) by smtp.corp.redhat.com (Postfix) with ESMTP id 675D53C21; Fri, 5 Apr 2024 14:47:00 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, ferruh.yigit@amd.com, stable@dpdk.org, Aman Singh , Yuying Zhang , Jie Hai , Yisen Zhuang , Ting Xu Subject: [PATCH v2 5/8] net: fix outer UDP checksum in Intel prepare helper Date: Fri, 5 Apr 2024 16:45:59 +0200 Message-ID: <20240405144604.906695-6-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.1 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 Setting a pseudo header checksum in the outer UDP checksum is a Intel (and some other vendors) requirement. Applications (like OVS) requesting outer UDP checksum without doing this extra setup have broken outer UDP checksums. Move this specific setup from testpmd to the "common" helper rte_net_intel_cksum_flags_prepare(). net/hns3 can then be adjusted. Bugzilla ID: 1406 Fixes: d8e5e69f3a9b ("app/testpmd: add GTP parsing and Tx checksum offload") Cc: stable@dpdk.org Signed-off-by: David Marchand --- app/test-pmd/csumonly.c | 11 +---- drivers/net/hns3/hns3_rxtx.c | 93 ++++++++++-------------------------- lib/net/rte_net.h | 18 ++++++- 3 files changed, 44 insertions(+), 78 deletions(-) diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c index f5125c2788..71add6ca47 100644 --- a/app/test-pmd/csumonly.c +++ b/app/test-pmd/csumonly.c @@ -577,8 +577,6 @@ static uint64_t process_outer_cksums(void *outer_l3_hdr, struct testpmd_offload_info *info, uint64_t tx_offloads, int tso_enabled, struct rte_mbuf *m) { - struct rte_ipv4_hdr *ipv4_hdr = outer_l3_hdr; - struct rte_ipv6_hdr *ipv6_hdr = outer_l3_hdr; struct rte_udp_hdr *udp_hdr; uint64_t ol_flags = 0; @@ -588,6 +586,8 @@ process_outer_cksums(void *outer_l3_hdr, struct testpmd_offload_info *info, if (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_IPV4_CKSUM) { ol_flags |= RTE_MBUF_F_TX_OUTER_IP_CKSUM; } else { + struct rte_ipv4_hdr *ipv4_hdr = outer_l3_hdr; + ipv4_hdr->hdr_checksum = 0; ipv4_hdr->hdr_checksum = rte_ipv4_cksum(ipv4_hdr); } @@ -608,13 +608,6 @@ process_outer_cksums(void *outer_l3_hdr, struct testpmd_offload_info *info, /* Skip SW outer UDP checksum generation if HW supports it */ if (tx_offloads & RTE_ETH_TX_OFFLOAD_OUTER_UDP_CKSUM) { - if (info->outer_ethertype == _htons(RTE_ETHER_TYPE_IPV4)) - udp_hdr->dgram_cksum - = rte_ipv4_phdr_cksum(ipv4_hdr, ol_flags); - else - udp_hdr->dgram_cksum - = rte_ipv6_phdr_cksum(ipv6_hdr, ol_flags); - ol_flags |= RTE_MBUF_F_TX_OUTER_UDP_CKSUM; return ol_flags; } diff --git a/drivers/net/hns3/hns3_rxtx.c b/drivers/net/hns3/hns3_rxtx.c index 7e636a0a2e..03fc919fd7 100644 --- a/drivers/net/hns3/hns3_rxtx.c +++ b/drivers/net/hns3/hns3_rxtx.c @@ -3616,58 +3616,6 @@ hns3_pkt_need_linearized(struct rte_mbuf *tx_pkts, uint32_t bd_num, return false; } -static bool -hns3_outer_ipv4_cksum_prepared(struct rte_mbuf *m, uint64_t ol_flags, - uint32_t *l4_proto) -{ - struct rte_ipv4_hdr *ipv4_hdr; - ipv4_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv4_hdr *, - m->outer_l2_len); - if (ol_flags & RTE_MBUF_F_TX_OUTER_IP_CKSUM) - ipv4_hdr->hdr_checksum = 0; - if (ol_flags & RTE_MBUF_F_TX_OUTER_UDP_CKSUM) { - struct rte_udp_hdr *udp_hdr; - /* - * If OUTER_UDP_CKSUM is support, HW can calculate the pseudo - * header for TSO packets - */ - if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) - return true; - udp_hdr = rte_pktmbuf_mtod_offset(m, struct rte_udp_hdr *, - m->outer_l2_len + m->outer_l3_len); - udp_hdr->dgram_cksum = rte_ipv4_phdr_cksum(ipv4_hdr, ol_flags); - - return true; - } - *l4_proto = ipv4_hdr->next_proto_id; - return false; -} - -static bool -hns3_outer_ipv6_cksum_prepared(struct rte_mbuf *m, uint64_t ol_flags, - uint32_t *l4_proto) -{ - struct rte_ipv6_hdr *ipv6_hdr; - ipv6_hdr = rte_pktmbuf_mtod_offset(m, struct rte_ipv6_hdr *, - m->outer_l2_len); - if (ol_flags & RTE_MBUF_F_TX_OUTER_UDP_CKSUM) { - struct rte_udp_hdr *udp_hdr; - /* - * If OUTER_UDP_CKSUM is support, HW can calculate the pseudo - * header for TSO packets - */ - if (ol_flags & RTE_MBUF_F_TX_TCP_SEG) - return true; - 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, ol_flags); - - return true; - } - *l4_proto = ipv6_hdr->proto; - return false; -} - static void hns3_outer_header_cksum_prepare(struct rte_mbuf *m) { @@ -3675,29 +3623,38 @@ hns3_outer_header_cksum_prepare(struct rte_mbuf *m) 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))) + 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) { - if (hns3_outer_ipv4_cksum_prepared(m, ol_flags, &l4_proto)) - return; + 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 { - if (hns3_outer_ipv6_cksum_prepared(m, ol_flags, &l4_proto)) - return; + 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 */ - if (l4_proto == IPPROTO_UDP && (ol_flags & RTE_MBUF_F_TX_TCP_SEG)) { - 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; - } + 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 diff --git a/lib/net/rte_net.h b/lib/net/rte_net.h index ef3ff4c6fd..efd9d5f5ee 100644 --- a/lib/net/rte_net.h +++ b/lib/net/rte_net.h @@ -121,7 +121,8 @@ rte_net_intel_cksum_flags_prepare(struct rte_mbuf *m, uint64_t ol_flags) * 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_UDP_SEG | RTE_MBUF_F_TX_OUTER_IP_CKSUM | + RTE_MBUF_F_TX_OUTER_UDP_CKSUM))) return 0; if (ol_flags & (RTE_MBUF_F_TX_OUTER_IPV4 | RTE_MBUF_F_TX_OUTER_IPV6)) { @@ -135,6 +136,21 @@ 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_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); + } 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); + } + } } /* -- 2.44.0