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 0DA6E2C2E for ; Tue, 27 Jun 2017 10:18:20 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Jun 2017 01:18:19 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.39,399,1493708400"; d="scan'208";a="1145179623" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 27 Jun 2017 01:18:16 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id v5R8IF6A016121; Tue, 27 Jun 2017 09:18:15 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id v5R8IFb0017366; Tue, 27 Jun 2017 09:18:15 +0100 Received: (from achiliki@localhost) by sivswdev01.ir.intel.com with LOCAL id v5R8IFtF017358; Tue, 27 Jun 2017 09:18:15 +0100 From: Andrey Chilikin To: dev@dpdk.org Cc: beilei.xing@intel.com, jingjing.wu@intel.com, Andrey Chilikin Date: Tue, 27 Jun 2017 09:18:12 +0100 Message-Id: <1498551492-17214-3-git-send-email-andrey.chilikin@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1498551492-17214-1-git-send-email-andrey.chilikin@intel.com> References: <1498551492-17214-1-git-send-email-andrey.chilikin@intel.com> In-Reply-To: <1495901077-11845-1-git-send-email-andrey.chilikin@intel.com> References: <1495901077-11845-1-git-send-email-andrey.chilikin@intel.com> Subject: [dpdk-dev] [PATCH v2 2/2] app/testpmd: enable ddp remove profile feature X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 27 Jun 2017 08:18:21 -0000 New command 'ddp del (port) (profile_path)' removes previously loaded profile and deletes it from the list of the loaded profiles. Signed-off-by: Andrey Chilikin --- app/test-pmd/cmdline.c | 103 ++++++++++++++++++++++++++-- app/test-pmd/config.c | 21 ++++++ app/test-pmd/testpmd.h | 1 + doc/guides/testpmd_app_ug/testpmd_funcs.rst | 7 ++ 4 files changed, 125 insertions(+), 7 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 0afac68..73baaa6 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -602,9 +602,12 @@ 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" - "ddp add (port_id) (profile_path)\n" + "ddp add (port_id) (profile_path[,output_path])\n" " Load a profile package on a port\n\n" + "ddp del (port_id) (profile_path)\n" + " Delete a profile package from a port\n\n" + "ptype mapping get (port_id) (valid_only)\n" " Get ptype mapping on a port\n\n" @@ -12860,6 +12863,9 @@ cmd_ddp_add_parsed( struct cmd_ddp_add_result *res = parsed_result; uint8_t *buff; uint32_t size; + char *filepath; + char *file_fld[2]; + int file_num; int ret = -ENOTSUP; if (res->port_id > nb_ports) { @@ -12872,9 +12878,18 @@ cmd_ddp_add_parsed( return; } - buff = open_ddp_package_file(res->filepath, &size); - if (!buff) + filepath = strdup(res->filepath); + if (filepath == NULL) { + printf("Failed to allocate memory\n"); return; + } + file_num = rte_strsplit(filepath, strlen(filepath), file_fld, 2, ','); + + buff = open_ddp_package_file(file_fld[0], &size); + if (!buff) { + free((void *)filepath); + return; + } #ifdef RTE_LIBRTE_I40E_PMD if (ret == -ENOTSUP) @@ -12883,18 +12898,21 @@ cmd_ddp_add_parsed( RTE_PMD_I40E_PKG_OP_WR_ADD); #endif - if (ret < 0) - printf("Failed to load profile.\n"); - else if (ret > 0) + if (ret == -EEXIST) printf("Profile has already existed.\n"); + else if (ret < 0) + printf("Failed to load profile.\n"); + else if (file_num == 2) + save_ddp_package_file(file_fld[1], buff, size); close_ddp_package_file(buff); + free((void *)filepath); } cmdline_parse_inst_t cmd_ddp_add = { .f = cmd_ddp_add_parsed, .data = NULL, - .help_str = "ddp add ", + .help_str = "ddp add ", .tokens = { (void *)&cmd_ddp_add_ddp, (void *)&cmd_ddp_add_add, @@ -12904,6 +12922,76 @@ cmdline_parse_inst_t cmd_ddp_add = { }, }; +/* Delete dynamic device personalization*/ +struct cmd_ddp_del_result { + cmdline_fixed_string_t ddp; + cmdline_fixed_string_t del; + uint8_t port_id; + char filepath[]; +}; + +cmdline_parse_token_string_t cmd_ddp_del_ddp = + TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, ddp, "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); +cmdline_parse_token_string_t cmd_ddp_del_filepath = + TOKEN_STRING_INITIALIZER(struct cmd_ddp_del_result, filepath, NULL); + +static void +cmd_ddp_del_parsed( + void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_ddp_del_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_ddp_package_file(res->filepath, &size); + if (!buff) + return; + +#ifdef RTE_LIBRTE_I40E_PMD + if (ret == -ENOTSUP) + ret = rte_pmd_i40e_process_ddp_package(res->port_id, + buff, size, + RTE_PMD_I40E_PKG_OP_WR_DEL); +#endif + + if (ret == -EACCES) + printf("Profile does not exist.\n"); + else if (ret < 0) + printf("Failed to delete profile.\n"); + + close_ddp_package_file(buff); +} + +cmdline_parse_inst_t cmd_ddp_del = { + .f = cmd_ddp_del_parsed, + .data = NULL, + .help_str = "ddp del ", + .tokens = { + (void *)&cmd_ddp_del_ddp, + (void *)&cmd_ddp_del_del, + (void *)&cmd_ddp_del_port_id, + (void *)&cmd_ddp_del_filepath, + NULL, + }, +}; + /* Get dynamic device personalization profile info list*/ #define PROFILE_INFO_SIZE 48 #define MAX_PROFILE_NUM 16 @@ -13747,6 +13835,7 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_strict_link_prio, (cmdline_parse_inst_t *)&cmd_tc_min_bw, (cmdline_parse_inst_t *)&cmd_ddp_add, + (cmdline_parse_inst_t *)&cmd_ddp_del, (cmdline_parse_inst_t *)&cmd_ddp_get_list, (cmdline_parse_inst_t *)&cmd_show_vf_stats, (cmdline_parse_inst_t *)&cmd_clear_vf_stats, diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 4d873cd..a4606d3 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -3310,6 +3310,27 @@ 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) +{ + FILE *fh = fopen(file_path, "wb"); + + if (fh == NULL) { + printf("%s: Failed to open %s\n", __func__, file_path); + return -1; + } + + if (fwrite(buf, 1, size, fh) != size) { + fclose(fh); + printf("%s: File write operation failed\n", __func__); + return -1; + } + + fclose(fh); + + return 0; +} + +int close_ddp_package_file(uint8_t *buf) { if (buf) { diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index e6c43ba..107a1b2 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -632,6 +632,7 @@ 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_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); enum print_warning { diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index 0e50c10..4de61f6 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -1211,6 +1211,13 @@ Add an E-tag forwarding filter on a port:: Delete an E-tag forwarding filter on a port:: testpmd> E-tag set filter del e-tag-id (value) port (port_id) +ddp del +~~~~~~~ + +Delete a dynamic device personalization package:: + + testpmd> ddp del (port_id) (package_path) + ptype mapping ~~~~~~~~~~~~~ -- 2.13.0