From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id C680B7EF3 for ; Wed, 22 Oct 2014 02:54:14 +0200 (CEST) Received: from orsmga002.jf.intel.com ([10.7.209.21]) by orsmga102.jf.intel.com with ESMTP; 21 Oct 2014 18:01:26 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.04,766,1406617200"; d="scan'208";a="622879491" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by orsmga002.jf.intel.com with ESMTP; 21 Oct 2014 18:02:30 -0700 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shvmail01.sh.intel.com with ESMTP id s9M12Sim010663; Wed, 22 Oct 2014 09:02:28 +0800 Received: from shecgisg004.sh.intel.com (localhost [127.0.0.1]) by shecgisg004.sh.intel.com (8.13.6/8.13.6/SuSE Linux 0.8) with ESMTP id s9M12QjT011338; Wed, 22 Oct 2014 09:02:28 +0800 Received: (from wujingji@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id s9M12Qpu011334; Wed, 22 Oct 2014 09:02:26 +0800 From: Jingjing Wu To: dev@dpdk.org Date: Wed, 22 Oct 2014 09:01:24 +0800 Message-Id: <1413939687-11177-19-git-send-email-jingjing.wu@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1413939687-11177-1-git-send-email-jingjing.wu@intel.com> References: <1411711418-12881-1-git-send-email-jingjing.wu@intel.com> <1413939687-11177-1-git-send-email-jingjing.wu@intel.com> Subject: [dpdk-dev] [PATCH v4 18/21] testpmd: add test command to configure flexible payload X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Oct 2014 00:54:17 -0000 add test command to configure flexible payload Signed-off-by: Jingjing Wu --- app/test-pmd/cmdline.c | 143 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 143 insertions(+) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 7324783..1caca54 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -685,6 +686,10 @@ static void cmd_help_long_parsed(void *parsed_result, "flush_flow_diretor (port_id)\n" " Flush all flow director entries of a device.\n\n" + + "flow_director_flex_payload (port_id)" + " (l2|l3|l4) (config)\n" + " Configure flex payload selection.\n\n" ); } } @@ -7907,6 +7912,143 @@ cmdline_parse_inst_t cmd_flush_flow_director = { }, }; +/* *** deal with flow director flexible payload configuration *** */ +struct cmd_flow_director_flexpayload_result { + cmdline_fixed_string_t flow_director_flexpayload; + uint8_t port_id; + cmdline_fixed_string_t payload_layer; + cmdline_fixed_string_t payload_cfg; +}; + +static inline int +parse_flex_payload_cfg(const char *q_arg, + struct rte_eth_flex_payload_cfg *cfg) +{ + char s[256]; + const char *p, *p0 = q_arg; + char *end; + enum fieldnames { + FLD_OFFSET = 0, + FLD_SIZE, + _NUM_FLD + }; + unsigned long int_fld[_NUM_FLD]; + char *str_fld[_NUM_FLD]; + int i; + unsigned size; + + cfg->nb_field = 0; + p = strchr(p0, '('); + while (p != NULL) { + ++p; + p0 = strchr(p, ')'); + if (p0 == NULL) + return -1; + + size = p0 - p; + if (size >= sizeof(s)) + return -1; + + snprintf(s, sizeof(s), "%.*s", size, p); + if (rte_strsplit(s, sizeof(s), str_fld, _NUM_FLD, ',') != _NUM_FLD) + return -1; + for (i = 0; i < _NUM_FLD; i++) { + errno = 0; + int_fld[i] = strtoul(str_fld[i], &end, 0); + if (errno != 0 || end == str_fld[i] || int_fld[i] > 255) + return -1; + } + cfg->field[cfg->nb_field].offset = (uint8_t)int_fld[FLD_OFFSET]; + cfg->field[cfg->nb_field].size = (uint8_t)int_fld[FLD_SIZE]; + cfg->nb_field++; + if (cfg->nb_field > 3) { + printf("exceeded max number of fields\n"); + return -1; + } + p = strchr(p0, '('); + } + return 0; +} + +static void +cmd_flow_director_flxpld_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_flow_director_flexpayload_result *res = parsed_result; + struct rte_eth_fdir_cfg fdir_cfg; + struct rte_eth_flex_payload_cfg *flxpld_cfg; + int ret = 0; + int cfg_size = 3 * sizeof(struct rte_eth_field_vector) + + offsetof(struct rte_eth_flex_payload_cfg, field); + + ret = rte_eth_dev_filter_supported(res->port_id, RTE_ETH_FILTER_FDIR); + if (ret < 0) { + printf("flow director is not supported on port %u.\n", + res->port_id); + return; + } + + memset(&fdir_cfg, 0, sizeof(struct rte_eth_fdir_cfg)); + + flxpld_cfg = (struct rte_eth_flex_payload_cfg *)rte_zmalloc_socket("CLI", + cfg_size, CACHE_LINE_SIZE, rte_socket_id()); + + if (flxpld_cfg == NULL) { + printf("fail to malloc memory to configure flex payload\n"); + return; + } + + if (!strcmp(res->payload_layer, "l2")) + flxpld_cfg->type = RTE_ETH_L2_PAYLOAD; + else if (!strcmp(res->payload_layer, "l3")) + flxpld_cfg->type = RTE_ETH_L3_PAYLOAD; + else if (!strcmp(res->payload_layer, "l4")) + flxpld_cfg->type = RTE_ETH_L4_PAYLOAD; + + ret = parse_flex_payload_cfg(res->payload_cfg, flxpld_cfg); + if (ret < 0) { + printf("error: Cannot parse flex payload input.\n"); + rte_free(flxpld_cfg); + return; + } + fdir_cfg.cmd = RTE_ETH_FDIR_CFG_FLX; + fdir_cfg.cfg = flxpld_cfg; + ret = rte_eth_dev_filter_ctrl(res->port_id, RTE_ETH_FILTER_FDIR, + RTE_ETH_FILTER_SET, &fdir_cfg); + if (ret < 0) + printf("fdir flex payload setting error: (%s)\n", + strerror(-ret)); + rte_free(flxpld_cfg); +} + +cmdline_parse_token_string_t cmd_flow_director_flexpayload = + TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, + 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); +cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_layer = + TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, + payload_layer, "l2#l3#l4"); +cmdline_parse_token_string_t cmd_flow_director_flexpayload_payload_cfg = + TOKEN_STRING_INITIALIZER(struct cmd_flow_director_flexpayload_result, + payload_cfg, NULL); + +cmdline_parse_inst_t cmd_set_flow_director_flex_payload = { + .f = cmd_flow_director_flxpld_parsed, + .data = NULL, + .help_str = "set flow director's flex payload on NIC", + .tokens = { + (void *)&cmd_flow_director_flexpayload, + (void *)&cmd_flow_director_flexpayload_port_id, + (void *)&cmd_flow_director_flexpayload_payload_layer, + (void *)&cmd_flow_director_flexpayload_payload_cfg, + NULL, + }, +}; + /* ******************************************************************************** */ /* list of instructions */ @@ -8037,6 +8179,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_payload, NULL, }; -- 1.8.1.4