1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2017 Intel Corporation
8 #include <rte_ethdev.h>
11 #include "gso_common.h"
13 #include "gso_tunnel_tcp4.h"
14 #include "gso_tunnel_udp4.h"
17 #define ILLEGAL_UDP_GSO_CTX(ctx) \
18 ((((ctx)->gso_types & DEV_TX_OFFLOAD_UDP_TSO) == 0) || \
19 (ctx)->gso_size < RTE_GSO_UDP_SEG_SIZE_MIN)
21 #define ILLEGAL_TCP_GSO_CTX(ctx) \
22 ((((ctx)->gso_types & (DEV_TX_OFFLOAD_TCP_TSO | \
23 DEV_TX_OFFLOAD_VXLAN_TNL_TSO | \
24 DEV_TX_OFFLOAD_GRE_TNL_TSO)) == 0) || \
25 (ctx)->gso_size < RTE_GSO_SEG_SIZE_MIN)
28 rte_gso_segment(struct rte_mbuf *pkt,
29 const struct rte_gso_ctx *gso_ctx,
30 struct rte_mbuf **pkts_out,
33 struct rte_mempool *direct_pool, *indirect_pool;
39 if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
41 (ILLEGAL_UDP_GSO_CTX(gso_ctx) &&
42 ILLEGAL_TCP_GSO_CTX(gso_ctx)))
45 if (gso_ctx->gso_size >= pkt->pkt_len) {
46 pkt->ol_flags &= (~(PKT_TX_TCP_SEG | PKT_TX_UDP_SEG));
50 direct_pool = gso_ctx->direct_pool;
51 indirect_pool = gso_ctx->indirect_pool;
52 gso_size = gso_ctx->gso_size;
53 ipid_delta = (gso_ctx->flag != RTE_GSO_FLAG_IPID_FIXED);
54 ol_flags = pkt->ol_flags;
56 if ((IS_IPV4_VXLAN_TCP4(pkt->ol_flags) &&
57 (gso_ctx->gso_types & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) ||
58 ((IS_IPV4_GRE_TCP4(pkt->ol_flags) &&
59 (gso_ctx->gso_types & DEV_TX_OFFLOAD_GRE_TNL_TSO)))) {
60 pkt->ol_flags &= (~PKT_TX_TCP_SEG);
61 ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
62 direct_pool, indirect_pool,
63 pkts_out, nb_pkts_out);
64 } else if (IS_IPV4_VXLAN_UDP4(pkt->ol_flags) &&
65 (gso_ctx->gso_types & DEV_TX_OFFLOAD_VXLAN_TNL_TSO) &&
66 (gso_ctx->gso_types & DEV_TX_OFFLOAD_UDP_TSO)) {
67 pkt->ol_flags &= (~PKT_TX_UDP_SEG);
68 ret = gso_tunnel_udp4_segment(pkt, gso_size,
69 direct_pool, indirect_pool,
70 pkts_out, nb_pkts_out);
71 } else if (IS_IPV4_TCP(pkt->ol_flags) &&
72 (gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO)) {
73 pkt->ol_flags &= (~PKT_TX_TCP_SEG);
74 ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
75 direct_pool, indirect_pool,
76 pkts_out, nb_pkts_out);
77 } else if (IS_IPV4_UDP(pkt->ol_flags) &&
78 (gso_ctx->gso_types & DEV_TX_OFFLOAD_UDP_TSO)) {
79 pkt->ol_flags &= (~PKT_TX_UDP_SEG);
80 ret = gso_udp4_segment(pkt, gso_size, direct_pool,
81 indirect_pool, pkts_out, nb_pkts_out);
83 /* unsupported packet, skip */
84 RTE_LOG(DEBUG, GSO, "Unsupported packet type\n");
89 /* Revert the ol_flags in the event of failure. */
90 pkt->ol_flags = ol_flags;