From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp-ft5.fr.colt.net (smtp-ft5.fr.colt.net [213.41.78.197]) by dpdk.org (Postfix) with ESMTP id 1659DB0C4 for ; Fri, 16 May 2014 10:58:45 +0200 (CEST) Received: from smtp-ex1.fr.colt.net (smtp-ex1.fr.colt.net [213.41.78.194]) by smtp-ft5.fr.colt.net (8.14.3/8.14.3/Debian-5+lenny1) with ESMTP id s4G8wrbs025056 for ; Fri, 16 May 2014 10:58:53 +0200 Received: from 33.106-14-84.ripe.coltfrance.com ([84.14.106.33] helo=proxy.6wind.com) by smtp-ex1.fr.colt.net with esmtp (Exim) (envelope-from ) id 1WlDye-0004gB-2k for ; Fri, 16 May 2014 10:58:53 +0200 Received: from 6wind.com (unknown [10.16.0.189]) by proxy.6wind.com (Postfix) with SMTP id 88AAD5AE3E; Fri, 16 May 2014 10:58:51 +0200 (CEST) Received: by 6wind.com (sSMTP sendmail emulation); Fri, 16 May 2014 10:58:50 +0200 From: Ivan Boule To: dev@dpdk.org Date: Fri, 16 May 2014 10:58:43 +0200 Message-Id: <1400230723-2830-6-git-send-email-ivan.boule@6wind.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1400230723-2830-1-git-send-email-ivan.boule@6wind.com> References: <1400230723-2830-1-git-send-email-ivan.boule@6wind.com> X-ACL-Warn: 1/1 recipients OK. Subject: [dpdk-dev] [PATCH v2 5/5] app/testpmd: allow to configure RSS hash key X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 May 2014 08:58:45 -0000 Add the command "port config X rss-hash-key key" in the 'testpmd' application to configure the RSS hash key used to compute the RSS hash of input [IP] packets received on port X. Signed-off-by: Ivan Boule --- app/test-pmd/cmdline.c | 96 +++++++++++++++++++++++++++++++++++++++++++++++- app/test-pmd/config.c | 28 ++++++++++++++ app/test-pmd/testpmd.h | 1 + 3 files changed, 124 insertions(+), 1 deletion(-) diff --git a/app/test-pmd/cmdline.c b/app/test-pmd/cmdline.c index 0b6749c..7b4f090 100644 --- a/app/test-pmd/cmdline.c +++ b/app/test-pmd/cmdline.c @@ -1192,6 +1192,99 @@ cmdline_parse_inst_t cmd_config_rss = { }, }; +/* *** configure rss hash key *** */ +struct cmd_config_rss_hash_key { + cmdline_fixed_string_t port; + cmdline_fixed_string_t config; + uint8_t port_id; + cmdline_fixed_string_t rss_hash_key; + cmdline_fixed_string_t key; +}; + +#define RSS_HASH_KEY_LENGTH 40 +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) + printf("invalid key: character %c at position %d is not a " + "valid hexa digit\n", key[idx], idx); + return hexa_v; +} + +static void +cmd_config_rss_hash_key_parsed(void *parsed_result, + __attribute__((unused)) struct cmdline *cl, + __attribute__((unused)) void *data) +{ + struct cmd_config_rss_hash_key *res = parsed_result; + uint8_t hash_key[RSS_HASH_KEY_LENGTH]; + uint8_t xdgt0; + uint8_t xdgt1; + int i; + + /* Check the length of the RSS hash key */ + if (strlen(res->key) != (RSS_HASH_KEY_LENGTH * 2)) { + printf("key length: %d invalid - key must be a string of %d" + "hexa-decimal numbers\n", (int) strlen(res->key), + RSS_HASH_KEY_LENGTH * 2); + return; + } + /* Translate RSS hash key into binary representation */ + for (i = 0; i < RSS_HASH_KEY_LENGTH; 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; + hash_key[i]= (uint8_t) ((xdgt0 * 16) + xdgt1); + } + port_rss_hash_key_update(res->port_id, hash_key); +} + +cmdline_parse_token_string_t cmd_config_rss_hash_key_port = + TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, port, "port"); +cmdline_parse_token_string_t cmd_config_rss_hash_key_config = + TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, config, + "config"); +cmdline_parse_token_string_t cmd_config_rss_hash_key_port_id = + TOKEN_NUM_INITIALIZER(struct cmd_config_rss_hash_key, port_id, UINT8); +cmdline_parse_token_string_t cmd_config_rss_hash_key_rss_hash_key = + TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, + rss_hash_key, "rss-hash-key"); +cmdline_parse_token_string_t cmd_config_rss_hash_key_value = + TOKEN_STRING_INITIALIZER(struct cmd_config_rss_hash_key, key, NULL); + +cmdline_parse_inst_t cmd_config_rss_hash_key = { + .f = cmd_config_rss_hash_key_parsed, + .data = NULL, + .help_str = "port config X rss-hash-key 80 hexa digits", + .tokens = { + (void *)&cmd_config_rss_hash_key_port, + (void *)&cmd_config_rss_hash_key_config, + (void *)&cmd_config_rss_hash_key_port_id, + (void *)&cmd_config_rss_hash_key_rss_hash_key, + (void *)&cmd_config_rss_hash_key_value, + NULL, + }, +}; + /* *** Configure RSS RETA *** */ struct cmd_config_rss_reta { cmdline_fixed_string_t port; @@ -1413,7 +1506,7 @@ cmdline_parse_inst_t cmd_showport_rss_hash = { cmdline_parse_inst_t cmd_showport_rss_hash_key = { .f = cmd_showport_rss_hash_parsed, - .data = "show_rss_key", + .data = (void *)1, .help_str = "show port X rss-hash key (X = port number)\n", .tokens = { (void *)&cmd_showport_rss_hash_show, @@ -5322,6 +5415,7 @@ cmdline_parse_ctx_t main_ctx[] = { (cmdline_parse_inst_t *)&cmd_reset_mirror_rule, (cmdline_parse_inst_t *)&cmd_showport_rss_hash, (cmdline_parse_inst_t *)&cmd_showport_rss_hash_key, + (cmdline_parse_inst_t *)&cmd_config_rss_hash_key, (cmdline_parse_inst_t *)&cmd_dump, (cmdline_parse_inst_t *)&cmd_dump_one, NULL, diff --git a/app/test-pmd/config.c b/app/test-pmd/config.c index 614f28f..6feda7a 100644 --- a/app/test-pmd/config.c +++ b/app/test-pmd/config.c @@ -746,6 +746,34 @@ port_rss_hash_conf_show(portid_t port_id, int show_rss_key) printf("\n"); } +void +port_rss_hash_key_update(portid_t port_id, uint8_t *hash_key) +{ + struct rte_eth_rss_conf rss_conf; + int diag; + + rss_conf.rss_key = NULL; + diag = rte_eth_dev_rss_hash_conf_get(port_id, &rss_conf); + if (diag == 0) { + rss_conf.rss_key = hash_key; + diag = rte_eth_dev_rss_hash_update(port_id, &rss_conf); + } + if (diag == 0) + return; + + switch (diag) { + case -ENODEV: + printf("port index %d invalid\n", port_id); + break; + case -ENOTSUP: + printf("operation not supported by device\n"); + break; + default: + printf("operation failed - diag=%d\n", diag); + break; + } +} + /* * Setup forwarding configuration for each logical core. */ diff --git a/app/test-pmd/testpmd.h b/app/test-pmd/testpmd.h index b9d47c4..66c7736 100644 --- a/app/test-pmd/testpmd.h +++ b/app/test-pmd/testpmd.h @@ -524,6 +524,7 @@ void set_vf_rx_vlan(portid_t port_id, uint16_t vlan_id, uint64_t vf_mask, uint8_t on); void port_rss_hash_conf_show(portid_t port_id, int show_rss_key); +void port_rss_hash_key_update(portid_t port_id, uint8_t *hash_key); /* * Work-around of a compilation error with ICC on invocations of the -- 1.7.10.4