lib/gro: add Generic Receive Offload API framework
[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 0
49
50
51 struct rte_gro_param {
52         /**< desired GRO types */
53         uint64_t gro_types;
54         /**< max flow number */
55         uint16_t max_flow_num;
56         /**< max packet number per flow */
57         uint16_t max_item_per_flow;
58         /**< socket index for allocating GRO related data structures,
59          * like reassembly tables. When use rte_gro_reassemble_burst(),
60          * applications don't need to set this value.
61          */
62         uint16_t socket_id;
63 };
64
65 /**
66  * @warning
67  * @b EXPERIMENTAL: this API may change without prior notice
68  *
69  * This function create a GRO context object, which is used to merge
70  * packets in rte_gro_reassemble().
71  *
72  * @param param
73  *  applications use it to pass needed parameters to create a GRO
74  *  context object.
75  *
76  * @return
77  *  if create successfully, return a pointer which points to the GRO
78  *  context object. Otherwise, return NULL.
79  */
80 void *rte_gro_ctx_create(const struct rte_gro_param *param);
81
82 /**
83  * @warning
84  * @b EXPERIMENTAL: this API may change without prior notice
85  *
86  * This function destroys a GRO context object.
87  *
88  * @param ctx
89  *  pointer points to a GRO context object.
90  */
91 void rte_gro_ctx_destroy(void *ctx);
92
93 /**
94  * This is one of the main reassembly APIs, which merges numbers of
95  * packets at a time. It assumes that all inputted packets are with
96  * correct checksums. That is, applications should guarantee all
97  * inputted packets are correct. Besides, it doesn't re-calculate
98  * checksums for merged packets. If inputted packets are IP fragmented,
99  * this function assumes them are complete (i.e. with L4 header). After
100  * finishing processing, it returns all GROed packets to applications
101  * immediately.
102  *
103  * @param pkts
104  *  a pointer array which points to the packets to reassemble. Besides,
105  *  it keeps packet addresses for GROed packets.
106  * @param nb_pkts
107  *  the number of packets to reassemble.
108  * @param param
109  *  applications use it to tell rte_gro_reassemble_burst() what rules
110  *  are demanded.
111  *
112  * @return
113  *  the number of packets after been GROed. If no packets are merged,
114  *  the returned value is nb_pkts.
115  */
116 uint16_t rte_gro_reassemble_burst(struct rte_mbuf **pkts,
117                 uint16_t nb_pkts,
118                 const struct rte_gro_param *param);
119
120 /**
121  * @warning
122  * @b EXPERIMENTAL: this API may change without prior notice
123  *
124  * Reassembly function, which tries to merge inputted packets with
125  * the packets in the reassembly tables of a given GRO context. This
126  * function assumes all inputted packets are with correct checksums.
127  * And it won't update checksums if two packets are merged. Besides,
128  * if inputted packets are IP fragmented, this function assumes they
129  * are complete packets (i.e. with L4 header).
130  *
131  * If the inputted packets don't have data or are with unsupported GRO
132  * types etc., they won't be processed and are returned to applications.
133  * Otherwise, the inputted packets are either merged or inserted into
134  * the table. If applications want get packets in the table, they need
135  * to call flush API.
136  *
137  * @param pkts
138  *  packet to reassemble. Besides, after this function finishes, it
139  *  keeps the unprocessed packets (e.g. without data or unsupported
140  *  GRO types).
141  * @param nb_pkts
142  *  the number of packets to reassemble.
143  * @param ctx
144  *  a pointer points to a GRO context object.
145  *
146  * @return
147  *  return the number of unprocessed packets (e.g. without data or
148  *  unsupported GRO types). If all packets are processed (merged or
149  *  inserted into the table), return 0.
150  */
151 uint16_t rte_gro_reassemble(struct rte_mbuf **pkts,
152                 uint16_t nb_pkts,
153                 void *ctx);
154
155 /**
156  * @warning
157  * @b EXPERIMENTAL: this API may change without prior notice
158  *
159  * This function flushes the timeout packets from reassembly tables of
160  * desired GRO types. The max number of flushed timeout packets is the
161  * element number of the array which is used to keep the flushed packets.
162  *
163  * Besides, this function won't re-calculate checksums for merged
164  * packets in the tables. That is, the returned packets may be with
165  * wrong checksums.
166  *
167  * @param ctx
168  *  a pointer points to a GRO context object.
169  * @param timeout_cycles
170  *  max TTL for packets in reassembly tables, measured in nanosecond.
171  * @param gro_types
172  *  this function only flushes packets which belong to the GRO types
173  *  specified by gro_types.
174  * @param out
175  *  a pointer array that is used to keep flushed timeout packets.
176  * @param nb_out
177  *  the element number of out. It's also the max number of timeout
178  *  packets that can be flushed finally.
179  *
180  * @return
181  *  the number of flushed packets. If no packets are flushed, return 0.
182  */
183 uint16_t rte_gro_timeout_flush(void *ctx,
184                 uint64_t timeout_cycles,
185                 uint64_t gro_types,
186                 struct rte_mbuf **out,
187                 uint16_t max_nb_out);
188
189 /**
190  * @warning
191  * @b EXPERIMENTAL: this API may change without prior notice
192  *
193  * This function returns the number of packets in all reassembly tables
194  * of a given GRO context.
195  *
196  * @param ctx
197  *  pointer points to a GRO context object.
198  *
199  * @return
200  *  the number of packets in all reassembly tables.
201  */
202 uint64_t rte_gro_get_pkt_count(void *ctx);
203
204 #ifdef __cplusplus
205 }
206 #endif
207
208 #endif /* _RTE_GRO_H_ */