From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) by dpdk.org (Postfix) with ESMTP id 4582A7F45 for ; Thu, 30 Oct 2014 08:18:47 +0100 (CET) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga101.fm.intel.com with ESMTP; 30 Oct 2014 00:27:42 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.07,284,1413270000"; d="scan'208";a="623301472" Received: from shvmail01.sh.intel.com ([10.239.29.42]) by fmsmga002.fm.intel.com with ESMTP; 30 Oct 2014 00:27:41 -0700 Received: from shecgisg004.sh.intel.com (shecgisg004.sh.intel.com [10.239.29.89]) by shvmail01.sh.intel.com with ESMTP id s9U7Rd8w008101; Thu, 30 Oct 2014 15:27:39 +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 s9U7Rbi5007995; Thu, 30 Oct 2014 15:27:39 +0800 Received: (from wujingji@localhost) by shecgisg004.sh.intel.com (8.13.6/8.13.6/Submit) id s9U7RaCP007991; Thu, 30 Oct 2014 15:27:36 +0800 From: Jingjing Wu To: dev@dpdk.org Date: Thu, 30 Oct 2014 15:26:43 +0800 Message-Id: <1414654006-7472-19-git-send-email-jingjing.wu@intel.com> X-Mailer: git-send-email 1.7.4.1 In-Reply-To: <1414654006-7472-1-git-send-email-jingjing.wu@intel.com> References: <1413939687-11177-1-git-send-email-jingjing.wu@intel.com> <1414654006-7472-1-git-send-email-jingjing.wu@intel.com> Subject: [dpdk-dev] [PATCH v5 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: Thu, 30 Oct 2014 07:18:48 -0000 Test command is added to configure flexible payload Signed-off-by: Jingjing Wu --- app/test-pmd/cmdline.c | 144 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index f8960d8..5a84a6c 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -58,6 +58,7 @@ #include #include #include +#include #include #include #include @@ -703,6 +704,10 @@ 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_payload (port_id)" + " (l2|l3|l4) (config)\n" + " Configure flex payload selection.\n\n" ); } } @@ -8125,6 +8130,144 @@ 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: %hhu\n", + cfg->nb_field); + 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 */ @@ -8257,6 +8400,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