From: Tiwei Bie <tiwei.bie@intel.com>
To: dev@dpdk.org
Cc: Yuanhan Liu <yuanhan.liu@linux.intel.com>
Subject: [dpdk-dev] [RFC 02/29] net/virtio: implement 1.1 guest Tx
Date: Wed, 21 Jun 2017 10:57:38 +0800 [thread overview]
Message-ID: <1498013885-102779-3-git-send-email-tiwei.bie@intel.com> (raw)
In-Reply-To: <1498013885-102779-1-git-send-email-tiwei.bie@intel.com>
From: Yuanhan Liu <yuanhan.liu@linux.intel.com>
build only so far
Signed-off-by: Yuanhan Liu <yuanhan.liu@linux.intel.com>
---
drivers/net/virtio/Makefile | 1 +
drivers/net/virtio/virtio_ethdev.c | 24 ++++--
drivers/net/virtio/virtio_ethdev.h | 3 +
drivers/net/virtio/virtio_rxtx.c | 3 +
drivers/net/virtio/virtio_rxtx_1.1.c | 159 +++++++++++++++++++++++++++++++++++
5 files changed, 183 insertions(+), 7 deletions(-)
create mode 100644 drivers/net/virtio/virtio_rxtx_1.1.c
diff --git a/drivers/net/virtio/Makefile b/drivers/net/virtio/Makefile
index b21b878..4c4ff42 100644
--- a/drivers/net/virtio/Makefile
+++ b/drivers/net/virtio/Makefile
@@ -49,6 +49,7 @@ LIBABIVER := 1
SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtqueue.c
SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_pci.c
SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_rxtx.c
+SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_rxtx_1.1.c
SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_ethdev.c
SRCS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += virtio_rxtx_simple.c
diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index 7c4799a..35ce07d 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -334,12 +334,12 @@ virtio_init_vring(struct virtqueue *vq)
vq->vq_desc_tail_idx = (uint16_t)(vq->vq_nentries - 1);
vring_desc_init(vr->desc, size);
- }
- /*
- * Disable device(host) interrupting guest
- */
- virtqueue_disable_intr(vq);
+ /*
+ * Disable device(host) interrupting guest
+ */
+ virtqueue_disable_intr(vq);
+ }
}
static int
@@ -625,7 +625,8 @@ virtio_dev_close(struct rte_eth_dev *dev)
}
vtpci_reset(hw);
- virtio_dev_free_mbufs(dev);
+ if (!vtpci_version_1_1(hw))
+ virtio_dev_free_mbufs(dev);
virtio_free_queues(hw);
}
@@ -1535,7 +1536,6 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
RTE_BUILD_BUG_ON(RTE_PKTMBUF_HEADROOM < sizeof(struct virtio_net_hdr_mrg_rxbuf));
eth_dev->dev_ops = &virtio_eth_dev_ops;
- eth_dev->tx_pkt_burst = &virtio_xmit_pkts;
if (rte_eal_process_type() == RTE_PROC_SECONDARY) {
if (!hw->virtio_user_dev) {
@@ -1579,6 +1579,12 @@ eth_virtio_dev_init(struct rte_eth_dev *eth_dev)
if (ret < 0)
return ret;
+ /* FIXME: as second process? */
+ if (vtpci_version_1_1(hw))
+ eth_dev->tx_pkt_burst = &virtio_xmit_pkts_1_1;
+ else
+ eth_dev->tx_pkt_burst = &virtio_xmit_pkts;
+
/* Setup interrupt callback */
if (eth_dev->data->dev_flags & RTE_ETH_DEV_INTR_LSC)
rte_intr_callback_register(eth_dev->intr_handle,
@@ -1750,6 +1756,10 @@ virtio_dev_start(struct rte_eth_dev *dev)
}
}
+ /*no rx support for virtio 1.1 yet*/
+ if (vtpci_version_1_1(hw))
+ return 0;
+
/*Notify the backend
*Otherwise the tap backend might already stop its queue due to fullness.
*vhost backend will have no chance to be waked up
diff --git a/drivers/net/virtio/virtio_ethdev.h b/drivers/net/virtio/virtio_ethdev.h
index c3413c6..deed34e 100644
--- a/drivers/net/virtio/virtio_ethdev.h
+++ b/drivers/net/virtio/virtio_ethdev.h
@@ -69,6 +69,7 @@
1u << VIRTIO_NET_F_MTU | \
1u << VIRTIO_RING_F_INDIRECT_DESC | \
1ULL << VIRTIO_F_VERSION_1 | \
+ 1ULL << VIRTIO_F_VERSION_1_1 | \
1ULL << VIRTIO_F_IOMMU_PLATFORM)
#define VIRTIO_PMD_SUPPORTED_GUEST_FEATURES \
@@ -104,6 +105,8 @@ uint16_t virtio_recv_mergeable_pkts(void *rx_queue, struct rte_mbuf **rx_pkts,
uint16_t virtio_xmit_pkts(void *tx_queue, struct rte_mbuf **tx_pkts,
uint16_t nb_pkts);
+uint16_t virtio_xmit_pkts_1_1(void *tx_queue, struct rte_mbuf **tx_pkts,
+ uint16_t nb_pkts);
uint16_t virtio_recv_pkts_vec(void *rx_queue, struct rte_mbuf **rx_pkts,
uint16_t nb_pkts);
diff --git a/drivers/net/virtio/virtio_rxtx.c b/drivers/net/virtio/virtio_rxtx.c
index fbc96df..e697192 100644
--- a/drivers/net/virtio/virtio_rxtx.c
+++ b/drivers/net/virtio/virtio_rxtx.c
@@ -427,6 +427,9 @@ virtio_dev_rx_queue_setup(struct rte_eth_dev *dev,
PMD_INIT_FUNC_TRACE();
+ if (vtpci_version_1_1(hw))
+ return 0;
+
if (nb_desc == 0 || nb_desc > vq->vq_nentries)
nb_desc = vq->vq_nentries;
vq->vq_free_cnt = RTE_MIN(vq->vq_free_cnt, nb_desc);
diff --git a/drivers/net/virtio/virtio_rxtx_1.1.c b/drivers/net/virtio/virtio_rxtx_1.1.c
new file mode 100644
index 0000000..e47a346
--- /dev/null
+++ b/drivers/net/virtio/virtio_rxtx_1.1.c
@@ -0,0 +1,159 @@
+/*-
+ * BSD LICENSE
+ *
+ * Copyright(c) 2010-2016 Intel Corporation. All rights reserved.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * * Neither the name of Intel Corporation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include <rte_cycles.h>
+#include <rte_memory.h>
+#include <rte_memzone.h>
+#include <rte_branch_prediction.h>
+#include <rte_mempool.h>
+#include <rte_malloc.h>
+#include <rte_mbuf.h>
+#include <rte_ether.h>
+#include <rte_ethdev.h>
+#include <rte_prefetch.h>
+#include <rte_string_fns.h>
+#include <rte_errno.h>
+#include <rte_byteorder.h>
+#include <rte_cpuflags.h>
+#include <rte_net.h>
+#include <rte_ip.h>
+#include <rte_udp.h>
+#include <rte_tcp.h>
+
+#include "virtio_logs.h"
+#include "virtio_ethdev.h"
+#include "virtio_pci.h"
+#include "virtqueue.h"
+#include "virtio_rxtx.h"
+
+/* Cleanup from completed transmits. */
+static void
+virtio_xmit_cleanup(struct virtqueue *vq)
+{
+ uint16_t idx;
+ uint16_t size = vq->vq_nentries;
+ struct vring_desc_1_1 *desc = vq->vq_ring.desc_1_1;
+
+ idx = vq->vq_used_cons_idx & (size - 1);
+ while ((desc[idx].flags & DESC_HW) == 0) {
+ struct vq_desc_extra *dxp;
+
+ dxp = &vq->vq_descx[idx];
+ if (dxp->cookie != NULL) {
+ rte_pktmbuf_free(dxp->cookie);
+ dxp->cookie = NULL;
+ }
+
+ idx = (++vq->vq_used_cons_idx) & (size - 1);
+ vq->vq_free_cnt++;
+
+ if (vq->vq_free_cnt >= size)
+ break;
+ }
+}
+
+static inline void
+virtio_xmit(struct virtnet_tx *txvq, struct rte_mbuf *mbuf)
+{
+ struct virtio_tx_region *txr = txvq->virtio_net_hdr_mz->addr;
+ struct virtqueue *vq = txvq->vq;
+ struct vring_desc_1_1 *desc = vq->vq_ring.desc_1_1;
+ uint16_t idx;
+ uint16_t head_idx = (vq->vq_avail_idx++) & (vq->vq_nentries - 1);
+
+ idx = head_idx;
+ vq->vq_free_cnt -= mbuf->nb_segs + 1;
+ vq->vq_descx[idx].cookie = mbuf;
+
+ desc[idx].addr = txvq->virtio_net_hdr_mem +
+ RTE_PTR_DIFF(&txr[idx].tx_hdr, txr);
+ desc[idx].len = vq->hw->vtnet_hdr_size;
+ desc[idx].flags = VRING_DESC_F_NEXT;
+
+ do {
+ idx = (vq->vq_avail_idx++) & (vq->vq_nentries - 1);
+ desc[idx].addr = VIRTIO_MBUF_DATA_DMA_ADDR(mbuf, vq);
+ desc[idx].len = mbuf->data_len;
+ desc[idx].flags = DESC_HW | VRING_DESC_F_NEXT;
+ } while ((mbuf = mbuf->next) != NULL);
+
+ desc[idx].flags &= ~VRING_DESC_F_NEXT;
+
+ /*
+ * update the head last, so that when the host saw such flag
+ * is set, it means all others in the same chain is also set
+ */
+ rte_smp_wmb();
+ desc[head_idx].flags |= DESC_HW;
+}
+
+uint16_t
+virtio_xmit_pkts_1_1(void *tx_queue, struct rte_mbuf **tx_pkts, uint16_t nb_pkts)
+{
+ struct virtnet_tx *txvq = tx_queue;
+ struct virtqueue *vq = txvq->vq;
+ uint16_t i;
+
+ if (unlikely(nb_pkts < 1))
+ return nb_pkts;
+
+ PMD_TX_LOG(DEBUG, "%d packets to xmit", nb_pkts);
+
+ for (i = 0; i < nb_pkts; i++) {
+ struct rte_mbuf *txm = tx_pkts[i];
+
+ if (unlikely(txm->nb_segs + 1 > vq->vq_free_cnt)) {
+ virtio_xmit_cleanup(vq);
+
+ if (unlikely(txm->nb_segs + 1 > vq->vq_free_cnt)) {
+ PMD_TX_LOG(ERR,
+ "No free tx descriptors to transmit");
+ break;
+ }
+ }
+
+ virtio_xmit(txvq, txm);
+ txvq->stats.bytes += txm->pkt_len;
+ }
+
+ txvq->stats.packets += i;
+ txvq->stats.errors += nb_pkts - i;
+
+ return i;
+}
--
2.7.4
next prev parent reply other threads:[~2017-06-21 2:59 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-21 2:57 [dpdk-dev] [RFC 00/29] latest virtio1.1 prototype Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 01/29] net/virtio: vring init for 1.1 Tiwei Bie
2017-06-21 2:57 ` Tiwei Bie [this message]
2017-06-21 2:57 ` [dpdk-dev] [RFC 03/29] net/virtio-user: add option to enable 1.1 Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 04/29] vhost: enable 1.1 for testing Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 05/29] vhost: set desc addr for 1.1 Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 06/29] vhost: implement virtio 1.1 dequeue path Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 07/29] vhost: mark desc being used Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 08/29] xxx: batch the desc_hw update? Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 09/29] xxx: virtio: remove overheads Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 10/29] vhost: prefetch desc Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 11/29] add virtio 1.1 test guide Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 12/29] testpmd: add s-txonly Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 13/29] net/virtio: implement the Rx code path Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 14/29] vhost: a rough implementation on enqueue " Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 15/29] vhost: descriptor length should include vhost header Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 16/29] net/virtio: avoid touching packet data Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 17/29] net/virtio: fix virtio1.1 feature negotiation Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 18/29] net/virtio: the Rx support for virtio1.1 has been added now Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 19/29] vhost: VIRTIO_NET_F_MRG_RXBUF is not supported for now Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 20/29] vhost: fix vring addr setup Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 21/29] net/virtio: free mbuf when need to use Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 22/29] vhost: don't copy descs during Rx Tiwei Bie
2017-06-21 2:57 ` [dpdk-dev] [RFC 23/29] vhost: fix mbuf leak Tiwei Bie
2017-06-21 2:58 ` [dpdk-dev] [RFC 24/29] net/virtio: cleanup txd when free count below threshold Tiwei Bie
2017-06-21 2:58 ` [dpdk-dev] [RFC 25/29] net/virtio: refill descs for vhost in batch Tiwei Bie
2017-06-21 2:58 ` [dpdk-dev] [RFC 26/29] vhost: remove dead code Tiwei Bie
2017-06-21 2:58 ` [dpdk-dev] [RFC 27/29] vhost: various optimizations for Tx Tiwei Bie
2017-06-21 2:58 ` [dpdk-dev] [RFC 28/29] vhost: make the code more readable Tiwei Bie
2017-06-21 2:58 ` [dpdk-dev] [RFC 29/29] vhost: update and return descs in batch Tiwei Bie
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=1498013885-102779-3-git-send-email-tiwei.bie@intel.com \
--to=tiwei.bie@intel.com \
--cc=dev@dpdk.org \
--cc=yuanhan.liu@linux.intel.com \
/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).