From patchwork Thu Jun 22 08:03:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bogdan Pricope X-Patchwork-Id: 106189 Delivered-To: patch@linaro.org Received: by 10.140.91.2 with SMTP id y2csp2334695qgd; Thu, 22 Jun 2017 01:04:42 -0700 (PDT) X-Received: by 10.55.22.167 with SMTP id 39mr1395828qkw.20.1498118682295; Thu, 22 Jun 2017 01:04:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1498118682; cv=none; d=google.com; s=arc-20160816; b=tFQid+DFSi032fQAZ9eJvSe9snv6d6B3UJuyHaGC2YzMBqqYV6cS6oZxHAy+HOvlmH +ilQiw0KiON2Qs5BPcjd3gH2CouCYqWzh5WEzQ2LhF6CxXYm+iryVWiY+6afNHwMmzVV y/BkrYijX1lf/OFRAPFjTRmV2j5+kYVHL7Yddi6YKf2GEQNerHrguyhgDpgYDHh4XIFX Q0e1bngU5JilqiHVoxTZlIakFiWOUkl4N4bMFu0XwuVrLeku2ins6KmUN1h5/+QxAFAu eZwr5Teo6AQ86ZJqcVILWypOPue8YUJUAegB7fd7AIxa15HgR/UGcqswwg6fEt0NxFlh uypA== 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=5YxPSbFyDXLeEEhsdECc/WNyBE1z069KvgbnT6/3oH0=; b=ocme/lG1FRE/H0iQIQyxXs4B4W/8VOYzMC1PI3HZe0KHUuaOGM0ToEnKmsFdikNtfP MSROIEUGvv0bKedQTmvFYDEU2Tfr4ORb7Jq2uaJt5FScml+cRbJuVlzV4LV+WzexCzxt M6UVazEqqu5uLY95UbaoM2Tydpi5GfoehIRsvBNy/1FzfJEKb0UFVooJkImz/tHA4G9I pelzp/Ll/iFjRRpHDLcDmnePFtrJm4aHCrexAGQocvbsOg8Tijj5uT5bVgSGivNwEAqN rk9iehcJ2PMOYvuD2+IJ7qnmjsc9PTFklHOjeZcT8GG4shZVYq+SFebEK+4Csxwbbd2g 7s9g== 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 x34si492541qtc.283.2017.06.22.01.04.42; Thu, 22 Jun 2017 01:04:42 -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 08B4760C10; Thu, 22 Jun 2017 08:04:42 +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 331F060679; Thu, 22 Jun 2017 08:04:31 +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 46B6360679; Thu, 22 Jun 2017 08:04:28 +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 EC8AD60C02 for ; Thu, 22 Jun 2017 08:04:04 +0000 (UTC) Received: by mail-wr0-f178.google.com with SMTP id 77so12205098wrb.1 for ; Thu, 22 Jun 2017 01:04:04 -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=5YxPSbFyDXLeEEhsdECc/WNyBE1z069KvgbnT6/3oH0=; b=gP2QWY8bg5XtM9MdiWLN/+7jXKpmvIbzIVOwBG58orkY6lJi11g/9rkPDQQkfpM7wR VHNi0t0rpezATFewSbYst6wY+xyGeKCGZ2BY019LZh1yXBiTd5yBDasFkavNIVPQV1dA JlUQ5u8rpg4DwTwwYvF33ro03kIymivxweyoNu3YR5gUgLA1CNgZpU6056Guk+H1rCXH 2hyqCdgSN/OErVtpEeE4XOBOzpE6qmnCWhf7fbmblqypZjDCiTipvBAbcowqC91Hdk/9 BUYxEDVojcNVMRw3mNf/P/cfPB7ymu6E7soFUSBZodtw4xjrm1Mk3yCe7jSqBp75vF2E 1Jgw== X-Gm-Message-State: AKS2vOxVTTtNCLN9Z4CivD4REv4lRHmePwbtS7XrHgAglrnTT0ea4/C4 ouXkl5yV4CcNaB3deerkbUqE X-Received: by 10.28.14.205 with SMTP id 196mr704688wmo.27.1498118643426; Thu, 22 Jun 2017 01:04:03 -0700 (PDT) Received: from netbricks-team.enea.se ([193.202.22.66]) by smtp.gmail.com with ESMTPSA id r40sm1466379wrb.37.2017.06.22.01.04.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 22 Jun 2017 01:04:02 -0700 (PDT) From: Bogdan Pricope To: lng-odp@lists.linaro.org Date: Thu, 22 Jun 2017 11:03:47 +0300 Message-Id: <1498118627-3763-2-git-send-email-bogdan.pricope@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1498118627-3763-1-git-send-email-bogdan.pricope@linaro.org> References: <1498118627-3763-1-git-send-email-bogdan.pricope@linaro.org> Subject: [lng-odp] [CLOUD-DEVv2] 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 | 27 +++++++++++ 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, 625 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..af864ee --- /dev/null +++ b/example/ddf_app/odp_ddf_app.c @@ -0,0 +1,49 @@ +/* Copyright (c) 2017, 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..aa892ac --- /dev/null +++ b/example/ddf_ifs/Makefile.am @@ -0,0 +1,27 @@ +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 \ + $(srcdir)/ddf_ifs_api.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..fa2276f --- /dev/null +++ b/example/ddf_ifs/ddf_ifs.c @@ -0,0 +1,28 @@ +/* Copyright (c) 2017, 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..ff8bc27 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs.h @@ -0,0 +1,18 @@ +/* Copyright (c) 2017, 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..0d948ae --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_api.h @@ -0,0 +1,25 @@ +/* Copyright (c) 2017, 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..4d08e51 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_dev_dpdk.c @@ -0,0 +1,25 @@ +/* Copyright (c) 2017, 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..84583a3 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_dev_dpdk.h @@ -0,0 +1,24 @@ +/* Copyright (c) 2017, 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..ec451d6 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_devio_direct.c @@ -0,0 +1,51 @@ +/* Copyright (c) 2017, 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..9c00460 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_devio_direct.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2017, 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..53f9475 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_driver.c @@ -0,0 +1,69 @@ +/* Copyright (c) 2017, 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..e990c34 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_driver.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2017, 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..8450dee --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_enumr_class.c @@ -0,0 +1,47 @@ +/* Copyright (c) 2017, 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..a3cb037 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_enumr_class.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2017, 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..782f7b7 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_enumr_dpdk.c @@ -0,0 +1,86 @@ +/* Copyright (c) 2017, 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..e670d54 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_enumr_dpdk.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2017, 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..f5e1a2c --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_enumr_generic.c @@ -0,0 +1,57 @@ +/* Copyright (c) 2017, 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..0eeb073 --- /dev/null +++ b/example/ddf_ifs/ddf_ifs_enumr_generic.h @@ -0,0 +1,20 @@ +/* Copyright (c) 2017, 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])