From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-f42.google.com (mail-wr1-f42.google.com [209.85.221.42]) by dpdk.org (Postfix) with ESMTP id 39A014CB1 for ; Thu, 30 Aug 2018 15:42:39 +0200 (CEST) Received: by mail-wr1-f42.google.com with SMTP id w11-v6so8115738wrc.5 for ; Thu, 30 Aug 2018 06:42:39 -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:content-transfer-encoding; bh=vf6BtGYuBn+3R66fSCynak34q++F3TYKspOzkVzfhuo=; b=WyujyV/oJK2ttF4gpOy/HWA4JDTNodwygUO7oBKHo0D02b8r836rg4SB9nPKYgLGBq yV3E23DnD43dCcUCj1zD3npmaQQqVq9SQfffhrKp6jzmHQ/RtefK4YHADSDe0Kkmy0Ov p3TsHoQbiq8zEJWEdnIDundXqC8Kim2Ik4nEPhQzgMa7MJCBWXkd/kdiT17NV/BJrOr6 3l3BAcp+nTmrE9SzuA/3zyDe0wSUHzFvpmlCR4QQWHtNU8Y+cB+sjUz98pliRCUZ/qNg TkHL1rNcuXBN+Nm6t5NmIlojclFqiT7I6igChwCBJwxVsisFTLhR7t03bRuryuII9IlK WjFw== 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:content-transfer-encoding; bh=vf6BtGYuBn+3R66fSCynak34q++F3TYKspOzkVzfhuo=; b=e4FE9oM1Q8/qhBBYXIStE4VsxrRmwxjeBfHBiooLkfQxOB4WJlj2XmukB3z23H1aBW Gh0N++juIKspMT7GEWpkZAcJHdB6CrSa+a9RbAsJQWhgebc6BE2foklY0W3nbVhQJafm ZhweJqc6rxhhPD/4+v2RZfycE9mGFFhToFdApj5LJJ2v83LpPA533ilGokhdx0pX+YUg n1is6/EHzt9JM9Yag7kIboW/b8Mrsze1nHueQZ8PCdDESembEgcB6uUThhFs8rzQ6vzt g9r8jLpt2w76tEi6CWM2EWOsxcRT+ksX/sekjniea/nfmn42P324qUB+H97vkWnA+XxV L15Q== X-Gm-Message-State: APzg51C8ghqSRsCBq+e7uh+hCUuWMCpW6tpIxjpLSEvwrtJLTOSkv+J9 SMQIzCodQk2p2yH2y35cLK0pvL8ikwc= X-Google-Smtp-Source: ANB0VdbgWagqtUUn8iyPbi8nqhECKTb109upTrPBbjnLdaMwVTsgppmeZtven4arulk4Wygfknk4Ew== X-Received: by 2002:adf:a708:: with SMTP id c8-v6mr7704497wrd.56.1535636558564; Thu, 30 Aug 2018 06:42:38 -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 w10-v6sm5247731wrp.31.2018.08.30.06.42.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 30 Aug 2018 06:42:37 -0700 (PDT) From: Gaetan Rivet To: dev@dpdk.org Cc: Gaetan Rivet Date: Thu, 30 Aug 2018 15:41:56 +0200 Message-Id: X-Mailer: git-send-email 2.18.0 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v1 05/13] ethdev: add private generic device iterator 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, 30 Aug 2018 13:42:39 -0000 This iterator can be customized with a comparison function that will trigger a stopping condition. It can be leveraged to write several different iterators that have similar but non-identical purposes. It is private to librte_ethdev. Signed-off-by: Gaetan Rivet --- lib/librte_ethdev/Makefile | 1 + lib/librte_ethdev/eth_private.c | 31 +++++++++++++++++++++++++++++++ lib/librte_ethdev/eth_private.h | 26 ++++++++++++++++++++++++++ lib/librte_ethdev/meson.build | 3 ++- 4 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 lib/librte_ethdev/eth_private.c create mode 100644 lib/librte_ethdev/eth_private.h diff --git a/lib/librte_ethdev/Makefile b/lib/librte_ethdev/Makefile index 0935a275e..3c1c92cb9 100644 --- a/lib/librte_ethdev/Makefile +++ b/lib/librte_ethdev/Makefile @@ -18,6 +18,7 @@ EXPORT_MAP := rte_ethdev_version.map LIBABIVER := 10 +SRCS-y += eth_private.c SRCS-y += rte_ethdev.c SRCS-y += rte_flow.c SRCS-y += rte_tm.c diff --git a/lib/librte_ethdev/eth_private.c b/lib/librte_ethdev/eth_private.c new file mode 100644 index 000000000..d565568a0 --- /dev/null +++ b/lib/librte_ethdev/eth_private.c @@ -0,0 +1,31 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Gaëtan Rivet + */ + +#include "rte_ethdev.h" +#include "eth_private.h" + +struct rte_eth_dev * +eth_find_device(const struct rte_eth_dev *start, rte_eth_cmp_t cmp, + const void *data) +{ + struct rte_eth_dev *edev; + ptrdiff_t idx; + + /* Avoid Undefined Behaviour */ + if (start != NULL && + (start < &rte_eth_devices[0] || + start > &rte_eth_devices[RTE_MAX_ETHPORTS])) + return NULL; + if (start != NULL) + idx = start - &rte_eth_devices[0] + 1; + else + idx = 0; + for (; idx < RTE_MAX_ETHPORTS; idx++) { + edev = &rte_eth_devices[idx]; + if (cmp(edev, data) == 0) + return edev; + } + return NULL; +} + diff --git a/lib/librte_ethdev/eth_private.h b/lib/librte_ethdev/eth_private.h new file mode 100644 index 000000000..0f5c6d5c4 --- /dev/null +++ b/lib/librte_ethdev/eth_private.h @@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright(c) 2018 Gaëtan Rivet + */ + +#ifndef _RTE_ETH_PRIVATE_H_ +#define _RTE_ETH_PRIVATE_H_ + +#include "rte_ethdev.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* Generic rte_eth_dev comparison function. */ +typedef int (*rte_eth_cmp_t)(const struct rte_eth_dev *, const void *); + +/* Generic rte_eth_dev iterator. */ +struct rte_eth_dev * +eth_find_device(const struct rte_eth_dev *_start, rte_eth_cmp_t cmp, + const void *data); + +#ifdef __cplusplus +} +#endif + +#endif /* _RTE_ETH_PRIVATE_H_ */ diff --git a/lib/librte_ethdev/meson.build b/lib/librte_ethdev/meson.build index 596cd0f39..372d3ca06 100644 --- a/lib/librte_ethdev/meson.build +++ b/lib/librte_ethdev/meson.build @@ -4,7 +4,8 @@ name = 'ethdev' version = 10 allow_experimental_apis = true -sources = files('ethdev_profile.c', +sources = files('eth_private.c', + 'ethdev_profile.c', 'rte_ethdev.c', 'rte_flow.c', 'rte_mtr.c', -- 2.18.0