From patchwork Mon Oct 22 13:15: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: 47137 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 1EF204F90; Mon, 22 Oct 2018 15:15:40 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id ED2CD4F90 for ; Mon, 22 Oct 2018 15:15:38 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 900BA21F79; Mon, 22 Oct 2018 09:15:38 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 22 Oct 2018 09:15: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=kf2fiOdU/B 5VEaMedEj1pgh78QtCL1ovvKofyK8o9Ks=; b=rc0tIMJBAXD2STqWwwh6XsnA2p RlIlxeifHVjAeBakuBDDuC4/MgJ0YXk4J6KiQa7U0foZd0+Kem2YSlDWJp1I1TRh L9J5Ym0xCNWUbZnDSjOU/kUaqeUrVdxiWnbkUiAZwIs7bXVcWwpG8sSSPGz09QWk gAHtWAjtP7tgXreNE= 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=h2CdtZZk xk1Nf7p6Cq0aXN6PYnqVd0ZbugI/Xe8wH0/4GaeMWqCscJDuA86WiBUeT86gF7Zj IUeMSE9OYtl7+o2XgST7LpHDZXEUUKBYrX85XflLxrNRCKpiiRJx6raqQtLe6mzu WIEyrQggnmSP0g7m17fJWuq5xiVHe8LqxjnIpjMk3wc5H9Wijb8Wca1NRh/eCepp Ndtf115ukli5Q3oYNbPp63iG9K9rwSvH27PyafePlUABAV+gZ1IvX8PrbjvZWXhE KRaEay15DTq6QSSMsYsL1uLY6W+pCLAhybYy80dAu7L7xEmxSAx7+4x5NjACqxIM +ga2SmljOBWCAQ== 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 BEF55E4897; Mon, 22 Oct 2018 09:15: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: Mon, 22 Oct 2018 15:15:27 +0200 Message-Id: <20181022131530.6403-2-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181022131530.6403-1-thomas@monjalon.net> References: <20181009021858.19216-1-thomas@monjalon.net> <20181022131530.6403-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 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 Mon Oct 22 13:15: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: 47138 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 AE72054AE; Mon, 22 Oct 2018 15:15:44 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 46F6754AE for ; Mon, 22 Oct 2018 15:15:43 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id DE38D22138; Mon, 22 Oct 2018 09:15:42 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 22 Oct 2018 09:15:42 -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=pFOj8tX2/O wyEEWrlvuv4EHCvoGnUp8mb+0VFfilsco=; b=U7P7nJtcY+AMjXMxFqZEJFcm19 wDq056OSoPc/90phv1E6x7XUNAZHVtlxh1kFrtodIzoidOhQuANfLasa4qYA2dNI Z7F8jI7vTpi6wkwpme1eUBpvQMTPx2W1K7iowE4IUv6ddkdbfprKT5OPiE8jcPhc Dsa1XAQ4BTAbdvUjU= 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=pFOj8tX2/OwyEEWrlvuv4EHCvoGnUp8mb+0VFfilsco=; b=GMGLFONN fovKZ4B/W3iXPSodL2jKz9sbHiCMK4JXNFArMx2iz8kiNPPnmRAjT8YPdy9IYyWp DkCXGH6jOUSSkz6tNMpEa/YraPoSmwvJGI0o+PGzaRBM5Eg4aEc916p875Z6BArT RVntduxb77VUR51mRFL9Nh6fRI18V4URPeA8v4/rSAhGwVCP2yQewsPZwkgJlBUC vlXEBMDD8lzLJSm5HxizMO8gziIYfNNddw0VVRq/9lm5LIxxBDo6rveZxbAeg07u miRgFnjeoOvfqCNYPjmhf2E6/K9blaKmpZzOrED67+e6QBHiM/4XqowDt2xUU+kQ b9enzatt78JKng== 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 993D0E405D; Mon, 22 Oct 2018 09:15:41 -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: Mon, 22 Oct 2018 15:15:28 +0200 Message-Id: <20181022131530.6403-3-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181022131530.6403-1-thomas@monjalon.net> References: <20181009021858.19216-1-thomas@monjalon.net> <20181022131530.6403-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 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 2b218d4a2..1c04f95ea 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -4349,8 +4349,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) { @@ -4415,89 +4413,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 Mon Oct 22 13:15: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: 47139 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 AD61E5681; Mon, 22 Oct 2018 15:15:49 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 354975398 for ; Mon, 22 Oct 2018 15:15:47 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 9D95322105; Mon, 22 Oct 2018 09:15:46 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 22 Oct 2018 09:15:46 -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=wpSh5L2Bih 5RLY+5MHAwFuW5ZDIzraAK5y6xnF0lOhI=; b=iYMio7x8pPSqTLURxXZkOpi4rZ irS1mjWAAWb7Xc570yG9Ibh2uhFblNrOcPtOSSW+9q09Y6zNthTN61zDpfED6KFH /52lgtPumC/xZagxNSgOvxXCldeWWplW1W7BeVMKLiPNia2iM1aXlD0p1CKcDT4q r+ewXr5IaSiaoG+as= 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=wpSh5L2Bih5RLY+5MHAwFuW5ZDIzraAK5y6xnF0lOhI=; b=k2uvGeOU r6uK2JGMN7QyeOBWDvPzfmyMwB/gLcMqqF+MGZTBgaf+RJU/8JbhDQVEuDQCxJjq Tkdkraj6MwwzL9nWwoz9YlBXMMVCx3pf6u6LaponXXuLBBa2k92nK7puVeLw2ywU tVzlv22eS/bj/kkFAro2ETSvTowG3gd5mX6NeEX4SI4tZmejf53YEk3jP6W6vPHM XRVwxkLYENXus91ZaHDvVfN5JbXtULCa7iV7hT9Z9U5hPyZ8o/ViisO91LJ+7Jjn fcHhRx8nEQTVBN2zMUnMf6+BcRAEUl55VDz0lHoVxKrE83JecHuS4qML9Ofngqlk jbElqHvrcXSLYA== 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 32A32E4899; Mon, 22 Oct 2018 09:15:45 -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: Mon, 22 Oct 2018 15:15:29 +0200 Message-Id: <20181022131530.6403-4-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181022131530.6403-1-thomas@monjalon.net> References: <20181009021858.19216-1-thomas@monjalon.net> <20181022131530.6403-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 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 | 4 +++ 5 files changed, 53 insertions(+), 1 deletion(-) diff --git a/drivers/net/i40e/i40e_vf_representor.c b/drivers/net/i40e/i40e_vf_representor.c index 43fe00cca..a523e50da 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 eb9bbe5cb..917ee68fc 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 b2be74b51..297cbffc0 100644 --- a/drivers/net/mlx5/mlx5.c +++ b/drivers/net/mlx5/mlx5.c @@ -1084,8 +1084,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 9a020ce3b..8f03f83f6 100644 --- a/lib/librte_ethdev/rte_ethdev_core.h +++ b/lib/librte_ethdev/rte_ethdev_core.h @@ -625,6 +625,10 @@ 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 in dev_flags. + */ } __rte_cache_aligned; /** From patchwork Mon Oct 22 13:15: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: 47140 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 C546B5323; Mon, 22 Oct 2018 15:15:55 +0200 (CEST) Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 375E95699 for ; Mon, 22 Oct 2018 15:15:51 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id A521A2211B; Mon, 22 Oct 2018 09:15:50 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Mon, 22 Oct 2018 09:15:50 -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=KutNzoeiOI tzflqh9oOorXqLLwwocP8G1/D46tmI7pI=; b=OwyaBQooyQ0dosgUmETyUJZiSP jAJz5jnYG2DpW6KFQ83xVBjM7cHe2SEQ/zdepxy9WzxQL9tYVWXcwGZ4rzTKfJ89 gGGedB4eCwQRxUiYdr2nJ5ELWuktckTbbT/F5OGRmaaTfHsDEaO5nJpIhOk/ptgI WSy/sOTQovhJ1kLNU= 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=KutNzoeiOItzflqh9oOorXqLLwwocP8G1/D46tmI7pI=; b=F7t9krsO vHyhN6QpSPTQeDTSgE0c3THtbWWn9Pf9lnI/CFAr/qSuyZzGGUHhrL4cz+AQCMNP rPd0cKRqjQ8napqgBcJ6SZcBqhyUu9E/kJnuPaBvYSRLXNHlk9IdefYj07p1TtaR hFKwvG1X4W8vEKsjQgXvnzvT+reM9mx5vJzl3QSs5BPZDpmdYXgQmhzCjRTprX2y weucEtZVYci81tuby0nd5rGiVMxKjHp6XRNdROU0SYK6WHi+unHj+yNCvqJrRv37 gaZd7k8kmCED46G2/EJERM9Ii1XoFbbz7xC6SdujmtR9C403B9A2P+Mx/wb8u/fR 9z01lw0PdqW01w== 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 50D5CE4897; Mon, 22 Oct 2018 09:15:49 -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: Mon, 22 Oct 2018 15:15:30 +0200 Message-Id: <20181022131530.6403-5-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181022131530.6403-1-thomas@monjalon.net> References: <20181009021858.19216-1-thomas@monjalon.net> <20181022131530.6403-1-thomas@monjalon.net> MIME-Version: 1.0 Subject: [dpdk-dev] [PATCH v3 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 Acked-by: Andrew Rybchenko --- 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 24351cc40..2b903fa37 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',