From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f193.google.com (mail-wr0-f193.google.com [209.85.128.193]) by dpdk.org (Postfix) with ESMTP id C70CCA84E for ; Thu, 15 Mar 2018 18:50:18 +0100 (CET) Received: by mail-wr0-f193.google.com with SMTP id m12so9116244wrm.13 for ; Thu, 15 Mar 2018 10:50:18 -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 :in-reply-to:references; bh=lkJg5HynZOfx0U0k3o7RTSocWckEmdwbP53iZj9fMWc=; b=11t8T0WqVyQ4Ui8JF6oi4J5JKZdk/JubdrMnKpQ6bl27CuNULM2nrBUdnpfMv/thJZ CtZq89iM0AOXu6UNkYIfgIiszanKnU5cTl/1a2uSt5GjtoUfUmrKJkbBYIjw+TRdEyGb LV96xOhjig+cg6d+uJ4VRHW2GbGdGFpmx5wZOchBKBVYhswZY9VCgdH5aNQzlk00gCmq mcL0/KTmHpRbZmM5LR5w6flrQRkz13pwY6X8zSe0ICJd22r07JLVXMazAz/b4/1T6cvd FLJ9v44eFtpj+qSgzNsSqj/rdGwKoKzuqEnyVFQXzL7pyX7B26lpacDn3kfHPsRWfucH TyTw== 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:in-reply-to:references; bh=lkJg5HynZOfx0U0k3o7RTSocWckEmdwbP53iZj9fMWc=; b=HtH+I+ssLm69rgMuT33UvnkHwPMVsX5Z7noMWtg0h6AIS3b1L9hjdOmGm7JXQOQOci h62kgK/2EAA+PRJwDQLBsAwAbNmJMxo5R0PmEufMC2VBxnSXeSOpilph4YpqIaR+tUz6 2lU7aa5yGsRsymiZCwvEfPchMEsi8xnNkfHSDEXkqZrU9CCg5YQs4V5BMcLn+X5zqzVW sgt3eJoYEJW5rbdXL6tY2r5BhUepk776EBkCiXinSUDw5mrWVkbakMMpAtwEk/Zc0KPE WhF333hlrIv7U3xPXLArr/wgZIaSlRGabN/q/C4ZFfNjzwJuGcoHRjWUxqgih6MJZqYm amog== X-Gm-Message-State: AElRT7FdkFD9p0jy9K1N1AvVaogA8FrPB9Zg43frSZU3ShqBfQmuu/op EBgh5hXS7rhetg5OxHonep2U2EbN X-Google-Smtp-Source: AG47ELtJci5BxuD+CLdbnzwToh5rwd5dR4D7Rw3WaWmEQBiDLlUB5ShaS4qXrhoMop31NSPsomPz9g== X-Received: by 10.223.150.11 with SMTP id b11mr3814442wra.55.1521136217912; Thu, 15 Mar 2018 10:50:17 -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 69sm4756596wmp.36.2018.03.15.10.50.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Mar 2018 10:50:16 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 15 Mar 2018 18:49:36 +0100 Message-Id: X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v1 06/18] eal/dev: implement device iteration initialization 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: Thu, 15 Mar 2018 17:50:19 -0000 Parse a device description. Split this description in their relevant part for both abstraction layer. No dynamic allocation is performed. Signed-off-by: Gaetan Rivet --- lib/librte_eal/common/eal_common_dev.c | 58 +++++++++++++++++++++++++++++++++ lib/librte_eal/common/include/rte_dev.h | 23 +++++++++++++ lib/librte_eal/rte_eal_version.map | 1 + 3 files changed, 82 insertions(+) diff --git a/lib/librte_eal/common/eal_common_dev.c b/lib/librte_eal/common/eal_common_dev.c index 4032f1bd8..bdab1423a 100644 --- a/lib/librte_eal/common/eal_common_dev.c +++ b/lib/librte_eal/common/eal_common_dev.c @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -245,3 +246,60 @@ rte_eal_hotplug_remove(const char *busname, const char *devname) rte_eal_devargs_remove(busname, devname); return ret; } + +int __rte_experimental +rte_dev_iterator_init(struct rte_dev_iterator *it, const char *str) +{ + struct rte_bus *bus = NULL; + struct rte_class *cls = NULL; + struct rte_kvarg kv; + + /* Having both busstr and clsstr NULL is illegal, + * marking this iterator as invalid unless + * everything goes well. + */ + it->busstr = NULL; + it->clsstr = NULL; + /* Safety checks and prep-work */ + if (rte_parse_kv(str, &kv)) { + RTE_LOG(ERR, EAL, "Could not parse: %s\n", str); + return -1; + } + it->device = NULL; + it->class_device = NULL; + if (strcmp(kv.key, "bus") == 0) { + char *slash; + + bus = rte_bus_find_by_name(kv.value); + it->busstr = str; + slash = strchr(str, '/'); + if (slash != NULL) { + if (rte_parse_kv(slash + 1, &kv)) + return -1; + cls = rte_class_find_by_name(kv.value); + it->clsstr = slash + 1; + } + } else if (strcmp(kv.key, "class") == 0) { + cls = rte_class_find_by_name(kv.value); + it->clsstr = str; + } else { + rte_errno = EINVAL; + return -rte_errno; + } + /* The string should have at least + * one layer specified. + */ + if (bus == NULL && cls == NULL) { + rte_errno = EINVAL; + return -rte_errno; + } + if ((bus != NULL && bus->dev_iterate == NULL) || + (cls != NULL && cls->dev_iterate == NULL)) { + rte_errno = ENOTSUP; + return -rte_errno; + } + it->devstr = str; + it->bus = bus; + it->cls = cls; + return 0; +} diff --git a/lib/librte_eal/common/include/rte_dev.h b/lib/librte_eal/common/include/rte_dev.h index d272d7191..9b53f0ad3 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -299,6 +299,29 @@ struct rte_dev_iterator { */ typedef struct rte_device *(*rte_dev_iterate_t)(struct rte_dev_iterator *it); +/** + * Initializes a device iterator. + * + * This iterator allows accessing a list of devices matching a criteria. + * The device matching is made among all buses and classes currently registered, + * filtered by the device description given as parameter. + * + * This function will not allocate any memory. It is safe to stop the + * iteration at any moment and let the iterator go out of context. + * + * @param it + * Device iterator handle. + * + * @param str + * Device description string. + * + * @return + * 0 on successful initialization. + * <0 on error. + */ +int __rte_experimental +rte_dev_iterator_init(struct rte_dev_iterator *it, const char *str); + #ifdef __cplusplus } #endif diff --git a/lib/librte_eal/rte_eal_version.map b/lib/librte_eal/rte_eal_version.map index 910cb23c9..921da3075 100644 --- a/lib/librte_eal/rte_eal_version.map +++ b/lib/librte_eal/rte_eal_version.map @@ -228,6 +228,7 @@ EXPERIMENTAL { rte_mp_sendmsg; rte_mp_request; rte_mp_reply; + rte_dev_iterator_init; rte_service_attr_get; rte_service_attr_reset_all; rte_service_component_register; -- 2.11.0