From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr0-f196.google.com (mail-wr0-f196.google.com [209.85.128.196]) by dpdk.org (Postfix) with ESMTP id 9D2701B667 for ; Sun, 15 Apr 2018 17:08:37 +0200 (CEST) Received: by mail-wr0-f196.google.com with SMTP id q13so15871965wre.3 for ; Sun, 15 Apr 2018 08:08:37 -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=0yrOYTyEYRmKpjxbUW9Sta2CECu8ZMnppErt3D9qCtE=; b=1gGgjq25W2ASlxs/NBRKIXx2V1X+jf+yrY7P6ZF485LizWV1rk7ANOq7SSUA+MvZxj WcdAQWU9bH3hwLKk0qHgPHpDnyfD3dxMC2HzWIMM/o/n9nPTORQ+zLe5EFxv7QLwtAMx ox9NQbJBmfVrnysztdoBv0WGunMeoUCL0vtFhxbmbWHCxQ9kdtnxQ3fklxHAQORd1oVG xkGaBpOSRO++coSiMqNDpjISC536qgkWH5UZpW5ON03QNKepccgjPbZOVEKSIn/YlA2N upof7hnspJ/BLmT9d3xeQGzmvzVAwipKL0dNXppe6uGmiXC136sAFYlb+uiL6cMzryMP lmcQ== 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=0yrOYTyEYRmKpjxbUW9Sta2CECu8ZMnppErt3D9qCtE=; b=XF4hmW5YIkS/1dM/d+QDwaBbwQqdjcm3R71Lxl8MhWbRt7LWtIzoZyfY60tidVS374 S8531dLrlZH0dbfBMUCvmUgXyT2HnDLOmaTzTJuhe+bwRpgjVWCz8T0WpXfoADcxn3FT cyiwoQ+uKnl9MdNlPKI7e8o+IfwgcG6YyZo+ckZ6JjZ79Z/wTBdGyf/7cDBHZNhd9+Oe pQObPCzK/yAgJdd8RaW8eLAy2tJjpBDTtKYfgvUFrX+dI0n4AgKwq5+KWRTNuSM70hMG 8E5MkEmgd/KjWsVtZto50AHQ5u7AHSlyV+xqZX7zpT4rxKtLVFDPFtFrsS6y+6BJ3nhp XoyA== X-Gm-Message-State: ALQs6tCdPQvSZ3CMMOqr+FV4cF5ysbsGeD0VnWQ8NE2zBm30IBoa9+b0 hpnQGmPRzTjSS2DwB8CdxeEC1do2 X-Google-Smtp-Source: AIpwx488qj1Q9jSAlRyzZCdpfJzYsbRRJEn1tmgX4jNaPoH6PkpchWNVAtgPKxDW/d8ZhZTRZdfQZA== X-Received: by 10.28.202.7 with SMTP id a7mr8771708wmg.93.1523804915950; Sun, 15 Apr 2018 08:08:35 -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 r200sm13673438wmb.39.2018.04.15.08.08.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 15 Apr 2018 08:08:34 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Sun, 15 Apr 2018 17:07:49 +0200 Message-Id: <84667d408935896bfc370ac19596a77bc773924e.1523804657.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 v7 20/22] 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: Sun, 15 Apr 2018 15:08:37 -0000 Signed-off-by: Gaetan Rivet --- lib/Makefile | 2 +- lib/librte_ether/Makefile | 3 +- lib/librte_ether/rte_class_eth.c | 79 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 82 insertions(+), 2 deletions(-) create mode 100644 lib/librte_ether/rte_class_eth.c diff --git a/lib/Makefile b/lib/Makefile index 4206485d3..47513f03f 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -23,7 +23,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 2fa133fbc..d4c3a8d06 100644 --- a/lib/librte_ether/Makefile +++ b/lib/librte_ether/Makefile @@ -12,7 +12,7 @@ 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 @@ -20,6 +20,7 @@ LIBABIVER := 9 SRCS-y += eth_private.c 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..32c736d32 --- /dev/null +++ b/lib/librte_ether/rte_class_eth.c @@ -0,0 +1,79 @@ +/* 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" +#include "eth_private.h" + +enum eth_params { + RTE_ETH_PARAMS_MAX, +}; + +static const char * const eth_params_keys[] = { + [RTE_ETH_PARAMS_MAX] = NULL, +}; + +struct eth_dev_match_arg { + struct rte_device *device; + struct rte_kvargs *kvlist; +}; + +#define eth_dev_match_arg(d, k) \ + (&(const struct eth_dev_match_arg) { \ + .device = (d), \ + .kvlist = (k), \ + }) + +static int +eth_dev_match(const struct rte_eth_dev *edev, + const void *_arg) +{ + const struct eth_dev_match_arg *arg = _arg; + const struct rte_kvargs *kvlist = arg->kvlist; + + if (edev->state == RTE_ETH_DEV_UNUSED) + return -1; + if (edev->device != arg->device) + return -1; + if (kvlist == NULL) + /* Empty string matches everything. */ + return 0; + return 0; +} + +static void * +eth_dev_iterate(const void *start, + const char *str, + const struct rte_dev_iterator *it) +{ + struct rte_kvargs *kvargs = NULL; + struct rte_eth_dev *edev = NULL; + + if (str != NULL) { + kvargs = rte_kvargs_parse(str, eth_params_keys); + if (kvargs == NULL) { + RTE_LOG(ERR, EAL, "cannot parse argument list\n"); + rte_errno = EINVAL; + return NULL; + } + } + edev = eth_find_device(start, eth_dev_match, + eth_dev_match_arg(it->device, kvargs)); + rte_kvargs_free(kvargs); + return edev; +} + +struct rte_class rte_class_eth = { + .dev_iterate = eth_dev_iterate, +}; + +RTE_REGISTER_CLASS(eth, rte_class_eth); -- 2.11.0