dpdk/lib/gso/rte_gso.h
<<
>>
Prefs
   1/* SPDX-License-Identifier: BSD-3-Clause
   2 * Copyright(c) 2017 Intel Corporation
   3 */
   4
   5#ifndef _RTE_GSO_H_
   6#define _RTE_GSO_H_
   7
   8/**
   9 * @file
  10 * Interface to GSO library
  11 */
  12
  13#ifdef __cplusplus
  14extern "C" {
  15#endif
  16
  17#include <stdint.h>
  18#include <rte_mbuf.h>
  19
  20/* Minimum GSO segment size for TCP based packets. */
  21#define RTE_GSO_SEG_SIZE_MIN (sizeof(struct rte_ether_hdr) + \
  22                sizeof(struct rte_ipv4_hdr) + sizeof(struct rte_tcp_hdr) + 1)
  23
  24/* Minimum GSO segment size for UDP based packets. */
  25#define RTE_GSO_UDP_SEG_SIZE_MIN (sizeof(struct rte_ether_hdr) + \
  26                sizeof(struct rte_ipv4_hdr) + sizeof(struct rte_udp_hdr) + 1)
  27
  28/* GSO flags for rte_gso_ctx. */
  29#define RTE_GSO_FLAG_IPID_FIXED (1ULL << 0)
  30/**< Use fixed IP ids for output GSO segments. Setting
  31 * 0 indicates using incremental IP ids.
  32 */
  33
  34/**
  35 * GSO context structure.
  36 */
  37struct rte_gso_ctx {
  38        struct rte_mempool *direct_pool;
  39        /**< MBUF pool for allocating direct buffers, which are used
  40         * to store packet headers for GSO segments.
  41         */
  42        struct rte_mempool *indirect_pool;
  43        /**< MBUF pool for allocating indirect buffers, which are used
  44         * to locate packet payloads for GSO segments. The indirect
  45         * buffer doesn't contain any data, but simply points to an
  46         * offset within the packet to segment.
  47         */
  48        uint64_t flag;
  49        /**< flag that controls specific attributes of output segments,
  50         * such as the type of IP ID generated (i.e. fixed or incremental).
  51         */
  52        uint32_t gso_types;
  53        /**< the bit mask of required GSO types. The GSO library
  54         * uses the same macros as that of describing device TX
  55         * offloading capabilities (i.e. DEV_TX_OFFLOAD_*_TSO) for
  56         * gso_types.
  57         *
  58         * For example, if applications want to segment TCP/IPv4
  59         * packets, set DEV_TX_OFFLOAD_TCP_TSO in gso_types.
  60         */
  61        uint16_t gso_size;
  62        /**< maximum size of an output GSO segment, including packet
  63         * header and payload, measured in bytes. Must exceed
  64         * RTE_GSO_SEG_SIZE_MIN.
  65         */
  66};
  67
  68/**
  69 * Segmentation function, which supports processing of both single- and
  70 * multi- MBUF packets.
  71 *
  72 * Note that we refer to the packets that are segmented from the input
  73 * packet as 'GSO segments'. rte_gso_segment() doesn't check if the
  74 * input packet has correct checksums, and doesn't update checksums for
  75 * output GSO segments. Additionally, it doesn't process IP fragment
  76 * packets.
  77 *
  78 * Before calling rte_gso_segment(), applications must set proper ol_flags
  79 * for the packet. The GSO library uses the same macros as that of TSO.
  80 * For example, set PKT_TX_TCP_SEG and PKT_TX_IPV4 in ol_flags to segment
  81 * a TCP/IPv4 packet. If rte_gso_segment() succeeds, the PKT_TX_TCP_SEG
  82 * flag is removed for all GSO segments and the input packet.
  83 *
  84 * Each of the newly-created GSO segments is organized as a two-segment
  85 * MBUF, where the first segment is a standard MBUF, which stores a copy
  86 * of packet header, and the second is an indirect MBUF which points to
  87 * a section of data in the input packet. Since each GSO segment has
  88 * multiple MBUFs (i.e. typically 2 MBUFs), the driver of the interface which
  89 * the GSO segments are sent to should support transmission of multi-segment
  90 * packets.
  91 *
  92 * If the input packet is GSO'd, all the indirect segments are attached to the
  93 * input packet.
  94 *
  95 * rte_gso_segment() will not free the input packet no matter whether it is
  96 * GSO'd or not, the application should free it after calling rte_gso_segment().
  97 *
  98 * If the memory space in pkts_out or MBUF pools is insufficient, this
  99 * function fails, and it returns (-1) * errno. Otherwise, GSO succeeds,
 100 * and this function returns the number of output GSO segments filled in
 101 * pkts_out.
 102 *
 103 * @param pkt
 104 *  The packet mbuf to segment.
 105 * @param ctx
 106 *  GSO context object pointer.
 107 * @param pkts_out
 108 *  Pointer array used to store the MBUF addresses of output GSO
 109 *  segments, when rte_gso_segment() succeeds.
 110 * @param nb_pkts_out
 111 *  The max number of items that pkts_out can keep.
 112 *
 113 * @return
 114 *  - The number of GSO segments filled in pkts_out on success.
 115 *  - Return 0 if it does not need to be GSO'd.
 116 *  - Return -ENOMEM if run out of memory in MBUF pools.
 117 *  - Return -EINVAL for invalid parameters.
 118 */
 119int rte_gso_segment(struct rte_mbuf *pkt,
 120                const struct rte_gso_ctx *ctx,
 121                struct rte_mbuf **pkts_out,
 122                uint16_t nb_pkts_out);
 123#ifdef __cplusplus
 124}
 125#endif
 126
 127#endif /* _RTE_GSO_H_ */
 128