3b4fec03924b2c7d277987fe203f9ec94f3109e1
[dpdk.git] / lib / librte_gro / rte_gro.h
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2017 Intel Corporation. All rights reserved.
5  *
6  *   Redistribution and use in source and binary forms, with or without
7  *   modification, are permitted provided that the following conditions
8  *   are met:
9  *
10  *     * Redistributions of source code must retain the above copyright
11  *       notice, this list of conditions and the following disclaimer.
12  *     * Redistributions in binary form must reproduce the above copyright
13  *       notice, this list of conditions and the following disclaimer in
14  *       the documentation and/or other materials provided with the
15  *       distribution.
16  *     * Neither the name of Intel Corporation nor the names of its
17  *       contributors may be used to endorse or promote products derived
18  *       from this software without specific prior written permission.
19  *
20  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */
32
33 #ifndef _RTE_GRO_H_
34 #define _RTE_GRO_H_
35
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
39
40 /**< the max packets number that rte_gro_reassemble_burst()
41  * can process in each invocation.
42  */
43 #define RTE_GRO_MAX_BURST_ITEM_NUM 128U
44
45 /**< max number of supported GRO types */
46 #define RTE_GRO_TYPE_MAX_NUM 64
47 /**< current supported GRO num */
48 #define RTE_GRO_TYPE_SUPPORT_NUM 1
49
50 /**< TCP/IPv4 GRO flag */
51 #define RTE_GRO_TCP_IPV4_INDEX 0
52 #define RTE_GRO_TCP_IPV4 (1ULL << RTE_GRO_TCP_IPV4_INDEX)
53
54 struct rte_gro_param {
55         /**< desired GRO types */
56         uint64_t gro_types;
57         /**< max flow number */
58         uint16_t max_flow_num;
59         /**< max packet number per flow */
60         uint16_t max_item_per_flow;
61         /**< socket index for allocating GRO related data structures,
62          * like reassembly tables. When use rte_gro_reassemble_burst(),
63          * applications don't need to set this value.
64          */
65         uint16_t socket_id;
66 };
67
68 /**
69  * @warning
70  * @b EXPERIMENTAL: this API may change without prior notice
71  *
72  * This function create a GRO context object, which is used to merge
73  * packets in rte_gro_reassemble().
74  *
75  * @param param
76  *  applications use it to pass needed parameters to create a GRO
77  *  context object.
78  *
79  * @return
80  *  if create successfully, return a pointer which points to the GRO
81  *  context object. Otherwise, return NULL.
82  */
83 void *rte_gro_ctx_create(const struct rte_gro_param *param);
84
85 /**
86  * @warning
87  * @b EXPERIMENTAL: this API may change without prior notice
88  *
89  * This function destroys a GRO context object.
90  *
91  * @param ctx
92  *  pointer points to a GRO context object.
93  */
94 void rte_gro_ctx_destroy(void *ctx);
95
96 /**
97  * This is one of the main reassembly APIs, which merges numbers of
98  * packets at a time. It assumes that all inputted packets are with
99  * correct checksums. That is, applications should guarantee all
100  * inputted packets are correct. Besides, it doesn't re-calculate
101  * checksums for merged packets. If inputted packets are IP fragmented,
102  * this function assumes them are complete (i.e. with L4 header). After
103  * finishing processing, it returns all GROed packets to applications
104  * immediately.
105  *
106  * @param pkts
107  *  a pointer array which points to the packets to reassemble. Besides,
108  *  it keeps packet addresses for GROed packets.
109  * @param nb_pkts
110  *  the number of packets to reassemble.
111  * @param param
112  *  applications use it to tell rte_gro_reassemble_burst() what rules
113  *  are demanded.
114  *
115  * @return
116  *  the number of packets after been GROed. If no packets are merged,
117  *  the returned value is nb_pkts.
118  */
119 uint16_t rte_gro_reassemble_burst(struct rte_mbuf **pkts,
120                 uint16_t nb_pkts,
121                 const struct rte_gro_param *param);
122
123 /**
124  * @warning
125  * @b EXPERIMENTAL: this API may change without prior notice
126  *
127  * Reassembly function, which tries to merge inputted packets with
128  * the packets in the reassembly tables of a given GRO context. This
129  * function assumes all inputted packets are with correct checksums.
130  * And it won't update checksums if two packets are merged. Besides,
131  * if inputted packets are IP fragmented, this function assumes they
132  * are complete packets (i.e. with L4 header).
133  *
134  * If the inputted packets don't have data or are with unsupported GRO
135  * types etc., they won't be processed and are returned to applications.
136  * Otherwise, the inputted packets are either merged or inserted into
137  * the table. If applications want get packets in the table, they need
138  * to call flush API.
139  *
140  * @param pkts
141  *  packet to reassemble. Besides, after this function finishes, it
142  *  keeps the unprocessed packets (e.g. without data or unsupported
143  *  GRO types).
144  * @param nb_pkts
145  *  the number of packets to reassemble.
146  * @param ctx
147  *  a pointer points to a GRO context object.
148  *
149  * @return
150  *  return the number of unprocessed packets (e.g. without data or
151  *  unsupported GRO types). If all packets are processed (merged or
152  *  inserted into the table), return 0.
153  */
154 uint16_t rte_gro_reassemble(struct rte_mbuf **pkts,
155                 uint16_t nb_pkts,
156                 void *ctx);
157
158 /**
159  * @warning
160  * @b EXPERIMENTAL: this API may change without prior notice
161  *
162  * This function flushes the timeout packets from reassembly tables of
163  * desired GRO types. The max number of flushed timeout packets is the
164  * element number of the array which is used to keep the flushed packets.
165  *
166  * Besides, this function won't re-calculate checksums for merged
167  * packets in the tables. That is, the returned packets may be with
168  * wrong checksums.
169  *
170  * @param ctx
171  *  a pointer points to a GRO context object.
172  * @param timeout_cycles
173  *  max TTL for packets in reassembly tables, measured in nanosecond.
174  * @param gro_types
175  *  this function only flushes packets which belong to the GRO types
176  *  specified by gro_types.
177  * @param out
178  *  a pointer array that is used to keep flushed timeout packets.
179  * @param nb_out
180  *  the element number of out. It's also the max number of timeout
181  *  packets that can be flushed finally.
182  *
183  * @return
184  *  the number of flushed packets. If no packets are flushed, return 0.
185  */
186 uint16_t rte_gro_timeout_flush(void *ctx,
187                 uint64_t timeout_cycles,
188                 uint64_t gro_types,
189                 struct rte_mbuf **out,
190                 uint16_t max_nb_out);
191
192 /**
193  * @warning
194  * @b EXPERIMENTAL: this API may change without prior notice
195  *
196  * This function returns the number of packets in all reassembly tables
197  * of a given GRO context.
198  *
199  * @param ctx
200  *  pointer points to a GRO context object.
201  *
202  * @return
203  *  the number of packets in all reassembly tables.
204  */
205 uint64_t rte_gro_get_pkt_count(void *ctx);
206
207 #ifdef __cplusplus
208 }
209 #endif
210
211 #endif /* _RTE_GRO_H_ */