4 * Copyright(c) 2017 Intel Corporation. All rights reserved.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
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
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.
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.
33 #include <rte_malloc.h>
38 typedef void *(*gro_tbl_create_fn)(uint16_t socket_id,
39 uint16_t max_flow_num,
40 uint16_t max_item_per_flow);
41 typedef void (*gro_tbl_destroy_fn)(void *tbl);
42 typedef uint32_t (*gro_tbl_pkt_count_fn)(void *tbl);
44 static gro_tbl_create_fn tbl_create_fn[RTE_GRO_TYPE_MAX_NUM];
45 static gro_tbl_destroy_fn tbl_destroy_fn[RTE_GRO_TYPE_MAX_NUM];
46 static gro_tbl_pkt_count_fn tbl_pkt_count_fn[RTE_GRO_TYPE_MAX_NUM];
49 * GRO context structure, which is used to merge packets. It keeps
50 * many reassembly tables of desired GRO types. Applications need to
51 * create GRO context objects before using rte_gro_reassemble to
55 /* GRO types to perform */
57 /* reassembly tables */
58 void *tbls[RTE_GRO_TYPE_MAX_NUM];
62 rte_gro_ctx_create(const struct rte_gro_param *param)
64 struct gro_ctx *gro_ctx;
65 gro_tbl_create_fn create_tbl_fn;
66 uint64_t gro_type_flag = 0;
67 uint64_t gro_types = 0;
70 gro_ctx = rte_zmalloc_socket(__func__,
71 sizeof(struct gro_ctx),
77 for (i = 0; i < RTE_GRO_TYPE_MAX_NUM; i++) {
78 gro_type_flag = 1 << i;
79 if ((param->gro_types & gro_type_flag) == 0)
82 create_tbl_fn = tbl_create_fn[i];
83 if (create_tbl_fn == NULL)
86 gro_ctx->tbls[i] = create_tbl_fn(param->socket_id,
88 param->max_item_per_flow);
89 if (gro_ctx->tbls[i] == NULL) {
90 /* destroy all created tables */
91 gro_ctx->gro_types = gro_types;
92 rte_gro_ctx_destroy(gro_ctx);
95 gro_types |= gro_type_flag;
97 gro_ctx->gro_types = param->gro_types;
103 rte_gro_ctx_destroy(void *ctx)
105 gro_tbl_destroy_fn destroy_tbl_fn;
106 struct gro_ctx *gro_ctx = ctx;
107 uint64_t gro_type_flag;
112 for (i = 0; i < RTE_GRO_TYPE_MAX_NUM; i++) {
113 gro_type_flag = 1 << i;
114 if ((gro_ctx->gro_types & gro_type_flag) == 0)
116 destroy_tbl_fn = tbl_destroy_fn[i];
118 destroy_tbl_fn(gro_ctx->tbls[i]);
124 rte_gro_reassemble_burst(struct rte_mbuf **pkts __rte_unused,
126 const struct rte_gro_param *param __rte_unused)
132 rte_gro_reassemble(struct rte_mbuf **pkts __rte_unused,
134 void *ctx __rte_unused)
140 rte_gro_timeout_flush(void *ctx __rte_unused,
141 uint64_t timeout_cycles __rte_unused,
142 uint64_t gro_types __rte_unused,
143 struct rte_mbuf **out __rte_unused,
144 uint16_t max_nb_out __rte_unused)
150 rte_gro_get_pkt_count(void *ctx)
152 struct gro_ctx *gro_ctx = ctx;
153 gro_tbl_pkt_count_fn pkt_count_fn;
154 uint64_t item_num = 0;
155 uint64_t gro_type_flag;
158 for (i = 0; i < RTE_GRO_TYPE_MAX_NUM; i++) {
159 gro_type_flag = 1 << i;
160 if ((gro_ctx->gro_types & gro_type_flag) == 0)
163 pkt_count_fn = tbl_pkt_count_fn[i];
164 if (pkt_count_fn == NULL)
166 item_num += pkt_count_fn(gro_ctx->tbls[i]);