Skip to content

Commit

Permalink
virtio: add new driver
Browse files Browse the repository at this point in the history
This PMD can be used in a VM having virtio-net NIC.

Note: it is a different implementation than virtio-usermap extension.

Signed-off-by: Intel
  • Loading branch information
Intel authored and Thomas Monjalon committed Oct 9, 2013
1 parent 7ef0072 commit c1f8630
Show file tree
Hide file tree
Showing 20 changed files with 2,335 additions and 7 deletions.
10 changes: 10 additions & 0 deletions config/defconfig_i686-default-linuxapp-gcc
Expand Up @@ -163,6 +163,16 @@ CONFIG_RTE_LIBRTE_IXGBE_PF_DISABLE_STRIP_CRC=n
CONFIG_RTE_LIBRTE_IXGBE_RX_ALLOW_BULK_ALLOC=y
CONFIG_RTE_LIBRTE_IXGBE_ALLOW_UNSUPPORTED_SFP=n

#
# Compile burst-oriented VIRTIO PMD driver
#
CONFIG_RTE_LIBRTE_VIRTIO_PMD=y
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_INIT=n
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_RX=n
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_TX=n
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_DRIVER=n
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_DUMP=n

#
# Do prefetch of packet data within PMD driver receive function
#
Expand Down
10 changes: 10 additions & 0 deletions config/defconfig_i686-default-linuxapp-icc
Expand Up @@ -164,6 +164,16 @@ CONFIG_RTE_LIBRTE_IXGBE_PF_DISABLE_STRIP_CRC=n
CONFIG_RTE_LIBRTE_IXGBE_RX_ALLOW_BULK_ALLOC=y
CONFIG_RTE_LIBRTE_IXGBE_ALLOW_UNSUPPORTED_SFP=n

#
# Compile burst-oriented VIRTIO PMD driver
#
CONFIG_RTE_LIBRTE_VIRTIO_PMD=y
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_INIT=n
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_RX=n
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_TX=n
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_DRIVER=n
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_DUMP=n

#
# Do prefetch of packet data within PMD driver receive function
#
Expand Down
10 changes: 10 additions & 0 deletions config/defconfig_x86_64-default-linuxapp-gcc
Expand Up @@ -175,6 +175,16 @@ CONFIG_RTE_LIBRTE_IXGBE_PF_DISABLE_STRIP_CRC=n
CONFIG_RTE_LIBRTE_IXGBE_RX_ALLOW_BULK_ALLOC=y
CONFIG_RTE_LIBRTE_IXGBE_ALLOW_UNSUPPORTED_SFP=n

#
# Compile burst-oriented VIRTIO PMD driver
#
CONFIG_RTE_LIBRTE_VIRTIO_PMD=y
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_INIT=n
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_RX=n
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_TX=n
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_DRIVER=n
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_DUMP=n

#
# Compile example software rings based PMD
#
Expand Down
10 changes: 10 additions & 0 deletions config/defconfig_x86_64-default-linuxapp-icc
Expand Up @@ -164,6 +164,16 @@ CONFIG_RTE_LIBRTE_IXGBE_PF_DISABLE_STRIP_CRC=n
CONFIG_RTE_LIBRTE_IXGBE_RX_ALLOW_BULK_ALLOC=y
CONFIG_RTE_LIBRTE_IXGBE_ALLOW_UNSUPPORTED_SFP=n

#
# Compile burst-oriented VIRTIO PMD driver
#
CONFIG_RTE_LIBRTE_VIRTIO_PMD=y
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_INIT=n
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_RX=n
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_TX=n
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_DRIVER=n
CONFIG_RTE_LIBRTE_VIRTIO_DEBUG_DUMP=n

#
# Compile example software rings based PMD
#
Expand Down
1 change: 1 addition & 0 deletions lib/Makefile
Expand Up @@ -44,6 +44,7 @@ DIRS-$(CONFIG_RTE_LIBRTE_E1000_PMD) += librte_pmd_e1000
DIRS-$(CONFIG_RTE_LIBRTE_IXGBE_PMD) += librte_pmd_ixgbe
DIRS-$(CONFIG_RTE_LIBRTE_PMD_RING) += librte_pmd_ring
DIRS-$(CONFIG_RTE_LIBRTE_PMD_PCAP) += librte_pmd_pcap
DIRS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += librte_pmd_virtio
DIRS-$(CONFIG_RTE_LIBRTE_HASH) += librte_hash
DIRS-$(CONFIG_RTE_LIBRTE_LPM) += librte_lpm
DIRS-$(CONFIG_RTE_LIBRTE_NET) += librte_net
Expand Down
22 changes: 20 additions & 2 deletions lib/librte_eal/common/include/rte_pci_dev_ids.h
Expand Up @@ -63,15 +63,17 @@
* This file contains a list of the PCI device IDs recognised by DPDK, which
* can be used to fill out an array of structures describing the devices.
*
* Currently three families of devices are recognised: those supported by the
* IGB driver, by EM driver, and those supported by the IXGBE driver.
* Currently four families of devices are recognised: those supported by the
* IGB driver, by EM driver, those supported by the IXGBE driver, and by virtio
* driver which is a para virtualization driver running in guest virtual machine.
* The inclusion of these in an array built using this file depends on the
* definition of
* RTE_PCI_DEV_ID_DECL_EM
* RTE_PCI_DEV_ID_DECL_IGB
* RTE_PCI_DEV_ID_DECL_IGBVF
* RTE_PCI_DEV_ID_DECL_IXGBE
* RTE_PCI_DEV_ID_DECL_IXGBEVF
* RTE_PCI_DEV_ID_DECL_VIRTIO
* at the time when this file is included.
*
* In order to populate an array, the user of this file must define this macro:
Expand Down Expand Up @@ -112,11 +114,20 @@
#define RTE_PCI_DEV_ID_DECL_IXGBEVF(vend, dev)
#endif

#ifndef RTE_PCI_DEV_ID_DECL_VIRTIO
#define RTE_PCI_DEV_ID_DECL_VIRTIO(vend, dev)
#endif

#ifndef PCI_VENDOR_ID_INTEL
/** Vendor ID used by Intel devices */
#define PCI_VENDOR_ID_INTEL 0x8086
#endif

#ifndef PCI_VENDOR_ID_QUMRANET
/** Vendor ID used by virtio devices */
#define PCI_VENDOR_ID_QUMRANET 0x1AF4
#endif

/******************** Physical EM devices from e1000_hw.h ********************/

#define E1000_DEV_ID_82542 0x1000
Expand Down Expand Up @@ -417,6 +428,12 @@ RTE_PCI_DEV_ID_DECL_IXGBEVF(PCI_VENDOR_ID_INTEL, IXGBE_DEV_ID_82599_VF_HV)
RTE_PCI_DEV_ID_DECL_IXGBEVF(PCI_VENDOR_ID_INTEL, IXGBE_DEV_ID_X540_VF)
RTE_PCI_DEV_ID_DECL_IXGBEVF(PCI_VENDOR_ID_INTEL, IXGBE_DEV_ID_X540_VF_HV)

/****************** Virtio devices from virtio.h ******************/

#define QUMRANET_DEV_ID_VIRTIO 0x1000

RTE_PCI_DEV_ID_DECL_VIRTIO(PCI_VENDOR_ID_QUMRANET, QUMRANET_DEV_ID_VIRTIO)

/*
* Undef all RTE_PCI_DEV_ID_DECL_* here.
*/
Expand All @@ -425,3 +442,4 @@ RTE_PCI_DEV_ID_DECL_IXGBEVF(PCI_VENDOR_ID_INTEL, IXGBE_DEV_ID_X540_VF_HV)
#undef RTE_PCI_DEV_ID_DECL_IGBVF
#undef RTE_PCI_DEV_ID_DECL_IXGBE
#undef RTE_PCI_DEV_ID_DECL_IXGBEVF
#undef RTE_PCI_DEV_ID_DECL_VIRTIO
35 changes: 32 additions & 3 deletions lib/librte_eal/linuxapp/eal/eal_pci.c
Expand Up @@ -65,6 +65,7 @@
#include <rte_string_fns.h>
#include <rte_debug.h>

#include "rte_pci_dev_ids.h"
#include "eal_filesystem.h"
#include "eal_private.h"

Expand Down Expand Up @@ -467,10 +468,12 @@ pci_uio_map_resource(struct rte_pci_device *dev)
struct dirent *e;
DIR *dir;
char dirname[PATH_MAX];
char filename[PATH_MAX];
char dirname2[PATH_MAX];
char devname[PATH_MAX]; /* contains the /dev/uioX */
void *mapaddr;
unsigned uio_num;
unsigned long start,size;
uint64_t phaddr;
uint64_t offset;
uint64_t pagesz;
Expand All @@ -482,7 +485,8 @@ pci_uio_map_resource(struct rte_pci_device *dev)
dev->intr_handle.fd = -1;

/* secondary processes - use already recorded details */
if (rte_eal_process_type() != RTE_PROC_PRIMARY)
if ((rte_eal_process_type() != RTE_PROC_PRIMARY) &&
(dev->id.vendor_id != PCI_VENDOR_ID_QUMRANET))
return (pci_uio_map_secondary(dev));

/* depending on kernel version, uio can be located in uio/uioX
Expand Down Expand Up @@ -544,17 +548,42 @@ pci_uio_map_resource(struct rte_pci_device *dev)
return -1;
}

if(dev->id.vendor_id == PCI_VENDOR_ID_QUMRANET) {
/* get portio size */
rte_snprintf(filename, sizeof(filename),
"%s/portio/port0/size", dirname2);
if (eal_parse_sysfs_value(filename, &size) < 0) {
RTE_LOG(ERR, EAL, "%s(): cannot parse size\n",
__func__);
return -1;
}

/* get portio start */
rte_snprintf(filename, sizeof(filename),
"%s/portio/port0/start", dirname2);
if (eal_parse_sysfs_value(filename, &start) < 0) {
RTE_LOG(ERR, EAL, "%s(): cannot parse portio start\n",
__func__);
return -1;
}
dev->mem_resource[0].addr = (void *)(uintptr_t)start;
dev->mem_resource[0].len = (uint64_t)size;
RTE_LOG(DEBUG, EAL, "PCI Port IO found start=0x%lx with size=0x%lx\n", start, size);
/* rte_virtio_pmd does not need any other bar even if available */
return (0);
}

/* allocate the mapping details for secondary processes*/
if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
RTE_LOG(ERR, EAL,
"%s(): cannot store uio mmap details\n", __func__);
return (-1);
}

rte_snprintf(devname, sizeof(devname), "/dev/uio%u", uio_num);
rte_snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
memcpy(&uio_res->pci_addr, &dev->addr, sizeof(uio_res->pci_addr));

/* collect info about device mappings */
if ((nb_maps = pci_uio_get_mappings(dirname2, uio_res->maps,
sizeof (uio_res->maps) / sizeof (uio_res->maps[0])))
Expand Down
1 change: 1 addition & 0 deletions lib/librte_eal/linuxapp/igb_uio/igb_uio.c
Expand Up @@ -75,6 +75,7 @@ static struct pci_device_id igbuio_pci_ids[] = {
#define RTE_PCI_DEV_ID_DECL_IGBVF(vend, dev) {PCI_DEVICE(vend, dev)},
#define RTE_PCI_DEV_ID_DECL_IXGBE(vend, dev) {PCI_DEVICE(vend, dev)},
#define RTE_PCI_DEV_ID_DECL_IXGBEVF(vend, dev) {PCI_DEVICE(vend, dev)},
#define RTE_PCI_DEV_ID_DECL_VIRTIO(vend, dev) {PCI_DEVICE(vend, dev)},
#include <rte_pci_dev_ids.h>
{ 0, },
};
Expand Down
16 changes: 16 additions & 0 deletions lib/librte_ether/rte_ethdev.h
Expand Up @@ -1257,6 +1257,15 @@ extern int rte_ixgbe_pmd_init(void);
*/
extern int rte_ixgbevf_pmd_init(void);

/**
* The initialization function of the driver for Qumranet virtio-net
* Ethernet devices.
* Invoked once at EAL start time.
* @return
* 0 on success
*/
extern int rte_virtio_pmd_init(void);

/**
* The initialization function of *all* supported and enabled drivers.
* Right now, the following PMDs are supported:
Expand Down Expand Up @@ -1306,6 +1315,13 @@ int rte_pmd_init_all(void)
}
#endif /* RTE_LIBRTE_IXGBE_PMD */

#ifdef RTE_LIBRTE_VIRTIO_PMD
if ((ret = rte_virtio_pmd_init()) != 0) {
RTE_LOG(ERR, PMD, "Cannot init virtio PMD\n");
return (ret);
}
#endif /* RTE_LIBRTE_VIRTIO_PMD */

if (ret == -ENODEV)
RTE_LOG(ERR, PMD, "No PMD(s) are configured\n");
return (ret);
Expand Down
57 changes: 57 additions & 0 deletions lib/librte_pmd_virtio/Makefile
@@ -0,0 +1,57 @@
# BSD LICENSE
#
# Copyright(c) 2010-2013 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 $(RTE_SDK)/mk/rte.vars.mk

#
# library name
#
LIB = librte_pmd_virtio.a

CFLAGS += -O3
CFLAGS += $(WERROR_FLAGS)


#
# all source are stored in SRCS-y
#
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_ethdev.c


# this lib depends upon:
DEPDIRS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += lib/librte_eal lib/librte_ether
DEPDIRS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += lib/librte_mempool lib/librte_mbuf
DEPDIRS-$(CONFIG_RTE_LIBRTE_VIRTIO_PMD) += lib/librte_net lib/librte_malloc

include $(RTE_SDK)/mk/rte.lib.mk

0 comments on commit c1f8630

Please sign in to comment.