From patchwork Mon May 23 07:10:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Marchand X-Patchwork-Id: 111598 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 DFAE7A04FD; Mon, 23 May 2022 09:11:45 +0200 (CEST) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 20C1041611; Mon, 23 May 2022 09:11:17 +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 5284F40041 for ; Mon, 23 May 2022 09:11:15 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1653289874; 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=nXjFpa2NyK1ONgWCA9WiOROW+gHc5mn7l/LvTjFMSfI=; b=PIVgZEFedzVfzquRUdgylAo4RXFb/mNaN2UDqttBktdW5AYIlLlj7jLI2KDl4K+T2CMn4/ JmYtwQJEDRE/t5loLuIQOU8/Dw9ihuzjuwbAqXEfxjAdEFjte1mgu+9ymV9d8rGTVkY61z Wh5Oiv2fedkWwbc594a8XPVk5ssetco= 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-99-5GhbPun4Mpe_EB2NGfEGVA-1; Mon, 23 May 2022 03:11:11 -0400 X-MC-Unique: 5GhbPun4Mpe_EB2NGfEGVA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E1AC285A5B5; Mon, 23 May 2022 07:11:10 +0000 (UTC) Received: from fchome.home (unknown [10.40.192.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id 538DE1415100; Mon, 23 May 2022 07:11:08 +0000 (UTC) From: David Marchand To: dev@dpdk.org Cc: thomas@monjalon.net, andrew.rybchenko@oktetlabs.ru, ferruh.yigit@xilinx.com, Xiaoyun Li , Aman Singh , Yuying Zhang , Qiming Yang , Wenjun Wu Subject: [PATCH 6/6] net/ixgbe: move testpmd commands Date: Mon, 23 May 2022 09:10:31 +0200 Message-Id: <20220523071031.1868862-7-david.marchand@redhat.com> In-Reply-To: <20220523071031.1868862-1-david.marchand@redhat.com> References: <20220513075718.18674-1-david.marchand@redhat.com> <20220523071031.1868862-1-david.marchand@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.7 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 --- Changes since RFC v2: - dropped bypass commands, - updated documentation, - fixed some indent, --- app/test-pmd/cmdline.c | 688 +------------------- app/test-pmd/testpmd.h | 1 + doc/guides/nics/ixgbe.rst | 51 ++ doc/guides/testpmd_app_ug/testpmd_funcs.rst | 47 +- drivers/net/ixgbe/ixgbe_testpmd.c | 657 +++++++++++++++++++ drivers/net/ixgbe/meson.build | 2 + 6 files changed, 713 insertions(+), 733 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 e496fa1d14..75e6c805d2 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_commands) commands_head = TAILQ_HEAD_INITIALIZER(commands_head); -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; @@ -335,24 +333,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" - "vlan set stripq (on|off) (port_id,queue_id)\n" " Set the VLAN strip for a queue on a port.\n\n" @@ -365,8 +348,6 @@ static void cmd_help_long_parsed(void *parsed_result, "set vf vlan antispoof (port_id) (vf_id) (on|off)\n" " Set VLAN antispoof for a VF from the PF.\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" @@ -9644,100 +9625,6 @@ static 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 */ -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; - -#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)); - } -} - -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, - }, -}; - /* vf mac address configuration */ /* Common result structure for vf mac address */ @@ -9842,573 +9729,6 @@ static 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 */ -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) { -#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)); - } -} - -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) { -#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)); - } -} - -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; - -#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)); - } -} - -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); - } - -#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)); - } -} - -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, - }, -}; - -/* Common definition of VF and TC TX bandwidth configuration */ -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 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; -} - -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)); - } -} - -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, - }, -}; - /** Set VXLAN encapsulation details */ struct cmd_set_vxlan_result { cmdline_fixed_string_t set; @@ -13904,17 +13224,11 @@ 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, (cmdline_parse_inst_t *)&cmd_vf_rxvlan_filter, (cmdline_parse_inst_t *)&cmd_set_vf_mac_addr, - (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, @@ -14093,7 +13407,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.h b/app/test-pmd/testpmd.h index 8252daef95..7eb147c611 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -867,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/doc/guides/nics/ixgbe.rst b/doc/guides/nics/ixgbe.rst index 82fa453fa2..893ce71baa 100644 --- a/doc/guides/nics/ixgbe.rst +++ b/doc/guides/nics/ixgbe.rst @@ -317,6 +317,57 @@ the VFs which are required.:: Currently hot-plugging of representor ports is not supported so all required representors must be specified on the creation of the PF. +Testpmd driver specific commands +-------------------------------- + +Some ixgbe driver specific features are integrated in testpmd. + +set split drop enable (for VF) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +Set split drop enable bit for VF from PF:: + + testpmd> set vf split drop (port_id) (vf_id) (on|off) + +set macsec offload +~~~~~~~~~~~~~~~~~~ + +Enable/disable MACsec offload:: + + testpmd> set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off) + testpmd> set macsec offload (port_id) off + +set macsec sc +~~~~~~~~~~~~~ + +Configure MACsec secure connection (SC):: + + testpmd> set macsec sc (tx|rx) (port_id) (mac) (pi) + +.. note:: + + The pi argument is ignored for tx. + Check the NIC Datasheet for hardware limitations. + +set macsec sa +~~~~~~~~~~~~~ + +Configure MACsec secure association (SA):: + + testpmd> set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key) + +.. note:: + + The IDX value must be 0 or 1. + Check the NIC Datasheet for hardware limitations. + +set tc tx min bandwidth +~~~~~~~~~~~~~~~~~~~~~~~ + +Set all TCs' TX min relative bandwidth (%) globally for all PF and VFs:: + + testpmd> set tc tx min-bandwidth (port_id) (bw1, bw2, ...) + Supported Chipsets and NICs --------------------------- diff --git a/doc/guides/testpmd_app_ug/testpmd_funcs.rst b/doc/guides/testpmd_app_ug/testpmd_funcs.rst index 55009507ed..047ea4e46c 100644 --- a/doc/guides/testpmd_app_ug/testpmd_funcs.rst +++ b/doc/guides/testpmd_app_ug/testpmd_funcs.rst @@ -930,13 +930,6 @@ set drop enable bit for all queues:: testpmd> set all queues drop (port_id) (on|off) -set split drop enable (for VF) -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -set split drop enable bit for VF from PF:: - - testpmd> set vf split drop (port_id) (vf_id) (on|off) - set mac antispoof (for VF) ~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -944,38 +937,6 @@ Set mac antispoof for a VF from the PF:: testpmd> set vf mac antispoof (port_id) (vf_id) (on|off) -set macsec offload -~~~~~~~~~~~~~~~~~~ - -Enable/disable MACsec offload:: - - testpmd> set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off) - testpmd> set macsec offload (port_id) off - -set macsec sc -~~~~~~~~~~~~~ - -Configure MACsec secure connection (SC):: - - testpmd> set macsec sc (tx|rx) (port_id) (mac) (pi) - -.. note:: - - The pi argument is ignored for tx. - Check the NIC Datasheet for hardware limits. - -set macsec sa -~~~~~~~~~~~~~ - -Configure MACsec secure association (SA):: - - testpmd> set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key) - -.. note:: - - The IDX value must be 0 or 1. - Check the NIC Datasheet for hardware limits. - vlan set stripq ~~~~~~~~~~~~~~~ @@ -1384,13 +1345,6 @@ Set the allmulti mode for a port or for all ports:: Same as the ifconfig (8) option. Controls how multicast packets are handled. -set tc tx min bandwidth -~~~~~~~~~~~~~~~~~~~~~~~ - -Set all TCs' TX min relative bandwidth (%) globally for all PF and VFs:: - - testpmd> set tc tx min-bandwidth (port_id) (bw1, bw2, ...) - set flow_ctrl rx ~~~~~~~~~~~~~~~~ @@ -5360,3 +5314,4 @@ See: - :doc:`../prog_guide/link_bonding_poll_mode_drv_lib` - :doc:`../nics/i40e` +- :doc:`../nics/ixgbe` diff --git a/drivers/net/ixgbe/ixgbe_testpmd.c b/drivers/net/ixgbe/ixgbe_testpmd.c new file mode 100644 index 0000000000..7d221a3eb0 --- /dev/null +++ b/drivers/net/ixgbe/ixgbe_testpmd.c @@ -0,0 +1,657 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2010-2016 Intel Corporation. + */ + +#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; +} + +/* 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_commands ixgbe_cmds = { + .commands = { + { + &cmd_set_vf_split_drop_en, + "set vf split drop (port_id) (vf_id) (on|off)\n" + " Set split drop enable bit for a VF from the PF.\n", + }, + { + &cmd_set_macsec_offload_on, + "set macsec offload (port_id) on encrypt (on|off) replay-protect (on|off)\n" + " Enable MACsec offload.\n", + }, + { + &cmd_set_macsec_offload_off, + "set macsec offload (port_id) off\n" + " Disable MACsec offload.\n", + }, + { + &cmd_set_macsec_sc, + "set macsec sc (tx|rx) (port_id) (mac) (pi)\n" + " Configure MACsec secure connection (SC).\n", + }, + { + &cmd_set_macsec_sa, + "set macsec sa (tx|rx) (port_id) (idx) (an) (pn) (key)\n" + " Configure MACsec secure association (SA).\n", + }, + { + &cmd_tc_min_bw, + "set tc tx min-bandwidth (port_id) (bw1, bw2, ...)\n" + " Set all TCs' min bandwidth(%%) for all PF and VFs.\n", + }, + { NULL, NULL }, + }, +}; +TESTPMD_ADD_DRIVER_COMMANDS(ixgbe_cmds) 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'