* Create a new hash table for use with four byte keys. * * @param params * Parameters used in creation of hash table. * * @return * Pointer to hash table structure that is used in future hash table * operations, or NULL on error. */
| 70 | * operations, or NULL on error. |
| 71 | */ |
| 72 | struct rte_fbk_hash_table * |
| 73 | rte_fbk_hash_create(const struct rte_fbk_hash_params *params) |
| 74 | { |
| 75 | struct rte_fbk_hash_table *ht = NULL; |
| 76 | struct rte_tailq_entry *te; |
| 77 | char hash_name[RTE_FBK_HASH_NAMESIZE]; |
| 78 | const uint32_t mem_size = |
| 79 | sizeof(*ht) + (sizeof(ht->t[0]) * params->entries); |
| 80 | uint32_t i; |
| 81 | struct rte_fbk_hash_list *fbk_hash_list; |
| 82 | rte_fbk_hash_fn default_hash_func = (rte_fbk_hash_fn)rte_jhash_1word; |
| 83 | |
| 84 | fbk_hash_list = RTE_TAILQ_CAST(rte_fbk_hash_tailq.head, |
| 85 | rte_fbk_hash_list); |
| 86 | |
| 87 | /* Error checking of parameters. */ |
| 88 | if ((!rte_is_power_of_2(params->entries)) || |
| 89 | (!rte_is_power_of_2(params->entries_per_bucket)) || |
| 90 | (params->entries == 0) || |
| 91 | (params->entries_per_bucket == 0) || |
| 92 | (params->entries_per_bucket > params->entries) || |
| 93 | (params->entries > RTE_FBK_HASH_ENTRIES_MAX) || |
| 94 | (params->entries_per_bucket > RTE_FBK_HASH_ENTRIES_PER_BUCKET_MAX)){ |
| 95 | rte_errno = EINVAL; |
| 96 | return NULL; |
| 97 | } |
| 98 | |
| 99 | snprintf(hash_name, sizeof(hash_name), "FBK_%s", params->name); |
| 100 | |
| 101 | rte_mcfg_tailq_write_lock(); |
| 102 | |
| 103 | /* guarantee there's no existing */ |
| 104 | TAILQ_FOREACH(te, fbk_hash_list, next) { |
| 105 | ht = (struct rte_fbk_hash_table *) te->data; |
| 106 | if (strncmp(params->name, ht->name, RTE_FBK_HASH_NAMESIZE) == 0) |
| 107 | break; |
| 108 | } |
| 109 | ht = NULL; |
| 110 | if (te != NULL) { |
| 111 | rte_errno = EEXIST; |
| 112 | goto exit; |
| 113 | } |
| 114 | |
| 115 | te = rte_zmalloc("FBK_HASH_TAILQ_ENTRY", sizeof(*te), 0); |
| 116 | if (te == NULL) { |
| 117 | RTE_LOG(ERR, HASH, "Failed to allocate tailq entry\n"); |
| 118 | goto exit; |
| 119 | } |
| 120 | |
| 121 | /* Allocate memory for table. */ |
| 122 | ht = rte_zmalloc_socket(hash_name, mem_size, |
| 123 | 0, params->socket_id); |
| 124 | if (ht == NULL) { |
| 125 | RTE_LOG(ERR, HASH, "Failed to allocate fbk hash table\n"); |
| 126 | rte_free(te); |
| 127 | goto exit; |
| 128 | } |
| 129 |