DPDK patches and discussions
 help / color / mirror / Atom feed
From: Bruce Richardson <bruce.richardson@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH 2/3] ring: add support for converting a ring to ethdev
Date: Fri, 16 May 2014 19:15:13 +0100	[thread overview]
Message-ID: <1400264114-28455-3-git-send-email-bruce.richardson@intel.com> (raw)
In-Reply-To: <1400264114-28455-1-git-send-email-bruce.richardson@intel.com>

Add in a pair of functions which meet the criteria for rx_burst and
tx_burst, which then allow a ring to be used as though it were an
ethdev, so that code can be written agnostically. Provide a convertion
function that takes a single ring and returns an index of the ethdev
corresponding to it.

Signed-off-by: Bruce Richardson <bruce.richardson@intel.com>
---
 lib/librte_ring/Makefile   |  1 +
 lib/librte_ring/rte_ring.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 lib/librte_ring/rte_ring.h | 11 +++++++++++
 3 files changed, 54 insertions(+)

diff --git a/lib/librte_ring/Makefile b/lib/librte_ring/Makefile
index 64c3460..b1d35ac 100644
--- a/lib/librte_ring/Makefile
+++ b/lib/librte_ring/Makefile
@@ -34,6 +34,7 @@ include $(RTE_SDK)/mk/rte.vars.mk
 # library name
 LIB = librte_ring.a
 
+CFLAGS += -I$(RTE_SDK)/lib/librte_ether
 CFLAGS += $(WERROR_FLAGS) -I$(SRCDIR) -O3
 
 # all source are stored in SRCS-y
diff --git a/lib/librte_ring/rte_ring.c b/lib/librte_ring/rte_ring.c
index 3a919b0..56a46a7 100644
--- a/lib/librte_ring/rte_ring.c
+++ b/lib/librte_ring/rte_ring.c
@@ -86,6 +86,7 @@
 #include <rte_errno.h>
 #include <rte_string_fns.h>
 #include <rte_spinlock.h>
+#include <rte_ethdev.h>
 
 #include "rte_ring.h"
 
@@ -136,6 +137,7 @@ rte_ring_init(struct rte_ring *r, const char *name, unsigned count,
 	/* init the ring structure */
 	memset(r, 0, sizeof(*r));
 	rte_snprintf(r->name, sizeof(r->name), "%s", name);
+	r->self = r;
 	r->flags = flags;
 	r->prod.watermark = count;
 	r->prod.sp_enqueue = !!(flags & RING_F_SP_ENQ);
@@ -319,3 +321,43 @@ rte_ring_lookup(const char *name)
 
 	return r;
 }
+
+static uint16_t
+ring_eth_rx_burst(void *rxq, struct rte_mbuf **rx_pkts,
+		uint16_t nb_pkts)
+{
+	struct rte_ring *r = rxq;
+	return rte_ring_dequeue_burst(r, (void *)rx_pkts, nb_pkts);
+}
+
+static uint16_t
+ring_eth_tx_burst(void *txq, struct rte_mbuf **tx_pkts,
+		uint16_t nb_pkts)
+{
+	struct rte_ring *r = txq;
+	return rte_ring_enqueue_burst(r, (void *)tx_pkts, nb_pkts);
+}
+
+int
+rte_ring_as_eth_dev(struct rte_ring *r)
+{
+	static struct eth_dev_ops ops = { NULL };
+
+	/* reserve an ethdev entry */
+	struct rte_eth_dev *eth_dev = rte_eth_dev_allocate();
+	if (eth_dev == NULL)
+		goto error;
+
+	eth_dev->dev_ops = &ops;
+	eth_dev->rx_pkt_burst = ring_eth_rx_burst;
+	eth_dev->tx_pkt_burst = ring_eth_tx_burst;
+	eth_dev->data->nb_rx_queues = 1;
+	eth_dev->data->rx_queues = &r->self;
+	eth_dev->data->nb_tx_queues = 1;
+	eth_dev->data->tx_queues = &r->self;
+
+	return eth_dev->data->port_id;
+
+error:
+	return -1;
+}
diff --git a/lib/librte_ring/rte_ring.h b/lib/librte_ring/rte_ring.h
index da54e34..be6bc08 100644
--- a/lib/librte_ring/rte_ring.h
+++ b/lib/librte_ring/rte_ring.h
@@ -141,6 +141,7 @@ struct rte_ring {
 	TAILQ_ENTRY(rte_ring) next;      /**< Next in list. */
 
 	char name[RTE_RING_NAMESIZE];    /**< Name of the ring. */
+	void *self;                      /**< Self pointer - used by ethdev fn */
 	int flags;                       /**< Flags supplied at creation. */
 
 	/** Ring producer status. */
@@ -296,6 +297,16 @@ struct rte_ring *rte_ring_create(const char *name, unsigned count,
 				 int socket_id, unsigned flags);
 
 /**
+ * Use a ring as though it were an ethernet port
+ *
+ * @param r
+ *  Pointer to the ring structure
+ * @return
+ *  The port number of the new ethdev to be used for rx/tx burst functions
+ */
+int rte_ring_as_eth_dev(struct rte_ring *r);
+
+/**
  * Change the high water mark.
  *
  * If *count* is 0, water marking is disabled. Otherwise, it is set to the
-- 
1.9.0

  parent reply	other threads:[~2014-05-16 18:15 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-05-16 18:15 [dpdk-dev] [PATCH 0/3] ring: provide rte_ring_as_ethdev API Bruce Richardson
2014-05-16 18:15 ` [dpdk-dev] [PATCH 1/3] ethdev: Remove ethdev.h dependency on mbuf + mempool Bruce Richardson
2014-05-16 18:15 ` Bruce Richardson [this message]
2014-05-16 18:15 ` [dpdk-dev] [PATCH 3/3] ring: autotest for using ring as ethdev Bruce Richardson
2014-05-16 18:54 ` [dpdk-dev] [PATCH 0/3] ring: provide rte_ring_as_ethdev API Neil Horman
2014-05-19 10:59   ` Richardson, Bruce
2014-05-19 13:40     ` Neil Horman

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=1400264114-28455-3-git-send-email-bruce.richardson@intel.com \
    --to=bruce.richardson@intel.com \
    --cc=dev@dpdk.org \
    /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).