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;
38 if (pkt == NULL || pkts_out == NULL || gso_ctx == NULL ||
40 (ILLEGAL_UDP_GSO_CTX(gso_ctx) &&
41 ILLEGAL_TCP_GSO_CTX(gso_ctx)))
44 if (gso_ctx->gso_size >= pkt->pkt_len) {
45 pkt->ol_flags &= (~(PKT_TX_TCP_SEG | PKT_TX_UDP_SEG));
49 direct_pool = gso_ctx->direct_pool;
50 indirect_pool = gso_ctx->indirect_pool;
51 gso_size = gso_ctx->gso_size;
52 ipid_delta = (gso_ctx->flag != RTE_GSO_FLAG_IPID_FIXED);
53 ol_flags = pkt->ol_flags;
55 if ((IS_IPV4_VXLAN_TCP4(pkt->ol_flags) &&
56 (gso_ctx->gso_types & DEV_TX_OFFLOAD_VXLAN_TNL_TSO)) ||
57 ((IS_IPV4_GRE_TCP4(pkt->ol_flags) &&
58 (gso_ctx->gso_types & DEV_TX_OFFLOAD_GRE_TNL_TSO)))) {
59 pkt->ol_flags &= (~PKT_TX_TCP_SEG);
60 ret = gso_tunnel_tcp4_segment(pkt, gso_size, ipid_delta,
61 direct_pool, indirect_pool,
62 pkts_out, nb_pkts_out);
63 } else if (IS_IPV4_TCP(pkt->ol_flags) &&
64 (gso_ctx->gso_types & DEV_TX_OFFLOAD_TCP_TSO)) {
65 pkt->ol_flags &= (~PKT_TX_TCP_SEG);
66 ret = gso_tcp4_segment(pkt, gso_size, ipid_delta,
67 direct_pool, indirect_pool,
68 pkts_out, nb_pkts_out);
69 } else if (IS_IPV4_UDP(pkt->ol_flags) &&
70 (gso_ctx->gso_types & DEV_TX_OFFLOAD_UDP_TSO)) {
71 pkt->ol_flags &= (~PKT_TX_UDP_SEG);
72 ret = gso_udp4_segment(pkt, gso_size, direct_pool,
73 indirect_pool, pkts_out, nb_pkts_out);
75 /* unsupported packet, skip */
76 RTE_LOG(DEBUG, GSO, "Unsupported packet type\n");
81 /* Revert the ol_flags in the event of failure. */
82 pkt->ol_flags = ol_flags;