From patchwork Fri May 13 07:57:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 111120 X-Patchwork-Delegate: andrew.rybchenko@oktetlabs.ru Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 39EDAA00C3; Fri, 13 May 2022 09:57:33 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 2711442831; Fri, 13 May 2022 09:57:33 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 12D6840DDE for ; Fri, 13 May 2022 09:57:31 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652428650; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uuYRMt/qfTVXYLhuWToDdMSSIIzrUej3LFwN8islQKk=; b=CGAQox5VMK2DIfSx+1DmYRfmDJQK1TTa0ztrmx6K8Gnj515JiFLqITAtUnJBpAtaoVp/Hm nejNS6SUbn/mwioFTzWbqoVSYQce/UA3AgVcGPlGXna/JWLVhh+1jwNZyJZmigV+1Uik3H hVSceAmtbjhGie/Fq+Z/k9dusCkOoFQ= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-247-KoEP0cAwM42EEVfcODM5YA-1; Fri, 13 May 2022 03:57:27 -0400 X-MC-Unique: KoEP0cAwM42EEVfcODM5YA-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E3DE61C05ACB; Fri, 13 May 2022 07:57:26 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.193.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9E9AC401E89; Fri, 13 May 2022 07:57:25 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, Xiaoyun Li , Aman Singh , Yuying Zhang , Bruce Richardson Subject: [RFC PATCH 1/4] app/testpmd: register driver specific commands Date: Fri, 13 May 2022 09:57:15 +0200 Message-Id: <20220513075718.18674-2-david.marchand@redhat.com> In-Reply-To: <20220513075718.18674-1-david.marchand@redhat.com> References: <20220513075718.18674-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Introduce a testpmd API so that drivers can register specific commands. A driver can list some files to compile with testpmd, by setting them in the testpmd_sources (driver local) meson variable. drivers/meson.build then takes care of appending this to a global meson variable, and adding the driver to testpmd dependency. Note: testpmd.h is fixed to that it is self sufficient when being included. Signed-off-by: David Marchand --- app/test-pmd/cmdline.c | 83 ++++++++++++++++++++++++++++++++++++---- app/test-pmd/meson.build | 5 +++ app/test-pmd/testpmd.c | 4 ++ app/test-pmd/testpmd.h | 16 ++++++++ drivers/meson.build | 5 +++ meson.build | 2 + 6 files changed, 108 insertions(+), 7 deletions(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 6ffea8e21a..ed62027834 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -69,6 +69,9 @@ #include "bpf_cmd.h" static struct cmdline *testpmd_cl; +static cmdline_parse_ctx_t *main_ctx; +static TAILQ_HEAD(, testpmd_cmdline_parser) cmdline_parsers = + TAILQ_HEAD_INITIALIZER(cmdline_parsers); static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue); @@ -94,6 +97,7 @@ static void cmd_help_brief_parsed(__rte_unused void *parsed_result, " help filters : Filters configuration help.\n" " help traffic_management : Traffic Management commands.\n" " help devices : Device related cmds.\n" + " help drivers : Driver specific cmds.\n" " help all : All of the above sections.\n\n" ); @@ -1177,6 +1181,21 @@ static void cmd_help_long_parsed(void *parsed_result, ); } + if (show_all || !strcmp(res->section, "drivers")) { + struct testpmd_cmdline_parser *parser; + unsigned int i; + + cmdline_printf( + cl, + "\n" + "Driver specific:\n" + "----------------\n" + ); + TAILQ_FOREACH(parser, &cmdline_parsers, next) { + for (i = 0; parser->help[i] != NULL; i++) + cmdline_printf(cl, "%s\n", parser->help[i]); + } + } } cmdline_parse_token_string_t cmd_help_long_help = @@ -1184,14 +1203,14 @@ cmdline_parse_token_string_t cmd_help_long_help = cmdline_parse_token_string_t cmd_help_long_section = TOKEN_STRING_INITIALIZER(struct cmd_help_long_result, section, - "all#control#display#config#" - "ports#registers#filters#traffic_management#devices"); + "all#control#display#config#ports#registers#" + "filters#traffic_management#devices#drivers"); cmdline_parse_inst_t cmd_help_long = { .f = cmd_help_long_parsed, .data = NULL, .help_str = "help all|control|display|config|ports|register|" - "filters|traffic_management|devices: " + "filters|traffic_management|devices|drivers: " "Show help", .tokens = { (void *)&cmd_help_long_help, @@ -17810,7 +17829,7 @@ cmdline_parse_inst_t cmd_show_port_flow_transfer_proxy = { /* ******************************************************************************** */ /* list of instructions */ -cmdline_parse_ctx_t main_ctx[] = { +static cmdline_parse_ctx_t builtin_ctx[] = { (cmdline_parse_inst_t *)&cmd_help_brief, (cmdline_parse_inst_t *)&cmd_help_long, (cmdline_parse_inst_t *)&cmd_quit, @@ -18096,6 +18115,59 @@ cmdline_parse_ctx_t main_ctx[] = { NULL, }; +void +testpmd_add_commands(struct testpmd_cmdline_parser *parser) +{ + TAILQ_INSERT_TAIL(&cmdline_parsers, parser, next); +} + +int +init_cmdline(void) +{ + struct testpmd_cmdline_parser *parser; + cmdline_parse_ctx_t *ctx; + unsigned int count = 0; + unsigned int i; + + /* initialize non-constant commands */ + cmd_set_fwd_mode_init(); + cmd_set_fwd_retry_mode_init(); + + main_ctx = NULL; + for (i = 0; builtin_ctx[i] != NULL; i++) { + ctx = realloc(main_ctx, (count + i + 1) * sizeof(*ctx)); + if (ctx == NULL) + goto err; + main_ctx = ctx; + main_ctx[count + i] = builtin_ctx[i]; + } + count += i; + + TAILQ_FOREACH(parser, &cmdline_parsers, next) { + for (i = 0; parser->ctx[i] != NULL; i++) { + ctx = realloc(main_ctx, (count + i + 1) * sizeof(*ctx)); + if (ctx == NULL) + goto err; + ctx[count + i] = parser->ctx[i]; + } + count += i; + } + + /* cmdline expects a NULL terminated array */ + ctx = realloc(main_ctx, (count + 1) * sizeof(*ctx)); + if (ctx == NULL) + goto err; + ctx[count] = NULL; + count += 1; + + main_ctx = ctx; + + return 0; +err: + free(main_ctx); + return -1; +} + /* read cmdline commands from file */ void cmdline_read_from_file(const char *filename) @@ -18123,9 +18195,6 @@ void prompt(void) { int ret; - /* initialize non-constant commands */ - cmd_set_fwd_mode_init(); - cmd_set_fwd_retry_mode_init(); testpmd_cl = cmdline_stdin_new(main_ctx, "testpmd> "); if (testpmd_cl == NULL) diff --git a/app/test-pmd/meson.build b/app/test-pmd/meson.build index 43130c8856..46a7511e9a 100644 --- a/app/test-pmd/meson.build +++ b/app/test-pmd/meson.build @@ -73,3 +73,8 @@ endif if dpdk_conf.has('RTE_NET_DPAA') deps += ['bus_dpaa', 'mempool_dpaa', 'net_dpaa'] endif + +# Driver specific sources include some testpmd headers. +includes = include_directories('.') +sources += testpmd_drivers_sources +deps += testpmd_drivers_deps diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index fe2ce19f99..5bda46e32b 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -4263,6 +4263,10 @@ main(int argc, char** argv) } #endif #ifdef RTE_LIB_CMDLINE + if (init_cmdline() != 0) + rte_exit(EXIT_FAILURE, + "Could not initialise cmdline context.\n"); + if (strlen(cmdline_filename) != 0) cmdline_read_from_file(cmdline_filename); diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 31f766c965..9058d21a07 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -16,7 +16,13 @@ #include #endif #include +#include +#include +#include + #include +#include + #include #ifdef RTE_HAS_JANSSON #include @@ -866,6 +872,7 @@ unsigned int parse_item_list(const char *str, const char *item_name, unsigned int *parsed_items, int check_unique_values); void launch_args_parse(int argc, char** argv); void cmdline_read_from_file(const char *filename); +int init_cmdline(void); void prompt(void); void prompt_exit(void); void nic_stats_display(portid_t port_id); @@ -1169,6 +1176,15 @@ extern int flow_parse(const char *src, void *result, unsigned int size, struct rte_flow_item **pattern, struct rte_flow_action **actions); +/* For registering commands out of testpmd sources. */ +struct testpmd_cmdline_parser { + TAILQ_ENTRY(testpmd_cmdline_parser) next; + cmdline_parse_ctx_t *ctx; + const char *help[]; +}; + +void testpmd_add_commands(struct testpmd_cmdline_parser *parser); + /* * Work-around of a compilation error with ICC on invocations of the * rte_be_to_cpu_16() function. diff --git a/drivers/meson.build b/drivers/meson.build index 1d8123b00c..4daa2658b7 100644 --- a/drivers/meson.build +++ b/drivers/meson.build @@ -102,6 +102,7 @@ foreach subpath:subdirs # static builds. ext_deps = [] pkgconfig_extra_libs = [] + testpmd_sources = [] if not enable_drivers.contains(drv_path) build = false @@ -246,6 +247,10 @@ foreach subpath:subdirs set_variable('shared_@0@'.format(lib_name), shared_dep) set_variable('static_@0@'.format(lib_name), static_dep) dependency_name = ''.join(lib_name.split('rte_')) + if testpmd_sources.length() != 0 + testpmd_drivers_sources += testpmd_sources + testpmd_drivers_deps += dependency_name + endif if developer_mode message('drivers/@0@: Defining dependency "@1@"'.format( drv_path, dependency_name)) diff --git a/meson.build b/meson.build index 937f6110c0..5561171617 100644 --- a/meson.build +++ b/meson.build @@ -42,6 +42,8 @@ dpdk_drivers = [] dpdk_extra_ldflags = [] dpdk_libs_disabled = [] dpdk_drvs_disabled = [] +testpmd_drivers_sources = [] +testpmd_drivers_deps = [] abi_version_file = files('ABI_VERSION') if host_machine.cpu_family().startswith('x86') From patchwork Fri May 13 07:57:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 111123 X-Patchwork-Delegate: andrew.rybchenko@oktetlabs.ru Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 1EEB5A00C3; Fri, 13 May 2022 09:57:58 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 9A09942843; Fri, 13 May 2022 09:57:49 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mails.dpdk.org (Postfix) with ESMTP id 557434283B for ; Fri, 13 May 2022 09:57:48 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652428667; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xriTvsNCDNQoUdaaHcViTrotwOOKjlkC8CbVwYbpkcs=; b=AbB/fV3218nTc0QhHIaoZ6xrsffA4Myguku/9dCR0u3bBGPmbbWI+F/TM5OmleiWzK0Xst xifkPEt9QY6bXoRza81WdpYZOmyJYDNPmifxuSNklKNmBo+BE37RaKehnx07Gt5uv6m/9G Lujeb/5fOhPNljpHpy283jrNl7y5IQI= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-282-wPgaego4PWu719nkKChVog-1; Fri, 13 May 2022 03:57:31 -0400 X-MC-Unique: wPgaego4PWu719nkKChVog-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1B4331C05AC8; Fri, 13 May 2022 07:57:31 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.193.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34A82401E89; Fri, 13 May 2022 07:57:29 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, Xiaoyun Li , Aman Singh , Yuying Zhang , Chas Williams , "Min Hu (Connor)" Subject: [RFC PATCH 2/4] net/bonding: move testpmd commands Date: Fri, 13 May 2022 09:57:16 +0200 Message-Id: <20220513075718.18674-3-david.marchand@redhat.com> In-Reply-To: <20220513075718.18674-1-david.marchand@redhat.com> References: <20220513075718.18674-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Move related specific testpmd commands into this driver directory. While at it, fix checkpatch warnings. Signed-off-by: David Marchand --- app/test-pmd/cmdline.c | 1035 ------------------- app/test-pmd/meson.build | 3 - drivers/net/bonding/meson.build | 1 + drivers/net/bonding/rte_eth_bond_testpmd.c | 1037 ++++++++++++++++++++ 4 files changed, 1038 insertions(+), 1038 deletions(-) create mode 100644 drivers/net/bonding/rte_eth_bond_testpmd.c diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index ed62027834..ae4759fbfe 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -47,10 +47,6 @@ #include #include #include -#ifdef RTE_NET_BOND -#include -#include -#endif #if defined RTE_BUS_DPAA && defined RTE_NET_DPAA #include #endif @@ -614,44 +610,6 @@ static void cmd_help_long_parsed(void *parsed_result, " Show the bypass configuration for a bypass enabled NIC" " using the lowest port on the NIC.\n\n" -#ifdef RTE_NET_BOND - "create bonded device (mode) (socket)\n" - " Create a new bonded device with specific bonding mode and socket.\n\n" - - "add bonding slave (slave_id) (port_id)\n" - " Add a slave device to a bonded device.\n\n" - - "remove bonding slave (slave_id) (port_id)\n" - " Remove a slave device from a bonded device.\n\n" - - "set bonding mode (value) (port_id)\n" - " Set the bonding mode on a bonded device.\n\n" - - "set bonding primary (slave_id) (port_id)\n" - " Set the primary slave for a bonded device.\n\n" - - "show bonding config (port_id)\n" - " Show the bonding config for port_id.\n\n" - - "show bonding lacp info (port_id)\n" - " Show the bonding lacp information for port_id.\n\n" - - "set bonding mac_addr (port_id) (address)\n" - " Set the MAC address of a bonded device.\n\n" - - "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)" - " Set Aggregation mode for IEEE802.3AD (mode 4)" - - "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n" - " Set the transmit balance policy for bonded device running in balance mode.\n\n" - - "set bonding mon_period (port_id) (value)\n" - " Set the bonding link status monitoring polling period in ms.\n\n" - - "set bonding lacp dedicated_queues (enable|disable)\n" - " Enable/disable dedicated queues for LACP control traffic.\n\n" - -#endif "set link-up port (port_id)\n" " Set link up for a port.\n\n" @@ -5925,985 +5883,6 @@ cmdline_parse_inst_t cmd_show_bypass_config = { }, }; -#ifdef RTE_NET_BOND -/* *** SET BONDING MODE *** */ -struct cmd_set_bonding_mode_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t bonding; - cmdline_fixed_string_t mode; - uint8_t value; - portid_t port_id; -}; - -static void cmd_set_bonding_mode_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_set_bonding_mode_result *res = parsed_result; - portid_t port_id = res->port_id; - struct rte_port *port = &ports[port_id]; - - /* - * Bonding mode changed means resources of device changed, like whether - * started rte timer or not. Device should be restarted when resources - * of device changed. - */ - if (port->port_status != RTE_PORT_STOPPED) { - fprintf(stderr, - "\t Error: Can't set bonding mode when port %d is not stopped\n", - port_id); - return; - } - - /* Set the bonding mode for the relevant port. */ - if (0 != rte_eth_bond_mode_set(port_id, res->value)) - fprintf(stderr, "\t Failed to set bonding mode for port = %d.\n", - port_id); -} - -cmdline_parse_token_string_t cmd_setbonding_mode_set = -TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, - set, "set"); -cmdline_parse_token_string_t cmd_setbonding_mode_bonding = -TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, - bonding, "bonding"); -cmdline_parse_token_string_t cmd_setbonding_mode_mode = -TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, - mode, "mode"); -cmdline_parse_token_num_t cmd_setbonding_mode_value = -TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result, - value, RTE_UINT8); -cmdline_parse_token_num_t cmd_setbonding_mode_port = -TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result, - port_id, RTE_UINT16); - -cmdline_parse_inst_t cmd_set_bonding_mode = { - .f = cmd_set_bonding_mode_parsed, - .help_str = "set bonding mode : " - "Set the bonding mode for port_id", - .data = NULL, - .tokens = { - (void *) &cmd_setbonding_mode_set, - (void *) &cmd_setbonding_mode_bonding, - (void *) &cmd_setbonding_mode_mode, - (void *) &cmd_setbonding_mode_value, - (void *) &cmd_setbonding_mode_port, - NULL - } -}; - -/* *** SET BONDING SLOW_QUEUE SW/HW *** */ -struct cmd_set_bonding_lacp_dedicated_queues_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t bonding; - cmdline_fixed_string_t lacp; - cmdline_fixed_string_t dedicated_queues; - portid_t port_id; - cmdline_fixed_string_t mode; -}; - -static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result; - portid_t port_id = res->port_id; - struct rte_port *port; - - port = &ports[port_id]; - - /** Check if the port is not started **/ - if (port->port_status != RTE_PORT_STOPPED) { - fprintf(stderr, "Please stop port %d first\n", port_id); - return; - } - - if (!strcmp(res->mode, "enable")) { - if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0) - printf("Dedicate queues for LACP control packets" - " enabled\n"); - else - printf("Enabling dedicate queues for LACP control " - "packets on port %d failed\n", port_id); - } else if (!strcmp(res->mode, "disable")) { - if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0) - printf("Dedicated queues for LACP control packets " - "disabled\n"); - else - printf("Disabling dedicated queues for LACP control " - "traffic on port %d failed\n", port_id); - } -} - -cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set = -TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, - set, "set"); -cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding = -TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, - bonding, "bonding"); -cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp = -TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, - lacp, "lacp"); -cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues = -TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, - dedicated_queues, "dedicated_queues"); -cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id = -TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, - port_id, RTE_UINT16); -cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode = -TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, - mode, "enable#disable"); - -cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = { - .f = cmd_set_bonding_lacp_dedicated_queues_parsed, - .help_str = "set bonding lacp dedicated_queues " - "enable|disable: " - "Enable/disable dedicated queues for LACP control traffic for port_id", - .data = NULL, - .tokens = { - (void *)&cmd_setbonding_lacp_dedicated_queues_set, - (void *)&cmd_setbonding_lacp_dedicated_queues_bonding, - (void *)&cmd_setbonding_lacp_dedicated_queues_lacp, - (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues, - (void *)&cmd_setbonding_lacp_dedicated_queues_port_id, - (void *)&cmd_setbonding_lacp_dedicated_queues_mode, - NULL - } -}; - -/* *** SET BALANCE XMIT POLICY *** */ -struct cmd_set_bonding_balance_xmit_policy_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t bonding; - cmdline_fixed_string_t balance_xmit_policy; - portid_t port_id; - cmdline_fixed_string_t policy; -}; - -static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result; - portid_t port_id = res->port_id; - uint8_t policy; - - if (!strcmp(res->policy, "l2")) { - policy = BALANCE_XMIT_POLICY_LAYER2; - } else if (!strcmp(res->policy, "l23")) { - policy = BALANCE_XMIT_POLICY_LAYER23; - } else if (!strcmp(res->policy, "l34")) { - policy = BALANCE_XMIT_POLICY_LAYER34; - } else { - fprintf(stderr, "\t Invalid xmit policy selection"); - return; - } - - /* Set the bonding mode for the relevant port. */ - if (0 != rte_eth_bond_xmit_policy_set(port_id, policy)) { - fprintf(stderr, - "\t Failed to set bonding balance xmit policy for port = %d.\n", - port_id); - } -} - -cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set = -TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, - set, "set"); -cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding = -TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, - bonding, "bonding"); -cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy = -TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, - balance_xmit_policy, "balance_xmit_policy"); -cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port = -TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, - port_id, RTE_UINT16); -cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy = -TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, - policy, "l2#l23#l34"); - -cmdline_parse_inst_t cmd_set_balance_xmit_policy = { - .f = cmd_set_bonding_balance_xmit_policy_parsed, - .help_str = "set bonding balance_xmit_policy " - "l2|l23|l34: " - "Set the bonding balance_xmit_policy for port_id", - .data = NULL, - .tokens = { - (void *)&cmd_setbonding_balance_xmit_policy_set, - (void *)&cmd_setbonding_balance_xmit_policy_bonding, - (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy, - (void *)&cmd_setbonding_balance_xmit_policy_port, - (void *)&cmd_setbonding_balance_xmit_policy_policy, - NULL - } -}; - -/* *** SHOW IEEE802.3 BONDING INFORMATION *** */ -struct cmd_show_bonding_lacp_info_result { - cmdline_fixed_string_t show; - cmdline_fixed_string_t bonding; - cmdline_fixed_string_t lacp; - cmdline_fixed_string_t info; - portid_t port_id; -}; - -static void port_param_show(struct port_params *params) -{ - char buf[RTE_ETHER_ADDR_FMT_SIZE]; - - printf("\t\tsystem priority: %u\n", params->system_priority); - rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, ¶ms->system); - printf("\t\tsystem mac address: %s\n", buf); - printf("\t\tport key: %u\n", params->key); - printf("\t\tport priority: %u\n", params->port_priority); - printf("\t\tport number: %u\n", params->port_number); -} - -static void lacp_slave_info_show(struct rte_eth_bond_8023ad_slave_info *info) -{ - char a_state[256] = { 0 }; - char p_state[256] = { 0 }; - int a_len = 0; - int p_len = 0; - uint32_t i; - - static const char * const state[] = { - "ACTIVE", - "TIMEOUT", - "AGGREGATION", - "SYNCHRONIZATION", - "COLLECTING", - "DISTRIBUTING", - "DEFAULTED", - "EXPIRED" - }; - static const char * const selection[] = { - "UNSELECTED", - "STANDBY", - "SELECTED" - }; - - for (i = 0; i < RTE_DIM(state); i++) { - if ((info->actor_state >> i) & 1) - a_len += snprintf(&a_state[a_len], - RTE_DIM(a_state) - a_len, "%s ", - state[i]); - - if ((info->partner_state >> i) & 1) - p_len += snprintf(&p_state[p_len], - RTE_DIM(p_state) - p_len, "%s ", - state[i]); - } - printf("\tAggregator port id: %u\n", info->agg_port_id); - printf("\tselection: %s\n", selection[info->selected]); - printf("\tActor detail info:\n"); - port_param_show(&info->actor); - printf("\t\tport state: %s\n", a_state); - printf("\tPartner detail info:\n"); - port_param_show(&info->partner); - printf("\t\tport state: %s\n", p_state); - printf("\n"); -} - -static void lacp_conf_show(struct rte_eth_bond_8023ad_conf *conf) -{ - printf("\tfast period: %u ms\n", conf->fast_periodic_ms); - printf("\tslow period: %u ms\n", conf->slow_periodic_ms); - printf("\tshort timeout: %u ms\n", conf->short_timeout_ms); - printf("\tlong timeout: %u ms\n", conf->long_timeout_ms); - printf("\taggregate wait timeout: %u ms\n", - conf->aggregate_wait_timeout_ms); - printf("\ttx period: %u ms\n", conf->tx_period_ms); - printf("\trx marker period: %u ms\n", conf->rx_marker_period_ms); - printf("\tupdate timeout: %u ms\n", conf->update_timeout_ms); - switch (conf->agg_selection) { - case AGG_BANDWIDTH: - printf("\taggregation mode: bandwidth\n"); - break; - case AGG_STABLE: - printf("\taggregation mode: stable\n"); - break; - case AGG_COUNT: - printf("\taggregation mode: count\n"); - break; - default: - printf("\taggregation mode: invalid\n"); - break; - } - - printf("\n"); -} - -static void cmd_show_bonding_lacp_info_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_show_bonding_lacp_info_result *res = parsed_result; - struct rte_eth_bond_8023ad_slave_info slave_info; - struct rte_eth_bond_8023ad_conf port_conf; - portid_t slaves[RTE_MAX_ETHPORTS]; - portid_t port_id = res->port_id; - int num_active_slaves; - int bonding_mode; - int i; - int ret; - - bonding_mode = rte_eth_bond_mode_get(port_id); - if (bonding_mode != BONDING_MODE_8023AD) { - fprintf(stderr, "\tBonding mode is not mode 4\n"); - return; - } - - num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves, - RTE_MAX_ETHPORTS); - if (num_active_slaves < 0) { - fprintf(stderr, "\tFailed to get active slave list for port = %u\n", - port_id); - return; - } - if (num_active_slaves == 0) - fprintf(stderr, "\tIEEE802.3 port %u has no active slave\n", - port_id); - - printf("\tIEEE802.3 port: %u\n", port_id); - ret = rte_eth_bond_8023ad_conf_get(port_id, &port_conf); - if (ret) { - fprintf(stderr, "\tGet bonded device %u info failed\n", - port_id); - return; - } - lacp_conf_show(&port_conf); - - for (i = 0; i < num_active_slaves; i++) { - ret = rte_eth_bond_8023ad_slave_info(port_id, slaves[i], - &slave_info); - if (ret) { - fprintf(stderr, "\tGet slave device %u info failed\n", - slaves[i]); - return; - } - printf("\tSlave Port: %u\n", slaves[i]); - lacp_slave_info_show(&slave_info); - } -} - -cmdline_parse_token_string_t cmd_show_bonding_lacp_info_show = -TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result, - show, "show"); -cmdline_parse_token_string_t cmd_show_bonding_lacp_info_bonding = -TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result, - bonding, "bonding"); -cmdline_parse_token_string_t cmd_show_bonding_lacp_info_lacp = -TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result, - bonding, "lacp"); -cmdline_parse_token_string_t cmd_show_bonding_lacp_info_info = -TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result, - info, "info"); -cmdline_parse_token_num_t cmd_show_bonding_lacp_info_port_id = -TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_lacp_info_result, - port_id, RTE_UINT16); - -cmdline_parse_inst_t cmd_show_bonding_lacp_info = { - .f = cmd_show_bonding_lacp_info_parsed, - .help_str = "show bonding lacp info : " - "Show bonding IEEE802.3 information for port_id", - .data = NULL, - .tokens = { - (void *)&cmd_show_bonding_lacp_info_show, - (void *)&cmd_show_bonding_lacp_info_bonding, - (void *)&cmd_show_bonding_lacp_info_lacp, - (void *)&cmd_show_bonding_lacp_info_info, - (void *)&cmd_show_bonding_lacp_info_port_id, - NULL - } -}; - -/* *** SHOW NIC BONDING CONFIGURATION *** */ -struct cmd_show_bonding_config_result { - cmdline_fixed_string_t show; - cmdline_fixed_string_t bonding; - cmdline_fixed_string_t config; - portid_t port_id; -}; - -static void cmd_show_bonding_config_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_show_bonding_config_result *res = parsed_result; - int bonding_mode, agg_mode; - portid_t slaves[RTE_MAX_ETHPORTS]; - int num_slaves, num_active_slaves; - int primary_id; - int i; - portid_t port_id = res->port_id; - - /* Display the bonding mode.*/ - bonding_mode = rte_eth_bond_mode_get(port_id); - if (bonding_mode < 0) { - fprintf(stderr, "\tFailed to get bonding mode for port = %d\n", - port_id); - return; - } else - printf("\tBonding mode: %d\n", bonding_mode); - - if (bonding_mode == BONDING_MODE_BALANCE || - bonding_mode == BONDING_MODE_8023AD) { - int balance_xmit_policy; - - balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id); - if (balance_xmit_policy < 0) { - fprintf(stderr, - "\tFailed to get balance xmit policy for port = %d\n", - port_id); - return; - } else { - printf("\tBalance Xmit Policy: "); - - switch (balance_xmit_policy) { - case BALANCE_XMIT_POLICY_LAYER2: - printf("BALANCE_XMIT_POLICY_LAYER2"); - break; - case BALANCE_XMIT_POLICY_LAYER23: - printf("BALANCE_XMIT_POLICY_LAYER23"); - break; - case BALANCE_XMIT_POLICY_LAYER34: - printf("BALANCE_XMIT_POLICY_LAYER34"); - break; - } - printf("\n"); - } - } - - if (bonding_mode == BONDING_MODE_8023AD) { - agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id); - printf("\tIEEE802.3AD Aggregator Mode: "); - switch (agg_mode) { - case AGG_BANDWIDTH: - printf("bandwidth"); - break; - case AGG_STABLE: - printf("stable"); - break; - case AGG_COUNT: - printf("count"); - break; - } - printf("\n"); - } - - num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS); - - if (num_slaves < 0) { - fprintf(stderr, "\tFailed to get slave list for port = %d\n", - port_id); - return; - } - if (num_slaves > 0) { - printf("\tSlaves (%d): [", num_slaves); - for (i = 0; i < num_slaves - 1; i++) - printf("%d ", slaves[i]); - - printf("%d]\n", slaves[num_slaves - 1]); - } else { - printf("\tSlaves: []\n"); - - } - - num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves, - RTE_MAX_ETHPORTS); - - if (num_active_slaves < 0) { - fprintf(stderr, - "\tFailed to get active slave list for port = %d\n", - port_id); - return; - } - if (num_active_slaves > 0) { - printf("\tActive Slaves (%d): [", num_active_slaves); - for (i = 0; i < num_active_slaves - 1; i++) - printf("%d ", slaves[i]); - - printf("%d]\n", slaves[num_active_slaves - 1]); - - } else { - printf("\tActive Slaves: []\n"); - - } - - primary_id = rte_eth_bond_primary_get(port_id); - if (primary_id < 0) { - fprintf(stderr, "\tFailed to get primary slave for port = %d\n", - port_id); - return; - } else - printf("\tPrimary: [%d]\n", primary_id); - -} - -cmdline_parse_token_string_t cmd_showbonding_config_show = -TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, - show, "show"); -cmdline_parse_token_string_t cmd_showbonding_config_bonding = -TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, - bonding, "bonding"); -cmdline_parse_token_string_t cmd_showbonding_config_config = -TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, - config, "config"); -cmdline_parse_token_num_t cmd_showbonding_config_port = -TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result, - port_id, RTE_UINT16); - -cmdline_parse_inst_t cmd_show_bonding_config = { - .f = cmd_show_bonding_config_parsed, - .help_str = "show bonding config : " - "Show the bonding config for port_id", - .data = NULL, - .tokens = { - (void *)&cmd_showbonding_config_show, - (void *)&cmd_showbonding_config_bonding, - (void *)&cmd_showbonding_config_config, - (void *)&cmd_showbonding_config_port, - NULL - } -}; - -/* *** SET BONDING PRIMARY *** */ -struct cmd_set_bonding_primary_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t bonding; - cmdline_fixed_string_t primary; - portid_t slave_id; - portid_t port_id; -}; - -static void cmd_set_bonding_primary_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_set_bonding_primary_result *res = parsed_result; - portid_t master_port_id = res->port_id; - portid_t slave_port_id = res->slave_id; - - /* Set the primary slave for a bonded device. */ - if (0 != rte_eth_bond_primary_set(master_port_id, slave_port_id)) { - fprintf(stderr, "\t Failed to set primary slave for port = %d.\n", - master_port_id); - return; - } - init_port_config(); -} - -cmdline_parse_token_string_t cmd_setbonding_primary_set = -TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, - set, "set"); -cmdline_parse_token_string_t cmd_setbonding_primary_bonding = -TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, - bonding, "bonding"); -cmdline_parse_token_string_t cmd_setbonding_primary_primary = -TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, - primary, "primary"); -cmdline_parse_token_num_t cmd_setbonding_primary_slave = -TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result, - slave_id, RTE_UINT16); -cmdline_parse_token_num_t cmd_setbonding_primary_port = -TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result, - port_id, RTE_UINT16); - -cmdline_parse_inst_t cmd_set_bonding_primary = { - .f = cmd_set_bonding_primary_parsed, - .help_str = "set bonding primary : " - "Set the primary slave for port_id", - .data = NULL, - .tokens = { - (void *)&cmd_setbonding_primary_set, - (void *)&cmd_setbonding_primary_bonding, - (void *)&cmd_setbonding_primary_primary, - (void *)&cmd_setbonding_primary_slave, - (void *)&cmd_setbonding_primary_port, - NULL - } -}; - -/* *** ADD SLAVE *** */ -struct cmd_add_bonding_slave_result { - cmdline_fixed_string_t add; - cmdline_fixed_string_t bonding; - cmdline_fixed_string_t slave; - portid_t slave_id; - portid_t port_id; -}; - -static void cmd_add_bonding_slave_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_add_bonding_slave_result *res = parsed_result; - portid_t master_port_id = res->port_id; - portid_t slave_port_id = res->slave_id; - - /* add the slave for a bonded device. */ - if (0 != rte_eth_bond_slave_add(master_port_id, slave_port_id)) { - fprintf(stderr, - "\t Failed to add slave %d to master port = %d.\n", - slave_port_id, master_port_id); - return; - } - init_port_config(); - set_port_slave_flag(slave_port_id); -} - -cmdline_parse_token_string_t cmd_addbonding_slave_add = -TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, - add, "add"); -cmdline_parse_token_string_t cmd_addbonding_slave_bonding = -TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, - bonding, "bonding"); -cmdline_parse_token_string_t cmd_addbonding_slave_slave = -TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, - slave, "slave"); -cmdline_parse_token_num_t cmd_addbonding_slave_slaveid = -TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result, - slave_id, RTE_UINT16); -cmdline_parse_token_num_t cmd_addbonding_slave_port = -TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result, - port_id, RTE_UINT16); - -cmdline_parse_inst_t cmd_add_bonding_slave = { - .f = cmd_add_bonding_slave_parsed, - .help_str = "add bonding slave : " - "Add a slave device to a bonded device", - .data = NULL, - .tokens = { - (void *)&cmd_addbonding_slave_add, - (void *)&cmd_addbonding_slave_bonding, - (void *)&cmd_addbonding_slave_slave, - (void *)&cmd_addbonding_slave_slaveid, - (void *)&cmd_addbonding_slave_port, - NULL - } -}; - -/* *** REMOVE SLAVE *** */ -struct cmd_remove_bonding_slave_result { - cmdline_fixed_string_t remove; - cmdline_fixed_string_t bonding; - cmdline_fixed_string_t slave; - portid_t slave_id; - portid_t port_id; -}; - -static void cmd_remove_bonding_slave_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_remove_bonding_slave_result *res = parsed_result; - portid_t master_port_id = res->port_id; - portid_t slave_port_id = res->slave_id; - - /* remove the slave from a bonded device. */ - if (0 != rte_eth_bond_slave_remove(master_port_id, slave_port_id)) { - fprintf(stderr, - "\t Failed to remove slave %d from master port = %d.\n", - slave_port_id, master_port_id); - return; - } - init_port_config(); - clear_port_slave_flag(slave_port_id); -} - -cmdline_parse_token_string_t cmd_removebonding_slave_remove = - TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, - remove, "remove"); -cmdline_parse_token_string_t cmd_removebonding_slave_bonding = - TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, - bonding, "bonding"); -cmdline_parse_token_string_t cmd_removebonding_slave_slave = - TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, - slave, "slave"); -cmdline_parse_token_num_t cmd_removebonding_slave_slaveid = - TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result, - slave_id, RTE_UINT16); -cmdline_parse_token_num_t cmd_removebonding_slave_port = - TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result, - port_id, RTE_UINT16); - -cmdline_parse_inst_t cmd_remove_bonding_slave = { - .f = cmd_remove_bonding_slave_parsed, - .help_str = "remove bonding slave : " - "Remove a slave device from a bonded device", - .data = NULL, - .tokens = { - (void *)&cmd_removebonding_slave_remove, - (void *)&cmd_removebonding_slave_bonding, - (void *)&cmd_removebonding_slave_slave, - (void *)&cmd_removebonding_slave_slaveid, - (void *)&cmd_removebonding_slave_port, - NULL - } -}; - -/* *** CREATE BONDED DEVICE *** */ -struct cmd_create_bonded_device_result { - cmdline_fixed_string_t create; - cmdline_fixed_string_t bonded; - cmdline_fixed_string_t device; - uint8_t mode; - uint8_t socket; -}; - -static int bond_dev_num = 0; - -static void cmd_create_bonded_device_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_create_bonded_device_result *res = parsed_result; - char ethdev_name[RTE_ETH_NAME_MAX_LEN]; - int port_id; - int ret; - - if (test_done == 0) { - fprintf(stderr, "Please stop forwarding first\n"); - return; - } - - snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d", - bond_dev_num++); - - /* Create a new bonded device. */ - port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket); - if (port_id < 0) { - fprintf(stderr, "\t Failed to create bonded device.\n"); - return; - } else { - printf("Created new bonded device %s on (port %d).\n", ethdev_name, - port_id); - - /* Update number of ports */ - nb_ports = rte_eth_dev_count_avail(); - reconfig(port_id, res->socket); - ret = rte_eth_promiscuous_enable(port_id); - if (ret != 0) - fprintf(stderr, - "Failed to enable promiscuous mode for port %u: %s - ignore\n", - port_id, rte_strerror(-ret)); - - ports[port_id].need_setup = 0; - ports[port_id].port_status = RTE_PORT_STOPPED; - } - -} - -cmdline_parse_token_string_t cmd_createbonded_device_create = - TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, - create, "create"); -cmdline_parse_token_string_t cmd_createbonded_device_bonded = - TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, - bonded, "bonded"); -cmdline_parse_token_string_t cmd_createbonded_device_device = - TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, - device, "device"); -cmdline_parse_token_num_t cmd_createbonded_device_mode = - TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result, - mode, RTE_UINT8); -cmdline_parse_token_num_t cmd_createbonded_device_socket = - TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result, - socket, RTE_UINT8); - -cmdline_parse_inst_t cmd_create_bonded_device = { - .f = cmd_create_bonded_device_parsed, - .help_str = "create bonded device : " - "Create a new bonded device with specific bonding mode and socket", - .data = NULL, - .tokens = { - (void *)&cmd_createbonded_device_create, - (void *)&cmd_createbonded_device_bonded, - (void *)&cmd_createbonded_device_device, - (void *)&cmd_createbonded_device_mode, - (void *)&cmd_createbonded_device_socket, - NULL - } -}; - -/* *** SET MAC ADDRESS IN BONDED DEVICE *** */ -struct cmd_set_bond_mac_addr_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t bonding; - cmdline_fixed_string_t mac_addr; - uint16_t port_num; - struct rte_ether_addr address; -}; - -static void cmd_set_bond_mac_addr_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_set_bond_mac_addr_result *res = parsed_result; - int ret; - - if (port_id_is_invalid(res->port_num, ENABLED_WARN)) - return; - - ret = rte_eth_bond_mac_address_set(res->port_num, &res->address); - - /* check the return value and print it if is < 0 */ - if (ret < 0) - fprintf(stderr, "set_bond_mac_addr error: (%s)\n", - strerror(-ret)); -} - -cmdline_parse_token_string_t cmd_set_bond_mac_addr_set = - TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set"); -cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding = - TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding, - "bonding"); -cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac = - TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr, - "mac_addr"); -cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum = - TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, - port_num, RTE_UINT16); -cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr = - TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address); - -cmdline_parse_inst_t cmd_set_bond_mac_addr = { - .f = cmd_set_bond_mac_addr_parsed, - .data = (void *) 0, - .help_str = "set bonding mac_addr ", - .tokens = { - (void *)&cmd_set_bond_mac_addr_set, - (void *)&cmd_set_bond_mac_addr_bonding, - (void *)&cmd_set_bond_mac_addr_mac, - (void *)&cmd_set_bond_mac_addr_portnum, - (void *)&cmd_set_bond_mac_addr_addr, - NULL - } -}; - - -/* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */ -struct cmd_set_bond_mon_period_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t bonding; - cmdline_fixed_string_t mon_period; - uint16_t port_num; - uint32_t period_ms; -}; - -static void cmd_set_bond_mon_period_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_set_bond_mon_period_result *res = parsed_result; - int ret; - - ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms); - - /* check the return value and print it if is < 0 */ - if (ret < 0) - fprintf(stderr, "set_bond_mac_addr error: (%s)\n", - strerror(-ret)); -} - -cmdline_parse_token_string_t cmd_set_bond_mon_period_set = - TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, - set, "set"); -cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding = - TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, - bonding, "bonding"); -cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period = - TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, - mon_period, "mon_period"); -cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum = - TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result, - port_num, RTE_UINT16); -cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms = - TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result, - period_ms, RTE_UINT32); - -cmdline_parse_inst_t cmd_set_bond_mon_period = { - .f = cmd_set_bond_mon_period_parsed, - .data = (void *) 0, - .help_str = "set bonding mon_period ", - .tokens = { - (void *)&cmd_set_bond_mon_period_set, - (void *)&cmd_set_bond_mon_period_bonding, - (void *)&cmd_set_bond_mon_period_mon_period, - (void *)&cmd_set_bond_mon_period_portnum, - (void *)&cmd_set_bond_mon_period_period_ms, - NULL - } -}; - - - -struct cmd_set_bonding_agg_mode_policy_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t bonding; - cmdline_fixed_string_t agg_mode; - uint16_t port_num; - cmdline_fixed_string_t policy; -}; - - -static void -cmd_set_bonding_agg_mode(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result; - uint8_t policy = AGG_BANDWIDTH; - - if (!strcmp(res->policy, "bandwidth")) - policy = AGG_BANDWIDTH; - else if (!strcmp(res->policy, "stable")) - policy = AGG_STABLE; - else if (!strcmp(res->policy, "count")) - policy = AGG_COUNT; - - rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy); -} - - -cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set = - TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, - set, "set"); -cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding = - TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, - bonding, "bonding"); - -cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode = - TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, - agg_mode, "agg_mode"); - -cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum = - TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, - port_num, RTE_UINT16); - -cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string = - TOKEN_STRING_INITIALIZER( - struct cmd_set_bonding_balance_xmit_policy_result, - policy, "stable#bandwidth#count"); - -cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = { - .f = cmd_set_bonding_agg_mode, - .data = (void *) 0, - .help_str = "set bonding mode IEEE802.3AD aggregator policy ", - .tokens = { - (void *)&cmd_set_bonding_agg_mode_set, - (void *)&cmd_set_bonding_agg_mode_bonding, - (void *)&cmd_set_bonding_agg_mode_agg_mode, - (void *)&cmd_set_bonding_agg_mode_portnum, - (void *)&cmd_set_bonding_agg_mode_policy_string, - NULL - } -}; - - -#endif /* RTE_NET_BOND */ - /* *** SET FORWARDING MODE *** */ struct cmd_set_fwd_mode_result { cmdline_fixed_string_t set; @@ -17870,20 +16849,6 @@ static cmdline_parse_ctx_t builtin_ctx[] = { (cmdline_parse_inst_t *)&cmd_set_bypass_event, (cmdline_parse_inst_t *)&cmd_set_bypass_timeout, (cmdline_parse_inst_t *)&cmd_show_bypass_config, -#ifdef RTE_NET_BOND - (cmdline_parse_inst_t *) &cmd_set_bonding_mode, - (cmdline_parse_inst_t *) &cmd_show_bonding_config, - (cmdline_parse_inst_t *) &cmd_show_bonding_lacp_info, - (cmdline_parse_inst_t *) &cmd_set_bonding_primary, - (cmdline_parse_inst_t *) &cmd_add_bonding_slave, - (cmdline_parse_inst_t *) &cmd_remove_bonding_slave, - (cmdline_parse_inst_t *) &cmd_create_bonded_device, - (cmdline_parse_inst_t *) &cmd_set_bond_mac_addr, - (cmdline_parse_inst_t *) &cmd_set_balance_xmit_policy, - (cmdline_parse_inst_t *) &cmd_set_bond_mon_period, - (cmdline_parse_inst_t *) &cmd_set_lacp_dedicated_queues, - (cmdline_parse_inst_t *) &cmd_set_bonding_agg_mode_policy, -#endif (cmdline_parse_inst_t *)&cmd_vlan_offload, (cmdline_parse_inst_t *)&cmd_vlan_tpid, (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all, diff --git a/app/test-pmd/meson.build b/app/test-pmd/meson.build index 46a7511e9a..07634332f3 100644 --- a/app/test-pmd/meson.build +++ b/app/test-pmd/meson.build @@ -58,9 +58,6 @@ endif if dpdk_conf.has('RTE_LIB_PDUMP') deps += 'pdump' endif -if dpdk_conf.has('RTE_NET_BOND') - deps += 'net_bond' -endif if dpdk_conf.has('RTE_NET_BNXT') deps += 'net_bnxt' endif diff --git a/drivers/net/bonding/meson.build b/drivers/net/bonding/meson.build index 402b44be1a..faea892295 100644 --- a/drivers/net/bonding/meson.build +++ b/drivers/net/bonding/meson.build @@ -16,6 +16,7 @@ sources = files( 'rte_eth_bond_flow.c', 'rte_eth_bond_pmd.c', ) +testpmd_sources = files('rte_eth_bond_testpmd.c') deps += 'sched' # needed for rte_bitmap.h deps += ['ip_frag'] diff --git a/drivers/net/bonding/rte_eth_bond_testpmd.c b/drivers/net/bonding/rte_eth_bond_testpmd.c new file mode 100644 index 0000000000..834e2da4e6 --- /dev/null +++ b/drivers/net/bonding/rte_eth_bond_testpmd.c @@ -0,0 +1,1037 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2016 Intel Corporation. + */ + +#include +#include + +#include +#include +#include +#include + +#include "testpmd.h" + +/* *** SET BONDING MODE *** */ +struct cmd_set_bonding_mode_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t bonding; + cmdline_fixed_string_t mode; + uint8_t value; + portid_t port_id; +}; + +static void cmd_set_bonding_mode_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_set_bonding_mode_result *res = parsed_result; + portid_t port_id = res->port_id; + struct rte_port *port = &ports[port_id]; + + /* + * Bonding mode changed means resources of device changed, like whether + * started rte timer or not. Device should be restarted when resources + * of device changed. + */ + if (port->port_status != RTE_PORT_STOPPED) { + fprintf(stderr, + "\t Error: Can't set bonding mode when port %d is not stopped\n", + port_id); + return; + } + + /* Set the bonding mode for the relevant port. */ + if (rte_eth_bond_mode_set(port_id, res->value) != 0) + fprintf(stderr, "\t Failed to set bonding mode for port = %d.\n", + port_id); +} + +cmdline_parse_token_string_t cmd_setbonding_mode_set = +TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, + set, "set"); +cmdline_parse_token_string_t cmd_setbonding_mode_bonding = +TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, + bonding, "bonding"); +cmdline_parse_token_string_t cmd_setbonding_mode_mode = +TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_mode_result, + mode, "mode"); +cmdline_parse_token_num_t cmd_setbonding_mode_value = +TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result, + value, RTE_UINT8); +cmdline_parse_token_num_t cmd_setbonding_mode_port = +TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_mode_result, + port_id, RTE_UINT16); + +cmdline_parse_inst_t cmd_set_bonding_mode = { + .f = cmd_set_bonding_mode_parsed, + .help_str = "set bonding mode : " + "Set the bonding mode for port_id", + .data = NULL, + .tokens = { + (void *)&cmd_setbonding_mode_set, + (void *)&cmd_setbonding_mode_bonding, + (void *)&cmd_setbonding_mode_mode, + (void *)&cmd_setbonding_mode_value, + (void *)&cmd_setbonding_mode_port, + NULL + } +}; + +/* *** SET BONDING SLOW_QUEUE SW/HW *** */ +struct cmd_set_bonding_lacp_dedicated_queues_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t bonding; + cmdline_fixed_string_t lacp; + cmdline_fixed_string_t dedicated_queues; + portid_t port_id; + cmdline_fixed_string_t mode; +}; + +static void cmd_set_bonding_lacp_dedicated_queues_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_set_bonding_lacp_dedicated_queues_result *res = parsed_result; + portid_t port_id = res->port_id; + struct rte_port *port; + + port = &ports[port_id]; + + /** Check if the port is not started **/ + if (port->port_status != RTE_PORT_STOPPED) { + fprintf(stderr, "Please stop port %d first\n", port_id); + return; + } + + if (!strcmp(res->mode, "enable")) { + if (rte_eth_bond_8023ad_dedicated_queues_enable(port_id) == 0) + printf("Dedicate queues for LACP control packets" + " enabled\n"); + else + printf("Enabling dedicate queues for LACP control " + "packets on port %d failed\n", port_id); + } else if (!strcmp(res->mode, "disable")) { + if (rte_eth_bond_8023ad_dedicated_queues_disable(port_id) == 0) + printf("Dedicated queues for LACP control packets " + "disabled\n"); + else + printf("Disabling dedicated queues for LACP control " + "traffic on port %d failed\n", port_id); + } +} + +cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_set = +TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, + set, "set"); +cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_bonding = +TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, + bonding, "bonding"); +cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_lacp = +TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, + lacp, "lacp"); +cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_dedicated_queues = +TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, + dedicated_queues, "dedicated_queues"); +cmdline_parse_token_num_t cmd_setbonding_lacp_dedicated_queues_port_id = +TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, + port_id, RTE_UINT16); +cmdline_parse_token_string_t cmd_setbonding_lacp_dedicated_queues_mode = +TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_lacp_dedicated_queues_result, + mode, "enable#disable"); + +cmdline_parse_inst_t cmd_set_lacp_dedicated_queues = { + .f = cmd_set_bonding_lacp_dedicated_queues_parsed, + .help_str = "set bonding lacp dedicated_queues " + "enable|disable: " + "Enable/disable dedicated queues for LACP control traffic for port_id", + .data = NULL, + .tokens = { + (void *)&cmd_setbonding_lacp_dedicated_queues_set, + (void *)&cmd_setbonding_lacp_dedicated_queues_bonding, + (void *)&cmd_setbonding_lacp_dedicated_queues_lacp, + (void *)&cmd_setbonding_lacp_dedicated_queues_dedicated_queues, + (void *)&cmd_setbonding_lacp_dedicated_queues_port_id, + (void *)&cmd_setbonding_lacp_dedicated_queues_mode, + NULL + } +}; + +/* *** SET BALANCE XMIT POLICY *** */ +struct cmd_set_bonding_balance_xmit_policy_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t bonding; + cmdline_fixed_string_t balance_xmit_policy; + portid_t port_id; + cmdline_fixed_string_t policy; +}; + +static void cmd_set_bonding_balance_xmit_policy_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_set_bonding_balance_xmit_policy_result *res = parsed_result; + portid_t port_id = res->port_id; + uint8_t policy; + + if (!strcmp(res->policy, "l2")) { + policy = BALANCE_XMIT_POLICY_LAYER2; + } else if (!strcmp(res->policy, "l23")) { + policy = BALANCE_XMIT_POLICY_LAYER23; + } else if (!strcmp(res->policy, "l34")) { + policy = BALANCE_XMIT_POLICY_LAYER34; + } else { + fprintf(stderr, "\t Invalid xmit policy selection"); + return; + } + + /* Set the bonding mode for the relevant port. */ + if (rte_eth_bond_xmit_policy_set(port_id, policy) != 0) { + fprintf(stderr, + "\t Failed to set bonding balance xmit policy for port = %d.\n", + port_id); + } +} + +cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_set = +TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, + set, "set"); +cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_bonding = +TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, + bonding, "bonding"); +cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_balance_xmit_policy = +TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, + balance_xmit_policy, "balance_xmit_policy"); +cmdline_parse_token_num_t cmd_setbonding_balance_xmit_policy_port = +TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, + port_id, RTE_UINT16); +cmdline_parse_token_string_t cmd_setbonding_balance_xmit_policy_policy = +TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, + policy, "l2#l23#l34"); + +cmdline_parse_inst_t cmd_set_balance_xmit_policy = { + .f = cmd_set_bonding_balance_xmit_policy_parsed, + .help_str = "set bonding balance_xmit_policy " + "l2|l23|l34: " + "Set the bonding balance_xmit_policy for port_id", + .data = NULL, + .tokens = { + (void *)&cmd_setbonding_balance_xmit_policy_set, + (void *)&cmd_setbonding_balance_xmit_policy_bonding, + (void *)&cmd_setbonding_balance_xmit_policy_balance_xmit_policy, + (void *)&cmd_setbonding_balance_xmit_policy_port, + (void *)&cmd_setbonding_balance_xmit_policy_policy, + NULL + } +}; + +/* *** SHOW IEEE802.3 BONDING INFORMATION *** */ +struct cmd_show_bonding_lacp_info_result { + cmdline_fixed_string_t show; + cmdline_fixed_string_t bonding; + cmdline_fixed_string_t lacp; + cmdline_fixed_string_t info; + portid_t port_id; +}; + +static void port_param_show(struct port_params *params) +{ + char buf[RTE_ETHER_ADDR_FMT_SIZE]; + + printf("\t\tsystem priority: %u\n", params->system_priority); + rte_ether_format_addr(buf, RTE_ETHER_ADDR_FMT_SIZE, ¶ms->system); + printf("\t\tsystem mac address: %s\n", buf); + printf("\t\tport key: %u\n", params->key); + printf("\t\tport priority: %u\n", params->port_priority); + printf("\t\tport number: %u\n", params->port_number); +} + +static void lacp_slave_info_show(struct rte_eth_bond_8023ad_slave_info *info) +{ + char a_state[256] = { 0 }; + char p_state[256] = { 0 }; + int a_len = 0; + int p_len = 0; + uint32_t i; + + static const char * const state[] = { + "ACTIVE", + "TIMEOUT", + "AGGREGATION", + "SYNCHRONIZATION", + "COLLECTING", + "DISTRIBUTING", + "DEFAULTED", + "EXPIRED" + }; + static const char * const selection[] = { + "UNSELECTED", + "STANDBY", + "SELECTED" + }; + + for (i = 0; i < RTE_DIM(state); i++) { + if ((info->actor_state >> i) & 1) + a_len += snprintf(&a_state[a_len], + RTE_DIM(a_state) - a_len, "%s ", + state[i]); + + if ((info->partner_state >> i) & 1) + p_len += snprintf(&p_state[p_len], + RTE_DIM(p_state) - p_len, "%s ", + state[i]); + } + printf("\tAggregator port id: %u\n", info->agg_port_id); + printf("\tselection: %s\n", selection[info->selected]); + printf("\tActor detail info:\n"); + port_param_show(&info->actor); + printf("\t\tport state: %s\n", a_state); + printf("\tPartner detail info:\n"); + port_param_show(&info->partner); + printf("\t\tport state: %s\n", p_state); + printf("\n"); +} + +static void lacp_conf_show(struct rte_eth_bond_8023ad_conf *conf) +{ + printf("\tfast period: %u ms\n", conf->fast_periodic_ms); + printf("\tslow period: %u ms\n", conf->slow_periodic_ms); + printf("\tshort timeout: %u ms\n", conf->short_timeout_ms); + printf("\tlong timeout: %u ms\n", conf->long_timeout_ms); + printf("\taggregate wait timeout: %u ms\n", + conf->aggregate_wait_timeout_ms); + printf("\ttx period: %u ms\n", conf->tx_period_ms); + printf("\trx marker period: %u ms\n", conf->rx_marker_period_ms); + printf("\tupdate timeout: %u ms\n", conf->update_timeout_ms); + switch (conf->agg_selection) { + case AGG_BANDWIDTH: + printf("\taggregation mode: bandwidth\n"); + break; + case AGG_STABLE: + printf("\taggregation mode: stable\n"); + break; + case AGG_COUNT: + printf("\taggregation mode: count\n"); + break; + default: + printf("\taggregation mode: invalid\n"); + break; + } + + printf("\n"); +} + +static void cmd_show_bonding_lacp_info_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_show_bonding_lacp_info_result *res = parsed_result; + struct rte_eth_bond_8023ad_slave_info slave_info; + struct rte_eth_bond_8023ad_conf port_conf; + portid_t slaves[RTE_MAX_ETHPORTS]; + portid_t port_id = res->port_id; + int num_active_slaves; + int bonding_mode; + int i; + int ret; + + bonding_mode = rte_eth_bond_mode_get(port_id); + if (bonding_mode != BONDING_MODE_8023AD) { + fprintf(stderr, "\tBonding mode is not mode 4\n"); + return; + } + + num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves, + RTE_MAX_ETHPORTS); + if (num_active_slaves < 0) { + fprintf(stderr, "\tFailed to get active slave list for port = %u\n", + port_id); + return; + } + if (num_active_slaves == 0) + fprintf(stderr, "\tIEEE802.3 port %u has no active slave\n", + port_id); + + printf("\tIEEE802.3 port: %u\n", port_id); + ret = rte_eth_bond_8023ad_conf_get(port_id, &port_conf); + if (ret) { + fprintf(stderr, "\tGet bonded device %u info failed\n", + port_id); + return; + } + lacp_conf_show(&port_conf); + + for (i = 0; i < num_active_slaves; i++) { + ret = rte_eth_bond_8023ad_slave_info(port_id, slaves[i], + &slave_info); + if (ret) { + fprintf(stderr, "\tGet slave device %u info failed\n", + slaves[i]); + return; + } + printf("\tSlave Port: %u\n", slaves[i]); + lacp_slave_info_show(&slave_info); + } +} + +cmdline_parse_token_string_t cmd_show_bonding_lacp_info_show = +TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result, + show, "show"); +cmdline_parse_token_string_t cmd_show_bonding_lacp_info_bonding = +TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result, + bonding, "bonding"); +cmdline_parse_token_string_t cmd_show_bonding_lacp_info_lacp = +TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result, + bonding, "lacp"); +cmdline_parse_token_string_t cmd_show_bonding_lacp_info_info = +TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_lacp_info_result, + info, "info"); +cmdline_parse_token_num_t cmd_show_bonding_lacp_info_port_id = +TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_lacp_info_result, + port_id, RTE_UINT16); + +cmdline_parse_inst_t cmd_show_bonding_lacp_info = { + .f = cmd_show_bonding_lacp_info_parsed, + .help_str = "show bonding lacp info : " + "Show bonding IEEE802.3 information for port_id", + .data = NULL, + .tokens = { + (void *)&cmd_show_bonding_lacp_info_show, + (void *)&cmd_show_bonding_lacp_info_bonding, + (void *)&cmd_show_bonding_lacp_info_lacp, + (void *)&cmd_show_bonding_lacp_info_info, + (void *)&cmd_show_bonding_lacp_info_port_id, + NULL + } +}; + +/* *** SHOW NIC BONDING CONFIGURATION *** */ +struct cmd_show_bonding_config_result { + cmdline_fixed_string_t show; + cmdline_fixed_string_t bonding; + cmdline_fixed_string_t config; + portid_t port_id; +}; + +static void cmd_show_bonding_config_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_show_bonding_config_result *res = parsed_result; + int bonding_mode, agg_mode; + portid_t slaves[RTE_MAX_ETHPORTS]; + int num_slaves, num_active_slaves; + int primary_id; + int i; + portid_t port_id = res->port_id; + + /* Display the bonding mode.*/ + bonding_mode = rte_eth_bond_mode_get(port_id); + if (bonding_mode < 0) { + fprintf(stderr, "\tFailed to get bonding mode for port = %d\n", + port_id); + return; + } + printf("\tBonding mode: %d\n", bonding_mode); + + if (bonding_mode == BONDING_MODE_BALANCE || + bonding_mode == BONDING_MODE_8023AD) { + int balance_xmit_policy; + + balance_xmit_policy = rte_eth_bond_xmit_policy_get(port_id); + if (balance_xmit_policy < 0) { + fprintf(stderr, + "\tFailed to get balance xmit policy for port = %d\n", + port_id); + return; + } + printf("\tBalance Xmit Policy: "); + + switch (balance_xmit_policy) { + case BALANCE_XMIT_POLICY_LAYER2: + printf("BALANCE_XMIT_POLICY_LAYER2"); + break; + case BALANCE_XMIT_POLICY_LAYER23: + printf("BALANCE_XMIT_POLICY_LAYER23"); + break; + case BALANCE_XMIT_POLICY_LAYER34: + printf("BALANCE_XMIT_POLICY_LAYER34"); + break; + } + printf("\n"); + } + + if (bonding_mode == BONDING_MODE_8023AD) { + agg_mode = rte_eth_bond_8023ad_agg_selection_get(port_id); + printf("\tIEEE802.3AD Aggregator Mode: "); + switch (agg_mode) { + case AGG_BANDWIDTH: + printf("bandwidth"); + break; + case AGG_STABLE: + printf("stable"); + break; + case AGG_COUNT: + printf("count"); + break; + } + printf("\n"); + } + + num_slaves = rte_eth_bond_slaves_get(port_id, slaves, RTE_MAX_ETHPORTS); + + if (num_slaves < 0) { + fprintf(stderr, "\tFailed to get slave list for port = %d\n", + port_id); + return; + } + if (num_slaves > 0) { + printf("\tSlaves (%d): [", num_slaves); + for (i = 0; i < num_slaves - 1; i++) + printf("%d ", slaves[i]); + + printf("%d]\n", slaves[num_slaves - 1]); + } else { + printf("\tSlaves: []\n"); + } + + num_active_slaves = rte_eth_bond_active_slaves_get(port_id, slaves, + RTE_MAX_ETHPORTS); + + if (num_active_slaves < 0) { + fprintf(stderr, + "\tFailed to get active slave list for port = %d\n", + port_id); + return; + } + if (num_active_slaves > 0) { + printf("\tActive Slaves (%d): [", num_active_slaves); + for (i = 0; i < num_active_slaves - 1; i++) + printf("%d ", slaves[i]); + + printf("%d]\n", slaves[num_active_slaves - 1]); + + } else { + printf("\tActive Slaves: []\n"); + } + + primary_id = rte_eth_bond_primary_get(port_id); + if (primary_id < 0) { + fprintf(stderr, "\tFailed to get primary slave for port = %d\n", + port_id); + return; + } + printf("\tPrimary: [%d]\n", primary_id); +} + +cmdline_parse_token_string_t cmd_showbonding_config_show = +TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, + show, "show"); +cmdline_parse_token_string_t cmd_showbonding_config_bonding = +TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, + bonding, "bonding"); +cmdline_parse_token_string_t cmd_showbonding_config_config = +TOKEN_STRING_INITIALIZER(struct cmd_show_bonding_config_result, + config, "config"); +cmdline_parse_token_num_t cmd_showbonding_config_port = +TOKEN_NUM_INITIALIZER(struct cmd_show_bonding_config_result, + port_id, RTE_UINT16); + +cmdline_parse_inst_t cmd_show_bonding_config = { + .f = cmd_show_bonding_config_parsed, + .help_str = "show bonding config : " + "Show the bonding config for port_id", + .data = NULL, + .tokens = { + (void *)&cmd_showbonding_config_show, + (void *)&cmd_showbonding_config_bonding, + (void *)&cmd_showbonding_config_config, + (void *)&cmd_showbonding_config_port, + NULL + } +}; + +/* *** SET BONDING PRIMARY *** */ +struct cmd_set_bonding_primary_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t bonding; + cmdline_fixed_string_t primary; + portid_t slave_id; + portid_t port_id; +}; + +static void cmd_set_bonding_primary_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_set_bonding_primary_result *res = parsed_result; + portid_t master_port_id = res->port_id; + portid_t slave_port_id = res->slave_id; + + /* Set the primary slave for a bonded device. */ + if (rte_eth_bond_primary_set(master_port_id, slave_port_id) != 0) { + fprintf(stderr, "\t Failed to set primary slave for port = %d.\n", + master_port_id); + return; + } + init_port_config(); +} + +cmdline_parse_token_string_t cmd_setbonding_primary_set = +TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, + set, "set"); +cmdline_parse_token_string_t cmd_setbonding_primary_bonding = +TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, + bonding, "bonding"); +cmdline_parse_token_string_t cmd_setbonding_primary_primary = +TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_primary_result, + primary, "primary"); +cmdline_parse_token_num_t cmd_setbonding_primary_slave = +TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result, + slave_id, RTE_UINT16); +cmdline_parse_token_num_t cmd_setbonding_primary_port = +TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_primary_result, + port_id, RTE_UINT16); + +cmdline_parse_inst_t cmd_set_bonding_primary = { + .f = cmd_set_bonding_primary_parsed, + .help_str = "set bonding primary : " + "Set the primary slave for port_id", + .data = NULL, + .tokens = { + (void *)&cmd_setbonding_primary_set, + (void *)&cmd_setbonding_primary_bonding, + (void *)&cmd_setbonding_primary_primary, + (void *)&cmd_setbonding_primary_slave, + (void *)&cmd_setbonding_primary_port, + NULL + } +}; + +/* *** ADD SLAVE *** */ +struct cmd_add_bonding_slave_result { + cmdline_fixed_string_t add; + cmdline_fixed_string_t bonding; + cmdline_fixed_string_t slave; + portid_t slave_id; + portid_t port_id; +}; + +static void cmd_add_bonding_slave_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_add_bonding_slave_result *res = parsed_result; + portid_t master_port_id = res->port_id; + portid_t slave_port_id = res->slave_id; + + /* add the slave for a bonded device. */ + if (rte_eth_bond_slave_add(master_port_id, slave_port_id) != 0) { + fprintf(stderr, + "\t Failed to add slave %d to master port = %d.\n", + slave_port_id, master_port_id); + return; + } + init_port_config(); + set_port_slave_flag(slave_port_id); +} + +cmdline_parse_token_string_t cmd_addbonding_slave_add = +TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, + add, "add"); +cmdline_parse_token_string_t cmd_addbonding_slave_bonding = +TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, + bonding, "bonding"); +cmdline_parse_token_string_t cmd_addbonding_slave_slave = +TOKEN_STRING_INITIALIZER(struct cmd_add_bonding_slave_result, + slave, "slave"); +cmdline_parse_token_num_t cmd_addbonding_slave_slaveid = +TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result, + slave_id, RTE_UINT16); +cmdline_parse_token_num_t cmd_addbonding_slave_port = +TOKEN_NUM_INITIALIZER(struct cmd_add_bonding_slave_result, + port_id, RTE_UINT16); + +cmdline_parse_inst_t cmd_add_bonding_slave = { + .f = cmd_add_bonding_slave_parsed, + .help_str = "add bonding slave : " + "Add a slave device to a bonded device", + .data = NULL, + .tokens = { + (void *)&cmd_addbonding_slave_add, + (void *)&cmd_addbonding_slave_bonding, + (void *)&cmd_addbonding_slave_slave, + (void *)&cmd_addbonding_slave_slaveid, + (void *)&cmd_addbonding_slave_port, + NULL + } +}; + +/* *** REMOVE SLAVE *** */ +struct cmd_remove_bonding_slave_result { + cmdline_fixed_string_t remove; + cmdline_fixed_string_t bonding; + cmdline_fixed_string_t slave; + portid_t slave_id; + portid_t port_id; +}; + +static void cmd_remove_bonding_slave_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_remove_bonding_slave_result *res = parsed_result; + portid_t master_port_id = res->port_id; + portid_t slave_port_id = res->slave_id; + + /* remove the slave from a bonded device. */ + if (rte_eth_bond_slave_remove(master_port_id, slave_port_id) != 0) { + fprintf(stderr, + "\t Failed to remove slave %d from master port = %d.\n", + slave_port_id, master_port_id); + return; + } + init_port_config(); + clear_port_slave_flag(slave_port_id); +} + +cmdline_parse_token_string_t cmd_removebonding_slave_remove = + TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, + remove, "remove"); +cmdline_parse_token_string_t cmd_removebonding_slave_bonding = + TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, + bonding, "bonding"); +cmdline_parse_token_string_t cmd_removebonding_slave_slave = + TOKEN_STRING_INITIALIZER(struct cmd_remove_bonding_slave_result, + slave, "slave"); +cmdline_parse_token_num_t cmd_removebonding_slave_slaveid = + TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result, + slave_id, RTE_UINT16); +cmdline_parse_token_num_t cmd_removebonding_slave_port = + TOKEN_NUM_INITIALIZER(struct cmd_remove_bonding_slave_result, + port_id, RTE_UINT16); + +cmdline_parse_inst_t cmd_remove_bonding_slave = { + .f = cmd_remove_bonding_slave_parsed, + .help_str = "remove bonding slave : " + "Remove a slave device from a bonded device", + .data = NULL, + .tokens = { + (void *)&cmd_removebonding_slave_remove, + (void *)&cmd_removebonding_slave_bonding, + (void *)&cmd_removebonding_slave_slave, + (void *)&cmd_removebonding_slave_slaveid, + (void *)&cmd_removebonding_slave_port, + NULL + } +}; + +/* *** CREATE BONDED DEVICE *** */ +struct cmd_create_bonded_device_result { + cmdline_fixed_string_t create; + cmdline_fixed_string_t bonded; + cmdline_fixed_string_t device; + uint8_t mode; + uint8_t socket; +}; + +static int bond_dev_num; + +static void cmd_create_bonded_device_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_create_bonded_device_result *res = parsed_result; + char ethdev_name[RTE_ETH_NAME_MAX_LEN]; + int port_id; + int ret; + + if (test_done == 0) { + fprintf(stderr, "Please stop forwarding first\n"); + return; + } + + snprintf(ethdev_name, RTE_ETH_NAME_MAX_LEN, "net_bonding_testpmd_%d", + bond_dev_num++); + + /* Create a new bonded device. */ + port_id = rte_eth_bond_create(ethdev_name, res->mode, res->socket); + if (port_id < 0) { + fprintf(stderr, "\t Failed to create bonded device.\n"); + return; + } + printf("Created new bonded device %s on (port %d).\n", ethdev_name, + port_id); + + /* Update number of ports */ + nb_ports = rte_eth_dev_count_avail(); + reconfig(port_id, res->socket); + ret = rte_eth_promiscuous_enable(port_id); + if (ret != 0) + fprintf(stderr, "Failed to enable promiscuous mode for port %u: %s - ignore\n", + port_id, rte_strerror(-ret)); + + ports[port_id].need_setup = 0; + ports[port_id].port_status = RTE_PORT_STOPPED; +} + +cmdline_parse_token_string_t cmd_createbonded_device_create = + TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, + create, "create"); +cmdline_parse_token_string_t cmd_createbonded_device_bonded = + TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, + bonded, "bonded"); +cmdline_parse_token_string_t cmd_createbonded_device_device = + TOKEN_STRING_INITIALIZER(struct cmd_create_bonded_device_result, + device, "device"); +cmdline_parse_token_num_t cmd_createbonded_device_mode = + TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result, + mode, RTE_UINT8); +cmdline_parse_token_num_t cmd_createbonded_device_socket = + TOKEN_NUM_INITIALIZER(struct cmd_create_bonded_device_result, + socket, RTE_UINT8); + +cmdline_parse_inst_t cmd_create_bonded_device = { + .f = cmd_create_bonded_device_parsed, + .help_str = "create bonded device : " + "Create a new bonded device with specific bonding mode and socket", + .data = NULL, + .tokens = { + (void *)&cmd_createbonded_device_create, + (void *)&cmd_createbonded_device_bonded, + (void *)&cmd_createbonded_device_device, + (void *)&cmd_createbonded_device_mode, + (void *)&cmd_createbonded_device_socket, + NULL + } +}; + +/* *** SET MAC ADDRESS IN BONDED DEVICE *** */ +struct cmd_set_bond_mac_addr_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t bonding; + cmdline_fixed_string_t mac_addr; + uint16_t port_num; + struct rte_ether_addr address; +}; + +static void cmd_set_bond_mac_addr_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_set_bond_mac_addr_result *res = parsed_result; + int ret; + + if (port_id_is_invalid(res->port_num, ENABLED_WARN)) + return; + + ret = rte_eth_bond_mac_address_set(res->port_num, &res->address); + + /* check the return value and print it if is < 0 */ + if (ret < 0) + fprintf(stderr, "set_bond_mac_addr error: (%s)\n", + strerror(-ret)); +} + +cmdline_parse_token_string_t cmd_set_bond_mac_addr_set = + TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, set, "set"); +cmdline_parse_token_string_t cmd_set_bond_mac_addr_bonding = + TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, bonding, + "bonding"); +cmdline_parse_token_string_t cmd_set_bond_mac_addr_mac = + TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mac_addr_result, mac_addr, + "mac_addr"); +cmdline_parse_token_num_t cmd_set_bond_mac_addr_portnum = + TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mac_addr_result, + port_num, RTE_UINT16); +cmdline_parse_token_etheraddr_t cmd_set_bond_mac_addr_addr = + TOKEN_ETHERADDR_INITIALIZER(struct cmd_set_bond_mac_addr_result, address); + +cmdline_parse_inst_t cmd_set_bond_mac_addr = { + .f = cmd_set_bond_mac_addr_parsed, + .data = NULL, + .help_str = "set bonding mac_addr ", + .tokens = { + (void *)&cmd_set_bond_mac_addr_set, + (void *)&cmd_set_bond_mac_addr_bonding, + (void *)&cmd_set_bond_mac_addr_mac, + (void *)&cmd_set_bond_mac_addr_portnum, + (void *)&cmd_set_bond_mac_addr_addr, + NULL + } +}; + +/* *** SET LINK STATUS MONITORING POLLING PERIOD ON BONDED DEVICE *** */ +struct cmd_set_bond_mon_period_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t bonding; + cmdline_fixed_string_t mon_period; + uint16_t port_num; + uint32_t period_ms; +}; + +static void cmd_set_bond_mon_period_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_set_bond_mon_period_result *res = parsed_result; + int ret; + + ret = rte_eth_bond_link_monitoring_set(res->port_num, res->period_ms); + + /* check the return value and print it if is < 0 */ + if (ret < 0) + fprintf(stderr, "set_bond_mac_addr error: (%s)\n", + strerror(-ret)); +} + +cmdline_parse_token_string_t cmd_set_bond_mon_period_set = + TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, + set, "set"); +cmdline_parse_token_string_t cmd_set_bond_mon_period_bonding = + TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, + bonding, "bonding"); +cmdline_parse_token_string_t cmd_set_bond_mon_period_mon_period = + TOKEN_STRING_INITIALIZER(struct cmd_set_bond_mon_period_result, + mon_period, "mon_period"); +cmdline_parse_token_num_t cmd_set_bond_mon_period_portnum = + TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result, + port_num, RTE_UINT16); +cmdline_parse_token_num_t cmd_set_bond_mon_period_period_ms = + TOKEN_NUM_INITIALIZER(struct cmd_set_bond_mon_period_result, + period_ms, RTE_UINT32); + +cmdline_parse_inst_t cmd_set_bond_mon_period = { + .f = cmd_set_bond_mon_period_parsed, + .data = NULL, + .help_str = "set bonding mon_period ", + .tokens = { + (void *)&cmd_set_bond_mon_period_set, + (void *)&cmd_set_bond_mon_period_bonding, + (void *)&cmd_set_bond_mon_period_mon_period, + (void *)&cmd_set_bond_mon_period_portnum, + (void *)&cmd_set_bond_mon_period_period_ms, + NULL + } +}; + +struct cmd_set_bonding_agg_mode_policy_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t bonding; + cmdline_fixed_string_t agg_mode; + uint16_t port_num; + cmdline_fixed_string_t policy; +}; + +static void +cmd_set_bonding_agg_mode(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_set_bonding_agg_mode_policy_result *res = parsed_result; + uint8_t policy = AGG_BANDWIDTH; + + if (!strcmp(res->policy, "bandwidth")) + policy = AGG_BANDWIDTH; + else if (!strcmp(res->policy, "stable")) + policy = AGG_STABLE; + else if (!strcmp(res->policy, "count")) + policy = AGG_COUNT; + + rte_eth_bond_8023ad_agg_selection_set(res->port_num, policy); +} + +cmdline_parse_token_string_t cmd_set_bonding_agg_mode_set = + TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, + set, "set"); +cmdline_parse_token_string_t cmd_set_bonding_agg_mode_bonding = + TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, + bonding, "bonding"); + +cmdline_parse_token_string_t cmd_set_bonding_agg_mode_agg_mode = + TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, + agg_mode, "agg_mode"); + +cmdline_parse_token_num_t cmd_set_bonding_agg_mode_portnum = + TOKEN_NUM_INITIALIZER(struct cmd_set_bonding_agg_mode_policy_result, + port_num, RTE_UINT16); + +cmdline_parse_token_string_t cmd_set_bonding_agg_mode_policy_string = + TOKEN_STRING_INITIALIZER(struct cmd_set_bonding_balance_xmit_policy_result, + policy, "stable#bandwidth#count"); + +cmdline_parse_inst_t cmd_set_bonding_agg_mode_policy = { + .f = cmd_set_bonding_agg_mode, + .data = NULL, + .help_str = "set bonding mode IEEE802.3AD aggregator policy ", + .tokens = { + (void *)&cmd_set_bonding_agg_mode_set, + (void *)&cmd_set_bonding_agg_mode_bonding, + (void *)&cmd_set_bonding_agg_mode_agg_mode, + (void *)&cmd_set_bonding_agg_mode_portnum, + (void *)&cmd_set_bonding_agg_mode_policy_string, + NULL + } +}; + +static struct testpmd_cmdline_parser driver_parser = { + .ctx = (cmdline_parse_ctx_t[]) { + (cmdline_parse_inst_t *)&cmd_set_bonding_mode, + (cmdline_parse_inst_t *)&cmd_show_bonding_config, + (cmdline_parse_inst_t *)&cmd_show_bonding_lacp_info, + (cmdline_parse_inst_t *)&cmd_set_bonding_primary, + (cmdline_parse_inst_t *)&cmd_add_bonding_slave, + (cmdline_parse_inst_t *)&cmd_remove_bonding_slave, + (cmdline_parse_inst_t *)&cmd_create_bonded_device, + (cmdline_parse_inst_t *)&cmd_set_bond_mac_addr, + (cmdline_parse_inst_t *)&cmd_set_balance_xmit_policy, + (cmdline_parse_inst_t *)&cmd_set_bond_mon_period, + (cmdline_parse_inst_t *)&cmd_set_lacp_dedicated_queues, + (cmdline_parse_inst_t *)&cmd_set_bonding_agg_mode_policy, + NULL + }, + .help = { + "set bonding mode (value) (port_id)\n" + " Set the bonding mode on a bonded device.\n", + + "show bonding config (port_id)\n" + " Show the bonding config for port_id.\n", + + "show bonding lacp info (port_id)\n" + " Show the bonding lacp information for port_id.\n", + + "set bonding primary (slave_id) (port_id)\n" + " Set the primary slave for a bonded device.\n", + + "add bonding slave (slave_id) (port_id)\n" + " Add a slave device to a bonded device.\n", + + "remove bonding slave (slave_id) (port_id)\n" + " Remove a slave device from a bonded device.\n", + + "create bonded device (mode) (socket)\n" + " Create a new bonded device with specific bonding mode and socket.\n", + + "set bonding mac_addr (port_id) (address)\n" + " Set the MAC address of a bonded device.\n", + + "set bonding balance_xmit_policy (port_id) (l2|l23|l34)\n" + " Set the transmit balance policy for bonded device running in balance mode.\n", + + "set bonding mon_period (port_id) (value)\n" + " Set the bonding link status monitoring polling period in ms.\n", + + "set bonding lacp dedicated_queues (enable|disable)\n" + " Enable/disable dedicated queues for LACP control traffic.\n", + + "set bonding mode IEEE802.3AD aggregator policy (port_id) (agg_name)\n" + " Set Aggregation mode for IEEE802.3AD (mode 4)\n", + + NULL + }, +}; + +RTE_INIT(bonding_testpmd) +{ + testpmd_add_commands(&driver_parser); +} From patchwork Fri May 13 07:57:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 111121 X-Patchwork-Delegate: andrew.rybchenko@oktetlabs.ru Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 2B78EA00C3; Fri, 13 May 2022 09:57:41 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 1CFB2427F1; Fri, 13 May 2022 09:57:41 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 56C0D40DDE for ; Fri, 13 May 2022 09:57:39 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652428658; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=C1FXXZmuHTq+JOcb/pshooBQKeID1uv3KdGCsIKrZwg=; b=KlgljyU2/QjTwoEjBwMiHbTTTPKFVBAp5E662sbQA//XAZp6wRsDbRv7JwsngDlGRja1yz XtKAm9/nytzEihPSCqzBtwMPsR5N7r1x25rMyGmJl4mmnIpnP1mQhBQeo6Vbma4mClb4i6 EFIYDwry2m0BFrRCzKc1ObFhkW7eu0U= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-581-EtKFw5ohO8mop5AsGgJFfQ-1; Fri, 13 May 2022 03:57:35 -0400 X-MC-Unique: EtKFw5ohO8mop5AsGgJFfQ-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 333B2185A794; Fri, 13 May 2022 07:57:35 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.193.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id BF498416361; Fri, 13 May 2022 07:57:32 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, Xiaoyun Li , Aman Singh , Yuying Zhang , Beilei Xing Subject: [RFC PATCH 3/4] net/i40e: move testpmd commands Date: Fri, 13 May 2022 09:57:17 +0200 Message-Id: <20220513075718.18674-4-david.marchand@redhat.com> In-Reply-To: <20220513075718.18674-1-david.marchand@redhat.com> References: <20220513075718.18674-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Move related specific testpmd commands into this driver directory. Signed-off-by: David Marchand --- app/test-pmd/cmdline.c | 665 -------------------------------- drivers/net/i40e/i40e_testpmd.c | 655 +++++++++++++++++++++++++++++++ drivers/net/i40e/meson.build | 2 + 3 files changed, 657 insertions(+), 665 deletions(-) create mode 100644 drivers/net/i40e/i40e_testpmd.c diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index ae4759fbfe..fee05c1a0c 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -637,21 +637,6 @@ static void cmd_help_long_parsed(void *parsed_result, "set port (port_id) ptype_mask (ptype_mask)\n" " set packet types classification for a specific port\n\n" - "set port (port_id) queue-region region_id (value) " - "queue_start_index (value) queue_num (value)\n" - " Set a queue region on a port\n\n" - - "set port (port_id) queue-region region_id (value) " - "flowtype (value)\n" - " Set a flowtype region index on a port\n\n" - - "set port (port_id) queue-region UP (value) region_id (value)\n" - " Set the mapping of User Priority to " - "queue region on a port\n\n" - - "set port (port_id) queue-region flush (on|off)\n" - " flush all queue region related configuration\n\n" - "show port meter cap (port_id)\n" " Show port meter capability information\n\n" @@ -702,9 +687,6 @@ static void cmd_help_long_parsed(void *parsed_result, "set port meter stats mask (port_id) (mtr_id) (stats_mask)\n" " meter update stats\n\n" - "show port (port_id) queue-region\n" - " show all queue region related configuration info\n\n" - "set port (port_id) fec_mode auto|off|rs|baser\n" " set fec mode for a specific port\n\n" @@ -912,13 +894,6 @@ static void cmd_help_long_parsed(void *parsed_result, "filters:\n" "--------\n\n" -#ifdef RTE_NET_I40E - "flow_director_filter (port_id) mode raw (add|del|update)" - " flow (flow_id) (drop|fwd) queue (queue_id)" - " fd_id (fd_id_value) packet (packet file name)\n" - " Add/Del a raw type flow director filter.\n\n" -#endif - "flow_director_mask (port_id) mode IP vlan (vlan_value)" " src_mask (ipv4_src) (ipv6_src) (src_port)" " dst_mask (ipv4_dst) (ipv6_dst) (dst_port)\n" @@ -9094,450 +9069,6 @@ cmdline_parse_inst_t cmd_dump_one = { }, }; -/* *** queue region set *** */ -struct cmd_queue_region_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t port; - portid_t port_id; - cmdline_fixed_string_t cmd; - cmdline_fixed_string_t region; - uint8_t region_id; - cmdline_fixed_string_t queue_start_index; - uint8_t queue_id; - cmdline_fixed_string_t queue_num; - uint8_t queue_num_value; -}; - -static void -cmd_queue_region_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_queue_region_result *res = parsed_result; - int ret = -ENOTSUP; -#ifdef RTE_NET_I40E - struct rte_pmd_i40e_queue_region_conf region_conf; - enum rte_pmd_i40e_queue_region_op op_type; -#endif - - if (port_id_is_invalid(res->port_id, ENABLED_WARN)) - return; - -#ifdef RTE_NET_I40E - memset(®ion_conf, 0, sizeof(region_conf)); - op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET; - region_conf.region_id = res->region_id; - region_conf.queue_num = res->queue_num_value; - region_conf.queue_start_index = res->queue_id; - - ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, - op_type, ®ion_conf); -#endif - - switch (ret) { - case 0: - break; - case -ENOTSUP: - fprintf(stderr, "function not implemented or supported\n"); - break; - default: - fprintf(stderr, "queue region config error: (%s)\n", - strerror(-ret)); - } -} - -cmdline_parse_token_string_t cmd_queue_region_set = -TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, - set, "set"); -cmdline_parse_token_string_t cmd_queue_region_port = - TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port"); -cmdline_parse_token_num_t cmd_queue_region_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, - port_id, RTE_UINT16); -cmdline_parse_token_string_t cmd_queue_region_cmd = - TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, - cmd, "queue-region"); -cmdline_parse_token_string_t cmd_queue_region_id = - TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, - region, "region_id"); -cmdline_parse_token_num_t cmd_queue_region_index = - TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, - region_id, RTE_UINT8); -cmdline_parse_token_string_t cmd_queue_region_queue_start_index = - TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, - queue_start_index, "queue_start_index"); -cmdline_parse_token_num_t cmd_queue_region_queue_id = - TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, - queue_id, RTE_UINT8); -cmdline_parse_token_string_t cmd_queue_region_queue_num = - TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, - queue_num, "queue_num"); -cmdline_parse_token_num_t cmd_queue_region_queue_num_value = - TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, - queue_num_value, RTE_UINT8); - -cmdline_parse_inst_t cmd_queue_region = { - .f = cmd_queue_region_parsed, - .data = NULL, - .help_str = "set port queue-region region_id " - "queue_start_index queue_num : Set a queue region", - .tokens = { - (void *)&cmd_queue_region_set, - (void *)&cmd_queue_region_port, - (void *)&cmd_queue_region_port_id, - (void *)&cmd_queue_region_cmd, - (void *)&cmd_queue_region_id, - (void *)&cmd_queue_region_index, - (void *)&cmd_queue_region_queue_start_index, - (void *)&cmd_queue_region_queue_id, - (void *)&cmd_queue_region_queue_num, - (void *)&cmd_queue_region_queue_num_value, - NULL, - }, -}; - -/* *** queue region and flowtype set *** */ -struct cmd_region_flowtype_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t port; - portid_t port_id; - cmdline_fixed_string_t cmd; - cmdline_fixed_string_t region; - uint8_t region_id; - cmdline_fixed_string_t flowtype; - uint8_t flowtype_id; -}; - -static void -cmd_region_flowtype_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_region_flowtype_result *res = parsed_result; - int ret = -ENOTSUP; -#ifdef RTE_NET_I40E - struct rte_pmd_i40e_queue_region_conf region_conf; - enum rte_pmd_i40e_queue_region_op op_type; -#endif - - if (port_id_is_invalid(res->port_id, ENABLED_WARN)) - return; - -#ifdef RTE_NET_I40E - memset(®ion_conf, 0, sizeof(region_conf)); - - op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET; - region_conf.region_id = res->region_id; - region_conf.hw_flowtype = res->flowtype_id; - - ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, - op_type, ®ion_conf); -#endif - - switch (ret) { - case 0: - break; - case -ENOTSUP: - fprintf(stderr, "function not implemented or supported\n"); - break; - default: - fprintf(stderr, "region flowtype config error: (%s)\n", - strerror(-ret)); - } -} - -cmdline_parse_token_string_t cmd_region_flowtype_set = -TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, - set, "set"); -cmdline_parse_token_string_t cmd_region_flowtype_port = - TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, - port, "port"); -cmdline_parse_token_num_t cmd_region_flowtype_port_index = - TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result, - port_id, RTE_UINT16); -cmdline_parse_token_string_t cmd_region_flowtype_cmd = - TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, - cmd, "queue-region"); -cmdline_parse_token_string_t cmd_region_flowtype_index = - TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, - region, "region_id"); -cmdline_parse_token_num_t cmd_region_flowtype_id = - TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result, - region_id, RTE_UINT8); -cmdline_parse_token_string_t cmd_region_flowtype_flow_index = - TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, - flowtype, "flowtype"); -cmdline_parse_token_num_t cmd_region_flowtype_flow_id = - TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result, - flowtype_id, RTE_UINT8); -cmdline_parse_inst_t cmd_region_flowtype = { - .f = cmd_region_flowtype_parsed, - .data = NULL, - .help_str = "set port queue-region region_id " - "flowtype : Set a flowtype region index", - .tokens = { - (void *)&cmd_region_flowtype_set, - (void *)&cmd_region_flowtype_port, - (void *)&cmd_region_flowtype_port_index, - (void *)&cmd_region_flowtype_cmd, - (void *)&cmd_region_flowtype_index, - (void *)&cmd_region_flowtype_id, - (void *)&cmd_region_flowtype_flow_index, - (void *)&cmd_region_flowtype_flow_id, - NULL, - }, -}; - -/* *** User Priority (UP) to queue region (region_id) set *** */ -struct cmd_user_priority_region_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t port; - portid_t port_id; - cmdline_fixed_string_t cmd; - cmdline_fixed_string_t user_priority; - uint8_t user_priority_id; - cmdline_fixed_string_t region; - uint8_t region_id; -}; - -static void -cmd_user_priority_region_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_user_priority_region_result *res = parsed_result; - int ret = -ENOTSUP; -#ifdef RTE_NET_I40E - struct rte_pmd_i40e_queue_region_conf region_conf; - enum rte_pmd_i40e_queue_region_op op_type; -#endif - - if (port_id_is_invalid(res->port_id, ENABLED_WARN)) - return; - -#ifdef RTE_NET_I40E - memset(®ion_conf, 0, sizeof(region_conf)); - op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET; - region_conf.user_priority = res->user_priority_id; - region_conf.region_id = res->region_id; - - ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, - op_type, ®ion_conf); -#endif - - switch (ret) { - case 0: - break; - case -ENOTSUP: - fprintf(stderr, "function not implemented or supported\n"); - break; - default: - fprintf(stderr, "user_priority region config error: (%s)\n", - strerror(-ret)); - } -} - -cmdline_parse_token_string_t cmd_user_priority_region_set = - TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, - set, "set"); -cmdline_parse_token_string_t cmd_user_priority_region_port = - TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, - port, "port"); -cmdline_parse_token_num_t cmd_user_priority_region_port_index = - TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result, - port_id, RTE_UINT16); -cmdline_parse_token_string_t cmd_user_priority_region_cmd = - TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, - cmd, "queue-region"); -cmdline_parse_token_string_t cmd_user_priority_region_UP = - TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, - user_priority, "UP"); -cmdline_parse_token_num_t cmd_user_priority_region_UP_id = - TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result, - user_priority_id, RTE_UINT8); -cmdline_parse_token_string_t cmd_user_priority_region_region = - TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, - region, "region_id"); -cmdline_parse_token_num_t cmd_user_priority_region_region_id = - TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result, - region_id, RTE_UINT8); - -cmdline_parse_inst_t cmd_user_priority_region = { - .f = cmd_user_priority_region_parsed, - .data = NULL, - .help_str = "set port queue-region UP " - "region_id : Set the mapping of User Priority (UP) " - "to queue region (region_id) ", - .tokens = { - (void *)&cmd_user_priority_region_set, - (void *)&cmd_user_priority_region_port, - (void *)&cmd_user_priority_region_port_index, - (void *)&cmd_user_priority_region_cmd, - (void *)&cmd_user_priority_region_UP, - (void *)&cmd_user_priority_region_UP_id, - (void *)&cmd_user_priority_region_region, - (void *)&cmd_user_priority_region_region_id, - NULL, - }, -}; - -/* *** flush all queue region related configuration *** */ -struct cmd_flush_queue_region_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t port; - portid_t port_id; - cmdline_fixed_string_t cmd; - cmdline_fixed_string_t flush; - cmdline_fixed_string_t what; -}; - -static void -cmd_flush_queue_region_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_flush_queue_region_result *res = parsed_result; - int ret = -ENOTSUP; -#ifdef RTE_NET_I40E - struct rte_pmd_i40e_queue_region_conf region_conf; - enum rte_pmd_i40e_queue_region_op op_type; -#endif - - if (port_id_is_invalid(res->port_id, ENABLED_WARN)) - return; - -#ifdef RTE_NET_I40E - memset(®ion_conf, 0, sizeof(region_conf)); - - if (strcmp(res->what, "on") == 0) - op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON; - else - op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF; - - ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, - op_type, ®ion_conf); -#endif - - switch (ret) { - case 0: - break; - case -ENOTSUP: - fprintf(stderr, "function not implemented or supported\n"); - break; - default: - fprintf(stderr, "queue region config flush error: (%s)\n", - strerror(-ret)); - } -} - -cmdline_parse_token_string_t cmd_flush_queue_region_set = - TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, - set, "set"); -cmdline_parse_token_string_t cmd_flush_queue_region_port = - TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, - port, "port"); -cmdline_parse_token_num_t cmd_flush_queue_region_port_index = - TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result, - port_id, RTE_UINT16); -cmdline_parse_token_string_t cmd_flush_queue_region_cmd = - TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, - cmd, "queue-region"); -cmdline_parse_token_string_t cmd_flush_queue_region_flush = - TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, - flush, "flush"); -cmdline_parse_token_string_t cmd_flush_queue_region_what = - TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, - what, "on#off"); - -cmdline_parse_inst_t cmd_flush_queue_region = { - .f = cmd_flush_queue_region_parsed, - .data = NULL, - .help_str = "set port queue-region flush on|off" - ": flush all queue region related configuration", - .tokens = { - (void *)&cmd_flush_queue_region_set, - (void *)&cmd_flush_queue_region_port, - (void *)&cmd_flush_queue_region_port_index, - (void *)&cmd_flush_queue_region_cmd, - (void *)&cmd_flush_queue_region_flush, - (void *)&cmd_flush_queue_region_what, - NULL, - }, -}; - -/* *** get all queue region related configuration info *** */ -struct cmd_show_queue_region_info { - cmdline_fixed_string_t show; - cmdline_fixed_string_t port; - portid_t port_id; - cmdline_fixed_string_t cmd; -}; - -static void -cmd_show_queue_region_info_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_show_queue_region_info *res = parsed_result; - int ret = -ENOTSUP; -#ifdef RTE_NET_I40E - struct rte_pmd_i40e_queue_regions rte_pmd_regions; - enum rte_pmd_i40e_queue_region_op op_type; -#endif - - if (port_id_is_invalid(res->port_id, ENABLED_WARN)) - return; - -#ifdef RTE_NET_I40E - memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions)); - - op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET; - - ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, - op_type, &rte_pmd_regions); - - port_queue_region_info_display(res->port_id, &rte_pmd_regions); -#endif - - switch (ret) { - case 0: - break; - case -ENOTSUP: - fprintf(stderr, "function not implemented or supported\n"); - break; - default: - fprintf(stderr, "queue region config info show error: (%s)\n", - strerror(-ret)); - } -} - -cmdline_parse_token_string_t cmd_show_queue_region_info_get = -TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info, - show, "show"); -cmdline_parse_token_string_t cmd_show_queue_region_info_port = - TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info, - port, "port"); -cmdline_parse_token_num_t cmd_show_queue_region_info_port_index = - TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info, - port_id, RTE_UINT16); -cmdline_parse_token_string_t cmd_show_queue_region_info_cmd = - TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info, - cmd, "queue-region"); - -cmdline_parse_inst_t cmd_show_queue_region_info_all = { - .f = cmd_show_queue_region_info_parsed, - .data = NULL, - .help_str = "show port queue-region" - ": show all queue region related configuration info", - .tokens = { - (void *)&cmd_show_queue_region_info_get, - (void *)&cmd_show_queue_region_info_port, - (void *)&cmd_show_queue_region_info_port_index, - (void *)&cmd_show_queue_region_info_cmd, - NULL, - }, -}; - /* *** Filters Control *** */ #define IPV4_ADDR_TO_UINT(ip_addr, ip) \ @@ -9562,194 +9093,6 @@ do { \ } \ } while (0) -#ifdef RTE_NET_I40E - -static uint16_t -str2flowtype(char *string) -{ - uint8_t i = 0; - static const struct { - char str[32]; - uint16_t type; - } flowtype_str[] = { - {"raw", RTE_ETH_FLOW_RAW}, - {"ipv4", RTE_ETH_FLOW_IPV4}, - {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4}, - {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP}, - {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP}, - {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP}, - {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER}, - {"ipv6", RTE_ETH_FLOW_IPV6}, - {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6}, - {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP}, - {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP}, - {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP}, - {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER}, - {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD}, - {"ipv6-ex", RTE_ETH_FLOW_IPV6_EX}, - {"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX}, - {"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX}, - {"gtpu", RTE_ETH_FLOW_GTPU}, - }; - - for (i = 0; i < RTE_DIM(flowtype_str); i++) { - if (!strcmp(flowtype_str[i].str, string)) - return flowtype_str[i].type; - } - - if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64) - return (uint16_t)atoi(string); - - return RTE_ETH_FLOW_UNKNOWN; -} - -/* *** deal with flow director filter *** */ -struct cmd_flow_director_result { - cmdline_fixed_string_t flow_director_filter; - portid_t port_id; - cmdline_fixed_string_t mode; - cmdline_fixed_string_t mode_value; - cmdline_fixed_string_t ops; - cmdline_fixed_string_t flow; - cmdline_fixed_string_t flow_type; - cmdline_fixed_string_t drop; - cmdline_fixed_string_t queue; - uint16_t queue_id; - cmdline_fixed_string_t fd_id; - uint32_t fd_id_value; - cmdline_fixed_string_t packet; - char filepath[]; -}; - -static void -cmd_flow_director_filter_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_flow_director_result *res = parsed_result; - int ret = 0; - struct rte_pmd_i40e_flow_type_mapping - mapping[RTE_PMD_I40E_FLOW_TYPE_MAX]; - struct rte_pmd_i40e_pkt_template_conf conf; - uint16_t flow_type = str2flowtype(res->flow_type); - uint16_t i, port = res->port_id; - uint8_t add; - - memset(&conf, 0, sizeof(conf)); - - if (flow_type == RTE_ETH_FLOW_UNKNOWN) { - fprintf(stderr, "Invalid flow type specified.\n"); - return; - } - ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, - mapping); - if (ret) - return; - if (mapping[flow_type].pctype == 0ULL) { - fprintf(stderr, "Invalid flow type specified.\n"); - return; - } - for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) { - if (mapping[flow_type].pctype & (1ULL << i)) { - conf.input.pctype = i; - break; - } - } - - conf.input.packet = open_file(res->filepath, - &conf.input.length); - if (!conf.input.packet) - return; - if (!strcmp(res->drop, "drop")) - conf.action.behavior = - RTE_PMD_I40E_PKT_TEMPLATE_REJECT; - else - conf.action.behavior = - RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT; - conf.action.report_status = - RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID; - conf.action.rx_queue = res->queue_id; - conf.soft_id = res->fd_id_value; - add = strcmp(res->ops, "del") ? 1 : 0; - ret = rte_pmd_i40e_flow_add_del_packet_template(port, - &conf, - add); - if (ret < 0) - fprintf(stderr, "flow director config error: (%s)\n", - strerror(-ret)); - close_file(conf.input.packet); -} - -cmdline_parse_token_string_t cmd_flow_director_filter = - TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, - flow_director_filter, "flow_director_filter"); -cmdline_parse_token_num_t cmd_flow_director_port_id = - TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, - port_id, RTE_UINT16); -cmdline_parse_token_string_t cmd_flow_director_ops = - TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, - ops, "add#del#update"); -cmdline_parse_token_string_t cmd_flow_director_flow = - TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, - flow, "flow"); -cmdline_parse_token_string_t cmd_flow_director_flow_type = - TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, - flow_type, NULL); -cmdline_parse_token_string_t cmd_flow_director_drop = - TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, - drop, "drop#fwd"); -cmdline_parse_token_string_t cmd_flow_director_queue = - TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, - queue, "queue"); -cmdline_parse_token_num_t cmd_flow_director_queue_id = - TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, - queue_id, RTE_UINT16); -cmdline_parse_token_string_t cmd_flow_director_fd_id = - TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, - fd_id, "fd_id"); -cmdline_parse_token_num_t cmd_flow_director_fd_id_value = - TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, - fd_id_value, RTE_UINT32); - -cmdline_parse_token_string_t cmd_flow_director_mode = - TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, - mode, "mode"); -cmdline_parse_token_string_t cmd_flow_director_mode_raw = - TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, - mode_value, "raw"); -cmdline_parse_token_string_t cmd_flow_director_packet = - TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, - packet, "packet"); -cmdline_parse_token_string_t cmd_flow_director_filepath = - TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, - filepath, NULL); - -cmdline_parse_inst_t cmd_add_del_raw_flow_director = { - .f = cmd_flow_director_filter_parsed, - .data = NULL, - .help_str = "flow_director_filter ... : Add or delete a raw flow " - "director entry on NIC", - .tokens = { - (void *)&cmd_flow_director_filter, - (void *)&cmd_flow_director_port_id, - (void *)&cmd_flow_director_mode, - (void *)&cmd_flow_director_mode_raw, - (void *)&cmd_flow_director_ops, - (void *)&cmd_flow_director_flow, - (void *)&cmd_flow_director_flow_type, - (void *)&cmd_flow_director_drop, - (void *)&cmd_flow_director_queue, - (void *)&cmd_flow_director_queue_id, - (void *)&cmd_flow_director_fd_id, - (void *)&cmd_flow_director_fd_id_value, - (void *)&cmd_flow_director_packet, - (void *)&cmd_flow_director_filepath, - NULL, - }, -}; - -#endif /* RTE_NET_I40E */ - /* *** deal with flow director mask *** */ struct cmd_flow_director_mask_result { cmdline_fixed_string_t flow_director_mask; @@ -16939,9 +16282,6 @@ static cmdline_parse_ctx_t builtin_ctx[] = { (cmdline_parse_inst_t *)&cmd_cleanup_txq_mbufs, (cmdline_parse_inst_t *)&cmd_dump, (cmdline_parse_inst_t *)&cmd_dump_one, -#ifdef RTE_NET_I40E - (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director, -#endif (cmdline_parse_inst_t *)&cmd_set_flow_director_ip_mask, (cmdline_parse_inst_t *)&cmd_set_flow_director_mac_vlan_mask, (cmdline_parse_inst_t *)&cmd_set_flow_director_tunnel_mask, @@ -17023,11 +16363,6 @@ static cmdline_parse_ctx_t builtin_ctx[] = { (cmdline_parse_inst_t *)&cmd_pctype_mapping_get, (cmdline_parse_inst_t *)&cmd_pctype_mapping_reset, (cmdline_parse_inst_t *)&cmd_pctype_mapping_update, - (cmdline_parse_inst_t *)&cmd_queue_region, - (cmdline_parse_inst_t *)&cmd_region_flowtype, - (cmdline_parse_inst_t *)&cmd_user_priority_region, - (cmdline_parse_inst_t *)&cmd_flush_queue_region, - (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all, (cmdline_parse_inst_t *)&cmd_show_port_tm_cap, (cmdline_parse_inst_t *)&cmd_show_port_tm_level_cap, (cmdline_parse_inst_t *)&cmd_show_port_tm_node_cap, diff --git a/drivers/net/i40e/i40e_testpmd.c b/drivers/net/i40e/i40e_testpmd.c new file mode 100644 index 0000000000..09cd4ff72d --- /dev/null +++ b/drivers/net/i40e/i40e_testpmd.c @@ -0,0 +1,655 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2016 Intel Corporation. + */ +#include + +#include +#include + +#include "testpmd.h" + +/* *** queue region set *** */ +struct cmd_queue_region_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t port; + portid_t port_id; + cmdline_fixed_string_t cmd; + cmdline_fixed_string_t region; + uint8_t region_id; + cmdline_fixed_string_t queue_start_index; + uint8_t queue_id; + cmdline_fixed_string_t queue_num; + uint8_t queue_num_value; +}; + +static void +cmd_queue_region_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_queue_region_result *res = parsed_result; + int ret = -ENOTSUP; + struct rte_pmd_i40e_queue_region_conf region_conf; + enum rte_pmd_i40e_queue_region_op op_type; + + if (port_id_is_invalid(res->port_id, ENABLED_WARN)) + return; + + memset(®ion_conf, 0, sizeof(region_conf)); + op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_SET; + region_conf.region_id = res->region_id; + region_conf.queue_num = res->queue_num_value; + region_conf.queue_start_index = res->queue_id; + + ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, + op_type, ®ion_conf); + switch (ret) { + case 0: + break; + case -ENOTSUP: + fprintf(stderr, "function not implemented or supported\n"); + break; + default: + fprintf(stderr, "queue region config error: (%s)\n", + strerror(-ret)); + } +} + +cmdline_parse_token_string_t cmd_queue_region_set = +TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, + set, "set"); +cmdline_parse_token_string_t cmd_queue_region_port = + TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, port, "port"); +cmdline_parse_token_num_t cmd_queue_region_port_id = + TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, + port_id, RTE_UINT16); +cmdline_parse_token_string_t cmd_queue_region_cmd = + TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, + cmd, "queue-region"); +cmdline_parse_token_string_t cmd_queue_region_id = + TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, + region, "region_id"); +cmdline_parse_token_num_t cmd_queue_region_index = + TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, + region_id, RTE_UINT8); +cmdline_parse_token_string_t cmd_queue_region_queue_start_index = + TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, + queue_start_index, "queue_start_index"); +cmdline_parse_token_num_t cmd_queue_region_queue_id = + TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, + queue_id, RTE_UINT8); +cmdline_parse_token_string_t cmd_queue_region_queue_num = + TOKEN_STRING_INITIALIZER(struct cmd_queue_region_result, + queue_num, "queue_num"); +cmdline_parse_token_num_t cmd_queue_region_queue_num_value = + TOKEN_NUM_INITIALIZER(struct cmd_queue_region_result, + queue_num_value, RTE_UINT8); + +cmdline_parse_inst_t cmd_queue_region = { + .f = cmd_queue_region_parsed, + .data = NULL, + .help_str = "set port queue-region region_id " + "queue_start_index queue_num : Set a queue region", + .tokens = { + (void *)&cmd_queue_region_set, + (void *)&cmd_queue_region_port, + (void *)&cmd_queue_region_port_id, + (void *)&cmd_queue_region_cmd, + (void *)&cmd_queue_region_id, + (void *)&cmd_queue_region_index, + (void *)&cmd_queue_region_queue_start_index, + (void *)&cmd_queue_region_queue_id, + (void *)&cmd_queue_region_queue_num, + (void *)&cmd_queue_region_queue_num_value, + NULL, + }, +}; + +/* *** queue region and flowtype set *** */ +struct cmd_region_flowtype_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t port; + portid_t port_id; + cmdline_fixed_string_t cmd; + cmdline_fixed_string_t region; + uint8_t region_id; + cmdline_fixed_string_t flowtype; + uint8_t flowtype_id; +}; + +static void +cmd_region_flowtype_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_region_flowtype_result *res = parsed_result; + int ret = -ENOTSUP; + struct rte_pmd_i40e_queue_region_conf region_conf; + enum rte_pmd_i40e_queue_region_op op_type; + + if (port_id_is_invalid(res->port_id, ENABLED_WARN)) + return; + + memset(®ion_conf, 0, sizeof(region_conf)); + + op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_FLOWTYPE_SET; + region_conf.region_id = res->region_id; + region_conf.hw_flowtype = res->flowtype_id; + + ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, + op_type, ®ion_conf); + switch (ret) { + case 0: + break; + case -ENOTSUP: + fprintf(stderr, "function not implemented or supported\n"); + break; + default: + fprintf(stderr, "region flowtype config error: (%s)\n", + strerror(-ret)); + } +} + +cmdline_parse_token_string_t cmd_region_flowtype_set = +TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, + set, "set"); +cmdline_parse_token_string_t cmd_region_flowtype_port = + TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, + port, "port"); +cmdline_parse_token_num_t cmd_region_flowtype_port_index = + TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result, + port_id, RTE_UINT16); +cmdline_parse_token_string_t cmd_region_flowtype_cmd = + TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, + cmd, "queue-region"); +cmdline_parse_token_string_t cmd_region_flowtype_index = + TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, + region, "region_id"); +cmdline_parse_token_num_t cmd_region_flowtype_id = + TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result, + region_id, RTE_UINT8); +cmdline_parse_token_string_t cmd_region_flowtype_flow_index = + TOKEN_STRING_INITIALIZER(struct cmd_region_flowtype_result, + flowtype, "flowtype"); +cmdline_parse_token_num_t cmd_region_flowtype_flow_id = + TOKEN_NUM_INITIALIZER(struct cmd_region_flowtype_result, + flowtype_id, RTE_UINT8); +cmdline_parse_inst_t cmd_region_flowtype = { + .f = cmd_region_flowtype_parsed, + .data = NULL, + .help_str = "set port queue-region region_id " + "flowtype : Set a flowtype region index", + .tokens = { + (void *)&cmd_region_flowtype_set, + (void *)&cmd_region_flowtype_port, + (void *)&cmd_region_flowtype_port_index, + (void *)&cmd_region_flowtype_cmd, + (void *)&cmd_region_flowtype_index, + (void *)&cmd_region_flowtype_id, + (void *)&cmd_region_flowtype_flow_index, + (void *)&cmd_region_flowtype_flow_id, + NULL, + }, +}; + +/* *** User Priority (UP) to queue region (region_id) set *** */ +struct cmd_user_priority_region_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t port; + portid_t port_id; + cmdline_fixed_string_t cmd; + cmdline_fixed_string_t user_priority; + uint8_t user_priority_id; + cmdline_fixed_string_t region; + uint8_t region_id; +}; + +static void +cmd_user_priority_region_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_user_priority_region_result *res = parsed_result; + int ret = -ENOTSUP; + struct rte_pmd_i40e_queue_region_conf region_conf; + enum rte_pmd_i40e_queue_region_op op_type; + + if (port_id_is_invalid(res->port_id, ENABLED_WARN)) + return; + + memset(®ion_conf, 0, sizeof(region_conf)); + op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_USER_PRIORITY_SET; + region_conf.user_priority = res->user_priority_id; + region_conf.region_id = res->region_id; + + ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, + op_type, ®ion_conf); + switch (ret) { + case 0: + break; + case -ENOTSUP: + fprintf(stderr, "function not implemented or supported\n"); + break; + default: + fprintf(stderr, "user_priority region config error: (%s)\n", + strerror(-ret)); + } +} + +cmdline_parse_token_string_t cmd_user_priority_region_set = + TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, + set, "set"); +cmdline_parse_token_string_t cmd_user_priority_region_port = + TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, + port, "port"); +cmdline_parse_token_num_t cmd_user_priority_region_port_index = + TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result, + port_id, RTE_UINT16); +cmdline_parse_token_string_t cmd_user_priority_region_cmd = + TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, + cmd, "queue-region"); +cmdline_parse_token_string_t cmd_user_priority_region_UP = + TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, + user_priority, "UP"); +cmdline_parse_token_num_t cmd_user_priority_region_UP_id = + TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result, + user_priority_id, RTE_UINT8); +cmdline_parse_token_string_t cmd_user_priority_region_region = + TOKEN_STRING_INITIALIZER(struct cmd_user_priority_region_result, + region, "region_id"); +cmdline_parse_token_num_t cmd_user_priority_region_region_id = + TOKEN_NUM_INITIALIZER(struct cmd_user_priority_region_result, + region_id, RTE_UINT8); + +cmdline_parse_inst_t cmd_user_priority_region = { + .f = cmd_user_priority_region_parsed, + .data = NULL, + .help_str = "set port queue-region UP " + "region_id : Set the mapping of User Priority (UP) " + "to queue region (region_id) ", + .tokens = { + (void *)&cmd_user_priority_region_set, + (void *)&cmd_user_priority_region_port, + (void *)&cmd_user_priority_region_port_index, + (void *)&cmd_user_priority_region_cmd, + (void *)&cmd_user_priority_region_UP, + (void *)&cmd_user_priority_region_UP_id, + (void *)&cmd_user_priority_region_region, + (void *)&cmd_user_priority_region_region_id, + NULL, + }, +}; + +/* *** flush all queue region related configuration *** */ +struct cmd_flush_queue_region_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t port; + portid_t port_id; + cmdline_fixed_string_t cmd; + cmdline_fixed_string_t flush; + cmdline_fixed_string_t what; +}; + +static void +cmd_flush_queue_region_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_flush_queue_region_result *res = parsed_result; + int ret = -ENOTSUP; + struct rte_pmd_i40e_queue_region_conf region_conf; + enum rte_pmd_i40e_queue_region_op op_type; + + if (port_id_is_invalid(res->port_id, ENABLED_WARN)) + return; + + memset(®ion_conf, 0, sizeof(region_conf)); + + if (strcmp(res->what, "on") == 0) + op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_ON; + else + op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_ALL_FLUSH_OFF; + + ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, + op_type, ®ion_conf); + switch (ret) { + case 0: + break; + case -ENOTSUP: + fprintf(stderr, "function not implemented or supported\n"); + break; + default: + fprintf(stderr, "queue region config flush error: (%s)\n", + strerror(-ret)); + } +} + +cmdline_parse_token_string_t cmd_flush_queue_region_set = + TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, + set, "set"); +cmdline_parse_token_string_t cmd_flush_queue_region_port = + TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, + port, "port"); +cmdline_parse_token_num_t cmd_flush_queue_region_port_index = + TOKEN_NUM_INITIALIZER(struct cmd_flush_queue_region_result, + port_id, RTE_UINT16); +cmdline_parse_token_string_t cmd_flush_queue_region_cmd = + TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, + cmd, "queue-region"); +cmdline_parse_token_string_t cmd_flush_queue_region_flush = + TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, + flush, "flush"); +cmdline_parse_token_string_t cmd_flush_queue_region_what = + TOKEN_STRING_INITIALIZER(struct cmd_flush_queue_region_result, + what, "on#off"); + +cmdline_parse_inst_t cmd_flush_queue_region = { + .f = cmd_flush_queue_region_parsed, + .data = NULL, + .help_str = "set port queue-region flush on|off" + ": flush all queue region related configuration", + .tokens = { + (void *)&cmd_flush_queue_region_set, + (void *)&cmd_flush_queue_region_port, + (void *)&cmd_flush_queue_region_port_index, + (void *)&cmd_flush_queue_region_cmd, + (void *)&cmd_flush_queue_region_flush, + (void *)&cmd_flush_queue_region_what, + NULL, + }, +}; + +/* *** get all queue region related configuration info *** */ +struct cmd_show_queue_region_info { + cmdline_fixed_string_t show; + cmdline_fixed_string_t port; + portid_t port_id; + cmdline_fixed_string_t cmd; +}; + +static void +cmd_show_queue_region_info_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_show_queue_region_info *res = parsed_result; + int ret = -ENOTSUP; + struct rte_pmd_i40e_queue_regions rte_pmd_regions; + enum rte_pmd_i40e_queue_region_op op_type; + + if (port_id_is_invalid(res->port_id, ENABLED_WARN)) + return; + + memset(&rte_pmd_regions, 0, sizeof(rte_pmd_regions)); + + op_type = RTE_PMD_I40E_RSS_QUEUE_REGION_INFO_GET; + + ret = rte_pmd_i40e_rss_queue_region_conf(res->port_id, + op_type, &rte_pmd_regions); + + port_queue_region_info_display(res->port_id, &rte_pmd_regions); + switch (ret) { + case 0: + break; + case -ENOTSUP: + fprintf(stderr, "function not implemented or supported\n"); + break; + default: + fprintf(stderr, "queue region config info show error: (%s)\n", + strerror(-ret)); + } +} + +cmdline_parse_token_string_t cmd_show_queue_region_info_get = +TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info, + show, "show"); +cmdline_parse_token_string_t cmd_show_queue_region_info_port = + TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info, + port, "port"); +cmdline_parse_token_num_t cmd_show_queue_region_info_port_index = + TOKEN_NUM_INITIALIZER(struct cmd_show_queue_region_info, + port_id, RTE_UINT16); +cmdline_parse_token_string_t cmd_show_queue_region_info_cmd = + TOKEN_STRING_INITIALIZER(struct cmd_show_queue_region_info, + cmd, "queue-region"); + +cmdline_parse_inst_t cmd_show_queue_region_info_all = { + .f = cmd_show_queue_region_info_parsed, + .data = NULL, + .help_str = "show port queue-region" + ": show all queue region related configuration info", + .tokens = { + (void *)&cmd_show_queue_region_info_get, + (void *)&cmd_show_queue_region_info_port, + (void *)&cmd_show_queue_region_info_port_index, + (void *)&cmd_show_queue_region_info_cmd, + NULL, + }, +}; + +static uint16_t +str2flowtype(char *string) +{ + uint8_t i = 0; + static const struct { + char str[32]; + uint16_t type; + } flowtype_str[] = { + {"raw", RTE_ETH_FLOW_RAW}, + {"ipv4", RTE_ETH_FLOW_IPV4}, + {"ipv4-frag", RTE_ETH_FLOW_FRAG_IPV4}, + {"ipv4-tcp", RTE_ETH_FLOW_NONFRAG_IPV4_TCP}, + {"ipv4-udp", RTE_ETH_FLOW_NONFRAG_IPV4_UDP}, + {"ipv4-sctp", RTE_ETH_FLOW_NONFRAG_IPV4_SCTP}, + {"ipv4-other", RTE_ETH_FLOW_NONFRAG_IPV4_OTHER}, + {"ipv6", RTE_ETH_FLOW_IPV6}, + {"ipv6-frag", RTE_ETH_FLOW_FRAG_IPV6}, + {"ipv6-tcp", RTE_ETH_FLOW_NONFRAG_IPV6_TCP}, + {"ipv6-udp", RTE_ETH_FLOW_NONFRAG_IPV6_UDP}, + {"ipv6-sctp", RTE_ETH_FLOW_NONFRAG_IPV6_SCTP}, + {"ipv6-other", RTE_ETH_FLOW_NONFRAG_IPV6_OTHER}, + {"l2_payload", RTE_ETH_FLOW_L2_PAYLOAD}, + {"ipv6-ex", RTE_ETH_FLOW_IPV6_EX}, + {"ipv6-tcp-ex", RTE_ETH_FLOW_IPV6_TCP_EX}, + {"ipv6-udp-ex", RTE_ETH_FLOW_IPV6_UDP_EX}, + {"gtpu", RTE_ETH_FLOW_GTPU}, + }; + + for (i = 0; i < RTE_DIM(flowtype_str); i++) { + if (!strcmp(flowtype_str[i].str, string)) + return flowtype_str[i].type; + } + + if (isdigit(string[0]) && atoi(string) > 0 && atoi(string) < 64) + return (uint16_t)atoi(string); + + return RTE_ETH_FLOW_UNKNOWN; +} + +/* *** deal with flow director filter *** */ +struct cmd_flow_director_result { + cmdline_fixed_string_t flow_director_filter; + portid_t port_id; + cmdline_fixed_string_t mode; + cmdline_fixed_string_t mode_value; + cmdline_fixed_string_t ops; + cmdline_fixed_string_t flow; + cmdline_fixed_string_t flow_type; + cmdline_fixed_string_t drop; + cmdline_fixed_string_t queue; + uint16_t queue_id; + cmdline_fixed_string_t fd_id; + uint32_t fd_id_value; + cmdline_fixed_string_t packet; + char filepath[]; +}; + +static void +cmd_flow_director_filter_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_flow_director_result *res = parsed_result; + int ret = 0; + struct rte_pmd_i40e_flow_type_mapping + mapping[RTE_PMD_I40E_FLOW_TYPE_MAX]; + struct rte_pmd_i40e_pkt_template_conf conf; + uint16_t flow_type = str2flowtype(res->flow_type); + uint16_t i, port = res->port_id; + uint8_t add; + + memset(&conf, 0, sizeof(conf)); + + if (flow_type == RTE_ETH_FLOW_UNKNOWN) { + fprintf(stderr, "Invalid flow type specified.\n"); + return; + } + ret = rte_pmd_i40e_flow_type_mapping_get(res->port_id, + mapping); + if (ret) + return; + if (mapping[flow_type].pctype == 0ULL) { + fprintf(stderr, "Invalid flow type specified.\n"); + return; + } + for (i = 0; i < RTE_PMD_I40E_PCTYPE_MAX; i++) { + if (mapping[flow_type].pctype & (1ULL << i)) { + conf.input.pctype = i; + break; + } + } + + conf.input.packet = open_file(res->filepath, + &conf.input.length); + if (!conf.input.packet) + return; + if (!strcmp(res->drop, "drop")) + conf.action.behavior = + RTE_PMD_I40E_PKT_TEMPLATE_REJECT; + else + conf.action.behavior = + RTE_PMD_I40E_PKT_TEMPLATE_ACCEPT; + conf.action.report_status = + RTE_PMD_I40E_PKT_TEMPLATE_REPORT_ID; + conf.action.rx_queue = res->queue_id; + conf.soft_id = res->fd_id_value; + add = strcmp(res->ops, "del") ? 1 : 0; + ret = rte_pmd_i40e_flow_add_del_packet_template(port, + &conf, + add); + if (ret < 0) + fprintf(stderr, "flow director config error: (%s)\n", + strerror(-ret)); + close_file(conf.input.packet); +} + +cmdline_parse_token_string_t cmd_flow_director_filter = + TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, + flow_director_filter, "flow_director_filter"); +cmdline_parse_token_num_t cmd_flow_director_port_id = + TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, + port_id, RTE_UINT16); +cmdline_parse_token_string_t cmd_flow_director_ops = + TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, + ops, "add#del#update"); +cmdline_parse_token_string_t cmd_flow_director_flow = + TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, + flow, "flow"); +cmdline_parse_token_string_t cmd_flow_director_flow_type = + TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, + flow_type, NULL); +cmdline_parse_token_string_t cmd_flow_director_drop = + TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, + drop, "drop#fwd"); +cmdline_parse_token_string_t cmd_flow_director_queue = + TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, + queue, "queue"); +cmdline_parse_token_num_t cmd_flow_director_queue_id = + TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, + queue_id, RTE_UINT16); +cmdline_parse_token_string_t cmd_flow_director_fd_id = + TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, + fd_id, "fd_id"); +cmdline_parse_token_num_t cmd_flow_director_fd_id_value = + TOKEN_NUM_INITIALIZER(struct cmd_flow_director_result, + fd_id_value, RTE_UINT32); + +cmdline_parse_token_string_t cmd_flow_director_mode = + TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, + mode, "mode"); +cmdline_parse_token_string_t cmd_flow_director_mode_raw = + TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, + mode_value, "raw"); +cmdline_parse_token_string_t cmd_flow_director_packet = + TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, + packet, "packet"); +cmdline_parse_token_string_t cmd_flow_director_filepath = + TOKEN_STRING_INITIALIZER(struct cmd_flow_director_result, + filepath, NULL); + +cmdline_parse_inst_t cmd_add_del_raw_flow_director = { + .f = cmd_flow_director_filter_parsed, + .data = NULL, + .help_str = "flow_director_filter ... : Add or delete a raw flow " + "director entry on NIC", + .tokens = { + (void *)&cmd_flow_director_filter, + (void *)&cmd_flow_director_port_id, + (void *)&cmd_flow_director_mode, + (void *)&cmd_flow_director_mode_raw, + (void *)&cmd_flow_director_ops, + (void *)&cmd_flow_director_flow, + (void *)&cmd_flow_director_flow_type, + (void *)&cmd_flow_director_drop, + (void *)&cmd_flow_director_queue, + (void *)&cmd_flow_director_queue_id, + (void *)&cmd_flow_director_fd_id, + (void *)&cmd_flow_director_fd_id_value, + (void *)&cmd_flow_director_packet, + (void *)&cmd_flow_director_filepath, + NULL, + }, +}; + +static struct testpmd_cmdline_parser driver_parser = { + .ctx = (cmdline_parse_ctx_t[]) { + (cmdline_parse_inst_t *)&cmd_queue_region, + (cmdline_parse_inst_t *)&cmd_region_flowtype, + (cmdline_parse_inst_t *)&cmd_user_priority_region, + (cmdline_parse_inst_t *)&cmd_flush_queue_region, + (cmdline_parse_inst_t *)&cmd_show_queue_region_info_all, + (cmdline_parse_inst_t *)&cmd_add_del_raw_flow_director, + NULL + }, + .help = { + "set port (port_id) queue-region region_id (value) " + "queue_start_index (value) queue_num (value)\n" + " Set a queue region on a port\n", + + "set port (port_id) queue-region region_id (value) " + "flowtype (value)\n" + " Set a flowtype region index on a port\n", + + "set port (port_id) queue-region UP (value) region_id (value)\n" + " Set the mapping of User Priority to " + "queue region on a port\n", + + "set port (port_id) queue-region flush (on|off)\n" + " flush all queue region related configuration\n", + + "show port (port_id) queue-region\n" + " show all queue region related configuration info\n", + + "flow_director_filter (port_id) mode raw (add|del|update)" + " flow (flow_id) (drop|fwd) queue (queue_id)" + " fd_id (fd_id_value) packet (packet file name)\n" + " Add/Del a raw type flow director filter.\n", + + NULL + }, +}; + +RTE_INIT(i40e_testpmd) +{ + testpmd_add_commands(&driver_parser); +} diff --git a/drivers/net/i40e/meson.build b/drivers/net/i40e/meson.build index efc5f93e35..b282ec7213 100644 --- a/drivers/net/i40e/meson.build +++ b/drivers/net/i40e/meson.build @@ -21,6 +21,8 @@ sources = files( 'rte_pmd_i40e.c', ) +testpmd_sources = files('i40e_testpmd.c') + deps += ['hash'] includes += include_directories('base') From patchwork Fri May 13 07:57:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 111122 X-Patchwork-Delegate: andrew.rybchenko@oktetlabs.ru Return-Path: X-Original-To: patchwork@inbox.dpdk.org Delivered-To: patchwork@inbox.dpdk.org Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id 4F3CFA00C3; Fri, 13 May 2022 09:57:48 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 58BEB410EF; Fri, 13 May 2022 09:57:46 +0200 (CEST) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by mails.dpdk.org (Postfix) with ESMTP id 92BFC40DDE for ; Fri, 13 May 2022 09:57:45 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1652428665; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2BkmPM0qP4CtHNL4p5OC2Ybvs85zWUE8WfFPO68G0jk=; b=JyHzYu1UCOxz3quAfJdK1kyyQhe2Jg4ZWvItSULQrxThX5f+6XBxJQR/aXBYd/ZdhHdV9w +3iiV7WkCeM1Sa68mRFImxiqX4AX58iSzXs0YNP8Iv38MgQQnrFS6TR5mFGhluax7VRu28 O9mY8tiZr1W+q3CW2Qj74WWiwpQDHBc= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-599-W3w_Kd4eOVCsK8dpWxxQug-1; Fri, 13 May 2022 03:57:40 -0400 X-MC-Unique: W3w_Kd4eOVCsK8dpWxxQug-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id AB45A185A794; Fri, 13 May 2022 07:57:37 +0000 (UTC) Received: from dmarchan.remote.csb (unknown [10.40.193.195]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1848A416362; Fri, 13 May 2022 07:57:35 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, Xiaoyun Li , Aman Singh , Yuying Zhang , Qiming Yang , Wenjun Wu Subject: [RFC PATCH 4/4] net/ixgbe: move testpmd commands Date: Fri, 13 May 2022 09:57:18 +0200 Message-Id: <20220513075718.18674-5-david.marchand@redhat.com> In-Reply-To: <20220513075718.18674-1-david.marchand@redhat.com> References: <20220513075718.18674-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=david.marchand@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Move related specific testpmd commands into this driver directory. While at it, fix checkpatch warnings. The bypass code required some special init code before starting a port. This is removed from testpmd itself and a new (*untested*) command is added. Note: bypass commands were not compiled since the switch to meson. This change reinstates them, though I am really tempted to drop them since we had no complaint for such a long time. Signed-off-by: David Marchand --- app/test-pmd/cmdline.c | 977 +----------------------- app/test-pmd/testpmd.c | 14 - app/test-pmd/testpmd.h | 5 +- drivers/net/ixgbe/ixgbe_testpmd.c | 1147 +++++++++++++++++++++++++++++ drivers/net/ixgbe/meson.build | 2 + 5 files changed, 1151 insertions(+), 994 deletions(-) create mode 100644 drivers/net/ixgbe/ixgbe_testpmd.c diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index fee05c1a0c..a5a5ef9588 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -69,8 +69,6 @@ static cmdline_parse_ctx_t *main_ctx; static TAILQ_HEAD(, testpmd_cmdline_parser) cmdline_parsers = TAILQ_HEAD_INITIALIZER(cmdline_parsers); -static void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue); - /* *** Help command with introduction. *** */ struct cmd_help_brief_result { cmdline_fixed_string_t help; @@ -344,24 +342,9 @@ static void cmd_help_long_parsed(void *parsed_result, "set all queues drop (port_id) (on|off)\n" " Set drop enable bit for all queues.\n\n" - "set vf split drop (port_id) (vf_id) (on|off)\n" - " Set split drop enable bit for a VF from the PF.\n\n" - "set vf mac antispoof (port_id) (vf_id) (on|off).\n" " Set MAC antispoof for a VF from the PF.\n\n" - "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n" - " Enable MACsec offload.\n\n" - - "set macsec offload (port_id) off\n" - " Disable MACsec offload.\n\n" - - "set macsec sc (tx|rx) (port_id) (mac) (pi)\n" - " Configure MACsec secure connection (SC).\n\n" - - "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n" - " Configure MACsec secure association (SA).\n\n" - "set vf broadcast (port_id) (vf_id) (on|off)\n" " Set VF broadcast for a VF from the PF.\n\n" @@ -392,9 +375,6 @@ static void cmd_help_long_parsed(void *parsed_result, "set tx strict-link-priority (port_id) (tc_bitmap)\n" " Set some TCs' strict link priority mode on a physical port.\n\n" - "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n" - " Set all TCs' min bandwidth(%%) for all PF and VFs.\n\n" - "vlan set (strip|filter|qinq_strip|extend) (on|off) (port_id)\n" " Set the VLAN strip or filter or qinq strip or extend\n\n" @@ -587,29 +567,6 @@ static void cmd_help_long_parsed(void *parsed_result, " Flush (default) or don't flush RX streams before" " forwarding. Mainly used with PCAP drivers.\n\n" - "set bypass mode (normal|bypass|isolate) (port_id)\n" - " Set the bypass mode for the lowest port on bypass enabled" - " NIC.\n\n" - - "set bypass event (timeout|os_on|os_off|power_on|power_off) " - "mode (normal|bypass|isolate) (port_id)\n" - " Set the event required to initiate specified bypass mode for" - " the lowest port on a bypass enabled NIC where:\n" - " timeout = enable bypass after watchdog timeout.\n" - " os_on = enable bypass when OS/board is powered on.\n" - " os_off = enable bypass when OS/board is powered off.\n" - " power_on = enable bypass when power supply is turned on.\n" - " power_off = enable bypass when power supply is turned off." - "\n\n" - - "set bypass timeout (0|1.5|2|3|4|8|16|32)\n" - " Set the bypass watchdog timeout to 'n' seconds" - " where 0 = instant.\n\n" - - "show bypass config (port_id)\n" - " Show the bypass configuration for a bypass enabled NIC" - " using the lowest port on the NIC.\n\n" - "set link-up port (port_id)\n" " Set link up for a port.\n\n" @@ -5517,347 +5474,6 @@ cmdline_parse_inst_t cmd_set_link_check = { }, }; -/* *** SET NIC BYPASS MODE *** */ -struct cmd_set_bypass_mode_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t bypass; - cmdline_fixed_string_t mode; - cmdline_fixed_string_t value; - portid_t port_id; -}; - -static void -cmd_set_bypass_mode_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_set_bypass_mode_result *res = parsed_result; - portid_t port_id = res->port_id; - int32_t rc = -EINVAL; - -#if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS - uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; - - if (!strcmp(res->value, "bypass")) - bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS; - else if (!strcmp(res->value, "isolate")) - bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE; - else - bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; - - /* Set the bypass mode for the relevant port. */ - rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode); -#endif - if (rc != 0) - fprintf(stderr, "\t Failed to set bypass mode for port = %d.\n", - port_id); -} - -cmdline_parse_token_string_t cmd_setbypass_mode_set = - TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, - set, "set"); -cmdline_parse_token_string_t cmd_setbypass_mode_bypass = - TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, - bypass, "bypass"); -cmdline_parse_token_string_t cmd_setbypass_mode_mode = - TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, - mode, "mode"); -cmdline_parse_token_string_t cmd_setbypass_mode_value = - TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, - value, "normal#bypass#isolate"); -cmdline_parse_token_num_t cmd_setbypass_mode_port = - TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result, - port_id, RTE_UINT16); - -cmdline_parse_inst_t cmd_set_bypass_mode = { - .f = cmd_set_bypass_mode_parsed, - .help_str = "set bypass mode normal|bypass|isolate : " - "Set the NIC bypass mode for port_id", - .data = NULL, - .tokens = { - (void *)&cmd_setbypass_mode_set, - (void *)&cmd_setbypass_mode_bypass, - (void *)&cmd_setbypass_mode_mode, - (void *)&cmd_setbypass_mode_value, - (void *)&cmd_setbypass_mode_port, - NULL, - }, -}; - -/* *** SET NIC BYPASS EVENT *** */ -struct cmd_set_bypass_event_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t bypass; - cmdline_fixed_string_t event; - cmdline_fixed_string_t event_value; - cmdline_fixed_string_t mode; - cmdline_fixed_string_t mode_value; - portid_t port_id; -}; - -static void -cmd_set_bypass_event_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - int32_t rc = -EINVAL; - struct cmd_set_bypass_event_result *res = parsed_result; - portid_t port_id = res->port_id; - -#if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS - uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE; - uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; - - if (!strcmp(res->event_value, "timeout")) - bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT; - else if (!strcmp(res->event_value, "os_on")) - bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON; - else if (!strcmp(res->event_value, "os_off")) - bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF; - else if (!strcmp(res->event_value, "power_on")) - bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON; - else if (!strcmp(res->event_value, "power_off")) - bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF; - else - bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE; - - if (!strcmp(res->mode_value, "bypass")) - bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS; - else if (!strcmp(res->mode_value, "isolate")) - bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE; - else - bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; - - /* Set the watchdog timeout. */ - if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) { - - rc = -EINVAL; - if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) { - rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id, - bypass_timeout); - } - if (rc != 0) { - fprintf(stderr, - "Failed to set timeout value %u for port %d, errto code: %d.\n", - bypass_timeout, port_id, rc); - } - } - - /* Set the bypass event to transition to bypass mode. */ - rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event, - bypass_mode); -#endif - - if (rc != 0) - fprintf(stderr, "\t Failed to set bypass event for port = %d.\n", - port_id); -} - -cmdline_parse_token_string_t cmd_setbypass_event_set = - TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, - set, "set"); -cmdline_parse_token_string_t cmd_setbypass_event_bypass = - TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, - bypass, "bypass"); -cmdline_parse_token_string_t cmd_setbypass_event_event = - TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, - event, "event"); -cmdline_parse_token_string_t cmd_setbypass_event_event_value = - TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, - event_value, "none#timeout#os_off#os_on#power_on#power_off"); -cmdline_parse_token_string_t cmd_setbypass_event_mode = - TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, - mode, "mode"); -cmdline_parse_token_string_t cmd_setbypass_event_mode_value = - TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, - mode_value, "normal#bypass#isolate"); -cmdline_parse_token_num_t cmd_setbypass_event_port = - TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result, - port_id, RTE_UINT16); - -cmdline_parse_inst_t cmd_set_bypass_event = { - .f = cmd_set_bypass_event_parsed, - .help_str = "set bypass event none|timeout|os_on|os_off|power_on|" - "power_off mode normal|bypass|isolate : " - "Set the NIC bypass event mode for port_id", - .data = NULL, - .tokens = { - (void *)&cmd_setbypass_event_set, - (void *)&cmd_setbypass_event_bypass, - (void *)&cmd_setbypass_event_event, - (void *)&cmd_setbypass_event_event_value, - (void *)&cmd_setbypass_event_mode, - (void *)&cmd_setbypass_event_mode_value, - (void *)&cmd_setbypass_event_port, - NULL, - }, -}; - - -/* *** SET NIC BYPASS TIMEOUT *** */ -struct cmd_set_bypass_timeout_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t bypass; - cmdline_fixed_string_t timeout; - cmdline_fixed_string_t value; -}; - -static void -cmd_set_bypass_timeout_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - __rte_unused struct cmd_set_bypass_timeout_result *res = parsed_result; - -#if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS - if (!strcmp(res->value, "1.5")) - bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC; - else if (!strcmp(res->value, "2")) - bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC; - else if (!strcmp(res->value, "3")) - bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC; - else if (!strcmp(res->value, "4")) - bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC; - else if (!strcmp(res->value, "8")) - bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC; - else if (!strcmp(res->value, "16")) - bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC; - else if (!strcmp(res->value, "32")) - bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC; - else - bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF; -#endif -} - -cmdline_parse_token_string_t cmd_setbypass_timeout_set = - TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, - set, "set"); -cmdline_parse_token_string_t cmd_setbypass_timeout_bypass = - TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, - bypass, "bypass"); -cmdline_parse_token_string_t cmd_setbypass_timeout_timeout = - TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, - timeout, "timeout"); -cmdline_parse_token_string_t cmd_setbypass_timeout_value = - TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, - value, "0#1.5#2#3#4#8#16#32"); - -cmdline_parse_inst_t cmd_set_bypass_timeout = { - .f = cmd_set_bypass_timeout_parsed, - .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: " - "Set the NIC bypass watchdog timeout in seconds", - .data = NULL, - .tokens = { - (void *)&cmd_setbypass_timeout_set, - (void *)&cmd_setbypass_timeout_bypass, - (void *)&cmd_setbypass_timeout_timeout, - (void *)&cmd_setbypass_timeout_value, - NULL, - }, -}; - -/* *** SHOW NIC BYPASS MODE *** */ -struct cmd_show_bypass_config_result { - cmdline_fixed_string_t show; - cmdline_fixed_string_t bypass; - cmdline_fixed_string_t config; - portid_t port_id; -}; - -static void -cmd_show_bypass_config_parsed(void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_show_bypass_config_result *res = parsed_result; - portid_t port_id = res->port_id; - int rc = -EINVAL; -#if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS - uint32_t event_mode; - uint32_t bypass_mode; - uint32_t timeout = bypass_timeout; - unsigned int i; - - static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] = - {"off", "1.5", "2", "3", "4", "8", "16", "32"}; - static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] = - {"UNKNOWN", "normal", "bypass", "isolate"}; - static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = { - "NONE", - "OS/board on", - "power supply on", - "OS/board off", - "power supply off", - "timeout"}; - - /* Display the bypass mode.*/ - if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) { - fprintf(stderr, "\tFailed to get bypass mode for port = %d\n", - port_id); - return; - } - else { - if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode)) - bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE; - - printf("\tbypass mode = %s\n", modes[bypass_mode]); - } - - /* Display the bypass timeout.*/ - if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout)) - timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF; - - printf("\tbypass timeout = %s\n", timeouts[timeout]); - - /* Display the bypass events and associated modes. */ - for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) { - - if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) { - fprintf(stderr, - "\tFailed to get bypass mode for event = %s\n", - events[i]); - } else { - if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode)) - event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE; - - printf("\tbypass event: %-16s = %s\n", events[i], - modes[event_mode]); - } - } -#endif - if (rc != 0) - fprintf(stderr, - "\tFailed to get bypass configuration for port = %d\n", - port_id); -} - -cmdline_parse_token_string_t cmd_showbypass_config_show = - TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, - show, "show"); -cmdline_parse_token_string_t cmd_showbypass_config_bypass = - TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, - bypass, "bypass"); -cmdline_parse_token_string_t cmd_showbypass_config_config = - TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, - config, "config"); -cmdline_parse_token_num_t cmd_showbypass_config_port = - TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result, - port_id, RTE_UINT16); - -cmdline_parse_inst_t cmd_show_bypass_config = { - .f = cmd_show_bypass_config_parsed, - .help_str = "show bypass config : " - "Show the NIC bypass config for port_id", - .data = NULL, - .tokens = { - (void *)&cmd_showbypass_config_show, - (void *)&cmd_showbypass_config_bypass, - (void *)&cmd_showbypass_config_config, - (void *)&cmd_showbypass_config_port, - NULL, - }, -}; - /* *** SET FORWARDING MODE *** */ struct cmd_set_fwd_mode_result { cmdline_fixed_string_t set; @@ -10079,100 +9695,6 @@ cmdline_parse_inst_t cmd_set_all_queues_drop_en = { }, }; -/* vf split drop enable configuration */ - -/* Common result structure for vf split drop enable */ -struct cmd_vf_split_drop_en_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t vf; - cmdline_fixed_string_t split; - cmdline_fixed_string_t drop; - portid_t port_id; - uint16_t vf_id; - cmdline_fixed_string_t on_off; -}; - -/* Common CLI fields for vf split drop enable disable */ -cmdline_parse_token_string_t cmd_vf_split_drop_en_set = - TOKEN_STRING_INITIALIZER - (struct cmd_vf_split_drop_en_result, - set, "set"); -cmdline_parse_token_string_t cmd_vf_split_drop_en_vf = - TOKEN_STRING_INITIALIZER - (struct cmd_vf_split_drop_en_result, - vf, "vf"); -cmdline_parse_token_string_t cmd_vf_split_drop_en_split = - TOKEN_STRING_INITIALIZER - (struct cmd_vf_split_drop_en_result, - split, "split"); -cmdline_parse_token_string_t cmd_vf_split_drop_en_drop = - TOKEN_STRING_INITIALIZER - (struct cmd_vf_split_drop_en_result, - drop, "drop"); -cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id = - TOKEN_NUM_INITIALIZER - (struct cmd_vf_split_drop_en_result, - port_id, RTE_UINT16); -cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id = - TOKEN_NUM_INITIALIZER - (struct cmd_vf_split_drop_en_result, - vf_id, RTE_UINT16); -cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off = - TOKEN_STRING_INITIALIZER - (struct cmd_vf_split_drop_en_result, - on_off, "on#off"); - -static void -cmd_set_vf_split_drop_en_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_vf_split_drop_en_result *res = parsed_result; - int ret = -ENOTSUP; - int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; - - if (port_id_is_invalid(res->port_id, ENABLED_WARN)) - return; - -#ifdef RTE_NET_IXGBE - ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id, - is_on); -#endif - switch (ret) { - case 0: - break; - case -EINVAL: - fprintf(stderr, "invalid vf_id %d or is_on %d\n", - res->vf_id, is_on); - break; - case -ENODEV: - fprintf(stderr, "invalid port_id %d\n", res->port_id); - break; - case -ENOTSUP: - fprintf(stderr, "not supported on port %d\n", res->port_id); - break; - default: - fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); - } -} - -cmdline_parse_inst_t cmd_set_vf_split_drop_en = { - .f = cmd_set_vf_split_drop_en_parsed, - .data = NULL, - .help_str = "set vf split drop on|off", - .tokens = { - (void *)&cmd_vf_split_drop_en_set, - (void *)&cmd_vf_split_drop_en_vf, - (void *)&cmd_vf_split_drop_en_split, - (void *)&cmd_vf_split_drop_en_drop, - (void *)&cmd_vf_split_drop_en_port_id, - (void *)&cmd_vf_split_drop_en_vf_id, - (void *)&cmd_vf_split_drop_en_on_off, - NULL, - }, -}; - /* vf mac address configuration */ /* Common result structure for vf mac address */ @@ -10277,431 +9799,6 @@ cmdline_parse_inst_t cmd_set_vf_mac_addr = { }, }; -/* MACsec configuration */ - -/* Common result structure for MACsec offload enable */ -struct cmd_macsec_offload_on_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t macsec; - cmdline_fixed_string_t offload; - portid_t port_id; - cmdline_fixed_string_t on; - cmdline_fixed_string_t encrypt; - cmdline_fixed_string_t en_on_off; - cmdline_fixed_string_t replay_protect; - cmdline_fixed_string_t rp_on_off; -}; - -/* Common CLI fields for MACsec offload disable */ -cmdline_parse_token_string_t cmd_macsec_offload_on_set = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_offload_on_result, - set, "set"); -cmdline_parse_token_string_t cmd_macsec_offload_on_macsec = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_offload_on_result, - macsec, "macsec"); -cmdline_parse_token_string_t cmd_macsec_offload_on_offload = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_offload_on_result, - offload, "offload"); -cmdline_parse_token_num_t cmd_macsec_offload_on_port_id = - TOKEN_NUM_INITIALIZER - (struct cmd_macsec_offload_on_result, - port_id, RTE_UINT16); -cmdline_parse_token_string_t cmd_macsec_offload_on_on = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_offload_on_result, - on, "on"); -cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_offload_on_result, - encrypt, "encrypt"); -cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_offload_on_result, - en_on_off, "on#off"); -cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_offload_on_result, - replay_protect, "replay-protect"); -cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_offload_on_result, - rp_on_off, "on#off"); - -static void -cmd_set_macsec_offload_on_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_macsec_offload_on_result *res = parsed_result; - int ret = -ENOTSUP; - portid_t port_id = res->port_id; - int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0; - int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0; - struct rte_eth_dev_info dev_info; - - if (port_id_is_invalid(port_id, ENABLED_WARN)) - return; - if (!port_is_stopped(port_id)) { - fprintf(stderr, "Please stop port %d first\n", port_id); - return; - } - - ret = eth_dev_info_get_print_err(port_id, &dev_info); - if (ret != 0) - return; - - if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) { -#ifdef RTE_NET_IXGBE - ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp); -#endif - } - RTE_SET_USED(en); - RTE_SET_USED(rp); - - switch (ret) { - case 0: - ports[port_id].dev_conf.txmode.offloads |= - RTE_ETH_TX_OFFLOAD_MACSEC_INSERT; - cmd_reconfig_device_queue(port_id, 1, 1); - break; - case -ENODEV: - fprintf(stderr, "invalid port_id %d\n", port_id); - break; - case -ENOTSUP: - fprintf(stderr, "not supported on port %d\n", port_id); - break; - default: - fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); - } -} - -cmdline_parse_inst_t cmd_set_macsec_offload_on = { - .f = cmd_set_macsec_offload_on_parsed, - .data = NULL, - .help_str = "set macsec offload on " - "encrypt on|off replay-protect on|off", - .tokens = { - (void *)&cmd_macsec_offload_on_set, - (void *)&cmd_macsec_offload_on_macsec, - (void *)&cmd_macsec_offload_on_offload, - (void *)&cmd_macsec_offload_on_port_id, - (void *)&cmd_macsec_offload_on_on, - (void *)&cmd_macsec_offload_on_encrypt, - (void *)&cmd_macsec_offload_on_en_on_off, - (void *)&cmd_macsec_offload_on_replay_protect, - (void *)&cmd_macsec_offload_on_rp_on_off, - NULL, - }, -}; - -/* Common result structure for MACsec offload disable */ -struct cmd_macsec_offload_off_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t macsec; - cmdline_fixed_string_t offload; - portid_t port_id; - cmdline_fixed_string_t off; -}; - -/* Common CLI fields for MACsec offload disable */ -cmdline_parse_token_string_t cmd_macsec_offload_off_set = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_offload_off_result, - set, "set"); -cmdline_parse_token_string_t cmd_macsec_offload_off_macsec = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_offload_off_result, - macsec, "macsec"); -cmdline_parse_token_string_t cmd_macsec_offload_off_offload = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_offload_off_result, - offload, "offload"); -cmdline_parse_token_num_t cmd_macsec_offload_off_port_id = - TOKEN_NUM_INITIALIZER - (struct cmd_macsec_offload_off_result, - port_id, RTE_UINT16); -cmdline_parse_token_string_t cmd_macsec_offload_off_off = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_offload_off_result, - off, "off"); - -static void -cmd_set_macsec_offload_off_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_macsec_offload_off_result *res = parsed_result; - int ret = -ENOTSUP; - struct rte_eth_dev_info dev_info; - portid_t port_id = res->port_id; - - if (port_id_is_invalid(port_id, ENABLED_WARN)) - return; - if (!port_is_stopped(port_id)) { - fprintf(stderr, "Please stop port %d first\n", port_id); - return; - } - - ret = eth_dev_info_get_print_err(port_id, &dev_info); - if (ret != 0) - return; - - if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) { -#ifdef RTE_NET_IXGBE - ret = rte_pmd_ixgbe_macsec_disable(port_id); -#endif - } - switch (ret) { - case 0: - ports[port_id].dev_conf.txmode.offloads &= - ~RTE_ETH_TX_OFFLOAD_MACSEC_INSERT; - cmd_reconfig_device_queue(port_id, 1, 1); - break; - case -ENODEV: - fprintf(stderr, "invalid port_id %d\n", port_id); - break; - case -ENOTSUP: - fprintf(stderr, "not supported on port %d\n", port_id); - break; - default: - fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); - } -} - -cmdline_parse_inst_t cmd_set_macsec_offload_off = { - .f = cmd_set_macsec_offload_off_parsed, - .data = NULL, - .help_str = "set macsec offload off", - .tokens = { - (void *)&cmd_macsec_offload_off_set, - (void *)&cmd_macsec_offload_off_macsec, - (void *)&cmd_macsec_offload_off_offload, - (void *)&cmd_macsec_offload_off_port_id, - (void *)&cmd_macsec_offload_off_off, - NULL, - }, -}; - -/* Common result structure for MACsec secure connection configure */ -struct cmd_macsec_sc_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t macsec; - cmdline_fixed_string_t sc; - cmdline_fixed_string_t tx_rx; - portid_t port_id; - struct rte_ether_addr mac; - uint16_t pi; -}; - -/* Common CLI fields for MACsec secure connection configure */ -cmdline_parse_token_string_t cmd_macsec_sc_set = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_sc_result, - set, "set"); -cmdline_parse_token_string_t cmd_macsec_sc_macsec = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_sc_result, - macsec, "macsec"); -cmdline_parse_token_string_t cmd_macsec_sc_sc = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_sc_result, - sc, "sc"); -cmdline_parse_token_string_t cmd_macsec_sc_tx_rx = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_sc_result, - tx_rx, "tx#rx"); -cmdline_parse_token_num_t cmd_macsec_sc_port_id = - TOKEN_NUM_INITIALIZER - (struct cmd_macsec_sc_result, - port_id, RTE_UINT16); -cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac = - TOKEN_ETHERADDR_INITIALIZER - (struct cmd_macsec_sc_result, - mac); -cmdline_parse_token_num_t cmd_macsec_sc_pi = - TOKEN_NUM_INITIALIZER - (struct cmd_macsec_sc_result, - pi, RTE_UINT16); - -static void -cmd_set_macsec_sc_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_macsec_sc_result *res = parsed_result; - int ret = -ENOTSUP; - int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0; - -#ifdef RTE_NET_IXGBE - ret = is_tx ? - rte_pmd_ixgbe_macsec_config_txsc(res->port_id, - res->mac.addr_bytes) : - rte_pmd_ixgbe_macsec_config_rxsc(res->port_id, - res->mac.addr_bytes, res->pi); -#endif - RTE_SET_USED(is_tx); - - switch (ret) { - case 0: - break; - case -ENODEV: - fprintf(stderr, "invalid port_id %d\n", res->port_id); - break; - case -ENOTSUP: - fprintf(stderr, "not supported on port %d\n", res->port_id); - break; - default: - fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); - } -} - -cmdline_parse_inst_t cmd_set_macsec_sc = { - .f = cmd_set_macsec_sc_parsed, - .data = NULL, - .help_str = "set macsec sc tx|rx ", - .tokens = { - (void *)&cmd_macsec_sc_set, - (void *)&cmd_macsec_sc_macsec, - (void *)&cmd_macsec_sc_sc, - (void *)&cmd_macsec_sc_tx_rx, - (void *)&cmd_macsec_sc_port_id, - (void *)&cmd_macsec_sc_mac, - (void *)&cmd_macsec_sc_pi, - NULL, - }, -}; - -/* Common result structure for MACsec secure connection configure */ -struct cmd_macsec_sa_result { - cmdline_fixed_string_t set; - cmdline_fixed_string_t macsec; - cmdline_fixed_string_t sa; - cmdline_fixed_string_t tx_rx; - portid_t port_id; - uint8_t idx; - uint8_t an; - uint32_t pn; - cmdline_fixed_string_t key; -}; - -/* Common CLI fields for MACsec secure connection configure */ -cmdline_parse_token_string_t cmd_macsec_sa_set = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_sa_result, - set, "set"); -cmdline_parse_token_string_t cmd_macsec_sa_macsec = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_sa_result, - macsec, "macsec"); -cmdline_parse_token_string_t cmd_macsec_sa_sa = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_sa_result, - sa, "sa"); -cmdline_parse_token_string_t cmd_macsec_sa_tx_rx = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_sa_result, - tx_rx, "tx#rx"); -cmdline_parse_token_num_t cmd_macsec_sa_port_id = - TOKEN_NUM_INITIALIZER - (struct cmd_macsec_sa_result, - port_id, RTE_UINT16); -cmdline_parse_token_num_t cmd_macsec_sa_idx = - TOKEN_NUM_INITIALIZER - (struct cmd_macsec_sa_result, - idx, RTE_UINT8); -cmdline_parse_token_num_t cmd_macsec_sa_an = - TOKEN_NUM_INITIALIZER - (struct cmd_macsec_sa_result, - an, RTE_UINT8); -cmdline_parse_token_num_t cmd_macsec_sa_pn = - TOKEN_NUM_INITIALIZER - (struct cmd_macsec_sa_result, - pn, RTE_UINT32); -cmdline_parse_token_string_t cmd_macsec_sa_key = - TOKEN_STRING_INITIALIZER - (struct cmd_macsec_sa_result, - key, NULL); - -static void -cmd_set_macsec_sa_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_macsec_sa_result *res = parsed_result; - int ret = -ENOTSUP; - int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0; - uint8_t key[16] = { 0 }; - uint8_t xdgt0; - uint8_t xdgt1; - int key_len; - int i; - - key_len = strlen(res->key) / 2; - if (key_len > 16) - key_len = 16; - - for (i = 0; i < key_len; i++) { - xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2)); - if (xdgt0 == 0xFF) - return; - xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1); - if (xdgt1 == 0xFF) - return; - key[i] = (uint8_t) ((xdgt0 * 16) + xdgt1); - } - -#ifdef RTE_NET_IXGBE - ret = is_tx ? - rte_pmd_ixgbe_macsec_select_txsa(res->port_id, - res->idx, res->an, res->pn, key) : - rte_pmd_ixgbe_macsec_select_rxsa(res->port_id, - res->idx, res->an, res->pn, key); -#endif - RTE_SET_USED(is_tx); - RTE_SET_USED(key); - - switch (ret) { - case 0: - break; - case -EINVAL: - fprintf(stderr, "invalid idx %d or an %d\n", res->idx, res->an); - break; - case -ENODEV: - fprintf(stderr, "invalid port_id %d\n", res->port_id); - break; - case -ENOTSUP: - fprintf(stderr, "not supported on port %d\n", res->port_id); - break; - default: - fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); - } -} - -cmdline_parse_inst_t cmd_set_macsec_sa = { - .f = cmd_set_macsec_sa_parsed, - .data = NULL, - .help_str = "set macsec sa tx|rx ", - .tokens = { - (void *)&cmd_macsec_sa_set, - (void *)&cmd_macsec_sa_macsec, - (void *)&cmd_macsec_sa_sa, - (void *)&cmd_macsec_sa_tx_rx, - (void *)&cmd_macsec_sa_port_id, - (void *)&cmd_macsec_sa_idx, - (void *)&cmd_macsec_sa_an, - (void *)&cmd_macsec_sa_pn, - (void *)&cmd_macsec_sa_key, - NULL, - }, -}; - /* VF unicast promiscuous mode configuration */ /* Common result structure for VF unicast promiscuous mode */ @@ -11294,68 +10391,6 @@ cmdline_parse_inst_t cmd_vf_tc_min_bw = { }, }; -static void -cmd_tc_min_bw_parsed( - void *parsed_result, - __rte_unused struct cmdline *cl, - __rte_unused void *data) -{ - struct cmd_vf_tc_bw_result *res = parsed_result; - struct rte_port *port; - uint8_t tc_num; - uint8_t bw[16]; - int ret = -ENOTSUP; - - if (port_id_is_invalid(res->port_id, ENABLED_WARN)) - return; - - port = &ports[res->port_id]; - /** Check if the port is not started **/ - if (port->port_status != RTE_PORT_STOPPED) { - fprintf(stderr, "Please stop port %d first\n", res->port_id); - return; - } - - ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list); - if (ret) - return; - -#ifdef RTE_NET_IXGBE - ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw); -#endif - - switch (ret) { - case 0: - break; - case -EINVAL: - fprintf(stderr, "invalid bandwidth\n"); - break; - case -ENODEV: - fprintf(stderr, "invalid port_id %d\n", res->port_id); - break; - case -ENOTSUP: - fprintf(stderr, "function not implemented\n"); - break; - default: - fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); - } -} - -cmdline_parse_inst_t cmd_tc_min_bw = { - .f = cmd_tc_min_bw_parsed, - .data = NULL, - .help_str = "set tc tx min-bandwidth ", - .tokens = { - (void *)&cmd_vf_tc_bw_set, - (void *)&cmd_vf_tc_bw_tc, - (void *)&cmd_vf_tc_bw_tx, - (void *)&cmd_vf_tc_bw_min_bw, - (void *)&cmd_vf_tc_bw_port_id, - (void *)&cmd_vf_tc_bw_bw_list, - NULL, - }, -}; - /* TC max bandwidth setting */ static void cmd_vf_tc_max_bw_parsed( @@ -16188,10 +15223,6 @@ static cmdline_parse_ctx_t builtin_ctx[] = { (cmdline_parse_inst_t *)&cmd_set_allmulti_mode_all, (cmdline_parse_inst_t *)&cmd_set_flush_rx, (cmdline_parse_inst_t *)&cmd_set_link_check, - (cmdline_parse_inst_t *)&cmd_set_bypass_mode, - (cmdline_parse_inst_t *)&cmd_set_bypass_event, - (cmdline_parse_inst_t *)&cmd_set_bypass_timeout, - (cmdline_parse_inst_t *)&cmd_show_bypass_config, (cmdline_parse_inst_t *)&cmd_vlan_offload, (cmdline_parse_inst_t *)&cmd_vlan_tpid, (cmdline_parse_inst_t *)&cmd_rx_vlan_filter_all, @@ -16307,11 +15338,6 @@ static cmdline_parse_ctx_t builtin_ctx[] = { (cmdline_parse_inst_t *)&cmd_set_vf_vlan_insert, (cmdline_parse_inst_t *)&cmd_set_tx_loopback, (cmdline_parse_inst_t *)&cmd_set_all_queues_drop_en, - (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en, - (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on, - (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off, - (cmdline_parse_inst_t *)&cmd_set_macsec_sc, - (cmdline_parse_inst_t *)&cmd_set_macsec_sa, (cmdline_parse_inst_t *)&cmd_set_vf_traffic, (cmdline_parse_inst_t *)&cmd_set_vf_rxmode, (cmdline_parse_inst_t *)&cmd_vf_rate_limit, @@ -16325,7 +15351,6 @@ static cmdline_parse_ctx_t builtin_ctx[] = { (cmdline_parse_inst_t *)&cmd_vf_tc_min_bw, (cmdline_parse_inst_t *)&cmd_vf_tc_max_bw, (cmdline_parse_inst_t *)&cmd_strict_link_prio, - (cmdline_parse_inst_t *)&cmd_tc_min_bw, (cmdline_parse_inst_t *)&cmd_set_vxlan, (cmdline_parse_inst_t *)&cmd_set_vxlan_tos_ttl, (cmdline_parse_inst_t *)&cmd_set_vxlan_with_vlan, @@ -16518,7 +15543,7 @@ prompt_exit(void) } } -static void +void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue) { if (id == (portid_t)RTE_PORT_ALL) { diff --git a/app/test-pmd/testpmd.c b/app/test-pmd/testpmd.c index 5bda46e32b..84e7996556 100644 --- a/app/test-pmd/testpmd.c +++ b/app/test-pmd/testpmd.c @@ -437,16 +437,6 @@ uint32_t event_print_mask = (UINT32_C(1) << RTE_ETH_EVENT_UNKNOWN) | */ int do_mlockall = 0; -/* - * NIC bypass mode configuration options. - */ - -#if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS -/* The NIC bypass watchdog timeout. */ -uint32_t bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF; -#endif - - #ifdef RTE_LIB_LATENCYSTATS /* @@ -3800,10 +3790,6 @@ init_port_config(void) if (ret != 0) return; -#if defined RTE_NET_IXGBE && defined RTE_LIBRTE_IXGBE_BYPASS - rte_pmd_ixgbe_bypass_init(pid); -#endif - if (lsc_interrupt && (*port->dev_info.dev_flags & RTE_ETH_DEV_INTR_LSC)) port->dev_conf.intr_conf.lsc = 1; if (rmv_interrupt && (*port->dev_info.dev_flags & RTE_ETH_DEV_INTR_RMV)) diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index 9058d21a07..48dff3b8a6 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -439,10 +439,6 @@ extern uint8_t hot_plug; /**< enable by "--hot-plug" parameter */ extern int do_mlockall; /**< set by "--mlockall" or "--no-mlockall" parameter */ extern uint8_t clear_ptypes; /**< disabled by set ptype cmd */ -#ifdef RTE_LIBRTE_IXGBE_BYPASS -extern uint32_t bypass_timeout; /**< Store the NIC bypass watchdog timeout */ -#endif - /* * Store specified sockets on which memory pool to be used by ports * is allocated. @@ -871,6 +867,7 @@ unsigned int parse_item_list(const char *str, const char *item_name, unsigned int max_items, unsigned int *parsed_items, int check_unique_values); void launch_args_parse(int argc, char** argv); +void cmd_reconfig_device_queue(portid_t id, uint8_t dev, uint8_t queue); void cmdline_read_from_file(const char *filename); int init_cmdline(void); void prompt(void); diff --git a/drivers/net/ixgbe/ixgbe_testpmd.c b/drivers/net/ixgbe/ixgbe_testpmd.c new file mode 100644 index 0000000000..1a4ffb69be --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_testpmd.c @@ -0,0 +1,1147 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2016 Intel Corporation. + */ + +#define RTE_LIBRTE_IXGBE_BYPASS + +#include +#include "ixgbe_ethdev.h" +#include "rte_pmd_ixgbe.h" + +#include +#include +#include + +#include "testpmd.h" + +static uint8_t +hexa_digit_to_value(char hexa_digit) +{ + if ((hexa_digit >= '0') && (hexa_digit <= '9')) + return (uint8_t)(hexa_digit - '0'); + if ((hexa_digit >= 'a') && (hexa_digit <= 'f')) + return (uint8_t)((hexa_digit - 'a') + 10); + if ((hexa_digit >= 'A') && (hexa_digit <= 'F')) + return (uint8_t)((hexa_digit - 'A') + 10); + /* Invalid hexa digit */ + return 0xFF; +} + +static uint8_t +parse_and_check_key_hexa_digit(char *key, int idx) +{ + uint8_t hexa_v; + + hexa_v = hexa_digit_to_value(key[idx]); + if (hexa_v == 0xFF) + fprintf(stderr, + "invalid key: character %c at position %d is not a valid hexa digit\n", + key[idx], idx); + return hexa_v; +} + +static int +vf_tc_min_bw_parse_bw_list(uint8_t *bw_list, + uint8_t *tc_num, + char *str) +{ + uint32_t size; + const char *p, *p0 = str; + char s[256]; + char *end; + char *str_fld[16]; + uint16_t i; + int ret; + + p = strchr(p0, '('); + if (p == NULL) { + fprintf(stderr, + "The bandwidth-list should be '(bw1, bw2, ...)'\n"); + return -1; + } + p++; + p0 = strchr(p, ')'); + if (p0 == NULL) { + fprintf(stderr, + "The bandwidth-list should be '(bw1, bw2, ...)'\n"); + return -1; + } + size = p0 - p; + if (size >= sizeof(s)) { + fprintf(stderr, + "The string size exceeds the internal buffer size\n"); + return -1; + } + snprintf(s, sizeof(s), "%.*s", size, p); + ret = rte_strsplit(s, sizeof(s), str_fld, 16, ','); + if (ret <= 0) { + fprintf(stderr, "Failed to get the bandwidth list.\n"); + return -1; + } + *tc_num = ret; + for (i = 0; i < ret; i++) + bw_list[i] = (uint8_t)strtoul(str_fld[i], &end, 0); + + return 0; +} + +/* The NIC bypass watchdog timeout. */ +uint32_t bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF; + +static inline bool +check_bypass_enabled(portid_t port_id) +{ + struct ixgbe_adapter *adapter; + + adapter = rte_eth_devices[port_id].data->dev_private; + if (adapter->bps.ops.bypass_rw == NULL) { + fprintf(stderr, "Bypass is not enabled on this port.\n"); + return false; + } + + return true; +} + +/* Enable bypass mode */ +struct cmd_config_bypass_result { + cmdline_fixed_string_t port; + cmdline_fixed_string_t config; + cmdline_fixed_string_t bypass; + portid_t port_id; + cmdline_fixed_string_t value; +}; + +static void +cmd_config_bypass_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_config_bypass_result *res = parsed_result; + portid_t port_id = res->port_id; + + if (ports[port_id].port_status == RTE_PORT_STARTED) { + fprintf(stderr, "Cannot change bypass configuration while port is started, please stop it and retry\n"); + return; + } + + if (strcmp(res->value, "on") == 0) + rte_pmd_ixgbe_bypass_init(port_id); +} + +static cmdline_parse_token_string_t cmd_config_bypass_port = + TOKEN_STRING_INITIALIZER(struct cmd_config_bypass_result, port, "port"); +static cmdline_parse_token_string_t cmd_config_bypass_config = + TOKEN_STRING_INITIALIZER(struct cmd_config_bypass_result, config, "config"); +static cmdline_parse_token_string_t cmd_config_bypass_bypass = + TOKEN_STRING_INITIALIZER(struct cmd_config_bypass_result, bypass, "bypass"); +static cmdline_parse_token_num_t cmd_config_bypass_port_id = + TOKEN_NUM_INITIALIZER(struct cmd_config_bypass_result, port_id, RTE_UINT16); +static cmdline_parse_token_string_t cmd_config_bypass_value = + TOKEN_STRING_INITIALIZER(struct cmd_config_bypass_result, value, "on#off"); + +static cmdline_parse_inst_t cmd_config_bypass = { + .f = cmd_config_bypass_parsed, + .data = NULL, + .help_str = "port config bypass on|off", + .tokens = { + (void *)&cmd_config_bypass_port, + (void *)&cmd_config_bypass_config, + (void *)&cmd_config_bypass_bypass, + (void *)&cmd_config_bypass_port_id, + (void *)&cmd_config_bypass_value, + NULL, + }, +}; + +/* *** SET NIC BYPASS MODE *** */ +struct cmd_set_bypass_mode_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t bypass; + cmdline_fixed_string_t mode; + cmdline_fixed_string_t value; + portid_t port_id; +}; + +static void +cmd_set_bypass_mode_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_set_bypass_mode_result *res = parsed_result; + uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; + portid_t port_id = res->port_id; + int32_t rc = -EINVAL; + + if (!check_bypass_enabled(port_id)) + return; + + if (!strcmp(res->value, "bypass")) + bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS; + else if (!strcmp(res->value, "isolate")) + bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE; + else + bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; + + /* Set the bypass mode for the relevant port. */ + rc = rte_pmd_ixgbe_bypass_state_set(port_id, &bypass_mode); + if (rc != 0) + fprintf(stderr, "\t Failed to set bypass mode for port = %d.\n", + port_id); +} + +static cmdline_parse_token_string_t cmd_setbypass_mode_set = + TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, + set, "set"); +static cmdline_parse_token_string_t cmd_setbypass_mode_bypass = + TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, + bypass, "bypass"); +static cmdline_parse_token_string_t cmd_setbypass_mode_mode = + TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, + mode, "mode"); +static cmdline_parse_token_string_t cmd_setbypass_mode_value = + TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_mode_result, + value, "normal#bypass#isolate"); +static cmdline_parse_token_num_t cmd_setbypass_mode_port = + TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_mode_result, + port_id, RTE_UINT16); + +static cmdline_parse_inst_t cmd_set_bypass_mode = { + .f = cmd_set_bypass_mode_parsed, + .help_str = "set bypass mode normal|bypass|isolate : " + "Set the NIC bypass mode for port_id", + .data = NULL, + .tokens = { + (void *)&cmd_setbypass_mode_set, + (void *)&cmd_setbypass_mode_bypass, + (void *)&cmd_setbypass_mode_mode, + (void *)&cmd_setbypass_mode_value, + (void *)&cmd_setbypass_mode_port, + NULL, + }, +}; + +/* *** SET NIC BYPASS EVENT *** */ +struct cmd_set_bypass_event_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t bypass; + cmdline_fixed_string_t event; + cmdline_fixed_string_t event_value; + cmdline_fixed_string_t mode; + cmdline_fixed_string_t mode_value; + portid_t port_id; +}; + +static void +cmd_set_bypass_event_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + int32_t rc = -EINVAL; + struct cmd_set_bypass_event_result *res = parsed_result; + portid_t port_id = res->port_id; + uint32_t bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE; + uint32_t bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; + + if (!check_bypass_enabled(port_id)) + return; + + if (!strcmp(res->event_value, "timeout")) + bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT; + else if (!strcmp(res->event_value, "os_on")) + bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_ON; + else if (!strcmp(res->event_value, "os_off")) + bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_OS_OFF; + else if (!strcmp(res->event_value, "power_on")) + bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_ON; + else if (!strcmp(res->event_value, "power_off")) + bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_POWER_OFF; + else + bypass_event = RTE_PMD_IXGBE_BYPASS_EVENT_NONE; + + if (!strcmp(res->mode_value, "bypass")) + bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_BYPASS; + else if (!strcmp(res->mode_value, "isolate")) + bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_ISOLATE; + else + bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NORMAL; + + /* Set the watchdog timeout. */ + if (bypass_event == RTE_PMD_IXGBE_BYPASS_EVENT_TIMEOUT) { + rc = -EINVAL; + if (RTE_PMD_IXGBE_BYPASS_TMT_VALID(bypass_timeout)) { + rc = rte_pmd_ixgbe_bypass_wd_timeout_store(port_id, + bypass_timeout); + } + if (rc != 0) { + fprintf(stderr, + "Failed to set timeout value %u for port %d, errto code: %d.\n", + bypass_timeout, port_id, rc); + } + } + + /* Set the bypass event to transition to bypass mode. */ + rc = rte_pmd_ixgbe_bypass_event_store(port_id, bypass_event, + bypass_mode); + if (rc != 0) + fprintf(stderr, "\t Failed to set bypass event for port = %d.\n", + port_id); +} + +static cmdline_parse_token_string_t cmd_setbypass_event_set = + TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, + set, "set"); +static cmdline_parse_token_string_t cmd_setbypass_event_bypass = + TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, + bypass, "bypass"); +static cmdline_parse_token_string_t cmd_setbypass_event_event = + TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, + event, "event"); +static cmdline_parse_token_string_t cmd_setbypass_event_event_value = + TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, + event_value, "none#timeout#os_off#os_on#power_on#power_off"); +static cmdline_parse_token_string_t cmd_setbypass_event_mode = + TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, + mode, "mode"); +static cmdline_parse_token_string_t cmd_setbypass_event_mode_value = + TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_event_result, + mode_value, "normal#bypass#isolate"); +static cmdline_parse_token_num_t cmd_setbypass_event_port = + TOKEN_NUM_INITIALIZER(struct cmd_set_bypass_event_result, + port_id, RTE_UINT16); + +static cmdline_parse_inst_t cmd_set_bypass_event = { + .f = cmd_set_bypass_event_parsed, + .help_str = "set bypass event none|timeout|os_on|os_off|power_on|" + "power_off mode normal|bypass|isolate : " + "Set the NIC bypass event mode for port_id", + .data = NULL, + .tokens = { + (void *)&cmd_setbypass_event_set, + (void *)&cmd_setbypass_event_bypass, + (void *)&cmd_setbypass_event_event, + (void *)&cmd_setbypass_event_event_value, + (void *)&cmd_setbypass_event_mode, + (void *)&cmd_setbypass_event_mode_value, + (void *)&cmd_setbypass_event_port, + NULL, + }, +}; + + +/* *** SET NIC BYPASS TIMEOUT *** */ +struct cmd_set_bypass_timeout_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t bypass; + cmdline_fixed_string_t timeout; + cmdline_fixed_string_t value; +}; + +static void +cmd_set_bypass_timeout_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_set_bypass_timeout_result *res = parsed_result; + + if (!strcmp(res->value, "1.5")) + bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_1_5_SEC; + else if (!strcmp(res->value, "2")) + bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_2_SEC; + else if (!strcmp(res->value, "3")) + bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_3_SEC; + else if (!strcmp(res->value, "4")) + bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_4_SEC; + else if (!strcmp(res->value, "8")) + bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_8_SEC; + else if (!strcmp(res->value, "16")) + bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_16_SEC; + else if (!strcmp(res->value, "32")) + bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_32_SEC; + else + bypass_timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF; +} + +static cmdline_parse_token_string_t cmd_setbypass_timeout_set = + TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, + set, "set"); +static cmdline_parse_token_string_t cmd_setbypass_timeout_bypass = + TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, + bypass, "bypass"); +static cmdline_parse_token_string_t cmd_setbypass_timeout_timeout = + TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, + timeout, "timeout"); +static cmdline_parse_token_string_t cmd_setbypass_timeout_value = + TOKEN_STRING_INITIALIZER(struct cmd_set_bypass_timeout_result, + value, "0#1.5#2#3#4#8#16#32"); + +static cmdline_parse_inst_t cmd_set_bypass_timeout = { + .f = cmd_set_bypass_timeout_parsed, + .help_str = "set bypass timeout 0|1.5|2|3|4|8|16|32: " + "Set the NIC bypass watchdog timeout in seconds", + .data = NULL, + .tokens = { + (void *)&cmd_setbypass_timeout_set, + (void *)&cmd_setbypass_timeout_bypass, + (void *)&cmd_setbypass_timeout_timeout, + (void *)&cmd_setbypass_timeout_value, + NULL, + }, +}; + +/* *** SHOW NIC BYPASS MODE *** */ +struct cmd_show_bypass_config_result { + cmdline_fixed_string_t show; + cmdline_fixed_string_t bypass; + cmdline_fixed_string_t config; + portid_t port_id; +}; + +static void +cmd_show_bypass_config_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_show_bypass_config_result *res = parsed_result; + portid_t port_id = res->port_id; + int rc = -EINVAL; + uint32_t event_mode; + uint32_t bypass_mode; + uint32_t timeout = bypass_timeout; + unsigned int i; + + static const char * const timeouts[RTE_PMD_IXGBE_BYPASS_TMT_NUM] = { + "off", "1.5", "2", "3", "4", "8", "16", "32" + }; + static const char * const modes[RTE_PMD_IXGBE_BYPASS_MODE_NUM] = { + "UNKNOWN", "normal", "bypass", "isolate" + }; + static const char * const events[RTE_PMD_IXGBE_BYPASS_EVENT_NUM] = { + "NONE", + "OS/board on", + "power supply on", + "OS/board off", + "power supply off", + "timeout"}; + + if (!check_bypass_enabled(port_id)) + return; + + /* Display the bypass mode.*/ + if (rte_pmd_ixgbe_bypass_state_show(port_id, &bypass_mode) != 0) { + fprintf(stderr, "\tFailed to get bypass mode for port = %d\n", + port_id); + return; + } + if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(bypass_mode)) + bypass_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE; + + printf("\tbypass mode = %s\n", modes[bypass_mode]); + + /* Display the bypass timeout.*/ + if (!RTE_PMD_IXGBE_BYPASS_TMT_VALID(timeout)) + timeout = RTE_PMD_IXGBE_BYPASS_TMT_OFF; + + printf("\tbypass timeout = %s\n", timeouts[timeout]); + + /* Display the bypass events and associated modes. */ + for (i = RTE_PMD_IXGBE_BYPASS_EVENT_START; i < RTE_DIM(events); i++) { + if (rte_pmd_ixgbe_bypass_event_show(port_id, i, &event_mode)) { + fprintf(stderr, + "\tFailed to get bypass mode for event = %s\n", + events[i]); + } else { + if (!RTE_PMD_IXGBE_BYPASS_MODE_VALID(event_mode)) + event_mode = RTE_PMD_IXGBE_BYPASS_MODE_NONE; + + printf("\tbypass event: %-16s = %s\n", events[i], + modes[event_mode]); + } + } + if (rc != 0) + fprintf(stderr, + "\tFailed to get bypass configuration for port = %d\n", + port_id); +} + +static cmdline_parse_token_string_t cmd_showbypass_config_show = + TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, + show, "show"); +static cmdline_parse_token_string_t cmd_showbypass_config_bypass = + TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, + bypass, "bypass"); +static cmdline_parse_token_string_t cmd_showbypass_config_config = + TOKEN_STRING_INITIALIZER(struct cmd_show_bypass_config_result, + config, "config"); +static cmdline_parse_token_num_t cmd_showbypass_config_port = + TOKEN_NUM_INITIALIZER(struct cmd_show_bypass_config_result, + port_id, RTE_UINT16); + +static cmdline_parse_inst_t cmd_show_bypass_config = { + .f = cmd_show_bypass_config_parsed, + .help_str = "show bypass config : " + "Show the NIC bypass config for port_id", + .data = NULL, + .tokens = { + (void *)&cmd_showbypass_config_show, + (void *)&cmd_showbypass_config_bypass, + (void *)&cmd_showbypass_config_config, + (void *)&cmd_showbypass_config_port, + NULL, + }, +}; + +/* Common result structure for vf split drop enable */ +struct cmd_vf_split_drop_en_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t vf; + cmdline_fixed_string_t split; + cmdline_fixed_string_t drop; + portid_t port_id; + uint16_t vf_id; + cmdline_fixed_string_t on_off; +}; + +/* Common CLI fields for vf split drop enable disable */ +static cmdline_parse_token_string_t cmd_vf_split_drop_en_set = + TOKEN_STRING_INITIALIZER + (struct cmd_vf_split_drop_en_result, + set, "set"); +static cmdline_parse_token_string_t cmd_vf_split_drop_en_vf = + TOKEN_STRING_INITIALIZER + (struct cmd_vf_split_drop_en_result, + vf, "vf"); +static cmdline_parse_token_string_t cmd_vf_split_drop_en_split = + TOKEN_STRING_INITIALIZER + (struct cmd_vf_split_drop_en_result, + split, "split"); +static cmdline_parse_token_string_t cmd_vf_split_drop_en_drop = + TOKEN_STRING_INITIALIZER + (struct cmd_vf_split_drop_en_result, + drop, "drop"); +static cmdline_parse_token_num_t cmd_vf_split_drop_en_port_id = + TOKEN_NUM_INITIALIZER + (struct cmd_vf_split_drop_en_result, + port_id, RTE_UINT16); +static cmdline_parse_token_num_t cmd_vf_split_drop_en_vf_id = + TOKEN_NUM_INITIALIZER + (struct cmd_vf_split_drop_en_result, + vf_id, RTE_UINT16); +static cmdline_parse_token_string_t cmd_vf_split_drop_en_on_off = + TOKEN_STRING_INITIALIZER + (struct cmd_vf_split_drop_en_result, + on_off, "on#off"); + +static void +cmd_set_vf_split_drop_en_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_vf_split_drop_en_result *res = parsed_result; + int ret = -ENOTSUP; + int is_on = (strcmp(res->on_off, "on") == 0) ? 1 : 0; + + if (port_id_is_invalid(res->port_id, ENABLED_WARN)) + return; + + ret = rte_pmd_ixgbe_set_vf_split_drop_en(res->port_id, res->vf_id, + is_on); + switch (ret) { + case 0: + break; + case -EINVAL: + fprintf(stderr, "invalid vf_id %d or is_on %d\n", + res->vf_id, is_on); + break; + case -ENODEV: + fprintf(stderr, "invalid port_id %d\n", res->port_id); + break; + case -ENOTSUP: + fprintf(stderr, "not supported on port %d\n", res->port_id); + break; + default: + fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); + } +} + +static cmdline_parse_inst_t cmd_set_vf_split_drop_en = { + .f = cmd_set_vf_split_drop_en_parsed, + .data = NULL, + .help_str = "set vf split drop on|off", + .tokens = { + (void *)&cmd_vf_split_drop_en_set, + (void *)&cmd_vf_split_drop_en_vf, + (void *)&cmd_vf_split_drop_en_split, + (void *)&cmd_vf_split_drop_en_drop, + (void *)&cmd_vf_split_drop_en_port_id, + (void *)&cmd_vf_split_drop_en_vf_id, + (void *)&cmd_vf_split_drop_en_on_off, + NULL, + }, +}; + +/* MACsec configuration */ + +/* Common result structure for MACsec offload enable */ +struct cmd_macsec_offload_on_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t macsec; + cmdline_fixed_string_t offload; + portid_t port_id; + cmdline_fixed_string_t on; + cmdline_fixed_string_t encrypt; + cmdline_fixed_string_t en_on_off; + cmdline_fixed_string_t replay_protect; + cmdline_fixed_string_t rp_on_off; +}; + +/* Common CLI fields for MACsec offload disable */ +static cmdline_parse_token_string_t cmd_macsec_offload_on_set = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_offload_on_result, + set, "set"); +static cmdline_parse_token_string_t cmd_macsec_offload_on_macsec = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_offload_on_result, + macsec, "macsec"); +static cmdline_parse_token_string_t cmd_macsec_offload_on_offload = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_offload_on_result, + offload, "offload"); +static cmdline_parse_token_num_t cmd_macsec_offload_on_port_id = + TOKEN_NUM_INITIALIZER + (struct cmd_macsec_offload_on_result, + port_id, RTE_UINT16); +static cmdline_parse_token_string_t cmd_macsec_offload_on_on = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_offload_on_result, + on, "on"); +static cmdline_parse_token_string_t cmd_macsec_offload_on_encrypt = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_offload_on_result, + encrypt, "encrypt"); +static cmdline_parse_token_string_t cmd_macsec_offload_on_en_on_off = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_offload_on_result, + en_on_off, "on#off"); +static cmdline_parse_token_string_t cmd_macsec_offload_on_replay_protect = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_offload_on_result, + replay_protect, "replay-protect"); +static cmdline_parse_token_string_t cmd_macsec_offload_on_rp_on_off = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_offload_on_result, + rp_on_off, "on#off"); + +static void +cmd_set_macsec_offload_on_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_macsec_offload_on_result *res = parsed_result; + int ret = -ENOTSUP; + portid_t port_id = res->port_id; + int en = (strcmp(res->en_on_off, "on") == 0) ? 1 : 0; + int rp = (strcmp(res->rp_on_off, "on") == 0) ? 1 : 0; + struct rte_eth_dev_info dev_info; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + if (!port_is_stopped(port_id)) { + fprintf(stderr, "Please stop port %d first\n", port_id); + return; + } + + ret = eth_dev_info_get_print_err(port_id, &dev_info); + if (ret != 0) + return; + + if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) + ret = rte_pmd_ixgbe_macsec_enable(port_id, en, rp); + + switch (ret) { + case 0: + ports[port_id].dev_conf.txmode.offloads |= + RTE_ETH_TX_OFFLOAD_MACSEC_INSERT; + cmd_reconfig_device_queue(port_id, 1, 1); + break; + case -ENODEV: + fprintf(stderr, "invalid port_id %d\n", port_id); + break; + case -ENOTSUP: + fprintf(stderr, "not supported on port %d\n", port_id); + break; + default: + fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); + } +} + +static cmdline_parse_inst_t cmd_set_macsec_offload_on = { + .f = cmd_set_macsec_offload_on_parsed, + .data = NULL, + .help_str = "set macsec offload on " + "encrypt on|off replay-protect on|off", + .tokens = { + (void *)&cmd_macsec_offload_on_set, + (void *)&cmd_macsec_offload_on_macsec, + (void *)&cmd_macsec_offload_on_offload, + (void *)&cmd_macsec_offload_on_port_id, + (void *)&cmd_macsec_offload_on_on, + (void *)&cmd_macsec_offload_on_encrypt, + (void *)&cmd_macsec_offload_on_en_on_off, + (void *)&cmd_macsec_offload_on_replay_protect, + (void *)&cmd_macsec_offload_on_rp_on_off, + NULL, + }, +}; + +/* Common result structure for MACsec offload disable */ +struct cmd_macsec_offload_off_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t macsec; + cmdline_fixed_string_t offload; + portid_t port_id; + cmdline_fixed_string_t off; +}; + +/* Common CLI fields for MACsec offload disable */ +static cmdline_parse_token_string_t cmd_macsec_offload_off_set = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_offload_off_result, + set, "set"); +static cmdline_parse_token_string_t cmd_macsec_offload_off_macsec = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_offload_off_result, + macsec, "macsec"); +static cmdline_parse_token_string_t cmd_macsec_offload_off_offload = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_offload_off_result, + offload, "offload"); +static cmdline_parse_token_num_t cmd_macsec_offload_off_port_id = + TOKEN_NUM_INITIALIZER + (struct cmd_macsec_offload_off_result, + port_id, RTE_UINT16); +static cmdline_parse_token_string_t cmd_macsec_offload_off_off = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_offload_off_result, + off, "off"); + +static void +cmd_set_macsec_offload_off_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_macsec_offload_off_result *res = parsed_result; + int ret = -ENOTSUP; + struct rte_eth_dev_info dev_info; + portid_t port_id = res->port_id; + + if (port_id_is_invalid(port_id, ENABLED_WARN)) + return; + if (!port_is_stopped(port_id)) { + fprintf(stderr, "Please stop port %d first\n", port_id); + return; + } + + ret = eth_dev_info_get_print_err(port_id, &dev_info); + if (ret != 0) + return; + + if (dev_info.tx_offload_capa & RTE_ETH_TX_OFFLOAD_MACSEC_INSERT) + ret = rte_pmd_ixgbe_macsec_disable(port_id); + switch (ret) { + case 0: + ports[port_id].dev_conf.txmode.offloads &= + ~RTE_ETH_TX_OFFLOAD_MACSEC_INSERT; + cmd_reconfig_device_queue(port_id, 1, 1); + break; + case -ENODEV: + fprintf(stderr, "invalid port_id %d\n", port_id); + break; + case -ENOTSUP: + fprintf(stderr, "not supported on port %d\n", port_id); + break; + default: + fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); + } +} + +static cmdline_parse_inst_t cmd_set_macsec_offload_off = { + .f = cmd_set_macsec_offload_off_parsed, + .data = NULL, + .help_str = "set macsec offload off", + .tokens = { + (void *)&cmd_macsec_offload_off_set, + (void *)&cmd_macsec_offload_off_macsec, + (void *)&cmd_macsec_offload_off_offload, + (void *)&cmd_macsec_offload_off_port_id, + (void *)&cmd_macsec_offload_off_off, + NULL, + }, +}; + +/* Common result structure for MACsec secure connection configure */ +struct cmd_macsec_sc_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t macsec; + cmdline_fixed_string_t sc; + cmdline_fixed_string_t tx_rx; + portid_t port_id; + struct rte_ether_addr mac; + uint16_t pi; +}; + +/* Common CLI fields for MACsec secure connection configure */ +static cmdline_parse_token_string_t cmd_macsec_sc_set = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_sc_result, + set, "set"); +static cmdline_parse_token_string_t cmd_macsec_sc_macsec = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_sc_result, + macsec, "macsec"); +static cmdline_parse_token_string_t cmd_macsec_sc_sc = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_sc_result, + sc, "sc"); +static cmdline_parse_token_string_t cmd_macsec_sc_tx_rx = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_sc_result, + tx_rx, "tx#rx"); +static cmdline_parse_token_num_t cmd_macsec_sc_port_id = + TOKEN_NUM_INITIALIZER + (struct cmd_macsec_sc_result, + port_id, RTE_UINT16); +static cmdline_parse_token_etheraddr_t cmd_macsec_sc_mac = + TOKEN_ETHERADDR_INITIALIZER + (struct cmd_macsec_sc_result, + mac); +static cmdline_parse_token_num_t cmd_macsec_sc_pi = + TOKEN_NUM_INITIALIZER + (struct cmd_macsec_sc_result, + pi, RTE_UINT16); + +static void +cmd_set_macsec_sc_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_macsec_sc_result *res = parsed_result; + int ret = -ENOTSUP; + int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0; + + ret = is_tx ? + rte_pmd_ixgbe_macsec_config_txsc(res->port_id, + res->mac.addr_bytes) : + rte_pmd_ixgbe_macsec_config_rxsc(res->port_id, + res->mac.addr_bytes, res->pi); + switch (ret) { + case 0: + break; + case -ENODEV: + fprintf(stderr, "invalid port_id %d\n", res->port_id); + break; + case -ENOTSUP: + fprintf(stderr, "not supported on port %d\n", res->port_id); + break; + default: + fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); + } +} + +static cmdline_parse_inst_t cmd_set_macsec_sc = { + .f = cmd_set_macsec_sc_parsed, + .data = NULL, + .help_str = "set macsec sc tx|rx ", + .tokens = { + (void *)&cmd_macsec_sc_set, + (void *)&cmd_macsec_sc_macsec, + (void *)&cmd_macsec_sc_sc, + (void *)&cmd_macsec_sc_tx_rx, + (void *)&cmd_macsec_sc_port_id, + (void *)&cmd_macsec_sc_mac, + (void *)&cmd_macsec_sc_pi, + NULL, + }, +}; + +/* Common result structure for MACsec secure connection configure */ +struct cmd_macsec_sa_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t macsec; + cmdline_fixed_string_t sa; + cmdline_fixed_string_t tx_rx; + portid_t port_id; + uint8_t idx; + uint8_t an; + uint32_t pn; + cmdline_fixed_string_t key; +}; + +/* Common CLI fields for MACsec secure connection configure */ +static cmdline_parse_token_string_t cmd_macsec_sa_set = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_sa_result, + set, "set"); +static cmdline_parse_token_string_t cmd_macsec_sa_macsec = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_sa_result, + macsec, "macsec"); +static cmdline_parse_token_string_t cmd_macsec_sa_sa = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_sa_result, + sa, "sa"); +static cmdline_parse_token_string_t cmd_macsec_sa_tx_rx = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_sa_result, + tx_rx, "tx#rx"); +static cmdline_parse_token_num_t cmd_macsec_sa_port_id = + TOKEN_NUM_INITIALIZER + (struct cmd_macsec_sa_result, + port_id, RTE_UINT16); +static cmdline_parse_token_num_t cmd_macsec_sa_idx = + TOKEN_NUM_INITIALIZER + (struct cmd_macsec_sa_result, + idx, RTE_UINT8); +static cmdline_parse_token_num_t cmd_macsec_sa_an = + TOKEN_NUM_INITIALIZER + (struct cmd_macsec_sa_result, + an, RTE_UINT8); +static cmdline_parse_token_num_t cmd_macsec_sa_pn = + TOKEN_NUM_INITIALIZER + (struct cmd_macsec_sa_result, + pn, RTE_UINT32); +static cmdline_parse_token_string_t cmd_macsec_sa_key = + TOKEN_STRING_INITIALIZER + (struct cmd_macsec_sa_result, + key, NULL); + +static void +cmd_set_macsec_sa_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_macsec_sa_result *res = parsed_result; + int ret = -ENOTSUP; + int is_tx = (strcmp(res->tx_rx, "tx") == 0) ? 1 : 0; + uint8_t key[16] = { 0 }; + uint8_t xdgt0; + uint8_t xdgt1; + int key_len; + int i; + + key_len = strlen(res->key) / 2; + if (key_len > 16) + key_len = 16; + + for (i = 0; i < key_len; i++) { + xdgt0 = parse_and_check_key_hexa_digit(res->key, (i * 2)); + if (xdgt0 == 0xFF) + return; + xdgt1 = parse_and_check_key_hexa_digit(res->key, (i * 2) + 1); + if (xdgt1 == 0xFF) + return; + key[i] = (uint8_t)((xdgt0 * 16) + xdgt1); + } + + ret = is_tx ? + rte_pmd_ixgbe_macsec_select_txsa(res->port_id, + res->idx, res->an, res->pn, key) : + rte_pmd_ixgbe_macsec_select_rxsa(res->port_id, + res->idx, res->an, res->pn, key); + + switch (ret) { + case 0: + break; + case -EINVAL: + fprintf(stderr, "invalid idx %d or an %d\n", res->idx, res->an); + break; + case -ENODEV: + fprintf(stderr, "invalid port_id %d\n", res->port_id); + break; + case -ENOTSUP: + fprintf(stderr, "not supported on port %d\n", res->port_id); + break; + default: + fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); + } +} + +struct cmd_vf_tc_bw_result { + cmdline_fixed_string_t set; + cmdline_fixed_string_t tc; + cmdline_fixed_string_t tx; + cmdline_fixed_string_t min_bw; + portid_t port_id; + cmdline_fixed_string_t bw_list; +}; + +static cmdline_parse_token_string_t cmd_vf_tc_bw_set = + TOKEN_STRING_INITIALIZER + (struct cmd_vf_tc_bw_result, + set, "set"); +static cmdline_parse_token_string_t cmd_vf_tc_bw_tc = + TOKEN_STRING_INITIALIZER + (struct cmd_vf_tc_bw_result, + tc, "tc"); +static cmdline_parse_token_string_t cmd_vf_tc_bw_tx = + TOKEN_STRING_INITIALIZER + (struct cmd_vf_tc_bw_result, + tx, "tx"); +static cmdline_parse_token_string_t cmd_vf_tc_bw_min_bw = + TOKEN_STRING_INITIALIZER + (struct cmd_vf_tc_bw_result, + min_bw, "min-bandwidth"); +static cmdline_parse_token_num_t cmd_vf_tc_bw_port_id = + TOKEN_NUM_INITIALIZER + (struct cmd_vf_tc_bw_result, + port_id, RTE_UINT16); +static cmdline_parse_token_string_t cmd_vf_tc_bw_bw_list = + TOKEN_STRING_INITIALIZER + (struct cmd_vf_tc_bw_result, + bw_list, NULL); + +static cmdline_parse_inst_t cmd_set_macsec_sa = { + .f = cmd_set_macsec_sa_parsed, + .data = NULL, + .help_str = "set macsec sa tx|rx ", + .tokens = { + (void *)&cmd_macsec_sa_set, + (void *)&cmd_macsec_sa_macsec, + (void *)&cmd_macsec_sa_sa, + (void *)&cmd_macsec_sa_tx_rx, + (void *)&cmd_macsec_sa_port_id, + (void *)&cmd_macsec_sa_idx, + (void *)&cmd_macsec_sa_an, + (void *)&cmd_macsec_sa_pn, + (void *)&cmd_macsec_sa_key, + NULL, + }, +}; + +static void +cmd_tc_min_bw_parsed(void *parsed_result, + __rte_unused struct cmdline *cl, + __rte_unused void *data) +{ + struct cmd_vf_tc_bw_result *res = parsed_result; + struct rte_port *port; + uint8_t tc_num; + uint8_t bw[16]; + int ret = -ENOTSUP; + + if (port_id_is_invalid(res->port_id, ENABLED_WARN)) + return; + + port = &ports[res->port_id]; + /** Check if the port is not started **/ + if (port->port_status != RTE_PORT_STOPPED) { + fprintf(stderr, "Please stop port %d first\n", res->port_id); + return; + } + + ret = vf_tc_min_bw_parse_bw_list(bw, &tc_num, res->bw_list); + if (ret) + return; + + ret = rte_pmd_ixgbe_set_tc_bw_alloc(res->port_id, tc_num, bw); + + switch (ret) { + case 0: + break; + case -EINVAL: + fprintf(stderr, "invalid bandwidth\n"); + break; + case -ENODEV: + fprintf(stderr, "invalid port_id %d\n", res->port_id); + break; + case -ENOTSUP: + fprintf(stderr, "function not implemented\n"); + break; + default: + fprintf(stderr, "programming error: (%s)\n", strerror(-ret)); + } +} + +static cmdline_parse_inst_t cmd_tc_min_bw = { + .f = cmd_tc_min_bw_parsed, + .data = NULL, + .help_str = "set tc tx min-bandwidth ", + .tokens = { + (void *)&cmd_vf_tc_bw_set, + (void *)&cmd_vf_tc_bw_tc, + (void *)&cmd_vf_tc_bw_tx, + (void *)&cmd_vf_tc_bw_min_bw, + (void *)&cmd_vf_tc_bw_port_id, + (void *)&cmd_vf_tc_bw_bw_list, + NULL, + }, +}; + +static struct testpmd_cmdline_parser driver_parser = { + .ctx = (cmdline_parse_ctx_t[]) { + (cmdline_parse_inst_t *)&cmd_config_bypass, + (cmdline_parse_inst_t *)&cmd_set_bypass_mode, + (cmdline_parse_inst_t *)&cmd_set_bypass_event, + (cmdline_parse_inst_t *)&cmd_set_bypass_timeout, + (cmdline_parse_inst_t *)&cmd_show_bypass_config, + (cmdline_parse_inst_t *)&cmd_set_vf_split_drop_en, + (cmdline_parse_inst_t *)&cmd_set_macsec_offload_on, + (cmdline_parse_inst_t *)&cmd_set_macsec_offload_off, + (cmdline_parse_inst_t *)&cmd_set_macsec_sc, + (cmdline_parse_inst_t *)&cmd_set_macsec_sa, + (cmdline_parse_inst_t *)&cmd_tc_min_bw, + NULL + }, + .help = { + "port config bypass (port_id) (on|off)\n", + " Enable/disable bypass before starting the port\n", + + "set bypass mode (normal|bypass|isolate) (port_id)\n" + " Set the bypass mode for the lowest port on bypass enabled" + " NIC.\n", + + "set bypass event (timeout|os_on|os_off|power_on|power_off) " + "mode (normal|bypass|isolate) (port_id)\n" + " Set the event required to initiate specified bypass mode for" + " the lowest port on a bypass enabled NIC where:\n" + " timeout = enable bypass after watchdog timeout.\n" + " os_on = enable bypass when OS/board is powered on.\n" + " os_off = enable bypass when OS/board is powered off.\n" + " power_on = enable bypass when power supply is turned on.\n" + " power_off = enable bypass when power supply is turned off." + "\n", + + "set bypass timeout (0|1.5|2|3|4|8|16|32)\n" + " Set the bypass watchdog timeout to 'n' seconds" + " where 0 = instant.\n", + + "show bypass config (port_id)\n" + " Show the bypass configuration for a bypass enabled NIC" + " using the lowest port on the NIC.\n", + + "set vf split drop (port_id) (vf_id) (on|off)\n" + " Set split drop enable bit for a VF from the PF.\n", + + "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n" + " Enable MACsec offload.\n", + + "set macsec offload (port_id) off\n" + " Disable MACsec offload.\n", + + "set macsec sc (tx|rx) (port_id) (mac) (pi)\n" + " Configure MACsec secure connection (SC).\n", + + "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n" + " Configure MACsec secure association (SA).\n", + + "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n" + " Set all TCs' min bandwidth(%%) for all PF and VFs.\n", + + NULL + }, +}; + +RTE_INIT(ixgbe_testpmd) +{ + testpmd_add_commands(&driver_parser); +} diff --git a/drivers/net/ixgbe/meson.build b/drivers/net/ixgbe/meson.build index 162f8d5f46..a18908ef7c 100644 --- a/drivers/net/ixgbe/meson.build +++ b/drivers/net/ixgbe/meson.build @@ -20,6 +20,8 @@ sources = files( 'rte_pmd_ixgbe.c', ) +testpmd_sources = files('ixgbe_testpmd.c') + deps += ['hash', 'security'] if arch_subdir == 'x86'