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"
16 #define ILLEGAL_UDP_GSO_CTX(ctx) \
17 ((((ctx)->gso_types & DEV_TX_OFFLOAD_UDP_TSO) == 0) || \
18 (ctx)->gso_size < RTE_GSO_UDP_SEG_SIZE_MIN)
20 #define ILLEGAL_TCP_GSO_CTX(ctx) \
21 ((((ctx)->gso_types & (DEV_TX_OFFLOAD_TCP_TSO | \
22 DEV_TX_OFFLOAD_VXLAN_TNL_TSO | \
23 DEV_TX_OFFLOAD_GRE_TNL_TSO)) == 0) || \
24 (ctx)->gso_size < RTE_GSO_SEG_SIZE_MIN)
27 rte_gso_segment(struct rte_mbuf *pkt,
28 const struct rte_gso_ctx *gso_ctx,
29 struct rte_mbuf **pkts_out,
32 struct rte_mempool *direct_pool, *indirect_pool;
33 struct rte_mbuf *pkt_seg;
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));
51 direct_pool = gso_ctx->direct_pool;
52 indirect_pool = gso_ctx->indirect_pool;
53 gso_size = gso_ctx->gso_size;
54 ipid_delta = (gso_ctx->flag != RTE_GSO_FLAG_IPID_FIXED);
55 ol_flags = pkt->ol_flags;
57 if ((IS_IPV4_VXLAN_TCP4(pkt->ol_flags) &&
58 (gso_ctx->gso_types & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) ||
59 ((IS_IPV4_GRE_TCP4(pkt->ol_flags) &&
60 (gso_ctx->gso_types & DEV_TX_OFFLOAD_GRE_TNL_TSO)))) {
61 pkt->ol_flags &= (~PKT_TX_TCP_SEG);
62 ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
63 direct_pool, indirect_pool,
64 pkts_out, nb_pkts_out);
65 } else if (IS_IPV4_TCP(pkt->ol_flags) &&
66 (gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO)) {
67 pkt->ol_flags &= (~PKT_TX_TCP_SEG);
68 ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
69 direct_pool, indirect_pool,
70 pkts_out, nb_pkts_out);
71 } else if (IS_IPV4_UDP(pkt->ol_flags) &&
72 (gso_ctx->gso_types & DEV_TX_OFFLOAD_UDP_TSO)) {
73 pkt->ol_flags &= (~PKT_TX_UDP_SEG);
74 ret = gso_udp4_segment(pkt, gso_size, direct_pool,
75 indirect_pool, pkts_out, nb_pkts_out);
77 /* unsupported packet, skip */
79 RTE_LOG(DEBUG, GSO, "Unsupported packet type\n");
86 rte_mbuf_refcnt_update(pkt_seg, -1);
87 pkt_seg = pkt_seg->next;
90 /* Revert the ol_flags in the event of failure. */
91 pkt->ol_flags = ol_flags;