9d3b4fc82e69373ef49d2cac3006108cc65dcb17
[dpdk.git] / lib / librte_gso / rte_gso.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2017 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33
34 #ifndef _RTE_GSO_H_
35 #define _RTE_GSO_H_
36
37 /**
38  * @file
39  * Interface to GSO library
40  */
41
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45
46 #include <stdint.h>
47 #include <rte_mbuf.h>
48
49 /* GSO flags for rte_gso_ctx. */
50 #define RTE_GSO_FLAG_IPID_FIXED (1ULL << 0)
51 /**< Use fixed IP ids for output GSO segments. Setting
52  * 0 indicates using incremental IP ids.
53  */
54
55 /**
56  * GSO context structure.
57  */
58 struct rte_gso_ctx {
59         struct rte_mempool *direct_pool;
60         /**< MBUF pool for allocating direct buffers, which are used
61          * to store packet headers for GSO segments.
62          */
63         struct rte_mempool *indirect_pool;
64         /**< MBUF pool for allocating indirect buffers, which are used
65          * to locate packet payloads for GSO segments. The indirect
66          * buffer doesn't contain any data, but simply points to an
67          * offset within the packet to segment.
68          */
69         uint64_t flag;
70         /**< flag that controls specific attributes of output segments,
71          * such as the type of IP ID generated (i.e. fixed or incremental).
72          */
73         uint32_t gso_types;
74         /**< the bit mask of required GSO types. The GSO library
75          * uses the same macros as that of describing device TX
76          * offloading capabilities (i.e. DEV_TX_OFFLOAD_*_TSO) for
77          * gso_types.
78          *
79          * For example, if applications want to segment TCP/IPv4
80          * packets, set DEV_TX_OFFLOAD_TCP_TSO in gso_types.
81          */
82         uint16_t gso_size;
83         /**< maximum size of an output GSO segment, including packet
84          * header and payload, measured in bytes.
85          */
86 };
87
88 /**
89  * Segmentation function, which supports processing of both single- and
90  * multi- MBUF packets.
91  *
92  * Note that we refer to the packets that are segmented from the input
93  * packet as 'GSO segments'. rte_gso_segment() doesn't check if the
94  * input packet has correct checksums, and doesn't update checksums for
95  * output GSO segments. Additionally, it doesn't process IP fragment
96  * packets.
97  *
98  * Before calling rte_gso_segment(), applications must set proper ol_flags
99  * for the packet. The GSO library uses the same macros as that of TSO.
100  * For example, set PKT_TX_TCP_SEG and PKT_TX_IPV4 in ol_flags to segment
101  * a TCP/IPv4 packet. If rte_gso_segment() succceds, the PKT_TX_TCP_SEG
102  * flag is removed for all GSO segments and the input packet.
103  *
104  * Each of the newly-created GSO segments is organized as a two-segment
105  * MBUF, where the first segment is a standard MBUF, which stores a copy
106  * of packet header, and the second is an indirect MBUF which points to
107  * a section of data in the input packet. Since each GSO segment has
108  * multiple MBUFs (i.e. typically 2 MBUFs), the driver of the interface which
109  * the GSO segments are sent to should support transmission of multi-segment
110  * packets.
111  *
112  * If the input packet is GSO'd, its mbuf refcnt reduces by 1. Therefore,
113  * when all GSO segments are freed, the input packet is freed automatically.
114  *
115  * If the memory space in pkts_out or MBUF pools is insufficient, this
116  * function fails, and it returns (-1) * errno. Otherwise, GSO succeeds,
117  * and this function returns the number of output GSO segments filled in
118  * pkts_out.
119  *
120  * @param pkt
121  *  The packet mbuf to segment.
122  * @param ctx
123  *  GSO context object pointer.
124  * @param pkts_out
125  *  Pointer array used to store the MBUF addresses of output GSO
126  *  segments, when rte_gso_segment() succeeds.
127  * @param nb_pkts_out
128  *  The max number of items that pkts_out can keep.
129  *
130  * @return
131  *  - The number of GSO segments filled in pkts_out on success.
132  *  - Return -ENOMEM if run out of memory in MBUF pools.
133  *  - Return -EINVAL for invalid parameters.
134  */
135 int rte_gso_segment(struct rte_mbuf *pkt,
136                 const struct rte_gso_ctx *ctx,
137                 struct rte_mbuf **pkts_out,
138                 uint16_t nb_pkts_out);
139 #ifdef __cplusplus
140 }
141 #endif
142
143 #endif /* _RTE_GSO_H_ */