From: David Marchand <david.marchand@redhat.com>
To: dev@dpdk.org
Cc: thomas@monjalon.net, ferruh.yigit@amd.com,
Aman Singh <aman.deep.singh@intel.com>,
Yuying Zhang <yuying.zhang@intel.com>,
Jie Hai <haijie1@huawei.com>,
Yisen Zhuang <yisen.zhuang@huawei.com>
Subject: [PATCH 8/8] net: clear outer UDP checksum in Intel prepare helper
Date: Fri, 5 Apr 2024 14:49:47 +0200 [thread overview]
Message-ID: <20240405125039.897933-9-david.marchand@redhat.com> (raw)
In-Reply-To: <20240405125039.897933-1-david.marchand@redhat.com>
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 <david.marchand@redhat.com>
---
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
next prev parent reply other threads:[~2024-04-05 12:53 UTC|newest]
Thread overview: 52+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-04-05 12:49 [PATCH 0/8] Fix outer UDP checksum for Intel nics David Marchand
2024-04-05 12:49 ` [PATCH 1/8] net/ice: fix check for outer UDP checksum offload David Marchand
2024-04-05 14:19 ` David Marchand
2024-04-05 12:49 ` [PATCH 2/8] net/ice: enhance debug when HW fails to transmit David Marchand
2024-04-05 12:49 ` [PATCH 3/8] mbuf: fix Tx checksum offload examples David Marchand
2024-04-05 12:49 ` [PATCH 4/8] app/testpmd: fix outer IP checksum offload David Marchand
2024-04-05 12:49 ` [PATCH 5/8] net: fix outer UDP checksum in Intel prepare helper David Marchand
2024-04-05 12:49 ` [PATCH 6/8] net/i40e: fix outer UDP checksum offload for X710 David Marchand
2024-04-05 12:49 ` [PATCH 7/8] net/iavf: remove outer UDP checksum offload for X710 VF David Marchand
2024-04-05 12:49 ` David Marchand [this message]
2024-04-05 14:45 ` [PATCH v2 0/8] Fix outer UDP checksum for Intel nics David Marchand
2024-04-05 14:45 ` [PATCH v2 1/8] net/ice: fix check for outer UDP checksum offload David Marchand
2024-04-08 15:05 ` Bruce Richardson
2024-04-05 14:45 ` [PATCH v2 2/8] net/ice: enhance debug when HW fails to transmit David Marchand
2024-04-08 15:23 ` Bruce Richardson
2024-04-11 8:30 ` David Marchand
2024-04-11 8:42 ` Bruce Richardson
2024-04-15 8:32 ` David Marchand
2024-04-05 14:45 ` [PATCH v2 3/8] mbuf: fix Tx checksum offload examples David Marchand
2024-04-05 16:20 ` Morten Brørup
2024-04-08 10:12 ` David Marchand
2024-04-09 13:38 ` Konstantin Ananyev
2024-04-09 14:44 ` Morten Brørup
2024-04-10 10:35 ` Konstantin Ananyev
2024-04-10 12:20 ` Morten Brørup
2024-04-12 12:46 ` Konstantin Ananyev
2024-04-12 14:44 ` Morten Brørup
2024-04-12 15:17 ` Konstantin Ananyev
2024-04-12 15:54 ` Morten Brørup
2024-04-16 9:16 ` Konstantin Ananyev
2024-04-16 11:36 ` Konstantin Ananyev
2024-04-15 15:07 ` Ferruh Yigit
2024-04-16 7:14 ` Morten Brørup
2024-04-16 9:26 ` Konstantin Ananyev
2024-04-05 14:45 ` [PATCH v2 4/8] app/testpmd: fix outer IP checksum offload David Marchand
2024-04-05 14:45 ` [PATCH v2 5/8] net: fix outer UDP checksum in Intel prepare helper David Marchand
2024-04-05 14:46 ` [PATCH v2 6/8] net/i40e: fix outer UDP checksum offload for X710 David Marchand
2024-04-05 14:46 ` [PATCH v2 7/8] net/iavf: remove outer UDP checksum offload for X710 VF David Marchand
2024-04-05 14:46 ` [PATCH v2 8/8] net: clear outer UDP checksum in Intel prepare helper David Marchand
2024-04-18 8:20 ` [PATCH v3 0/7] Fix outer UDP checksum for Intel nics David Marchand
2024-04-18 8:20 ` [PATCH v3 1/7] net/ice: fix check for outer UDP checksum offload David Marchand
2024-04-19 11:46 ` Morten Brørup
2024-04-18 8:20 ` [PATCH v3 2/7] net/ice: enhance debug when HW fails to transmit David Marchand
2024-04-18 8:20 ` [PATCH v3 3/7] app/testpmd: fix outer IP checksum offload David Marchand
2024-06-11 18:25 ` Ferruh Yigit
2024-04-18 8:20 ` [PATCH v3 4/7] net: fix outer UDP checksum in Intel prepare helper David Marchand
2024-04-18 8:20 ` [PATCH v3 5/7] net/i40e: fix outer UDP checksum offload for X710 David Marchand
2024-04-18 8:20 ` [PATCH v3 6/7] net/iavf: remove outer UDP checksum offload for X710 VF David Marchand
2024-04-18 8:20 ` [PATCH v3 7/7] net: clear outer UDP checksum in Intel prepare helper David Marchand
2024-05-03 13:10 ` [PATCH v3 0/7] Fix outer UDP checksum for Intel nics David Marchand
2024-05-27 18:06 ` Ali Alnubani
2024-06-11 21:10 ` Ferruh Yigit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240405125039.897933-9-david.marchand@redhat.com \
--to=david.marchand@redhat.com \
--cc=aman.deep.singh@intel.com \
--cc=dev@dpdk.org \
--cc=ferruh.yigit@amd.com \
--cc=haijie1@huawei.com \
--cc=thomas@monjalon.net \
--cc=yisen.zhuang@huawei.com \
--cc=yuying.zhang@intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).