From patchwork Wed Oct 10 19:23:27 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 46520 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 02EE01B5D2; Wed, 10 Oct 2018 21:23:39 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id C06541B5BB for ; Wed, 10 Oct 2018 21:23:35 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 6A5DB20D2D; Wed, 10 Oct 2018 15:23:35 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 10 Oct 2018 15:23:35 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=mesmtp; bh=kf2fiOdU/B 5VEaMedEj1pgh78QtCL1ovvKofyK8o9Ks=; b=XHbbfmaq8quxkfw71JSNV74FKy SmCHmC2w+ydFGxpo6rZvvnmkGQoLHkAu6NmITQtUgjzS3IW5jbjJFH3UJrSaRgcv 3gnZg60Cuah7vytyaHnWARHJkTcoE3aqu9hwVuFuGSd2gpGBiWMzBa7aQwx3lUM3 FUdRh2ukx9zSCdVRE= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=kf2fiOdU/B5VEaMedEj1pgh78QtCL1ovvKofyK8o9Ks=; b=yP+RgpN3 vI3S6ev+EmTSqsJYj3p+Z5yUIEeuxIc0sEPtRRIkBAI0PlS058ghMVOaZVVyvWyX yr1s3s4Zn5+t7WD8yXX++0uPqnPK7IbEWezZcS8KRYzhwibM+4IhOG5z1ofn8lg8 QSmKckUEY9kK9/4z3IOLuXG76r7wpW3VbDJMSenlODPNHDbPJZahArJXbvI4ux5d mkYmcIG0BNx/ilsBVxV116tLsuuuerWGpdF+a2CeMOKWhMkC6g9mQqNigP9XspkN LA+p2kILfjwcWc2r78yN6C4hbK+RbKY/PPrMyVG1696zGJp5K0RgDDiWVxvK95JO RDrX96s1B1jSPA== X-ME-Sender: X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 30D7FE489A; Wed, 10 Oct 2018 15:23:34 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com, ferruh.yigit@intel.com, arybchenko@solarflare.com, olivier.matz@6wind.com, remy.horton@intel.com, bruce.richardson@intel.com Date: Wed, 10 Oct 2018 21:23:27 +0200 Message-Id: <20181010192330.21105-2-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181010192330.21105-1-thomas@monjalon.net> References: <20181009021858.19216-1-thomas@monjalon.net> <20181010192330.21105-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2 1/4] kvargs: support list value X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" If a value contains a comma, rte_kvargs_tokenize() will split here. In order to support list syntax [a,b] as value, an extra parsing of the square brackets is added. Signed-off-by: Thomas Monjalon --- lib/librte_kvargs/rte_kvargs.c | 14 ++++++++++++++ test/test/test_kvargs.c | 21 +++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/lib/librte_kvargs/rte_kvargs.c b/lib/librte_kvargs/rte_kvargs.c index a28f76945..e616da351 100644 --- a/lib/librte_kvargs/rte_kvargs.c +++ b/lib/librte_kvargs/rte_kvargs.c @@ -44,6 +44,20 @@ rte_kvargs_tokenize(struct rte_kvargs *kvlist, const char *params) kvlist->pairs[i].value == NULL) return -1; + /* Detect list [a,b] to skip comma delimiter in list. */ + str = kvlist->pairs[i].value; + if (str[0] == '[') { + /* Find the end of the list. */ + while (str[strlen(str) - 1] != ']') { + /* Restore the comma erased by strtok_r(). */ + str[strlen(str)] = ','; + /* Parse until next comma. */ + str = strtok_r(NULL, RTE_KVARGS_PAIRS_DELIM, &ctx1); + if (str == NULL) + return -1; /* no closing bracket */ + } + } + kvlist->count++; str = NULL; } diff --git a/test/test/test_kvargs.c b/test/test/test_kvargs.c index e6738624e..a42056f36 100644 --- a/test/test/test_kvargs.c +++ b/test/test/test_kvargs.c @@ -137,6 +137,26 @@ static int test_valid_kvargs(void) } rte_kvargs_free(kvlist); + /* third test using list as value */ + args = "foo=[0,1],check=value2"; + valid_keys = valid_keys_list; + kvlist = rte_kvargs_parse(args, valid_keys); + if (kvlist == NULL) { + printf("rte_kvargs_parse() error"); + goto fail; + } + if (strcmp(kvlist->pairs[0].value, "[0,1]") != 0) { + printf("wrong value %s", kvlist->pairs[0].value); + goto fail; + } + count = kvlist->count; + if (count != 2) { + printf("invalid count value %d\n", count); + rte_kvargs_free(kvlist); + goto fail; + } + rte_kvargs_free(kvlist); + return 0; fail: @@ -162,6 +182,7 @@ static int test_invalid_kvargs(void) "foo=1,,foo=2", /* empty key/value */ "foo=1,foo", /* no value */ "foo=1,=2", /* no key */ + "foo=[1,2", /* no closing bracket in value */ ",=", /* also test with a smiley */ NULL }; const char **args; From patchwork Wed Oct 10 19:23:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 46521 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id E49FC1B5F9; Wed, 10 Oct 2018 21:23:41 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 526871B5CD for ; Wed, 10 Oct 2018 21:23:38 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 6F08F220F6; Wed, 10 Oct 2018 15:23:36 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 10 Oct 2018 15:23:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=mesmtp; bh=YOvKawBZan iHr+6j7NFh/I25CZVzJGpxTwwfGLu0Zl4=; b=BNRULF5AwojsurZEHQ5J3hLgR2 rycAa3FL3DsbexSI7kUVorA1haRKS9WTE+DYb6PE/HepLjUmiZ57Mxq8EajdIb/l ve4+AIvIanNcXt+3vExL6oexO2/laO1IhO+DHu6qr448/d6zuaq2Scc4/FZyCiah 0J/YigzaCM4H/bPfI= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=YOvKawBZaniHr+6j7NFh/I25CZVzJGpxTwwfGLu0Zl4=; b=aQDT2lEZ Kt3r0RbomMgL6Nwe/2HuQcblQgJeESkP0zW8N04dgXjntRXz2c5bWhN4M3+Sny5R 0qRpDzdWfHbyXooqXYQVsmkl2AKdfWUKNEEehLVZFEiy/nBKHv3Eh5g3EkncdnE/ W/FcXpzZadqJm0bInlp6+5mCHcF9O//2baIYw1qPZ761lJpGSgvS276R0hcYuHzR eTgY08booWcb792fZxUlIj85IhyrwAvMuMhlOmQyIuCSZo4kWFwnV+/SmDYBSogs ggfpcmC1McB7WTNevjxVga0s1wkCoJTAblynk8LrWV8OCsqH7s+2hUkk7ft+q0G1 UZwxXCiiVMS4vQ== X-ME-Sender: X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 4255EE4898; Wed, 10 Oct 2018 15:23:35 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com, ferruh.yigit@intel.com, arybchenko@solarflare.com, olivier.matz@6wind.com, remy.horton@intel.com, bruce.richardson@intel.com Date: Wed, 10 Oct 2018 21:23:28 +0200 Message-Id: <20181010192330.21105-3-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181010192330.21105-1-thomas@monjalon.net> References: <20181009021858.19216-1-thomas@monjalon.net> <20181010192330.21105-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2 2/4] ethdev: move representor parsing functions X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The functions for representor devargs parsing were static in the file rte_ethdev.c. In order to reuse them in the file rte_class_eth.c, they are moved to the files ethdev_private.c/.h. A log is fixed by adding a missing line feed. Signed-off-by: Thomas Monjalon Acked-by: Andrew Rybchenko --- lib/librte_ethdev/ethdev_private.c | 82 ++++++++++++++++++++++++++++ lib/librte_ethdev/ethdev_private.h | 6 +++ lib/librte_ethdev/rte_ethdev.c | 85 ------------------------------ 3 files changed, 88 insertions(+), 85 deletions(-) diff --git a/lib/librte_ethdev/ethdev_private.c b/lib/librte_ethdev/ethdev_private.c index acc787dba..162a502fe 100644 --- a/lib/librte_ethdev/ethdev_private.c +++ b/lib/librte_ethdev/ethdev_private.c @@ -3,6 +3,7 @@ */ #include "rte_ethdev.h" +#include "rte_ethdev_driver.h" #include "ethdev_private.h" uint16_t @@ -37,3 +38,84 @@ eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, return NULL; } +int +rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback, + void *data) +{ + char *str_start; + int state; + int result; + + if (*str != '[') + /* Single element, not a list */ + return callback(str, data); + + /* Sanity check, then strip the brackets */ + str_start = &str[strlen(str) - 1]; + if (*str_start != ']') { + RTE_LOG(ERR, EAL, "(%s): List does not end with ']'\n", str); + return -EINVAL; + } + str++; + *str_start = '\0'; + + /* Process list elements */ + state = 0; + while (1) { + if (state == 0) { + if (*str == '\0') + break; + if (*str != ',') { + str_start = str; + state = 1; + } + } else if (state == 1) { + if (*str == ',' || *str == '\0') { + if (str > str_start) { + /* Non-empty string fragment */ + *str = '\0'; + result = callback(str_start, data); + if (result < 0) + return result; + } + state = 0; + } + } + str++; + } + return 0; +} + +static int +rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list, + const uint16_t max_list) +{ + uint16_t lo, hi, val; + int result; + + result = sscanf(str, "%hu-%hu", &lo, &hi); + if (result == 1) { + if (*len_list >= max_list) + return -ENOMEM; + list[(*len_list)++] = lo; + } else if (result == 2) { + if (lo >= hi || lo > RTE_MAX_ETHPORTS || hi > RTE_MAX_ETHPORTS) + return -EINVAL; + for (val = lo; val <= hi; val++) { + if (*len_list >= max_list) + return -ENOMEM; + list[(*len_list)++] = val; + } + } else + return -EINVAL; + return 0; +} + +int +rte_eth_devargs_parse_representor_ports(char *str, void *data) +{ + struct rte_eth_devargs *eth_da = data; + + return rte_eth_devargs_process_range(str, eth_da->representor_ports, + ð_da->nb_representor_ports, RTE_MAX_ETHPORTS); +} diff --git a/lib/librte_ethdev/ethdev_private.h b/lib/librte_ethdev/ethdev_private.h index e67cf6831..7b787bf97 100644 --- a/lib/librte_ethdev/ethdev_private.h +++ b/lib/librte_ethdev/ethdev_private.h @@ -25,6 +25,12 @@ struct rte_eth_dev * eth_find_device(const struct rte_eth_dev *_start, rte_eth_cmp_t cmp, const void *data); +/* Parse devargs value for representor parameter. */ +typedef int (*rte_eth_devargs_callback_t)(char *str, void *data); +int rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback, + void *data); +int rte_eth_devargs_parse_representor_ports(char *str, void *data); + #ifdef __cplusplus } #endif diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index 9ac802f3f..3062dc711 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -4309,8 +4309,6 @@ rte_eth_switch_domain_free(uint16_t domain_id) return 0; } -typedef int (*rte_eth_devargs_callback_t)(char *str, void *data); - static int rte_eth_devargs_tokenise(struct rte_kvargs *arglist, const char *str_in) { @@ -4375,89 +4373,6 @@ rte_eth_devargs_tokenise(struct rte_kvargs *arglist, const char *str_in) } } -static int -rte_eth_devargs_parse_list(char *str, rte_eth_devargs_callback_t callback, - void *data) -{ - char *str_start; - int state; - int result; - - if (*str != '[') - /* Single element, not a list */ - return callback(str, data); - - /* Sanity check, then strip the brackets */ - str_start = &str[strlen(str) - 1]; - if (*str_start != ']') { - RTE_LOG(ERR, EAL, "(%s): List does not end with ']'", str); - return -EINVAL; - } - str++; - *str_start = '\0'; - - /* Process list elements */ - state = 0; - while (1) { - if (state == 0) { - if (*str == '\0') - break; - if (*str != ',') { - str_start = str; - state = 1; - } - } else if (state == 1) { - if (*str == ',' || *str == '\0') { - if (str > str_start) { - /* Non-empty string fragment */ - *str = '\0'; - result = callback(str_start, data); - if (result < 0) - return result; - } - state = 0; - } - } - str++; - } - return 0; -} - -static int -rte_eth_devargs_process_range(char *str, uint16_t *list, uint16_t *len_list, - const uint16_t max_list) -{ - uint16_t lo, hi, val; - int result; - - result = sscanf(str, "%hu-%hu", &lo, &hi); - if (result == 1) { - if (*len_list >= max_list) - return -ENOMEM; - list[(*len_list)++] = lo; - } else if (result == 2) { - if (lo >= hi || lo > RTE_MAX_ETHPORTS || hi > RTE_MAX_ETHPORTS) - return -EINVAL; - for (val = lo; val <= hi; val++) { - if (*len_list >= max_list) - return -ENOMEM; - list[(*len_list)++] = val; - } - } else - return -EINVAL; - return 0; -} - - -static int -rte_eth_devargs_parse_representor_ports(char *str, void *data) -{ - struct rte_eth_devargs *eth_da = data; - - return rte_eth_devargs_process_range(str, eth_da->representor_ports, - ð_da->nb_representor_ports, RTE_MAX_ETHPORTS); -} - int __rte_experimental rte_eth_devargs_parse(const char *dargs, struct rte_eth_devargs *eth_da) { From patchwork Wed Oct 10 19:23:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 46522 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id A37171B60B; Wed, 10 Oct 2018 21:23:44 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 6583F1B5D2 for ; Wed, 10 Oct 2018 21:23:38 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 0091E221D0; Wed, 10 Oct 2018 15:23:37 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 10 Oct 2018 15:23:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=mesmtp; bh=w7bYp2MTyu Mcm57aprbhCdk5G76T187/QtSJkt+HfBU=; b=DsTQBTNsFAaqqUWaWdBmJSebDD TnRE0VGQhAOoxelR4z2JbBFmQ2OAQ6X2Cht/St9bX78Bv3AUbfK2vctdArBmbZk6 qvUjeWOAOxy7To7Lo+kpzFYb0a1VQGmtduFsqwKrVhJWR/nJXMQVf85/p0h8xj0p KxRoTuMtmSdhx88wY= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=w7bYp2MTyuMcm57aprbhCdk5G76T187/QtSJkt+HfBU=; b=F8WAHNjC H6dyBbTyVd56vVtczC6VLcFQU9nU/hbAXc1nzwBhYdTr0SkCLJutzrzte2bqsun5 KXjgxd6BpnQC0HOt1ncu4diNAvc3qdgSv+X2K2Z6h3mAwfM3gZe0FquLKjrw0k0B n2Tgki8klPVnLHQhCtuT+uYM6n5b3YRFhhm2cfXhTASMm03Xx+FbLHiTG8ygN8+T 80reVHpiNPlVv93+XLxJ0l9kGZtvPlWrJdmu6Bg1okJCHTYQHsOKb/04X5qTCFOO EySx866+TXaFDHg44ueDsaXPJWGZZ5Nf0KgKPoBHSJmHBtXWQacffM8n3cEKCtR/ 6SF2ITBkkPZHzQ== X-ME-Sender: X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 551F4E4920; Wed, 10 Oct 2018 15:23:36 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com, ferruh.yigit@intel.com, arybchenko@solarflare.com, olivier.matz@6wind.com, remy.horton@intel.com, bruce.richardson@intel.com Date: Wed, 10 Oct 2018 21:23:29 +0200 Message-Id: <20181010192330.21105-4-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181010192330.21105-1-thomas@monjalon.net> References: <20181009021858.19216-1-thomas@monjalon.net> <20181010192330.21105-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2 3/4] ethdev: support representor id as iterator filter X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The representor id is added in rte_eth_dev_data in order to be able to match a port with its representor id in devargs. Signed-off-by: Thomas Monjalon Reviewed-by: Andrew Rybchenko --- drivers/net/i40e/i40e_vf_representor.c | 1 + drivers/net/ixgbe/ixgbe_vf_representor.c | 1 + drivers/net/mlx5/mlx5.c | 4 ++- lib/librte_ethdev/rte_class_eth.c | 44 ++++++++++++++++++++++++ lib/librte_ethdev/rte_ethdev_core.h | 2 ++ 5 files changed, 51 insertions(+), 1 deletion(-) diff --git a/drivers/net/i40e/i40e_vf_representor.c b/drivers/net/i40e/i40e_vf_representor.c index 24751d13c..a377c1064 100644 --- a/drivers/net/i40e/i40e_vf_representor.c +++ b/drivers/net/i40e/i40e_vf_representor.c @@ -504,6 +504,7 @@ i40e_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params) } ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR; + ethdev->data->representor_id = representor->vf_id; /* Setting the number queues allocated to the VF */ ethdev->data->nb_rx_queues = vf->vsi->nb_qps; diff --git a/drivers/net/ixgbe/ixgbe_vf_representor.c b/drivers/net/ixgbe/ixgbe_vf_representor.c index b0fbbc49f..26e2af4f8 100644 --- a/drivers/net/ixgbe/ixgbe_vf_representor.c +++ b/drivers/net/ixgbe/ixgbe_vf_representor.c @@ -192,6 +192,7 @@ ixgbe_vf_representor_init(struct rte_eth_dev *ethdev, void *init_params) return -ENODEV; ethdev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR; + ethdev->data->representor_id = representor->vf_id; /* Set representor device ops */ ethdev->dev_ops = &ixgbe_vf_representor_dev_ops; diff --git a/drivers/net/mlx5/mlx5.c b/drivers/net/mlx5/mlx5.c index cf258345f..de8bab342 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -1075,8 +1075,10 @@ mlx5_dev_spawn(struct rte_device *dpdk_dev, err = ENOMEM; goto error; } - if (priv->representor) + if (priv->representor) { eth_dev->data->dev_flags |= RTE_ETH_DEV_REPRESENTOR; + eth_dev->data->representor_id = priv->representor_id; + } eth_dev->data->dev_private = priv; priv->dev_data = eth_dev->data; eth_dev->data->mac_addrs = priv->mac; diff --git a/lib/librte_ethdev/rte_class_eth.c b/lib/librte_ethdev/rte_class_eth.c index 58fed694b..fca7fe4d4 100644 --- a/lib/librte_ethdev/rte_class_eth.c +++ b/lib/librte_ethdev/rte_class_eth.c @@ -12,13 +12,16 @@ #include "rte_ethdev.h" #include "rte_ethdev_core.h" +#include "rte_ethdev_driver.h" #include "ethdev_private.h" enum eth_params { + RTE_ETH_PARAM_REPRESENTOR, RTE_ETH_PARAM_MAX, }; static const char * const eth_params_keys[] = { + [RTE_ETH_PARAM_REPRESENTOR] = "representor", [RTE_ETH_PARAM_MAX] = NULL, }; @@ -33,10 +36,44 @@ struct eth_dev_match_arg { .kvlist = (k), \ }) +static int +eth_representor_cmp(const char *key __rte_unused, + const char *value, void *opaque) +{ + int ret; + char *values; + const struct rte_eth_dev_data *data = opaque; + struct rte_eth_devargs representors; + uint16_t index; + + if ((data->dev_flags & RTE_ETH_DEV_REPRESENTOR) == 0) + return -1; /* not a representor port */ + + /* Parse devargs representor values. */ + values = strdup(value); + if (values == NULL) + return -1; + memset(&representors, 0, sizeof(representors)); + ret = rte_eth_devargs_parse_list(values, + rte_eth_devargs_parse_representor_ports, + &representors); + free(values); + if (ret != 0) + return -1; /* invalid devargs value */ + + /* Return 0 if representor id is matching one of the values. */ + for (index = 0; index < representors.nb_representor_ports; index++) + if (data->representor_id == + representors.representor_ports[index]) + return 0; + return -1; /* no match */ +} + static int eth_dev_match(const struct rte_eth_dev *edev, const void *_arg) { + int ret; const struct eth_dev_match_arg *arg = _arg; const struct rte_kvargs *kvlist = arg->kvlist; @@ -47,6 +84,13 @@ eth_dev_match(const struct rte_eth_dev *edev, if (kvlist == NULL) /* Empty string matches everything. */ return 0; + + ret = rte_kvargs_process(kvlist, + eth_params_keys[RTE_ETH_PARAM_REPRESENTOR], + eth_representor_cmp, edev->data); + if (ret != 0) + return -1; + return 0; } diff --git a/lib/librte_ethdev/rte_ethdev_core.h b/lib/librte_ethdev/rte_ethdev_core.h index 33d12b3a2..ac67fde28 100644 --- a/lib/librte_ethdev/rte_ethdev_core.h +++ b/lib/librte_ethdev/rte_ethdev_core.h @@ -613,6 +613,8 @@ struct rte_eth_dev_data { struct rte_vlan_filter_conf vlan_filter_conf; /**< VLAN filter configuration. */ struct rte_eth_dev_owner owner; /**< The port owner. */ + uint16_t representor_id; + /**< switch specific identifier - valid if RTE_ETH_DEV_REPRESENTOR */ } __rte_cache_aligned; /** From patchwork Wed Oct 10 19:23:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thomas Monjalon X-Patchwork-Id: 46523 X-Patchwork-Delegate: ferruh.yigit@amd.com Return-Path: X-Original-To: patchwork@dpdk.org Delivered-To: patchwork@dpdk.org Received: from [92.243.14.124] (localhost [127.0.0.1]) by dpdk.org (Postfix) with ESMTP id 3EF8A1B722; Wed, 10 Oct 2018 21:23:47 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 18AFA1B5DE for ; Wed, 10 Oct 2018 21:23:39 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id B8BD522169; Wed, 10 Oct 2018 15:23:38 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 10 Oct 2018 15:23:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=mesmtp; bh=HrolM9gBaj UVBb3eUsWMgNj0899cI65t1vlifbtw5tk=; b=jW7rpmkpXdttWT/0rs/4YFhw6T x9LFJFZ50K/fEYjZ3npwamKpl0Q3Uh7OCfiGIL8lDOmRny+Jry9ITVQV3cvVPRa6 I3nXtDuW1/gL738OnxYc31rLQKJK49stFfpNsDa7WT3i9OC3503CCXNarVcEiiQW Pamm285a7SeEFObuQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=HrolM9gBajUVBb3eUsWMgNj0899cI65t1vlifbtw5tk=; b=ZhTI1wyG 1O61Ui+kIjZ/LPAxRSdWMl9BJCLjNGWdQ0ruvyXzJK3lyrMWQ8z6FK572tH2srl7 CWvgAA7falCEhnfJqQy/TysjoTkW7JUA6KWjeJ0aAjai9kdDEr9U0JRNMMNRI6C6 DCLp+llJ5YrO39sxcKWqqtrYuKFBMnPP5biyqEcf8DZ5Qet6DZ0CsllapBAYPLIf c0R3zvdbgmVLywMDFRR4hgJaeotbcRExDg/FgwWneTjsHca0FWe9YVWauaSkEZWz vFjm8pqyBX6zNm9KYuymmCFH7sAR+3BaCLJ1KddrjVW0O6vqRp7c5dT4FKlzuCZb NrdtZay490VG/Q== X-ME-Sender: X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 6D718E4898; Wed, 10 Oct 2018 15:23:37 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com, ferruh.yigit@intel.com, arybchenko@solarflare.com, olivier.matz@6wind.com, remy.horton@intel.com, bruce.richardson@intel.com Date: Wed, 10 Oct 2018 21:23:30 +0200 Message-Id: <20181010192330.21105-5-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181010192330.21105-1-thomas@monjalon.net> References: <20181009021858.19216-1-thomas@monjalon.net> <20181010192330.21105-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v2 4/4] ethdev: support MAC address as iterator filter X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" The MAC addresses of a port can be matched with devargs. As the conflict between rte_ether.h and netinet/ether.h is not resolved, the MAC parsing is done with a rte_cmdline function. As a result, cmdline library becomes a dependency of ethdev. Signed-off-by: Thomas Monjalon --- lib/Makefile | 1 + lib/librte_cmdline/meson.build | 4 ++++ lib/librte_ethdev/Makefile | 2 +- lib/librte_ethdev/meson.build | 2 +- lib/librte_ethdev/rte_class_eth.c | 36 +++++++++++++++++++++++++++++++ lib/meson.build | 5 +++-- 6 files changed, 46 insertions(+), 4 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 8c839425d..a264945d3 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -25,6 +25,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring DEPDIRS-librte_ethdev += librte_mbuf DEPDIRS-librte_ethdev += librte_kvargs +DEPDIRS-librte_ethdev += librte_cmdline DIRS-$(CONFIG_RTE_LIBRTE_BBDEV) += librte_bbdev DEPDIRS-librte_bbdev := librte_eal librte_mempool librte_mbuf DIRS-$(CONFIG_RTE_LIBRTE_CRYPTODEV) += librte_cryptodev diff --git a/lib/librte_cmdline/meson.build b/lib/librte_cmdline/meson.build index 5741817ac..30498906c 100644 --- a/lib/librte_cmdline/meson.build +++ b/lib/librte_cmdline/meson.build @@ -1,6 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2017 Intel Corporation +# This library is processed before EAL +includes = [global_inc] +includes += include_directories('../librte_eal/common/include') + version = 2 sources = files('cmdline.c', 'cmdline_cirbuf.c', diff --git a/lib/librte_ethdev/Makefile b/lib/librte_ethdev/Makefile index e27bcd5ac..3e27ae466 100644 --- a/lib/librte_ethdev/Makefile +++ b/lib/librte_ethdev/Makefile @@ -12,7 +12,7 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring -LDLIBS += -lrte_mbuf -lrte_kvargs +LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_cmdline EXPORT_MAP := rte_ethdev_version.map diff --git a/lib/librte_ethdev/meson.build b/lib/librte_ethdev/meson.build index 6783013fd..a4d850268 100644 --- a/lib/librte_ethdev/meson.build +++ b/lib/librte_ethdev/meson.build @@ -26,4 +26,4 @@ headers = files('rte_ethdev.h', 'rte_tm.h', 'rte_tm_driver.h') -deps += ['net', 'kvargs'] +deps += ['net', 'kvargs', 'cmdline'] diff --git a/lib/librte_ethdev/rte_class_eth.c b/lib/librte_ethdev/rte_class_eth.c index fca7fe4d4..16b47c3bc 100644 --- a/lib/librte_ethdev/rte_class_eth.c +++ b/lib/librte_ethdev/rte_class_eth.c @@ -4,6 +4,7 @@ #include +#include #include #include #include @@ -16,11 +17,13 @@ #include "ethdev_private.h" enum eth_params { + RTE_ETH_PARAM_MAC, RTE_ETH_PARAM_REPRESENTOR, RTE_ETH_PARAM_MAX, }; static const char * const eth_params_keys[] = { + [RTE_ETH_PARAM_MAC] = "mac", [RTE_ETH_PARAM_REPRESENTOR] = "representor", [RTE_ETH_PARAM_MAX] = NULL, }; @@ -36,6 +39,33 @@ struct eth_dev_match_arg { .kvlist = (k), \ }) +static int +eth_mac_cmp(const char *key __rte_unused, + const char *value, void *opaque) +{ + int ret; + struct ether_addr mac; + const struct rte_eth_dev_data *data = opaque; + struct rte_eth_dev_info dev_info; + uint32_t index; + + /* Parse devargs MAC address. */ + /* + * cannot use ether_aton_r(value, &mac) + * because of include conflict with rte_ether.h + */ + ret = cmdline_parse_etheraddr(NULL, value, &mac, sizeof(mac)); + if (ret < 0) + return -1; /* invalid devargs value */ + + /* Return 0 if devargs MAC is matching one of the device MACs. */ + rte_eth_dev_info_get(data->port_id, &dev_info); + for (index = 0; index < dev_info.max_mac_addrs; index++) + if (is_same_ether_addr(&mac, &data->mac_addrs[index])) + return 0; + return -1; /* no match */ +} + static int eth_representor_cmp(const char *key __rte_unused, const char *value, void *opaque) @@ -85,6 +115,12 @@ eth_dev_match(const struct rte_eth_dev *edev, /* Empty string matches everything. */ return 0; + ret = rte_kvargs_process(kvlist, + eth_params_keys[RTE_ETH_PARAM_MAC], + eth_mac_cmp, edev->data); + if (ret != 0) + return -1; + ret = rte_kvargs_process(kvlist, eth_params_keys[RTE_ETH_PARAM_REPRESENTOR], eth_representor_cmp, edev->data); diff --git a/lib/meson.build b/lib/meson.build index 3acc67e6e..f344ffdef 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -9,13 +9,14 @@ # given as a dep, no need to mention ring. This is especially true for the # core libs which are widely reused, so their deps are kept to a minimum. libraries = [ 'compat', # just a header, used for versioning - 'kvargs', + 'cmdline', # ethdev depends on cmdline for parsing functions + 'kvargs', # eal depends on kvargs 'eal', 'ring', 'mempool', 'mbuf', 'net', 'ethdev', 'pci', # core 'metrics', # bitrate/latency stats depends on this 'hash', # efd depends on this 'timer', # eventdev depends on this 'acl', 'bbdev', 'bitratestats', 'cfgfile', - 'cmdline', 'compressdev', 'cryptodev', + 'compressdev', 'cryptodev', 'distributor', 'efd', 'eventdev', 'gro', 'gso', 'ip_frag', 'jobstats', 'kni', 'latencystats', 'lpm', 'member',