From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-f52.google.com (mail-wm1-f52.google.com [209.85.128.52]) by dpdk.org (Postfix) with ESMTP id 699575B36 for ; Wed, 19 Sep 2018 18:04:17 +0200 (CEST) Received: by mail-wm1-f52.google.com with SMTP id n11-v6so7585271wmc.2 for ; Wed, 19 Sep 2018 09:04:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=6wind-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=16Hb8UovXCHR9FohgrgsJxW0jLcJyIzOgFOiPw0BzW0=; b=GooncoIKzlmsjpRuhK9ifx77IT8N7Gn+9Scf1VcSEQc0QT7sMFoCElsT7rNs2oJhT8 BZr4I/tFlms7OlfWp2swPTzlssoqyRNxGJtE3V31KY+jzeoPAON+nbzKA0TeH+1jphxG U//2iwZ9vkoVeV/FGt8lIJurirsAEGD9C1Aj3wPenHOkzhP6T9nX0B1rYx7TR+Y21Sbu PTyAPcttMESdAiWrNSX2ZN1zBG7AwI+PSyy/Od5PeeUaR9ANQ6dPzCVfixIg7hftaPy6 pPdFG2DQuEesWD/+cLdvoI20AnRfMmWxkVj29doQ4V/CZYxeuenLiKKs6auX5/yFjIp0 nPGA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=16Hb8UovXCHR9FohgrgsJxW0jLcJyIzOgFOiPw0BzW0=; b=e02svKTjX/Jwz2k3MamlzZXxwICp1jjfn74bntII/axzywGnOCVMP2byiqseVQvFZ4 ebfu6ozNZUgnprI6aXbVn777aLt9vAyM+xGuQ8f5r8DMfm9ynjBgTutfeLl/jHM88b5u JkQ5quz7vxUoASA+DGcp0q69P221Y2YFdnzphvlxJD3oYHA+Dn2yypvP2KVrEBxNwhmd 7doPCvO2295BL9ljBqWJ/dz9lz5qfmF5qFP2PVBU63OCWyWNulRpiG+M1v6ACC0t9Zzf +KHmY8gQY+U2uOKhFz33xd8WLhZtYH7ODRhj+/MMoFcNV/BPIj9U/hUKDj8/vBcylsb1 IMng== X-Gm-Message-State: APzg51B0WiZcgZPqQb0vJYQVlokZkorj2hiXIjGqV5C9zWCJddW8BEMR XzoKlY7vmbp8DpKJj+0qtEilQAy0cbc= X-Google-Smtp-Source: ANB0VdaZJGNle6aly2A+tyV7+kg+rfDZiTG2iVUBdUIROh+++RKs3V6TjQHtIL4wUHVHgXkZVY2cUQ== X-Received: by 2002:a1c:501:: with SMTP id 1-v6mr20834864wmf.140.1537373056596; Wed, 19 Sep 2018 09:04:16 -0700 (PDT) Received: from bidouze.dev.6wind.com. (host.78.145.23.62.rev.coltfrance.com. [62.23.145.78]) by smtp.gmail.com with ESMTPSA id x24-v6sm34983671wrd.13.2018.09.19.09.04.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 19 Sep 2018 09:04:15 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Wed, 19 Sep 2018 18:03:42 +0200 Message-Id: <52d2e15926c5c190cb9e98e1b462b3e1e2057842.1537372746.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2 12/13] ethdev: process declarative eth devargs 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: Wed, 19 Sep 2018 16:04:17 -0000 Process the eth parameters of a devargs. For each parameters that have a setter implemented, the relevant field in rte_eth_dev field is written. Currently only "name" is implemented. Signed-off-by: Gaetan Rivet --- lib/librte_ethdev/ethdev_private.h | 5 +++ lib/librte_ethdev/rte_class_eth.c | 72 ++++++++++++++++++++++++++++++ lib/librte_ethdev/rte_ethdev.c | 7 +++ 3 files changed, 84 insertions(+) diff --git a/lib/librte_ethdev/ethdev_private.h b/lib/librte_ethdev/ethdev_private.h index 0f5c6d5c4..c0c065165 100644 --- a/lib/librte_ethdev/ethdev_private.h +++ b/lib/librte_ethdev/ethdev_private.h @@ -19,6 +19,11 @@ struct rte_eth_dev * eth_find_device(const struct rte_eth_dev *_start, rte_eth_cmp_t cmp, const void *data); +/* Generic rte_eth_dev parameters processor. */ +int +rte_eth_dev_args_parse(struct rte_eth_dev *eth_dev, + struct rte_devargs *da); + #ifdef __cplusplus } #endif diff --git a/lib/librte_ethdev/rte_class_eth.c b/lib/librte_ethdev/rte_class_eth.c index 66fd48dc2..7a8b81423 100644 --- a/lib/librte_ethdev/rte_class_eth.c +++ b/lib/librte_ethdev/rte_class_eth.c @@ -6,9 +6,11 @@ #include #include +#include #include #include #include +#include #include "rte_ethdev.h" #include "rte_ethdev_core.h" @@ -35,6 +37,19 @@ struct eth_dev_match_arg { .kvlist = (k), \ }) +typedef int (*eth_dev_set_t)(struct rte_eth_dev *edev, const char *value); + +static enum eth_params +ethdev_param_id(const char *key) +{ + int i; + + for (i = 0; i < RTE_ETH_PARAMS_MAX; i++) + if (strcmp(key, eth_params_keys[i]) == 0) + return i; + return RTE_ETH_PARAMS_MAX; +} + static int eth_dev_match(const struct rte_eth_dev *edev, const void *_arg) @@ -79,6 +94,63 @@ eth_dev_iterate(const void *start, return edev; } +static int +eth_dev_set_name(struct rte_eth_dev *edev, + const char *value) +{ + size_t n; + + n = strlcpy(edev->data->name, value, + sizeof(edev->data->name)); + + /* Name was truncated. */ + if (n >= sizeof(edev->data->name)) { + RTE_LOG(ERR, EAL, "Name %s is too long\n", value); + return -1; + } + return 0; +} + +static int +ethdev_args_process(const char *key, + const char *value, + void *_edev) +{ + static eth_dev_set_t eth_dev_set[] = { + [RTE_ETH_PARAMS_NAME] = eth_dev_set_name, + [RTE_ETH_PARAMS_MAX] = NULL, + }; + struct rte_eth_dev *edev = _edev; + int param; + + param = ethdev_param_id(key); + if (eth_dev_set[param]) + return eth_dev_set[param](edev, value); + return 0; +} + +int +rte_eth_dev_args_parse(struct rte_eth_dev *edev, + struct rte_devargs *devargs) +{ + struct rte_kvargs *kvargs = NULL; + int ret; + + if (devargs == NULL || devargs->cls_str == NULL) + return 0; + + kvargs = rte_kvargs_parse_delim(devargs->cls_str, eth_params_keys, "/"); + if (kvargs == NULL) { + RTE_LOG(ERR, EAL, "cannot parse argument list\n"); + return -EINVAL; + } + ret = rte_kvargs_process(kvargs, NULL, ethdev_args_process, edev); + rte_kvargs_free(kvargs); + if (ret != 0) + return -1; + return 0; +} + struct rte_class rte_class_eth = { .dev_iterate = eth_dev_iterate, }; diff --git a/lib/librte_ethdev/rte_ethdev.c b/lib/librte_ethdev/rte_ethdev.c index aa7730ce2..b03fe7f4b 100644 --- a/lib/librte_ethdev/rte_ethdev.c +++ b/lib/librte_ethdev/rte_ethdev.c @@ -41,6 +41,7 @@ #include "rte_ethdev.h" #include "rte_ethdev_driver.h" #include "ethdev_profile.h" +#include "ethdev_private.h" int rte_eth_dev_logtype; @@ -3504,6 +3505,12 @@ rte_eth_dev_create(struct rte_device *device, const char *name, } } + retval = rte_eth_dev_args_parse(ethdev, device->devargs); + if (retval) { + RTE_LOG(ERR, EAL, "ethdev parsing failed"); + goto probe_failed; + } + retval = ethdev_init(ethdev, init_params); if (retval) { RTE_LOG(ERR, EAL, "ethdev initialisation failed"); -- 2.18.0