From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f195.google.com (mail-wr0-f195.google.com [209.85.128.195]) by dpdk.org (Postfix) with ESMTP id 05CECAAD0 for ; Thu, 15 Mar 2018 18:50:24 +0100 (CET) Received: by mail-wr0-f195.google.com with SMTP id s12so6650718wre.7 for ; Thu, 15 Mar 2018 10:50:23 -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 :mime-version:in-reply-to:references:content-transfer-encoding; bh=W+RcLfyv+jpqEbXbZeE/WYszaqbD7P3ejNsItk6cU6o=; b=jZ+USKVyb3CJJiHv8+xfS0jaGwuKS9Etr1DzeJsROQ7oBMC0EblFkX1iQVR1ua/qcb G4RzlKya3B+NIwpsUKlSgEAiwlf8SP/lJovmRY5keCJ7OCt+TpOL55q0udNoAbXTrqC9 +XSgi3BewSWcXu3E18GAW0M61jFr9CuGB7WfYPTLPrHsKPSHcr1+aDxsgvTLAgEk24PO TfG/w+/TQeu8g0wW902vco4qJwJ6xa6PAvAIX0q/viOnPF9Y1CwLDiLvV/Nj3yb7H7Mt L+jwl+WsOwtcQL7bHs3kWc98k31mpSokaDX2Pulo+MYbgiG3YhVu/K9T4I1BTGqIxT5l HM0A== 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:mime-version:in-reply-to:references :content-transfer-encoding; bh=W+RcLfyv+jpqEbXbZeE/WYszaqbD7P3ejNsItk6cU6o=; b=Bsjl9nwk6M36MiuTDdl/Atv1QghZ55KgXYjv9SMhnF19O8PYn93TSVxQHN/6CMl7yu ULyBN2hMhEADn5x/5Fui746b+kYINO+okgoL+pXMLMnD5Hkff7R8wkZTe2EifYMJW9pk D9+185tScjF/TPrVKRnioaFhoNoe3rDvK0yjjBh6bXZeUlJKYehl3/D81NeJ4mq8nFzT pf/xI3M1HmmyThAH9MkFEu+9Vz/3WIjr4TjJ7RtauwTCFEv+GEsN8/1g/DZZqBhh2lpG Kq+VvWrLnV8WxGM+ngaIpAGjH+MXsKb2u9Sv+cD+fF49XSjBnLp3kPKZulsDh00Oi2HU 1mkw== X-Gm-Message-State: AElRT7EX+U1lpmZb5+6mtNdecuJ71W17a+lfef8dv0PZVJuIFYabGhY0 94a0em49tFdLSpJoNUNiCgd+EIXk X-Google-Smtp-Source: AG47ELso0yRaGUtN6Ep/GEFjwHa1eSNXU2UKd6Os+VBJkSVBTxm1aOfCNPukvwL5kFC2+TCFXF487Q== X-Received: by 10.223.151.204 with SMTP id t12mr8450295wrb.156.1521136223224; Thu, 15 Mar 2018 10:50:23 -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.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 15 Mar 2018 10:50:22 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 15 Mar 2018 18:49:40 +0100 Message-Id: <74ca45500d7e6e137b2a4a07645f43c125ccbd29.1521124599.git.gaetan.rivet@6wind.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: References: MIME-Version: 1.0 In-Reply-To: References: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v1 10/18] ethdev: register ether layer as a class 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:25 -0000 Signed-off-by: Gaetan Rivet --- lib/Makefile | 2 +- lib/librte_ether/Makefile | 3 +- lib/librte_ether/rte_class_eth.c | 86 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 2 deletions(-) create mode 100644 lib/librte_ether/rte_class_eth.c diff --git a/lib/Makefile b/lib/Makefile index ec965a606..6bb6a8bed 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -20,7 +20,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_CMDLINE) += librte_cmdline DEPDIRS-librte_cmdline := librte_eal DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ether DEPDIRS-librte_ether := librte_net librte_eal librte_mempool librte_ring -DEPDIRS-librte_ether += librte_mbuf +DEPDIRS-librte_ether += librte_mbuf librte_kvargs 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_ether/Makefile b/lib/librte_ether/Makefile index 3ca5782bb..a1a0393de 100644 --- a/lib/librte_ether/Makefile +++ b/lib/librte_ether/Makefile @@ -12,13 +12,14 @@ CFLAGS += -DALLOW_EXPERIMENTAL_API CFLAGS += -O3 CFLAGS += $(WERROR_FLAGS) LDLIBS += -lrte_net -lrte_eal -lrte_mempool -lrte_ring -LDLIBS += -lrte_mbuf +LDLIBS += -lrte_mbuf -lrte_kvargs EXPORT_MAP := rte_ethdev_version.map LIBABIVER := 8 SRCS-y += rte_ethdev.c +SRCS-y += rte_class_eth.c SRCS-y += rte_flow.c SRCS-y += rte_tm.c SRCS-y += rte_mtr.c diff --git a/lib/librte_ether/rte_class_eth.c b/lib/librte_ether/rte_class_eth.c new file mode 100644 index 000000000..bfa821d09 --- /dev/null +++ b/lib/librte_ether/rte_class_eth.c @@ -0,0 +1,86 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Gaƫtan Rivet + */ + +#include + +#include +#include +#include +#include +#include + +#include "rte_ethdev.h" +#include "rte_ethdev_core.h" + +static int +eth_dev_match(struct rte_eth_dev *edev, + struct rte_kvargs *kvlist) +{ + (void) kvlist; + (void) edev; + return 0; +} + +static struct rte_device * +eth_dev_iterate(struct rte_dev_iterator *it) +{ + struct rte_eth_dev *start = it->class_device; + struct rte_kvargs *kvargs = NULL; + struct rte_eth_dev *edev = NULL; + struct rte_device *dev = NULL; + char *str = NULL; + uint16_t p = 0; + + if (it->clsstr != NULL) { + char *slash; + + str = strdup(it->clsstr); + if (str == NULL) { + RTE_LOG(ERR, EAL, "cannot allocate string copy\n"); + rte_errno = ENOMEM; + return NULL; + } + slash = strchr(str, '/'); + slash = slash ? slash : strchr(str, '\0'); + if (slash == NULL) { + RTE_LOG(ERR, EAL, "malformed string\n"); + rte_errno = EINVAL; + goto free_str; + } + slash[0] = '\0'; + kvargs = rte_kvargs_parse(str, NULL); + if (kvargs == NULL) { + RTE_LOG(ERR, EAL, "cannot parse argument list\n"); + rte_errno = EINVAL; + goto free_str; + } + } + if (start) + p = start->data->port_id + 1; + dev = it->device; + for (p = rte_eth_find_next(p); + p < RTE_MAX_ETHPORTS; + p = rte_eth_find_next(p + 1)) { + edev = &rte_eth_devices[p]; + if (dev != edev->device) + continue; + if (eth_dev_match(edev, kvargs) == 0) { + it->class_device = edev; + goto free_str; + } + } + dev = NULL; +free_str: + if (it->clsstr != NULL) { + rte_kvargs_free(kvargs); + free(str); + } + return dev; +} + +struct rte_class rte_class_eth = { + .dev_iterate = eth_dev_iterate, +}; + +RTE_REGISTER_CLASS(eth, rte_class_eth); -- 2.11.0