From mboxrd@z Thu Jan 1 00:00:00 1970 From: Beilei Xing Subject: [PATCH v5 2/5] app/testpmd: add command for loading a profile Date: Mon, 27 Mar 2017 14:17:52 +0800 Message-ID: <1490595475-139869-3-git-send-email-beilei.xing@intel.com> References: <1490350768-65006-1-git-send-email-beilei.xing@intel.com> <1490595475-139869-1-git-send-email-beilei.xing@intel.com> Cc: helin.zhang@intel.com, dev@dpdk.org To: jingjing.wu@intel.com Return-path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id 411C6F969 for ; Mon, 27 Mar 2017 08:19:31 +0200 (CEST) In-Reply-To: <1490595475-139869-1-git-send-email-beilei.xing@intel.com> List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch is to add testpmd CLI for loading a pipeline personalization profile. Signed-off-by: Beilei Xing --- app/test-pmd/cmdline.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++ app/test-pmd/config.c | 67 +++++++++++++++++++++++++++++++++++++++++++++ app/test-pmd/testpmd.h | 3 ++ 3 files changed, 144 insertions(+) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 6e0625d..bb99f85 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -579,6 +579,9 @@ 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" + "add ppp (port_id) (profile_path)\n" + " Load a profile package on a port\n\n" + , list_pkt_forwarding_modes() ); } @@ -12402,6 +12405,76 @@ cmdline_parse_inst_t cmd_set_vf_vlan_tag = { }, }; +/* Load Pipeline Personalization Profile */ +struct cmd_add_ppp_result { + cmdline_fixed_string_t add; + cmdline_fixed_string_t ppp; + uint8_t port_id; + char filepath[]; +}; + +cmdline_parse_token_string_t cmd_add_ppp_add = + TOKEN_STRING_INITIALIZER(struct cmd_add_ppp_result, add, "add"); +cmdline_parse_token_string_t cmd_add_ppp_ppp = + TOKEN_STRING_INITIALIZER(struct cmd_add_ppp_result, ppp, "ppp"); +cmdline_parse_token_num_t cmd_add_ppp_port_id = + TOKEN_NUM_INITIALIZER(struct cmd_add_ppp_result, port_id, UINT8); +cmdline_parse_token_string_t cmd_add_ppp_filepath = + TOKEN_STRING_INITIALIZER(struct cmd_add_ppp_result, filepath, NULL); + +static void +cmd_add_ppp_parsed( + void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_add_ppp_result *res = parsed_result; + uint8_t *buff; + uint32_t size; + int ret = -ENOTSUP; + + if (res->port_id > nb_ports) { + printf("Invalid port, range is [0, %d]\n", nb_ports - 1); + return; + } + + if (!all_ports_stopped()) { + printf("Please stop all ports first\n"); + return; + } + + buff = open_ppp_package_file(res->filepath, &size); + if (!buff) + return; + +#ifdef RTE_LIBRTE_I40E_PMD + if (ret == -ENOTSUP) + ret = rte_pmd_i40e_process_ppp_package(res->port_id, + buff, size, + RTE_PMD_I40E_PKG_OP_WR_ADD); +#endif + + if (ret < 0) + printf("Failed to load profile.\n"); + else if (ret > 0) + printf("Profile has already existed.\n"); + + close_ppp_package_file(buff); +} + +cmdline_parse_inst_t cmd_add_ppp = { + .f = cmd_add_ppp_parsed, + .data = NULL, + .help_str = "add/remove ppp ", + .tokens = { + (void *)&cmd_add_ppp_add, + (void *)&cmd_add_ppp_ppp, + (void *)&cmd_add_ppp_port_id, + (void *)&cmd_add_ppp_filepath, + NULL, + }, +}; + /* ******************************************************************************** */ /* list of instructions */ @@ -12577,6 +12650,7 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_set_vf_allmulti, (cmdline_parse_inst_t *)&cmd_set_vf_broadcast, (cmdline_parse_inst_t *)&cmd_set_vf_vlan_tag, + (cmdline_parse_inst_t *)&cmd_add_ppp, NULL, }; diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 80491fc..eb3d572 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -3245,3 +3245,70 @@ port_dcb_info_display(uint8_t port_id) printf("\t%4d", dcb_info.tc_queue.tc_txq[0][i].nb_queue); printf("\n"); } + +uint8_t * +open_ppp_package_file(const char *file_path, uint32_t *size) +{ + FILE *fh = fopen(file_path, "rb"); + uint32_t pkg_size; + uint8_t *buf = NULL; + int ret = 0; + + if (size) + *size = 0; + + if (fh == NULL) { + printf("%s: Failed to open %s\n", __func__, file_path); + return buf; + } + + ret = fseek(fh, 0, SEEK_END); + if (ret < 0) { + fclose(fh); + printf("%s: File operations failed\n", __func__); + return buf; + } + + pkg_size = ftell(fh); + + buf = (uint8_t *)malloc(pkg_size); + if (!buf) { + fclose(fh); + 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_ppp_package_file(buf); + return NULL; + } + + ret = fread(buf, 1, pkg_size, fh); + if (ret < 0) { + fclose(fh); + printf("%s: File read operation failed\n", __func__); + close_ppp_package_file(buf); + return NULL; + } + + if (size) + *size = pkg_size; + + fclose(fh); + + return buf; +} + +int +close_ppp_package_file(uint8_t *buf) +{ + if (buf) { + free((void *)buf); + return 0; + } + + return -1; +} diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 8cf2860..6bcd9c4 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -622,6 +622,9 @@ 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); +uint8_t *open_ppp_package_file(const char *file_path, uint32_t *size); +int close_ppp_package_file(uint8_t *buf); + enum print_warning { ENABLED_WARN = 0, DISABLED_WARN -- 2.5.5