X-Git-Url: http://git.droids-corp.org/?a=blobdiff_plain;f=lib%2Flibrte_pipeline%2Frte_swx_pipeline.c;h=eaaed7a0a92520abd482f71511df327d509edbfa;hb=3a1aca384d3ac628dec8830714826e323f509dec;hp=77eae19278ca6bd5140f8ce467d277cce8c7d590;hpb=31035e87b20772696aa0a697cf18cc0ea2d2f536;p=dpdk.git diff --git a/lib/librte_pipeline/rte_swx_pipeline.c b/lib/librte_pipeline/rte_swx_pipeline.c index 77eae19278..eaaed7a0a9 100644 --- a/lib/librte_pipeline/rte_swx_pipeline.c +++ b/lib/librte_pipeline/rte_swx_pipeline.c @@ -5,6 +5,7 @@ #include #include #include +#include #include #include @@ -22,7 +23,17 @@ do { \ } while (0) #define CHECK_NAME(name, err_code) \ - CHECK((name) && (name)[0], err_code) + CHECK((name) && \ + (name)[0] && \ + (strnlen((name), RTE_SWX_NAME_SIZE) < RTE_SWX_NAME_SIZE), \ + err_code) + +#define CHECK_INSTRUCTION(instr, err_code) \ + CHECK((instr) && \ + (instr)[0] && \ + (strnlen((instr), RTE_SWX_INSTRUCTION_SIZE) < \ + RTE_SWX_INSTRUCTION_SIZE), \ + err_code) #ifndef TRACE_LEVEL #define TRACE_LEVEL 0 @@ -480,7 +491,7 @@ struct instr_dst_src { struct instr_operand dst; union { struct instr_operand src; - uint32_t src_val; + uint64_t src_val; }; }; @@ -508,7 +519,7 @@ struct instr_jmp { union { struct instr_operand b; - uint32_t b_val; + uint64_t b_val; }; }; @@ -1635,12 +1646,12 @@ rte_swx_pipeline_extern_type_member_func_register(struct rte_swx_pipeline *p, CHECK(p, EINVAL); - CHECK(extern_type_name, EINVAL); + CHECK_NAME(extern_type_name, EINVAL); type = extern_type_find(p, extern_type_name); CHECK(type, EINVAL); CHECK(type->n_funcs < RTE_SWX_EXTERN_TYPE_MEMBER_FUNCS_MAX, ENOSPC); - CHECK(name, EINVAL); + CHECK_NAME(name, EINVAL); CHECK(!extern_type_member_func_find(type, name), EEXIST); CHECK(member_func, EINVAL); @@ -3189,7 +3200,8 @@ instr_mov_translate(struct rte_swx_pipeline *p, { char *dst = tokens[1], *src = tokens[2]; struct field *fdst, *fsrc; - uint32_t dst_struct_id, src_struct_id, src_val; + uint64_t src_val; + uint32_t dst_struct_id, src_struct_id; CHECK(n_tokens == 3, EINVAL); @@ -3214,17 +3226,17 @@ instr_mov_translate(struct rte_swx_pipeline *p, } /* MOV_I. */ - src_val = strtoul(src, &src, 0); + src_val = strtoull(src, &src, 0); CHECK(!src[0], EINVAL); if (dst[0] == 'h') - src_val = htonl(src_val); + src_val = hton64(src_val) >> (64 - fdst->n_bits); instr->type = INSTR_MOV_I; instr->mov.dst.struct_id = (uint8_t)dst_struct_id; instr->mov.dst.n_bits = fdst->n_bits; instr->mov.dst.offset = fdst->offset / 8; - instr->mov.src_val = (uint32_t)src_val; + instr->mov.src_val = src_val; return 0; } @@ -3264,7 +3276,7 @@ instr_mov_i_exec(struct rte_swx_pipeline *p) struct thread *t = &p->threads[p->thread_id]; struct instruction *ip = t->ip; - TRACE("[Thread %2u] mov m.f %x\n", + TRACE("[Thread %2u] mov m.f %" PRIx64 "\n", p->thread_id, ip->mov.src_val); @@ -3451,7 +3463,8 @@ instr_alu_add_translate(struct rte_swx_pipeline *p, { char *dst = tokens[1], *src = tokens[2]; struct field *fdst, *fsrc; - uint32_t dst_struct_id, src_struct_id, src_val; + uint64_t src_val; + uint32_t dst_struct_id, src_struct_id; CHECK(n_tokens == 3, EINVAL); @@ -3479,7 +3492,7 @@ instr_alu_add_translate(struct rte_swx_pipeline *p, } /* ADD_MI, ADD_HI. */ - src_val = strtoul(src, &src, 0); + src_val = strtoull(src, &src, 0); CHECK(!src[0], EINVAL); instr->type = INSTR_ALU_ADD_MI; @@ -3489,7 +3502,7 @@ instr_alu_add_translate(struct rte_swx_pipeline *p, instr->alu.dst.struct_id = (uint8_t)dst_struct_id; instr->alu.dst.n_bits = fdst->n_bits; instr->alu.dst.offset = fdst->offset / 8; - instr->alu.src_val = (uint32_t)src_val; + instr->alu.src_val = src_val; return 0; } @@ -3503,7 +3516,8 @@ instr_alu_sub_translate(struct rte_swx_pipeline *p, { char *dst = tokens[1], *src = tokens[2]; struct field *fdst, *fsrc; - uint32_t dst_struct_id, src_struct_id, src_val; + uint64_t src_val; + uint32_t dst_struct_id, src_struct_id; CHECK(n_tokens == 3, EINVAL); @@ -3531,7 +3545,7 @@ instr_alu_sub_translate(struct rte_swx_pipeline *p, } /* SUB_MI, SUB_HI. */ - src_val = strtoul(src, &src, 0); + src_val = strtoull(src, &src, 0); CHECK(!src[0], EINVAL); instr->type = INSTR_ALU_SUB_MI; @@ -3541,7 +3555,7 @@ instr_alu_sub_translate(struct rte_swx_pipeline *p, instr->alu.dst.struct_id = (uint8_t)dst_struct_id; instr->alu.dst.n_bits = fdst->n_bits; instr->alu.dst.offset = fdst->offset / 8; - instr->alu.src_val = (uint32_t)src_val; + instr->alu.src_val = src_val; return 0; } @@ -3632,7 +3646,8 @@ instr_alu_shl_translate(struct rte_swx_pipeline *p, { char *dst = tokens[1], *src = tokens[2]; struct field *fdst, *fsrc; - uint32_t dst_struct_id, src_struct_id, src_val; + uint64_t src_val; + uint32_t dst_struct_id, src_struct_id; CHECK(n_tokens == 3, EINVAL); @@ -3660,7 +3675,7 @@ instr_alu_shl_translate(struct rte_swx_pipeline *p, } /* SHL_MI, SHL_HI. */ - src_val = strtoul(src, &src, 0); + src_val = strtoull(src, &src, 0); CHECK(!src[0], EINVAL); instr->type = INSTR_ALU_SHL_MI; @@ -3670,7 +3685,7 @@ instr_alu_shl_translate(struct rte_swx_pipeline *p, instr->alu.dst.struct_id = (uint8_t)dst_struct_id; instr->alu.dst.n_bits = fdst->n_bits; instr->alu.dst.offset = fdst->offset / 8; - instr->alu.src_val = (uint32_t)src_val; + instr->alu.src_val = src_val; return 0; } @@ -3684,7 +3699,8 @@ instr_alu_shr_translate(struct rte_swx_pipeline *p, { char *dst = tokens[1], *src = tokens[2]; struct field *fdst, *fsrc; - uint32_t dst_struct_id, src_struct_id, src_val; + uint64_t src_val; + uint32_t dst_struct_id, src_struct_id; CHECK(n_tokens == 3, EINVAL); @@ -3712,7 +3728,7 @@ instr_alu_shr_translate(struct rte_swx_pipeline *p, } /* SHR_MI, SHR_HI. */ - src_val = strtoul(src, &src, 0); + src_val = strtoull(src, &src, 0); CHECK(!src[0], EINVAL); instr->type = INSTR_ALU_SHR_MI; @@ -3722,7 +3738,7 @@ instr_alu_shr_translate(struct rte_swx_pipeline *p, instr->alu.dst.struct_id = (uint8_t)dst_struct_id; instr->alu.dst.n_bits = fdst->n_bits; instr->alu.dst.offset = fdst->offset / 8; - instr->alu.src_val = (uint32_t)src_val; + instr->alu.src_val = src_val; return 0; } @@ -3736,7 +3752,8 @@ instr_alu_and_translate(struct rte_swx_pipeline *p, { char *dst = tokens[1], *src = tokens[2]; struct field *fdst, *fsrc; - uint32_t dst_struct_id, src_struct_id, src_val; + uint64_t src_val; + uint32_t dst_struct_id, src_struct_id; CHECK(n_tokens == 3, EINVAL); @@ -3761,17 +3778,17 @@ instr_alu_and_translate(struct rte_swx_pipeline *p, } /* AND_I. */ - src_val = strtoul(src, &src, 0); + src_val = strtoull(src, &src, 0); CHECK(!src[0], EINVAL); if (dst[0] == 'h') - src_val = htonl(src_val); + src_val = hton64(src_val) >> (64 - fdst->n_bits); instr->type = INSTR_ALU_AND_I; instr->alu.dst.struct_id = (uint8_t)dst_struct_id; instr->alu.dst.n_bits = fdst->n_bits; instr->alu.dst.offset = fdst->offset / 8; - instr->alu.src_val = (uint32_t)src_val; + instr->alu.src_val = src_val; return 0; } @@ -3785,7 +3802,8 @@ instr_alu_or_translate(struct rte_swx_pipeline *p, { char *dst = tokens[1], *src = tokens[2]; struct field *fdst, *fsrc; - uint32_t dst_struct_id, src_struct_id, src_val; + uint64_t src_val; + uint32_t dst_struct_id, src_struct_id; CHECK(n_tokens == 3, EINVAL); @@ -3810,17 +3828,17 @@ instr_alu_or_translate(struct rte_swx_pipeline *p, } /* OR_I. */ - src_val = strtoul(src, &src, 0); + src_val = strtoull(src, &src, 0); CHECK(!src[0], EINVAL); if (dst[0] == 'h') - src_val = htonl(src_val); + src_val = hton64(src_val) >> (64 - fdst->n_bits); instr->type = INSTR_ALU_OR_I; instr->alu.dst.struct_id = (uint8_t)dst_struct_id; instr->alu.dst.n_bits = fdst->n_bits; instr->alu.dst.offset = fdst->offset / 8; - instr->alu.src_val = (uint32_t)src_val; + instr->alu.src_val = src_val; return 0; } @@ -3834,7 +3852,8 @@ instr_alu_xor_translate(struct rte_swx_pipeline *p, { char *dst = tokens[1], *src = tokens[2]; struct field *fdst, *fsrc; - uint32_t dst_struct_id, src_struct_id, src_val; + uint64_t src_val; + uint32_t dst_struct_id, src_struct_id; CHECK(n_tokens == 3, EINVAL); @@ -3859,17 +3878,17 @@ instr_alu_xor_translate(struct rte_swx_pipeline *p, } /* XOR_I. */ - src_val = strtoul(src, &src, 0); + src_val = strtoull(src, &src, 0); CHECK(!src[0], EINVAL); if (dst[0] == 'h') - src_val = htonl(src_val); + src_val = hton64(src_val) >> (64 - fdst->n_bits); instr->type = INSTR_ALU_XOR_I; instr->alu.dst.struct_id = (uint8_t)dst_struct_id; instr->alu.dst.n_bits = fdst->n_bits; instr->alu.dst.offset = fdst->offset / 8; - instr->alu.src_val = (uint32_t)src_val; + instr->alu.src_val = src_val; return 0; } @@ -4658,7 +4677,7 @@ instr_jmp_invalid_translate(struct rte_swx_pipeline *p, { struct header *h; - CHECK(n_tokens == 2, EINVAL); + CHECK(n_tokens == 3, EINVAL); strcpy(data->jmp_label, tokens[1]); @@ -4765,7 +4784,8 @@ instr_jmp_eq_translate(struct rte_swx_pipeline *p, { char *a = tokens[2], *b = tokens[3]; struct field *fa, *fb; - uint32_t a_struct_id, b_struct_id, b_val; + uint64_t b_val; + uint32_t a_struct_id, b_struct_id; CHECK(n_tokens == 4, EINVAL); @@ -4793,18 +4813,18 @@ instr_jmp_eq_translate(struct rte_swx_pipeline *p, } /* JMP_EQ_I. */ - b_val = strtoul(b, &b, 0); + b_val = strtoull(b, &b, 0); CHECK(!b[0], EINVAL); if (a[0] == 'h') - b_val = htonl(b_val); + b_val = hton64(b_val) >> (64 - fa->n_bits); instr->type = INSTR_JMP_EQ_I; instr->jmp.ip = NULL; /* Resolved later. */ instr->jmp.a.struct_id = (uint8_t)a_struct_id; instr->jmp.a.n_bits = fa->n_bits; instr->jmp.a.offset = fa->offset / 8; - instr->jmp.b_val = (uint32_t)b_val; + instr->jmp.b_val = b_val; return 0; } @@ -4818,7 +4838,8 @@ instr_jmp_neq_translate(struct rte_swx_pipeline *p, { char *a = tokens[2], *b = tokens[3]; struct field *fa, *fb; - uint32_t a_struct_id, b_struct_id, b_val; + uint64_t b_val; + uint32_t a_struct_id, b_struct_id; CHECK(n_tokens == 4, EINVAL); @@ -4846,18 +4867,18 @@ instr_jmp_neq_translate(struct rte_swx_pipeline *p, } /* JMP_NEQ_I. */ - b_val = strtoul(b, &b, 0); + b_val = strtoull(b, &b, 0); CHECK(!b[0], EINVAL); if (a[0] == 'h') - b_val = htonl(b_val); + b_val = hton64(b_val) >> (64 - fa->n_bits); instr->type = INSTR_JMP_NEQ_I; instr->jmp.ip = NULL; /* Resolved later. */ instr->jmp.a.struct_id = (uint8_t)a_struct_id; instr->jmp.a.n_bits = fa->n_bits; instr->jmp.a.offset = fa->offset / 8; - instr->jmp.b_val = (uint32_t)b_val; + instr->jmp.b_val = b_val; return 0; } @@ -4871,7 +4892,8 @@ instr_jmp_lt_translate(struct rte_swx_pipeline *p, { char *a = tokens[2], *b = tokens[3]; struct field *fa, *fb; - uint32_t a_struct_id, b_struct_id, b_val; + uint64_t b_val; + uint32_t a_struct_id, b_struct_id; CHECK(n_tokens == 4, EINVAL); @@ -4902,7 +4924,7 @@ instr_jmp_lt_translate(struct rte_swx_pipeline *p, } /* JMP_LT_MI, JMP_LT_HI. */ - b_val = strtoul(b, &b, 0); + b_val = strtoull(b, &b, 0); CHECK(!b[0], EINVAL); instr->type = INSTR_JMP_LT_MI; @@ -4913,7 +4935,7 @@ instr_jmp_lt_translate(struct rte_swx_pipeline *p, instr->jmp.a.struct_id = (uint8_t)a_struct_id; instr->jmp.a.n_bits = fa->n_bits; instr->jmp.a.offset = fa->offset / 8; - instr->jmp.b_val = (uint32_t)b_val; + instr->jmp.b_val = b_val; return 0; } @@ -4927,7 +4949,8 @@ instr_jmp_gt_translate(struct rte_swx_pipeline *p, { char *a = tokens[2], *b = tokens[3]; struct field *fa, *fb; - uint32_t a_struct_id, b_struct_id, b_val; + uint64_t b_val; + uint32_t a_struct_id, b_struct_id; CHECK(n_tokens == 4, EINVAL); @@ -4958,7 +4981,7 @@ instr_jmp_gt_translate(struct rte_swx_pipeline *p, } /* JMP_GT_MI, JMP_GT_HI. */ - b_val = strtoul(b, &b, 0); + b_val = strtoull(b, &b, 0); CHECK(!b[0], EINVAL); instr->type = INSTR_JMP_GT_MI; @@ -4969,7 +4992,7 @@ instr_jmp_gt_translate(struct rte_swx_pipeline *p, instr->jmp.a.struct_id = (uint8_t)a_struct_id; instr->jmp.a.n_bits = fa->n_bits; instr->jmp.a.offset = fa->offset / 8; - instr->jmp.b_val = (uint32_t)b_val; + instr->jmp.b_val = b_val; return 0; } @@ -5280,8 +5303,6 @@ instr_return_exec(struct rte_swx_pipeline *p) t->ip = t->ret; } -#define RTE_SWX_INSTRUCTION_TOKENS_MAX 16 - static int instr_translate(struct rte_swx_pipeline *p, struct action *action, @@ -5301,6 +5322,7 @@ instr_translate(struct rte_swx_pipeline *p, break; CHECK(n_tokens < RTE_SWX_INSTRUCTION_TOKENS_MAX, EINVAL); + CHECK_NAME(token, EINVAL); tokens[n_tokens] = token; n_tokens++; @@ -5647,7 +5669,7 @@ instr_jmp_resolve(struct instruction *instructions, data->jmp_label); CHECK(found, EINVAL); - instr->jmp.ip = &instr[found - instruction_data]; + instr->jmp.ip = &instructions[found - instruction_data]; } return 0; @@ -5671,7 +5693,7 @@ instr_verify(struct rte_swx_pipeline *p __rte_unused, for (i = 0; i < n_instructions; i++) { type = instr[i].type; - if (instr[i].type == INSTR_TX) + if (type == INSTR_TX) break; } CHECK(i < n_instructions, EINVAL); @@ -5774,6 +5796,9 @@ instr_pattern_emit_many_tx_detect(struct instruction *instr, if (instr[i].type != INSTR_TX) return 0; + if (data[i].n_users) + return 0; + i++; *n_pattern_instr = i; @@ -5932,14 +5957,13 @@ instruction_config(struct rte_swx_pipeline *p, { struct instruction *instr = NULL; struct instruction_data *data = NULL; - char *string = NULL; int err = 0; uint32_t i; CHECK(n_instructions, EINVAL); CHECK(instructions, EINVAL); for (i = 0; i < n_instructions; i++) - CHECK(instructions[i], EINVAL); + CHECK_INSTRUCTION(instructions[i], EINVAL); /* Memory allocation. */ instr = calloc(n_instructions, sizeof(struct instruction)); @@ -5955,15 +5979,17 @@ instruction_config(struct rte_swx_pipeline *p, } for (i = 0; i < n_instructions; i++) { - string = strdup(instructions[i]); + char *string = strdup(instructions[i]); if (!string) { err = ENOMEM; goto error; } err = instr_translate(p, a, string, &instr[i], &data[i]); - if (err) + if (err) { + free(string); goto error; + } free(string); } @@ -5982,8 +6008,6 @@ instruction_config(struct rte_swx_pipeline *p, if (err) goto error; - free(data); - if (a) { a->instructions = instr; a->n_instructions = n_instructions; @@ -5992,10 +6016,10 @@ instruction_config(struct rte_swx_pipeline *p, p->n_instructions = n_instructions; } + free(data); return 0; error: - free(string); free(data); free(instr); return err; @@ -6152,6 +6176,18 @@ action_find(struct rte_swx_pipeline *p, const char *name) return NULL; } +static struct action * +action_find_by_id(struct rte_swx_pipeline *p, uint32_t id) +{ + struct action *action = NULL; + + TAILQ_FOREACH(action, &p->actions, node) + if (action->id == id) + return action; + + return NULL; +} + static struct field * action_field_find(struct action *a, const char *name) { @@ -6431,7 +6467,7 @@ rte_swx_pipeline_table_config(struct rte_swx_pipeline *p, struct action *a; uint32_t action_data_size; - CHECK(action_name, EINVAL); + CHECK_NAME(action_name, EINVAL); a = action_find(p, action_name); CHECK(a, EINVAL); @@ -6441,7 +6477,7 @@ rte_swx_pipeline_table_config(struct rte_swx_pipeline *p, action_data_size_max = action_data_size; } - CHECK(params->default_action_name, 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)) @@ -6452,6 +6488,9 @@ rte_swx_pipeline_table_config(struct rte_swx_pipeline *p, !params->default_action_data, EINVAL); /* Table type checks. */ + if (recommended_table_type_name) + CHECK_NAME(recommended_table_type_name, EINVAL); + if (params->n_fields) { enum rte_swx_table_match_type match_type; @@ -6939,9 +6978,193 @@ rte_swx_pipeline_run(struct rte_swx_pipeline *p, uint32_t n_instructions) 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; + + 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; + + 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->is_header; + 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; + + 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_pipeline_table_state_get(struct rte_swx_pipeline *p, struct rte_swx_table_state **table_state) @@ -6963,3 +7186,39 @@ rte_swx_pipeline_table_state_set(struct rte_swx_pipeline *p, 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; +}