diff mbox series

[ovs-dev,v5,04/12] dp-packet: Expand offloads preparation helper.

Message ID 20250603094637.1250238-5-david.marchand@redhat.com
State Superseded
Delegated to: Ilya Maximets
Headers show
Series OVS checksum offloads revamp. | expand

Checks

Context Check Description
ovsrobot/apply-robot success apply and check: success
ovsrobot/github-robot-_Build_and_Test success github build: passed
ovsrobot/github-robot-_Build_and_Test success github build: passed

Commit Message

David Marchand June 3, 2025, 9:46 a.m. UTC
Expand this helper to clearly separate the non tunnel case from the
tunnel one. This will make later changes easier to read.

Signed-off-by: David Marchand <david.marchand@redhat.com>
---
 lib/dp-packet.c | 120 +++++++++++++++++++++++++++---------------------
 lib/dp-packet.h |   1 -
 2 files changed, 67 insertions(+), 54 deletions(-)
diff mbox series

Patch

diff --git a/lib/dp-packet.c b/lib/dp-packet.c
index 313f783224..a7e3fb82bb 100644
--- a/lib/dp-packet.c
+++ b/lib/dp-packet.c
@@ -551,44 +551,56 @@  dp_packet_compare_offsets(struct dp_packet *b1, struct dp_packet *b2,
     return true;
 }
 
-void
-dp_packet_tnl_outer_ol_send_prepare(struct dp_packet *p,
-                                    uint64_t flags)
-{
-    if (dp_packet_hwol_is_outer_ipv4_cksum(p)) {
-        if (!(flags & NETDEV_TX_OFFLOAD_OUTER_IP_CKSUM)) {
-            dp_packet_ip_set_header_csum(p, false);
-            dp_packet_ol_set_ip_csum_good(p);
-            dp_packet_hwol_reset_outer_ipv4_csum(p);
-        }
-    }
-
-    if (!dp_packet_hwol_is_outer_udp_cksum(p)) {
-        return;
-    }
-
-    if (!(flags & NETDEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
-        packet_udp_complete_csum(p, false);
-        dp_packet_ol_set_l4_csum_good(p);
-        dp_packet_hwol_reset_outer_udp_csum(p);
-    }
-}
-
 /* Checks if the packet 'p' is compatible with netdev_ol_flags 'flags'
  * and if not, updates the packet with the software fall back. */
 void
 dp_packet_ol_send_prepare(struct dp_packet *p, uint64_t flags)
 {
-    bool tnl_inner = false;
-
     if (!dp_packet_hwol_tx_is_any_csum(p)) {
         /* Only checksumming needs actions. */
         return;
     }
 
+    if (!dp_packet_hwol_is_tunnel(p)) {
+        if (dp_packet_hwol_tx_ip_csum(p)) {
+            if (dp_packet_ip_checksum_good(p)) {
+                dp_packet_hwol_reset_tx_ip_csum(p);
+            } else if (!(flags & NETDEV_TX_OFFLOAD_IPV4_CKSUM)) {
+                dp_packet_ip_set_header_csum(p, false);
+                dp_packet_ol_set_ip_csum_good(p);
+                dp_packet_hwol_reset_tx_ip_csum(p);
+            }
+        }
+
+        if (dp_packet_hwol_tx_l4_checksum(p)) {
+            if (dp_packet_l4_checksum_good(p)) {
+                dp_packet_hwol_reset_tx_l4_csum(p);
+                return;
+            }
+
+            if (dp_packet_hwol_l4_is_tcp(p)
+                && !(flags & NETDEV_TX_OFFLOAD_TCP_CKSUM)) {
+                packet_tcp_complete_csum(p, false);
+                dp_packet_ol_set_l4_csum_good(p);
+                dp_packet_hwol_reset_tx_l4_csum(p);
+            } else if (dp_packet_hwol_l4_is_udp(p)
+                       && !(flags & NETDEV_TX_OFFLOAD_UDP_CKSUM)) {
+                packet_udp_complete_csum(p, false);
+                dp_packet_ol_set_l4_csum_good(p);
+                dp_packet_hwol_reset_tx_l4_csum(p);
+            } else if (!(flags & NETDEV_TX_OFFLOAD_SCTP_CKSUM)
+                       && dp_packet_hwol_l4_is_sctp(p)) {
+                packet_sctp_complete_csum(p, false);
+                dp_packet_ol_set_l4_csum_good(p);
+                dp_packet_hwol_reset_tx_l4_csum(p);
+            }
+        }
+
+        return;
+    }
+
     if (dp_packet_hwol_is_tunnel_geneve(p) ||
         dp_packet_hwol_is_tunnel_vxlan(p)) {
-        tnl_inner = true;
 
         /* If the TX interface doesn't support UDP tunnel offload but does
          * support inner checksum offload and an outer UDP checksum is
@@ -601,50 +613,52 @@  dp_packet_ol_send_prepare(struct dp_packet *p, uint64_t flags)
                        NETDEV_TX_OFFLOAD_SCTP_CKSUM |
                        NETDEV_TX_OFFLOAD_IPV4_CKSUM);
         }
-    } else if (dp_packet_hwol_is_tunnel_gre(p)) {
-        tnl_inner = true;
     }
 
     if (dp_packet_hwol_tx_ip_csum(p)) {
         if (dp_packet_ip_checksum_good(p)) {
             dp_packet_hwol_reset_tx_ip_csum(p);
         } else if (!(flags & NETDEV_TX_OFFLOAD_IPV4_CKSUM)) {
-            dp_packet_ip_set_header_csum(p, tnl_inner);
+            dp_packet_ip_set_header_csum(p, true);
             dp_packet_ol_set_ip_csum_good(p);
             dp_packet_hwol_reset_tx_ip_csum(p);
         }
     }
 
-    if (!dp_packet_hwol_tx_l4_checksum(p)) {
-        if (tnl_inner) {
-            dp_packet_tnl_outer_ol_send_prepare(p, flags);
+    if (dp_packet_hwol_tx_l4_checksum(p)) {
+        if (dp_packet_hwol_l4_is_tcp(p)
+            && !(flags & NETDEV_TX_OFFLOAD_TCP_CKSUM)) {
+            packet_tcp_complete_csum(p, true);
+            dp_packet_ol_set_l4_csum_good(p);
+            dp_packet_hwol_reset_tx_l4_csum(p);
+        } else if (dp_packet_hwol_l4_is_udp(p)
+                   && !(flags & NETDEV_TX_OFFLOAD_UDP_CKSUM)) {
+            packet_udp_complete_csum(p, true);
+            dp_packet_ol_set_l4_csum_good(p);
+            dp_packet_hwol_reset_tx_l4_csum(p);
+        } else if (!(flags & NETDEV_TX_OFFLOAD_SCTP_CKSUM)
+                   && dp_packet_hwol_l4_is_sctp(p)) {
+            packet_sctp_complete_csum(p, true);
+            dp_packet_ol_set_l4_csum_good(p);
+            dp_packet_hwol_reset_tx_l4_csum(p);
         }
-        return;
     }
 
-    if (dp_packet_l4_checksum_good(p) && !tnl_inner) {
-        dp_packet_hwol_reset_tx_l4_csum(p);
-        return;
+    if (dp_packet_hwol_is_outer_ipv4_cksum(p)) {
+        if (!(flags & NETDEV_TX_OFFLOAD_OUTER_IP_CKSUM)) {
+            dp_packet_ip_set_header_csum(p, false);
+            dp_packet_ol_set_ip_csum_good(p);
+            dp_packet_hwol_reset_outer_ipv4_csum(p);
+        }
     }
 
-    if (dp_packet_hwol_l4_is_tcp(p)
-        && !(flags & NETDEV_TX_OFFLOAD_TCP_CKSUM)) {
-        packet_tcp_complete_csum(p, tnl_inner);
-        dp_packet_ol_set_l4_csum_good(p);
-        dp_packet_hwol_reset_tx_l4_csum(p);
-    } else if (dp_packet_hwol_l4_is_udp(p)
-               && !(flags & NETDEV_TX_OFFLOAD_UDP_CKSUM)) {
-        packet_udp_complete_csum(p, tnl_inner);
-        dp_packet_ol_set_l4_csum_good(p);
-        dp_packet_hwol_reset_tx_l4_csum(p);
-    } else if (!(flags & NETDEV_TX_OFFLOAD_SCTP_CKSUM)
-               && dp_packet_hwol_l4_is_sctp(p)) {
-        packet_sctp_complete_csum(p, tnl_inner);
-        dp_packet_ol_set_l4_csum_good(p);
-        dp_packet_hwol_reset_tx_l4_csum(p);
+    if (!dp_packet_hwol_is_outer_udp_cksum(p)) {
+        return;
     }
 
-    if (tnl_inner) {
-        dp_packet_tnl_outer_ol_send_prepare(p, flags);
+    if (!(flags & NETDEV_TX_OFFLOAD_OUTER_UDP_CKSUM)) {
+        packet_udp_complete_csum(p, false);
+        dp_packet_ol_set_l4_csum_good(p);
+        dp_packet_hwol_reset_outer_udp_csum(p);
     }
 }
diff --git a/lib/dp-packet.h b/lib/dp-packet.h
index 3c7dd86d45..003013da95 100644
--- a/lib/dp-packet.h
+++ b/lib/dp-packet.h
@@ -281,7 +281,6 @@  bool dp_packet_compare_offsets(struct dp_packet *good,
                                struct dp_packet *test,
                                struct ds *err_str);
 void dp_packet_ol_send_prepare(struct dp_packet *, uint64_t);
-void dp_packet_tnl_outer_ol_send_prepare(struct dp_packet *, uint64_t);
 
 
 /* Frees memory that 'b' points to, as well as 'b' itself. */