4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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.
38 #include <rte_memory.h>
40 #include <rte_byteorder.h>
42 #include "rte_ip_frag.h"
43 #include "ip_frag_common.h"
45 #define IP_FRAG_HASH_FNUM 2
47 /* free mbufs from death row */
49 rte_ip_frag_free_death_row(struct rte_ip_frag_death_row *dr,
54 k = RTE_MIN(prefetch, dr->cnt);
57 for (i = 0; i != k; i++)
58 rte_prefetch0(dr->row[i]);
60 for (i = 0; i != n - k; i++) {
61 rte_prefetch0(dr->row[i + k]);
62 rte_pktmbuf_free(dr->row[i]);
66 rte_pktmbuf_free(dr->row[i]);
71 /* create fragmentation table */
72 struct rte_ip_frag_tbl *
73 rte_ip_frag_table_create(uint32_t bucket_num, uint32_t bucket_entries,
74 uint32_t max_entries, uint64_t max_cycles, int socket_id)
76 struct rte_ip_frag_tbl *tbl;
80 nb_entries = rte_align32pow2(bucket_num);
81 nb_entries *= bucket_entries;
82 nb_entries *= IP_FRAG_HASH_FNUM;
84 /* check input parameters. */
85 if (rte_is_power_of_2(bucket_entries) == 0 ||
86 nb_entries > UINT32_MAX || nb_entries == 0 ||
87 nb_entries < max_entries) {
88 RTE_LOG(ERR, USER1, "%s: invalid input parameter\n", __func__);
92 sz = sizeof (*tbl) + nb_entries * sizeof (tbl->pkt[0]);
93 if ((tbl = rte_zmalloc_socket(__func__, sz, CACHE_LINE_SIZE,
94 socket_id)) == NULL) {
96 "%s: allocation of %zu bytes at socket %d failed do\n",
97 __func__, sz, socket_id);
101 RTE_LOG(INFO, USER1, "%s: allocated of %zu bytes at socket %d\n",
102 __func__, sz, socket_id);
104 tbl->max_cycles = max_cycles;
105 tbl->max_entries = max_entries;
106 tbl->nb_entries = (uint32_t)nb_entries;
107 tbl->nb_buckets = bucket_num;
108 tbl->bucket_entries = bucket_entries;
109 tbl->entry_mask = (tbl->nb_entries - 1) & ~(tbl->bucket_entries - 1);
111 TAILQ_INIT(&(tbl->lru));
115 /* dump frag table statistics to file */
117 rte_ip_frag_table_statistics_dump(FILE *f, const struct rte_ip_frag_tbl *tbl)
119 uint64_t fail_total, fail_nospace;
121 fail_total = tbl->stat.fail_total;
122 fail_nospace = tbl->stat.fail_nospace;
124 fprintf(f, "max entries:\t%u;\n"
125 "entries in use:\t%u;\n"
126 "finds/inserts:\t%" PRIu64 ";\n"
127 "entries added:\t%" PRIu64 ";\n"
128 "entries deleted by timeout:\t%" PRIu64 ";\n"
129 "entries reused by timeout:\t%" PRIu64 ";\n"
130 "total add failures:\t%" PRIu64 ";\n"
131 "add no-space failures:\t%" PRIu64 ";\n"
132 "add hash-collisions failures:\t%" PRIu64 ";\n",
141 fail_total - fail_nospace);