From patchwork Fri Mar 3 07:26:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Xing, Beilei" X-Patchwork-Id: 21235 Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [IPv6:::1]) by dpdk.org (Postfix) with ESMTP id 7CB0BF966; Fri, 3 Mar 2017 08:28:09 +0100 (CET) Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by dpdk.org (Postfix) with ESMTP id 925FE2B93 for ; Fri, 3 Mar 2017 08:27:34 +0100 (CET) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Mar 2017 23:27:33 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.35,235,1484035200"; d="scan'208";a="830442009" Received: from unknown (HELO dpdk9.sh.intel.com) ([10.239.129.31]) by FMSMGA003.fm.intel.com with ESMTP; 02 Mar 2017 23:27:33 -0800 From: Beilei Xing To: jingjing.wu@intel.com Cc: helin.zhang@intel.com, dev@dpdk.org Date: Fri, 3 Mar 2017 15:26:15 +0800 Message-Id: <1488525977-15321-11-git-send-email-beilei.xing@intel.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1488525977-15321-1-git-send-email-beilei.xing@intel.com> References: <1488525977-15321-1-git-send-email-beilei.xing@intel.com> Subject: [dpdk-dev] [PATCH 4/6] app/testpmd: add command for writing personalization profile 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: , Errors-To: dev-bounces@dpdk.org Sender: "dev" This patch is to add testpmd CLI for writing personalization profile. Signed-off-by: Beilei Xing --- app/test-pmd/cmdline.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++ app/test-pmd/config.c | 54 ++++++++++++++++++++++++++++++++++++++++++++ app/test-pmd/testpmd.h | 3 +++ 3 files changed, 118 insertions(+) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 43fc636..6b6af87 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -12395,6 +12395,66 @@ cmdline_parse_inst_t cmd_set_vf_vlan_tag = { }, }; +/* Write Pipeline Personalization Profile */ +struct cmd_write_ppp_result { + cmdline_fixed_string_t write; + cmdline_fixed_string_t ppp; + uint8_t port_id; + char filename[]; +}; + +cmdline_parse_token_string_t cmd_write_ppp_write = + TOKEN_STRING_INITIALIZER(struct cmd_write_ppp_result, write, "write"); +cmdline_parse_token_string_t cmd_write_ppp_ppp = + TOKEN_STRING_INITIALIZER(struct cmd_write_ppp_result, ppp, "ppp"); +cmdline_parse_token_num_t cmd_write_ppp_port_id = + TOKEN_NUM_INITIALIZER(struct cmd_write_ppp_result, port_id, UINT8); +cmdline_parse_token_string_t cmd_write_ppp_filename = + TOKEN_STRING_INITIALIZER(struct cmd_write_ppp_result, filename, NULL); + +static void +cmd_write_ppp_parsed( + void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_write_ppp_result *res = parsed_result; + uint8_t *buff; + 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_package_file(res->filename); + if (!buff) + return; + + ret = i40e_process_package(res->port_id, buff); + if (ret < 0) + printf("Failed to write profile.\n"); + + close_package_file(buff); +} + +cmdline_parse_inst_t cmd_write_ppp = { + .f = cmd_write_ppp_parsed, + .data = NULL, + .help_str = "write ppp ", + .tokens = { + (void *)&cmd_write_ppp_write, + (void *)&cmd_write_ppp_ppp, + (void *)&cmd_write_ppp_port_id, + (void *)&cmd_write_ppp_filename, + NULL, + }, +}; /* ******************************************************************************** */ /* list of instructions */ @@ -12570,6 +12630,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_write_ppp, NULL, }; diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 80491fc..f520c42 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -3245,3 +3245,57 @@ 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_package_file(const char *file_path) +{ + FILE *fh = fopen(file_path, "rb"); + uint32_t pkg_size; + uint8_t *buf = NULL; + int ret = 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 operations failed\n", __func__); + close_package_file(buf); + return NULL; + } + fread(buf, 1, pkg_size, fh); + + fclose(fh); + + return buf; +} + +int +close_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..2a7f683 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_package_file(const char *file_path); +int close_package_file(uint8_t *buf); + enum print_warning { ENABLED_WARN = 0, DISABLED_WARN