From patchwork Thu Aug 31 12:18:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bogdan Pricope X-Patchwork-Id: 111383 Delivered-To: patch@linaro.org Received: by 10.140.95.112 with SMTP id h103csp2459360qge; Thu, 31 Aug 2017 05:19:01 -0700 (PDT) X-Google-Smtp-Source: ADKCNb5WuusvymR//2ykVPLNvHZH5IBAA8f020odW9/DmsJdZoD5+1Worx6Is+GQqeSB6wiQsjwa X-Received: by 10.36.18.140 with SMTP id 134mr544839itp.62.1504181941013; Thu, 31 Aug 2017 05:19:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1504181941; cv=none; d=google.com; s=arc-20160816; b=UA2Rvj3daUdC53+71Eb9Dy3VFmtQfSBkvFRRb0W+NArv/hQlJadhbxIwJxJaCl4L/8 Hy4xQFjB9P48aCkQUFFCYvSd0WqiFBW6j45P8drlrmD1TW8nDhzQi8YsfXY0/Nvy7NYP 5TQ6h3N0E0e4QtFWFmO8ePN0pVmdjGq6iFaPoju2ijSO8oPKROiqK8HHsQ9ceXskiz8u Io9vr4T05Ub2zZT2f59AhmM5gD3VXmyksn8kQl77EZfUVsj9EP2fCCnfQSXW8vXpZ5Rc dzKGwEx5uXW+88613xWxDDboFMOC5EhDLVOBzpLnnhbYactUNK4zP6fRCOJHQVcXLj83 jhqQ== 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=6AXPodpu8VRMHA9JHBuxGN3T3cnCiAecAIXHj4UGZKA=; b=RKjyVlK2q+DhtxY91NKHRncY72fGU7CWdlBlGmPO/SvWB4ZB5D6Fo7LzJf9yyRX/SG DvCQjVE146AJPAucWh5z8wWbzyA6Y64BYikUPGLlGbnsvuzn7ph/2kCHaAgbyu6fEQEd enVWwBN+5LgY9+kBiHHp/0fMS+o0LwokPgX4nK4W9RxpYwfXbyH0niBEj7cXjtnl0aBE hTVdSpFS13xNknNyCdDvPNXCOqQqmCKyIrmqXsjq2aPBMHA78JbOfj1hav7mmdtLZOqs Hul+RDMjwmPvy60af/WgtgPhXuPoP+ag4QPzKinlVCKi7a8pBUFJNAcfqyoBfQg6PkV3 veKg== 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 t62si7002050iod.31.2017.08.31.05.19.00; Thu, 31 Aug 2017 05:19:00 -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 8E43763574; Thu, 31 Aug 2017 12:19:00 +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=-1.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, RCVD_IN_SORBS_SPAM, URIBL_BLOCKED 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 CC3F160C39; Thu, 31 Aug 2017 12:18:50 +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 00851609DA; Thu, 31 Aug 2017 12:18:47 +0000 (UTC) Received: from mail-wm0-f46.google.com (mail-wm0-f46.google.com [74.125.82.46]) by lists.linaro.org (Postfix) with ESMTPS id C250E609DA for ; Thu, 31 Aug 2017 12:18:23 +0000 (UTC) Received: by mail-wm0-f46.google.com with SMTP id v2so3606749wmf.0 for ; Thu, 31 Aug 2017 05:18:23 -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=6AXPodpu8VRMHA9JHBuxGN3T3cnCiAecAIXHj4UGZKA=; b=WTUTZc6voMLdnh5F727KU6Y2LqrPvk+/0WXh+7k4iF6R6dgPgifqtnOChkG+DQHEyn U3vCMsmz/go4Gb/eMOyEX8tBEct979mQ5mfgR/voPpCjTbo4bFaJZtyyRl0iT1nQO/tx PPGpc3r631ILO/H2zpBZgyKgKeW6mje2VP5X+PQpVU6MJI5iHvl29YIeaPATKkpliBbf Of/aaqIMSAm10nxXzaSZ04sZWTj6YK708CzFdBgzfmORyRyvltUfSTCGnmOpRpGqm/Il tNJrNQyglxx520g8Tz3Ql4lcKNmDuf4W2O3+Tq/c6mzgAGIgGhnbjwOWuRPc0nP4N2UO WBcw== X-Gm-Message-State: AHPjjUg3psp1VcWfNpcEuMB1zMhxqJQHzzFyzKsNCZa/8gWveGybgn56 mVCQZlFzyfX0BV1YedCsETKp X-Received: by 10.28.128.195 with SMTP id b186mr385135wmd.116.1504181902407; Thu, 31 Aug 2017 05:18:22 -0700 (PDT) Received: from netbricks-team.enea.se ([193.202.22.66]) by smtp.gmail.com with ESMTPSA id 12sm7090730wrz.76.2017.08.31.05.18.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 31 Aug 2017 05:18:21 -0700 (PDT) From: Bogdan Pricope To: lng-odp@lists.linaro.org Date: Thu, 31 Aug 2017 15:18:05 +0300 Message-Id: <1504181885-5149-2-git-send-email-bogdan.pricope@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1504181885-5149-1-git-send-email-bogdan.pricope@linaro.org> References: <1504181885-5149-1-git-send-email-bogdan.pricope@linaro.org> Subject: [lng-odp] [CLOUD-DEV, RFCv1] examples: register custom pktio_ops module 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/ddf_app/odp_ddf_app.c | 16 +++- example/ddf_ifs/Makefile.am | 4 +- example/ddf_ifs/ddf_ifs_driver.c | 88 ++++++++++++++++++++++ frameworks/modular/odp_module.h | 10 +++ .../include/odp_pktio_ops_subsystem.h | 10 +++ 5 files changed, 125 insertions(+), 3 deletions(-) -- 2.1.4 diff --git a/example/ddf_app/odp_ddf_app.c b/example/ddf_app/odp_ddf_app.c index af864ee..619663e 100644 --- a/example/ddf_app/odp_ddf_app.c +++ b/example/ddf_app/odp_ddf_app.c @@ -20,9 +20,12 @@ int main(int argc, char *argv[]) { odp_instance_t instance; + odp_pktio_t pktio = ODP_PKTIO_INVALID; - (void)argc; - (void)argv; + if (argc == 1 || argc > 2) { + printf("Error: invalid parameter.\nUsage:\n\t%s \n", argv[0]); + exit(0); + } EXAMPLE_DBG("Start DDF Application...\n"); @@ -37,6 +40,15 @@ int main(int argc, char *argv[]) exit(EXIT_FAILURE); } + /* Open pktio*/ + pktio = odp_pktio_open(argv[1], ODP_POOL_INVALID, NULL); + if (pktio == ODP_PKTIO_INVALID) + EXAMPLE_ERR("Error: Failed to open pktio \"%s\".\n", argv[1]); + + /* Close pktio*/ + if (odp_pktio_close(pktio)) + EXAMPLE_ERR("Error: Failed to close pktio \"%s\".\n", argv[1]); + /* Print ddf objects*/ odpdrv_print_all(); diff --git a/example/ddf_ifs/Makefile.am b/example/ddf_ifs/Makefile.am index aa892ac..8bd666e 100644 --- a/example/ddf_ifs/Makefile.am +++ b/example/ddf_ifs/Makefile.am @@ -2,8 +2,10 @@ LIB = $(top_builddir)/lib AM_CPPFLAGS += -I$(srcdir) \ -I$(top_srcdir)/include \ + -I$(top_srcdir)/include/odp/arch/@ARCH_ABI@ \ -I$(top_srcdir)/platform/@with_platform@/include \ - -I$(top_srcdir)/platform/@with_platform@/arch/@ARCH_DIR@ + -I$(top_srcdir)/platform/@with_platform@/arch/@ARCH_DIR@ \ + -I$(top_srcdir)/frameworks/modular lib_LTLIBRARIES = $(LIB)/libddf_ifs.la diff --git a/example/ddf_ifs/ddf_ifs_driver.c b/example/ddf_ifs/ddf_ifs_driver.c index 53f9475..0a4cc29 100644 --- a/example/ddf_ifs/ddf_ifs_driver.c +++ b/example/ddf_ifs/ddf_ifs_driver.c @@ -7,9 +7,19 @@ #include #include #include "odp_drv.h" +#include #include "ddf_ifs_api.h" #include "ddf_ifs_driver.h" +#define DDF_IFS_NAME_SIZE 50 +#define DDF_IFS_DEV_PREFIX "ddf_ifs:" +#define DDF_IFS_DEV_PREFIX_LEN 8 +/** Packet socket using netmap mmaped rings for both Rx and Tx */ +typedef struct { + char dev_name[DDF_IFS_NAME_SIZE]; /**< interface name */ +} pktio_ops_ddf_ifs_data_t; + + static odpdrv_driver_t ddf_ifs_driver; static int drv_data = 12; @@ -46,8 +56,79 @@ static int ddf_ifs_driver_remove(void) return 0; } +static int ddf_ifs_init_global(void) +{ + printf("%s()\n", __func__); + return 0; +} +static int ddf_ifs_term_global(void) +{ + printf("%s()\n", __func__); + return 0; +} + +static int ddf_ifs_open(odp_pktio_t pktio ODP_UNUSED, pktio_entry_t *pktio_entry, + const char *devname, odp_pool_t pool) +{ + pktio_ops_ddf_ifs_data_t *pkt_ddf_ifs = _ops_data(pktio_entry, ddf_ifs); + + (void)pktio; + (void)pool; + + printf("%s(%s)\n", __func__, devname); + if (strncmp(devname, DDF_IFS_DEV_PREFIX, DDF_IFS_DEV_PREFIX_LEN) == 0) + devname += DDF_IFS_DEV_PREFIX_LEN; + else + return -1; + + strcpy(pkt_ddf_ifs->dev_name, devname); + printf("%s() - device %s oppened!!!\n", __func__, + pkt_ddf_ifs->dev_name); + return 0; +} + +static int ddf_ifs_close(pktio_entry_t *pktio_entry) +{ + pktio_ops_ddf_ifs_data_t *pkt_ddf_ifs = _ops_data(pktio_entry, ddf_ifs); + + printf("%s() - device %s closed.\n", __func__, pkt_ddf_ifs->dev_name); + + return 0; +} + +static pktio_ops_module_t ddf_ifs_pktio_ops = { + .base = { + .name = "ddf_ifs", + .init_local = NULL, + .term_local = NULL, + .init_global = ddf_ifs_init_global, + .term_global = ddf_ifs_term_global, + }, + .open = ddf_ifs_open, + .close = ddf_ifs_close, + .start = NULL/*ddf_ifs_start*/, + .stop = NULL/*ddf_ifs_stop*/, + .stats = NULL/*ddf_ifs_stats*/, + .stats_reset = NULL/*ddf_ifs_stats_reset*/, + .pktin_ts_res = NULL, + .pktin_ts_from_ns = NULL, + .recv = NULL/*ddf_ifs_recv*/, + .send = NULL/*ddf_ifs_send*/, + .mtu_get = NULL/*ddf_ifs_mtu_get*/, + .promisc_mode_set = NULL/*ddf_ifs_promisc_mode_set*/, + .promisc_mode_get = NULL/*ddf_ifs_promisc_mode_get*/, + .mac_get = NULL/*ddf_ifs_mac_addr_get*/, + .link_status = NULL/*ddf_ifs_link_status*/, + .capability = NULL/*ddf_ifs_capability*/, + .config = NULL, + .input_queues_config = NULL/*ddf_ifs_input_queues_config*/, + .output_queues_config = NULL/*ddf_ifs_output_queues_config*/, + .print = NULL/*ddf_ifs_print*/, +}; + int register_driver(void) { +/* Register ddf driver*/ odpdrv_driver_param_t param = { .name = DDF_IFS_DRV_NAME, .devios = {{DDF_IFS_DEVIO_API_NAME, DDF_IFS_DEVIO_API_VER}, @@ -65,5 +146,12 @@ int register_driver(void) return -1; } +/* Register pktio_ops module*/ + odp_module_constructor(&ddf_ifs_pktio_ops); + + odp_subsystem_register_module(pktio_ops, &ddf_ifs_pktio_ops); + +/* Explicit call to Init global*/ + ddf_ifs_init_global(); return 0; } diff --git a/frameworks/modular/odp_module.h b/frameworks/modular/odp_module.h index 59f67c8..b20501e 100644 --- a/frameworks/modular/odp_module.h +++ b/frameworks/modular/odp_module.h @@ -38,6 +38,11 @@ #ifndef ODP_MODULE_H_ #define ODP_MODULE_H_ +#include + +#ifdef __cplusplus +extern "C" { +#endif #include #include @@ -293,4 +298,9 @@ int __subsystem_register_module( __subsystem_set_active(&__subsystem(name), base); \ }) +#ifdef __cplusplus +} +#endif + +#include #endif diff --git a/platform/linux-generic/include/odp_pktio_ops_subsystem.h b/platform/linux-generic/include/odp_pktio_ops_subsystem.h index ff497a2..468c70d 100644 --- a/platform/linux-generic/include/odp_pktio_ops_subsystem.h +++ b/platform/linux-generic/include/odp_pktio_ops_subsystem.h @@ -8,6 +8,11 @@ #ifndef ODP_PKTIO_OPS_SUBSYSTEM_H_ #define ODP_PKTIO_OPS_SUBSYSTEM_H_ +#include + +#ifdef __cplusplus +extern "C" { +#endif #include #include @@ -78,4 +83,9 @@ typedef ODP_MODULE_CLASS(pktio_ops) { odp_api_proto(pktio_ops, print) print; } pktio_ops_module_t; +#ifdef __cplusplus +} +#endif + +#include #endif