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 D10737CBA for ; Wed, 21 Mar 2018 18:16:09 +0100 (CET) Received: by mail-wr0-f193.google.com with SMTP id z8so5971191wrh.7 for ; Wed, 21 Mar 2018 10:16:09 -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=BmZhmYtX6YRhG8TI1c5qX3VUQ/3M+6U8GAEECW1+9Vw=; b=r9aPnGkNIC1qw9vTeuLMPo7YVEl26ccaH+AAYRdHTZ+du8b8wfJ/at/kn0cyNKH4DD eVe8c+s2uyC0JHfGGvnEMKpK3TvOP6t242PkZIGQOQUrmIElytDMcc2bol6iKT4GYrZV qBYQ28YHhrlxT1F1Baf//F9ZcvOClBDNK4FFHImbELaoM5yVnHKFnby5DDfawCug/XBn tKJQ+4Bad0XgjG1pJFmjv1waAUNA1koujcqLiVk9BMW/wYsHx4490QfkBQTLNkTji2Pe EqhUz8u1jgjAmi0DFcet5rOvrQCtxLvuRRqBbhwI07EpCsy9mQrOTrkFAQBWHALazn7s TcSQ== 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=BmZhmYtX6YRhG8TI1c5qX3VUQ/3M+6U8GAEECW1+9Vw=; b=ArS92btL8zABUWyb5VPjN6yr7gEscKowlee3Yf1l/g7L9m/ViddKDncpkLPMuYGqxn dqnEc+29gh14uhGF+N1tm0ENoK5AgyCwOJO+HwJPmL+2NTnG0swJ44hnFEYC2q29Jz5V ClmCX6+Dqc7XPGxth2izjCFShhGce8g9/u05qPN0Rm7O8ljuNAqFxf130TQs2iiPVck1 +y2jWcAryZ2Pjh/oqeoRAsnEq8gZwTO9jCyx6SkhzZJDE0W3K9H0xi8eYChSoGd64zaH R1KZ4hIJUMcdR5fVgjM7sqKm9agWhM0kBJicoEMqq2LlvSssCrWdPxMm6uRNbHAdh6a5 ex5g== X-Gm-Message-State: AElRT7FUz+8PNT61VrPRQwzoScAWU+4ae5V48q+rb/I593bVLdcP2B5r 28vh7pP9Toyo50BFcvYnzBZK2fmk X-Google-Smtp-Source: AG47ELt8oYb8vQEgBBp+RN/xMgk4/Q6bzmIjpK1tYXlJgmgu/x9RKqDksbxnTU7CUwsZQ+/B4nxTOQ== X-Received: by 10.223.173.72 with SMTP id p66mr17013778wrc.191.1521652569011; Wed, 21 Mar 2018 10:16:09 -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 l10sm4224101wrf.37.2018.03.21.10.16.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 21 Mar 2018 10:16:07 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Wed, 21 Mar 2018 18:15:29 +0100 Message-Id: <74abf65c89ef029922659ae8efb6e000964b6e6a.1521652453.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: In-Reply-To: References: Subject: [dpdk-dev] [PATCH v2 08/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: Wed, 21 Mar 2018 17:16:10 -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 937ff6079..7ce13e068 100644 --- a/lib/librte_eal/common/include/rte_dev.h +++ b/lib/librte_eal/common/include/rte_dev.h @@ -310,6 +310,29 @@ typedef void *(*rte_dev_iterate_t)(const void *start, const char *devstr, const 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