diff mbox series

[dpdk-dev,02/21] net/softnic: add software queue object

Message ID 20180608124155.140663-3-jasvinder.singh@intel.com (mailing list archive)
State Superseded, archived
Delegated to: Cristian Dumitrescu
Headers show
Series [dpdk-dev,01/21] net/softnic: restructuring | expand

Checks

Context Check Description
ci/Intel-compilation fail Compilation issues
ci/checkpatch warning coding style issues

Commit Message

Singh, Jasvinder June 8, 2018, 12:41 p.m. UTC
Add swq object implementation to the softnic.

Signed-off-by: Cristian Dumitrescu <cristian.dumitrescu@intel.com>
Signed-off-by: Jasvinder Singh <jasvinder.singh@intel.com>
---
 drivers/net/softnic/Makefile                    |  1 +
 drivers/net/softnic/rte_eth_softnic.c           |  7 ++
 drivers/net/softnic/rte_eth_softnic_internals.h | 39 ++++++++++
 drivers/net/softnic/rte_eth_softnic_swq.c       | 98 +++++++++++++++++++++++++
 4 files changed, 145 insertions(+)
 create mode 100644 drivers/net/softnic/rte_eth_softnic_swq.c
diff mbox series

Patch

diff --git a/drivers/net/softnic/Makefile b/drivers/net/softnic/Makefile
index d56fecd..d8e62bf 100644
--- a/drivers/net/softnic/Makefile
+++ b/drivers/net/softnic/Makefile
@@ -22,6 +22,7 @@  LIBABIVER := 1
 # all source are stored in SRCS-y
 #
 SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic.c
+SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_swq.c
 SRCS-$(CONFIG_RTE_LIBRTE_PMD_SOFTNIC) += rte_eth_softnic_tm.c
 
 #
diff --git a/drivers/net/softnic/rte_eth_softnic.c b/drivers/net/softnic/rte_eth_softnic.c
index 342ae2c..364cd65 100644
--- a/drivers/net/softnic/rte_eth_softnic.c
+++ b/drivers/net/softnic/rte_eth_softnic.c
@@ -218,14 +218,21 @@  pmd_init(struct pmd_params *params)
 	if (p == NULL)
 		return NULL;
 
+	/* Params */
 	memcpy(&p->params, params, sizeof(p->params));
 
+	/* Resources */
+	swq_init(p);
 	return p;
 }
 
 static void
 pmd_free(struct pmd_internals *p)
 {
+	if (p == NULL)
+		return;
+
+	swq_free(p);
 	rte_free(p);
 }
 
diff --git a/drivers/net/softnic/rte_eth_softnic_internals.h b/drivers/net/softnic/rte_eth_softnic_internals.h
index dbe5a37..aac5a92 100644
--- a/drivers/net/softnic/rte_eth_softnic_internals.h
+++ b/drivers/net/softnic/rte_eth_softnic_internals.h
@@ -7,8 +7,10 @@ 
 
 #include <stddef.h>
 #include <stdint.h>
+#include <sys/queue.h>
 
 #include <rte_mbuf.h>
+#include <rte_ring.h>
 #include <rte_ethdev.h>
 #include <rte_sched.h>
 #include <rte_ethdev_driver.h>
@@ -16,6 +18,8 @@ 
 
 #include "rte_eth_softnic.h"
 
+#define NAME_SIZE                                            64
+
 /**
  * PMD Parameters
  */
@@ -50,6 +54,21 @@  struct pmd_params {
 };
 
 /**
+ * SWQ
+ */
+struct swq_params {
+	uint32_t size;
+};
+
+struct swq {
+	TAILQ_ENTRY(swq) node;
+	char name[NAME_SIZE];
+	struct rte_ring *r;
+};
+
+TAILQ_HEAD(swq_list, swq);
+
+/**
  * Traffic Management (TM) Internals
  */
 
@@ -172,9 +191,29 @@  struct pmd_internals {
 	struct {
 		struct tm_internals tm; /**< Traffic Management */
 	} soft;
+
+	struct swq_list swq_list;
 };
 
 /**
+ * SWQ
+ */
+int
+swq_init(struct pmd_internals *p);
+
+void
+swq_free(struct pmd_internals *p);
+
+struct swq *
+swq_find(struct pmd_internals *p,
+	const char *name);
+
+struct swq *
+swq_create(struct pmd_internals *p,
+	const char *name,
+	struct swq_params *params);
+
+/**
  * Traffic Management (TM) Operation
  */
 extern const struct rte_tm_ops pmd_tm_ops;
diff --git a/drivers/net/softnic/rte_eth_softnic_swq.c b/drivers/net/softnic/rte_eth_softnic_swq.c
new file mode 100644
index 0000000..d385dd1
--- /dev/null
+++ b/drivers/net/softnic/rte_eth_softnic_swq.c
@@ -0,0 +1,98 @@ 
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2018 Intel Corporation
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <rte_string_fns.h>
+
+#include "rte_eth_softnic_internals.h"
+
+int
+swq_init(struct pmd_internals *p)
+{
+	TAILQ_INIT(&p->swq_list);
+
+	return 0;
+}
+
+void
+swq_free(struct pmd_internals *p)
+{
+	for ( ; ; ) {
+		struct swq *swq;
+
+		swq = TAILQ_FIRST(&p->swq_list);
+		if (swq == NULL)
+			break;
+
+		TAILQ_REMOVE(&p->swq_list, swq, node);
+		rte_ring_free(swq->r);
+		free(swq);
+	}
+}
+
+struct swq *
+swq_find(struct pmd_internals *p,
+	const char *name)
+{
+	struct swq *swq;
+
+	if (name == NULL)
+		return NULL;
+
+	TAILQ_FOREACH(swq, &p->swq_list, node)
+		if (strcmp(swq->name, name) == 0)
+			return swq;
+
+	return NULL;
+}
+
+struct swq *
+swq_create(struct pmd_internals *p,
+	const char *name,
+	struct swq_params *params)
+{
+	char ring_name[NAME_SIZE];
+	struct swq *swq;
+	struct rte_ring *r;
+	unsigned int flags = RING_F_SP_ENQ | RING_F_SC_DEQ;
+
+	/* Check input params */
+	if ((name == NULL) ||
+		swq_find(p, name) ||
+		(params == NULL) ||
+		(params->size == 0))
+		return NULL;
+
+	/* Resource create */
+	snprintf(ring_name, sizeof(ring_name), "%s_%s",
+		p->params.name,
+		name);
+
+	r = rte_ring_create(
+		ring_name,
+		params->size,
+		p->params.cpu_id,
+		flags);
+
+	if (r == NULL)
+		return NULL;
+
+	/* Node allocation */
+	swq = calloc(1, sizeof(struct swq));
+	if (swq == NULL) {
+		rte_ring_free(r);
+		return NULL;
+	}
+
+	/* Node fill in */
+	strlcpy(swq->name, name, sizeof(swq->name));
+	swq->r = r;
+
+	/* Node add to list */
+	TAILQ_INSERT_TAIL(&p->swq_list, swq, node);
+
+	return swq;
+}