diff options
author | Luca Boccassi <luca.boccassi@gmail.com> | 2017-11-08 14:15:11 +0000 |
---|---|---|
committer | Luca Boccassi <luca.boccassi@gmail.com> | 2017-11-08 14:45:54 +0000 |
commit | 055c52583a2794da8ba1e85a48cce3832372b12f (patch) | |
tree | 8ceb1cb78fbb46a0f341f8ee24feb3c6b5540013 /app | |
parent | f239aed5e674965691846e8ce3f187dd47523689 (diff) |
New upstream version 17.11-rc3
Change-Id: I6a5baa40612fe0c20f30b5fa773a6cbbac63a685
Signed-off-by: Luca Boccassi <luca.boccassi@gmail.com>
Diffstat (limited to 'app')
48 files changed, 7914 insertions, 1330 deletions
diff --git a/app/pdump/main.c b/app/pdump/main.c index 3b13753d..66272f59 100644 --- a/app/pdump/main.c +++ b/app/pdump/main.c @@ -131,7 +131,7 @@ struct pdump_stats { struct pdump_tuples { /* cli params */ - uint8_t port; + uint16_t port; char *device_id; uint16_t queue; char rx_dev[TX_STREAM_SIZE]; @@ -579,7 +579,7 @@ signal_handler(int sig_num) } static inline int -configure_vdev(uint8_t port_id) +configure_vdev(uint16_t port_id) { struct ether_addr addr; const uint16_t rxRings = 0, txRings = 1; @@ -609,7 +609,7 @@ configure_vdev(uint8_t port_id) rte_eth_macaddr_get(port_id, &addr); printf("Port %u MAC: %02"PRIx8" %02"PRIx8" %02"PRIx8 " %02"PRIx8" %02"PRIx8" %02"PRIx8"\n", - (unsigned)port_id, + port_id, addr.addr_bytes[0], addr.addr_bytes[1], addr.addr_bytes[2], addr.addr_bytes[3], addr.addr_bytes[4], addr.addr_bytes[5]); @@ -623,7 +623,7 @@ static void create_mp_ring_vdev(void) { int i; - uint8_t portid; + uint16_t portid; struct pdump_tuples *pt = NULL; struct rte_mempool *mbuf_pool = NULL; char vdev_args[SIZE]; diff --git a/app/proc_info/main.c b/app/proc_info/main.c index 8b753a2e..64fbbd0f 100644 --- a/app/proc_info/main.c +++ b/app/proc_info/main.c @@ -310,7 +310,7 @@ meminfo_display(void) } static void -nic_stats_display(uint8_t port_id) +nic_stats_display(uint16_t port_id) { struct rte_eth_stats stats; uint8_t i; @@ -349,7 +349,7 @@ nic_stats_display(uint8_t port_id) } static void -nic_stats_clear(uint8_t port_id) +nic_stats_clear(uint16_t port_id) { printf("\n Clearing NIC stats for port %d\n", port_id); rte_eth_stats_reset(port_id); @@ -411,7 +411,7 @@ static void collectd_resolve_cnt_type(char *cnt_type, size_t cnt_type_len, } static void -nic_xstats_by_name_display(uint8_t port_id, char *name) +nic_xstats_by_name_display(uint16_t port_id, char *name) { uint64_t id; @@ -426,7 +426,7 @@ nic_xstats_by_name_display(uint8_t port_id, char *name) } static void -nic_xstats_by_ids_display(uint8_t port_id, uint64_t *ids, int len) +nic_xstats_by_ids_display(uint16_t port_id, uint64_t *ids, int len) { struct rte_eth_xstat_name *xstats_names; uint64_t *values; @@ -473,7 +473,7 @@ err: } static void -nic_xstats_display(uint8_t port_id) +nic_xstats_display(uint16_t port_id) { struct rte_eth_xstat_name *xstats_names; uint64_t *values; @@ -524,7 +524,9 @@ nic_xstats_display(uint8_t port_id) sprintf(buf, "PUTVAL %s/dpdkstat-port.%u/%s-%s N:%" PRIu64"\n", host_id, port_id, counter_type, xstats_names[i].name, values[i]); - write(stdout_fd, buf, strlen(buf)); + ret = write(stdout_fd, buf, strlen(buf)); + if (ret < 0) + goto err; } else { printf("%s: %"PRIu64"\n", xstats_names[i].name, values[i]); @@ -539,7 +541,7 @@ err: } static void -nic_xstats_clear(uint8_t port_id) +nic_xstats_clear(uint16_t port_id) { printf("\n Clearing NIC xstats for port %d\n", port_id); rte_eth_xstats_reset(port_id); @@ -616,7 +618,7 @@ main(int argc, char **argv) char n_flag[] = "-n4"; char mp_flag[] = "--proc-type=secondary"; char *argp[argc + 3]; - uint8_t nb_ports; + uint16_t nb_ports; /* preparse app arguments */ ret = proc_info_preparse_args(argc, argv); diff --git a/app/test-crypto-perf/Makefile b/app/test-crypto-perf/Makefile index e4a989fe..c75d7ed1 100644 --- a/app/test-crypto-perf/Makefile +++ b/app/test-crypto-perf/Makefile @@ -42,7 +42,13 @@ SRCS-y += cperf_options_parsing.c SRCS-y += cperf_test_vectors.c SRCS-y += cperf_test_throughput.c SRCS-y += cperf_test_latency.c +SRCS-y += cperf_test_pmd_cyclecount.c SRCS-y += cperf_test_verify.c SRCS-y += cperf_test_vector_parsing.c +SRCS-y += cperf_test_common.c + +ifeq ($(CONFIG_RTE_LIBRTE_PMD_CRYPTO_SCHEDULER),y) +LDLIBS += -lrte_pmd_crypto_scheduler +endif include $(RTE_SDK)/mk/rte.app.mk diff --git a/app/test-crypto-perf/cperf_ops.c b/app/test-crypto-perf/cperf_ops.c index 88fb9725..23d30ca3 100644 --- a/app/test-crypto-perf/cperf_ops.c +++ b/app/test-crypto-perf/cperf_ops.c @@ -37,7 +37,7 @@ static int cperf_set_ops_null_cipher(struct rte_crypto_op **ops, - struct rte_mbuf **bufs_in, struct rte_mbuf **bufs_out, + uint32_t src_buf_offset, uint32_t dst_buf_offset, uint16_t nb_ops, struct rte_cryptodev_sym_session *sess, const struct cperf_options *options, const struct cperf_test_vector *test_vector __rte_unused, @@ -48,10 +48,18 @@ cperf_set_ops_null_cipher(struct rte_crypto_op **ops, for (i = 0; i < nb_ops; i++) { struct rte_crypto_sym_op *sym_op = ops[i]->sym; + ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; rte_crypto_op_attach_sym_session(ops[i], sess); - sym_op->m_src = bufs_in[i]; - sym_op->m_dst = bufs_out[i]; + sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + + src_buf_offset); + + /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */ + if (dst_buf_offset == 0) + sym_op->m_dst = NULL; + else + sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] + + dst_buf_offset); /* cipher parameters */ sym_op->cipher.data.length = options->test_buffer_size; @@ -63,7 +71,7 @@ cperf_set_ops_null_cipher(struct rte_crypto_op **ops, static int cperf_set_ops_null_auth(struct rte_crypto_op **ops, - struct rte_mbuf **bufs_in, struct rte_mbuf **bufs_out, + uint32_t src_buf_offset, uint32_t dst_buf_offset, uint16_t nb_ops, struct rte_cryptodev_sym_session *sess, const struct cperf_options *options, const struct cperf_test_vector *test_vector __rte_unused, @@ -74,10 +82,18 @@ cperf_set_ops_null_auth(struct rte_crypto_op **ops, for (i = 0; i < nb_ops; i++) { struct rte_crypto_sym_op *sym_op = ops[i]->sym; + ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; rte_crypto_op_attach_sym_session(ops[i], sess); - sym_op->m_src = bufs_in[i]; - sym_op->m_dst = bufs_out[i]; + sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + + src_buf_offset); + + /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */ + if (dst_buf_offset == 0) + sym_op->m_dst = NULL; + else + sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] + + dst_buf_offset); /* auth parameters */ sym_op->auth.data.length = options->test_buffer_size; @@ -89,7 +105,7 @@ cperf_set_ops_null_auth(struct rte_crypto_op **ops, static int cperf_set_ops_cipher(struct rte_crypto_op **ops, - struct rte_mbuf **bufs_in, struct rte_mbuf **bufs_out, + uint32_t src_buf_offset, uint32_t dst_buf_offset, uint16_t nb_ops, struct rte_cryptodev_sym_session *sess, const struct cperf_options *options, const struct cperf_test_vector *test_vector, @@ -100,10 +116,18 @@ cperf_set_ops_cipher(struct rte_crypto_op **ops, for (i = 0; i < nb_ops; i++) { struct rte_crypto_sym_op *sym_op = ops[i]->sym; + ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; rte_crypto_op_attach_sym_session(ops[i], sess); - sym_op->m_src = bufs_in[i]; - sym_op->m_dst = bufs_out[i]; + sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + + src_buf_offset); + + /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */ + if (dst_buf_offset == 0) + sym_op->m_dst = NULL; + else + sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] + + dst_buf_offset); /* cipher parameters */ if (options->cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || @@ -132,7 +156,7 @@ cperf_set_ops_cipher(struct rte_crypto_op **ops, static int cperf_set_ops_auth(struct rte_crypto_op **ops, - struct rte_mbuf **bufs_in, struct rte_mbuf **bufs_out, + uint32_t src_buf_offset, uint32_t dst_buf_offset, uint16_t nb_ops, struct rte_cryptodev_sym_session *sess, const struct cperf_options *options, const struct cperf_test_vector *test_vector, @@ -143,10 +167,18 @@ cperf_set_ops_auth(struct rte_crypto_op **ops, for (i = 0; i < nb_ops; i++) { struct rte_crypto_sym_op *sym_op = ops[i]->sym; + ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; rte_crypto_op_attach_sym_session(ops[i], sess); - sym_op->m_src = bufs_in[i]; - sym_op->m_dst = bufs_out[i]; + sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + + src_buf_offset); + + /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */ + if (dst_buf_offset == 0) + sym_op->m_dst = NULL; + else + sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] + + dst_buf_offset); if (test_vector->auth_iv.length) { uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i], @@ -167,21 +199,29 @@ cperf_set_ops_auth(struct rte_crypto_op **ops, struct rte_mbuf *buf, *tbuf; if (options->out_of_place) { - buf = bufs_out[i]; + buf = sym_op->m_dst; } else { - tbuf = bufs_in[i]; + tbuf = sym_op->m_src; while ((tbuf->next != NULL) && (offset >= tbuf->data_len)) { offset -= tbuf->data_len; tbuf = tbuf->next; } + /* + * If there is not enough room in segment, + * place the digest in the next segment + */ + if ((tbuf->data_len - offset) < options->digest_sz) { + tbuf = tbuf->next; + offset = 0; + } buf = tbuf; } sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(buf, uint8_t *, offset); sym_op->auth.digest.phys_addr = - rte_pktmbuf_mtophys_offset(buf, offset); + rte_pktmbuf_iova_offset(buf, offset); } @@ -211,7 +251,7 @@ cperf_set_ops_auth(struct rte_crypto_op **ops, static int cperf_set_ops_cipher_auth(struct rte_crypto_op **ops, - struct rte_mbuf **bufs_in, struct rte_mbuf **bufs_out, + uint32_t src_buf_offset, uint32_t dst_buf_offset, uint16_t nb_ops, struct rte_cryptodev_sym_session *sess, const struct cperf_options *options, const struct cperf_test_vector *test_vector, @@ -222,10 +262,18 @@ cperf_set_ops_cipher_auth(struct rte_crypto_op **ops, for (i = 0; i < nb_ops; i++) { struct rte_crypto_sym_op *sym_op = ops[i]->sym; + ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; rte_crypto_op_attach_sym_session(ops[i], sess); - sym_op->m_src = bufs_in[i]; - sym_op->m_dst = bufs_out[i]; + sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + + src_buf_offset); + + /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */ + if (dst_buf_offset == 0) + sym_op->m_dst = NULL; + else + sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] + + dst_buf_offset); /* cipher parameters */ if (options->cipher_algo == RTE_CRYPTO_CIPHER_SNOW3G_UEA2 || @@ -248,21 +296,29 @@ cperf_set_ops_cipher_auth(struct rte_crypto_op **ops, struct rte_mbuf *buf, *tbuf; if (options->out_of_place) { - buf = bufs_out[i]; + buf = sym_op->m_dst; } else { - tbuf = bufs_in[i]; + tbuf = sym_op->m_src; while ((tbuf->next != NULL) && (offset >= tbuf->data_len)) { offset -= tbuf->data_len; tbuf = tbuf->next; } + /* + * If there is not enough room in segment, + * place the digest in the next segment + */ + if ((tbuf->data_len - offset) < options->digest_sz) { + tbuf = tbuf->next; + offset = 0; + } buf = tbuf; } sym_op->auth.digest.data = rte_pktmbuf_mtod_offset(buf, uint8_t *, offset); sym_op->auth.digest.phys_addr = - rte_pktmbuf_mtophys_offset(buf, offset); + rte_pktmbuf_iova_offset(buf, offset); } if (options->auth_algo == RTE_CRYPTO_AUTH_SNOW3G_UIA2 || @@ -300,29 +356,41 @@ cperf_set_ops_cipher_auth(struct rte_crypto_op **ops, static int cperf_set_ops_aead(struct rte_crypto_op **ops, - struct rte_mbuf **bufs_in, struct rte_mbuf **bufs_out, + uint32_t src_buf_offset, uint32_t dst_buf_offset, uint16_t nb_ops, struct rte_cryptodev_sym_session *sess, const struct cperf_options *options, const struct cperf_test_vector *test_vector, uint16_t iv_offset) { uint16_t i; + /* AAD is placed after the IV */ + uint16_t aad_offset = iv_offset + + RTE_ALIGN_CEIL(test_vector->aead_iv.length, 16); for (i = 0; i < nb_ops; i++) { struct rte_crypto_sym_op *sym_op = ops[i]->sym; + ops[i]->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; rte_crypto_op_attach_sym_session(ops[i], sess); - sym_op->m_src = bufs_in[i]; - sym_op->m_dst = bufs_out[i]; + sym_op->m_src = (struct rte_mbuf *)((uint8_t *)ops[i] + + src_buf_offset); + + /* Set dest mbuf to NULL if out-of-place (dst_buf_offset = 0) */ + if (dst_buf_offset == 0) + sym_op->m_dst = NULL; + else + sym_op->m_dst = (struct rte_mbuf *)((uint8_t *)ops[i] + + dst_buf_offset); /* AEAD parameters */ sym_op->aead.data.length = options->test_buffer_size; - sym_op->aead.data.offset = - RTE_ALIGN_CEIL(options->aead_aad_sz, 16); + sym_op->aead.data.offset = 0; - sym_op->aead.aad.data = rte_pktmbuf_mtod(bufs_in[i], uint8_t *); - sym_op->aead.aad.phys_addr = rte_pktmbuf_mtophys(bufs_in[i]); + sym_op->aead.aad.data = rte_crypto_op_ctod_offset(ops[i], + uint8_t *, aad_offset); + sym_op->aead.aad.phys_addr = rte_crypto_op_ctophys_offset(ops[i], + aad_offset); if (options->aead_op == RTE_CRYPTO_AEAD_OP_DECRYPT) { sym_op->aead.digest.data = test_vector->digest.data; @@ -335,21 +403,29 @@ cperf_set_ops_aead(struct rte_crypto_op **ops, struct rte_mbuf *buf, *tbuf; if (options->out_of_place) { - buf = bufs_out[i]; + buf = sym_op->m_dst; } else { - tbuf = bufs_in[i]; + tbuf = sym_op->m_src; while ((tbuf->next != NULL) && (offset >= tbuf->data_len)) { offset -= tbuf->data_len; tbuf = tbuf->next; } + /* + * If there is not enough room in segment, + * place the digest in the next segment + */ + if ((tbuf->data_len - offset) < options->digest_sz) { + tbuf = tbuf->next; + offset = 0; + } buf = tbuf; } sym_op->aead.digest.data = rte_pktmbuf_mtod_offset(buf, uint8_t *, offset); sym_op->aead.digest.phys_addr = - rte_pktmbuf_mtophys_offset(buf, offset); + rte_pktmbuf_iova_offset(buf, offset); } } @@ -358,8 +434,26 @@ cperf_set_ops_aead(struct rte_crypto_op **ops, uint8_t *iv_ptr = rte_crypto_op_ctod_offset(ops[i], uint8_t *, iv_offset); - memcpy(iv_ptr, test_vector->aead_iv.data, + /* + * If doing AES-CCM, nonce is copied one byte + * after the start of IV field, and AAD is copied + * 18 bytes after the start of the AAD field. + */ + if (options->aead_algo == RTE_CRYPTO_AEAD_AES_CCM) { + memcpy(iv_ptr + 1, test_vector->aead_iv.data, test_vector->aead_iv.length); + + memcpy(ops[i]->sym->aead.aad.data + 18, + test_vector->aad.data, + test_vector->aad.length); + } else { + memcpy(iv_ptr, test_vector->aead_iv.data, + test_vector->aead_iv.length); + + memcpy(ops[i]->sym->aead.aad.data, + test_vector->aad.data, + test_vector->aad.length); + } } } diff --git a/app/test-crypto-perf/cperf_ops.h b/app/test-crypto-perf/cperf_ops.h index 1f8fa937..94951cc3 100644 --- a/app/test-crypto-perf/cperf_ops.h +++ b/app/test-crypto-perf/cperf_ops.h @@ -47,7 +47,7 @@ typedef struct rte_cryptodev_sym_session *(*cperf_sessions_create_t)( uint16_t iv_offset); typedef int (*cperf_populate_ops_t)(struct rte_crypto_op **ops, - struct rte_mbuf **bufs_in, struct rte_mbuf **bufs_out, + uint32_t src_buf_offset, uint32_t dst_buf_offset, uint16_t nb_ops, struct rte_cryptodev_sym_session *sess, const struct cperf_options *options, const struct cperf_test_vector *test_vector, diff --git a/app/test-crypto-perf/cperf_options.h b/app/test-crypto-perf/cperf_options.h index 10cd2d8a..da4fb47c 100644 --- a/app/test-crypto-perf/cperf_options.h +++ b/app/test-crypto-perf/cperf_options.h @@ -11,7 +11,8 @@ #define CPERF_TOTAL_OPS ("total-ops") #define CPERF_BURST_SIZE ("burst-sz") #define CPERF_BUFFER_SIZE ("buffer-sz") -#define CPERF_SEGMENTS_NB ("segments-nb") +#define CPERF_SEGMENT_SIZE ("segment-sz") +#define CPERF_DESC_NB ("desc-nb") #define CPERF_DEVTYPE ("devtype") #define CPERF_OPTYPE ("optype") @@ -40,12 +41,16 @@ #define CPERF_CSV ("csv-friendly") +/* benchmark-specific options */ +#define CPERF_PMDCC_DELAY_MS ("pmd-cyclecount-delay-ms") + #define MAX_LIST 32 enum cperf_perf_test_type { CPERF_TEST_TYPE_THROUGHPUT, CPERF_TEST_TYPE_LATENCY, - CPERF_TEST_TYPE_VERIFY + CPERF_TEST_TYPE_VERIFY, + CPERF_TEST_TYPE_PMDCC }; @@ -66,8 +71,10 @@ struct cperf_options { uint32_t pool_sz; uint32_t total_ops; - uint32_t segments_nb; + uint32_t segment_sz; uint32_t test_buffer_size; + uint32_t nb_descriptors; + uint16_t nb_qps; uint32_t sessionless:1; uint32_t out_of_place:1; @@ -113,6 +120,8 @@ struct cperf_options { uint32_t min_burst_size; uint32_t inc_burst_size; + /* pmd-cyclecount specific options */ + uint32_t pmdcc_delay; }; void diff --git a/app/test-crypto-perf/cperf_options_parsing.c b/app/test-crypto-perf/cperf_options_parsing.c index 085aa8fe..ad43e84c 100644 --- a/app/test-crypto-perf/cperf_options_parsing.c +++ b/app/test-crypto-perf/cperf_options_parsing.c @@ -46,6 +46,47 @@ struct name_id_map { uint32_t id; }; +static void +usage(char *progname) +{ + printf("%s [EAL options] --\n" + " --silent: disable options dump\n" + " --ptest throughput / latency / verify / pmd-cycleount :" + " set test type\n" + " --pool_sz N: set the number of crypto ops/mbufs allocated\n" + " --total-ops N: set the number of total operations performed\n" + " --burst-sz N: set the number of packets per burst\n" + " --buffer-sz N: set the size of a single packet\n" + " --segment-sz N: set the size of the segment to use\n" + " --desc-nb N: set number of descriptors for each crypto device\n" + " --devtype TYPE: set crypto device type to use\n" + " --optype cipher-only / auth-only / cipher-then-auth /\n" + " auth-then-cipher / aead : set operation type\n" + " --sessionless: enable session-less crypto operations\n" + " --out-of-place: enable out-of-place crypto operations\n" + " --test-file NAME: set the test vector file path\n" + " --test-name NAME: set specific test name section in test file\n" + " --cipher-algo ALGO: set cipher algorithm\n" + " --cipher-op encrypt / decrypt: set the cipher operation\n" + " --cipher-key-sz N: set the cipher key size\n" + " --cipher-iv-sz N: set the cipher IV size\n" + " --auth-algo ALGO: set auth algorithm\n" + " --auth-op generate / verify: set the auth operation\n" + " --auth-key-sz N: set the auth key size\n" + " --auth-iv-sz N: set the auth IV size\n" + " --aead-algo ALGO: set AEAD algorithm\n" + " --aead-op encrypt / decrypt: set the AEAD operation\n" + " --aead-key-sz N: set the AEAD key size\n" + " --aead-iv-sz N: set the AEAD IV size\n" + " --aead-aad-sz N: set the AEAD AAD size\n" + " --digest-sz N: set the digest size\n" + " --pmd-cyclecount-delay-ms N: set delay between enqueue\n" + " and dequeue in pmd-cyclecount benchmarking mode\n" + " --csv-friendly: enable test result output CSV friendly\n" + " -h: prints this help\n", + progname); +} + static int get_str_key_id_mapping(struct name_id_map *map, unsigned int map_len, const char *str_key) @@ -76,6 +117,10 @@ parse_cperf_test_type(struct cperf_options *opts, const char *arg) { cperf_test_type_strs[CPERF_TEST_TYPE_LATENCY], CPERF_TEST_TYPE_LATENCY + }, + { + cperf_test_type_strs[CPERF_TEST_TYPE_PMDCC], + CPERF_TEST_TYPE_PMDCC } }; @@ -137,6 +182,7 @@ parse_range(const char *arg, uint32_t *min, uint32_t *max, uint32_t *inc) if (copy_arg == NULL) return -1; + errno = 0; token = strtok(copy_arg, ":"); /* Parse minimum value */ @@ -203,6 +249,7 @@ parse_list(const char *arg, uint32_t *list, uint32_t *min, uint32_t *max) if (copy_arg == NULL) return -1; + errno = 0; token = strtok(copy_arg, ","); /* Parse first value */ @@ -322,17 +369,35 @@ parse_buffer_sz(struct cperf_options *opts, const char *arg) } static int -parse_segments_nb(struct cperf_options *opts, const char *arg) +parse_segment_sz(struct cperf_options *opts, const char *arg) { - int ret = parse_uint32_t(&opts->segments_nb, arg); + int ret = parse_uint32_t(&opts->segment_sz, arg); if (ret) { - RTE_LOG(ERR, USER1, "failed to parse segments number\n"); + RTE_LOG(ERR, USER1, "failed to parse segment size\n"); return -1; } - if ((opts->segments_nb == 0) || (opts->segments_nb > 255)) { - RTE_LOG(ERR, USER1, "invalid segments number specified\n"); + if (opts->segment_sz == 0) { + RTE_LOG(ERR, USER1, "Segment size has to be bigger than 0\n"); + return -1; + } + + return 0; +} + +static int +parse_desc_nb(struct cperf_options *opts, const char *arg) +{ + int ret = parse_uint32_t(&opts->nb_descriptors, arg); + + if (ret) { + RTE_LOG(ERR, USER1, "failed to parse descriptors number\n"); + return -1; + } + + if (opts->nb_descriptors == 0) { + RTE_LOG(ERR, USER1, "invalid descriptors number specified\n"); return -1; } @@ -623,6 +688,20 @@ parse_csv_friendly(struct cperf_options *opts, const char *arg __rte_unused) return 0; } +static int +parse_pmd_cyclecount_delay_ms(struct cperf_options *opts, + const char *arg) +{ + int ret = parse_uint32_t(&opts->pmdcc_delay, arg); + + if (ret) { + RTE_LOG(ERR, USER1, "failed to parse pmd-cyclecount delay\n"); + return -1; + } + + return 0; +} + typedef int (*option_parser_t)(struct cperf_options *opts, const char *arg); @@ -640,7 +719,8 @@ static struct option lgopts[] = { { CPERF_TOTAL_OPS, required_argument, 0, 0 }, { CPERF_BURST_SIZE, required_argument, 0, 0 }, { CPERF_BUFFER_SIZE, required_argument, 0, 0 }, - { CPERF_SEGMENTS_NB, required_argument, 0, 0 }, + { CPERF_SEGMENT_SIZE, required_argument, 0, 0 }, + { CPERF_DESC_NB, required_argument, 0, 0 }, { CPERF_DEVTYPE, required_argument, 0, 0 }, { CPERF_OPTYPE, required_argument, 0, 0 }, @@ -674,6 +754,8 @@ static struct option lgopts[] = { { CPERF_CSV, no_argument, 0, 0}, + { CPERF_PMDCC_DELAY_MS, required_argument, 0, 0 }, + { NULL, 0, 0, 0 } }; @@ -684,6 +766,7 @@ cperf_options_default(struct cperf_options *opts) opts->pool_sz = 8192; opts->total_ops = 10000000; + opts->nb_descriptors = 2048; opts->buffer_size_list[0] = 64; opts->buffer_size_count = 1; @@ -697,10 +780,15 @@ cperf_options_default(struct cperf_options *opts) opts->min_burst_size = 32; opts->inc_burst_size = 0; - opts->segments_nb = 1; + /* + * Will be parsed from command line or set to + * maximum buffer size + digest, later + */ + opts->segment_sz = 0; strncpy(opts->device_type, "crypto_aesni_mb", sizeof(opts->device_type)); + opts->nb_qps = 1; opts->op_type = CPERF_CIPHER_THEN_AUTH; @@ -727,6 +815,8 @@ cperf_options_default(struct cperf_options *opts) opts->aead_aad_sz = 0; opts->digest_sz = 12; + + opts->pmdcc_delay = 0; } static int @@ -739,7 +829,8 @@ cperf_opts_parse_long(int opt_idx, struct cperf_options *opts) { CPERF_TOTAL_OPS, parse_total_ops }, { CPERF_BURST_SIZE, parse_burst_sz }, { CPERF_BUFFER_SIZE, parse_buffer_sz }, - { CPERF_SEGMENTS_NB, parse_segments_nb }, + { CPERF_SEGMENT_SIZE, parse_segment_sz }, + { CPERF_DESC_NB, parse_desc_nb }, { CPERF_DEVTYPE, parse_device_type }, { CPERF_OPTYPE, parse_op_type }, { CPERF_SESSIONLESS, parse_sessionless }, @@ -761,6 +852,7 @@ cperf_opts_parse_long(int opt_idx, struct cperf_options *opts) { CPERF_AEAD_AAD_SZ, parse_aead_aad_sz }, { CPERF_DIGEST_SZ, parse_digest_sz }, { CPERF_CSV, parse_csv_friendly}, + { CPERF_PMDCC_DELAY_MS, parse_pmd_cyclecount_delay_ms}, }; unsigned int i; @@ -778,11 +870,14 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv) { int opt, retval, opt_idx; - while ((opt = getopt_long(argc, argv, "", lgopts, &opt_idx)) != EOF) { + while ((opt = getopt_long(argc, argv, "h", lgopts, &opt_idx)) != EOF) { switch (opt) { + case 'h': + usage(argv[0]); + rte_exit(EXIT_SUCCESS, "Displayed help\n"); + break; /* long options */ case 0: - retval = cperf_opts_parse_long(opt_idx, options); if (retval != 0) return retval; @@ -790,6 +885,7 @@ cperf_options_parse(struct cperf_options *options, int argc, char **argv) break; default: + usage(argv[0]); return -EINVAL; } } @@ -830,14 +926,26 @@ check_cipher_buffer_length(struct cperf_options *options) if (options->cipher_algo == RTE_CRYPTO_CIPHER_DES_CBC || options->cipher_algo == RTE_CRYPTO_CIPHER_3DES_CBC || options->cipher_algo == RTE_CRYPTO_CIPHER_3DES_ECB) { - for (buffer_size = options->min_buffer_size; - buffer_size < options->max_buffer_size; - buffer_size += options->inc_buffer_size) { + if (options->inc_buffer_size != 0) + buffer_size = options->min_buffer_size; + else + buffer_size = options->buffer_size_list[0]; + + while (buffer_size <= options->max_buffer_size) { if ((buffer_size % DES_BLOCK_SIZE) != 0) { RTE_LOG(ERR, USER1, "Some of the buffer sizes are " "not suitable for the algorithm selected\n"); return -EINVAL; } + + if (options->inc_buffer_size != 0) + buffer_size += options->inc_buffer_size; + else { + if (++buffer_size_idx == options->buffer_size_count) + break; + buffer_size = options->buffer_size_list[buffer_size_idx]; + } + } } @@ -847,9 +955,21 @@ check_cipher_buffer_length(struct cperf_options *options) int cperf_options_check(struct cperf_options *options) { - if (options->segments_nb > options->min_buffer_size) { + if (options->op_type == CPERF_CIPHER_ONLY) + options->digest_sz = 0; + + /* + * If segment size is not set, assume only one segment, + * big enough to contain the largest buffer and the digest + */ + if (options->segment_sz == 0) + options->segment_sz = options->max_buffer_size + + options->digest_sz; + + if (options->segment_sz < options->digest_sz) { RTE_LOG(ERR, USER1, - "Segments number greater than buffer size.\n"); + "Segment size should be at least " + "the size of the digest\n"); return -EINVAL; } @@ -882,13 +1002,6 @@ cperf_options_check(struct cperf_options *options) } if (options->test == CPERF_TEST_TYPE_VERIFY && - options->total_ops > options->pool_sz) { - RTE_LOG(ERR, USER1, "Total number of ops must be less than or" - " equal to the pool size.\n"); - return -EINVAL; - } - - if (options->test == CPERF_TEST_TYPE_VERIFY && (options->inc_buffer_size != 0 || options->buffer_size_count > 1)) { RTE_LOG(ERR, USER1, "Only one buffer size is allowed when " @@ -904,6 +1017,14 @@ cperf_options_check(struct cperf_options *options) return -EINVAL; } + if (options->test == CPERF_TEST_TYPE_PMDCC && + options->pool_sz < options->nb_descriptors) { + RTE_LOG(ERR, USER1, "For pmd cyclecount benchmarks, pool size " + "must be equal or greater than the number of " + "cryptodev descriptors.\n"); + return -EINVAL; + } + if (options->op_type == CPERF_CIPHER_THEN_AUTH) { if (options->cipher_op != RTE_CRYPTO_CIPHER_OP_ENCRYPT && options->auth_op != @@ -965,13 +1086,16 @@ cperf_options_dump(struct cperf_options *opts) printf("%u ", opts->burst_size_list[size_idx]); printf("\n"); } - printf("\n# segments per buffer: %u\n", opts->segments_nb); + printf("\n# segment size: %u\n", opts->segment_sz); printf("#\n"); printf("# cryptodev type: %s\n", opts->device_type); printf("#\n"); + printf("# number of queue pairs per device: %u\n", opts->nb_qps); printf("# crypto operation: %s\n", cperf_op_type_strs[opts->op_type]); printf("# sessionless: %s\n", opts->sessionless ? "yes" : "no"); printf("# out of place: %s\n", opts->out_of_place ? "yes" : "no"); + if (opts->test == CPERF_TEST_TYPE_PMDCC) + printf("# inter-burst delay: %u ms\n", opts->pmdcc_delay); printf("#\n"); diff --git a/app/test-crypto-perf/cperf_test_common.c b/app/test-crypto-perf/cperf_test_common.c new file mode 100644 index 00000000..328744ef --- /dev/null +++ b/app/test-crypto-perf/cperf_test_common.c @@ -0,0 +1,244 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2017 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <rte_malloc.h> + +#include "cperf_test_common.h" + +struct obj_params { + uint32_t src_buf_offset; + uint32_t dst_buf_offset; + uint16_t segment_sz; + uint16_t segments_nb; +}; + +static void +fill_single_seg_mbuf(struct rte_mbuf *m, struct rte_mempool *mp, + void *obj, uint32_t mbuf_offset, uint16_t segment_sz) +{ + uint32_t mbuf_hdr_size = sizeof(struct rte_mbuf); + + /* start of buffer is after mbuf structure and priv data */ + m->priv_size = 0; + m->buf_addr = (char *)m + mbuf_hdr_size; + m->buf_iova = rte_mempool_virt2iova(obj) + + mbuf_offset + mbuf_hdr_size; + m->buf_len = segment_sz; + m->data_len = segment_sz; + + /* No headroom needed for the buffer */ + m->data_off = 0; + + /* init some constant fields */ + m->pool = mp; + m->nb_segs = 1; + m->port = 0xff; + rte_mbuf_refcnt_set(m, 1); + m->next = NULL; +} + +static void +fill_multi_seg_mbuf(struct rte_mbuf *m, struct rte_mempool *mp, + void *obj, uint32_t mbuf_offset, uint16_t segment_sz, + uint16_t segments_nb) +{ + uint16_t mbuf_hdr_size = sizeof(struct rte_mbuf); + uint16_t remaining_segments = segments_nb; + struct rte_mbuf *next_mbuf; + rte_iova_t next_seg_phys_addr = rte_mempool_virt2iova(obj) + + mbuf_offset + mbuf_hdr_size; + + do { + /* start of buffer is after mbuf structure and priv data */ + m->priv_size = 0; + m->buf_addr = (char *)m + mbuf_hdr_size; + m->buf_iova = next_seg_phys_addr; + next_seg_phys_addr += mbuf_hdr_size + segment_sz; + m->buf_len = segment_sz; + m->data_len = segment_sz; + + /* No headroom needed for the buffer */ + m->data_off = 0; + + /* init some constant fields */ + m->pool = mp; + m->nb_segs = segments_nb; + m->port = 0xff; + rte_mbuf_refcnt_set(m, 1); + next_mbuf = (struct rte_mbuf *) ((uint8_t *) m + + mbuf_hdr_size + segment_sz); + m->next = next_mbuf; + m = next_mbuf; + remaining_segments--; + + } while (remaining_segments > 0); + + m->next = NULL; +} + +static void +mempool_obj_init(struct rte_mempool *mp, + void *opaque_arg, + void *obj, + __attribute__((unused)) unsigned int i) +{ + struct obj_params *params = opaque_arg; + struct rte_crypto_op *op = obj; + struct rte_mbuf *m = (struct rte_mbuf *) ((uint8_t *) obj + + params->src_buf_offset); + /* Set crypto operation */ + op->type = RTE_CRYPTO_OP_TYPE_SYMMETRIC; + op->status = RTE_CRYPTO_OP_STATUS_NOT_PROCESSED; + op->sess_type = RTE_CRYPTO_OP_WITH_SESSION; + op->phys_addr = rte_mem_virt2phy(obj); + op->mempool = mp; + + /* Set source buffer */ + op->sym->m_src = m; + if (params->segments_nb == 1) + fill_single_seg_mbuf(m, mp, obj, params->src_buf_offset, + params->segment_sz); + else + fill_multi_seg_mbuf(m, mp, obj, params->src_buf_offset, + params->segment_sz, params->segments_nb); + + + /* Set destination buffer */ + if (params->dst_buf_offset) { + m = (struct rte_mbuf *) ((uint8_t *) obj + + params->dst_buf_offset); + fill_single_seg_mbuf(m, mp, obj, params->dst_buf_offset, + params->segment_sz); + op->sym->m_dst = m; + } else + op->sym->m_dst = NULL; +} + +int +cperf_alloc_common_memory(const struct cperf_options *options, + const struct cperf_test_vector *test_vector, + uint8_t dev_id, uint16_t qp_id, + size_t extra_op_priv_size, + uint32_t *src_buf_offset, + uint32_t *dst_buf_offset, + struct rte_mempool **pool) +{ + char pool_name[32] = ""; + int ret; + + /* Calculate the object size */ + uint16_t crypto_op_size = sizeof(struct rte_crypto_op) + + sizeof(struct rte_crypto_sym_op); + uint16_t crypto_op_private_size; + /* + * If doing AES-CCM, IV field needs to be 16 bytes long, + * and AAD field needs to be long enough to have 18 bytes, + * plus the length of the AAD, and all rounded to a + * multiple of 16 bytes. + */ + if (options->aead_algo == RTE_CRYPTO_AEAD_AES_CCM) { + crypto_op_private_size = extra_op_priv_size + + test_vector->cipher_iv.length + + test_vector->auth_iv.length + + RTE_ALIGN_CEIL(test_vector->aead_iv.length, 16) + + RTE_ALIGN_CEIL(options->aead_aad_sz + 18, 16); + } else { + crypto_op_private_size = extra_op_priv_size + + test_vector->cipher_iv.length + + test_vector->auth_iv.length + + test_vector->aead_iv.length + + options->aead_aad_sz; + } + + uint16_t crypto_op_total_size = crypto_op_size + + crypto_op_private_size; + uint16_t crypto_op_total_size_padded = + RTE_CACHE_LINE_ROUNDUP(crypto_op_total_size); + uint32_t mbuf_size = sizeof(struct rte_mbuf) + options->segment_sz; + uint32_t max_size = options->max_buffer_size + options->digest_sz; + uint16_t segments_nb = (max_size % options->segment_sz) ? + (max_size / options->segment_sz) + 1 : + max_size / options->segment_sz; + uint32_t obj_size = crypto_op_total_size_padded + + (mbuf_size * segments_nb); + + snprintf(pool_name, sizeof(pool_name), "pool_cdev_%u_qp_%u", + dev_id, qp_id); + + *src_buf_offset = crypto_op_total_size_padded; + + struct obj_params params = { + .segment_sz = options->segment_sz, + .segments_nb = segments_nb, + .src_buf_offset = crypto_op_total_size_padded, + .dst_buf_offset = 0 + }; + + if (options->out_of_place) { + *dst_buf_offset = *src_buf_offset + + (mbuf_size * segments_nb); + params.dst_buf_offset = *dst_buf_offset; + /* Destination buffer will be one segment only */ + obj_size += max_size; + } + + *pool = rte_mempool_create_empty(pool_name, + options->pool_sz, obj_size, 512, 0, + rte_socket_id(), 0); + if (*pool == NULL) { + RTE_LOG(ERR, USER1, + "Cannot allocate mempool for device %u\n", + dev_id); + return -1; + } + + ret = rte_mempool_set_ops_byname(*pool, + RTE_MBUF_DEFAULT_MEMPOOL_OPS, NULL); + if (ret != 0) { + RTE_LOG(ERR, USER1, + "Error setting mempool handler for device %u\n", + dev_id); + return -1; + } + + ret = rte_mempool_populate_default(*pool); + if (ret < 0) { + RTE_LOG(ERR, USER1, + "Error populating mempool for device %u\n", + dev_id); + return -1; + } + + rte_mempool_obj_iter(*pool, mempool_obj_init, (void *)¶ms); + + return 0; +} diff --git a/app/test-crypto-perf/cperf_test_common.h b/app/test-crypto-perf/cperf_test_common.h new file mode 100644 index 00000000..4cee7852 --- /dev/null +++ b/app/test-crypto-perf/cperf_test_common.h @@ -0,0 +1,52 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2017 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CPERF_TEST_COMMON_H_ +#define _CPERF_TEST_COMMON_H_ + +#include <stdint.h> + +#include <rte_mempool.h> + +#include "cperf_options.h" +#include "cperf_test_vectors.h" + +int +cperf_alloc_common_memory(const struct cperf_options *options, + const struct cperf_test_vector *test_vector, + uint8_t dev_id, uint16_t qp_id, + size_t extra_op_priv_size, + uint32_t *src_buf_offset, + uint32_t *dst_buf_offset, + struct rte_mempool **pool); + +#endif /* _CPERF_TEST_COMMON_H_ */ diff --git a/app/test-crypto-perf/cperf_test_latency.c b/app/test-crypto-perf/cperf_test_latency.c index 58b21abd..ca2a4ba6 100644 --- a/app/test-crypto-perf/cperf_test_latency.c +++ b/app/test-crypto-perf/cperf_test_latency.c @@ -37,7 +37,7 @@ #include "cperf_test_latency.h" #include "cperf_ops.h" - +#include "cperf_test_common.h" struct cperf_op_result { uint64_t tsc_start; @@ -50,17 +50,15 @@ struct cperf_latency_ctx { uint16_t qp_id; uint8_t lcore_id; - struct rte_mempool *pkt_mbuf_pool_in; - struct rte_mempool *pkt_mbuf_pool_out; - struct rte_mbuf **mbufs_in; - struct rte_mbuf **mbufs_out; - - struct rte_mempool *crypto_op_pool; + struct rte_mempool *pool; struct rte_cryptodev_sym_session *sess; cperf_populate_ops_t populate_ops; + uint32_t src_buf_offset; + uint32_t dst_buf_offset; + const struct cperf_options *options; const struct cperf_test_vector *test_vector; struct cperf_op_result *res; @@ -74,124 +72,22 @@ struct priv_op_data { #define min(a, b) (a < b ? (uint64_t)a : (uint64_t)b) static void -cperf_latency_test_free(struct cperf_latency_ctx *ctx, uint32_t mbuf_nb) +cperf_latency_test_free(struct cperf_latency_ctx *ctx) { - uint32_t i; - if (ctx) { if (ctx->sess) { rte_cryptodev_sym_session_clear(ctx->dev_id, ctx->sess); rte_cryptodev_sym_session_free(ctx->sess); } - if (ctx->mbufs_in) { - for (i = 0; i < mbuf_nb; i++) - rte_pktmbuf_free(ctx->mbufs_in[i]); - - rte_free(ctx->mbufs_in); - } - - if (ctx->mbufs_out) { - for (i = 0; i < mbuf_nb; i++) { - if (ctx->mbufs_out[i] != NULL) - rte_pktmbuf_free(ctx->mbufs_out[i]); - } - - rte_free(ctx->mbufs_out); - } - - if (ctx->pkt_mbuf_pool_in) - rte_mempool_free(ctx->pkt_mbuf_pool_in); - - if (ctx->pkt_mbuf_pool_out) - rte_mempool_free(ctx->pkt_mbuf_pool_out); - - if (ctx->crypto_op_pool) - rte_mempool_free(ctx->crypto_op_pool); + if (ctx->pool) + rte_mempool_free(ctx->pool); rte_free(ctx->res); rte_free(ctx); } } -static struct rte_mbuf * -cperf_mbuf_create(struct rte_mempool *mempool, - uint32_t segments_nb, - const struct cperf_options *options, - const struct cperf_test_vector *test_vector) -{ - struct rte_mbuf *mbuf; - uint32_t segment_sz = options->max_buffer_size / segments_nb; - uint32_t last_sz = options->max_buffer_size % segments_nb; - uint8_t *mbuf_data; - uint8_t *test_data = - (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ? - test_vector->plaintext.data : - test_vector->ciphertext.data; - - mbuf = rte_pktmbuf_alloc(mempool); - if (mbuf == NULL) - goto error; - - mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, segment_sz); - if (mbuf_data == NULL) - goto error; - - memcpy(mbuf_data, test_data, segment_sz); - test_data += segment_sz; - segments_nb--; - - while (segments_nb) { - struct rte_mbuf *m; - - m = rte_pktmbuf_alloc(mempool); - if (m == NULL) - goto error; - - rte_pktmbuf_chain(mbuf, m); - - mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, segment_sz); - if (mbuf_data == NULL) - goto error; - - memcpy(mbuf_data, test_data, segment_sz); - test_data += segment_sz; - segments_nb--; - } - - if (last_sz) { - mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, last_sz); - if (mbuf_data == NULL) - goto error; - - memcpy(mbuf_data, test_data, last_sz); - } - - if (options->op_type != CPERF_CIPHER_ONLY) { - mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, - options->digest_sz); - if (mbuf_data == NULL) - goto error; - } - - if (options->op_type == CPERF_AEAD) { - uint8_t *aead = (uint8_t *)rte_pktmbuf_prepend(mbuf, - RTE_ALIGN_CEIL(options->aead_aad_sz, 16)); - - if (aead == NULL) - goto error; - - memcpy(aead, test_vector->aad.data, test_vector->aad.length); - } - - return mbuf; -error: - if (mbuf != NULL) - rte_pktmbuf_free(mbuf); - - return NULL; -} - void * cperf_latency_test_constructor(struct rte_mempool *sess_mp, uint8_t dev_id, uint16_t qp_id, @@ -200,8 +96,7 @@ cperf_latency_test_constructor(struct rte_mempool *sess_mp, const struct cperf_op_fns *op_fns) { struct cperf_latency_ctx *ctx = NULL; - unsigned int mbuf_idx = 0; - char pool_name[32] = ""; + size_t extra_op_priv_size = sizeof(struct priv_op_data); ctx = rte_malloc(NULL, sizeof(struct cperf_latency_ctx), 0); if (ctx == NULL) @@ -224,80 +119,10 @@ cperf_latency_test_constructor(struct rte_mempool *sess_mp, if (ctx->sess == NULL) goto err; - snprintf(pool_name, sizeof(pool_name), "cperf_pool_in_cdev_%d", - dev_id); - - ctx->pkt_mbuf_pool_in = rte_pktmbuf_pool_create(pool_name, - options->pool_sz * options->segments_nb, 0, 0, - RTE_PKTMBUF_HEADROOM + - RTE_CACHE_LINE_ROUNDUP( - (options->max_buffer_size / options->segments_nb) + - (options->max_buffer_size % options->segments_nb) + - options->digest_sz), - rte_socket_id()); - - if (ctx->pkt_mbuf_pool_in == NULL) - goto err; - - /* Generate mbufs_in with plaintext populated for test */ - ctx->mbufs_in = rte_malloc(NULL, - (sizeof(struct rte_mbuf *) * - ctx->options->pool_sz), 0); - - for (mbuf_idx = 0; mbuf_idx < options->pool_sz; mbuf_idx++) { - ctx->mbufs_in[mbuf_idx] = cperf_mbuf_create( - ctx->pkt_mbuf_pool_in, options->segments_nb, - options, test_vector); - if (ctx->mbufs_in[mbuf_idx] == NULL) - goto err; - } - - if (options->out_of_place == 1) { - - snprintf(pool_name, sizeof(pool_name), - "cperf_pool_out_cdev_%d", - dev_id); - - ctx->pkt_mbuf_pool_out = rte_pktmbuf_pool_create( - pool_name, options->pool_sz, 0, 0, - RTE_PKTMBUF_HEADROOM + - RTE_CACHE_LINE_ROUNDUP( - options->max_buffer_size + - options->digest_sz), - rte_socket_id()); - - if (ctx->pkt_mbuf_pool_out == NULL) - goto err; - } - - ctx->mbufs_out = rte_malloc(NULL, - (sizeof(struct rte_mbuf *) * - ctx->options->pool_sz), 0); - - for (mbuf_idx = 0; mbuf_idx < options->pool_sz; mbuf_idx++) { - if (options->out_of_place == 1) { - ctx->mbufs_out[mbuf_idx] = cperf_mbuf_create( - ctx->pkt_mbuf_pool_out, 1, - options, test_vector); - if (ctx->mbufs_out[mbuf_idx] == NULL) - goto err; - } else { - ctx->mbufs_out[mbuf_idx] = NULL; - } - } - - snprintf(pool_name, sizeof(pool_name), "cperf_op_pool_cdev_%d", - dev_id); - - uint16_t priv_size = sizeof(struct priv_op_data) + - test_vector->cipher_iv.length + - test_vector->auth_iv.length + - test_vector->aead_iv.length; - ctx->crypto_op_pool = rte_crypto_op_pool_create(pool_name, - RTE_CRYPTO_OP_TYPE_SYMMETRIC, options->pool_sz, - 512, priv_size, rte_socket_id()); - - if (ctx->crypto_op_pool == NULL) + if (cperf_alloc_common_memory(options, test_vector, dev_id, qp_id, + extra_op_priv_size, + &ctx->src_buf_offset, &ctx->dst_buf_offset, + &ctx->pool) < 0) goto err; ctx->res = rte_malloc(NULL, sizeof(struct cperf_op_result) * @@ -308,7 +133,7 @@ cperf_latency_test_constructor(struct rte_mempool *sess_mp, return ctx; err: - cperf_latency_test_free(ctx, mbuf_idx); + cperf_latency_test_free(ctx); return NULL; } @@ -347,7 +172,7 @@ cperf_latency_test_runner(void *arg) int linearize = 0; /* Check if source mbufs require coalescing */ - if (ctx->options->segments_nb > 1) { + if (ctx->options->segment_sz < ctx->options->max_buffer_size) { rte_cryptodev_info_get(ctx->dev_id, &dev_info); if ((dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER) == 0) @@ -373,7 +198,7 @@ cperf_latency_test_runner(void *arg) while (test_burst_size <= ctx->options->max_burst_size) { uint64_t ops_enqd = 0, ops_deqd = 0; - uint64_t m_idx = 0, b_idx = 0; + uint64_t b_idx = 0; uint64_t tsc_val, tsc_end, tsc_start; uint64_t tsc_max = 0, tsc_min = ~0UL, tsc_tot = 0, tsc_idx = 0; @@ -388,11 +213,9 @@ cperf_latency_test_runner(void *arg) ctx->options->total_ops - enqd_tot; - /* Allocate crypto ops from pool */ - if (burst_size != rte_crypto_op_bulk_alloc( - ctx->crypto_op_pool, - RTE_CRYPTO_OP_TYPE_SYMMETRIC, - ops, burst_size)) { + /* Allocate objects containing crypto operations and mbufs */ + if (rte_mempool_get_bulk(ctx->pool, (void **)ops, + burst_size) != 0) { RTE_LOG(ERR, USER1, "Failed to allocate more crypto operations " "from the the crypto operation pool.\n" @@ -402,8 +225,8 @@ cperf_latency_test_runner(void *arg) } /* Setup crypto op, attach mbuf etc */ - (ctx->populate_ops)(ops, &ctx->mbufs_in[m_idx], - &ctx->mbufs_out[m_idx], + (ctx->populate_ops)(ops, ctx->src_buf_offset, + ctx->dst_buf_offset, burst_size, ctx->sess, ctx->options, ctx->test_vector, iv_offset); @@ -432,7 +255,7 @@ cperf_latency_test_runner(void *arg) /* Free memory for not enqueued operations */ if (ops_enqd != burst_size) - rte_mempool_put_bulk(ctx->crypto_op_pool, + rte_mempool_put_bulk(ctx->pool, (void **)&ops[ops_enqd], burst_size - ops_enqd); @@ -448,16 +271,11 @@ cperf_latency_test_runner(void *arg) } if (likely(ops_deqd)) { - /* - * free crypto ops so they can be reused. We don't free - * the mbufs here as we don't want to reuse them as - * the crypto operation will change the data and cause - * failures. - */ + /* Free crypto ops so they can be reused. */ for (i = 0; i < ops_deqd; i++) store_timestamp(ops_processed[i], tsc_end); - rte_mempool_put_bulk(ctx->crypto_op_pool, + rte_mempool_put_bulk(ctx->pool, (void **)ops_processed, ops_deqd); deqd_tot += ops_deqd; @@ -469,9 +287,6 @@ cperf_latency_test_runner(void *arg) enqd_max = max(ops_enqd, enqd_max); enqd_min = min(ops_enqd, enqd_min); - m_idx += ops_enqd; - m_idx = m_idx + test_burst_size > ctx->options->pool_sz ? - 0 : m_idx; b_idx++; } @@ -490,7 +305,7 @@ cperf_latency_test_runner(void *arg) for (i = 0; i < ops_deqd; i++) store_timestamp(ops_processed[i], tsc_end); - rte_mempool_put_bulk(ctx->crypto_op_pool, + rte_mempool_put_bulk(ctx->pool, (void **)ops_processed, ops_deqd); deqd_tot += ops_deqd; @@ -586,7 +401,5 @@ cperf_latency_test_destructor(void *arg) if (ctx == NULL) return; - rte_cryptodev_stop(ctx->dev_id); - - cperf_latency_test_free(ctx, ctx->options->pool_sz); + cperf_latency_test_free(ctx); } diff --git a/app/test-crypto-perf/cperf_test_pmd_cyclecount.c b/app/test-crypto-perf/cperf_test_pmd_cyclecount.c new file mode 100644 index 00000000..9b41724a --- /dev/null +++ b/app/test-crypto-perf/cperf_test_pmd_cyclecount.c @@ -0,0 +1,520 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2017 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <stdbool.h> + +#include <rte_crypto.h> +#include <rte_cryptodev.h> +#include <rte_cycles.h> +#include <rte_malloc.h> + +#include "cperf_ops.h" +#include "cperf_test_pmd_cyclecount.h" +#include "cperf_test_common.h" + +#define PRETTY_HDR_FMT "%12s%12s%12s%12s%12s%12s%12s%12s%12s%12s\n\n" +#define PRETTY_LINE_FMT "%12u%12u%12u%12u%12u%12u%12u%12.0f%12.0f%12.0f\n" +#define CSV_HDR_FMT "%s,%s,%s,%s,%s,%s,%s,%s,%s,%s\n" +#define CSV_LINE_FMT "%10u;%10u;%u;%u;%u;%u;%u;%.f3;%.f3;%.f3\n" + +struct cperf_pmd_cyclecount_ctx { + uint8_t dev_id; + uint16_t qp_id; + uint8_t lcore_id; + + struct rte_mempool *pool; + struct rte_crypto_op **ops; + struct rte_crypto_op **ops_processed; + + struct rte_cryptodev_sym_session *sess; + + cperf_populate_ops_t populate_ops; + + uint32_t src_buf_offset; + uint32_t dst_buf_offset; + + const struct cperf_options *options; + const struct cperf_test_vector *test_vector; +}; + +struct pmd_cyclecount_state { + struct cperf_pmd_cyclecount_ctx *ctx; + const struct cperf_options *opts; + uint32_t lcore; + uint64_t delay; + int linearize; + uint32_t ops_enqd; + uint32_t ops_deqd; + uint32_t ops_enq_retries; + uint32_t ops_deq_retries; + double cycles_per_build; + double cycles_per_enq; + double cycles_per_deq; +}; + +static const uint16_t iv_offset = + sizeof(struct rte_crypto_op) + sizeof(struct rte_crypto_sym_op); + +static void +cperf_pmd_cyclecount_test_free(struct cperf_pmd_cyclecount_ctx *ctx) +{ + if (ctx) { + if (ctx->sess) { + rte_cryptodev_sym_session_clear(ctx->dev_id, ctx->sess); + rte_cryptodev_sym_session_free(ctx->sess); + } + + if (ctx->pool) + rte_mempool_free(ctx->pool); + + if (ctx->ops) + rte_free(ctx->ops); + + if (ctx->ops_processed) + rte_free(ctx->ops_processed); + + rte_free(ctx); + } +} + +void * +cperf_pmd_cyclecount_test_constructor(struct rte_mempool *sess_mp, + uint8_t dev_id, uint16_t qp_id, + const struct cperf_options *options, + const struct cperf_test_vector *test_vector, + const struct cperf_op_fns *op_fns) +{ + struct cperf_pmd_cyclecount_ctx *ctx = NULL; + + /* preallocate buffers for crypto ops as they can get quite big */ + size_t alloc_sz = sizeof(struct rte_crypto_op *) * + options->nb_descriptors; + + ctx = rte_malloc(NULL, sizeof(struct cperf_pmd_cyclecount_ctx), 0); + if (ctx == NULL) + goto err; + + ctx->dev_id = dev_id; + ctx->qp_id = qp_id; + + ctx->populate_ops = op_fns->populate_ops; + ctx->options = options; + ctx->test_vector = test_vector; + + /* IV goes at the end of the crypto operation */ + uint16_t iv_offset = sizeof(struct rte_crypto_op) + + sizeof(struct rte_crypto_sym_op); + + ctx->sess = op_fns->sess_create( + sess_mp, dev_id, options, test_vector, iv_offset); + if (ctx->sess == NULL) + goto err; + + if (cperf_alloc_common_memory(options, test_vector, dev_id, qp_id, 0, + &ctx->src_buf_offset, &ctx->dst_buf_offset, + &ctx->pool) < 0) + goto err; + + ctx->ops = rte_malloc("ops", alloc_sz, 0); + if (!ctx->ops) + goto err; + + ctx->ops_processed = rte_malloc("ops_processed", alloc_sz, 0); + if (!ctx->ops_processed) + goto err; + + return ctx; + +err: + cperf_pmd_cyclecount_test_free(ctx); + + return NULL; +} + +/* benchmark alloc-build-free of ops */ +static inline int +pmd_cyclecount_bench_ops(struct pmd_cyclecount_state *state, uint32_t cur_op, + uint16_t test_burst_size) +{ + uint32_t iter_ops_left = state->opts->total_ops - cur_op; + uint32_t iter_ops_needed = + RTE_MIN(state->opts->nb_descriptors, iter_ops_left); + uint32_t cur_iter_op; + + for (cur_iter_op = 0; cur_iter_op < iter_ops_needed; + cur_iter_op += test_burst_size) { + uint32_t burst_size = RTE_MIN(state->opts->total_ops - cur_op, + test_burst_size); + struct rte_crypto_op **ops = &state->ctx->ops[cur_iter_op]; + + /* Allocate objects containing crypto operations and mbufs */ + if (rte_mempool_get_bulk(state->ctx->pool, (void **)ops, + burst_size) != 0) { + RTE_LOG(ERR, USER1, + "Failed to allocate more crypto operations " + "from the the crypto operation pool.\n" + "Consider increasing the pool size " + "with --pool-sz\n"); + return -1; + } + + /* Setup crypto op, attach mbuf etc */ + (state->ctx->populate_ops)(ops, + state->ctx->src_buf_offset, + state->ctx->dst_buf_offset, + burst_size, + state->ctx->sess, state->opts, + state->ctx->test_vector, iv_offset); + +#ifdef CPERF_LINEARIZATION_ENABLE + /* Check if source mbufs require coalescing */ + if (state->linearize) { + uint8_t i; + for (i = 0; i < burst_size; i++) { + struct rte_mbuf *src = ops[i]->sym->m_src; + rte_pktmbuf_linearize(src); + } + } +#endif /* CPERF_LINEARIZATION_ENABLE */ + rte_mempool_put_bulk(state->ctx->pool, (void **)ops, + burst_size); + } + + return 0; +} + +/* allocate and build ops (no free) */ +static int +pmd_cyclecount_build_ops(struct pmd_cyclecount_state *state, + uint32_t iter_ops_needed, uint16_t test_burst_size) +{ + uint32_t cur_iter_op; + + for (cur_iter_op = 0; cur_iter_op < iter_ops_needed; + cur_iter_op += test_burst_size) { + uint32_t burst_size = RTE_MIN( + iter_ops_needed - cur_iter_op, test_burst_size); + struct rte_crypto_op **ops = &state->ctx->ops[cur_iter_op]; + + /* Allocate objects containing crypto operations and mbufs */ + if (rte_mempool_get_bulk(state->ctx->pool, (void **)ops, + burst_size) != 0) { + RTE_LOG(ERR, USER1, + "Failed to allocate more crypto operations " + "from the the crypto operation pool.\n" + "Consider increasing the pool size " + "with --pool-sz\n"); + return -1; + } + + /* Setup crypto op, attach mbuf etc */ + (state->ctx->populate_ops)(ops, + state->ctx->src_buf_offset, + state->ctx->dst_buf_offset, + burst_size, + state->ctx->sess, state->opts, + state->ctx->test_vector, iv_offset); + } + return 0; +} + +/* benchmark enqueue, returns number of ops enqueued */ +static uint32_t +pmd_cyclecount_bench_enq(struct pmd_cyclecount_state *state, + uint32_t iter_ops_needed, uint16_t test_burst_size) +{ + /* Enqueue full descriptor ring of ops on crypto device */ + uint32_t cur_iter_op = 0; + while (cur_iter_op < iter_ops_needed) { + uint32_t burst_size = RTE_MIN(iter_ops_needed - cur_iter_op, + test_burst_size); + struct rte_crypto_op **ops = &state->ctx->ops[cur_iter_op]; + uint32_t burst_enqd; + + burst_enqd = rte_cryptodev_enqueue_burst(state->ctx->dev_id, + state->ctx->qp_id, ops, burst_size); + + /* if we couldn't enqueue anything, the queue is full */ + if (!burst_enqd) { + /* don't try to dequeue anything we didn't enqueue */ + return cur_iter_op; + } + + if (burst_enqd < burst_size) + state->ops_enq_retries++; + state->ops_enqd += burst_enqd; + cur_iter_op += burst_enqd; + } + return iter_ops_needed; +} + +/* benchmark dequeue */ +static void +pmd_cyclecount_bench_deq(struct pmd_cyclecount_state *state, + uint32_t iter_ops_needed, uint16_t test_burst_size) +{ + /* Dequeue full descriptor ring of ops on crypto device */ + uint32_t cur_iter_op = 0; + while (cur_iter_op < iter_ops_needed) { + uint32_t burst_size = RTE_MIN(iter_ops_needed - cur_iter_op, + test_burst_size); + struct rte_crypto_op **ops_processed = + &state->ctx->ops[cur_iter_op]; + uint32_t burst_deqd; + + burst_deqd = rte_cryptodev_dequeue_burst(state->ctx->dev_id, + state->ctx->qp_id, ops_processed, burst_size); + + if (burst_deqd < burst_size) + state->ops_deq_retries++; + state->ops_deqd += burst_deqd; + cur_iter_op += burst_deqd; + } +} + +/* run benchmark per burst size */ +static inline int +pmd_cyclecount_bench_burst_sz( + struct pmd_cyclecount_state *state, uint16_t test_burst_size) +{ + uint64_t tsc_start; + uint64_t tsc_end; + uint64_t tsc_op; + uint64_t tsc_enq; + uint64_t tsc_deq; + uint32_t cur_op; + + /* reset all counters */ + tsc_enq = 0; + tsc_deq = 0; + state->ops_enqd = 0; + state->ops_enq_retries = 0; + state->ops_deqd = 0; + state->ops_deq_retries = 0; + + /* + * Benchmark crypto op alloc-build-free separately. + */ + tsc_start = rte_rdtsc_precise(); + + for (cur_op = 0; cur_op < state->opts->total_ops; + cur_op += state->opts->nb_descriptors) { + if (unlikely(pmd_cyclecount_bench_ops( + state, cur_op, test_burst_size))) + return -1; + } + + tsc_end = rte_rdtsc_precise(); + tsc_op = tsc_end - tsc_start; + + + /* + * Hardware acceleration cyclecount benchmarking loop. + * + * We're benchmarking raw enq/deq performance by filling up the device + * queue, so we never get any failed enqs unless the driver won't accept + * the exact number of descriptors we requested, or the driver won't + * wrap around the end of the TX ring. However, since we're only + * dequeueing once we've filled up the queue, we have to benchmark it + * piecemeal and then average out the results. + */ + cur_op = 0; + while (cur_op < state->opts->total_ops) { + uint32_t iter_ops_left = state->opts->total_ops - cur_op; + uint32_t iter_ops_needed = RTE_MIN( + state->opts->nb_descriptors, iter_ops_left); + uint32_t iter_ops_allocd = iter_ops_needed; + + /* allocate and build ops */ + if (unlikely(pmd_cyclecount_build_ops(state, iter_ops_needed, + test_burst_size))) + return -1; + + tsc_start = rte_rdtsc_precise(); + + /* fill up TX ring */ + iter_ops_needed = pmd_cyclecount_bench_enq(state, + iter_ops_needed, test_burst_size); + + tsc_end = rte_rdtsc_precise(); + + tsc_enq += tsc_end - tsc_start; + + /* allow for HW to catch up */ + if (state->delay) + rte_delay_us_block(state->delay); + + tsc_start = rte_rdtsc_precise(); + + /* drain RX ring */ + pmd_cyclecount_bench_deq(state, iter_ops_needed, + test_burst_size); + + tsc_end = rte_rdtsc_precise(); + + tsc_deq += tsc_end - tsc_start; + + cur_op += iter_ops_needed; + + /* + * we may not have processed all ops that we allocated, so + * free everything we've allocated. + */ + rte_mempool_put_bulk(state->ctx->pool, + (void **)state->ctx->ops, iter_ops_allocd); + } + + state->cycles_per_build = (double)tsc_op / state->opts->total_ops; + state->cycles_per_enq = (double)tsc_enq / state->ops_enqd; + state->cycles_per_deq = (double)tsc_deq / state->ops_deqd; + + return 0; +} + +int +cperf_pmd_cyclecount_test_runner(void *test_ctx) +{ + struct pmd_cyclecount_state state = {0}; + const struct cperf_options *opts; + uint16_t test_burst_size; + uint8_t burst_size_idx = 0; + + state.ctx = test_ctx; + opts = state.ctx->options; + state.opts = opts; + state.lcore = rte_lcore_id(); + state.linearize = 0; + + static int only_once; + static bool warmup = true; + + /* + * We need a small delay to allow for hardware to process all the crypto + * operations. We can't automatically figure out what the delay should + * be, so we leave it up to the user (by default it's 0). + */ + state.delay = 1000 * opts->pmdcc_delay; + +#ifdef CPERF_LINEARIZATION_ENABLE + struct rte_cryptodev_info dev_info; + + /* Check if source mbufs require coalescing */ + if (opts->segments_sz < ctx->options->max_buffer_size) { + rte_cryptodev_info_get(state.ctx->dev_id, &dev_info); + if ((dev_info.feature_flags & + RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER) == + 0) { + state.linearize = 1; + } + } +#endif /* CPERF_LINEARIZATION_ENABLE */ + + state.ctx->lcore_id = state.lcore; + + /* Get first size from range or list */ + if (opts->inc_burst_size != 0) + test_burst_size = opts->min_burst_size; + else + test_burst_size = opts->burst_size_list[0]; + + while (test_burst_size <= opts->max_burst_size) { + /* do a benchmark run */ + if (pmd_cyclecount_bench_burst_sz(&state, test_burst_size)) + return -1; + + /* + * First run is always a warm up run. + */ + if (warmup) { + warmup = false; + continue; + } + + if (!opts->csv) { + if (!only_once) + printf(PRETTY_HDR_FMT, "lcore id", "Buf Size", + "Burst Size", "Enqueued", + "Dequeued", "Enq Retries", + "Deq Retries", "Cycles/Op", + "Cycles/Enq", "Cycles/Deq"); + only_once = 1; + + printf(PRETTY_LINE_FMT, state.ctx->lcore_id, + opts->test_buffer_size, test_burst_size, + state.ops_enqd, state.ops_deqd, + state.ops_enq_retries, + state.ops_deq_retries, + state.cycles_per_build, + state.cycles_per_enq, + state.cycles_per_deq); + } else { + if (!only_once) + printf(CSV_HDR_FMT, "# lcore id", "Buf Size", + "Burst Size", "Enqueued", + "Dequeued", "Enq Retries", + "Deq Retries", "Cycles/Op", + "Cycles/Enq", "Cycles/Deq"); + only_once = 1; + + printf(CSV_LINE_FMT, state.ctx->lcore_id, + opts->test_buffer_size, test_burst_size, + state.ops_enqd, state.ops_deqd, + state.ops_enq_retries, + state.ops_deq_retries, + state.cycles_per_build, + state.cycles_per_enq, + state.cycles_per_deq); + } + + /* Get next size from range or list */ + if (opts->inc_burst_size != 0) + test_burst_size += opts->inc_burst_size; + else { + if (++burst_size_idx == opts->burst_size_count) + break; + test_burst_size = opts->burst_size_list[burst_size_idx]; + } + } + + return 0; +} + +void +cperf_pmd_cyclecount_test_destructor(void *arg) +{ + struct cperf_pmd_cyclecount_ctx *ctx = arg; + + if (ctx == NULL) + return; + + cperf_pmd_cyclecount_test_free(ctx); +} diff --git a/app/test-crypto-perf/cperf_test_pmd_cyclecount.h b/app/test-crypto-perf/cperf_test_pmd_cyclecount.h new file mode 100644 index 00000000..93f0eae0 --- /dev/null +++ b/app/test-crypto-perf/cperf_test_pmd_cyclecount.h @@ -0,0 +1,61 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2017 Intel Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CPERF_TEST_PMD_CYCLECOUNT_H_ +#define _CPERF_TEST_PMD_CYCLECOUNT_H_ + +#include <stdint.h> + +#include <rte_mbuf.h> + +#include "cperf.h" +#include "cperf_ops.h" +#include "cperf_options.h" +#include "cperf_test_vectors.h" + + +void * +cperf_pmd_cyclecount_test_constructor( + struct rte_mempool *sess_mp, + uint8_t dev_id, + uint16_t qp_id, + const struct cperf_options *options, + const struct cperf_test_vector *test_vector, + const struct cperf_op_fns *ops_fn); + +int +cperf_pmd_cyclecount_test_runner(void *test_ctx); + +void +cperf_pmd_cyclecount_test_destructor(void *test_ctx); + +#endif /* _CPERF_TEST_PMD_CYCLECOUNT_H_ */ diff --git a/app/test-crypto-perf/cperf_test_throughput.c b/app/test-crypto-perf/cperf_test_throughput.c index 3bb1cb05..b84dc630 100644 --- a/app/test-crypto-perf/cperf_test_throughput.c +++ b/app/test-crypto-perf/cperf_test_throughput.c @@ -37,145 +37,42 @@ #include "cperf_test_throughput.h" #include "cperf_ops.h" +#include "cperf_test_common.h" struct cperf_throughput_ctx { uint8_t dev_id; uint16_t qp_id; uint8_t lcore_id; - struct rte_mempool *pkt_mbuf_pool_in; - struct rte_mempool *pkt_mbuf_pool_out; - struct rte_mbuf **mbufs_in; - struct rte_mbuf **mbufs_out; - - struct rte_mempool *crypto_op_pool; + struct rte_mempool *pool; struct rte_cryptodev_sym_session *sess; cperf_populate_ops_t populate_ops; + uint32_t src_buf_offset; + uint32_t dst_buf_offset; + const struct cperf_options *options; const struct cperf_test_vector *test_vector; }; static void -cperf_throughput_test_free(struct cperf_throughput_ctx *ctx, uint32_t mbuf_nb) +cperf_throughput_test_free(struct cperf_throughput_ctx *ctx) { - uint32_t i; - if (ctx) { if (ctx->sess) { rte_cryptodev_sym_session_clear(ctx->dev_id, ctx->sess); rte_cryptodev_sym_session_free(ctx->sess); } - if (ctx->mbufs_in) { - for (i = 0; i < mbuf_nb; i++) - rte_pktmbuf_free(ctx->mbufs_in[i]); - - rte_free(ctx->mbufs_in); - } - - if (ctx->mbufs_out) { - for (i = 0; i < mbuf_nb; i++) { - if (ctx->mbufs_out[i] != NULL) - rte_pktmbuf_free(ctx->mbufs_out[i]); - } - - rte_free(ctx->mbufs_out); - } - - if (ctx->pkt_mbuf_pool_in) - rte_mempool_free(ctx->pkt_mbuf_pool_in); - - if (ctx->pkt_mbuf_pool_out) - rte_mempool_free(ctx->pkt_mbuf_pool_out); - - if (ctx->crypto_op_pool) - rte_mempool_free(ctx->crypto_op_pool); + if (ctx->pool) + rte_mempool_free(ctx->pool); rte_free(ctx); } } -static struct rte_mbuf * -cperf_mbuf_create(struct rte_mempool *mempool, - uint32_t segments_nb, - const struct cperf_options *options, - const struct cperf_test_vector *test_vector) -{ - struct rte_mbuf *mbuf; - uint32_t segment_sz = options->max_buffer_size / segments_nb; - uint32_t last_sz = options->max_buffer_size % segments_nb; - uint8_t *mbuf_data; - uint8_t *test_data = - (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ? - test_vector->plaintext.data : - test_vector->ciphertext.data; - - mbuf = rte_pktmbuf_alloc(mempool); - if (mbuf == NULL) - goto error; - - mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, segment_sz); - if (mbuf_data == NULL) - goto error; - - memcpy(mbuf_data, test_data, segment_sz); - test_data += segment_sz; - segments_nb--; - - while (segments_nb) { - struct rte_mbuf *m; - - m = rte_pktmbuf_alloc(mempool); - if (m == NULL) - goto error; - - rte_pktmbuf_chain(mbuf, m); - - mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, segment_sz); - if (mbuf_data == NULL) - goto error; - - memcpy(mbuf_data, test_data, segment_sz); - test_data += segment_sz; - segments_nb--; - } - - if (last_sz) { - mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, last_sz); - if (mbuf_data == NULL) - goto error; - - memcpy(mbuf_data, test_data, last_sz); - } - - if (options->op_type != CPERF_CIPHER_ONLY) { - mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, - options->digest_sz); - if (mbuf_data == NULL) - goto error; - } - - if (options->op_type == CPERF_AEAD) { - uint8_t *aead = (uint8_t *)rte_pktmbuf_prepend(mbuf, - RTE_ALIGN_CEIL(options->aead_aad_sz, 16)); - - if (aead == NULL) - goto error; - - memcpy(aead, test_vector->aad.data, test_vector->aad.length); - } - - return mbuf; -error: - if (mbuf != NULL) - rte_pktmbuf_free(mbuf); - - return NULL; -} - void * cperf_throughput_test_constructor(struct rte_mempool *sess_mp, uint8_t dev_id, uint16_t qp_id, @@ -184,8 +81,6 @@ cperf_throughput_test_constructor(struct rte_mempool *sess_mp, const struct cperf_op_fns *op_fns) { struct cperf_throughput_ctx *ctx = NULL; - unsigned int mbuf_idx = 0; - char pool_name[32] = ""; ctx = rte_malloc(NULL, sizeof(struct cperf_throughput_ctx), 0); if (ctx == NULL) @@ -198,7 +93,7 @@ cperf_throughput_test_constructor(struct rte_mempool *sess_mp, ctx->options = options; ctx->test_vector = test_vector; - /* IV goes at the end of the cryptop operation */ + /* IV goes at the end of the crypto operation */ uint16_t iv_offset = sizeof(struct rte_crypto_op) + sizeof(struct rte_crypto_sym_op); @@ -207,81 +102,14 @@ cperf_throughput_test_constructor(struct rte_mempool *sess_mp, if (ctx->sess == NULL) goto err; - snprintf(pool_name, sizeof(pool_name), "cperf_pool_in_cdev_%d", - dev_id); - - ctx->pkt_mbuf_pool_in = rte_pktmbuf_pool_create(pool_name, - options->pool_sz * options->segments_nb, 0, 0, - RTE_PKTMBUF_HEADROOM + - RTE_CACHE_LINE_ROUNDUP( - (options->max_buffer_size / options->segments_nb) + - (options->max_buffer_size % options->segments_nb) + - options->digest_sz), - rte_socket_id()); - - if (ctx->pkt_mbuf_pool_in == NULL) - goto err; - - /* Generate mbufs_in with plaintext populated for test */ - ctx->mbufs_in = rte_malloc(NULL, - (sizeof(struct rte_mbuf *) * ctx->options->pool_sz), 0); - - for (mbuf_idx = 0; mbuf_idx < options->pool_sz; mbuf_idx++) { - ctx->mbufs_in[mbuf_idx] = cperf_mbuf_create( - ctx->pkt_mbuf_pool_in, options->segments_nb, - options, test_vector); - if (ctx->mbufs_in[mbuf_idx] == NULL) - goto err; - } - - if (options->out_of_place == 1) { - - snprintf(pool_name, sizeof(pool_name), "cperf_pool_out_cdev_%d", - dev_id); - - ctx->pkt_mbuf_pool_out = rte_pktmbuf_pool_create( - pool_name, options->pool_sz, 0, 0, - RTE_PKTMBUF_HEADROOM + - RTE_CACHE_LINE_ROUNDUP( - options->max_buffer_size + - options->digest_sz), - rte_socket_id()); - - if (ctx->pkt_mbuf_pool_out == NULL) - goto err; - } - - ctx->mbufs_out = rte_malloc(NULL, - (sizeof(struct rte_mbuf *) * - ctx->options->pool_sz), 0); - - for (mbuf_idx = 0; mbuf_idx < options->pool_sz; mbuf_idx++) { - if (options->out_of_place == 1) { - ctx->mbufs_out[mbuf_idx] = cperf_mbuf_create( - ctx->pkt_mbuf_pool_out, 1, - options, test_vector); - if (ctx->mbufs_out[mbuf_idx] == NULL) - goto err; - } else { - ctx->mbufs_out[mbuf_idx] = NULL; - } - } - - snprintf(pool_name, sizeof(pool_name), "cperf_op_pool_cdev_%d", - dev_id); - - uint16_t priv_size = test_vector->cipher_iv.length + - test_vector->auth_iv.length + test_vector->aead_iv.length; - - ctx->crypto_op_pool = rte_crypto_op_pool_create(pool_name, - RTE_CRYPTO_OP_TYPE_SYMMETRIC, options->pool_sz, - 512, priv_size, rte_socket_id()); - if (ctx->crypto_op_pool == NULL) + if (cperf_alloc_common_memory(options, test_vector, dev_id, qp_id, 0, + &ctx->src_buf_offset, &ctx->dst_buf_offset, + &ctx->pool) < 0) goto err; return ctx; err: - cperf_throughput_test_free(ctx, mbuf_idx); + cperf_throughput_test_free(ctx); return NULL; } @@ -306,7 +134,7 @@ cperf_throughput_test_runner(void *test_ctx) int linearize = 0; /* Check if source mbufs require coalescing */ - if (ctx->options->segments_nb > 1) { + if (ctx->options->segment_sz < ctx->options->max_buffer_size) { rte_cryptodev_info_get(ctx->dev_id, &dev_info); if ((dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER) == 0) @@ -333,7 +161,7 @@ cperf_throughput_test_runner(void *test_ctx) uint64_t ops_enqd = 0, ops_enqd_total = 0, ops_enqd_failed = 0; uint64_t ops_deqd = 0, ops_deqd_total = 0, ops_deqd_failed = 0; - uint64_t m_idx = 0, tsc_start, tsc_end, tsc_duration; + uint64_t tsc_start, tsc_end, tsc_duration; uint16_t ops_unused = 0; @@ -349,11 +177,9 @@ cperf_throughput_test_runner(void *test_ctx) uint16_t ops_needed = burst_size - ops_unused; - /* Allocate crypto ops from pool */ - if (ops_needed != rte_crypto_op_bulk_alloc( - ctx->crypto_op_pool, - RTE_CRYPTO_OP_TYPE_SYMMETRIC, - ops, ops_needed)) { + /* Allocate objects containing crypto operations and mbufs */ + if (rte_mempool_get_bulk(ctx->pool, (void **)ops, + ops_needed) != 0) { RTE_LOG(ERR, USER1, "Failed to allocate more crypto operations " "from the the crypto operation pool.\n" @@ -363,10 +189,11 @@ cperf_throughput_test_runner(void *test_ctx) } /* Setup crypto op, attach mbuf etc */ - (ctx->populate_ops)(ops, &ctx->mbufs_in[m_idx], - &ctx->mbufs_out[m_idx], - ops_needed, ctx->sess, ctx->options, - ctx->test_vector, iv_offset); + (ctx->populate_ops)(ops, ctx->src_buf_offset, + ctx->dst_buf_offset, + ops_needed, ctx->sess, + ctx->options, ctx->test_vector, + iv_offset); /** * When ops_needed is smaller than ops_enqd, the @@ -411,12 +238,8 @@ cperf_throughput_test_runner(void *test_ctx) ops_processed, test_burst_size); if (likely(ops_deqd)) { - /* free crypto ops so they can be reused. We don't free - * the mbufs here as we don't want to reuse them as - * the crypto operation will change the data and cause - * failures. - */ - rte_mempool_put_bulk(ctx->crypto_op_pool, + /* Free crypto ops so they can be reused. */ + rte_mempool_put_bulk(ctx->pool, (void **)ops_processed, ops_deqd); ops_deqd_total += ops_deqd; @@ -429,9 +252,6 @@ cperf_throughput_test_runner(void *test_ctx) ops_deqd_failed++; } - m_idx += ops_needed; - m_idx = m_idx + test_burst_size > ctx->options->pool_sz ? - 0 : m_idx; } /* Dequeue any operations still in the crypto device */ @@ -446,9 +266,8 @@ cperf_throughput_test_runner(void *test_ctx) if (ops_deqd == 0) ops_deqd_failed++; else { - rte_mempool_put_bulk(ctx->crypto_op_pool, + rte_mempool_put_bulk(ctx->pool, (void **)ops_processed, ops_deqd); - ops_deqd_total += ops_deqd; } } @@ -534,7 +353,5 @@ cperf_throughput_test_destructor(void *arg) if (ctx == NULL) return; - rte_cryptodev_stop(ctx->dev_id); - - cperf_throughput_test_free(ctx, ctx->options->pool_sz); + cperf_throughput_test_free(ctx); } diff --git a/app/test-crypto-perf/cperf_test_vector_parsing.c b/app/test-crypto-perf/cperf_test_vector_parsing.c index 148a6041..d4736f9e 100644 --- a/app/test-crypto-perf/cperf_test_vector_parsing.c +++ b/app/test-crypto-perf/cperf_test_vector_parsing.c @@ -116,6 +116,20 @@ show_test_vector(struct cperf_test_vector *test_vector) printf("\n"); } + if (test_vector->aead_key.data) { + printf("\naead_key =\n"); + for (i = 0; i < test_vector->aead_key.length; ++i) { + if ((i % wrap == 0) && (i != 0)) + printf("\n"); + if (i == (uint32_t)(test_vector->aead_key.length - 1)) + printf("0x%02x", test_vector->aead_key.data[i]); + else + printf("0x%02x, ", + test_vector->aead_key.data[i]); + } + printf("\n"); + } + if (test_vector->cipher_iv.data) { printf("\ncipher_iv =\n"); for (i = 0; i < test_vector->cipher_iv.length; ++i) { @@ -142,6 +156,19 @@ show_test_vector(struct cperf_test_vector *test_vector) printf("\n"); } + if (test_vector->aead_iv.data) { + printf("\naead_iv =\n"); + for (i = 0; i < test_vector->aead_iv.length; ++i) { + if ((i % wrap == 0) && (i != 0)) + printf("\n"); + if (i == (uint32_t)(test_vector->aead_iv.length - 1)) + printf("0x%02x", test_vector->aead_iv.data[i]); + else + printf("0x%02x, ", test_vector->aead_iv.data[i]); + } + printf("\n"); + } + if (test_vector->ciphertext.data) { printf("\nciphertext =\n"); for (i = 0; i < test_vector->ciphertext.length; ++i) { @@ -345,6 +372,20 @@ parse_entry(char *entry, struct cperf_test_vector *vector, vector->auth_key.length = opts->auth_key_sz; } + } else if (strstr(key_token, "aead_key")) { + rte_free(vector->aead_key.data); + vector->aead_key.data = data; + if (tc_found) + vector->aead_key.length = data_length; + else { + if (opts->aead_key_sz > data_length) { + printf("Global aead_key shorter than " + "aead_key_sz\n"); + return -1; + } + vector->aead_key.length = opts->aead_key_sz; + } + } else if (strstr(key_token, "cipher_iv")) { rte_free(vector->cipher_iv.data); vector->cipher_iv.data = data; @@ -373,6 +414,20 @@ parse_entry(char *entry, struct cperf_test_vector *vector, vector->auth_iv.length = opts->auth_iv_sz; } + } else if (strstr(key_token, "aead_iv")) { + rte_free(vector->aead_iv.data); + vector->aead_iv.data = data; + if (tc_found) + vector->aead_iv.length = data_length; + else { + if (opts->aead_iv_sz > data_length) { + printf("Global aead iv shorter than " + "aead_iv_sz\n"); + return -1; + } + vector->aead_iv.length = opts->aead_iv_sz; + } + } else if (strstr(key_token, "ciphertext")) { rte_free(vector->ciphertext.data); vector->ciphertext.data = data; @@ -390,7 +445,7 @@ parse_entry(char *entry, struct cperf_test_vector *vector, } else if (strstr(key_token, "aad")) { rte_free(vector->aad.data); vector->aad.data = data; - vector->aad.phys_addr = rte_malloc_virt2phy(vector->aad.data); + vector->aad.phys_addr = rte_malloc_virt2iova(vector->aad.data); if (tc_found) vector->aad.length = data_length; else { @@ -405,7 +460,7 @@ parse_entry(char *entry, struct cperf_test_vector *vector, } else if (strstr(key_token, "digest")) { rte_free(vector->digest.data); vector->digest.data = data; - vector->digest.phys_addr = rte_malloc_virt2phy( + vector->digest.phys_addr = rte_malloc_virt2iova( vector->digest.data); if (tc_found) vector->digest.length = data_length; diff --git a/app/test-crypto-perf/cperf_test_vectors.c b/app/test-crypto-perf/cperf_test_vectors.c index e51dcc3f..fa911ff6 100644 --- a/app/test-crypto-perf/cperf_test_vectors.c +++ b/app/test-crypto-perf/cperf_test_vectors.c @@ -498,7 +498,7 @@ cperf_test_vector_get_dummy(struct cperf_options *options) return NULL; } t_vec->digest.phys_addr = - rte_malloc_virt2phy(t_vec->digest.data); + rte_malloc_virt2iova(t_vec->digest.data); t_vec->digest.length = options->digest_sz; memcpy(t_vec->digest.data, digest, options->digest_sz); @@ -531,7 +531,7 @@ cperf_test_vector_get_dummy(struct cperf_options *options) return NULL; } memcpy(t_vec->aad.data, aad, options->aead_aad_sz); - t_vec->aad.phys_addr = rte_malloc_virt2phy(t_vec->aad.data); + t_vec->aad.phys_addr = rte_malloc_virt2iova(t_vec->aad.data); t_vec->aad.length = options->aead_aad_sz; } else { t_vec->aad.data = NULL; @@ -546,7 +546,7 @@ cperf_test_vector_get_dummy(struct cperf_options *options) return NULL; } t_vec->digest.phys_addr = - rte_malloc_virt2phy(t_vec->digest.data); + rte_malloc_virt2iova(t_vec->digest.data); t_vec->digest.length = options->digest_sz; memcpy(t_vec->digest.data, digest, options->digest_sz); t_vec->data.aead_offset = 0; diff --git a/app/test-crypto-perf/cperf_test_vectors.h b/app/test-crypto-perf/cperf_test_vectors.h index 85955703..cb5d8284 100644 --- a/app/test-crypto-perf/cperf_test_vectors.h +++ b/app/test-crypto-perf/cperf_test_vectors.h @@ -78,13 +78,13 @@ struct cperf_test_vector { struct { uint8_t *data; - phys_addr_t phys_addr; + rte_iova_t phys_addr; uint16_t length; } aad; struct { uint8_t *data; - phys_addr_t phys_addr; + rte_iova_t phys_addr; uint16_t length; } digest; diff --git a/app/test-crypto-perf/cperf_test_verify.c b/app/test-crypto-perf/cperf_test_verify.c index a314646c..6945c8b4 100644 --- a/app/test-crypto-perf/cperf_test_verify.c +++ b/app/test-crypto-perf/cperf_test_verify.c @@ -37,23 +37,22 @@ #include "cperf_test_verify.h" #include "cperf_ops.h" +#include "cperf_test_common.h" struct cperf_verify_ctx { uint8_t dev_id; uint16_t qp_id; uint8_t lcore_id; - struct rte_mempool *pkt_mbuf_pool_in; - struct rte_mempool *pkt_mbuf_pool_out; - struct rte_mbuf **mbufs_in; - struct rte_mbuf **mbufs_out; - - struct rte_mempool *crypto_op_pool; + struct rte_mempool *pool; struct rte_cryptodev_sym_session *sess; cperf_populate_ops_t populate_ops; + uint32_t src_buf_offset; + uint32_t dst_buf_offset; + const struct cperf_options *options; const struct cperf_test_vector *test_vector; }; @@ -63,123 +62,21 @@ struct cperf_op_result { }; static void -cperf_verify_test_free(struct cperf_verify_ctx *ctx, uint32_t mbuf_nb) +cperf_verify_test_free(struct cperf_verify_ctx *ctx) { - uint32_t i; - if (ctx) { if (ctx->sess) { rte_cryptodev_sym_session_clear(ctx->dev_id, ctx->sess); rte_cryptodev_sym_session_free(ctx->sess); } - if (ctx->mbufs_in) { - for (i = 0; i < mbuf_nb; i++) - rte_pktmbuf_free(ctx->mbufs_in[i]); - - rte_free(ctx->mbufs_in); - } - - if (ctx->mbufs_out) { - for (i = 0; i < mbuf_nb; i++) { - if (ctx->mbufs_out[i] != NULL) - rte_pktmbuf_free(ctx->mbufs_out[i]); - } - - rte_free(ctx->mbufs_out); - } - - if (ctx->pkt_mbuf_pool_in) - rte_mempool_free(ctx->pkt_mbuf_pool_in); - - if (ctx->pkt_mbuf_pool_out) - rte_mempool_free(ctx->pkt_mbuf_pool_out); - - if (ctx->crypto_op_pool) - rte_mempool_free(ctx->crypto_op_pool); + if (ctx->pool) + rte_mempool_free(ctx->pool); rte_free(ctx); } } -static struct rte_mbuf * -cperf_mbuf_create(struct rte_mempool *mempool, - uint32_t segments_nb, - const struct cperf_options *options, - const struct cperf_test_vector *test_vector) -{ - struct rte_mbuf *mbuf; - uint32_t segment_sz = options->max_buffer_size / segments_nb; - uint32_t last_sz = options->max_buffer_size % segments_nb; - uint8_t *mbuf_data; - uint8_t *test_data = - (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ? - test_vector->plaintext.data : - test_vector->ciphertext.data; - - mbuf = rte_pktmbuf_alloc(mempool); - if (mbuf == NULL) - goto error; - - mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, segment_sz); - if (mbuf_data == NULL) - goto error; - - memcpy(mbuf_data, test_data, segment_sz); - test_data += segment_sz; - segments_nb--; - - while (segments_nb) { - struct rte_mbuf *m; - - m = rte_pktmbuf_alloc(mempool); - if (m == NULL) - goto error; - - rte_pktmbuf_chain(mbuf, m); - - mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, segment_sz); - if (mbuf_data == NULL) - goto error; - - memcpy(mbuf_data, test_data, segment_sz); - test_data += segment_sz; - segments_nb--; - } - - if (last_sz) { - mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, last_sz); - if (mbuf_data == NULL) - goto error; - - memcpy(mbuf_data, test_data, last_sz); - } - - if (options->op_type != CPERF_CIPHER_ONLY) { - mbuf_data = (uint8_t *)rte_pktmbuf_append(mbuf, - options->digest_sz); - if (mbuf_data == NULL) - goto error; - } - - if (options->op_type == CPERF_AEAD) { - uint8_t *aead = (uint8_t *)rte_pktmbuf_prepend(mbuf, - RTE_ALIGN_CEIL(options->aead_aad_sz, 16)); - - if (aead == NULL) - goto error; - - memcpy(aead, test_vector->aad.data, test_vector->aad.length); - } - - return mbuf; -error: - if (mbuf != NULL) - rte_pktmbuf_free(mbuf); - - return NULL; -} - void * cperf_verify_test_constructor(struct rte_mempool *sess_mp, uint8_t dev_id, uint16_t qp_id, @@ -188,8 +85,6 @@ cperf_verify_test_constructor(struct rte_mempool *sess_mp, const struct cperf_op_fns *op_fns) { struct cperf_verify_ctx *ctx = NULL; - unsigned int mbuf_idx = 0; - char pool_name[32] = ""; ctx = rte_malloc(NULL, sizeof(struct cperf_verify_ctx), 0); if (ctx == NULL) @@ -202,7 +97,7 @@ cperf_verify_test_constructor(struct rte_mempool *sess_mp, ctx->options = options; ctx->test_vector = test_vector; - /* IV goes at the end of the cryptop operation */ + /* IV goes at the end of the crypto operation */ uint16_t iv_offset = sizeof(struct rte_crypto_op) + sizeof(struct rte_crypto_sym_op); @@ -211,80 +106,14 @@ cperf_verify_test_constructor(struct rte_mempool *sess_mp, if (ctx->sess == NULL) goto err; - snprintf(pool_name, sizeof(pool_name), "cperf_pool_in_cdev_%d", - dev_id); - - ctx->pkt_mbuf_pool_in = rte_pktmbuf_pool_create(pool_name, - options->pool_sz * options->segments_nb, 0, 0, - RTE_PKTMBUF_HEADROOM + - RTE_CACHE_LINE_ROUNDUP( - (options->max_buffer_size / options->segments_nb) + - (options->max_buffer_size % options->segments_nb) + - options->digest_sz), - rte_socket_id()); - - if (ctx->pkt_mbuf_pool_in == NULL) - goto err; - - /* Generate mbufs_in with plaintext populated for test */ - ctx->mbufs_in = rte_malloc(NULL, - (sizeof(struct rte_mbuf *) * ctx->options->pool_sz), 0); - - for (mbuf_idx = 0; mbuf_idx < options->pool_sz; mbuf_idx++) { - ctx->mbufs_in[mbuf_idx] = cperf_mbuf_create( - ctx->pkt_mbuf_pool_in, options->segments_nb, - options, test_vector); - if (ctx->mbufs_in[mbuf_idx] == NULL) - goto err; - } - - if (options->out_of_place == 1) { - - snprintf(pool_name, sizeof(pool_name), "cperf_pool_out_cdev_%d", - dev_id); - - ctx->pkt_mbuf_pool_out = rte_pktmbuf_pool_create( - pool_name, options->pool_sz, 0, 0, - RTE_PKTMBUF_HEADROOM + - RTE_CACHE_LINE_ROUNDUP( - options->max_buffer_size + - options->digest_sz), - rte_socket_id()); - - if (ctx->pkt_mbuf_pool_out == NULL) - goto err; - } - - ctx->mbufs_out = rte_malloc(NULL, - (sizeof(struct rte_mbuf *) * - ctx->options->pool_sz), 0); - - for (mbuf_idx = 0; mbuf_idx < options->pool_sz; mbuf_idx++) { - if (options->out_of_place == 1) { - ctx->mbufs_out[mbuf_idx] = cperf_mbuf_create( - ctx->pkt_mbuf_pool_out, 1, - options, test_vector); - if (ctx->mbufs_out[mbuf_idx] == NULL) - goto err; - } else { - ctx->mbufs_out[mbuf_idx] = NULL; - } - } - - snprintf(pool_name, sizeof(pool_name), "cperf_op_pool_cdev_%d", - dev_id); - - uint16_t priv_size = test_vector->cipher_iv.length + - test_vector->auth_iv.length + test_vector->aead_iv.length; - ctx->crypto_op_pool = rte_crypto_op_pool_create(pool_name, - RTE_CRYPTO_OP_TYPE_SYMMETRIC, options->pool_sz, - 512, priv_size, rte_socket_id()); - if (ctx->crypto_op_pool == NULL) + if (cperf_alloc_common_memory(options, test_vector, dev_id, qp_id, 0, + &ctx->src_buf_offset, &ctx->dst_buf_offset, + &ctx->pool) < 0) goto err; return ctx; err: - cperf_verify_test_free(ctx, mbuf_idx); + cperf_verify_test_free(ctx); return NULL; } @@ -362,10 +191,13 @@ cperf_verify_op(struct rte_crypto_op *op, break; case CPERF_AEAD: cipher = 1; - cipher_offset = vector->aad.length; + cipher_offset = 0; auth = 1; - auth_offset = vector->aad.length + options->test_buffer_size; + auth_offset = options->test_buffer_size; break; + default: + res = 1; + goto out; } if (cipher == 1) { @@ -386,9 +218,39 @@ cperf_verify_op(struct rte_crypto_op *op, options->digest_sz); } +out: + rte_free(data); return !!res; } +static void +cperf_mbuf_set(struct rte_mbuf *mbuf, + const struct cperf_options *options, + const struct cperf_test_vector *test_vector) +{ + uint32_t segment_sz = options->segment_sz; + uint8_t *mbuf_data; + uint8_t *test_data = + (options->cipher_op == RTE_CRYPTO_CIPHER_OP_ENCRYPT) ? + test_vector->plaintext.data : + test_vector->ciphertext.data; + uint32_t remaining_bytes = options->max_buffer_size; + + while (remaining_bytes) { + mbuf_data = rte_pktmbuf_mtod(mbuf, uint8_t *); + + if (remaining_bytes <= segment_sz) { + memcpy(mbuf_data, test_data, remaining_bytes); + return; + } + + memcpy(mbuf_data, test_data, segment_sz); + remaining_bytes -= segment_sz; + test_data += segment_sz; + mbuf = mbuf->next; + } +} + int cperf_verify_test_runner(void *test_ctx) { @@ -400,7 +262,7 @@ cperf_verify_test_runner(void *test_ctx) static int only_once; - uint64_t i, m_idx = 0; + uint64_t i; uint16_t ops_unused = 0; struct rte_crypto_op *ops[ctx->options->max_burst_size]; @@ -413,7 +275,7 @@ cperf_verify_test_runner(void *test_ctx) int linearize = 0; /* Check if source mbufs require coalescing */ - if (ctx->options->segments_nb > 1) { + if (ctx->options->segment_sz < ctx->options->max_buffer_size) { rte_cryptodev_info_get(ctx->dev_id, &dev_info); if ((dev_info.feature_flags & RTE_CRYPTODEV_FF_MBUF_SCATTER_GATHER) == 0) @@ -440,11 +302,9 @@ cperf_verify_test_runner(void *test_ctx) uint16_t ops_needed = burst_size - ops_unused; - /* Allocate crypto ops from pool */ - if (ops_needed != rte_crypto_op_bulk_alloc( - ctx->crypto_op_pool, - RTE_CRYPTO_OP_TYPE_SYMMETRIC, - ops, ops_needed)) { + /* Allocate objects containing crypto operations and mbufs */ + if (rte_mempool_get_bulk(ctx->pool, (void **)ops, + ops_needed) != 0) { RTE_LOG(ERR, USER1, "Failed to allocate more crypto operations " "from the the crypto operation pool.\n" @@ -454,11 +314,18 @@ cperf_verify_test_runner(void *test_ctx) } /* Setup crypto op, attach mbuf etc */ - (ctx->populate_ops)(ops, &ctx->mbufs_in[m_idx], - &ctx->mbufs_out[m_idx], + (ctx->populate_ops)(ops, ctx->src_buf_offset, + ctx->dst_buf_offset, ops_needed, ctx->sess, ctx->options, ctx->test_vector, iv_offset); + + /* Populate the mbuf with the test vector, for verification */ + for (i = 0; i < ops_needed; i++) + cperf_mbuf_set(ops[i]->sym->m_src, + ctx->options, + ctx->test_vector); + #ifdef CPERF_LINEARIZATION_ENABLE if (linearize) { /* PMD doesn't support scatter-gather and source buffer @@ -488,10 +355,6 @@ cperf_verify_test_runner(void *test_ctx) ops_deqd = rte_cryptodev_dequeue_burst(ctx->dev_id, ctx->qp_id, ops_processed, ctx->options->max_burst_size); - m_idx += ops_needed; - if (m_idx + ctx->options->max_burst_size > ctx->options->pool_sz) - m_idx = 0; - if (ops_deqd == 0) { /** * Count dequeue polls which didn't return any @@ -506,13 +369,10 @@ cperf_verify_test_runner(void *test_ctx) if (cperf_verify_op(ops_processed[i], ctx->options, ctx->test_vector)) ops_failed++; - /* free crypto ops so they can be reused. We don't free - * the mbufs here as we don't want to reuse them as - * the crypto operation will change the data and cause - * failures. - */ - rte_crypto_op_free(ops_processed[i]); } + /* Free crypto ops so they can be reused. */ + rte_mempool_put_bulk(ctx->pool, + (void **)ops_processed, ops_deqd); ops_deqd_total += ops_deqd; } @@ -534,13 +394,10 @@ cperf_verify_test_runner(void *test_ctx) if (cperf_verify_op(ops_processed[i], ctx->options, ctx->test_vector)) ops_failed++; - /* free crypto ops so they can be reused. We don't free - * the mbufs here as we don't want to reuse them as - * the crypto operation will change the data and cause - * failures. - */ - rte_crypto_op_free(ops_processed[i]); } + /* Free crypto ops so they can be reused. */ + rte_mempool_put_bulk(ctx->pool, + (void **)ops_processed, ops_deqd); ops_deqd_total += ops_deqd; } @@ -594,7 +451,5 @@ cperf_verify_test_destructor(void *arg) if (ctx == NULL) return; - rte_cryptodev_stop(ctx->dev_id); - - cperf_verify_test_free(ctx, ctx->options->pool_sz); + cperf_verify_test_free(ctx); } diff --git a/app/test-crypto-perf/main.c b/app/test-crypto-perf/main.c index 99f5d3e0..29373f5b 100644 --- a/app/test-crypto-perf/main.c +++ b/app/test-crypto-perf/main.c @@ -35,6 +35,9 @@ #include <rte_eal.h> #include <rte_cryptodev.h> +#ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER +#include <rte_cryptodev_scheduler.h> +#endif #include "cperf.h" #include "cperf_options.h" @@ -42,6 +45,7 @@ #include "cperf_test_throughput.h" #include "cperf_test_latency.h" #include "cperf_test_verify.h" +#include "cperf_test_pmd_cyclecount.h" #define NUM_SESSIONS 2048 #define SESS_MEMPOOL_CACHE_SIZE 64 @@ -49,7 +53,8 @@ const char *cperf_test_type_strs[] = { [CPERF_TEST_TYPE_THROUGHPUT] = "throughput", [CPERF_TEST_TYPE_LATENCY] = "latency", - [CPERF_TEST_TYPE_VERIFY] = "verify" + [CPERF_TEST_TYPE_VERIFY] = "verify", + [CPERF_TEST_TYPE_PMDCC] = "pmd-cyclecount" }; const char *cperf_op_type_strs[] = { @@ -75,6 +80,11 @@ const struct cperf_test cperf_testmap[] = { cperf_verify_test_constructor, cperf_verify_test_runner, cperf_verify_test_destructor + }, + [CPERF_TEST_TYPE_PMDCC] = { + cperf_pmd_cyclecount_test_constructor, + cperf_pmd_cyclecount_test_runner, + cperf_pmd_cyclecount_test_destructor } }; @@ -83,7 +93,7 @@ cperf_initialize_cryptodev(struct cperf_options *opts, uint8_t *enabled_cdevs, struct rte_mempool *session_pool_socket[]) { uint8_t enabled_cdev_count = 0, nb_lcores, cdev_id; - unsigned int i; + unsigned int i, j; int ret; enabled_cdev_count = rte_cryptodev_devices_get(opts->device_type, @@ -112,21 +122,53 @@ cperf_initialize_cryptodev(struct cperf_options *opts, uint8_t *enabled_cdevs, max_sess_size = sess_size; } + /* + * Calculate number of needed queue pairs, based on the amount + * of available number of logical cores and crypto devices. + * For instance, if there are 4 cores and 2 crypto devices, + * 2 queue pairs will be set up per device. + */ + opts->nb_qps = (nb_lcores % enabled_cdev_count) ? + (nb_lcores / enabled_cdev_count) + 1 : + nb_lcores / enabled_cdev_count; + for (i = 0; i < enabled_cdev_count && i < RTE_CRYPTO_MAX_DEVS; i++) { cdev_id = enabled_cdevs[i]; +#ifdef RTE_LIBRTE_PMD_CRYPTO_SCHEDULER + /* + * If multi-core scheduler is used, limit the number + * of queue pairs to 1, as there is no way to know + * how many cores are being used by the PMD, and + * how many will be available for the application. + */ + if (!strcmp((const char *)opts->device_type, "crypto_scheduler") && + rte_cryptodev_scheduler_mode_get(cdev_id) == + CDEV_SCHED_MODE_MULTICORE) + opts->nb_qps = 1; +#endif + + struct rte_cryptodev_info cdev_info; uint8_t socket_id = rte_cryptodev_socket_id(cdev_id); + rte_cryptodev_info_get(cdev_id, &cdev_info); + if (opts->nb_qps > cdev_info.max_nb_queue_pairs) { + printf("Number of needed queue pairs is higher " + "than the maximum number of queue pairs " + "per device.\n"); + printf("Lower the number of cores or increase " + "the number of crypto devices\n"); + return -EINVAL; + } struct rte_cryptodev_config conf = { - .nb_queue_pairs = 1, - .socket_id = socket_id + .nb_queue_pairs = opts->nb_qps, + .socket_id = socket_id }; struct rte_cryptodev_qp_conf qp_conf = { - .nb_descriptors = 2048 + .nb_descriptors = opts->nb_descriptors }; - if (session_pool_socket[socket_id] == NULL) { char mp_name[RTE_MEMPOOL_NAMESIZE]; struct rte_mempool *sess_mp; @@ -158,14 +200,16 @@ cperf_initialize_cryptodev(struct cperf_options *opts, uint8_t *enabled_cdevs, return -EINVAL; } - ret = rte_cryptodev_queue_pair_setup(cdev_id, 0, + for (j = 0; j < opts->nb_qps; j++) { + ret = rte_cryptodev_queue_pair_setup(cdev_id, j, &qp_conf, socket_id, session_pool_socket[socket_id]); if (ret < 0) { printf("Failed to setup queue pair %u on " - "cryptodev %u", 0, cdev_id); + "cryptodev %u", j, cdev_id); return -EINVAL; } + } ret = rte_cryptodev_start(cdev_id); if (ret < 0) { @@ -380,6 +424,7 @@ main(int argc, char **argv) struct rte_mempool *session_pool_socket[RTE_MAX_NUMA_NODES] = { 0 }; int nb_cryptodevs = 0; + uint16_t total_nb_qps = 0; uint8_t cdev_id, i; uint8_t enabled_cdevs[RTE_CRYPTO_MAX_DEVS] = { 0 }; @@ -410,11 +455,12 @@ main(int argc, char **argv) goto err; } + nb_cryptodevs = cperf_initialize_cryptodev(&opts, enabled_cdevs, + session_pool_socket); + if (!opts.silent) cperf_options_dump(&opts); - nb_cryptodevs = cperf_initialize_cryptodev(&opts, enabled_cdevs, - session_pool_socket); if (nb_cryptodevs < 1) { RTE_LOG(ERR, USER1, "Failed to initialise requested crypto " "device type\n"); @@ -464,23 +510,29 @@ main(int argc, char **argv) if (!opts.silent) show_test_vector(t_vec); + total_nb_qps = nb_cryptodevs * opts.nb_qps; + i = 0; + uint8_t qp_id = 0, cdev_index = 0; RTE_LCORE_FOREACH_SLAVE(lcore_id) { - if (i == nb_cryptodevs) + if (i == total_nb_qps) break; - cdev_id = enabled_cdevs[i]; + cdev_id = enabled_cdevs[cdev_index]; uint8_t socket_id = rte_cryptodev_socket_id(cdev_id); - ctx[cdev_id] = cperf_testmap[opts.test].constructor( - session_pool_socket[socket_id], cdev_id, 0, + ctx[i] = cperf_testmap[opts.test].constructor( + session_pool_socket[socket_id], cdev_id, qp_id, &opts, t_vec, &op_fns); - if (ctx[cdev_id] == NULL) { + if (ctx[i] == NULL) { RTE_LOG(ERR, USER1, "Test run constructor failed\n"); goto err; } + qp_id = (qp_id + 1) % opts.nb_qps; + if (qp_id == 0) + cdev_index++; i++; } @@ -494,19 +546,17 @@ main(int argc, char **argv) i = 0; RTE_LCORE_FOREACH_SLAVE(lcore_id) { - if (i == nb_cryptodevs) + if (i == total_nb_qps) break; - cdev_id = enabled_cdevs[i]; - rte_eal_remote_launch(cperf_testmap[opts.test].runner, - ctx[cdev_id], lcore_id); + ctx[i], lcore_id); i++; } i = 0; RTE_LCORE_FOREACH_SLAVE(lcore_id) { - if (i == nb_cryptodevs) + if (i == total_nb_qps) break; rte_eal_wait_lcore(lcore_id); i++; @@ -525,15 +575,17 @@ main(int argc, char **argv) i = 0; RTE_LCORE_FOREACH_SLAVE(lcore_id) { - if (i == nb_cryptodevs) + if (i == total_nb_qps) break; - cdev_id = enabled_cdevs[i]; - - cperf_testmap[opts.test].destructor(ctx[cdev_id]); + cperf_testmap[opts.test].destructor(ctx[i]); i++; } + for (i = 0; i < nb_cryptodevs && + i < RTE_CRYPTO_MAX_DEVS; i++) + rte_cryptodev_stop(enabled_cdevs[i]); + free_test_vector(t_vec, &opts); printf("\n"); @@ -542,16 +594,20 @@ main(int argc, char **argv) err: i = 0; RTE_LCORE_FOREACH_SLAVE(lcore_id) { - if (i == nb_cryptodevs) + if (i == total_nb_qps) break; cdev_id = enabled_cdevs[i]; - if (ctx[cdev_id] && cperf_testmap[opts.test].destructor) - cperf_testmap[opts.test].destructor(ctx[cdev_id]); + if (ctx[i] && cperf_testmap[opts.test].destructor) + cperf_testmap[opts.test].destructor(ctx[i]); i++; } + for (i = 0; i < nb_cryptodevs && + i < RTE_CRYPTO_MAX_DEVS; i++) + rte_cryptodev_stop(enabled_cdevs[i]); + free_test_vector(t_vec, &opts); printf("\n"); diff --git a/app/test-eventdev/evt_common.h b/app/test-eventdev/evt_common.h index 41020760..0fadab4a 100644 --- a/app/test-eventdev/evt_common.h +++ b/app/test-eventdev/evt_common.h @@ -36,6 +36,7 @@ #include <rte_common.h> #include <rte_debug.h> #include <rte_eventdev.h> +#include <rte_service.h> #define CLNRM "\x1b[0m" #define CLRED "\x1b[31m" @@ -92,25 +93,43 @@ evt_has_all_types_queue(uint8_t dev_id) true : false; } -static inline uint32_t -evt_sched_type2queue_cfg(uint8_t sched_type) +static inline int +evt_service_setup(uint8_t dev_id) { - uint32_t ret; - - switch (sched_type) { - case RTE_SCHED_TYPE_ATOMIC: - ret = RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY; - break; - case RTE_SCHED_TYPE_ORDERED: - ret = RTE_EVENT_QUEUE_CFG_ORDERED_ONLY; - break; - case RTE_SCHED_TYPE_PARALLEL: - ret = RTE_EVENT_QUEUE_CFG_PARALLEL_ONLY; - break; - default: - rte_panic("Invalid sched_type %d\n", sched_type); + uint32_t service_id; + int32_t core_cnt; + unsigned int lcore = 0; + uint32_t core_array[RTE_MAX_LCORE]; + uint8_t cnt; + uint8_t min_cnt = UINT8_MAX; + + if (evt_has_distributed_sched(dev_id)) + return 0; + + if (!rte_service_lcore_count()) + return -ENOENT; + + if (!rte_event_dev_service_id_get(dev_id, &service_id)) { + core_cnt = rte_service_lcore_list(core_array, + RTE_MAX_LCORE); + if (core_cnt < 0) + return -ENOENT; + /* Get the core which has least number of services running. */ + while (core_cnt--) { + /* Reset default mapping */ + rte_service_map_lcore_set(service_id, + core_array[core_cnt], 0); + cnt = rte_service_lcore_count_services( + core_array[core_cnt]); + if (cnt < min_cnt) { + lcore = core_array[core_cnt]; + min_cnt = cnt; + } + } + if (rte_service_map_lcore_set(service_id, lcore, 1)) + return -ENOENT; } - return ret; + return 0; } #endif /* _EVT_COMMON_*/ diff --git a/app/test-eventdev/evt_options.c b/app/test-eventdev/evt_options.c index 65e22f84..e2187dfc 100644 --- a/app/test-eventdev/evt_options.c +++ b/app/test-eventdev/evt_options.c @@ -114,13 +114,6 @@ evt_parse_test_name(struct evt_options *opt, const char *arg) } static int -evt_parse_slcore(struct evt_options *opt, const char *arg) -{ - opt->slcore = atoi(arg); - return 0; -} - -static int evt_parse_socket_id(struct evt_options *opt, const char *arg) { opt->socket_id = atoi(arg); @@ -188,7 +181,6 @@ usage(char *program) "\t--test : name of the test application to run\n" "\t--socket_id : socket_id of application resources\n" "\t--pool_sz : pool size of the mempool\n" - "\t--slcore : lcore id of the scheduler\n" "\t--plcores : list of lcore ids for producers\n" "\t--wlcores : list of lcore ids for workers\n" "\t--stlist : list of scheduled types of the stages\n" @@ -254,7 +246,6 @@ static struct option lgopts[] = { { EVT_POOL_SZ, 1, 0, 0 }, { EVT_NB_PKTS, 1, 0, 0 }, { EVT_WKR_DEQ_DEP, 1, 0, 0 }, - { EVT_SCHED_LCORE, 1, 0, 0 }, { EVT_SCHED_TYPE_LIST, 1, 0, 0 }, { EVT_FWD_LATENCY, 0, 0, 0 }, { EVT_QUEUE_PRIORITY, 0, 0, 0 }, @@ -278,7 +269,6 @@ evt_opts_parse_long(int opt_idx, struct evt_options *opt) { EVT_POOL_SZ, evt_parse_pool_sz}, { EVT_NB_PKTS, evt_parse_nb_pkts}, { EVT_WKR_DEQ_DEP, evt_parse_wkr_deq_dep}, - { EVT_SCHED_LCORE, evt_parse_slcore}, { EVT_SCHED_TYPE_LIST, evt_parse_sched_type_list}, { EVT_FWD_LATENCY, evt_parse_fwd_latency}, { EVT_QUEUE_PRIORITY, evt_parse_queue_priority}, diff --git a/app/test-eventdev/evt_options.h b/app/test-eventdev/evt_options.h index d8a9fdcc..a9a91252 100644 --- a/app/test-eventdev/evt_options.h +++ b/app/test-eventdev/evt_options.h @@ -47,7 +47,6 @@ #define EVT_VERBOSE ("verbose") #define EVT_DEVICE ("dev") #define EVT_TEST ("test") -#define EVT_SCHED_LCORE ("slcore") #define EVT_PROD_LCORES ("plcores") #define EVT_WORK_LCORES ("wlcores") #define EVT_NB_FLOWS ("nb_flows") @@ -67,7 +66,6 @@ struct evt_options { bool plcores[RTE_MAX_LCORE]; bool wlcores[RTE_MAX_LCORE]; uint8_t sched_type_list[EVT_MAX_STAGES]; - int slcore; uint32_t nb_flows; int socket_id; int pool_sz; @@ -219,12 +217,6 @@ evt_dump_nb_flows(struct evt_options *opt) } static inline void -evt_dump_scheduler_lcore(struct evt_options *opt) -{ - evt_dump("scheduler lcore", "%d", opt->slcore); -} - -static inline void evt_dump_worker_dequeue_depth(struct evt_options *opt) { evt_dump("worker deq depth", "%d", opt->wkr_deq_dep); diff --git a/app/test-eventdev/test_order_atq.c b/app/test-eventdev/test_order_atq.c index 7e6c67d4..4ee0dea8 100644 --- a/app/test-eventdev/test_order_atq.c +++ b/app/test-eventdev/test_order_atq.c @@ -179,6 +179,12 @@ order_atq_eventdev_setup(struct evt_test *test, struct evt_options *opt) if (ret) return ret; + ret = evt_service_setup(opt->dev_id); + if (ret) { + evt_err("No service lcore found to run event dev."); + return ret; + } + ret = rte_event_dev_start(opt->dev_id); if (ret) { evt_err("failed to start eventdev %d", opt->dev_id); diff --git a/app/test-eventdev/test_order_common.c b/app/test-eventdev/test_order_common.c index 80e14c08..7cfe7fac 100644 --- a/app/test-eventdev/test_order_common.c +++ b/app/test-eventdev/test_order_common.c @@ -292,9 +292,6 @@ order_launch_lcores(struct evt_test *test, struct evt_options *opt, int64_t old_remaining = -1; while (t->err == false) { - - rte_event_schedule(opt->dev_id); - uint64_t new_cycles = rte_get_timer_cycles(); int64_t remaining = rte_atomic64_read(&t->outstand_pkts); diff --git a/app/test-eventdev/test_order_queue.c b/app/test-eventdev/test_order_queue.c index beadd9c3..eef69a4c 100644 --- a/app/test-eventdev/test_order_queue.c +++ b/app/test-eventdev/test_order_queue.c @@ -164,7 +164,7 @@ order_queue_eventdev_setup(struct evt_test *test, struct evt_options *opt) /* q0 (ordered queue) configuration */ struct rte_event_queue_conf q0_ordered_conf = { .priority = RTE_EVENT_DEV_PRIORITY_NORMAL, - .event_queue_cfg = RTE_EVENT_QUEUE_CFG_ORDERED_ONLY, + .schedule_type = RTE_SCHED_TYPE_ORDERED, .nb_atomic_flows = opt->nb_flows, .nb_atomic_order_sequences = opt->nb_flows, }; @@ -177,7 +177,7 @@ order_queue_eventdev_setup(struct evt_test *test, struct evt_options *opt) /* q1 (atomic queue) configuration */ struct rte_event_queue_conf q1_atomic_conf = { .priority = RTE_EVENT_DEV_PRIORITY_NORMAL, - .event_queue_cfg = RTE_EVENT_QUEUE_CFG_ATOMIC_ONLY, + .schedule_type = RTE_SCHED_TYPE_ATOMIC, .nb_atomic_flows = opt->nb_flows, .nb_atomic_order_sequences = opt->nb_flows, }; @@ -192,6 +192,12 @@ order_queue_eventdev_setup(struct evt_test *test, struct evt_options *opt) if (ret) return ret; + ret = evt_service_setup(opt->dev_id); + if (ret) { + evt_err("No service lcore found to run event dev."); + return ret; + } + ret = rte_event_dev_start(opt->dev_id); if (ret) { evt_err("failed to start eventdev %d", opt->dev_id); diff --git a/app/test-eventdev/test_perf_atq.c b/app/test-eventdev/test_perf_atq.c index 9c3efa3a..0e9f2db0 100644 --- a/app/test-eventdev/test_perf_atq.c +++ b/app/test-eventdev/test_perf_atq.c @@ -221,6 +221,12 @@ perf_atq_eventdev_setup(struct evt_test *test, struct evt_options *opt) if (ret) return ret; + ret = evt_service_setup(opt->dev_id); + if (ret) { + evt_err("No service lcore found to run event dev."); + return ret; + } + ret = rte_event_dev_start(opt->dev_id); if (ret) { evt_err("failed to start eventdev %d", opt->dev_id); diff --git a/app/test-eventdev/test_perf_common.c b/app/test-eventdev/test_perf_common.c index 7b092994..e77b4723 100644 --- a/app/test-eventdev/test_perf_common.c +++ b/app/test-eventdev/test_perf_common.c @@ -88,18 +88,6 @@ perf_producer(void *arg) return 0; } -static inline int -scheduler(void *arg) -{ - struct test_perf *t = arg; - const uint8_t dev_id = t->opt->dev_id; - - while (t->done == false) - rte_event_schedule(dev_id); - - return 0; -} - static inline uint64_t processed_pkts(struct test_perf *t) { @@ -163,15 +151,6 @@ perf_launch_lcores(struct evt_test *test, struct evt_options *opt, port_idx++; } - /* launch scheduler */ - if (!evt_has_distributed_sched(opt->dev_id)) { - ret = rte_eal_remote_launch(scheduler, t, opt->slcore); - if (ret) { - evt_err("failed to launch sched %d", opt->slcore); - return ret; - } - } - const uint64_t total_pkts = opt->nb_pkts * evt_nr_active_lcores(opt->plcores); @@ -307,10 +286,9 @@ int perf_opt_check(struct evt_options *opt, uint64_t nb_queues) { unsigned int lcores; - bool need_slcore = !evt_has_distributed_sched(opt->dev_id); - /* N producer + N worker + 1 scheduler(based on dev capa) + 1 master */ - lcores = need_slcore ? 4 : 3; + /* N producer + N worker + 1 master */ + lcores = 3; if (rte_lcore_count() < lcores) { evt_err("test need minimum %d lcores", lcores); @@ -322,10 +300,6 @@ perf_opt_check(struct evt_options *opt, uint64_t nb_queues) evt_err("worker lcores overlaps with master lcore"); return -1; } - if (need_slcore && evt_lcores_has_overlap(opt->wlcores, opt->slcore)) { - evt_err("worker lcores overlaps with scheduler lcore"); - return -1; - } if (evt_lcores_has_overlap_multi(opt->wlcores, opt->plcores)) { evt_err("worker lcores overlaps producer lcores"); return -1; @@ -344,10 +318,6 @@ perf_opt_check(struct evt_options *opt, uint64_t nb_queues) evt_err("producer lcores overlaps with master lcore"); return -1; } - if (need_slcore && evt_lcores_has_overlap(opt->plcores, opt->slcore)) { - evt_err("producer lcores overlaps with scheduler lcore"); - return -1; - } if (evt_has_disabled_lcore(opt->plcores)) { evt_err("one or more producer lcores are not enabled"); return -1; @@ -357,17 +327,6 @@ perf_opt_check(struct evt_options *opt, uint64_t nb_queues) return -1; } - /* Validate scheduler lcore */ - if (!evt_has_distributed_sched(opt->dev_id) && - opt->slcore == (int)rte_get_master_lcore()) { - evt_err("scheduler lcore and master lcore should be different"); - return -1; - } - if (need_slcore && !rte_lcore_is_enabled(opt->slcore)) { - evt_err("scheduler lcore is not enabled"); - return -1; - } - if (evt_has_invalid_stage(opt)) return -1; @@ -405,8 +364,6 @@ perf_opt_dump(struct evt_options *opt, uint8_t nb_queues) evt_dump_producer_lcores(opt); evt_dump("nb_worker_lcores", "%d", evt_nr_active_lcores(opt->wlcores)); evt_dump_worker_lcores(opt); - if (!evt_has_distributed_sched(opt->dev_id)) - evt_dump_scheduler_lcore(opt); evt_dump_nb_stages(opt); evt_dump("nb_evdev_ports", "%d", perf_nb_event_ports(opt)); evt_dump("nb_evdev_queues", "%d", nb_queues); diff --git a/app/test-eventdev/test_perf_common.h b/app/test-eventdev/test_perf_common.h index 4956586c..c6fc70cd 100644 --- a/app/test-eventdev/test_perf_common.h +++ b/app/test-eventdev/test_perf_common.h @@ -159,6 +159,7 @@ int perf_test_setup(struct evt_test *test, struct evt_options *opt); int perf_mempool_setup(struct evt_test *test, struct evt_options *opt); int perf_event_dev_port_setup(struct evt_test *test, struct evt_options *opt, uint8_t stride, uint8_t nb_queues); +int perf_event_dev_service_setup(uint8_t dev_id); int perf_launch_lcores(struct evt_test *test, struct evt_options *opt, int (*worker)(void *)); void perf_opt_dump(struct evt_options *opt, uint8_t nb_queues); diff --git a/app/test-eventdev/test_perf_queue.c b/app/test-eventdev/test_perf_queue.c index 658c08a0..d843eea1 100644 --- a/app/test-eventdev/test_perf_queue.c +++ b/app/test-eventdev/test_perf_queue.c @@ -205,8 +205,8 @@ perf_queue_eventdev_setup(struct evt_test *test, struct evt_options *opt) }; /* queue configurations */ for (queue = 0; queue < perf_queue_nb_event_queues(opt); queue++) { - q_conf.event_queue_cfg = evt_sched_type2queue_cfg - (opt->sched_type_list[queue % nb_stages]); + q_conf.schedule_type = + (opt->sched_type_list[queue % nb_stages]); if (opt->q_priority) { uint8_t stage_pos = queue % nb_stages; @@ -232,6 +232,12 @@ perf_queue_eventdev_setup(struct evt_test *test, struct evt_options *opt) if (ret) return ret; + ret = evt_service_setup(opt->dev_id); + if (ret) { + evt_err("No service lcore found to run event dev."); + return ret; + } + ret = rte_event_dev_start(opt->dev_id); if (ret) { evt_err("failed to start eventdev %d", opt->dev_id); diff --git a/app/test-pmd/Makefile b/app/test-pmd/Makefile index c36be19f..d21308fc 100644 --- a/app/test-pmd/Makefile +++ b/app/test-pmd/Makefile @@ -48,6 +48,8 @@ SRCS-y := testpmd.c SRCS-y += parameters.c SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline.c SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_flow.c +SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_mtr.c +SRCS-$(CONFIG_RTE_LIBRTE_CMDLINE) += cmdline_tm.c SRCS-y += config.c SRCS-y += iofwd.c SRCS-y += macfwd.c @@ -59,6 +61,10 @@ SRCS-y += csumonly.c SRCS-y += icmpecho.c SRCS-$(CONFIG_RTE_LIBRTE_IEEE1588) += ieee1588fwd.c +ifeq ($(CONFIG_RTE_LIBRTE_PMD_SOFTNIC)$(CONFIG_RTE_LIBRTE_SCHED),yy) +SRCS-y += tm.c +endif + ifeq ($(CONFIG_RTE_BUILD_SHARED_LIB),y) ifeq ($(CONFIG_RTE_LIBRTE_PMD_BOND),y) @@ -81,6 +87,10 @@ ifeq ($(CONFIG_RTE_LIBRTE_PMD_XENVIRT),y) LDLIBS += -lrte_pmd_xenvirt endif +ifeq ($(CONFIG_RTE_LIBRTE_PMD_SOFTNIC),y) +LDLIBS += -lrte_pmd_softnic +endif + endif CFLAGS_cmdline.o := -D_GNU_SOURCE diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index cd8c3585..f71d9630 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -99,6 +99,8 @@ #include <rte_pmd_bnxt.h> #endif #include "testpmd.h" +#include "cmdline_mtr.h" +#include "cmdline_tm.h" static struct cmdline *testpmd_cl; @@ -230,6 +232,27 @@ static void cmd_help_long_parsed(void *parsed_result, "clear vf stats (port_id) (vf_id)\n" " Reset a VF's statistics.\n\n" + + "show port (port_id) pctype mapping\n" + " Get flow ptype to pctype mapping on a port\n\n" + + "show port meter stats (port_id) (meter_id) (clear)\n" + " Get meter stats on a port\n\n" + "show port tm cap (port_id)\n" + " Display the port TM capability.\n\n" + + "show port tm level cap (port_id) (level_id)\n" + " Display the port TM hierarchical level capability.\n\n" + + "show port tm node cap (port_id) (node_id)\n" + " Display the port TM node capability.\n\n" + + "show port tm node type (port_id) (node_id)\n" + " Display the port TM node type.\n\n" + + "show port tm node stats (port_id) (node_id) (clear)\n" + " Display the port TM node stats.\n\n" + ); } @@ -423,13 +446,27 @@ static void cmd_help_long_parsed(void *parsed_result, "tso show (portid)" " Display the status of TCP Segmentation Offload.\n\n" - "gro (on|off) (port_id)" + "set port (port_id) gro on|off\n" " Enable or disable Generic Receive Offload in" " csum forwarding engine.\n\n" - "gro set (max_flow_num) (max_item_num_per_flow) (port_id)\n" - " Set max flow number and max packet number per-flow" - " for GRO.\n\n" + "show port (port_id) gro\n" + " Display GRO configuration.\n\n" + + "set gro flush (cycles)\n" + " Set the cycle to flush GROed packets from" + " reassembly tables.\n\n" + + "set port (port_id) gso (on|off)" + " Enable or disable Generic Segmentation Offload in" + " csum forwarding engine.\n\n" + + "set gso segsz (length)\n" + " Set max packet length for output GSO segments," + " including packet header and payload.\n\n" + + "show port (port_id) gso\n" + " Show GSO configuration.\n\n" "set fwd (%s)\n" " Set packet forwarding mode.\n\n" @@ -489,6 +526,10 @@ static void cmd_help_long_parsed(void *parsed_result, " e.g., 'set stat_qmap rx 0 2 5' sets rx queue 2" " on port 0 to mapping 5.\n\n" + "set xstats-hide-zero on|off\n" + " Set the option to hide the zero values" + " for xstats display.\n" + "set port (port_id) vf (vf_id) rx|tx on|off\n" " Enable/Disable a VF receive/tranmit from a port\n\n" @@ -619,6 +660,11 @@ static void cmd_help_long_parsed(void *parsed_result, "E-tag set filter del e-tag-id (value) port (port_id)\n" " Delete an E-tag forwarding filter on a port\n\n" +#if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED + "set port tm hierarchy default (port_id)\n" + " Set default traffic Management hierarchy on a port\n\n" + +#endif "ddp add (port_id) (profile_path[,output_path])\n" " Load a profile package on a port\n\n" @@ -637,6 +683,100 @@ static void cmd_help_long_parsed(void *parsed_result, "ptype mapping update (port_id) (hw_ptype) (sw_ptype)\n" " Update a ptype mapping item on a port\n\n" + "set port (port_id) queue-region region_id (value) " + "queue_start_index (value) queue_num (value)\n" + " Set a queue region on a port\n\n" + + "set port (port_id) queue-region region_id (value) " + "flowtype (value)\n" + " Set a flowtype region index on a port\n\n" + + "set port (port_id) queue-region UP (value) region_id (value)\n" + " Set the mapping of User Priority to " + "queue region on a port\n\n" + + "set port (port_id) queue-region flush (on|off)\n" + " flush all queue region related configuration\n\n" + + "add port meter profile srtcm_rfc2697 (port_id) (profile_id) (cir) (cbs) (ebs) (color_aware)\n" + " meter profile add - srtcm rfc 2697\n\n" + + "add port meter profile trtcm_rfc2698 (port_id) (profile_id) (cir) (pir) (cbs) (pbs)\n" + " meter profile add - trtcm rfc 2698\n\n" + + "add port meter profile trtcm_rfc4115 (port_id) (profile_id) (cir) (eir) (cbs) (ebs)\n" + " meter profile add - trtcm rfc 4115\n\n" + + "del port meter profile (port_id) (profile_id)\n" + " meter profile delete\n\n" + + "set port meter (port_id) (mtr_id) (profile_id) (g_action) (y_action) (r_action) (stats_mask) (shared)\n" + " meter create\n\n" + + "del port meter (port_id) (mtr_id)\n" + " meter delete\n\n" + + "set port meter profile (port_id) (mtr_id) (profile_id)\n" + " meter update meter profile\n\n" + + "set port meter policer action (port_id) (mtr_id) (color) (action)\n" + " meter update policer action\n\n" + + "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n" + " meter update stats\n\n" + + "show port (port_id) queue-region\n" + " show all queue region related configuration info\n\n" + + "add port tm node shaper profile (port_id) (shaper_profile_id)" + " (tb_rate) (tb_size) (packet_length_adjust)\n" + " Add port tm node private shaper profile.\n\n" + + "del port tm node shaper profile (port_id) (shaper_profile_id)\n" + " Delete port tm node private shaper profile.\n\n" + + "add port tm node shared shaper (port_id) (shared_shaper_id)" + " (shaper_profile_id)\n" + " Add/update port tm node shared shaper.\n\n" + + "del port tm node shared shaper (port_id) (shared_shaper_id)\n" + " Delete port tm node shared shaper.\n\n" + + "set port tm node shaper profile (port_id) (node_id)" + " (shaper_profile_id)\n" + " Set port tm node shaper profile.\n\n" + + "add port tm node wred profile (port_id) (wred_profile_id)" + " (color_g) (min_th_g) (max_th_g) (maxp_inv_g) (wq_log2_g)" + " (color_y) (min_th_y) (max_th_y) (maxp_inv_y) (wq_log2_y)" + " (color_r) (min_th_r) (max_th_r) (maxp_inv_r) (wq_log2_r)\n" + " Add port tm node wred profile.\n\n" + + "del port tm node wred profile (port_id) (wred_profile_id)\n" + " Delete port tm node wred profile.\n\n" + + "add port tm nonleaf node (port_id) (node_id) (parent_node_id)" + " (priority) (weight) (level_id) (shaper_profile_id)" + " (n_sp_priorities) (stats_mask) (n_shared_shapers)" + " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n" + " Add port tm nonleaf node.\n\n" + + "add port tm leaf node (port_id) (node_id) (parent_node_id)" + " (priority) (weight) (level_id) (shaper_profile_id)" + " (cman_mode) (wred_profile_id) (stats_mask) (n_shared_shapers)" + " [(shared_shaper_id_0) (shared_shaper_id_1)...]\n" + " Add port tm leaf node.\n\n" + + "del port tm node (port_id) (node_id)\n" + " Delete port tm node.\n\n" + + "set port tm node parent (port_id) (node_id) (parent_node_id)" + " (priority) (weight)\n" + " Set port tm node parent.\n\n" + + "port tm hierarchy commit (port_id) (clean_on_fail)\n" + " Commit tm hierarchy.\n\n" + , list_pkt_forwarding_modes() ); } @@ -675,13 +815,14 @@ static void cmd_help_long_parsed(void *parsed_result, "port config all max-pkt-len (value)\n" " Set the max packet length.\n\n" - "port config all (crc-strip|scatter|rx-cksum|hw-vlan|hw-vlan-filter|" + "port config all (crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|hw-vlan-filter|" "hw-vlan-strip|hw-vlan-extend|drop-en)" " (on|off)\n" " Set crc-strip/scatter/rx-checksum/hardware-vlan/drop_en" " for ports.\n\n" - "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none)\n" + "port config all rss (all|ip|tcp|udp|sctp|ether|port|vxlan|" + "geneve|nvgre|none|<flowtype_id>)\n" " Set the RSS mode.\n\n" "port config port-id rss reta (hash,queue)[,(hash,queue)]\n" @@ -716,6 +857,13 @@ static void cmd_help_long_parsed(void *parsed_result, "port config (port_id|all) l2-tunnel E-tag" " (enable|disable)\n" " Enable/disable the E-tag support.\n\n" + + "port config (port_id) pctype mapping reset\n" + " Reset flow type to pctype mapping on a port\n\n" + + "port config (port_id) pctype mapping update" + " (pctype_id_0[,pctype_id_1]*) (flow_type_id)\n" + " Update a flow type to pctype mapping item on a port\n\n" ); } @@ -878,8 +1026,8 @@ static void cmd_help_long_parsed(void *parsed_result, "set_hash_input_set (port_id) (ipv4|ipv4-frag|" "ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|ipv6|" "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|" - "l2_payload) (ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|" - "dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|" + "l2_payload|<flowtype_id>) (ovlan|ivlan|src-ipv4|dst-ipv4|" + "src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|ipv6-tc|" "ipv6-next-header|udp-src-port|udp-dst-port|" "tcp-src-port|tcp-dst-port|sctp-src-port|" "sctp-dst-port|sctp-veri-tag|udp-key|gre-key|fld-1st|" @@ -972,6 +1120,8 @@ static void cmd_operate_port_parsed(void *parsed_result, stop_port(RTE_PORT_ALL); else if (!strcmp(res->name, "close")) close_port(RTE_PORT_ALL); + else if (!strcmp(res->name, "reset")) + reset_port(RTE_PORT_ALL); else printf("Unknown parameter\n"); } @@ -981,14 +1131,14 @@ cmdline_parse_token_string_t cmd_operate_port_all_cmd = "port"); cmdline_parse_token_string_t cmd_operate_port_all_port = TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, name, - "start#stop#close"); + "start#stop#close#reset"); cmdline_parse_token_string_t cmd_operate_port_all_all = TOKEN_STRING_INITIALIZER(struct cmd_operate_port_result, value, "all"); cmdline_parse_inst_t cmd_operate_port = { .f = cmd_operate_port_parsed, .data = NULL, - .help_str = "port start|stop|close all: Start/Stop/Close all ports", + .help_str = "port start|stop|close all: Start/Stop/Close/Reset all ports", .tokens = { (void *)&cmd_operate_port_all_cmd, (void *)&cmd_operate_port_all_port, @@ -1016,6 +1166,8 @@ static void cmd_operate_specific_port_parsed(void *parsed_result, stop_port(res->value); else if (!strcmp(res->name, "close")) close_port(res->value); + else if (!strcmp(res->name, "reset")) + reset_port(res->value); else printf("Unknown parameter\n"); } @@ -1025,7 +1177,7 @@ cmdline_parse_token_string_t cmd_operate_specific_port_cmd = keyword, "port"); cmdline_parse_token_string_t cmd_operate_specific_port_port = TOKEN_STRING_INITIALIZER(struct cmd_operate_specific_port_result, - name, "start#stop#close"); + name, "start#stop#close#reset"); cmdline_parse_token_num_t cmd_operate_specific_port_id = TOKEN_NUM_INITIALIZER(struct cmd_operate_specific_port_result, value, UINT8); @@ -1033,7 +1185,7 @@ cmdline_parse_token_num_t cmd_operate_specific_port_id = cmdline_parse_inst_t cmd_operate_specific_port = { .f = cmd_operate_specific_port_parsed, .data = NULL, - .help_str = "port start|stop|close <port_id>: Start/Stop/Close port_id", + .help_str = "port start|stop|close <port_id>: Start/Stop/Close/Reset port_id", .tokens = { (void *)&cmd_operate_specific_port_cmd, (void *)&cmd_operate_specific_port_port, @@ -1088,7 +1240,7 @@ cmdline_parse_inst_t cmd_operate_attach_port = { struct cmd_operate_detach_port_result { cmdline_fixed_string_t port; cmdline_fixed_string_t keyword; - uint8_t port_id; + portid_t port_id; }; static void cmd_operate_detach_port_parsed(void *parsed_result, @@ -1111,7 +1263,7 @@ cmdline_parse_token_string_t cmd_operate_detach_port_keyword = keyword, "detach"); cmdline_parse_token_num_t cmd_operate_detach_port_port_id = TOKEN_NUM_INITIALIZER(struct cmd_operate_detach_port_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_operate_detach_port = { .f = cmd_operate_detach_port_parsed, @@ -1490,7 +1642,7 @@ struct cmd_config_mtu_result { cmdline_fixed_string_t port; cmdline_fixed_string_t keyword; cmdline_fixed_string_t mtu; - uint8_t port_id; + portid_t port_id; uint16_t value; }; @@ -1518,7 +1670,7 @@ cmdline_parse_token_string_t cmd_config_mtu_mtu = TOKEN_STRING_INITIALIZER(struct cmd_config_mtu_result, keyword, "mtu"); cmdline_parse_token_num_t cmd_config_mtu_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, port_id, UINT16); cmdline_parse_token_num_t cmd_config_mtu_value = TOKEN_NUM_INITIALIZER(struct cmd_config_mtu_result, value, UINT16); @@ -1584,6 +1736,15 @@ cmd_config_rx_mode_flag_parsed(void *parsed_result, printf("Unknown parameter\n"); return; } + } else if (!strcmp(res->name, "rx-timestamp")) { + if (!strcmp(res->value, "on")) + rx_mode.hw_timestamp = 1; + else if (!strcmp(res->value, "off")) + rx_mode.hw_timestamp = 0; + else { + printf("Unknown parameter\n"); + return; + } } else if (!strcmp(res->name, "hw-vlan")) { if (!strcmp(res->value, "on")) { rx_mode.hw_vlan_filter = 1; @@ -1652,7 +1813,7 @@ cmdline_parse_token_string_t cmd_config_rx_mode_flag_all = TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, all, "all"); cmdline_parse_token_string_t cmd_config_rx_mode_flag_name = TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, name, - "crc-strip#scatter#rx-cksum#hw-vlan#" + "crc-strip#scatter#rx-cksum#rx-timestamp#hw-vlan#" "hw-vlan-filter#hw-vlan-strip#hw-vlan-extend"); cmdline_parse_token_string_t cmd_config_rx_mode_flag_value = TOKEN_STRING_INITIALIZER(struct cmd_config_rx_mode_flag, value, @@ -1661,7 +1822,7 @@ cmdline_parse_token_string_t cmd_config_rx_mode_flag_value = cmdline_parse_inst_t cmd_config_rx_mode_flag = { .f = cmd_config_rx_mode_flag_parsed, .data = NULL, - .help_str = "port config all crc-strip|scatter|rx-cksum|hw-vlan|" + .help_str = "port config all crc-strip|scatter|rx-cksum|rx-timestamp|hw-vlan|" "hw-vlan-filter|hw-vlan-strip|hw-vlan-extend on|off", .tokens = { (void *)&cmd_config_rx_mode_flag_port, @@ -1688,7 +1849,7 @@ cmd_config_rss_parsed(void *parsed_result, __attribute__((unused)) void *data) { struct cmd_config_rss *res = parsed_result; - struct rte_eth_rss_conf rss_conf; + struct rte_eth_rss_conf rss_conf = { .rss_key_len = 0, }; int diag; uint8_t i; @@ -1716,6 +1877,9 @@ cmd_config_rss_parsed(void *parsed_result, rss_conf.rss_hf = ETH_RSS_NVGRE; else if (!strcmp(res->value, "none")) rss_conf.rss_hf = 0; + else if (isdigit(res->value[0]) && atoi(res->value) > 0 && + atoi(res->value) < 64) + rss_conf.rss_hf = 1ULL << atoi(res->value); else { printf("Unknown parameter\n"); return; @@ -1739,14 +1903,13 @@ cmdline_parse_token_string_t cmd_config_rss_all = cmdline_parse_token_string_t cmd_config_rss_name = TOKEN_STRING_INITIALIZER(struct cmd_config_rss, name, "rss"); cmdline_parse_token_string_t cmd_config_rss_value = - TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, - "all#ip#tcp#udp#sctp#ether#port#vxlan#geneve#nvgre#none"); + TOKEN_STRING_INITIALIZER(struct cmd_config_rss, value, NULL); cmdline_parse_inst_t cmd_config_rss = { .f = cmd_config_rss_parsed, .data = NULL, .help_str = "port config all rss " - "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none", + "all|ip|tcp|udp|sctp|ether|port|vxlan|geneve|nvgre|none|<flowtype_id>", .tokens = { (void *)&cmd_config_rss_port, (void *)&cmd_config_rss_keyword, @@ -1761,7 +1924,7 @@ cmdline_parse_inst_t cmd_config_rss = { struct cmd_config_rss_hash_key { cmdline_fixed_string_t port; cmdline_fixed_string_t config; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t rss_hash_key; cmdline_fixed_string_t rss_type; cmdline_fixed_string_t key; @@ -1843,7 +2006,7 @@ cmdline_parse_token_string_t cmd_config_rss_hash_key_config = TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config, "config"); cmdline_parse_token_num_t cmd_config_rss_hash_key_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT16); cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key = TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, rss_hash_key, "rss-hash-key"); @@ -1878,7 +2041,7 @@ cmdline_parse_inst_t cmd_config_rss_hash_key = { /* *** configure port rxq/txq start/stop *** */ struct cmd_config_rxtx_queue { cmdline_fixed_string_t port; - uint8_t portid; + portid_t portid; cmdline_fixed_string_t rxtxq; uint16_t qid; cmdline_fixed_string_t opname; @@ -1946,7 +2109,7 @@ cmd_config_rxtx_queue_parsed(void *parsed_result, cmdline_parse_token_string_t cmd_config_rxtx_queue_port = TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, port, "port"); cmdline_parse_token_num_t cmd_config_rxtx_queue_portid = - TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_config_rxtx_queue, portid, UINT16); cmdline_parse_token_string_t cmd_config_rxtx_queue_rxtxq = TOKEN_STRING_INITIALIZER(struct cmd_config_rxtx_queue, rxtxq, "rxq#txq"); cmdline_parse_token_num_t cmd_config_rxtx_queue_qid = @@ -1973,7 +2136,7 @@ cmdline_parse_inst_t cmd_config_rxtx_queue = { struct cmd_config_rss_reta { cmdline_fixed_string_t port; cmdline_fixed_string_t keyword; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t name; cmdline_fixed_string_t list_name; cmdline_fixed_string_t list_of_items; @@ -2082,7 +2245,7 @@ cmdline_parse_token_string_t cmd_config_rss_reta_port = cmdline_parse_token_string_t cmd_config_rss_reta_keyword = TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, keyword, "config"); cmdline_parse_token_num_t cmd_config_rss_reta_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_config_rss_reta, port_id, UINT16); cmdline_parse_token_string_t cmd_config_rss_reta_name = TOKEN_STRING_INITIALIZER(struct cmd_config_rss_reta, name, "rss"); cmdline_parse_token_string_t cmd_config_rss_reta_list_name = @@ -2109,7 +2272,7 @@ cmdline_parse_inst_t cmd_config_rss_reta = { struct cmd_showport_reta { cmdline_fixed_string_t show; cmdline_fixed_string_t port; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t rss; cmdline_fixed_string_t reta; uint16_t size; @@ -2164,12 +2327,14 @@ cmd_showport_reta_parsed(void *parsed_result, struct cmd_showport_reta *res = parsed_result; struct rte_eth_rss_reta_entry64 reta_conf[8]; struct rte_eth_dev_info dev_info; + uint16_t max_reta_size; memset(&dev_info, 0, sizeof(dev_info)); rte_eth_dev_info_get(res->port_id, &dev_info); - if (dev_info.reta_size == 0 || res->size != dev_info.reta_size || - res->size > ETH_RSS_RETA_SIZE_512) { - printf("Invalid redirection table size: %u\n", res->size); + max_reta_size = RTE_MIN(dev_info.reta_size, ETH_RSS_RETA_SIZE_512); + if (res->size == 0 || res->size > max_reta_size) { + printf("Invalid redirection table size: %u (1-%u)\n", + res->size, max_reta_size); return; } @@ -2188,7 +2353,7 @@ cmdline_parse_token_string_t cmd_showport_reta_show = cmdline_parse_token_string_t cmd_showport_reta_port = TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, port, "port"); cmdline_parse_token_num_t cmd_showport_reta_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_showport_reta, port_id, UINT16); cmdline_parse_token_string_t cmd_showport_reta_rss = TOKEN_STRING_INITIALIZER(struct cmd_showport_reta, rss, "rss"); cmdline_parse_token_string_t cmd_showport_reta_reta = @@ -2219,7 +2384,7 @@ cmdline_parse_inst_t cmd_showport_reta = { struct cmd_showport_rss_hash { cmdline_fixed_string_t show; cmdline_fixed_string_t port; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t rss_hash; cmdline_fixed_string_t rss_type; cmdline_fixed_string_t key; /* optional argument */ @@ -2240,7 +2405,7 @@ cmdline_parse_token_string_t cmd_showport_rss_hash_show = cmdline_parse_token_string_t cmd_showport_rss_hash_port = TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, port, "port"); cmdline_parse_token_num_t cmd_showport_rss_hash_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_showport_rss_hash, port_id, UINT16); cmdline_parse_token_string_t cmd_showport_rss_hash_rss_hash = TOKEN_STRING_INITIALIZER(struct cmd_showport_rss_hash, rss_hash, "rss-hash"); @@ -2292,7 +2457,7 @@ cmdline_parse_inst_t cmd_showport_rss_hash_key = { struct cmd_config_dcb { cmdline_fixed_string_t port; cmdline_fixed_string_t config; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t dcb; cmdline_fixed_string_t vt; cmdline_fixed_string_t vt_en; @@ -2358,7 +2523,7 @@ cmdline_parse_token_string_t cmd_config_dcb_port = cmdline_parse_token_string_t cmd_config_dcb_config = TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, config, "config"); cmdline_parse_token_num_t cmd_config_dcb_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_config_dcb, port_id, UINT16); cmdline_parse_token_string_t cmd_config_dcb_dcb = TOKEN_STRING_INITIALIZER(struct cmd_config_dcb, dcb, "dcb"); cmdline_parse_token_string_t cmd_config_dcb_vt = @@ -2995,7 +3160,7 @@ struct cmd_rx_vlan_filter_all_result { cmdline_fixed_string_t rx_vlan; cmdline_fixed_string_t what; cmdline_fixed_string_t all; - uint8_t port_id; + portid_t port_id; }; static void @@ -3022,7 +3187,7 @@ cmdline_parse_token_string_t cmd_rx_vlan_filter_all_all = all, "all"); cmdline_parse_token_num_t cmd_rx_vlan_filter_all_portid = TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_all_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_rx_vlan_filter_all = { .f = cmd_rx_vlan_filter_all_parsed, @@ -3148,7 +3313,7 @@ struct cmd_vlan_tpid_result { cmdline_fixed_string_t vlan_type; cmdline_fixed_string_t what; uint16_t tp_id; - uint8_t port_id; + portid_t port_id; }; static void @@ -3210,7 +3375,7 @@ struct cmd_rx_vlan_filter_result { cmdline_fixed_string_t rx_vlan; cmdline_fixed_string_t what; uint16_t vlan_id; - uint8_t port_id; + portid_t port_id; }; static void @@ -3237,7 +3402,7 @@ cmdline_parse_token_num_t cmd_rx_vlan_filter_vlanid = vlan_id, UINT16); cmdline_parse_token_num_t cmd_rx_vlan_filter_portid = TOKEN_NUM_INITIALIZER(struct cmd_rx_vlan_filter_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_rx_vlan_filter = { .f = cmd_rx_vlan_filter_parsed, @@ -3258,7 +3423,7 @@ cmdline_parse_inst_t cmd_rx_vlan_filter = { struct cmd_tx_vlan_set_result { cmdline_fixed_string_t tx_vlan; cmdline_fixed_string_t set; - uint8_t port_id; + portid_t port_id; uint16_t vlan_id; }; @@ -3280,7 +3445,7 @@ cmdline_parse_token_string_t cmd_tx_vlan_set_set = set, "set"); cmdline_parse_token_num_t cmd_tx_vlan_set_portid = TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_tx_vlan_set_vlanid = TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_result, vlan_id, UINT16); @@ -3304,7 +3469,7 @@ cmdline_parse_inst_t cmd_tx_vlan_set = { struct cmd_tx_vlan_set_qinq_result { cmdline_fixed_string_t tx_vlan; cmdline_fixed_string_t set; - uint8_t port_id; + portid_t port_id; uint16_t vlan_id; uint16_t vlan_id_outer; }; @@ -3327,7 +3492,7 @@ cmdline_parse_token_string_t cmd_tx_vlan_set_qinq_set = set, "set"); cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_portid = TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_tx_vlan_set_qinq_vlanid = TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_qinq_result, vlan_id, UINT16); @@ -3356,7 +3521,7 @@ struct cmd_tx_vlan_set_pvid_result { cmdline_fixed_string_t tx_vlan; cmdline_fixed_string_t set; cmdline_fixed_string_t pvid; - uint8_t port_id; + portid_t port_id; uint16_t vlan_id; cmdline_fixed_string_t mode; }; @@ -3385,7 +3550,7 @@ cmdline_parse_token_string_t cmd_tx_vlan_set_pvid_pvid = pvid, "pvid"); cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_port_id = TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_tx_vlan_set_pvid_vlan_id = TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_set_pvid_result, vlan_id, UINT16); @@ -3412,7 +3577,7 @@ cmdline_parse_inst_t cmd_tx_vlan_set_pvid = { struct cmd_tx_vlan_reset_result { cmdline_fixed_string_t tx_vlan; cmdline_fixed_string_t reset; - uint8_t port_id; + portid_t port_id; }; static void @@ -3433,7 +3598,7 @@ cmdline_parse_token_string_t cmd_tx_vlan_reset_reset = reset, "reset"); cmdline_parse_token_num_t cmd_tx_vlan_reset_portid = TOKEN_NUM_INITIALIZER(struct cmd_tx_vlan_reset_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_tx_vlan_reset = { .f = cmd_tx_vlan_reset_parsed, @@ -3455,7 +3620,7 @@ struct cmd_csum_result { cmdline_fixed_string_t mode; cmdline_fixed_string_t proto; cmdline_fixed_string_t hwsw; - uint8_t port_id; + portid_t port_id; }; static void @@ -3560,7 +3725,7 @@ cmdline_parse_token_string_t cmd_csum_hwsw = hwsw, "hw#sw"); cmdline_parse_token_num_t cmd_csum_portid = TOKEN_NUM_INITIALIZER(struct cmd_csum_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_csum_set = { .f = cmd_csum_parsed, @@ -3599,7 +3764,7 @@ struct cmd_csum_tunnel_result { cmdline_fixed_string_t csum; cmdline_fixed_string_t parse; cmdline_fixed_string_t onoff; - uint8_t port_id; + portid_t port_id; }; static void @@ -3633,7 +3798,7 @@ cmdline_parse_token_string_t cmd_csum_tunnel_onoff = onoff, "on#off"); cmdline_parse_token_num_t cmd_csum_tunnel_portid = TOKEN_NUM_INITIALIZER(struct cmd_csum_tunnel_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_csum_tunnel = { .f = cmd_csum_tunnel_parsed, @@ -3654,7 +3819,7 @@ struct cmd_tso_set_result { cmdline_fixed_string_t tso; cmdline_fixed_string_t mode; uint16_t tso_segsz; - uint8_t port_id; + portid_t port_id; }; static void @@ -3697,7 +3862,7 @@ cmdline_parse_token_num_t cmd_tso_set_tso_segsz = tso_segsz, UINT16); cmdline_parse_token_num_t cmd_tso_set_portid = TOKEN_NUM_INITIALIZER(struct cmd_tso_set_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_tso_set = { .f = cmd_tso_set_parsed, @@ -3737,11 +3902,11 @@ struct cmd_tunnel_tso_set_result { cmdline_fixed_string_t tso; cmdline_fixed_string_t mode; uint16_t tso_segsz; - uint8_t port_id; + portid_t port_id; }; static void -check_tunnel_tso_nic_support(uint8_t port_id) +check_tunnel_tso_nic_support(portid_t port_id) { struct rte_eth_dev_info dev_info; @@ -3814,7 +3979,7 @@ cmdline_parse_token_num_t cmd_tunnel_tso_set_tso_segsz = tso_segsz, UINT16); cmdline_parse_token_num_t cmd_tunnel_tso_set_portid = TOKEN_NUM_INITIALIZER(struct cmd_tunnel_tso_set_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_tunnel_tso_set = { .f = cmd_tunnel_tso_set_parsed, @@ -3850,115 +4015,311 @@ cmdline_parse_inst_t cmd_tunnel_tso_show = { }; /* *** SET GRO FOR A PORT *** */ -struct cmd_gro_result { +struct cmd_gro_enable_result { + cmdline_fixed_string_t cmd_set; + cmdline_fixed_string_t cmd_port; cmdline_fixed_string_t cmd_keyword; - cmdline_fixed_string_t mode; - uint8_t port_id; + cmdline_fixed_string_t cmd_onoff; + portid_t cmd_pid; }; static void -cmd_enable_gro_parsed(void *parsed_result, +cmd_gro_enable_parsed(void *parsed_result, __attribute__((unused)) struct cmdline *cl, __attribute__((unused)) void *data) { - struct cmd_gro_result *res; + struct cmd_gro_enable_result *res; res = parsed_result; - setup_gro(res->mode, res->port_id); + if (!strcmp(res->cmd_keyword, "gro")) + setup_gro(res->cmd_onoff, res->cmd_pid); +} + +cmdline_parse_token_string_t cmd_gro_enable_set = + TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result, + cmd_set, "set"); +cmdline_parse_token_string_t cmd_gro_enable_port = + TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result, + cmd_keyword, "port"); +cmdline_parse_token_num_t cmd_gro_enable_pid = + TOKEN_NUM_INITIALIZER(struct cmd_gro_enable_result, + cmd_pid, UINT16); +cmdline_parse_token_string_t cmd_gro_enable_keyword = + TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result, + cmd_keyword, "gro"); +cmdline_parse_token_string_t cmd_gro_enable_onoff = + TOKEN_STRING_INITIALIZER(struct cmd_gro_enable_result, + cmd_onoff, "on#off"); + +cmdline_parse_inst_t cmd_gro_enable = { + .f = cmd_gro_enable_parsed, + .data = NULL, + .help_str = "set port <port_id> gro on|off", + .tokens = { + (void *)&cmd_gro_enable_set, + (void *)&cmd_gro_enable_port, + (void *)&cmd_gro_enable_pid, + (void *)&cmd_gro_enable_keyword, + (void *)&cmd_gro_enable_onoff, + NULL, + }, +}; + +/* *** DISPLAY GRO CONFIGURATION *** */ +struct cmd_gro_show_result { + cmdline_fixed_string_t cmd_show; + cmdline_fixed_string_t cmd_port; + cmdline_fixed_string_t cmd_keyword; + portid_t cmd_pid; +}; + +static void +cmd_gro_show_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_gro_show_result *res; + + res = parsed_result; + if (!strcmp(res->cmd_keyword, "gro")) + show_gro(res->cmd_pid); +} + +cmdline_parse_token_string_t cmd_gro_show_show = + TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result, + cmd_show, "show"); +cmdline_parse_token_string_t cmd_gro_show_port = + TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result, + cmd_port, "port"); +cmdline_parse_token_num_t cmd_gro_show_pid = + TOKEN_NUM_INITIALIZER(struct cmd_gro_show_result, + cmd_pid, UINT16); +cmdline_parse_token_string_t cmd_gro_show_keyword = + TOKEN_STRING_INITIALIZER(struct cmd_gro_show_result, + cmd_keyword, "gro"); + +cmdline_parse_inst_t cmd_gro_show = { + .f = cmd_gro_show_parsed, + .data = NULL, + .help_str = "show port <port_id> gro", + .tokens = { + (void *)&cmd_gro_show_show, + (void *)&cmd_gro_show_port, + (void *)&cmd_gro_show_pid, + (void *)&cmd_gro_show_keyword, + NULL, + }, +}; + +/* *** SET FLUSH CYCLES FOR GRO *** */ +struct cmd_gro_flush_result { + cmdline_fixed_string_t cmd_set; + cmdline_fixed_string_t cmd_keyword; + cmdline_fixed_string_t cmd_flush; + uint8_t cmd_cycles; +}; + +static void +cmd_gro_flush_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_gro_flush_result *res; + + res = parsed_result; + if ((!strcmp(res->cmd_keyword, "gro")) && + (!strcmp(res->cmd_flush, "flush"))) + setup_gro_flush_cycles(res->cmd_cycles); } -cmdline_parse_token_string_t cmd_gro_keyword = - TOKEN_STRING_INITIALIZER(struct cmd_gro_result, +cmdline_parse_token_string_t cmd_gro_flush_set = + TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result, + cmd_set, "set"); +cmdline_parse_token_string_t cmd_gro_flush_keyword = + TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result, cmd_keyword, "gro"); -cmdline_parse_token_string_t cmd_gro_mode = - TOKEN_STRING_INITIALIZER(struct cmd_gro_result, - mode, "on#off"); -cmdline_parse_token_num_t cmd_gro_pid = - TOKEN_NUM_INITIALIZER(struct cmd_gro_result, - port_id, UINT8); +cmdline_parse_token_string_t cmd_gro_flush_flush = + TOKEN_STRING_INITIALIZER(struct cmd_gro_flush_result, + cmd_flush, "flush"); +cmdline_parse_token_num_t cmd_gro_flush_cycles = + TOKEN_NUM_INITIALIZER(struct cmd_gro_flush_result, + cmd_cycles, UINT8); -cmdline_parse_inst_t cmd_enable_gro = { - .f = cmd_enable_gro_parsed, +cmdline_parse_inst_t cmd_gro_flush = { + .f = cmd_gro_flush_parsed, .data = NULL, - .help_str = "gro (on|off) (port_id)", + .help_str = "set gro flush <cycles>", .tokens = { - (void *)&cmd_gro_keyword, - (void *)&cmd_gro_mode, - (void *)&cmd_gro_pid, + (void *)&cmd_gro_flush_set, + (void *)&cmd_gro_flush_keyword, + (void *)&cmd_gro_flush_flush, + (void *)&cmd_gro_flush_cycles, NULL, }, }; -/* *** SET MAX FLOW NUMBER AND ITEM NUM PER FLOW FOR GRO *** */ -struct cmd_gro_set_result { - cmdline_fixed_string_t gro; - cmdline_fixed_string_t mode; - uint16_t flow_num; - uint16_t item_num_per_flow; - uint8_t port_id; +/* *** ENABLE/DISABLE GSO *** */ +struct cmd_gso_enable_result { + cmdline_fixed_string_t cmd_set; + cmdline_fixed_string_t cmd_port; + cmdline_fixed_string_t cmd_keyword; + cmdline_fixed_string_t cmd_mode; + portid_t cmd_pid; }; static void -cmd_gro_set_parsed(void *parsed_result, +cmd_gso_enable_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_gso_enable_result *res; + + res = parsed_result; + if (!strcmp(res->cmd_keyword, "gso")) + setup_gso(res->cmd_mode, res->cmd_pid); +} + +cmdline_parse_token_string_t cmd_gso_enable_set = + TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result, + cmd_set, "set"); +cmdline_parse_token_string_t cmd_gso_enable_port = + TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result, + cmd_port, "port"); +cmdline_parse_token_string_t cmd_gso_enable_keyword = + TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result, + cmd_keyword, "gso"); +cmdline_parse_token_string_t cmd_gso_enable_mode = + TOKEN_STRING_INITIALIZER(struct cmd_gso_enable_result, + cmd_mode, "on#off"); +cmdline_parse_token_num_t cmd_gso_enable_pid = + TOKEN_NUM_INITIALIZER(struct cmd_gso_enable_result, + cmd_pid, UINT16); + +cmdline_parse_inst_t cmd_gso_enable = { + .f = cmd_gso_enable_parsed, + .data = NULL, + .help_str = "set port <port_id> gso on|off", + .tokens = { + (void *)&cmd_gso_enable_set, + (void *)&cmd_gso_enable_port, + (void *)&cmd_gso_enable_pid, + (void *)&cmd_gso_enable_keyword, + (void *)&cmd_gso_enable_mode, + NULL, + }, +}; + +/* *** SET MAX PACKET LENGTH FOR GSO SEGMENTS *** */ +struct cmd_gso_size_result { + cmdline_fixed_string_t cmd_set; + cmdline_fixed_string_t cmd_keyword; + cmdline_fixed_string_t cmd_segsz; + uint16_t cmd_size; +}; + +static void +cmd_gso_size_parsed(void *parsed_result, __attribute__((unused)) struct cmdline *cl, __attribute__((unused)) void *data) { - struct cmd_gro_set_result *res = parsed_result; + struct cmd_gso_size_result *res = parsed_result; - if (port_id_is_invalid(res->port_id, ENABLED_WARN)) - return; if (test_done == 0) { - printf("Before set GRO flow_num and item_num_per_flow," - " please stop forwarding first\n"); + printf("Before setting GSO segsz, please first" + " stop fowarding\n"); return; } - if (!strcmp(res->mode, "set")) { - if (res->flow_num == 0) - printf("Invalid flow number. Revert to default value:" - " %u.\n", GRO_DEFAULT_FLOW_NUM); + if (!strcmp(res->cmd_keyword, "gso") && + !strcmp(res->cmd_segsz, "segsz")) { + if (res->cmd_size < RTE_GSO_SEG_SIZE_MIN) + printf("gso_size should be larger than %zu." + " Please input a legal value\n", + RTE_GSO_SEG_SIZE_MIN); else - gro_ports[res->port_id].param.max_flow_num = - res->flow_num; + gso_max_segment_size = res->cmd_size; + } +} - if (res->item_num_per_flow == 0) - printf("Invalid item number per-flow. Revert" - " to default value:%u.\n", - GRO_DEFAULT_ITEM_NUM_PER_FLOW); - else - gro_ports[res->port_id].param.max_item_per_flow = - res->item_num_per_flow; +cmdline_parse_token_string_t cmd_gso_size_set = + TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result, + cmd_set, "set"); +cmdline_parse_token_string_t cmd_gso_size_keyword = + TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result, + cmd_keyword, "gso"); +cmdline_parse_token_string_t cmd_gso_size_segsz = + TOKEN_STRING_INITIALIZER(struct cmd_gso_size_result, + cmd_segsz, "segsz"); +cmdline_parse_token_num_t cmd_gso_size_size = + TOKEN_NUM_INITIALIZER(struct cmd_gso_size_result, + cmd_size, UINT16); + +cmdline_parse_inst_t cmd_gso_size = { + .f = cmd_gso_size_parsed, + .data = NULL, + .help_str = "set gso segsz <length>", + .tokens = { + (void *)&cmd_gso_size_set, + (void *)&cmd_gso_size_keyword, + (void *)&cmd_gso_size_segsz, + (void *)&cmd_gso_size_size, + NULL, + }, +}; + +/* *** SHOW GSO CONFIGURATION *** */ +struct cmd_gso_show_result { + cmdline_fixed_string_t cmd_show; + cmdline_fixed_string_t cmd_port; + cmdline_fixed_string_t cmd_keyword; + portid_t cmd_pid; +}; + +static void +cmd_gso_show_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_gso_show_result *res = parsed_result; + + if (!rte_eth_dev_is_valid_port(res->cmd_pid)) { + printf("invalid port id %u\n", res->cmd_pid); + return; + } + if (!strcmp(res->cmd_keyword, "gso")) { + if (gso_ports[res->cmd_pid].enable) { + printf("Max GSO'd packet size: %uB\n" + "Supported GSO types: TCP/IPv4, " + "VxLAN with inner TCP/IPv4 packet, " + "GRE with inner TCP/IPv4 packet\n", + gso_max_segment_size); + } else + printf("GSO is not enabled on Port %u\n", res->cmd_pid); } } -cmdline_parse_token_string_t cmd_gro_set_gro = - TOKEN_STRING_INITIALIZER(struct cmd_gro_set_result, - gro, "gro"); -cmdline_parse_token_string_t cmd_gro_set_mode = - TOKEN_STRING_INITIALIZER(struct cmd_gro_set_result, - mode, "set"); -cmdline_parse_token_num_t cmd_gro_set_flow_num = - TOKEN_NUM_INITIALIZER(struct cmd_gro_set_result, - flow_num, UINT16); -cmdline_parse_token_num_t cmd_gro_set_item_num_per_flow = - TOKEN_NUM_INITIALIZER(struct cmd_gro_set_result, - item_num_per_flow, UINT16); -cmdline_parse_token_num_t cmd_gro_set_portid = - TOKEN_NUM_INITIALIZER(struct cmd_gro_set_result, - port_id, UINT8); +cmdline_parse_token_string_t cmd_gso_show_show = +TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result, + cmd_show, "show"); +cmdline_parse_token_string_t cmd_gso_show_port = +TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result, + cmd_port, "port"); +cmdline_parse_token_string_t cmd_gso_show_keyword = + TOKEN_STRING_INITIALIZER(struct cmd_gso_show_result, + cmd_keyword, "gso"); +cmdline_parse_token_num_t cmd_gso_show_pid = + TOKEN_NUM_INITIALIZER(struct cmd_gso_show_result, + cmd_pid, UINT16); -cmdline_parse_inst_t cmd_gro_set = { - .f = cmd_gro_set_parsed, +cmdline_parse_inst_t cmd_gso_show = { + .f = cmd_gso_show_parsed, .data = NULL, - .help_str = "gro set <max_flow_num> <max_item_num_per_flow> " - "<port_id>: set max flow number and max packet number per-flow " - "for GRO", + .help_str = "show port <port_id> gso", .tokens = { - (void *)&cmd_gro_set_gro, - (void *)&cmd_gro_set_mode, - (void *)&cmd_gro_set_flow_num, - (void *)&cmd_gro_set_item_num_per_flow, - (void *)&cmd_gro_set_portid, + (void *)&cmd_gso_show_show, + (void *)&cmd_gso_show_port, + (void *)&cmd_gso_show_pid, + (void *)&cmd_gso_show_keyword, NULL, }, }; @@ -4048,7 +4409,7 @@ struct cmd_set_bypass_mode_result { cmdline_fixed_string_t bypass; cmdline_fixed_string_t mode; cmdline_fixed_string_t value; - uint8_t port_id; + portid_t port_id; }; static void @@ -4091,7 +4452,7 @@ cmdline_parse_token_string_t cmd_setbypass_mode_value = value, "normal#bypass#isolate"); cmdline_parse_token_num_t cmd_setbypass_mode_port = TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_set_bypass_mode = { .f = cmd_set_bypass_mode_parsed, @@ -4116,7 +4477,7 @@ struct cmd_set_bypass_event_result { cmdline_fixed_string_t event_value; cmdline_fixed_string_t mode; cmdline_fixed_string_t mode_value; - uint8_t port_id; + portid_t port_id; }; static void @@ -4197,7 +4558,7 @@ cmdline_parse_token_string_t cmd_setbypass_event_mode_value = mode_value, "normal#bypass#isolate"); cmdline_parse_token_num_t cmd_setbypass_event_port = TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_set_bypass_event = { .f = cmd_set_bypass_event_parsed, @@ -4285,7 +4646,7 @@ struct cmd_show_bypass_config_result { cmdline_fixed_string_t show; cmdline_fixed_string_t bypass; cmdline_fixed_string_t config; - uint8_t port_id; + portid_t port_id; }; static void @@ -4364,7 +4725,7 @@ cmdline_parse_token_string_t cmd_showbypass_config_config = config, "config"); cmdline_parse_token_num_t cmd_showbypass_config_port = TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_show_bypass_config = { .f = cmd_show_bypass_config_parsed, @@ -4387,7 +4748,7 @@ struct cmd_set_bonding_mode_result { cmdline_fixed_string_t bonding; cmdline_fixed_string_t mode; uint8_t value; - uint8_t port_id; + portid_t port_id; }; static void cmd_set_bonding_mode_parsed(void *parsed_result, @@ -4416,7 +4777,7 @@ TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result, value, UINT8); cmdline_parse_token_num_t cmd_setbonding_mode_port = TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_set_bonding_mode = { .f = cmd_set_bonding_mode_parsed, @@ -4439,7 +4800,7 @@ struct cmd_set_bonding_lacp_dedicated_queues_result { cmdline_fixed_string_t bonding; cmdline_fixed_string_t lacp; cmdline_fixed_string_t dedicated_queues; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t mode; }; @@ -4490,7 +4851,7 @@ TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, dedicated_queues, "dedicated_queues"); cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id = TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode = TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, mode, "enable#disable"); @@ -4517,7 +4878,7 @@ struct cmd_set_bonding_balance_xmit_policy_result { cmdline_fixed_string_t set; cmdline_fixed_string_t bonding; cmdline_fixed_string_t balance_xmit_policy; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t policy; }; @@ -4558,7 +4919,7 @@ TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, balance_xmit_policy, "balance_xmit_policy"); cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port = TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy = TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, policy, "l2#l23#l34"); @@ -4584,7 +4945,7 @@ struct cmd_show_bonding_config_result { cmdline_fixed_string_t show; cmdline_fixed_string_t bonding; cmdline_fixed_string_t config; - uint8_t port_id; + portid_t port_id; }; static void cmd_show_bonding_config_parsed(void *parsed_result, @@ -4593,7 +4954,7 @@ static void cmd_show_bonding_config_parsed(void *parsed_result, { struct cmd_show_bonding_config_result *res = parsed_result; int bonding_mode, agg_mode; - uint8_t slaves[RTE_MAX_ETHPORTS]; + portid_t slaves[RTE_MAX_ETHPORTS]; int num_slaves, num_active_slaves; int primary_id; int i; @@ -4706,7 +5067,7 @@ TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, config, "config"); cmdline_parse_token_num_t cmd_showbonding_config_port = TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_show_bonding_config = { .f = cmd_show_bonding_config_parsed, @@ -4727,8 +5088,8 @@ struct cmd_set_bonding_primary_result { cmdline_fixed_string_t set; cmdline_fixed_string_t bonding; cmdline_fixed_string_t primary; - uint8_t slave_id; - uint8_t port_id; + portid_t slave_id; + portid_t port_id; }; static void cmd_set_bonding_primary_parsed(void *parsed_result, @@ -4759,10 +5120,10 @@ TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, primary, "primary"); cmdline_parse_token_num_t cmd_setbonding_primary_slave = TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result, - slave_id, UINT8); + slave_id, UINT16); cmdline_parse_token_num_t cmd_setbonding_primary_port = TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_set_bonding_primary = { .f = cmd_set_bonding_primary_parsed, @@ -4784,8 +5145,8 @@ struct cmd_add_bonding_slave_result { cmdline_fixed_string_t add; cmdline_fixed_string_t bonding; cmdline_fixed_string_t slave; - uint8_t slave_id; - uint8_t port_id; + portid_t slave_id; + portid_t port_id; }; static void cmd_add_bonding_slave_parsed(void *parsed_result, @@ -4817,10 +5178,10 @@ TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, slave, "slave"); cmdline_parse_token_num_t cmd_addbonding_slave_slaveid = TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result, - slave_id, UINT8); + slave_id, UINT16); cmdline_parse_token_num_t cmd_addbonding_slave_port = TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_add_bonding_slave = { .f = cmd_add_bonding_slave_parsed, @@ -4842,8 +5203,8 @@ struct cmd_remove_bonding_slave_result { cmdline_fixed_string_t remove; cmdline_fixed_string_t bonding; cmdline_fixed_string_t slave; - uint8_t slave_id; - uint8_t port_id; + portid_t slave_id; + portid_t port_id; }; static void cmd_remove_bonding_slave_parsed(void *parsed_result, @@ -4875,10 +5236,10 @@ cmdline_parse_token_string_t cmd_removebonding_slave_slave = slave, "slave"); cmdline_parse_token_num_t cmd_removebonding_slave_slaveid = TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result, - slave_id, UINT8); + slave_id, UINT16); cmdline_parse_token_num_t cmd_removebonding_slave_port = TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_remove_bonding_slave = { .f = cmd_remove_bonding_slave_parsed, @@ -4975,7 +5336,7 @@ struct cmd_set_bond_mac_addr_result { cmdline_fixed_string_t set; cmdline_fixed_string_t bonding; cmdline_fixed_string_t mac_addr; - uint8_t port_num; + uint16_t port_num; struct ether_addr address; }; @@ -5005,7 +5366,8 @@ cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac = TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr, "mac_addr"); cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum = - TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, port_num, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, + port_num, UINT16); cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr = TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address); @@ -5029,7 +5391,7 @@ struct cmd_set_bond_mon_period_result { cmdline_fixed_string_t set; cmdline_fixed_string_t bonding; cmdline_fixed_string_t mon_period; - uint8_t port_num; + uint16_t port_num; uint32_t period_ms; }; @@ -5063,7 +5425,7 @@ cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period = mon_period, "mon_period"); cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum = TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result, - port_num, UINT8); + port_num, UINT16); cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms = TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result, period_ms, UINT32); @@ -5088,7 +5450,7 @@ struct cmd_set_bonding_agg_mode_policy_result { cmdline_fixed_string_t set; cmdline_fixed_string_t bonding; cmdline_fixed_string_t agg_mode; - uint8_t port_num; + uint16_t port_num; cmdline_fixed_string_t policy; }; @@ -5131,7 +5493,7 @@ cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode = cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum = TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, - port_num, UINT8); + port_num, UINT16); cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string = TOKEN_STRING_INITIALIZER( @@ -5345,7 +5707,7 @@ struct cmd_set_promisc_mode_result { cmdline_fixed_string_t set; cmdline_fixed_string_t promisc; cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ - uint8_t port_num; /* valid if "allports" argument == 0 */ + uint16_t port_num; /* valid if "allports" argument == 0 */ cmdline_fixed_string_t mode; }; @@ -5425,7 +5787,7 @@ struct cmd_set_allmulti_mode_result { cmdline_fixed_string_t set; cmdline_fixed_string_t allmulti; cmdline_fixed_string_t port_all; /* valid if "allports" argument == 1 */ - uint8_t port_num; /* valid if "allports" argument == 0 */ + uint16_t port_num; /* valid if "allports" argument == 0 */ cmdline_fixed_string_t mode; }; @@ -5469,7 +5831,7 @@ cmdline_parse_token_string_t cmd_setallmulti_portall = "all"); cmdline_parse_token_num_t cmd_setallmulti_portnum = TOKEN_NUM_INITIALIZER(struct cmd_set_allmulti_mode_result, port_num, - UINT8); + UINT16); cmdline_parse_token_string_t cmd_setallmulti_mode = TOKEN_STRING_INITIALIZER(struct cmd_set_allmulti_mode_result, mode, "on#off"); @@ -5521,7 +5883,7 @@ struct cmd_link_flow_ctrl_set_result { uint16_t pause_time; cmdline_fixed_string_t xon_str; uint16_t send_xon; - uint8_t port_id; + portid_t port_id; }; cmdline_parse_token_string_t cmd_lfc_set_set = @@ -5580,7 +5942,7 @@ cmdline_parse_token_string_t cmd_lfc_set_autoneg = autoneg, "on#off"); cmdline_parse_token_num_t cmd_lfc_set_portid = TOKEN_NUM_INITIALIZER(struct cmd_link_flow_ctrl_set_result, - port_id, UINT8); + port_id, UINT16); /* forward declaration */ static void @@ -5819,7 +6181,7 @@ struct cmd_priority_flow_ctrl_set_result { uint32_t low_water; uint16_t pause_time; uint8_t priority; - uint8_t port_id; + portid_t port_id; }; static void @@ -5887,7 +6249,7 @@ cmdline_parse_token_num_t cmd_pfc_set_priority = priority, UINT8); cmdline_parse_token_num_t cmd_pfc_set_portid = TOKEN_NUM_INITIALIZER(struct cmd_priority_flow_ctrl_set_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_priority_flow_control_set = { .f = cmd_priority_flow_ctrl_set_parsed, @@ -6045,7 +6407,7 @@ struct cmd_set_link_up_result { cmdline_fixed_string_t set; cmdline_fixed_string_t link_up; cmdline_fixed_string_t port; - uint8_t port_id; + portid_t port_id; }; cmdline_parse_token_string_t cmd_set_link_up_set = @@ -6056,7 +6418,7 @@ cmdline_parse_token_string_t cmd_set_link_up_link_up = cmdline_parse_token_string_t cmd_set_link_up_port = TOKEN_STRING_INITIALIZER(struct cmd_set_link_up_result, port, "port"); cmdline_parse_token_num_t cmd_set_link_up_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_set_link_up_result, port_id, UINT16); static void cmd_set_link_up_parsed(__attribute__((unused)) void *parsed_result, __attribute__((unused)) struct cmdline *cl, @@ -6084,7 +6446,7 @@ struct cmd_set_link_down_result { cmdline_fixed_string_t set; cmdline_fixed_string_t link_down; cmdline_fixed_string_t port; - uint8_t port_id; + portid_t port_id; }; cmdline_parse_token_string_t cmd_set_link_down_set = @@ -6095,7 +6457,7 @@ cmdline_parse_token_string_t cmd_set_link_down_link_down = cmdline_parse_token_string_t cmd_set_link_down_port = TOKEN_STRING_INITIALIZER(struct cmd_set_link_down_result, port, "port"); cmdline_parse_token_num_t cmd_set_link_down_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_set_link_down_result, port_id, UINT16); static void cmd_set_link_down_parsed( __attribute__((unused)) void *parsed_result, @@ -6235,7 +6597,7 @@ struct cmd_showport_result { cmdline_fixed_string_t show; cmdline_fixed_string_t port; cmdline_fixed_string_t what; - uint8_t portnum; + uint16_t portnum; }; static void cmd_showport_parsed(void *parsed_result, @@ -6273,7 +6635,7 @@ cmdline_parse_token_string_t cmd_showport_what = TOKEN_STRING_INITIALIZER(struct cmd_showport_result, what, "info#stats#xstats#fdir#stat_qmap#dcb_tc#cap"); cmdline_parse_token_num_t cmd_showport_portnum = - TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_showport_result, portnum, UINT16); cmdline_parse_inst_t cmd_showport = { .f = cmd_showport_parsed, @@ -6295,7 +6657,7 @@ struct cmd_showqueue_result { cmdline_fixed_string_t show; cmdline_fixed_string_t type; cmdline_fixed_string_t what; - uint8_t portnum; + uint16_t portnum; uint16_t queuenum; }; @@ -6319,7 +6681,7 @@ cmdline_parse_token_string_t cmd_showqueue_type = cmdline_parse_token_string_t cmd_showqueue_what = TOKEN_STRING_INITIALIZER(struct cmd_showqueue_result, what, "info"); cmdline_parse_token_num_t cmd_showqueue_portnum = - TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, portnum, UINT16); cmdline_parse_token_num_t cmd_showqueue_queuenum = TOKEN_NUM_INITIALIZER(struct cmd_showqueue_result, queuenum, UINT16); @@ -6341,7 +6703,7 @@ cmdline_parse_inst_t cmd_showqueue = { struct cmd_read_reg_result { cmdline_fixed_string_t read; cmdline_fixed_string_t reg; - uint8_t port_id; + portid_t port_id; uint32_t reg_off; }; @@ -6359,7 +6721,7 @@ cmdline_parse_token_string_t cmd_read_reg_read = cmdline_parse_token_string_t cmd_read_reg_reg = TOKEN_STRING_INITIALIZER(struct cmd_read_reg_result, reg, "reg"); cmdline_parse_token_num_t cmd_read_reg_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, port_id, UINT16); cmdline_parse_token_num_t cmd_read_reg_reg_off = TOKEN_NUM_INITIALIZER(struct cmd_read_reg_result, reg_off, UINT32); @@ -6380,7 +6742,7 @@ cmdline_parse_inst_t cmd_read_reg = { struct cmd_read_reg_bit_field_result { cmdline_fixed_string_t read; cmdline_fixed_string_t regfield; - uint8_t port_id; + portid_t port_id; uint32_t reg_off; uint8_t bit1_pos; uint8_t bit2_pos; @@ -6404,7 +6766,7 @@ cmdline_parse_token_string_t cmd_read_reg_bit_field_regfield = regfield, "regfield"); cmdline_parse_token_num_t cmd_read_reg_bit_field_port_id = TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, port_id, - UINT8); + UINT16); cmdline_parse_token_num_t cmd_read_reg_bit_field_reg_off = TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_field_result, reg_off, UINT32); @@ -6435,7 +6797,7 @@ cmdline_parse_inst_t cmd_read_reg_bit_field = { struct cmd_read_reg_bit_result { cmdline_fixed_string_t read; cmdline_fixed_string_t regbit; - uint8_t port_id; + portid_t port_id; uint32_t reg_off; uint8_t bit_pos; }; @@ -6455,7 +6817,7 @@ cmdline_parse_token_string_t cmd_read_reg_bit_regbit = TOKEN_STRING_INITIALIZER(struct cmd_read_reg_bit_result, regbit, "regbit"); cmdline_parse_token_num_t cmd_read_reg_bit_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, port_id, UINT16); cmdline_parse_token_num_t cmd_read_reg_bit_reg_off = TOKEN_NUM_INITIALIZER(struct cmd_read_reg_bit_result, reg_off, UINT32); cmdline_parse_token_num_t cmd_read_reg_bit_bit_pos = @@ -6479,7 +6841,7 @@ cmdline_parse_inst_t cmd_read_reg_bit = { struct cmd_write_reg_result { cmdline_fixed_string_t write; cmdline_fixed_string_t reg; - uint8_t port_id; + portid_t port_id; uint32_t reg_off; uint32_t value; }; @@ -6498,7 +6860,7 @@ cmdline_parse_token_string_t cmd_write_reg_write = cmdline_parse_token_string_t cmd_write_reg_reg = TOKEN_STRING_INITIALIZER(struct cmd_write_reg_result, reg, "reg"); cmdline_parse_token_num_t cmd_write_reg_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, port_id, UINT16); cmdline_parse_token_num_t cmd_write_reg_reg_off = TOKEN_NUM_INITIALIZER(struct cmd_write_reg_result, reg_off, UINT32); cmdline_parse_token_num_t cmd_write_reg_value = @@ -6522,7 +6884,7 @@ cmdline_parse_inst_t cmd_write_reg = { struct cmd_write_reg_bit_field_result { cmdline_fixed_string_t write; cmdline_fixed_string_t regfield; - uint8_t port_id; + portid_t port_id; uint32_t reg_off; uint8_t bit1_pos; uint8_t bit2_pos; @@ -6547,7 +6909,7 @@ cmdline_parse_token_string_t cmd_write_reg_bit_field_regfield = regfield, "regfield"); cmdline_parse_token_num_t cmd_write_reg_bit_field_port_id = TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, port_id, - UINT8); + UINT16); cmdline_parse_token_num_t cmd_write_reg_bit_field_reg_off = TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_field_result, reg_off, UINT32); @@ -6583,7 +6945,7 @@ cmdline_parse_inst_t cmd_write_reg_bit_field = { struct cmd_write_reg_bit_result { cmdline_fixed_string_t write; cmdline_fixed_string_t regbit; - uint8_t port_id; + portid_t port_id; uint32_t reg_off; uint8_t bit_pos; uint8_t value; @@ -6605,7 +6967,7 @@ cmdline_parse_token_string_t cmd_write_reg_bit_regbit = TOKEN_STRING_INITIALIZER(struct cmd_write_reg_bit_result, regbit, "regbit"); cmdline_parse_token_num_t cmd_write_reg_bit_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, port_id, UINT16); cmdline_parse_token_num_t cmd_write_reg_bit_reg_off = TOKEN_NUM_INITIALIZER(struct cmd_write_reg_bit_result, reg_off, UINT32); cmdline_parse_token_num_t cmd_write_reg_bit_bit_pos = @@ -6633,7 +6995,7 @@ cmdline_parse_inst_t cmd_write_reg_bit = { struct cmd_read_rxd_txd_result { cmdline_fixed_string_t read; cmdline_fixed_string_t rxd_txd; - uint8_t port_id; + portid_t port_id; uint16_t queue_id; uint16_t desc_id; }; @@ -6657,7 +7019,7 @@ cmdline_parse_token_string_t cmd_read_rxd_txd_rxd_txd = TOKEN_STRING_INITIALIZER(struct cmd_read_rxd_txd_result, rxd_txd, "rxd#txd"); cmdline_parse_token_num_t cmd_read_rxd_txd_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, port_id, UINT16); cmdline_parse_token_num_t cmd_read_rxd_txd_queue_id = TOKEN_NUM_INITIALIZER(struct cmd_read_rxd_txd_result, queue_id, UINT16); cmdline_parse_token_num_t cmd_read_rxd_txd_desc_id = @@ -6707,7 +7069,7 @@ cmdline_parse_inst_t cmd_quit = { struct cmd_mac_addr_result { cmdline_fixed_string_t mac_addr_cmd; cmdline_fixed_string_t what; - uint8_t port_num; + uint16_t port_num; struct ether_addr address; }; @@ -6739,7 +7101,8 @@ cmdline_parse_token_string_t cmd_mac_addr_what = TOKEN_STRING_INITIALIZER(struct cmd_mac_addr_result, what, "add#remove#set"); cmdline_parse_token_num_t cmd_mac_addr_portnum = - TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_mac_addr_result, port_num, + UINT16); cmdline_parse_token_etheraddr_t cmd_mac_addr_addr = TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address); @@ -6763,7 +7126,7 @@ struct cmd_set_qmap_result { cmdline_fixed_string_t set; cmdline_fixed_string_t qmap; cmdline_fixed_string_t what; - uint8_t port_id; + portid_t port_id; uint16_t queue_id; uint8_t map_value; }; @@ -6790,7 +7153,7 @@ cmdline_parse_token_string_t cmd_setqmap_what = what, "tx#rx"); cmdline_parse_token_num_t cmd_setqmap_portid = TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_setqmap_queueid = TOKEN_NUM_INITIALIZER(struct cmd_set_qmap_result, queue_id, UINT16); @@ -6814,11 +7177,53 @@ cmdline_parse_inst_t cmd_set_qmap = { }, }; +/* *** SET OPTION TO HIDE ZERO VALUES FOR XSTATS DISPLAY *** */ +struct cmd_set_xstats_hide_zero_result { + cmdline_fixed_string_t keyword; + cmdline_fixed_string_t name; + cmdline_fixed_string_t on_off; +}; + +static void +cmd_set_xstats_hide_zero_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_set_xstats_hide_zero_result *res; + uint16_t on_off = 0; + + res = parsed_result; + on_off = !strcmp(res->on_off, "on") ? 1 : 0; + set_xstats_hide_zero(on_off); +} + +cmdline_parse_token_string_t cmd_set_xstats_hide_zero_keyword = + TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result, + keyword, "set"); +cmdline_parse_token_string_t cmd_set_xstats_hide_zero_name = + TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result, + name, "xstats-hide-zero"); +cmdline_parse_token_string_t cmd_set_xstats_hide_zero_on_off = + TOKEN_STRING_INITIALIZER(struct cmd_set_xstats_hide_zero_result, + on_off, "on#off"); + +cmdline_parse_inst_t cmd_set_xstats_hide_zero = { + .f = cmd_set_xstats_hide_zero_parsed, + .data = NULL, + .help_str = "set xstats-hide-zero on|off", + .tokens = { + (void *)&cmd_set_xstats_hide_zero_keyword, + (void *)&cmd_set_xstats_hide_zero_name, + (void *)&cmd_set_xstats_hide_zero_on_off, + NULL, + }, +}; + /* *** CONFIGURE UNICAST HASH TABLE *** */ struct cmd_set_uc_hash_table { cmdline_fixed_string_t set; cmdline_fixed_string_t port; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t what; struct ether_addr address; cmdline_fixed_string_t mode; @@ -6850,7 +7255,7 @@ cmdline_parse_token_string_t cmd_set_uc_hash_port = port, "port"); cmdline_parse_token_num_t cmd_set_uc_hash_portid = TOKEN_NUM_INITIALIZER(struct cmd_set_uc_hash_table, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_set_uc_hash_what = TOKEN_STRING_INITIALIZER(struct cmd_set_uc_hash_table, what, "uta"); @@ -6879,7 +7284,7 @@ cmdline_parse_inst_t cmd_set_uc_hash_filter = { struct cmd_set_uc_all_hash_table { cmdline_fixed_string_t set; cmdline_fixed_string_t port; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t what; cmdline_fixed_string_t value; cmdline_fixed_string_t mode; @@ -6911,7 +7316,7 @@ cmdline_parse_token_string_t cmd_set_uc_all_hash_port = port, "port"); cmdline_parse_token_num_t cmd_set_uc_all_hash_portid = TOKEN_NUM_INITIALIZER(struct cmd_set_uc_all_hash_table, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_set_uc_all_hash_what = TOKEN_STRING_INITIALIZER(struct cmd_set_uc_all_hash_table, what, "uta"); @@ -6941,7 +7346,7 @@ cmdline_parse_inst_t cmd_set_uc_all_hash_filter = { struct cmd_set_vf_macvlan_filter { cmdline_fixed_string_t set; cmdline_fixed_string_t port; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t vf; uint8_t vf_id; struct ether_addr address; @@ -6960,7 +7365,7 @@ cmd_set_vf_macvlan_parsed(void *parsed_result, memset(&filter, 0, sizeof(struct rte_eth_mac_filter)); - (void)rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN); + rte_memcpy(&filter.mac_addr, &res->address, ETHER_ADDR_LEN); /* set VF MAC filter */ filter.is_vf = 1; @@ -7003,7 +7408,7 @@ cmdline_parse_token_string_t cmd_set_vf_macvlan_port = port, "port"); cmdline_parse_token_num_t cmd_set_vf_macvlan_portid = TOKEN_NUM_INITIALIZER(struct cmd_set_vf_macvlan_filter, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_set_vf_macvlan_vf = TOKEN_STRING_INITIALIZER(struct cmd_set_vf_macvlan_filter, vf, "vf"); @@ -7045,7 +7450,7 @@ cmdline_parse_inst_t cmd_set_vf_macvlan_filter = { struct cmd_set_vf_traffic { cmdline_fixed_string_t set; cmdline_fixed_string_t port; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t vf; uint8_t vf_id; cmdline_fixed_string_t what; @@ -7072,7 +7477,7 @@ cmdline_parse_token_string_t cmd_setvf_traffic_port = port, "port"); cmdline_parse_token_num_t cmd_setvf_traffic_portid = TOKEN_NUM_INITIALIZER(struct cmd_set_vf_traffic, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_setvf_traffic_vf = TOKEN_STRING_INITIALIZER(struct cmd_set_vf_traffic, vf, "vf"); @@ -7106,7 +7511,7 @@ cmdline_parse_inst_t cmd_set_vf_traffic = { struct cmd_set_vf_rxmode { cmdline_fixed_string_t set; cmdline_fixed_string_t port; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t vf; uint8_t vf_id; cmdline_fixed_string_t what; @@ -7135,6 +7540,8 @@ cmd_set_vf_rxmode_parsed(void *parsed_result, rx_mode |= ETH_VMDQ_ACCEPT_MULTICAST; } + RTE_SET_USED(is_on); + #ifdef RTE_LIBRTE_IXGBE_PMD if (ret == -ENOTSUP) ret = rte_pmd_ixgbe_set_vf_rxmode(res->port_id, res->vf_id, @@ -7158,7 +7565,7 @@ cmdline_parse_token_string_t cmd_set_vf_rxmode_port = port, "port"); cmdline_parse_token_num_t cmd_set_vf_rxmode_portid = TOKEN_NUM_INITIALIZER(struct cmd_set_vf_rxmode, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_set_vf_rxmode_vf = TOKEN_STRING_INITIALIZER(struct cmd_set_vf_rxmode, vf, "vf"); @@ -7198,7 +7605,7 @@ struct cmd_vf_mac_addr_result { cmdline_fixed_string_t mac_addr_cmd; cmdline_fixed_string_t what; cmdline_fixed_string_t port; - uint8_t port_num; + uint16_t port_num; cmdline_fixed_string_t vf; uint8_t vf_num; struct ether_addr address; @@ -7209,11 +7616,22 @@ static void cmd_vf_mac_addr_parsed(void *parsed_result, __attribute__((unused)) void *data) { struct cmd_vf_mac_addr_result *res = parsed_result; - int ret = 0; + int ret = -ENOTSUP; + + if (strcmp(res->what, "add") != 0) + return; + +#ifdef RTE_LIBRTE_I40E_PMD + if (ret == -ENOTSUP) + ret = rte_pmd_i40e_add_vf_mac_addr(res->port_num, res->vf_num, + &res->address); +#endif +#ifdef RTE_LIBRTE_BNXT_PMD + if (ret == -ENOTSUP) + ret = rte_pmd_bnxt_mac_addr_add(res->port_num, &res->address, + res->vf_num); +#endif - if (strcmp(res->what, "add") == 0) - ret = rte_eth_dev_mac_addr_add(res->port_num, - &res->address, res->vf_num); if(ret < 0) printf("vf_mac_addr_cmd error: (%s)\n", strerror(-ret)); @@ -7230,7 +7648,7 @@ cmdline_parse_token_string_t cmd_vf_mac_addr_port = port,"port"); cmdline_parse_token_num_t cmd_vf_mac_addr_portnum = TOKEN_NUM_INITIALIZER(struct cmd_vf_mac_addr_result, - port_num, UINT8); + port_num, UINT16); cmdline_parse_token_string_t cmd_vf_mac_addr_vf = TOKEN_STRING_INITIALIZER(struct cmd_vf_mac_addr_result, vf,"vf"); @@ -7264,7 +7682,7 @@ struct cmd_vf_rx_vlan_filter { cmdline_fixed_string_t what; uint16_t vlan_id; cmdline_fixed_string_t port; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t vf; uint64_t vf_mask; }; @@ -7327,7 +7745,7 @@ cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_port = port, "port"); cmdline_parse_token_num_t cmd_vf_rx_vlan_filter_portid = TOKEN_NUM_INITIALIZER(struct cmd_vf_rx_vlan_filter, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_vf_rx_vlan_filter_vf = TOKEN_STRING_INITIALIZER(struct cmd_vf_rx_vlan_filter, vf, "vf"); @@ -7356,7 +7774,7 @@ cmdline_parse_inst_t cmd_vf_rxvlan_filter = { struct cmd_queue_rate_limit_result { cmdline_fixed_string_t set; cmdline_fixed_string_t port; - uint8_t port_num; + uint16_t port_num; cmdline_fixed_string_t queue; uint8_t queue_num; cmdline_fixed_string_t rate; @@ -7388,7 +7806,7 @@ cmdline_parse_token_string_t cmd_queue_rate_limit_port = port, "port"); cmdline_parse_token_num_t cmd_queue_rate_limit_portnum = TOKEN_NUM_INITIALIZER(struct cmd_queue_rate_limit_result, - port_num, UINT8); + port_num, UINT16); cmdline_parse_token_string_t cmd_queue_rate_limit_queue = TOKEN_STRING_INITIALIZER(struct cmd_queue_rate_limit_result, queue, "queue"); @@ -7423,7 +7841,7 @@ cmdline_parse_inst_t cmd_queue_rate_limit = { struct cmd_vf_rate_limit_result { cmdline_fixed_string_t set; cmdline_fixed_string_t port; - uint8_t port_num; + uint16_t port_num; cmdline_fixed_string_t vf; uint8_t vf_num; cmdline_fixed_string_t rate; @@ -7458,7 +7876,7 @@ cmdline_parse_token_string_t cmd_vf_rate_limit_port = port, "port"); cmdline_parse_token_num_t cmd_vf_rate_limit_portnum = TOKEN_NUM_INITIALIZER(struct cmd_vf_rate_limit_result, - port_num, UINT8); + port_num, UINT16); cmdline_parse_token_string_t cmd_vf_rate_limit_vf = TOKEN_STRING_INITIALIZER(struct cmd_vf_rate_limit_result, vf, "vf"); @@ -7502,7 +7920,7 @@ cmdline_parse_inst_t cmd_vf_rate_limit = { struct cmd_tunnel_filter_result { cmdline_fixed_string_t cmd; cmdline_fixed_string_t what; - uint8_t port_id; + portid_t port_id; struct ether_addr outer_mac; struct ether_addr inner_mac; cmdline_ipaddr_t ip_value; @@ -7596,7 +8014,7 @@ cmdline_parse_token_string_t cmd_tunnel_filter_what = what, "add#rm"); cmdline_parse_token_num_t cmd_tunnel_filter_port_id = TOKEN_NUM_INITIALIZER(struct cmd_tunnel_filter_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_etheraddr_t cmd_tunnel_filter_outer_mac = TOKEN_ETHERADDR_INITIALIZER(struct cmd_tunnel_filter_result, outer_mac); @@ -7652,7 +8070,7 @@ struct cmd_tunnel_udp_config { cmdline_fixed_string_t cmd; cmdline_fixed_string_t what; uint16_t udp_port; - uint8_t port_id; + portid_t port_id; }; static void @@ -7691,7 +8109,7 @@ cmdline_parse_token_num_t cmd_tunnel_udp_config_udp_port = udp_port, UINT16); cmdline_parse_token_num_t cmd_tunnel_udp_config_port_id = TOKEN_NUM_INITIALIZER(struct cmd_tunnel_udp_config, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_tunnel_udp_config = { .f = cmd_tunnel_udp_config_parsed, @@ -7710,7 +8128,7 @@ cmdline_parse_inst_t cmd_tunnel_udp_config = { /* *** GLOBAL CONFIG *** */ struct cmd_global_config_result { cmdline_fixed_string_t cmd; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t cfg_type; uint8_t len; }; @@ -7737,7 +8155,8 @@ cmdline_parse_token_string_t cmd_global_config_cmd = TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cmd, "global_config"); cmdline_parse_token_num_t cmd_global_config_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_global_config_result, port_id, + UINT16); cmdline_parse_token_string_t cmd_global_config_type = TOKEN_STRING_INITIALIZER(struct cmd_global_config_result, cfg_type, "gre-key-len"); @@ -7762,7 +8181,7 @@ cmdline_parse_inst_t cmd_global_config = { struct cmd_set_mirror_mask_result { cmdline_fixed_string_t set; cmdline_fixed_string_t port; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t mirror; uint8_t rule_id; cmdline_fixed_string_t what; @@ -7780,7 +8199,7 @@ cmdline_parse_token_string_t cmd_mirror_mask_port = port, "port"); cmdline_parse_token_num_t cmd_mirror_mask_portid = TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_mask_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_mirror_mask_mirror = TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_mask_result, mirror, "mirror-rule"); @@ -7878,7 +8297,7 @@ cmdline_parse_inst_t cmd_set_mirror_mask = { struct cmd_set_mirror_link_result { cmdline_fixed_string_t set; cmdline_fixed_string_t port; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t mirror; uint8_t rule_id; cmdline_fixed_string_t what; @@ -7895,7 +8314,7 @@ cmdline_parse_token_string_t cmd_mirror_link_port = port, "port"); cmdline_parse_token_num_t cmd_mirror_link_portid = TOKEN_NUM_INITIALIZER(struct cmd_set_mirror_link_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_mirror_link_mirror = TOKEN_STRING_INITIALIZER(struct cmd_set_mirror_link_result, mirror, "mirror-rule"); @@ -7968,7 +8387,7 @@ cmdline_parse_inst_t cmd_set_mirror_link = { struct cmd_rm_mirror_rule_result { cmdline_fixed_string_t reset; cmdline_fixed_string_t port; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t mirror; uint8_t rule_id; }; @@ -7981,7 +8400,7 @@ cmdline_parse_token_string_t cmd_rm_mirror_rule_port = port, "port"); cmdline_parse_token_num_t cmd_rm_mirror_rule_portid = TOKEN_NUM_INITIALIZER(struct cmd_rm_mirror_rule_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_rm_mirror_rule_mirror = TOKEN_STRING_INITIALIZER(struct cmd_rm_mirror_rule_result, mirror, "mirror-rule"); @@ -8126,7 +8545,7 @@ cmdline_parse_inst_t cmd_dump_one = { /* *** Add/Del syn filter *** */ struct cmd_syn_filter_result { cmdline_fixed_string_t filter; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t ops; cmdline_fixed_string_t priority; cmdline_fixed_string_t high; @@ -8180,7 +8599,7 @@ cmdline_parse_token_string_t cmd_syn_filter_filter = filter, "syn_filter"); cmdline_parse_token_num_t cmd_syn_filter_port_id = TOKEN_NUM_INITIALIZER(struct cmd_syn_filter_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_syn_filter_ops = TOKEN_STRING_INITIALIZER(struct cmd_syn_filter_result, ops, "add#del"); @@ -8214,10 +8633,452 @@ cmdline_parse_inst_t cmd_syn_filter = { }, }; +/* *** queue region set *** */ +struct cmd_queue_region_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t port; + portid_t port_id; + cmdline_fixed_string_t cmd; + cmdline_fixed_string_t region; + uint8_t region_id; + cmdline_fixed_string_t queue_start_index; + uint8_t queue_id; + cmdline_fixed_string_t queue_num; + uint8_t queue_num_value; +}; + +static void +cmd_queue_region_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_queue_region_result *res = parsed_result; + int ret = -ENOTSUP; +#ifdef RTE_LIBRTE_I40E_PMD + struct rte_pmd_i40e_queue_region_conf region_conf; + enum rte_pmd_i40e_queue_region_op op_type; +#endif + + if (port_id_is_invalid(res->port_id, ENABLED_WARN)) + return; + +#ifdef RTE_LIBRTE_I40E_PMD + memset(®ion_conf, 0, sizeof(region_conf)); + op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET; + region_conf.region_id = res->region_id; + region_conf.queue_num = res->queue_num_value; + region_conf.queue_start_index = res->queue_id; + + ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, + op_type, ®ion_conf); +#endif + + switch (ret) { + case 0: + break; + case -ENOTSUP: + printf("function not implemented or supported\n"); + break; + default: + printf("queue region config error: (%s)\n", strerror(-ret)); + } +} + +cmdline_parse_token_string_t cmd_queue_region_set = +TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, + set, "set"); +cmdline_parse_token_string_t cmd_queue_region_port = + TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port"); +cmdline_parse_token_num_t cmd_queue_region_port_id = + TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, + port_id, UINT16); +cmdline_parse_token_string_t cmd_queue_region_cmd = + TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, + cmd, "queue-region"); +cmdline_parse_token_string_t cmd_queue_region_id = + TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, + region, "region_id"); +cmdline_parse_token_num_t cmd_queue_region_index = + TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, + region_id, UINT8); +cmdline_parse_token_string_t cmd_queue_region_queue_start_index = + TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, + queue_start_index, "queue_start_index"); +cmdline_parse_token_num_t cmd_queue_region_queue_id = + TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, + queue_id, UINT8); +cmdline_parse_token_string_t cmd_queue_region_queue_num = + TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, + queue_num, "queue_num"); +cmdline_parse_token_num_t cmd_queue_region_queue_num_value = + TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, + queue_num_value, UINT8); + +cmdline_parse_inst_t cmd_queue_region = { + .f = cmd_queue_region_parsed, + .data = NULL, + .help_str = "set port <port_id> queue-region region_id <value> " + "queue_start_index <value> queue_num <value>: Set a queue region", + .tokens = { + (void *)&cmd_queue_region_set, + (void *)&cmd_queue_region_port, + (void *)&cmd_queue_region_port_id, + (void *)&cmd_queue_region_cmd, + (void *)&cmd_queue_region_id, + (void *)&cmd_queue_region_index, + (void *)&cmd_queue_region_queue_start_index, + (void *)&cmd_queue_region_queue_id, + (void *)&cmd_queue_region_queue_num, + (void *)&cmd_queue_region_queue_num_value, + NULL, + }, +}; + +/* *** queue region and flowtype set *** */ +struct cmd_region_flowtype_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t port; + portid_t port_id; + cmdline_fixed_string_t cmd; + cmdline_fixed_string_t region; + uint8_t region_id; + cmdline_fixed_string_t flowtype; + uint8_t flowtype_id; +}; + +static void +cmd_region_flowtype_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_region_flowtype_result *res = parsed_result; + int ret = -ENOTSUP; +#ifdef RTE_LIBRTE_I40E_PMD + struct rte_pmd_i40e_queue_region_conf region_conf; + enum rte_pmd_i40e_queue_region_op op_type; +#endif + + if (port_id_is_invalid(res->port_id, ENABLED_WARN)) + return; + +#ifdef RTE_LIBRTE_I40E_PMD + memset(®ion_conf, 0, sizeof(region_conf)); + + op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET; + region_conf.region_id = res->region_id; + region_conf.hw_flowtype = res->flowtype_id; + + ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, + op_type, ®ion_conf); +#endif + + switch (ret) { + case 0: + break; + case -ENOTSUP: + printf("function not implemented or supported\n"); + break; + default: + printf("region flowtype config error: (%s)\n", strerror(-ret)); + } +} + +cmdline_parse_token_string_t cmd_region_flowtype_set = +TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, + set, "set"); +cmdline_parse_token_string_t cmd_region_flowtype_port = + TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, + port, "port"); +cmdline_parse_token_num_t cmd_region_flowtype_port_index = + TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result, + port_id, UINT16); +cmdline_parse_token_string_t cmd_region_flowtype_cmd = + TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, + cmd, "queue-region"); +cmdline_parse_token_string_t cmd_region_flowtype_index = + TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, + region, "region_id"); +cmdline_parse_token_num_t cmd_region_flowtype_id = + TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result, + region_id, UINT8); +cmdline_parse_token_string_t cmd_region_flowtype_flow_index = + TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, + flowtype, "flowtype"); +cmdline_parse_token_num_t cmd_region_flowtype_flow_id = + TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result, + flowtype_id, UINT8); +cmdline_parse_inst_t cmd_region_flowtype = { + .f = cmd_region_flowtype_parsed, + .data = NULL, + .help_str = "set port <port_id> queue-region region_id <value> " + "flowtype <value>: Set a flowtype region index", + .tokens = { + (void *)&cmd_region_flowtype_set, + (void *)&cmd_region_flowtype_port, + (void *)&cmd_region_flowtype_port_index, + (void *)&cmd_region_flowtype_cmd, + (void *)&cmd_region_flowtype_index, + (void *)&cmd_region_flowtype_id, + (void *)&cmd_region_flowtype_flow_index, + (void *)&cmd_region_flowtype_flow_id, + NULL, + }, +}; + +/* *** User Priority (UP) to queue region (region_id) set *** */ +struct cmd_user_priority_region_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t port; + portid_t port_id; + cmdline_fixed_string_t cmd; + cmdline_fixed_string_t user_priority; + uint8_t user_priority_id; + cmdline_fixed_string_t region; + uint8_t region_id; +}; + +static void +cmd_user_priority_region_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_user_priority_region_result *res = parsed_result; + int ret = -ENOTSUP; +#ifdef RTE_LIBRTE_I40E_PMD + struct rte_pmd_i40e_queue_region_conf region_conf; + enum rte_pmd_i40e_queue_region_op op_type; +#endif + + if (port_id_is_invalid(res->port_id, ENABLED_WARN)) + return; + +#ifdef RTE_LIBRTE_I40E_PMD + memset(®ion_conf, 0, sizeof(region_conf)); + op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET; + region_conf.user_priority = res->user_priority_id; + region_conf.region_id = res->region_id; + + ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, + op_type, ®ion_conf); +#endif + + switch (ret) { + case 0: + break; + case -ENOTSUP: + printf("function not implemented or supported\n"); + break; + default: + printf("user_priority region config error: (%s)\n", + strerror(-ret)); + } +} + +cmdline_parse_token_string_t cmd_user_priority_region_set = + TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, + set, "set"); +cmdline_parse_token_string_t cmd_user_priority_region_port = + TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, + port, "port"); +cmdline_parse_token_num_t cmd_user_priority_region_port_index = + TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result, + port_id, UINT16); +cmdline_parse_token_string_t cmd_user_priority_region_cmd = + TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, + cmd, "queue-region"); +cmdline_parse_token_string_t cmd_user_priority_region_UP = + TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, + user_priority, "UP"); +cmdline_parse_token_num_t cmd_user_priority_region_UP_id = + TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result, + user_priority_id, UINT8); +cmdline_parse_token_string_t cmd_user_priority_region_region = + TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, + region, "region_id"); +cmdline_parse_token_num_t cmd_user_priority_region_region_id = + TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result, + region_id, UINT8); + +cmdline_parse_inst_t cmd_user_priority_region = { + .f = cmd_user_priority_region_parsed, + .data = NULL, + .help_str = "set port <port_id> queue-region UP <value> " + "region_id <value>: Set the mapping of User Priority (UP) " + "to queue region (region_id) ", + .tokens = { + (void *)&cmd_user_priority_region_set, + (void *)&cmd_user_priority_region_port, + (void *)&cmd_user_priority_region_port_index, + (void *)&cmd_user_priority_region_cmd, + (void *)&cmd_user_priority_region_UP, + (void *)&cmd_user_priority_region_UP_id, + (void *)&cmd_user_priority_region_region, + (void *)&cmd_user_priority_region_region_id, + NULL, + }, +}; + +/* *** flush all queue region related configuration *** */ +struct cmd_flush_queue_region_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t port; + portid_t port_id; + cmdline_fixed_string_t cmd; + cmdline_fixed_string_t flush; + cmdline_fixed_string_t what; +}; + +static void +cmd_flush_queue_region_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_flush_queue_region_result *res = parsed_result; + int ret = -ENOTSUP; +#ifdef RTE_LIBRTE_I40E_PMD + struct rte_pmd_i40e_queue_region_conf region_conf; + enum rte_pmd_i40e_queue_region_op op_type; +#endif + + if (port_id_is_invalid(res->port_id, ENABLED_WARN)) + return; + +#ifdef RTE_LIBRTE_I40E_PMD + memset(®ion_conf, 0, sizeof(region_conf)); + + if (strcmp(res->what, "on") == 0) + op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON; + else + op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF; + + ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, + op_type, ®ion_conf); +#endif + + switch (ret) { + case 0: + break; + case -ENOTSUP: + printf("function not implemented or supported\n"); + break; + default: + printf("queue region config flush error: (%s)\n", + strerror(-ret)); + } +} + +cmdline_parse_token_string_t cmd_flush_queue_region_set = + TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, + set, "set"); +cmdline_parse_token_string_t cmd_flush_queue_region_port = + TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, + port, "port"); +cmdline_parse_token_num_t cmd_flush_queue_region_port_index = + TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result, + port_id, UINT16); +cmdline_parse_token_string_t cmd_flush_queue_region_cmd = + TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, + cmd, "queue-region"); +cmdline_parse_token_string_t cmd_flush_queue_region_flush = + TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, + flush, "flush"); +cmdline_parse_token_string_t cmd_flush_queue_region_what = + TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, + what, "on#off"); + +cmdline_parse_inst_t cmd_flush_queue_region = { + .f = cmd_flush_queue_region_parsed, + .data = NULL, + .help_str = "set port <port_id> queue-region flush on|off" + ": flush all queue region related configuration", + .tokens = { + (void *)&cmd_flush_queue_region_set, + (void *)&cmd_flush_queue_region_port, + (void *)&cmd_flush_queue_region_port_index, + (void *)&cmd_flush_queue_region_cmd, + (void *)&cmd_flush_queue_region_flush, + (void *)&cmd_flush_queue_region_what, + NULL, + }, +}; + +/* *** get all queue region related configuration info *** */ +struct cmd_show_queue_region_info { + cmdline_fixed_string_t show; + cmdline_fixed_string_t port; + portid_t port_id; + cmdline_fixed_string_t cmd; +}; + +static void +cmd_show_queue_region_info_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_show_queue_region_info *res = parsed_result; + int ret = -ENOTSUP; +#ifdef RTE_LIBRTE_I40E_PMD + struct rte_pmd_i40e_queue_regions rte_pmd_regions; + enum rte_pmd_i40e_queue_region_op op_type; +#endif + + if (port_id_is_invalid(res->port_id, ENABLED_WARN)) + return; + +#ifdef RTE_LIBRTE_I40E_PMD + memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions)); + + op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET; + + ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, + op_type, &rte_pmd_regions); + + port_queue_region_info_display(res->port_id, &rte_pmd_regions); +#endif + + switch (ret) { + case 0: + break; + case -ENOTSUP: + printf("function not implemented or supported\n"); + break; + default: + printf("queue region config info show error: (%s)\n", + strerror(-ret)); + } +} + +cmdline_parse_token_string_t cmd_show_queue_region_info_get = +TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info, + show, "show"); +cmdline_parse_token_string_t cmd_show_queue_region_info_port = + TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info, + port, "port"); +cmdline_parse_token_num_t cmd_show_queue_region_info_port_index = + TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info, + port_id, UINT16); +cmdline_parse_token_string_t cmd_show_queue_region_info_cmd = + TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info, + cmd, "queue-region"); + +cmdline_parse_inst_t cmd_show_queue_region_info_all = { + .f = cmd_show_queue_region_info_parsed, + .data = NULL, + .help_str = "show port <port_id> queue-region" + ": show all queue region related configuration info", + .tokens = { + (void *)&cmd_show_queue_region_info_get, + (void *)&cmd_show_queue_region_info_port, + (void *)&cmd_show_queue_region_info_port_index, + (void *)&cmd_show_queue_region_info_cmd, + NULL, + }, +}; + /* *** ADD/REMOVE A 2tuple FILTER *** */ struct cmd_2tuple_filter_result { cmdline_fixed_string_t filter; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t ops; cmdline_fixed_string_t dst_port; uint16_t dst_port_value; @@ -8296,7 +9157,7 @@ cmdline_parse_token_string_t cmd_2tuple_filter_filter = filter, "2tuple_filter"); cmdline_parse_token_num_t cmd_2tuple_filter_port_id = TOKEN_NUM_INITIALIZER(struct cmd_2tuple_filter_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_2tuple_filter_ops = TOKEN_STRING_INITIALIZER(struct cmd_2tuple_filter_result, ops, "add#del"); @@ -8366,7 +9227,7 @@ cmdline_parse_inst_t cmd_2tuple_filter = { /* *** ADD/REMOVE A 5tuple FILTER *** */ struct cmd_5tuple_filter_result { cmdline_fixed_string_t filter; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t ops; cmdline_fixed_string_t dst_ip; cmdline_ipaddr_t dst_ip_value; @@ -8475,7 +9336,7 @@ cmdline_parse_token_string_t cmd_5tuple_filter_filter = filter, "5tuple_filter"); cmdline_parse_token_num_t cmd_5tuple_filter_port_id = TOKEN_NUM_INITIALIZER(struct cmd_5tuple_filter_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_5tuple_filter_ops = TOKEN_STRING_INITIALIZER(struct cmd_5tuple_filter_result, ops, "add#del"); @@ -8571,7 +9432,7 @@ cmdline_parse_inst_t cmd_5tuple_filter = { struct cmd_flex_filter_result { cmdline_fixed_string_t filter; cmdline_fixed_string_t ops; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t len; uint8_t len_value; cmdline_fixed_string_t bytes; @@ -8698,7 +9559,7 @@ cmdline_parse_token_string_t cmd_flex_filter_filter = filter, "flex_filter"); cmdline_parse_token_num_t cmd_flex_filter_port_id = TOKEN_NUM_INITIALIZER(struct cmd_flex_filter_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_flex_filter_ops = TOKEN_STRING_INITIALIZER(struct cmd_flex_filter_result, ops, "add#del"); @@ -8761,7 +9622,7 @@ cmdline_parse_inst_t cmd_flex_filter = { /* *** deal with ethertype filter *** */ struct cmd_ethertype_filter_result { cmdline_fixed_string_t filter; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t ops; cmdline_fixed_string_t mac; struct ether_addr mac_addr; @@ -8777,7 +9638,7 @@ cmdline_parse_token_string_t cmd_ethertype_filter_filter = filter, "ethertype_filter"); cmdline_parse_token_num_t cmd_ethertype_filter_port_id = TOKEN_NUM_INITIALIZER(struct cmd_ethertype_filter_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_ethertype_filter_ops = TOKEN_STRING_INITIALIZER(struct cmd_ethertype_filter_result, ops, "add#del"); @@ -8823,7 +9684,7 @@ cmd_ethertype_filter_parsed(void *parsed_result, memset(&filter, 0, sizeof(filter)); if (!strcmp(res->mac, "mac_addr")) { filter.flags |= RTE_ETHTYPE_FLAGS_MAC; - (void)rte_memcpy(&filter.mac_addr, &res->mac_addr, + rte_memcpy(&filter.mac_addr, &res->mac_addr, sizeof(struct ether_addr)); } if (!strcmp(res->drop, "drop")) @@ -8870,7 +9731,7 @@ cmdline_parse_inst_t cmd_ethertype_filter = { /* *** deal with flow director filter *** */ struct cmd_flow_director_result { cmdline_fixed_string_t flow_director_filter; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t mode; cmdline_fixed_string_t mode_value; cmdline_fixed_string_t ops; @@ -8976,6 +9837,10 @@ str2flowtype(char *string) if (!strcmp(flowtype_str[i].str, string)) return flowtype_str[i].type; } + + if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64) + return (uint16_t)atoi(string); + return RTE_ETH_FLOW_UNKNOWN; } @@ -9012,7 +9877,7 @@ do { \ #define IPV6_ADDR_TO_ARRAY(ip_addr, ip) \ do { \ if ((ip_addr).family == AF_INET6) \ - (void)rte_memcpy(&(ip), \ + rte_memcpy(&(ip), \ &((ip_addr).addr.ipv6), \ sizeof(struct in6_addr)); \ else { \ @@ -9144,12 +10009,12 @@ cmd_flow_director_filter_parsed(void *parsed_result, } if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_MAC_VLAN) - (void)rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr, + rte_memcpy(&entry.input.flow.mac_vlan_flow.mac_addr, &res->mac_addr, sizeof(struct ether_addr)); if (fdir_conf.mode == RTE_FDIR_MODE_PERFECT_TUNNEL) { - (void)rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr, + rte_memcpy(&entry.input.flow.tunnel_flow.mac_addr, &res->mac_addr, sizeof(struct ether_addr)); entry.input.flow.tunnel_flow.tunnel_type = @@ -9158,7 +10023,7 @@ cmd_flow_director_filter_parsed(void *parsed_result, rte_cpu_to_be_32(res->tunnel_id_value); } - (void)rte_memcpy(entry.input.flow_ext.flexbytes, + rte_memcpy(entry.input.flow_ext.flexbytes, flexbytes, RTE_ETH_FDIR_MAX_FLEXLEN); @@ -9217,7 +10082,7 @@ cmdline_parse_token_string_t cmd_flow_director_filter = flow_director_filter, "flow_director_filter"); cmdline_parse_token_num_t cmd_flow_director_port_id = TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_flow_director_ops = TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, ops, "add#del#update"); @@ -9346,7 +10211,7 @@ cmdline_parse_inst_t cmd_add_del_ip_flow_director = { "ipv6-other|ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|" "l2_payload src <src_ip> dst <dst_ip> tos <tos_value> " "proto <proto_value> ttl <ttl_value> vlan <vlan_value> " - "flexbytes <flexbyte_vaues> drop|fw <pf_vf> queue <queue_id> " + "flexbytes <flexbyte_values> drop|fw <pf_vf> queue <queue_id> " "fd_id <fd_id_value>: " "Add or delete an ip flow director entry on NIC", .tokens = { @@ -9542,7 +10407,7 @@ cmdline_parse_inst_t cmd_add_del_tunnel_flow_director = { struct cmd_flush_flow_director_result { cmdline_fixed_string_t flush_flow_director; - uint8_t port_id; + portid_t port_id; }; cmdline_parse_token_string_t cmd_flush_flow_director_flush = @@ -9550,7 +10415,7 @@ cmdline_parse_token_string_t cmd_flush_flow_director_flush = flush_flow_director, "flush_flow_director"); cmdline_parse_token_num_t cmd_flush_flow_director_port_id = TOKEN_NUM_INITIALIZER(struct cmd_flush_flow_director_result, - port_id, UINT8); + port_id, UINT16); static void cmd_flush_flow_director_parsed(void *parsed_result, @@ -9589,7 +10454,7 @@ cmdline_parse_inst_t cmd_flush_flow_director = { /* *** deal with flow director mask *** */ struct cmd_flow_director_mask_result { cmdline_fixed_string_t flow_director_mask; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t mode; cmdline_fixed_string_t mode_value; cmdline_fixed_string_t vlan; @@ -9673,7 +10538,7 @@ cmdline_parse_token_string_t cmd_flow_director_mask = flow_director_mask, "flow_director_mask"); cmdline_parse_token_num_t cmd_flow_director_mask_port_id = TOKEN_NUM_INITIALIZER(struct cmd_flow_director_mask_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_flow_director_mask_vlan = TOKEN_STRING_INITIALIZER(struct cmd_flow_director_mask_result, vlan, "vlan"); @@ -9801,7 +10666,7 @@ cmdline_parse_inst_t cmd_set_flow_director_tunnel_mask = { /* *** deal with flow director mask on flexible payload *** */ struct cmd_flow_director_flex_mask_result { cmdline_fixed_string_t flow_director_flexmask; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t flow; cmdline_fixed_string_t flow_type; cmdline_fixed_string_t mask; @@ -9856,7 +10721,7 @@ cmd_flow_director_flex_mask_parsed(void *parsed_result, memset(&port->dev_conf.fdir_conf.flex_conf.flex_mask[i], 0, sizeof(struct rte_eth_fdir_flex_mask)); port->dev_conf.fdir_conf.flex_conf.nb_flexmasks = 1; - (void)rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0], + rte_memcpy(&port->dev_conf.fdir_conf.flex_conf.flex_mask[0], &flex_mask, sizeof(struct rte_eth_fdir_flex_mask)); cmd_reconfig_device_queue(res->port_id, 1, 1); @@ -9893,7 +10758,7 @@ cmdline_parse_token_string_t cmd_flow_director_flexmask = "flow_director_flex_mask"); cmdline_parse_token_num_t cmd_flow_director_flexmask_port_id = TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flex_mask_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_flow_director_flexmask_flow = TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, flow, "flow"); @@ -9923,7 +10788,7 @@ cmdline_parse_inst_t cmd_set_flow_director_flex_mask = { /* *** deal with flow director flexible payload configuration *** */ struct cmd_flow_director_flexpayload_result { cmdline_fixed_string_t flow_director_flexpayload; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t payload_layer; cmdline_fixed_string_t payload_cfg; }; @@ -10016,7 +10881,7 @@ cmdline_parse_token_string_t cmd_flow_director_flexpayload = "flow_director_flex_payload"); cmdline_parse_token_num_t cmd_flow_director_flexpayload_port_id = TOKEN_NUM_INITIALIZER(struct cmd_flow_director_flexpayload_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer = TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, payload_layer, "raw#l2#l3#l4"); @@ -10045,7 +10910,7 @@ extern cmdline_parse_inst_t cmd_flow; /* *** Get symmetric hash enable per port *** */ struct cmd_get_sym_hash_ena_per_port_result { cmdline_fixed_string_t get_sym_hash_ena_per_port; - uint8_t port_id; + portid_t port_id; }; static void @@ -10084,7 +10949,7 @@ cmdline_parse_token_string_t cmd_get_sym_hash_ena_per_port_all = get_sym_hash_ena_per_port, "get_sym_hash_ena_per_port"); cmdline_parse_token_num_t cmd_get_sym_hash_ena_per_port_port_id = TOKEN_NUM_INITIALIZER(struct cmd_get_sym_hash_ena_per_port_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = { .f = cmd_get_sym_hash_per_port_parsed, @@ -10101,7 +10966,7 @@ cmdline_parse_inst_t cmd_get_sym_hash_ena_per_port = { struct cmd_set_sym_hash_ena_per_port_result { cmdline_fixed_string_t set_sym_hash_ena_per_port; cmdline_fixed_string_t enable; - uint8_t port_id; + portid_t port_id; }; static void @@ -10140,7 +11005,7 @@ cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_all = set_sym_hash_ena_per_port, "set_sym_hash_ena_per_port"); cmdline_parse_token_num_t cmd_set_sym_hash_ena_per_port_port_id = TOKEN_NUM_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_set_sym_hash_ena_per_port_enable = TOKEN_STRING_INITIALIZER(struct cmd_set_sym_hash_ena_per_port_result, enable, "enable#disable"); @@ -10160,7 +11025,7 @@ cmdline_parse_inst_t cmd_set_sym_hash_ena_per_port = { /* Get global config of hash function */ struct cmd_get_hash_global_config_result { cmdline_fixed_string_t get_hash_global_config; - uint8_t port_id; + portid_t port_id; }; static char * @@ -10261,7 +11126,7 @@ cmdline_parse_token_string_t cmd_get_hash_global_config_all = get_hash_global_config, "get_hash_global_config"); cmdline_parse_token_num_t cmd_get_hash_global_config_port_id = TOKEN_NUM_INITIALIZER(struct cmd_get_hash_global_config_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_inst_t cmd_get_hash_global_config = { .f = cmd_get_hash_global_config_parsed, @@ -10277,7 +11142,7 @@ cmdline_parse_inst_t cmd_get_hash_global_config = { /* Set global config of hash function */ struct cmd_set_hash_global_config_result { cmdline_fixed_string_t set_hash_global_config; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t hash_func; cmdline_fixed_string_t flow_type; cmdline_fixed_string_t enable; @@ -10333,7 +11198,7 @@ cmdline_parse_token_string_t cmd_set_hash_global_config_all = set_hash_global_config, "set_hash_global_config"); cmdline_parse_token_num_t cmd_set_hash_global_config_port_id = TOKEN_NUM_INITIALIZER(struct cmd_set_hash_global_config_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_set_hash_global_config_hash_func = TOKEN_STRING_INITIALIZER(struct cmd_set_hash_global_config_result, hash_func, "toeplitz#simple_xor#default"); @@ -10367,7 +11232,7 @@ cmdline_parse_inst_t cmd_set_hash_global_config = { /* Set hash input set */ struct cmd_set_hash_input_set_result { cmdline_fixed_string_t set_hash_input_set; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t flow_type; cmdline_fixed_string_t inset_field; cmdline_fixed_string_t select; @@ -10449,12 +11314,10 @@ cmdline_parse_token_string_t cmd_set_hash_input_set_cmd = set_hash_input_set, "set_hash_input_set"); cmdline_parse_token_num_t cmd_set_hash_input_set_port_id = TOKEN_NUM_INITIALIZER(struct cmd_set_hash_input_set_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_set_hash_input_set_flow_type = TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, - flow_type, - "ipv4-frag#ipv4-tcp#ipv4-udp#ipv4-sctp#ipv4-other#" - "ipv6-frag#ipv6-tcp#ipv6-udp#ipv6-sctp#ipv6-other#l2_payload"); + flow_type, NULL); cmdline_parse_token_string_t cmd_set_hash_input_set_field = TOKEN_STRING_INITIALIZER(struct cmd_set_hash_input_set_result, inset_field, @@ -10473,7 +11336,7 @@ cmdline_parse_inst_t cmd_set_hash_input_set = { .data = NULL, .help_str = "set_hash_input_set <port_id> " "ipv4-frag|ipv4-tcp|ipv4-udp|ipv4-sctp|ipv4-other|" - "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload " + "ipv6-frag|ipv6-tcp|ipv6-udp|ipv6-sctp|ipv6-other|l2_payload|<flowtype_id> " "ovlan|ivlan|src-ipv4|dst-ipv4|src-ipv6|dst-ipv6|ipv4-tos|ipv4-proto|" "ipv6-tc|ipv6-next-header|udp-src-port|udp-dst-port|tcp-src-port|" "tcp-dst-port|sctp-src-port|sctp-dst-port|sctp-veri-tag|udp-key|" @@ -10492,7 +11355,7 @@ cmdline_parse_inst_t cmd_set_hash_input_set = { /* Set flow director input set */ struct cmd_set_fdir_input_set_result { cmdline_fixed_string_t set_fdir_input_set; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t flow_type; cmdline_fixed_string_t inset_field; cmdline_fixed_string_t select; @@ -10524,7 +11387,7 @@ cmdline_parse_token_string_t cmd_set_fdir_input_set_cmd = set_fdir_input_set, "set_fdir_input_set"); cmdline_parse_token_num_t cmd_set_fdir_input_set_port_id = TOKEN_NUM_INITIALIZER(struct cmd_set_fdir_input_set_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_set_fdir_input_set_flow_type = TOKEN_STRING_INITIALIZER(struct cmd_set_fdir_input_set_result, flow_type, @@ -10567,7 +11430,7 @@ cmdline_parse_inst_t cmd_set_fdir_input_set = { struct cmd_mcast_addr_result { cmdline_fixed_string_t mcast_addr_cmd; cmdline_fixed_string_t what; - uint8_t port_num; + uint16_t port_num; struct ether_addr mc_addr; }; @@ -10597,7 +11460,7 @@ cmdline_parse_token_string_t cmd_mcast_addr_what = TOKEN_STRING_INITIALIZER(struct cmd_mcast_addr_result, what, "add#remove"); cmdline_parse_token_num_t cmd_mcast_addr_portnum = - TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_mcast_addr_result, port_num, UINT16); cmdline_parse_token_etheraddr_t cmd_mcast_addr_addr = TOKEN_ETHERADDR_INITIALIZER(struct cmd_mac_addr_result, address); @@ -10901,7 +11764,7 @@ struct cmd_config_e_tag_result { cmdline_fixed_string_t dst_pool; uint8_t dst_pool_val; cmdline_fixed_string_t port; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t vf; uint8_t vf_id; }; @@ -10982,7 +11845,7 @@ cmdline_parse_token_string_t cmd_config_e_tag_port = cmdline_parse_token_num_t cmd_config_e_tag_port_id = TOKEN_NUM_INITIALIZER (struct cmd_config_e_tag_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_config_e_tag_vf = TOKEN_STRING_INITIALIZER (struct cmd_config_e_tag_result, @@ -11284,7 +12147,7 @@ struct cmd_vf_vlan_anti_spoof_result { cmdline_fixed_string_t vf; cmdline_fixed_string_t vlan; cmdline_fixed_string_t antispoof; - uint8_t port_id; + portid_t port_id; uint32_t vf_id; cmdline_fixed_string_t on_off; }; @@ -11309,7 +12172,7 @@ cmdline_parse_token_string_t cmd_vf_vlan_anti_spoof_antispoof = cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_port_id = TOKEN_NUM_INITIALIZER (struct cmd_vf_vlan_anti_spoof_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_vf_vlan_anti_spoof_vf_id = TOKEN_NUM_INITIALIZER (struct cmd_vf_vlan_anti_spoof_result, @@ -11390,7 +12253,7 @@ struct cmd_vf_mac_anti_spoof_result { cmdline_fixed_string_t vf; cmdline_fixed_string_t mac; cmdline_fixed_string_t antispoof; - uint8_t port_id; + portid_t port_id; uint32_t vf_id; cmdline_fixed_string_t on_off; }; @@ -11415,7 +12278,7 @@ cmdline_parse_token_string_t cmd_vf_mac_anti_spoof_antispoof = cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_port_id = TOKEN_NUM_INITIALIZER (struct cmd_vf_mac_anti_spoof_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_vf_mac_anti_spoof_vf_id = TOKEN_NUM_INITIALIZER (struct cmd_vf_mac_anti_spoof_result, @@ -11496,7 +12359,7 @@ struct cmd_vf_vlan_stripq_result { cmdline_fixed_string_t vf; cmdline_fixed_string_t vlan; cmdline_fixed_string_t stripq; - uint8_t port_id; + portid_t port_id; uint16_t vf_id; cmdline_fixed_string_t on_off; }; @@ -11521,7 +12384,7 @@ cmdline_parse_token_string_t cmd_vf_vlan_stripq_stripq = cmdline_parse_token_num_t cmd_vf_vlan_stripq_port_id = TOKEN_NUM_INITIALIZER (struct cmd_vf_vlan_stripq_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_vf_vlan_stripq_vf_id = TOKEN_NUM_INITIALIZER (struct cmd_vf_vlan_stripq_result, @@ -11602,7 +12465,7 @@ struct cmd_vf_vlan_insert_result { cmdline_fixed_string_t vf; cmdline_fixed_string_t vlan; cmdline_fixed_string_t insert; - uint8_t port_id; + portid_t port_id; uint16_t vf_id; uint16_t vlan_id; }; @@ -11627,7 +12490,7 @@ cmdline_parse_token_string_t cmd_vf_vlan_insert_insert = cmdline_parse_token_num_t cmd_vf_vlan_insert_port_id = TOKEN_NUM_INITIALIZER (struct cmd_vf_vlan_insert_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_vf_vlan_insert_vf_id = TOKEN_NUM_INITIALIZER (struct cmd_vf_vlan_insert_result, @@ -11705,7 +12568,7 @@ struct cmd_tx_loopback_result { cmdline_fixed_string_t set; cmdline_fixed_string_t tx; cmdline_fixed_string_t loopback; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t on_off; }; @@ -11725,7 +12588,7 @@ cmdline_parse_token_string_t cmd_tx_loopback_loopback = cmdline_parse_token_num_t cmd_tx_loopback_port_id = TOKEN_NUM_INITIALIZER (struct cmd_tx_loopback_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_tx_loopback_on_off = TOKEN_STRING_INITIALIZER (struct cmd_tx_loopback_result, @@ -11797,7 +12660,7 @@ struct cmd_all_queues_drop_en_result { cmdline_fixed_string_t all; cmdline_fixed_string_t queues; cmdline_fixed_string_t drop; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t on_off; }; @@ -11821,7 +12684,7 @@ cmdline_parse_token_string_t cmd_all_queues_drop_en_drop = cmdline_parse_token_num_t cmd_all_queues_drop_en_port_id = TOKEN_NUM_INITIALIZER (struct cmd_all_queues_drop_en_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_all_queues_drop_en_on_off = TOKEN_STRING_INITIALIZER (struct cmd_all_queues_drop_en_result, @@ -11888,7 +12751,7 @@ struct cmd_vf_split_drop_en_result { cmdline_fixed_string_t vf; cmdline_fixed_string_t split; cmdline_fixed_string_t drop; - uint8_t port_id; + portid_t port_id; uint16_t vf_id; cmdline_fixed_string_t on_off; }; @@ -11913,7 +12776,7 @@ cmdline_parse_token_string_t cmd_vf_split_drop_en_drop = cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id = TOKEN_NUM_INITIALIZER (struct cmd_vf_split_drop_en_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id = TOKEN_NUM_INITIALIZER (struct cmd_vf_split_drop_en_result, @@ -11981,7 +12844,7 @@ struct cmd_set_vf_mac_addr_result { cmdline_fixed_string_t vf; cmdline_fixed_string_t mac; cmdline_fixed_string_t addr; - uint8_t port_id; + portid_t port_id; uint16_t vf_id; struct ether_addr mac_addr; @@ -12007,7 +12870,7 @@ cmdline_parse_token_string_t cmd_set_vf_mac_addr_addr = cmdline_parse_token_num_t cmd_set_vf_mac_addr_port_id = TOKEN_NUM_INITIALIZER (struct cmd_set_vf_mac_addr_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_set_vf_mac_addr_vf_id = TOKEN_NUM_INITIALIZER (struct cmd_set_vf_mac_addr_result, @@ -12084,7 +12947,7 @@ struct cmd_macsec_offload_on_result { cmdline_fixed_string_t set; cmdline_fixed_string_t macsec; cmdline_fixed_string_t offload; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t on; cmdline_fixed_string_t encrypt; cmdline_fixed_string_t en_on_off; @@ -12108,7 +12971,7 @@ cmdline_parse_token_string_t cmd_macsec_offload_on_offload = cmdline_parse_token_num_t cmd_macsec_offload_on_port_id = TOKEN_NUM_INITIALIZER (struct cmd_macsec_offload_on_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_macsec_offload_on_on = TOKEN_STRING_INITIALIZER (struct cmd_macsec_offload_on_result, @@ -12190,7 +13053,7 @@ struct cmd_macsec_offload_off_result { cmdline_fixed_string_t set; cmdline_fixed_string_t macsec; cmdline_fixed_string_t offload; - uint8_t port_id; + portid_t port_id; cmdline_fixed_string_t off; }; @@ -12210,7 +13073,7 @@ cmdline_parse_token_string_t cmd_macsec_offload_off_offload = cmdline_parse_token_num_t cmd_macsec_offload_off_port_id = TOKEN_NUM_INITIALIZER (struct cmd_macsec_offload_off_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_string_t cmd_macsec_offload_off_off = TOKEN_STRING_INITIALIZER (struct cmd_macsec_offload_off_result, @@ -12268,7 +13131,7 @@ struct cmd_macsec_sc_result { cmdline_fixed_string_t macsec; cmdline_fixed_string_t sc; cmdline_fixed_string_t tx_rx; - uint8_t port_id; + portid_t port_id; struct ether_addr mac; uint16_t pi; }; @@ -12293,7 +13156,7 @@ cmdline_parse_token_string_t cmd_macsec_sc_tx_rx = cmdline_parse_token_num_t cmd_macsec_sc_port_id = TOKEN_NUM_INITIALIZER (struct cmd_macsec_sc_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac = TOKEN_ETHERADDR_INITIALIZER (struct cmd_macsec_sc_result, @@ -12358,7 +13221,7 @@ struct cmd_macsec_sa_result { cmdline_fixed_string_t macsec; cmdline_fixed_string_t sa; cmdline_fixed_string_t tx_rx; - uint8_t port_id; + portid_t port_id; uint8_t idx; uint8_t an; uint32_t pn; @@ -12385,7 +13248,7 @@ cmdline_parse_token_string_t cmd_macsec_sa_tx_rx = cmdline_parse_token_num_t cmd_macsec_sa_port_id = TOKEN_NUM_INITIALIZER (struct cmd_macsec_sa_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_macsec_sa_idx = TOKEN_NUM_INITIALIZER (struct cmd_macsec_sa_result, @@ -12484,7 +13347,7 @@ struct cmd_vf_promisc_result { cmdline_fixed_string_t set; cmdline_fixed_string_t vf; cmdline_fixed_string_t promisc; - uint8_t port_id; + portid_t port_id; uint32_t vf_id; cmdline_fixed_string_t on_off; }; @@ -12505,7 +13368,7 @@ cmdline_parse_token_string_t cmd_vf_promisc_promisc = cmdline_parse_token_num_t cmd_vf_promisc_port_id = TOKEN_NUM_INITIALIZER (struct cmd_vf_promisc_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_vf_promisc_vf_id = TOKEN_NUM_INITIALIZER (struct cmd_vf_promisc_result, @@ -12574,7 +13437,7 @@ struct cmd_vf_allmulti_result { cmdline_fixed_string_t set; cmdline_fixed_string_t vf; cmdline_fixed_string_t allmulti; - uint8_t port_id; + portid_t port_id; uint32_t vf_id; cmdline_fixed_string_t on_off; }; @@ -12595,7 +13458,7 @@ cmdline_parse_token_string_t cmd_vf_allmulti_allmulti = cmdline_parse_token_num_t cmd_vf_allmulti_port_id = TOKEN_NUM_INITIALIZER (struct cmd_vf_allmulti_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_vf_allmulti_vf_id = TOKEN_NUM_INITIALIZER (struct cmd_vf_allmulti_result, @@ -12664,7 +13527,7 @@ struct cmd_set_vf_broadcast_result { cmdline_fixed_string_t set; cmdline_fixed_string_t vf; cmdline_fixed_string_t broadcast; - uint8_t port_id; + portid_t port_id; uint16_t vf_id; cmdline_fixed_string_t on_off; }; @@ -12685,7 +13548,7 @@ cmdline_parse_token_string_t cmd_set_vf_broadcast_broadcast = cmdline_parse_token_num_t cmd_set_vf_broadcast_port_id = TOKEN_NUM_INITIALIZER (struct cmd_set_vf_broadcast_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_set_vf_broadcast_vf_id = TOKEN_NUM_INITIALIZER (struct cmd_set_vf_broadcast_result, @@ -12754,7 +13617,7 @@ struct cmd_set_vf_vlan_tag_result { cmdline_fixed_string_t vf; cmdline_fixed_string_t vlan; cmdline_fixed_string_t tag; - uint8_t port_id; + portid_t port_id; uint16_t vf_id; cmdline_fixed_string_t on_off; }; @@ -12779,7 +13642,7 @@ cmdline_parse_token_string_t cmd_set_vf_vlan_tag_tag = cmdline_parse_token_num_t cmd_set_vf_vlan_tag_port_id = TOKEN_NUM_INITIALIZER (struct cmd_set_vf_vlan_tag_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_set_vf_vlan_tag_vf_id = TOKEN_NUM_INITIALIZER (struct cmd_set_vf_vlan_tag_result, @@ -12850,7 +13713,7 @@ struct cmd_vf_tc_bw_result { cmdline_fixed_string_t min_bw; cmdline_fixed_string_t max_bw; cmdline_fixed_string_t strict_link_prio; - uint8_t port_id; + portid_t port_id; uint16_t vf_id; uint8_t tc_no; uint32_t bw; @@ -12889,7 +13752,7 @@ cmdline_parse_token_string_t cmd_vf_tc_bw_max_bw = cmdline_parse_token_num_t cmd_vf_tc_bw_port_id = TOKEN_NUM_INITIALIZER (struct cmd_vf_tc_bw_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_vf_tc_bw_vf_id = TOKEN_NUM_INITIALIZER (struct cmd_vf_tc_bw_result, @@ -13181,6 +14044,86 @@ cmdline_parse_inst_t cmd_vf_tc_max_bw = { }, }; + +#if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED + +/* *** Set Port default Traffic Management Hierarchy *** */ +struct cmd_set_port_tm_hierarchy_default_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t port; + cmdline_fixed_string_t tm; + cmdline_fixed_string_t hierarchy; + cmdline_fixed_string_t def; + portid_t port_id; +}; + +cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_set = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_tm_hierarchy_default_result, set, "set"); +cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_port = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_tm_hierarchy_default_result, port, "port"); +cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_tm = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_tm_hierarchy_default_result, tm, "tm"); +cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_hierarchy = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_tm_hierarchy_default_result, + hierarchy, "hierarchy"); +cmdline_parse_token_string_t cmd_set_port_tm_hierarchy_default_default = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_tm_hierarchy_default_result, + def, "default"); +cmdline_parse_token_num_t cmd_set_port_tm_hierarchy_default_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_set_port_tm_hierarchy_default_result, + port_id, UINT16); + +static void cmd_set_port_tm_hierarchy_default_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_set_port_tm_hierarchy_default_result *res = parsed_result; + struct rte_port *p; + portid_t port_id = res->port_id; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + p = &ports[port_id]; + + /* Port tm flag */ + if (p->softport.tm_flag == 0) { + printf(" tm not enabled on port %u (error)\n", port_id); + return; + } + + /* Forward mode: tm */ + if (strcmp(cur_fwd_config.fwd_eng->fwd_mode_name, "tm")) { + printf(" tm mode not enabled(error)\n"); + return; + } + + /* Set the default tm hierarchy */ + p->softport.tm.default_hierarchy_enable = 1; +} + +cmdline_parse_inst_t cmd_set_port_tm_hierarchy_default = { + .f = cmd_set_port_tm_hierarchy_default_parsed, + .data = NULL, + .help_str = "set port tm hierarchy default <port_id>", + .tokens = { + (void *)&cmd_set_port_tm_hierarchy_default_set, + (void *)&cmd_set_port_tm_hierarchy_default_port, + (void *)&cmd_set_port_tm_hierarchy_default_tm, + (void *)&cmd_set_port_tm_hierarchy_default_hierarchy, + (void *)&cmd_set_port_tm_hierarchy_default_default, + (void *)&cmd_set_port_tm_hierarchy_default_port_id, + NULL, + }, +}; +#endif + /* Strict link priority scheduling mode setting */ static void cmd_strict_link_prio_parsed( @@ -13233,7 +14176,7 @@ cmdline_parse_inst_t cmd_strict_link_prio = { struct cmd_ddp_add_result { cmdline_fixed_string_t ddp; cmdline_fixed_string_t add; - uint8_t port_id; + portid_t port_id; char filepath[]; }; @@ -13242,7 +14185,7 @@ cmdline_parse_token_string_t cmd_ddp_add_ddp = cmdline_parse_token_string_t cmd_ddp_add_add = TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, add, "add"); cmdline_parse_token_num_t cmd_ddp_add_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_ddp_add_result, port_id, UINT16); cmdline_parse_token_string_t cmd_ddp_add_filepath = TOKEN_STRING_INITIALIZER(struct cmd_ddp_add_result, filepath, NULL); @@ -13318,7 +14261,7 @@ cmdline_parse_inst_t cmd_ddp_add = { struct cmd_ddp_del_result { cmdline_fixed_string_t ddp; cmdline_fixed_string_t del; - uint8_t port_id; + portid_t port_id; char filepath[]; }; @@ -13327,7 +14270,7 @@ cmdline_parse_token_string_t cmd_ddp_del_ddp = cmdline_parse_token_string_t cmd_ddp_del_del = TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, del, "del"); cmdline_parse_token_num_t cmd_ddp_del_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_ddp_del_result, port_id, UINT16); cmdline_parse_token_string_t cmd_ddp_del_filepath = TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL); @@ -13412,12 +14355,20 @@ cmd_ddp_info_parsed( uint32_t pkg_size; int ret = -ENOTSUP; #ifdef RTE_LIBRTE_I40E_PMD - uint32_t i; + uint32_t i, j, n; uint8_t *buff; - uint32_t buff_size; + uint32_t buff_size = 0; struct rte_pmd_i40e_profile_info info; - uint32_t dev_num; + uint32_t dev_num = 0; struct rte_pmd_i40e_ddp_device_id *devs; + uint32_t proto_num = 0; + struct rte_pmd_i40e_proto_info *proto = NULL; + uint32_t pctype_num = 0; + struct rte_pmd_i40e_ptype_info *pctype; + uint32_t ptype_num = 0; + struct rte_pmd_i40e_ptype_info *ptype; + uint8_t proto_id; + #endif pkg = open_ddp_package_file(res->filepath, &pkg_size); @@ -13470,12 +14421,11 @@ cmd_ddp_info_parsed( (uint8_t *)&dev_num, sizeof(dev_num), RTE_PMD_I40E_PKG_INFO_DEVID_NUM); if (!ret && dev_num) { - devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(dev_num * - sizeof(struct rte_pmd_i40e_ddp_device_id)); + buff_size = dev_num * sizeof(struct rte_pmd_i40e_ddp_device_id); + devs = (struct rte_pmd_i40e_ddp_device_id *)malloc(buff_size); if (devs) { ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, - (uint8_t *)devs, dev_num * - sizeof(struct rte_pmd_i40e_ddp_device_id), + (uint8_t *)devs, buff_size, RTE_PMD_I40E_PKG_INFO_DEVID_LIST); if (!ret) { printf("List of supported devices:\n"); @@ -13491,7 +14441,110 @@ cmd_ddp_info_parsed( free(devs); } } + + /* get information about protocols and packet types */ + ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, + (uint8_t *)&proto_num, sizeof(proto_num), + RTE_PMD_I40E_PKG_INFO_PROTOCOL_NUM); + if (ret || !proto_num) + goto no_print_return; + + buff_size = proto_num * sizeof(struct rte_pmd_i40e_proto_info); + proto = (struct rte_pmd_i40e_proto_info *)malloc(buff_size); + if (!proto) + goto no_print_return; + + ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)proto, + buff_size, + RTE_PMD_I40E_PKG_INFO_PROTOCOL_LIST); + if (!ret) { + printf("List of used protocols:\n"); + for (i = 0; i < proto_num; i++) + printf(" %2u: %s\n", proto[i].proto_id, + proto[i].name); + printf("\n"); + } + ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, + (uint8_t *)&pctype_num, sizeof(pctype_num), + RTE_PMD_I40E_PKG_INFO_PCTYPE_NUM); + if (ret || !pctype_num) + goto no_print_pctypes; + + buff_size = pctype_num * sizeof(struct rte_pmd_i40e_ptype_info); + pctype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size); + if (!pctype) + goto no_print_pctypes; + + ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)pctype, + buff_size, + RTE_PMD_I40E_PKG_INFO_PCTYPE_LIST); + if (ret) { + free(pctype); + goto no_print_pctypes; + } + + printf("List of defined packet classification types:\n"); + for (i = 0; i < pctype_num; i++) { + printf(" %2u:", pctype[i].ptype_id); + for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) { + proto_id = pctype[i].protocols[j]; + if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) { + for (n = 0; n < proto_num; n++) { + if (proto[n].proto_id == proto_id) { + printf(" %s", proto[n].name); + break; + } + } + } + } + printf("\n"); + } + printf("\n"); + free(pctype); + +no_print_pctypes: + + ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)&ptype_num, + sizeof(ptype_num), + RTE_PMD_I40E_PKG_INFO_PTYPE_NUM); + if (ret || !ptype_num) + goto no_print_return; + + buff_size = ptype_num * sizeof(struct rte_pmd_i40e_ptype_info); + ptype = (struct rte_pmd_i40e_ptype_info *)malloc(buff_size); + if (!ptype) + goto no_print_return; + + ret = rte_pmd_i40e_get_ddp_info(pkg, pkg_size, (uint8_t *)ptype, + buff_size, + RTE_PMD_I40E_PKG_INFO_PTYPE_LIST); + if (ret) { + free(ptype); + goto no_print_return; + } + printf("List of defined packet types:\n"); + for (i = 0; i < ptype_num; i++) { + printf(" %2u:", ptype[i].ptype_id); + for (j = 0; j < RTE_PMD_I40E_PROTO_NUM; j++) { + proto_id = ptype[i].protocols[j]; + if (proto_id != RTE_PMD_I40E_PROTO_UNUSED) { + for (n = 0; n < proto_num; n++) { + if (proto[n].proto_id == proto_id) { + printf(" %s", proto[n].name); + break; + } + } + } + } + printf("\n"); + } + free(ptype); + printf("\n"); + ret = 0; +no_print_return: + if (proto) + free(proto); #endif if (ret == -ENOTSUP) printf("Function not supported in PMD driver\n"); @@ -13519,7 +14572,7 @@ struct cmd_ddp_get_list_result { cmdline_fixed_string_t ddp; cmdline_fixed_string_t get; cmdline_fixed_string_t list; - uint8_t port_id; + portid_t port_id; }; cmdline_parse_token_string_t cmd_ddp_get_list_ddp = @@ -13529,7 +14582,7 @@ cmdline_parse_token_string_t cmd_ddp_get_list_get = cmdline_parse_token_string_t cmd_ddp_get_list_list = TOKEN_STRING_INITIALIZER(struct cmd_ddp_get_list_result, list, "list"); cmdline_parse_token_num_t cmd_ddp_get_list_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT8); + TOKEN_NUM_INITIALIZER(struct cmd_ddp_get_list_result, port_id, UINT16); static void cmd_ddp_get_list_parsed( @@ -13606,7 +14659,7 @@ struct cmd_show_vf_stats_result { cmdline_fixed_string_t show; cmdline_fixed_string_t vf; cmdline_fixed_string_t stats; - uint8_t port_id; + portid_t port_id; uint16_t vf_id; }; @@ -13626,7 +14679,7 @@ cmdline_parse_token_string_t cmd_show_vf_stats_stats = cmdline_parse_token_num_t cmd_show_vf_stats_port_id = TOKEN_NUM_INITIALIZER (struct cmd_show_vf_stats_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_show_vf_stats_vf_id = TOKEN_NUM_INITIALIZER (struct cmd_show_vf_stats_result, @@ -13715,7 +14768,7 @@ struct cmd_clear_vf_stats_result { cmdline_fixed_string_t clear; cmdline_fixed_string_t vf; cmdline_fixed_string_t stats; - uint8_t port_id; + portid_t port_id; uint16_t vf_id; }; @@ -13735,7 +14788,7 @@ cmdline_parse_token_string_t cmd_clear_vf_stats_stats = cmdline_parse_token_num_t cmd_clear_vf_stats_port_id = TOKEN_NUM_INITIALIZER (struct cmd_clear_vf_stats_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_clear_vf_stats_vf_id = TOKEN_NUM_INITIALIZER (struct cmd_clear_vf_stats_result, @@ -13795,6 +14848,303 @@ cmdline_parse_inst_t cmd_clear_vf_stats = { }, }; +/* port config pctype mapping reset */ + +/* Common result structure for port config pctype mapping reset */ +struct cmd_pctype_mapping_reset_result { + cmdline_fixed_string_t port; + cmdline_fixed_string_t config; + portid_t port_id; + cmdline_fixed_string_t pctype; + cmdline_fixed_string_t mapping; + cmdline_fixed_string_t reset; +}; + +/* Common CLI fields for port config pctype mapping reset*/ +cmdline_parse_token_string_t cmd_pctype_mapping_reset_port = + TOKEN_STRING_INITIALIZER + (struct cmd_pctype_mapping_reset_result, + port, "port"); +cmdline_parse_token_string_t cmd_pctype_mapping_reset_config = + TOKEN_STRING_INITIALIZER + (struct cmd_pctype_mapping_reset_result, + config, "config"); +cmdline_parse_token_num_t cmd_pctype_mapping_reset_port_id = + TOKEN_NUM_INITIALIZER + (struct cmd_pctype_mapping_reset_result, + port_id, UINT16); +cmdline_parse_token_string_t cmd_pctype_mapping_reset_pctype = + TOKEN_STRING_INITIALIZER + (struct cmd_pctype_mapping_reset_result, + pctype, "pctype"); +cmdline_parse_token_string_t cmd_pctype_mapping_reset_mapping = + TOKEN_STRING_INITIALIZER + (struct cmd_pctype_mapping_reset_result, + mapping, "mapping"); +cmdline_parse_token_string_t cmd_pctype_mapping_reset_reset = + TOKEN_STRING_INITIALIZER + (struct cmd_pctype_mapping_reset_result, + reset, "reset"); + +static void +cmd_pctype_mapping_reset_parsed( + void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_pctype_mapping_reset_result *res = parsed_result; + int ret = -ENOTSUP; + + if (port_id_is_invalid(res->port_id, ENABLED_WARN)) + return; + +#ifdef RTE_LIBRTE_I40E_PMD + ret = rte_pmd_i40e_flow_type_mapping_reset(res->port_id); +#endif + + switch (ret) { + case 0: + break; + case -ENODEV: + printf("invalid port_id %d\n", res->port_id); + break; + case -ENOTSUP: + printf("function not implemented\n"); + break; + default: + printf("programming error: (%s)\n", strerror(-ret)); + } +} + +cmdline_parse_inst_t cmd_pctype_mapping_reset = { + .f = cmd_pctype_mapping_reset_parsed, + .data = NULL, + .help_str = "port config <port_id> pctype mapping reset", + .tokens = { + (void *)&cmd_pctype_mapping_reset_port, + (void *)&cmd_pctype_mapping_reset_config, + (void *)&cmd_pctype_mapping_reset_port_id, + (void *)&cmd_pctype_mapping_reset_pctype, + (void *)&cmd_pctype_mapping_reset_mapping, + (void *)&cmd_pctype_mapping_reset_reset, + NULL, + }, +}; + +/* show port pctype mapping */ + +/* Common result structure for show port pctype mapping */ +struct cmd_pctype_mapping_get_result { + cmdline_fixed_string_t show; + cmdline_fixed_string_t port; + portid_t port_id; + cmdline_fixed_string_t pctype; + cmdline_fixed_string_t mapping; +}; + +/* Common CLI fields for pctype mapping get */ +cmdline_parse_token_string_t cmd_pctype_mapping_get_show = + TOKEN_STRING_INITIALIZER + (struct cmd_pctype_mapping_get_result, + show, "show"); +cmdline_parse_token_string_t cmd_pctype_mapping_get_port = + TOKEN_STRING_INITIALIZER + (struct cmd_pctype_mapping_get_result, + port, "port"); +cmdline_parse_token_num_t cmd_pctype_mapping_get_port_id = + TOKEN_NUM_INITIALIZER + (struct cmd_pctype_mapping_get_result, + port_id, UINT16); +cmdline_parse_token_string_t cmd_pctype_mapping_get_pctype = + TOKEN_STRING_INITIALIZER + (struct cmd_pctype_mapping_get_result, + pctype, "pctype"); +cmdline_parse_token_string_t cmd_pctype_mapping_get_mapping = + TOKEN_STRING_INITIALIZER + (struct cmd_pctype_mapping_get_result, + mapping, "mapping"); + +static void +cmd_pctype_mapping_get_parsed( + void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_pctype_mapping_get_result *res = parsed_result; + int ret = -ENOTSUP; +#ifdef RTE_LIBRTE_I40E_PMD + struct rte_pmd_i40e_flow_type_mapping + mapping[RTE_PMD_I40E_FLOW_TYPE_MAX]; + int i, j, first_pctype; +#endif + + if (port_id_is_invalid(res->port_id, ENABLED_WARN)) + return; + +#ifdef RTE_LIBRTE_I40E_PMD + ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, mapping); +#endif + + switch (ret) { + case 0: + break; + case -ENODEV: + printf("invalid port_id %d\n", res->port_id); + return; + case -ENOTSUP: + printf("function not implemented\n"); + return; + default: + printf("programming error: (%s)\n", strerror(-ret)); + return; + } + +#ifdef RTE_LIBRTE_I40E_PMD + for (i = 0; i < RTE_PMD_I40E_FLOW_TYPE_MAX; i++) { + if (mapping[i].pctype != 0ULL) { + first_pctype = 1; + + printf("pctype: "); + for (j = 0; j < RTE_PMD_I40E_PCTYPE_MAX; j++) { + if (mapping[i].pctype & (1ULL << j)) { + printf(first_pctype ? + "%02d" : ",%02d", j); + first_pctype = 0; + } + } + printf(" -> flowtype: %02d\n", mapping[i].flow_type); + } + } +#endif +} + +cmdline_parse_inst_t cmd_pctype_mapping_get = { + .f = cmd_pctype_mapping_get_parsed, + .data = NULL, + .help_str = "show port <port_id> pctype mapping", + .tokens = { + (void *)&cmd_pctype_mapping_get_show, + (void *)&cmd_pctype_mapping_get_port, + (void *)&cmd_pctype_mapping_get_port_id, + (void *)&cmd_pctype_mapping_get_pctype, + (void *)&cmd_pctype_mapping_get_mapping, + NULL, + }, +}; + +/* port config pctype mapping update */ + +/* Common result structure for port config pctype mapping update */ +struct cmd_pctype_mapping_update_result { + cmdline_fixed_string_t port; + cmdline_fixed_string_t config; + portid_t port_id; + cmdline_fixed_string_t pctype; + cmdline_fixed_string_t mapping; + cmdline_fixed_string_t update; + cmdline_fixed_string_t pctype_list; + uint16_t flow_type; +}; + +/* Common CLI fields for pctype mapping update*/ +cmdline_parse_token_string_t cmd_pctype_mapping_update_port = + TOKEN_STRING_INITIALIZER + (struct cmd_pctype_mapping_update_result, + port, "port"); +cmdline_parse_token_string_t cmd_pctype_mapping_update_config = + TOKEN_STRING_INITIALIZER + (struct cmd_pctype_mapping_update_result, + config, "config"); +cmdline_parse_token_num_t cmd_pctype_mapping_update_port_id = + TOKEN_NUM_INITIALIZER + (struct cmd_pctype_mapping_update_result, + port_id, UINT16); +cmdline_parse_token_string_t cmd_pctype_mapping_update_pctype = + TOKEN_STRING_INITIALIZER + (struct cmd_pctype_mapping_update_result, + pctype, "pctype"); +cmdline_parse_token_string_t cmd_pctype_mapping_update_mapping = + TOKEN_STRING_INITIALIZER + (struct cmd_pctype_mapping_update_result, + mapping, "mapping"); +cmdline_parse_token_string_t cmd_pctype_mapping_update_update = + TOKEN_STRING_INITIALIZER + (struct cmd_pctype_mapping_update_result, + update, "update"); +cmdline_parse_token_string_t cmd_pctype_mapping_update_pc_type = + TOKEN_STRING_INITIALIZER + (struct cmd_pctype_mapping_update_result, + pctype_list, NULL); +cmdline_parse_token_num_t cmd_pctype_mapping_update_flow_type = + TOKEN_NUM_INITIALIZER + (struct cmd_pctype_mapping_update_result, + flow_type, UINT16); + +static void +cmd_pctype_mapping_update_parsed( + void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_pctype_mapping_update_result *res = parsed_result; + int ret = -ENOTSUP; +#ifdef RTE_LIBRTE_I40E_PMD + struct rte_pmd_i40e_flow_type_mapping mapping; + unsigned int i; + unsigned int nb_item; + unsigned int pctype_list[RTE_PMD_I40E_PCTYPE_MAX]; +#endif + + if (port_id_is_invalid(res->port_id, ENABLED_WARN)) + return; + +#ifdef RTE_LIBRTE_I40E_PMD + nb_item = parse_item_list(res->pctype_list, "pctypes", + RTE_PMD_I40E_PCTYPE_MAX, pctype_list, 1); + mapping.flow_type = res->flow_type; + for (i = 0, mapping.pctype = 0ULL; i < nb_item; i++) + mapping.pctype |= (1ULL << pctype_list[i]); + ret = rte_pmd_i40e_flow_type_mapping_update(res->port_id, + &mapping, + 1, + 0); +#endif + + switch (ret) { + case 0: + break; + case -EINVAL: + printf("invalid pctype or flow type\n"); + break; + case -ENODEV: + printf("invalid port_id %d\n", res->port_id); + break; + case -ENOTSUP: + printf("function not implemented\n"); + break; + default: + printf("programming error: (%s)\n", strerror(-ret)); + } +} + +cmdline_parse_inst_t cmd_pctype_mapping_update = { + .f = cmd_pctype_mapping_update_parsed, + .data = NULL, + .help_str = "port config <port_id> pctype mapping update" + " <pctype_id_0,[pctype_id_1]*> <flowtype_id>", + .tokens = { + (void *)&cmd_pctype_mapping_update_port, + (void *)&cmd_pctype_mapping_update_config, + (void *)&cmd_pctype_mapping_update_port_id, + (void *)&cmd_pctype_mapping_update_pctype, + (void *)&cmd_pctype_mapping_update_mapping, + (void *)&cmd_pctype_mapping_update_update, + (void *)&cmd_pctype_mapping_update_pc_type, + (void *)&cmd_pctype_mapping_update_flow_type, + NULL, + }, +}; + /* ptype mapping get */ /* Common result structure for ptype mapping get */ @@ -13802,7 +15152,7 @@ struct cmd_ptype_mapping_get_result { cmdline_fixed_string_t ptype; cmdline_fixed_string_t mapping; cmdline_fixed_string_t get; - uint8_t port_id; + portid_t port_id; uint8_t valid_only; }; @@ -13822,7 +15172,7 @@ cmdline_parse_token_string_t cmd_ptype_mapping_get_get = cmdline_parse_token_num_t cmd_ptype_mapping_get_port_id = TOKEN_NUM_INITIALIZER (struct cmd_ptype_mapping_get_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_ptype_mapping_get_valid_only = TOKEN_NUM_INITIALIZER (struct cmd_ptype_mapping_get_result, @@ -13897,7 +15247,7 @@ struct cmd_ptype_mapping_replace_result { cmdline_fixed_string_t ptype; cmdline_fixed_string_t mapping; cmdline_fixed_string_t replace; - uint8_t port_id; + portid_t port_id; uint32_t target; uint8_t mask; uint32_t pkt_type; @@ -13919,7 +15269,7 @@ cmdline_parse_token_string_t cmd_ptype_mapping_replace_replace = cmdline_parse_token_num_t cmd_ptype_mapping_replace_port_id = TOKEN_NUM_INITIALIZER (struct cmd_ptype_mapping_replace_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_ptype_mapping_replace_target = TOKEN_NUM_INITIALIZER (struct cmd_ptype_mapping_replace_result, @@ -13994,7 +15344,7 @@ struct cmd_ptype_mapping_reset_result { cmdline_fixed_string_t ptype; cmdline_fixed_string_t mapping; cmdline_fixed_string_t reset; - uint8_t port_id; + portid_t port_id; }; /* Common CLI fields for ptype mapping reset*/ @@ -14013,7 +15363,7 @@ cmdline_parse_token_string_t cmd_ptype_mapping_reset_reset = cmdline_parse_token_num_t cmd_ptype_mapping_reset_port_id = TOKEN_NUM_INITIALIZER (struct cmd_ptype_mapping_reset_result, - port_id, UINT8); + port_id, UINT16); static void cmd_ptype_mapping_reset_parsed( @@ -14065,7 +15415,7 @@ struct cmd_ptype_mapping_update_result { cmdline_fixed_string_t ptype; cmdline_fixed_string_t mapping; cmdline_fixed_string_t reset; - uint8_t port_id; + portid_t port_id; uint8_t hw_ptype; uint32_t sw_ptype; }; @@ -14086,7 +15436,7 @@ cmdline_parse_token_string_t cmd_ptype_mapping_update_update = cmdline_parse_token_num_t cmd_ptype_mapping_update_port_id = TOKEN_NUM_INITIALIZER (struct cmd_ptype_mapping_update_result, - port_id, UINT8); + port_id, UINT16); cmdline_parse_token_num_t cmd_ptype_mapping_update_hw_ptype = TOKEN_NUM_INITIALIZER (struct cmd_ptype_mapping_update_result, @@ -14249,8 +15599,12 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_tso_show, (cmdline_parse_inst_t *)&cmd_tunnel_tso_set, (cmdline_parse_inst_t *)&cmd_tunnel_tso_show, - (cmdline_parse_inst_t *)&cmd_enable_gro, - (cmdline_parse_inst_t *)&cmd_gro_set, + (cmdline_parse_inst_t *)&cmd_gro_enable, + (cmdline_parse_inst_t *)&cmd_gro_flush, + (cmdline_parse_inst_t *)&cmd_gro_show, + (cmdline_parse_inst_t *)&cmd_gso_enable, + (cmdline_parse_inst_t *)&cmd_gso_size, + (cmdline_parse_inst_t *)&cmd_gso_show, (cmdline_parse_inst_t *)&cmd_link_flow_control_set, (cmdline_parse_inst_t *)&cmd_link_flow_control_set_rx, (cmdline_parse_inst_t *)&cmd_link_flow_control_set_tx, @@ -14272,6 +15626,7 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_stop, (cmdline_parse_inst_t *)&cmd_mac_addr, (cmdline_parse_inst_t *)&cmd_set_qmap, + (cmdline_parse_inst_t *)&cmd_set_xstats_hide_zero, (cmdline_parse_inst_t *)&cmd_operate_port, (cmdline_parse_inst_t *)&cmd_operate_specific_port, (cmdline_parse_inst_t *)&cmd_operate_attach_port, @@ -14330,6 +15685,15 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_set_hash_input_set, (cmdline_parse_inst_t *)&cmd_set_fdir_input_set, (cmdline_parse_inst_t *)&cmd_flow, + (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_srtcm, + (cmdline_parse_inst_t *)&cmd_add_port_meter_profile_trtcm, + (cmdline_parse_inst_t *)&cmd_del_port_meter_profile, + (cmdline_parse_inst_t *)&cmd_set_port_meter, + (cmdline_parse_inst_t *)&cmd_del_port_meter, + (cmdline_parse_inst_t *)&cmd_set_port_meter_profile, + (cmdline_parse_inst_t *)&cmd_set_port_meter_policer_action, + (cmdline_parse_inst_t *)&cmd_set_port_meter_stats_mask, + (cmdline_parse_inst_t *)&cmd_show_port_meter_stats, (cmdline_parse_inst_t *)&cmd_mcast_addr, (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_all, (cmdline_parse_inst_t *)&cmd_config_l2_tunnel_eth_type_specific, @@ -14366,6 +15730,9 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw, (cmdline_parse_inst_t *)&cmd_strict_link_prio, (cmdline_parse_inst_t *)&cmd_tc_min_bw, +#if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED + (cmdline_parse_inst_t *)&cmd_set_port_tm_hierarchy_default, +#endif (cmdline_parse_inst_t *)&cmd_ddp_add, (cmdline_parse_inst_t *)&cmd_ddp_del, (cmdline_parse_inst_t *)&cmd_ddp_get_list, @@ -14376,6 +15743,32 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_ptype_mapping_replace, (cmdline_parse_inst_t *)&cmd_ptype_mapping_reset, (cmdline_parse_inst_t *)&cmd_ptype_mapping_update, + + (cmdline_parse_inst_t *)&cmd_pctype_mapping_get, + (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset, + (cmdline_parse_inst_t *)&cmd_pctype_mapping_update, + (cmdline_parse_inst_t *)&cmd_queue_region, + (cmdline_parse_inst_t *)&cmd_region_flowtype, + (cmdline_parse_inst_t *)&cmd_user_priority_region, + (cmdline_parse_inst_t *)&cmd_flush_queue_region, + (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all, + (cmdline_parse_inst_t *)&cmd_show_port_tm_cap, + (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap, + (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap, + (cmdline_parse_inst_t *)&cmd_show_port_tm_node_type, + (cmdline_parse_inst_t *)&cmd_show_port_tm_node_stats, + (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shaper_profile, + (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shaper_profile, + (cmdline_parse_inst_t *)&cmd_add_port_tm_node_shared_shaper, + (cmdline_parse_inst_t *)&cmd_del_port_tm_node_shared_shaper, + (cmdline_parse_inst_t *)&cmd_add_port_tm_node_wred_profile, + (cmdline_parse_inst_t *)&cmd_del_port_tm_node_wred_profile, + (cmdline_parse_inst_t *)&cmd_set_port_tm_node_shaper_profile, + (cmdline_parse_inst_t *)&cmd_add_port_tm_nonleaf_node, + (cmdline_parse_inst_t *)&cmd_add_port_tm_leaf_node, + (cmdline_parse_inst_t *)&cmd_del_port_tm_node, + (cmdline_parse_inst_t *)&cmd_set_port_tm_node_parent, + (cmdline_parse_inst_t *)&cmd_port_tm_hierarchy_commit, NULL, }; diff --git a/app/test-pmd/cmdline_flow.c b/app/test-pmd/cmdline_flow.c index a17a0043..df16d2ab 100644 --- a/app/test-pmd/cmdline_flow.c +++ b/app/test-pmd/cmdline_flow.c @@ -171,6 +171,10 @@ enum index { ITEM_GRE_PROTO, ITEM_FUZZY, ITEM_FUZZY_THRESH, + ITEM_GTP, + ITEM_GTP_TEID, + ITEM_GTPC, + ITEM_GTPU, /* Validate/create actions. */ ACTIONS, @@ -194,6 +198,8 @@ enum index { ACTION_VF, ACTION_VF_ORIGINAL, ACTION_VF_ID, + ACTION_METER, + ACTION_METER_ID, }; /** Size of pattern[] field in struct rte_flow_item_raw. */ @@ -226,7 +232,7 @@ struct context { int args_num; /**< Number of entries in args[]. */ uint32_t eol:1; /**< EOL has been detected. */ uint32_t last:1; /**< No more arguments. */ - uint16_t port; /**< Current port ID (for completions). */ + portid_t port; /**< Current port ID (for completions). */ uint32_t objdata; /**< Object-specific data. */ void *object; /**< Address of current object for relative offsets. */ void *objmask; /**< Object a full mask must be written to. */ @@ -346,7 +352,7 @@ struct token { /** Parser output buffer layout expected by cmd_flow_parsed(). */ struct buffer { enum index command; /**< Flow command. */ - uint16_t port; /**< Affected port ID. */ + portid_t port; /**< Affected port ID. */ union { struct { struct rte_flow_attr attr; @@ -451,6 +457,9 @@ static const enum index next_item[] = { ITEM_MPLS, ITEM_GRE, ITEM_FUZZY, + ITEM_GTP, + ITEM_GTPC, + ITEM_GTPU, ZERO, }; @@ -588,6 +597,12 @@ static const enum index item_gre[] = { ZERO, }; +static const enum index item_gtp[] = { + ITEM_GTP_TEID, + ITEM_NEXT, + ZERO, +}; + static const enum index next_action[] = { ACTION_END, ACTION_VOID, @@ -601,6 +616,7 @@ static const enum index next_action[] = { ACTION_RSS, ACTION_PF, ACTION_VF, + ACTION_METER, ZERO, }; @@ -635,6 +651,12 @@ static const enum index action_vf[] = { ZERO, }; +static const enum index action_meter[] = { + ACTION_METER_ID, + ACTION_NEXT, + ZERO, +}; + static int parse_init(struct context *, const struct token *, const char *, unsigned int, void *, unsigned int); @@ -1421,6 +1443,33 @@ static const struct token token_list[] = { .args = ARGS(ARGS_ENTRY(struct rte_flow_item_fuzzy, thresh)), }, + [ITEM_GTP] = { + .name = "gtp", + .help = "match GTP header", + .priv = PRIV_ITEM(GTP, sizeof(struct rte_flow_item_gtp)), + .next = NEXT(item_gtp), + .call = parse_vc, + }, + [ITEM_GTP_TEID] = { + .name = "teid", + .help = "tunnel endpoint identifier", + .next = NEXT(item_gtp, NEXT_ENTRY(UNSIGNED), item_param), + .args = ARGS(ARGS_ENTRY_HTON(struct rte_flow_item_gtp, teid)), + }, + [ITEM_GTPC] = { + .name = "gtpc", + .help = "match GTP header", + .priv = PRIV_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)), + .next = NEXT(item_gtp), + .call = parse_vc, + }, + [ITEM_GTPU] = { + .name = "gtpu", + .help = "match GTP header", + .priv = PRIV_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)), + .next = NEXT(item_gtp), + .call = parse_vc, + }, /* Validate/create actions. */ [ACTIONS] = { @@ -1566,6 +1615,21 @@ static const struct token token_list[] = { .args = ARGS(ARGS_ENTRY(struct rte_flow_action_vf, id)), .call = parse_vc_conf, }, + [ACTION_METER] = { + .name = "meter", + .help = "meter the directed packets at given id", + .priv = PRIV_ACTION(METER, + sizeof(struct rte_flow_action_meter)), + .next = NEXT(action_meter), + .call = parse_vc, + }, + [ACTION_METER_ID] = { + .name = "mtr_id", + .help = "meter id to use", + .next = NEXT(action_meter, NEXT_ENTRY(UNSIGNED)), + .args = ARGS(ARGS_ENTRY(struct rte_flow_action_meter, mtr_id)), + .call = parse_vc_conf, + }, }; /** Remove and return last entry from argument stack. */ @@ -2578,7 +2642,7 @@ comp_rule_id(struct context *ctx, const struct token *token, (void)token; if (port_id_is_invalid(ctx->port, DISABLED_WARN) || - ctx->port == (uint16_t)RTE_PORT_ALL) + ctx->port == (portid_t)RTE_PORT_ALL) return -1; port = &ports[ctx->port]; for (pf = port->flow_list; pf != NULL; pf = pf->next) { diff --git a/app/test-pmd/cmdline_mtr.c b/app/test-pmd/cmdline_mtr.c new file mode 100644 index 00000000..d8d806d7 --- /dev/null +++ b/app/test-pmd/cmdline_mtr.c @@ -0,0 +1,1018 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2017 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <cmdline_parse.h> +#include <cmdline_parse_num.h> +#include <cmdline_parse_string.h> + +#include <rte_ethdev.h> +#include <rte_flow.h> +#include <rte_mtr.h> + +#include "testpmd.h" +#include "cmdline_mtr.h" + +/** Display Meter Error Message */ +static void +print_err_msg(struct rte_mtr_error *error) +{ + static const char *const errstrlist[] = { + [RTE_MTR_ERROR_TYPE_NONE] = "no error", + [RTE_MTR_ERROR_TYPE_UNSPECIFIED] = "cause unspecified", + [RTE_MTR_ERROR_TYPE_METER_PROFILE_ID] = "meter profile id", + [RTE_MTR_ERROR_TYPE_METER_PROFILE] = "meter profile null", + [RTE_MTR_ERROR_TYPE_MTR_ID] = "meter id", + [RTE_MTR_ERROR_TYPE_MTR_PARAMS] = "meter params null", + [RTE_MTR_ERROR_TYPE_POLICER_ACTION_GREEN] + = "policer action(green)", + [RTE_MTR_ERROR_TYPE_POLICER_ACTION_YELLOW] + = "policer action(yellow)", + [RTE_MTR_ERROR_TYPE_POLICER_ACTION_RED] + = "policer action(red)", + [RTE_MTR_ERROR_TYPE_STATS_MASK] = "stats mask", + [RTE_MTR_ERROR_TYPE_STATS] = "stats", + [RTE_MTR_ERROR_TYPE_SHARED] + = "shared meter", + }; + + const char *errstr; + char buf[64]; + + if ((unsigned int)error->type >= RTE_DIM(errstrlist) || + !errstrlist[error->type]) + errstr = "unknown type"; + else + errstr = errstrlist[error->type]; + + if (error->cause) + snprintf(buf, sizeof(buf), "cause: %p, ", error->cause); + + printf("%s: %s%s (error %d)\n", errstr, error->cause ? buf : "", + error->message ? error->message : "(no stated reason)", + error->type); +} + +static int +string_to_policer_action(char *s) +{ + if (strcmp(s, "G") == 0) + return MTR_POLICER_ACTION_COLOR_GREEN; + + if (strcmp(s, "Y") == 0) + return MTR_POLICER_ACTION_COLOR_YELLOW; + + if (strcmp(s, "R") == 0) + return MTR_POLICER_ACTION_COLOR_RED; + + if (strcmp(s, "D") == 0) + return MTR_POLICER_ACTION_DROP; + + return -1; +} + +/* *** Add Port Meter Profile srtcm_rfc2697 *** */ +struct cmd_add_port_meter_profile_srtcm_result { + cmdline_fixed_string_t add; + cmdline_fixed_string_t port; + cmdline_fixed_string_t meter; + cmdline_fixed_string_t profile; + cmdline_fixed_string_t srtcm_rfc2697; + uint16_t port_id; + uint32_t profile_id; + uint64_t cir; + uint64_t cbs; + uint64_t ebs; + uint8_t color_aware; +}; + +cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_add = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_meter_profile_srtcm_result, add, "add"); +cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_port = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_meter_profile_srtcm_result, + port, "port"); +cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_meter = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_meter_profile_srtcm_result, + meter, "meter"); +cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_profile = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_meter_profile_srtcm_result, + profile, "profile"); +cmdline_parse_token_string_t cmd_add_port_meter_profile_srtcm_srtcm_rfc2697 = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_meter_profile_srtcm_result, + srtcm_rfc2697, "srtcm_rfc2697"); +cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_meter_profile_srtcm_result, + port_id, UINT16); +cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_profile_id = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_meter_profile_srtcm_result, + profile_id, UINT32); +cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cir = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_meter_profile_srtcm_result, + cir, UINT64); +cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_cbs = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_meter_profile_srtcm_result, + cbs, UINT64); +cmdline_parse_token_num_t cmd_add_port_meter_profile_srtcm_ebs = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_meter_profile_srtcm_result, + ebs, UINT64); + +static void cmd_add_port_meter_profile_srtcm_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_add_port_meter_profile_srtcm_result *res = parsed_result; + struct rte_mtr_meter_profile mp; + struct rte_mtr_error error; + uint32_t profile_id = res->profile_id; + uint16_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + /* Private shaper profile params */ + memset(&mp, 0, sizeof(struct rte_mtr_meter_profile)); + mp.alg = 0; + mp.srtcm_rfc2697.cir = res->cir; + mp.srtcm_rfc2697.cbs = res->cbs; + mp.srtcm_rfc2697.ebs = res->ebs; + + ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_add_port_meter_profile_srtcm = { + .f = cmd_add_port_meter_profile_srtcm_parsed, + .data = NULL, + .help_str = "Add port meter profile srtcm (rfc2697)", + .tokens = { + (void *)&cmd_add_port_meter_profile_srtcm_add, + (void *)&cmd_add_port_meter_profile_srtcm_port, + (void *)&cmd_add_port_meter_profile_srtcm_meter, + (void *)&cmd_add_port_meter_profile_srtcm_profile, + (void *)&cmd_add_port_meter_profile_srtcm_port_id, + (void *)&cmd_add_port_meter_profile_srtcm_profile_id, + (void *)&cmd_add_port_meter_profile_srtcm_srtcm_rfc2697, + (void *)&cmd_add_port_meter_profile_srtcm_cir, + (void *)&cmd_add_port_meter_profile_srtcm_cbs, + (void *)&cmd_add_port_meter_profile_srtcm_ebs, + NULL, + }, +}; + +/* *** Add Port Meter Profile trtcm_rfc2698 *** */ +struct cmd_add_port_meter_profile_trtcm_result { + cmdline_fixed_string_t add; + cmdline_fixed_string_t port; + cmdline_fixed_string_t meter; + cmdline_fixed_string_t profile; + cmdline_fixed_string_t trtcm_rfc2698; + uint16_t port_id; + uint32_t profile_id; + uint64_t cir; + uint64_t pir; + uint64_t cbs; + uint64_t pbs; +}; + +cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_add = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_result, add, "add"); +cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_port = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_result, + port, "port"); +cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_meter = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_result, + meter, "meter"); +cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_profile = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_result, + profile, "profile"); +cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_trtcm_rfc2698 = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_result, + trtcm_rfc2698, "trtcm_rfc2698"); +cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_result, + port_id, UINT16); +cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_profile_id = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_result, + profile_id, UINT32); +cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cir = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_result, + cir, UINT64); +cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pir = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_result, + pir, UINT64); +cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_cbs = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_result, + cbs, UINT64); +cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_pbs = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_result, + pbs, UINT64); + +static void cmd_add_port_meter_profile_trtcm_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_add_port_meter_profile_trtcm_result *res = parsed_result; + struct rte_mtr_meter_profile mp; + struct rte_mtr_error error; + uint32_t profile_id = res->profile_id; + uint16_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + /* Private shaper profile params */ + memset(&mp, 0, sizeof(struct rte_mtr_meter_profile)); + mp.alg = 0; + mp.trtcm_rfc2698.cir = res->cir; + mp.trtcm_rfc2698.pir = res->pir; + mp.trtcm_rfc2698.cbs = res->cbs; + mp.trtcm_rfc2698.pbs = res->pbs; + + ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm = { + .f = cmd_add_port_meter_profile_trtcm_parsed, + .data = NULL, + .help_str = "Add port meter profile trtcm (rfc2698)", + .tokens = { + (void *)&cmd_add_port_meter_profile_trtcm_add, + (void *)&cmd_add_port_meter_profile_trtcm_port, + (void *)&cmd_add_port_meter_profile_trtcm_meter, + (void *)&cmd_add_port_meter_profile_trtcm_profile, + (void *)&cmd_add_port_meter_profile_trtcm_port_id, + (void *)&cmd_add_port_meter_profile_trtcm_profile_id, + (void *)&cmd_add_port_meter_profile_trtcm_trtcm_rfc2698, + (void *)&cmd_add_port_meter_profile_trtcm_cir, + (void *)&cmd_add_port_meter_profile_trtcm_pir, + (void *)&cmd_add_port_meter_profile_trtcm_cbs, + (void *)&cmd_add_port_meter_profile_trtcm_pbs, + NULL, + }, +}; + +/* *** Add Port Meter Profile trtcm_rfc4115 *** */ +struct cmd_add_port_meter_profile_trtcm_rfc4115_result { + cmdline_fixed_string_t add; + cmdline_fixed_string_t port; + cmdline_fixed_string_t meter; + cmdline_fixed_string_t profile; + cmdline_fixed_string_t trtcm_rfc4115; + uint16_t port_id; + uint32_t profile_id; + uint64_t cir; + uint64_t eir; + uint64_t cbs; + uint64_t ebs; +}; + +cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_add = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_rfc4115_result, add, + "add"); +cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_port = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_rfc4115_result, + port, "port"); +cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_meter = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_rfc4115_result, + meter, "meter"); +cmdline_parse_token_string_t cmd_add_port_meter_profile_trtcm_rfc4115_profile = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_rfc4115_result, + profile, "profile"); +cmdline_parse_token_string_t + cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115 = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_rfc4115_result, + trtcm_rfc4115, "trtcm_rfc4115"); +cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_rfc4115_result, + port_id, UINT16); +cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_profile_id = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_rfc4115_result, + profile_id, UINT32); +cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cir = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_rfc4115_result, + cir, UINT64); +cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_eir = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_rfc4115_result, + eir, UINT64); +cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_cbs = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_rfc4115_result, + cbs, UINT64); +cmdline_parse_token_num_t cmd_add_port_meter_profile_trtcm_rfc4115_ebs = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_meter_profile_trtcm_rfc4115_result, + ebs, UINT64); + +static void cmd_add_port_meter_profile_trtcm_rfc4115_parsed( + void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_add_port_meter_profile_trtcm_rfc4115_result *res = + parsed_result; + struct rte_mtr_meter_profile mp; + struct rte_mtr_error error; + uint32_t profile_id = res->profile_id; + uint16_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + /* Private shaper profile params */ + memset(&mp, 0, sizeof(struct rte_mtr_meter_profile)); + mp.alg = 0; + mp.trtcm_rfc4115.cir = res->cir; + mp.trtcm_rfc4115.eir = res->eir; + mp.trtcm_rfc4115.cbs = res->cbs; + mp.trtcm_rfc4115.ebs = res->ebs; + + ret = rte_mtr_meter_profile_add(port_id, profile_id, &mp, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm_rfc4115 = { + .f = cmd_add_port_meter_profile_trtcm_rfc4115_parsed, + .data = NULL, + .help_str = "Add port meter profile trtcm (rfc4115)", + .tokens = { + (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_add, + (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port, + (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_meter, + (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile, + (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_port_id, + (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_profile_id, + (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_trtcm_rfc4115, + (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cir, + (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_eir, + (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_cbs, + (void *)&cmd_add_port_meter_profile_trtcm_rfc4115_ebs, + NULL, + }, +}; + +/* *** Delete Port Meter Profile *** */ +struct cmd_del_port_meter_profile_result { + cmdline_fixed_string_t del; + cmdline_fixed_string_t port; + cmdline_fixed_string_t meter; + cmdline_fixed_string_t profile; + uint16_t port_id; + uint32_t profile_id; +}; + +cmdline_parse_token_string_t cmd_del_port_meter_profile_del = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_meter_profile_result, del, "del"); +cmdline_parse_token_string_t cmd_del_port_meter_profile_port = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_meter_profile_result, + port, "port"); +cmdline_parse_token_string_t cmd_del_port_meter_profile_meter = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_meter_profile_result, + meter, "meter"); +cmdline_parse_token_string_t cmd_del_port_meter_profile_profile = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_meter_profile_result, + profile, "profile"); +cmdline_parse_token_num_t cmd_del_port_meter_profile_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_del_port_meter_profile_result, + port_id, UINT16); +cmdline_parse_token_num_t cmd_del_port_meter_profile_profile_id = + TOKEN_NUM_INITIALIZER( + struct cmd_del_port_meter_profile_result, + profile_id, UINT32); + +static void cmd_del_port_meter_profile_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_del_port_meter_profile_result *res = parsed_result; + struct rte_mtr_error error; + uint32_t profile_id = res->profile_id; + uint16_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + /* Delete meter profile */ + ret = rte_mtr_meter_profile_delete(port_id, profile_id, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_del_port_meter_profile = { + .f = cmd_del_port_meter_profile_parsed, + .data = NULL, + .help_str = "Delete port meter profile", + .tokens = { + (void *)&cmd_del_port_meter_profile_del, + (void *)&cmd_del_port_meter_profile_port, + (void *)&cmd_del_port_meter_profile_meter, + (void *)&cmd_del_port_meter_profile_profile, + (void *)&cmd_del_port_meter_profile_port_id, + (void *)&cmd_del_port_meter_profile_profile_id, + NULL, + }, +}; + +/* *** Create Port Meter Object *** */ +struct cmd_set_port_meter_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t port; + cmdline_fixed_string_t meter; + uint16_t port_id; + uint32_t mtr_id; + uint32_t profile_id; + cmdline_fixed_string_t g_action; + cmdline_fixed_string_t y_action; + cmdline_fixed_string_t r_action; + uint64_t statistics_mask; + uint32_t shared; +}; + +cmdline_parse_token_string_t cmd_set_port_meter_set = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_result, set, "set"); +cmdline_parse_token_string_t cmd_set_port_meter_port = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_result, port, "port"); +cmdline_parse_token_string_t cmd_set_port_meter_meter = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_result, meter, "meter"); +cmdline_parse_token_num_t cmd_set_port_meter_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_set_port_meter_result, port_id, UINT16); +cmdline_parse_token_num_t cmd_set_port_meter_mtr_id = + TOKEN_NUM_INITIALIZER( + struct cmd_set_port_meter_result, mtr_id, UINT32); +cmdline_parse_token_num_t cmd_set_port_meter_profile_id = + TOKEN_NUM_INITIALIZER( + struct cmd_set_port_meter_result, profile_id, UINT32); +cmdline_parse_token_string_t cmd_set_port_meter_g_action = + TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_result, + g_action, "R#Y#G#D"); +cmdline_parse_token_string_t cmd_set_port_meter_y_action = + TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_result, + y_action, "R#Y#G#D"); +cmdline_parse_token_string_t cmd_set_port_meter_r_action = + TOKEN_STRING_INITIALIZER(struct cmd_set_port_meter_result, + r_action, "R#Y#G#D"); +cmdline_parse_token_num_t cmd_set_port_meter_statistics_mask = + TOKEN_NUM_INITIALIZER(struct cmd_set_port_meter_result, + statistics_mask, UINT64); +cmdline_parse_token_num_t cmd_set_port_meter_shared = + TOKEN_NUM_INITIALIZER(struct cmd_set_port_meter_result, + shared, UINT32); + +static void cmd_set_port_meter_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_set_port_meter_result *res = parsed_result; + struct rte_mtr_error error; + struct rte_mtr_params params; + uint32_t mtr_id = res->mtr_id; + uint32_t shared = res->shared; + uint16_t port_id = res->port_id; + + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + /* Meter params */ + memset(¶ms, 0, sizeof(struct rte_mtr_params)); + params.meter_profile_id = res->profile_id; + params.use_prev_mtr_color = 1; + params.dscp_table = NULL; + params.meter_enable = 1; + params.action[RTE_MTR_GREEN] = + string_to_policer_action(res->g_action); + params.action[RTE_MTR_YELLOW] = + string_to_policer_action(res->y_action); + params.action[RTE_MTR_RED] = + string_to_policer_action(res->r_action); + params.stats_mask = res->statistics_mask; + + ret = rte_mtr_create(port_id, mtr_id, ¶ms, shared, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_set_port_meter = { + .f = cmd_set_port_meter_parsed, + .data = NULL, + .help_str = "Set port meter", + .tokens = { + (void *)&cmd_set_port_meter_set, + (void *)&cmd_set_port_meter_port, + (void *)&cmd_set_port_meter_meter, + (void *)&cmd_set_port_meter_port_id, + (void *)&cmd_set_port_meter_mtr_id, + (void *)&cmd_set_port_meter_profile_id, + (void *)&cmd_set_port_meter_g_action, + (void *)&cmd_set_port_meter_y_action, + (void *)&cmd_set_port_meter_r_action, + (void *)&cmd_set_port_meter_statistics_mask, + (void *)&cmd_set_port_meter_shared, + NULL, + }, +}; + +/* *** Delete Port Meter Object *** */ +struct cmd_del_port_meter_result { + cmdline_fixed_string_t del; + cmdline_fixed_string_t port; + cmdline_fixed_string_t meter; + uint16_t port_id; + uint32_t mtr_id; +}; + +cmdline_parse_token_string_t cmd_del_port_meter_del = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_meter_result, del, "del"); +cmdline_parse_token_string_t cmd_del_port_meter_port = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_meter_result, port, "port"); +cmdline_parse_token_string_t cmd_del_port_meter_meter = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_meter_result, meter, "meter"); +cmdline_parse_token_num_t cmd_del_port_meter_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_del_port_meter_result, port_id, UINT16); +cmdline_parse_token_num_t cmd_del_port_meter_mtr_id = + TOKEN_NUM_INITIALIZER( + struct cmd_del_port_meter_result, mtr_id, UINT32); + +static void cmd_del_port_meter_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_del_port_meter_result *res = parsed_result; + struct rte_mtr_error error; + uint32_t mtr_id = res->mtr_id; + uint16_t port_id = res->port_id; + + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + /* Destroy Meter */ + ret = rte_mtr_destroy(port_id, mtr_id, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_del_port_meter = { + .f = cmd_del_port_meter_parsed, + .data = NULL, + .help_str = "Delete port meter", + .tokens = { + (void *)&cmd_del_port_meter_del, + (void *)&cmd_del_port_meter_port, + (void *)&cmd_del_port_meter_meter, + (void *)&cmd_del_port_meter_port_id, + (void *)&cmd_del_port_meter_mtr_id, + NULL, + }, +}; + +/* *** Set Port Meter Profile *** */ +struct cmd_set_port_meter_profile_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t port; + cmdline_fixed_string_t meter; + cmdline_fixed_string_t profile; + uint16_t port_id; + uint32_t mtr_id; + uint32_t profile_id; +}; + +cmdline_parse_token_string_t cmd_set_port_meter_profile_set = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_profile_result, set, "set"); +cmdline_parse_token_string_t cmd_set_port_meter_profile_port = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_profile_result, port, "port"); +cmdline_parse_token_string_t cmd_set_port_meter_profile_meter = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_profile_result, meter, "meter"); +cmdline_parse_token_string_t cmd_set_port_meter_profile_profile = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_profile_result, profile, "profile"); +cmdline_parse_token_num_t cmd_set_port_meter_profile_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_set_port_meter_profile_result, port_id, UINT16); +cmdline_parse_token_num_t cmd_set_port_meter_profile_mtr_id = + TOKEN_NUM_INITIALIZER( + struct cmd_set_port_meter_profile_result, mtr_id, UINT32); +cmdline_parse_token_num_t cmd_set_port_meter_profile_profile_id = + TOKEN_NUM_INITIALIZER( + struct cmd_set_port_meter_profile_result, profile_id, UINT32); + +static void cmd_set_port_meter_profile_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_set_port_meter_profile_result *res = parsed_result; + struct rte_mtr_error error; + uint32_t mtr_id = res->mtr_id; + uint32_t profile_id = res->profile_id; + uint16_t port_id = res->port_id; + + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + /* Set meter profile */ + ret = rte_mtr_meter_profile_update(port_id, mtr_id, + profile_id, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_set_port_meter_profile = { + .f = cmd_set_port_meter_profile_parsed, + .data = NULL, + .help_str = "Set port meter profile", + .tokens = { + (void *)&cmd_set_port_meter_profile_set, + (void *)&cmd_set_port_meter_profile_port, + (void *)&cmd_set_port_meter_profile_meter, + (void *)&cmd_set_port_meter_profile_profile, + (void *)&cmd_set_port_meter_profile_port_id, + (void *)&cmd_set_port_meter_profile_mtr_id, + (void *)&cmd_set_port_meter_profile_profile_id, + NULL, + }, +}; + +/* *** Set Port Meter Policer Action *** */ +struct cmd_set_port_meter_policer_action_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t port; + cmdline_fixed_string_t meter; + cmdline_fixed_string_t policer; + cmdline_fixed_string_t action; + uint16_t port_id; + uint32_t mtr_id; + cmdline_fixed_string_t color; + cmdline_fixed_string_t policer_action; +}; + +cmdline_parse_token_string_t cmd_set_port_meter_policer_action_set = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_policer_action_result, set, "set"); +cmdline_parse_token_string_t cmd_set_port_meter_policer_action_port = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_policer_action_result, port, "port"); +cmdline_parse_token_string_t cmd_set_port_meter_policer_action_meter = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_policer_action_result, meter, + "meter"); +cmdline_parse_token_string_t cmd_set_port_meter_policer_action_policer = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_policer_action_result, policer, + "policer"); +cmdline_parse_token_string_t cmd_set_port_meter_policer_action_action = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_policer_action_result, action, + "action"); +cmdline_parse_token_num_t cmd_set_port_meter_policer_action_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_set_port_meter_policer_action_result, port_id, + UINT16); +cmdline_parse_token_num_t cmd_set_port_meter_policer_action_mtr_id = + TOKEN_NUM_INITIALIZER( + struct cmd_set_port_meter_policer_action_result, mtr_id, + UINT32); +cmdline_parse_token_string_t cmd_set_port_meter_policer_action_color = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_policer_action_result, color, + "G#Y#R"); +cmdline_parse_token_string_t cmd_set_port_meter_policer_action_policer_action = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_policer_action_result, + policer_action, "G#Y#R#D"); + +static void cmd_set_port_meter_policer_action_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_set_port_meter_policer_action_result *res = parsed_result; + enum rte_mtr_color color; + enum rte_mtr_policer_action action[RTE_MTR_COLORS]; + struct rte_mtr_error error; + uint32_t mtr_id = res->mtr_id; + uint16_t port_id = res->port_id; + char *c = res->color; + char *a = res->policer_action; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + /* Color */ + if (strcmp(c, "G") == 0) + color = RTE_MTR_GREEN; + else if (strcmp(c, "Y") == 0) + color = RTE_MTR_YELLOW; + else + color = RTE_MTR_RED; + + /* Action */ + if (strcmp(a, "G") == 0) + action[color] = MTR_POLICER_ACTION_COLOR_GREEN; + else if (strcmp(a, "Y") == 0) + action[color] = MTR_POLICER_ACTION_COLOR_YELLOW; + else if (strcmp(a, "R") == 0) + action[color] = MTR_POLICER_ACTION_COLOR_RED; + else + action[color] = MTR_POLICER_ACTION_DROP; + + ret = rte_mtr_policer_actions_update(port_id, mtr_id, + 1 << color, action, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_set_port_meter_policer_action = { + .f = cmd_set_port_meter_policer_action_parsed, + .data = NULL, + .help_str = "Set port meter policer action", + .tokens = { + (void *)&cmd_set_port_meter_policer_action_set, + (void *)&cmd_set_port_meter_policer_action_port, + (void *)&cmd_set_port_meter_policer_action_meter, + (void *)&cmd_set_port_meter_policer_action_policer, + (void *)&cmd_set_port_meter_policer_action_action, + (void *)&cmd_set_port_meter_policer_action_port_id, + (void *)&cmd_set_port_meter_policer_action_mtr_id, + (void *)&cmd_set_port_meter_policer_action_color, + (void *)&cmd_set_port_meter_policer_action_policer_action, + NULL, + }, +}; + +/* *** Set Port Meter Stats Mask *** */ +struct cmd_set_port_meter_stats_mask_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t port; + cmdline_fixed_string_t meter; + cmdline_fixed_string_t stats; + cmdline_fixed_string_t mask; + uint16_t port_id; + uint32_t mtr_id; + uint64_t stats_mask; +}; + +cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_set = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_stats_mask_result, set, "set"); +cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_port = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_stats_mask_result, port, "port"); +cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_meter = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_stats_mask_result, meter, "meter"); +cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_stats = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_stats_mask_result, stats, "stats"); +cmdline_parse_token_string_t cmd_set_port_meter_stats_mask_mask = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_meter_stats_mask_result, mask, "mask"); +cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_set_port_meter_stats_mask_result, port_id, UINT16); +cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_mtr_id = + TOKEN_NUM_INITIALIZER( + struct cmd_set_port_meter_stats_mask_result, mtr_id, UINT32); +cmdline_parse_token_num_t cmd_set_port_meter_stats_mask_stats_mask = + TOKEN_NUM_INITIALIZER( + struct cmd_set_port_meter_stats_mask_result, stats_mask, + UINT64); + +static void cmd_set_port_meter_stats_mask_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_set_port_meter_stats_mask_result *res = parsed_result; + struct rte_mtr_error error; + uint64_t stats_mask = res->stats_mask; + uint32_t mtr_id = res->mtr_id; + uint16_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + ret = rte_mtr_stats_update(port_id, mtr_id, stats_mask, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_set_port_meter_stats_mask = { + .f = cmd_set_port_meter_stats_mask_parsed, + .data = NULL, + .help_str = "Set port meter stats mask", + .tokens = { + (void *)&cmd_set_port_meter_stats_mask_set, + (void *)&cmd_set_port_meter_stats_mask_port, + (void *)&cmd_set_port_meter_stats_mask_meter, + (void *)&cmd_set_port_meter_stats_mask_stats, + (void *)&cmd_set_port_meter_stats_mask_mask, + (void *)&cmd_set_port_meter_stats_mask_port_id, + (void *)&cmd_set_port_meter_stats_mask_mtr_id, + (void *)&cmd_set_port_meter_stats_mask_stats_mask, + NULL, + }, +}; + +/* *** Show Port Meter Stats *** */ +struct cmd_show_port_meter_stats_result { + cmdline_fixed_string_t show; + cmdline_fixed_string_t port; + cmdline_fixed_string_t meter; + cmdline_fixed_string_t stats; + uint16_t port_id; + uint32_t mtr_id; + uint32_t clear; +}; + +cmdline_parse_token_string_t cmd_show_port_meter_stats_show = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_meter_stats_result, show, "show"); +cmdline_parse_token_string_t cmd_show_port_meter_stats_port = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_meter_stats_result, port, "port"); +cmdline_parse_token_string_t cmd_show_port_meter_stats_meter = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_meter_stats_result, meter, "meter"); +cmdline_parse_token_string_t cmd_show_port_meter_stats_stats = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_meter_stats_result, stats, "stats"); +cmdline_parse_token_num_t cmd_show_port_meter_stats_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_show_port_meter_stats_result, port_id, UINT16); +cmdline_parse_token_num_t cmd_show_port_meter_stats_mtr_id = + TOKEN_NUM_INITIALIZER( + struct cmd_show_port_meter_stats_result, mtr_id, UINT32); +cmdline_parse_token_num_t cmd_show_port_meter_stats_clear = + TOKEN_NUM_INITIALIZER( + struct cmd_show_port_meter_stats_result, clear, UINT32); + +static void cmd_show_port_meter_stats_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_show_port_meter_stats_result *res = parsed_result; + struct rte_mtr_stats stats; + uint64_t stats_mask = 0; + struct rte_mtr_error error; + uint32_t mtr_id = res->mtr_id; + uint32_t clear = res->clear; + uint16_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + memset(&stats, 0, sizeof(struct rte_mtr_stats)); + ret = rte_mtr_stats_read(port_id, mtr_id, &stats, + &stats_mask, clear, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } + + /* Display stats */ + if (stats_mask & RTE_MTR_STATS_N_PKTS_GREEN) + printf("\tPkts G: %" PRIu64 "\n", + stats.n_pkts[RTE_MTR_GREEN]); + if (stats_mask & RTE_MTR_STATS_N_BYTES_GREEN) + printf("\tBytes G: %" PRIu64 "\n", + stats.n_bytes[RTE_MTR_GREEN]); + if (stats_mask & RTE_MTR_STATS_N_PKTS_YELLOW) + printf("\tPkts Y: %" PRIu64 "\n", + stats.n_pkts[RTE_MTR_YELLOW]); + if (stats_mask & RTE_MTR_STATS_N_BYTES_YELLOW) + printf("\tBytes Y: %" PRIu64 "\n", + stats.n_bytes[RTE_MTR_YELLOW]); + if (stats_mask & RTE_MTR_STATS_N_PKTS_RED) + printf("\tPkts R: %" PRIu64 "\n", + stats.n_pkts[RTE_MTR_RED]); + if (stats_mask & RTE_MTR_STATS_N_BYTES_RED) + printf("\tBytes Y: %" PRIu64 "\n", + stats.n_bytes[RTE_MTR_RED]); + if (stats_mask & RTE_MTR_STATS_N_PKTS_DROPPED) + printf("\tPkts DROPPED: %" PRIu64 "\n", + stats.n_pkts_dropped); + if (stats_mask & RTE_MTR_STATS_N_BYTES_DROPPED) + printf("\tBytes DROPPED: %" PRIu64 "\n", + stats.n_bytes_dropped); +} + +cmdline_parse_inst_t cmd_show_port_meter_stats = { + .f = cmd_show_port_meter_stats_parsed, + .data = NULL, + .help_str = "Show port meter stats", + .tokens = { + (void *)&cmd_show_port_meter_stats_show, + (void *)&cmd_show_port_meter_stats_port, + (void *)&cmd_show_port_meter_stats_meter, + (void *)&cmd_show_port_meter_stats_stats, + (void *)&cmd_show_port_meter_stats_port_id, + (void *)&cmd_show_port_meter_stats_mtr_id, + (void *)&cmd_show_port_meter_stats_clear, + NULL, + }, +}; diff --git a/app/test-pmd/cmdline_mtr.h b/app/test-pmd/cmdline_mtr.h new file mode 100644 index 00000000..5d599efc --- /dev/null +++ b/app/test-pmd/cmdline_mtr.h @@ -0,0 +1,49 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2017 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CMDLINE_MTR_H_ +#define _CMDLINE_MTR_H_ + +/* Traffic Metering and Policing */ +extern cmdline_parse_inst_t cmd_add_port_meter_profile_srtcm; +extern cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm; +extern cmdline_parse_inst_t cmd_add_port_meter_profile_trtcm_rfc4115; +extern cmdline_parse_inst_t cmd_del_port_meter_profile; +extern cmdline_parse_inst_t cmd_set_port_meter; +extern cmdline_parse_inst_t cmd_del_port_meter; +extern cmdline_parse_inst_t cmd_set_port_meter_profile; +extern cmdline_parse_inst_t cmd_set_port_meter_policer_action; +extern cmdline_parse_inst_t cmd_set_port_meter_stats_mask; +extern cmdline_parse_inst_t cmd_show_port_meter_stats; + +#endif /* _CMDLINE_MTR_H_ */ diff --git a/app/test-pmd/cmdline_tm.c b/app/test-pmd/cmdline_tm.c new file mode 100644 index 00000000..4acef98f --- /dev/null +++ b/app/test-pmd/cmdline_tm.c @@ -0,0 +1,2071 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2017 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include <cmdline_parse.h> +#include <cmdline_parse_num.h> +#include <cmdline_parse_string.h> + +#include <rte_ethdev.h> +#include <rte_flow.h> +#include <rte_tm.h> + +#include "testpmd.h" +#include "cmdline_tm.h" + +#define PARSE_DELIMITER " \f\n\r\t\v" +#define MAX_NUM_SHARED_SHAPERS 256 + +#define skip_white_spaces(pos) \ +({ \ + __typeof__(pos) _p = (pos); \ + for ( ; isspace(*_p); _p++) \ + ; \ + _p; \ +}) + +/** Display TM Error Message */ +static void +print_err_msg(struct rte_tm_error *error) +{ + static const char *const errstrlist[] = { + [RTE_TM_ERROR_TYPE_NONE] = "no error", + [RTE_TM_ERROR_TYPE_UNSPECIFIED] = "cause unspecified", + [RTE_TM_ERROR_TYPE_CAPABILITIES] + = "capability parameter null", + [RTE_TM_ERROR_TYPE_LEVEL_ID] = "level id", + [RTE_TM_ERROR_TYPE_WRED_PROFILE] + = "wred profile null", + [RTE_TM_ERROR_TYPE_WRED_PROFILE_GREEN] = "wred profile(green)", + [RTE_TM_ERROR_TYPE_WRED_PROFILE_YELLOW] + = "wred profile(yellow)", + [RTE_TM_ERROR_TYPE_WRED_PROFILE_RED] = "wred profile(red)", + [RTE_TM_ERROR_TYPE_WRED_PROFILE_ID] = "wred profile id", + [RTE_TM_ERROR_TYPE_SHARED_WRED_CONTEXT_ID] + = "shared wred context id", + [RTE_TM_ERROR_TYPE_SHAPER_PROFILE] = "shaper profile null", + [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_RATE] + = "committed rate field (shaper profile)", + [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_COMMITTED_SIZE] + = "committed size field (shaper profile)", + [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_RATE] + = "peak rate field (shaper profile)", + [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PEAK_SIZE] + = "peak size field (shaper profile)", + [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_PKT_ADJUST_LEN] + = "packet adjust length field (shaper profile)", + [RTE_TM_ERROR_TYPE_SHAPER_PROFILE_ID] = "shaper profile id", + [RTE_TM_ERROR_TYPE_SHARED_SHAPER_ID] = "shared shaper id", + [RTE_TM_ERROR_TYPE_NODE_PARENT_NODE_ID] = "parent node id", + [RTE_TM_ERROR_TYPE_NODE_PRIORITY] = "node priority", + [RTE_TM_ERROR_TYPE_NODE_WEIGHT] = "node weight", + [RTE_TM_ERROR_TYPE_NODE_PARAMS] = "node parameter null", + [RTE_TM_ERROR_TYPE_NODE_PARAMS_SHAPER_PROFILE_ID] + = "shaper profile id field (node params)", + [RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_SHAPER_ID] + = "shared shaper id field (node params)", + [RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_SHAPERS] + = "num shared shapers field (node params)", + [RTE_TM_ERROR_TYPE_NODE_PARAMS_WFQ_WEIGHT_MODE] + = "wfq weght mode field (node params)", + [RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SP_PRIORITIES] + = "num strict priorities field (node params)", + [RTE_TM_ERROR_TYPE_NODE_PARAMS_CMAN] + = "congestion management mode field (node params)", + [RTE_TM_ERROR_TYPE_NODE_PARAMS_WRED_PROFILE_ID] = + "wred profile id field (node params)", + [RTE_TM_ERROR_TYPE_NODE_PARAMS_SHARED_WRED_CONTEXT_ID] + = "shared wred context id field (node params)", + [RTE_TM_ERROR_TYPE_NODE_PARAMS_N_SHARED_WRED_CONTEXTS] + = "num shared wred contexts field (node params)", + [RTE_TM_ERROR_TYPE_NODE_PARAMS_STATS] + = "stats field (node params)", + [RTE_TM_ERROR_TYPE_NODE_ID] = "node id", + }; + + const char *errstr; + char buf[64]; + + if ((unsigned int)error->type >= RTE_DIM(errstrlist) || + !errstrlist[error->type]) + errstr = "unknown type"; + else + errstr = errstrlist[error->type]; + + if (error->cause) + snprintf(buf, sizeof(buf), "cause: %p, ", error->cause); + + printf("%s: %s%s (error %d)\n", errstr, error->cause ? buf : "", + error->message ? error->message : "(no stated reason)", + error->type); +} + +static int +read_uint64(uint64_t *value, const char *p) +{ + char *next; + uint64_t val; + + p = skip_white_spaces(p); + if (!isdigit(*p)) + return -EINVAL; + + val = strtoul(p, &next, 10); + if (p == next) + return -EINVAL; + + p = next; + switch (*p) { + case 'T': + val *= 1024ULL; + /* fall through */ + case 'G': + val *= 1024ULL; + /* fall through */ + case 'M': + val *= 1024ULL; + /* fall through */ + case 'k': + case 'K': + val *= 1024ULL; + p++; + break; + } + + p = skip_white_spaces(p); + if (*p != '\0') + return -EINVAL; + + *value = val; + return 0; +} + +static int +read_uint32(uint32_t *value, const char *p) +{ + uint64_t val = 0; + int ret = read_uint64(&val, p); + + if (ret < 0) + return ret; + + if (val > UINT32_MAX) + return -ERANGE; + + *value = val; + return 0; +} + +static int +parse_multi_ss_id_str(char *s_str, uint32_t *n_ssp, uint32_t shaper_id[]) +{ + uint32_t n_shared_shapers = 0, i = 0; + char *token; + + /* First token: num of shared shapers */ + token = strtok_r(s_str, PARSE_DELIMITER, &s_str); + if (token == NULL) + return -1; + + if (read_uint32(&n_shared_shapers, token)) + return -1; + + /* Check: num of shared shaper */ + if (n_shared_shapers >= MAX_NUM_SHARED_SHAPERS) { + printf(" Number of shared shapers exceed the max (error)\n"); + return -1; + } + + /* Parse shared shaper ids */ + while (1) { + token = strtok_r(s_str, PARSE_DELIMITER, &s_str); + if ((token != NULL && n_shared_shapers == 0) || + (token == NULL && i < n_shared_shapers)) + return -1; + + if (token == NULL) + break; + + if (read_uint32(&shaper_id[i], token)) + return -1; + i++; + } + *n_ssp = n_shared_shapers; + + return 0; +} +/* *** Port TM Capability *** */ +struct cmd_show_port_tm_cap_result { + cmdline_fixed_string_t show; + cmdline_fixed_string_t port; + cmdline_fixed_string_t tm; + cmdline_fixed_string_t cap; + uint16_t port_id; +}; + +cmdline_parse_token_string_t cmd_show_port_tm_cap_show = + TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result, + show, "show"); +cmdline_parse_token_string_t cmd_show_port_tm_cap_port = + TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result, + port, "port"); +cmdline_parse_token_string_t cmd_show_port_tm_cap_tm = + TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result, + tm, "tm"); +cmdline_parse_token_string_t cmd_show_port_tm_cap_cap = + TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_cap_result, + cap, "cap"); +cmdline_parse_token_num_t cmd_show_port_tm_cap_port_id = + TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_cap_result, + port_id, UINT16); + +static void cmd_show_port_tm_cap_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_show_port_tm_cap_result *res = parsed_result; + struct rte_tm_capabilities cap; + struct rte_tm_error error; + portid_t port_id = res->port_id; + uint32_t i; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + memset(&cap, 0, sizeof(struct rte_tm_capabilities)); + ret = rte_tm_capabilities_get(port_id, &cap, &error); + if (ret) { + print_err_msg(&error); + return; + } + + printf("\n**** Port TM Capabilities ****\n\n"); + printf("cap.n_nodes_max %" PRIu32 "\n", cap.n_nodes_max); + printf("cap.n_levels_max %" PRIu32 "\n", cap.n_levels_max); + printf("cap.non_leaf_nodes_identical %" PRId32 "\n", + cap.non_leaf_nodes_identical); + printf("cap.leaf_nodes_identical %" PRId32 "\n", + cap.leaf_nodes_identical); + printf("cap.shaper_n_max %u\n", cap.shaper_n_max); + printf("cap.shaper_private_n_max %" PRIu32 "\n", + cap.shaper_private_n_max); + printf("cap.shaper_private_dual_rate_n_max %" PRId32 "\n", + cap.shaper_private_dual_rate_n_max); + printf("cap.shaper_private_rate_min %" PRIu64 "\n", + cap.shaper_private_rate_min); + printf("cap.shaper_private_rate_max %" PRIu64 "\n", + cap.shaper_private_rate_max); + printf("cap.shaper_shared_n_max %" PRIu32 "\n", + cap.shaper_shared_n_max); + printf("cap.shaper_shared_n_nodes_per_shaper_max %" PRIu32 "\n", + cap.shaper_shared_n_nodes_per_shaper_max); + printf("cap.shaper_shared_n_shapers_per_node_max %" PRIu32 "\n", + cap.shaper_shared_n_shapers_per_node_max); + printf("cap.shaper_shared_dual_rate_n_max %" PRIu32 "\n", + cap.shaper_shared_dual_rate_n_max); + printf("cap.shaper_shared_rate_min %" PRIu64 "\n", + cap.shaper_shared_rate_min); + printf("cap.shaper_shared_rate_max %" PRIu64 "\n", + cap.shaper_shared_rate_max); + printf("cap.shaper_pkt_length_adjust_min %" PRId32 "\n", + cap.shaper_pkt_length_adjust_min); + printf("cap.shaper_pkt_length_adjust_max %" PRId32 "\n", + cap.shaper_pkt_length_adjust_max); + printf("cap.sched_n_children_max %" PRIu32 "\n", + cap.sched_n_children_max); + printf("cap.sched_sp_n_priorities_max %" PRIu32 "\n", + cap.sched_sp_n_priorities_max); + printf("cap.sched_wfq_n_children_per_group_max %" PRIu32 "\n", + cap.sched_wfq_n_children_per_group_max); + printf("cap.sched_wfq_n_groups_max %" PRIu32 "\n", + cap.sched_wfq_n_groups_max); + printf("cap.sched_wfq_weight_max %" PRIu32 "\n", + cap.sched_wfq_weight_max); + printf("cap.cman_head_drop_supported %" PRId32 "\n", + cap.cman_head_drop_supported); + printf("cap.cman_wred_context_n_max %" PRIu32 "\n", + cap.cman_wred_context_n_max); + printf("cap.cman_wred_context_private_n_max %" PRIu32 "\n", + cap.cman_wred_context_private_n_max); + printf("cap.cman_wred_context_shared_n_max %" PRIu32 "\n", + cap.cman_wred_context_shared_n_max); + printf("cap.cman_wred_context_shared_n_nodes_per_context_max %" PRIu32 + "\n", cap.cman_wred_context_shared_n_nodes_per_context_max); + printf("cap.cman_wred_context_shared_n_contexts_per_node_max %" PRIu32 + "\n", cap.cman_wred_context_shared_n_contexts_per_node_max); + + for (i = 0; i < RTE_TM_COLORS; i++) { + printf("cap.mark_vlan_dei_supported %" PRId32 "\n", + cap.mark_vlan_dei_supported[i]); + printf("cap.mark_ip_ecn_tcp_supported %" PRId32 "\n", + cap.mark_ip_ecn_tcp_supported[i]); + printf("cap.mark_ip_ecn_sctp_supported %" PRId32 "\n", + cap.mark_ip_ecn_sctp_supported[i]); + printf("cap.mark_ip_dscp_supported %" PRId32 "\n", + cap.mark_ip_dscp_supported[i]); + } + + printf("cap.dynamic_update_mask %" PRIx64 "\n", + cap.dynamic_update_mask); + printf("cap.stats_mask %" PRIx64 "\n", cap.stats_mask); +} + +cmdline_parse_inst_t cmd_show_port_tm_cap = { + .f = cmd_show_port_tm_cap_parsed, + .data = NULL, + .help_str = "Show Port TM Capabilities", + .tokens = { + (void *)&cmd_show_port_tm_cap_show, + (void *)&cmd_show_port_tm_cap_port, + (void *)&cmd_show_port_tm_cap_tm, + (void *)&cmd_show_port_tm_cap_cap, + (void *)&cmd_show_port_tm_cap_port_id, + NULL, + }, +}; + +/* *** Port TM Hierarchical Level Capability *** */ +struct cmd_show_port_tm_level_cap_result { + cmdline_fixed_string_t show; + cmdline_fixed_string_t port; + cmdline_fixed_string_t tm; + cmdline_fixed_string_t level; + cmdline_fixed_string_t cap; + uint16_t port_id; + uint32_t level_id; +}; + +cmdline_parse_token_string_t cmd_show_port_tm_level_cap_show = + TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result, + show, "show"); +cmdline_parse_token_string_t cmd_show_port_tm_level_cap_port = + TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result, + port, "port"); +cmdline_parse_token_string_t cmd_show_port_tm_level_cap_tm = + TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result, + tm, "tm"); +cmdline_parse_token_string_t cmd_show_port_tm_level_cap_level = + TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result, + level, "level"); +cmdline_parse_token_string_t cmd_show_port_tm_level_cap_cap = + TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_level_cap_result, + cap, "cap"); +cmdline_parse_token_num_t cmd_show_port_tm_level_cap_port_id = + TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_level_cap_result, + port_id, UINT16); +cmdline_parse_token_num_t cmd_show_port_tm_level_cap_level_id = + TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_level_cap_result, + level_id, UINT32); + + +static void cmd_show_port_tm_level_cap_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_show_port_tm_level_cap_result *res = parsed_result; + struct rte_tm_level_capabilities lcap; + struct rte_tm_error error; + portid_t port_id = res->port_id; + uint32_t level_id = res->level_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + memset(&lcap, 0, sizeof(struct rte_tm_level_capabilities)); + ret = rte_tm_level_capabilities_get(port_id, level_id, &lcap, &error); + if (ret) { + print_err_msg(&error); + return; + } + printf("\n** Port TM Hierarchy level %" PRIu32 " Capability **\n\n", + level_id); + + printf("cap.n_nodes_max %" PRIu32 "\n", lcap.n_nodes_max); + printf("cap.n_nodes_nonleaf_max %" PRIu32 "\n", + lcap.n_nodes_nonleaf_max); + printf("cap.n_nodes_leaf_max %" PRIu32 "\n", lcap.n_nodes_leaf_max); + printf("cap.non_leaf_nodes_identical %" PRId32 "\n", + lcap.non_leaf_nodes_identical); + printf("cap.leaf_nodes_identical %" PRId32 "\n", + lcap.leaf_nodes_identical); + if (level_id <= 3) { + printf("cap.nonleaf.shaper_private_supported %" PRId32 "\n", + lcap.nonleaf.shaper_private_supported); + printf("cap.nonleaf.shaper_private_dual_rate_supported %" PRId32 + "\n", lcap.nonleaf.shaper_private_dual_rate_supported); + printf("cap.nonleaf.shaper_private_rate_min %" PRIu64 "\n", + lcap.nonleaf.shaper_private_rate_min); + printf("cap.nonleaf.shaper_private_rate_max %" PRIu64 "\n", + lcap.nonleaf.shaper_private_rate_max); + printf("cap.nonleaf.shaper_shared_n_max %" PRIu32 "\n", + lcap.nonleaf.shaper_shared_n_max); + printf("cap.nonleaf.sched_n_children_max %" PRIu32 "\n", + lcap.nonleaf.sched_n_children_max); + printf("cap.nonleaf.sched_sp_n_priorities_max %" PRIu32 "\n", + lcap.nonleaf.sched_sp_n_priorities_max); + printf("cap.nonleaf.sched_wfq_n_children_per_group_max %" PRIu32 + "\n", lcap.nonleaf.sched_wfq_n_children_per_group_max); + printf("cap.nonleaf.sched_wfq_n_groups_max %" PRIu32 "\n", + lcap.nonleaf.sched_wfq_n_groups_max); + printf("cap.nonleaf.sched_wfq_weight_max %" PRIu32 "\n", + lcap.nonleaf.sched_wfq_weight_max); + printf("cap.nonleaf.stats_mask %" PRIx64 "\n", + lcap.nonleaf.stats_mask); + } else { + printf("cap.leaf.shaper_private_supported %" PRId32 "\n", + lcap.leaf.shaper_private_supported); + printf("cap.leaf.shaper_private_dual_rate_supported %" PRId32 + "\n", lcap.leaf.shaper_private_dual_rate_supported); + printf("cap.leaf.shaper_private_rate_min %" PRIu64 "\n", + lcap.leaf.shaper_private_rate_min); + printf("cap.leaf.shaper_private_rate_max %" PRIu64 "\n", + lcap.leaf.shaper_private_rate_max); + printf("cap.leaf.shaper_shared_n_max %" PRIu32 "\n", + lcap.leaf.shaper_shared_n_max); + printf("cap.leaf.cman_head_drop_supported %" PRId32 "\n", + lcap.leaf.cman_head_drop_supported); + printf("cap.leaf.cman_wred_context_private_supported %" PRId32 + "\n", lcap.leaf.cman_wred_context_private_supported); + printf("cap.leaf.cman_wred_context_shared_n_max %" PRIu32 "\n", + lcap.leaf.cman_wred_context_shared_n_max); + printf("cap.leaf.stats_mask %" PRIx64 "\n", + lcap.leaf.stats_mask); + } +} + +cmdline_parse_inst_t cmd_show_port_tm_level_cap = { + .f = cmd_show_port_tm_level_cap_parsed, + .data = NULL, + .help_str = "Show Port TM Hierarhical level Capabilities", + .tokens = { + (void *)&cmd_show_port_tm_level_cap_show, + (void *)&cmd_show_port_tm_level_cap_port, + (void *)&cmd_show_port_tm_level_cap_tm, + (void *)&cmd_show_port_tm_level_cap_level, + (void *)&cmd_show_port_tm_level_cap_cap, + (void *)&cmd_show_port_tm_level_cap_port_id, + (void *)&cmd_show_port_tm_level_cap_level_id, + NULL, + }, +}; + +/* *** Port TM Hierarchy Node Capability *** */ +struct cmd_show_port_tm_node_cap_result { + cmdline_fixed_string_t show; + cmdline_fixed_string_t port; + cmdline_fixed_string_t tm; + cmdline_fixed_string_t node; + cmdline_fixed_string_t cap; + uint16_t port_id; + uint32_t node_id; +}; + +cmdline_parse_token_string_t cmd_show_port_tm_node_cap_show = + TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result, + show, "show"); +cmdline_parse_token_string_t cmd_show_port_tm_node_cap_port = + TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result, + port, "port"); +cmdline_parse_token_string_t cmd_show_port_tm_node_cap_tm = + TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result, + tm, "tm"); +cmdline_parse_token_string_t cmd_show_port_tm_node_cap_node = + TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result, + node, "node"); +cmdline_parse_token_string_t cmd_show_port_tm_node_cap_cap = + TOKEN_STRING_INITIALIZER(struct cmd_show_port_tm_node_cap_result, + cap, "cap"); +cmdline_parse_token_num_t cmd_show_port_tm_node_cap_port_id = + TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_cap_result, + port_id, UINT16); +cmdline_parse_token_num_t cmd_show_port_tm_node_cap_node_id = + TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_cap_result, + node_id, UINT32); + +static void cmd_show_port_tm_node_cap_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_show_port_tm_node_cap_result *res = parsed_result; + struct rte_tm_node_capabilities ncap; + struct rte_tm_error error; + uint32_t node_id = res->node_id; + portid_t port_id = res->port_id; + int ret, is_leaf = 0; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + /* Node id must be valid */ + ret = rte_tm_node_type_get(port_id, node_id, &is_leaf, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } + + memset(&ncap, 0, sizeof(struct rte_tm_node_capabilities)); + ret = rte_tm_node_capabilities_get(port_id, node_id, &ncap, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } + printf("\n** Port TM Hierarchy node %" PRIu32 " Capability **\n\n", + node_id); + printf("cap.shaper_private_supported %" PRId32 "\n", + ncap.shaper_private_supported); + printf("cap.shaper_private_dual_rate_supported %" PRId32 "\n", + ncap.shaper_private_dual_rate_supported); + printf("cap.shaper_private_rate_min %" PRIu64 "\n", + ncap.shaper_private_rate_min); + printf("cap.shaper_private_rate_max %" PRIu64 "\n", + ncap.shaper_private_rate_max); + printf("cap.shaper_shared_n_max %" PRIu32 "\n", + ncap.shaper_shared_n_max); + if (!is_leaf) { + printf("cap.nonleaf.sched_n_children_max %" PRIu32 "\n", + ncap.nonleaf.sched_n_children_max); + printf("cap.nonleaf.sched_sp_n_priorities_max %" PRIu32 "\n", + ncap.nonleaf.sched_sp_n_priorities_max); + printf("cap.nonleaf.sched_wfq_n_children_per_group_max %" PRIu32 + "\n", ncap.nonleaf.sched_wfq_n_children_per_group_max); + printf("cap.nonleaf.sched_wfq_n_groups_max %" PRIu32 "\n", + ncap.nonleaf.sched_wfq_n_groups_max); + printf("cap.nonleaf.sched_wfq_weight_max %" PRIu32 "\n", + ncap.nonleaf.sched_wfq_weight_max); + } else { + printf("cap.leaf.cman_head_drop_supported %" PRId32 "\n", + ncap.leaf.cman_head_drop_supported); + printf("cap.leaf.cman_wred_context_private_supported %" PRId32 + "\n", ncap.leaf.cman_wred_context_private_supported); + printf("cap.leaf.cman_wred_context_shared_n_max %" PRIu32 "\n", + ncap.leaf.cman_wred_context_shared_n_max); + } + printf("cap.stats_mask %" PRIx64 "\n", ncap.stats_mask); +} + +cmdline_parse_inst_t cmd_show_port_tm_node_cap = { + .f = cmd_show_port_tm_node_cap_parsed, + .data = NULL, + .help_str = "Show Port TM Hierarchy node capabilities", + .tokens = { + (void *)&cmd_show_port_tm_node_cap_show, + (void *)&cmd_show_port_tm_node_cap_port, + (void *)&cmd_show_port_tm_node_cap_tm, + (void *)&cmd_show_port_tm_node_cap_node, + (void *)&cmd_show_port_tm_node_cap_cap, + (void *)&cmd_show_port_tm_node_cap_port_id, + (void *)&cmd_show_port_tm_node_cap_node_id, + NULL, + }, +}; + +/* *** Show Port TM Node Statistics *** */ +struct cmd_show_port_tm_node_stats_result { + cmdline_fixed_string_t show; + cmdline_fixed_string_t port; + cmdline_fixed_string_t tm; + cmdline_fixed_string_t node; + cmdline_fixed_string_t stats; + uint16_t port_id; + uint32_t node_id; + uint32_t clear; +}; + +cmdline_parse_token_string_t cmd_show_port_tm_node_stats_show = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_tm_node_stats_result, show, "show"); +cmdline_parse_token_string_t cmd_show_port_tm_node_stats_port = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_tm_node_stats_result, port, "port"); +cmdline_parse_token_string_t cmd_show_port_tm_node_stats_tm = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_tm_node_stats_result, tm, "tm"); +cmdline_parse_token_string_t cmd_show_port_tm_node_stats_node = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_tm_node_stats_result, node, "node"); +cmdline_parse_token_string_t cmd_show_port_tm_node_stats_stats = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_tm_node_stats_result, stats, "stats"); +cmdline_parse_token_num_t cmd_show_port_tm_node_stats_port_id = + TOKEN_NUM_INITIALIZER(struct cmd_show_port_tm_node_stats_result, + port_id, UINT16); +cmdline_parse_token_num_t cmd_show_port_tm_node_stats_node_id = + TOKEN_NUM_INITIALIZER( + struct cmd_show_port_tm_node_stats_result, + node_id, UINT32); +cmdline_parse_token_num_t cmd_show_port_tm_node_stats_clear = + TOKEN_NUM_INITIALIZER( + struct cmd_show_port_tm_node_stats_result, clear, UINT32); + +static void cmd_show_port_tm_node_stats_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_show_port_tm_node_stats_result *res = parsed_result; + struct rte_tm_node_stats stats; + struct rte_tm_error error; + uint64_t stats_mask = 0; + uint32_t node_id = res->node_id; + uint32_t clear = res->clear; + portid_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + /* Port status */ + if (!port_is_started(port_id)) { + printf(" Port %u not started (error)\n", port_id); + return; + } + + memset(&stats, 0, sizeof(struct rte_tm_node_stats)); + ret = rte_tm_node_stats_read(port_id, node_id, &stats, + &stats_mask, clear, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } + + /* Display stats */ + if (stats_mask & RTE_TM_STATS_N_PKTS) + printf("\tPkts scheduled from node: %" PRIu64 "\n", + stats.n_pkts); + if (stats_mask & RTE_TM_STATS_N_BYTES) + printf("\tBytes scheduled from node: %" PRIu64 "\n", + stats.n_bytes); + if (stats_mask & RTE_TM_STATS_N_PKTS_GREEN_DROPPED) + printf("\tPkts dropped (green): %" PRIu64 "\n", + stats.leaf.n_pkts_dropped[RTE_TM_GREEN]); + if (stats_mask & RTE_TM_STATS_N_PKTS_YELLOW_DROPPED) + printf("\tPkts dropped (yellow): %" PRIu64 "\n", + stats.leaf.n_pkts_dropped[RTE_TM_YELLOW]); + if (stats_mask & RTE_TM_STATS_N_PKTS_RED_DROPPED) + printf("\tPkts dropped (red): %" PRIu64 "\n", + stats.leaf.n_pkts_dropped[RTE_TM_RED]); + if (stats_mask & RTE_TM_STATS_N_BYTES_GREEN_DROPPED) + printf("\tBytes dropped (green): %" PRIu64 "\n", + stats.leaf.n_bytes_dropped[RTE_TM_GREEN]); + if (stats_mask & RTE_TM_STATS_N_BYTES_YELLOW_DROPPED) + printf("\tBytes dropped (yellow): %" PRIu64 "\n", + stats.leaf.n_bytes_dropped[RTE_TM_YELLOW]); + if (stats_mask & RTE_TM_STATS_N_BYTES_RED_DROPPED) + printf("\tBytes dropped (red): %" PRIu64 "\n", + stats.leaf.n_bytes_dropped[RTE_TM_RED]); + if (stats_mask & RTE_TM_STATS_N_PKTS_QUEUED) + printf("\tPkts queued: %" PRIu64 "\n", + stats.leaf.n_pkts_queued); + if (stats_mask & RTE_TM_STATS_N_BYTES_QUEUED) + printf("\tBytes queued: %" PRIu64 "\n", + stats.leaf.n_bytes_queued); +} + +cmdline_parse_inst_t cmd_show_port_tm_node_stats = { + .f = cmd_show_port_tm_node_stats_parsed, + .data = NULL, + .help_str = "Show port tm node stats", + .tokens = { + (void *)&cmd_show_port_tm_node_stats_show, + (void *)&cmd_show_port_tm_node_stats_port, + (void *)&cmd_show_port_tm_node_stats_tm, + (void *)&cmd_show_port_tm_node_stats_node, + (void *)&cmd_show_port_tm_node_stats_stats, + (void *)&cmd_show_port_tm_node_stats_port_id, + (void *)&cmd_show_port_tm_node_stats_node_id, + (void *)&cmd_show_port_tm_node_stats_clear, + NULL, + }, +}; + +/* *** Show Port TM Node Type *** */ +struct cmd_show_port_tm_node_type_result { + cmdline_fixed_string_t show; + cmdline_fixed_string_t port; + cmdline_fixed_string_t tm; + cmdline_fixed_string_t node; + cmdline_fixed_string_t type; + uint16_t port_id; + uint32_t node_id; +}; + +cmdline_parse_token_string_t cmd_show_port_tm_node_type_show = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_tm_node_type_result, show, "show"); +cmdline_parse_token_string_t cmd_show_port_tm_node_type_port = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_tm_node_type_result, port, "port"); +cmdline_parse_token_string_t cmd_show_port_tm_node_type_tm = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_tm_node_type_result, tm, "tm"); +cmdline_parse_token_string_t cmd_show_port_tm_node_type_node = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_tm_node_type_result, node, "node"); +cmdline_parse_token_string_t cmd_show_port_tm_node_type_type = + TOKEN_STRING_INITIALIZER( + struct cmd_show_port_tm_node_type_result, type, "type"); +cmdline_parse_token_num_t cmd_show_port_tm_node_type_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_show_port_tm_node_type_result, + port_id, UINT16); +cmdline_parse_token_num_t cmd_show_port_tm_node_type_node_id = + TOKEN_NUM_INITIALIZER( + struct cmd_show_port_tm_node_type_result, + node_id, UINT32); + +static void cmd_show_port_tm_node_type_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_show_port_tm_node_type_result *res = parsed_result; + struct rte_tm_error error; + uint32_t node_id = res->node_id; + portid_t port_id = res->port_id; + int ret, is_leaf = 0; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + ret = rte_tm_node_type_get(port_id, node_id, &is_leaf, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } + + if (is_leaf == 1) + printf("leaf node\n"); + else + printf("nonleaf node\n"); + +} + +cmdline_parse_inst_t cmd_show_port_tm_node_type = { + .f = cmd_show_port_tm_node_type_parsed, + .data = NULL, + .help_str = "Show port tm node type", + .tokens = { + (void *)&cmd_show_port_tm_node_type_show, + (void *)&cmd_show_port_tm_node_type_port, + (void *)&cmd_show_port_tm_node_type_tm, + (void *)&cmd_show_port_tm_node_type_node, + (void *)&cmd_show_port_tm_node_type_type, + (void *)&cmd_show_port_tm_node_type_port_id, + (void *)&cmd_show_port_tm_node_type_node_id, + NULL, + }, +}; + +/* *** Add Port TM Private Shaper Profile *** */ +struct cmd_add_port_tm_node_shaper_profile_result { + cmdline_fixed_string_t add; + cmdline_fixed_string_t port; + cmdline_fixed_string_t tm; + cmdline_fixed_string_t node; + cmdline_fixed_string_t shaper; + cmdline_fixed_string_t profile; + uint16_t port_id; + uint32_t shaper_id; + uint64_t tb_rate; + uint64_t tb_size; + uint32_t pktlen_adjust; +}; + +cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_add = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_shaper_profile_result, add, "add"); +cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_port = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_shaper_profile_result, + port, "port"); +cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_tm = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_shaper_profile_result, + tm, "tm"); +cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_node = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_shaper_profile_result, + node, "node"); +cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_shaper = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_shaper_profile_result, + shaper, "shaper"); +cmdline_parse_token_string_t cmd_add_port_tm_node_shaper_profile_profile = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_shaper_profile_result, + profile, "profile"); +cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_shaper_profile_result, + port_id, UINT16); +cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_shaper_id = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_shaper_profile_result, + shaper_id, UINT32); +cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_tb_rate = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_shaper_profile_result, + tb_rate, UINT64); +cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_tb_size = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_shaper_profile_result, + tb_size, UINT64); +cmdline_parse_token_num_t cmd_add_port_tm_node_shaper_profile_pktlen_adjust = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_shaper_profile_result, + pktlen_adjust, UINT32); + +static void cmd_add_port_tm_node_shaper_profile_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_add_port_tm_node_shaper_profile_result *res = parsed_result; + struct rte_tm_shaper_params sp; + struct rte_tm_error error; + uint32_t shaper_id = res->shaper_id; + uint32_t pkt_len_adjust = res->pktlen_adjust; + portid_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + /* Private shaper profile params */ + memset(&sp, 0, sizeof(struct rte_tm_shaper_params)); + sp.peak.rate = res->tb_rate; + sp.peak.size = res->tb_size; + sp.pkt_length_adjust = pkt_len_adjust; + + ret = rte_tm_shaper_profile_add(port_id, shaper_id, &sp, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_add_port_tm_node_shaper_profile = { + .f = cmd_add_port_tm_node_shaper_profile_parsed, + .data = NULL, + .help_str = "Add port tm node private shaper profile", + .tokens = { + (void *)&cmd_add_port_tm_node_shaper_profile_add, + (void *)&cmd_add_port_tm_node_shaper_profile_port, + (void *)&cmd_add_port_tm_node_shaper_profile_tm, + (void *)&cmd_add_port_tm_node_shaper_profile_node, + (void *)&cmd_add_port_tm_node_shaper_profile_shaper, + (void *)&cmd_add_port_tm_node_shaper_profile_profile, + (void *)&cmd_add_port_tm_node_shaper_profile_port_id, + (void *)&cmd_add_port_tm_node_shaper_profile_shaper_id, + (void *)&cmd_add_port_tm_node_shaper_profile_tb_rate, + (void *)&cmd_add_port_tm_node_shaper_profile_tb_size, + (void *)&cmd_add_port_tm_node_shaper_profile_pktlen_adjust, + NULL, + }, +}; + +/* *** Delete Port TM Private Shaper Profile *** */ +struct cmd_del_port_tm_node_shaper_profile_result { + cmdline_fixed_string_t del; + cmdline_fixed_string_t port; + cmdline_fixed_string_t tm; + cmdline_fixed_string_t node; + cmdline_fixed_string_t shaper; + cmdline_fixed_string_t profile; + uint16_t port_id; + uint32_t shaper_id; +}; + +cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_del = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_shaper_profile_result, del, "del"); +cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_port = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_shaper_profile_result, + port, "port"); +cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_tm = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_shaper_profile_result, tm, "tm"); +cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_node = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_shaper_profile_result, + node, "node"); +cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_shaper = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_shaper_profile_result, + shaper, "shaper"); +cmdline_parse_token_string_t cmd_del_port_tm_node_shaper_profile_profile = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_shaper_profile_result, + profile, "profile"); +cmdline_parse_token_num_t cmd_del_port_tm_node_shaper_profile_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_del_port_tm_node_shaper_profile_result, + port_id, UINT16); +cmdline_parse_token_num_t cmd_del_port_tm_node_shaper_profile_shaper_id = + TOKEN_NUM_INITIALIZER( + struct cmd_del_port_tm_node_shaper_profile_result, + shaper_id, UINT32); + +static void cmd_del_port_tm_node_shaper_profile_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_del_port_tm_node_shaper_profile_result *res = parsed_result; + struct rte_tm_error error; + uint32_t shaper_id = res->shaper_id; + portid_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + ret = rte_tm_shaper_profile_delete(port_id, shaper_id, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_del_port_tm_node_shaper_profile = { + .f = cmd_del_port_tm_node_shaper_profile_parsed, + .data = NULL, + .help_str = "Delete port tm node private shaper profile", + .tokens = { + (void *)&cmd_del_port_tm_node_shaper_profile_del, + (void *)&cmd_del_port_tm_node_shaper_profile_port, + (void *)&cmd_del_port_tm_node_shaper_profile_tm, + (void *)&cmd_del_port_tm_node_shaper_profile_node, + (void *)&cmd_del_port_tm_node_shaper_profile_shaper, + (void *)&cmd_del_port_tm_node_shaper_profile_profile, + (void *)&cmd_del_port_tm_node_shaper_profile_port_id, + (void *)&cmd_del_port_tm_node_shaper_profile_shaper_id, + NULL, + }, +}; + +/* *** Add/Update Port TM shared Shaper *** */ +struct cmd_add_port_tm_node_shared_shaper_result { + cmdline_fixed_string_t cmd_type; + cmdline_fixed_string_t port; + cmdline_fixed_string_t tm; + cmdline_fixed_string_t node; + cmdline_fixed_string_t shared; + cmdline_fixed_string_t shaper; + uint16_t port_id; + uint32_t shared_shaper_id; + uint32_t shaper_profile_id; +}; + +cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_cmd_type = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_shared_shaper_result, + cmd_type, "add#set"); +cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_port = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_shared_shaper_result, port, "port"); +cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_tm = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_shared_shaper_result, tm, "tm"); +cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_node = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_shared_shaper_result, node, "node"); +cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_shared = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_shared_shaper_result, + shared, "shared"); +cmdline_parse_token_string_t cmd_add_port_tm_node_shared_shaper_shaper = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_shared_shaper_result, + shaper, "shaper"); +cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_shared_shaper_result, + port_id, UINT16); +cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_shared_shaper_id = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_shared_shaper_result, + shared_shaper_id, UINT32); +cmdline_parse_token_num_t cmd_add_port_tm_node_shared_shaper_shaper_profile_id = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_shared_shaper_result, + shaper_profile_id, UINT32); + +static void cmd_add_port_tm_node_shared_shaper_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_add_port_tm_node_shared_shaper_result *res = parsed_result; + struct rte_tm_error error; + uint32_t shared_shaper_id = res->shared_shaper_id; + uint32_t shaper_profile_id = res->shaper_profile_id; + portid_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + /* Command type: add */ + if ((strcmp(res->cmd_type, "add") == 0) && + (port_is_started(port_id))) { + printf(" Port %u not stopped (error)\n", port_id); + return; + } + + /* Command type: set (update) */ + if ((strcmp(res->cmd_type, "set") == 0) && + (!port_is_started(port_id))) { + printf(" Port %u not started (error)\n", port_id); + return; + } + + ret = rte_tm_shared_shaper_add_update(port_id, shared_shaper_id, + shaper_profile_id, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_add_port_tm_node_shared_shaper = { + .f = cmd_add_port_tm_node_shared_shaper_parsed, + .data = NULL, + .help_str = "add/update port tm node shared shaper", + .tokens = { + (void *)&cmd_add_port_tm_node_shared_shaper_cmd_type, + (void *)&cmd_add_port_tm_node_shared_shaper_port, + (void *)&cmd_add_port_tm_node_shared_shaper_tm, + (void *)&cmd_add_port_tm_node_shared_shaper_node, + (void *)&cmd_add_port_tm_node_shared_shaper_shared, + (void *)&cmd_add_port_tm_node_shared_shaper_shaper, + (void *)&cmd_add_port_tm_node_shared_shaper_port_id, + (void *)&cmd_add_port_tm_node_shared_shaper_shared_shaper_id, + (void *)&cmd_add_port_tm_node_shared_shaper_shaper_profile_id, + NULL, + }, +}; + +/* *** Delete Port TM shared Shaper *** */ +struct cmd_del_port_tm_node_shared_shaper_result { + cmdline_fixed_string_t del; + cmdline_fixed_string_t port; + cmdline_fixed_string_t tm; + cmdline_fixed_string_t node; + cmdline_fixed_string_t shared; + cmdline_fixed_string_t shaper; + uint16_t port_id; + uint32_t shared_shaper_id; +}; + +cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_del = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_shared_shaper_result, del, "del"); +cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_port = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_shared_shaper_result, port, "port"); +cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_tm = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_shared_shaper_result, tm, "tm"); +cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_node = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_shared_shaper_result, node, "node"); +cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_shared = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_shared_shaper_result, + shared, "shared"); +cmdline_parse_token_string_t cmd_del_port_tm_node_shared_shaper_shaper = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_shared_shaper_result, + shaper, "shaper"); +cmdline_parse_token_num_t cmd_del_port_tm_node_shared_shaper_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_del_port_tm_node_shared_shaper_result, + port_id, UINT16); +cmdline_parse_token_num_t cmd_del_port_tm_node_shared_shaper_shared_shaper_id = + TOKEN_NUM_INITIALIZER( + struct cmd_del_port_tm_node_shared_shaper_result, + shared_shaper_id, UINT32); + +static void cmd_del_port_tm_node_shared_shaper_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_del_port_tm_node_shared_shaper_result *res = parsed_result; + struct rte_tm_error error; + uint32_t shared_shaper_id = res->shared_shaper_id; + portid_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + ret = rte_tm_shared_shaper_delete(port_id, shared_shaper_id, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_del_port_tm_node_shared_shaper = { + .f = cmd_del_port_tm_node_shared_shaper_parsed, + .data = NULL, + .help_str = "delete port tm node shared shaper", + .tokens = { + (void *)&cmd_del_port_tm_node_shared_shaper_del, + (void *)&cmd_del_port_tm_node_shared_shaper_port, + (void *)&cmd_del_port_tm_node_shared_shaper_tm, + (void *)&cmd_del_port_tm_node_shared_shaper_node, + (void *)&cmd_del_port_tm_node_shared_shaper_shared, + (void *)&cmd_del_port_tm_node_shared_shaper_shaper, + (void *)&cmd_del_port_tm_node_shared_shaper_port_id, + (void *)&cmd_del_port_tm_node_shared_shaper_shared_shaper_id, + NULL, + }, +}; + +/* *** Add Port TM Node WRED Profile *** */ +struct cmd_add_port_tm_node_wred_profile_result { + cmdline_fixed_string_t add; + cmdline_fixed_string_t port; + cmdline_fixed_string_t tm; + cmdline_fixed_string_t node; + cmdline_fixed_string_t wred; + cmdline_fixed_string_t profile; + uint16_t port_id; + uint32_t wred_profile_id; + cmdline_fixed_string_t color_g; + uint16_t min_th_g; + uint16_t max_th_g; + uint16_t maxp_inv_g; + uint16_t wq_log2_g; + cmdline_fixed_string_t color_y; + uint16_t min_th_y; + uint16_t max_th_y; + uint16_t maxp_inv_y; + uint16_t wq_log2_y; + cmdline_fixed_string_t color_r; + uint16_t min_th_r; + uint16_t max_th_r; + uint16_t maxp_inv_r; + uint16_t wq_log2_r; +}; + +cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_add = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, add, "add"); +cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_port = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, port, "port"); +cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_tm = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, tm, "tm"); +cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_node = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, node, "node"); +cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_wred = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, wred, "wred"); +cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_profile = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, + profile, "profile"); +cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, + port_id, UINT16); +cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wred_profile_id = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, + wred_profile_id, UINT32); +cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_g = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, + color_g, "G#g"); +cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_g = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, + min_th_g, UINT16); +cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_g = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, + max_th_g, UINT16); +cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_g = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, + maxp_inv_g, UINT16); +cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_g = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, + wq_log2_g, UINT16); +cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_y = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, + color_y, "Y#y"); +cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_y = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, + min_th_y, UINT16); +cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_y = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, + max_th_y, UINT16); +cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_y = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, + maxp_inv_y, UINT16); +cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_y = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, + wq_log2_y, UINT16); +cmdline_parse_token_string_t cmd_add_port_tm_node_wred_profile_color_r = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, + color_r, "R#r"); +cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_min_th_r = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, + min_th_r, UINT16); +cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_max_th_r = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, + max_th_r, UINT16); +cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_maxp_inv_r = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, + maxp_inv_r, UINT16); +cmdline_parse_token_num_t cmd_add_port_tm_node_wred_profile_wq_log2_r = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_node_wred_profile_result, + wq_log2_r, UINT16); + + +static void cmd_add_port_tm_node_wred_profile_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_add_port_tm_node_wred_profile_result *res = parsed_result; + struct rte_tm_wred_params wp; + enum rte_tm_color color; + struct rte_tm_error error; + uint32_t wred_profile_id = res->wred_profile_id; + portid_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + memset(&wp, 0, sizeof(struct rte_tm_wred_params)); + + /* WRED Params (Green Color)*/ + color = RTE_TM_GREEN; + wp.red_params[color].min_th = res->min_th_g; + wp.red_params[color].max_th = res->max_th_g; + wp.red_params[color].maxp_inv = res->maxp_inv_g; + wp.red_params[color].wq_log2 = res->wq_log2_g; + + + /* WRED Params (Yellow Color)*/ + color = RTE_TM_YELLOW; + wp.red_params[color].min_th = res->min_th_y; + wp.red_params[color].max_th = res->max_th_y; + wp.red_params[color].maxp_inv = res->maxp_inv_y; + wp.red_params[color].wq_log2 = res->wq_log2_y; + + /* WRED Params (Red Color)*/ + color = RTE_TM_RED; + wp.red_params[color].min_th = res->min_th_r; + wp.red_params[color].max_th = res->max_th_r; + wp.red_params[color].maxp_inv = res->maxp_inv_r; + wp.red_params[color].wq_log2 = res->wq_log2_r; + + ret = rte_tm_wred_profile_add(port_id, wred_profile_id, &wp, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_add_port_tm_node_wred_profile = { + .f = cmd_add_port_tm_node_wred_profile_parsed, + .data = NULL, + .help_str = "Add port tm node wred profile", + .tokens = { + (void *)&cmd_add_port_tm_node_wred_profile_add, + (void *)&cmd_add_port_tm_node_wred_profile_port, + (void *)&cmd_add_port_tm_node_wred_profile_tm, + (void *)&cmd_add_port_tm_node_wred_profile_node, + (void *)&cmd_add_port_tm_node_wred_profile_wred, + (void *)&cmd_add_port_tm_node_wred_profile_profile, + (void *)&cmd_add_port_tm_node_wred_profile_port_id, + (void *)&cmd_add_port_tm_node_wred_profile_wred_profile_id, + (void *)&cmd_add_port_tm_node_wred_profile_color_g, + (void *)&cmd_add_port_tm_node_wred_profile_min_th_g, + (void *)&cmd_add_port_tm_node_wred_profile_max_th_g, + (void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_g, + (void *)&cmd_add_port_tm_node_wred_profile_wq_log2_g, + (void *)&cmd_add_port_tm_node_wred_profile_color_y, + (void *)&cmd_add_port_tm_node_wred_profile_min_th_y, + (void *)&cmd_add_port_tm_node_wred_profile_max_th_y, + (void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_y, + (void *)&cmd_add_port_tm_node_wred_profile_wq_log2_y, + (void *)&cmd_add_port_tm_node_wred_profile_color_r, + (void *)&cmd_add_port_tm_node_wred_profile_min_th_r, + (void *)&cmd_add_port_tm_node_wred_profile_max_th_r, + (void *)&cmd_add_port_tm_node_wred_profile_maxp_inv_r, + (void *)&cmd_add_port_tm_node_wred_profile_wq_log2_r, + NULL, + }, +}; + +/* *** Delete Port TM node WRED Profile *** */ +struct cmd_del_port_tm_node_wred_profile_result { + cmdline_fixed_string_t del; + cmdline_fixed_string_t port; + cmdline_fixed_string_t tm; + cmdline_fixed_string_t node; + cmdline_fixed_string_t wred; + cmdline_fixed_string_t profile; + uint16_t port_id; + uint32_t wred_profile_id; +}; + +cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_del = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_wred_profile_result, del, "del"); +cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_port = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_wred_profile_result, port, "port"); +cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_tm = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_wred_profile_result, tm, "tm"); +cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_node = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_wred_profile_result, node, "node"); +cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_wred = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_wred_profile_result, wred, "wred"); +cmdline_parse_token_string_t cmd_del_port_tm_node_wred_profile_profile = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_wred_profile_result, + profile, "profile"); +cmdline_parse_token_num_t cmd_del_port_tm_node_wred_profile_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_del_port_tm_node_wred_profile_result, + port_id, UINT16); +cmdline_parse_token_num_t cmd_del_port_tm_node_wred_profile_wred_profile_id = + TOKEN_NUM_INITIALIZER( + struct cmd_del_port_tm_node_wred_profile_result, + wred_profile_id, UINT32); + +static void cmd_del_port_tm_node_wred_profile_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_del_port_tm_node_wred_profile_result *res = parsed_result; + struct rte_tm_error error; + uint32_t wred_profile_id = res->wred_profile_id; + portid_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + ret = rte_tm_wred_profile_delete(port_id, wred_profile_id, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_del_port_tm_node_wred_profile = { + .f = cmd_del_port_tm_node_wred_profile_parsed, + .data = NULL, + .help_str = "Delete port tm node wred profile", + .tokens = { + (void *)&cmd_del_port_tm_node_wred_profile_del, + (void *)&cmd_del_port_tm_node_wred_profile_port, + (void *)&cmd_del_port_tm_node_wred_profile_tm, + (void *)&cmd_del_port_tm_node_wred_profile_node, + (void *)&cmd_del_port_tm_node_wred_profile_wred, + (void *)&cmd_del_port_tm_node_wred_profile_profile, + (void *)&cmd_del_port_tm_node_wred_profile_port_id, + (void *)&cmd_del_port_tm_node_wred_profile_wred_profile_id, + NULL, + }, +}; + +/* *** Update Port TM Node Shaper profile *** */ +struct cmd_set_port_tm_node_shaper_profile_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t port; + cmdline_fixed_string_t tm; + cmdline_fixed_string_t node; + cmdline_fixed_string_t shaper; + cmdline_fixed_string_t profile; + uint16_t port_id; + uint32_t node_id; + uint32_t shaper_profile_id; +}; + +cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_set = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_tm_node_shaper_profile_result, set, "set"); +cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_port = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_tm_node_shaper_profile_result, + port, "port"); +cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_tm = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_tm_node_shaper_profile_result, tm, "tm"); +cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_node = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_tm_node_shaper_profile_result, + node, "node"); +cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_shaper = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_tm_node_shaper_profile_result, + shaper, "shaper"); +cmdline_parse_token_string_t cmd_set_port_tm_node_shaper_profile_profile = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_tm_node_shaper_profile_result, + profile, "profile"); +cmdline_parse_token_num_t cmd_set_port_tm_node_shaper_profile_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_set_port_tm_node_shaper_profile_result, + port_id, UINT16); +cmdline_parse_token_num_t cmd_set_port_tm_node_shaper_profile_node_id = + TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_shaper_profile_result, + node_id, UINT32); +cmdline_parse_token_num_t + cmd_set_port_tm_node_shaper_shaper_profile_profile_id = + TOKEN_NUM_INITIALIZER( + struct cmd_set_port_tm_node_shaper_profile_result, + shaper_profile_id, UINT32); + +static void cmd_set_port_tm_node_shaper_profile_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_set_port_tm_node_shaper_profile_result *res = parsed_result; + struct rte_tm_error error; + uint32_t node_id = res->node_id; + uint32_t shaper_profile_id = res->shaper_profile_id; + portid_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + /* Port status */ + if (!port_is_started(port_id)) { + printf(" Port %u not started (error)\n", port_id); + return; + } + + ret = rte_tm_node_shaper_update(port_id, node_id, + shaper_profile_id, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_set_port_tm_node_shaper_profile = { + .f = cmd_set_port_tm_node_shaper_profile_parsed, + .data = NULL, + .help_str = "Set port tm node shaper profile", + .tokens = { + (void *)&cmd_set_port_tm_node_shaper_profile_set, + (void *)&cmd_set_port_tm_node_shaper_profile_port, + (void *)&cmd_set_port_tm_node_shaper_profile_tm, + (void *)&cmd_set_port_tm_node_shaper_profile_node, + (void *)&cmd_set_port_tm_node_shaper_profile_shaper, + (void *)&cmd_set_port_tm_node_shaper_profile_profile, + (void *)&cmd_set_port_tm_node_shaper_profile_port_id, + (void *)&cmd_set_port_tm_node_shaper_profile_node_id, + (void *)&cmd_set_port_tm_node_shaper_shaper_profile_profile_id, + NULL, + }, +}; + +/* *** Add Port TM nonleaf node *** */ +struct cmd_add_port_tm_nonleaf_node_result { + cmdline_fixed_string_t add; + cmdline_fixed_string_t port; + cmdline_fixed_string_t tm; + cmdline_fixed_string_t nonleaf; + cmdline_fixed_string_t node; + uint16_t port_id; + uint32_t node_id; + int32_t parent_node_id; + uint32_t priority; + uint32_t weight; + uint32_t level_id; + uint32_t shaper_profile_id; + uint32_t n_sp_priorities; + uint64_t stats_mask; + cmdline_multi_string_t multi_shared_shaper_id; +}; + +cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_add = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_nonleaf_node_result, add, "add"); +cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_port = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_nonleaf_node_result, port, "port"); +cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_tm = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_nonleaf_node_result, tm, "tm"); +cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_nonleaf = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_nonleaf_node_result, nonleaf, "nonleaf"); +cmdline_parse_token_string_t cmd_add_port_tm_nonleaf_node_node = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_nonleaf_node_result, node, "node"); +cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_add_port_tm_nonleaf_node_result, + port_id, UINT16); +cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_node_id = + TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, + node_id, UINT32); +cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_parent_node_id = + TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, + parent_node_id, INT32); +cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_priority = + TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, + priority, UINT32); +cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_weight = + TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, + weight, UINT32); +cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_level_id = + TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, + level_id, UINT32); +cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_shaper_profile_id = + TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, + shaper_profile_id, UINT32); +cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_n_sp_priorities = + TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, + n_sp_priorities, UINT32); +cmdline_parse_token_num_t cmd_add_port_tm_nonleaf_node_stats_mask = + TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, + stats_mask, UINT64); +cmdline_parse_token_string_t + cmd_add_port_tm_nonleaf_node_multi_shared_shaper_id = + TOKEN_STRING_INITIALIZER(struct cmd_add_port_tm_nonleaf_node_result, + multi_shared_shaper_id, TOKEN_STRING_MULTI); + +static void cmd_add_port_tm_nonleaf_node_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_add_port_tm_nonleaf_node_result *res = parsed_result; + struct rte_tm_error error; + struct rte_tm_node_params np; + uint32_t *shared_shaper_id; + uint32_t parent_node_id, n_shared_shapers = 0; + char *s_str = res->multi_shared_shaper_id; + portid_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + /* Port status */ + if (port_is_started(port_id)) { + printf(" Port %u not stopped (error)\n", port_id); + return; + } + + memset(&np, 0, sizeof(struct rte_tm_node_params)); + + /* Node parameters */ + if (res->parent_node_id < 0) + parent_node_id = UINT32_MAX; + else + parent_node_id = res->parent_node_id; + + shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS * + sizeof(uint32_t)); + if (shared_shaper_id == NULL) { + printf(" Memory not allocated for shared shapers (error)\n"); + return; + } + + /* Parse multi shared shaper id string */ + ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id); + if (ret) { + printf(" Shared shapers params string parse error\n"); + free(shared_shaper_id); + return; + } + + np.shaper_profile_id = res->shaper_profile_id; + np.n_shared_shapers = n_shared_shapers; + if (np.n_shared_shapers) + np.shared_shaper_id = &shared_shaper_id[0]; + else + np.shared_shaper_id = NULL; + + np.nonleaf.n_sp_priorities = res->n_sp_priorities; + np.stats_mask = res->stats_mask; + np.nonleaf.wfq_weight_mode = NULL; + + ret = rte_tm_node_add(port_id, res->node_id, parent_node_id, + res->priority, res->weight, res->level_id, + &np, &error); + if (ret != 0) { + print_err_msg(&error); + free(shared_shaper_id); + return; + } +} + +cmdline_parse_inst_t cmd_add_port_tm_nonleaf_node = { + .f = cmd_add_port_tm_nonleaf_node_parsed, + .data = NULL, + .help_str = "Add port tm nonleaf node", + .tokens = { + (void *)&cmd_add_port_tm_nonleaf_node_add, + (void *)&cmd_add_port_tm_nonleaf_node_port, + (void *)&cmd_add_port_tm_nonleaf_node_tm, + (void *)&cmd_add_port_tm_nonleaf_node_nonleaf, + (void *)&cmd_add_port_tm_nonleaf_node_node, + (void *)&cmd_add_port_tm_nonleaf_node_port_id, + (void *)&cmd_add_port_tm_nonleaf_node_node_id, + (void *)&cmd_add_port_tm_nonleaf_node_parent_node_id, + (void *)&cmd_add_port_tm_nonleaf_node_priority, + (void *)&cmd_add_port_tm_nonleaf_node_weight, + (void *)&cmd_add_port_tm_nonleaf_node_level_id, + (void *)&cmd_add_port_tm_nonleaf_node_shaper_profile_id, + (void *)&cmd_add_port_tm_nonleaf_node_n_sp_priorities, + (void *)&cmd_add_port_tm_nonleaf_node_stats_mask, + (void *)&cmd_add_port_tm_nonleaf_node_multi_shared_shaper_id, + NULL, + }, +}; + +/* *** Add Port TM leaf node *** */ +struct cmd_add_port_tm_leaf_node_result { + cmdline_fixed_string_t add; + cmdline_fixed_string_t port; + cmdline_fixed_string_t tm; + cmdline_fixed_string_t leaf; + cmdline_fixed_string_t node; + uint16_t port_id; + uint32_t node_id; + int32_t parent_node_id; + uint32_t priority; + uint32_t weight; + uint32_t level_id; + uint32_t shaper_profile_id; + uint32_t cman_mode; + uint32_t wred_profile_id; + uint64_t stats_mask; + cmdline_multi_string_t multi_shared_shaper_id; +}; + +cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_add = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_leaf_node_result, add, "add"); +cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_port = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_leaf_node_result, port, "port"); +cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_tm = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_leaf_node_result, tm, "tm"); +cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_nonleaf = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_leaf_node_result, leaf, "leaf"); +cmdline_parse_token_string_t cmd_add_port_tm_leaf_node_node = + TOKEN_STRING_INITIALIZER( + struct cmd_add_port_tm_leaf_node_result, node, "node"); +cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_port_id = + TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, + port_id, UINT16); +cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_node_id = + TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, + node_id, UINT32); +cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_parent_node_id = + TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, + parent_node_id, INT32); +cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_priority = + TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, + priority, UINT32); +cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_weight = + TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, + weight, UINT32); +cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_level_id = + TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, + level_id, UINT32); +cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_shaper_profile_id = + TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, + shaper_profile_id, UINT32); +cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_cman_mode = + TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, + cman_mode, UINT32); +cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_wred_profile_id = + TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, + wred_profile_id, UINT32); +cmdline_parse_token_num_t cmd_add_port_tm_leaf_node_stats_mask = + TOKEN_NUM_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, + stats_mask, UINT64); +cmdline_parse_token_string_t + cmd_add_port_tm_leaf_node_multi_shared_shaper_id = + TOKEN_STRING_INITIALIZER(struct cmd_add_port_tm_leaf_node_result, + multi_shared_shaper_id, TOKEN_STRING_MULTI); + +static void cmd_add_port_tm_leaf_node_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_add_port_tm_leaf_node_result *res = parsed_result; + struct rte_tm_error error; + struct rte_tm_node_params np; + uint32_t *shared_shaper_id; + uint32_t parent_node_id, n_shared_shapers = 0; + portid_t port_id = res->port_id; + char *s_str = res->multi_shared_shaper_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + /* Port status */ + if (port_is_started(port_id)) { + printf(" Port %u not stopped (error)\n", port_id); + return; + } + + memset(&np, 0, sizeof(struct rte_tm_node_params)); + + /* Node parameters */ + if (res->parent_node_id < 0) + parent_node_id = UINT32_MAX; + else + parent_node_id = res->parent_node_id; + + shared_shaper_id = (uint32_t *)malloc(MAX_NUM_SHARED_SHAPERS * + sizeof(uint32_t)); + if (shared_shaper_id == NULL) { + printf(" Memory not allocated for shared shapers (error)\n"); + return; + } + + /* Parse multi shared shaper id string */ + ret = parse_multi_ss_id_str(s_str, &n_shared_shapers, shared_shaper_id); + if (ret) { + printf(" Shared shapers params string parse error\n"); + free(shared_shaper_id); + return; + } + + np.shaper_profile_id = res->shaper_profile_id; + np.n_shared_shapers = n_shared_shapers; + + if (np.n_shared_shapers) + np.shared_shaper_id = &shared_shaper_id[0]; + else + np.shared_shaper_id = NULL; + + np.leaf.cman = res->cman_mode; + np.leaf.wred.wred_profile_id = res->wred_profile_id; + np.stats_mask = res->stats_mask; + + ret = rte_tm_node_add(port_id, res->node_id, parent_node_id, + res->priority, res->weight, res->level_id, + &np, &error); + if (ret != 0) { + print_err_msg(&error); + free(shared_shaper_id); + return; + } +} + +cmdline_parse_inst_t cmd_add_port_tm_leaf_node = { + .f = cmd_add_port_tm_leaf_node_parsed, + .data = NULL, + .help_str = "Add port tm leaf node", + .tokens = { + (void *)&cmd_add_port_tm_leaf_node_add, + (void *)&cmd_add_port_tm_leaf_node_port, + (void *)&cmd_add_port_tm_leaf_node_tm, + (void *)&cmd_add_port_tm_leaf_node_nonleaf, + (void *)&cmd_add_port_tm_leaf_node_node, + (void *)&cmd_add_port_tm_leaf_node_port_id, + (void *)&cmd_add_port_tm_leaf_node_node_id, + (void *)&cmd_add_port_tm_leaf_node_parent_node_id, + (void *)&cmd_add_port_tm_leaf_node_priority, + (void *)&cmd_add_port_tm_leaf_node_weight, + (void *)&cmd_add_port_tm_leaf_node_level_id, + (void *)&cmd_add_port_tm_leaf_node_shaper_profile_id, + (void *)&cmd_add_port_tm_leaf_node_cman_mode, + (void *)&cmd_add_port_tm_leaf_node_wred_profile_id, + (void *)&cmd_add_port_tm_leaf_node_stats_mask, + (void *)&cmd_add_port_tm_leaf_node_multi_shared_shaper_id, + NULL, + }, +}; + +/* *** Delete Port TM Node *** */ +struct cmd_del_port_tm_node_result { + cmdline_fixed_string_t del; + cmdline_fixed_string_t port; + cmdline_fixed_string_t tm; + cmdline_fixed_string_t node; + uint16_t port_id; + uint32_t node_id; +}; + +cmdline_parse_token_string_t cmd_del_port_tm_node_del = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_result, del, "del"); +cmdline_parse_token_string_t cmd_del_port_tm_node_port = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_result, port, "port"); +cmdline_parse_token_string_t cmd_del_port_tm_node_tm = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_result, tm, "tm"); +cmdline_parse_token_string_t cmd_del_port_tm_node_node = + TOKEN_STRING_INITIALIZER( + struct cmd_del_port_tm_node_result, node, "node"); +cmdline_parse_token_num_t cmd_del_port_tm_node_port_id = + TOKEN_NUM_INITIALIZER(struct cmd_del_port_tm_node_result, + port_id, UINT16); +cmdline_parse_token_num_t cmd_del_port_tm_node_node_id = + TOKEN_NUM_INITIALIZER(struct cmd_del_port_tm_node_result, + node_id, UINT32); + +static void cmd_del_port_tm_node_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_del_port_tm_node_result *res = parsed_result; + struct rte_tm_error error; + uint32_t node_id = res->node_id; + portid_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + /* Port status */ + if (port_is_started(port_id)) { + printf(" Port %u not stopped (error)\n", port_id); + return; + } + + ret = rte_tm_node_delete(port_id, node_id, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_del_port_tm_node = { + .f = cmd_del_port_tm_node_parsed, + .data = NULL, + .help_str = "Delete port tm node", + .tokens = { + (void *)&cmd_del_port_tm_node_del, + (void *)&cmd_del_port_tm_node_port, + (void *)&cmd_del_port_tm_node_tm, + (void *)&cmd_del_port_tm_node_node, + (void *)&cmd_del_port_tm_node_port_id, + (void *)&cmd_del_port_tm_node_node_id, + NULL, + }, +}; + +/* *** Update Port TM Node Parent *** */ +struct cmd_set_port_tm_node_parent_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t port; + cmdline_fixed_string_t tm; + cmdline_fixed_string_t node; + cmdline_fixed_string_t parent; + uint16_t port_id; + uint32_t node_id; + uint32_t parent_id; + uint32_t priority; + uint32_t weight; +}; + +cmdline_parse_token_string_t cmd_set_port_tm_node_parent_set = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_tm_node_parent_result, set, "set"); +cmdline_parse_token_string_t cmd_set_port_tm_node_parent_port = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_tm_node_parent_result, port, "port"); +cmdline_parse_token_string_t cmd_set_port_tm_node_parent_tm = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_tm_node_parent_result, tm, "tm"); +cmdline_parse_token_string_t cmd_set_port_tm_node_parent_node = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_tm_node_parent_result, node, "node"); +cmdline_parse_token_string_t cmd_set_port_tm_node_parent_parent = + TOKEN_STRING_INITIALIZER( + struct cmd_set_port_tm_node_parent_result, parent, "parent"); +cmdline_parse_token_num_t cmd_set_port_tm_node_parent_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_set_port_tm_node_parent_result, port_id, UINT16); +cmdline_parse_token_num_t cmd_set_port_tm_node_parent_node_id = + TOKEN_NUM_INITIALIZER( + struct cmd_set_port_tm_node_parent_result, node_id, UINT32); +cmdline_parse_token_num_t cmd_set_port_tm_node_parent_parent_id = + TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result, + parent_id, UINT32); +cmdline_parse_token_num_t cmd_set_port_tm_node_parent_priority = + TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result, + priority, UINT32); +cmdline_parse_token_num_t cmd_set_port_tm_node_parent_weight = + TOKEN_NUM_INITIALIZER(struct cmd_set_port_tm_node_parent_result, + weight, UINT32); + +static void cmd_set_port_tm_node_parent_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_set_port_tm_node_parent_result *res = parsed_result; + struct rte_tm_error error; + uint32_t node_id = res->node_id; + uint32_t parent_id = res->parent_id; + uint32_t priority = res->priority; + uint32_t weight = res->weight; + portid_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + /* Port status */ + if (!port_is_started(port_id)) { + printf(" Port %u not started (error)\n", port_id); + return; + } + + ret = rte_tm_node_parent_update(port_id, node_id, + parent_id, priority, weight, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_set_port_tm_node_parent = { + .f = cmd_set_port_tm_node_parent_parsed, + .data = NULL, + .help_str = "Set port tm node parent", + .tokens = { + (void *)&cmd_set_port_tm_node_parent_set, + (void *)&cmd_set_port_tm_node_parent_port, + (void *)&cmd_set_port_tm_node_parent_tm, + (void *)&cmd_set_port_tm_node_parent_node, + (void *)&cmd_set_port_tm_node_parent_parent, + (void *)&cmd_set_port_tm_node_parent_port_id, + (void *)&cmd_set_port_tm_node_parent_node_id, + (void *)&cmd_set_port_tm_node_parent_parent_id, + (void *)&cmd_set_port_tm_node_parent_priority, + (void *)&cmd_set_port_tm_node_parent_weight, + NULL, + }, +}; + +/* *** Port TM Hierarchy Commit *** */ +struct cmd_port_tm_hierarchy_commit_result { + cmdline_fixed_string_t port; + cmdline_fixed_string_t tm; + cmdline_fixed_string_t hierarchy; + cmdline_fixed_string_t commit; + uint16_t port_id; + cmdline_fixed_string_t clean_on_fail; +}; + +cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_port = + TOKEN_STRING_INITIALIZER( + struct cmd_port_tm_hierarchy_commit_result, port, "port"); +cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_tm = + TOKEN_STRING_INITIALIZER( + struct cmd_port_tm_hierarchy_commit_result, tm, "tm"); +cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_hierarchy = + TOKEN_STRING_INITIALIZER( + struct cmd_port_tm_hierarchy_commit_result, + hierarchy, "hierarchy"); +cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_commit = + TOKEN_STRING_INITIALIZER( + struct cmd_port_tm_hierarchy_commit_result, commit, "commit"); +cmdline_parse_token_num_t cmd_port_tm_hierarchy_commit_port_id = + TOKEN_NUM_INITIALIZER( + struct cmd_port_tm_hierarchy_commit_result, + port_id, UINT16); +cmdline_parse_token_string_t cmd_port_tm_hierarchy_commit_clean_on_fail = + TOKEN_STRING_INITIALIZER(struct cmd_port_tm_hierarchy_commit_result, + clean_on_fail, "yes#no"); + +static void cmd_port_tm_hierarchy_commit_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_port_tm_hierarchy_commit_result *res = parsed_result; + struct rte_tm_error error; + uint32_t clean_on_fail; + portid_t port_id = res->port_id; + int ret; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + + if (strcmp(res->clean_on_fail, "yes") == 0) + clean_on_fail = 1; + else + clean_on_fail = 0; + + ret = rte_tm_hierarchy_commit(port_id, clean_on_fail, &error); + if (ret != 0) { + print_err_msg(&error); + return; + } +} + +cmdline_parse_inst_t cmd_port_tm_hierarchy_commit = { + .f = cmd_port_tm_hierarchy_commit_parsed, + .data = NULL, + .help_str = "Set port tm node shaper profile", + .tokens = { + (void *)&cmd_port_tm_hierarchy_commit_port, + (void *)&cmd_port_tm_hierarchy_commit_tm, + (void *)&cmd_port_tm_hierarchy_commit_hierarchy, + (void *)&cmd_port_tm_hierarchy_commit_commit, + (void *)&cmd_port_tm_hierarchy_commit_port_id, + (void *)&cmd_port_tm_hierarchy_commit_clean_on_fail, + NULL, + }, +}; diff --git a/app/test-pmd/cmdline_tm.h b/app/test-pmd/cmdline_tm.h new file mode 100644 index 00000000..9d5fdf0a --- /dev/null +++ b/app/test-pmd/cmdline_tm.h @@ -0,0 +1,56 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2017 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _CMDLINE_TM_H_ +#define _CMDLINE_TM_H_ + + /* Traffic Management CLI */ +extern cmdline_parse_inst_t cmd_show_port_tm_cap; +extern cmdline_parse_inst_t cmd_show_port_tm_level_cap; +extern cmdline_parse_inst_t cmd_show_port_tm_node_cap; +extern cmdline_parse_inst_t cmd_show_port_tm_node_type; +extern cmdline_parse_inst_t cmd_show_port_tm_node_stats; +extern cmdline_parse_inst_t cmd_add_port_tm_node_shaper_profile; +extern cmdline_parse_inst_t cmd_del_port_tm_node_shaper_profile; +extern cmdline_parse_inst_t cmd_add_port_tm_node_shared_shaper; +extern cmdline_parse_inst_t cmd_del_port_tm_node_shared_shaper; +extern cmdline_parse_inst_t cmd_add_port_tm_node_wred_profile; +extern cmdline_parse_inst_t cmd_del_port_tm_node_wred_profile; +extern cmdline_parse_inst_t cmd_set_port_tm_node_shaper_profile; +extern cmdline_parse_inst_t cmd_add_port_tm_nonleaf_node; +extern cmdline_parse_inst_t cmd_add_port_tm_leaf_node; +extern cmdline_parse_inst_t cmd_del_port_tm_node; +extern cmdline_parse_inst_t cmd_set_port_tm_node_parent; +extern cmdline_parse_inst_t cmd_port_tm_hierarchy_commit; + +#endif /* _CMDLINE_TM_H_ */ diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 3ae3e1cd..cd2ac116 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -40,6 +40,10 @@ #include <inttypes.h> #include <sys/queue.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <unistd.h> #include <rte_common.h> #include <rte_byteorder.h> @@ -67,6 +71,9 @@ #ifdef RTE_LIBRTE_IXGBE_PMD #include <rte_pmd_ixgbe.h> #endif +#ifdef RTE_LIBRTE_I40E_PMD +#include <rte_pmd_i40e.h> +#endif #ifdef RTE_LIBRTE_BNXT_PMD #include <rte_pmd_bnxt.h> #endif @@ -203,8 +210,10 @@ nic_stats_display(portid_t port_id) if (diff_cycles > 0) diff_cycles = prev_cycles[port_id] - diff_cycles; - diff_pkts_rx = stats.ipackets - prev_pkts_rx[port_id]; - diff_pkts_tx = stats.opackets - prev_pkts_tx[port_id]; + diff_pkts_rx = (stats.ipackets > prev_pkts_rx[port_id]) ? + (stats.ipackets - prev_pkts_rx[port_id]) : 0; + diff_pkts_tx = (stats.opackets > prev_pkts_tx[port_id]) ? + (stats.opackets - prev_pkts_tx[port_id]) : 0; prev_pkts_rx[port_id] = stats.ipackets; prev_pkts_tx[port_id] = stats.opackets; mpps_rx = diff_cycles > 0 ? @@ -283,10 +292,13 @@ nic_xstats_display(portid_t port_id) } /* Display xstats */ - for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) + for (idx_xstat = 0; idx_xstat < cnt_xstats; idx_xstat++) { + if (xstats_hide_zero && !xstats[idx_xstat].value) + continue; printf("%s: %"PRIu64"\n", xstats_names[idx_xstat].name, xstats[idx_xstat].value); + } free(xstats_names); free(xstats); } @@ -358,7 +370,7 @@ rx_queue_infos_display(portid_t port_id, uint16_t queue_id) rc = rte_eth_rx_queue_info_get(port_id, queue_id, &qinfo); if (rc != 0) { - printf("Failed to retrieve information for port: %hhu, " + printf("Failed to retrieve information for port: %u, " "RX queue: %hu\nerror desc: %s(%d)\n", port_id, queue_id, strerror(-rc), rc); return; @@ -391,7 +403,7 @@ tx_queue_infos_display(portid_t port_id, uint16_t queue_id) rc = rte_eth_tx_queue_info_get(port_id, queue_id, &qinfo); if (rc != 0) { - printf("Failed to retrieve information for port: %hhu, " + printf("Failed to retrieve information for port: %u, " "TX queue: %hu\nerror desc: %s(%d)\n", port_id, queue_id, strerror(-rc), rc); return; @@ -498,12 +510,15 @@ port_infos_display(portid_t port_id) char *p; printf("Supported flow types:\n"); - for (i = RTE_ETH_FLOW_UNKNOWN + 1; i < RTE_ETH_FLOW_MAX; - i++) { + for (i = RTE_ETH_FLOW_UNKNOWN + 1; + i < sizeof(dev_info.flow_type_rss_offloads) * CHAR_BIT; i++) { if (!(dev_info.flow_type_rss_offloads & (1ULL << i))) continue; p = flowtype_to_str(i); - printf(" %s\n", (p ? p : "unknown")); + if (p) + printf(" %s\n", p); + else + printf(" user defined %d\n", i); } } @@ -598,6 +613,14 @@ port_offload_cap_display(portid_t port_id) printf("off\n"); } + if (dev_info.rx_offload_capa & DEV_RX_OFFLOAD_TIMESTAMP) { + printf("HW timestamp: "); + if (dev->data->dev_conf.rxmode.hw_timestamp) + printf("on\n"); + else + printf("off\n"); + } + if (dev_info.tx_offload_capa & DEV_TX_OFFLOAD_QINQ_INSERT) { printf("Double VLANs insert: "); if (ports[port_id].tx_ol_flags & @@ -947,6 +970,9 @@ static const struct { MK_FLOW_ITEM(MPLS, sizeof(struct rte_flow_item_mpls)), MK_FLOW_ITEM(GRE, sizeof(struct rte_flow_item_gre)), MK_FLOW_ITEM(FUZZY, sizeof(struct rte_flow_item_fuzzy)), + MK_FLOW_ITEM(GTP, sizeof(struct rte_flow_item_gtp)), + MK_FLOW_ITEM(GTPC, sizeof(struct rte_flow_item_gtp)), + MK_FLOW_ITEM(GTPU, sizeof(struct rte_flow_item_gtp)), }; /** Compute storage space needed by item specification. */ @@ -1474,7 +1500,7 @@ tx_desc_id_is_invalid(uint16_t txdesc_id) } static const struct rte_memzone * -ring_dma_zone_lookup(const char *ring_name, uint8_t port_id, uint16_t q_id) +ring_dma_zone_lookup(const char *ring_name, portid_t port_id, uint16_t q_id) { char mz_name[RTE_MEMZONE_NAMESIZE]; const struct rte_memzone *mz; @@ -1524,9 +1550,9 @@ ring_rxd_display_dword(union igb_ring_dword dword) static void ring_rx_descriptor_display(const struct rte_memzone *ring_mz, #ifndef RTE_LIBRTE_I40E_16BYTE_RX_DESC - uint8_t port_id, + portid_t port_id, #else - __rte_unused uint8_t port_id, + __rte_unused portid_t port_id, #endif uint16_t desc_id) { @@ -1879,7 +1905,7 @@ simple_fwd_config_setup(void) fwd_streams[i]->rx_queue = 0; fwd_streams[i]->tx_port = fwd_ports_ids[j]; fwd_streams[i]->tx_queue = 0; - fwd_streams[i]->peer_addr = j; + fwd_streams[i]->peer_addr = fwd_streams[i]->tx_port; fwd_streams[i]->retry_enabled = retry_enabled; if (port_topology == PORT_TOPOLOGY_PAIRED) { @@ -1887,7 +1913,7 @@ simple_fwd_config_setup(void) fwd_streams[j]->rx_queue = 0; fwd_streams[j]->tx_port = fwd_ports_ids[i]; fwd_streams[j]->tx_queue = 0; - fwd_streams[j]->peer_addr = i; + fwd_streams[j]->peer_addr = fwd_streams[j]->tx_port; fwd_streams[j]->retry_enabled = retry_enabled; } } @@ -2420,7 +2446,7 @@ set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs) } void -setup_gro(const char *mode, uint8_t port_id) +setup_gro(const char *onoff, portid_t port_id) { if (!rte_eth_dev_is_valid_port(port_id)) { printf("invalid port id %u\n", port_id); @@ -2431,29 +2457,101 @@ setup_gro(const char *mode, uint8_t port_id) " please stop forwarding first\n"); return; } - if (strcmp(mode, "on") == 0) { - if (gro_ports[port_id].enable) { - printf("port %u has enabled GRO\n", port_id); + if (strcmp(onoff, "on") == 0) { + if (gro_ports[port_id].enable != 0) { + printf("Port %u has enabled GRO. Please" + " disable GRO first\n", port_id); return; } - gro_ports[port_id].enable = 1; - gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4; - - if (gro_ports[port_id].param.max_flow_num == 0) + if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) { + gro_ports[port_id].param.gro_types = RTE_GRO_TCP_IPV4; gro_ports[port_id].param.max_flow_num = GRO_DEFAULT_FLOW_NUM; - if (gro_ports[port_id].param.max_item_per_flow == 0) gro_ports[port_id].param.max_item_per_flow = GRO_DEFAULT_ITEM_NUM_PER_FLOW; + } + gro_ports[port_id].enable = 1; } else { if (gro_ports[port_id].enable == 0) { - printf("port %u has disabled GRO\n", port_id); + printf("Port %u has disabled GRO\n", port_id); return; } gro_ports[port_id].enable = 0; } } +void +setup_gro_flush_cycles(uint8_t cycles) +{ + if (test_done == 0) { + printf("Before change flush interval for GRO," + " please stop forwarding first.\n"); + return; + } + + if (cycles > GRO_MAX_FLUSH_CYCLES || cycles < + GRO_DEFAULT_FLUSH_CYCLES) { + printf("The flushing cycle be in the range" + " of 1 to %u. Revert to the default" + " value %u.\n", + GRO_MAX_FLUSH_CYCLES, + GRO_DEFAULT_FLUSH_CYCLES); + cycles = GRO_DEFAULT_FLUSH_CYCLES; + } + + gro_flush_cycles = cycles; +} + +void +show_gro(portid_t port_id) +{ + struct rte_gro_param *param; + uint32_t max_pkts_num; + + param = &gro_ports[port_id].param; + + if (!rte_eth_dev_is_valid_port(port_id)) { + printf("Invalid port id %u.\n", port_id); + return; + } + if (gro_ports[port_id].enable) { + printf("GRO type: TCP/IPv4\n"); + if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) { + max_pkts_num = param->max_flow_num * + param->max_item_per_flow; + } else + max_pkts_num = MAX_PKT_BURST * GRO_MAX_FLUSH_CYCLES; + printf("Max number of packets to perform GRO: %u\n", + max_pkts_num); + printf("Flushing cycles: %u\n", gro_flush_cycles); + } else + printf("Port %u doesn't enable GRO.\n", port_id); +} + +void +setup_gso(const char *mode, portid_t port_id) +{ + if (!rte_eth_dev_is_valid_port(port_id)) { + printf("invalid port id %u\n", port_id); + return; + } + if (strcmp(mode, "on") == 0) { + if (test_done == 0) { + printf("before enabling GSO," + " please stop forwarding first\n"); + return; + } + gso_ports[port_id].enable = 1; + } else if (strcmp(mode, "off") == 0) { + if (test_done == 0) { + printf("before disabling GSO," + " please stop forwarding first\n"); + return; + } + gso_ports[port_id].enable = 0; + } +} + char* list_pkt_forwarding_modes(void) { @@ -2771,6 +2869,12 @@ set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value) } } +void +set_xstats_hide_zero(uint8_t on_off) +{ + xstats_hide_zero = on_off; +} + static inline void print_fdir_mask(struct rte_eth_fdir_masks *mask) { @@ -3004,7 +3108,7 @@ fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg) return; } } - (void)rte_memcpy(&flex_conf->flex_mask[idx], + rte_memcpy(&flex_conf->flex_mask[idx], cfg, sizeof(struct rte_eth_fdir_flex_mask)); } @@ -3034,7 +3138,7 @@ fdir_set_flex_payload(portid_t port_id, struct rte_eth_flex_payload_cfg *cfg) return; } } - (void)rte_memcpy(&flex_conf->flex_set[idx], + rte_memcpy(&flex_conf->flex_set[idx], cfg, sizeof(struct rte_eth_flex_payload_cfg)); @@ -3090,6 +3194,10 @@ set_vf_rate_limit(portid_t port_id, uint16_t vf, uint16_t rate, uint64_t q_msk) { int diag = -ENOTSUP; + RTE_SET_USED(vf); + RTE_SET_USED(rate); + RTE_SET_USED(q_msk); + #ifdef RTE_LIBRTE_IXGBE_PMD if (diag == -ENOTSUP) diag = rte_pmd_ixgbe_set_vf_rate_limit(port_id, vf, rate, @@ -3180,7 +3288,7 @@ mcast_addr_pool_remove(struct rte_port *port, uint32_t addr_idx) } static void -eth_port_multicast_addr_list_set(uint8_t port_id) +eth_port_multicast_addr_list_set(portid_t port_id) { struct rte_port *port; int diag; @@ -3195,7 +3303,7 @@ eth_port_multicast_addr_list_set(uint8_t port_id) } void -mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr) +mcast_addr_add(portid_t port_id, struct ether_addr *mc_addr) { struct rte_port *port; uint32_t i; @@ -3223,7 +3331,7 @@ mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr) } void -mcast_addr_remove(uint8_t port_id, struct ether_addr *mc_addr) +mcast_addr_remove(portid_t port_id, struct ether_addr *mc_addr) { struct rte_port *port; uint32_t i; @@ -3250,7 +3358,7 @@ mcast_addr_remove(uint8_t port_id, struct ether_addr *mc_addr) } void -port_dcb_info_display(uint8_t port_id) +port_dcb_info_display(portid_t port_id) { struct rte_eth_dcb_info dcb_info; uint16_t i; @@ -3295,46 +3403,43 @@ port_dcb_info_display(uint8_t port_id) uint8_t * open_ddp_package_file(const char *file_path, uint32_t *size) { - FILE *fh = fopen(file_path, "rb"); - uint32_t pkg_size; + int fd = open(file_path, O_RDONLY); + off_t pkg_size; uint8_t *buf = NULL; int ret = 0; + struct stat st_buf; if (size) *size = 0; - if (fh == NULL) { + if (fd == -1) { printf("%s: Failed to open %s\n", __func__, file_path); return buf; } - ret = fseek(fh, 0, SEEK_END); - if (ret < 0) { - fclose(fh); + if ((fstat(fd, &st_buf) != 0) || (!S_ISREG(st_buf.st_mode))) { + close(fd); printf("%s: File operations failed\n", __func__); return buf; } - pkg_size = ftell(fh); + pkg_size = st_buf.st_size; + if (pkg_size < 0) { + close(fd); + printf("%s: File operations failed\n", __func__); + return buf; + } buf = (uint8_t *)malloc(pkg_size); if (!buf) { - fclose(fh); + close(fd); printf("%s: Failed to malloc memory\n", __func__); return buf; } - ret = fseek(fh, 0, SEEK_SET); - if (ret < 0) { - fclose(fh); - printf("%s: File seek operation failed\n", __func__); - close_ddp_package_file(buf); - return NULL; - } - - ret = fread(buf, 1, pkg_size, fh); + ret = read(fd, buf, pkg_size); if (ret < 0) { - fclose(fh); + close(fd); printf("%s: File read operation failed\n", __func__); close_ddp_package_file(buf); return NULL; @@ -3343,7 +3448,7 @@ open_ddp_package_file(const char *file_path, uint32_t *size) if (size) *size = pkg_size; - fclose(fh); + close(fd); return buf; } @@ -3379,3 +3484,46 @@ close_ddp_package_file(uint8_t *buf) return -1; } + +void +port_queue_region_info_display(portid_t port_id, void *buf) +{ +#ifdef RTE_LIBRTE_I40E_PMD + uint16_t i, j; + struct rte_pmd_i40e_queue_regions *info = + (struct rte_pmd_i40e_queue_regions *)buf; + static const char *queue_region_info_stats_border = "-------"; + + if (!info->queue_region_number) + printf("there is no region has been set before"); + + printf("\n %s All queue region info for port=%2d %s", + queue_region_info_stats_border, port_id, + queue_region_info_stats_border); + printf("\n queue_region_number: %-14u \n", + info->queue_region_number); + + for (i = 0; i < info->queue_region_number; i++) { + printf("\n region_id: %-14u queue_number: %-14u " + "queue_start_index: %-14u \n", + info->region[i].region_id, + info->region[i].queue_num, + info->region[i].queue_start_index); + + printf(" user_priority_num is %-14u :", + info->region[i].user_priority_num); + for (j = 0; j < info->region[i].user_priority_num; j++) + printf(" %-14u ", info->region[i].user_priority[j]); + + printf("\n flowtype_num is %-14u :", + info->region[i].flowtype_num); + for (j = 0; j < info->region[i].flowtype_num; j++) + printf(" %-14u ", info->region[i].hw_flowtype[j]); + } +#else + RTE_SET_USED(port_id); + RTE_SET_USED(buf); +#endif + + printf("\n\n"); +} diff --git a/app/test-pmd/csumonly.c b/app/test-pmd/csumonly.c index 90c81198..aa29f5fc 100644 --- a/app/test-pmd/csumonly.c +++ b/app/test-pmd/csumonly.c @@ -49,7 +49,6 @@ #include <rte_cycles.h> #include <rte_memory.h> #include <rte_memcpy.h> -#include <rte_memzone.h> #include <rte_launch.h> #include <rte_eal.h> #include <rte_per_lcore.h> @@ -70,6 +69,8 @@ #include <rte_string_fns.h> #include <rte_flow.h> #include <rte_gro.h> +#include <rte_gso.h> + #include "testpmd.h" #define IP_DEFTTL 64 /* from RFC 1340. */ @@ -91,6 +92,7 @@ /* structure that caches offload info for the current packet */ struct testpmd_offload_info { uint16_t ethertype; + uint8_t gso_enable; uint16_t l2_len; uint16_t l3_len; uint16_t l4_len; @@ -381,6 +383,8 @@ process_inner_cksums(void *l3_hdr, const struct testpmd_offload_info *info, get_udptcp_checksum(l3_hdr, tcp_hdr, info->ethertype); } + if (info->gso_enable) + ol_flags |= PKT_TX_TCP_SEG; } else if (info->l4_proto == IPPROTO_SCTP) { sctp_hdr = (struct sctp_hdr *)((char *)l3_hdr + info->l3_len); sctp_hdr->cksum = 0; @@ -627,10 +631,16 @@ static void pkt_burst_checksum_forward(struct fwd_stream *fs) { struct rte_mbuf *pkts_burst[MAX_PKT_BURST]; + struct rte_mbuf *gso_segments[GSO_MAX_PKT_BURST]; + struct rte_gso_ctx *gso_ctx; + struct rte_mbuf **tx_pkts_burst; struct rte_port *txp; struct rte_mbuf *m, *p; struct ether_hdr *eth_hdr; void *l3_hdr = NULL, *outer_l3_hdr = NULL; /* can be IPv4 or IPv6 */ + void **gro_ctx; + uint16_t gro_pkts_num; + uint8_t gro_enable; uint16_t nb_rx; uint16_t nb_tx; uint16_t nb_prep; @@ -641,6 +651,8 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) uint32_t rx_bad_ip_csum; uint32_t rx_bad_l4_csum; struct testpmd_offload_info info; + uint16_t nb_segments = 0; + int ret; #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES uint64_t start_tsc; @@ -657,23 +669,21 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) nb_pkt_per_burst); if (unlikely(nb_rx == 0)) return; - if (unlikely(gro_ports[fs->rx_port].enable)) - nb_rx = rte_gro_reassemble_burst(pkts_burst, - nb_rx, - &(gro_ports[fs->rx_port].param)); - #ifdef RTE_TEST_PMD_RECORD_BURST_STATS fs->rx_burst_stats.pkt_burst_spread[nb_rx]++; #endif fs->rx_packets += nb_rx; rx_bad_ip_csum = 0; rx_bad_l4_csum = 0; + gro_enable = gro_ports[fs->rx_port].enable; txp = &ports[fs->tx_port]; testpmd_ol_flags = txp->tx_ol_flags; memset(&info, 0, sizeof(info)); info.tso_segsz = txp->tso_segsz; info.tunnel_tso_segsz = txp->tunnel_tso_segsz; + if (gso_ports[fs->tx_port].enable) + info.gso_enable = 1; for (i = 0; i < nb_rx; i++) { if (likely(i < nb_rx - 1)) @@ -851,13 +861,57 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) } } + if (unlikely(gro_enable)) { + if (gro_flush_cycles == GRO_DEFAULT_FLUSH_CYCLES) { + nb_rx = rte_gro_reassemble_burst(pkts_burst, nb_rx, + &(gro_ports[fs->rx_port].param)); + } else { + gro_ctx = current_fwd_lcore()->gro_ctx; + nb_rx = rte_gro_reassemble(pkts_burst, nb_rx, gro_ctx); + + if (++fs->gro_times >= gro_flush_cycles) { + gro_pkts_num = rte_gro_get_pkt_count(gro_ctx); + if (gro_pkts_num > MAX_PKT_BURST - nb_rx) + gro_pkts_num = MAX_PKT_BURST - nb_rx; + + nb_rx += rte_gro_timeout_flush(gro_ctx, 0, + RTE_GRO_TCP_IPV4, + &pkts_burst[nb_rx], + gro_pkts_num); + fs->gro_times = 0; + } + } + } + + if (gso_ports[fs->tx_port].enable == 0) + tx_pkts_burst = pkts_burst; + else { + gso_ctx = &(current_fwd_lcore()->gso_ctx); + gso_ctx->gso_size = gso_max_segment_size; + for (i = 0; i < nb_rx; i++) { + ret = rte_gso_segment(pkts_burst[i], gso_ctx, + &gso_segments[nb_segments], + GSO_MAX_PKT_BURST - nb_segments); + if (ret >= 0) + nb_segments += ret; + else { + RTE_LOG(DEBUG, USER1, + "Unable to segment packet"); + rte_pktmbuf_free(pkts_burst[i]); + } + } + + tx_pkts_burst = gso_segments; + nb_rx = nb_segments; + } + nb_prep = rte_eth_tx_prepare(fs->tx_port, fs->tx_queue, - pkts_burst, nb_rx); + tx_pkts_burst, nb_rx); if (nb_prep != nb_rx) printf("Preparing packet burst to transmit failed: %s\n", rte_strerror(rte_errno)); - nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, pkts_burst, + nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, tx_pkts_burst, nb_prep); /* @@ -868,7 +922,7 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) { rte_delay_us(burst_tx_delay_time); nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue, - &pkts_burst[nb_tx], nb_rx - nb_tx); + &tx_pkts_burst[nb_tx], nb_rx - nb_tx); } } fs->tx_packets += nb_tx; @@ -881,9 +935,10 @@ pkt_burst_checksum_forward(struct fwd_stream *fs) if (unlikely(nb_tx < nb_rx)) { fs->fwd_dropped += (nb_rx - nb_tx); do { - rte_pktmbuf_free(pkts_burst[nb_tx]); + rte_pktmbuf_free(tx_pkts_burst[nb_tx]); } while (++nb_tx < nb_rx); } + #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES end_tsc = rte_rdtsc(); core_cycles = (end_tsc - start_tsc); diff --git a/app/test-pmd/flowgen.c b/app/test-pmd/flowgen.c index 54e56f60..acf9af94 100644 --- a/app/test-pmd/flowgen.c +++ b/app/test-pmd/flowgen.c @@ -50,7 +50,6 @@ #include <rte_cycles.h> #include <rte_memory.h> #include <rte_memcpy.h> -#include <rte_memzone.h> #include <rte_launch.h> #include <rte_eal.h> #include <rte_per_lcore.h> diff --git a/app/test-pmd/ieee1588fwd.c b/app/test-pmd/ieee1588fwd.c index 51170ee3..91ee7864 100644 --- a/app/test-pmd/ieee1588fwd.c +++ b/app/test-pmd/ieee1588fwd.c @@ -86,12 +86,11 @@ port_ieee1588_rx_timestamp_check(portid_t pi, uint32_t index) struct timespec timestamp = {0, 0}; if (rte_eth_timesync_read_rx_timestamp(pi, ×tamp, index) < 0) { - printf("Port %u RX timestamp registers not valid\n", - (unsigned) pi); + printf("Port %u RX timestamp registers not valid\n", pi); return; } printf("Port %u RX timestamp value %lu s %lu ns\n", - (unsigned) pi, timestamp.tv_sec, timestamp.tv_nsec); + pi, timestamp.tv_sec, timestamp.tv_nsec); } #define MAX_TX_TMST_WAIT_MICROSECS 1000 /**< 1 milli-second */ @@ -110,12 +109,12 @@ port_ieee1588_tx_timestamp_check(portid_t pi) if (wait_us >= MAX_TX_TMST_WAIT_MICROSECS) { printf("Port %u TX timestamp registers not valid after " "%u micro-seconds\n", - (unsigned) pi, (unsigned) MAX_TX_TMST_WAIT_MICROSECS); + pi, MAX_TX_TMST_WAIT_MICROSECS); return; } printf("Port %u TX timestamp value %lu s %lu ns validated after " "%u micro-second%s\n", - (unsigned) pi, timestamp.tv_sec, timestamp.tv_nsec, wait_us, + pi, timestamp.tv_sec, timestamp.tv_nsec, wait_us, (wait_us == 1) ? "" : "s"); } @@ -148,11 +147,11 @@ ieee1588_packet_fwd(struct fwd_stream *fs) if (eth_type == ETHER_TYPE_1588) { printf("Port %u Received PTP packet not filtered" " by hardware\n", - (unsigned) fs->rx_port); + fs->rx_port); } else { printf("Port %u Received non PTP packet type=0x%4x " "len=%u\n", - (unsigned) fs->rx_port, eth_type, + fs->rx_port, eth_type, (unsigned) mb->pkt_len); } rte_pktmbuf_free(mb); @@ -161,7 +160,7 @@ ieee1588_packet_fwd(struct fwd_stream *fs) if (eth_type != ETHER_TYPE_1588) { printf("Port %u Received NON PTP packet incorrectly" " detected by hardware\n", - (unsigned) fs->rx_port); + fs->rx_port); rte_pktmbuf_free(mb); return; } @@ -175,19 +174,19 @@ ieee1588_packet_fwd(struct fwd_stream *fs) if (ptp_hdr->version != 0x02) { printf("Port %u Received PTP V2 Ethernet frame with wrong PTP" " protocol version 0x%x (should be 0x02)\n", - (unsigned) fs->rx_port, ptp_hdr->version); + fs->rx_port, ptp_hdr->version); rte_pktmbuf_free(mb); return; } if (ptp_hdr->msg_id != PTP_SYNC_MESSAGE) { printf("Port %u Received PTP V2 Ethernet frame with unexpected" " message ID 0x%x (expected 0x0 - PTP_SYNC_MESSAGE)\n", - (unsigned) fs->rx_port, ptp_hdr->msg_id); + fs->rx_port, ptp_hdr->msg_id); rte_pktmbuf_free(mb); return; } printf("Port %u IEEE1588 PTP V2 SYNC Message filtered by hardware\n", - (unsigned) fs->rx_port); + fs->rx_port); /* * Check that the received PTP packet has been timestamped by the @@ -196,7 +195,7 @@ ieee1588_packet_fwd(struct fwd_stream *fs) if (! (mb->ol_flags & PKT_RX_IEEE1588_TMST)) { printf("Port %u Received PTP packet not timestamped" " by hardware\n", - (unsigned) fs->rx_port); + fs->rx_port); rte_pktmbuf_free(mb); return; } @@ -216,8 +215,7 @@ ieee1588_packet_fwd(struct fwd_stream *fs) mb->ol_flags |= PKT_TX_IEEE1588_TMST; fs->tx_packets += 1; if (rte_eth_tx_burst(fs->rx_port, fs->tx_queue, &mb, 1) == 0) { - printf("Port %u sent PTP packet dropped\n", - (unsigned) fs->rx_port); + printf("Port %u sent PTP packet dropped\n", fs->rx_port); fs->fwd_dropped += 1; rte_pktmbuf_free(mb); return; diff --git a/app/test-pmd/iofwd.c b/app/test-pmd/iofwd.c index 9b54f654..ff6de45c 100644 --- a/app/test-pmd/iofwd.c +++ b/app/test-pmd/iofwd.c @@ -48,7 +48,6 @@ #include <rte_debug.h> #include <rte_cycles.h> #include <rte_memory.h> -#include <rte_memzone.h> #include <rte_launch.h> #include <rte_eal.h> #include <rte_per_lcore.h> diff --git a/app/test-pmd/macfwd.c b/app/test-pmd/macfwd.c index 06dbc73a..f4a4bf29 100644 --- a/app/test-pmd/macfwd.c +++ b/app/test-pmd/macfwd.c @@ -49,7 +49,6 @@ #include <rte_cycles.h> #include <rte_memory.h> #include <rte_memcpy.h> -#include <rte_memzone.h> #include <rte_launch.h> #include <rte_eal.h> #include <rte_per_lcore.h> diff --git a/app/test-pmd/macswap.c b/app/test-pmd/macswap.c index 19cda0ea..721865c9 100644 --- a/app/test-pmd/macswap.c +++ b/app/test-pmd/macswap.c @@ -49,7 +49,6 @@ #include <rte_cycles.h> #include <rte_memory.h> #include <rte_memcpy.h> -#include <rte_memzone.h> #include <rte_launch.h> #include <rte_eal.h> #include <rte_per_lcore.h> diff --git a/app/test-pmd/parameters.c b/app/test-pmd/parameters.c index 2f7f70fd..84e7a63e 100644 --- a/app/test-pmd/parameters.c +++ b/app/test-pmd/parameters.c @@ -55,7 +55,6 @@ #include <rte_debug.h> #include <rte_cycles.h> #include <rte_memory.h> -#include <rte_memzone.h> #include <rte_launch.h> #include <rte_eal.h> #include <rte_per_lcore.h> @@ -162,6 +161,7 @@ usage(char* progname) printf(" --disable-crc-strip: disable CRC stripping by hardware.\n"); printf(" --enable-lro: enable large receive offload.\n"); printf(" --enable-rx-cksum: enable rx hardware checksum offload.\n"); + printf(" --enable-rx-timestamp: enable rx hardware timestamp offload.\n"); printf(" --disable-hw-vlan: disable hardware vlan.\n"); printf(" --disable-hw-vlan-filter: disable hardware vlan filter.\n"); printf(" --disable-hw-vlan-strip: disable hardware vlan strip.\n"); @@ -393,7 +393,8 @@ parse_portnuma_config(const char *q_arg) char s[256]; const char *p, *p0 = q_arg; char *end; - uint8_t i,port_id,socket_id; + uint8_t i, socket_id; + portid_t port_id; unsigned size; enum fieldnames { FLD_PORT = 0, @@ -423,8 +424,9 @@ parse_portnuma_config(const char *q_arg) if (errno != 0 || end == str_fld[i] || int_fld[i] > 255) return -1; } - port_id = (uint8_t)int_fld[FLD_PORT]; - if (port_id_is_invalid(port_id, ENABLED_WARN)) { + port_id = (portid_t)int_fld[FLD_PORT]; + if (port_id_is_invalid(port_id, ENABLED_WARN) || + port_id == (portid_t)RTE_PORT_ALL) { printf("Valid port range is [0"); RTE_ETH_FOREACH_DEV(pid) printf(", %d", pid); @@ -448,7 +450,8 @@ parse_ringnuma_config(const char *q_arg) char s[256]; const char *p, *p0 = q_arg; char *end; - uint8_t i,port_id,ring_flag,socket_id; + uint8_t i, ring_flag, socket_id; + portid_t port_id; unsigned size; enum fieldnames { FLD_PORT = 0, @@ -482,8 +485,9 @@ parse_ringnuma_config(const char *q_arg) if (errno != 0 || end == str_fld[i] || int_fld[i] > 255) return -1; } - port_id = (uint8_t)int_fld[FLD_PORT]; - if (port_id_is_invalid(port_id, ENABLED_WARN)) { + port_id = (portid_t)int_fld[FLD_PORT]; + if (port_id_is_invalid(port_id, ENABLED_WARN) || + port_id == (portid_t)RTE_PORT_ALL) { printf("Valid port range is [0"); RTE_ETH_FOREACH_DEV(pid) printf(", %d", pid); @@ -601,6 +605,7 @@ launch_args_parse(int argc, char** argv) { "disable-crc-strip", 0, 0, 0 }, { "enable-lro", 0, 0, 0 }, { "enable-rx-cksum", 0, 0, 0 }, + { "enable-rx-timestamp", 0, 0, 0 }, { "enable-scatter", 0, 0, 0 }, { "disable-hw-vlan", 0, 0, 0 }, { "disable-hw-vlan-filter", 0, 0, 0 }, @@ -734,7 +739,7 @@ launch_args_parse(int argc, char** argv) if (!strcmp(lgopts[opt_idx].name, "nb-ports")) { n = atoi(optarg); if (n > 0 && n <= nb_ports) - nb_fwd_ports = (uint8_t) n; + nb_fwd_ports = n; else rte_exit(EXIT_FAILURE, "Invalid port %d\n", n); @@ -899,6 +904,9 @@ launch_args_parse(int argc, char** argv) rx_mode.enable_scatter = 1; if (!strcmp(lgopts[opt_idx].name, "enable-rx-cksum")) rx_mode.hw_ip_checksum = 1; + if (!strcmp(lgopts[opt_idx].name, + "enable-rx-timestamp")) + rx_mode.hw_timestamp = 1; if (!strcmp(lgopts[opt_idx].name, "disable-hw-vlan")) { rx_mode.hw_vlan_filter = 0; @@ -932,7 +940,7 @@ launch_args_parse(int argc, char** argv) port_topology = PORT_TOPOLOGY_LOOP; else rte_exit(EXIT_FAILURE, "port-topology %s invalid -" - " must be: paired or chained \n", + " must be: paired, chained or loop\n", optarg); } if (!strcmp(lgopts[opt_idx].name, "forward-mode")) diff --git a/app/test-pmd/rxonly.c b/app/test-pmd/rxonly.c index 5ef02190..fb6e8e33 100644 --- a/app/test-pmd/rxonly.c +++ b/app/test-pmd/rxonly.c @@ -49,7 +49,6 @@ #include <rte_cycles.h> #include <rte_memory.h> #include <rte_memcpy.h> -#include <rte_memzone.h> #include <rte_launch.h> #include <rte_eal.h> #include <rte_per_lcore.h> @@ -122,7 +121,7 @@ pkt_burst_receive(struct fwd_stream *fs) */ if (verbose_level > 0) printf("port %u/queue %u: received %u packets\n", - (unsigned) fs->rx_port, + fs->rx_port, (unsigned) fs->rx_queue, (unsigned) nb_rx); for (i = 0; i < nb_rx; i++) { @@ -158,6 +157,8 @@ pkt_burst_receive(struct fwd_stream *fs) printf("hash=0x%x ID=0x%x ", mb->hash.fdir.hash, mb->hash.fdir.id); } + if (ol_flags & PKT_RX_TIMESTAMP) + printf(" - timestamp %"PRIu64" ", mb->timestamp); if (ol_flags & PKT_RX_VLAN_STRIPPED) printf(" - VLAN tci=0x%x", mb->vlan_tci); if (ol_flags & PKT_RX_QINQ_STRIPPED) diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 7d401394..c3ab4484 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -38,6 +38,7 @@ #include <string.h> #include <time.h> #include <fcntl.h> +#include <sys/mman.h> #include <sys/types.h> #include <errno.h> @@ -56,7 +57,6 @@ #include <rte_cycles.h> #include <rte_memory.h> #include <rte_memcpy.h> -#include <rte_memzone.h> #include <rte_launch.h> #include <rte_eal.h> #include <rte_alarm.h> @@ -76,9 +76,6 @@ #ifdef RTE_LIBRTE_IXGBE_PMD #include <rte_pmd_ixgbe.h> #endif -#ifdef RTE_LIBRTE_PMD_XENVIRT -#include <rte_eth_xenvirt.h> -#endif #ifdef RTE_LIBRTE_PDUMP #include <rte_pdump.h> #endif @@ -90,7 +87,6 @@ #ifdef RTE_LIBRTE_LATENCY_STATS #include <rte_latencystats.h> #endif -#include <rte_gro.h> #include "testpmd.h" @@ -167,6 +163,10 @@ struct fwd_engine * fwd_engines[] = { &tx_only_engine, &csum_fwd_engine, &icmp_echo_engine, +#if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED + &softnic_tm_engine, + &softnic_tm_bypass_engine, +#endif #ifdef RTE_LIBRTE_IEEE1588 &ieee1588_fwd_engine, #endif @@ -183,6 +183,13 @@ uint16_t mbuf_data_size = DEFAULT_MBUF_DATA_SIZE; /**< Mbuf data space size. */ uint32_t param_total_num_mbufs = 0; /**< number of mbufs in all pools - if * specified on command-line. */ uint16_t stats_period; /**< Period to show statistics (disabled by default) */ + +/* + * In container, it cannot terminate the process which running with 'stats-period' + * option. Set flag to exit stats period loop after received SIGINT/SIGTERM. + */ +uint8_t f_quit; + /* * Configuration of packet segments used by the "txonly" processing engine. */ @@ -339,6 +346,7 @@ struct rte_eth_rxmode rx_mode = { .hw_vlan_extend = 0, /**< Extended VLAN disabled. */ .jumbo_frame = 0, /**< Jumbo Frame Support disabled. */ .hw_strip_crc = 1, /**< CRC stripping by hardware enabled. */ + .hw_timestamp = 0, /**< HW timestamp enabled. */ }; struct rte_fdir_conf fdir_conf = { @@ -375,6 +383,11 @@ struct queue_stats_mappings *rx_queue_stats_mappings = rx_queue_stats_mappings_a uint16_t nb_tx_queue_stats_mappings = 0; uint16_t nb_rx_queue_stats_mappings = 0; +/* + * Display zero values by default for xstats + */ +uint8_t xstats_hide_zero; + unsigned int num_sockets = 0; unsigned int socket_ids[RTE_MAX_NUMA_NODES]; @@ -386,11 +399,13 @@ uint8_t bitrate_enabled; #endif struct gro_status gro_ports[RTE_MAX_ETHPORTS]; +uint8_t gro_flush_cycles = GRO_DEFAULT_FLUSH_CYCLES; /* Forward function declarations */ -static void map_port_queue_stats_mapping_registers(uint8_t pi, struct rte_port *port); +static void map_port_queue_stats_mapping_registers(portid_t pi, + struct rte_port *port); static void check_all_ports_link_status(uint32_t port_mask); -static int eth_event_callback(uint8_t port_id, +static int eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, void *ret_param); @@ -400,6 +415,9 @@ static int eth_event_callback(uint8_t port_id, */ static int all_ports_started(void); +struct gso_status gso_ports[RTE_MAX_ETHPORTS]; +uint16_t gso_max_segment_size = ETHER_MAX_LEN - ETHER_CRC_LEN; + /* * Helper function to check if socket is already discovered. * If yes, return positive value. If not, return zero. @@ -463,9 +481,10 @@ static void set_default_fwd_ports_config(void) { portid_t pt_id; + int i = 0; - for (pt_id = 0; pt_id < nb_ports; pt_id++) - fwd_ports_ids[pt_id] = pt_id; + RTE_ETH_FOREACH_DEV(pt_id) + fwd_ports_ids[i++] = pt_id; nb_cfg_ports = nb_ports; nb_fwd_ports = nb_ports; @@ -497,37 +516,25 @@ mbuf_pool_create(uint16_t mbuf_seg_size, unsigned nb_mbuf, "create a new mbuf pool <%s>: n=%u, size=%u, socket=%u\n", pool_name, nb_mbuf, mbuf_seg_size, socket_id); -#ifdef RTE_LIBRTE_PMD_XENVIRT - rte_mp = rte_mempool_gntalloc_create(pool_name, nb_mbuf, mb_size, - (unsigned) mb_mempool_cache, - sizeof(struct rte_pktmbuf_pool_private), - rte_pktmbuf_pool_init, NULL, - rte_pktmbuf_init, NULL, - socket_id, 0); -#endif - - /* if the former XEN allocation failed fall back to normal allocation */ - if (rte_mp == NULL) { - if (mp_anon != 0) { - rte_mp = rte_mempool_create_empty(pool_name, nb_mbuf, - mb_size, (unsigned) mb_mempool_cache, - sizeof(struct rte_pktmbuf_pool_private), - socket_id, 0); - if (rte_mp == NULL) - goto err; - - if (rte_mempool_populate_anon(rte_mp) == 0) { - rte_mempool_free(rte_mp); - rte_mp = NULL; - goto err; - } - rte_pktmbuf_pool_init(rte_mp, NULL); - rte_mempool_obj_iter(rte_mp, rte_pktmbuf_init, NULL); - } else { - /* wrapper to rte_mempool_create() */ - rte_mp = rte_pktmbuf_pool_create(pool_name, nb_mbuf, - mb_mempool_cache, 0, mbuf_seg_size, socket_id); + if (mp_anon != 0) { + rte_mp = rte_mempool_create_empty(pool_name, nb_mbuf, + mb_size, (unsigned) mb_mempool_cache, + sizeof(struct rte_pktmbuf_pool_private), + socket_id, 0); + if (rte_mp == NULL) + goto err; + + if (rte_mempool_populate_anon(rte_mp) == 0) { + rte_mempool_free(rte_mp); + rte_mp = NULL; + goto err; } + rte_pktmbuf_pool_init(rte_mp, NULL); + rte_mempool_obj_iter(rte_mp, rte_pktmbuf_init, NULL); + } else { + /* wrapper to rte_mempool_create() */ + rte_mp = rte_pktmbuf_pool_create(pool_name, nb_mbuf, + mb_mempool_cache, 0, mbuf_seg_size, socket_id); } err: @@ -570,6 +577,8 @@ init_config(void) unsigned int nb_mbuf_per_pool; lcoreid_t lc_id; uint8_t port_per_socket[RTE_MAX_NUMA_NODES]; + struct rte_gro_param gro_param; + uint32_t gso_types; memset(port_per_socket,0,RTE_MAX_NUMA_NODES); @@ -654,6 +663,8 @@ init_config(void) init_port_config(); + gso_types = DEV_TX_OFFLOAD_TCP_TSO | DEV_TX_OFFLOAD_VXLAN_TNL_TSO | + DEV_TX_OFFLOAD_GRE_TNL_TSO; /* * Records which Mbuf pool to use by each logical core, if needed. */ @@ -664,6 +675,13 @@ init_config(void) if (mbp == NULL) mbp = mbuf_pool_find(0); fwd_lcores[lc_id]->mbp = mbp; + /* initialize GSO context */ + fwd_lcores[lc_id]->gso_ctx.direct_pool = mbp; + fwd_lcores[lc_id]->gso_ctx.indirect_pool = mbp; + fwd_lcores[lc_id]->gso_ctx.gso_types = gso_types; + fwd_lcores[lc_id]->gso_ctx.gso_size = ETHER_MAX_LEN - + ETHER_CRC_LEN; + fwd_lcores[lc_id]->gso_ctx.flag = 0; } /* Configuration of packet forwarding streams. */ @@ -671,6 +689,20 @@ init_config(void) rte_exit(EXIT_FAILURE, "FAIL from init_fwd_streams()\n"); fwd_config_setup(); + + /* create a gro context for each lcore */ + gro_param.gro_types = RTE_GRO_TCP_IPV4; + gro_param.max_flow_num = GRO_MAX_FLUSH_CYCLES; + gro_param.max_item_per_flow = MAX_PKT_BURST; + for (lc_id = 0; lc_id < nb_lcores; lc_id++) { + gro_param.socket_id = rte_lcore_to_socket_id( + fwd_lcores_cpuids[lc_id]); + fwd_lcores[lc_id]->gro_ctx = rte_gro_ctx_create(&gro_param); + if (fwd_lcores[lc_id]->gro_ctx == NULL) { + rte_exit(EXIT_FAILURE, + "rte_gro_ctx_create() failed\n"); + } + } } @@ -1217,6 +1249,7 @@ stop_packet_forwarding(void) #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES uint64_t fwd_cycles; #endif + static const char *acc_stats_border = "+++++++++++++++"; if (test_done) { @@ -1307,6 +1340,7 @@ stop_packet_forwarding(void) fwd_port_stats_display(pt_id, &stats); } + printf("\n %s Accumulated forward statistics for all ports" "%s\n", acc_stats_border, acc_stats_border); @@ -1335,14 +1369,14 @@ stop_packet_forwarding(void) void dev_set_link_up(portid_t pid) { - if (rte_eth_dev_set_link_up((uint8_t)pid) < 0) + if (rte_eth_dev_set_link_up(pid) < 0) printf("\nSet link up fail.\n"); } void dev_set_link_down(portid_t pid) { - if (rte_eth_dev_set_link_down((uint8_t)pid) < 0) + if (rte_eth_dev_set_link_down(pid) < 0) printf("\nSet link down fail.\n"); } @@ -1683,6 +1717,47 @@ close_port(portid_t pid) } void +reset_port(portid_t pid) +{ + int diag; + portid_t pi; + struct rte_port *port; + + if (port_id_is_invalid(pid, ENABLED_WARN)) + return; + + printf("Resetting ports...\n"); + + RTE_ETH_FOREACH_DEV(pi) { + if (pid != pi && pid != (portid_t)RTE_PORT_ALL) + continue; + + if (port_is_forwarding(pi) != 0 && test_done == 0) { + printf("Please remove port %d from forwarding " + "configuration.\n", pi); + continue; + } + + if (port_is_bonding_slave(pi)) { + printf("Please remove port %d from bonded device.\n", + pi); + continue; + } + + diag = rte_eth_dev_reset(pi); + if (diag == 0) { + port = &ports[pi]; + port->need_reconfig = 1; + port->need_reconfig_queues = 1; + } else { + printf("Failed to reset port %d. diag=%d\n", pi, diag); + } + } + + printf("Done\n"); +} + +void attach_port(char *identifier) { portid_t pi = 0; @@ -1714,7 +1789,7 @@ attach_port(char *identifier) } void -detach_port(uint8_t port_id) +detach_port(portid_t port_id) { char name[RTE_ETH_NAME_MAX_LEN]; @@ -1775,7 +1850,8 @@ check_all_ports_link_status(uint32_t port_mask) { #define CHECK_INTERVAL 100 /* 100ms */ #define MAX_CHECK_TIME 90 /* 9s (90 * 100ms) in total */ - uint8_t portid, count, all_ports_up, print_flag = 0; + portid_t portid; + uint8_t count, all_ports_up, print_flag = 0; struct rte_eth_link link; printf("Checking link statuses...\n"); @@ -1790,14 +1866,13 @@ check_all_ports_link_status(uint32_t port_mask) /* print link status if flag set */ if (print_flag == 1) { if (link.link_status) - printf("Port %d Link Up - speed %u " - "Mbps - %s\n", (uint8_t)portid, - (unsigned)link.link_speed, + printf( + "Port%d Link Up. speed %u Mbps- %s\n", + portid, link.link_speed, (link.link_duplex == ETH_LINK_FULL_DUPLEX) ? ("full-duplex") : ("half-duplex\n")); else - printf("Port %d Link Down\n", - (uint8_t)portid); + printf("Port %d Link Down\n", portid); continue; } /* clear all_ports_up flag if any link down */ @@ -1829,7 +1904,7 @@ static void rmv_event_callback(void *arg) { struct rte_eth_dev *dev; - uint8_t port_id = (intptr_t)arg; + portid_t port_id = (intptr_t)arg; RTE_ETH_VALID_PORTID_OR_RET(port_id); dev = &rte_eth_devices[port_id]; @@ -1844,7 +1919,7 @@ rmv_event_callback(void *arg) /* This function is used by the interrupt thread */ static int -eth_event_callback(uint8_t port_id, enum rte_eth_event_type type, void *param, +eth_event_callback(portid_t port_id, enum rte_eth_event_type type, void *param, void *ret_param) { static const char * const event_desc[] = { @@ -1884,7 +1959,7 @@ eth_event_callback(uint8_t port_id, enum rte_eth_event_type type, void *param, } static int -set_tx_queue_stats_mapping_registers(uint8_t port_id, struct rte_port *port) +set_tx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port) { uint16_t i; int diag; @@ -1907,7 +1982,7 @@ set_tx_queue_stats_mapping_registers(uint8_t port_id, struct rte_port *port) } static int -set_rx_queue_stats_mapping_registers(uint8_t port_id, struct rte_port *port) +set_rx_queue_stats_mapping_registers(portid_t port_id, struct rte_port *port) { uint16_t i; int diag; @@ -1930,7 +2005,7 @@ set_rx_queue_stats_mapping_registers(uint8_t port_id, struct rte_port *port) } static void -map_port_queue_stats_mapping_registers(uint8_t pi, struct rte_port *port) +map_port_queue_stats_mapping_registers(portid_t pi, struct rte_port *port) { int diag = 0; @@ -2044,6 +2119,17 @@ init_port_config(void) (rte_eth_devices[pid].data->dev_flags & RTE_ETH_DEV_INTR_RMV)) port->dev_conf.intr_conf.rmv = 1; + +#if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED + /* Detect softnic port */ + if (!strcmp(port->dev_info.driver_name, "net_softnic")) { + port->softnic_enable = 1; + memset(&port->softport, 0, sizeof(struct softnic_port)); + + if (!strcmp(cur_fwd_eng->fwd_mode_name, "tm")) + port->softport.tm_flag = 1; + } +#endif } } @@ -2111,8 +2197,8 @@ get_eth_dcb_conf(struct rte_eth_conf *eth_conf, 1 << (i % vmdq_rx_conf->nb_queue_pools); } for (i = 0; i < ETH_DCB_NUM_USER_PRIORITIES; i++) { - vmdq_rx_conf->dcb_tc[i] = i; - vmdq_tx_conf->dcb_tc[i] = i; + vmdq_rx_conf->dcb_tc[i] = i % num_tcs; + vmdq_tx_conf->dcb_tc[i] = i % num_tcs; } /* set DCB mode of RX and TX of multiple queues */ @@ -2173,7 +2259,7 @@ init_port_dcb_config(portid_t pid, * Set the numbers of RX & TX queues to 0, so * the RX & TX queues will not be setup. */ - (void)rte_eth_dev_configure(pid, 0, 0, &port_conf); + rte_eth_dev_configure(pid, 0, 0, &port_conf); rte_eth_dev_info_get(pid, &rte_port->dev_info); @@ -2277,6 +2363,8 @@ signal_handler(int signum) rte_latencystats_uninit(); #endif force_quit(); + /* Set flag to indicate the force termination. */ + f_quit = 1; /* exit with the expected status */ signal(signum, SIG_DFL); kill(getpid(), signum); @@ -2287,7 +2375,7 @@ int main(int argc, char** argv) { int diag; - uint8_t port_id; + portid_t port_id; signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); @@ -2296,6 +2384,11 @@ main(int argc, char** argv) if (diag < 0) rte_panic("Cannot init EAL\n"); + if (mlockall(MCL_CURRENT | MCL_FUTURE)) { + RTE_LOG(NOTICE, USER1, "mlockall() failed with error \"%s\"\n", + strerror(errno)); + } + #ifdef RTE_LIBRTE_PDUMP /* initialize packet capture framework */ rte_pdump_init(NULL); @@ -2394,6 +2487,8 @@ main(int argc, char** argv) char c; int rc; + f_quit = 0; + printf("No commandline core given, start packet forwarding\n"); start_packet_forwarding(tx_first); if (stats_period != 0) { @@ -2403,7 +2498,7 @@ main(int argc, char** argv) /* Convert to number of cycles */ timer_period = stats_period * rte_get_timer_hz(); - while (1) { + while (f_quit == 0) { cur_time = rte_get_timer_cycles(); diff_time += cur_time - prev_time; diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index c9d7739b..1639d27e 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -35,7 +35,9 @@ #define _TESTPMD_H_ #include <rte_pci.h> +#include <rte_bus_pci.h> #include <rte_gro.h> +#include <rte_gso.h> #define RTE_PORT_ALL (~(portid_t)0x0) @@ -78,12 +80,18 @@ #define UMA_NO_CONFIG 0xFF typedef uint8_t lcoreid_t; -typedef uint8_t portid_t; +typedef uint16_t portid_t; typedef uint16_t queueid_t; typedef uint16_t streamid_t; #define MAX_QUEUE_ID ((1 << (sizeof(queueid_t) * 8)) - 1) +#if defined RTE_LIBRTE_PMD_SOFTNIC && defined RTE_LIBRTE_SCHED +#define TM_MODE 1 +#else +#define TM_MODE 0 +#endif + enum { PORT_TOPOLOGY_PAIRED, PORT_TOPOLOGY_CHAINED, @@ -120,6 +128,7 @@ struct fwd_stream { unsigned int fwd_dropped; /**< received packets not forwarded */ unsigned int rx_bad_ip_csum ; /**< received packets has bad ip checksum */ unsigned int rx_bad_l4_csum ; /**< received packets has bad l4 checksum */ + unsigned int gro_times; /**< GRO operation times */ #ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES uint64_t core_cycles; /**< used for RX and TX processing */ #endif @@ -162,6 +171,38 @@ struct port_flow { uint8_t data[]; /**< Storage for pattern/actions. */ }; +#ifdef TM_MODE +/** + * Soft port tm related parameters + */ +struct softnic_port_tm { + uint32_t default_hierarchy_enable; /**< def hierarchy enable flag */ + uint32_t hierarchy_config; /**< set to 1 if hierarchy configured */ + + uint32_t n_subports_per_port; /**< Num of subport nodes per port */ + uint32_t n_pipes_per_subport; /**< Num of pipe nodes per subport */ + + uint64_t tm_pktfield0_slabpos; /**< Pkt field position for subport */ + uint64_t tm_pktfield0_slabmask; /**< Pkt field mask for the subport */ + uint64_t tm_pktfield0_slabshr; + uint64_t tm_pktfield1_slabpos; /**< Pkt field position for the pipe */ + uint64_t tm_pktfield1_slabmask; /**< Pkt field mask for the pipe */ + uint64_t tm_pktfield1_slabshr; + uint64_t tm_pktfield2_slabpos; /**< Pkt field position table index */ + uint64_t tm_pktfield2_slabmask; /**< Pkt field mask for tc table idx */ + uint64_t tm_pktfield2_slabshr; + uint64_t tm_tc_table[64]; /**< TC translation table */ +}; + +/** + * The data structure associate with softnic port + */ +struct softnic_port { + unsigned int tm_flag; /**< set to 1 if tm feature is enabled */ + struct softnic_port_tm tm; /**< softnic port tm parameters */ +}; +#endif + /** * The data structure associated with each port. */ @@ -195,6 +236,10 @@ struct rte_port { uint32_t mc_addr_nb; /**< nb. of addr. in mc_addr_pool */ uint8_t slave_flag; /**< bonding slave port */ struct port_flow *flow_list; /**< Associated flows. */ +#ifdef TM_MODE + unsigned int softnic_enable; /**< softnic flag */ + struct softnic_port softport; /**< softnic port params */ +#endif }; /** @@ -205,7 +250,9 @@ struct rte_port { * CPU id. configuration table. */ struct fwd_lcore { + struct rte_gso_ctx gso_ctx; /**< GSO context */ struct rte_mempool *mbp; /**< The mbuf pool to use by this core */ + void *gro_ctx; /**< GRO context */ streamid_t stream_idx; /**< index of 1st stream in "fwd_streams" */ streamid_t stream_nb; /**< number of streams in "fwd_streams" */ lcoreid_t cpuid_idx; /**< index of logical core in CPU id table */ @@ -253,6 +300,10 @@ extern struct fwd_engine rx_only_engine; extern struct fwd_engine tx_only_engine; extern struct fwd_engine csum_fwd_engine; extern struct fwd_engine icmp_echo_engine; +#ifdef TM_MODE +extern struct fwd_engine softnic_tm_engine; +extern struct fwd_engine softnic_tm_bypass_engine; +#endif #ifdef RTE_LIBRTE_IEEE1588 extern struct fwd_engine ieee1588_fwd_engine; #endif @@ -283,7 +334,7 @@ enum dcb_mode_enable #define MAX_RX_QUEUE_STATS_MAPPINGS 4096 /* MAX_PORT of 32 @ 128 rx_queues/port */ struct queue_stats_mappings { - uint8_t port_id; + portid_t port_id; uint16_t queue_id; uint8_t stats_counter_id; } __rte_cache_aligned; @@ -298,6 +349,8 @@ extern struct queue_stats_mappings *rx_queue_stats_mappings; extern uint16_t nb_tx_queue_stats_mappings; extern uint16_t nb_rx_queue_stats_mappings; +extern uint8_t xstats_hide_zero; /**< Hide zero values for xstats display */ + /* globals used for configuration */ extern uint16_t verbose_level; /**< Drives messages being displayed, if any. */ extern uint8_t interactive; @@ -434,13 +487,26 @@ extern struct ether_addr peer_eth_addrs[RTE_MAX_ETHPORTS]; extern uint32_t burst_tx_delay_time; /**< Burst tx delay time(us) for mac-retry. */ extern uint32_t burst_tx_retry_num; /**< Burst tx retry number for mac-retry. */ -#define GRO_DEFAULT_FLOW_NUM 4 -#define GRO_DEFAULT_ITEM_NUM_PER_FLOW DEF_PKT_BURST +#define GRO_DEFAULT_ITEM_NUM_PER_FLOW 32 +#define GRO_DEFAULT_FLOW_NUM (RTE_GRO_MAX_BURST_ITEM_NUM / \ + GRO_DEFAULT_ITEM_NUM_PER_FLOW) + +#define GRO_DEFAULT_FLUSH_CYCLES 1 +#define GRO_MAX_FLUSH_CYCLES 4 + struct gro_status { struct rte_gro_param param; uint8_t enable; }; extern struct gro_status gro_ports[RTE_MAX_ETHPORTS]; +extern uint8_t gro_flush_cycles; + +#define GSO_MAX_PKT_BURST 2048 +struct gso_status { + uint8_t enable; +}; +extern struct gso_status gso_ports[RTE_MAX_ETHPORTS]; +extern uint16_t gso_max_segment_size; static inline unsigned int lcore_num(void) @@ -587,6 +653,8 @@ void tx_vlan_pvid_set(portid_t port_id, uint16_t vlan_id, int on); void set_qmap(portid_t port_id, uint8_t is_rx, uint16_t queue_id, uint8_t map_value); +void set_xstats_hide_zero(uint8_t on_off); + void set_verbose_level(uint16_t vb_level); void set_tx_pkt_segments(unsigned *seg_lengths, unsigned nb_segs); void show_tx_pkt_segments(void); @@ -610,8 +678,9 @@ int init_port_dcb_config(portid_t pid, enum dcb_mode_enable dcb_mode, int start_port(portid_t pid); void stop_port(portid_t pid); void close_port(portid_t pid); +void reset_port(portid_t pid); void attach_port(char *identifier); -void detach_port(uint8_t port_id); +void detach_port(portid_t port_id); int all_ports_stopped(void); int port_is_started(portid_t port_id); void pmd_test_exit(void); @@ -634,23 +703,24 @@ void port_rss_hash_conf_show(portid_t port_id, char rss_info[], int show_rss_key); void port_rss_hash_key_update(portid_t port_id, char rss_type[], uint8_t *hash_key, uint hash_key_len); -void get_syn_filter(uint8_t port_id); -void get_ethertype_filter(uint8_t port_id, uint16_t index); -void get_2tuple_filter(uint8_t port_id, uint16_t index); -void get_5tuple_filter(uint8_t port_id, uint16_t index); int rx_queue_id_is_invalid(queueid_t rxq_id); int tx_queue_id_is_invalid(queueid_t txq_id); -void setup_gro(const char *mode, uint8_t port_id); +void setup_gro(const char *onoff, portid_t port_id); +void setup_gro_flush_cycles(uint8_t cycles); +void show_gro(portid_t port_id); +void setup_gso(const char *mode, portid_t port_id); /* Functions to manage the set of filtered Multicast MAC addresses */ -void mcast_addr_add(uint8_t port_id, struct ether_addr *mc_addr); -void mcast_addr_remove(uint8_t port_id, struct ether_addr *mc_addr); -void port_dcb_info_display(uint8_t port_id); +void mcast_addr_add(portid_t port_id, struct ether_addr *mc_addr); +void mcast_addr_remove(portid_t port_id, struct ether_addr *mc_addr); +void port_dcb_info_display(portid_t port_id); uint8_t *open_ddp_package_file(const char *file_path, uint32_t *size); int save_ddp_package_file(const char *file_path, uint8_t *buf, uint32_t size); int close_ddp_package_file(uint8_t *buf); +void port_queue_region_info_display(portid_t port_id, void *buf); + enum print_warning { ENABLED_WARN = 0, DISABLED_WARN diff --git a/app/test-pmd/tm.c b/app/test-pmd/tm.c new file mode 100644 index 00000000..dd837cb8 --- /dev/null +++ b/app/test-pmd/tm.c @@ -0,0 +1,865 @@ +/*- + * BSD LICENSE + * + * Copyright(c) 2017 Intel Corporation. All rights reserved. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in + * the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Intel Corporation nor the names of its + * contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +#include <stdio.h> +#include <sys/stat.h> + +#include <rte_cycles.h> +#include <rte_mbuf.h> +#include <rte_ethdev.h> +#include <rte_flow.h> +#include <rte_meter.h> +#include <rte_eth_softnic.h> +#include <rte_tm.h> + +#include "testpmd.h" + +#define SUBPORT_NODES_PER_PORT 1 +#define PIPE_NODES_PER_SUBPORT 4096 +#define TC_NODES_PER_PIPE 4 +#define QUEUE_NODES_PER_TC 4 + +#define NUM_PIPE_NODES \ + (SUBPORT_NODES_PER_PORT * PIPE_NODES_PER_SUBPORT) + +#define NUM_TC_NODES \ + (NUM_PIPE_NODES * TC_NODES_PER_PIPE) + +#define ROOT_NODE_ID 1000000 +#define SUBPORT_NODES_START_ID 900000 +#define PIPE_NODES_START_ID 800000 +#define TC_NODES_START_ID 700000 + +#define STATS_MASK_DEFAULT \ + (RTE_TM_STATS_N_PKTS | \ + RTE_TM_STATS_N_BYTES | \ + RTE_TM_STATS_N_PKTS_GREEN_DROPPED | \ + RTE_TM_STATS_N_BYTES_GREEN_DROPPED) + +#define STATS_MASK_QUEUE \ + (STATS_MASK_DEFAULT | \ + RTE_TM_STATS_N_PKTS_QUEUED) + +#define BYTES_IN_MBPS (1000 * 1000 / 8) +#define TOKEN_BUCKET_SIZE 1000000 + +/* TM Hierarchy Levels */ +enum tm_hierarchy_level { + TM_NODE_LEVEL_PORT = 0, + TM_NODE_LEVEL_SUBPORT, + TM_NODE_LEVEL_PIPE, + TM_NODE_LEVEL_TC, + TM_NODE_LEVEL_QUEUE, + TM_NODE_LEVEL_MAX, +}; + +struct tm_hierarchy { + /* TM Nodes */ + uint32_t root_node_id; + uint32_t subport_node_id[SUBPORT_NODES_PER_PORT]; + uint32_t pipe_node_id[SUBPORT_NODES_PER_PORT][PIPE_NODES_PER_SUBPORT]; + uint32_t tc_node_id[NUM_PIPE_NODES][TC_NODES_PER_PIPE]; + uint32_t queue_node_id[NUM_TC_NODES][QUEUE_NODES_PER_TC]; + + /* TM Hierarchy Nodes Shaper Rates */ + uint32_t root_node_shaper_rate; + uint32_t subport_node_shaper_rate; + uint32_t pipe_node_shaper_rate; + uint32_t tc_node_shaper_rate; + uint32_t tc_node_shared_shaper_rate; + + uint32_t n_shapers; +}; + +#define BITFIELD(byte_array, slab_pos, slab_mask, slab_shr) \ +({ \ + uint64_t slab = *((uint64_t *) &byte_array[slab_pos]); \ + uint64_t val = \ + (rte_be_to_cpu_64(slab) & slab_mask) >> slab_shr; \ + val; \ +}) + +#define RTE_SCHED_PORT_HIERARCHY(subport, pipe, \ + traffic_class, queue, color) \ + ((((uint64_t) (queue)) & 0x3) | \ + ((((uint64_t) (traffic_class)) & 0x3) << 2) | \ + ((((uint64_t) (color)) & 0x3) << 4) | \ + ((((uint64_t) (subport)) & 0xFFFF) << 16) | \ + ((((uint64_t) (pipe)) & 0xFFFFFFFF) << 32)) + + +static void +pkt_metadata_set(struct rte_port *p, struct rte_mbuf **pkts, + uint32_t n_pkts) +{ + struct softnic_port_tm *tm = &p->softport.tm; + uint32_t i; + + for (i = 0; i < (n_pkts & (~0x3)); i += 4) { + struct rte_mbuf *pkt0 = pkts[i]; + struct rte_mbuf *pkt1 = pkts[i + 1]; + struct rte_mbuf *pkt2 = pkts[i + 2]; + struct rte_mbuf *pkt3 = pkts[i + 3]; + + uint8_t *pkt0_data = rte_pktmbuf_mtod(pkt0, uint8_t *); + uint8_t *pkt1_data = rte_pktmbuf_mtod(pkt1, uint8_t *); + uint8_t *pkt2_data = rte_pktmbuf_mtod(pkt2, uint8_t *); + uint8_t *pkt3_data = rte_pktmbuf_mtod(pkt3, uint8_t *); + + uint64_t pkt0_subport = BITFIELD(pkt0_data, + tm->tm_pktfield0_slabpos, + tm->tm_pktfield0_slabmask, + tm->tm_pktfield0_slabshr); + uint64_t pkt0_pipe = BITFIELD(pkt0_data, + tm->tm_pktfield1_slabpos, + tm->tm_pktfield1_slabmask, + tm->tm_pktfield1_slabshr); + uint64_t pkt0_dscp = BITFIELD(pkt0_data, + tm->tm_pktfield2_slabpos, + tm->tm_pktfield2_slabmask, + tm->tm_pktfield2_slabshr); + uint32_t pkt0_tc = tm->tm_tc_table[pkt0_dscp & 0x3F] >> 2; + uint32_t pkt0_tc_q = tm->tm_tc_table[pkt0_dscp & 0x3F] & 0x3; + uint64_t pkt1_subport = BITFIELD(pkt1_data, + tm->tm_pktfield0_slabpos, + tm->tm_pktfield0_slabmask, + tm->tm_pktfield0_slabshr); + uint64_t pkt1_pipe = BITFIELD(pkt1_data, + tm->tm_pktfield1_slabpos, + tm->tm_pktfield1_slabmask, + tm->tm_pktfield1_slabshr); + uint64_t pkt1_dscp = BITFIELD(pkt1_data, + tm->tm_pktfield2_slabpos, + tm->tm_pktfield2_slabmask, + tm->tm_pktfield2_slabshr); + uint32_t pkt1_tc = tm->tm_tc_table[pkt1_dscp & 0x3F] >> 2; + uint32_t pkt1_tc_q = tm->tm_tc_table[pkt1_dscp & 0x3F] & 0x3; + + uint64_t pkt2_subport = BITFIELD(pkt2_data, + tm->tm_pktfield0_slabpos, + tm->tm_pktfield0_slabmask, + tm->tm_pktfield0_slabshr); + uint64_t pkt2_pipe = BITFIELD(pkt2_data, + tm->tm_pktfield1_slabpos, + tm->tm_pktfield1_slabmask, + tm->tm_pktfield1_slabshr); + uint64_t pkt2_dscp = BITFIELD(pkt2_data, + tm->tm_pktfield2_slabpos, + tm->tm_pktfield2_slabmask, + tm->tm_pktfield2_slabshr); + uint32_t pkt2_tc = tm->tm_tc_table[pkt2_dscp & 0x3F] >> 2; + uint32_t pkt2_tc_q = tm->tm_tc_table[pkt2_dscp & 0x3F] & 0x3; + + uint64_t pkt3_subport = BITFIELD(pkt3_data, + tm->tm_pktfield0_slabpos, + tm->tm_pktfield0_slabmask, + tm->tm_pktfield0_slabshr); + uint64_t pkt3_pipe = BITFIELD(pkt3_data, + tm->tm_pktfield1_slabpos, + tm->tm_pktfield1_slabmask, + tm->tm_pktfield1_slabshr); + uint64_t pkt3_dscp = BITFIELD(pkt3_data, + tm->tm_pktfield2_slabpos, + tm->tm_pktfield2_slabmask, + tm->tm_pktfield2_slabshr); + uint32_t pkt3_tc = tm->tm_tc_table[pkt3_dscp & 0x3F] >> 2; + uint32_t pkt3_tc_q = tm->tm_tc_table[pkt3_dscp & 0x3F] & 0x3; + + uint64_t pkt0_sched = RTE_SCHED_PORT_HIERARCHY(pkt0_subport, + pkt0_pipe, + pkt0_tc, + pkt0_tc_q, + 0); + uint64_t pkt1_sched = RTE_SCHED_PORT_HIERARCHY(pkt1_subport, + pkt1_pipe, + pkt1_tc, + pkt1_tc_q, + 0); + uint64_t pkt2_sched = RTE_SCHED_PORT_HIERARCHY(pkt2_subport, + pkt2_pipe, + pkt2_tc, + pkt2_tc_q, + 0); + uint64_t pkt3_sched = RTE_SCHED_PORT_HIERARCHY(pkt3_subport, + pkt3_pipe, + pkt3_tc, + pkt3_tc_q, + 0); + + pkt0->hash.sched.lo = pkt0_sched & 0xFFFFFFFF; + pkt0->hash.sched.hi = pkt0_sched >> 32; + pkt1->hash.sched.lo = pkt1_sched & 0xFFFFFFFF; + pkt1->hash.sched.hi = pkt1_sched >> 32; + pkt2->hash.sched.lo = pkt2_sched & 0xFFFFFFFF; + pkt2->hash.sched.hi = pkt2_sched >> 32; + pkt3->hash.sched.lo = pkt3_sched & 0xFFFFFFFF; + pkt3->hash.sched.hi = pkt3_sched >> 32; + } + + for (; i < n_pkts; i++) { + struct rte_mbuf *pkt = pkts[i]; + + uint8_t *pkt_data = rte_pktmbuf_mtod(pkt, uint8_t *); + + uint64_t pkt_subport = BITFIELD(pkt_data, + tm->tm_pktfield0_slabpos, + tm->tm_pktfield0_slabmask, + tm->tm_pktfield0_slabshr); + uint64_t pkt_pipe = BITFIELD(pkt_data, + tm->tm_pktfield1_slabpos, + tm->tm_pktfield1_slabmask, + tm->tm_pktfield1_slabshr); + uint64_t pkt_dscp = BITFIELD(pkt_data, + tm->tm_pktfield2_slabpos, + tm->tm_pktfield2_slabmask, + tm->tm_pktfield2_slabshr); + uint32_t pkt_tc = tm->tm_tc_table[pkt_dscp & 0x3F] >> 2; + uint32_t pkt_tc_q = tm->tm_tc_table[pkt_dscp & 0x3F] & 0x3; + + uint64_t pkt_sched = RTE_SCHED_PORT_HIERARCHY(pkt_subport, + pkt_pipe, + pkt_tc, + pkt_tc_q, + 0); + + pkt->hash.sched.lo = pkt_sched & 0xFFFFFFFF; + pkt->hash.sched.hi = pkt_sched >> 32; + } +} + +/* + * Soft port packet forward + */ +static void +softport_packet_fwd(struct fwd_stream *fs) +{ + struct rte_mbuf *pkts_burst[MAX_PKT_BURST]; + struct rte_port *rte_tx_port = &ports[fs->tx_port]; + uint16_t nb_rx; + uint16_t nb_tx; + uint32_t retry; + +#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES + uint64_t start_tsc; + uint64_t end_tsc; + uint64_t core_cycles; +#endif + +#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES + start_tsc = rte_rdtsc(); +#endif + + /* Packets Receive */ + nb_rx = rte_eth_rx_burst(fs->rx_port, fs->rx_queue, + pkts_burst, nb_pkt_per_burst); + fs->rx_packets += nb_rx; + +#ifdef RTE_TEST_PMD_RECORD_BURST_STATS + fs->rx_burst_stats.pkt_burst_spread[nb_rx]++; +#endif + + if (rte_tx_port->softnic_enable) { + /* Set packet metadata if tm flag enabled */ + if (rte_tx_port->softport.tm_flag) + pkt_metadata_set(rte_tx_port, pkts_burst, nb_rx); + + /* Softport run */ + rte_pmd_softnic_run(fs->tx_port); + } + nb_tx = rte_eth_tx_burst(fs->tx_port, fs->tx_queue, + pkts_burst, nb_rx); + + /* Retry if necessary */ + if (unlikely(nb_tx < nb_rx) && fs->retry_enabled) { + retry = 0; + while (nb_tx < nb_rx && retry++ < burst_tx_retry_num) { + rte_delay_us(burst_tx_delay_time); + nb_tx += rte_eth_tx_burst(fs->tx_port, fs->tx_queue, + &pkts_burst[nb_tx], nb_rx - nb_tx); + } + } + fs->tx_packets += nb_tx; + +#ifdef RTE_TEST_PMD_RECORD_BURST_STATS + fs->tx_burst_stats.pkt_burst_spread[nb_tx]++; +#endif + + if (unlikely(nb_tx < nb_rx)) { + fs->fwd_dropped += (nb_rx - nb_tx); + do { + rte_pktmbuf_free(pkts_burst[nb_tx]); + } while (++nb_tx < nb_rx); + } +#ifdef RTE_TEST_PMD_RECORD_CORE_CYCLES + end_tsc = rte_rdtsc(); + core_cycles = (end_tsc - start_tsc); + fs->core_cycles = (uint64_t) (fs->core_cycles + core_cycles); +#endif +} + +static void +set_tm_hiearchy_nodes_shaper_rate(portid_t port_id, struct tm_hierarchy *h) +{ + struct rte_eth_link link_params; + uint64_t tm_port_rate; + + memset(&link_params, 0, sizeof(link_params)); + + rte_eth_link_get(port_id, &link_params); + tm_port_rate = (uint64_t)link_params.link_speed * BYTES_IN_MBPS; + + if (tm_port_rate > UINT32_MAX) + tm_port_rate = UINT32_MAX; + + /* Set tm hierarchy shapers rate */ + h->root_node_shaper_rate = tm_port_rate; + h->subport_node_shaper_rate = + tm_port_rate / SUBPORT_NODES_PER_PORT; + h->pipe_node_shaper_rate + = h->subport_node_shaper_rate / PIPE_NODES_PER_SUBPORT; + h->tc_node_shaper_rate = h->pipe_node_shaper_rate; + h->tc_node_shared_shaper_rate = h->subport_node_shaper_rate; +} + +static int +softport_tm_root_node_add(portid_t port_id, struct tm_hierarchy *h, + struct rte_tm_error *error) +{ + struct rte_tm_node_params rnp; + struct rte_tm_shaper_params rsp; + uint32_t priority, weight, level_id, shaper_profile_id; + + memset(&rsp, 0, sizeof(struct rte_tm_shaper_params)); + memset(&rnp, 0, sizeof(struct rte_tm_node_params)); + + /* Shaper profile Parameters */ + rsp.peak.rate = h->root_node_shaper_rate; + rsp.peak.size = TOKEN_BUCKET_SIZE; + rsp.pkt_length_adjust = RTE_TM_ETH_FRAMING_OVERHEAD_FCS; + shaper_profile_id = 0; + + if (rte_tm_shaper_profile_add(port_id, shaper_profile_id, + &rsp, error)) { + printf("%s ERROR(%d)-%s!(shaper_id %u)\n ", + __func__, error->type, error->message, + shaper_profile_id); + return -1; + } + + /* Root Node Parameters */ + h->root_node_id = ROOT_NODE_ID; + weight = 1; + priority = 0; + level_id = TM_NODE_LEVEL_PORT; + rnp.shaper_profile_id = shaper_profile_id; + rnp.nonleaf.n_sp_priorities = 1; + rnp.stats_mask = STATS_MASK_DEFAULT; + + /* Add Node to TM Hierarchy */ + if (rte_tm_node_add(port_id, h->root_node_id, RTE_TM_NODE_ID_NULL, + priority, weight, level_id, &rnp, error)) { + printf("%s ERROR(%d)-%s!(node_id %u, parent_id %u, level %u)\n", + __func__, error->type, error->message, + h->root_node_id, RTE_TM_NODE_ID_NULL, + level_id); + return -1; + } + /* Update */ + h->n_shapers++; + + printf(" Root node added (Start id %u, Count %u, level %u)\n", + h->root_node_id, 1, level_id); + + return 0; +} + +static int +softport_tm_subport_node_add(portid_t port_id, struct tm_hierarchy *h, + struct rte_tm_error *error) +{ + uint32_t subport_parent_node_id, subport_node_id = 0; + struct rte_tm_node_params snp; + struct rte_tm_shaper_params ssp; + uint32_t priority, weight, level_id, shaper_profile_id; + uint32_t i; + + memset(&ssp, 0, sizeof(struct rte_tm_shaper_params)); + memset(&snp, 0, sizeof(struct rte_tm_node_params)); + + shaper_profile_id = h->n_shapers; + + /* Add Shaper Profile to TM Hierarchy */ + for (i = 0; i < SUBPORT_NODES_PER_PORT; i++) { + ssp.peak.rate = h->subport_node_shaper_rate; + ssp.peak.size = TOKEN_BUCKET_SIZE; + ssp.pkt_length_adjust = RTE_TM_ETH_FRAMING_OVERHEAD_FCS; + + if (rte_tm_shaper_profile_add(port_id, shaper_profile_id, + &ssp, error)) { + printf("%s ERROR(%d)-%s!(shaper_id %u)\n ", + __func__, error->type, error->message, + shaper_profile_id); + return -1; + } + + /* Node Parameters */ + h->subport_node_id[i] = SUBPORT_NODES_START_ID + i; + subport_parent_node_id = h->root_node_id; + weight = 1; + priority = 0; + level_id = TM_NODE_LEVEL_SUBPORT; + snp.shaper_profile_id = shaper_profile_id; + snp.nonleaf.n_sp_priorities = 1; + snp.stats_mask = STATS_MASK_DEFAULT; + + /* Add Node to TM Hiearchy */ + if (rte_tm_node_add(port_id, + h->subport_node_id[i], + subport_parent_node_id, + priority, weight, + level_id, + &snp, + error)) { + printf("%s ERROR(%d)-%s!(node %u,parent %u,level %u)\n", + __func__, + error->type, + error->message, + h->subport_node_id[i], + subport_parent_node_id, + level_id); + return -1; + } + shaper_profile_id++; + subport_node_id++; + } + /* Update */ + h->n_shapers = shaper_profile_id; + + printf(" Subport nodes added (Start id %u, Count %u, level %u)\n", + h->subport_node_id[0], SUBPORT_NODES_PER_PORT, level_id); + + return 0; +} + +static int +softport_tm_pipe_node_add(portid_t port_id, struct tm_hierarchy *h, + struct rte_tm_error *error) +{ + uint32_t pipe_parent_node_id; + struct rte_tm_node_params pnp; + struct rte_tm_shaper_params psp; + uint32_t priority, weight, level_id, shaper_profile_id; + uint32_t i, j; + + memset(&psp, 0, sizeof(struct rte_tm_shaper_params)); + memset(&pnp, 0, sizeof(struct rte_tm_node_params)); + + shaper_profile_id = h->n_shapers; + + /* Shaper Profile Parameters */ + psp.peak.rate = h->pipe_node_shaper_rate; + psp.peak.size = TOKEN_BUCKET_SIZE; + psp.pkt_length_adjust = RTE_TM_ETH_FRAMING_OVERHEAD_FCS; + + /* Pipe Node Parameters */ + weight = 1; + priority = 0; + level_id = TM_NODE_LEVEL_PIPE; + pnp.nonleaf.n_sp_priorities = 4; + pnp.stats_mask = STATS_MASK_DEFAULT; + + /* Add Shaper Profiles and Nodes to TM Hierarchy */ + for (i = 0; i < SUBPORT_NODES_PER_PORT; i++) { + for (j = 0; j < PIPE_NODES_PER_SUBPORT; j++) { + if (rte_tm_shaper_profile_add(port_id, + shaper_profile_id, &psp, error)) { + printf("%s ERROR(%d)-%s!(shaper_id %u)\n ", + __func__, error->type, error->message, + shaper_profile_id); + return -1; + } + pnp.shaper_profile_id = shaper_profile_id; + pipe_parent_node_id = h->subport_node_id[i]; + h->pipe_node_id[i][j] = PIPE_NODES_START_ID + + (i * PIPE_NODES_PER_SUBPORT) + j; + + if (rte_tm_node_add(port_id, + h->pipe_node_id[i][j], + pipe_parent_node_id, + priority, weight, level_id, + &pnp, + error)) { + printf("%s ERROR(%d)-%s!(node %u,parent %u )\n", + __func__, + error->type, + error->message, + h->pipe_node_id[i][j], + pipe_parent_node_id); + + return -1; + } + shaper_profile_id++; + } + } + /* Update */ + h->n_shapers = shaper_profile_id; + + printf(" Pipe nodes added (Start id %u, Count %u, level %u)\n", + h->pipe_node_id[0][0], NUM_PIPE_NODES, level_id); + + return 0; +} + +static int +softport_tm_tc_node_add(portid_t port_id, struct tm_hierarchy *h, + struct rte_tm_error *error) +{ + uint32_t tc_parent_node_id; + struct rte_tm_node_params tnp; + struct rte_tm_shaper_params tsp, tssp; + uint32_t shared_shaper_profile_id[TC_NODES_PER_PIPE]; + uint32_t priority, weight, level_id, shaper_profile_id; + uint32_t pos, n_tc_nodes, i, j, k; + + memset(&tsp, 0, sizeof(struct rte_tm_shaper_params)); + memset(&tssp, 0, sizeof(struct rte_tm_shaper_params)); + memset(&tnp, 0, sizeof(struct rte_tm_node_params)); + + shaper_profile_id = h->n_shapers; + + /* Private Shaper Profile (TC) Parameters */ + tsp.peak.rate = h->tc_node_shaper_rate; + tsp.peak.size = TOKEN_BUCKET_SIZE; + tsp.pkt_length_adjust = RTE_TM_ETH_FRAMING_OVERHEAD_FCS; + + /* Shared Shaper Profile (TC) Parameters */ + tssp.peak.rate = h->tc_node_shared_shaper_rate; + tssp.peak.size = TOKEN_BUCKET_SIZE; + tssp.pkt_length_adjust = RTE_TM_ETH_FRAMING_OVERHEAD_FCS; + + /* TC Node Parameters */ + weight = 1; + level_id = TM_NODE_LEVEL_TC; + tnp.n_shared_shapers = 1; + tnp.nonleaf.n_sp_priorities = 1; + tnp.stats_mask = STATS_MASK_DEFAULT; + + /* Add Shared Shaper Profiles to TM Hierarchy */ + for (i = 0; i < TC_NODES_PER_PIPE; i++) { + shared_shaper_profile_id[i] = shaper_profile_id; + + if (rte_tm_shaper_profile_add(port_id, + shared_shaper_profile_id[i], &tssp, error)) { + printf("%s ERROR(%d)-%s!(Shared shaper profileid %u)\n", + __func__, error->type, error->message, + shared_shaper_profile_id[i]); + + return -1; + } + if (rte_tm_shared_shaper_add_update(port_id, i, + shared_shaper_profile_id[i], error)) { + printf("%s ERROR(%d)-%s!(Shared shaper id %u)\n", + __func__, error->type, error->message, i); + + return -1; + } + shaper_profile_id++; + } + + /* Add Shaper Profiles and Nodes to TM Hierarchy */ + n_tc_nodes = 0; + for (i = 0; i < SUBPORT_NODES_PER_PORT; i++) { + for (j = 0; j < PIPE_NODES_PER_SUBPORT; j++) { + for (k = 0; k < TC_NODES_PER_PIPE ; k++) { + priority = k; + tc_parent_node_id = h->pipe_node_id[i][j]; + tnp.shared_shaper_id = + (uint32_t *)calloc(1, sizeof(uint32_t)); + tnp.shared_shaper_id[0] = k; + pos = j + (i * PIPE_NODES_PER_SUBPORT); + h->tc_node_id[pos][k] = + TC_NODES_START_ID + n_tc_nodes; + + if (rte_tm_shaper_profile_add(port_id, + shaper_profile_id, &tsp, error)) { + printf("%s ERROR(%d)-%s!(shaper %u)\n", + __func__, error->type, + error->message, + shaper_profile_id); + + return -1; + } + tnp.shaper_profile_id = shaper_profile_id; + if (rte_tm_node_add(port_id, + h->tc_node_id[pos][k], + tc_parent_node_id, + priority, weight, + level_id, + &tnp, error)) { + printf("%s ERROR(%d)-%s!(node id %u)\n", + __func__, + error->type, + error->message, + h->tc_node_id[pos][k]); + + return -1; + } + shaper_profile_id++; + n_tc_nodes++; + } + } + } + /* Update */ + h->n_shapers = shaper_profile_id; + + printf(" TC nodes added (Start id %u, Count %u, level %u)\n", + h->tc_node_id[0][0], n_tc_nodes, level_id); + + return 0; +} + +static int +softport_tm_queue_node_add(portid_t port_id, struct tm_hierarchy *h, + struct rte_tm_error *error) +{ + uint32_t queue_parent_node_id; + struct rte_tm_node_params qnp; + uint32_t priority, weight, level_id, pos; + uint32_t n_queue_nodes, i, j, k; + + memset(&qnp, 0, sizeof(struct rte_tm_node_params)); + + /* Queue Node Parameters */ + priority = 0; + weight = 1; + level_id = TM_NODE_LEVEL_QUEUE; + qnp.shaper_profile_id = RTE_TM_SHAPER_PROFILE_ID_NONE; + qnp.leaf.cman = RTE_TM_CMAN_TAIL_DROP; + qnp.stats_mask = STATS_MASK_QUEUE; + + /* Add Queue Nodes to TM Hierarchy */ + n_queue_nodes = 0; + for (i = 0; i < NUM_PIPE_NODES; i++) { + for (j = 0; j < TC_NODES_PER_PIPE; j++) { + queue_parent_node_id = h->tc_node_id[i][j]; + for (k = 0; k < QUEUE_NODES_PER_TC; k++) { + pos = j + (i * TC_NODES_PER_PIPE); + h->queue_node_id[pos][k] = n_queue_nodes; + if (rte_tm_node_add(port_id, + h->queue_node_id[pos][k], + queue_parent_node_id, + priority, + weight, + level_id, + &qnp, error)) { + printf("%s ERROR(%d)-%s!(node %u)\n", + __func__, + error->type, + error->message, + h->queue_node_id[pos][k]); + + return -1; + } + n_queue_nodes++; + } + } + } + printf(" Queue nodes added (Start id %u, Count %u, level %u)\n", + h->queue_node_id[0][0], n_queue_nodes, level_id); + + return 0; +} + +/* + * TM Packet Field Setup + */ +static void +softport_tm_pktfield_setup(portid_t port_id) +{ + struct rte_port *p = &ports[port_id]; + uint64_t pktfield0_mask = 0; + uint64_t pktfield1_mask = 0x0000000FFF000000LLU; + uint64_t pktfield2_mask = 0x00000000000000FCLLU; + + p->softport.tm = (struct softnic_port_tm) { + .n_subports_per_port = SUBPORT_NODES_PER_PORT, + .n_pipes_per_subport = PIPE_NODES_PER_SUBPORT, + + /* Packet field to identify subport + * + * Default configuration assumes only one subport, thus + * the subport ID is hardcoded to 0 + */ + .tm_pktfield0_slabpos = 0, + .tm_pktfield0_slabmask = pktfield0_mask, + .tm_pktfield0_slabshr = + __builtin_ctzll(pktfield0_mask), + + /* Packet field to identify pipe. + * + * Default value assumes Ethernet/IPv4/UDP packets, + * UDP payload bits 12 .. 23 + */ + .tm_pktfield1_slabpos = 40, + .tm_pktfield1_slabmask = pktfield1_mask, + .tm_pktfield1_slabshr = + __builtin_ctzll(pktfield1_mask), + + /* Packet field used as index into TC translation table + * to identify the traffic class and queue. + * + * Default value assumes Ethernet/IPv4 packets, IPv4 + * DSCP field + */ + .tm_pktfield2_slabpos = 8, + .tm_pktfield2_slabmask = pktfield2_mask, + .tm_pktfield2_slabshr = + __builtin_ctzll(pktfield2_mask), + + .tm_tc_table = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, + }, /**< TC translation table */ + }; +} + +static int +softport_tm_hierarchy_specify(portid_t port_id, struct rte_tm_error *error) +{ + + struct tm_hierarchy h; + int status; + + memset(&h, 0, sizeof(struct tm_hierarchy)); + + /* TM hierarchy shapers rate */ + set_tm_hiearchy_nodes_shaper_rate(port_id, &h); + + /* Add root node (level 0) */ + status = softport_tm_root_node_add(port_id, &h, error); + if (status) + return status; + + /* Add subport node (level 1) */ + status = softport_tm_subport_node_add(port_id, &h, error); + if (status) + return status; + + /* Add pipe nodes (level 2) */ + status = softport_tm_pipe_node_add(port_id, &h, error); + if (status) + return status; + + /* Add traffic class nodes (level 3) */ + status = softport_tm_tc_node_add(port_id, &h, error); + if (status) + return status; + + /* Add queue nodes (level 4) */ + status = softport_tm_queue_node_add(port_id, &h, error); + if (status) + return status; + + /* TM packet fields setup */ + softport_tm_pktfield_setup(port_id); + + return 0; +} + +/* + * Soft port Init + */ +static void +softport_tm_begin(portid_t pi) +{ + struct rte_port *port = &ports[pi]; + + /* Soft port TM flag */ + if (port->softport.tm_flag == 1) { + printf("\n\n TM feature available on port %u\n", pi); + + /* Soft port TM hierarchy configuration */ + if ((port->softport.tm.hierarchy_config == 0) && + (port->softport.tm.default_hierarchy_enable == 1)) { + struct rte_tm_error error; + int status; + + /* Stop port */ + rte_eth_dev_stop(pi); + + /* TM hierarchy specification */ + status = softport_tm_hierarchy_specify(pi, &error); + if (status) { + printf(" TM Hierarchy built error(%d) - %s\n", + error.type, error.message); + return; + } + printf("\n TM Hierarchy Specified!\n\v"); + + /* TM hierarchy commit */ + status = rte_tm_hierarchy_commit(pi, 0, &error); + if (status) { + printf(" Hierarchy commit error(%d) - %s\n", + error.type, error.message); + return; + } + printf(" Hierarchy Committed (port %u)!", pi); + port->softport.tm.hierarchy_config = 1; + + /* Start port */ + status = rte_eth_dev_start(pi); + if (status) { + printf("\n Port %u start error!\n", pi); + return; + } + printf("\n Port %u started!\n", pi); + return; + } + } + printf("\n TM feature not available on port %u", pi); +} + +struct fwd_engine softnic_tm_engine = { + .fwd_mode_name = "tm", + .port_fwd_begin = softport_tm_begin, + .port_fwd_end = NULL, + .packet_fwd = softport_packet_fwd, +}; + +struct fwd_engine softnic_tm_bypass_engine = { + .fwd_mode_name = "tm-bypass", + .port_fwd_begin = NULL, + .port_fwd_end = NULL, + .packet_fwd = softport_packet_fwd, +}; diff --git a/app/test-pmd/txonly.c b/app/test-pmd/txonly.c index 7070ddc3..309c7389 100644 --- a/app/test-pmd/txonly.c +++ b/app/test-pmd/txonly.c @@ -49,7 +49,6 @@ #include <rte_cycles.h> #include <rte_memory.h> #include <rte_memcpy.h> -#include <rte_memzone.h> #include <rte_launch.h> #include <rte_eal.h> #include <rte_per_lcore.h> |