From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by dpdk.org (Postfix) with ESMTP id D54F5B0FB for ; Fri, 16 May 2014 20:15:11 +0200 (CEST) Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP; 16 May 2014 11:10:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="4.97,1068,1389772800"; d="scan'208";a="512901725" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by orsmga001.jf.intel.com with ESMTP; 16 May 2014 11:15:17 -0700 Received: from sivswdev02.ir.intel.com (sivswdev02.ir.intel.com [10.237.217.46]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id s4GIFGPg005884; Fri, 16 May 2014 19:15:16 +0100 Received: from sivswdev02.ir.intel.com (localhost [127.0.0.1]) by sivswdev02.ir.intel.com with ESMTP id s4GIFGtk028580; Fri, 16 May 2014 19:15:16 +0100 Received: (from bricha3@localhost) by sivswdev02.ir.intel.com with id s4GIFGD5028576; Fri, 16 May 2014 19:15:16 +0100 From: Bruce Richardson To: dev@dpdk.org Date: Fri, 16 May 2014 19:15:13 +0100 Message-Id: <1400264114-28455-3-git-send-email-bruce.richardson@intel.com> X-Mailer: git-send-email 1.7.0.7 In-Reply-To: <1400264114-28455-1-git-send-email-bruce.richardson@intel.com> References: <1400264114-28455-1-git-send-email-bruce.richardson@intel.com> Subject: [dpdk-dev] [PATCH 2/3] ring: add support for converting a ring to ethdev X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: patches and discussions about DPDK List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 16 May 2014 18:15:12 -0000 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 --- 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 #include #include +#include #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