From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Content-Transfer-Encoding: 8bit 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: , X-List-Received-Date: Mon, 22 Oct 2018 13:15:43 -0000 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) { -- 2.19.0