From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from out3-smtp.messagingengine.com (out3-smtp.messagingengine.com [66.111.4.27]) by dpdk.org (Postfix) with ESMTP id 18AFA1B5DE for ; Wed, 10 Oct 2018 21:23:39 +0200 (CEST) Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id B8BD522169; Wed, 10 Oct 2018 15:23:38 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 10 Oct 2018 15:23:38 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=monjalon.net; h= from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; s=mesmtp; bh=HrolM9gBaj UVBb3eUsWMgNj0899cI65t1vlifbtw5tk=; b=jW7rpmkpXdttWT/0rs/4YFhw6T x9LFJFZ50K/fEYjZ3npwamKpl0Q3Uh7OCfiGIL8lDOmRny+Jry9ITVQV3cvVPRa6 I3nXtDuW1/gL738OnxYc31rLQKJK49stFfpNsDa7WT3i9OC3503CCXNarVcEiiQW Pamm285a7SeEFObuQ= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :in-reply-to:message-id:mime-version:references:subject:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; bh=HrolM9gBajUVBb3eUsWMgNj0899cI65t1vlifbtw5tk=; b=ZhTI1wyG 1O61Ui+kIjZ/LPAxRSdWMl9BJCLjNGWdQ0ruvyXzJK3lyrMWQ8z6FK572tH2srl7 CWvgAA7falCEhnfJqQy/TysjoTkW7JUA6KWjeJ0aAjai9kdDEr9U0JRNMMNRI6C6 DCLp+llJ5YrO39sxcKWqqtrYuKFBMnPP5biyqEcf8DZ5Qet6DZ0CsllapBAYPLIf c0R3zvdbgmVLywMDFRR4hgJaeotbcRExDg/FgwWneTjsHca0FWe9YVWauaSkEZWz vFjm8pqyBX6zNm9KYuymmCFH7sAR+3BaCLJ1KddrjVW0O6vqRp7c5dT4FKlzuCZb NrdtZay490VG/Q== X-ME-Sender: X-ME-Proxy: Received: from xps.monjalon.net (184.203.134.77.rev.sfr.net [77.134.203.184]) by mail.messagingengine.com (Postfix) with ESMTPA id 6D718E4898; Wed, 10 Oct 2018 15:23:37 -0400 (EDT) From: Thomas Monjalon To: dev@dpdk.org Cc: gaetan.rivet@6wind.com, ophirmu@mellanox.com, ferruh.yigit@intel.com, arybchenko@solarflare.com, olivier.matz@6wind.com, remy.horton@intel.com, bruce.richardson@intel.com Date: Wed, 10 Oct 2018 21:23:30 +0200 Message-Id: <20181010192330.21105-5-thomas@monjalon.net> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181010192330.21105-1-thomas@monjalon.net> References: <20181009021858.19216-1-thomas@monjalon.net> <20181010192330.21105-1-thomas@monjalon.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 4/4] ethdev: support MAC address as iterator filter 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, 10 Oct 2018 19:23:39 -0000 The MAC addresses of a port can be matched with devargs. As the conflict between rte_ether.h and netinet/ether.h is not resolved, the MAC parsing is done with a rte_cmdline function. As a result, cmdline library becomes a dependency of ethdev. Signed-off-by: Thomas Monjalon --- lib/Makefile | 1 + lib/librte_cmdline/meson.build | 4 ++++ lib/librte_ethdev/Makefile | 2 +- lib/librte_ethdev/meson.build | 2 +- lib/librte_ethdev/rte_class_eth.c | 36 +++++++++++++++++++++++++++++++ lib/meson.build | 5 +++-- 6 files changed, 46 insertions(+), 4 deletions(-) diff --git a/lib/Makefile b/lib/Makefile index 8c839425d..a264945d3 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -25,6 +25,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_ETHER) += librte_ethdev DEPDIRS-librte_ethdev := librte_net librte_eal librte_mempool librte_ring DEPDIRS-librte_ethdev += librte_mbuf DEPDIRS-librte_ethdev += librte_kvargs +DEPDIRS-librte_ethdev += librte_cmdline 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_cmdline/meson.build b/lib/librte_cmdline/meson.build index 5741817ac..30498906c 100644 --- a/lib/librte_cmdline/meson.build +++ b/lib/librte_cmdline/meson.build @@ -1,6 +1,10 @@ # SPDX-License-Identifier: BSD-3-Clause # Copyright(c) 2017 Intel Corporation +# This library is processed before EAL +includes = [global_inc] +includes += include_directories('../librte_eal/common/include') + version = 2 sources = files('cmdline.c', 'cmdline_cirbuf.c', diff --git a/lib/librte_ethdev/Makefile b/lib/librte_ethdev/Makefile index e27bcd5ac..3e27ae466 100644 --- a/lib/librte_ethdev/Makefile +++ b/lib/librte_ethdev/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 -lrte_kvargs +LDLIBS += -lrte_mbuf -lrte_kvargs -lrte_cmdline EXPORT_MAP := rte_ethdev_version.map diff --git a/lib/librte_ethdev/meson.build b/lib/librte_ethdev/meson.build index 6783013fd..a4d850268 100644 --- a/lib/librte_ethdev/meson.build +++ b/lib/librte_ethdev/meson.build @@ -26,4 +26,4 @@ headers = files('rte_ethdev.h', 'rte_tm.h', 'rte_tm_driver.h') -deps += ['net', 'kvargs'] +deps += ['net', 'kvargs', 'cmdline'] diff --git a/lib/librte_ethdev/rte_class_eth.c b/lib/librte_ethdev/rte_class_eth.c index fca7fe4d4..16b47c3bc 100644 --- a/lib/librte_ethdev/rte_class_eth.c +++ b/lib/librte_ethdev/rte_class_eth.c @@ -4,6 +4,7 @@ #include +#include #include #include #include @@ -16,11 +17,13 @@ #include "ethdev_private.h" enum eth_params { + RTE_ETH_PARAM_MAC, RTE_ETH_PARAM_REPRESENTOR, RTE_ETH_PARAM_MAX, }; static const char * const eth_params_keys[] = { + [RTE_ETH_PARAM_MAC] = "mac", [RTE_ETH_PARAM_REPRESENTOR] = "representor", [RTE_ETH_PARAM_MAX] = NULL, }; @@ -36,6 +39,33 @@ struct eth_dev_match_arg { .kvlist = (k), \ }) +static int +eth_mac_cmp(const char *key __rte_unused, + const char *value, void *opaque) +{ + int ret; + struct ether_addr mac; + const struct rte_eth_dev_data *data = opaque; + struct rte_eth_dev_info dev_info; + uint32_t index; + + /* Parse devargs MAC address. */ + /* + * cannot use ether_aton_r(value, &mac) + * because of include conflict with rte_ether.h + */ + ret = cmdline_parse_etheraddr(NULL, value, &mac, sizeof(mac)); + if (ret < 0) + return -1; /* invalid devargs value */ + + /* Return 0 if devargs MAC is matching one of the device MACs. */ + rte_eth_dev_info_get(data->port_id, &dev_info); + for (index = 0; index < dev_info.max_mac_addrs; index++) + if (is_same_ether_addr(&mac, &data->mac_addrs[index])) + return 0; + return -1; /* no match */ +} + static int eth_representor_cmp(const char *key __rte_unused, const char *value, void *opaque) @@ -85,6 +115,12 @@ eth_dev_match(const struct rte_eth_dev *edev, /* Empty string matches everything. */ return 0; + ret = rte_kvargs_process(kvlist, + eth_params_keys[RTE_ETH_PARAM_MAC], + eth_mac_cmp, edev->data); + if (ret != 0) + return -1; + ret = rte_kvargs_process(kvlist, eth_params_keys[RTE_ETH_PARAM_REPRESENTOR], eth_representor_cmp, edev->data); diff --git a/lib/meson.build b/lib/meson.build index 3acc67e6e..f344ffdef 100644 --- a/lib/meson.build +++ b/lib/meson.build @@ -9,13 +9,14 @@ # given as a dep, no need to mention ring. This is especially true for the # core libs which are widely reused, so their deps are kept to a minimum. libraries = [ 'compat', # just a header, used for versioning - 'kvargs', + 'cmdline', # ethdev depends on cmdline for parsing functions + 'kvargs', # eal depends on kvargs 'eal', 'ring', 'mempool', 'mbuf', 'net', 'ethdev', 'pci', # core 'metrics', # bitrate/latency stats depends on this 'hash', # efd depends on this 'timer', # eventdev depends on this 'acl', 'bbdev', 'bitratestats', 'cfgfile', - 'cmdline', 'compressdev', 'cryptodev', + 'compressdev', 'cryptodev', 'distributor', 'efd', 'eventdev', 'gro', 'gso', 'ip_frag', 'jobstats', 'kni', 'latencystats', 'lpm', 'member', -- 2.19.0