1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2019-2021 Broadcom
7 #include <rte_common.h>
13 #include "tf_common.h"
17 #include "tf_ext_flow_handle.h"
18 #include "tf_device.h"
25 #if (TF_EM_ALLOC == 1)
30 * Insert EM internal entry API
36 tf_em_hash_insert_int_entry(struct tf *tfp,
37 struct tf_insert_em_entry_parms *parms)
41 uint16_t rptr_index = 0;
42 uint8_t rptr_entry = 0;
43 uint8_t num_of_entries = 0;
44 #if (TF_EM_ALLOC == 1)
53 struct tf_dev_info *dev;
54 struct tf_session *tfs;
56 /* Retrieve the session information */
57 rc = tf_session_get_session_internal(tfp, &tfs);
61 /* Retrieve the device information */
62 rc = tf_session_get_device(tfs, &dev);
65 #if (TF_EM_ALLOC == 1)
66 pool = (struct dpool *)tfs->em_pool[parms->dir];
67 index = dpool_alloc(pool,
68 parms->em_record_sz_in_bits / 128,
71 if (index == DP_INVALID_INDEX) {
73 "%s, EM entry index allocation failed\n",
74 tf_dir_2_str(parms->dir));
78 pool = (struct stack *)tfs->em_pool[parms->dir];
79 rc = stack_pop(pool, &index);
82 "%s, EM entry index allocation failed\n",
83 tf_dir_2_str(parms->dir));
88 if (dev->ops->tf_dev_cfa_key_hash == NULL)
91 big_hash = dev->ops->tf_dev_cfa_key_hash((uint64_t *)parms->key,
92 TF_P58_HW_EM_KEY_MAX_SIZE * 8);
93 key0_hash = (uint32_t)(big_hash >> 32);
94 key1_hash = (uint32_t)(big_hash & 0xFFFFFFFF);
97 rc = tf_msg_hash_insert_em_internal_entry(tfp,
105 /* Free the allocated index before returning */
106 #if (TF_EM_ALLOC == 1)
107 dpool_free(pool, index);
109 stack_push(pool, index);
115 ((rptr_index << TF_EM_INTERNAL_INDEX_SHIFT) |
117 0); /* N/A for internal table */
119 TF_SET_FLOW_ID(parms->flow_id,
121 TF_GFID_TABLE_INTERNAL,
124 TF_SET_FIELDS_IN_FLOW_HANDLE(parms->flow_handle,
125 (uint32_t)num_of_entries,
127 TF_FLAGS_FLOW_HANDLE_INTERNAL,
131 #if (TF_EM_ALLOC == 1)
132 dpool_set_entry_data(pool, index, parms->flow_handle);
137 /** Delete EM internal entry API
144 tf_em_hash_delete_int_entry(struct tf *tfp,
145 struct tf_delete_em_entry_parms *parms)
148 struct tf_session *tfs;
149 #if (TF_EM_ALLOC == 1)
154 /* Retrieve the session information */
155 rc = tf_session_get_session(tfp, &tfs);
158 "%s: Failed to lookup session, rc:%s\n",
159 tf_dir_2_str(parms->dir),
164 rc = tf_msg_delete_em_entry(tfp, parms);
166 /* Return resource to pool */
168 #if (TF_EM_ALLOC == 1)
169 pool = (struct dpool *)tfs->em_pool[parms->dir];
170 dpool_free(pool, parms->index);
172 pool = (struct stack *)tfs->em_pool[parms->dir];
173 stack_push(pool, parms->index);
180 #if (TF_EM_ALLOC == 1)
181 /** Move EM internal entry API
188 tf_em_move_int_entry(struct tf *tfp,
189 struct tf_move_em_entry_parms *parms)
193 struct tf_session *tfs;
195 /* Retrieve the session information */
196 rc = tf_session_get_session(tfp, &tfs);
199 "%s: Failed to lookup session, rc:%s\n",
200 tf_dir_2_str(parms->dir),
205 rc = tf_msg_move_em_entry(tfp, parms);
207 /* Return resource to pool */
209 pool = (struct dpool *)tfs->em_pool[parms->dir];
210 dpool_free(pool, parms->index);