2 // Copyright (c) 2010-2017 Intel Corporation
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
16 #include <rte_common.h>
17 #include <rte_table_hash.h>
18 #include <rte_hash_crc.h>
19 #include "hash_utils.h"
21 /* This is a copy of the rte_table_hash_params from DPDK 17.11 *
22 * So if DPDK decides to change the structure the modifications *
23 * to PROX code should mainly be limited to this file *
25 struct prox_rte_table_params {
32 rte_table_hash_op_hash f_hash;
36 #if RTE_VERSION < RTE_VERSION_NUM(17,11,0,0)
38 static void *prox_rte_table_create(struct prox_rte_table_params *params, int socket_id, uint32_t entry_size)
40 if (params->key_size == 8) {
41 struct rte_table_hash_key8_ext_params dpdk17_08_params;
42 dpdk17_08_params.n_entries = params->n_keys;
43 dpdk17_08_params.n_entries_ext = params->n_keys >> 2;
44 dpdk17_08_params.f_hash = (rte_table_hash_op_hash)rte_hash_crc;
45 dpdk17_08_params.seed = params->seed;
46 dpdk17_08_params.signature_offset = HASH_METADATA_OFFSET(8); // Ignored for dosig
47 dpdk17_08_params.key_offset = HASH_METADATA_OFFSET(0);
48 dpdk17_08_params.key_mask = params->key_mask;
49 return rte_table_hash_key8_ext_dosig_ops.f_create(&dpdk17_08_params, socket_id, entry_size);
51 struct rte_table_hash_ext_params dpdk17_08_params;
52 dpdk17_08_params.key_size = params->key_size;
53 dpdk17_08_params.n_keys = params->n_keys;
54 dpdk17_08_params.n_buckets = params->n_buckets;
55 dpdk17_08_params.n_buckets_ext = params->n_buckets >> 1;
56 dpdk17_08_params.seed = params->seed;
57 dpdk17_08_params.f_hash = (rte_table_hash_op_hash)rte_hash_crc;
58 dpdk17_08_params.signature_offset = HASH_METADATA_OFFSET(0);
59 dpdk17_08_params.key_offset = HASH_METADATA_OFFSET(0);
60 return rte_table_hash_ext_dosig_ops.f_create(&dpdk17_08_params, socket_id, entry_size);
64 #define prox_rte_table_free rte_table_hash_ext_dosig_ops.f_free
65 #define prox_rte_table_add rte_table_hash_ext_dosig_ops.f_add
66 #define prox_rte_table_delete rte_table_hash_ext_dosig_ops.f_delete
67 #define prox_rte_table_add_bulk rte_table_hash_ext_dosig_ops.f_add_bulk
68 #define prox_rte_table_delete_bulk rte_table_hash_ext_dosig_ops.f_delete_bulk
69 #define prox_rte_table_lookup rte_table_hash_ext_dosig_ops.f_lookup
70 #define prox_rte_table_stats rte_table_hash_ext_dosig_ops.f_stats
72 #define prox_rte_table_key8_free rte_table_hash_key8_ext_dosig_ops.f_free
73 #define prox_rte_table_key8_add rte_table_hash_key8_ext_dosig_ops.f_add
74 #define prox_rte_table_key8_delete rte_table_hash_key8_ext_dosig_ops.f_delete
75 #define prox_rte_table_key8_add_bulk rte_table_hash_key8_ext_dosig_ops.f_add_bulk
76 #define prox_rte_table_key8_delete_bulk rte_table_hash_key8_ext_dosig_ops.f_delete_bulk
77 #define prox_rte_table_key8_lookup rte_table_hash_key8_ext_dosig_ops.f_lookup
78 #define prox_rte_table_key8_stats rte_table_hash_key8_ext_dosig_ops.f_stats
80 #define rte_log_set_global_level rte_set_log_level
84 static void *prox_rte_table_create(struct prox_rte_table_params *params, int socket_id, uint32_t entry_size)
86 struct rte_table_hash_params dpdk_17_11_params;
87 dpdk_17_11_params.name = params->name;
88 dpdk_17_11_params.key_size = params->key_size;
89 dpdk_17_11_params.key_offset = params->key_offset;
90 dpdk_17_11_params.key_mask = params->key_mask;
91 dpdk_17_11_params.n_keys = params->n_keys;
92 dpdk_17_11_params.n_buckets = rte_align32pow2(params->n_buckets);
93 dpdk_17_11_params.f_hash = params->f_hash;
94 dpdk_17_11_params.seed = params->seed;
96 if (params->key_size == 8) {
97 return rte_table_hash_key8_ext_ops.f_create(&dpdk_17_11_params, socket_id, entry_size);
99 return rte_table_hash_ext_ops.f_create(&dpdk_17_11_params, socket_id, entry_size);
103 #define prox_rte_table_free rte_table_hash_ext_ops.f_free
104 #define prox_rte_table_add rte_table_hash_ext_ops.f_add
105 #define prox_rte_table_delete rte_table_hash_ext_ops.f_delete
106 #define prox_rte_table_add_bulk rte_table_hash_ext_ops.f_add_bulk
107 #define prox_rte_table_delete_bulk rte_table_hash_ext_ops.f_delete_bulk
108 #define prox_rte_table_lookup rte_table_hash_ext_ops.f_lookup
109 #define prox_rte_table_stats rte_table_hash_ext_ops.f_stats
111 #define prox_rte_table_key8_free rte_table_hash_key8_ext_ops.f_free
112 #define prox_rte_table_key8_add rte_table_hash_key8_ext_ops.f_add
113 #define prox_rte_table_key8_delete rte_table_hash_key8_ext_ops.f_delete
114 #define prox_rte_table_key8_add_bulk rte_table_hash_key8_ext_ops.f_add_bulk
115 #define prox_rte_table_key8_delete_bulk rte_table_hash_key8_ext_ops.f_delete_bulk
116 #define prox_rte_table_key8_lookup rte_table_hash_key8_ext_ops.f_lookup
117 #define prox_rte_table_key8_stats rte_table_hash_key8_ext_ops.f_stats