From: Anoob Joseph <anoobj@marvell.com>
To: Akhil Goyal <akhil.goyal@nxp.com>, Radu Nicolau <radu.nicolau@intel.com>
Cc: Anoob Joseph <anoobj@marvell.com>,
Thomas Monjalon <thomas@monjalon.net>,
Jerin Jacob <jerinj@marvell.com>,
Narayana Prasad <pathreya@marvell.com>, <dev@dpdk.org>,
Lukasz Bartosik <lbartosik@marvell.com>
Subject: [dpdk-dev] [RFC PATCH 04/13] examples/ipsec-secgw: add Tx adapter support
Date: Wed, 9 Oct 2019 20:40:07 +0530 [thread overview]
Message-ID: <1570633816-4706-5-git-send-email-anoobj@marvell.com> (raw)
In-Reply-To: <1570633816-4706-1-git-send-email-anoobj@marvell.com>
Add Tx adapter support. The event helper init routine will initialize
the Tx adapter according to the configuration. If Tx adapter config
is not present it will generate a default config.
Signed-off-by: Anoob Joseph <anoobj@marvell.com>
Signed-off-by: Lukasz Bartosik <lbartosik@marvell.com>
---
examples/ipsec-secgw/event_helper.c | 375 +++++++++++++++++++++++++++++++++++-
examples/ipsec-secgw/event_helper.h | 58 ++++++
2 files changed, 424 insertions(+), 9 deletions(-)
diff --git a/examples/ipsec-secgw/event_helper.c b/examples/ipsec-secgw/event_helper.c
index b5417a0..7745fbb 100644
--- a/examples/ipsec-secgw/event_helper.c
+++ b/examples/ipsec-secgw/event_helper.c
@@ -2,31 +2,58 @@
* Copyright (C) 2019 Marvell International Ltd.
*/
#include <rte_event_eth_rx_adapter.h>
+#include <rte_event_eth_tx_adapter.h>
#include <rte_ethdev.h>
#include <rte_bitmap.h>
#include <rte_malloc.h>
#include "event_helper.h"
+static int
+eh_get_enabled_cores(struct rte_bitmap *eth_core_mask)
+{
+ int i;
+ int count = 0;
+
+ RTE_LCORE_FOREACH(i) {
+ /* Check if this core is enabled in core_mask*/
+ if (rte_bitmap_get(eth_core_mask, i)) {
+ /* We have enabled core */
+ count++;
+ }
+ }
+ return count;
+}
+
static inline unsigned int
-eh_get_next_rx_core(struct eventmode_conf *em_conf,
- unsigned int prev_core)
+eh_get_next_eth_core(struct eventmode_conf *em_conf)
{
unsigned int next_core;
+ static unsigned int prev_core = -1;
+
+ /*
+ * Make sure we have atleast one eth core running, else the following
+ * logic would lead to an infinite loop.
+ */
+ if (eh_get_enabled_cores(em_conf->eth_core_mask) == 0) {
+ EH_LOG_ERR("No enabled eth core found");
+ return RTE_MAX_LCORE;
+ }
get_next_core:
/* Get the next core */
- next_core = rte_get_next_lcore(prev_core, 0, 0);
+ next_core = rte_get_next_lcore(prev_core, 0, 1);
/* Check if we have reached max lcores */
if (next_core == RTE_MAX_LCORE)
return next_core;
- /* Only some cores would be marked as rx cores. Skip others */
- if (!(rte_bitmap_get(em_conf->eth_core_mask, next_core))) {
- prev_core = next_core;
+ /* Update prev_core */
+ prev_core = next_core;
+
+ /* Only some cores would be marked as eth cores. Skip others */
+ if (!(rte_bitmap_get(em_conf->eth_core_mask, next_core)))
goto get_next_core;
- }
return next_core;
}
@@ -45,7 +72,7 @@ eh_get_next_active_core(struct eventmode_conf *em_conf,
if (next_core == RTE_MAX_LCORE)
return next_core;
- /* Some cores would be reserved as rx cores. Skip them */
+ /* Some cores would be reserved as eth cores. Skip them */
if (rte_bitmap_get(em_conf->eth_core_mask, next_core)) {
prev_core = next_core;
goto get_next_core;
@@ -54,6 +81,23 @@ eh_get_next_active_core(struct eventmode_conf *em_conf,
return next_core;
}
+static struct eventdev_params *
+eh_get_eventdev_params(struct eventmode_conf *em_conf,
+ uint8_t eventdev_id)
+{
+ int i;
+
+ for (i = 0; i < em_conf->nb_eventdev; i++) {
+ if (em_conf->eventdev_config[i].eventdev_id == eventdev_id)
+ break;
+ }
+
+ /* No match */
+ if (i == em_conf->nb_eventdev)
+ return NULL;
+
+ return &(em_conf->eventdev_config[i]);
+}
static int
eh_validate_user_params(struct eventmode_conf *em_conf)
{
@@ -224,7 +268,7 @@ eh_set_default_conf_rx_adapter(struct eventmode_conf *em_conf)
/* Set adapter conf */
adapter->eventdev_id = eventdev_id;
adapter->adapter_id = adapter_id;
- adapter->rx_core_id = eh_get_next_rx_core(em_conf, -1);
+ adapter->rx_core_id = eh_get_next_eth_core(em_conf);
/*
* All queues of one eth device (port) will be mapped to one event
@@ -271,6 +315,100 @@ eh_set_default_conf_rx_adapter(struct eventmode_conf *em_conf)
}
static int
+eh_set_default_conf_tx_adapter(struct eventmode_conf *em_conf)
+{
+ int nb_eth_dev;
+ int eventdev_id;
+ int adapter_id;
+ int i;
+ int conn_id;
+ struct eventdev_params *eventdev_config;
+ struct tx_adapter_conf *tx_adapter;
+ struct tx_adapter_connection_info *conn;
+
+ /*
+ * Create one Tx adapter with all eth queues mapped to event queues
+ * 1:1.
+ */
+
+ if (em_conf->nb_eventdev == 0) {
+ EH_LOG_ERR("No event devs registered");
+ return -EINVAL;
+ }
+
+ /* Get the number of eth devs */
+ nb_eth_dev = rte_eth_dev_count_avail();
+
+ /* Use the first event dev */
+ eventdev_config = &(em_conf->eventdev_config[0]);
+
+ /* Get eventdev ID */
+ eventdev_id = eventdev_config->eventdev_id;
+ adapter_id = 0;
+
+ /* Get adapter conf */
+ tx_adapter = &(em_conf->tx_adapter[adapter_id]);
+
+ /* Set adapter conf */
+ tx_adapter->eventdev_id = eventdev_id;
+ tx_adapter->adapter_id = adapter_id;
+
+ /* TODO: Tx core is required only when internal port is not present */
+
+ tx_adapter->tx_core_id = eh_get_next_eth_core(em_conf);
+
+ /*
+ * Application would need to use one event queue per adapter for
+ * submitting packets for Tx. Reserving the last queue available
+ * and decrementing the total available event queues for this
+ */
+
+ /* Queue numbers start at 0 */
+ tx_adapter->tx_ev_queue = eventdev_config->nb_eventqueue - 1;
+
+ /* Update the number of event queues available in eventdev */
+ eventdev_config->nb_eventqueue--;
+
+ /*
+ * All Tx queues of the eth device (port) will be mapped to the event
+ * device.
+ */
+
+ /* Set defaults for connections */
+
+ /*
+ * One eth device (port) would be one connection. All Tx queues of
+ * the device would be mapped to the Tx adapter.
+ */
+
+ for (i = 0; i < nb_eth_dev; i++) {
+
+ /* Use only the ports enabled */
+ if ((em_conf->eth_portmask & (1 << i)) == 0)
+ continue;
+
+ /* Get the connection id */
+ conn_id = tx_adapter->nb_connections;
+
+ /* Get the connection */
+ conn = &(tx_adapter->conn[conn_id]);
+
+ /* Add ethdev to connections */
+ conn->ethdev_id = i;
+
+ /* Add all eth tx queues to adapter */
+ conn->ethdev_tx_qid = -1;
+
+ /* Update no of connections */
+ tx_adapter->nb_connections++;
+ }
+
+ /* We have setup one adapter */
+ em_conf->nb_tx_adapter = 1;
+ return 0;
+}
+
+static int
eh_validate_conf(struct eventmode_conf *em_conf)
{
int ret;
@@ -310,6 +448,16 @@ eh_validate_conf(struct eventmode_conf *em_conf)
return ret;
}
+ /*
+ * See if tx adapters are specified. Else generate a default conf
+ * with one tx adapter.
+ */
+ if (em_conf->nb_tx_adapter == 0) {
+ ret = eh_set_default_conf_tx_adapter(em_conf);
+ if (ret != 0)
+ return ret;
+ }
+
return 0;
}
@@ -579,6 +727,147 @@ eh_initialize_rx_adapter(struct eventmode_conf *em_conf)
return 0;
}
+static int
+eh_tx_adapter_configure(struct eventmode_conf *em_conf,
+ struct tx_adapter_conf *adapter)
+{
+ int ret, j;
+ uint8_t tx_port_id = 0;
+ uint8_t eventdev_id;
+ uint32_t service_id;
+ struct rte_event_port_conf port_conf = {0};
+ struct rte_event_dev_info evdev_default_conf = {0};
+ struct tx_adapter_connection_info *conn;
+ struct eventdev_params *eventdev_config;
+
+ /* Get event dev ID */
+ eventdev_id = adapter->eventdev_id;
+
+ /* Get event device conf */
+ eventdev_config = eh_get_eventdev_params(em_conf, eventdev_id);
+
+ /* Create Tx adapter */
+
+ /* Get default configuration of event dev */
+ ret = rte_event_dev_info_get(eventdev_id, &evdev_default_conf);
+ if (ret < 0) {
+ EH_LOG_ERR("Error in getting event device info[devID:%d]",
+ eventdev_id);
+ return ret;
+ }
+
+ /* Setup port conf */
+ port_conf.new_event_threshold =
+ evdev_default_conf.max_num_events;
+ port_conf.dequeue_depth =
+ evdev_default_conf.max_event_port_dequeue_depth;
+ port_conf.enqueue_depth =
+ evdev_default_conf.max_event_port_enqueue_depth;
+
+ /* Create Tx adapter */
+ ret = rte_event_eth_tx_adapter_create(adapter->adapter_id,
+ adapter->eventdev_id,
+ &port_conf);
+ if (ret < 0) {
+ EH_LOG_ERR("Error in Tx adapter creation");
+ return ret;
+ }
+
+ /* Setup various connections in the adapter */
+ for (j = 0; j < adapter->nb_connections; j++) {
+
+ /* Get connection */
+ conn = &(adapter->conn[j]);
+
+ /* Add queue to the adapter */
+ ret = rte_event_eth_tx_adapter_queue_add(
+ adapter->adapter_id,
+ conn->ethdev_id,
+ conn->ethdev_tx_qid);
+ if (ret < 0) {
+ EH_LOG_ERR("Error in adding eth queue in Tx adapter");
+ return ret;
+ }
+ }
+
+ /* Get event port used by the adapter */
+ ret = rte_event_eth_tx_adapter_event_port_get(
+ adapter->adapter_id,
+ &tx_port_id);
+ if (ret) {
+ EH_LOG_ERR("Failed to get Tx adapter port ID");
+ return ret;
+ }
+
+ /*
+ * TODO: event queue for Tx adapter is required only if the
+ * INTERNAL PORT is not present.
+ */
+
+ /*
+ * Tx event queue would be reserved for Tx adapter. Need to unlink
+ * this queue from all other ports
+ *
+ */
+ for (j = 0; j < eventdev_config->nb_eventport; j++) {
+ rte_event_port_unlink(eventdev_id, j,
+ &(adapter->tx_ev_queue), 1);
+ }
+
+ ret = rte_event_port_link(
+ eventdev_id,
+ tx_port_id,
+ &(adapter->tx_ev_queue),
+ NULL, 1);
+ if (ret != 1) {
+ EH_LOG_ERR("Failed to link event queue to port");
+ return ret;
+ }
+
+ /* Get the service ID used by Tx adapter */
+ ret = rte_event_eth_tx_adapter_service_id_get(adapter->adapter_id,
+ &service_id);
+ if (ret != -ESRCH && ret != 0) {
+ EH_LOG_ERR("Error getting service ID used by adapter");
+ return ret;
+ }
+
+ /*
+ * TODO
+ * Tx core will invoke the service when required. The runstate check
+ * is not required.
+ *
+ */
+ rte_service_set_runstate_mapped_check(service_id, 0);
+
+ /* Start adapter */
+ ret = rte_event_eth_tx_adapter_start(adapter->adapter_id);
+ if (ret) {
+ EH_LOG_ERR("Error in starting Tx adapter");
+ return ret;
+ }
+
+ return 0;
+}
+
+static int
+eh_initialize_tx_adapter(struct eventmode_conf *em_conf)
+{
+ int i, ret;
+ struct tx_adapter_conf *adapter;
+
+ /* Configure Tx adapters */
+ for (i = 0; i < em_conf->nb_tx_adapter; i++) {
+ adapter = &(em_conf->tx_adapter[i]);
+ ret = eh_tx_adapter_configure(em_conf, adapter);
+ if (ret < 0) {
+ EH_LOG_ERR("Tx adapter configuration failed");
+ return ret;
+ }
+ }
+ return 0;
+}
+
int32_t
eh_devs_init(struct eh_conf *mode_conf)
{
@@ -631,6 +920,11 @@ eh_devs_init(struct eh_conf *mode_conf)
if (ret != 0)
return ret;
+ /* Setup Tx adapter */
+ ret = eh_initialize_tx_adapter(em_conf);
+ if (ret != 0)
+ return ret;
+
/* Start eth devices after setting up adapter */
RTE_ETH_FOREACH_DEV(portid) {
@@ -713,5 +1007,68 @@ eh_devs_uninit(struct eh_conf *mode_conf)
}
}
+ /* Stop and release tx adapters */
+ for (i = 0; i < em_conf->nb_tx_adapter; i++) {
+
+ id = em_conf->tx_adapter[i].adapter_id;
+ ret = rte_event_eth_tx_adapter_stop(id);
+ if (ret < 0) {
+ EH_LOG_ERR("Error stopping tx adapter %d", id);
+ return ret;
+ }
+
+ for (j = 0; j < em_conf->tx_adapter[i].nb_connections; j++) {
+
+ ret = rte_event_eth_tx_adapter_queue_del(id,
+ em_conf->tx_adapter[i].conn[j].ethdev_id, -1);
+ if (ret < 0) {
+ EH_LOG_ERR(
+ "Error deleting tx adapter queues %d",
+ id);
+ return ret;
+ }
+ }
+
+ ret = rte_event_eth_tx_adapter_free(id);
+ if (ret < 0) {
+ EH_LOG_ERR("Error freeing tx adapter %d", id);
+ return ret;
+ }
+ }
+
return 0;
}
+
+uint8_t
+eh_get_tx_queue(struct eh_conf *mode_conf, uint8_t eventdev_id)
+{
+ struct eventdev_params *eventdev_config;
+ struct eventmode_conf *em_conf;
+
+ if (mode_conf == NULL) {
+ EH_LOG_ERR("Invalid conf");
+ return -EINVAL;
+ }
+
+ if (mode_conf->mode_params == NULL) {
+ EH_LOG_ERR("Invalid mode params");
+ return -EINVAL;
+ }
+
+ /* Get eventmode conf */
+ em_conf = (struct eventmode_conf *)(mode_conf->mode_params);
+
+ /* Get event device conf */
+ eventdev_config = eh_get_eventdev_params(em_conf, eventdev_id);
+
+ if (eventdev_config == NULL) {
+ EH_LOG_ERR("Error reading eventdev conf");
+ return -EINVAL;
+ }
+
+ /*
+ * The last queue would be reserved to be used as atomic queue for the
+ * last stage (eth packet tx stage)
+ */
+ return eventdev_config->nb_eventqueue - 1;
+}
diff --git a/examples/ipsec-secgw/event_helper.h b/examples/ipsec-secgw/event_helper.h
index 4233b42..01e2aca 100644
--- a/examples/ipsec-secgw/event_helper.h
+++ b/examples/ipsec-secgw/event_helper.h
@@ -10,6 +10,16 @@ extern "C" {
#include <rte_log.h>
+/**
+ * Flag to indicate that the event device used by all adapters is same
+ */
+#define EH_TX_EV_LINK_COMMON_EVENT_DEV (1 << 0)
+
+/**
+ * Flag to indicate that the event queue to be used for all adapters is same
+ */
+#define EH_TX_EV_LINK_COMMON_EVENT_QUEUE (1 << 1)
+
#define RTE_LOGTYPE_EH RTE_LOGTYPE_USER4
#define EH_LOG_ERR(...) \
@@ -23,9 +33,15 @@ extern "C" {
/* Max Rx adapters supported */
#define EVENT_MODE_MAX_RX_ADAPTERS RTE_EVENT_MAX_DEVS
+/* Max Tx adapters supported */
+#define EVENT_MODE_MAX_TX_ADAPTERS RTE_EVENT_MAX_DEVS
+
/* Max Rx adapter connections */
#define EVENT_MODE_MAX_CONNECTIONS_PER_ADAPTER 16
+/* Max Tx adapter connections */
+#define EVENT_MODE_MAX_CONNECTIONS_PER_TX_ADAPTER 16
+
/* Max event queues supported per event device */
#define EVENT_MODE_MAX_EVENT_QUEUES_PER_DEV RTE_EVENT_MAX_QUEUES_PER_DEV
@@ -33,6 +49,9 @@ extern "C" {
#define EVENT_MODE_MAX_LCORE_LINKS \
(EVENT_MODE_MAX_EVENT_DEVS * EVENT_MODE_MAX_EVENT_QUEUES_PER_DEV)
+/* Max adapters that one Tx core can handle */
+#define EVENT_MODE_MAX_ADAPTERS_PER_TX_CORE EVENT_MODE_MAX_TX_ADAPTERS
+
/**
* Packet transfer mode of the application
*/
@@ -80,6 +99,23 @@ struct rx_adapter_conf {
conn[EVENT_MODE_MAX_CONNECTIONS_PER_ADAPTER];
};
+/* Tx adapter connection info */
+struct tx_adapter_connection_info {
+ uint8_t ethdev_id;
+ int32_t ethdev_tx_qid;
+};
+
+/* Tx adapter conf */
+struct tx_adapter_conf {
+ int32_t eventdev_id;
+ int32_t adapter_id;
+ uint32_t tx_core_id;
+ uint8_t nb_connections;
+ struct tx_adapter_connection_info
+ conn[EVENT_MODE_MAX_CONNECTIONS_PER_TX_ADAPTER];
+ uint8_t tx_ev_queue;
+};
+
/* Eventmode conf data */
struct eventmode_conf {
int nb_eventdev;
@@ -90,6 +126,10 @@ struct eventmode_conf {
/**< No of Rx adapters */
struct rx_adapter_conf rx_adapter[EVENT_MODE_MAX_RX_ADAPTERS];
/**< Rx adapter conf */
+ uint8_t nb_tx_adapter;
+ /**< No of Tx adapters */
+ struct tx_adapter_conf tx_adapter[EVENT_MODE_MAX_TX_ADAPTERS];
+ /** Tx adapter conf */
uint8_t nb_link;
/**< No of links */
struct eh_event_link_info
@@ -170,6 +210,24 @@ eh_devs_init(struct eh_conf *mode_conf);
int32_t
eh_devs_uninit(struct eh_conf *mode_conf);
+/**
+ * Get eventdev tx queue
+ *
+ * If the application uses event device which does not support internal port
+ * then it needs to submit the events to a Tx queue before final transmission.
+ * This Tx queue will be created internally by the eventmode helper subsystem,
+ * and application will need its queue ID when it runs the execution loop.
+ *
+ * @param mode_conf
+ * Configuration of the mode in which app is doing packet handling
+ * @param eventdev_id
+ * Event device ID
+ * @return
+ * Tx queue ID
+ */
+uint8_t
+eh_get_tx_queue(struct eh_conf *mode_conf, uint8_t eventdev_id);
+
#ifdef __cplusplus
}
#endif
--
2.7.4
next prev parent reply other threads:[~2019-10-09 15:11 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-09 15:10 [dpdk-dev] [RFC PATCH 00/13] add eventmode to ipsec-secgw Anoob Joseph
2019-10-09 15:10 ` [dpdk-dev] [RFC PATCH 01/13] examples/ipsec-secgw: add framework for eventmode helper Anoob Joseph
2019-10-09 15:10 ` [dpdk-dev] [RFC PATCH 02/13] examples/ipsec-secgw: add eventdev port-lcore link Anoob Joseph
2019-10-09 15:10 ` [dpdk-dev] [RFC PATCH 03/13] examples/ipsec-secgw: add Rx adapter support Anoob Joseph
2019-10-09 15:10 ` Anoob Joseph [this message]
2019-10-09 15:10 ` [dpdk-dev] [RFC PATCH 05/13] examples/ipsec-secgw: add routines to display config Anoob Joseph
2019-10-09 15:10 ` [dpdk-dev] [RFC PATCH 06/13] examples/ipsec-secgw: add routines to launch workers Anoob Joseph
2019-10-09 15:10 ` [dpdk-dev] [RFC PATCH 07/13] examples/ipsec-secgw: add support for internal ports Anoob Joseph
2019-10-09 15:10 ` [dpdk-dev] [RFC PATCH 08/13] examples/ipsec-secgw: add eventmode to ipsec-secgw Anoob Joseph
2019-10-09 15:10 ` [dpdk-dev] [RFC PATCH 09/13] examples/ipsec-secgw: add app inbound worker Anoob Joseph
2019-10-09 15:10 ` [dpdk-dev] [RFC PATCH 10/13] examples/ipsec-secgw: add app processing code Anoob Joseph
2019-10-09 15:10 ` [dpdk-dev] [RFC PATCH 11/13] examples/ipsec-secgw: add driver outbound worker Anoob Joseph
2019-10-09 15:10 ` [dpdk-dev] [RFC PATCH 12/13] examples/ipsec-secgw: add app " Anoob Joseph
2019-10-09 15:10 ` [dpdk-dev] [RFC PATCH 13/13] examples/ipsec-secgw: add cmd line option for bufs Anoob Joseph
2019-10-16 13:02 ` [dpdk-dev] [RFC PATCH 00/13] add eventmode to ipsec-secgw Ananyev, Konstantin
2019-10-25 6:31 ` Anoob Joseph
2019-10-25 9:39 ` Ananyev, Konstantin
2019-10-28 5:44 ` Anoob Joseph
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1570633816-4706-5-git-send-email-anoobj@marvell.com \
--to=anoobj@marvell.com \
--cc=akhil.goyal@nxp.com \
--cc=dev@dpdk.org \
--cc=jerinj@marvell.com \
--cc=lbartosik@marvell.com \
--cc=pathreya@marvell.com \
--cc=radu.nicolau@intel.com \
--cc=thomas@monjalon.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).