From patchwork Wed Jun 21 08:10:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bogdan Pricope X-Patchwork-Id: 106057 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp1805889qgd; Wed, 21 Jun 2017 01:11:41 -0700 (PDT) X-Received: by 10.200.9.47 with SMTP id t44mr8066781qth.107.1498032701309; Wed, 21 Jun 2017 01:11:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498032701; cv=none; d=google.com; s=arc-20160816; b=0YUdakmlyqiOe9MzlLpyINuSgJkecKVuKRAFSH6dCJyqGoYicVTAJ9x1Lw7goYhEdQ BHmosGR28TaaXOR/dvLhPgf35bFVvB0VWdd5neNAxop+a/3q0LRhvfpmvqqKWPiuwxnz 0cSqZOFQfFNqEv+3foTKvPmq+otPXpqEU8ZYQWQHD+1kY0ltTLxkiGifo4/dxqak76w/ Hhi3+mv015ya6xACmXgQMOdjBHee+ybzDrKFE6Xl9s1LJ+YM4xEEXhMx8WuLGIEM7oGc P8KQ9VNzyDM0K7x81kuzk8KxnP/pCofXNQ3E3+neLAqsfphD8ZOAo9Wo/qSrPqzOLcWQ RD5g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject:references:in-reply-to :message-id:date:to:from:delivered-to:arc-authentication-results; bh=INa48bboNISO93ifD41GfHa5wVmlqFDRZ4/GC7fP+4U=; b=0vpXywvA8Bq5lJB7c+KweIOpviyxDdWM8jpn51L82AkICk6ni8A99OWp/v/uspmMQV aIifcHbq26tD4qpkX+/eUy1kBo5/ewHO2avwjeCuZ3+HFMXeLnnQ/aGQeakhCG5XGEo2 kRHu3X4oeRUycZIurY13burXEhVfMMmKANP6+lWJA5hQl7RtKq+tHM9nMk+8HA4z8ytr +B2EWzssmz2qDrz8XcHa0j6nKcW/Hej9MV1htyjD28LScS3+ZwbVtGTefqQpG26neE00 EW1EDWCDKSMNNkzDhNoIj2Gb1hv5+vBFs3vTk0hymRrazeYinNBUaIwh/cTLZpic+uTv ixQQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.linaro.org (lists.linaro.org. [54.225.227.206]) by mx.google.com with ESMTP id t33si14199322qtt.217.2017.06.21.01.11.41; Wed, 21 Jun 2017 01:11:41 -0700 (PDT) Received-SPF: pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) client-ip=54.225.227.206; Authentication-Results: mx.google.com; spf=pass (google.com: domain of lng-odp-bounces@lists.linaro.org designates 54.225.227.206 as permitted sender) smtp.mailfrom=lng-odp-bounces@lists.linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id F32E86092B; Wed, 21 Jun 2017 08:11:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on ip-10-142-244-252 X-Spam-Level: X-Spam-Status: No, score=-3.0 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, URIBL_BLOCKED, URIBL_SBL, URIBL_SBL_A autolearn=disabled version=3.4.0 Received: from [127.0.0.1] (localhost [127.0.0.1]) by lists.linaro.org (Postfix) with ESMTP id C5EAC60845; Wed, 21 Jun 2017 08:11:29 +0000 (UTC) X-Original-To: lng-odp@lists.linaro.org Delivered-To: lng-odp@lists.linaro.org Received: by lists.linaro.org (Postfix, from userid 109) id 3198960845; Wed, 21 Jun 2017 08:11:27 +0000 (UTC) Received: from mail-wr0-f178.google.com (mail-wr0-f178.google.com [209.85.128.178]) by lists.linaro.org (Postfix) with ESMTPS id A01A160923 for ; Wed, 21 Jun 2017 08:10:58 +0000 (UTC) Received: by mail-wr0-f178.google.com with SMTP id c11so68366520wrc.3 for ; Wed, 21 Jun 2017 01:10:58 -0700 (PDT) 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; bh=INa48bboNISO93ifD41GfHa5wVmlqFDRZ4/GC7fP+4U=; b=JFnpL26FrIkoyevA7pUtTGlFuizkRYdH+ug6+iuTuDqRC8Q2KSd/eel5upJCzuh38A 6DbAhGCA55sP5kkm0ejZionmGKnzyI2tQOwZc57BoI1SQv4dQQxD/R3mnG7sg3x7JJ7q EnYQZ1IaaZQy8RJ64HgMMkjP/Z/t5pcBFkm3dFCcY3YUHsZLKQskh43lYdcAEFfDdDV+ oMM7fTgKtSfHoV1z4J41wvxaitDZ5xl5ZeNXyrxxTP7MAjJv17SyH1ZFozM2HN16QUiM RJt4v3ACnrE49cr27dYFi8l/PIyTZdiInwDAGhg6xIlcNGgRY3C8lGXP5Ooahj/wK9vP EWhw== X-Gm-Message-State: AKS2vOxGiFhG+9YqaboE/5uZQhuxacMI79t4sWw4ASLIN0VbG+FdM5MX vZpLs/QEcAfGvTVUiMOK3T02 X-Received: by 10.28.147.132 with SMTP id v126mr5590059wmd.107.1498032657115; Wed, 21 Jun 2017 01:10:57 -0700 (PDT) Received: from netbricks-team.enea.se ([193.202.22.66]) by smtp.gmail.com with ESMTPSA id y42sm14408976wrc.51.2017.06.21.01.10.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Jun 2017 01:10:56 -0700 (PDT) From: Bogdan Pricope To: lng-odp@lists.linaro.org Date: Wed, 21 Jun 2017 11:10:44 +0300 Message-Id: <1498032644-26189-2-git-send-email-bogdan.pricope@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1498032644-26189-1-git-send-email-bogdan.pricope@linaro.org> References: <1498032644-26189-1-git-send-email-bogdan.pricope@linaro.org> Subject: [lng-odp] [CLOUD-DEV] ddf: examples: add ddf module skeleton and ddf application X-BeenThere: lng-odp@lists.linaro.org X-Mailman-Version: 2.1.16 Precedence: list List-Id: "The OpenDataPlane \(ODP\) List" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: lng-odp-bounces@lists.linaro.org Sender: "lng-odp" Signed-off-by: Bogdan Pricope --- example/Makefile.am | 4 +- example/ddf_app/Makefile.am | 10 ++++ example/ddf_app/odp_ddf_app.c | 49 +++++++++++++++++++ example/ddf_ifs/Makefile.am | 26 ++++++++++ example/ddf_ifs/ddf_ifs.c | 28 +++++++++++ example/ddf_ifs/ddf_ifs.h | 18 +++++++ example/ddf_ifs/ddf_ifs_api.h | 25 ++++++++++ example/ddf_ifs/ddf_ifs_dev_dpdk.c | 25 ++++++++++ example/ddf_ifs/ddf_ifs_dev_dpdk.h | 24 +++++++++ example/ddf_ifs/ddf_ifs_devio_direct.c | 51 +++++++++++++++++++ example/ddf_ifs/ddf_ifs_devio_direct.h | 20 ++++++++ example/ddf_ifs/ddf_ifs_driver.c | 69 ++++++++++++++++++++++++++ example/ddf_ifs/ddf_ifs_driver.h | 20 ++++++++ example/ddf_ifs/ddf_ifs_enumr_class.c | 47 ++++++++++++++++++ example/ddf_ifs/ddf_ifs_enumr_class.h | 20 ++++++++ example/ddf_ifs/ddf_ifs_enumr_dpdk.c | 86 +++++++++++++++++++++++++++++++++ example/ddf_ifs/ddf_ifs_enumr_dpdk.h | 20 ++++++++ example/ddf_ifs/ddf_ifs_enumr_generic.c | 57 ++++++++++++++++++++++ example/ddf_ifs/ddf_ifs_enumr_generic.h | 20 ++++++++ example/ddf_ifs/odp.conf | 4 ++ example/m4/configure.m4 | 2 + 21 files changed, 624 insertions(+), 1 deletion(-) create mode 100644 example/ddf_app/Makefile.am create mode 100644 example/ddf_app/odp_ddf_app.c create mode 100644 example/ddf_ifs/Makefile.am create mode 100644 example/ddf_ifs/ddf_ifs.c create mode 100644 example/ddf_ifs/ddf_ifs.h create mode 100644 example/ddf_ifs/ddf_ifs_api.h create mode 100644 example/ddf_ifs/ddf_ifs_dev_dpdk.c create mode 100644 example/ddf_ifs/ddf_ifs_dev_dpdk.h create mode 100644 example/ddf_ifs/ddf_ifs_devio_direct.c create mode 100644 example/ddf_ifs/ddf_ifs_devio_direct.h create mode 100644 example/ddf_ifs/ddf_ifs_driver.c create mode 100644 example/ddf_ifs/ddf_ifs_driver.h create mode 100644 example/ddf_ifs/ddf_ifs_enumr_class.c create mode 100644 example/ddf_ifs/ddf_ifs_enumr_class.h create mode 100644 example/ddf_ifs/ddf_ifs_enumr_dpdk.c create mode 100644 example/ddf_ifs/ddf_ifs_enumr_dpdk.h create mode 100644 example/ddf_ifs/ddf_ifs_enumr_generic.c create mode 100644 example/ddf_ifs/ddf_ifs_enumr_generic.h create mode 100644 example/ddf_ifs/odp.conf -- 1.9.1 diff --git a/example/Makefile.am b/example/Makefile.am index dfc07b6..b209585 100644 --- a/example/Makefile.am +++ b/example/Makefile.am @@ -8,4 +8,6 @@ SUBDIRS = classifier \ switch \ time \ timer \ - traffic_mgmt + traffic_mgmt \ + ddf_ifs \ + ddf_app diff --git a/example/ddf_app/Makefile.am b/example/ddf_app/Makefile.am new file mode 100644 index 0000000..e654202 --- /dev/null +++ b/example/ddf_app/Makefile.am @@ -0,0 +1,10 @@ +include $(top_srcdir)/example/Makefile.inc + +bin_PROGRAMS = odp_ddf_app$(EXEEXT) +odp_ddf_app_LDFLAGS = $(AM_LDFLAGS) -shared +odp_ddf_app_CFLAGS = $(AM_CFLAGS) -I${top_srcdir}/example + +noinst_HEADERS = \ + $(top_srcdir)/example/example_debug.h + +dist_odp_ddf_app_SOURCES = odp_ddf_app.c diff --git a/example/ddf_app/odp_ddf_app.c b/example/ddf_app/odp_ddf_app.c new file mode 100644 index 0000000..c2d7abf --- /dev/null +++ b/example/ddf_app/odp_ddf_app.c @@ -0,0 +1,49 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +/** enable strtok */ +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#include +#include + +#include +#include +#include +#include + +int main(int argc, char *argv[]) +{ + odp_instance_t instance; + + (void)argc; + (void)argv; + + EXAMPLE_DBG("Start DDF Application...\n"); + + /* Initialize ODP before calling anything else */ + if (odp_init_global(&instance, NULL, NULL)) { + EXAMPLE_ERR("Error: ODP global init failed.\n"); + exit(EXIT_FAILURE); + } + + if (odp_init_local(instance, ODP_THREAD_CONTROL)) { + EXAMPLE_ERR("Error: ODP local init failed.\n"); + exit(EXIT_FAILURE); + } + + /* Print ddf objects*/ + odpdrv_print_all(); + + /* Terminate ODP */ + odp_term_local(); + odp_term_global(instance); + + EXAMPLE_DBG("Exit DDF Application.\n"); + return 0; +} diff --git a/example/ddf_ifs/Makefile.am b/example/ddf_ifs/Makefile.am new file mode 100644 index 0000000..b11cf3d --- /dev/null +++ b/example/ddf_ifs/Makefile.am @@ -0,0 +1,26 @@ +LIB = $(top_builddir)/lib + +AM_CPPFLAGS += -I$(srcdir) \ + -I$(top_srcdir)/include \ + -I$(top_srcdir)/platform/@with_platform@/include \ + -I$(top_srcdir)/platform/@with_platform@/arch/@ARCH_DIR@ + +lib_LTLIBRARIES = $(LIB)/libddf_ifs.la + +noinst_HEADERS = \ + $(srcdir)/ddf_ifs.h \ + $(srcdir)/ddf_ifs_enumr_class.h \ + $(srcdir)/ddf_ifs_enumr_dpdk.h \ + $(srcdir)/ddf_ifs_enumr_generic.h \ + $(srcdir)/ddf_ifs_dev_dpdk.h \ + $(srcdir)/ddf_ifs_devio_direct.h \ + $(srcdir)/ddf_ifs_driver.h + +__LIB__libddf_ifs_la_SOURCES = \ + ddf_ifs.c \ + ddf_ifs_enumr_class.c \ + ddf_ifs_enumr_dpdk.c \ + ddf_ifs_enumr_generic.c \ + ddf_ifs_dev_dpdk.c \ + ddf_ifs_devio_direct.c \ + ddf_ifs_driver.c diff --git a/example/ddf_ifs/ddf_ifs.c b/example/ddf_ifs/ddf_ifs.c new file mode 100644 index 0000000..cd4e48b --- /dev/null +++ b/example/ddf_ifs/ddf_ifs.c @@ -0,0 +1,28 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include "odp_drv.h" +#include "ddf_ifs.h" +#include "ddf_ifs_enumr_class.h" +#include "ddf_ifs_devio_direct.h" +#include "ddf_ifs_driver.h" + +static ODPDRV_CONSTRUCTOR void ddf_ifs_construct(void) +{ + printf("%s()\n", __func__); + + register_enumerator_class(); + + register_devio_direct(); + + register_driver(); +} + +static __attribute__((destructor)) void ddf_ifs_destruct(void) +{ + printf("%s()\n", __func__); +} diff --git a/example/ddf_ifs/ddf_ifs.h b/example/ddf_ifs/ddf_ifs.h new file mode 100644 index 0000000..980b520 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs.h @@ -0,0 +1,18 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_DDF_IFS_H_ +#define _ODP_DDF_IFS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /*_ODP_DDF_IFS_H_*/ diff --git a/example/ddf_ifs/ddf_ifs_api.h b/example/ddf_ifs/ddf_ifs_api.h new file mode 100644 index 0000000..757658e --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_api.h @@ -0,0 +1,25 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_DDF_IFS_API_H_ +#define _ODP_DDF_IFS_API_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#define DDF_IFS_DEV_API_NAME "ifs_api" +#define DDF_IFS_DEV_API_VER 0 +#define DDF_IFS_DEVIO_API_NAME "devio_api" +#define DDF_IFS_DEVIO_API_VER 0 + +#define DDF_IFS_DRV_NAME "ddf_ifs_drv" + +#ifdef __cplusplus +} +#endif + +#endif /*_ODP_DDF_IFS_API_H_*/ diff --git a/example/ddf_ifs/ddf_ifs_dev_dpdk.c b/example/ddf_ifs/ddf_ifs_dev_dpdk.c new file mode 100644 index 0000000..d66a15c --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_dev_dpdk.c @@ -0,0 +1,25 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include "odp_drv.h" +#include "ddf_ifs_dev_dpdk.h" + +odpdrv_device_t dpdk_device_create(odpdrv_enumr_t enumr, + const char *dev_addr, + void *enum_data) +{ + odpdrv_device_param_t param; + + printf("\t%s(%s)\n", __func__, dev_addr); + + param.enumerator = enumr; + strcpy(param.address, dev_addr); + param.enum_dev = enum_data; + + return odpdrv_device_create(¶m); +} diff --git a/example/ddf_ifs/ddf_ifs_dev_dpdk.h b/example/ddf_ifs/ddf_ifs_dev_dpdk.h new file mode 100644 index 0000000..2a81f6a --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_dev_dpdk.h @@ -0,0 +1,24 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_DDF_IFS_DEV_DPDK_H_ +#define _ODP_DDF_IFS_DEV_DPDK_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +#include "odp_drv.h" + +odpdrv_device_t dpdk_device_create(odpdrv_enumr_t enumr, + const char *dev_addr, + void *enum_data); + +#ifdef __cplusplus +} +#endif + +#endif /*_ODP_DDF_IFS_DEV_DPDK_H_*/ diff --git a/example/ddf_ifs/ddf_ifs_devio_direct.c b/example/ddf_ifs/ddf_ifs_devio_direct.c new file mode 100644 index 0000000..ea508a0 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_devio_direct.c @@ -0,0 +1,51 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include "odp_drv.h" +#include "ddf_ifs_api.h" +#include "ddf_ifs_devio_direct.h" + +static odpdrv_devio_t devio_direct; + +static int devio_direct_probe(odpdrv_device_t dev) +{ + (void)dev; + + printf("%s()\n", __func__); + + return 0; +} + +static int devio_direct_remove(void) +{ + printf("%s()\n", __func__); + + return 0; +} + +int register_devio_direct(void) +{ + odpdrv_devio_param_t param = { + .api_name = DDF_IFS_DEVIO_API_NAME, + .api_version = DDF_IFS_DEVIO_API_VER, + .enumr_api_name = DDF_IFS_DEV_API_NAME, + .enumr_api_version = DDF_IFS_DEV_API_VER, + .probe = devio_direct_probe, + .remove = devio_direct_remove, + .ops = NULL + }; + + printf("\t%s()\n", __func__); + + devio_direct = odpdrv_devio_register(¶m); + if (ODPDRV_DEVIO_INVALID == devio_direct) { + printf("\tError: failed to %s()\n", __func__); + return -1; + } + + return 0; +} diff --git a/example/ddf_ifs/ddf_ifs_devio_direct.h b/example/ddf_ifs/ddf_ifs_devio_direct.h new file mode 100644 index 0000000..28c549d --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_devio_direct.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_DDF_IFS_DEVIO_DIRECT_H_ +#define _ODP_DDF_IFS_DEVIO_DIRECT_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +int register_devio_direct(void); + +#ifdef __cplusplus +} +#endif + +#endif /*_ODP_DDF_IFS_DEVIO_DIRECT_H_*/ diff --git a/example/ddf_ifs/ddf_ifs_driver.c b/example/ddf_ifs/ddf_ifs_driver.c new file mode 100644 index 0000000..2dc5870 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_driver.c @@ -0,0 +1,69 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include +#include "odp_drv.h" +#include "ddf_ifs_api.h" +#include "ddf_ifs_driver.h" + +static odpdrv_driver_t ddf_ifs_driver; +static int drv_data = 12; + +static int ddf_ifs_driver_probe(odpdrv_device_t dev, odpdrv_devio_t devio, + int devio_idx) +{ + printf("%s(dev, devio, devio_idx = %d)\n", __func__, devio_idx); + + (void)devio; + + odpdrv_device_set_data(dev, (void *)&drv_data); + + return 0; +} + +static int ddf_ifs_driver_unbind(odpdrv_device_t dev, + void (*callback)(odpdrv_device_t dev), + uint32_t flags) +{ + printf("%s()\n", __func__); + + if (!(flags & ODPDRV_DRV_UNBIND_IMMEDIATE)) + return -1; /* unsupported*/ + + callback(dev); + + return 0; +} + +static int ddf_ifs_driver_remove(void) +{ + printf("%s()\n", __func__); + + return 0; +} + +int register_driver(void) +{ + odpdrv_driver_param_t param = { + .name = DDF_IFS_DRV_NAME, + .devios = {{DDF_IFS_DEVIO_API_NAME, DDF_IFS_DEVIO_API_VER}, + {"", 0}, {"", 0} }, + .probe = ddf_ifs_driver_probe, + .unbind = ddf_ifs_driver_unbind, + .remove = ddf_ifs_driver_remove, + }; + + printf("\t%s()\n", __func__); + + ddf_ifs_driver = odpdrv_driver_register(¶m); + if (ODPDRV_DRIVER_INVALID == ddf_ifs_driver) { + printf("Error: Failed to %s()\n", __func__); + return -1; + } + + return 0; +} diff --git a/example/ddf_ifs/ddf_ifs_driver.h b/example/ddf_ifs/ddf_ifs_driver.h new file mode 100644 index 0000000..4954c5a --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_driver.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_DDF_IFS_DRIVER_H_ +#define _ODP_DDF_IFS_DRIVER_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +int register_driver(void); + +#ifdef __cplusplus +} +#endif + +#endif /*_ODP_DDF_IFS_DRIVER_H_*/ diff --git a/example/ddf_ifs/ddf_ifs_enumr_class.c b/example/ddf_ifs/ddf_ifs_enumr_class.c new file mode 100644 index 0000000..a7b5d51 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_enumr_class.c @@ -0,0 +1,47 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include "odp_drv.h" +#include "ddf_ifs_enumr_class.h" +#include "ddf_ifs_enumr_dpdk.h" +#include "ddf_ifs_enumr_generic.h" + +static odpdrv_enumr_class_t enumr_class; + +static int enumr_class_ifs_probe(void) +{ + printf("%s()\n", __func__); + + if (register_enumerator_dpdk(enumr_class)) + return -1; + + if (register_enumerator_generic(enumr_class)) + return -1; + + return 0; +} + +static int enumr_class_ifs_remove(void) +{ + printf("%s()\n", __func__); + + return 0; +} + +int register_enumerator_class(void) +{ + odpdrv_enumr_class_param_t param = { + .name = "enumr_class_ifs", + .probe = enumr_class_ifs_probe, + .remove = enumr_class_ifs_remove + }; + + printf("\t%s()\n", __func__); + enumr_class = odpdrv_enumr_class_register(¶m); + + return 0; +} diff --git a/example/ddf_ifs/ddf_ifs_enumr_class.h b/example/ddf_ifs/ddf_ifs_enumr_class.h new file mode 100644 index 0000000..42c02fc --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_enumr_class.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_DDF_IFS_ENUMR_CLASS_H_ +#define _ODP_DDF_IFS_ENUMR_CLASS_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +int register_enumerator_class(void); + +#ifdef __cplusplus +} +#endif + +#endif /*_ODP_DDF_IFS_ENUMR_CLASS_H_*/ diff --git a/example/ddf_ifs/ddf_ifs_enumr_dpdk.c b/example/ddf_ifs/ddf_ifs_enumr_dpdk.c new file mode 100644 index 0000000..cc97e36 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_enumr_dpdk.c @@ -0,0 +1,86 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include "odp_drv.h" +#include "ddf_ifs_api.h" +#include "ddf_ifs_enumr_dpdk.h" +#include "ddf_ifs_dev_dpdk.h" + +static odpdrv_enumr_t dpdk_enumr; + +#define TEST_DPDK_DEV_CNT 3 +#define DDF_DPDK_DEV_MAX 10 + +static odpdrv_device_t dpdk_dev[DDF_DPDK_DEV_MAX]; +static int dpdk_dev_cnt; +static int dpdk_enumr_probe(void) +{ + int dpdk_dev_cnt_detected = TEST_DPDK_DEV_CNT; /* detected with + dpdk APIs*/ + char dev_addr[ODPDRV_NAME_ADDR_SZ]; + int i; + + printf("%s() - %d devices found\n", __func__, dpdk_dev_cnt_detected); + + if (dpdk_dev_cnt_detected > DDF_DPDK_DEV_MAX) { + dpdk_dev_cnt_detected = DDF_DPDK_DEV_MAX; + printf("\tWarning: dpdk device count scaled down to %d\n", + dpdk_dev_cnt_detected); + } + for (i = 0; i < dpdk_dev_cnt_detected; i++) { + sprintf(dev_addr, "0000:01:00.%d", i); + dpdk_dev[dpdk_dev_cnt] = dpdk_device_create(dpdk_enumr, + dev_addr, + NULL); + if (dpdk_dev[dpdk_dev_cnt] == ODPDRV_DEVICE_INVALID) + printf("\tError: unable to create device: %s\n", + dev_addr); + else + dpdk_dev_cnt++; + } + + return 0; +} + +static int dpdk_enumr_remove(void) +{ + printf("%s()\n", __func__); + return 0; +} + +static int dpdk_enumr_register_notif(void (*event_handler) (uint64_t event), + int64_t event_mask) +{ + (void)event_handler; + (void)event_mask; + + printf("%s()\n", __func__); + + return 0; +} + +int register_enumerator_dpdk(odpdrv_enumr_class_t enumr_class) +{ + struct odpdrv_enumr_param_t param = { + .enumr_class = enumr_class, + .api_name = DDF_IFS_DEV_API_NAME, + .api_version = DDF_IFS_DEV_API_VER, + .probe = dpdk_enumr_probe, + .remove = dpdk_enumr_remove, + .register_notifier = dpdk_enumr_register_notif + }; + + printf("\t%s()\n", __func__); + + dpdk_enumr = odpdrv_enumr_register(¶m); + if (ODPDRV_ENUMR_INVALID == dpdk_enumr) { + printf("\tError: failed to register_enumerator_dpdk()\n"); + return -1; + } + + return 0; +} diff --git a/example/ddf_ifs/ddf_ifs_enumr_dpdk.h b/example/ddf_ifs/ddf_ifs_enumr_dpdk.h new file mode 100644 index 0000000..516d9e3 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_enumr_dpdk.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_DDF_IFS_ENUMR_DPDK_H_ +#define _ODP_DDF_IFS_ENUMR_DPDK_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +int register_enumerator_dpdk(odpdrv_enumr_class_t enumr_class); + +#ifdef __cplusplus +} +#endif + +#endif /*_ODP_DDF_IFS_ENUMR_DPDK_H_*/ diff --git a/example/ddf_ifs/ddf_ifs_enumr_generic.c b/example/ddf_ifs/ddf_ifs_enumr_generic.c new file mode 100644 index 0000000..34a59a8 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_enumr_generic.c @@ -0,0 +1,57 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#include +#include "odp_drv.h" +#include "ddf_ifs_api.h" +#include "ddf_ifs_enumr_generic.h" + +static odpdrv_enumr_t gen_enumr; + +static int gen_enumr_probe(void) +{ + printf("%s() - no devices found\n", __func__); + return 0; +} + +static int gen_enumr_remove(void) +{ + printf("%s()\n", __func__); + return 0; +} + +static int gen_enumr_register_notif(void (*event_handler) (uint64_t event), + int64_t event_mask) +{ + (void)event_handler; + (void)event_mask; + + printf("%s()\n", __func__); + + return 0; +} + +int register_enumerator_generic(odpdrv_enumr_class_t enumr_class) +{ + struct odpdrv_enumr_param_t param = { + .enumr_class = enumr_class, + .api_name = DDF_IFS_DEV_API_NAME, + .api_version = DDF_IFS_DEV_API_VER, + .probe = gen_enumr_probe, + .remove = gen_enumr_remove, + .register_notifier = gen_enumr_register_notif + }; + + printf("\t%s()\n", __func__); + + gen_enumr = odpdrv_enumr_register(¶m); + if (ODPDRV_ENUMR_INVALID == gen_enumr) { + printf("\tError:failed to %s()\n", __func__); + return -1; + } + + return 0; +} diff --git a/example/ddf_ifs/ddf_ifs_enumr_generic.h b/example/ddf_ifs/ddf_ifs_enumr_generic.h new file mode 100644 index 0000000..2f0b8b8 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_enumr_generic.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2014, Linaro Limited + * All rights reserved. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +#ifndef _ODP_DDF_IFS_ENUMR_GENERIC_H_ +#define _ODP_DDF_IFS_ENUMR_GENERIC_H_ + +#ifdef __cplusplus +extern "C" { +#endif + +int register_enumerator_generic(odpdrv_enumr_class_t enumr_class); + +#ifdef __cplusplus +} +#endif + +#endif /*_ODP_DDF_IFS_ENUMR_GENERIC_H_*/ diff --git a/example/ddf_ifs/odp.conf b/example/ddf_ifs/odp.conf new file mode 100644 index 0000000..14968a7 --- /dev/null +++ b/example/ddf_ifs/odp.conf @@ -0,0 +1,4 @@ +module: +{ + modules = ("libddf_ifs.so.0"); +}; diff --git a/example/m4/configure.m4 b/example/m4/configure.m4 index 620db04..9e7973b 100644 --- a/example/m4/configure.m4 +++ b/example/m4/configure.m4 @@ -21,4 +21,6 @@ AC_CONFIG_FILES([example/classifier/Makefile example/time/Makefile example/timer/Makefile example/traffic_mgmt/Makefile + example/ddf_ifs/Makefile + example/ddf_app/Makefile example/Makefile])