From mboxrd@z Thu Jan  1 00:00:00 1970
Return-Path: <dev-bounces@dpdk.org>
Received: from dpdk.org (dpdk.org [92.243.14.124])
	by inbox.dpdk.org (Postfix) with ESMTP id D70EDA0534;
	Tue,  4 Feb 2020 15:00:36 +0100 (CET)
Received: from [92.243.14.124] (localhost [127.0.0.1])
	by dpdk.org (Postfix) with ESMTP id 3F4C21C1F1;
	Tue,  4 Feb 2020 14:59:21 +0100 (CET)
Received: from mx0b-0016f401.pphosted.com (mx0a-0016f401.pphosted.com
 [67.231.148.174]) by dpdk.org (Postfix) with ESMTP id 1CF1F1C1E8
 for <dev@dpdk.org>; Tue,  4 Feb 2020 14:59:19 +0100 (CET)
Received: from pps.filterd (m0045849.ppops.net [127.0.0.1])
 by mx0a-0016f401.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id
 014Dsuv9005016; Tue, 4 Feb 2020 05:59:19 -0800
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=marvell.com;
 h=from : to : cc :
 subject : date : message-id : in-reply-to : references : mime-version :
 content-type; s=pfpt0818; bh=MJZWdIm+CSdvr644hN2tkp1VyDR50oV6YaD+XiBkbEM=;
 b=y2xpq2OU62H1Np5RxSvCEhEDCfeQWMKhNTno/vQWid4slPWT84RgKjM0A8r3wRNsiTy/
 1Ro4Uhed/4pSFx61JOfERfYS4EFzErLxl7nC1dDkxrUP2a2vapF7h/SQIBwYyPMmXssN
 AXlcU4VcJaiTHYPf6CXxNeaLjTGdrqGyd27vAM1z4dwKnE9UeixKGK7qDNLICFyYPETV
 KQrG/ulaHye5apPPgM8vV09brsl24yZBYY8qsVcC8i7bPijDdOLML9xEhacQ05lIThEH
 ocd+UbhrPIomYHVSvgg02XUUYMj1DJQ5r9wQRhap6zqOvHjYb0NbiCoNRK7YmqMWPy+z iw== 
Received: from sc-exch01.marvell.com ([199.233.58.181])
 by mx0a-0016f401.pphosted.com with ESMTP id 2xw7jvmm7f-1
 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT);
 Tue, 04 Feb 2020 05:59:19 -0800
Received: from SC-EXCH03.marvell.com (10.93.176.83) by SC-EXCH01.marvell.com
 (10.93.176.81) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Tue, 4 Feb
 2020 05:59:17 -0800
Received: from maili.marvell.com (10.93.176.43) by SC-EXCH03.marvell.com
 (10.93.176.83) with Microsoft SMTP Server id 15.0.1497.2 via Frontend
 Transport; Tue, 4 Feb 2020 05:59:17 -0800
Received: from luke.marvell.com (unknown [10.95.130.32])
 by maili.marvell.com (Postfix) with ESMTP id C234D3F7141;
 Tue,  4 Feb 2020 05:59:14 -0800 (PST)
From: Lukasz Bartosik <lbartosik@marvell.com>
To: Akhil Goyal <akhil.goyal@nxp.com>, Radu Nicolau <radu.nicolau@intel.com>, 
 Thomas Monjalon <thomas@monjalon.net>
CC: Jerin Jacob <jerinj@marvell.com>, Narayana Prasad <pathreya@marvell.com>, 
 Ankur Dwivedi <adwivedi@marvell.com>, Anoob Joseph <anoobj@marvell.com>,
 Archana Muniganti <marchana@marvell.com>, Tejasree Kondoj
 <ktejasree@marvell.com>, Vamsi Attunuru <vattunuru@marvell.com>,
 "Konstantin Ananyev" <konstantin.ananyev@intel.com>, <dev@dpdk.org>
Date: Tue, 4 Feb 2020 14:58:37 +0100
Message-ID: <1580824721-21527-10-git-send-email-lbartosik@marvell.com>
X-Mailer: git-send-email 2.7.4
In-Reply-To: <1580824721-21527-1-git-send-email-lbartosik@marvell.com>
References: <1579527918-360-1-git-send-email-anoobj@marvell.com>
 <1580824721-21527-1-git-send-email-lbartosik@marvell.com>
MIME-Version: 1.0
Content-Type: text/plain
X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572
 definitions=2020-02-04_04:2020-02-04,
 2020-02-04 signatures=0
Subject: [dpdk-dev] [PATCH v3 09/13] examples/ipsec-secgw: add event helper
	config init/uninit
X-BeenThere: dev@dpdk.org
X-Mailman-Version: 2.1.15
Precedence: list
List-Id: DPDK patches and discussions <dev.dpdk.org>
List-Unsubscribe: <https://mails.dpdk.org/options/dev>,
 <mailto:dev-request@dpdk.org?subject=unsubscribe>
List-Archive: <http://mails.dpdk.org/archives/dev/>
List-Post: <mailto:dev@dpdk.org>
List-Help: <mailto:dev-request@dpdk.org?subject=help>
List-Subscribe: <https://mails.dpdk.org/listinfo/dev>,
 <mailto:dev-request@dpdk.org?subject=subscribe>
Errors-To: dev-bounces@dpdk.org
Sender: "dev" <dev-bounces@dpdk.org>

Add eventmode helper eh_conf_init and eh_conf_uninit
functions which purpose is to initialize and
unitialize eventmode helper configuration.

Signed-off-by: Anoob Joseph <anoobj@marvell.com>
Signed-off-by: Lukasz Bartosik <lbartosik@marvell.com>
---
 examples/ipsec-secgw/event_helper.c | 103 ++++++++++++++++++++++++++++++++++++
 examples/ipsec-secgw/event_helper.h |  23 ++++++++
 2 files changed, 126 insertions(+)

diff --git a/examples/ipsec-secgw/event_helper.c b/examples/ipsec-secgw/event_helper.c
index 6b21884..423576d 100644
--- a/examples/ipsec-secgw/event_helper.c
+++ b/examples/ipsec-secgw/event_helper.c
@@ -1385,6 +1385,109 @@ eh_display_link_conf(struct eventmode_conf *em_conf)
 	EH_LOG_INFO("");
 }
 
+struct eh_conf *
+eh_conf_init(void)
+{
+	struct eventmode_conf *em_conf = NULL;
+	struct eh_conf *conf = NULL;
+	unsigned int eth_core_id;
+	void *bitmap = NULL;
+	uint32_t nb_bytes;
+
+	/* Allocate memory for config */
+	conf = calloc(1, sizeof(struct eh_conf));
+	if (conf == NULL) {
+		EH_LOG_ERR("Failed to allocate memory for eventmode helper "
+			   "config");
+		return NULL;
+	}
+
+	/* Set default conf */
+
+	/* Packet transfer mode: poll */
+	conf->mode = EH_PKT_TRANSFER_MODE_POLL;
+
+	/* Keep all ethernet ports enabled by default */
+	conf->eth_portmask = -1;
+
+	/* Allocate memory for event mode params */
+	conf->mode_params = calloc(1, sizeof(struct eventmode_conf));
+	if (conf->mode_params == NULL) {
+		EH_LOG_ERR("Failed to allocate memory for event mode params");
+		goto free_conf;
+	}
+
+	/* Get eventmode conf */
+	em_conf = conf->mode_params;
+
+	/* Allocate and initialize bitmap for eth cores */
+	nb_bytes = rte_bitmap_get_memory_footprint(RTE_MAX_LCORE);
+	if (!nb_bytes) {
+		EH_LOG_ERR("Failed to get bitmap footprint");
+		goto free_em_conf;
+	}
+
+	bitmap = rte_zmalloc("event-helper-ethcore-bitmap", nb_bytes,
+			     RTE_CACHE_LINE_SIZE);
+	if (!bitmap) {
+		EH_LOG_ERR("Failed to allocate memory for eth cores bitmap\n");
+		goto free_em_conf;
+	}
+
+	em_conf->eth_core_mask = rte_bitmap_init(RTE_MAX_LCORE, bitmap,
+						 nb_bytes);
+	if (!em_conf->eth_core_mask) {
+		EH_LOG_ERR("Failed to initialize bitmap");
+		goto free_bitmap;
+	}
+
+	/* Set schedule type as not set */
+	em_conf->ext_params.sched_type = SCHED_TYPE_NOT_SET;
+
+	/* Set two cores as eth cores for Rx & Tx */
+
+	/* Use first core other than master core as Rx core */
+	eth_core_id = rte_get_next_lcore(0,	/* curr core */
+					 1,	/* skip master core */
+					 0	/* wrap */);
+
+	rte_bitmap_set(em_conf->eth_core_mask, eth_core_id);
+
+	/* Use next core as Tx core */
+	eth_core_id = rte_get_next_lcore(eth_core_id,	/* curr core */
+					 1,		/* skip master core */
+					 0		/* wrap */);
+
+	rte_bitmap_set(em_conf->eth_core_mask, eth_core_id);
+
+	return conf;
+
+free_bitmap:
+	rte_free(bitmap);
+free_em_conf:
+	free(em_conf);
+free_conf:
+	free(conf);
+	return NULL;
+}
+
+void
+eh_conf_uninit(struct eh_conf *conf)
+{
+	struct eventmode_conf *em_conf = NULL;
+
+	if (!conf || !conf->mode_params)
+		return;
+
+	/* Get eventmode conf */
+	em_conf = conf->mode_params;
+
+	/* Free evenmode configuration memory */
+	rte_free(em_conf->eth_core_mask);
+	free(em_conf);
+	free(conf);
+}
+
 void
 eh_display_conf(struct eh_conf *conf)
 {
diff --git a/examples/ipsec-secgw/event_helper.h b/examples/ipsec-secgw/event_helper.h
index 15a7bd6..7ad975f 100644
--- a/examples/ipsec-secgw/event_helper.h
+++ b/examples/ipsec-secgw/event_helper.h
@@ -50,6 +50,9 @@ extern "C" {
 /* Max adapters that one Tx core can handle */
 #define EVENT_MODE_MAX_ADAPTERS_PER_TX_CORE EVENT_MODE_MAX_TX_ADAPTERS
 
+/* Used to indicate that queue schedule type is not set */
+#define SCHED_TYPE_NOT_SET	3
+
 /**
  * Packet transfer mode of the application
  */
@@ -204,6 +207,26 @@ struct eh_app_worker_params {
 };
 
 /**
+ * Allocate memory for event helper configuration and initialize
+ * it with default values.
+ *
+ * @return
+ * - pointer to event helper configuration structure on success.
+ * - NULL on failure.
+ */
+struct eh_conf *
+eh_conf_init(void);
+
+/**
+ * Uninitialize event helper configuration and release its memory
+. *
+ * @param conf
+ *   Event helper configuration
+ */
+void
+eh_conf_uninit(struct eh_conf *conf);
+
+/**
  * Initialize event mode devices
  *
  * Application can call this function to get the event devices, eth devices
-- 
2.7.4