From aeca06df4ef7609982cf586f0c58fc6f1d8867f8 Mon Sep 17 00:00:00 2001 From: Jingjing Wu Date: Fri, 21 Nov 2014 08:46:55 +0800 Subject: [PATCH] app/testpmd: configure flow director flexible mask test command added to configure flexible mask Signed-off-by: Jingjing Wu Acked-by: Konstantin Ananyev --- app/test-pmd/cmdline.c | 94 ++++++++++++++++++++++++++++++++++++++++++ app/test-pmd/config.c | 30 ++++++++++++++ app/test-pmd/testpmd.h | 3 +- 3 files changed, 126 insertions(+), 1 deletion(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index b5d65c3fef..f527b63518 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -723,6 +723,11 @@ static void cmd_help_long_parsed(void *parsed_result, "flush_flow_director (port_id)\n" " Flush all flow director entries of a device.\n\n" + + "flow_director_flex_mask (port_id)" + " flow (ip4|ip4-frag|tcp4|udp4|sctp4|ip6|ip6-frag|tcp6|udp6|sctp6|all)" + " (mask)\n" + " Configure mask of flex payload.\n\n" ); } } @@ -8312,6 +8317,94 @@ cmdline_parse_inst_t cmd_flush_flow_director = { }, }; +/* *** 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; + cmdline_fixed_string_t flow; + cmdline_fixed_string_t flow_type; + cmdline_fixed_string_t mask; +}; + +static void +cmd_flow_director_flex_mask_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_flow_director_flex_mask_result *res = parsed_result; + struct rte_eth_fdir_flex_mask flex_mask; + struct rte_port *port; + enum rte_eth_flow_type i; + int ret; + + if (res->port_id > nb_ports) { + printf("Invalid port, range is [0, %d]\n", nb_ports - 1); + return; + } + + port = &ports[res->port_id]; + /** Check if the port is not started **/ + if (port->port_status != RTE_PORT_STOPPED) { + printf("Please stop port %d first\n", res->port_id); + return; + } + + memset(&flex_mask, 0, sizeof(struct rte_eth_fdir_flex_mask)); + ret = parse_flexbytes(res->mask, + flex_mask.mask, + RTE_ETH_FDIR_MAX_FLEXLEN); + if (ret < 0) { + printf("error: Cannot parse mask input.\n"); + return; + } + if (!strcmp(res->flow_type, "all")) { + for (i = RTE_ETH_FLOW_TYPE_UDPV4; + i <= RTE_ETH_FLOW_TYPE_FRAG_IPV6; + i++) { + flex_mask.flow_type = i; + fdir_set_flex_mask(res->port_id, &flex_mask); + } + cmd_reconfig_device_queue(res->port_id, 1, 0); + return; + } + flex_mask.flow_type = str2flowtype(res->flow_type); + fdir_set_flex_mask(res->port_id, &flex_mask); + cmd_reconfig_device_queue(res->port_id, 1, 0); +} + +cmdline_parse_token_string_t cmd_flow_director_flexmask = + TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, + 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); +cmdline_parse_token_string_t cmd_flow_director_flexmask_flow = + TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, + flow, "flow"); +cmdline_parse_token_string_t cmd_flow_director_flexmask_flow_type = + TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, + flow_type, + "ip4#ip4-frag#tcp4#udp4#sctp4#" + "ip6#ip6-frag#tcp6#udp6#sctp6#all"); +cmdline_parse_token_string_t cmd_flow_director_flexmask_mask = + TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flex_mask_result, + mask, NULL); + +cmdline_parse_inst_t cmd_set_flow_director_flex_mask = { + .f = cmd_flow_director_flex_mask_parsed, + .data = NULL, + .help_str = "set flow director's flex mask on NIC", + .tokens = { + (void *)&cmd_flow_director_flexmask, + (void *)&cmd_flow_director_flexmask_port_id, + (void *)&cmd_flow_director_flexmask_flow, + (void *)&cmd_flow_director_flexmask_flow_type, + (void *)&cmd_flow_director_flexmask_mask, + NULL, + }, +}; + /* ******************************************************************************** */ /* list of instructions */ @@ -8446,6 +8539,7 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_add_del_udp_flow_director, (cmdline_parse_inst_t *)&cmd_add_del_sctp_flow_director, (cmdline_parse_inst_t *)&cmd_flush_flow_director, + (cmdline_parse_inst_t *)&cmd_set_flow_director_flex_mask, NULL, }; diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 1dda5e4f81..eb26306fac 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -2019,6 +2019,36 @@ fdir_set_masks(portid_t port_id, struct rte_fdir_masks *fdir_masks) "diag=%d\n", port_id, diag); } +void +fdir_set_flex_mask(portid_t port_id, struct rte_eth_fdir_flex_mask *cfg) +{ + struct rte_port *port; + struct rte_eth_fdir_flex_conf *flex_conf; + int i, idx = 0; + + port = &ports[port_id]; + flex_conf = &port->dev_conf.fdir_conf.flex_conf; + for (i = 0; i < RTE_ETH_FLOW_TYPE_MAX; i++) { + if (cfg->flow_type == flex_conf->flex_mask[i].flow_type) { + idx = i; + break; + } + } + if (i >= RTE_ETH_FLOW_TYPE_MAX) { + if (flex_conf->nb_flexmasks < RTE_DIM(flex_conf->flex_mask)) { + idx = flex_conf->nb_flexmasks; + flex_conf->nb_flexmasks++; + } else { + printf("The flex mask table is full. Can not set flex" + " mask for flow_type(%u).", cfg->flow_type); + return; + } + } + (void)rte_memcpy(&flex_conf->flex_mask[idx], + cfg, + sizeof(struct rte_eth_fdir_flex_mask)); +} + void set_vf_traffic(portid_t port_id, uint8_t is_rx, uint16_t vf, uint8_t on) { diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 10bf13f162..b3908748fe 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -532,7 +532,8 @@ void fdir_update_perfect_filter(portid_t port_id, uint16_t soft_id, void fdir_remove_perfect_filter(portid_t port_id, uint16_t soft_id, struct rte_fdir_filter *fdir_filter); void fdir_set_masks(portid_t port_id, struct rte_fdir_masks *fdir_masks); - +void fdir_set_flex_mask(portid_t port_id, + struct rte_eth_fdir_flex_mask *cfg); void port_rss_reta_info(portid_t port_id, struct rte_eth_rss_reta_entry64 *reta_conf, uint16_t nb_entries); -- 2.20.1