+ return 0;
+
+error:
+ selector_build_free(p);
+ return status;
+}
+
+static void
+selector_free(struct rte_swx_pipeline *p)
+{
+ selector_build_free(p);
+
+ /* Selector tables. */
+ for ( ; ; ) {
+ struct selector *elem;
+
+ elem = TAILQ_FIRST(&p->selectors);
+ if (!elem)
+ break;
+
+ TAILQ_REMOVE(&p->selectors, elem, node);
+ free(elem->selector_fields);
+ free(elem);
+ }
+}
+
+/*
+ * Learner table.
+ */
+static struct learner *
+learner_find(struct rte_swx_pipeline *p, const char *name)
+{
+ struct learner *l;
+
+ TAILQ_FOREACH(l, &p->learners, node)
+ if (!strcmp(l->name, name))
+ return l;
+
+ return NULL;
+}
+
+static struct learner *
+learner_find_by_id(struct rte_swx_pipeline *p, uint32_t id)
+{
+ struct learner *l = NULL;
+
+ TAILQ_FOREACH(l, &p->learners, node)
+ if (l->id == id)
+ return l;
+
+ return NULL;
+}
+
+static int
+learner_match_fields_check(struct rte_swx_pipeline *p,
+ struct rte_swx_pipeline_learner_params *params,
+ struct header **header)
+{
+ struct header *h0 = NULL;
+ struct field *hf, *mf;
+ uint32_t i;
+
+ /* Return if no match fields. */
+ if (!params->n_fields || !params->field_names)
+ return -EINVAL;
+
+ /* Check that all the match fields either belong to the same header
+ * or are all meta-data fields.
+ */
+ hf = header_field_parse(p, params->field_names[0], &h0);
+ mf = metadata_field_parse(p, params->field_names[0]);
+ if (!hf && !mf)
+ return -EINVAL;
+
+ for (i = 1; i < params->n_fields; i++)
+ if (h0) {
+ struct header *h;
+
+ hf = header_field_parse(p, params->field_names[i], &h);
+ if (!hf || (h->id != h0->id))
+ return -EINVAL;
+ } else {
+ mf = metadata_field_parse(p, params->field_names[i]);
+ if (!mf)
+ return -EINVAL;
+ }
+
+ /* Check that there are no duplicated match fields. */
+ for (i = 0; i < params->n_fields; i++) {
+ const char *field_name = params->field_names[i];
+ uint32_t j;
+
+ for (j = i + 1; j < params->n_fields; j++)
+ if (!strcmp(params->field_names[j], field_name))
+ return -EINVAL;
+ }
+
+ /* Return. */
+ if (header)
+ *header = h0;
+
+ return 0;
+}
+
+static int
+learner_action_args_check(struct rte_swx_pipeline *p, struct action *a, const char *mf_name)
+{
+ struct struct_type *mst = p->metadata_st, *ast = a->st;
+ struct field *mf, *af;
+ uint32_t mf_pos, i;
+
+ if (!ast) {
+ if (mf_name)
+ return -EINVAL;
+
+ return 0;
+ }
+
+ /* Check that mf_name is the name of a valid meta-data field. */
+ CHECK_NAME(mf_name, EINVAL);
+ mf = metadata_field_parse(p, mf_name);
+ CHECK(mf, EINVAL);
+
+ /* Check that there are enough meta-data fields, starting with the mf_name field, to cover
+ * all the action arguments.
+ */
+ mf_pos = mf - mst->fields;
+ CHECK(mst->n_fields - mf_pos >= ast->n_fields, EINVAL);
+
+ /* Check that the size of each of the identified meta-data fields matches exactly the size
+ * of the corresponding action argument.
+ */
+ for (i = 0; i < ast->n_fields; i++) {
+ mf = &mst->fields[mf_pos + i];
+ af = &ast->fields[i];
+
+ CHECK(mf->n_bits == af->n_bits, EINVAL);
+ }
+
+ return 0;
+}
+
+static int
+learner_action_learning_check(struct rte_swx_pipeline *p,
+ struct action *action,
+ const char **action_names,
+ uint32_t n_actions)
+{
+ uint32_t i;
+
+ /* For each "learn" instruction of the current action, check that the learned action (i.e.
+ * the action passed as argument to the "learn" instruction) is also enabled for the
+ * current learner table.
+ */
+ for (i = 0; i < action->n_instructions; i++) {
+ struct instruction *instr = &action->instructions[i];
+ uint32_t found = 0, j;
+
+ if (instr->type != INSTR_LEARNER_LEARN)
+ continue;
+
+ for (j = 0; j < n_actions; j++) {
+ struct action *a;
+
+ a = action_find(p, action_names[j]);
+ if (!a)
+ return -EINVAL;
+
+ if (a->id == instr->learn.action_id)
+ found = 1;
+ }
+
+ if (!found)
+ return -EINVAL;
+ }
+
+ return 0;
+}
+
+int
+rte_swx_pipeline_learner_config(struct rte_swx_pipeline *p,
+ const char *name,
+ struct rte_swx_pipeline_learner_params *params,
+ uint32_t size,
+ uint32_t timeout)
+{
+ struct learner *l = NULL;
+ struct action *default_action;
+ struct header *header = NULL;
+ uint32_t action_data_size_max = 0, i;
+ int status = 0;
+
+ CHECK(p, EINVAL);
+
+ CHECK_NAME(name, EINVAL);
+ CHECK(!table_find(p, name), EEXIST);
+ CHECK(!selector_find(p, name), EEXIST);
+ CHECK(!learner_find(p, name), EEXIST);
+
+ CHECK(params, EINVAL);
+
+ /* Match checks. */
+ status = learner_match_fields_check(p, params, &header);
+ if (status)
+ return status;
+
+ /* Action checks. */
+ CHECK(params->n_actions, EINVAL);
+ CHECK(params->action_names, EINVAL);
+ for (i = 0; i < params->n_actions; i++) {
+ const char *action_name = params->action_names[i];
+ struct action *a;
+ uint32_t action_data_size;
+ int action_is_for_table_entries = 1, action_is_for_default_entry = 1;
+
+ CHECK_NAME(action_name, EINVAL);
+
+ a = action_find(p, action_name);
+ CHECK(a, EINVAL);
+
+ status = learner_action_learning_check(p,
+ a,
+ params->action_names,
+ params->n_actions);
+ if (status)
+ return status;
+
+ action_data_size = a->st ? a->st->n_bits / 8 : 0;
+ if (action_data_size > action_data_size_max)
+ action_data_size_max = action_data_size;
+
+ if (params->action_is_for_table_entries)
+ action_is_for_table_entries = params->action_is_for_table_entries[i];
+ if (params->action_is_for_default_entry)
+ action_is_for_default_entry = params->action_is_for_default_entry[i];
+ CHECK(action_is_for_table_entries || action_is_for_default_entry, EINVAL);
+ }
+
+ CHECK_NAME(params->default_action_name, EINVAL);
+ for (i = 0; i < p->n_actions; i++)
+ if (!strcmp(params->action_names[i],
+ params->default_action_name))
+ break;
+ CHECK(i < params->n_actions, EINVAL);
+ CHECK(!params->action_is_for_default_entry || params->action_is_for_default_entry[i],
+ EINVAL);
+
+ default_action = action_find(p, params->default_action_name);
+ CHECK((default_action->st && params->default_action_data) ||
+ !params->default_action_data, EINVAL);
+
+ /* Any other checks. */
+ CHECK(size, EINVAL);
+ CHECK(timeout, EINVAL);
+
+ /* Memory allocation. */
+ l = calloc(1, sizeof(struct learner));
+ if (!l)
+ goto nomem;
+
+ l->fields = calloc(params->n_fields, sizeof(struct field *));
+ if (!l->fields)
+ goto nomem;
+
+ l->actions = calloc(params->n_actions, sizeof(struct action *));
+ if (!l->actions)
+ goto nomem;
+
+ if (action_data_size_max) {
+ l->default_action_data = calloc(1, action_data_size_max);
+ if (!l->default_action_data)
+ goto nomem;
+ }
+
+ l->action_is_for_table_entries = calloc(params->n_actions, sizeof(int));
+ if (!l->action_is_for_table_entries)
+ goto nomem;
+
+ l->action_is_for_default_entry = calloc(params->n_actions, sizeof(int));
+ if (!l->action_is_for_default_entry)
+ goto nomem;
+
+ /* Node initialization. */
+ strcpy(l->name, name);
+
+ for (i = 0; i < params->n_fields; i++) {
+ const char *field_name = params->field_names[i];
+
+ l->fields[i] = header ?
+ header_field_parse(p, field_name, NULL) :
+ metadata_field_parse(p, field_name);
+ }
+
+ l->n_fields = params->n_fields;
+
+ l->header = header;
+
+ for (i = 0; i < params->n_actions; i++) {
+ int action_is_for_table_entries = 1, action_is_for_default_entry = 1;
+
+ if (params->action_is_for_table_entries)
+ action_is_for_table_entries = params->action_is_for_table_entries[i];
+ if (params->action_is_for_default_entry)
+ action_is_for_default_entry = params->action_is_for_default_entry[i];
+
+ l->actions[i] = action_find(p, params->action_names[i]);
+ l->action_is_for_table_entries[i] = action_is_for_table_entries;
+ l->action_is_for_default_entry[i] = action_is_for_default_entry;
+ }
+
+ l->default_action = default_action;
+
+ if (default_action->st)
+ memcpy(l->default_action_data,
+ params->default_action_data,
+ default_action->st->n_bits / 8);
+
+ l->n_actions = params->n_actions;
+
+ l->default_action_is_const = params->default_action_is_const;
+
+ l->action_data_size_max = action_data_size_max;
+
+ l->size = size;
+
+ l->timeout = timeout;
+
+ l->id = p->n_learners;
+
+ /* Node add to tailq. */
+ TAILQ_INSERT_TAIL(&p->learners, l, node);
+ p->n_learners++;
+
+ return 0;
+
+nomem:
+ if (!l)
+ return -ENOMEM;
+
+ free(l->action_is_for_default_entry);
+ free(l->action_is_for_table_entries);
+ free(l->default_action_data);
+ free(l->actions);
+ free(l->fields);
+ free(l);
+
+ return -ENOMEM;
+}
+
+static void
+learner_params_free(struct rte_swx_table_learner_params *params)
+{
+ if (!params)
+ return;
+
+ free(params->key_mask0);
+
+ free(params);
+}
+
+static struct rte_swx_table_learner_params *
+learner_params_get(struct learner *l)
+{
+ struct rte_swx_table_learner_params *params = NULL;
+ struct field *first, *last;
+ uint32_t i;
+
+ /* Memory allocation. */
+ params = calloc(1, sizeof(struct rte_swx_table_learner_params));
+ if (!params)
+ goto error;
+
+ /* Find first (smallest offset) and last (biggest offset) match fields. */
+ first = l->fields[0];
+ last = l->fields[0];
+
+ for (i = 0; i < l->n_fields; i++) {
+ struct field *f = l->fields[i];
+
+ if (f->offset < first->offset)
+ first = f;
+
+ if (f->offset > last->offset)
+ last = f;
+ }
+
+ /* Key offset and size. */
+ params->key_offset = first->offset / 8;
+ params->key_size = (last->offset + last->n_bits - first->offset) / 8;
+
+ /* Memory allocation. */
+ params->key_mask0 = calloc(1, params->key_size);
+ if (!params->key_mask0)
+ goto error;
+
+ /* Key mask. */
+ for (i = 0; i < l->n_fields; i++) {
+ struct field *f = l->fields[i];
+ uint32_t start = (f->offset - first->offset) / 8;
+ size_t size = f->n_bits / 8;
+
+ memset(¶ms->key_mask0[start], 0xFF, size);
+ }
+
+ /* Action data size. */
+ params->action_data_size = l->action_data_size_max;
+
+ /* Maximum number of keys. */
+ params->n_keys_max = l->size;
+
+ /* Timeout. */
+ params->key_timeout = l->timeout;
+
+ return params;
+
+error:
+ learner_params_free(params);
+ return NULL;
+}
+
+static void
+learner_build_free(struct rte_swx_pipeline *p)
+{
+ uint32_t i;
+
+ for (i = 0; i < RTE_SWX_PIPELINE_THREADS_MAX; i++) {
+ struct thread *t = &p->threads[i];
+ uint32_t j;
+
+ if (!t->learners)
+ continue;
+
+ for (j = 0; j < p->n_learners; j++) {
+ struct learner_runtime *r = &t->learners[j];
+
+ free(r->mailbox);
+ }
+
+ free(t->learners);
+ t->learners = NULL;
+ }
+
+ if (p->learner_stats) {
+ for (i = 0; i < p->n_learners; i++)
+ free(p->learner_stats[i].n_pkts_action);
+
+ free(p->learner_stats);
+ }
+}
+
+static int
+learner_build(struct rte_swx_pipeline *p)
+{
+ uint32_t i;
+ int status = 0;
+
+ /* Per pipeline: learner statistics. */
+ p->learner_stats = calloc(p->n_learners, sizeof(struct learner_statistics));
+ CHECK(p->learner_stats, ENOMEM);
+
+ for (i = 0; i < p->n_learners; i++) {
+ p->learner_stats[i].n_pkts_action = calloc(p->n_actions, sizeof(uint64_t));
+ CHECK(p->learner_stats[i].n_pkts_action, ENOMEM);
+ }
+
+ /* Per thread: learner run-time. */
+ for (i = 0; i < RTE_SWX_PIPELINE_THREADS_MAX; i++) {
+ struct thread *t = &p->threads[i];
+ struct learner *l;
+
+ t->learners = calloc(p->n_learners, sizeof(struct learner_runtime));
+ if (!t->learners) {
+ status = -ENOMEM;
+ goto error;
+ }
+
+ TAILQ_FOREACH(l, &p->learners, node) {
+ struct learner_runtime *r = &t->learners[l->id];
+ uint64_t size;
+
+ /* r->mailbox. */
+ size = rte_swx_table_learner_mailbox_size_get();
+ if (size) {
+ r->mailbox = calloc(1, size);
+ if (!r->mailbox) {
+ status = -ENOMEM;
+ goto error;
+ }
+ }
+
+ /* r->key. */
+ r->key = l->header ?
+ &t->structs[l->header->struct_id] :
+ &t->structs[p->metadata_struct_id];
+ }
+ }
+
+ return 0;
+
+error:
+ learner_build_free(p);
+ return status;
+}
+
+static void
+learner_free(struct rte_swx_pipeline *p)
+{
+ learner_build_free(p);
+
+ /* Learner tables. */
+ for ( ; ; ) {
+ struct learner *l;
+
+ l = TAILQ_FIRST(&p->learners);
+ if (!l)
+ break;
+
+ TAILQ_REMOVE(&p->learners, l, node);
+ free(l->fields);
+ free(l->actions);
+ free(l->default_action_data);
+ free(l);
+ }
+}
+
+/*
+ * Table state.
+ */
+static int
+table_state_build(struct rte_swx_pipeline *p)
+{
+ struct table *table;
+ struct selector *s;
+ struct learner *l;
+
+ p->table_state = calloc(p->n_tables + p->n_selectors,
+ sizeof(struct rte_swx_table_state));
+ CHECK(p->table_state, ENOMEM);
+
+ TAILQ_FOREACH(table, &p->tables, node) {
+ struct rte_swx_table_state *ts = &p->table_state[table->id];
+
+ if (table->type) {
+ struct rte_swx_table_params *params;
+
+ /* ts->obj. */
+ params = table_params_get(table);
+ CHECK(params, ENOMEM);
+
+ ts->obj = table->type->ops.create(params,
+ NULL,
+ table->args,
+ p->numa_node);
+
+ table_params_free(params);
+ CHECK(ts->obj, ENODEV);
+ }
+
+ /* ts->default_action_data. */
+ if (table->action_data_size_max) {
+ ts->default_action_data =
+ malloc(table->action_data_size_max);
+ CHECK(ts->default_action_data, ENOMEM);
+
+ memcpy(ts->default_action_data,
+ table->default_action_data,
+ table->action_data_size_max);
+ }
+
+ /* ts->default_action_id. */
+ ts->default_action_id = table->default_action->id;
+ }
+
+ TAILQ_FOREACH(s, &p->selectors, node) {
+ struct rte_swx_table_state *ts = &p->table_state[p->n_tables + s->id];
+ struct rte_swx_table_selector_params *params;
+
+ /* ts->obj. */
+ params = selector_table_params_get(s);
+ CHECK(params, ENOMEM);
+
+ ts->obj = rte_swx_table_selector_create(params, NULL, p->numa_node);
+
+ selector_params_free(params);
+ CHECK(ts->obj, ENODEV);
+ }
+
+ TAILQ_FOREACH(l, &p->learners, node) {
+ struct rte_swx_table_state *ts = &p->table_state[p->n_tables +
+ p->n_selectors + l->id];
+ struct rte_swx_table_learner_params *params;
+
+ /* ts->obj. */
+ params = learner_params_get(l);
+ CHECK(params, ENOMEM);
+
+ ts->obj = rte_swx_table_learner_create(params, p->numa_node);
+ learner_params_free(params);
+ CHECK(ts->obj, ENODEV);
+
+ /* ts->default_action_data. */
+ if (l->action_data_size_max) {
+ ts->default_action_data = malloc(l->action_data_size_max);
+ CHECK(ts->default_action_data, ENOMEM);
+
+ memcpy(ts->default_action_data,
+ l->default_action_data,
+ l->action_data_size_max);
+ }
+
+ /* ts->default_action_id. */
+ ts->default_action_id = l->default_action->id;
+ }
+
+ return 0;
+}
+
+static void
+table_state_build_free(struct rte_swx_pipeline *p)
+{
+ uint32_t i;
+
+ if (!p->table_state)
+ return;
+
+ for (i = 0; i < p->n_tables; i++) {
+ struct rte_swx_table_state *ts = &p->table_state[i];
+ struct table *table = table_find_by_id(p, i);
+
+ /* ts->obj. */
+ if (table->type && ts->obj)
+ table->type->ops.free(ts->obj);
+
+ /* ts->default_action_data. */
+ free(ts->default_action_data);
+ }
+
+ for (i = 0; i < p->n_selectors; i++) {
+ struct rte_swx_table_state *ts = &p->table_state[p->n_tables + i];
+
+ /* ts->obj. */
+ if (ts->obj)
+ rte_swx_table_selector_free(ts->obj);
+ }
+
+ for (i = 0; i < p->n_learners; i++) {
+ struct rte_swx_table_state *ts = &p->table_state[p->n_tables + p->n_selectors + i];
+
+ /* ts->obj. */
+ if (ts->obj)
+ rte_swx_table_learner_free(ts->obj);
+
+ /* ts->default_action_data. */
+ free(ts->default_action_data);
+ }
+
+ free(p->table_state);
+ p->table_state = NULL;
+}
+
+static void
+table_state_free(struct rte_swx_pipeline *p)
+{
+ table_state_build_free(p);
+}
+
+/*
+ * Register array.
+ */
+static struct regarray *
+regarray_find(struct rte_swx_pipeline *p, const char *name)
+{
+ struct regarray *elem;
+
+ TAILQ_FOREACH(elem, &p->regarrays, node)
+ if (!strcmp(elem->name, name))
+ return elem;
+
+ return NULL;
+}
+
+static struct regarray *
+regarray_find_by_id(struct rte_swx_pipeline *p, uint32_t id)
+{
+ struct regarray *elem = NULL;
+
+ TAILQ_FOREACH(elem, &p->regarrays, node)
+ if (elem->id == id)
+ return elem;
+
+ return NULL;
+}
+
+int
+rte_swx_pipeline_regarray_config(struct rte_swx_pipeline *p,
+ const char *name,
+ uint32_t size,
+ uint64_t init_val)
+{
+ struct regarray *r;
+
+ CHECK(p, EINVAL);
+
+ CHECK_NAME(name, EINVAL);
+ CHECK(!regarray_find(p, name), EEXIST);
+
+ CHECK(size, EINVAL);
+ size = rte_align32pow2(size);
+
+ /* Memory allocation. */
+ r = calloc(1, sizeof(struct regarray));
+ CHECK(r, ENOMEM);
+
+ /* Node initialization. */
+ strcpy(r->name, name);
+ r->init_val = init_val;
+ r->size = size;
+ r->id = p->n_regarrays;
+
+ /* Node add to tailq. */
+ TAILQ_INSERT_TAIL(&p->regarrays, r, node);
+ p->n_regarrays++;
+
+ return 0;
+}
+
+static int
+regarray_build(struct rte_swx_pipeline *p)
+{
+ struct regarray *regarray;
+
+ if (!p->n_regarrays)
+ return 0;
+
+ p->regarray_runtime = calloc(p->n_regarrays, sizeof(struct regarray_runtime));
+ CHECK(p->regarray_runtime, ENOMEM);
+
+ TAILQ_FOREACH(regarray, &p->regarrays, node) {
+ struct regarray_runtime *r = &p->regarray_runtime[regarray->id];
+ uint32_t i;
+
+ r->regarray = env_malloc(regarray->size * sizeof(uint64_t),
+ RTE_CACHE_LINE_SIZE,
+ p->numa_node);
+ CHECK(r->regarray, ENOMEM);
+
+ if (regarray->init_val)
+ for (i = 0; i < regarray->size; i++)
+ r->regarray[i] = regarray->init_val;
+
+ r->size_mask = regarray->size - 1;
+ }
+
+ return 0;
+}
+
+static void
+regarray_build_free(struct rte_swx_pipeline *p)
+{
+ uint32_t i;
+
+ if (!p->regarray_runtime)
+ return;
+
+ for (i = 0; i < p->n_regarrays; i++) {
+ struct regarray *regarray = regarray_find_by_id(p, i);
+ struct regarray_runtime *r = &p->regarray_runtime[i];
+
+ env_free(r->regarray, regarray->size * sizeof(uint64_t));
+ }
+
+ free(p->regarray_runtime);
+ p->regarray_runtime = NULL;
+}
+
+static void
+regarray_free(struct rte_swx_pipeline *p)
+{
+ regarray_build_free(p);
+
+ for ( ; ; ) {
+ struct regarray *elem;
+
+ elem = TAILQ_FIRST(&p->regarrays);
+ if (!elem)
+ break;
+
+ TAILQ_REMOVE(&p->regarrays, elem, node);
+ free(elem);
+ }
+}
+
+/*
+ * Meter array.
+ */
+static struct meter_profile *
+meter_profile_find(struct rte_swx_pipeline *p, const char *name)
+{
+ struct meter_profile *elem;
+
+ TAILQ_FOREACH(elem, &p->meter_profiles, node)
+ if (!strcmp(elem->name, name))
+ return elem;
+
+ return NULL;
+}
+
+static struct metarray *
+metarray_find(struct rte_swx_pipeline *p, const char *name)
+{
+ struct metarray *elem;
+
+ TAILQ_FOREACH(elem, &p->metarrays, node)
+ if (!strcmp(elem->name, name))
+ return elem;
+
+ return NULL;
+}
+
+static struct metarray *
+metarray_find_by_id(struct rte_swx_pipeline *p, uint32_t id)
+{
+ struct metarray *elem = NULL;
+
+ TAILQ_FOREACH(elem, &p->metarrays, node)
+ if (elem->id == id)
+ return elem;
+
+ return NULL;
+}
+
+int
+rte_swx_pipeline_metarray_config(struct rte_swx_pipeline *p,
+ const char *name,
+ uint32_t size)
+{
+ struct metarray *m;
+
+ CHECK(p, EINVAL);
+
+ CHECK_NAME(name, EINVAL);
+ CHECK(!metarray_find(p, name), EEXIST);
+
+ CHECK(size, EINVAL);
+ size = rte_align32pow2(size);
+
+ /* Memory allocation. */
+ m = calloc(1, sizeof(struct metarray));
+ CHECK(m, ENOMEM);
+
+ /* Node initialization. */
+ strcpy(m->name, name);
+ m->size = size;
+ m->id = p->n_metarrays;
+
+ /* Node add to tailq. */
+ TAILQ_INSERT_TAIL(&p->metarrays, m, node);
+ p->n_metarrays++;
+
+ return 0;
+}
+
+struct meter_profile meter_profile_default = {
+ .node = {0},
+ .name = "",
+ .params = {0},
+
+ .profile = {
+ .cbs = 10000,
+ .pbs = 10000,
+ .cir_period = 1,
+ .cir_bytes_per_period = 1,
+ .pir_period = 1,
+ .pir_bytes_per_period = 1,
+ },
+
+ .n_users = 0,
+};
+
+static void
+meter_init(struct meter *m)
+{
+ memset(m, 0, sizeof(struct meter));
+ rte_meter_trtcm_config(&m->m, &meter_profile_default.profile);
+ m->profile = &meter_profile_default;
+ m->color_mask = RTE_COLOR_GREEN;
+
+ meter_profile_default.n_users++;
+}
+
+static int
+metarray_build(struct rte_swx_pipeline *p)
+{
+ struct metarray *m;
+
+ if (!p->n_metarrays)
+ return 0;
+
+ p->metarray_runtime = calloc(p->n_metarrays, sizeof(struct metarray_runtime));
+ CHECK(p->metarray_runtime, ENOMEM);
+
+ TAILQ_FOREACH(m, &p->metarrays, node) {
+ struct metarray_runtime *r = &p->metarray_runtime[m->id];
+ uint32_t i;
+
+ r->metarray = env_malloc(m->size * sizeof(struct meter),
+ RTE_CACHE_LINE_SIZE,
+ p->numa_node);
+ CHECK(r->metarray, ENOMEM);
+
+ for (i = 0; i < m->size; i++)
+ meter_init(&r->metarray[i]);
+
+ r->size_mask = m->size - 1;
+ }
+
+ return 0;
+}
+
+static void
+metarray_build_free(struct rte_swx_pipeline *p)
+{
+ uint32_t i;
+
+ if (!p->metarray_runtime)
+ return;
+
+ for (i = 0; i < p->n_metarrays; i++) {
+ struct metarray *m = metarray_find_by_id(p, i);
+ struct metarray_runtime *r = &p->metarray_runtime[i];
+
+ env_free(r->metarray, m->size * sizeof(struct meter));
+ }
+
+ free(p->metarray_runtime);
+ p->metarray_runtime = NULL;
+}
+
+static void
+metarray_free(struct rte_swx_pipeline *p)
+{
+ metarray_build_free(p);
+
+ /* Meter arrays. */
+ for ( ; ; ) {
+ struct metarray *elem;
+
+ elem = TAILQ_FIRST(&p->metarrays);
+ if (!elem)
+ break;
+
+ TAILQ_REMOVE(&p->metarrays, elem, node);
+ free(elem);
+ }
+
+ /* Meter profiles. */
+ for ( ; ; ) {
+ struct meter_profile *elem;
+
+ elem = TAILQ_FIRST(&p->meter_profiles);
+ if (!elem)
+ break;
+
+ TAILQ_REMOVE(&p->meter_profiles, elem, node);
+ free(elem);
+ }
+}
+
+/*
+ * Pipeline.
+ */
+int
+rte_swx_pipeline_config(struct rte_swx_pipeline **p, int numa_node)
+{
+ struct rte_swx_pipeline *pipeline;
+
+ /* Check input parameters. */
+ CHECK(p, EINVAL);
+
+ /* Memory allocation. */
+ pipeline = calloc(1, sizeof(struct rte_swx_pipeline));
+ CHECK(pipeline, ENOMEM);
+
+ /* Initialization. */
+ TAILQ_INIT(&pipeline->struct_types);
+ TAILQ_INIT(&pipeline->port_in_types);
+ TAILQ_INIT(&pipeline->ports_in);
+ TAILQ_INIT(&pipeline->port_out_types);
+ TAILQ_INIT(&pipeline->ports_out);
+ TAILQ_INIT(&pipeline->extern_types);
+ TAILQ_INIT(&pipeline->extern_objs);
+ TAILQ_INIT(&pipeline->extern_funcs);
+ TAILQ_INIT(&pipeline->headers);
+ TAILQ_INIT(&pipeline->actions);
+ TAILQ_INIT(&pipeline->table_types);
+ TAILQ_INIT(&pipeline->tables);
+ TAILQ_INIT(&pipeline->selectors);
+ TAILQ_INIT(&pipeline->learners);
+ TAILQ_INIT(&pipeline->regarrays);
+ TAILQ_INIT(&pipeline->meter_profiles);
+ TAILQ_INIT(&pipeline->metarrays);
+
+ pipeline->n_structs = 1; /* Struct 0 is reserved for action_data. */
+ pipeline->numa_node = numa_node;
+
+ *p = pipeline;
+ return 0;
+}
+
+void
+rte_swx_pipeline_free(struct rte_swx_pipeline *p)
+{
+ void *lib;
+
+ if (!p)
+ return;
+
+ lib = p->lib;
+
+ free(p->instruction_data);
+ free(p->instructions);
+
+ metarray_free(p);
+ regarray_free(p);
+ table_state_free(p);
+ learner_free(p);
+ selector_free(p);
+ table_free(p);
+ action_free(p);
+ instruction_table_free(p);
+ metadata_free(p);
+ header_free(p);
+ extern_func_free(p);
+ extern_obj_free(p);
+ port_out_free(p);
+ port_in_free(p);
+ struct_free(p);
+
+ free(p);
+
+ if (lib)
+ dlclose(lib);
+}
+
+int
+rte_swx_pipeline_instructions_config(struct rte_swx_pipeline *p,
+ const char **instructions,
+ uint32_t n_instructions)
+{
+ int err;
+ uint32_t i;
+
+ err = instruction_config(p, NULL, instructions, n_instructions);
+ if (err)
+ return err;
+
+ /* Thread instruction pointer reset. */
+ for (i = 0; i < RTE_SWX_PIPELINE_THREADS_MAX; i++) {
+ struct thread *t = &p->threads[i];
+
+ thread_ip_reset(p, t);
+ }
+
+ return 0;
+}
+
+static int
+pipeline_compile(struct rte_swx_pipeline *p);
+
+int
+rte_swx_pipeline_build(struct rte_swx_pipeline *p)
+{
+ int status;
+
+ CHECK(p, EINVAL);
+ CHECK(p->build_done == 0, EEXIST);
+
+ status = port_in_build(p);
+ if (status)
+ goto error;
+
+ status = port_out_build(p);
+ if (status)
+ goto error;
+
+ status = struct_build(p);
+ if (status)
+ goto error;
+
+ status = extern_obj_build(p);
+ if (status)
+ goto error;
+
+ status = extern_func_build(p);
+ if (status)
+ goto error;
+
+ status = header_build(p);
+ if (status)
+ goto error;
+
+ status = metadata_build(p);
+ if (status)
+ goto error;
+
+ status = instruction_table_build(p);
+ if (status)
+ goto error;
+
+ status = action_build(p);
+ if (status)
+ goto error;
+
+ status = table_build(p);
+ if (status)
+ goto error;
+
+ status = selector_build(p);
+ if (status)
+ goto error;
+
+ status = learner_build(p);
+ if (status)
+ goto error;
+
+ status = table_state_build(p);
+ if (status)
+ goto error;
+
+ status = regarray_build(p);
+ if (status)
+ goto error;
+
+ status = metarray_build(p);
+ if (status)
+ goto error;
+
+ p->build_done = 1;
+
+ pipeline_compile(p);
+
+ return 0;
+
+error:
+ metarray_build_free(p);
+ regarray_build_free(p);
+ table_state_build_free(p);
+ learner_build_free(p);
+ selector_build_free(p);
+ table_build_free(p);
+ action_build_free(p);
+ instruction_table_build_free(p);
+ metadata_build_free(p);
+ header_build_free(p);
+ extern_func_build_free(p);
+ extern_obj_build_free(p);
+ port_out_build_free(p);
+ port_in_build_free(p);
+ struct_build_free(p);
+
+ return status;
+}
+
+void
+rte_swx_pipeline_run(struct rte_swx_pipeline *p, uint32_t n_instructions)
+{
+ uint32_t i;
+
+ for (i = 0; i < n_instructions; i++)
+ instr_exec(p);
+}
+
+void
+rte_swx_pipeline_flush(struct rte_swx_pipeline *p)
+{
+ uint32_t i;
+
+ for (i = 0; i < p->n_ports_out; i++) {
+ struct port_out_runtime *port = &p->out[i];
+
+ if (port->flush)
+ port->flush(port->obj);
+ }
+}
+
+/*
+ * Control.
+ */
+int
+rte_swx_ctl_pipeline_info_get(struct rte_swx_pipeline *p,
+ struct rte_swx_ctl_pipeline_info *pipeline)
+{
+ struct action *action;
+ struct table *table;
+ uint32_t n_actions = 0, n_tables = 0;
+
+ if (!p || !pipeline)
+ return -EINVAL;
+
+ TAILQ_FOREACH(action, &p->actions, node)
+ n_actions++;
+
+ TAILQ_FOREACH(table, &p->tables, node)
+ n_tables++;
+
+ pipeline->n_ports_in = p->n_ports_in;
+ pipeline->n_ports_out = p->n_ports_out;
+ pipeline->n_actions = n_actions;
+ pipeline->n_tables = n_tables;
+ pipeline->n_selectors = p->n_selectors;
+ pipeline->n_learners = p->n_learners;
+ pipeline->n_regarrays = p->n_regarrays;
+ pipeline->n_metarrays = p->n_metarrays;
+
+ return 0;
+}
+
+int
+rte_swx_ctl_pipeline_numa_node_get(struct rte_swx_pipeline *p, int *numa_node)
+{
+ if (!p || !numa_node)
+ return -EINVAL;
+
+ *numa_node = p->numa_node;
+ return 0;
+}
+
+int
+rte_swx_ctl_action_info_get(struct rte_swx_pipeline *p,
+ uint32_t action_id,
+ struct rte_swx_ctl_action_info *action)
+{
+ struct action *a = NULL;
+
+ if (!p || (action_id >= p->n_actions) || !action)
+ return -EINVAL;
+
+ a = action_find_by_id(p, action_id);
+ if (!a)
+ return -EINVAL;
+
+ strcpy(action->name, a->name);
+ action->n_args = a->st ? a->st->n_fields : 0;
+ return 0;
+}
+
+int
+rte_swx_ctl_action_arg_info_get(struct rte_swx_pipeline *p,
+ uint32_t action_id,
+ uint32_t action_arg_id,
+ struct rte_swx_ctl_action_arg_info *action_arg)
+{
+ struct action *a = NULL;
+ struct field *arg = NULL;
+
+ if (!p || (action_id >= p->n_actions) || !action_arg)
+ return -EINVAL;
+
+ a = action_find_by_id(p, action_id);
+ if (!a || !a->st || (action_arg_id >= a->st->n_fields))
+ return -EINVAL;
+
+ arg = &a->st->fields[action_arg_id];
+ strcpy(action_arg->name, arg->name);
+ action_arg->n_bits = arg->n_bits;
+ action_arg->is_network_byte_order = a->args_endianness[action_arg_id];
+
+ return 0;
+}
+
+int
+rte_swx_ctl_table_info_get(struct rte_swx_pipeline *p,
+ uint32_t table_id,
+ struct rte_swx_ctl_table_info *table)
+{
+ struct table *t = NULL;
+
+ if (!p || !table)
+ return -EINVAL;
+
+ t = table_find_by_id(p, table_id);
+ if (!t)
+ return -EINVAL;
+
+ strcpy(table->name, t->name);
+ strcpy(table->args, t->args);
+ table->n_match_fields = t->n_fields;
+ table->n_actions = t->n_actions;
+ table->default_action_is_const = t->default_action_is_const;
+ table->size = t->size;
+ return 0;
+}
+
+int
+rte_swx_ctl_table_match_field_info_get(struct rte_swx_pipeline *p,
+ uint32_t table_id,
+ uint32_t match_field_id,
+ struct rte_swx_ctl_table_match_field_info *match_field)
+{
+ struct table *t;
+ struct match_field *f;
+
+ if (!p || (table_id >= p->n_tables) || !match_field)
+ return -EINVAL;
+
+ t = table_find_by_id(p, table_id);
+ if (!t || (match_field_id >= t->n_fields))
+ return -EINVAL;
+
+ f = &t->fields[match_field_id];
+ match_field->match_type = f->match_type;
+ match_field->is_header = t->header ? 1 : 0;
+ match_field->n_bits = f->field->n_bits;
+ match_field->offset = f->field->offset;
+
+ return 0;
+}
+
+int
+rte_swx_ctl_table_action_info_get(struct rte_swx_pipeline *p,
+ uint32_t table_id,
+ uint32_t table_action_id,
+ struct rte_swx_ctl_table_action_info *table_action)
+{
+ struct table *t;
+
+ if (!p || (table_id >= p->n_tables) || !table_action)
+ return -EINVAL;
+
+ t = table_find_by_id(p, table_id);
+ if (!t || (table_action_id >= t->n_actions))
+ return -EINVAL;
+
+ table_action->action_id = t->actions[table_action_id]->id;
+
+ table_action->action_is_for_table_entries = t->action_is_for_table_entries[table_action_id];
+ table_action->action_is_for_default_entry = t->action_is_for_default_entry[table_action_id];
+
+ return 0;
+}
+
+int
+rte_swx_ctl_table_ops_get(struct rte_swx_pipeline *p,
+ uint32_t table_id,
+ struct rte_swx_table_ops *table_ops,
+ int *is_stub)
+{
+ struct table *t;
+
+ if (!p || (table_id >= p->n_tables))
+ return -EINVAL;
+
+ t = table_find_by_id(p, table_id);
+ if (!t)
+ return -EINVAL;
+
+ if (t->type) {
+ if (table_ops)
+ memcpy(table_ops, &t->type->ops, sizeof(*table_ops));
+ *is_stub = 0;
+ } else {
+ *is_stub = 1;
+ }
+
+ return 0;
+}
+
+int
+rte_swx_ctl_selector_info_get(struct rte_swx_pipeline *p,
+ uint32_t selector_id,
+ struct rte_swx_ctl_selector_info *selector)
+{
+ struct selector *s = NULL;
+
+ if (!p || !selector)
+ return -EINVAL;
+
+ s = selector_find_by_id(p, selector_id);
+ if (!s)
+ return -EINVAL;
+
+ strcpy(selector->name, s->name);
+
+ selector->n_selector_fields = s->n_selector_fields;
+ selector->n_groups_max = s->n_groups_max;
+ selector->n_members_per_group_max = s->n_members_per_group_max;
+
+ return 0;
+}
+
+int
+rte_swx_ctl_selector_group_id_field_info_get(struct rte_swx_pipeline *p,
+ uint32_t selector_id,
+ struct rte_swx_ctl_table_match_field_info *field)
+{
+ struct selector *s;
+
+ if (!p || (selector_id >= p->n_selectors) || !field)
+ return -EINVAL;
+
+ s = selector_find_by_id(p, selector_id);
+ if (!s)
+ return -EINVAL;
+
+ field->match_type = RTE_SWX_TABLE_MATCH_EXACT;
+ field->is_header = 0;
+ field->n_bits = s->group_id_field->n_bits;
+ field->offset = s->group_id_field->offset;
+
+ return 0;
+}
+
+int
+rte_swx_ctl_selector_field_info_get(struct rte_swx_pipeline *p,
+ uint32_t selector_id,
+ uint32_t selector_field_id,
+ struct rte_swx_ctl_table_match_field_info *field)
+{
+ struct selector *s;
+ struct field *f;
+
+ if (!p || (selector_id >= p->n_selectors) || !field)
+ return -EINVAL;
+
+ s = selector_find_by_id(p, selector_id);
+ if (!s || (selector_field_id >= s->n_selector_fields))
+ return -EINVAL;
+
+ f = s->selector_fields[selector_field_id];
+ field->match_type = RTE_SWX_TABLE_MATCH_EXACT;
+ field->is_header = s->selector_header ? 1 : 0;
+ field->n_bits = f->n_bits;
+ field->offset = f->offset;
+
+ return 0;
+}
+
+int
+rte_swx_ctl_selector_member_id_field_info_get(struct rte_swx_pipeline *p,
+ uint32_t selector_id,
+ struct rte_swx_ctl_table_match_field_info *field)
+{
+ struct selector *s;
+
+ if (!p || (selector_id >= p->n_selectors) || !field)
+ return -EINVAL;
+
+ s = selector_find_by_id(p, selector_id);
+ if (!s)
+ return -EINVAL;
+
+ field->match_type = RTE_SWX_TABLE_MATCH_EXACT;
+ field->is_header = 0;
+ field->n_bits = s->member_id_field->n_bits;
+ field->offset = s->member_id_field->offset;
+
+ return 0;
+}
+
+int
+rte_swx_ctl_learner_info_get(struct rte_swx_pipeline *p,
+ uint32_t learner_id,
+ struct rte_swx_ctl_learner_info *learner)
+{
+ struct learner *l = NULL;
+
+ if (!p || !learner)
+ return -EINVAL;
+
+ l = learner_find_by_id(p, learner_id);
+ if (!l)
+ return -EINVAL;
+
+ strcpy(learner->name, l->name);
+
+ learner->n_match_fields = l->n_fields;
+ learner->n_actions = l->n_actions;
+ learner->default_action_is_const = l->default_action_is_const;
+ learner->size = l->size;
+
+ return 0;
+}
+
+int
+rte_swx_ctl_learner_match_field_info_get(struct rte_swx_pipeline *p,
+ uint32_t learner_id,
+ uint32_t match_field_id,
+ struct rte_swx_ctl_table_match_field_info *match_field)
+{
+ struct learner *l;
+ struct field *f;
+
+ if (!p || (learner_id >= p->n_learners) || !match_field)
+ return -EINVAL;
+
+ l = learner_find_by_id(p, learner_id);
+ if (!l || (match_field_id >= l->n_fields))
+ return -EINVAL;
+
+ f = l->fields[match_field_id];
+ match_field->match_type = RTE_SWX_TABLE_MATCH_EXACT;
+ match_field->is_header = l->header ? 1 : 0;
+ match_field->n_bits = f->n_bits;
+ match_field->offset = f->offset;
+
+ return 0;
+}
+
+int
+rte_swx_ctl_learner_action_info_get(struct rte_swx_pipeline *p,
+ uint32_t learner_id,
+ uint32_t learner_action_id,
+ struct rte_swx_ctl_table_action_info *learner_action)
+{
+ struct learner *l;
+
+ if (!p || (learner_id >= p->n_learners) || !learner_action)
+ return -EINVAL;
+
+ l = learner_find_by_id(p, learner_id);
+ if (!l || (learner_action_id >= l->n_actions))
+ return -EINVAL;
+
+ learner_action->action_id = l->actions[learner_action_id]->id;
+
+ learner_action->action_is_for_table_entries =
+ l->action_is_for_table_entries[learner_action_id];
+
+ learner_action->action_is_for_default_entry =
+ l->action_is_for_default_entry[learner_action_id];
+
+ return 0;
+}
+
+int
+rte_swx_pipeline_table_state_get(struct rte_swx_pipeline *p,
+ struct rte_swx_table_state **table_state)
+{
+ if (!p || !table_state || !p->build_done)
+ return -EINVAL;
+
+ *table_state = p->table_state;
+ return 0;
+}
+
+int
+rte_swx_pipeline_table_state_set(struct rte_swx_pipeline *p,
+ struct rte_swx_table_state *table_state)
+{
+ if (!p || !table_state || !p->build_done)
+ return -EINVAL;
+
+ p->table_state = table_state;
+ return 0;
+}
+
+int
+rte_swx_ctl_pipeline_port_in_stats_read(struct rte_swx_pipeline *p,
+ uint32_t port_id,
+ struct rte_swx_port_in_stats *stats)
+{
+ struct port_in *port;
+
+ if (!p || !stats)
+ return -EINVAL;
+
+ port = port_in_find(p, port_id);
+ if (!port)
+ return -EINVAL;
+
+ port->type->ops.stats_read(port->obj, stats);
+ return 0;
+}
+
+int
+rte_swx_ctl_pipeline_port_out_stats_read(struct rte_swx_pipeline *p,
+ uint32_t port_id,
+ struct rte_swx_port_out_stats *stats)
+{
+ struct port_out *port;
+
+ if (!p || !stats)
+ return -EINVAL;
+
+ port = port_out_find(p, port_id);
+ if (!port)
+ return -EINVAL;
+
+ port->type->ops.stats_read(port->obj, stats);
+ return 0;
+}
+
+int
+rte_swx_ctl_pipeline_table_stats_read(struct rte_swx_pipeline *p,
+ const char *table_name,
+ struct rte_swx_table_stats *stats)
+{
+ struct table *table;
+ struct table_statistics *table_stats;
+
+ if (!p || !table_name || !table_name[0] || !stats || !stats->n_pkts_action)
+ return -EINVAL;
+
+ table = table_find(p, table_name);
+ if (!table)
+ return -EINVAL;
+
+ table_stats = &p->table_stats[table->id];
+
+ memcpy(stats->n_pkts_action,
+ table_stats->n_pkts_action,
+ p->n_actions * sizeof(uint64_t));
+
+ stats->n_pkts_hit = table_stats->n_pkts_hit[1];
+ stats->n_pkts_miss = table_stats->n_pkts_hit[0];
+
+ return 0;
+}
+
+int
+rte_swx_ctl_pipeline_selector_stats_read(struct rte_swx_pipeline *p,
+ const char *selector_name,
+ struct rte_swx_pipeline_selector_stats *stats)
+{
+ struct selector *s;
+
+ if (!p || !selector_name || !selector_name[0] || !stats)
+ return -EINVAL;
+
+ s = selector_find(p, selector_name);
+ if (!s)
+ return -EINVAL;
+
+ stats->n_pkts = p->selector_stats[s->id].n_pkts;
+
+ return 0;
+}
+
+int
+rte_swx_ctl_pipeline_learner_stats_read(struct rte_swx_pipeline *p,
+ const char *learner_name,
+ struct rte_swx_learner_stats *stats)
+{
+ struct learner *l;
+ struct learner_statistics *learner_stats;
+
+ if (!p || !learner_name || !learner_name[0] || !stats || !stats->n_pkts_action)
+ return -EINVAL;
+
+ l = learner_find(p, learner_name);
+ if (!l)
+ return -EINVAL;
+
+ learner_stats = &p->learner_stats[l->id];
+
+ memcpy(stats->n_pkts_action,
+ learner_stats->n_pkts_action,
+ p->n_actions * sizeof(uint64_t));
+
+ stats->n_pkts_hit = learner_stats->n_pkts_hit[1];
+ stats->n_pkts_miss = learner_stats->n_pkts_hit[0];
+
+ stats->n_pkts_learn_ok = learner_stats->n_pkts_learn[0];
+ stats->n_pkts_learn_err = learner_stats->n_pkts_learn[1];
+
+ stats->n_pkts_forget = learner_stats->n_pkts_forget;
+
+ return 0;
+}
+
+int
+rte_swx_ctl_regarray_info_get(struct rte_swx_pipeline *p,
+ uint32_t regarray_id,
+ struct rte_swx_ctl_regarray_info *regarray)
+{
+ struct regarray *r;
+
+ if (!p || !regarray)
+ return -EINVAL;
+
+ r = regarray_find_by_id(p, regarray_id);
+ if (!r)
+ return -EINVAL;
+
+ strcpy(regarray->name, r->name);
+ regarray->size = r->size;
+ return 0;
+}
+
+int
+rte_swx_ctl_pipeline_regarray_read(struct rte_swx_pipeline *p,
+ const char *regarray_name,
+ uint32_t regarray_index,
+ uint64_t *value)
+{
+ struct regarray *regarray;
+ struct regarray_runtime *r;
+
+ if (!p || !regarray_name || !value)
+ return -EINVAL;
+
+ regarray = regarray_find(p, regarray_name);
+ if (!regarray || (regarray_index >= regarray->size))
+ return -EINVAL;
+
+ r = &p->regarray_runtime[regarray->id];
+ *value = r->regarray[regarray_index];
+ return 0;
+}
+
+int
+rte_swx_ctl_pipeline_regarray_write(struct rte_swx_pipeline *p,
+ const char *regarray_name,
+ uint32_t regarray_index,
+ uint64_t value)
+{
+ struct regarray *regarray;
+ struct regarray_runtime *r;
+
+ if (!p || !regarray_name)
+ return -EINVAL;
+
+ regarray = regarray_find(p, regarray_name);
+ if (!regarray || (regarray_index >= regarray->size))
+ return -EINVAL;
+
+ r = &p->regarray_runtime[regarray->id];
+ r->regarray[regarray_index] = value;
+ return 0;
+}
+
+int
+rte_swx_ctl_metarray_info_get(struct rte_swx_pipeline *p,
+ uint32_t metarray_id,
+ struct rte_swx_ctl_metarray_info *metarray)
+{
+ struct metarray *m;
+
+ if (!p || !metarray)
+ return -EINVAL;
+
+ m = metarray_find_by_id(p, metarray_id);
+ if (!m)
+ return -EINVAL;
+
+ strcpy(metarray->name, m->name);
+ metarray->size = m->size;
+ return 0;
+}
+
+int
+rte_swx_ctl_meter_profile_add(struct rte_swx_pipeline *p,
+ const char *name,
+ struct rte_meter_trtcm_params *params)
+{
+ struct meter_profile *mp;
+ int status;
+
+ CHECK(p, EINVAL);
+ CHECK_NAME(name, EINVAL);
+ CHECK(params, EINVAL);
+ CHECK(!meter_profile_find(p, name), EEXIST);
+
+ /* Node allocation. */
+ mp = calloc(1, sizeof(struct meter_profile));
+ CHECK(mp, ENOMEM);
+
+ /* Node initialization. */
+ strcpy(mp->name, name);
+ memcpy(&mp->params, params, sizeof(struct rte_meter_trtcm_params));
+ status = rte_meter_trtcm_profile_config(&mp->profile, params);
+ if (status) {
+ free(mp);
+ CHECK(0, EINVAL);
+ }
+
+ /* Node add to tailq. */
+ TAILQ_INSERT_TAIL(&p->meter_profiles, mp, node);